From a8d5a9e1aba143fc0d9862c25b3b70e0c6341ec9 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Wed, 27 Dec 2017 12:37:01 -0500 Subject: [PATCH] [emscripten] request canvas size instead of CSS size (#370) --- src/platform/emscripten/ffi.rs | 11 +++++++++++ src/platform/emscripten/mod.rs | 9 +++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/platform/emscripten/ffi.rs b/src/platform/emscripten/ffi.rs index 65291a92..f1d12c14 100644 --- a/src/platform/emscripten/ffi.rs +++ b/src/platform/emscripten/ffi.rs @@ -3,6 +3,8 @@ #![allow(non_camel_case_types)] use std::os::raw::{c_int, c_char, c_void, c_ulong, c_double, c_long, c_ushort}; +#[cfg(test)] +use std::mem; pub type EM_BOOL = c_int; pub type EM_UTF8 = c_char; @@ -219,6 +221,15 @@ fn bindgen_test_layout_EmscriptenPointerlockChangeEvent() { } extern "C" { + pub fn emscripten_set_canvas_size( + width: c_int, height: c_int) + -> EMSCRIPTEN_RESULT; + + pub fn emscripten_get_canvas_size( + width: *mut c_int, height: *mut c_int, + is_fullscreen: *mut c_int) + -> EMSCRIPTEN_RESULT; + pub fn emscripten_set_element_css_size( target: *const c_char, width: c_double, height: c_double) -> EMSCRIPTEN_RESULT; diff --git a/src/platform/emscripten/mod.rs b/src/platform/emscripten/mod.rs index 41e9045d..b879bf50 100644 --- a/src/platform/emscripten/mod.rs +++ b/src/platform/emscripten/mod.rs @@ -6,7 +6,7 @@ use std::mem; use std::os::raw::{c_char, c_void, c_double, c_ulong, c_int}; use std::ptr; use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::{Mutex, Arc, Weak}; +use std::sync::{Mutex, Arc}; use std::cell::RefCell; use std::collections::VecDeque; @@ -424,10 +424,11 @@ impl Window { pub fn get_inner_size(&self) -> Option<(u32, u32)> { unsafe { use std::{mem, ptr}; - let mut width = mem::uninitialized(); - let mut height = mem::uninitialized(); + let mut width = 0; + let mut height = 0; + let mut fullscreen = 0; - if ffi::emscripten_get_element_css_size(ptr::null(), &mut width, &mut height) + if ffi::emscripten_get_canvas_size(&mut width, &mut height, &mut fullscreen) != ffi::EMSCRIPTEN_RESULT_SUCCESS { None