Skip to content

Commit 6497007

Browse files
committed
De-duplicate shadow item code.
1 parent 1b549b9 commit 6497007

File tree

2 files changed

+57
-63
lines changed

2 files changed

+57
-63
lines changed

webrender/src/display_list_flattener.rs

Lines changed: 54 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/* This Source Code Form is subject to the terms of the Mozilla Public
32
* License, v. 2.0. If a copy of the MPL was not distributed with this
43
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@@ -1267,7 +1266,7 @@ impl<'a> DisplayListFlattener<'a> {
12671266
PrimitiveInstanceKind::Picture { ref mut pic_index, ..} => *pic_index = current_pic_index,
12681267
_ => unreachable!()
12691268
};
1270-
1269+
12711270
if cur_instance.is_chased() {
12721271
println!("\tis a composite picture for a stacking context with {:?}", filter);
12731272
}
@@ -1304,7 +1303,7 @@ impl<'a> DisplayListFlattener<'a> {
13041303
PrimitiveInstanceKind::Picture { ref mut pic_index, ..} => *pic_index = current_pic_index,
13051304
_ => unreachable!()
13061305
};
1307-
1306+
13081307
if cur_instance.is_chased() {
13091308
println!("\tis a mix-blend picture for a stacking context with {:?}", mix_blend_mode);
13101309
}
@@ -1602,42 +1601,10 @@ impl<'a> DisplayListFlattener<'a> {
16021601
match item {
16031602
// TODO(djg): ugh. de-duplicate this code.
16041603
ShadowItem::Primitive(ref pending_primitive) => {
1605-
// Offset the local rect and clip rect by the shadow offset.
1606-
let mut info = pending_primitive.info.clone();
1607-
info.rect = info.rect.translate(&pending_shadow.shadow.offset);
1608-
info.clip_rect = info.clip_rect.translate(&pending_shadow.shadow.offset);
1609-
1610-
// Construct and add a primitive for the given shadow.
1611-
let shadow_prim_instance = self.create_primitive(
1612-
&info,
1613-
pending_primitive.clip_and_scroll.clip_chain_id,
1614-
pending_primitive.clip_and_scroll.spatial_node_index,
1615-
pending_primitive.prim.create_shadow(
1616-
&pending_shadow.shadow,
1617-
),
1618-
);
1619-
1620-
// Add the new primitive to the shadow picture.
1621-
prims.push(shadow_prim_instance);
1604+
self.add_shadow_prim(&pending_shadow, pending_primitive, &mut prims)
16221605
}
16231606
ShadowItem::TextRun(ref pending_text_run) => {
1624-
// Offset the local rect and clip rect by the shadow offset.
1625-
let mut info = pending_text_run.info.clone();
1626-
info.rect = info.rect.translate(&pending_shadow.shadow.offset);
1627-
info.clip_rect = info.clip_rect.translate(&pending_shadow.shadow.offset);
1628-
1629-
// Construct and add a primitive for the given shadow.
1630-
let shadow_prim_instance = self.create_primitive(
1631-
&info,
1632-
pending_text_run.clip_and_scroll.clip_chain_id,
1633-
pending_text_run.clip_and_scroll.spatial_node_index,
1634-
pending_text_run.prim.create_shadow(
1635-
&pending_shadow.shadow,
1636-
),
1637-
);
1638-
1639-
// Add the new primitive to the shadow picture.
1640-
prims.push(shadow_prim_instance);
1607+
self.add_shadow_prim(&pending_shadow, pending_text_run, &mut prims)
16411608
}
16421609
_ => {}
16431610
}
@@ -1704,31 +1671,10 @@ impl<'a> DisplayListFlattener<'a> {
17041671
}
17051672
}
17061673
ShadowItem::Primitive(pending_primitive) => {
1707-
// For a normal primitive, if it has alpha > 0, then we add this
1708-
// as a normal primitive to the parent picture.
1709-
if pending_primitive.prim.is_visible() {
1710-
self.add_prim_to_draw_list(
1711-
&pending_primitive.info,
1712-
pending_primitive.clip_and_scroll.clip_chain_id,
1713-
pending_primitive.clip_and_scroll,
1714-
pending_primitive.prim,
1715-
);
1716-
}
1674+
self.add_shadow_prim_to_draw_list(pending_primitive)
17171675
},
17181676
ShadowItem::TextRun(pending_text_run) => {
1719-
// For a normal primitive, if it has alpha > 0, then we add this
1720-
// as a normal primitive to the parent picture.
1721-
//
1722-
// TODO(djg): Can this be cleaned up? It looks identical to
1723-
// another piece of code.
1724-
if pending_text_run.prim.is_visible() {
1725-
self.add_prim_to_draw_list(
1726-
&pending_text_run.info,
1727-
pending_text_run.clip_and_scroll.clip_chain_id,
1728-
pending_text_run.clip_and_scroll,
1729-
pending_text_run.prim,
1730-
);
1731-
}
1677+
self.add_shadow_prim_to_draw_list(pending_text_run)
17321678
},
17331679
}
17341680
}
@@ -1737,6 +1683,54 @@ impl<'a> DisplayListFlattener<'a> {
17371683
self.pending_shadow_items = items;
17381684
}
17391685

1686+
fn add_shadow_prim<P>(
1687+
&mut self,
1688+
pending_shadow: &PendingShadow,
1689+
pending_primitive: &PendingPrimitive<P>,
1690+
prims: &mut Vec<PrimitiveInstance>,
1691+
)
1692+
where
1693+
P: Internable<InternData=PrimitiveSceneData> + CreateShadow,
1694+
P::Source: AsInstanceKind<Handle<P::Marker>> + BuildKey<P>,
1695+
DocumentResources: InternerMut<P>,
1696+
{
1697+
// Offset the local rect and clip rect by the shadow offset.
1698+
let mut info = pending_primitive.info.clone();
1699+
info.rect = info.rect.translate(&pending_shadow.shadow.offset);
1700+
info.clip_rect = info.clip_rect.translate(&pending_shadow.shadow.offset);
1701+
1702+
// Construct and add a primitive for the given shadow.
1703+
let shadow_prim_instance = self.create_primitive(
1704+
&info,
1705+
pending_primitive.clip_and_scroll.clip_chain_id,
1706+
pending_primitive.clip_and_scroll.spatial_node_index,
1707+
pending_primitive.prim.create_shadow(
1708+
&pending_shadow.shadow,
1709+
),
1710+
);
1711+
1712+
// Add the new primitive to the shadow picture.
1713+
prims.push(shadow_prim_instance);
1714+
}
1715+
1716+
fn add_shadow_prim_to_draw_list<P>(&mut self, pending_primitive: PendingPrimitive<P>)
1717+
where
1718+
P: Internable<InternData = PrimitiveSceneData> + IsVisible,
1719+
P::Source: AsInstanceKind<Handle<P::Marker>> + BuildKey<P>,
1720+
DocumentResources: InternerMut<P>,
1721+
{
1722+
// For a normal primitive, if it has alpha > 0, then we add this
1723+
// as a normal primitive to the parent picture.
1724+
if pending_primitive.prim.is_visible() {
1725+
self.add_prim_to_draw_list(
1726+
&pending_primitive.info,
1727+
pending_primitive.clip_and_scroll.clip_chain_id,
1728+
pending_primitive.clip_and_scroll,
1729+
pending_primitive.prim,
1730+
);
1731+
}
1732+
}
1733+
17401734
#[cfg(debug_assertions)]
17411735
fn register_chase_primitive_by_rect(
17421736
&mut self,

webrender/src/prim_store/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use border::{BorderSegmentCacheKey, NormalBorderAu};
1616
use clip::{ClipStore};
1717
use clip_scroll_tree::{ClipScrollTree, SpatialNodeIndex};
1818
use clip::{ClipDataStore, ClipNodeFlags, ClipChainId, ClipChainInstance, ClipItem, ClipNodeCollector};
19-
use display_list_flattener::{AsInstanceKind, BuildKey, IsVisible};
19+
use display_list_flattener::{AsInstanceKind, BuildKey, CreateShadow, IsVisible};
2020
use euclid::{SideOffsets2D, TypedTransform3D, TypedRect, TypedScale, TypedSize2D};
2121
use frame_builder::{FrameBuildingContext, FrameBuildingState, PictureContext, PictureState};
2222
use frame_builder::PrimitiveContext;
@@ -2110,11 +2110,11 @@ impl IsVisible for PrimitiveKeyKind {
21102110
}
21112111
}
21122112

2113-
impl PrimitiveKeyKind {
2113+
impl CreateShadow for PrimitiveKeyKind {
21142114
// Create a clone of this PrimitiveContainer, applying whatever
21152115
// changes are necessary to the primitive to support rendering
21162116
// it as part of the supplied shadow.
2117-
pub fn create_shadow(
2117+
fn create_shadow(
21182118
&self,
21192119
shadow: &Shadow,
21202120
) -> PrimitiveKeyKind {

0 commit comments

Comments
 (0)