Skip to content

Commit 01e0fcb

Browse files
fix(uno): Ensure that the canvas' context is active when rendering (#2559) (#2560)
(cherry picked from commit d5bcfdf) Co-authored-by: Jérôme Laban <jerome.laban@nventive.com>
1 parent 39c88ed commit 01e0fcb

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

source/SkiaSharp.Views.Uno/SkiaSharp.Views.Uno.WinUI.Wasm/WasmScripts/SkiaSharp.Views.Uno.Wasm.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@
106106
this.currentRequest = window.requestAnimationFrame(() => {
107107

108108
if (this.requestRender) {
109+
// make current for this canvas instance
110+
GL.makeContextCurrent(this.glCtx);
111+
109112
this.requestRender();
110113
}
111114

@@ -178,12 +181,12 @@
178181
throw `No <canvas> with id ${canvasOrCanvasId} was found`;
179182
}
180183

181-
var ctx = SKSwapChainPanel.createWebGLContext(canvas);
182-
if (!ctx || ctx < 0)
184+
this.glCtx = SKSwapChainPanel.createWebGLContext(canvas);
185+
if (!this.glCtx || this.glCtx < 0)
183186
throw `Failed to create WebGL context: err ${ctx}`;
184187

185188
// make current
186-
GL.makeContextCurrent(ctx);
189+
GL.makeContextCurrent(this.glCtx);
187190

188191
// Starting from .NET 7 the GLctx is defined in an inaccessible scope
189192
// when the current GL context changes. We need to pick it up from the
@@ -196,7 +199,7 @@
196199
// read values
197200
this.canvas = canvas;
198201
return {
199-
ctx: ctx,
202+
ctx: this.glCtx,
200203
fbo: currentGLctx.getParameter(currentGLctx.FRAMEBUFFER_BINDING),
201204
stencil: currentGLctx.getParameter(currentGLctx.STENCIL_BITS),
202205
sample: 0, // TODO: currentGLctx.getParameter(GLctx.SAMPLES)

0 commit comments

Comments
 (0)