Skip to content

Commit b64f144

Browse files
authored
Make use of emscripten_supports_offscreencanvas. NFC (#21204)
1 parent f7651be commit b64f144

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/library_html5_webgl.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ var LibraryHtml5WebGL = {
4545
emscripten_webgl_do_create_context__deps: [
4646
#if OFFSCREENCANVAS_SUPPORT
4747
'malloc',
48+
'emscripten_supports_offscreencanvas',
4849
#endif
4950
#if PTHREADS && OFFSCREEN_FRAMEBUFFER
5051
'emscripten_webgl_create_context_proxied',
@@ -95,7 +96,7 @@ var LibraryHtml5WebGL = {
9596
dbg('Performance warning: forcing renderViaOffscreenBackBuffer=true and preserveDrawingBuffer=true since proxying WebGL rendering.');
9697
#endif
9798
// We will be proxying - if OffscreenCanvas is supported, we can proxy a bit more efficiently by avoiding having to create an Offscreen FBO.
98-
if (typeof OffscreenCanvas == 'undefined') {
99+
if (!_emscripten_supports_offscreencanvas()) {
99100
{{{ makeSetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.renderViaOffscreenBackBuffer, '1', 'i32') }}};
100101
{{{ makeSetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.preserveDrawingBuffer, '1', 'i32') }}};
101102
}
@@ -115,12 +116,12 @@ var LibraryHtml5WebGL = {
115116
if (canvas.offscreenCanvas) canvas = canvas.offscreenCanvas;
116117

117118
#if GL_DEBUG
118-
if (typeof OffscreenCanvas != 'undefined' && canvas instanceof OffscreenCanvas) dbg(`emscripten_webgl_create_context: Creating an OffscreenCanvas-based WebGL context on target "${targetStr}"`);
119+
if (_emscripten_supports_offscreencanvas() && canvas instanceof OffscreenCanvas) dbg(`emscripten_webgl_create_context: Creating an OffscreenCanvas-based WebGL context on target "${targetStr}"`);
119120
else if (typeof HTMLCanvasElement != 'undefined' && canvas instanceof HTMLCanvasElement) dbg(`emscripten_webgl_create_context: Creating an HTMLCanvasElement-based WebGL context on target "${targetStr}"`);
120121
#endif
121122

122123
if (contextAttributes.explicitSwapControl) {
123-
var supportsOffscreenCanvas = canvas.transferControlToOffscreen || (typeof OffscreenCanvas != 'undefined' && canvas instanceof OffscreenCanvas);
124+
var supportsOffscreenCanvas = canvas.transferControlToOffscreen || (_emscripten_supports_offscreencanvas() && canvas instanceof OffscreenCanvas);
124125

125126
if (!supportsOffscreenCanvas) {
126127
#if OFFSCREEN_FRAMEBUFFER

test/canvas_animate_resize.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,14 @@ int main()
126126
printf("Created context with handle %u\n", (unsigned int)ctx);
127127
if (!ctx)
128128
{
129-
EM_ASM({
130-
if (typeof OffscreenCanvas === 'undefined') {
129+
if (!emscripten_supports_offscreencanvas()) {
130+
EM_ASM({
131131
xhr = new XMLHttpRequest();
132132
xhr.open('GET', 'http://localhost:8888/report_result?skipped:%20OffscreenCanvas%20is%20not%20supported!');
133133
xhr.send();
134134
setTimeout(function() { window.close() }, 2000);
135-
}
136-
});
135+
});
136+
}
137137
return 0;
138138
}
139139
emscripten_webgl_make_context_current(ctx);

0 commit comments

Comments
 (0)