From 3257622d4b3dfa28f33e6cea9dff78f0fa4cdc38 Mon Sep 17 00:00:00 2001 From: David Worsham Date: Wed, 8 Jan 2020 12:15:12 -0800 Subject: [PATCH] Fix bad PhysicalShapeLayer performance when using system_composite --- flow/layers/physical_shape_layer.cc | 51 +++++------------------------ flow/layers/physical_shape_layer.h | 4 --- 2 files changed, 9 insertions(+), 46 deletions(-) diff --git a/flow/layers/physical_shape_layer.cc b/flow/layers/physical_shape_layer.cc index 524c5a2ac939a..996fc1a3331f5 100644 --- a/flow/layers/physical_shape_layer.cc +++ b/flow/layers/physical_shape_layer.cc @@ -45,8 +45,6 @@ PhysicalShapeLayer::PhysicalShapeLayer(SkColor color, // an SkPath. frameRRect_ = SkRRect::MakeRect(path.getBounds()); } - - set_dimensions(frameRRect_); } void PhysicalShapeLayer::Preroll(PrerollContext* context, @@ -61,57 +59,26 @@ void PhysicalShapeLayer::Preroll(PrerollContext* context, set_paint_bounds(path_.getBounds()); } else { if (PhysicalShapeLayerBase::can_system_composite()) { + // always system composite these layers when possible and an elevation is + // present; we are doing it for the shadow effect and in order for + // elevation to be construed as height in Z set_needs_system_composite(true); + + // paint_bounds should be explicitly empty when dimensions is set, or the + // layer's children could be drawn twice + set_dimensions(frameRRect_); + set_paint_bounds(SkRect::MakeEmpty()); + return; } - //#if defined(OS_FUCHSIA) - // // Let the system compositor draw all shadows for us. - // set_needs_system_composite(true); - //#else // We will draw the shadow in Paint(), so add some margin to the paint // bounds to leave space for the shadow. We fill this whole region and clip // children to it so we don't need to join the child paint bounds. set_paint_bounds(ComputeShadowBounds(path_.getBounds(), elevation(), context->frame_device_pixel_ratio)); - //#endif // defined(OS_FUCHSIA) - } -} - -#if defined(OS_FUCHSIA) - -void PhysicalShapeLayer::UpdateScene(SceneUpdateContext& context) { - FML_DCHECK(needs_system_composite()); - TRACE_EVENT0("flutter", "PhysicalShapeLayer::UpdateScene"); - - // Retained rendering: speedup by reusing a retained entity node if possible. - // When an entity node is reused, no paint layer is added to the frame so we - // won't call PhysicalShapeLayer::Paint. - LayerRasterCacheKey key(unique_id(), context.Matrix()); - if (context.HasRetainedNode(key)) { - TRACE_EVENT_INSTANT0("flutter", "retained layer cache hit"); - const scenic::EntityNode& retained_node = context.GetRetainedNode(key); - FML_DCHECK(context.top_entity()); - FML_DCHECK(retained_node.session() == context.session()); - context.top_entity()->entity_node().AddChild(retained_node); - return; } - - TRACE_EVENT_INSTANT0("flutter", "cache miss, creating"); - // If we can't find an existing retained surface, create one. - SceneUpdateContext::Frame frame(context, frameRRect_, color(), opacity(), - elevation(), this); - - for (auto& layer : layers()) { - if (layer->needs_painting()) { - frame.AddPaintLayer(layer.get()); - } - } - - UpdateSceneChildren(context); } -#endif // defined(OS_FUCHSIA) - void PhysicalShapeLayer::Paint(PaintContext& context) const { TRACE_EVENT0("flutter", "PhysicalShapeLayer::Paint"); FML_DCHECK(needs_painting()); diff --git a/flow/layers/physical_shape_layer.h b/flow/layers/physical_shape_layer.h index 34b3c59fe355b..b309da7fd5386 100644 --- a/flow/layers/physical_shape_layer.h +++ b/flow/layers/physical_shape_layer.h @@ -55,10 +55,6 @@ class PhysicalShapeLayer : public PhysicalShapeLayerBase { return clip_behavior_ == Clip::antiAliasWithSaveLayer; } -#if defined(OS_FUCHSIA) - void UpdateScene(SceneUpdateContext& context) override; -#endif // defined(OS_FUCHSIA) - private: SkColor shadow_color_; SkPath path_;