@@ -17,31 +17,35 @@ PhysicalShapeLayer::PhysicalShapeLayer(SkColor color,
1717 float elevation,
1818 const SkPath& path,
1919 Clip clip_behavior)
20- : color_ (color),
20+ : PhysicalShapeLayerBase (color, elevation ),
2121 shadow_color_ (shadow_color),
22- elevation_(elevation),
2322 path_(path),
24- isRect_(false ),
2523 clip_behavior_(clip_behavior) {
24+ // If rendering as a separate frame using the system compositor, then make
25+ // sure to set up the properties needed to do so.
26+ #if defined(OS_FUCHSIA)
2627 SkRect rect;
28+ SkRRect rrect;
2729 if (path.isRect (&rect)) {
28- isRect_ = true ;
29- frameRRect_ = SkRRect::MakeRect (rect);
30- } else if (path.isRRect (&frameRRect_)) {
31- isRect_ = frameRRect_.isRect ();
30+ rrect = SkRRect::MakeRect (rect);
31+ } else if (path.isRRect (&rrect)) {
32+ // Nothing needed here, as isRRect will fill in frameRRect_ already.
3233 } else if (path.isOval (&rect)) {
3334 // isRRect returns false for ovals, so we need to explicitly check isOval
3435 // as well.
35- frameRRect_ = SkRRect::MakeOval (rect);
36+ rrect = SkRRect::MakeOval (rect);
3637 } else {
3738 // Scenic currently doesn't provide an easy way to create shapes from
3839 // arbitrary paths.
3940 // For shapes that cannot be represented as a rounded rectangle we
4041 // default to use the bounding rectangle.
4142 // TODO(amirh): fix this once we have a way to create a Scenic shape from
4243 // an SkPath.
43- frameRRect_ = SkRRect::MakeRect (path.getBounds ());
44+ rrect = SkRRect::MakeRect (path.getBounds ());
4445 }
46+
47+ set_dimensions (rrect);
48+ #endif
4549}
4650
4751Layer::AnalysisResult PhysicalShapeLayer::Analyze () const {
@@ -55,74 +59,39 @@ Layer::AnalysisResult PhysicalShapeLayer::Analyze() const {
5559void PhysicalShapeLayer::Preroll (PrerollContext* context,
5660 const SkMatrix& matrix) {
5761 TRACE_EVENT0 (" flutter" , " PhysicalShapeLayer::Preroll" );
58- context->total_elevation += elevation_;
59- total_elevation_ = context->total_elevation ;
60- SkRect child_paint_bounds;
61- PrerollChildren (context, matrix, &child_paint_bounds);
62- context->total_elevation -= elevation_;
63-
64- if (elevation_ == 0 ) {
65- set_paint_bounds (path_.getBounds ());
66- } else {
67- #if defined(OS_FUCHSIA)
68- // Let the system compositor draw all shadows for us.
69- set_needs_system_composite (true );
70- #else
71- // We will draw the shadow in Paint(), so add some margin to the paint
72- // bounds to leave space for the shadow. We fill this whole region and clip
73- // children to it so we don't need to join the child paint bounds.
74- set_paint_bounds (ComputeShadowBounds (path_.getBounds (), elevation_,
75- context->frame_device_pixel_ratio ));
76- #endif // defined(OS_FUCHSIA)
77- }
78- }
79-
80- #if defined(OS_FUCHSIA)
62+ PhysicalShapeLayerBase::Preroll (context, matrix);
8163
82- void PhysicalShapeLayer::UpdateScene (SceneUpdateContext& context) {
83- FML_DCHECK (needs_system_composite ());
84- TRACE_EVENT0 (" flutter" , " PhysicalShapeLayer::UpdateScene" );
85-
86- // Retained rendering: speedup by reusing a retained entity node if possible.
87- // When an entity node is reused, no paint layer is added to the frame so we
88- // won't call PhysicalShapeLayer::Paint.
89- LayerRasterCacheKey key (unique_id (), context.Matrix ());
90- if (context.HasRetainedNode (key)) {
91- TRACE_EVENT_INSTANT0 (" flutter" , " retained layer cache hit" );
92- const scenic::EntityNode& retained_node = context.GetRetainedNode (key);
93- FML_DCHECK (context.top_entity ());
94- FML_DCHECK (retained_node.session () == context.session ());
95- context.top_entity ()->entity_node ().AddChild (retained_node);
64+ // Use the system compositor for shadows if it's available. 0-elevation
65+ // doesn't cast shadows, so it never uses the system compositor.
66+ if (PhysicalShapeLayerBase::can_system_composite () && elevation () != 0 ) {
9667 return ;
9768 }
9869
99- TRACE_EVENT_INSTANT0 (" flutter" , " cache miss, creating" );
100- // If we can't find an existing retained surface, create one.
101- SceneUpdateContext::Frame frame (context, frameRRect_, color_, elevation_,
102- total_elevation_, this );
103- for (auto & layer : layers ()) {
104- if (layer->needs_painting ()) {
105- frame.AddPaintLayer (layer.get ());
106- }
70+ // We either can't (unavailable) or shouldn't (no shadows) use the system
71+ // compositor.
72+ set_needs_system_composite (false );
73+ set_paint_bounds (path_.getBounds ()); // Ignore children bounds; use the path
74+ if (elevation () != 0 ) {
75+ // We will draw the shadow in Paint(), so add some margin to the paint
76+ // bounds to leave space for the shadow. We fill this whole region and clip
77+ // children to it so we don't need to join the child paint bounds.
78+ set_paint_bounds (ComputeShadowBounds (paint_bounds (), elevation (),
79+ context->frame_device_pixel_ratio ));
10780 }
108-
109- UpdateSceneChildren (context);
11081}
11182
112- #endif // defined(OS_FUCHSIA)
113-
11483void PhysicalShapeLayer::Paint (PaintContext& context) const {
11584 TRACE_EVENT0 (" flutter" , " PhysicalShapeLayer::Paint" );
11685 FML_DCHECK (needs_painting ());
11786
118- if (elevation_ != 0 ) {
119- DrawShadow (context.leaf_nodes_canvas , path_, shadow_color_, elevation_ ,
120- SkColorGetA (color_ ) != 0xff , context.frame_device_pixel_ratio );
87+ if (elevation () != 0 ) {
88+ DrawShadow (context.leaf_nodes_canvas , path_, shadow_color_, elevation () ,
89+ SkColorGetA (color () ) != 0xff , context.frame_device_pixel_ratio );
12190 }
12291
12392 // Call drawPath without clip if possible for better performance.
12493 SkPaint paint;
125- paint.setColor (color_ );
94+ paint.setColor (color () );
12695 paint.setAntiAlias (true );
12796 if (clip_behavior_ != Clip::antiAliasWithSaveLayer) {
12897 context.leaf_nodes_canvas ->drawPath (path_, paint);
@@ -152,7 +121,7 @@ void PhysicalShapeLayer::Paint(PaintContext& context) const {
152121 context.leaf_nodes_canvas ->drawPaint (paint);
153122 }
154123
155- PaintChildren (context);
124+ PhysicalShapeLayerBase::Paint (context);
156125
157126 context.internal_nodes_canvas ->restoreToCount (saveCount);
158127}
0 commit comments