servo/components/compositing/headless.rs
Nicholas Nethercote ce36e574f4 Rename lots of profiling-related things.
------------------------------------------------------------------------
BEFORE                              AFTER
------------------------------------------------------------------------
util::memory                        util::mem
- heap_size_of                      - heap_size_of (unchanged)
- SizeOf                            - HeapSizeOf
  - size_of_excluding_self            - heap_size_of_children

prof::mem                           prof::mem
- MemoryProfilerChan                - ProfilerChan
- MemoryReport                      - Report
- MemoryReportsChan                 - ReportsChan
- MemoryReporter                    - Reporter
- MemoryProfilerMsg                 - ProfilerMsg
  - {R,UnR}egisterMemoryReporter      - {R,UnR}egisterReporter
- MemoryProfiler                    - Prof
- ReportsForest                     - ReportsForest (unchanged)
- ReportsTree                       - ReportsTree   (unchanged)
- SystemMemoryReporter              - SystemReporter

prof::time                          prof::time
- TimeProfilerChan                  - ProfilerChan
- TimerMetadata                     - TimerMetadata (unchanged)
- Formatable                        - Formattable [spelling!]
- TimeProfilerMsg                   - ProfilerMsg
- TimeProfilerCategory              - ProfilerCategory
- TimeProfilerBuckets               - ProfilerBuckets
- TimeProfiler                      - Profiler
- TimerMetadataFrameType            - TimerMetadataFrameType (unchanged)
- TimerMetadataReflowType           - TimerMetadataReflowType (unchanged)
- ProfilerMetadata                  - ProfilerMetadata (unchanged)

In a few places both prof::time and prof::mem are used, and so
module-qualification is needed to avoid overlap, e.g. time::Profiler and
mem::Profiler. Likewise with std::mem and prof::mem. This is not a big
deal.
2015-03-25 16:00:23 -07:00

130 lines
4.6 KiB
Rust

/* 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 compositor_task::{CompositorEventListener, CompositorReceiver, Msg};
use windowing::WindowEvent;
use geom::scale_factor::ScaleFactor;
use geom::size::TypedSize2D;
use msg::constellation_msg::Msg as ConstellationMsg;
use msg::constellation_msg::{ConstellationChan, WindowSizeData};
use profile::mem;
use profile::time;
/// Starts the compositor, which listens for messages on the specified port.
///
/// This is the null compositor which doesn't draw anything to the screen.
/// It's intended for headless testing.
pub struct NullCompositor {
/// The port on which we receive messages.
pub port: Box<CompositorReceiver>,
/// A channel to the constellation.
constellation_chan: ConstellationChan,
/// A channel to the time profiler.
time_profiler_chan: time::ProfilerChan,
/// A channel to the memory profiler.
mem_profiler_chan: mem::ProfilerChan,
}
impl NullCompositor {
fn new(port: Box<CompositorReceiver>,
constellation_chan: ConstellationChan,
time_profiler_chan: time::ProfilerChan,
mem_profiler_chan: mem::ProfilerChan)
-> NullCompositor {
NullCompositor {
port: port,
constellation_chan: constellation_chan,
time_profiler_chan: time_profiler_chan,
mem_profiler_chan: mem_profiler_chan,
}
}
pub fn create(port: Box<CompositorReceiver>,
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);
// Tell the constellation about the initial fake size.
{
let ConstellationChan(ref chan) = compositor.constellation_chan;
chan.send(ConstellationMsg::ResizedWindow(WindowSizeData {
initial_viewport: TypedSize2D(640_f32, 480_f32),
visible_viewport: TypedSize2D(640_f32, 480_f32),
device_pixel_ratio: ScaleFactor::new(1.0),
})).unwrap();
}
compositor
}
}
impl CompositorEventListener for NullCompositor {
fn handle_event(&mut self, _: WindowEvent) -> bool {
match self.port.recv_compositor_msg() {
Msg::Exit(chan) => {
debug!("shutting down the constellation");
let ConstellationChan(ref con_chan) = self.constellation_chan;
con_chan.send(ConstellationMsg::Exit).unwrap();
chan.send(()).unwrap();
}
Msg::ShutdownComplete => {
debug!("constellation completed shutdown");
return false
}
Msg::GetGraphicsMetadata(chan) => {
chan.send(None).unwrap();
}
Msg::SetFrameTree(_, response_chan, _) => {
response_chan.send(()).unwrap();
}
// Explicitly list ignored messages so that when we add a new one,
// we'll notice and think about whether it needs a response, like
// SetFrameTree.
Msg::CreateOrUpdateBaseLayer(..) |
Msg::CreateOrUpdateDescendantLayer(..) |
Msg::SetLayerRect(..) |
Msg::AssignPaintedBuffers(..) |
Msg::ChangeReadyState(..) |
Msg::ChangePaintState(..) |
Msg::ScrollFragmentPoint(..) |
Msg::LoadComplete |
Msg::PaintMsgDiscarded(..) |
Msg::ScrollTimeout(..) |
Msg::ChangePageTitle(..) |
Msg::ChangePageUrl(..) |
Msg::KeyEvent(..) |
Msg::SetCursor(..) => {}
Msg::PaintTaskExited(..) => {}
}
true
}
fn repaint_synchronously(&mut self) {}
fn shutdown(&mut self) {
// Drain compositor port, sometimes messages contain channels that are blocking
// another task from finishing (i.e. SetIds)
while self.port.try_recv_compositor_msg().is_some() {}
self.time_profiler_chan.send(time::ProfilerMsg::Exit);
self.mem_profiler_chan.send(mem::ProfilerMsg::Exit);
}
fn pinch_zoom_level(&self) -> f32 {
1.0
}
fn get_title_for_main_frame(&self) {}
}