Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate interning text run #3369

Merged
merged 10 commits into from Dec 6, 2018

De-duplicate shadow item code.

  • Loading branch information
djg committed Dec 5, 2018
commit 8b9715ece8668b5916d9dc439ab17f2eba73c7fd
@@ -1,4 +1,3 @@

/* 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/. */
@@ -1791,42 +1790,10 @@ impl<'a> DisplayListFlattener<'a> {
match item {
// TODO(djg): ugh. de-duplicate this code.
ShadowItem::Primitive(ref pending_primitive) => {
// Offset the local rect and clip rect by the shadow offset.
let mut info = pending_primitive.info.clone();
info.rect = info.rect.translate(&pending_shadow.shadow.offset);
info.clip_rect = info.clip_rect.translate(&pending_shadow.shadow.offset);

// Construct and add a primitive for the given shadow.
let shadow_prim_instance = self.create_primitive(
&info,
pending_primitive.clip_and_scroll.clip_chain_id,
pending_primitive.clip_and_scroll.spatial_node_index,
pending_primitive.prim.create_shadow(
&pending_shadow.shadow,
),
);

// Add the new primitive to the shadow picture.
prims.push(shadow_prim_instance);
self.add_shadow_prim(&pending_shadow, pending_primitive, &mut prims)
}
ShadowItem::TextRun(ref pending_text_run) => {
// Offset the local rect and clip rect by the shadow offset.
let mut info = pending_text_run.info.clone();
info.rect = info.rect.translate(&pending_shadow.shadow.offset);
info.clip_rect = info.clip_rect.translate(&pending_shadow.shadow.offset);

// Construct and add a primitive for the given shadow.
let shadow_prim_instance = self.create_primitive(
&info,
pending_text_run.clip_and_scroll.clip_chain_id,
pending_text_run.clip_and_scroll.spatial_node_index,
pending_text_run.prim.create_shadow(
&pending_shadow.shadow,
),
);

// Add the new primitive to the shadow picture.
prims.push(shadow_prim_instance);
self.add_shadow_prim(&pending_shadow, pending_text_run, &mut prims)
}
_ => {}
}
@@ -1893,31 +1860,10 @@ impl<'a> DisplayListFlattener<'a> {
}
}
ShadowItem::Primitive(pending_primitive) => {
// For a normal primitive, if it has alpha > 0, then we add this
// as a normal primitive to the parent picture.
if pending_primitive.prim.is_visible() {
self.add_prim_to_draw_list(
&pending_primitive.info,
pending_primitive.clip_and_scroll.clip_chain_id,
pending_primitive.clip_and_scroll,
pending_primitive.prim,
);
}
self.add_shadow_prim_to_draw_list(pending_primitive)
},
ShadowItem::TextRun(pending_text_run) => {
// For a normal primitive, if it has alpha > 0, then we add this
// as a normal primitive to the parent picture.
//
// TODO(djg): Can this be cleaned up? It looks identical to
// another piece of code.
if pending_text_run.prim.is_visible() {
self.add_prim_to_draw_list(
&pending_text_run.info,
pending_text_run.clip_and_scroll.clip_chain_id,
pending_text_run.clip_and_scroll,
pending_text_run.prim,
);
}
self.add_shadow_prim_to_draw_list(pending_text_run)
},
}
}
@@ -1926,6 +1872,54 @@ impl<'a> DisplayListFlattener<'a> {
self.pending_shadow_items = items;
}

fn add_shadow_prim<P>(
&mut self,
pending_shadow: &PendingShadow,
pending_primitive: &PendingPrimitive<P>,
prims: &mut Vec<PrimitiveInstance>,
)
where
P: Internable<InternData=PrimitiveSceneData> + CreateShadow,
P::Source: AsInstanceKind<Handle<P::Marker>> + BuildKey<P>,
DocumentResources: InternerMut<P>,
{
// Offset the local rect and clip rect by the shadow offset.
let mut info = pending_primitive.info.clone();
info.rect = info.rect.translate(&pending_shadow.shadow.offset);
info.clip_rect = info.clip_rect.translate(&pending_shadow.shadow.offset);

// Construct and add a primitive for the given shadow.
let shadow_prim_instance = self.create_primitive(
&info,
pending_primitive.clip_and_scroll.clip_chain_id,
pending_primitive.clip_and_scroll.spatial_node_index,
pending_primitive.prim.create_shadow(
&pending_shadow.shadow,
),
);

// Add the new primitive to the shadow picture.
prims.push(shadow_prim_instance);
}

fn add_shadow_prim_to_draw_list<P>(&mut self, pending_primitive: PendingPrimitive<P>)
where
P: Internable<InternData = PrimitiveSceneData> + IsVisible,
P::Source: AsInstanceKind<Handle<P::Marker>> + BuildKey<P>,
DocumentResources: InternerMut<P>,
{
// For a normal primitive, if it has alpha > 0, then we add this
// as a normal primitive to the parent picture.
if pending_primitive.prim.is_visible() {
self.add_prim_to_draw_list(
&pending_primitive.info,
pending_primitive.clip_and_scroll.clip_chain_id,
pending_primitive.clip_and_scroll,
pending_primitive.prim,
);
}
}

#[cfg(debug_assertions)]
fn register_chase_primitive_by_rect(
&mut self,
@@ -16,7 +16,7 @@ use border::{BorderSegmentCacheKey, NormalBorderAu};
use clip::{ClipStore};
use clip_scroll_tree::{ClipScrollTree, SpatialNodeIndex};
use clip::{ClipDataStore, ClipNodeFlags, ClipChainId, ClipChainInstance, ClipItem, ClipNodeCollector};
use display_list_flattener::{AsInstanceKind, BuildKey, IsVisible};
use display_list_flattener::{AsInstanceKind, BuildKey, CreateShadow, IsVisible};
use euclid::{SideOffsets2D, TypedTransform3D, TypedRect, TypedScale, TypedSize2D};
use frame_builder::{FrameBuildingContext, FrameBuildingState, PictureContext, PictureState};
use frame_builder::PrimitiveContext;
@@ -2122,11 +2122,11 @@ impl IsVisible for PrimitiveKeyKind {
}
}

impl PrimitiveKeyKind {
impl CreateShadow for PrimitiveKeyKind {
// Create a clone of this PrimitiveContainer, applying whatever
// changes are necessary to the primitive to support rendering
// it as part of the supplied shadow.
pub fn create_shadow(
fn create_shadow(
&self,
shadow: &Shadow,
) -> PrimitiveKeyKind {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.