Skip to content

Commit be5643d

Browse files
authored
Remove use of legacy proxy system from library_html5.js. NFC (#20031)
1 parent 0c21eb9 commit be5643d

File tree

8 files changed

+54
-32
lines changed

8 files changed

+54
-32
lines changed

src/generated_struct_info32.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@
231231
"EM_PROMISE_MATCH": 1,
232232
"EM_PROMISE_MATCH_RELEASE": 2,
233233
"EM_PROMISE_REJECT": 3,
234-
"EM_PROXIED_RESIZE_OFFSCREENCANVAS": 654311424,
235234
"EM_TIMING_RAF": 1,
236235
"EM_TIMING_SETIMMEDIATE": 2,
237236
"EM_TIMING_SETTIMEOUT": 0,

src/generated_struct_info64.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@
231231
"EM_PROMISE_MATCH": 1,
232232
"EM_PROMISE_MATCH_RELEASE": 2,
233233
"EM_PROMISE_REJECT": 3,
234-
"EM_PROXIED_RESIZE_OFFSCREENCANVAS": 654311424,
235234
"EM_TIMING_RAF": 1,
236235
"EM_TIMING_SETIMMEDIATE": 2,
237236
"EM_TIMING_SETTIMEOUT": 0,

src/library_html5.js

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2375,31 +2375,14 @@ var LibraryHTML5 = {
23752375
#if OFFSCREENCANVAS_SUPPORT
23762376
_emscripten_set_offscreencanvas_size: 'emscripten_set_canvas_element_size',
23772377

2378-
$setOffscreenCanvasSizeOnTargetThread__deps: ['$stringToNewUTF8', 'emscripten_dispatch_to_thread_', '$withStackSave'],
2378+
$setOffscreenCanvasSizeOnTargetThread__deps: ['$stringToNewUTF8', '_emscripten_set_offscreencanvas_size_on_thread', '$withStackSave'],
23792379
$setOffscreenCanvasSizeOnTargetThread: (targetThread, targetCanvas, width, height) => {
23802380
targetCanvas = targetCanvas ? UTF8ToString(targetCanvas) : '';
2381-
withStackSave(() => {
2382-
var varargs = stackAlloc(12);
2383-
var targetCanvasPtr = 0;
2384-
if (targetCanvas) {
2385-
targetCanvasPtr = stringToNewUTF8(targetCanvas);
2386-
}
2387-
{{{ makeSetValue('varargs', 0, 'targetCanvasPtr', 'i32')}}};
2388-
{{{ makeSetValue('varargs', 4, 'width', 'i32')}}};
2389-
{{{ makeSetValue('varargs', 8, 'height', 'i32')}}};
2390-
// Note: If we are also a pthread, the call below could theoretically be done synchronously. However if the target pthread is waiting for a mutex from us, then
2391-
// these two threads will deadlock. At the moment, we'd like to consider that this kind of deadlock would be an Emscripten runtime bug, although if
2392-
// emscripten_set_canvas_element_size() was documented to require running an event in the queue of thread that owns the OffscreenCanvas, then that might be ok.
2393-
// (safer this way however)
2394-
_emscripten_dispatch_to_thread_(targetThread, {{{ cDefs.EM_PROXIED_RESIZE_OFFSCREENCANVAS }}}, 0, targetCanvasPtr /* satellite data */, varargs);
2395-
});
2396-
},
2397-
#else
2398-
_emscripten_set_offscreencanvas_size: (target, width, height) => {
2399-
#if ASSERTIONS
2400-
err('emscripten_set_offscreencanvas_size: Build with -sOFFSCREENCANVAS_SUPPORT=1 to enable transferring canvases to pthreads.');
2401-
#endif
2402-
return {{{ cDefs.EMSCRIPTEN_RESULT_NOT_SUPPORTED }}};
2381+
var targetCanvasPtr = 0;
2382+
if (targetCanvas) {
2383+
targetCanvasPtr = stringToNewUTF8(targetCanvas);
2384+
}
2385+
__emscripten_set_offscreencanvas_size_on_thread(targetThread, targetCanvasPtr, width, height);
24032386
},
24042387
#endif
24052388

@@ -2509,6 +2492,15 @@ var LibraryHTML5 = {
25092492
},
25102493
#endif
25112494

2495+
#if !PTHREADS || !OFFSCREENCANVAS_SUPPORT
2496+
_emscripten_set_offscreencanvas_size: (target, width, height) => {
2497+
#if ASSERTIONS
2498+
err('emscripten_set_offscreencanvas_size: Build with -sOFFSCREENCANVAS_SUPPORT=1 to enable transferring canvases to pthreads.');
2499+
#endif
2500+
return {{{ cDefs.EMSCRIPTEN_RESULT_NOT_SUPPORTED }}};
2501+
},
2502+
#endif
2503+
25122504
// JavaScript-friendly API, returns pair [width, height]
25132505
$getCanvasElementSize__deps: ['emscripten_get_canvas_element_size', '$withStackSave', '$stringToUTF8OnStack'],
25142506
$getCanvasElementSize: (target) => withStackSave(() => {

src/struct_info.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,6 @@
950950
{
951951
"file": "emscripten/threading.h",
952952
"defines": [
953-
"EM_PROXIED_RESIZE_OFFSCREENCANVAS",
954953
"EM_FUNC_SIG_V",
955954
"EM_FUNC_SIG_VI",
956955
"EM_FUNC_SIG_VII",

system/include/emscripten/threading_legacy.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ typedef struct em_queued_call em_queued_call;
118118
#define EM_FUNC_SIG_SPECIAL_INTERNAL (1 << 24)
119119
#define EM_PROXIED_FUNC_SPECIAL(x) (EM_FUNC_SIG_SPECIAL_INTERNAL | ((x) << 20))
120120

121-
#define EM_PROXIED_RESIZE_OFFSCREENCANVAS (EM_PROXIED_FUNC_SPECIAL(0) | EM_FUNC_SIG_IIII)
122-
123121
// Runs the given function synchronously on the main Emscripten runtime thread.
124122
// If this thread is the main thread, the operation is immediately performed,
125123
// and the result is returned.

system/lib/html5/offscreencanvas.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <assert.h>
2+
3+
#include "emscripten_internal.h"
4+
5+
typedef struct set_cavas_size_t {
6+
const char* target;
7+
int width;
8+
int height;
9+
} set_cavas_size_t;
10+
11+
static void do_set_size(void* arg) {
12+
set_cavas_size_t* args = (set_cavas_size_t*)arg;
13+
_emscripten_set_offscreencanvas_size(args->target, args->width, args->height);
14+
free(arg);
15+
}
16+
17+
void _emscripten_set_offscreencanvas_size_on_thread(pthread_t t,
18+
const char* target,
19+
int width,
20+
int height) {
21+
set_cavas_size_t* arg = malloc(sizeof(set_cavas_size_t));
22+
arg->target = target;
23+
arg->width = width;
24+
arg->height = height;
25+
26+
em_proxying_queue* q = emscripten_proxy_get_system_queue();
27+
28+
// Note: If we are also a pthread, the call below could theoretically be
29+
// done synchronously. However if the target pthread is waiting for a
30+
// mutex from us, then these two threads will deadlock. At the moment,
31+
// we'd like to consider that this kind of deadlock would be an Emscripten
32+
// runtime bug, although if emscripten_set_canvas_element_size() was
33+
// documented to require running an event in the queue of thread that owns
34+
// the OffscreenCanvas, then that might be ok. (safer this way however)
35+
if (!emscripten_proxy_async(q, t, do_set_size, arg)) {
36+
assert(false && "emscripten_proxy_async failed");
37+
}
38+
}

system/lib/pthread/proxying_legacy.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,6 @@ static void _do_call(void* arg) {
149149
// C function pointer
150150
assert(EM_FUNC_SIG_NUM_FUNC_ARGUMENTS(q->functionEnum) <= EM_QUEUED_CALL_MAX_ARGS);
151151
switch (q->functionEnum) {
152-
case EM_PROXIED_RESIZE_OFFSCREENCANVAS:
153-
q->returnValue.i =
154-
_emscripten_set_offscreencanvas_size(q->args[0].cp, q->args[1].i, q->args[2].i);
155-
break;
156152
case EM_FUNC_SIG_V:
157153
((em_func_v)q->functionPtr)();
158154
break;

tools/system_libs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,6 +1910,7 @@ def can_use(self):
19101910
class libhtml5(Library):
19111911
name = 'libhtml5'
19121912

1913+
includes = ['system/lib/libc']
19131914
cflags = ['-Oz', '-fno-inline-functions']
19141915
src_dir = 'system/lib/html5'
19151916
src_glob = '*.c'

0 commit comments

Comments
 (0)