Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/system/lib/html5/offscreencanvas.c
6171 views
1
#include <assert.h>
2
3
#include "emscripten_internal.h"
4
5
typedef struct set_canvas_size_t {
6
const char* target;
7
int width;
8
int height;
9
} set_canvas_size_t;
10
11
static void do_set_size(void* arg) {
12
set_canvas_size_t* args = (set_canvas_size_t*)arg;
13
emscripten_set_canvas_element_size(args->target, args->width, args->height);
14
free((char *) args->target);
15
free(arg);
16
}
17
18
// This function takes ownership of the "target" string.
19
void _emscripten_set_offscreencanvas_size_on_thread(pthread_t t,
20
const char* target,
21
int width,
22
int height) {
23
set_canvas_size_t* arg = malloc(sizeof(set_canvas_size_t));
24
arg->target = target; // taking ownership: will be freed in do_set_size
25
arg->width = width;
26
arg->height = height;
27
28
em_proxying_queue* q = emscripten_proxy_get_system_queue();
29
30
// Note: If we are also a pthread, the call below could theoretically be
31
// done synchronously. However if the target pthread is waiting for a
32
// mutex from us, then these two threads will deadlock. At the moment,
33
// we'd like to consider that this kind of deadlock would be an Emscripten
34
// runtime bug, although if emscripten_set_canvas_element_size() was
35
// documented to require running an event in the queue of thread that owns
36
// the OffscreenCanvas, then that might be ok. (safer this way however)
37
if (!emscripten_proxy_async(q, t, do_set_size, arg)) {
38
assert(false && "emscripten_proxy_async failed");
39
}
40
}
41
42