-
Notifications
You must be signed in to change notification settings - Fork 6k
Physical model layer that can draw shadows for a Material widget #3424
Conversation
1598af2 to
0d58d73
Compare
|
|
||
| // Add some margin to the paint bounds to leave space for the shadow. | ||
| SkRect bounds(context->child_paint_bounds); | ||
| bounds.outset(50.0, 50.0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do these numbers come from? We might need a way to ask SkShadowUtils how much space to reserve for a shadow with certain parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a hardcoded estimate of the upper bounds for where DrawShadow will paint. AFAIK Skia doesn't have a way to calculate this precisely. Added a comment.
flow/layers/physical_model_layer.cc
Outdated
| context->child_paint_bounds.setEmpty(); | ||
|
|
||
| // Add some margin to the paint bounds to leave space for the shadow. | ||
| SkRect bounds(context->child_paint_bounds); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem like the child paint bounds are relevant to computing the paint bounds of this layer. This layer is always going to be rrect_ + whatever margin we need for the shadow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
|
||
| void PhysicalModelLayer::Paint(PaintContext& context) { | ||
| TRACE_EVENT0("flutter", "PhysicalModelLayer::Paint"); | ||
| FTL_DCHECK(!needs_system_composite()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This DCHECK is going to blow up in Fuchsia. We should be able to do a system-composited version of this layer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like Fuchsia support will require a broader refactoring. Added a TODO.
flow/layers/physical_model_layer.cc
Outdated
| context.canvas.drawPath(path, paint); | ||
|
|
||
| SkAutoCanvasRestore save(&context.canvas, false); | ||
| context.canvas.saveLayer(&paint_bounds(), nullptr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should check whether the rrect is actually a rect (i.e., whether the radius is zero) and use save() rather than saveLayer() in that case.
Also, using the full paint_bounds is allocating a larger texture than necessary because the child cannot draw outside the clip. Instead, we should use the bounds of the rrect to for the size of the layer we save (skipping the margin we added to the paint bounds for the child).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
lib/ui/compositing.dart
Outdated
| /// Rasterization will be clipped to the given shape. | ||
| /// | ||
| /// See [pop] for details about the operation stack. | ||
| void pushPhysicalModel(RRect rrect, int elevation, Color color) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd make these named arguments because we're likely to extend them over time.
0d58d73 to
3dd2c5a
Compare
lib/ui/compositing.dart
Outdated
| /// Rasterization will be clipped to the given shape. | ||
| /// | ||
| /// See [pop] for details about the operation stack. | ||
| void pushPhysicalModel({RRect rrect, int elevation, Color color}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually put spaces after { and before } here.
3dd2c5a to
b48ac29
Compare
| } | ||
|
|
||
| SkPaint paint; | ||
| paint.setColor(SkColorSetA(color_, 0xFF)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is updating the alpha necessary? Might be unexpected behavior for callers expecting a lighter shadow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skia will draw some of the shadow within the bounds of the layer, so we're filling the layer with an opaque color to cover that part of the shadow
| if (!cullRect.intersect(rrect.sk_rrect.rect(), m_cullRects.top())) | ||
| cullRect = SkRect::MakeEmpty(); | ||
|
|
||
| std::unique_ptr<flow::PhysicalModelLayer> layer(new flow::PhysicalModelLayer()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: auto layer = std::make_unique<...> might be easier to write.
|
Can we land this? |
bcf90c2 to
472f5ba
Compare
472f5ba to
ab7b1e5
Compare

No description provided.