Skip to content

Commit

Permalink
Bug 1441308 - Make WR caches document-aware r=bholley
Browse files Browse the repository at this point in the history
This change makes the various WR caches segment their cached data by
document, so that documents' data are not evicted out from underneath them.

Differential Revision: https://phabricator.services.mozilla.com/D13343
  • Loading branch information
squarewave committed Jan 10, 2019
1 parent fbf2ecf commit 5151502
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 49 deletions.
2 changes: 1 addition & 1 deletion gfx/wr/webrender/src/frame_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ impl FrameBuilder {

render_tasks.write_task_data(device_pixel_scale);

resource_cache.end_frame();
resource_cache.end_frame(texture_cache_profile);

Frame {
window_size: self.window_size,
Expand Down
25 changes: 22 additions & 3 deletions gfx/wr/webrender/src/render_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,15 @@ impl ::std::ops::Sub<usize> for FrameId {
pub struct FrameStamp {
id: FrameId,
time: SystemTime,
document_id: DocumentId,
}

impl Eq for FrameStamp {}

impl PartialEq for FrameStamp {
fn eq(&self, other: &Self) -> bool {
// We should not be checking equality unless the documents are the same
debug_assert!(self.document_id == other.document_id);
self.id == other.id
}
}
Expand All @@ -175,11 +178,24 @@ impl FrameStamp {
self.time
}

/// Gets the DocumentId in this stamp.
pub fn document_id(&self) -> DocumentId {
self.document_id
}

pub fn is_valid(&self) -> bool {
// If any fields are their default values, the whole struct should equal INVALID
debug_assert!((self.time != UNIX_EPOCH && self.id != FrameId(0) && self.document_id != DocumentId::INVALID) ||
*self == Self::INVALID);
self.document_id != DocumentId::INVALID
}

/// Returns a FrameStamp corresponding to the first frame.
pub fn first() -> Self {
pub fn first(document_id: DocumentId) -> Self {
FrameStamp {
id: FrameId::first(),
time: SystemTime::now(),
document_id: document_id,
}
}

Expand All @@ -193,6 +209,7 @@ impl FrameStamp {
pub const INVALID: FrameStamp = FrameStamp {
id: FrameId(0),
time: UNIX_EPOCH,
document_id: DocumentId::INVALID,
};
}

Expand Down Expand Up @@ -332,6 +349,7 @@ struct Document {

impl Document {
pub fn new(
id: DocumentId,
window_size: DeviceIntSize,
layer: DocumentLayer,
default_device_pixel_ratio: f32,
Expand All @@ -349,7 +367,7 @@ impl Document {
device_pixel_ratio: default_device_pixel_ratio,
},
clip_scroll_tree: ClipScrollTree::new(),
stamp: FrameStamp::first(),
stamp: FrameStamp::first(id),
frame_builder: None,
output_pipelines: FastHashSet::default(),
hit_tester: None,
Expand Down Expand Up @@ -982,6 +1000,7 @@ impl RenderBackend {
}
ApiMsg::AddDocument(document_id, initial_size, layer) => {
let document = Document::new(
document_id,
initial_size,
layer,
self.default_device_pixel_ratio,
Expand Down Expand Up @@ -1747,7 +1766,7 @@ impl RenderBackend {
removed_pipelines: Vec::new(),
view: view.clone(),
clip_scroll_tree: ClipScrollTree::new(),
stamp: FrameStamp::first(),
stamp: FrameStamp::first(id),
frame_builder: Some(FrameBuilder::empty()),
output_pipelines: FastHashSet::default(),
dynamic_properties: SceneProperties::new(),
Expand Down
4 changes: 2 additions & 2 deletions gfx/wr/webrender/src/resource_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1610,7 +1610,6 @@ impl ResourceCache {
&mut self.texture_cache,
render_tasks,
);
self.texture_cache.end_frame(texture_cache_profile);
}

fn rasterize_missing_blob_images(&mut self) {
Expand Down Expand Up @@ -1767,9 +1766,10 @@ impl ResourceCache {
}
}

pub fn end_frame(&mut self) {
pub fn end_frame(&mut self, texture_cache_profile: &mut TextureCacheProfileCounters) {
debug_assert_eq!(self.state, State::QueryResources);
self.state = State::Idle;
self.texture_cache.end_frame(texture_cache_profile);
}

pub fn set_debug_flags(&mut self, flags: DebugFlags) {
Expand Down
Loading

0 comments on commit 5151502

Please sign in to comment.