Esempio n. 1
0
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});
Esempio n. 2
0
static void gfx_ctx_emscripten_get_canvas_size(int *width, int *height)
{
   EmscriptenFullscreenChangeEvent fullscreen_status;
   bool  is_fullscreen = false;
   EMSCRIPTEN_RESULT r = emscripten_get_fullscreen_status(&fullscreen_status);

   if (r == EMSCRIPTEN_RESULT_SUCCESS)
   {
      if (fullscreen_status.isFullscreen)
      {
         is_fullscreen = true;
         *width = fullscreen_status.screenWidth;
         *height = fullscreen_status.screenHeight;
      }
   }

   if (!is_fullscreen)
   {
      r = emscripten_get_canvas_element_size("#canvas", width, height);

      if (r != EMSCRIPTEN_RESULT_SUCCESS)
      {
         RARCH_ERR("[EMSCRIPTEN/EGL]: Could not get screen dimensions: %d\n",
            r);
         *width = 800;
         *height = 600;
      }
   }
}
Esempio n. 3
0
static void *gfx_ctx_emscripten_init(video_frame_info_t *video_info,
   void *video_driver)
{
#ifdef HAVE_EGL
   unsigned width, height;
   EGLint major, minor;
   EGLint n;
   static const EGLint attribute_list[] =
   {
      EGL_RED_SIZE, 8,
      EGL_GREEN_SIZE, 8,
      EGL_BLUE_SIZE, 8,
      EGL_ALPHA_SIZE, 8,
      EGL_DEPTH_SIZE, 16,
      EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
      EGL_NONE
   };
   static const EGLint context_attributes[] =
   {
      EGL_CONTEXT_CLIENT_VERSION, 2,
      EGL_NONE
   };
#endif
   emscripten_ctx_data_t *emscripten = (emscripten_ctx_data_t*)
      calloc(1, sizeof(*emscripten));

   if (!emscripten)
      return NULL;

   (void)video_driver;

   if (emscripten_initial_width == 0 || emscripten_initial_height == 0)
      emscripten_get_canvas_element_size("#canvas",
         &emscripten_initial_width, &emscripten_initial_height);

#ifdef HAVE_EGL
   if (g_egl_inited)
   {
      RARCH_LOG("[EMSCRIPTEN/EGL]: Attempted to re-initialize driver.\n");
      return (void*)"emscripten";
   }

   if (!egl_init_context(&emscripten->egl, EGL_NONE,
      (void *)EGL_DEFAULT_DISPLAY, &major, &minor, &n, attribute_list, NULL))
   {
      egl_report_error();
      goto error;
   }

   if (!egl_create_context(&emscripten->egl, context_attributes))
   {
      egl_report_error();
      goto error;
   }

   if (!egl_create_surface(&emscripten->egl, 0))
      goto error;

   egl_get_video_size(&emscripten->egl, &width, &height);

   emscripten->fb_width  = width;
   emscripten->fb_height = height;
   RARCH_LOG("[EMSCRIPTEN/EGL]: Dimensions: %ux%u\n", width, height);
#endif

   return emscripten;

error:
   gfx_ctx_emscripten_destroy(video_driver);
   return NULL;
}
Esempio n. 4
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;

  // Check that we see the change via 'mycanvasId'
  r = emscripten_get_canvas_element_size("myCanvasId", &w, &h);
  assert(r == EMSCRIPTEN_RESULT_SUCCESS);