servo: Merge #11443 - Remove CompositorEventListener trait (from kyleheadley:remove_trait_11339); r=asajeffrey
authorKyle Headley <kyle.headley@colorado.edu>
Wed, 01 Jun 2016 14:06:41 -0500
changeset 338979 f3435c1e5d272176991d7755926390971c06a925
parent 338978 a531e404d2b3bf0d73d0b946cdce5ec651f08687
child 338980 e75065a3379c629fbac7395d1b6b7d7cd3c81c46
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasajeffrey
servo: Merge #11443 - Remove CompositorEventListener trait (from kyleheadley:remove_trait_11339); r=asajeffrey <!-- Please describe your changes on the following line: --> --- <!-- 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 fix #11339 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because refactoring <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: c641ec97f02bf03a97f3562b9d138b14ebe1406c
servo/components/compositing/compositor.rs
servo/components/compositing/compositor_thread.rs
servo/components/compositing/lib.rs
servo/components/servo/lib.rs
servo/components/servo/main.rs
servo/ports/cef/browser.rs
--- a/servo/components/compositing/compositor.rs
+++ b/servo/components/compositing/compositor.rs
@@ -1,18 +1,18 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 use CompositionPipeline;
 use SendableFrameTree;
 use app_units::Au;
 use compositor_layer::{CompositorData, CompositorLayer, RcCompositorLayer, WantsScrollEventsFlag};
-use compositor_thread::{CompositorEventListener, CompositorProxy};
-use compositor_thread::{CompositorReceiver, InitialCompositorState, Msg, RenderListener};
+use compositor_thread::{CompositorProxy, CompositorReceiver};
+use compositor_thread::{InitialCompositorState, Msg, RenderListener};
 use delayed_composition::DelayedCompositionTimerProxy;
 use euclid::point::TypedPoint2D;
 use euclid::rect::TypedRect;
 use euclid::scale_factor::ScaleFactor;
 use euclid::size::TypedSize2D;
 use euclid::{Matrix4D, Point2D, Rect, Size2D};
 use gfx::paint_thread::{ChromeToPaintMsg, PaintRequest};
 use gfx_traits::{ScrollPolicy, StackingContextId};
@@ -2496,41 +2496,18 @@ impl<Window: WindowMethods> IOCompositor
             Some(ref webrender) if webrender.layers_are_bouncing_back() => {}
             _ => return,
         }
 
         if let Some(ref webrender_api) = self.webrender_api {
             webrender_api.tick_scrolling_bounce_animations()
         }
     }
-}
 
