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

Commit 6ac6e37

Browse files
committed
[Impeller] Fix advanced blends for DrawPaint
1 parent 326de1d commit 6ac6e37

14 files changed

+75
-17
lines changed

impeller/aiks/aiks_unittests.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,15 @@ TEST_P(AiksTest, CanDrawPaintMultipleTimes) {
12031203
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
12041204
}
12051205

1206+
TEST_P(AiksTest, CanDrawPaintWithAdvancedBlend) {
1207+
Canvas canvas;
1208+
canvas.Scale(Vector2(0.2, 0.2));
1209+
canvas.DrawPaint({.color = Color::MediumTurquoise()});
1210+
canvas.DrawPaint({.color = Color::Color::OrangeRed().WithAlpha(0.5),
1211+
.blend_mode = BlendMode::kHue});
1212+
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
1213+
}
1214+
12061215
TEST_P(AiksTest, PaintBlendModeIsRespected) {
12071216
Paint paint;
12081217
Canvas canvas;

impeller/display_list/dl_image_impeller.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ sk_sp<DlImageImpeller> DlImageImpeller::MakeFromYUVTextures(
3131
impeller::Entity entity;
3232
entity.SetBlendMode(impeller::BlendMode::kSource);
3333
auto snapshot = yuv_to_rgb_filter_contents->RenderToSnapshot(
34-
aiks_context->GetContentContext(), entity, std::nullopt, true,
35-
"MakeYUVToRGBFilter Snapshot");
34+
aiks_context->GetContentContext(), // renderer
35+
entity, // entity
36+
std::nullopt, // coverage_limit
37+
std::nullopt, // sampler_descriptor
38+
true, // msaa_enabled
39+
"MakeYUVToRGBFilter Snapshot"); // label
3640
return impeller::DlImageImpeller::Make(snapshot->texture);
3741
}
3842

