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

Commit 83a72a6

Browse files
committed
adjust clipping of savelayer content and improve unit tests
1 parent ae669cd commit 83a72a6

File tree

2 files changed

+51
-20
lines changed

2 files changed

+51
-20
lines changed

impeller/aiks/aiks_unittests.cc

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,28 +2763,56 @@ TEST_P(AiksTest, TranslucentSaveLayerWithColorAndImageFilterDrawsCorrectly) {
27632763
TEST_P(AiksTest, ImageFilteredSaveLayerWithUnboundedContents) {
27642764
Canvas canvas;
27652765

2766-
auto texture = CreateTextureForFixture("airplane.jpg");
2767-
auto blur_filter = ImageFilter::MakeBlur(Sigma{5.0}, Sigma{5.0},
2766+
auto blur_filter = ImageFilter::MakeBlur(Sigma{10.0}, Sigma{10.0},
27682767
FilterContents::BlurStyle::kNormal,
2769-
Entity::TileMode::kClamp);
2770-
auto image_source = ColorSource::MakeImage(texture, Entity::TileMode::kRepeat,
2771-
Entity::TileMode::kRepeat, {}, {});
2768+
Entity::TileMode::kDecal);
2769+
2770+
auto DrawLine = [&canvas](const Point& p0, const Point& p1, const Paint& p) {
2771+
auto path = PathBuilder{}
2772+
.AddLine(p0, p1)
2773+
.SetConvexity(Convexity::kConvex)
2774+
.TakePath();
2775+
Paint paint = p;
2776+
paint.style = Paint::Style::kStroke;
2777+
canvas.DrawPath(path, paint);
2778+
};
2779+
// Registration marks for the edge of the SaveLayer
2780+
DrawLine(Point(75, 100), Point(225, 100), {.color = Color::White()});
2781+
DrawLine(Point(75, 200), Point(225, 200), {.color = Color::White()});
2782+
DrawLine(Point(100, 75), Point(100, 225), {.color = Color::White()});
2783+
DrawLine(Point(200, 75), Point(200, 225), {.color = Color::White()});
27722784

27732785
canvas.SaveLayer({.image_filter = blur_filter},
27742786
Rect::MakeLTRB(100, 100, 200, 200));
2787+
{
2788+
// DrawPaint to verify correct behavior when the contents are unbounded.
2789+
canvas.DrawPaint({.color = Color::Yellow()});
2790+
2791+
// Contrasting rectangle to see interior blurring
2792+
canvas.DrawRect(Rect::MakeLTRB(125, 125, 175, 175),
2793+
{.color = Color::Blue()});
2794+
}
2795+
canvas.Restore();
27752796

2776-
canvas.DrawPaint({.color_source = image_source});
2797+
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
2798+
}
27772799

2778-
Paint blue = {.color = Color::Blue()};
2779-
Paint green = {.color = Color::Green()};
2800+
TEST_P(AiksTest, ImageFilteredUnboundedSaveLayerWithUnboundedContents) {
2801+
Canvas canvas;
27802802

2781-
canvas.DrawRect(Rect::MakeLTRB(125, 125, 175, 175), blue);
2803+
auto blur_filter = ImageFilter::MakeBlur(Sigma{10.0}, Sigma{10.0},
2804+
FilterContents::BlurStyle::kNormal,
2805+
Entity::TileMode::kDecal);
27822806

2783-
canvas.DrawRect(Rect::MakeLTRB(125, 50, 175, 98), green);
2784-
canvas.DrawRect(Rect::MakeLTRB(202, 125, 250, 175), green);
2785-
canvas.DrawRect(Rect::MakeLTRB(125, 202, 175, 250), green);
2786-
canvas.DrawRect(Rect::MakeLTRB(50, 125, 98, 175), green);
2807+
canvas.SaveLayer({.image_filter = blur_filter}, std::nullopt);
2808+
{
2809+
// DrawPaint to verify correct behavior when the contents are unbounded.
2810+
canvas.DrawPaint({.color = Color::Yellow()});
27872811

2812+
// Contrasting rectangle to see interior blurring
2813+
canvas.DrawRect(Rect::MakeLTRB(125, 125, 175, 175),
2814+
{.color = Color::Blue()});
2815+
}
27882816
canvas.Restore();
27892817

27902818
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));

impeller/entity/entity_pass.cc

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,6 @@ std::optional<Rect> EntityPass::GetSubpassCoverage(
198198
std::shared_ptr<FilterContents> image_filter =
199199
subpass.delegate_->WithImageFilter(Rect(), subpass.xformation_);
200200

201-
if (subpass.bounds_limit_.has_value()) {
202-
auto user_bounds_coverage =
203-
subpass.bounds_limit_->TransformBounds(subpass.xformation_);
204-
coverage_limit = Intersection(user_bounds_coverage, coverage_limit);
205-
}
206-
207201
// If the subpass has an image filter, then its coverage space may deviate
208202
// from the parent pass and make intersecting with the pass coverage limit
209203
// unsafe.
@@ -213,8 +207,17 @@ std::optional<Rect> EntityPass::GetSubpassCoverage(
213207
}
214208

215209
auto entities_coverage = subpass.GetElementsCoverage(coverage_limit);
210+
// The entities don't cover anything. There is nothing to do.
211+
if (!entities_coverage.has_value()) {
212+
return std::nullopt;
213+
}
216214

217-
return entities_coverage;
215+
if (!subpass.bounds_limit_.has_value()) {
216+
return entities_coverage;
217+
}
218+
auto user_bounds_coverage =
219+
subpass.bounds_limit_->TransformBounds(subpass.xformation_);
220+
return entities_coverage->Intersection(user_bounds_coverage);
218221
}
219222

220223
EntityPass* EntityPass::GetSuperpass() const {

0 commit comments

Comments
 (0)