int main(int argc, char **argv) { // For testing purposes, rename the canvas on the page to some arbitrary ID. EM_ASM(document.getElementById('canvas').id = 'myCanvasId'); // Accessing #canvas should resize Module['canvas'] EMSCRIPTEN_RESULT r = emscripten_set_canvas_element_size("#canvas", 100, 200); assert(r == EMSCRIPTEN_RESULT_SUCCESS); int w, h; r = emscripten_get_canvas_element_size("#canvas", &w, &h); assert(r == EMSCRIPTEN_RESULT_SUCCESS); assert(w == 100); assert(h == 200); w = h = 0; // Check that we see the change via 'NULL' r = emscripten_get_canvas_element_size(NULL, &w, &h); assert(r == EMSCRIPTEN_RESULT_SUCCESS); assert(w == 100); assert(h == 200); w = h = 0; // Check that we see the change via 'mycanvasId' r = emscripten_get_canvas_element_size("myCanvasId", &w, &h); assert(r == EMSCRIPTEN_RESULT_SUCCESS); assert(w == 100); assert(h == 200); // The following line will not work with OffscreenCanvas, that is covered in another test int jsAgreesWithSize = EM_ASM_INT({return Module['canvas'].width == 100 && Module['canvas'].height == 200});
static void gfx_ctx_emscripten_check_window(void *data, bool *quit, bool *resize, unsigned *width, unsigned *height, bool is_shutdown) { EMSCRIPTEN_RESULT r; int input_width; int input_height; emscripten_ctx_data_t *emscripten = (emscripten_ctx_data_t*)data; gfx_ctx_emscripten_get_canvas_size(&input_width, &input_height); if (input_width == 0 || input_height == 0) { input_width = emscripten_initial_width; input_height = emscripten_initial_height; emscripten->fb_width = emscripten->fb_height = 0; } *width = (unsigned)input_width; *height = (unsigned)input_height; *resize = false; if (input_width != emscripten->fb_width || input_height != emscripten->fb_height) { r = emscripten_set_canvas_element_size("#canvas", input_width, input_height); if (r != EMSCRIPTEN_RESULT_SUCCESS) RARCH_ERR("[EMSCRIPTEN/EGL]: error resizing canvas: %d\n", r); /* fix Module.requestFullscreen messing with the canvas size */ r = emscripten_set_element_css_size("#canvas", (double)input_width, (double)input_height); if (r != EMSCRIPTEN_RESULT_SUCCESS) RARCH_ERR("[EMSCRIPTEN/EGL]: error resizing canvas css: %d\n", r); *resize = true; } emscripten->fb_width = (unsigned)input_width; emscripten->fb_height = (unsigned)input_height; *quit = false; }
assert(w == 100); assert(h == 200); w = h = 0; // Check that we see the change via 'mycanvasId' r = emscripten_get_canvas_element_size("myCanvasId", &w, &h); assert(r == EMSCRIPTEN_RESULT_SUCCESS); assert(w == 100); assert(h == 200); // The following line will not work with OffscreenCanvas, that is covered in another test int jsAgreesWithSize = EM_ASM_INT({return Module['canvas'].width == 100 && Module['canvas'].height == 200}); assert(jsAgreesWithSize); // Accessing NULL should also resize Module['canvas'] r = emscripten_set_canvas_element_size(NULL, 101, 201); assert(r == EMSCRIPTEN_RESULT_SUCCESS); // Check that we see the change on the canvas (via the established #canvas) r = emscripten_get_canvas_element_size("#canvas", &w, &h); assert(r == EMSCRIPTEN_RESULT_SUCCESS); assert(w == 101); assert(h == 201); w = h = 0; // Check that we see the change via 'NULL' r = emscripten_get_canvas_element_size(NULL, &w, &h); assert(r == EMSCRIPTEN_RESULT_SUCCESS); assert(w == 101); assert(h == 201); w = h = 0;