Skip to content
Merged
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
7 changes: 7 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ full changeset diff at the end of each section.
Current Trunk
-------------
- Remove deprecated Pointer_stringify (use UTF8ToString instead). See #8011
- Added a new option -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1 that
changes the lookup semantics of DOM elements in html5.h event handler
callback and WebGL context creation. New behavior is to use CSS selector
strings to look up DOM elements over the old behavior, which was somewhat
ad hoc constructed rules around default Emscripten uses. The old behavior
will be deprecated and removed in the future. Build with -s ASSERTIONS=1
to get diagnostics messages related to this transition.

v1.38.26: 02/04/2019
--------------------
Expand Down
430 changes: 254 additions & 176 deletions src/library_html5.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1419,3 +1419,7 @@ var TARGET_BASENAME = '';
// this to 0 to save a little bit of code size and performance when catching exceptions.
var SUPPORT_LONGJMP = 1;

// If set to 1, disables old deprecated HTML5 API event target lookup behavior. When enabled,
// there is no "Module.canvas" object, no magic "null" default handling, and DOM element
// 'target' parameters are taken to refer to CSS selectors, instead of referring to DOM IDs.
var DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR = 0;
6 changes: 6 additions & 0 deletions src/struct_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,12 @@
"EMSCRIPTEN_RESULT_NOT_SUPPORTED",
"EMSCRIPTEN_RESULT_FAILED",
"EMSCRIPTEN_RESULT_NO_DATA",
"EMSCRIPTEN_RESULT_TIMED_OUT",

"EMSCRIPTEN_EVENT_TARGET_INVALID",
"EMSCRIPTEN_EVENT_TARGET_DOCUMENT",
"EMSCRIPTEN_EVENT_TARGET_WINDOW",
"EMSCRIPTEN_EVENT_TARGET_SCREEN",

