Allow shadows to be colored when physical layer is drawn by engine (flutter/engine#4812)
* pass shadow_color from dart:ui to physical layer * default shadow color to SK_ColorBLACK * add doc comments to pushPhysicalShape
This commit is contained in:
@@ -109,6 +109,7 @@ void DefaultLayerBuilder::PushShaderMask(sk_sp<SkShader> 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);
|
||||
}
|
||||
|
||||
@@ -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|
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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_);
|
||||
}
|
||||
|
||||
|
||||
@@ -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_;
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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<SkColor>(color), //
|
||||
static_cast<SkColor>(shadow_color),
|
||||
UIDartState::Current()->window()->viewport_metrics().device_pixel_ratio);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ class SceneBuilder : public fxl::RefCountedThreadSafe<SceneBuilder>,
|
||||
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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user