From 8e95efb8b2b40bf7a77e090eadf8df5128e43a08 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Fri, 20 Sep 2019 09:59:32 -0500 Subject: [PATCH 1/4] Share the GL bindings when creating a new glutin window which shares GL objects --- ports/glutin/headed_window.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/ports/glutin/headed_window.rs b/ports/glutin/headed_window.rs index 5d043c9378d..1b7dc0a580f 100644 --- a/ports/glutin/headed_window.rs +++ b/ports/glutin/headed_window.rs @@ -85,7 +85,7 @@ fn window_creation_scale_factor() -> Scale, - sharing: Option<&GlContext>, + sharing: Option<&Window>, events_loop: Rc>, ) -> Window { let opts = opts::get(); @@ -119,7 +119,11 @@ impl Window { } let context = match sharing { - Some(sharing) => sharing.new_window(context_builder, window_builder, events_loop.borrow().as_winit()), + Some(sharing) => sharing.gl_context.borrow().new_window( + context_builder, + window_builder, + events_loop.borrow().as_winit() + ), None => context_builder.build_windowed(window_builder, events_loop.borrow().as_winit()), }.expect("Failed to create window."); @@ -149,7 +153,9 @@ impl Window { context.window().show(); - let gl = match context.get_api() { + let gl = if let Some(sharing) = sharing { + sharing.gl.clone() + } else { match context.get_api() { Api::OpenGl => unsafe { gl::GlFns::load_with(|s| context.get_proc_address(s) as *const _) }, @@ -157,7 +163,7 @@ impl Window { gl::GlesFns::load_with(|s| context.get_proc_address(s) as *const _) }, Api::WebGl => unreachable!("webgl is unsupported"), - }; + } }; gl.clear_color(0.6, 0.6, 0.6, 1.0); gl.clear(gl::COLOR_BUFFER_BIT); @@ -494,10 +500,9 @@ impl webxr::glwindow::GlWindow for Window { } fn new_window(&self) -> Result, ()> { - let gl_context = self.gl_context.borrow(); Ok(Box::new(Window::new( self.inner_size.get(), - Some(&*gl_context), + Some(self), self.events_loop.clone(), ))) } From a7ed8f7e5a09da5db517c874d7feacae6504258d Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Fri, 20 Sep 2019 10:00:56 -0500 Subject: [PATCH 2/4] Add some debug! logs to the glutin port --- ports/glutin/headed_window.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ports/glutin/headed_window.rs b/ports/glutin/headed_window.rs index 1b7dc0a580f..0e5c54e2551 100644 --- a/ports/glutin/headed_window.rs +++ b/ports/glutin/headed_window.rs @@ -134,6 +134,7 @@ impl Window { } let context = unsafe { + debug!("Making window {:?} current", context.window().id()); context.make_current().expect("Couldn't make window current") }; @@ -173,6 +174,7 @@ impl Window { context.make_not_current(); + debug!("Created window {:?}", context.window().id()); let window = Window { gl_context: RefCell::new(context), events_loop, @@ -480,10 +482,12 @@ impl WindowPortsMethods for Window { impl webxr::glwindow::GlWindow for Window { fn make_current(&mut self) { + debug!("Making window {:?} current", self.gl_context.borrow().window().id()); self.gl_context.get_mut().make_current(); } fn swap_buffers(&mut self) { + debug!("Swapping buffers on window {:?}", self.gl_context.borrow().window().id()); self.gl_context.get_mut().swap_buffers(); self.gl_context.get_mut().make_not_current(); } From 5f503f034a85fae4cfd6aa17984b8797b914c75c Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Fri, 20 Sep 2019 10:01:50 -0500 Subject: [PATCH 3/4] Don't completely trust servo's tracking of the GL context in glutin --- ports/glutin/context.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ports/glutin/context.rs b/ports/glutin/context.rs index c26db664b94..a36e3f9c4e5 100644 --- a/ports/glutin/context.rs +++ b/ports/glutin/context.rs @@ -35,6 +35,13 @@ impl GlContext { *self = match std::mem::replace(self, GlContext::None) { GlContext::Current(c) => { warn!("Making an already current context current"); + // Servo thinks that that this window is current, + // but it might be wrong, since other code may have + // changed the current GL context. Just to be on + // the safe side, we make it current anyway. + let c = unsafe { + c.make_current().expect("Couldn't make window current") + }; GlContext::Current(c) }, GlContext::NotCurrent(c) => { From 99699ea70c384ee80c6c0d3a8714e8f356175038 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Fri, 20 Sep 2019 10:02:27 -0500 Subject: [PATCH 4/4] Make the current window not current while creating a new shared window in the glutin port --- ports/glutin/headed_window.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ports/glutin/headed_window.rs b/ports/glutin/headed_window.rs index 0e5c54e2551..2d1dd3ef2aa 100644 --- a/ports/glutin/headed_window.rs +++ b/ports/glutin/headed_window.rs @@ -133,6 +133,11 @@ impl Window { context.window().set_window_icon(Some(load_icon(icon_bytes))); } + if let Some(sharing) = sharing { + debug!("Making window {:?} not current", sharing.gl_context.borrow().window().id()); + sharing.gl_context.borrow_mut().make_not_current(); + } + let context = unsafe { debug!("Making window {:?} current", context.window().id()); context.make_current().expect("Couldn't make window current")