diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index 7b0314e0d54..628dff1fb9e 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -3,7 +3,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use compositor_layer::{CompositorData, CompositorLayer, WantsScrollEventsFlag}; -use compositor_task::{CompositorEventListener, CompositorProxy, CompositorReceiver, Msg}; +use compositor_task::{CompositorEventListener, CompositorProxy}; +use compositor_task::{CompositorReceiver, InitialCompositorState, Msg}; use constellation::SendableFrameTree; use pipeline::CompositionPipeline; use scrolling::ScrollingTimerProxy; @@ -248,23 +249,19 @@ pub fn reporter_name() -> String { } impl IOCompositor { - fn new(window: Rc, - sender: Box, - receiver: Box, - constellation_chan: ConstellationChan, - time_profiler_chan: time::ProfilerChan, - mem_profiler_chan: mem::ProfilerChan) + fn new(window: Rc, state: InitialCompositorState) -> IOCompositor { // Register this thread as a memory reporter, via its own channel. let (reporter_sender, reporter_receiver) = ipc::channel().unwrap(); - let compositor_proxy_for_memory_reporter = sender.clone_compositor_proxy(); + let compositor_proxy_for_memory_reporter = state.sender.clone_compositor_proxy(); ROUTER.add_route(reporter_receiver.to_opaque(), box move |reporter_request| { let reporter_request: ReporterRequest = reporter_request.to().unwrap(); compositor_proxy_for_memory_reporter.send(Msg::CollectMemoryReports( reporter_request.reports_channel)); }); let reporter = Reporter(reporter_sender); - mem_profiler_chan.send(mem::ProfilerMsg::RegisterReporter(reporter_name(), reporter)); + state.mem_profiler_chan.send( + mem::ProfilerMsg::RegisterReporter(reporter_name(), reporter)); let window_size = window.framebuffer_size(); let hidpi_factor = window.hidpi_factor(); @@ -276,7 +273,7 @@ impl IOCompositor { IOCompositor { window: window, native_display: native_display, - port: receiver, + port: state.receiver, context: None, root_pipeline: None, pipeline_details: HashMap::new(), @@ -286,8 +283,8 @@ impl IOCompositor { }), window_size: window_size, hidpi_factor: hidpi_factor, - channel_to_self: sender.clone_compositor_proxy(), - scrolling_timer: ScrollingTimerProxy::new(sender), + channel_to_self: state.sender.clone_compositor_proxy(), + scrolling_timer: ScrollingTimerProxy::new(state.sender), composition_request: CompositionRequest::NoCompositingNecessary, pending_scroll_events: Vec::new(), composite_target: composite_target, @@ -300,9 +297,9 @@ impl IOCompositor { zoom_time: 0f64, got_load_complete_message: false, frame_tree_id: FrameTreeId(0), - constellation_chan: constellation_chan, - time_profiler_chan: time_profiler_chan, - mem_profiler_chan: mem_profiler_chan, + constellation_chan: state.constellation_chan, + time_profiler_chan: state.time_profiler_chan, + mem_profiler_chan: state.mem_profiler_chan, fragment_point: None, last_composite_time: 0, has_seen_quit_event: false, @@ -311,19 +308,9 @@ impl IOCompositor { } } - pub fn create(window: Rc, - sender: Box, - receiver: Box, - constellation_chan: ConstellationChan, - time_profiler_chan: time::ProfilerChan, - mem_profiler_chan: mem::ProfilerChan) + pub fn create(window: Rc, state: InitialCompositorState) -> IOCompositor { - let mut compositor = IOCompositor::new(window, - sender, - receiver, - constellation_chan, - time_profiler_chan, - mem_profiler_chan); + let mut compositor = IOCompositor::new(window, state); // Set the size of the root layer. compositor.update_zoom_transform(); diff --git a/components/compositing/compositor_task.rs b/components/compositing/compositor_task.rs index 56f007d8fa1..eaf0645d2df 100644 --- a/components/compositing/compositor_task.rs +++ b/components/compositing/compositor_task.rs @@ -260,28 +260,16 @@ pub struct CompositorTask; impl CompositorTask { pub fn create(window: Option>, - sender: Box, - receiver: Box, - constellation_chan: ConstellationChan, - time_profiler_chan: time::ProfilerChan, - mem_profiler_chan: mem::ProfilerChan) + state: InitialCompositorState) -> Box where Window: WindowMethods + 'static { match window { Some(window) => { - box compositor::IOCompositor::create(window, - sender, - receiver, - constellation_chan, - time_profiler_chan, - mem_profiler_chan) + box compositor::IOCompositor::create(window, state) as Box } None => { - box headless::NullCompositor::create(receiver, - constellation_chan, - time_profiler_chan, - mem_profiler_chan) + box headless::NullCompositor::create(state) as Box } } @@ -296,3 +284,17 @@ pub trait CompositorEventListener { /// 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, + /// A port on which messages inbound to the compositor can be received. + pub receiver: Box, + /// A channel to the constellation. + pub constellation_chan: ConstellationChan, + /// A channel to the time profiler thread. + pub time_profiler_chan: time::ProfilerChan, + /// A channel to the memory profiler thread. + pub mem_profiler_chan: mem::ProfilerChan, +} diff --git a/components/compositing/headless.rs b/components/compositing/headless.rs index 0fa3ad5d04b..c5216152095 100644 --- a/components/compositing/headless.rs +++ b/components/compositing/headless.rs @@ -2,7 +2,8 @@ * 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 compositor_task::{CompositorEventListener, CompositorReceiver, Msg}; +use compositor_task::{CompositorEventListener, CompositorReceiver}; +use compositor_task::{InitialCompositorState, Msg}; use windowing::WindowEvent; use euclid::scale_factor::ScaleFactor; @@ -29,28 +30,17 @@ pub struct NullCompositor { } impl NullCompositor { - fn new(port: Box, - constellation_chan: ConstellationChan, - time_profiler_chan: time::ProfilerChan, - mem_profiler_chan: mem::ProfilerChan) - -> NullCompositor { + fn new(state: InitialCompositorState) -> NullCompositor { NullCompositor { - port: port, - constellation_chan: constellation_chan, - time_profiler_chan: time_profiler_chan, - mem_profiler_chan: mem_profiler_chan, + port: state.receiver, + constellation_chan: state.constellation_chan, + time_profiler_chan: state.time_profiler_chan, + mem_profiler_chan: state.mem_profiler_chan, } } - pub fn create(port: Box, - constellation_chan: ConstellationChan, - time_profiler_chan: time::ProfilerChan, - mem_profiler_chan: mem::ProfilerChan) - -> NullCompositor { - let compositor = NullCompositor::new(port, - constellation_chan, - time_profiler_chan, - mem_profiler_chan); + pub fn create(state: InitialCompositorState) -> NullCompositor { + let compositor = NullCompositor::new(state); // Tell the constellation about the initial fake size. { diff --git a/components/servo/lib.rs b/components/servo/lib.rs index 47cb2fd9ab6..feb1ef3bee5 100644 --- a/components/servo/lib.rs +++ b/components/servo/lib.rs @@ -81,6 +81,7 @@ pub use export::gleam::gl; use compositing::CompositorEventListener; use compositing::windowing::WindowEvent; +use compositing::compositor_task::InitialCompositorState; use compositing::windowing::WindowMethods; use compositing::{CompositorProxy, CompositorTask, Constellation}; @@ -163,12 +164,13 @@ impl Browser { // The compositor coordinates with the client window to create the final // rendered page and display it somewhere. - let compositor = CompositorTask::create(window, - compositor_proxy, - compositor_receiver, - constellation_chan, - time_profiler_chan, - mem_profiler_chan); + let compositor = CompositorTask::create(window, InitialCompositorState { + sender: compositor_proxy, + receiver: compositor_receiver, + constellation_chan: constellation_chan, + time_profiler_chan: time_profiler_chan, + mem_profiler_chan: mem_profiler_chan, + }); Browser { compositor: compositor,