mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
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 -->
This commit is contained in:
commit
de89b09f68
2 changed files with 27 additions and 6 deletions
|
@ -35,6 +35,13 @@ impl GlContext {
|
||||||
*self = match std::mem::replace(self, GlContext::None) {
|
*self = match std::mem::replace(self, GlContext::None) {
|
||||||
GlContext::Current(c) => {
|
GlContext::Current(c) => {
|
||||||
warn!("Making an already current context current");
|
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::Current(c)
|
||||||
},
|
},
|
||||||
GlContext::NotCurrent(c) => {
|
GlContext::NotCurrent(c) => {
|
||||||
|
|
|
@ -85,7 +85,7 @@ fn window_creation_scale_factor() -> Scale<f32, DeviceIndependentPixel, DevicePi
|
||||||
impl Window {
|
impl Window {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
win_size: Size2D<u32, DeviceIndependentPixel>,
|
win_size: Size2D<u32, DeviceIndependentPixel>,
|
||||||
sharing: Option<&GlContext>,
|
sharing: Option<&Window>,
|
||||||
events_loop: Rc<RefCell<EventsLoop>>,
|
events_loop: Rc<RefCell<EventsLoop>>,
|
||||||
) -> Window {
|
) -> Window {
|
||||||
let opts = opts::get();
|
let opts = opts::get();
|
||||||
|
@ -119,7 +119,11 @@ impl Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
let context = match sharing {
|
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()),
|
None => context_builder.build_windowed(window_builder, events_loop.borrow().as_winit()),
|
||||||
}.expect("Failed to create window.");
|
}.expect("Failed to create window.");
|
||||||
|
|
||||||
|
@ -129,7 +133,13 @@ impl Window {
|
||||||
context.window().set_window_icon(Some(load_icon(icon_bytes)));
|
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 {
|
let context = unsafe {
|
||||||
|
debug!("Making window {:?} current", context.window().id());
|
||||||
context.make_current().expect("Couldn't make window current")
|
context.make_current().expect("Couldn't make window current")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -149,7 +159,9 @@ impl Window {
|
||||||
|
|
||||||
context.window().show();
|
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 {
|
Api::OpenGl => unsafe {
|
||||||
gl::GlFns::load_with(|s| context.get_proc_address(s) as *const _)
|
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 _)
|
gl::GlesFns::load_with(|s| context.get_proc_address(s) as *const _)
|
||||||
},
|
},
|
||||||
Api::WebGl => unreachable!("webgl is unsupported"),
|
Api::WebGl => unreachable!("webgl is unsupported"),
|
||||||
};
|
} };
|
||||||
|
|
||||||
gl.clear_color(0.6, 0.6, 0.6, 1.0);
|
gl.clear_color(0.6, 0.6, 0.6, 1.0);
|
||||||
gl.clear(gl::COLOR_BUFFER_BIT);
|
gl.clear(gl::COLOR_BUFFER_BIT);
|
||||||
|
@ -167,6 +179,7 @@ impl Window {
|
||||||
|
|
||||||
context.make_not_current();
|
context.make_not_current();
|
||||||
|
|
||||||
|
debug!("Created window {:?}", context.window().id());
|
||||||
let window = Window {
|
let window = Window {
|
||||||
gl_context: RefCell::new(context),
|
gl_context: RefCell::new(context),
|
||||||
events_loop,
|
events_loop,
|
||||||
|
@ -474,10 +487,12 @@ impl WindowPortsMethods for Window {
|
||||||
|
|
||||||
impl webxr::glwindow::GlWindow for Window {
|
impl webxr::glwindow::GlWindow for Window {
|
||||||
fn make_current(&mut self) {
|
fn make_current(&mut self) {
|
||||||
|
debug!("Making window {:?} current", self.gl_context.borrow().window().id());
|
||||||
self.gl_context.get_mut().make_current();
|
self.gl_context.get_mut().make_current();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn swap_buffers(&mut self) {
|
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().swap_buffers();
|
||||||
self.gl_context.get_mut().make_not_current();
|
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>, ()> {
|
fn new_window(&self) -> Result<Box<dyn webxr::glwindow::GlWindow>, ()> {
|
||||||
let gl_context = self.gl_context.borrow();
|
|
||||||
Ok(Box::new(Window::new(
|
Ok(Box::new(Window::new(
|
||||||
self.inner_size.get(),
|
self.inner_size.get(),
|
||||||
Some(&*gl_context),
|
Some(self),
|
||||||
self.events_loop.clone(),
|
self.events_loop.clone(),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue