Skip to content

Commit

Permalink
Decoupled gfx and metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
streichgeorg committed Jan 15, 2018
1 parent 75f39b4 commit 4b7cb20
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 24 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion components/gfx/display_list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use app_units::Au;
use euclid::{Transform3D, Point2D, Vector2D, Rect, Size2D, TypedRect, SideOffsets2D};
use euclid::num::{One, Zero};
use gfx_traits::StackingContextId;
use gfx_traits::{self, StackingContextId};
use gfx_traits::print_tree::PrintTree;
use ipc_channel::ipc::IpcSharedMemory;
use msg::constellation_msg::PipelineId;
Expand Down Expand Up @@ -146,6 +146,25 @@ impl DisplayList {
}
}

impl gfx_traits::DisplayList for DisplayList {
/// Analyze the display list to figure out if this may be the first
/// contentful paint (i.e. the display list contains items of type text,
/// image, non-white canvas or SVG). Used by metrics.
fn is_contentful(&self) -> bool {
for item in &self.list {
match item {
&DisplayItem::Text(_) |
&DisplayItem::Image(_) => {
return true
}
_ => (),
}
}

false
}
}

/// Display list sections that make up a stacking context. Each section here refers
/// to the steps in CSS 2.1 Appendix E.
///
Expand Down
5 changes: 5 additions & 0 deletions components/gfx_traits/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,8 @@ pub fn node_id_from_clip_id(id: usize) -> Option<usize> {
}
None
}

pub trait DisplayList {
/// Returns true if this display list contains meaningful content.
fn is_contentful(&self) -> bool;
}
2 changes: 1 addition & 1 deletion components/layout_thread/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ impl LayoutThread {
// Observe notifications about rendered frames if needed right before
// sending the display list to WebRender in order to set time related
// Progressive Web Metrics.
self.paint_time_metrics.maybe_observe_paint_time(self, epoch, &display_list);
self.paint_time_metrics.maybe_observe_paint_time(self, epoch, &*display_list);

self.webrender_api.set_display_list(
self.webrender_document,
Expand Down
1 change: 0 additions & 1 deletion components/metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ name = "metrics"
path = "lib.rs"

[dependencies]
gfx = {path = "../gfx"}
gfx_traits = {path = "../gfx_traits"}
ipc-channel = "0.9"
log = "0.3.5"
Expand Down
21 changes: 2 additions & 19 deletions components/metrics/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* 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/. */

extern crate gfx;
extern crate gfx_traits;
extern crate ipc_channel;
#[macro_use]
Expand All @@ -17,8 +16,7 @@ extern crate servo_config;
extern crate servo_url;
extern crate time;

use gfx::display_list::{DisplayItem, DisplayList};
use gfx_traits::Epoch;
use gfx_traits::{Epoch, DisplayList};
use ipc_channel::ipc::IpcSender;
use msg::constellation_msg::PipelineId;
use profile_traits::time::{ProfilerChan, ProfilerCategory, send_profile_data};
Expand Down Expand Up @@ -324,24 +322,9 @@ impl PaintTimeMetrics {
return;
}

let mut is_contentful = false;
// Analyze the display list to figure out if this may be the first
// contentful paint (i.e. the display list contains items of type text,
// image, non-white canvas or SVG).
for item in &display_list.list {
match item {
&DisplayItem::Text(_) |
&DisplayItem::Image(_) => {
is_contentful = true;
break;
}
_ => (),
}
}

self.pending_metrics.borrow_mut().insert(epoch, (
profiler_metadata_factory.new_metadata(),
is_contentful,
display_list.is_contentful(),
));

// Send the pending metric information to the compositor thread.
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/metrics/paint_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn test_common(display_list: &DisplayList, epoch: Epoch) -> PaintTimeMetrics {
paint_time_metrics.maybe_observe_paint_time(
&dummy_profiler_metadata_factory,
epoch,
&display_list,
&*display_list,
);

// Should not set any metric until navigation start is set.
Expand Down

0 comments on commit 4b7cb20

Please sign in to comment.