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

Commit 8fe2eca

Browse files
committed
add test case and fix subpass coverage limits
1 parent 13b6e9e commit 8fe2eca

File tree

3 files changed

+61
-31
lines changed

3 files changed

+61
-31
lines changed

impeller/aiks/aiks_unittests.cc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2703,6 +2703,36 @@ TEST_P(AiksTest, TranslucentSaveLayerWithColorAndImageFilterDrawsCorrectly) {
27032703
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
27042704
}
27052705

2706+
TEST_P(AiksTest, ImageFilteredSaveLayerWithUnboundedContents) {
2707+
Canvas canvas;
2708+
2709+
auto texture = CreateTextureForFixture("airplane.jpg");
2710+
auto blur_filter = ImageFilter::MakeBlur(Sigma{5.0}, Sigma{5.0},
2711+
FilterContents::BlurStyle::kNormal,
2712+
Entity::TileMode::kClamp);
2713+
auto image_source = ColorSource::MakeImage(texture, Entity::TileMode::kRepeat,
2714+
Entity::TileMode::kRepeat, {}, {});
2715+
2716+
canvas.SaveLayer({.image_filter = blur_filter},
2717+
Rect::MakeLTRB(100, 100, 200, 200));
2718+
2719+
canvas.DrawPaint({.color_source = image_source});
2720+
2721+
Paint blue = {.color = Color::Blue()};
2722+
Paint green = {.color = Color::Green()};
2723+
2724+
canvas.DrawRect(Rect::MakeLTRB(125, 125, 175, 175), blue);
2725+
2726+
canvas.DrawRect(Rect::MakeLTRB(125, 50, 175, 98), green);
2727+
canvas.DrawRect(Rect::MakeLTRB(202, 125, 250, 175), green);
2728+
canvas.DrawRect(Rect::MakeLTRB(125, 202, 175, 250), green);
2729+
canvas.DrawRect(Rect::MakeLTRB(50, 125, 98, 175), green);
2730+
2731+
canvas.Restore();
2732+
2733+
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
2734+
}
2735+
27062736
TEST_P(AiksTest, TranslucentSaveLayerImageDrawsCorrectly) {
27072737
Canvas canvas;
27082738

impeller/entity/entity_pass.cc

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ 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+
201207
// If the subpass has an image filter, then its coverage space may deviate
202208
// from the parent pass and make intersecting with the pass coverage limit
203209
// unsafe.
@@ -207,17 +213,8 @@ std::optional<Rect> EntityPass::GetSubpassCoverage(
207213
}
208214

209215
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-
}
214216

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);
217+
return entities_coverage;
221218
}
222219

223220
EntityPass* EntityPass::GetSuperpass() const {

impeller/geometry/rect.h

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -315,31 +315,34 @@ struct TRect {
315315
using Rect = TRect<Scalar>;
316316
using IRect = TRect<int64_t>;
317317

318-
constexpr std::optional<Rect> Union(const Rect& a,
319-
const std::optional<Rect> b) {
320-
if (!b.has_value()) {
321-
return a;
322-
}
323-
return a.Union(b.value());
318+
constexpr inline std::optional<Rect> Union(const Rect& a,
319+
const std::optional<Rect> b) {
320+
return b.has_value() ? a.Union(b.value()) : a;
324321
}
325322

326-
constexpr std::optional<Rect> Union(const std::optional<Rect> a,
327-
const Rect& b) {
328-
if (!a.has_value()) {
329-
return b;
330-
}
331-
return a.value().Union(b);
323+
constexpr inline std::optional<Rect> Union(const std::optional<Rect> a,
324+
const Rect& b) {
325+
return Union(b, a);
332326
}
333327

334-
constexpr std::optional<Rect> Union(const std::optional<Rect> a,
335-
const std::optional<Rect> b) {
336-
if (!a.has_value()) {
337-
return b;
338-
}
339-
if (!b.has_value()) {
340-
return a;
341-
}
342-
return a.value().Union(b.value());
328+
constexpr inline std::optional<Rect> Union(const std::optional<Rect> a,
329+
const std::optional<Rect> b) {
330+
return a.has_value() ? Union(a.value(), b) : b;
331+
}
332+
333+
constexpr inline std::optional<Rect> Intersection(const Rect& a,
334+
const std::optional<Rect> b) {
335+
return b.has_value() ? a.Intersection(b.value()) : a;
336+
}
337+
338+
constexpr inline std::optional<Rect> Intersection(const std::optional<Rect> a,
339+
const Rect& b) {
340+
return Intersection(b, a);
341+
}
342+
343+
constexpr inline std::optional<Rect> Intersection(const std::optional<Rect> a,
344+
const std::optional<Rect> b) {
345+
return a.has_value() ? Intersection(a.value(), b) : b;
343346
}
344347

345348
} // namespace impeller

0 commit comments

Comments
 (0)