[Impeller] Add AbsorbOpacity enum. (#45838)
Part of https://github.com/flutter/flutter/issues/134681.
diff --git a/impeller/aiks/color_filter.cc b/impeller/aiks/color_filter.cc
index 72868a0..87f7022 100644
--- a/impeller/aiks/color_filter.cc
+++ b/impeller/aiks/color_filter.cc
@@ -45,7 +45,7 @@
std::shared_ptr<ColorFilterContents> BlendColorFilter::WrapWithGPUColorFilter(
std::shared_ptr<FilterInput> input,
- bool absorb_opacity) const {
+ ColorFilterContents::AbsorbOpacity absorb_opacity) const {
auto filter =
ColorFilterContents::MakeBlend(blend_mode_, {std::move(input)}, color_);
filter->SetAbsorbOpacity(absorb_opacity);
@@ -73,7 +73,7 @@
std::shared_ptr<ColorFilterContents> MatrixColorFilter::WrapWithGPUColorFilter(
std::shared_ptr<FilterInput> input,
- bool absorb_opacity) const {
+ ColorFilterContents::AbsorbOpacity absorb_opacity) const {
auto filter =
ColorFilterContents::MakeColorMatrix({std::move(input)}, color_matrix_);
filter->SetAbsorbOpacity(absorb_opacity);
@@ -101,7 +101,7 @@
std::shared_ptr<ColorFilterContents>
SrgbToLinearColorFilter::WrapWithGPUColorFilter(
std::shared_ptr<FilterInput> input,
- bool absorb_opacity) const {
+ ColorFilterContents::AbsorbOpacity absorb_opacity) const {
auto filter = ColorFilterContents::MakeSrgbToLinearFilter({std::move(input)});
filter->SetAbsorbOpacity(absorb_opacity);
return filter;
@@ -127,7 +127,7 @@
std::shared_ptr<ColorFilterContents>
LinearToSrgbColorFilter::WrapWithGPUColorFilter(
std::shared_ptr<FilterInput> input,
- bool absorb_opacity) const {
+ ColorFilterContents::AbsorbOpacity absorb_opacity) const {
auto filter = ColorFilterContents::MakeSrgbToLinearFilter({std::move(input)});
filter->SetAbsorbOpacity(absorb_opacity);
return filter;
diff --git a/impeller/aiks/color_filter.h b/impeller/aiks/color_filter.h
index 234cbc6..1c5bf32 100644
--- a/impeller/aiks/color_filter.h
+++ b/impeller/aiks/color_filter.h
@@ -43,7 +43,7 @@
/// treated as color information.
virtual std::shared_ptr<ColorFilterContents> WrapWithGPUColorFilter(
std::shared_ptr<FilterInput> input,
- bool absorb_opacity) const = 0;
+ ColorFilterContents::AbsorbOpacity absorb_opacity) const = 0;
/// @brief Returns a function that can be used to filter unpremultiplied
/// Impeller Colors on the CPU.
@@ -65,7 +65,7 @@
// |ColorFilter|
std::shared_ptr<ColorFilterContents> WrapWithGPUColorFilter(
std::shared_ptr<FilterInput> input,
- bool absorb_opacity) const override;
+ ColorFilterContents::AbsorbOpacity absorb_opacity) const override;
// |ColorFilter|
ColorFilterProc GetCPUColorFilterProc() const override;
@@ -91,7 +91,7 @@
// |ColorFilter|
std::shared_ptr<ColorFilterContents> WrapWithGPUColorFilter(
std::shared_ptr<FilterInput> input,
- bool absorb_opacity) const override;
+ ColorFilterContents::AbsorbOpacity absorb_opacity) const override;
// |ColorFilter|
ColorFilterProc GetCPUColorFilterProc() const override;
@@ -116,7 +116,7 @@
// |ColorFilter|
std::shared_ptr<ColorFilterContents> WrapWithGPUColorFilter(
std::shared_ptr<FilterInput> input,
- bool absorb_opacity) const override;
+ ColorFilterContents::AbsorbOpacity absorb_opacity) const override;
// |ColorFilter|
ColorFilterProc GetCPUColorFilterProc() const override;
@@ -138,7 +138,7 @@
// |ColorFilter|
std::shared_ptr<ColorFilterContents> WrapWithGPUColorFilter(
std::shared_ptr<FilterInput> input,
- bool absorb_opacity) const override;
+ ColorFilterContents::AbsorbOpacity absorb_opacity) const override;
// |ColorFilter|
ColorFilterProc GetCPUColorFilterProc() const override;
diff --git a/impeller/aiks/color_source.cc b/impeller/aiks/color_source.cc
index 3329bcb..da3191f 100644
--- a/impeller/aiks/color_source.cc
+++ b/impeller/aiks/color_source.cc
@@ -10,6 +10,7 @@
#include "impeller/aiks/paint.h"
#include "impeller/core/sampler_descriptor.h"
#include "impeller/entity/contents/conical_gradient_contents.h"
+#include "impeller/entity/contents/filters/color_filter_contents.h"
#include "impeller/entity/contents/linear_gradient_contents.h"
#include "impeller/entity/contents/radial_gradient_contents.h"
#include "impeller/entity/contents/runtime_effect_contents.h"
@@ -182,8 +183,8 @@
if (paint.color_filter) {
TiledTextureContents::ColorFilterProc filter_proc =
[color_filter = paint.color_filter](FilterInput::Ref input) {
- return color_filter->WrapWithGPUColorFilter(std::move(input),
- false);
+ return color_filter->WrapWithGPUColorFilter(
+ std::move(input), ColorFilterContents::AbsorbOpacity::kNo);
};
contents->SetColorFilter(filter_proc);
}
diff --git a/impeller/aiks/image_filter.cc b/impeller/aiks/image_filter.cc
index 6420e8c..7eba487 100644
--- a/impeller/aiks/image_filter.cc
+++ b/impeller/aiks/image_filter.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "impeller/aiks/image_filter.h"
+#include "impeller/entity/contents/filters/color_filter_contents.h"
#include "impeller/entity/contents/filters/filter_contents.h"
#include "impeller/entity/contents/filters/inputs/filter_input.h"
@@ -175,7 +176,8 @@
std::shared_ptr<FilterContents> ColorImageFilter::WrapInput(
const FilterInput::Ref& input) const {
- return color_filter_->WrapWithGPUColorFilter(input, false);
+ return color_filter_->WrapWithGPUColorFilter(
+ input, ColorFilterContents::AbsorbOpacity::kNo);
}
std::shared_ptr<ImageFilter> ColorImageFilter::Clone() const {
diff --git a/impeller/aiks/paint.cc b/impeller/aiks/paint.cc
index 5c2b808..9950661 100644
--- a/impeller/aiks/paint.cc
+++ b/impeller/aiks/paint.cc
@@ -58,7 +58,7 @@
std::shared_ptr<Contents> Paint::WithFilters(
std::shared_ptr<Contents> input) const {
- input = WithColorFilter(input, /*absorb_opacity=*/true);
+ input = WithColorFilter(input, ColorFilterContents::AbsorbOpacity::kYes);
input = WithInvertFilter(input);
auto image_filter = WithImageFilter(input, Matrix(), /*is_subpass=*/false);
if (image_filter) {
@@ -75,7 +75,7 @@
if (image_filter) {
input = image_filter;
}
- input = WithColorFilter(input, /*absorb_opacity=*/true);
+ input = WithColorFilter(input, ColorFilterContents::AbsorbOpacity::kYes);
return input;
}
@@ -103,7 +103,7 @@
std::shared_ptr<Contents> Paint::WithColorFilter(
std::shared_ptr<Contents> input,
- bool absorb_opacity) const {
+ ColorFilterContents::AbsorbOpacity absorb_opacity) const {
// Image input types will directly set their color filter,
// if any. See `TiledTextureContents.SetColorFilter`.
if (color_source.GetType() == ColorSource::Type::kImage) {
@@ -186,7 +186,8 @@
if (color_filter) {
color_contents = color_filter->WrapWithGPUColorFilter(
- FilterInput::Make(color_source_contents), true);
+ FilterInput::Make(color_source_contents),
+ ColorFilterContents::AbsorbOpacity::kYes);
}
/// 5. Composite the color source with the blurred mask.
diff --git a/impeller/aiks/paint.h b/impeller/aiks/paint.h
index 384b4bd..e13fd91 100644
--- a/impeller/aiks/paint.h
+++ b/impeller/aiks/paint.h
@@ -104,8 +104,10 @@
bool is_subpass) const;
private:
- std::shared_ptr<Contents> WithColorFilter(std::shared_ptr<Contents> input,
- bool absorb_opacity = false) const;
+ std::shared_ptr<Contents> WithColorFilter(
+ std::shared_ptr<Contents> input,
+ ColorFilterContents::AbsorbOpacity absorb_opacity =
+ ColorFilterContents::AbsorbOpacity::kNo) const;
std::shared_ptr<Contents> WithInvertFilter(
std::shared_ptr<Contents> input) const;
diff --git a/impeller/entity/contents/filters/blend_filter_contents.cc b/impeller/entity/contents/filters/blend_filter_contents.cc
index 3c1b861..7e50634 100644
--- a/impeller/entity/contents/filters/blend_filter_contents.cc
+++ b/impeller/entity/contents/filters/blend_filter_contents.cc
@@ -13,6 +13,7 @@
#include "impeller/entity/contents/anonymous_contents.h"
#include "impeller/entity/contents/content_context.h"
#include "impeller/entity/contents/contents.h"
+#include "impeller/entity/contents/filters/color_filter_contents.h"
#include "impeller/entity/contents/filters/inputs/filter_input.h"
#include "impeller/entity/contents/solid_color_contents.h"
#include "impeller/entity/entity.h"
@@ -76,7 +77,7 @@
const Rect& coverage,
BlendMode blend_mode,
std::optional<Color> foreground_color,
- bool absorb_opacity,
+ ColorFilterContents::AbsorbOpacity absorb_opacity,
PipelineProc pipeline_proc,
std::optional<Scalar> alpha) {
using VS = typename TPipeline::VertexShader;
@@ -184,7 +185,10 @@
dst_sampler_descriptor);
FS::BindTextureSamplerDst(cmd, dst_snapshot->texture, dst_sampler);
frame_info.dst_y_coord_scale = dst_snapshot->texture->GetYCoordScale();
- blend_info.dst_input_alpha = absorb_opacity ? dst_snapshot->opacity : 1.0;
+ blend_info.dst_input_alpha =
+ absorb_opacity == ColorFilterContents::AbsorbOpacity::kYes
+ ? dst_snapshot->opacity
+ : 1.0;
if (foreground_color.has_value()) {
blend_info.color_factor = 1;
@@ -227,14 +231,17 @@
}
return Entity::FromSnapshot(
- Snapshot{.texture = out_texture,
- .transform = Matrix::MakeTranslation(subpass_coverage.origin),
- // Since we absorbed the transform of the inputs and used the
- // respective snapshot sampling modes when blending, pass on
- // the default NN clamp sampler.
- .sampler_descriptor = {},
- .opacity = (absorb_opacity ? 1.0f : dst_snapshot->opacity) *
- alpha.value_or(1.0)},
+ Snapshot{
+ .texture = out_texture,
+ .transform = Matrix::MakeTranslation(subpass_coverage.origin),
+ // Since we absorbed the transform of the inputs and used the
+ // respective snapshot sampling modes when blending, pass on
+ // the default NN clamp sampler.
+ .sampler_descriptor = {},
+ .opacity = (absorb_opacity == ColorFilterContents::AbsorbOpacity::kYes
+ ? 1.0f
+ : dst_snapshot->opacity) *
+ alpha.value_or(1.0)},
entity.GetBlendMode(), entity.GetStencilDepth());
}
@@ -246,7 +253,7 @@
Color foreground_color,
BlendMode blend_mode,
std::optional<Scalar> alpha,
- bool absorb_opacity) const {
+ ColorFilterContents::AbsorbOpacity absorb_opacity) const {
auto dst_snapshot =
input->GetSnapshot("ForegroundAdvancedBlend", renderer, entity);
if (!dst_snapshot.has_value()) {
@@ -353,7 +360,9 @@
FS::BindTextureSamplerDst(cmd, dst_snapshot->texture, dst_sampler);
frame_info.dst_y_coord_scale = dst_snapshot->texture->GetYCoordScale();
blend_info.dst_input_alpha =
- absorb_opacity ? dst_snapshot->opacity * alpha.value_or(1.0) : 1.0;
+ absorb_opacity == ColorFilterContents::AbsorbOpacity::kYes
+ ? dst_snapshot->opacity * alpha.value_or(1.0)
+ : 1.0;
blend_info.color_factor = 1;
blend_info.color = foreground_color;
@@ -395,7 +404,7 @@
Color foreground_color,
BlendMode blend_mode,
std::optional<Scalar> alpha,
- bool absorb_opacity) const {
+ ColorFilterContents::AbsorbOpacity absorb_opacity) const {
if (blend_mode == BlendMode::kClear) {
return std::nullopt;
}
@@ -477,7 +486,9 @@
dst_snapshot->texture->GetYCoordScale();
frag_info.input_alpha =
- absorb_opacity ? dst_snapshot->opacity * alpha.value_or(1.0) : 1.0;
+ absorb_opacity == ColorFilterContents::AbsorbOpacity::kYes
+ ? dst_snapshot->opacity * alpha.value_or(1.0)
+ : 1.0;
frag_info.output_alpha = 1.0;
auto blend_coefficients =
@@ -520,7 +531,7 @@
const Rect& coverage,
BlendMode blend_mode,
std::optional<Color> foreground_color,
- bool absorb_opacity,
+ ColorFilterContents::AbsorbOpacity absorb_opacity,
std::optional<Scalar> alpha) {
using VS = BlendPipeline::VertexShader;
using FS = BlendPipeline::FragmentShader;
@@ -589,7 +600,10 @@
input->texture->GetYCoordScale();
FS::FragInfo frag_info;
- frag_info.input_alpha = absorb_opacity ? input->opacity : 1.0;
+ frag_info.input_alpha =
+ absorb_opacity == ColorFilterContents::AbsorbOpacity::kYes
+ ? input->opacity
+ : 1.0;
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
VS::BindFrameInfo(cmd, host_buffer.EmplaceUniform(frame_info));
@@ -647,14 +661,17 @@
}
return Entity::FromSnapshot(
- Snapshot{.texture = out_texture,
- .transform = Matrix::MakeTranslation(subpass_coverage.origin),
- // Since we absorbed the transform of the inputs and used the
- // respective snapshot sampling modes when blending, pass on
- // the default NN clamp sampler.
- .sampler_descriptor = {},
- .opacity = (absorb_opacity ? 1.0f : dst_snapshot->opacity) *
- alpha.value_or(1.0)},
+ Snapshot{
+ .texture = out_texture,
+ .transform = Matrix::MakeTranslation(subpass_coverage.origin),
+ // Since we absorbed the transform of the inputs and used the
+ // respective snapshot sampling modes when blending, pass on
+ // the default NN clamp sampler.
+ .sampler_descriptor = {},
+ .opacity = (absorb_opacity == ColorFilterContents::AbsorbOpacity::kYes
+ ? 1.0f
+ : dst_snapshot->opacity) *
+ alpha.value_or(1.0)},
entity.GetBlendMode(), entity.GetStencilDepth());
}
@@ -663,7 +680,8 @@
advanced_blend_proc_ = \
[](const FilterInput::Vector& inputs, const ContentContext& renderer, \
const Entity& entity, const Rect& coverage, BlendMode blend_mode, \
- std::optional<Color> fg_color, bool absorb_opacity, \
+ std::optional<Color> fg_color, \
+ ColorFilterContents::AbsorbOpacity absorb_opacity, \
std::optional<Scalar> alpha) { \
PipelineProc p = &ContentContext::GetBlend##mode##Pipeline; \
return AdvancedBlend<Blend##mode##Pipeline>( \
@@ -726,7 +744,7 @@
if (blend_mode_ <= Entity::kLastPipelineBlendMode) {
if (inputs.size() == 1 && foreground_color_.has_value() &&
- GetAbsorbOpacity()) {
+ GetAbsorbOpacity() == ColorFilterContents::AbsorbOpacity::kYes) {
return CreateForegroundPorterDuffBlend(
inputs[0], renderer, entity, coverage, foreground_color_.value(),
blend_mode_, GetAlpha(), GetAbsorbOpacity());
@@ -737,7 +755,7 @@
if (blend_mode_ <= Entity::kLastAdvancedBlendMode) {
if (inputs.size() == 1 && foreground_color_.has_value() &&
- GetAbsorbOpacity()) {
+ GetAbsorbOpacity() == ColorFilterContents::AbsorbOpacity::kYes) {
return CreateForegroundAdvancedBlend(
inputs[0], renderer, entity, coverage, foreground_color_.value(),
blend_mode_, GetAlpha(), GetAbsorbOpacity());
diff --git a/impeller/entity/contents/filters/blend_filter_contents.h b/impeller/entity/contents/filters/blend_filter_contents.h
index f279f7f..a0e49d2 100644
--- a/impeller/entity/contents/filters/blend_filter_contents.h
+++ b/impeller/entity/contents/filters/blend_filter_contents.h
@@ -33,15 +33,15 @@
class BlendFilterContents : public ColorFilterContents {
public:
- using AdvancedBlendProc =
- std::function<std::optional<Entity>(const FilterInput::Vector& inputs,
- const ContentContext& renderer,
- const Entity& entity,
- const Rect& coverage,
- BlendMode blend_mode,
- std::optional<Color> foreground_color,
- bool absorb_opacity,
- std::optional<Scalar> alpha)>;
+ using AdvancedBlendProc = std::function<std::optional<Entity>(
+ const FilterInput::Vector& inputs,
+ const ContentContext& renderer,
+ const Entity& entity,
+ const Rect& coverage,
+ BlendMode blend_mode,
+ std::optional<Color> foreground_color,
+ ColorFilterContents::AbsorbOpacity absorb_opacity,
+ std::optional<Scalar> alpha)>;
BlendFilterContents();
@@ -75,7 +75,7 @@
Color foreground_color,
BlendMode blend_mode,
std::optional<Scalar> alpha,
- bool absorb_opacity) const;
+ ColorFilterContents::AbsorbOpacity absorb_opacity) const;
/// @brief Optimized porter-duff blend that avoids a second subpass when there
/// is only a single input and a foreground color.
@@ -89,7 +89,7 @@
Color foreground_color,
BlendMode blend_mode,
std::optional<Scalar> alpha,
- bool absorb_opacity) const;
+ ColorFilterContents::AbsorbOpacity absorb_opacity) const;
BlendMode blend_mode_ = BlendMode::kSourceOver;
AdvancedBlendProc advanced_blend_proc_;
diff --git a/impeller/entity/contents/filters/color_filter_contents.cc b/impeller/entity/contents/filters/color_filter_contents.cc
index 51de176..f5a3645 100644
--- a/impeller/entity/contents/filters/color_filter_contents.cc
+++ b/impeller/entity/contents/filters/color_filter_contents.cc
@@ -82,11 +82,12 @@
ColorFilterContents::~ColorFilterContents() = default;
-void ColorFilterContents::SetAbsorbOpacity(bool absorb_opacity) {
+void ColorFilterContents::SetAbsorbOpacity(AbsorbOpacity absorb_opacity) {
absorb_opacity_ = absorb_opacity;
}
-bool ColorFilterContents::GetAbsorbOpacity() const {
+ColorFilterContents::AbsorbOpacity ColorFilterContents::GetAbsorbOpacity()
+ const {
return absorb_opacity_;
}
diff --git a/impeller/entity/contents/filters/color_filter_contents.h b/impeller/entity/contents/filters/color_filter_contents.h
index 0099c16..f09b2d7 100644
--- a/impeller/entity/contents/filters/color_filter_contents.h
+++ b/impeller/entity/contents/filters/color_filter_contents.h
@@ -10,6 +10,11 @@
class ColorFilterContents : public FilterContents {
public:
+ enum class AbsorbOpacity {
+ kYes,
+ kNo,
+ };
+
/// @brief the [inputs] are expected to be in the order of dst, src.
static std::shared_ptr<ColorFilterContents> MakeBlend(
BlendMode blend_mode,
@@ -30,9 +35,9 @@
~ColorFilterContents() override;
- void SetAbsorbOpacity(bool absorb_opacity);
+ void SetAbsorbOpacity(AbsorbOpacity absorb_opacity);
- bool GetAbsorbOpacity() const;
+ AbsorbOpacity GetAbsorbOpacity() const;
/// @brief Sets an alpha that is applied to the final blended result.
void SetAlpha(Scalar alpha);
@@ -40,7 +45,7 @@
std::optional<Scalar> GetAlpha() const;
private:
- bool absorb_opacity_ = false;
+ AbsorbOpacity absorb_opacity_ = AbsorbOpacity::kNo;
std::optional<Scalar> alpha_;
FML_DISALLOW_COPY_AND_ASSIGN(ColorFilterContents);
diff --git a/impeller/entity/contents/filters/color_matrix_filter_contents.cc b/impeller/entity/contents/filters/color_matrix_filter_contents.cc
index 24d0389..98024af 100644
--- a/impeller/entity/contents/filters/color_matrix_filter_contents.cc
+++ b/impeller/entity/contents/filters/color_matrix_filter_contents.cc
@@ -9,6 +9,7 @@
#include "impeller/entity/contents/anonymous_contents.h"
#include "impeller/entity/contents/content_context.h"
#include "impeller/entity/contents/contents.h"
+#include "impeller/entity/contents/filters/color_filter_contents.h"
#include "impeller/geometry/point.h"
#include "impeller/geometry/vector.h"
#include "impeller/renderer/render_pass.h"
@@ -94,7 +95,10 @@
matrix[3], matrix[8], matrix[13], matrix[18]
);
// clang-format on
- frag_info.input_alpha = absorb_opacity ? input_snapshot->opacity : 1.0f;
+ frag_info.input_alpha =
+ absorb_opacity == ColorFilterContents::AbsorbOpacity::kYes
+ ? input_snapshot->opacity
+ : 1.0f;
auto sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
FS::BindInputTexture(cmd, input_snapshot->texture, sampler);
FS::BindFragInfo(cmd, host_buffer.EmplaceUniform(frag_info));
diff --git a/impeller/entity/contents/filters/linear_to_srgb_filter_contents.cc b/impeller/entity/contents/filters/linear_to_srgb_filter_contents.cc
index e75c269..df6f5e0 100644
--- a/impeller/entity/contents/filters/linear_to_srgb_filter_contents.cc
+++ b/impeller/entity/contents/filters/linear_to_srgb_filter_contents.cc
@@ -76,7 +76,10 @@
input_snapshot->texture->GetYCoordScale();
FS::FragInfo frag_info;
- frag_info.input_alpha = absorb_opacity ? input_snapshot->opacity : 1.0f;
+ frag_info.input_alpha =
+ absorb_opacity == ColorFilterContents::AbsorbOpacity::kYes
+ ? input_snapshot->opacity
+ : 1.0f;
auto sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
FS::BindInputTexture(cmd, input_snapshot->texture, sampler);
diff --git a/impeller/entity/contents/filters/srgb_to_linear_filter_contents.cc b/impeller/entity/contents/filters/srgb_to_linear_filter_contents.cc
index 84568a0a..253089a 100644
--- a/impeller/entity/contents/filters/srgb_to_linear_filter_contents.cc
+++ b/impeller/entity/contents/filters/srgb_to_linear_filter_contents.cc
@@ -76,7 +76,10 @@
input_snapshot->texture->GetYCoordScale();
FS::FragInfo frag_info;
- frag_info.input_alpha = absorb_opacity ? input_snapshot->opacity : 1.0f;
+ frag_info.input_alpha =
+ absorb_opacity == ColorFilterContents::AbsorbOpacity::kYes
+ ? input_snapshot->opacity
+ : 1.0f;
auto sampler = renderer.GetContext()->GetSamplerLibrary()->GetSampler({});
FS::BindInputTexture(cmd, input_snapshot->texture, sampler);