Skip to content

Commit 9dbb687

Browse files
tguerinb-luk
authored andcommitted
[Impeller] Sample the render target rect in offscreen advanced blends (flutter#192988)
## Problem In the offscreen advanced blend path, the subpass render target is allocated with an integral size — `ISize(subpass_coverage.GetSize())`, a truncating conversion — and the quad spans that render target. But the texture coordinates are derived from the full, fractional coverage. The quad therefore displays a slightly larger region than it covers, scaling the contents by `trunc(w)/w`. That factor changes whenever the coverage crosses a pixel boundary, so animated content is resampled differently every frame, which reads as shaking and crawling. The coverage does not need to be meaningfully fractional: in the per-draw path the blend runs over the whole pass (`FlipBackdrop`), and floating-point residue in the transform chain is enough — instrumenting master while running the Rive artboard below, the extent truncated on 29% of blend subpasses and the origin was fractional on 34%. Only configurations **without framebuffer fetch** take this path — the iOS simulator, PowerVR, and Adreno on GLES. Devices with framebuffer fetch blend in-pass via `ApplyFramebufferBlend`, which is exact. ## Fix Derive the texture coordinates from the rect the render target actually represents, so the quad and the sampled region agree exactly. The render target size, the composite origin and the composited rect are all unchanged from master; `PipelineBlend` draws each input at its own size and transform and never had this mismatch, so it is not touched. ## Verification Measured on an iPhone 17 Pro simulator against a Rive artboard exercising Multiply, Screen, Overlay, Soft Light and Color Dodge, loaded with `Factory.flutter` so drawing goes through Flutter's canvas and into Impeller's blend paths. The landmark is the left edge of static artboard content that never moves in the animation, so every pixel of movement is the bug. 40 consecutive frames: | landmark | master | this PR | |---|---|---| | row 1 — position range | 0.237 px | **0.000 px** | | row 3 — position range | 0.655 px | **0.000 px** | | row 3 — frames moving >0.25 px | 10 / 39 | **0 / 39** | <details> <summary>lib/main.dart</summary> ```dart import 'package:flutter/material.dart'; import 'package:rive/rive.dart'; Future<void> main() async { WidgetsFlutterBinding.ensureInitialized(); await RiveNative.init(); runApp(const MaterialApp(home: Scaffold(body: BlendModeTest()))); } class BlendModeTest extends StatefulWidget { const BlendModeTest({super.key}); @OverRide State<BlendModeTest> createState() => _BlendModeTestState(); } class _BlendModeTestState extends State<BlendModeTest> { File? _file; RiveWidgetController? _controller; @OverRide void initState() { super.initState(); _load(); } Future<void> _load() async { // Factory.flutter routes drawing through Flutter's Canvas, so the artboard // goes through Impeller's blend paths. Factory.rive would use Rive's own // renderer and would not exercise this code at all. final file = await File.asset( 'assets/blend_mode_test.riv', riveFactory: Factory.flutter, ); if (file == null) { return; } setState(() { _file = file; _controller = RiveWidgetController(file); }); } @OverRide void dispose() { _controller?.dispose(); _file?.dispose(); super.dispose(); } @OverRide Widget build(BuildContext context) { final controller = _controller; if (controller == null) { return const Center(child: CircularProgressIndicator()); } return Container( color: const Color(0xFF9E9E9E), child: RiveWidget(controller: controller, fit: Fit.contain), ); } } ``` </details> | before | after | |---|---| | https://github.com/user-attachments/assets/0dfa75f6-8b7f-4cb6-876d-3314baac2f44 | https://github.com/user-attachments/assets/87f59617-12b4-40cb-9da4-35990d5df1ee | *(The recordings were made with an earlier revision of this change; the measured result for the final revision is identical.)* ## Golden change This changes exactly one engine golden (of 466 Metal goldens compared locally): `ColorFilterAdvancedBlendNoFbFetch`. It is a correction, not a regression. That test stacks thirty full-frame blends, so the per-frame resampling error accumulates into a visible smear of every cell edge. Cell 2's image begins at x=400 (400 px pitch, 320 px images); row y=220: | x → | 396 | 398 | 400 | 402 | 404 | 406 | |---|---|---|---|---|---|---| | same test through framebuffer fetch (exact) | black | black | (230,128,0) | (230,128,0) | (230,128,0) | (230,128,0) | | current golden | (255,116,0) | (255,137,0) | (229,128,0) | (229,128,0) | (221,125,5) | (199,121,20) | | this PR | black | black | (229,128,0) | (229,128,0) | (229,128,0) | (229,128,0) | The current golden bleeds orange four pixels into the empty gap before the cell and blurs the edge over ~7 px; this PR matches the exact in-pass rendering to within 1/255. The golden will need triage. ## Tests `DlGoldenTest.StackedOffscreenAdvancedBlendsDoNotResample` renders a hard backdrop edge and blends over it thirty times with `kLighten` on a context without framebuffer fetch, then requires the result to match a single blend. Lighten is idempotent, so the only thing that can differ is resampling error accumulated across the stacked subpasses. A 0.4x canvas scale makes the full-pass coverage fractional the same way the golden does. **Fails on master (RMSE 5.75), passes with this change (RMSE 0).** `impeller_unittests` `*Blend*`/`*Filter*`: 791 passing, 0 failing. The `ColorFilterAdvancedBlendNoFbFetch` golden exercises the same path with thirty stacked blends and visibly captures the defect. Fixes flutter#192980 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant in-code documentation (doc comments with `///`). - [x] If this PR introduces a new feature or capability, I created and linked a website documentation issue or PR in [flutter/website] (or verified none is needed). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/AI-contributions.md [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [CLA]: https://cla.developers.google.com/ [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md --------- Co-authored-by: b-luk <[email protected]>
1 parent 1467f62 commit 9dbb687

3 files changed

Lines changed: 252 additions & 26 deletions

File tree

‎engine/src/flutter/impeller/display_list/dl_golden_unittests.cc‎

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@
44

55
#include "impeller/display_list/dl_golden_unittests.h"
66

7+
#include <memory>
78
#include <utility>
89

910
#include "display_list/dl_color.h"
1011
#include "display_list/dl_paint.h"
1112
#include "display_list/geometry/dl_geometry_types.h"
1213
#include "display_list/geometry/dl_path_builder.h"
1314
#include "flutter/display_list/dl_builder.h"
15+
#include "flutter/fml/closure.h"
1416
#include "flutter/impeller/display_list/testing/render_text_in_canvas.h"
1517
#include "flutter/impeller/display_list/testing/rmse.h"
1618
#include "flutter/testing/testing.h"
1719
#include "gtest/gtest.h"
20+
#include "impeller/renderer/testing/mocks.h"
1821

1922
namespace flutter {
2023
namespace testing {
@@ -650,5 +653,173 @@ TEST_P(DlGoldenTest, SubpixelScaledTranslated) {
650653
EXPECT_EQ(intensity[4].x - intensity[0].x, 1);
651654
}
652655

656+
namespace {
657+
// Returns capabilities that forward to |capabilities| but report no
658+
// framebuffer fetch, which forces advanced blends into an offscreen subpass.
659+
std::shared_ptr<impeller::testing::MockCapabilities>
660+
MakeCapabilitiesWithoutFramebufferFetch(
661+
const std::shared_ptr<const impeller::Capabilities>& capabilities) {
662+
auto mock_capabilities =
663+
std::make_shared<impeller::testing::MockCapabilities>();
664+
EXPECT_CALL(*mock_capabilities, SupportsFramebufferFetch())
665+
.Times(::testing::AnyNumber())
666+
.WillRepeatedly(::testing::Return(false));
667+
FLT_FORWARD(mock_capabilities, capabilities, GetDefaultColorFormat);
668+
FLT_FORWARD(mock_capabilities, capabilities, GetDefaultStencilFormat);
669+
FLT_FORWARD(mock_capabilities, capabilities, GetDefaultDepthStencilFormat);
670+
FLT_FORWARD(mock_capabilities, capabilities, SupportsOffscreenMSAA);
671+
FLT_FORWARD(mock_capabilities, capabilities, SupportsImplicitResolvingMSAA);
672+
FLT_FORWARD(mock_capabilities, capabilities, SupportsReadFromResolve);
673+
FLT_FORWARD(mock_capabilities, capabilities, SupportsSSBO);
674+
FLT_FORWARD(mock_capabilities, capabilities, SupportsCompute);
675+
FLT_FORWARD(mock_capabilities, capabilities, SupportsTextureToTextureBlits);
676+
FLT_FORWARD(mock_capabilities, capabilities, GetDefaultGlyphAtlasFormat);
677+
FLT_FORWARD(mock_capabilities, capabilities, SupportsTriangleFan);
678+
FLT_FORWARD(mock_capabilities, capabilities, SupportsDecalSamplerAddressMode);
679+
FLT_FORWARD(mock_capabilities, capabilities, SupportsPrimitiveRestart);
680+
FLT_FORWARD(mock_capabilities, capabilities, GetMinimumUniformAlignment);
681+
return mock_capabilities;
682+
}
683+
} // namespace
684+
685+
// Advanced blends on devices without framebuffer fetch are rendered in an
686+
// offscreen subpass whose render target has an integral size. The texture
687+
// coordinates used to sample the inputs must describe exactly the rect that
688+
// render target covers; if they describe the fractional coverage instead, the
689+
// contents are rescaled on every blend. Stacking blends makes that error
690+
// accumulate into a visible drift, which is what this test checks. Lighten is
691+
// idempotent, so any number of stacked blends must produce the same image as a
692+
// single one.
693+
//
694+
// Regression test for https://github.com/flutter/flutter/issues/192980.
695+
TEST_P(DlGoldenTest, StackedOffscreenAdvancedBlendsDoNotResample) {
696+
if (GetParam() != PlaygroundBackend::kMetal) {
697+
GTEST_SKIP()
698+
<< "This backend doesn't yet support setting device capabilities.";
699+
}
700+
701+
std::shared_ptr<const impeller::Capabilities> old_capabilities =
702+
GetContext()->GetCapabilities();
703+
ASSERT_TRUE(
704+
SetCapabilities(MakeCapabilitiesWithoutFramebufferFetch(old_capabilities))
705+
.ok());
706+
// The playground context is shared across tests, so the mocked capabilities
707+
// have to be undone however this test exits.
708+
fml::ScopedCleanupClosure restore_capabilities([&]() {
709+
EXPECT_TRUE(SetCapabilities(std::const_pointer_cast<impeller::Capabilities>(
710+
old_capabilities))
711+
.ok());
712+
});
713+
714+
auto draw = [](DlCanvas* canvas, int blend_count) {
715+
canvas->DrawColor(DlColor(0xFF404040));
716+
// The per-draw blend path computes its coverage from the whole pass, so
717+
// the coverage is only fractional through floating point error in the
718+
// transform. A 0.4x scale (which the ColorFilterAdvancedBlendNoFbFetch
719+
// golden also uses) does not round trip exactly through its inverse and
720+
// leaves a 2048 pixel pass at 2047.99988. A pure scale keeps the origin at
721+
// exactly zero, isolating the size mismatch from compositing at a
722+
// fractional origin.
723+
canvas->Scale(0.4f, 0.4f);
724+
725+
// A backdrop with a hard vertical edge for the blends to resample.
726+
DlPaint backdrop;
727+
backdrop.setColor(DlColor(0xFFA0A0A0));
728+
canvas->DrawRect(DlRect::MakeLTRB(750, 0, 5120, 3840), backdrop);
729+
730+
DlPaint blend;
731+
blend.setColor(DlColor(0xFF808080));
732+
blend.setBlendMode(DlBlendMode::kLighten);
733+
for (int i = 0; i < blend_count; ++i) {
734+
canvas->DrawRect(DlRect::MakeLTRB(250, 250, 1750, 1250), blend);
735+
}
736+
};
737+
738+
auto make_screenshot = [&](int blend_count) {
739+
DisplayListBuilder builder;
740+
draw(&builder, blend_count);
741+
return MakeScreenshot(builder.Build());
742+
};
743+
744+
std::unique_ptr<impeller::testing::Screenshot> once = make_screenshot(1);
745+
if (!once) {
746+
GTEST_SKIP() << "making screenshots not supported.";
747+
}
748+
std::unique_ptr<impeller::testing::Screenshot> stacked = make_screenshot(30);
749+
ASSERT_TRUE(stacked);
750+
751+
double rmse = RMSE(once.get(), stacked.get());
752+
// Without the fix the thirty stacked blends drift the backdrop edge by
753+
// several pixels and the RMSE is about 5.75; with it the images are equal.
754+
EXPECT_LT(rmse, 1.0) << "rmse: " << rmse;
755+
}
756+
757+
// The offscreen subpass of an advanced blend must cover exactly the pixels its
758+
// coverage touches. The backdrop's coverage goes through the transform and its
759+
// inverse, so for a 2048x1536 pass it lands slightly below or slightly above
760+
// the integral size depending on the scale. Rounding the render target down
761+
// drops the last column and row when it lands below, and rounding it up adds
762+
// one when it lands above. Framebuffer fetch blends in place without a
763+
// subpass, so its output is the reference the offscreen path has to match.
764+
TEST_P(DlGoldenTest, OffscreenAdvancedBlendMatchesFramebufferFetch) {
765+
if (GetParam() != PlaygroundBackend::kMetal) {
766+
GTEST_SKIP()
767+
<< "This backend doesn't yet support setting device capabilities.";
768+
}
769+
770+
std::shared_ptr<const impeller::Capabilities> old_capabilities =
771+
GetContext()->GetCapabilities();
772+
if (!old_capabilities->SupportsFramebufferFetch()) {
773+
GTEST_SKIP() << "The reference image needs framebuffer fetch.";
774+
}
775+
std::shared_ptr<impeller::Capabilities> no_fb_fetch_capabilities =
776+
MakeCapabilitiesWithoutFramebufferFetch(old_capabilities);
777+
// The playground context is shared across tests, so the mocked capabilities
778+
// have to be undone however this test exits.
779+
fml::ScopedCleanupClosure restore_capabilities([&]() {
780+
EXPECT_TRUE(SetCapabilities(std::const_pointer_cast<impeller::Capabilities>(
781+
old_capabilities))
782+
.ok());
783+
});
784+
785+
// A 0.4x scale leaves the pass coverage at 2047.99988x1535.99988 and a 0.43x
786+
// scale at 2048.00024x1536.00024.
787+
for (Scalar scale : {0.4f, 0.43f}) {
788+
SCOPED_TRACE(scale);
789+
DisplayListBuilder builder;
790+
builder.DrawColor(DlColor(0xFF404040), DlBlendMode::kSrcOver);
791+
builder.Scale(scale, scale);
792+
DlPaint backdrop;
793+
backdrop.setColor(DlColor(0xFFA0A0A0));
794+
builder.DrawRect(
795+
DlRect::MakeLTRB(300 / scale, 0, 2048 / scale, 1536 / scale), backdrop);
796+
// A blend that reaches into the last column and row of the pass.
797+
DlPaint blend;
798+
blend.setColor(DlColor(0xFF20C020));
799+
blend.setBlendMode(DlBlendMode::kLighten);
800+
builder.DrawRect(DlRect::MakeLTRB(100 / scale, 100 / scale, 2047.5f / scale,
801+
1535.5f / scale),
802+
blend);
803+
sk_sp<DisplayList> display_list = builder.Build();
804+
805+
ASSERT_TRUE(SetCapabilities(std::const_pointer_cast<impeller::Capabilities>(
806+
old_capabilities))
807+
.ok());
808+
std::unique_ptr<impeller::testing::Screenshot> reference =
809+
MakeScreenshot(display_list);
810+
if (!reference) {
811+
GTEST_SKIP() << "making screenshots not supported.";
812+
}
813+
814+
ASSERT_TRUE(SetCapabilities(no_fb_fetch_capabilities).ok());
815+
std::unique_ptr<impeller::testing::Screenshot> offscreen =
816+
MakeScreenshot(display_list);
817+
ASSERT_TRUE(offscreen);
818+
819+
double rmse = RMSE(reference.get(), offscreen.get());
820+
EXPECT_LT(rmse, 0.1) << "rmse: " << rmse;
821+
}
822+
}
823+
653824
} // namespace testing
654825
} // namespace flutter

‎engine/src/flutter/impeller/entity/contents/filters/blend_filter_contents.cc‎

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "impeller/entity/contents/filters/blend_filter_contents.h"
66

77
#include <array>
8+
#include <cmath>
89
#include <memory>
910
#include <optional>
1011

@@ -25,6 +26,7 @@
2526
#include "impeller/entity/texture_fill.frag.h"
2627
#include "impeller/entity/texture_fill.vert.h"
2728
#include "impeller/geometry/color.h"
29+
#include "impeller/geometry/constants.h"
2830
#include "impeller/renderer/render_pass.h"
2931
#include "impeller/renderer/snapshot.h"
3032

@@ -116,12 +118,47 @@ static std::optional<Entity> AdvancedBlend(
116118
return std::nullopt;
117119
}
118120

121+
Rect subpass_coverage = coverage;
122+
if (entity.GetContents()) {
123+
auto coverage_hint = entity.GetContents()->GetCoverageHint();
124+
125+
if (coverage_hint.has_value()) {
126+
auto maybe_subpass_coverage =
127+
subpass_coverage.Intersection(*coverage_hint);
128+
if (!maybe_subpass_coverage.has_value()) {
129+
return std::nullopt; // Nothing to render.
130+
}
131+
132+
subpass_coverage = *maybe_subpass_coverage;
133+
}
134+
}
135+
136+
// The subpass render target has an integral size, rounded up so that it keeps
137+
// any partially covered edge pixels of |subpass_coverage|. A size that is
138+
// meant to be integral can land slightly above or below it after floating
139+
// point math (the backdrop's coverage goes through the transform and its
140+
// inverse), so values within kEhCloseEnough of an integer snap to it instead
141+
// of gaining a pixel. The texture coordinates must describe the same rect as
142+
// the quad, which spans the render target: if they describe the fractional
143+
// coverage instead, the contents are scaled by the ratio between the two,
144+
// and that ratio changes from frame to frame for animated content. Both the
145+
// allocation and the sampled rect use this one size.
146+
const Size coverage_size = subpass_coverage.GetSize();
147+
const Size render_target_size(
148+
std::ceil(coverage_size.width - kEhCloseEnough),
149+
std::ceil(coverage_size.height - kEhCloseEnough));
150+
const Rect render_target_coverage =
151+
Rect::MakeOriginSize(subpass_coverage.GetOrigin(), render_target_size);
152+
if (render_target_coverage.IsEmpty()) {
153+
return std::nullopt; // Nothing to render.
154+
}
155+
119156
auto dst_snapshot =
120157
inputs[0]->GetSnapshot("AdvancedBlend(Dst)", renderer, entity);
121158
if (!dst_snapshot.has_value()) {
122159
return std::nullopt;
123160
}
124-
auto maybe_dst_uvs = dst_snapshot->GetCoverageUVs(coverage);
161+
auto maybe_dst_uvs = dst_snapshot->GetCoverageUVs(render_target_coverage);
125162
if (!maybe_dst_uvs.has_value()) {
126163
return std::nullopt;
127164
}
@@ -138,7 +175,7 @@ static std::optional<Entity> AdvancedBlend(
138175
}
139176
return Entity::FromSnapshot(dst_snapshot.value(), entity.GetBlendMode());
140177
}
141-
auto maybe_src_uvs = src_snapshot->GetCoverageUVs(coverage);
178+
auto maybe_src_uvs = src_snapshot->GetCoverageUVs(render_target_coverage);
142179
if (!maybe_src_uvs.has_value()) {
143180
if (!dst_snapshot.has_value()) {
144181
return std::nullopt;
@@ -148,21 +185,6 @@ static std::optional<Entity> AdvancedBlend(
148185
src_uvs = maybe_src_uvs.value();
149186
}
150187

151-
Rect subpass_coverage = coverage;
152-
if (entity.GetContents()) {
153-
auto coverage_hint = entity.GetContents()->GetCoverageHint();
154-
155-
if (coverage_hint.has_value()) {
156-
auto maybe_subpass_coverage =
157-
subpass_coverage.Intersection(*coverage_hint);
158-
if (!maybe_subpass_coverage.has_value()) {
159-
return std::nullopt; // Nothing to render.
160-
}
161-
162-
subpass_coverage = *maybe_subpass_coverage;
163-
}
164-
}
165-
166188
//----------------------------------------------------------------------------
167189
/// Render to texture.
168190
///
@@ -226,9 +248,7 @@ static std::optional<Entity> AdvancedBlend(
226248
auto blend_uniform = data_host_buffer.EmplaceUniform(blend_info);
227249
FS::BindBlendInfo(pass, blend_uniform);
228250

229-
frame_info.mvp = pass.GetOrthographicTransform() *
230-
Matrix::MakeTranslation(coverage.GetOrigin() -
231-
subpass_coverage.GetOrigin());
251+
frame_info.mvp = pass.GetOrthographicTransform();
232252

233253
auto uniform_view = data_host_buffer.EmplaceUniform(frame_info);
234254
VS::BindFrameInfo(pass, uniform_view);
@@ -242,12 +262,12 @@ static std::optional<Entity> AdvancedBlend(
242262
return std::nullopt;
243263
}
244264
fml::StatusOr<RenderTarget> render_target =
245-
renderer.MakeSubpass("Advanced Blend Filter", //
246-
ISize(subpass_coverage.GetSize()), //
247-
command_buffer, //
248-
callback, //
249-
/*msaa_enabled=*/false, //
250-
/*depth_stencil_enabled=*/false //
265+
renderer.MakeSubpass("Advanced Blend Filter", //
266+
ISize(render_target_size), //
267+
command_buffer, //
268+
callback, //
269+
/*msaa_enabled=*/false, //
270+
/*depth_stencil_enabled=*/false //
251271
);
252272
if (!render_target.ok()) {
253273
return std::nullopt;

‎engine/src/flutter/impeller/entity/contents/filters/blend_filter_contents_unittests.cc‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,40 @@ TEST_P(BlendFilterContentsTest, AdvancedBlendColorAlignsColorTo4) {
6464
EXPECT_TRUE(result.has_value());
6565
}
6666

67+
// Without framebuffer fetch, the canvas blends against the backdrop by giving
68+
// it the inverse of the entity transform, so its coverage goes through the
69+
// transform and back and lands slightly off the texture size: a 0.4x scale
70+
// leaves a 2048x1536 backdrop at 2047.99988x1535.99988 and a 0.43x scale at
71+
// 2048.00024x1536.00024. The subpass must still match the backdrop exactly,
72+
// neither dropping its last column and row nor allocating an extra one.
73+
TEST_P(BlendFilterContentsTest, AdvancedBlendSubpassSnapsNearlyIntegralSize) {
74+
if (GetContentContext().GetDeviceCapabilities().SupportsFramebufferFetch()) {
75+
GTEST_SKIP() << "Advanced blends use framebuffer fetch on this backend.";
76+
}
77+
std::shared_ptr<Texture> backdrop = MakeTexture(ISize(2048, 1536));
78+
std::shared_ptr<Texture> source = MakeTexture(ISize(100, 100));
79+
ASSERT_TRUE(backdrop);
80+
ASSERT_TRUE(source);
81+
82+
for (Scalar scale : {0.4f, 0.43f}) {
83+
SCOPED_TRACE(scale);
84+
Matrix transform = Matrix::MakeScale({scale, scale, 1});
85+
BlendFilterContents filter_contents;
86+
filter_contents.SetInputs({FilterInput::Make(backdrop, transform.Invert()),
87+
FilterInput::Make(source)});
88+
filter_contents.SetBlendMode(BlendMode::kScreen);
89+
Entity entity;
90+
entity.SetTransform(transform);
91+
92+
std::optional<Entity> result = filter_contents.GetEntity(
93+
GetContentContext(), entity, /*coverage_hint=*/std::nullopt);
94+
95+
ASSERT_TRUE(result.has_value());
96+
std::optional<Rect> coverage = result->GetCoverage();
97+
ASSERT_TRUE(coverage.has_value());
98+
EXPECT_EQ(coverage->GetSize(), Size(2048, 1536));
99+
}
100+
}
101+
67102
} // namespace testing
68103
} // namespace impeller

0 commit comments

Comments
 (0)