-fn find_layer_with_pipeline_and_layer_id_for_layer(layer: Rc<Layer<CompositorData>>,
-                                                   pipeline_id: PipelineId,
-                                                   layer_id: LayerId)
-                                                   -> Option<Rc<Layer<CompositorData>>> {
-    if layer.extra_data.borrow().pipeline_id == pipeline_id &&
-       layer.extra_data.borrow().id == layer_id {
-        return Some(layer);
-    }
-
-    for kid in &*layer.children() {
-        let result = find_layer_with_pipeline_and_layer_id_for_layer(kid.clone(),
-                                                                     pipeline_id,
-                                                                     layer_id);
-        if result.is_some() {
-            return result;
-        }
-    }
-
-    None
-}
-
-impl<Window> CompositorEventListener for IOCompositor<Window> where Window: WindowMethods {
-    fn handle_events(&mut self, messages: Vec<WindowEvent>) -> bool {
+    pub fn handle_events(&mut self, messages: Vec<WindowEvent>) -> bool {
         // Check for new messages coming from the other threads in the system.
         while let Some(msg) = self.port.try_recv_compositor_msg() {
             if !self.handle_browser_message(msg) {
                 break
             }
         }
 
         if self.shutdown_state == ShutdownState::FinishedShuttingDown {
@@ -2563,17 +2540,17 @@ impl<Window> CompositorEventListener for
 
         self.shutdown_state != ShutdownState::FinishedShuttingDown
     }
 
     /// Repaints and recomposites synchronously. You must be careful when calling this, as if a
     /// paint is not scheduled the compositor will hang forever.
     ///
     /// This is used when resizing the window.
-    fn repaint_synchronously(&mut self) {
+    pub fn repaint_synchronously(&mut self) {
         if self.webrender.is_none() {
             while self.shutdown_state != ShutdownState::ShuttingDown {
                 let msg = self.port.recv_compositor_msg();
                 let received_new_buffers = match msg {
                     Msg::AssignPaintedBuffers(..) => true,
                     _ => false,
                 };
                 let keep_going = self.handle_browser_message(msg);
@@ -2599,32 +2576,53 @@ impl<Window> CompositorEventListener for
                 }
                 if !keep_going {
                     break
                 }
             }
         }
     }
 
-    fn pinch_zoom_level(&self) -> f32 {
+    pub fn pinch_zoom_level(&self) -> f32 {
         self.viewport_zoom.get() as f32
     }
 
-    fn title_for_main_frame(&self) {
+    pub fn title_for_main_frame(&self) {
         let root_pipeline_id = match self.root_pipeline {
             None => return,
             Some(ref root_pipeline) => root_pipeline.id,
         };
         let msg = ConstellationMsg::GetPipelineTitle(root_pipeline_id);
         if let Err(e) = self.constellation_chan.send(msg) {
             warn!("Failed to send pipeline title ({}).", e);
         }
     }
 }
 
+fn find_layer_with_pipeline_and_layer_id_for_layer(layer: Rc<Layer<CompositorData>>,
+                                                   pipeline_id: PipelineId,
+                                                   layer_id: LayerId)
+                                                   -> Option<Rc<Layer<CompositorData>>> {
+    if layer.extra_data.borrow().pipeline_id == pipeline_id &&
+       layer.extra_data.borrow().id == layer_id {
+        return Some(layer);
+    }
+
+    for kid in &*layer.children() {
+        let result = find_layer_with_pipeline_and_layer_id_for_layer(kid.clone(),
+                                                                     pipeline_id,
+                                                                     layer_id);
+        if result.is_some() {
+            return result;
+        }
+    }
+
+    None
+}
+
 /// Why we performed a composite. This is used for debugging.
 #[derive(Copy, Clone, PartialEq, Debug)]
 pub enum CompositingReason {
     /// We hit the delayed composition timeout. (See `delayed_composition.rs`.)
     DelayedCompositeTimeout,
     /// The window has been scrolled and we're starting the first recomposite.
     Scroll,
     /// A scroll has continued and we need to recomposite again.
--- a/servo/components/compositing/compositor_thread.rs
+++ b/servo/components/compositing/compositor_thread.rs
@@ -1,16 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 //! Communication with the compositor thread.
 
 use SendableFrameTree;
-use compositor::{self, CompositingReason};
+use compositor::{CompositingReason, IOCompositor};
 use euclid::point::Point2D;
 use euclid::size::Size2D;
 use gfx_traits::{Epoch, FrameTreeId, LayerId, LayerProperties, PaintListener};
 use ipc_channel::ipc::IpcSender;
 use layers::layers::{BufferRequest, LayerBufferSet};
 use layers::platform::surface::{NativeDisplay, NativeSurface};
 use msg::constellation_msg::{Image, Key, KeyModifiers, KeyState, PipelineId};
 use profile_traits::mem;
@@ -19,17 +19,17 @@ use script_traits::{AnimationState, Cons
 use std::fmt::{Debug, Error, Formatter};
 use std::rc::Rc;
 use std::sync::mpsc::{Receiver, Sender, channel};
 use style_traits::cursor::Cursor;
 use style_traits::viewport::ViewportConstraints;
 use url::Url;
 use webrender;
 use webrender_traits;
-use windowing::{WindowEvent, WindowMethods};
+use windowing::WindowMethods;
 
 /// Sends messages to the compositor. This is a trait supplied by the port because the method used
 /// to communicate with the compositor may have to kick OS event loops awake, communicate cross-
 /// process, and so forth.
 pub trait CompositorProxy : 'static + Send {
     /// Sends a message to the compositor.
     fn send(&self, msg: Msg);
     /// Clones the compositor proxy.
@@ -231,31 +231,22 @@ impl Debug for Msg {
     }
 }
 
 pub struct CompositorThread;
 
 impl CompositorThread {
     pub fn create<Window>(window: Rc<Window>,
                           state: InitialCompositorState)
-                          -> Box<CompositorEventListener + 'static>
+                          -> IOCompositor<Window>
                           where Window: WindowMethods + 'static {
-        box compositor::IOCompositor::create(window, state)
-            as Box<CompositorEventListener>
+        IOCompositor::create(window, state)
     }
 }
 
-pub trait CompositorEventListener {
-    fn handle_events(&mut self, events: Vec<WindowEvent>) -> bool;
-    fn repaint_synchronously(&mut self);
-    fn pinch_zoom_level(&self) -> f32;
-    /// Requests that the compositor send the title for the main frame as soon as possible.
-    fn title_for_main_frame(&self);
-}
-
 /// Data used to construct a compositor.
 pub struct InitialCompositorState {
     /// A channel to the compositor.
     pub sender: Box<CompositorProxy + Send>,
     /// A port on which messages inbound to the compositor can be received.
     pub receiver: Box<CompositorReceiver>,
     /// A channel to the constellation.
     pub constellation_chan: Sender<ConstellationMsg>,
--- a/servo/components/compositing/lib.rs
+++ b/servo/components/compositing/lib.rs
@@ -31,17 +31,18 @@ extern crate script_traits;
 extern crate style_traits;
 extern crate time;
 extern crate url;
 #[macro_use]
 extern crate util;
 extern crate webrender;
 extern crate webrender_traits;
 
-pub use compositor_thread::{CompositorEventListener, CompositorProxy, CompositorThread};
+pub use compositor_thread::{CompositorProxy, CompositorThread};
+pub use compositor::IOCompositor;
 use euclid::size::TypedSize2D;
 use gfx::paint_thread::ChromeToPaintMsg;
 use ipc_channel::ipc::IpcSender;
 use msg::constellation_msg::PipelineId;
 use script_traits::{ConstellationControlMsg, LayoutControlMsg};
 use std::sync::mpsc::Sender;
 use util::geometry::PagePx;
 
--- a/servo/components/servo/lib.rs
+++ b/servo/components/servo/lib.rs
@@ -52,21 +52,20 @@ extern crate webrender_traits;
 #[cfg(feature = "webdriver")]
 fn webdriver(port: u16, constellation: Sender<ConstellationMsg>) {
     webdriver_server::start_server(port, constellation);
 }
 
 #[cfg(not(feature = "webdriver"))]
 fn webdriver(_port: u16, _constellation: Sender<ConstellationMsg>) { }
 
-use compositing::CompositorEventListener;
 use compositing::compositor_thread::InitialCompositorState;
 use compositing::windowing::WindowEvent;
 use compositing::windowing::WindowMethods;
-use compositing::{CompositorProxy, CompositorThread};
+use compositing::{CompositorProxy, CompositorThread, IOCompositor};
 #[cfg(not(target_os = "windows"))]
 use constellation::content_process_sandbox_profile;
 use constellation::{Constellation, InitialConstellationState, UnprivilegedPipelineContent};
 #[cfg(not(target_os = "windows"))]
 use gaol::sandbox::{ChildSandbox, ChildSandboxMethods};
 use gfx::font_cache_thread::FontCacheThread;
 use ipc_channel::ipc::{self, IpcSender};
 use net::bluetooth_thread::BluetoothThreadFactory;
@@ -92,23 +91,22 @@ pub use gleam::gl;
 /// orchestrating the interaction between JavaScript, CSS layout,
 /// rendering, and the client window.
 ///
 /// Clients create a `Browser` for a given reference-counted type
 /// implementing `WindowMethods`, which is the bridge to whatever
 /// application Servo is embedded in. Clients then create an event
 /// loop to pump messages between the embedding application and
 /// various browser components.
-pub struct Browser {
-    compositor: Box<CompositorEventListener + 'static>,
+pub struct Browser<Window: WindowMethods + 'static> {
+    compositor: IOCompositor<Window>,
 }
 
-impl Browser {
-    pub fn new<Window>(window: Rc<Window>) -> Browser
-                       where Window: WindowMethods + 'static {
+impl<Window> Browser<Window> where Window: WindowMethods + 'static {
+    pub fn new(window: Rc<Window>) -> Browser<Window> {
         // Global configuration options, parsed from the command line.
         let opts = opts::get();
 
         script::init();
 
         // Get both endpoints of a special channel for communication between
         // the client window and the compositor. This channel is unique because
         // messages to client may need to pump a platform-specific event loop
--- a/servo/components/servo/main.rs
+++ b/servo/components/servo/main.rs
@@ -93,17 +93,17 @@ fn register_glutin_resize_handler(window
 
 fn unregister_glutin_resize_handler(window: &Rc<app::window::Window>) {
     unsafe {
         window.remove_nested_event_loop_listener();
     }
 }
 
 struct BrowserWrapper {
-    browser: Browser,
+    browser: Browser<app::window::Window>,
 }
 
 impl app::NestedEventLoopListener for BrowserWrapper {
     fn handle_event_from_nested_event_loop(&mut self, event: WindowEvent) -> bool {
         let is_resize = match event {
             WindowEvent::Resize(..) => true,
             _ => false,
         };
--- a/servo/ports/cef/browser.rs
+++ b/servo/ports/cef/browser.rs
@@ -22,18 +22,18 @@ use std::ptr;
 use std::rc::Rc;
 use std::sync::atomic::{AtomicIsize, Ordering};
 
 thread_local!(pub static ID_COUNTER: AtomicIsize = AtomicIsize::new(0));
 thread_local!(pub static BROWSERS: RefCell<Vec<CefBrowser>> = RefCell::new(vec!()));
 
 pub enum ServoBrowser {
     Invalid,
-    OnScreen(Browser),
-    OffScreen(Browser),
+    OnScreen(Browser<glutin_app::window::Window>),
+    OffScreen(Browser<window::Window>),
 }
 
 impl ServoBrowser {
     fn handle_event(&mut self, event: WindowEvent) {
         match *self {
             ServoBrowser::OnScreen(ref mut browser) => { browser.handle_events(vec![event]); }
             ServoBrowser::OffScreen(ref mut browser) => { browser.handle_events(vec![event]); }
             ServoBrowser::Invalid => {}