Skip to content

Commit

Permalink
Remove uses of deprecated functions emscripten_get_canvas_size() and …
Browse files Browse the repository at this point in the history
…emscripten_set_canvas_size() (#7998)
  • Loading branch information
juj authored Feb 4, 2019
1 parent 6b30209 commit 053198d
Show file tree
Hide file tree
Showing 18 changed files with 56 additions and 52 deletions.
4 changes: 0 additions & 4 deletions site/source/api_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ def get_mapped_items():
mapped_wiki_inline_code['emscripten_set_beforeunload_callback']=':c:func:`emscripten_set_beforeunload_callback`'
mapped_wiki_inline_code['emscripten_random()']=':c:func:`emscripten_random`'
mapped_wiki_inline_code['EMSCRIPTEN_RESULT']=':c:macro:`EMSCRIPTEN_RESULT`'
mapped_wiki_inline_code['emscripten_get_canvas_size']=':c:func:`emscripten_get_canvas_size`'
mapped_wiki_inline_code['emscripten_async_run_script']=':c:func:`emscripten_async_run_script`'
mapped_wiki_inline_code['emscripten_worker_respond()']=':c:func:`emscripten_worker_respond`'
mapped_wiki_inline_code['DOM_DELTA_PIXEL']=':c:macro:`DOM_DELTA_PIXEL`'
Expand Down Expand Up @@ -264,11 +263,8 @@ def get_mapped_items():
mapped_wiki_inline_code['EMSCRIPTEN_NETWORK_WEBRTC']=':c:macro:`EMSCRIPTEN_NETWORK_WEBRTC`'
mapped_wiki_inline_code['emscripten_log']=':c:func:`emscripten_log`'
mapped_wiki_inline_code['emscripten_set_wheel_callback']=':c:func:`emscripten_set_wheel_callback`'
mapped_wiki_inline_code['emscripten_set_canvas_size']=':c:func:`emscripten_set_canvas_size`'
mapped_wiki_inline_code['DOM_DELTA_PAGE']=':c:macro:`DOM_DELTA_PAGE`'
mapped_wiki_inline_code['emscripten_get_canvas_size()']=':c:func:`emscripten_get_canvas_size`'
mapped_wiki_inline_code['*emscripten_get_preloaded_image_data_from_FILE()']=':c:func:`*emscripten_get_preloaded_image_data_from_FILE`'
mapped_wiki_inline_code['emscripten_set_canvas_size()']=':c:func:`emscripten_set_canvas_size`'
mapped_wiki_inline_code['emscripten_get_callstack']=':c:func:`emscripten_get_callstack`'
mapped_wiki_inline_code['HEAPU32']=':js:data:`HEAPU32`'
mapped_wiki_inline_code['EMSCRIPTEN_VISIBILITY_HIDDEN']=':c:macro:`EMSCRIPTEN_VISIBILITY_HIDDEN`'
Expand Down
17 changes: 0 additions & 17 deletions site/source/docs/api_reference/emscripten.h.rst
Original file line number Diff line number Diff line change
Expand Up @@ -465,23 +465,6 @@ Functions
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.
.. c:function:: void emscripten_set_canvas_size(int width, int height)
Resizes the pixel width and height of the ``<canvas>`` element on the Emscripten web page.
:param int width: New pixel width of canvas element.
:param int height: New pixel height of canvas element.
.. c:function:: void emscripten_get_canvas_size(int * width, int * height, int * isFullscreen)
Gets the current pixel width and height of the ``<canvas>`` element as well as whether the canvas is fullscreen or not.
:param int* width: Pixel width of canvas element.
:param int* height: New pixel height of canvas element.
:param int* isFullscreen: If True (``*int > 0``), ``<canvas>`` is full screen.
.. c:function:: double emscripten_get_now(void)
Returns the highest-precision representation of the current time that the browser provides.
Expand Down
22 changes: 21 additions & 1 deletion site/source/docs/api_reference/html5.h.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ Defines
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
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
desired aspect ratio, call :c:func:`emscripten_set_canvas_size` before entering fullscreen mode.
desired aspect ratio, call :c:func:`emscripten_set_canvas_element_size` before entering fullscreen mode.
.. c:macro:: EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE
Expand Down Expand Up @@ -2140,6 +2140,26 @@ Functions
:rtype: |EM_BOOL|
.. c:function:: EMSCRIPTEN_RESULT emscripten_set_canvas_element_size(const char *target, int width, int height)
Resizes the pixel width and height of the given Canvas element in the DOM.
:param target: Specifies a selector for the canvas to resize.
:param width: New pixel width of canvas element.
:param height: New pixel height of canvas element.
:returns: EMSCRIPTEN_RESULT_SUCCESS if resizing succeeded, and one of the EMSCRIPTEN_RESULT_* error values on failure.
.. c:function:: EMSCRIPTEN_RESULT emscripten_get_canvas_element_size(const char *target, int *width, int *height)
Gets the current pixel width and height of the given Canvas element in the DOM.
:param target: Specifies a selector for the canvas to resize.
:param width: A pointer to memory location where the width of the canvas element is received. This pointer may not be null.
:param height: A pointer to memory location where the height of the canvas element is received. This pointer may not be null.
:returns: EMSCRIPTEN_RESULT_SUCCESS if resizing succeeded, and one of the EMSCRIPTEN_RESULT_* error values on failure.
CSS
===
Expand Down
2 changes: 1 addition & 1 deletion src/library_sdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// Notes:
// SDL_VIDEORESIZE: This is sent when the canvas is resized. Note that the user
// cannot manually do so, so this is only sent when the
// program manually resizes it (emscripten_set_canvas_size
// program manually resizes it (emscripten_set_canvas_element_size
// or otherwise).

var LibrarySDL = {
Expand Down
6 changes: 3 additions & 3 deletions tests/gl_textures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ GLuint program;

void draw()
{
int w, h, fs;
emscripten_get_canvas_size(&w, &h, &fs);
int w, h;
emscripten_get_canvas_element_size("#canvas", &w, &h);
float xs = (float)h / w;
float ys = 1.0f;
float mat[] = { xs, 0, 0, 0, 0, ys, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
Expand All @@ -57,7 +57,7 @@ void draw()

int main()
{
emscripten_set_canvas_size(256, 256);
emscripten_set_canvas_element_size("#canvas", 256, 256);
EmscriptenWebGLContextAttributes attr;
emscripten_webgl_init_context_attributes(&attr);
attr.alpha = attr.depth = attr.stencil = attr.antialias = attr.preserveDrawingBuffer = attr.failIfMajorPerformanceCaveat = 0;
Expand Down
9 changes: 5 additions & 4 deletions tests/sdl2_canvas_size.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <assert.h>

#include <emscripten.h>
#include <emscripten/html5.h>

int result = 0;

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

// Test 2: Check that getting current canvas size works.
int w, h, fs;
emscripten_get_canvas_size(&w, &h, &fs);
int w, h;
emscripten_get_canvas_element_size("#canvas", &w, &h);
printf("w:%d,h:%d\n", w,h);
assert(w == 700);
assert(h == 200);

// Test 3: Check that resizing the canvas works as well.
emscripten_set_canvas_size(640, 480);
emscripten_get_canvas_size(&w, &h, &fs);
emscripten_set_canvas_element_size("#canvas", 640, 480);
emscripten_get_canvas_element_size("#canvas", &w, &h);
printf("w:%d,h:%d\n", w,h);
assert(w == 640);
assert(h == 480);
Expand Down
5 changes: 3 additions & 2 deletions tests/sdl_canvas.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>
#include <emscripten.h>
#include <emscripten/html5.h>


int main(int argc, char **argv) {
Expand Down Expand Up @@ -52,8 +53,8 @@ int main(int argc, char **argv) {

SDL_LockSurface(screen);

int width, height, isFullscreen;
emscripten_get_canvas_size(&width, &height, &isFullscreen);
int width, height;
emscripten_get_canvas_element_size("#canvas", &width, &height);

if (width != 600 && height != 450)
{
Expand Down
5 changes: 3 additions & 2 deletions tests/sdl_canvas_alpha.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>
#include <emscripten.h>
#include <emscripten/html5.h>


int main(int argc, char **argv) {
Expand Down Expand Up @@ -43,8 +44,8 @@ int main(int argc, char **argv) {

SDL_LockSurface(screen);

int width, height, isFullscreen;
emscripten_get_canvas_size(&width, &height, &isFullscreen);
int width, height;
emscripten_get_canvas_element_size("#canvas", &width, &height);

if (width != 600 && height != 450)
{
Expand Down
9 changes: 5 additions & 4 deletions tests/sdl_fullscreen_samecanvassize.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <SDL/SDL_ttf.h>
#include <assert.h>
#include <emscripten.h>
#include <emscripten/html5.h>

int result = 1;

Expand All @@ -22,8 +23,8 @@ int wasFullscreen = 0;
int finished = 0;

void render() {
int width, height, isfs;
emscripten_get_canvas_size(&width, &height, &isfs);
int width, height;
emscripten_get_canvas_element_size("#canvas", &width, &height);
SDL_Rect rect = { 0, 0, width, height };
SDL_FillRect(screen, &rect, 0xff00ffff);
}
Expand Down Expand Up @@ -78,8 +79,8 @@ void mainloop() {
}

int main() {
int w, h, fs;
emscripten_get_canvas_size(&w, &h, &fs);
int w, h;
emscripten_get_canvas_element_size("#canvas", &w, &h);
printf("w:%d,h:%d\n", w,h);

SDL_Init(SDL_INIT_VIDEO);
Expand Down
4 changes: 2 additions & 2 deletions tests/sdl_togglefullscreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ static void render() {
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
#else
int width, height, isfs;
emscripten_get_canvas_size(&width, &height, &isfs);
int width, height;
emscripten_get_canvas_element_size("#canvas", &width, &height);
SDL_Rect rect = { 0, 0, width, height };
SDL_FillRect(screen, &rect, 0xff00ffff);
#endif
Expand Down
5 changes: 3 additions & 2 deletions tests/sdl_wm_togglefullscreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <SDL/SDL_ttf.h>
#include <assert.h>
#include <emscripten.h>
#include <emscripten/html5.h>

int result = 1;

Expand All @@ -22,8 +23,8 @@ int wasFullscreen = 0;
int finished = 0;

void render() {
int width, height, isfs;
emscripten_get_canvas_size(&width, &height, &isfs);
int width, height;
emscripten_get_canvas_element_size("#canvas", &width, &height);
SDL_Rect rect = { 0, 0, width, height };
SDL_FillRect(screen, &rect, 0xff00ffff);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/test_html5_fullscreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ GLuint program;

void draw()
{
int w, h, fs;
emscripten_get_canvas_size(&w, &h, &fs);
int w, h;
emscripten_get_canvas_element_size("#canvas", &w, &h);
float t = emscripten_get_now() / 1000.0f;
float xs = (float)h / w;
float ys = 1.0f;
Expand All @@ -124,8 +124,8 @@ void draw()

EM_BOOL on_canvassize_changed(int eventType, const void *reserved, void *userData)
{
int w, h, fs;
emscripten_get_canvas_size(&w, &h, &fs);
int w, h;
emscripten_get_canvas_element_size("#canvas", &w, &h);
double cssW, cssH;
emscripten_get_element_css_size(0, &cssW, &cssH);
printf("Canvas resized: WebGL RTT size: %dx%d, canvas CSS size: %02gx%02g\n", w, h, cssW, cssH);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_html5_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ EM_BOOL wheel_callback(int eventType, const EmscriptenWheelEvent *e, void *userD
int main()
{
// Make the canvas area stand out from the background.
emscripten_set_canvas_size(400, 300);
emscripten_set_canvas_element_size("#canvas", 400, 300);
EM_ASM(Module['canvas'].style.backgroundColor = 'black';);

EMSCRIPTEN_RESULT ret = emscripten_set_click_callback(0, 0, 1, mouse_callback);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_html5_pointerlockerror.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ int main()
printf("Reject the pointer lock request after clicking on canvas.\n");

// Make the canvas area stand out from the background.
emscripten_set_canvas_size(400, 300);
emscripten_set_canvas_element_size( "#canvas", 400, 300 );
EM_ASM(Module['canvas'].style.backgroundColor = 'black';);

EMSCRIPTEN_RESULT ret = emscripten_set_click_callback(0, 0, 1, click_callback);
Expand Down
2 changes: 1 addition & 1 deletion tests/webgl2_garbage_free_entrypoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ GLuint CompileShader(GLenum type, const char *src)

int main(int argc, char *argv[])
{
emscripten_set_canvas_size(256, 256);
emscripten_set_canvas_element_size("#canvas", 256, 256);
EmscriptenWebGLContextAttributes attr;
emscripten_webgl_init_context_attributes(&attr);
attr.alpha = attr.depth = attr.stencil = attr.antialias = attr.preserveDrawingBuffer = attr.failIfMajorPerformanceCaveat = 0;
Expand Down
2 changes: 1 addition & 1 deletion tests/webgl2_objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int result = 0;

int main()
{
emscripten_set_canvas_size( 100, 100 );
emscripten_set_canvas_element_size( "#canvas", 100, 100 );

EmscriptenWebGLContextAttributes attrs;
emscripten_webgl_init_context_attributes(&attrs);
Expand Down
2 changes: 1 addition & 1 deletion tests/webgl_shader_source_length.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int result = 0;

int main()
{
emscripten_set_canvas_size( 100, 100 );
emscripten_set_canvas_element_size( "#canvas", 100, 100 );

EmscriptenWebGLContextAttributes attrs;
emscripten_webgl_init_context_attributes(&attrs);
Expand Down
2 changes: 1 addition & 1 deletion tests/webgl_with_closure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

int main()
{
emscripten_set_canvas_size( 100, 100 );
emscripten_set_canvas_element_size( "#canvas", 100, 100 );

EmscriptenWebGLContextAttributes attrs;
emscripten_webgl_init_context_attributes(&attrs);
Expand Down

0 comments on commit 053198d

Please sign in to comment.