Auto merge of #23233 - paulrouget:glutin-port-refactoring, r=jdm

Glutin port refactoring

Glutin port refactoring in preparation for the compositor and libservo refactoring.

In theory, the only behavior change is for headless mode. The headless event loop now uses winit's event loop (but still headless).

Notes:
- headless and glutin window implementations are now separated
- I split the methods of the embedder in 2: window specific and general methods. In the future, we still want the app to run even without a window or with multiple windows

<!-- 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/23233)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2019-04-29 10:45:29 -04:00 committed by GitHub
commit a9f7b13230
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 1287 additions and 1067 deletions

View file

@ -103,7 +103,7 @@ impl FrameTreeId {
enum LayerPixel {}
/// NB: Never block on the constellation, because sometimes the constellation blocks on us.
pub struct IOCompositor<Window: WindowMethods> {
pub struct IOCompositor<Window: WindowMethods + ?Sized> {
/// The application window.
pub window: Rc<Window>,
@ -258,7 +258,7 @@ enum CompositeTarget {
PngFile,
}
impl<Window: WindowMethods> IOCompositor<Window> {
impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
fn new(window: Rc<Window>, state: InitialCompositorState) -> Self {
let composite_target = match opts::get().output_file {
Some(_) => CompositeTarget::PngFile,

View file

@ -148,8 +148,6 @@ pub trait WindowMethods {
/// Return the GL function pointer trait.
#[cfg(feature = "gl")]
fn gl(&self) -> Rc<dyn gl::Gl>;
/// Returns a thread-safe object to wake up the window's event loop.
fn create_event_loop_waker(&self) -> Box<dyn EventLoopWaker>;
/// Get the coordinates of the native window, the screen and the framebuffer.
fn get_coordinates(&self) -> EmbedderCoordinates;
/// Set whether the application is currently animating.
@ -157,6 +155,11 @@ pub trait WindowMethods {
/// will want to avoid blocking on UI events, and just
/// run the event loop at the vsync interval.
fn set_animation_state(&self, _state: AnimationState);
}
pub trait EmbedderMethods {
/// Returns a thread-safe object to wake up the window's event loop.
fn create_event_loop_waker(&self) -> Box<dyn EventLoopWaker>;
/// Register services with a VRServiceManager.
fn register_vr_services(
&self,

View file

@ -67,7 +67,7 @@ use canvas::webgl_thread::WebGLThreads;
use compositing::compositor_thread::{
CompositorProxy, CompositorReceiver, InitialCompositorState, Msg,
};
use compositing::windowing::{WindowEvent, WindowMethods};
use compositing::windowing::{EmbedderMethods, WindowEvent, WindowMethods};
use compositing::{CompositingReason, IOCompositor, ShutdownState};
#[cfg(all(
not(target_os = "windows"),
@ -148,7 +148,7 @@ type MediaBackend = media_platform::MediaBackend;
/// application Servo is embedded in. Clients then create an event
/// loop to pump messages between the embedding application and
/// various browser components.
pub struct Servo<Window: WindowMethods + 'static> {
pub struct Servo<Window: WindowMethods + 'static + ?Sized> {
compositor: IOCompositor<Window>,
constellation_chan: Sender<ConstellationMsg>,
embedder_receiver: EmbedderReceiver,
@ -197,9 +197,9 @@ impl webrender_api::RenderNotifier for RenderNotifier {
impl<Window> Servo<Window>
where
Window: WindowMethods + 'static,
Window: WindowMethods + 'static + ?Sized,
{
pub fn new(window: Rc<Window>) -> Servo<Window> {
pub fn new(embedder: Box<EmbedderMethods>, window: Rc<Window>) -> Servo<Window> {
// Global configuration options, parsed from the command line.
let opts = opts::get();
@ -218,9 +218,9 @@ where
// messages to client may need to pump a platform-specific event loop
// to deliver the message.
let (compositor_proxy, compositor_receiver) =
create_compositor_channel(window.create_event_loop_waker());
create_compositor_channel(embedder.create_event_loop_waker());
let (embedder_proxy, embedder_receiver) =
create_embedder_channel(window.create_event_loop_waker());
create_embedder_channel(embedder.create_event_loop_waker());
let time_profiler_chan = profile_time::Profiler::create(
&opts.time_profiling,
opts.time_profiler_trace_path.clone(),
@ -288,7 +288,7 @@ where
let webvr_services = if pref!(dom.webvr.enabled) {
let mut services = VRServiceManager::new();
services.register_defaults();
window.register_vr_services(&mut services, &mut webvr_heartbeats);
embedder.register_vr_services(&mut services, &mut webvr_heartbeats);
Some(services)
} else {
None