"EMSCRIPTEN_FULLSCREEN_SCALE_DEFAULT",
"EMSCRIPTEN_FULLSCREEN_SCALE_STRETCH",
Expand Down
7 changes: 7 additions & 0 deletions system/include/emscripten/html5.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ extern "C" {
#define EMSCRIPTEN_RESULT_NO_DATA -7
#define EMSCRIPTEN_RESULT_TIMED_OUT -8

#define EMSCRIPTEN_EVENT_TARGET_INVALID 0
#define EMSCRIPTEN_EVENT_TARGET_DOCUMENT ((const char*)1)
#define EMSCRIPTEN_EVENT_TARGET_WINDOW ((const char*)2)
#define EMSCRIPTEN_EVENT_TARGET_SCREEN ((const char*)3)

#define EM_BOOL int
#define EM_TRUE 1
#define EM_FALSE 0
Expand Down Expand Up @@ -141,6 +146,7 @@ typedef struct EmscriptenMouseEvent {
long movementY;
long targetX;
long targetY;
// canvasX and canvasY are deprecated - there no longer exists a Module['canvas'] object, so canvasX/Y are no longer reported (register a listener on canvas directly to get canvas coordinates, or translate manually)
long canvasX;
long canvasY;
long padding;
Expand Down Expand Up @@ -356,6 +362,7 @@ typedef struct EmscriptenTouchPoint
EM_BOOL onTarget;
long targetX;
long targetY;
// canvasX and canvasY are deprecated - there no longer exists a Module['canvas'] object, so canvasX/Y are no longer reported (register a listener on canvas directly to get canvas coordinates, or translate manually)
long canvasX;
long canvasY;
} EmscriptenTouchPoint;
Expand Down
2 changes: 1 addition & 1 deletion tests/canvas_animate_resize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ int main()
#if TEST_EXPLICIT_CONTEXT_SWAP
attr.explicitSwapControl = EM_TRUE;
#endif
ctx = emscripten_webgl_create_context(0, &attr);
ctx = emscripten_webgl_create_context("#canvas", &attr);
printf("Created context with handle %u\n", (unsigned int)ctx);
if (!ctx)
{
Expand Down
4 changes: 2 additions & 2 deletions tests/gl_in_mainthread_after_pthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void *ThreadMain(void *arg)
EmscriptenWebGLContextAttributes attr;
emscripten_webgl_init_context_attributes(&attr);
attr.explicitSwapControl = EM_TRUE;
ctx = emscripten_webgl_create_context(0, &attr);
ctx = emscripten_webgl_create_context("#canvas", &attr);
emscripten_webgl_make_context_current(ctx);

double color = 0;
Expand Down Expand Up @@ -103,7 +103,7 @@ void PollThreadExit(void *)
#ifdef TEST_MAIN_THREAD_EXPLICIT_COMMIT
attr.explicitSwapControl = EM_TRUE;
#endif
ctx = emscripten_webgl_create_context(0, &attr);
ctx = emscripten_webgl_create_context("#canvas", &attr);
emscripten_webgl_make_context_current(ctx);
printf("Main thread rendering. You should see the WebGL canvas fade from black to green.\n");
emscripten_set_main_loop(MainThreadRender, 0, 0);
Expand Down
2 changes: 1 addition & 1 deletion tests/gl_in_proxy_pthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int main()
EmscriptenWebGLContextAttributes attr;
emscripten_webgl_init_context_attributes(&attr);
attr.explicitSwapControl = EM_TRUE;
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context(0, &attr);
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context("#canvas", &attr);
printf("Created context with handle %u\n", (unsigned int)ctx);
emscripten_webgl_make_context_current(ctx);

Expand Down
2 changes: 1 addition & 1 deletion tests/gl_in_pthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void *ThreadMain(void *arg)
EmscriptenWebGLContextAttributes attr;
emscripten_webgl_init_context_attributes(&attr);
attr.explicitSwapControl = EM_TRUE;
ctx = emscripten_webgl_create_context(0, &attr);
ctx = emscripten_webgl_create_context("#canvas", &attr);
emscripten_webgl_make_context_current(ctx);

double color = 0;
Expand Down
2 changes: 1 addition & 1 deletion tests/gl_in_two_pthreads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ int main()
EmscriptenWebGLContextAttributes attr;
emscripten_webgl_init_context_attributes(&attr);
attr.explicitSwapControl = EM_TRUE;
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context(0, &attr);
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context("#canvas", &attr);
assert(ctx);

// Activate it
Expand Down
2 changes: 1 addition & 1 deletion tests/gl_only_in_pthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void *ThreadMain(void *arg)
EmscriptenWebGLContextAttributes attr;
emscripten_webgl_init_context_attributes(&attr);
attr.explicitSwapControl = EM_TRUE;
ctx = emscripten_webgl_create_context(0, &attr);
ctx = emscripten_webgl_create_context("#canvas", &attr);
emscripten_webgl_make_context_current(ctx);

double color = 0;
Expand Down
2 changes: 1 addition & 1 deletion tests/gl_textures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ int main()
attr.premultipliedAlpha = 0;
attr.majorVersion = 1;
attr.minorVersion = 0;
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context(0, &attr);
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context("#canvas", &attr);
emscripten_webgl_make_context_current(ctx);
GLuint vs = glCreateShader(GL_VERTEX_SHADER);
const char *vss = "attribute vec4 vPosition; uniform mat4 mat; varying vec2 texCoord; void main() { gl_Position = vPosition; texCoord = (vPosition.xy + vec2(1.0)) * vec2(0.5); }";
Expand Down
2 changes: 1 addition & 1 deletion tests/html5_callbacks_on_calling_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void *threadMain(void *arg)
{
registeringThreadId = pthread_self();

EMSCRIPTEN_RESULT ret = emscripten_set_mousemove_callback(0, (void*)0x42, 1, mouse_callback);
EMSCRIPTEN_RESULT ret = emscripten_set_mousemove_callback(EMSCRIPTEN_EVENT_TARGET_WINDOW, (void*)0x42, 1, mouse_callback);
assert(ret == EMSCRIPTEN_RESULT_SUCCESS);

printf("Please move the mouse cursor.\n");
Expand Down
2 changes: 1 addition & 1 deletion tests/preinitialized_webgl_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ int main()
{
EmscriptenWebGLContextAttributes attrs;
emscripten_webgl_init_context_attributes(&attrs);
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context(0, &attrs);
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context("#canvas", &attrs);
assert(context);
EMSCRIPTEN_RESULT res = emscripten_webgl_make_context_current(context);
assert(res >= 0);
Expand Down
2 changes: 1 addition & 1 deletion tests/resize_offscreencanvas_from_main_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void *thread_main(void *arg)
EmscriptenWebGLContextAttributes attr;
emscripten_webgl_init_context_attributes(&attr);
attr.explicitSwapControl = EM_TRUE;
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context(0, &attr);
EMSCRIPTEN_WEBGL_CONTEXT_HANDLE ctx = emscripten_webgl_create_context("#canvas", &attr);
assert(ctx);

// To start off, change the size of the OffscreenCanvas, main thread will test that it sees this change.
Expand Down
20 changes: 9 additions & 11 deletions tests/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2512,13 +2512,13 @@ def test_doublestart_bug(self):
def test_html5(self):
for opts in [[], ['-O2', '-g1', '--closure', '1'], ['-s', 'USE_PTHREADS=1', '-s', 'PROXY_TO_PTHREAD=1']]:
print(opts)
self.btest(path_from_root('tests', 'test_html5.c'), args=opts, expected='0', timeout=20)
self.btest(path_from_root('tests', 'test_html5.c'), args=['-s', 'DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1'] + opts, expected='0', timeout=20)

@requires_threads
def test_html5_gamepad(self):
for opts in [[], ['-O2', '-g1', '--closure', '1'], ['-s', 'USE_PTHREADS=1', '-s', 'PROXY_TO_PTHREAD=1']]:
print(opts)
self.btest(path_from_root('tests', 'test_gamepad.c'), args=opts, expected='0', timeout=20)
self.btest(path_from_root('tests', 'test_gamepad.c'), args=['-s', 'DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1'] + opts, expected='0', timeout=20)

@requires_graphics_hardware
def test_html5_webgl_create_context_no_antialias(self):
Expand All @@ -2543,7 +2543,7 @@ def test_html5_webgl_create_context2(self):
def test_html5_webgl_destroy_context(self):
for opts in [[], ['-O2', '-g1'], ['-s', 'FULL_ES2=1']]:
print(opts)
self.btest(path_from_root('tests', 'webgl_destroy_context.cpp'), args=opts + ['--shell-file', path_from_root('tests/webgl_destroy_context_shell.html'), '-lGL'], expected='0', timeout=20)
self.btest(path_from_root('tests', 'webgl_destroy_context.cpp'), args=opts + ['-s', 'DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1', '--shell-file', path_from_root('tests/webgl_destroy_context_shell.html'), '-lGL'], expected='0', timeout=20)

@no_chrome('see #7373')
@requires_graphics_hardware
Expand Down Expand Up @@ -2599,7 +2599,7 @@ def test_sdl_touch(self):
def test_html5_mouse(self):
for opts in [[], ['-O2', '-g1', '--closure', '1']]:
print(opts)
self.btest(path_from_root('tests', 'test_html5_mouse.c'), args=opts + ['-DAUTOMATE_SUCCESS=1'], expected='0')
self.btest(path_from_root('tests', 'test_html5_mouse.c'), args=opts + ['-s', 'DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1', '-DAUTOMATE_SUCCESS=1'], expected='0')

def test_sdl_mousewheel(self):
for opts in [[], ['-O2', '-g1', '--closure', '1']]:
Expand Down Expand Up @@ -4017,20 +4017,20 @@ def test_TextDecoder(self):
@requires_threads
def test_webgl_offscreen_canvas_in_pthread(self):
for args in [[], ['-DTEST_CHAINED_WEBGL_CONTEXT_PASSING']]:
self.btest('gl_in_pthread.cpp', expected='1', args=args + ['-s', 'USE_PTHREADS=1', '-s', 'PTHREAD_POOL_SIZE=2', '-s', 'OFFSCREENCANVAS_SUPPORT=1', '-lGL'])
self.btest('gl_in_pthread.cpp', expected='1', args=args + ['-s', 'USE_PTHREADS=1', '-s', 'PTHREAD_POOL_SIZE=2', '-s', 'OFFSCREENCANVAS_SUPPORT=1', '-lGL', '-s', 'DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1'])

# Tests that it is possible to render WebGL content on a <canvas> on the main thread, after it has once been used to render WebGL content in a pthread first
# -DTEST_MAIN_THREAD_EXPLICIT_COMMIT: Test the same (WebGL on main thread after pthread), but by using explicit .commit() to swap on the main thread instead of implicit "swap when rAF ends" logic
@no_chrome('see #7374')
@requires_threads
def test_webgl_offscreen_canvas_in_mainthread_after_pthread(self):
for args in [[], ['-DTEST_MAIN_THREAD_EXPLICIT_COMMIT']]:
self.btest('gl_in_mainthread_after_pthread.cpp', expected='0', args=args + ['-s', 'USE_PTHREADS=1', '-s', 'PTHREAD_POOL_SIZE=2', '-s', 'OFFSCREENCANVAS_SUPPORT=1', '-lGL'])
self.btest('gl_in_mainthread_after_pthread.cpp', expected='0', args=args + ['-s', 'USE_PTHREADS=1', '-s', 'PTHREAD_POOL_SIZE=2', '-s', 'OFFSCREENCANVAS_SUPPORT=1', '-lGL', '-s', 'DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1'])

@no_chrome('see #7374')
@requires_threads
def test_webgl_offscreen_canvas_only_in_pthread(self):
self.btest('gl_only_in_pthread.cpp', expected='0', args=['-s', 'USE_PTHREADS=1', '-s', 'PTHREAD_POOL_SIZE=1', '-s', 'OFFSCREENCANVAS_SUPPORT=1', '-lGL'])
self.btest('gl_only_in_pthread.cpp', expected='0', args=['-s', 'USE_PTHREADS=1', '-s', 'PTHREAD_POOL_SIZE=1', '-s', 'OFFSCREENCANVAS_SUPPORT=1', '-lGL', '-s', 'DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1'])

# Tests that rendering from client side memory without default-enabling extensions works.
@requires_graphics_hardware
Expand Down Expand Up @@ -4064,12 +4064,10 @@ def test_webgl_workaround_webgl_uniform_upload_bug(self):
# Tests that if a WebGL context is created in a pthread on a canvas that has not been transferred to that pthread, WebGL calls are then proxied to the main thread
# -DTEST_OFFSCREEN_CANVAS=1: Tests that if a WebGL context is created on a pthread that has the canvas transferred to it via using Emscripten's EMSCRIPTEN_PTHREAD_TRANSFERRED_CANVASES="#canvas", then OffscreenCanvas is used
# -DTEST_OFFSCREEN_CANVAS=2: Tests that if a WebGL context is created on a pthread that has the canvas transferred to it via automatic transferring of Module.canvas when EMSCRIPTEN_PTHREAD_TRANSFERRED_CANVASES is not defined, then OffscreenCanvas is also used
@requires_threads
@requires_graphics_hardware
@no_chrome('see #7374')
def test_webgl_offscreen_canvas_in_proxied_pthread(self):
for args in [[], ['-DTEST_OFFSCREEN_CANVAS=1'], ['-DTEST_OFFSCREEN_CANVAS=2']]:
cmd = args + ['-s', 'USE_PTHREADS=1', '-s', 'OFFSCREENCANVAS_SUPPORT=1', '-lGL', '-s', 'GL_DEBUG=1', '-s', 'PROXY_TO_PTHREAD=1']
cmd = args + ['-s', 'USE_PTHREADS=1', '-s', 'OFFSCREENCANVAS_SUPPORT=1', '-lGL', '-s', 'GL_DEBUG=1', '-s', 'PROXY_TO_PTHREAD=1', '-s', 'DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1']
print(str(cmd))
self.btest('gl_in_proxy_pthread.cpp', expected='1', args=cmd)

Expand All @@ -4079,7 +4077,7 @@ def test_webgl_offscreen_canvas_in_proxied_pthread(self):
def test_webgl_resize_offscreencanvas_from_main_thread(self):
for args1 in [[], ['-s', 'PROXY_TO_PTHREAD=1']]:
for args2 in [[], ['-DTEST_SYNC_BLOCKING_LOOP=1']]:
cmd = args1 + args2 + ['-s', 'USE_PTHREADS=1', '-s', 'OFFSCREENCANVAS_SUPPORT=1', '-lGL', '-s', 'GL_DEBUG=1']
cmd = args1 + args2 + ['-s', 'USE_PTHREADS=1', '-s', 'OFFSCREENCANVAS_SUPPORT=1', '-lGL', '-s', 'GL_DEBUG=1', '-s', 'DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1']
print(str(cmd))
self.btest('resize_offscreencanvas_from_main_thread.cpp', expected='1', args=cmd)

Expand Down
Loading