impeller/entity/contents/atlas_contents.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,13 @@ bool AtlasContents::Render(const ContentContext& renderer,
248248
auto contents = ColorFilterContents::MakeBlend(
249249
blend_mode_,
250250
{FilterInput::Make(dst_contents), FilterInput::Make(src_contents)});
251-
auto snapshot = contents->RenderToSnapshot(renderer, entity, std::nullopt,
252-
true, "AtlasContents Snapshot");
251+
auto snapshot =
252+
contents->RenderToSnapshot(renderer, // renderer
253+
entity, // entity
254+
std::nullopt, // coverage_limit
255+
std::nullopt, // sampler_descriptor
256+
true, // msaa_enabled
257+
"AtlasContents Snapshot"); // label
253258
if (!snapshot.has_value()) {
254259
return false;
255260
}

impeller/entity/contents/contents.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,14 @@ Contents::StencilCoverage Contents::GetStencilCoverage(
5959
std::optional<Snapshot> Contents::RenderToSnapshot(
6060
const ContentContext& renderer,
6161
const Entity& entity,
62+
std::optional<Rect> coverage_limit,
6263
const std::optional<SamplerDescriptor>& sampler_descriptor,
6364
bool msaa_enabled,
6465
const std::string& label) const {
6566
auto coverage = GetCoverage(entity);
67+
if (coverage_limit.has_value()) {
68+
coverage = coverage->Intersection(*coverage_limit);
69+
}
6670
if (!coverage.has_value()) {
6771
return std::nullopt;
6872
}

impeller/entity/contents/contents.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class Contents {
7777
virtual std::optional<Snapshot> RenderToSnapshot(
7878
const ContentContext& renderer,
7979
const Entity& entity,
80+
std::optional<Rect> coverage_limit = std::nullopt,
8081
const std::optional<SamplerDescriptor>& sampler_descriptor = std::nullopt,
8182
bool msaa_enabled = true,
8283
const std::string& label = "Snapshot") const;

impeller/entity/contents/filters/filter_contents.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,21 @@ std::optional<Entity> FilterContents::GetEntity(const ContentContext& renderer,
241241
std::optional<Snapshot> FilterContents::RenderToSnapshot(
242242
const ContentContext& renderer,
243243
const Entity& entity,
244+
std::optional<Rect> coverage_limit,
244245
const std::optional<SamplerDescriptor>& sampler_descriptor,
245246
bool msaa_enabled,
246247
const std::string& label) const {
247248
// Resolve the render instruction (entity) from the filter and render it to a
248249
// snapshot.
249250
if (std::optional<Entity> result = GetEntity(renderer, entity);
250251
result.has_value()) {
251-
return result->GetContents()->RenderToSnapshot(renderer, result.value(),
252-
std::nullopt, true, label);
252+
return result->GetContents()->RenderToSnapshot(
253+
renderer, // renderer
254+
result.value(), // entity
255+
std::nullopt, // coverage_limit
256+
std::nullopt, // sampler_descriptor
257+
true, // msaa_enabled
258+
label); // label
253259
}
254260

255261
return std::nullopt;

impeller/entity/contents/filters/filter_contents.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class FilterContents : public Contents {
125125
std::optional<Snapshot> RenderToSnapshot(
126126
const ContentContext& renderer,
127127
const Entity& entity,
128+
std::optional<Rect> coverage_limit = std::nullopt,
128129
const std::optional<SamplerDescriptor>& sampler_descriptor = std::nullopt,
129130
bool msaa_enabled = true,
130131
const std::string& label = "Filter Snapshot") const override;

impeller/entity/contents/filters/inputs/contents_filter_input.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ std::optional<Snapshot> ContentsFilterInput::GetSnapshot(
2727
const Entity& entity) const {
2828
if (!snapshot_.has_value()) {
2929
snapshot_ = contents_->RenderToSnapshot(
30-
renderer, entity, std::nullopt, msaa_enabled_,
31-
SPrintF("Contents to %s Filter Snapshot", label.c_str()));
30+
renderer, // renderer
31+
entity, // entity
32+
std::nullopt, // coverage_limit
33+
std::nullopt, // sampler_descriptor
34+
msaa_enabled_, // msaa_enabled
35+
SPrintF("Contents to %s Filter Snapshot", label.c_str())); // label
3236
}
3337
return snapshot_;
3438
}

impeller/entity/contents/filters/inputs/filter_contents_filter_input.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ std::optional<Snapshot> FilterContentsFilterInput::GetSnapshot(
2727
const Entity& entity) const {
2828
if (!snapshot_.has_value()) {
2929
snapshot_ = filter_->RenderToSnapshot(
30-
renderer, entity, std::nullopt, true,
31-
SPrintF("Filter to %s Filter Snapshot", label.c_str()));
30+
renderer, // renderer
31+
entity, // entity
32+
std::nullopt, // coverage_limit
33+
std::nullopt, // sampler_descriptor
34+
true, // msaa_enabled
35+
SPrintF("Filter to %s Filter Snapshot", label.c_str())); // label
3236
}
3337
return snapshot_;
3438
}

impeller/entity/contents/framebuffer_blend_contents.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@ bool FramebufferBlendContents::Render(const ContentContext& renderer,
4141

4242
auto& host_buffer = pass.GetTransientsBuffer();
4343

44-
auto src_snapshot =
45-
child_contents_->RenderToSnapshot(renderer, entity, std::nullopt, true,
46-
"FramebufferBlendContents Snapshot");
44+
auto src_snapshot = child_contents_->RenderToSnapshot(
45+
renderer, // renderer
46+
entity, // entity
47+
Rect::MakeSize(pass.GetRenderTargetSize()), // coverage_limit
48+
std::nullopt, // sampler_descriptor
49+
true, // msaa_enabled
50+
"FramebufferBlendContents Snapshot"); // label
4751
if (!src_snapshot.has_value()) {
4852
return true;
4953
}

impeller/entity/contents/texture_contents.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ std::optional<Rect> TextureContents::GetCoverage(const Entity& entity) const {
7676
std::optional<Snapshot> TextureContents::RenderToSnapshot(
7777
const ContentContext& renderer,
7878
const Entity& entity,
79+
std::optional<Rect> coverage_limit,
7980
const std::optional<SamplerDescriptor>& sampler_descriptor,
8081
bool msaa_enabled,
8182
const std::string& label) const {
@@ -95,8 +96,12 @@ std::optional<Snapshot> TextureContents::RenderToSnapshot(
9596
.opacity = opacity};
9697
}
9798
return Contents::RenderToSnapshot(
98-
renderer, entity, sampler_descriptor.value_or(sampler_descriptor_), true,
99-
label);
99+
renderer, // renderer
100+
entity, // entity
101+
std::nullopt, // coverage_limit
102+
sampler_descriptor.value_or(sampler_descriptor_), // sampler_descriptor
103+
true, // msaa_enabled
104+
label); // label
100105
}
101106

102107
static TextureFillVertexShader::PerVertexData ComputeVertexData(

impeller/entity/contents/texture_contents.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class TextureContents final : public Contents {
5757
std::optional<Snapshot> RenderToSnapshot(
5858
const ContentContext& renderer,
5959
const Entity& entity,
60+
std::optional<Rect> coverage_limit = std::nullopt,
6061
const std::optional<SamplerDescriptor>& sampler_descriptor = std::nullopt,
6162
bool msaa_enabled = true,
6263
const std::string& label = "Texture Snapshot") const override;

impeller/entity/contents/tiled_texture_contents.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ TiledTextureContents::CreateFilterTexture(
6666
const ColorFilterProc& filter = color_filter_.value();
6767
auto color_filter_contents = filter(FilterInput::Make(texture_));
6868
auto snapshot = color_filter_contents->RenderToSnapshot(
69-
renderer, Entity(), std::nullopt, true, "TiledTextureContents Snapshot");
69+
renderer, // renderer
70+
Entity(), // entity
71+
std::nullopt, // coverage_limit
72+
std::nullopt, // sampler_descriptor
73+
true, // msaa_enabled
74+
"TiledTextureContents Snapshot"); // label
7075
if (snapshot.has_value()) {
7176
return snapshot.value().texture;
7277
}

impeller/entity/contents/vertices_contents.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,12 @@ bool VerticesUVContents::Render(const ContentContext& renderer,
108108
auto src_contents = parent_.GetSourceContents();
109109

110110
auto snapshot = src_contents->RenderToSnapshot(
111-
renderer, entity, std::nullopt, true, "VerticesUVContents Snapshot");
111+
renderer, // renderer
112+
entity, // entity
113+
Rect::MakeSize(pass.GetRenderTargetSize()), // coverage_limit
114+
std::nullopt, // sampler_descriptor
115+
true, // msaa_enabled
116+
"VerticesUVContents Snapshot"); // label
112117
if (!snapshot.has_value()) {
113118
return false;
114119
}

0 commit comments

Comments
 (0)