Skip to content

Commit 053198d

Browse files
authored
Remove uses of deprecated functions emscripten_get_canvas_size() and emscripten_set_canvas_size() (#7998)
1 parent 6b30209 commit 053198d

18 files changed

+56
-52
lines changed

site/source/api_items.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ def get_mapped_items():
116116
mapped_wiki_inline_code['emscripten_set_beforeunload_callback']=':c:func:`emscripten_set_beforeunload_callback`'
117117
mapped_wiki_inline_code['emscripten_random()']=':c:func:`emscripten_random`'
118118
mapped_wiki_inline_code['EMSCRIPTEN_RESULT']=':c:macro:`EMSCRIPTEN_RESULT`'
119-
mapped_wiki_inline_code['emscripten_get_canvas_size']=':c:func:`emscripten_get_canvas_size`'
120119
mapped_wiki_inline_code['emscripten_async_run_script']=':c:func:`emscripten_async_run_script`'
121120
mapped_wiki_inline_code['emscripten_worker_respond()']=':c:func:`emscripten_worker_respond`'
122121
mapped_wiki_inline_code['DOM_DELTA_PIXEL']=':c:macro:`DOM_DELTA_PIXEL`'
@@ -264,11 +263,8 @@ def get_mapped_items():
264263
mapped_wiki_inline_code['EMSCRIPTEN_NETWORK_WEBRTC']=':c:macro:`EMSCRIPTEN_NETWORK_WEBRTC`'
265264
mapped_wiki_inline_code['emscripten_log']=':c:func:`emscripten_log`'
266265
mapped_wiki_inline_code['emscripten_set_wheel_callback']=':c:func:`emscripten_set_wheel_callback`'
267-
mapped_wiki_inline_code['emscripten_set_canvas_size']=':c:func:`emscripten_set_canvas_size`'
268266
mapped_wiki_inline_code['DOM_DELTA_PAGE']=':c:macro:`DOM_DELTA_PAGE`'
269-
mapped_wiki_inline_code['emscripten_get_canvas_size()']=':c:func:`emscripten_get_canvas_size`'
270267
mapped_wiki_inline_code['*emscripten_get_preloaded_image_data_from_FILE()']=':c:func:`*emscripten_get_preloaded_image_data_from_FILE`'
271-
mapped_wiki_inline_code['emscripten_set_canvas_size()']=':c:func:`emscripten_set_canvas_size`'
272268
mapped_wiki_inline_code['emscripten_get_callstack']=':c:func:`emscripten_get_callstack`'
273269
mapped_wiki_inline_code['HEAPU32']=':js:data:`HEAPU32`'
274270
mapped_wiki_inline_code['EMSCRIPTEN_VISIBILITY_HIDDEN']=':c:macro:`EMSCRIPTEN_VISIBILITY_HIDDEN`'

site/source/docs/api_reference/emscripten.h.rst

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -465,23 +465,6 @@ Functions
465465
Note that SDL’s ``SDL_ShowCursor`` command shows and hides the SDL cursor, not the OS one. This command is useful to hide the OS cursor if your app draws its own cursor.
466466
467467
468-
.. c:function:: void emscripten_set_canvas_size(int width, int height)
469-
470-
Resizes the pixel width and height of the ``<canvas>`` element on the Emscripten web page.
471-
472-
:param int width: New pixel width of canvas element.
473-
:param int height: New pixel height of canvas element.
474-
475-
476-
.. c:function:: void emscripten_get_canvas_size(int * width, int * height, int * isFullscreen)
477-
478-
Gets the current pixel width and height of the ``<canvas>`` element as well as whether the canvas is fullscreen or not.
479-
480-
:param int* width: Pixel width of canvas element.
481-
:param int* height: New pixel height of canvas element.
482-
:param int* isFullscreen: If True (``*int > 0``), ``<canvas>`` is full screen.
483-
484-
485468
.. c:function:: double emscripten_get_now(void)
486469
487470
Returns the highest-precision representation of the current time that the browser provides.

site/source/docs/api_reference/html5.h.rst

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ Defines
10431043
10441044
Specifies that the Emscripten runtime should explicitly scale the CSS size of the target element to cover the whole screen, while adding either vertical or horizontal
10451045
black letterbox padding to preserve the aspect ratio of the content. The aspect ratio that is used here is the render target size of the canvas element. To change the
1046-
desired aspect ratio, call :c:func:`emscripten_set_canvas_size` before entering fullscreen mode.
1046+
desired aspect ratio, call :c:func:`emscripten_set_canvas_element_size` before entering fullscreen mode.
10471047
10481048
.. c:macro:: EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE
10491049
@@ -2140,6 +2140,26 @@ Functions
21402140
:rtype: |EM_BOOL|
21412141
21422142
2143+
.. c:function:: EMSCRIPTEN_RESULT emscripten_set_canvas_element_size(const char *target, int width, int height)
2144+
2145+
Resizes the pixel width and height of the given Canvas element in the DOM.
2146+
2147+
:param target: Specifies a selector for the canvas to resize.
2148+
:param width: New pixel width of canvas element.
2149+
:param height: New pixel height of canvas element.
2150+
:returns: EMSCRIPTEN_RESULT_SUCCESS if resizing succeeded, and one of the EMSCRIPTEN_RESULT_* error values on failure.
2151+
2152+
2153+
.. c:function:: EMSCRIPTEN_RESULT emscripten_get_canvas_element_size(const char *target, int *width, int *height)
2154+
2155+
Gets the current pixel width and height of the given Canvas element in the DOM.
2156+
2157+
:param target: Specifies a selector for the canvas to resize.
2158+
:param width: A pointer to memory location where the width of the canvas element is received. This pointer may not be null.
2159+
:param height: A pointer to memory location where the height of the canvas element is received. This pointer may not be null.
2160+
:returns: EMSCRIPTEN_RESULT_SUCCESS if resizing succeeded, and one of the EMSCRIPTEN_RESULT_* error values on failure.
2161+
2162+
21432163
CSS
21442164
===
21452165

src/library_sdl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// Notes:
1212
// SDL_VIDEORESIZE: This is sent when the canvas is resized. Note that the user
1313
// cannot manually do so, so this is only sent when the
14-
// program manually resizes it (emscripten_set_canvas_size
14+
// program manually resizes it (emscripten_set_canvas_element_size
1515
// or otherwise).
1616

1717
var LibrarySDL = {

tests/gl_textures.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ GLuint program;
3131

3232
void draw()
3333
{
34-
int w, h, fs;
35-
emscripten_get_canvas_size(&w, &h, &fs);
34+
int w, h;
35+
emscripten_get_canvas_element_size("#canvas", &w, &h);
3636
float xs = (float)h / w;
3737
float ys = 1.0f;
3838
float mat[] = { xs, 0, 0, 0, 0, ys, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
@@ -57,7 +57,7 @@ void draw()
5757

5858
int main()
5959
{
60-
emscripten_set_canvas_size(256, 256);
60+
emscripten_set_canvas_element_size("#canvas", 256, 256);
6161
EmscriptenWebGLContextAttributes attr;
6262
emscripten_webgl_init_context_attributes(&attr);
6363
attr.alpha = attr.depth = attr.stencil = attr.antialias = attr.preserveDrawingBuffer = attr.failIfMajorPerformanceCaveat = 0;

tests/sdl2_canvas_size.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <assert.h>
1313

1414
#include <emscripten.h>
15+
#include <emscripten/html5.h>
1516

1617
int result = 0;
1718

@@ -36,15 +37,15 @@ int main(int argc, char *argv[])
3637
);
3738

3839
// Test 2: Check that getting current canvas size works.
39-
int w, h, fs;
40-
emscripten_get_canvas_size(&w, &h, &fs);
40+
int w, h;
41+
emscripten_get_canvas_element_size("#canvas", &w, &h);
4142
printf("w:%d,h:%d\n", w,h);
4243
assert(w == 700);
4344
assert(h == 200);
4445

4546
// Test 3: Check that resizing the canvas works as well.
46-
emscripten_set_canvas_size(640, 480);
47-
emscripten_get_canvas_size(&w, &h, &fs);
47+
emscripten_set_canvas_element_size("#canvas", 640, 480);
48+
emscripten_get_canvas_element_size("#canvas", &w, &h);
4849
printf("w:%d,h:%d\n", w,h);
4950
assert(w == 640);
5051
assert(h == 480);

tests/sdl_canvas.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <SDL/SDL.h>
1111
#include <SDL/SDL_ttf.h>
1212
#include <emscripten.h>
13+
#include <emscripten/html5.h>
1314

1415

1516
int main(int argc, char **argv) {
@@ -52,8 +53,8 @@ int main(int argc, char **argv) {
5253

5354
SDL_LockSurface(screen);
5455

55-
int width, height, isFullscreen;
56-
emscripten_get_canvas_size(&width, &height, &isFullscreen);
56+
int width, height;
57+
emscripten_get_canvas_element_size("#canvas", &width, &height);
5758

5859
if (width != 600 && height != 450)
5960
{

tests/sdl_canvas_alpha.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <SDL/SDL.h>
1212
#include <SDL/SDL_ttf.h>
1313
#include <emscripten.h>
14+
#include <emscripten/html5.h>
1415

1516

1617
int main(int argc, char **argv) {
@@ -43,8 +44,8 @@ int main(int argc, char **argv) {
4344

4445
SDL_LockSurface(screen);
4546

46-
int width, height, isFullscreen;
47-
emscripten_get_canvas_size(&width, &height, &isFullscreen);
47+
int width, height;
48+
emscripten_get_canvas_element_size("#canvas", &width, &height);
4849

4950
if (width != 600 && height != 450)
5051
{

tests/sdl_fullscreen_samecanvassize.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <SDL/SDL_ttf.h>
1111
#include <assert.h>
1212
#include <emscripten.h>
13+
#include <emscripten/html5.h>
1314

1415
int result = 1;
1516

@@ -22,8 +23,8 @@ int wasFullscreen = 0;
2223
int finished = 0;
2324

2425
void render() {
25-
int width, height, isfs;
26-
emscripten_get_canvas_size(&width, &height, &isfs);
26+
int width, height;
27+
emscripten_get_canvas_element_size("#canvas", &width, &height);
2728
SDL_Rect rect = { 0, 0, width, height };
2829
SDL_FillRect(screen, &rect, 0xff00ffff);
2930
}
@@ -78,8 +79,8 @@ void mainloop() {
7879
}
7980

8081
int main() {
81-
int w, h, fs;
82-
emscripten_get_canvas_size(&w, &h, &fs);
82+
int w, h;
83+
emscripten_get_canvas_element_size("#canvas", &w, &h);
8384
printf("w:%d,h:%d\n", w,h);
8485

8586
SDL_Init(SDL_INIT_VIDEO);

tests/sdl_togglefullscreen.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ static void render() {
7474
SDL_RenderClear(renderer);
7575
SDL_RenderPresent(renderer);
7676
#else
77-
int width, height, isfs;
78-
emscripten_get_canvas_size(&width, &height, &isfs);
77+
int width, height;
78+
emscripten_get_canvas_element_size("#canvas", &width, &height);
7979
SDL_Rect rect = { 0, 0, width, height };
8080
SDL_FillRect(screen, &rect, 0xff00ffff);
8181
#endif

0 commit comments

Comments
 (0)