Path: blob/main/system/lib/html5/offscreencanvas.c
6171 views
#include <assert.h>12#include "emscripten_internal.h"34typedef struct set_canvas_size_t {5const char* target;6int width;7int height;8} set_canvas_size_t;910static void do_set_size(void* arg) {11set_canvas_size_t* args = (set_canvas_size_t*)arg;12emscripten_set_canvas_element_size(args->target, args->width, args->height);13free((char *) args->target);14free(arg);15}1617// This function takes ownership of the "target" string.18void _emscripten_set_offscreencanvas_size_on_thread(pthread_t t,19const char* target,20int width,21int height) {22set_canvas_size_t* arg = malloc(sizeof(set_canvas_size_t));23arg->target = target; // taking ownership: will be freed in do_set_size24arg->width = width;25arg->height = height;2627em_proxying_queue* q = emscripten_proxy_get_system_queue();2829// Note: If we are also a pthread, the call below could theoretically be30// done synchronously. However if the target pthread is waiting for a31// mutex from us, then these two threads will deadlock. At the moment,32// we'd like to consider that this kind of deadlock would be an Emscripten33// runtime bug, although if emscripten_set_canvas_element_size() was34// documented to require running an event in the queue of thread that owns35// the OffscreenCanvas, then that might be ok. (safer this way however)36if (!emscripten_proxy_async(q, t, do_set_size, arg)) {37assert(false && "emscripten_proxy_async failed");38}39}404142