diff --git a/engine/src/flutter/flow/layers/default_layer_builder.cc b/engine/src/flutter/flow/layers/default_layer_builder.cc index 3f59943f77..9cf822528f 100644 --- a/engine/src/flutter/flow/layers/default_layer_builder.cc +++ b/engine/src/flutter/flow/layers/default_layer_builder.cc @@ -109,6 +109,7 @@ void DefaultLayerBuilder::PushShaderMask(sk_sp shader, void DefaultLayerBuilder::PushPhysicalShape(const SkPath& sk_path, double elevation, SkColor color, + SkColor shadow_color, SkScalar device_pixel_ratio) { SkRect cullRect; if (!cullRect.intersect(sk_path.getBounds(), cull_rects_.top())) { @@ -118,6 +119,7 @@ void DefaultLayerBuilder::PushPhysicalShape(const SkPath& sk_path, layer->set_path(sk_path); layer->set_elevation(elevation); layer->set_color(color); + layer->set_shadow_color(shadow_color); layer->set_device_pixel_ratio(device_pixel_ratio); PushLayer(std::move(layer), cullRect); } diff --git a/engine/src/flutter/flow/layers/default_layer_builder.h b/engine/src/flutter/flow/layers/default_layer_builder.h index 034769355c..a62ec46714 100644 --- a/engine/src/flutter/flow/layers/default_layer_builder.h +++ b/engine/src/flutter/flow/layers/default_layer_builder.h @@ -50,6 +50,7 @@ class DefaultLayerBuilder final : public LayerBuilder { void PushPhysicalShape(const SkPath& path, double elevation, SkColor color, + SkColor shadow_color, SkScalar device_pixel_ratio) override; // |flow::LayerBuilder| diff --git a/engine/src/flutter/flow/layers/layer_builder.h b/engine/src/flutter/flow/layers/layer_builder.h index ee181a9682..91ae13974a 100644 --- a/engine/src/flutter/flow/layers/layer_builder.h +++ b/engine/src/flutter/flow/layers/layer_builder.h @@ -50,6 +50,7 @@ class LayerBuilder { virtual void PushPhysicalShape(const SkPath& path, double elevation, SkColor color, + SkColor shadow_color, SkScalar device_pixel_ratio) = 0; virtual void PushPerformanceOverlay(uint64_t enabled_options, diff --git a/engine/src/flutter/flow/layers/physical_shape_layer.cc b/engine/src/flutter/flow/layers/physical_shape_layer.cc index e977add750..a730f9a8f9 100644 --- a/engine/src/flutter/flow/layers/physical_shape_layer.cc +++ b/engine/src/flutter/flow/layers/physical_shape_layer.cc @@ -82,7 +82,7 @@ void PhysicalShapeLayer::Paint(PaintContext& context) const { FXL_DCHECK(needs_painting()); if (elevation_ != 0) { - DrawShadow(&context.canvas, path_, SK_ColorBLACK, elevation_, + DrawShadow(&context.canvas, path_, shadow_color_, elevation_, SkColorGetA(color_) != 0xff, device_pixel_ratio_); } diff --git a/engine/src/flutter/flow/layers/physical_shape_layer.h b/engine/src/flutter/flow/layers/physical_shape_layer.h index 1976c77b09..c3df356b63 100644 --- a/engine/src/flutter/flow/layers/physical_shape_layer.h +++ b/engine/src/flutter/flow/layers/physical_shape_layer.h @@ -18,6 +18,7 @@ class PhysicalShapeLayer : public ContainerLayer { void set_elevation(float elevation) { elevation_ = elevation; } void set_color(SkColor color) { color_ = color; } + void set_shadow_color(SkColor shadow_color) { shadow_color_ = shadow_color; } void set_device_pixel_ratio(SkScalar dpr) { device_pixel_ratio_ = dpr; } static void DrawShadow(SkCanvas* canvas, @@ -38,6 +39,7 @@ class PhysicalShapeLayer : public ContainerLayer { private: float elevation_; SkColor color_; + SkColor shadow_color_; SkScalar device_pixel_ratio_; SkPath path_; bool isRect_; diff --git a/engine/src/flutter/lib/ui/compositing.dart b/engine/src/flutter/lib/ui/compositing.dart index af82d4d374..97e6c59e53 100644 --- a/engine/src/flutter/lib/ui/compositing.dart +++ b/engine/src/flutter/lib/ui/compositing.dart @@ -130,13 +130,16 @@ class SceneBuilder extends NativeFieldWrapperClass2 { /// Pushes a physical layer operation for an arbitrary shape onto the /// operation stack. /// - /// Rasterization will be clipped to the given shape. + /// Rasterization will be clipped to the given shape defined by [path]. If + /// [elevation] is greater than 0.0, then a shadow is drawn around the layer. + /// [shadowColor] defines the color of the shadow if present and [color] defines the + /// color of the layer background. /// /// See [pop] for details about the operation stack. - void pushPhysicalShape({ Path path, double elevation, Color color }) { - _pushPhysicalShape(path, elevation, color.value); + void pushPhysicalShape({ Path path, double elevation, Color color, Color shadowColor}) { + _pushPhysicalShape(path, elevation, color.value, shadowColor?.value ?? 0xFF000000); } - void _pushPhysicalShape(Path path, double elevation, int color) native + void _pushPhysicalShape(Path path, double elevation, int color, int shadowColor) native 'SceneBuilder_pushPhysicalShape'; /// Ends the effect of the most recently pushed operation. diff --git a/engine/src/flutter/lib/ui/compositing/scene_builder.cc b/engine/src/flutter/lib/ui/compositing/scene_builder.cc index 44f6c62477..006826abbf 100644 --- a/engine/src/flutter/lib/ui/compositing/scene_builder.cc +++ b/engine/src/flutter/lib/ui/compositing/scene_builder.cc @@ -102,11 +102,13 @@ void SceneBuilder::pushShaderMask(Shader* shader, void SceneBuilder::pushPhysicalShape(const CanvasPath* path, double elevation, - int color) { + int color, + int shadow_color) { layer_builder_->PushPhysicalShape( path->path(), // elevation, // static_cast(color), // + static_cast(shadow_color), UIDartState::Current()->window()->viewport_metrics().device_pixel_ratio); } diff --git a/engine/src/flutter/lib/ui/compositing/scene_builder.h b/engine/src/flutter/lib/ui/compositing/scene_builder.h index 873d91d964..fd1e20d2aa 100644 --- a/engine/src/flutter/lib/ui/compositing/scene_builder.h +++ b/engine/src/flutter/lib/ui/compositing/scene_builder.h @@ -47,7 +47,7 @@ class SceneBuilder : public fxl::RefCountedThreadSafe, double maskRectTop, double maskRectBottom, int blendMode); - void pushPhysicalShape(const CanvasPath* path, double elevation, int color); + void pushPhysicalShape(const CanvasPath* path, double elevation, int color, int shadowColor); void pop();