Pass events loop to glwindow test webvr implementation

This commit is contained in:
Alan Jeffrey 2019-06-14 14:39:20 -05:00
parent 18477d1e1e
commit 1e5e3c95c9
7 changed files with 24 additions and 16 deletions

View file

@ -54,7 +54,7 @@ lazy_static = "1"
libservo = {path = "../../components/servo"}
libc = "0.2"
log = "0.4"
rust-webvr = { version = "0.11", features = ["glwindow"] }
rust-webvr = { version = "0.12", features = ["glwindow"] }
tinyfiledialogs = "3.0"
[target.'cfg(any(target_os = "linux", target_os = "windows"))'.dependencies]

View file

@ -8,6 +8,7 @@ use crate::app;
use crate::events_loop::EventsLoop;
use gleam::gl;
use glutin;
use glutin::EventsLoopClosed;
use glutin::dpi::LogicalSize;
use rust_webvr::GlWindowVRService;
use servo::compositing::windowing::EmbedderMethods;
@ -46,6 +47,10 @@ impl EmbedderMethods for EmbedderCallbacks {
let name = String::from("Test VR Display");
let size = opts::get().initial_window_size.to_f64();
let size = LogicalSize::new(size.width, size.height);
let events_loop_clone = self.events_loop.clone();
let events_loop_factory = Box::new(move || {
events_loop_clone.borrow_mut().take().ok_or(EventsLoopClosed)
});
let window_builder = glutin::WindowBuilder::new()
.with_title(name.clone())
.with_dimensions(size)
@ -57,7 +62,7 @@ impl EmbedderMethods for EmbedderCallbacks {
.build_windowed(window_builder, &*self.events_loop.borrow().as_winit())
.expect("Failed to create window.");
let gl = self.gl.clone();
let (service, heartbeat) = GlWindowVRService::new(name, context, gl);
let (service, heartbeat) = GlWindowVRService::new(name, context, events_loop_factory, gl);
services.register(Box::new(service));
heartbeats.push(Box::new(heartbeat));

View file

@ -44,6 +44,9 @@ impl EventsLoop {
pub fn as_winit(&self) -> &glutin::EventsLoop {
&self.0.as_ref().expect("Can't access winit event loop while using the fake headless event loop")
}
pub fn take(&mut self) -> Option<glutin::EventsLoop> {
self.0.take()
}
pub fn poll_events<F>(&mut self, callback: F) where F: FnMut(glutin::Event) {
if let Some(ref mut events_loop) = self.0 {
events_loop.poll_events(callback);

View file

@ -19,7 +19,7 @@ raqote_backend = ["simpleservo/raqote_backend"]
[dependencies]
libservo = { path = "../../components/servo", features = ["no_static_freetype"] }
simpleservo = { path = "../libsimpleservo/api", features = ["no_static_freetype"] }
rust-webvr = { version = "0.11", features = ["magicleap"] }
rust-webvr = { version = "0.12", features = ["magicleap"] }
libc = "0.2"
log = "0.4"
servo-egl = "0.2"