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

Commit 1a09663

Browse files
committed
[Impeller] Incorporate filters in subpass coverage.
1 parent 1df0a23 commit 1a09663

20 files changed

+163
-14
lines changed

impeller/aiks/aiks_unittests.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3173,7 +3173,7 @@ TEST_P(AiksTest, MatrixSaveLayerFilter) {
31733173
canvas.SaveLayer({.image_filter = ImageFilter::MakeMatrix(
31743174
Matrix::MakeTranslation(Vector2(1, 1) *
31753175
(200 + 100 * k1OverSqrt2)) *
3176-
Matrix::MakeScale(Vector2(1, 1) * 0.2) *
3176+
Matrix::MakeScale(Vector2(1, 1) * 0.5) *
31773177
Matrix::MakeTranslation(Vector2(-200, -200)),
31783178
SamplerDescriptor{})},
31793179
std::nullopt);
@@ -3201,7 +3201,7 @@ TEST_P(AiksTest, MatrixBackdropFilter) {
32013201
{}, std::nullopt,
32023202
ImageFilter::MakeMatrix(
32033203
Matrix::MakeTranslation(Vector2(1, 1) * (100 + 100 * k1OverSqrt2)) *
3204-
Matrix::MakeScale(Vector2(1, 1) * 0.2) *
3204+
Matrix::MakeScale(Vector2(1, 1) * 0.5) *
32053205
Matrix::MakeTranslation(Vector2(-100, -100)),
32063206
SamplerDescriptor{}));
32073207
canvas.Restore();

impeller/aiks/paint.cc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,21 @@ std::shared_ptr<Contents> Paint::WithFilters(
6060
std::shared_ptr<Contents> input) const {
6161
input = WithColorFilter(input, /*absorb_opacity=*/true);
6262
input = WithInvertFilter(input);
63-
input = WithImageFilter(input, Matrix(), /*is_subpass=*/false);
63+
auto image_filter = WithImageFilter(input, Matrix(), /*is_subpass=*/false);
64+
if (image_filter) {
65+
input = image_filter;
66+
}
6467
return input;
6568
}
6669

6770
std::shared_ptr<Contents> Paint::WithFiltersForSubpassTarget(
6871
std::shared_ptr<Contents> input,
6972
const Matrix& effect_transform) const {
70-
input = WithImageFilter(input, effect_transform, /*is_subpass=*/true);
73+
auto image_filter =
74+
WithImageFilter(input, effect_transform, /*is_subpass=*/true);
75+
if (image_filter) {
76+
input = image_filter;
77+
}
7178
input = WithColorFilter(input, /*absorb_opacity=*/true);
7279
return input;
7380
}
@@ -81,12 +88,12 @@ std::shared_ptr<Contents> Paint::WithMaskBlur(std::shared_ptr<Contents> input,
8188
return input;
8289
}
8390

84-
std::shared_ptr<Contents> Paint::WithImageFilter(
85-
std::shared_ptr<Contents> input,
91+
std::shared_ptr<FilterContents> Paint::WithImageFilter(
92+
const FilterInput::Variant& input,
8693
const Matrix& effect_transform,
8794
bool is_subpass) const {
8895
if (!image_filter) {
89-
return input;
96+
return nullptr;
9097
}
9198
auto filter = image_filter->WrapInput(FilterInput::Make(input));
9299
filter->SetIsForSubpass(is_subpass);

impeller/aiks/paint.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,12 @@ struct Paint {
9898
std::shared_ptr<Contents> WithMaskBlur(std::shared_ptr<Contents> input,
9999
bool is_solid_color) const;
100100

101-
private:
102-
std::shared_ptr<Contents> WithImageFilter(std::shared_ptr<Contents> input,
103-
const Matrix& effect_transform,
104-
bool is_subpass) const;
101+
std::shared_ptr<FilterContents> WithImageFilter(
102+
const FilterInput::Variant& input,
103+
const Matrix& effect_transform,
104+
bool is_subpass) const;
105105

106+
private:
106107
std::shared_ptr<Contents> WithColorFilter(std::shared_ptr<Contents> input,
107108
bool absorb_opacity = false) const;
108109

impeller/aiks/paint_pass_delegate.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ std::shared_ptr<Contents> PaintPassDelegate::CreateContentsForSubpassTarget(
4747
effect_transform);
4848
}
4949

50+
// |EntityPassDelgate|
51+
std::shared_ptr<FilterContents> PaintPassDelegate::WithImageFilter(
52+
const FilterInput::Variant& input,
53+
const Matrix& effect_transform) const {
54+
return paint_.WithImageFilter(input, effect_transform, true);
55+
}
56+
5057
/// OpacityPeepholePassDelegate
5158
/// ----------------------------------------------
5259

@@ -140,4 +147,11 @@ OpacityPeepholePassDelegate::CreateContentsForSubpassTarget(
140147
effect_transform);
141148
}
142149

150+
// |EntityPassDelgate|
151+
std::shared_ptr<FilterContents> OpacityPeepholePassDelegate::WithImageFilter(
152+
const FilterInput::Variant& input,
153+
const Matrix& effect_transform) const {
154+
return paint_.WithImageFilter(input, effect_transform, true);
155+
}
156+
143157
} // namespace impeller

impeller/aiks/paint_pass_delegate.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class PaintPassDelegate final : public EntityPassDelegate {
3232
std::shared_ptr<Texture> target,
3333
const Matrix& effect_transform) override;
3434

35+
// |EntityPassDelgate|
36+
std::shared_ptr<FilterContents> WithImageFilter(
37+
const FilterInput::Variant& input,
38+
const Matrix& effect_transform) const override;
39+
3540
private:
3641
const Paint paint_;
3742

@@ -61,6 +66,11 @@ class OpacityPeepholePassDelegate final : public EntityPassDelegate {
6166
std::shared_ptr<Texture> target,
6267
const Matrix& effect_transform) override;
6368

69+
// |EntityPassDelgate|
70+
std::shared_ptr<FilterContents> WithImageFilter(
71+
const FilterInput::Variant& input,
72+
const Matrix& effect_transform) const override;
73+
6474
private:
6575
const Paint paint_;
6676

impeller/entity/contents/contents.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ std::optional<Color> Contents::AsBackgroundColor(const Entity& entity,
123123
return {};
124124
}
125125

126+
const FilterContents* Contents::AsFilter() const {
127+
return nullptr;
128+
}
129+
126130
bool Contents::ApplyColorFilter(
127131
const Contents::ColorFilterProc& color_filter_proc) {
128132
return false;

impeller/entity/contents/contents.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct ContentContextOptions;
2323
class Entity;
2424
class Surface;
2525
class RenderPass;
26+
class FilterContents;
2627

2728
ContentContextOptions OptionsFromPass(const RenderPass& pass);
2829

@@ -155,6 +156,12 @@ class Contents {
155156
virtual std::optional<Color> AsBackgroundColor(const Entity& entity,
156157
ISize target_size) const;
157158

159+
//----------------------------------------------------------------------------
160+
/// @brief Cast to a filter. Returns `nullptr` if this Contents is not a
161+
/// filter.
162+
///
163+
virtual const FilterContents* AsFilter() const;
164+
158165
//----------------------------------------------------------------------------
159166
/// @brief If possible, applies a color filter to this contents inputs on
160167
/// the CPU.

impeller/entity/contents/filters/filter_contents.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,25 @@ std::optional<Snapshot> FilterContents::RenderToSnapshot(
259259
return std::nullopt;
260260
}
261261

262+
const FilterContents* FilterContents::AsFilter() const {
263+
return this;
264+
}
265+
262266
Matrix FilterContents::GetLocalTransform(const Matrix& parent_transform) const {
263267
return Matrix();
264268
}
265269

266270
Matrix FilterContents::GetTransform(const Matrix& parent_transform) const {
267271
return parent_transform * GetLocalTransform(parent_transform);
268272
}
273+
bool FilterContents::HasBasisTransformations() const {
274+
for (auto& input : inputs_) {
275+
if (!input->HasBasisTransformations()) {
276+
return false;
277+
}
278+
}
279+
return true;
280+
}
269281

270282
bool FilterContents::IsLeaf() const {
271283
for (auto& input : inputs_) {

impeller/entity/contents/filters/filter_contents.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,22 @@ class FilterContents : public Contents {
125125
bool msaa_enabled = true,
126126
const std::string& label = "Filter Snapshot") const override;
127127

128+
// |Contents|
129+
const FilterContents* AsFilter() const override;
130+
128131
virtual Matrix GetLocalTransform(const Matrix& parent_transform) const;
129132

130133
Matrix GetTransform(const Matrix& parent_transform) const;
131134

135+
/// @brief Returns true of this filter graph performs basis transformations
136+
/// to the filtered content. For example: Rotating, scaling, and
137+
/// skewing are all basis transformations, but translating is not.
138+
///
139+
/// This is useful for determining whether a filtered object's space
140+
/// is compatible enough with the parent pass space to perform certain
141+
/// subpass optimizations.
142+
virtual bool HasBasisTransformations() const;
143+
132144
/// @brief Returns `true` if this filter does not have any `FilterInput`
133145
/// children.
134146
bool IsLeaf() const;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ void FilterContentsFilterInput::PopulateGlyphAtlas(
5858
filter_->PopulateGlyphAtlas(lazy_glyph_atlas, scale);
5959
}
6060

61+
bool FilterContentsFilterInput::HasBasisTransformations() const {
62+
return filter_->HasBasisTransformations();
63+
}
64+
6165
bool FilterContentsFilterInput::IsLeaf() const {
6266
return false;
6367
}

0 commit comments

Comments
 (0)