Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Emscripten support #857

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ build = "build.rs"
lazy_static = "0.2.0"
libc = "0.2"
shared_library = "0.1.0"

winit = "0.5.10"

[build-dependencies]
Expand Down Expand Up @@ -44,3 +45,4 @@ dwmapi-sys = "0.1"
osmesa-sys = "0.1.0"
wayland-client = { version = "0.7.4", features = ["egl", "dlopen"] }
x11-dl = "2.4"

93 changes: 46 additions & 47 deletions src/api/emscripten/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ use PixelFormat;
use PixelFormatRequirements;
use WindowAttributes;

use winit;
pub use winit::WindowProxy;


use std::collections::VecDeque;
use platform::PlatformSpecificWindowBuilderAttributes;

mod ffi;

pub struct Window {
context: ffi::EMSCRIPTEN_WEBGL_CONTEXT_HANDLE,
winit_window: winit::Window,
}

pub struct PollEventsIterator<'a> {
Expand All @@ -32,6 +37,7 @@ impl<'a> Iterator for PollEventsIterator<'a> {

#[inline]
fn next(&mut self) -> Option<Event> {
// TODO
None
}
}
Expand All @@ -45,56 +51,20 @@ impl<'a> Iterator for WaitEventsIterator<'a> {

#[inline]
fn next(&mut self) -> Option<Event> {
// TODO
None
}
}

#[derive(Clone)]
pub struct WindowProxy;

impl WindowProxy {
#[inline]
pub fn wakeup_event_loop(&self) {
unimplemented!()
}
}

#[derive(Clone)]
pub struct MonitorId;

#[inline]
pub fn get_available_monitors() -> VecDeque<MonitorId> {
let mut list = VecDeque::new();
list.push_back(MonitorId);
list
}

#[inline]
pub fn get_primary_monitor() -> MonitorId {
MonitorId
}

impl MonitorId {
#[inline]
pub fn get_name(&self) -> Option<String> {
Some("Canvas".to_owned())
}

#[inline]
pub fn get_native_identifier(&self) -> ::native_monitor::NativeMonitorId {
::native_monitor::NativeMonitorId::Unavailable
}

#[inline]
pub fn get_dimensions(&self) -> (u32, u32) {
unimplemented!()
}
}

impl Window {
pub fn new(window: &WindowAttributes, pf_reqs: &PixelFormatRequirements,
opengl: &GlAttributes<&Window>, _: &PlatformSpecificWindowBuilderAttributes) -> Result<Window, CreationError>
{
pub fn new(_: &WindowAttributes,
pf_reqs: &PixelFormatRequirements,
opengl: &GlAttributes<&Window>,
_: &PlatformSpecificWindowBuilderAttributes,
winit_builder: winit::WindowBuilder)
-> Result<Window, CreationError> {

let winit_window = winit_builder.build().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is that you wouldn't use winit at all. Just don't call it, and remove the winit_window field from the struct.

// getting the default values of attributes
let mut attributes = unsafe {
use std::mem;
Expand Down Expand Up @@ -127,7 +97,8 @@ impl Window {
// TODO: emscripten_set_webglcontextrestored_callback

Ok(Window {
context: context
context: context,
winit_window: winit_window
})
}

Expand Down Expand Up @@ -190,7 +161,7 @@ impl Window {

#[inline]
pub fn create_window_proxy(&self) -> WindowProxy {
WindowProxy
self.winit_window.create_window_proxy()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to panic! here. Nobody uses the window proxy, and it's going to be removed soon.

}

#[inline]
Expand All @@ -210,6 +181,7 @@ impl Window {

#[inline]
pub fn set_window_resize_callback(&mut self, _: Option<fn(u32, u32)>) {
// TODO
}

#[inline]
Expand All @@ -230,6 +202,31 @@ impl Window {
pub fn set_cursor_position(&self, x: i32, y: i32) -> Result<(), ()> {
Ok(())
}

#[inline]
pub fn get_inner_size_points(&self) -> Option<(u32, u32)> {
unimplemented!();
}

#[inline]
pub fn get_inner_size_pixels(&self) -> Option<(u32, u32)> {
unimplemented!();
}

#[inline]
pub fn as_winit_window(&self) -> &winit::Window {
&self.winit_window
}

#[inline]
pub fn as_winit_window_mut(&mut self) -> &mut winit::Window {
&mut self.winit_window
}

#[inline]
pub fn hdpi_factor(&self) -> f32 {
unimplemented!();
}
}

impl GlContext for Window {
Expand Down Expand Up @@ -295,3 +292,5 @@ fn error_to_str(code: ffi::EMSCRIPTEN_RESULT) -> &'static str {
_ => "Undocumented error"
}
}


4 changes: 2 additions & 2 deletions src/platform/emscripten/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use GlContext;
use PixelFormat;
use PixelFormatRequirements;

pub use api::emscripten::{Window, WindowProxy, MonitorId, get_available_monitors};
pub use api::emscripten::{get_primary_monitor, WaitEventsIterator, PollEventsIterator};
pub use api::emscripten::{Window, WindowProxy};
pub use api::emscripten::{WaitEventsIterator, PollEventsIterator};

pub struct HeadlessContext(Window);

Expand Down