-
Notifications
You must be signed in to change notification settings - Fork 6k
Make ui.Canvas.getDestinationClipBounds works with matrix #34835
Changes from 2 commits
31d44f5
739bdfb
56f9eb1
230f9d6
fb1a872
e0b1a0a
1869882
cab83b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2116,6 +2116,25 @@ TEST(DisplayList, ClipRectAffectsClipBounds) { | |
| ASSERT_EQ(builder.getDestinationClipBounds(), initialDestinationBounds); | ||
| } | ||
|
|
||
| TEST(DisplayList, ClipRectAffectsClipBoundsWithMatrix) { | ||
| DisplayListBuilder builder; | ||
| SkRect clipBounds1 = SkRect::MakeLTRB(0, 0, 10, 10); | ||
| SkRect clipBounds2 = SkRect::MakeLTRB(10, 10, 20, 20); | ||
| builder.save(); | ||
| builder.clipRect(clipBounds1, SkClipOp::kIntersect, false); | ||
| builder.translate(10, 0); | ||
| builder.clipRect(clipBounds1, SkClipOp::kIntersect, false); | ||
| ASSERT_EQ(builder.getDestinationClipBounds(), SkRect::MakeEmpty()); | ||
|
||
| builder.restore(); | ||
|
|
||
| builder.save(); | ||
| builder.clipRect(clipBounds1, SkClipOp::kIntersect, false); | ||
| builder.translate(-10, -10); | ||
| builder.clipRect(clipBounds2, SkClipOp::kIntersect, false); | ||
| ASSERT_EQ(builder.getDestinationClipBounds(), clipBounds1); | ||
| builder.restore(); | ||
| } | ||
|
|
||
| TEST(DisplayList, ClipRRectAffectsClipBounds) { | ||
| DisplayListBuilder builder; | ||
| SkRect clipBounds = SkRect::MakeLTRB(10.2, 11.3, 20.4, 25.7); | ||
|
|
@@ -2156,6 +2175,28 @@ TEST(DisplayList, ClipRRectAffectsClipBounds) { | |
| ASSERT_EQ(builder.getDestinationClipBounds(), initialDestinationBounds); | ||
| } | ||
|
|
||
| TEST(DisplayList, ClipRRectAffectsClipBoundsWithMatrix) { | ||
| DisplayListBuilder builder; | ||
| SkRect clipBounds1 = SkRect::MakeLTRB(0, 0, 10, 10); | ||
| SkRect clipBounds2 = SkRect::MakeLTRB(10, 10, 20, 20); | ||
| SkRRect clip1 = SkRRect::MakeRectXY(clipBounds1, 3, 2); | ||
| SkRRect clip2 = SkRRect::MakeRectXY(clipBounds2, 3, 2); | ||
|
|
||
| builder.save(); | ||
| builder.clipRRect(clip1, SkClipOp::kIntersect, false); | ||
| builder.translate(10, 0); | ||
| builder.clipRRect(clip1, SkClipOp::kIntersect, false); | ||
| ASSERT_EQ(builder.getDestinationClipBounds(), SkRect::MakeEmpty()); | ||
| builder.restore(); | ||
|
|
||
| builder.save(); | ||
| builder.clipRRect(clip1, SkClipOp::kIntersect, false); | ||
| builder.translate(-10, -10); | ||
| builder.clipRRect(clip2, SkClipOp::kIntersect, false); | ||
| ASSERT_EQ(builder.getDestinationClipBounds(), clipBounds1); | ||
| builder.restore(); | ||
| } | ||
|
|
||
| TEST(DisplayList, ClipPathAffectsClipBounds) { | ||
| DisplayListBuilder builder; | ||
| SkPath clip = SkPath().addCircle(10.2, 11.3, 2).addCircle(20.4, 25.7, 2); | ||
|
|
@@ -2196,6 +2237,27 @@ TEST(DisplayList, ClipPathAffectsClipBounds) { | |
| ASSERT_EQ(builder.getDestinationClipBounds(), initialDestinationBounds); | ||
| } | ||
|
|
||
| TEST(DisplayList, ClipPathAffectsClipBoundsWithMatrix) { | ||
| DisplayListBuilder builder; | ||
| SkRect clipBounds = SkRect::MakeLTRB(0, 0, 10, 10); | ||
| SkPath clip1 = SkPath().addCircle(2.5, 2.5, 2.5).addCircle(7.5, 7.5, 2.5); | ||
| SkPath clip2 = SkPath().addCircle(12.5, 12.5, 2.5).addCircle(17.5, 17.5, 2.5); | ||
|
|
||
| builder.save(); | ||
| builder.clipPath(clip1, SkClipOp::kIntersect, false); | ||
| builder.translate(10, 0); | ||
| builder.clipPath(clip1, SkClipOp::kIntersect, false); | ||
| ASSERT_EQ(builder.getDestinationClipBounds(), SkRect::MakeEmpty()); | ||
| builder.restore(); | ||
|
|
||
| builder.save(); | ||
| builder.clipPath(clip1, SkClipOp::kIntersect, false); | ||
| builder.translate(-10, -10); | ||
| builder.clipPath(clip2, SkClipOp::kIntersect, false); | ||
| ASSERT_EQ(builder.getDestinationClipBounds(), clipBounds); | ||
| builder.restore(); | ||
| } | ||
|
|
||
| TEST(DisplayList, DiffClipRectDoesNotAffectClipBounds) { | ||
| DisplayListBuilder builder; | ||
| SkRect diff_clip = SkRect::MakeLTRB(0, 0, 15, 15); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -731,6 +731,27 @@ void main() { | |
| expect(canvas.getDestinationClipBounds(), initialDestinationBounds); | ||
| }); | ||
|
|
||
| test('Canvas.clipRect with matrix affects canvas.getClipBounds', () async { | ||
| final PictureRecorder recorder = PictureRecorder(); | ||
| final Canvas canvas = Canvas(recorder); | ||
| const Rect clipBounds1 = Rect.fromLTRB(0.0, 0.0, 10.0, 10.0); | ||
| const Rect clipBounds2 = Rect.fromLTRB(10.0, 10.0, 20.0, 20.0); | ||
|
|
||
| canvas.save(); | ||
| canvas.clipRect(clipBounds1); | ||
| canvas.translate(0, 10.0); | ||
| canvas.clipRect(clipBounds1); | ||
| expect(canvas.getDestinationClipBounds(), Rect.fromLTRB(0.0, 0.0, 0.0, 0.0)); | ||
|
||
| canvas.restore(); | ||
|
|
||
| canvas.save(); | ||
| canvas.clipRect(clipBounds1); | ||
| canvas.translate(-10.0, -10.0); | ||
| canvas.clipRect(clipBounds2); | ||
| expect(canvas.getDestinationClipBounds(), clipBounds1); | ||
| canvas.restore(); | ||
| }); | ||
|
|
||
| test('Canvas.clipRRect affects canvas.getClipBounds', () async { | ||
| final PictureRecorder recorder = PictureRecorder(); | ||
| final Canvas canvas = Canvas(recorder); | ||
|
|
@@ -772,6 +793,29 @@ void main() { | |
| expect(canvas.getDestinationClipBounds(), initialDestinationBounds); | ||
| }); | ||
|
|
||
| test('Canvas.clipRRect with matrix affects canvas.getClipBounds', () async { | ||
| final PictureRecorder recorder = PictureRecorder(); | ||
| final Canvas canvas = Canvas(recorder); | ||
| const Rect clipBounds1 = Rect.fromLTRB(0.0, 0.0, 10.0, 10.0); | ||
| const Rect clipBounds2 = Rect.fromLTRB(10.0, 10.0, 20.0, 20.0); | ||
| final RRect clip1 = RRect.fromRectAndRadius(clipBounds1, const Radius.circular(3)); | ||
| final RRect clip2 = RRect.fromRectAndRadius(clipBounds2, const Radius.circular(3)); | ||
|
|
||
| canvas.save(); | ||
| canvas.clipRRect(clip1); | ||
| canvas.translate(0, 10.0); | ||
| canvas.clipRRect(clip1); | ||
| expect(canvas.getDestinationClipBounds(), Rect.fromLTRB(0.0, 0.0, 0.0, 0.0)); | ||
| canvas.restore(); | ||
|
|
||
| canvas.save(); | ||
| canvas.clipRRect(clip1); | ||
| canvas.translate(-10.0, -10.0); | ||
| canvas.clipRRect(clip2); | ||
| expect(canvas.getDestinationClipBounds(), clipBounds1); | ||
| canvas.restore(); | ||
| }); | ||
|
|
||
| test('Canvas.clipPath affects canvas.getClipBounds', () async { | ||
| final PictureRecorder recorder = PictureRecorder(); | ||
| final Canvas canvas = Canvas(recorder); | ||
|
|
@@ -813,6 +857,29 @@ void main() { | |
| expect(canvas.getDestinationClipBounds(), initialDestinationBounds); | ||
| }); | ||
|
|
||
| test('Canvas.clipPath with matrix affects canvas.getClipBounds', () async { | ||
| final PictureRecorder recorder = PictureRecorder(); | ||
| final Canvas canvas = Canvas(recorder); | ||
| const Rect clipBounds1 = Rect.fromLTRB(0.0, 0.0, 10.0, 10.0); | ||
| const Rect clipBounds2 = Rect.fromLTRB(10.0, 10.0, 20.0, 20.0); | ||
| final Path clip1 = Path()..addRect(clipBounds1)..addOval(clipBounds1); | ||
| final Path clip2 = Path()..addRect(clipBounds2)..addOval(clipBounds2); | ||
|
|
||
| canvas.save(); | ||
| canvas.clipPath(clip1); | ||
| canvas.translate(0, 10.0); | ||
| canvas.clipPath(clip1); | ||
| expect(canvas.getDestinationClipBounds(), Rect.fromLTRB(0.0, 0.0, 0.0, 0.0)); | ||
| canvas.restore(); | ||
|
|
||
| canvas.save(); | ||
| canvas.clipPath(clip1); | ||
| canvas.translate(-10.0, -10.0); | ||
| canvas.clipPath(clip2); | ||
| expect(canvas.getDestinationClipBounds(), clipBounds1); | ||
| canvas.restore(); | ||
| }); | ||
|
|
||
| test('Canvas.clipRect(diff) does not affect canvas.getClipBounds', () async { | ||
| final PictureRecorder recorder = PictureRecorder(); | ||
| final Canvas canvas = Canvas(recorder); | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.
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 typewithSkClipOp::kDifference. (Although Flutter can't access it yet)