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
12 changes: 4 additions & 8 deletions src/library_html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ var LibraryHTML5 = {
},

#if OFFSCREENCANVAS_SUPPORT
$findCanvasEventTarget__deps: ['$GL', '$maybeCStringToJsString'],
$findCanvasEventTarget__deps: ['$GL', '$maybeCStringToJsString', "$findEventTarget"],
$findCanvasEventTarget: (target) => {
target = maybeCStringToJsString(target);

Expand All @@ -363,13 +363,9 @@ var LibraryHTML5 = {
return GL.offscreenCanvases[target.substr(1)] // Remove '#' prefix
// If not found, if one is querying by using DOM tag name selector 'canvas', grab the first
// OffscreenCanvas that we can find.
|| (target == 'canvas' && Object.keys(GL.offscreenCanvases)[0])
// If that is not found either, query via the regular DOM selector.
#if PTHREADS
|| (typeof document != 'undefined' && document.querySelector(target));
#else
|| document.querySelector(target);
#endif
|| (target == 'canvas' && Object.values(GL.offscreenCanvases)[0])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this also missing the .canvas similar to in #22958

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was worried it would, but in fact we want the whole offscreenCanvases entry because the caller might need the shared canvas pointer. All of the callers do a check for the presence of an .offscreenCanvas field.

// If that is not found either, query via the regular findEventTarget mechanism.
|| findEventTarget(target);
},
#else
$findCanvasEventTarget: '$findEventTarget',
Expand Down
32 changes: 32 additions & 0 deletions test/browser/html5_special_canvas_event_targets.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2024 The Emscripten Authors. All rights reserved.
// Emscripten is available under two separate licenses, the MIT license and the
// University of Illinois/NCSA Open Source License. Both these licenses can be
// found in the LICENSE file.

#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <assert.h>

#include <emscripten/emscripten.h>
#include <emscripten/html5.h>

int main() {
EM_ASM({
specialHTMLTargets["!foovas"] = Module.canvas;
});
int w=0, h=0;
EMSCRIPTEN_RESULT res = emscripten_get_canvas_element_size(TARGET, &w, &h);
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
EmscriptenWebGLContextAttributes attrs;
emscripten_webgl_init_context_attributes(&attrs);
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context(TARGET, &attrs);
assert(context > 0);
res = emscripten_webgl_make_context_current(context);
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
assert(emscripten_webgl_get_current_context() == context);
res = emscripten_get_canvas_element_size(TARGET, &w, &h);
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
res = emscripten_webgl_destroy_context(context);
assert(res == EMSCRIPTEN_RESULT_SUCCESS);
return 0;
}
13 changes: 13 additions & 0 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2627,6 +2627,19 @@ def test_html5_webgl_create_context_swapcontrol(self, args):
def test_html5_special_event_targets(self):
self.btest_exit('html5_special_event_targets.cpp', args=['-lGL'])

@parameterized({
'': ([],),
'offscreen_no_pthread': (['-sOFFSCREENCANVAS_SUPPORT'],),
'offscreen_pthread': (['-sOFFSCREENCANVAS_SUPPORT', '-sPROXY_TO_PTHREAD', '-pthread'],),
})
@requires_graphics_hardware
# Verify bug https://github.com/emscripten-core/emscripten/issues/22942: findCanvasEventTarget doesn't use specialHTMLTargets
def test_html5_special_canvas_event_targets(self, args):
self.emcc_args += ['-lGL', '-sDISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1']
self.btest_exit('html5_special_canvas_event_targets.c', args=args + ['-DTARGET="!foovas"'])
self.btest_exit('html5_special_canvas_event_targets.c', args=args + ['-DTARGET="#canvas"'])
self.btest_exit('html5_special_canvas_event_targets.c', args=args + ['-DTARGET="canvas"'])

@requires_graphics_hardware
def test_html5_webgl_destroy_context(self):
for opts in ([], ['-O2', '-g1'], ['-sFULL_ES2']):
Expand Down
Loading