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::browser::Browser;
|
||||||
use crate::embedder::EmbedderCallbacks;
|
use crate::embedder::EmbedderCallbacks;
|
||||||
use crate::window_trait::WindowPortsMethods;
|
|
||||||
use crate::events_loop::EventsLoop;
|
use crate::events_loop::EventsLoop;
|
||||||
|
use crate::window_trait::WindowPortsMethods;
|
||||||
use crate::{headed_window, headless_window};
|
use crate::{headed_window, headless_window};
|
||||||
use glutin::WindowId;
|
use glutin::WindowId;
|
||||||
use servo::compositing::windowing::WindowEvent;
|
use servo::compositing::windowing::WindowEvent;
|
||||||
|
@ -34,14 +34,20 @@ pub struct App {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl App {
|
||||||
pub fn run() {
|
pub fn run(angle: bool, enable_vsync: bool) {
|
||||||
let events_loop = EventsLoop::new(opts::get().headless);
|
let events_loop = EventsLoop::new(opts::get().headless);
|
||||||
|
|
||||||
// Implements window methods, used by compositor.
|
// Implements window methods, used by compositor.
|
||||||
let window = if opts::get().headless {
|
let window = if opts::get().headless {
|
||||||
headless_window::Window::new(opts::get().initial_window_size)
|
headless_window::Window::new(opts::get().initial_window_size)
|
||||||
} else {
|
} 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.
|
// Implements embedder methods, used by libservo and constellation.
|
||||||
|
@ -49,6 +55,7 @@ impl App {
|
||||||
window.clone(),
|
window.clone(),
|
||||||
events_loop.clone(),
|
events_loop.clone(),
|
||||||
window.gl(),
|
window.gl(),
|
||||||
|
angle,
|
||||||
));
|
));
|
||||||
|
|
||||||
// Handle browser state.
|
// Handle browser state.
|
||||||
|
@ -110,7 +117,7 @@ impl App {
|
||||||
};
|
};
|
||||||
window.winit_event_to_servo_event(event);
|
window.winit_event_to_servo_event(event);
|
||||||
return cont;
|
return cont;
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -121,7 +128,10 @@ impl App {
|
||||||
fn run_loop(self) {
|
fn run_loop(self) {
|
||||||
loop {
|
loop {
|
||||||
let animating = WINDOWS.with(|windows| {
|
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 !animating || self.suspended.get() {
|
||||||
// If there's no animations running then we block on the window event loop.
|
// 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 {
|
pub fn gl_version(angle: bool) -> glutin::GlRequest {
|
||||||
if opts::get().angle {
|
if angle {
|
||||||
glutin::GlRequest::Specific(glutin::Api::OpenGlEs, (3, 0))
|
glutin::GlRequest::Specific(glutin::Api::OpenGlEs, (3, 0))
|
||||||
} else {
|
} else {
|
||||||
glutin::GlRequest::GlThenGles {
|
glutin::GlRequest::GlThenGles {
|
||||||
|
|
|
@ -9,8 +9,8 @@ use crate::events_loop::EventsLoop;
|
||||||
use crate::window_trait::WindowPortsMethods;
|
use crate::window_trait::WindowPortsMethods;
|
||||||
use gleam::gl;
|
use gleam::gl;
|
||||||
use glutin;
|
use glutin;
|
||||||
use glutin::EventsLoopClosed;
|
|
||||||
use glutin::dpi::LogicalSize;
|
use glutin::dpi::LogicalSize;
|
||||||
|
use glutin::EventsLoopClosed;
|
||||||
use rust_webvr::GlWindowVRService;
|
use rust_webvr::GlWindowVRService;
|
||||||
use servo::compositing::windowing::EmbedderMethods;
|
use servo::compositing::windowing::EmbedderMethods;
|
||||||
use servo::embedder_traits::EventLoopWaker;
|
use servo::embedder_traits::EventLoopWaker;
|
||||||
|
@ -24,15 +24,22 @@ pub struct EmbedderCallbacks {
|
||||||
window: Rc<dyn WindowPortsMethods>,
|
window: Rc<dyn WindowPortsMethods>,
|
||||||
events_loop: Rc<RefCell<EventsLoop>>,
|
events_loop: Rc<RefCell<EventsLoop>>,
|
||||||
gl: Rc<dyn gl::Gl>,
|
gl: Rc<dyn gl::Gl>,
|
||||||
|
angle: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EmbedderCallbacks {
|
impl EmbedderCallbacks {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
window: Rc<dyn WindowPortsMethods>,
|
window: Rc<dyn WindowPortsMethods>,
|
||||||
events_loop: Rc<RefCell<EventsLoop>>,
|
events_loop: Rc<RefCell<EventsLoop>>,
|
||||||
gl: Rc<dyn gl::Gl>
|
gl: Rc<dyn gl::Gl>,
|
||||||
|
angle: bool,
|
||||||
) -> EmbedderCallbacks {
|
) -> 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 size = LogicalSize::new(size.width, size.height);
|
||||||
let events_loop_clone = self.events_loop.clone();
|
let events_loop_clone = self.events_loop.clone();
|
||||||
let events_loop_factory = Box::new(move || {
|
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()
|
let window_builder = glutin::WindowBuilder::new()
|
||||||
.with_title(name.clone())
|
.with_title(name.clone())
|
||||||
|
@ -63,12 +73,13 @@ impl EmbedderMethods for EmbedderCallbacks {
|
||||||
.with_visibility(false)
|
.with_visibility(false)
|
||||||
.with_multitouch();
|
.with_multitouch();
|
||||||
let context = glutin::ContextBuilder::new()
|
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
|
.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())
|
.build_windowed(window_builder, &*self.events_loop.borrow().as_winit())
|
||||||
.expect("Failed to create window.");
|
.expect("Failed to create window.");
|
||||||
let gl = self.gl.clone();
|
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));
|
services.register(Box::new(service));
|
||||||
heartbeats.push(Box::new(heartbeat));
|
heartbeats.push(Box::new(heartbeat));
|
||||||
|
|
|
@ -71,6 +71,8 @@ pub struct Window {
|
||||||
fullscreen: Cell<bool>,
|
fullscreen: Cell<bool>,
|
||||||
gl: Rc<dyn gl::Gl>,
|
gl: Rc<dyn gl::Gl>,
|
||||||
xr_rotation: Cell<Rotation3D<f32, UnknownUnit, UnknownUnit>>,
|
xr_rotation: Cell<Rotation3D<f32, UnknownUnit, UnknownUnit>>,
|
||||||
|
angle: bool,
|
||||||
|
enable_vsync: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
@ -90,6 +92,8 @@ impl Window {
|
||||||
win_size: Size2D<u32, DeviceIndependentPixel>,
|
win_size: Size2D<u32, DeviceIndependentPixel>,
|
||||||
sharing: Option<&Window>,
|
sharing: Option<&Window>,
|
||||||
events_loop: Rc<RefCell<EventsLoop>>,
|
events_loop: Rc<RefCell<EventsLoop>>,
|
||||||
|
angle: bool,
|
||||||
|
enable_vsync: bool,
|
||||||
) -> Window {
|
) -> Window {
|
||||||
let opts = opts::get();
|
let opts = opts::get();
|
||||||
|
|
||||||
|
@ -114,8 +118,8 @@ impl Window {
|
||||||
window_builder = builder_with_platform_options(window_builder);
|
window_builder = builder_with_platform_options(window_builder);
|
||||||
|
|
||||||
let mut context_builder = glutin::ContextBuilder::new()
|
let mut context_builder = glutin::ContextBuilder::new()
|
||||||
.with_gl(app::gl_version())
|
.with_gl(app::gl_version(angle))
|
||||||
.with_vsync(opts.enable_vsync);
|
.with_vsync(enable_vsync);
|
||||||
|
|
||||||
if opts.use_msaa {
|
if opts.use_msaa {
|
||||||
context_builder = context_builder.with_multisampling(MULTISAMPLES)
|
context_builder = context_builder.with_multisampling(MULTISAMPLES)
|
||||||
|
@ -198,6 +202,8 @@ impl Window {
|
||||||
primary_monitor,
|
primary_monitor,
|
||||||
screen_size,
|
screen_size,
|
||||||
xr_rotation: Cell::new(Rotation3D::identity()),
|
xr_rotation: Cell::new(Rotation3D::identity()),
|
||||||
|
angle,
|
||||||
|
enable_vsync,
|
||||||
};
|
};
|
||||||
|
|
||||||
window.present();
|
window.present();
|
||||||
|
@ -545,6 +551,8 @@ impl webxr::glwindow::GlWindow for Window {
|
||||||
self.inner_size.get(),
|
self.inner_size.get(),
|
||||||
Some(self),
|
Some(self),
|
||||||
self.events_loop.clone(),
|
self.events_loop.clone(),
|
||||||
|
self.angle,
|
||||||
|
self.enable_vsync,
|
||||||
));
|
));
|
||||||
app::register_window(window.clone());
|
app::register_window(window.clone());
|
||||||
Ok(window)
|
Ok(window)
|
||||||
|
|
|
@ -128,7 +128,7 @@ pub fn main() {
|
||||||
process::exit(0);
|
process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
App::run();
|
App::run(opts::get().angle, opts::get().enable_vsync);
|
||||||
|
|
||||||
platform::deinit()
|
platform::deinit()
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ pub mod gl_glue;
|
||||||
|
|
||||||
pub use servo::script_traits::MouseButton;
|
pub use servo::script_traits::MouseButton;
|
||||||
|
|
||||||
|
use getopts::Options;
|
||||||
use servo::compositing::windowing::{
|
use servo::compositing::windowing::{
|
||||||
AnimationState, EmbedderCoordinates, EmbedderMethods, MouseWindowEvent, WindowEvent,
|
AnimationState, EmbedderCoordinates, EmbedderMethods, MouseWindowEvent, WindowEvent,
|
||||||
WindowMethods,
|
WindowMethods,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue