diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2019-09-21 04:22:24 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-21 04:22:24 -0400 |
commit | de89b09f681ec178fa03b7bfb0adb5bb3c96fba0 (patch) | |
tree | 78dd5a1e1b0abc90841b421f263ddd59cbc503a9 /ports | |
parent | d3727c2989f26d2ac5e1acd4cb93a57156feefe8 (diff) | |
parent | 99699ea70c384ee80c6c0d3a8714e8f356175038 (diff) | |
download | servo-de89b09f681ec178fa03b7bfb0adb5bb3c96fba0.tar.gz servo-de89b09f681ec178fa03b7bfb0adb5bb3c96fba0.zip |
Auto merge of #24253 - asajeffrey:glutin-new-window-shares-gl-bindings, r=paulrouget
Glutin new window shares gl bindings
<!-- Please describe your changes on the following line: -->
At the moment when the glutin port creates a new window which shares GL objects, it creates new GL bindings rather than sharting the existing ones. This PR fixes that.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes do not require tests because it's an efficiency improvement
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/24253)
<!-- Reviewable:end -->
Diffstat (limited to 'ports')
-rw-r--r-- | ports/glutin/context.rs | 7 | ||||
-rw-r--r-- | ports/glutin/headed_window.rs | 26 |
2 files changed, 27 insertions, 6 deletions
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) => { diff --git a/ports/glutin/headed_window.rs b/ports/glutin/headed_window.rs index bc423364a64..294f9c2973c 100644 --- a/ports/glutin/headed_window.rs +++ b/ports/glutin/headed_window.rs @@ -85,7 +85,7 @@ fn window_creation_scale_factor() -> Scale<f32, DeviceIndependentPixel, DevicePi impl Window { pub fn new( win_size: Size2D<u32, DeviceIndependentPixel>, - sharing: Option<&GlContext>, + sharing: Option<&Window>, events_loop: Rc<RefCell<EventsLoop>>, ) -> 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."); @@ -129,7 +133,13 @@ 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") }; @@ -149,7 +159,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 +169,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); @@ -167,6 +179,7 @@ impl Window { context.make_not_current(); + debug!("Created window {:?}", context.window().id()); let window = Window { gl_context: RefCell::new(context), events_loop, @@ -474,10 +487,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(); } @@ -494,10 +509,9 @@ impl webxr::glwindow::GlWindow for Window { } fn new_window(&self) -> Result<Box<dyn webxr::glwindow::GlWindow>, ()> { - 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(), ))) } |