@@ -52,23 +52,32 @@ void PhysicalShapeLayer::Preroll(PrerollContext* context,
5252
5353 context->total_elevation += elevation_;
5454 total_elevation_ = context->total_elevation ;
55+ #if defined(OS_FUCHSIA)
56+ child_layer_exists_below_ = context->child_scene_layer_exists_below ;
57+ context->child_scene_layer_exists_below = false ;
58+ #endif
59+
5560 SkRect child_paint_bounds;
5661 PrerollChildren (context, matrix, &child_paint_bounds);
62+
63+ #if defined(OS_FUCHSIA)
64+ children_need_system_compositing_ = needs_system_composite ();
65+ if (child_layer_exists_below_) {
66+ set_needs_system_composite (true );
67+ }
68+ context->child_scene_layer_exists_below =
69+ context->child_scene_layer_exists_below || child_layer_exists_below_;
70+ #endif
5771 context->total_elevation -= elevation_;
5872
5973 if (elevation_ == 0 ) {
6074 set_paint_bounds (path_.getBounds ());
6175 } else {
62- #if defined(OS_FUCHSIA)
63- // Let the system compositor draw all shadows for us.
64- set_needs_system_composite (true );
65- #else
6676 // We will draw the shadow in Paint(), so add some margin to the paint
6777 // bounds to leave space for the shadow. We fill this whole region and clip
6878 // children to it so we don't need to join the child paint bounds.
6979 set_paint_bounds (ComputeShadowBounds (path_.getBounds (), elevation_,
7080 context->frame_device_pixel_ratio ));
71- #endif // defined(OS_FUCHSIA)
7281 }
7382}
7483
@@ -78,37 +87,53 @@ void PhysicalShapeLayer::UpdateScene(SceneUpdateContext& context) {
7887 FML_DCHECK (needs_system_composite ());
7988 TRACE_EVENT0 (" flutter" , " PhysicalShapeLayer::UpdateScene" );
8089
81- float global_scenic_elevation =
82- context.GetGlobalElevationForNextScenicLayer ();
83- float local_scenic_elevation_ =
84- global_scenic_elevation - context.scenic_elevation ();
85- float z_translation = -local_scenic_elevation_;
86-
87- // Retained rendering: speedup by reusing a retained entity node if possible.
88- // When an entity node is reused, no paint layer is added to the frame so we
89- // won't call PhysicalShapeLayer::Paint.
90- LayerRasterCacheKey key (unique_id (), context.Matrix ());
91- if (context.HasRetainedNode (key)) {
92- TRACE_EVENT_INSTANT0 (" flutter" , " retained layer cache hit" );
93- scenic::EntityNode* retained_node = context.GetRetainedNode (key);
94- FML_DCHECK (context.top_entity ());
95- FML_DCHECK (retained_node->session () == context.session ());
96-
97- // Re-adjust the elevation.
98- retained_node->SetTranslation (0 .f , 0 .f , z_translation);
99-
100- context.top_entity ()->entity_node ().AddChild (*retained_node);
101- return ;
102- }
90+ // If there is embedded Fuchsia content in the scene (a ChildSceneLayer),
91+ // PhysicalShapeLayers that appear above the embedded content will be turned
92+ // into their own Scenic layers.
93+ if (child_layer_exists_below_) {
94+ // Reset paint bounds, because shadows are not rendered in this case
95+ // (see comment in Paint()).
96+ set_paint_bounds (path_.getBounds ());
10397
104- TRACE_EVENT_INSTANT0 (" flutter" , " cache miss, creating" );
105- // If we can't find an existing retained surface, create one.
106- SceneUpdateContext::Frame frame (
107- context, frameRRect_, color_, sk_float_round2int (context.alphaf () * 255 ),
108- " flutter::PhysicalShapeLayer" , z_translation, this );
109- for (auto & layer : layers ()) {
110- if (layer->needs_painting ()) {
111- frame.AddPaintLayer (layer.get ());
98+ float global_scenic_elevation = context.GetGlobalElevationForNextScenicLayer ();
99+ float local_scenic_elevation_ =
100+ global_scenic_elevation - context.scenic_elevation ();
101+ float z_translation = -local_scenic_elevation_;
102+
103+ // Retained rendering: speedup by reusing a retained entity node if
104+ // possible. When an entity node is reused, no paint layer is added to the
105+ // frame so we won't call PhysicalShapeLayer::Paint.
106+ LayerRasterCacheKey key (unique_id (), context.Matrix ());
107+ if (context.HasRetainedNode (key)) {
108+ TRACE_EVENT_INSTANT0 (" flutter" , " retained layer cache hit" );
109+ scenic::EntityNode* retained_node = context.GetRetainedNode (key);
110+ FML_DCHECK (context.top_entity ());
111+ FML_DCHECK (retained_node->session () == context.session ());
112+
113+ // Re-adjust the elevation.
114+ retained_node->SetTranslation (0 .f , 0 .f , z_translation);
115+
116+ context.top_entity ()->entity_node ().AddChild (*retained_node);
117+ return ;
118+ }
119+
120+ TRACE_EVENT_INSTANT0 (" flutter" , " cache miss, creating" );
121+ // If we can't find an existing retained surface, create one.
122+ SceneUpdateContext::Frame frame (context, frameRRect_, SK_ColorTRANSPARENT,
123+ sk_float_round2int (context.alphaf () * 255 ),
124+ " flutter::PhysicalShapeLayer" ,
125+ z_translation, this );
126+
127+ frame.AddPaintLayer (this );
128+
129+ // Node: UpdateSceneChildren needs to be called here so that |frame| is still
130+ // in scope (and therefore alive) while UpdateSceneChildren is being called.
131+ if (children_need_system_compositing_) {
132+ UpdateSceneChildren (context);
133+ }
134+ } else {
135+ if (children_need_system_compositing_) {
136+ UpdateSceneChildren (context);
112137 }
113138 }
114139}
@@ -128,7 +153,19 @@ void PhysicalShapeLayer::Paint(PaintContext& context) const {
128153 TRACE_EVENT0 (" flutter" , " PhysicalShapeLayer::Paint" );
129154 FML_DCHECK (needs_painting ());
130155
156+
157+ #if defined(OS_FUCHSIA)
158+ // TODO: Re-enable shadow drawing here.
159+ // Shadows are not rendered for PhysicalShapeLayers that exist as separate
160+ // system services; this is to maintain compatibility with the previous
161+ // implementation and has the added benefit of requiring smaller textures, since
162+ // extra space is not needed for the shadows.
163+ // This behavior might change after clients adjust their usage of PhysicalShaperLayer
164+ // to make elevation correlate to desired shadow size.
165+ if (false && !child_layer_exists_below_ && elevation_ != 0 ) {
166+ #else
131167 if (elevation_ != 0 ) {
168+ #endif
132169 DrawShadow (context.leaf_nodes_canvas , path_, shadow_color_, elevation_,
133170 SkColorGetA (color_) != 0xff , context.frame_device_pixel_ratio );
134171 }
0 commit comments