File: offscreencanvas.c

package info (click to toggle)
emscripten 3.1.69%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 121,860 kB
  • sloc: ansic: 636,110; cpp: 425,974; javascript: 78,401; python: 58,404; sh: 49,154; pascal: 5,237; makefile: 3,366; asm: 2,415; lisp: 1,869
file content (38 lines) | stat: -rw-r--r-- 1,441 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <assert.h>

#include "emscripten_internal.h"

typedef struct set_cavas_size_t {
  const char* target;
  int width;
  int height;
} set_cavas_size_t;

static void do_set_size(void* arg) {
  set_cavas_size_t* args = (set_cavas_size_t*)arg;
  _emscripten_set_offscreencanvas_size(args->target, args->width, args->height);
  free(arg);
}

void _emscripten_set_offscreencanvas_size_on_thread(pthread_t t,
                                                    const char* target,
                                                    int width,
                                                    int height) {
  set_cavas_size_t* arg = malloc(sizeof(set_cavas_size_t));
  arg->target = target;
  arg->width = width;
  arg->height = height;

  em_proxying_queue* q = emscripten_proxy_get_system_queue();

  // 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 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 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.  (safer this way however)
  if (!emscripten_proxy_async(q, t, do_set_size, arg)) {
    assert(false && "emscripten_proxy_async failed");
  }
}