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

Commit 558fe81

Browse files
authored
[Impeller] removes advanced plus blending (#52163)
Now that #52019 has landed, we shouldn't need it anymore. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
1 parent 03b08d7 commit 558fe81

19 files changed

+65
-180
lines changed

impeller/aiks/aiks_unittests.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -941,13 +941,14 @@ TEST_P(AiksTest, CanDrawPaintMultipleTimes) {
941941
TEST_P(AiksTest, FormatWideGamut) {
942942
EXPECT_EQ(GetContext()->GetCapabilities()->GetDefaultColorFormat(),
943943
PixelFormat::kB10G10R10A10XR);
944-
EXPECT_TRUE(IsAlphaClampedToOne(
945-
GetContext()->GetCapabilities()->GetDefaultColorFormat()));
946944
}
947945

948946
TEST_P(AiksTest, FormatSRGB) {
949-
EXPECT_TRUE(IsAlphaClampedToOne(
950-
GetContext()->GetCapabilities()->GetDefaultColorFormat()));
947+
PixelFormat pixel_format =
948+
GetContext()->GetCapabilities()->GetDefaultColorFormat();
949+
EXPECT_TRUE(pixel_format == PixelFormat::kR8G8B8A8UNormInt ||
950+
pixel_format == PixelFormat::kB8G8R8A8UNormInt)
951+
<< "pixel format: " << PixelFormatToString(pixel_format);
951952
}
952953

953954
TEST_P(AiksTest, TransformMultipliesCorrectly) {

impeller/compiler/shader_lib/impeller/color.glsl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,4 @@ f16vec4 IPHalfPremultiply(f16vec4 color) {
4646
return f16vec4(color.rgb * color.a, color.a);
4747
}
4848

49-
/// Performs the plus blend on `src` and `dst` which are premultiplied colors.
50-
//`max` determines the values the results are clamped to.
51-
f16vec4 IPHalfPlusBlend(f16vec4 src, f16vec4 dst) {
52-
float16_t min = 0.0hf;
53-
float16_t max = 1.0hf;
54-
return clamp(dst + src, min, max);
55-
}
56-
5749
#endif

impeller/core/formats.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,6 @@ constexpr bool IsStencilWritable(PixelFormat format) {
138138
}
139139
}
140140

141-
/// Returns `true` if the pixel format has an implicit `clamp(x, 0, 1)` in the
142-
/// pixel format. This is important for example when performing the `Plus` blend
143-
/// where we don't want alpha values over 1.0.
144-
constexpr bool IsAlphaClampedToOne(PixelFormat pixel_format) {
145-
return !(pixel_format == PixelFormat::kR32G32B32A32Float ||
146-
pixel_format == PixelFormat::kR16G16B16A16Float);
147-
}
148-
149141
constexpr const char* PixelFormatToString(PixelFormat format) {
150142
switch (format) {
151143
case PixelFormat::kUnknown:

impeller/entity/contents/content_context.cc

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ void ContentContextOptions::ApplyToPipelineDescriptor(
124124
color0.src_color_blend_factor = BlendFactor::kOneMinusDestinationAlpha;
125125
break;
126126
case BlendMode::kPlus:
127-
// The kPlusAdvanced should be used instead.
128-
FML_DCHECK(IsAlphaClampedToOne(color_attachment_pixel_format));
129127
color0.dst_alpha_blend_factor = BlendFactor::kOne;
130128
color0.dst_color_blend_factor = BlendFactor::kOne;
131129
color0.src_alpha_blend_factor = BlendFactor::kOne;
@@ -326,10 +324,6 @@ ContentContext::ContentContext(
326324
framebuffer_blend_lighten_pipelines_.CreateDefault(
327325
*context_, options_trianglestrip,
328326
{static_cast<Scalar>(BlendSelectValues::kLighten), supports_decal});
329-
framebuffer_blend_plus_advanced_pipelines_.CreateDefault(
330-
*context_, options_trianglestrip,
331-
{static_cast<Scalar>(BlendSelectValues::kPlusAdvanced),
332-
supports_decal});
333327
framebuffer_blend_luminosity_pipelines_.CreateDefault(
334328
*context_, options_trianglestrip,
335329
{static_cast<Scalar>(BlendSelectValues::kLuminosity), supports_decal});
@@ -377,9 +371,6 @@ ContentContext::ContentContext(
377371
blend_lighten_pipelines_.CreateDefault(
378372
*context_, options_trianglestrip,
379373
{static_cast<Scalar>(BlendSelectValues::kLighten), supports_decal});
380-
blend_plus_advanced_pipelines_.CreateDefault(
381-
*context_, options_trianglestrip,
382-
{static_cast<Scalar>(BlendSelectValues::kPlusAdvanced), supports_decal});
383374
blend_luminosity_pipelines_.CreateDefault(
384375
*context_, options_trianglestrip,
385376
{static_cast<Scalar>(BlendSelectValues::kLuminosity), supports_decal});

impeller/entity/contents/content_context.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ using BlendHuePipeline =
181181
RenderPipelineT<AdvancedBlendVertexShader, AdvancedBlendFragmentShader>;
182182
using BlendLightenPipeline =
183183
RenderPipelineT<AdvancedBlendVertexShader, AdvancedBlendFragmentShader>;
184-
using BlendPlusAdvancedPipeline =
185-
RenderPipelineT<AdvancedBlendVertexShader, AdvancedBlendFragmentShader>;
186184
using BlendLuminosityPipeline =
187185
RenderPipelineT<AdvancedBlendVertexShader, AdvancedBlendFragmentShader>;
188186
using BlendMultiplyPipeline =
@@ -223,9 +221,6 @@ using FramebufferBlendHuePipeline =
223221
using FramebufferBlendLightenPipeline =
224222
RenderPipelineT<FramebufferBlendVertexShader,
225223
FramebufferBlendFragmentShader>;
226-
using FramebufferBlendPlusAdvancedPipeline =
227-
RenderPipelineT<FramebufferBlendVertexShader,
228-
FramebufferBlendFragmentShader>;
229224
using FramebufferBlendLuminosityPipeline =
230225
RenderPipelineT<FramebufferBlendVertexShader,
231226
FramebufferBlendFragmentShader>;
@@ -609,11 +604,6 @@ class ContentContext {
609604
return GetPipeline(blend_lighten_pipelines_, opts);
610605
}
611606

612-
std::shared_ptr<Pipeline<PipelineDescriptor>> GetBlendPlusAdvancedPipeline(
613-
ContentContextOptions opts) const {
614-
return GetPipeline(blend_plus_advanced_pipelines_, opts);
615-
}
616-
617607
std::shared_ptr<Pipeline<PipelineDescriptor>> GetBlendLuminosityPipeline(
618608
ContentContextOptions opts) const {
619609
return GetPipeline(blend_luminosity_pipelines_, opts);
@@ -699,12 +689,6 @@ class ContentContext {
699689
return GetPipeline(framebuffer_blend_lighten_pipelines_, opts);
700690
}
701691

702-
std::shared_ptr<Pipeline<PipelineDescriptor>>
703-
GetFramebufferBlendPlusAdvancedPipeline(ContentContextOptions opts) const {
704-
FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch());
705-
return GetPipeline(framebuffer_blend_plus_advanced_pipelines_, opts);
706-
}
707-
708692
std::shared_ptr<Pipeline<PipelineDescriptor>>
709693
GetFramebufferBlendLuminosityPipeline(ContentContextOptions opts) const {
710694
FML_DCHECK(GetDeviceCapabilities().SupportsFramebufferFetch());
@@ -967,7 +951,6 @@ class ContentContext {
967951
mutable Variants<BlendHardLightPipeline> blend_hardlight_pipelines_;
968952
mutable Variants<BlendHuePipeline> blend_hue_pipelines_;
969953
mutable Variants<BlendLightenPipeline> blend_lighten_pipelines_;
970-
mutable Variants<BlendPlusAdvancedPipeline> blend_plus_advanced_pipelines_;
971954
mutable Variants<BlendLuminosityPipeline> blend_luminosity_pipelines_;
972955
mutable Variants<BlendMultiplyPipeline> blend_multiply_pipelines_;
973956
mutable Variants<BlendOverlayPipeline> blend_overlay_pipelines_;
@@ -993,8 +976,6 @@ class ContentContext {
993976
framebuffer_blend_hue_pipelines_;
994977
mutable Variants<FramebufferBlendLightenPipeline>
995978
framebuffer_blend_lighten_pipelines_;
996-
mutable Variants<FramebufferBlendPlusAdvancedPipeline>
997-
framebuffer_blend_plus_advanced_pipelines_;
998979
mutable Variants<FramebufferBlendLuminosityPipeline>
999980
framebuffer_blend_luminosity_pipelines_;
1000981
mutable Variants<FramebufferBlendMultiplyPipeline>

impeller/entity/contents/filters/blend_filter_contents.cc

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,6 @@ std::optional<Entity> BlendFilterContents::CreateForegroundAdvancedBlend(
339339
case BlendMode::kColor:
340340
pass.SetPipeline(renderer.GetBlendColorPipeline(options));
341341
break;
342-
case BlendMode::kPlusAdvanced:
343-
pass.SetPipeline(renderer.GetBlendPlusAdvancedPipeline(options));
344-
break;
345342
case BlendMode::kLuminosity:
346343
pass.SetPipeline(renderer.GetBlendLuminosityPipeline(options));
347344
break;
@@ -665,7 +662,7 @@ static std::optional<Entity> PipelineBlend(
665662

666663
#define BLEND_CASE(mode) \
667664
case BlendMode::k##mode: \
668-
return \
665+
advanced_blend_proc_ = \
669666
[](const FilterInput::Vector& inputs, const ContentContext& renderer, \
670667
const Entity& entity, const Rect& coverage, BlendMode blend_mode, \
671668
std::optional<Color> fg_color, \
@@ -678,39 +675,35 @@ static std::optional<Entity> PipelineBlend(
678675
}; \
679676
break;
680677

681-
namespace {
682-
BlendFilterContents::AdvancedBlendProc GetAdvancedBlendProc(
683-
BlendMode blend_mode) {
684-
switch (blend_mode) {
685-
BLEND_CASE(Screen)
686-
BLEND_CASE(Overlay)
687-
BLEND_CASE(Darken)
688-
BLEND_CASE(Lighten)
689-
BLEND_CASE(ColorDodge)
690-
BLEND_CASE(ColorBurn)
691-
BLEND_CASE(HardLight)
692-
BLEND_CASE(SoftLight)
693-
BLEND_CASE(Difference)
694-
BLEND_CASE(Exclusion)
695-
BLEND_CASE(Multiply)
696-
BLEND_CASE(Hue)
697-
BLEND_CASE(Saturation)
698-
BLEND_CASE(Color)
699-
BLEND_CASE(PlusAdvanced)
700-
BLEND_CASE(Luminosity)
701-
default:
702-
FML_UNREACHABLE();
703-
}
704-
}
705-
} // namespace
706-
707678
void BlendFilterContents::SetBlendMode(BlendMode blend_mode) {
708679
if (blend_mode > Entity::kLastAdvancedBlendMode) {
709680
VALIDATION_LOG << "Invalid blend mode " << static_cast<int>(blend_mode)
710681
<< " assigned to BlendFilterContents.";
711682
}
712683

713684
blend_mode_ = blend_mode;
685+
686+
if (blend_mode > Entity::kLastPipelineBlendMode) {
687+
switch (blend_mode) {
688+
BLEND_CASE(Screen)
689+
BLEND_CASE(Overlay)
690+
BLEND_CASE(Darken)
691+
BLEND_CASE(Lighten)
692+
BLEND_CASE(ColorDodge)
693+
BLEND_CASE(ColorBurn)
694+
BLEND_CASE(HardLight)
695+
BLEND_CASE(SoftLight)
696+
BLEND_CASE(Difference)
697+
BLEND_CASE(Exclusion)
698+
BLEND_CASE(Multiply)
699+
BLEND_CASE(Hue)
700+
BLEND_CASE(Saturation)
701+
BLEND_CASE(Color)
702+
BLEND_CASE(Luminosity)
703+
default:
704+
FML_UNREACHABLE();
705+
}
706+
}
714707
}
715708

716709
void BlendFilterContents::SetForegroundColor(std::optional<Color> color) {
@@ -734,35 +727,27 @@ std::optional<Entity> BlendFilterContents::RenderFilter(
734727
std::nullopt, GetAbsorbOpacity(), GetAlpha());
735728
}
736729

737-
BlendMode blend_mode = blend_mode_;
738-
if (blend_mode == BlendMode::kPlus &&
739-
!IsAlphaClampedToOne(
740-
renderer.GetContext()->GetCapabilities()->GetDefaultColorFormat())) {
741-
blend_mode = BlendMode::kPlusAdvanced;
742-
}
743-
744-
if (blend_mode <= Entity::kLastPipelineBlendMode) {
730+
if (blend_mode_ <= Entity::kLastPipelineBlendMode) {
745731
if (inputs.size() == 1 && foreground_color_.has_value() &&
746732
GetAbsorbOpacity() == ColorFilterContents::AbsorbOpacity::kYes) {
747733
return CreateForegroundPorterDuffBlend(
748734
inputs[0], renderer, entity, coverage, foreground_color_.value(),
749735
blend_mode_, GetAlpha(), GetAbsorbOpacity());
750736
}
751-
return PipelineBlend(inputs, renderer, entity, coverage, blend_mode,
737+
return PipelineBlend(inputs, renderer, entity, coverage, blend_mode_,
752738
foreground_color_, GetAbsorbOpacity(), GetAlpha());
753739
}
754740

755-
if (blend_mode <= Entity::kLastAdvancedBlendMode) {
741+
if (blend_mode_ <= Entity::kLastAdvancedBlendMode) {
756742
if (inputs.size() == 1 && foreground_color_.has_value() &&
757743
GetAbsorbOpacity() == ColorFilterContents::AbsorbOpacity::kYes) {
758744
return CreateForegroundAdvancedBlend(
759745
inputs[0], renderer, entity, coverage, foreground_color_.value(),
760-
blend_mode, GetAlpha(), GetAbsorbOpacity());
746+
blend_mode_, GetAlpha(), GetAbsorbOpacity());
761747
}
762-
AdvancedBlendProc advanced_blend_proc = GetAdvancedBlendProc(blend_mode);
763-
return advanced_blend_proc(inputs, renderer, entity, coverage, blend_mode,
764-
foreground_color_, GetAbsorbOpacity(),
765-
GetAlpha());
748+
return advanced_blend_proc_(inputs, renderer, entity, coverage, blend_mode_,
749+
foreground_color_, GetAbsorbOpacity(),
750+
GetAlpha());
766751
}
767752

768753
FML_UNREACHABLE();

impeller/entity/contents/filters/blend_filter_contents.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class BlendFilterContents : public ColorFilterContents {
9393
ColorFilterContents::AbsorbOpacity absorb_opacity) const;
9494

9595
BlendMode blend_mode_ = BlendMode::kSourceOver;
96+
AdvancedBlendProc advanced_blend_proc_;
9697
std::optional<Color> foreground_color_;
9798

9899
BlendFilterContents(const BlendFilterContents&) = delete;

impeller/entity/contents/framebuffer_blend_contents.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,6 @@ bool FramebufferBlendContents::Render(const ContentContext& renderer,
117117
case BlendMode::kColor:
118118
pass.SetPipeline(renderer.GetFramebufferBlendColorPipeline(options));
119119
break;
120-
case BlendMode::kPlusAdvanced:
121-
pass.SetPipeline(
122-
renderer.GetFramebufferBlendPlusAdvancedPipeline(options));
123-
break;
124120
case BlendMode::kLuminosity:
125121
pass.SetPipeline(renderer.GetFramebufferBlendLuminosityPipeline(options));
126122
break;

impeller/entity/contents/framebuffer_blend_contents.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ enum class BlendSelectValues {
2727
kHue,
2828
kSaturation,
2929
kColor,
30-
kPlusAdvanced,
3130
kLuminosity,
3231
};
3332

impeller/entity/entity_pass.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -967,13 +967,6 @@ bool EntityPass::OnRender(
967967
/// Setup advanced blends.
968968
///
969969

970-
if (result.entity.GetBlendMode() == BlendMode::kPlus &&
971-
!IsAlphaClampedToOne(pass_context.GetPassTarget()
972-
.GetRenderTarget()
973-
.GetRenderTargetPixelFormat())) {
974-
result.entity.SetBlendMode(BlendMode::kPlusAdvanced);
975-
}
976-
977970
if (result.entity.GetBlendMode() > Entity::kLastPipelineBlendMode) {
978971
if (renderer.GetDeviceCapabilities().SupportsFramebufferFetch()) {
979972
auto src_contents = result.entity.GetContents();

0 commit comments

Comments
 (0)