Skip to content

Commit ce799fb

Browse files
committed
Extract common key and template data.
1 parent 30e29b8 commit ce799fb

File tree

2 files changed

+86
-45
lines changed

2 files changed

+86
-45
lines changed

webrender/src/prim_store/mod.rs

Lines changed: 63 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,27 @@ impl From<LayoutPoint> for PointKey {
623623
#[cfg_attr(feature = "capture", derive(Serialize))]
624624
#[cfg_attr(feature = "replay", derive(Deserialize))]
625625
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
626-
pub struct PrimitiveKey {
626+
pub struct PrimKeyCommonData {
627627
pub is_backface_visible: bool,
628628
pub prim_rect: RectangleKey,
629629
pub clip_rect: RectangleKey,
630+
}
631+
632+
impl PrimKeyCommonData {
633+
pub fn with_info(info: &LayoutPrimitiveInfo) -> Self {
634+
PrimKeyCommonData {
635+
is_backface_visible: info.is_backface_visible,
636+
prim_rect: info.rect.into(),
637+
clip_rect: info.clip_rect.into(),
638+
}
639+
}
640+
}
641+
642+
#[cfg_attr(feature = "capture", derive(Serialize))]
643+
#[cfg_attr(feature = "replay", derive(Deserialize))]
644+
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
645+
pub struct PrimitiveKey {
646+
pub common: PrimKeyCommonData,
630647
pub kind: PrimitiveKeyKind,
631648
}
632649

@@ -638,9 +655,11 @@ impl PrimitiveKey {
638655
kind: PrimitiveKeyKind,
639656
) -> Self {
640657
PrimitiveKey {
641-
is_backface_visible,
642-
prim_rect: prim_rect.into(),
643-
clip_rect: clip_rect.into(),
658+
common: PrimKeyCommonData {
659+
is_backface_visible,
660+
prim_rect: prim_rect.into(),
661+
clip_rect: clip_rect.into(),
662+
},
644663
kind,
645664
}
646665
}
@@ -969,11 +988,10 @@ impl PrimitiveKeyKind {
969988

970989
#[cfg_attr(feature = "capture", derive(Serialize))]
971990
#[cfg_attr(feature = "replay", derive(Deserialize))]
972-
pub struct PrimitiveTemplate {
991+
pub struct PrimTemplateCommonData {
973992
pub is_backface_visible: bool,
974993
pub prim_rect: LayoutRect,
975994
pub clip_rect: LayoutRect,
976-
pub kind: PrimitiveTemplateKind,
977995
pub opacity: PrimitiveOpacity,
978996
/// The GPU cache handle for a primitive template. Since this structure
979997
/// is retained across display lists by interning, this GPU cache handle
@@ -982,23 +1000,47 @@ pub struct PrimitiveTemplate {
9821000
pub gpu_cache_handle: GpuCacheHandle,
9831001
}
9841002

985-
impl From<PrimitiveKey> for PrimitiveTemplate {
986-
fn from(item: PrimitiveKey) -> Self {
987-
let prim_rect = item.prim_rect.into();
988-
let clip_rect = item.clip_rect.into();
989-
let kind = item.kind.into_template(&prim_rect);
990-
991-
PrimitiveTemplate {
992-
is_backface_visible: item.is_backface_visible,
993-
prim_rect,
994-
clip_rect,
995-
kind,
1003+
impl PrimTemplateCommonData {
1004+
pub fn with_key_common(common: PrimKeyCommonData) -> Self {
1005+
PrimTemplateCommonData {
1006+
is_backface_visible: common.is_backface_visible,
1007+
prim_rect: common.prim_rect.into(),
1008+
clip_rect: common.clip_rect.into(),
9961009
gpu_cache_handle: GpuCacheHandle::new(),
9971010
opacity: PrimitiveOpacity::translucent(),
9981011
}
9991012
}
10001013
}
10011014

1015+
#[cfg_attr(feature = "capture", derive(Serialize))]
1016+
#[cfg_attr(feature = "replay", derive(Deserialize))]
1017+
pub struct PrimitiveTemplate {
1018+
pub common: PrimTemplateCommonData,
1019+
pub kind: PrimitiveTemplateKind,
1020+
}
1021+
1022+
impl ops::Deref for PrimitiveTemplate {
1023+
type Target = PrimTemplateCommonData;
1024+
fn deref(&self) -> &Self::Target {
1025+
&self.common
1026+
}
1027+
}
1028+
1029+
impl ops::DerefMut for PrimitiveTemplate {
1030+
fn deref_mut(&mut self) -> &mut Self::Target {
1031+
&mut self.common
1032+
}
1033+
}
1034+
1035+
impl From<PrimitiveKey> for PrimitiveTemplate {
1036+
fn from(item: PrimitiveKey) -> Self {
1037+
let common = PrimTemplateCommonData::with_key_common(item.common);
1038+
let kind = item.kind.into_template(&common.prim_rect);
1039+
1040+
PrimitiveTemplate { common, kind, }
1041+
}
1042+
}
1043+
10021044
impl PrimitiveTemplateKind {
10031045
/// Write any GPU blocks for the primitive template to the given request object.
10041046
fn write_prim_gpu_blocks(
@@ -1173,10 +1215,10 @@ impl PrimitiveTemplate {
11731215
surface_index: SurfaceIndex,
11741216
frame_state: &mut FrameBuildingState,
11751217
) {
1176-
if let Some(mut request) = frame_state.gpu_cache.request(&mut self.gpu_cache_handle) {
1218+
if let Some(mut request) = frame_state.gpu_cache.request(&mut self.common.gpu_cache_handle) {
11771219
self.kind.write_prim_gpu_blocks(
11781220
&mut request,
1179-
self.prim_rect.size,
1221+
self.common.prim_rect.size,
11801222
);
11811223
self.kind.write_segment_gpu_blocks(&mut request);
11821224
}
@@ -1215,8 +1257,8 @@ impl PrimitiveTemplate {
12151257
// then we just assume the gradient is translucent for now.
12161258
// (In the future we could consider segmenting in some cases).
12171259
let stride = stretch_size + tile_spacing;
1218-
if stride.width >= self.prim_rect.size.width &&
1219-
stride.height >= self.prim_rect.size.height {
1260+
if stride.width >= self.common.prim_rect.size.width &&
1261+
stride.height >= self.common.prim_rect.size.height {
12201262
stops_opacity
12211263
} else {
12221264
PrimitiveOpacity::translucent()

webrender/src/prim_store/text_run.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,30 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
use api::{AuHelpers, ColorF, DevicePixelScale, GlyphInstance, LayoutPrimitiveInfo};
6-
use api::{LayoutRect, LayoutToWorldTransform, LayoutVector2DAu, RasterSpace};
6+
use api::{LayoutToWorldTransform, LayoutVector2DAu, RasterSpace};
77
use api::Shadow;
88
use display_list_flattener::{AsInstanceKind, CreateShadow, IsVisible};
99
use frame_builder::{FrameBuildingState, PictureContext};
1010
use glyph_rasterizer::{FontInstance, FontTransform, GlyphKey, FONT_SIZE_LIMIT};
11-
use gpu_cache::{GpuCache, GpuCacheHandle};
11+
use gpu_cache::GpuCache;
1212
use intern;
1313
use prim_store::{PrimitiveOpacity, PrimitiveSceneData, PrimitiveScratchBuffer};
14-
use prim_store::{PrimitiveStore, RectangleKey};
14+
use prim_store::{PrimitiveStore, PrimKeyCommonData, PrimTemplateCommonData};
1515
use render_task::{RenderTaskTree};
1616
use renderer::{MAX_VERTEX_TEXTURE_WIDTH};
1717
use resource_cache::{ResourceCache};
1818
use tiling::SpecialRenderPasses;
1919
use util::{MatrixHelpers};
2020
use prim_store::PrimitiveInstanceKind;
21+
use std::ops;
2122
use storage;
2223

2324
/// A run of glyphs, with associated font information.
2425
#[cfg_attr(feature = "capture", derive(Serialize))]
2526
#[cfg_attr(feature = "replay", derive(Deserialize))]
2627
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
2728
pub struct TextRunKey {
28-
pub is_backface_visible: bool,
29-
pub prim_rect: RectangleKey,
30-
pub clip_rect: RectangleKey,
29+
pub common: PrimKeyCommonData,
3130
pub font: FontInstance,
3231
pub offset: LayoutVector2DAu,
3332
pub glyphs: Vec<GlyphInstance>,
@@ -37,9 +36,7 @@ pub struct TextRunKey {
3736
impl TextRunKey {
3837
pub fn new(info: &LayoutPrimitiveInfo, text_run: TextRun) -> Self {
3938
TextRunKey {
40-
is_backface_visible: info.is_backface_visible,
41-
prim_rect: info.rect.into(),
42-
clip_rect: info.clip_rect.into(),
39+
common: PrimKeyCommonData::with_info(info),
4340
font: text_run.font,
4441
offset: text_run.offset.into(),
4542
glyphs: text_run.glyphs,
@@ -69,31 +66,33 @@ impl AsInstanceKind<TextRunDataHandle> for TextRunKey {
6966
#[cfg_attr(feature = "capture", derive(Serialize))]
7067
#[cfg_attr(feature = "replay", derive(Deserialize))]
7168
pub struct TextRunTemplate {
72-
pub is_backface_visible: bool,
73-
pub prim_rect: LayoutRect,
74-
pub clip_rect: LayoutRect,
69+
pub common: PrimTemplateCommonData,
7570
pub font: FontInstance,
7671
pub offset: LayoutVector2DAu,
7772
pub glyphs: Vec<GlyphInstance>,
78-
pub opacity: PrimitiveOpacity,
79-
/// The GPU cache handle for a primitive template. Since this structure
80-
/// is retained across display lists by interning, this GPU cache handle
81-
/// also remains valid, which reduces the number of updates to the GPU
82-
/// cache when a new display list is processed.
83-
pub gpu_cache_handle: GpuCacheHandle,
73+
}
74+
75+
impl ops::Deref for TextRunTemplate {
76+
type Target = PrimTemplateCommonData;
77+
fn deref(&self) -> &Self::Target {
78+
&self.common
79+
}
80+
}
81+
82+
impl ops::DerefMut for TextRunTemplate {
83+
fn deref_mut(&mut self) -> &mut Self::Target {
84+
&mut self.common
85+
}
8486
}
8587

8688
impl From<TextRunKey> for TextRunTemplate {
8789
fn from(item: TextRunKey) -> Self {
90+
let common = PrimTemplateCommonData::with_key_common(item.common);
8891
TextRunTemplate {
89-
is_backface_visible: item.is_backface_visible,
90-
prim_rect: item.prim_rect.into(),
91-
clip_rect: item.clip_rect.into(),
92+
common,
9293
font: item.font,
9394
offset: item.offset,
9495
glyphs: item.glyphs,
95-
opacity: PrimitiveOpacity::translucent(),
96-
gpu_cache_handle: GpuCacheHandle::new(),
9796
}
9897
}
9998
}
@@ -115,7 +114,7 @@ impl TextRunTemplate {
115114
&mut self,
116115
frame_state: &mut FrameBuildingState,
117116
) {
118-
if let Some(mut request) = frame_state.gpu_cache.request(&mut self.gpu_cache_handle) {
117+
if let Some(mut request) = frame_state.gpu_cache.request(&mut self.common.gpu_cache_handle) {
119118
request.push(ColorF::from(self.font.color).premultiplied());
120119
// this is the only case where we need to provide plain color to GPU
121120
let bg_color = ColorF::from(self.font.bg_color);

0 commit comments

Comments
 (0)