Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@jason-simmons
Copy link
Member

No description provided.

@jason-simmons
Copy link
Member Author

@abarth


// 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);
Copy link
Contributor

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.

Copy link
Member Author

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.

context->child_paint_bounds.setEmpty();

// Add some margin to the paint bounds to leave space for the shadow.
SkRect bounds(context->child_paint_bounds);
Copy link
Contributor

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.

Copy link
Member Author

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());
Copy link
Contributor

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.

Copy link
Member Author

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.

context.canvas.drawPath(path, paint);

SkAutoCanvasRestore save(&context.canvas, false);
context.canvas.saveLayer(&paint_bounds(), nullptr);
Copy link
Contributor

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).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

/// Rasterization will be clipped to the given shape.
///
/// See [pop] for details about the operation stack.
void pushPhysicalModel(RRect rrect, int elevation, Color color) {
Copy link
Contributor

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.

/// Rasterization will be clipped to the given shape.
///
/// See [pop] for details about the operation stack.
void pushPhysicalModel({RRect rrect, int elevation, Color color}) {
Copy link
Contributor

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.

@abarth
Copy link
Contributor

abarth commented Feb 15, 2017

LGTM

}

SkPaint paint;
paint.setColor(SkColorSetA(color_, 0xFF));
Copy link
Member

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.

Copy link
Member Author

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());
Copy link
Member

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.

@chinmaygarde
Copy link
Member

Can we land this?

@jason-simmons jason-simmons force-pushed the physical_model branch 2 times, most recently from bcf90c2 to 472f5ba Compare February 17, 2017 00:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants