mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Remove some global options access within glutin
Removed opts::get() access for the two glutin specific options: angle and disable-vsync. This is the first step in a refactoring to separate these two options from the global options.
This commit is contained in:
parent
927dfd15bf
commit
24b8408916
5 changed files with 46 additions and 16 deletions
|
@ -6,8 +6,8 @@
|
|||
|
||||
use crate::browser::Browser;
|
||||
use crate::embedder::EmbedderCallbacks;
|
||||
use crate::window_trait::WindowPortsMethods;
|
||||
use crate::events_loop::EventsLoop;
|
||||
use crate::window_trait::WindowPortsMethods;
|
||||
use crate::{headed_window, headless_window};
|
||||
use glutin::WindowId;
|
||||
use servo::compositing::windowing::WindowEvent;
|
||||
|
@ -34,14 +34,20 @@ pub struct App {
|
|||
}
|
||||
|
||||
impl App {
|
||||
pub fn run() {
|
||||
pub fn run(angle: bool, enable_vsync: bool) {
|
||||
let events_loop = EventsLoop::new(opts::get().headless);
|
||||
|
||||
// Implements window methods, used by compositor.
|
||||
let window = if opts::get().headless {
|
||||
headless_window::Window::new(opts::get().initial_window_size)
|
||||
} else {
|
||||
Rc::new(headed_window::Window::new(opts::get().initial_window_size, None, events_loop.clone()))
|
||||
Rc::new(headed_window::Window::new(
|
||||
opts::get().initial_window_size,
|
||||
None,
|
||||
events_loop.clone(),
|
||||
angle,
|
||||
enable_vsync,
|
||||
))
|
||||
};
|
||||
|
||||
// Implements embedder methods, used by libservo and constellation.
|
||||
|
@ -49,6 +55,7 @@ impl App {
|
|||
window.clone(),
|
||||
events_loop.clone(),
|
||||
window.gl(),
|
||||
angle,
|
||||
));
|
||||
|
||||
// Handle browser state.
|
||||
|
@ -110,7 +117,7 @@ impl App {
|
|||
};
|
||||
window.winit_event_to_servo_event(event);
|
||||
return cont;
|
||||
}
|
||||
},
|
||||
}
|
||||
});
|
||||
},
|
||||
|
@ -121,7 +128,10 @@ impl App {
|
|||
fn run_loop(self) {
|
||||
loop {
|
||||
let animating = WINDOWS.with(|windows| {
|
||||
windows.borrow().iter().any(|(_, window)| window.is_animating())
|
||||
windows
|
||||
.borrow()
|
||||
.iter()
|
||||
.any(|(_, window)| window.is_animating())
|
||||
});
|
||||
if !animating || self.suspended.get() {
|
||||
// If there's no animations running then we block on the window event loop.
|
||||
|
@ -219,8 +229,8 @@ pub fn register_window(window: Rc<dyn WindowPortsMethods>) {
|
|||
});
|
||||
}
|
||||
|
||||
pub fn gl_version() -> glutin::GlRequest {
|
||||
if opts::get().angle {
|
||||
pub fn gl_version(angle: bool) -> glutin::GlRequest {
|
||||
if angle {
|
||||
glutin::GlRequest::Specific(glutin::Api::OpenGlEs, (3, 0))
|
||||
} else {
|
||||
glutin::GlRequest::GlThenGles {
|
||||
|
|
|
@ -9,8 +9,8 @@ use crate::events_loop::EventsLoop;
|
|||
use crate::window_trait::WindowPortsMethods;
|
||||
use gleam::gl;
|
||||
use glutin;
|
||||
use glutin::EventsLoopClosed;
|
||||
use glutin::dpi::LogicalSize;
|
||||
use glutin::EventsLoopClosed;
|
||||
use rust_webvr::GlWindowVRService;
|
||||
use servo::compositing::windowing::EmbedderMethods;
|
||||
use servo::embedder_traits::EventLoopWaker;
|
||||
|
@ -24,15 +24,22 @@ pub struct EmbedderCallbacks {
|
|||
window: Rc<dyn WindowPortsMethods>,
|
||||
events_loop: Rc<RefCell<EventsLoop>>,
|
||||
gl: Rc<dyn gl::Gl>,
|
||||
angle: bool,
|
||||
}
|
||||
|
||||
impl EmbedderCallbacks {
|
||||
pub fn new(
|
||||
window: Rc<dyn WindowPortsMethods>,
|
||||
events_loop: Rc<RefCell<EventsLoop>>,
|
||||
gl: Rc<dyn gl::Gl>
|
||||
gl: Rc<dyn gl::Gl>,
|
||||
angle: bool,
|
||||
) -> EmbedderCallbacks {
|
||||
EmbedderCallbacks { window, events_loop, gl }
|
||||
EmbedderCallbacks {
|
||||
window,
|
||||
events_loop,
|
||||
gl,
|
||||
angle,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,7 +62,10 @@ impl EmbedderMethods for EmbedderCallbacks {
|
|||
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)
|
||||
events_loop_clone
|
||||
.borrow_mut()
|
||||
.take()
|
||||
.ok_or(EventsLoopClosed)
|
||||
});
|
||||
let window_builder = glutin::WindowBuilder::new()
|
||||
.with_title(name.clone())
|
||||
|
@ -63,12 +73,13 @@ impl EmbedderMethods for EmbedderCallbacks {
|
|||
.with_visibility(false)
|
||||
.with_multitouch();
|
||||
let context = glutin::ContextBuilder::new()
|
||||
.with_gl(app::gl_version())
|
||||
.with_gl(app::gl_version(self.angle))
|
||||
.with_vsync(false) // Assume the browser vsync is the same as the test VR window vsync
|
||||
.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, events_loop_factory, gl);
|
||||
let (service, heartbeat) =
|
||||
GlWindowVRService::new(name, context, events_loop_factory, gl);
|
||||
|
||||
services.register(Box::new(service));
|
||||
heartbeats.push(Box::new(heartbeat));
|
||||
|
|
|
@ -71,6 +71,8 @@ pub struct Window {
|
|||
fullscreen: Cell<bool>,
|
||||
gl: Rc<dyn gl::Gl>,
|
||||
xr_rotation: Cell<Rotation3D<f32, UnknownUnit, UnknownUnit>>,
|
||||
angle: bool,
|
||||
enable_vsync: bool,
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
|
@ -90,6 +92,8 @@ impl Window {
|
|||
win_size: Size2D<u32, DeviceIndependentPixel>,
|
||||
sharing: Option<&Window>,
|
||||
events_loop: Rc<RefCell<EventsLoop>>,
|
||||
angle: bool,
|
||||
enable_vsync: bool,
|
||||
) -> Window {
|
||||
let opts = opts::get();
|
||||
|
||||
|
@ -114,8 +118,8 @@ impl Window {
|
|||
window_builder = builder_with_platform_options(window_builder);
|
||||
|
||||
let mut context_builder = glutin::ContextBuilder::new()
|
||||
.with_gl(app::gl_version())
|
||||
.with_vsync(opts.enable_vsync);
|
||||
.with_gl(app::gl_version(angle))
|
||||
.with_vsync(enable_vsync);
|
||||
|
||||
if opts.use_msaa {
|
||||
context_builder = context_builder.with_multisampling(MULTISAMPLES)
|
||||
|
@ -198,6 +202,8 @@ impl Window {
|
|||
primary_monitor,
|
||||
screen_size,
|
||||
xr_rotation: Cell::new(Rotation3D::identity()),
|
||||
angle,
|
||||
enable_vsync,
|
||||
};
|
||||
|
||||
window.present();
|
||||
|
@ -545,6 +551,8 @@ impl webxr::glwindow::GlWindow for Window {
|
|||
self.inner_size.get(),
|
||||
Some(self),
|
||||
self.events_loop.clone(),
|
||||
self.angle,
|
||||
self.enable_vsync,
|
||||
));
|
||||
app::register_window(window.clone());
|
||||
Ok(window)
|
||||
|
|
|
@ -128,7 +128,7 @@ pub fn main() {
|
|||
process::exit(0);
|
||||
}
|
||||
|
||||
App::run();
|
||||
App::run(opts::get().angle, opts::get().enable_vsync);
|
||||
|
||||
platform::deinit()
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ pub mod gl_glue;
|
|||
|
||||
pub use servo::script_traits::MouseButton;
|
||||
|
||||
use getopts::Options;
|
||||
use servo::compositing::windowing::{
|
||||
AnimationState, EmbedderCoordinates, EmbedderMethods, MouseWindowEvent, WindowEvent,
|
||||
WindowMethods,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue