This repository was archived by the owner on Feb 25, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +65
-0
lines changed Expand file tree Collapse file tree 4 files changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -117,6 +117,8 @@ extension CanvasKitExtension on CanvasKit {
117117 int width,
118118 int height,
119119 ColorSpace colorSpace,
120+ int sampleCount,
121+ int stencil,
120122 );
121123 external SkSurface MakeSWCanvasSurface (DomCanvasElement canvas);
122124
Original file line number Diff line number Diff line change @@ -98,6 +98,8 @@ class Surface {
9898 DomCanvasElement ? htmlCanvas;
9999 int _pixelWidth = - 1 ;
100100 int _pixelHeight = - 1 ;
101+ int _sampleCount = - 1 ;
102+ int _stencilBits = - 1 ;
101103
102104 /// Specify the GPU resource cache limits.
103105 void setSkiaResourceCacheMaxBytes (int bytes) {
@@ -334,6 +336,9 @@ class Surface {
334336 majorVersion: webGLVersion.toDouble (),
335337 ),
336338 ).toInt ();
339+ if (_sampleCount == - 1 || _stencilBits == - 1 ) {
340+ _initWebglParams ();
341+ }
337342
338343 _glContext = glContext;
339344
@@ -352,6 +357,12 @@ class Surface {
352357 htmlElement.append (htmlCanvas);
353358 }
354359
360+ void _initWebglParams () {
361+ final WebGLContext gl = htmlCanvas! .getGlContext (webGLVersion);
362+ _sampleCount = gl.getParameter (gl.samples);
363+ _stencilBits = gl.getParameter (gl.stencilBits);
364+ }
365+
355366 CkSurface _createNewSurface (ui.Size size) {
356367 assert (htmlCanvas != null );
357368 if (webGLVersion == - 1 ) {
@@ -369,6 +380,8 @@ class Surface {
369380 size.width.ceil (),
370381 size.height.ceil (),
371382 SkColorSpaceSRGB ,
383+ _sampleCount,
384+ _stencilBits
372385 );
373386
374387 if (skSurface == null ) {
Original file line number Diff line number Diff line change @@ -624,6 +624,27 @@ extension DomCanvasElementExtension on DomCanvasElement {
624624
625625 DomCanvasRenderingContext2D get context2D =>
626626 getContext ('2d' )! as DomCanvasRenderingContext2D ;
627+
628+ WebGLContext getGlContext (int majorVersion) {
629+ if (majorVersion == 1 ) {
630+ return getContext ('webgl' )! as WebGLContext ;
631+ }
632+ return getContext ('webgl2' )! as WebGLContext ;
633+ }
634+ }
635+
636+ @JS ()
637+ @staticInterop
638+ class WebGLContext {}
639+
640+ extension WebGLContextExtension on WebGLContext {
641+ external int getParameter (int value);
642+
643+ @JS ('SAMPLES' )
644+ external int get samples;
645+
646+ @JS ('STENCIL_BITS' )
647+ external int get stencilBits;
627648}
628649
629650@JS ()
Original file line number Diff line number Diff line change @@ -1778,4 +1778,33 @@ void _paragraphTests() {
17781778 canvasKit.TextHeightBehavior .DisableAll ,
17791779 );
17801780 });
1781+
1782+ test ('MakeOnScreenGLSurface test' , () {
1783+ final DomCanvasElement canvas = createDomCanvasElement (
1784+ width: 100 ,
1785+ height: 100 ,
1786+ );
1787+ final WebGLContext gl = canvas.getGlContext (webGLVersion);
1788+ final int sampleCount = gl.getParameter (gl.samples);
1789+ final int stencilBits = gl.getParameter (gl.stencilBits);
1790+
1791+ final int glContext = canvasKit.GetWebGLContext (
1792+ canvas,
1793+ SkWebGLContextOptions (
1794+ antialias: 0 ,
1795+ majorVersion: webGLVersion.toDouble (),
1796+ ),
1797+ ).toInt ();
1798+ final SkGrContext grContext = canvasKit.MakeGrContext (glContext);
1799+ final SkSurface ? skSurface = canvasKit.MakeOnScreenGLSurface (
1800+ grContext,
1801+ 100 ,
1802+ 100 ,
1803+ SkColorSpaceSRGB ,
1804+ sampleCount,
1805+ stencilBits
1806+ );
1807+
1808+ expect (skSurface, isNotNull);
1809+ }, skip: isFirefox); // Intended: Headless firefox has no webgl support https://github.com/flutter/flutter/issues/109265
17811810}
You can’t perform that action at this time.
0 commit comments