@@ -623,10 +623,27 @@ impl From<LayoutPoint> for PointKey {
623
623
#[ cfg_attr( feature = "capture" , derive( Serialize ) ) ]
624
624
#[ cfg_attr( feature = "replay" , derive( Deserialize ) ) ]
625
625
#[ derive( Debug , Clone , Eq , PartialEq , Hash ) ]
626
- pub struct PrimitiveKey {
626
+ pub struct PrimKeyCommonData {
627
627
pub is_backface_visible : bool ,
628
628
pub prim_rect : RectangleKey ,
629
629
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 ,
630
647
pub kind : PrimitiveKeyKind ,
631
648
}
632
649
@@ -638,9 +655,11 @@ impl PrimitiveKey {
638
655
kind : PrimitiveKeyKind ,
639
656
) -> Self {
640
657
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
+ } ,
644
663
kind,
645
664
}
646
665
}
@@ -969,11 +988,10 @@ impl PrimitiveKeyKind {
969
988
970
989
#[ cfg_attr( feature = "capture" , derive( Serialize ) ) ]
971
990
#[ cfg_attr( feature = "replay" , derive( Deserialize ) ) ]
972
- pub struct PrimitiveTemplate {
991
+ pub struct PrimTemplateCommonData {
973
992
pub is_backface_visible : bool ,
974
993
pub prim_rect : LayoutRect ,
975
994
pub clip_rect : LayoutRect ,
976
- pub kind : PrimitiveTemplateKind ,
977
995
pub opacity : PrimitiveOpacity ,
978
996
/// The GPU cache handle for a primitive template. Since this structure
979
997
/// is retained across display lists by interning, this GPU cache handle
@@ -982,23 +1000,47 @@ pub struct PrimitiveTemplate {
982
1000
pub gpu_cache_handle : GpuCacheHandle ,
983
1001
}
984
1002
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 ( ) ,
996
1009
gpu_cache_handle : GpuCacheHandle :: new ( ) ,
997
1010
opacity : PrimitiveOpacity :: translucent ( ) ,
998
1011
}
999
1012
}
1000
1013
}
1001
1014
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
+
1002
1044
impl PrimitiveTemplateKind {
1003
1045
/// Write any GPU blocks for the primitive template to the given request object.
1004
1046
fn write_prim_gpu_blocks (
@@ -1173,10 +1215,10 @@ impl PrimitiveTemplate {
1173
1215
surface_index : SurfaceIndex ,
1174
1216
frame_state : & mut FrameBuildingState ,
1175
1217
) {
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 ) {
1177
1219
self . kind . write_prim_gpu_blocks (
1178
1220
& mut request,
1179
- self . prim_rect . size ,
1221
+ self . common . prim_rect . size ,
1180
1222
) ;
1181
1223
self . kind . write_segment_gpu_blocks ( & mut request) ;
1182
1224
}
@@ -1215,8 +1257,8 @@ impl PrimitiveTemplate {
1215
1257
// then we just assume the gradient is translucent for now.
1216
1258
// (In the future we could consider segmenting in some cases).
1217
1259
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 {
1220
1262
stops_opacity
1221
1263
} else {
1222
1264
PrimitiveOpacity :: translucent ( )
0 commit comments