Skip to content

Commit

Permalink
Allow shadows to be colored when physical layer is drawn by engine (f…
Browse files Browse the repository at this point in the history
…lutter#4812)

* pass shadow_color from dart:ui to physical layer

* default shadow color to SK_ColorBLACK

* add doc comments to pushPhysicalShape
  • Loading branch information
jonahwilliams authored Mar 19, 2018
1 parent a9b5e1b commit bb2d177
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 7 deletions.
2 changes: 2 additions & 0 deletions flow/layers/default_layer_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand All @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions flow/layers/default_layer_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
1 change: 1 addition & 0 deletions flow/layers/layer_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion flow/layers/physical_shape_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
}

Expand Down
2 changes: 2 additions & 0 deletions flow/layers/physical_shape_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -38,6 +39,7 @@ class PhysicalShapeLayer : public ContainerLayer {
private:
float elevation_;
SkColor color_;
SkColor shadow_color_;
SkScalar device_pixel_ratio_;
SkPath path_;
bool isRect_;
Expand Down
11 changes: 7 additions & 4 deletions lib/ui/compositing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion lib/ui/compositing/scene_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ui/compositing/scene_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit bb2d177

Please sign in to comment.