Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/lib/libhtml5.js
Original file line number Diff line number Diff line change
Expand Up @@ -2104,21 +2104,24 @@ var LibraryHTML5 = {
}
return setCanvasElementSizeMainThread(target, width, height);
},
#else
#else // PTHREADS
emscripten_set_canvas_element_size: (target, width, height) => {
#if GL_DEBUG
dbg(`emscripten_set_canvas_element_size(target=${target},width=${width},height=${height}`);
#endif
var canvas = findCanvasEventTarget(target);
if (!canvas) return {{{ cDefs.EMSCRIPTEN_RESULT_UNKNOWN_TARGET }}};
#if OFFSCREENCANVAS_SUPPORT
if (canvas.offscreenCanvas) canvas = canvas.offscreenCanvas;
#endif
canvas.width = width;
canvas.height = height;
#if OFFSCREEN_FRAMEBUFFER
if (canvas.GLctxObject) GL.resizeOffscreenFramebuffer(canvas.GLctxObject);
#endif
return {{{ cDefs.EMSCRIPTEN_RESULT_SUCCESS }}};
},
#endif
#endif // !PTHREADS

$setCanvasElementSize: (target, width, height) => {
#if GL_DEBUG
Expand Down Expand Up @@ -2178,14 +2181,18 @@ var LibraryHTML5 = {
}
return getCanvasSizeMainThread(target, width, height);
},
#else
#else // PTHREADS
emscripten_get_canvas_element_size: (target, width, height) => {
var canvas = findCanvasEventTarget(target);
if (!canvas) return {{{ cDefs.EMSCRIPTEN_RESULT_UNKNOWN_TARGET }}};
#if OFFSCREENCANVAS_SUPPORT
if (canvas.offscreenCanvas) canvas = canvas.offscreenCanvas;
#endif
{{{ makeSetValue('width', '0', 'canvas.width', 'i32') }}};
{{{ makeSetValue('height', '0', 'canvas.height', 'i32') }}};
return {{{ cDefs.EMSCRIPTEN_RESULT_SUCCESS }}};
},
#endif
#endif // !PTHREADS

// JavaScript-friendly API, returns pair [width, height]
$getCanvasElementSize: (target) => {
Expand Down
12 changes: 2 additions & 10 deletions src/lib/libhtml5_webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ var LibraryHtml5WebGL = {
});`,
#endif

#if OFFSCREENCANVAS_SUPPORT
_emscripten_webgl_do_create_context__deps: ['malloc'],
#endif
// This function performs proxying manually, depending on the style of context that is to be created.
_emscripten_webgl_do_create_context: (target, attributes) => {
#if ASSERTIONS
Expand Down Expand Up @@ -104,10 +101,6 @@ var LibraryHtml5WebGL = {
#endif

var canvas = findCanvasEventTarget(target);
#if OFFSCREENCANVAS_SUPPORT
// If our canvas from findCanvasEventTarget is actually an offscreen canvas record, we should extract the inner canvas.
if (canvas?.canvas) { canvas = canvas.canvas; }

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done (correctly) down on line 146 below

#endif
#if GL_DEBUG
var targetStr = UTF8ToString(target);
#endif
Expand Down Expand Up @@ -175,8 +168,7 @@ var LibraryHtml5WebGL = {
#endif
if (!canvas.controlTransferredOffscreen) {
GL.offscreenCanvases[canvas.id] = {
canvas: canvas.transferControlToOffscreen(),
canvasSharedPtr: _malloc(12),
offscreenCanvas: canvas.transferControlToOffscreen(),
id: canvas.id
};
Comment thread
sbc100 marked this conversation as resolved.
Resolved
canvas.controlTransferredOffscreen = true;
Expand All @@ -186,7 +178,7 @@ var LibraryHtml5WebGL = {
#endif
return 0;
}
canvas = GL.offscreenCanvases[canvas.id].canvas;
canvas = GL.offscreenCanvases[canvas.id].offscreenCanvas;
}
}
#else // !OFFSCREENCANVAS_SUPPORT
Expand Down
18 changes: 18 additions & 0 deletions test/browser/webgl_create_context_swapcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ int main() {
EMSCRIPTEN_RESULT res = emscripten_webgl_make_context_current(context);
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
assert(emscripten_webgl_get_current_context() == context);

int w, h;
res = emscripten_get_canvas_element_size("#canvas", &w, &h);
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
assert(w == 300);
assert(h == 150);

res = emscripten_set_canvas_element_size("#canvas", 400, 200);
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
res = emscripten_get_canvas_element_size("#canvas", &w, &h);
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
assert(w == 400);
assert(h == 200);
res = emscripten_webgl_get_drawing_buffer_size(context, &w, &h);
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
assert(w == 400);
assert(h == 200);

emscripten_webgl_destroy_context(context);
assert(emscripten_webgl_get_current_context() == 0);
// Test that creating a context for a canvas that's already been used once succeeds
Expand Down
4 changes: 2 additions & 2 deletions test/codesize/test_codesize_hello_dylink_all.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"a.out.js": 272917,
"a.out.js": 272926,
"a.out.nodebug.wasm": 589443,
"total": 862360,
"total": 862369,
"sent": [
"IMG_Init",
"IMG_Load",
Expand Down
Loading