-
Notifications
You must be signed in to change notification settings - Fork 6k
Make ui.Canvas.getDestinationClipBounds works with matrix #34835
Conversation
flar
left a comment
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.
Clicking "submit" on the 2 changes I've identified so I don't forget, but I'm still looking at the unit tests when I can find the chance.
display_list/display_list_builder.cc
Outdated
| if (!current_layer_->clip_bounds.intersect(path.getBounds())) { | ||
| current_layer_->clip_bounds.setEmpty(); | ||
| } | ||
| intersect(path.getBounds()); |
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 "inverse fill type" here for completeness, but I don't think Flutter can create those so it's only theoretical.
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, I also added the logic for inverse fill type with SkClipOp::kDifference. (Although Flutter can't access it yet)
| clip.setFillType(SkPathFillType::kInverseWinding); | ||
| builder.clipPath(clip, SkClipOp::kIntersect, false); | ||
|
|
||
| SkRect initial_local_bounds = builder.getLocalClipBounds(); |
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.
"initial_"? That modifier would make sense if you were going to take measurements later on under a different name. It might be reasonable to just inline the getBounds calls into the ASSERT macros here.
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.
| builder.clipRect(clipBounds1, SkClipOp::kIntersect, false); | ||
| builder.translate(10, 0); | ||
| builder.clipRect(clipBounds1, SkClipOp::kIntersect, false); | ||
| ASSERT_EQ(builder.getDestinationClipBounds(), SkRect::MakeEmpty()); |
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.
Perhaps we should relax these to "get...Bounds().isEmpty()" rather than force a specific empty return value? Are they documented to return exactly that rectangle for an empty condition? I suppose we could just modify the test if we ever return a different value, but an implementation might decide to just max/min the 8 values and let their natural "emptiness" be a return value. We only get a hard-coded 0,0,0,0 rect because we use Skia for the intersections and they decided to return a false boolean with no changes to the rectangle for an empty intersection and so we have to manually force the answer to an empty answer (using MakeEmpty() for convenience).
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.
testing/dart/canvas_test.dart
Outdated
| canvas.clipRect(clipBounds1); | ||
| canvas.translate(0, 10.0); | ||
| canvas.clipRect(clipBounds1); | ||
| expect(canvas.getDestinationClipBounds(), Rect.fromLTRB(0.0, 0.0, 0.0, 0.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.
Same comment about measuring expectations against the "isEmpty" property rather than requiring a specific answer as I made above for the native tests.
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.
flar
left a comment
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.
Just a request to add a comment, but LGTM.
| break; | ||
| case SkClipOp::kDifference: | ||
| Push<ClipDifferencePathOp>(0, 1, path, is_aa); | ||
| if (path.isInverseFillType()) { |
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.
Add a reminder comment here about how this works. Nothing too detailed, just reminding the reader (i.e. me?) that inverted difference is like intersection...
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.
fix flutter/flutter#108154
cc @flar
Pre-launch Checklist
writing and running engine tests.
///).