Backed out 3 changesets (bug 1614655) for WebRender bustages. CLOSED TREE

Backed out changeset e79e84e8819c (bug 1614655)
Backed out changeset cc263e909c61 (bug 1614655)
Backed out changeset 10897d6106a8 (bug 1614655)
This commit is contained in:
Razvan Maries 2020-03-19 00:49:08 +02:00
parent b5a3fa67c6
commit e153e0a3e1
10 changed files with 167 additions and 253 deletions

View File

@ -85,7 +85,7 @@ Maybe<uint16_t> DisplayItemCache::AssignSlot(nsPaintedDisplayItem* aItem) {
return Nothing();
}
if (!aItem->CanBeReused() || !aItem->CanBeCached()) {
if (!aItem->CanBeReused()) {
// Do not try to cache items that cannot be reused.
return Nothing();
}
@ -129,16 +129,14 @@ Maybe<uint16_t> DisplayItemCache::CanReuseItem(
return Nothing();
}
// Spatial id and clip id can change between display lists.
if (!(aSpaceAndClip == slot.mSpaceAndClip)) {
// Spatial id and clip id can change between display lists, if items that
// generate them change their order.
// Mark the cache slot inactive and recache the item.
slot.mOccupied = false;
aItem->SetCantBeCached();
slotIndex = Nothing();
} else {
slot.mUsed = true;
return Nothing();
}
slot.mUsed = true;
return slotIndex;
}

View File

@ -1011,8 +1011,6 @@ void DisplayListBuilder::PopStackingContext(bool aIsReferenceFrame) {
wr::WrClipChainId DisplayListBuilder::DefineClipChain(
const nsTArray<wr::WrClipId>& aClips, bool aParentWithCurrentChain) {
CancelGroup();
const uint64_t* parent = nullptr;
if (aParentWithCurrentChain &&
mCurrentSpaceAndClipChain.clip_chain != wr::ROOT_CLIP_CHAIN) {
@ -1029,8 +1027,6 @@ wr::WrClipId DisplayListBuilder::DefineClip(
const Maybe<wr::WrSpaceAndClip>& aParent, const wr::LayoutRect& aClipRect,
const nsTArray<wr::ComplexClipRegion>* aComplex,
const wr::ImageMask* aMask) {
CancelGroup();
WrClipId clipId;
if (aParent) {
clipId = wr_dp_define_clip_with_parent_clip(
@ -1477,7 +1473,7 @@ void DisplayListBuilder::StartGroup(nsPaintedDisplayItem* aItem) {
mCurrentCacheSlot = mDisplayItemCache->AssignSlot(aItem);
if (mCurrentCacheSlot) {
wr_dp_start_item_group(mWrState);
wr_dp_start_item_group(mWrState, mCurrentCacheSlot.ref());
}
}

View File

@ -2196,6 +2196,7 @@ pub struct WrState {
pipeline_id: WrPipelineId,
frame_builder: WebRenderFrameBuilder,
current_tag: Option<ItemTag>,
current_item_key: Option<ItemKey>,
}
#[no_mangle]
@ -2206,6 +2207,7 @@ pub extern "C" fn wr_state_new(pipeline_id: WrPipelineId, content_size: LayoutSi
pipeline_id: pipeline_id,
frame_builder: WebRenderFrameBuilder::with_capacity(pipeline_id, content_size, capacity),
current_tag: None,
current_item_key: None,
});
Box::into_raw(state)
@ -2581,6 +2583,7 @@ fn common_item_properties_for_rect(
spatial_id: space_and_clip.spatial_id,
flags: prim_flags(is_backface_visible, /* prefer_compositor_surface */ false),
hit_info: state.current_tag,
item_key: state.current_item_key,
}
}
@ -2651,6 +2654,7 @@ pub extern "C" fn wr_dp_push_rect_with_parent_clip(
spatial_id: space_and_clip.spatial_id,
flags: prim_flags(is_backface_visible, /* prefer_compositor_surface */ false),
hit_info: state.current_tag,
item_key: state.current_item_key,
};
state.frame_builder.dl_builder.push_rect(&prim_info, color);
@ -2701,6 +2705,7 @@ pub extern "C" fn wr_dp_push_backdrop_filter_with_parent_clip(
spatial_id: space_and_clip.spatial_id,
flags: prim_flags(is_backface_visible, /* prefer_compositor_surface */ false),
hit_info: state.current_tag,
item_key: state.current_item_key,
};
state
@ -2731,6 +2736,7 @@ pub extern "C" fn wr_dp_push_clear_rect(
spatial_id: space_and_clip.spatial_id,
flags: prim_flags(true, /* prefer_compositor_surface */ false),
hit_info: state.current_tag,
item_key: state.current_item_key,
};
state.frame_builder.dl_builder.push_clear_rect(&prim_info);
@ -2759,6 +2765,7 @@ pub extern "C" fn wr_dp_push_hit_test(
spatial_id: space_and_clip.spatial_id,
flags: prim_flags(is_backface_visible, /* prefer_compositor_surface */ false),
hit_info: state.current_tag,
item_key: state.current_item_key,
};
state.frame_builder.dl_builder.push_hit_test(&prim_info);
@ -2786,6 +2793,7 @@ pub extern "C" fn wr_dp_push_clear_rect_with_parent_clip(
spatial_id: space_and_clip.spatial_id,
flags: prim_flags(true, /* prefer_compositor_surface */ false),
hit_info: state.current_tag,
item_key: state.current_item_key,
};
state.frame_builder.dl_builder.push_clear_rect(&prim_info);
@ -2814,6 +2822,7 @@ pub extern "C" fn wr_dp_push_image(
spatial_id: space_and_clip.spatial_id,
flags: prim_flags(is_backface_visible, prefer_compositor_surface),
hit_info: state.current_tag,
item_key: state.current_item_key,
};
let alpha_type = if premultiplied_alpha {
@ -2852,6 +2861,7 @@ pub extern "C" fn wr_dp_push_repeating_image(
spatial_id: space_and_clip.spatial_id,
flags: prim_flags(is_backface_visible, /* prefer_compositor_surface */ false),
hit_info: state.current_tag,
item_key: state.current_item_key,
};
let alpha_type = if premultiplied_alpha {
@ -2899,6 +2909,7 @@ pub extern "C" fn wr_dp_push_yuv_planar_image(
spatial_id: space_and_clip.spatial_id,
flags: prim_flags(is_backface_visible, prefer_compositor_surface),
hit_info: state.current_tag,
item_key: state.current_item_key,
};
state.frame_builder.dl_builder.push_yuv_image(
@ -2938,6 +2949,7 @@ pub extern "C" fn wr_dp_push_yuv_NV12_image(
spatial_id: space_and_clip.spatial_id,
flags: prim_flags(is_backface_visible, prefer_compositor_surface),
hit_info: state.current_tag,
item_key: state.current_item_key,
};
state.frame_builder.dl_builder.push_yuv_image(
@ -2976,6 +2988,7 @@ pub extern "C" fn wr_dp_push_yuv_interleaved_image(
spatial_id: space_and_clip.spatial_id,
flags: prim_flags(is_backface_visible, prefer_compositor_surface),
hit_info: state.current_tag,
item_key: state.current_item_key,
};
state.frame_builder.dl_builder.push_yuv_image(
@ -3014,6 +3027,7 @@ pub extern "C" fn wr_dp_push_text(
clip_id: space_and_clip.clip_id,
flags: prim_flags(is_backface_visible, /* prefer_compositor_surface */ false),
hit_info: state.current_tag,
item_key: state.current_item_key,
};
state
@ -3071,6 +3085,7 @@ pub extern "C" fn wr_dp_push_line(
spatial_id: space_and_clip.spatial_id,
flags: prim_flags(is_backface_visible, /* prefer_compositor_surface */ false),
hit_info: state.current_tag,
item_key: state.current_item_key,
};
state
@ -3113,6 +3128,7 @@ pub extern "C" fn wr_dp_push_border(
spatial_id: space_and_clip.spatial_id,
flags: prim_flags(is_backface_visible, /* prefer_compositor_surface */ false),
hit_info: state.current_tag,
item_key: state.current_item_key,
};
state
@ -3162,6 +3178,7 @@ pub extern "C" fn wr_dp_push_border_image(
spatial_id: space_and_clip.spatial_id,
flags: prim_flags(is_backface_visible, /* prefer_compositor_surface */ false),
hit_info: state.current_tag,
item_key: state.current_item_key,
};
state
@ -3220,6 +3237,7 @@ pub extern "C" fn wr_dp_push_border_gradient(
spatial_id: space_and_clip.spatial_id,
flags: prim_flags(is_backface_visible, /* prefer_compositor_surface */ false),
hit_info: state.current_tag,
item_key: state.current_item_key,
};
state
@ -3282,6 +3300,7 @@ pub extern "C" fn wr_dp_push_border_radial_gradient(
spatial_id: space_and_clip.spatial_id,
flags: prim_flags(is_backface_visible, /* prefer_compositor_surface */ false),
hit_info: state.current_tag,
item_key: state.current_item_key,
};
state
@ -3343,6 +3362,7 @@ pub extern "C" fn wr_dp_push_border_conic_gradient(
spatial_id: space_and_clip.spatial_id,
flags: prim_flags(is_backface_visible, /* prefer_compositor_surface */ false),
hit_info: state.current_tag,
item_key: state.current_item_key,
};
state
@ -3386,6 +3406,7 @@ pub extern "C" fn wr_dp_push_linear_gradient(
spatial_id: space_and_clip.spatial_id,
flags: prim_flags(is_backface_visible, /* prefer_compositor_surface */ false),
hit_info: state.current_tag,
item_key: state.current_item_key,
};
state
@ -3429,6 +3450,7 @@ pub extern "C" fn wr_dp_push_radial_gradient(
spatial_id: space_and_clip.spatial_id,
flags: prim_flags(is_backface_visible, /* prefer_compositor_surface */ false),
hit_info: state.current_tag,
item_key: state.current_item_key,
};
state
@ -3471,6 +3493,7 @@ pub extern "C" fn wr_dp_push_conic_gradient(
spatial_id: space_and_clip.spatial_id,
flags: prim_flags(is_backface_visible, /* prefer_compositor_surface */ false),
hit_info: state.current_tag,
item_key: state.current_item_key,
};
state
@ -3504,6 +3527,7 @@ pub extern "C" fn wr_dp_push_box_shadow(
spatial_id: space_and_clip.spatial_id,
flags: prim_flags(is_backface_visible, /* prefer_compositor_surface */ false),
hit_info: state.current_tag,
item_key: state.current_item_key,
};
state.frame_builder.dl_builder.push_box_shadow(
@ -3519,20 +3543,20 @@ pub extern "C" fn wr_dp_push_box_shadow(
}
#[no_mangle]
pub extern "C" fn wr_dp_start_item_group(state: &mut WrState) {
state.frame_builder.dl_builder.start_item_group();
pub extern "C" fn wr_dp_start_item_group(state: &mut WrState, key: ItemKey) {
state.current_item_key = Some(key);
state.frame_builder.dl_builder.start_item_group(key);
}
#[no_mangle]
pub extern "C" fn wr_dp_cancel_item_group(state: &mut WrState) {
state.current_item_key = None;
state.frame_builder.dl_builder.cancel_item_group();
}
#[no_mangle]
pub extern "C" fn wr_dp_finish_item_group(
state: &mut WrState,
key: ItemKey
) -> bool {
pub extern "C" fn wr_dp_finish_item_group(state: &mut WrState, key: ItemKey) -> bool {
state.current_item_key = None;
state.frame_builder.dl_builder.finish_item_group(key)
}

View File

@ -1510,9 +1510,8 @@ impl<'a> SceneBuilder<'a> {
unreachable!("Should have returned in parent method.")
}
DisplayItem::ReuseItems(key) |
DisplayItem::RetainedItems(key) => {
unreachable!("Iterator logic error: {:?}", key);
DisplayItem::ReuseItem(..) => {
unreachable!("Iterator logic error")
}
DisplayItem::PushShadow(info) => {

View File

@ -78,6 +78,8 @@ pub struct CommonItemProperties {
pub hit_info: Option<ItemTag>,
/// Various flags describing properties of this primitive.
pub flags: PrimitiveFlags,
/// The unique id of this display item.
pub item_key: Option<ItemKey>
}
impl CommonItemProperties {
@ -92,6 +94,7 @@ impl CommonItemProperties {
clip_id: space_and_clip.clip_id,
hit_info: None,
flags: PrimitiveFlags::default(),
item_key: None,
}
}
}
@ -162,8 +165,7 @@ pub enum DisplayItem {
PopStackingContext,
PopAllShadows,
ReuseItems(ItemKey),
RetainedItems(ItemKey),
ReuseItem(ItemKey),
}
/// This is a "complete" version of the DisplayItem, with all implicit trailing
@ -205,6 +207,8 @@ pub enum DebugDisplayItem {
PopReferenceFrame,
PopStackingContext,
PopAllShadows,
ReuseItem(ItemKey),
}
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
@ -1501,8 +1505,7 @@ impl DisplayItem {
DisplayItem::Rectangle(..) => "rectangle",
DisplayItem::ScrollFrame(..) => "scroll_frame",
DisplayItem::SetGradientStops => "set_gradient_stops",
DisplayItem::ReuseItems(..) => "reuse_item",
DisplayItem::RetainedItems(..) => "retained_items",
DisplayItem::ReuseItem(..) => "reuse_item",
DisplayItem::StickyFrame(..) => "sticky_frame",
DisplayItem::Text(..) => "text",
DisplayItem::YuvImage(..) => "yuv_image",

View File

@ -4,6 +4,8 @@
use crate::display_item::*;
use crate::display_list::*;
#[cfg(debug_assertions)]
use std::collections::HashSet;
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct CachedDisplayItem {
@ -12,7 +14,7 @@ pub struct CachedDisplayItem {
}
impl CachedDisplayItem {
pub fn display_item(&self) -> &DisplayItem {
pub fn item(&self) -> &DisplayItem {
&self.item
}
@ -38,71 +40,92 @@ impl From<DisplayItemRef<'_, '_>> for CachedDisplayItem {
}
}
#[derive(Clone, Deserialize, Serialize)]
struct CacheEntry {
items: Vec<CachedDisplayItem>,
occupied: bool,
fn key_from_item(item: &DisplayItem) -> ItemKey {
let key = match item {
DisplayItem::Rectangle(ref info) => info.common.item_key,
DisplayItem::ClearRectangle(ref info) => info.common.item_key,
DisplayItem::HitTest(ref info) => info.common.item_key,
DisplayItem::Text(ref info) => info.common.item_key,
DisplayItem::Image(ref info) => info.common.item_key,
_ => unimplemented!("Unexpected item: {:?}", item)
};
key.expect("Cached item without a key")
}
#[derive(Clone, Deserialize, Serialize)]
pub struct DisplayItemCache {
entries: Vec<CacheEntry>,
items: Vec<Option<CachedDisplayItem>>,
#[cfg(debug_assertions)]
keys: HashSet<ItemKey>,
}
impl DisplayItemCache {
fn add_item(&mut self, key: ItemKey, item: CachedDisplayItem) {
let mut entry = &mut self.entries[key as usize];
entry.items.push(item);
entry.occupied = true;
}
fn clear_entry(&mut self, key: ItemKey) {
let mut entry = &mut self.entries[key as usize];
entry.items.clear();
entry.occupied = false;
}
fn grow_if_needed(&mut self, capacity: usize) {
if capacity > self.entries.len() {
self.entries.resize_with(capacity, || CacheEntry {
items: Vec::new(),
occupied: false,
});
fn grow_if_needed(
&mut self,
capacity: usize
) {
if capacity > self.items.len() {
self.items.resize_with(capacity, || None::<CachedDisplayItem>);
// println!("Current cache size: {:?} elements, {:?} bytes",
// capacity, std::mem::size_of::<CachedDisplayItem>() * capacity);
}
}
pub fn get_items(&self, key: ItemKey) -> &[CachedDisplayItem] {
let entry = &self.entries[key as usize];
debug_assert!(entry.occupied);
entry.items.as_slice()
fn add_item(
&mut self,
item: CachedDisplayItem,
key: ItemKey,
) {
self.items[key as usize] = Some(item);
}
pub fn get_item(
&self,
key: ItemKey
) -> Option<&CachedDisplayItem> {
self.items[key as usize].as_ref()
}
pub fn new() -> Self {
Self {
entries: Vec::new(),
items: Vec::new(),
#[cfg(debug_assertions)]
/// Used to check that there is only one item per key.
keys: HashSet::new(),
}
}
pub fn update(&mut self, display_list: &BuiltDisplayList) {
pub fn update(
&mut self,
display_list: &BuiltDisplayList
) {
self.grow_if_needed(display_list.cache_size());
let mut iter = display_list.extra_data_iter();
let mut current_key: Option<ItemKey> = None;
#[cfg(debug_assertions)]
{
self.keys.clear();
}
loop {
let item = match iter.next() {
Some(item) => item,
None => break,
};
if let DisplayItem::RetainedItems(key) = item.item() {
current_key = Some(*key);
self.clear_entry(*key);
continue;
let item_key = key_from_item(item.item());
let cached_item = CachedDisplayItem::from(item);
#[cfg(debug_assertions)]
{
debug_assert!(self.keys.insert(item_key));
}
let key = current_key.expect("Missing RetainedItems marker");
let cached_item = CachedDisplayItem::from(item);
self.add_item(key, cached_item);
self.add_item(cached_item, item_key);
}
}
}

View File

@ -204,8 +204,6 @@ pub struct BuiltDisplayListIter<'a> {
list: &'a BuiltDisplayList,
data: &'a [u8],
cache: Option<&'a DisplayItemCache>,
pending_items: std::slice::Iter<'a, CachedDisplayItem>,
cur_cached_item: Option<&'a CachedDisplayItem>,
cur_item: di::DisplayItem,
cur_stops: ItemRange<'a, di::GradientStop>,
cur_glyphs: ItemRange<'a, GlyphInstance>,
@ -286,21 +284,29 @@ pub struct ItemStats {
pub struct DisplayItemRef<'a: 'b, 'b> {
iter: &'b BuiltDisplayListIter<'a>,
cached_item: Option<&'a CachedDisplayItem>,
}
// Some of these might just become ItemRanges
impl<'a, 'b> DisplayItemRef<'a, 'b> {
fn cached_or_iter_data<T>(
&self,
data: ItemRange<'a, T>
) -> ItemRange<'a, T> {
self.cached_item.map_or(data, |i| i.data_as_item_range())
}
pub fn display_list(&self) -> &BuiltDisplayList {
self.iter.display_list()
}
// Creates a new iterator where this element's iterator is, to hack around borrowck.
pub fn sub_iter(&self) -> BuiltDisplayListIter<'a> {
self.iter.sub_iter()
BuiltDisplayListIter::new(self.iter.list, self.iter.data, self.iter.cache)
}
pub fn item(&self) -> &di::DisplayItem {
self.iter.current_item()
self.cached_item.map_or(&self.iter.cur_item, |i| i.item())
}
pub fn clip_chain_items(&self) -> ItemRange<di::ClipId> {
@ -312,11 +318,11 @@ impl<'a, 'b> DisplayItemRef<'a, 'b> {
}
pub fn glyphs(&self) -> ItemRange<GlyphInstance> {
self.iter.glyphs()
self.cached_or_iter_data(self.iter.cur_glyphs)
}
pub fn gradient_stops(&self) -> ItemRange<di::GradientStop> {
self.iter.gradient_stops()
self.cached_or_iter_data(self.iter.cur_stops)
}
pub fn filters(&self) -> ItemRange<di::FilterOp> {
@ -487,8 +493,7 @@ impl BuiltDisplayList {
Real::PopReferenceFrame => Debug::PopReferenceFrame,
Real::PopStackingContext => Debug::PopStackingContext,
Real::PopAllShadows => Debug::PopAllShadows,
Real::ReuseItems(_) |
Real::RetainedItems(_) => unreachable!("Unexpected item"),
Real::ReuseItem(_) => unreachable!("Unexpected item"),
};
seq.serialize_element(&serial_di)?
}
@ -521,8 +526,6 @@ impl<'a> BuiltDisplayListIter<'a> {
list,
data,
cache,
pending_items: [].iter(),
cur_cached_item: None,
cur_item: di::DisplayItem::PopStackingContext,
cur_stops: ItemRange::default(),
cur_glyphs: ItemRange::default(),
@ -535,52 +538,14 @@ impl<'a> BuiltDisplayListIter<'a> {
debug_stats: DebugStats {
last_addr: data.as_ptr() as usize,
stats: HashMap::default(),
},
}
}
}
pub fn sub_iter(&self) -> Self {
let mut iter = BuiltDisplayListIter::new(
self.list, self.data, self.cache
);
iter.pending_items = self.pending_items.clone();
iter
}
pub fn display_list(&self) -> &'a BuiltDisplayList {
self.list
}
pub fn current_item(&self) -> &di::DisplayItem {
match self.cur_cached_item {
Some(cached_item) => cached_item.display_item(),
None => &self.cur_item
}
}
fn cached_item_range_or<T>(
&self,
data: ItemRange<'a, T>
) -> ItemRange<'a, T> {
match self.cur_cached_item {
Some(cached_item) => cached_item.data_as_item_range(),
None => data,
}
}
pub fn glyphs(&self) -> ItemRange<GlyphInstance> {
self.cached_item_range_or(self.cur_glyphs)
}
pub fn gradient_stops(&self) -> ItemRange<di::GradientStop> {
self.cached_item_range_or(self.cur_stops)
}
fn advance_pending_items(&mut self) -> bool {
self.cur_cached_item = self.pending_items.next();
self.cur_cached_item.is_some()
}
pub fn next<'b>(&'b mut self) -> Option<DisplayItemRef<'a, 'b>> {
use crate::DisplayItem::*;
@ -628,10 +593,6 @@ impl<'a> BuiltDisplayListIter<'a> {
pub fn next_raw<'b>(&'b mut self) -> Option<DisplayItemRef<'a, 'b>> {
use crate::DisplayItem::*;
if self.advance_pending_items() {
return Some(self.as_ref());
}
// A "red zone" of DisplayItem::max_size() bytes has been added to the
// end of the serialized display list. If this amount, or less, is
// remaining then we've reached the end of the display list.
@ -688,17 +649,6 @@ impl<'a> BuiltDisplayListIter<'a> {
self.cur_glyphs = skip_slice::<GlyphInstance>(&mut self.data);
self.debug_stats.log_slice("text.glyphs", &self.cur_glyphs);
}
ReuseItems(key) => {
match self.cache {
Some(cache) => {
self.pending_items = cache.get_items(key).iter();
self.advance_pending_items();
}
None => {
unreachable!("Cache marker without cache!");
}
}
}
_ => { /* do nothing */ }
}
@ -706,8 +656,17 @@ impl<'a> BuiltDisplayListIter<'a> {
}
pub fn as_ref<'b>(&'b self) -> DisplayItemRef<'a, 'b> {
let cached_item = match self.cur_item {
di::DisplayItem::ReuseItem(key) => {
let cache = self.cache.expect("Cache marker without cache!");
cache.get_item(key)
}
_ => None
};
DisplayItemRef {
iter: self,
cached_item
}
}
@ -910,6 +869,7 @@ impl<'de> Deserialize<'de> for BuiltDisplayList {
Debug::PopStackingContext => Real::PopStackingContext,
Debug::PopReferenceFrame => Real::PopReferenceFrame,
Debug::PopAllShadows => Real::PopAllShadows,
Debug::ReuseItem(_) => unreachable!("Unexpected item"),
};
poke_into_vec(&item, &mut data);
// the aux data is serialized after the item, hence the temporary
@ -945,25 +905,14 @@ pub struct SaveState {
next_clip_chain_id: u64,
}
/// DisplayListSection determines the target buffer for the display items.
pub enum DisplayListSection {
/// The main/default buffer: contains item data and item group markers.
Data,
/// Auxiliary buffer: contains the item data for item groups.
ExtraData,
/// Temporary buffer: contains the data for pending item group. Flushed to
/// one of the buffers above, after item grouping finishes.
Chunk,
}
#[derive(Clone)]
pub struct DisplayListBuilder {
pub data: Vec<u8>,
pub pipeline_id: PipelineId,
extra_data: Vec<u8>,
pending_chunk: Vec<u8>,
writing_to_chunk: bool,
extra_data_chunk_start: usize,
writing_extra_data_chunk: bool,
next_clip_index: usize,
next_spatial_index: usize,
@ -996,8 +945,8 @@ impl DisplayListBuilder {
pipeline_id,
extra_data: Vec::new(),
pending_chunk: Vec::new(),
writing_to_chunk: false,
extra_data_chunk_start: 0,
writing_extra_data_chunk: false,
next_clip_index: FIRST_CLIP_NODE_INDEX,
next_spatial_index: FIRST_SPATIAL_NODE_INDEX,
@ -1086,49 +1035,19 @@ impl DisplayListBuilder {
index
}
fn active_buffer(&mut self) -> &mut Vec<u8> {
if self.writing_extra_data_chunk {
&mut self.extra_data
} else {
&mut self.data
}
}
/// Print the display items in the list to stdout.
pub fn dump_serialized_display_list(&mut self) {
self.serialized_content_buffer = Some(String::new());
}
fn add_to_display_list_dump<T: std::fmt::Debug>(&mut self, item: T) {
if let Some(ref mut content) = self.serialized_content_buffer {
use std::fmt::Write;
write!(content, "{:?}\n", item).expect("DL dump write failed.");
}
}
/// Returns the default section that DisplayListBuilder will write to,
/// if no section is specified explicitly.
fn default_section(&self) -> DisplayListSection {
if self.writing_to_chunk {
DisplayListSection::Chunk
} else {
DisplayListSection::Data
}
}
fn buffer_from_section(
&mut self,
section: DisplayListSection
) -> &mut Vec<u8> {
match section {
DisplayListSection::Data => &mut self.data,
DisplayListSection::ExtraData => &mut self.extra_data,
DisplayListSection::Chunk => &mut self.pending_chunk,
}
}
#[inline]
pub fn push_item_to_section(
&mut self,
item: &di::DisplayItem,
section: DisplayListSection,
) {
poke_into_vec(item, self.buffer_from_section(section));
self.add_to_display_list_dump(item);
}
/// Add an item to the display list.
///
/// NOTE: It is usually preferable to use the specialized methods to push
@ -1136,7 +1055,12 @@ impl DisplayListBuilder {
/// result in WebRender panicking or behaving in unexpected ways.
#[inline]
pub fn push_item(&mut self, item: &di::DisplayItem) {
self.push_item_to_section(item, self.default_section());
poke_into_vec(item, self.active_buffer());
if let Some(ref mut content) = self.serialized_content_buffer {
use std::fmt::Write;
write!(content, "{:?}\n", item).expect("DL dump write failed.");
}
}
fn push_iter_impl<I>(data: &mut Vec<u8>, iter_source: I)
@ -1182,8 +1106,7 @@ impl DisplayListBuilder {
I::IntoIter: ExactSizeIterator,
I::Item: Poke,
{
let mut buffer = self.buffer_from_section(self.default_section());
Self::push_iter_impl(&mut buffer, iter);
Self::push_iter_impl(self.active_buffer(), iter);
}
pub fn push_rect(
@ -1821,57 +1744,35 @@ impl DisplayListBuilder {
self.push_item(&di::DisplayItem::PopAllShadows);
}
pub fn start_item_group(&mut self) {
debug_assert!(!self.writing_to_chunk);
debug_assert!(self.pending_chunk.is_empty());
self.writing_to_chunk = true;
fn truncate_extra_data_chunk(&mut self) {
self.extra_data.truncate(self.extra_data_chunk_start)
}
fn flush_pending_item_group(&mut self, key: di::ItemKey) {
// Push RetainedItems-marker to extra_data section.
self.push_retained_items(key);
// Push pending chunk to extra_data section.
self.extra_data.append(&mut self.pending_chunk);
// Push ReuseItems-marker to data section.
self.push_reuse_items(key);
pub fn start_item_group(&mut self, _key: di::ItemKey) {
self.writing_extra_data_chunk = true;
self.extra_data_chunk_start = self.extra_data.len();
}
pub fn finish_item_group(&mut self, key: di::ItemKey) -> bool {
debug_assert!(self.writing_to_chunk);
self.writing_to_chunk = false;
self.writing_extra_data_chunk = false;
if self.pending_chunk.len() > 0 {
self.flush_pending_item_group(key);
true
} else {
debug_assert!(self.pending_chunk.is_empty());
false
let chunk_size = self.extra_data.len() - self.extra_data_chunk_start;
if chunk_size > 0 {
self.push_reuse_items(key);
return true
}
false
}
pub fn cancel_item_group(&mut self) {
debug_assert!(self.writing_to_chunk);
self.writing_to_chunk = false;
// Push pending chunk to data section.
self.data.append(&mut self.pending_chunk);
debug_assert!(self.writing_extra_data_chunk);
self.writing_extra_data_chunk = false;
self.truncate_extra_data_chunk();
}
pub fn push_reuse_items(&mut self, key: di::ItemKey) {
self.push_item_to_section(
&di::DisplayItem::ReuseItems(key),
DisplayListSection::Data
);
}
fn push_retained_items(&mut self, key: di::ItemKey) {
self.push_item_to_section(
&di::DisplayItem::RetainedItems(key),
DisplayListSection::ExtraData
);
self.push_item(&di::DisplayItem::ReuseItem(key));
}
pub fn set_cache_size(&mut self, cache_size: usize) {

View File

@ -232,7 +232,6 @@ bool nsDisplayButtonBorder::CreateWebRenderCommands(
nsDisplayListBuilder* aDisplayListBuilder) {
// This is really a combination of paint box shadow inner +
// paint border.
aBuilder.StartGroup(this);
const nsRect buttonRect = nsRect(ToReferenceFrame(), mFrame->GetSize());
bool snap;
nsRegion visible = GetBounds(aDisplayListBuilder, &snap);
@ -245,17 +244,11 @@ bool nsDisplayButtonBorder::CreateWebRenderCommands(
nsRect(ToReferenceFrame(), mFrame->GetSize()), mFrame->Style(),
&borderIsEmpty, mFrame->GetSkipSides());
if (!br) {
if (borderIsEmpty) {
aBuilder.FinishGroup();
} else {
aBuilder.CancelGroup();
}
return borderIsEmpty;
}
br->CreateWebRenderCommands(this, aBuilder, aResources, aSc);
aBuilder.FinishGroup();
return true;
}
@ -380,10 +373,7 @@ bool nsDisplayButtonForeground::CreateWebRenderCommands(
return borderIsEmpty;
}
aBuilder.StartGroup(this);
br->CreateWebRenderCommands(this, aBuilder, aResources, aSc);
aBuilder.FinishGroup();
return true;
}

View File

@ -5693,18 +5693,14 @@ bool nsDisplayBorder::CreateWebRenderCommands(
nsDisplayListBuilder* aDisplayListBuilder) {
nsRect rect = nsRect(ToReferenceFrame(), mFrame->GetSize());
aBuilder.StartGroup(this);
ImgDrawResult drawResult = nsCSSRendering::CreateWebRenderCommandsForBorder(
this, mFrame, rect, aBuilder, aResources, aSc, aManager,
aDisplayListBuilder);
if (drawResult == ImgDrawResult::NOT_SUPPORTED) {
aBuilder.CancelGroup();
return false;
}
aBuilder.FinishGroup();
nsDisplayBorderGeometry::UpdateDrawResult(this, drawResult);
return true;
};
@ -9543,18 +9539,9 @@ bool nsDisplayText::CreateWebRenderCommands(
RefPtr<gfxContext> textDrawer = aBuilder.GetTextContext(
aResources, aSc, aManager, this, bounds, deviceOffset);
aBuilder.StartGroup(this);
RenderToContext(textDrawer, aDisplayListBuilder, true);
const bool result = textDrawer->GetTextDrawer()->Finish();
if (result) {
aBuilder.FinishGroup();
} else {
aBuilder.CancelGroup();
}
return result;
return textDrawer->GetTextDrawer()->Finish();
}
void nsDisplayText::RenderToContext(gfxContext* aCtx,

View File

@ -2308,12 +2308,6 @@ class nsDisplayItemBase : public nsDisplayItemLink {
void SetCantBeReused() { mItemFlags += ItemBaseFlag::CantBeReused; }
bool CanBeCached() const {
return !mItemFlags.contains(ItemBaseFlag::CantBeCached);
}
void SetCantBeCached() { mItemFlags += ItemBaseFlag::CantBeCached; }
bool IsOldItem() const { return !!mOldList; }
/**
@ -2415,7 +2409,6 @@ class nsDisplayItemBase : public nsDisplayItemLink {
private:
enum class ItemBaseFlag : uint8_t {
CantBeReused,
CantBeCached,
DeletedFrame,
ModifiedFrame,
ReusedItem,