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

Commit ee32ab7

Browse files
author
jonahwilliams
committed
require absorbing opacity
1 parent 6a22ec3 commit ee32ab7

2 files changed

Lines changed: 24 additions & 32 deletions

File tree

impeller/aiks/aiks_unittests.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,6 +2035,26 @@ TEST_P(AiksTest, TranslucentSaveLayerWithBlendImageFilterAndDrawsCorrectly) {
20352035
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
20362036
}
20372037

2038+
TEST_P(AiksTest, TranslucentSaveLayerWithColorImageFilterAndDrawsCorrectly) {
2039+
Canvas canvas;
2040+
2041+
canvas.DrawRect(Rect::MakeXYWH(100, 100, 300, 300), {.color = Color::Blue()});
2042+
2043+
canvas.SaveLayer({
2044+
.color = Color::Black().WithAlpha(0.5),
2045+
.color_filter =
2046+
[](FilterInput::Ref input) {
2047+
return ColorFilterContents::MakeBlend(
2048+
BlendMode::kDestinationOver, {std::move(input)}, Color::Red());
2049+
},
2050+
});
2051+
2052+
canvas.DrawRect(Rect::MakeXYWH(100, 500, 300, 300), {.color = Color::Blue()});
2053+
canvas.Restore();
2054+
2055+
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
2056+
}
2057+
20382058
TEST_P(AiksTest, TranslucentSaveLayerImageDrawsCorrectly) {
20392059
Canvas canvas;
20402060

impeller/entity/contents/filters/blend_filter_contents.cc

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -318,21 +318,6 @@ std::optional<Entity> BlendFilterContents::CreateForegroundAdvancedBlend(
318318

319319
auto contents = AnonymousContents::Make(render_proc, coverage_proc);
320320

321-
// If there is pending opacity but it was not absorbed by this entity, we have
322-
// to convert this back to a snapshot so it can be passed on. This generally
323-
// implies that there is another filter about to run, so we'd perform this
324-
// operation anyway.
325-
auto potential_opacity = alpha.value_or(1.0) * dst_snapshot->opacity;
326-
if (!absorb_opacity && potential_opacity < 1.0) {
327-
auto result_snapshot = contents->RenderToSnapshot(renderer, entity);
328-
if (!result_snapshot.has_value()) {
329-
return std::nullopt;
330-
}
331-
result_snapshot->opacity = potential_opacity;
332-
return Entity::FromSnapshot(result_snapshot.value(), entity.GetBlendMode(),
333-
entity.GetStencilDepth());
334-
}
335-
336321
Entity sub_entity;
337322
sub_entity.SetContents(std::move(contents));
338323
sub_entity.SetStencilDepth(entity.GetStencilDepth());
@@ -472,21 +457,6 @@ std::optional<Entity> BlendFilterContents::CreateForegroundPorterDuffBlend(
472457

473458
auto contents = AnonymousContents::Make(render_proc, coverage_proc);
474459

475-
// If there is pending opacity but it was not absorbed by this entity, we have
476-
// to convert this back to a snapshot so it can be passed on. This generally
477-
// implies that there is another filter about to run, so we'd perform this
478-
// operation anyway.
479-
auto potential_opacity = alpha.value_or(1.0) * dst_snapshot->opacity;
480-
if (!absorb_opacity && potential_opacity < 1.0) {
481-
auto result_snapshot = contents->RenderToSnapshot(renderer, entity);
482-
if (!result_snapshot.has_value()) {
483-
return std::nullopt;
484-
}
485-
result_snapshot->opacity = potential_opacity;
486-
return Entity::FromSnapshot(result_snapshot.value(), entity.GetBlendMode(),
487-
entity.GetStencilDepth());
488-
}
489-
490460
Entity sub_entity;
491461
sub_entity.SetContents(std::move(contents));
492462
sub_entity.SetStencilDepth(entity.GetStencilDepth());
@@ -685,7 +655,8 @@ std::optional<Entity> BlendFilterContents::RenderFilter(
685655
}
686656

687657
if (blend_mode_ <= Entity::kLastPipelineBlendMode) {
688-
if (inputs.size() == 1 && foreground_color_.has_value()) {
658+
if (inputs.size() == 1 && foreground_color_.has_value() &&
659+
GetAbsorbOpacity()) {
689660
return CreateForegroundPorterDuffBlend(
690661
inputs[0], renderer, entity, coverage, foreground_color_.value(),
691662
blend_mode_, GetAlpha(), GetAbsorbOpacity());
@@ -695,7 +666,8 @@ std::optional<Entity> BlendFilterContents::RenderFilter(
695666
}
696667

697668
if (blend_mode_ <= Entity::kLastAdvancedBlendMode) {
698-
if (inputs.size() == 1 && foreground_color_.has_value()) {
669+
if (inputs.size() == 1 && foreground_color_.has_value() &&
670+
GetAbsorbOpacity()) {
699671
return CreateForegroundAdvancedBlend(
700672
inputs[0], renderer, entity, coverage, foreground_color_.value(),
701673
blend_mode_, GetAlpha(), GetAbsorbOpacity());

0 commit comments

Comments
 (0)