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

Commit 669e912

Browse files
authored
[Impeller] Add Entity::RenderingMode enum. (#45845)
Resolves flutter/flutter#134681. For the various places where we track if a rendered entity is a subpass or not. After landing this, I think the next winning move is to make this an Entity field and remove the `SetRenderingMode` junk from the filter graph. That refactor is a bit more risky, so I plan to do that separately.
1 parent 683bca5 commit 669e912

16 files changed

+53
-34
lines changed

impeller/aiks/canvas.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,18 @@ void Canvas::Save(bool create_subpass,
6464
entry.cull_rect = xformation_stack_.back().cull_rect;
6565
entry.stencil_depth = xformation_stack_.back().stencil_depth;
6666
if (create_subpass) {
67-
entry.is_subpass = true;
67+
entry.rendering_mode = Entity::RenderingMode::kSubpass;
6868
auto subpass = std::make_unique<EntityPass>();
6969
subpass->SetEnableOffscreenCheckerboard(
7070
debug_options.offscreen_texture_checkerboard);
7171
if (backdrop_filter) {
7272
EntityPass::BackdropFilterProc backdrop_filter_proc =
7373
[backdrop_filter = backdrop_filter->Clone()](
7474
const FilterInput::Ref& input, const Matrix& effect_transform,
75-
bool is_subpass) {
75+
Entity::RenderingMode rendering_mode) {
7676
auto filter = backdrop_filter->WrapInput(input);
7777
filter->SetEffectTransform(effect_transform);
78-
filter->SetIsForSubpass(is_subpass);
78+
filter->SetRenderingMode(rendering_mode);
7979
return filter;
8080
};
8181
subpass->SetBackdropFilter(backdrop_filter_proc);
@@ -93,7 +93,8 @@ bool Canvas::Restore() {
9393
if (xformation_stack_.size() == 1) {
9494
return false;
9595
}
96-
if (xformation_stack_.back().is_subpass) {
96+
if (xformation_stack_.back().rendering_mode ==
97+
Entity::RenderingMode::kSubpass) {
9798
current_pass_ = GetCurrentPass().GetSuperpass();
9899
FML_DCHECK(current_pass_);
99100
}

impeller/aiks/canvas.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ struct CanvasStackEntry {
3535
// |cull_rect| is conservative screen-space bounds of the clipped output area
3636
std::optional<Rect> cull_rect;
3737
size_t stencil_depth = 0u;
38-
bool is_subpass = false;
38+
Entity::RenderingMode rendering_mode = Entity::RenderingMode::kDirect;
3939
bool contains_clips = false;
4040
};
4141

impeller/aiks/paint.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ std::shared_ptr<Contents> Paint::WithFilters(
6060
std::shared_ptr<Contents> input) const {
6161
input = WithColorFilter(input, ColorFilterContents::AbsorbOpacity::kYes);
6262
input = WithInvertFilter(input);
63-
auto image_filter = WithImageFilter(input, Matrix(), /*is_subpass=*/false);
63+
auto image_filter =
64+
WithImageFilter(input, Matrix(), Entity::RenderingMode::kDirect);
6465
if (image_filter) {
6566
input = image_filter;
6667
}
@@ -71,7 +72,7 @@ std::shared_ptr<Contents> Paint::WithFiltersForSubpassTarget(
7172
std::shared_ptr<Contents> input,
7273
const Matrix& effect_transform) const {
7374
auto image_filter =
74-
WithImageFilter(input, effect_transform, /*is_subpass=*/true);
75+
WithImageFilter(input, effect_transform, Entity::RenderingMode::kSubpass);
7576
if (image_filter) {
7677
input = image_filter;
7778
}
@@ -91,12 +92,12 @@ std::shared_ptr<Contents> Paint::WithMaskBlur(std::shared_ptr<Contents> input,
9192
std::shared_ptr<FilterContents> Paint::WithImageFilter(
9293
const FilterInput::Variant& input,
9394
const Matrix& effect_transform,
94-
bool is_subpass) const {
95+
Entity::RenderingMode rendering_mode) const {
9596
if (!image_filter) {
9697
return nullptr;
9798
}
9899
auto filter = image_filter->WrapInput(FilterInput::Make(input));
99-
filter->SetIsForSubpass(is_subpass);
100+
filter->SetRenderingMode(rendering_mode);
100101
filter->SetEffectTransform(effect_transform);
101102
return filter;
102103
}

impeller/aiks/paint.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct Paint {
2626
using ImageFilterProc = std::function<std::shared_ptr<FilterContents>(
2727
FilterInput::Ref,
2828
const Matrix& effect_transform,
29-
bool is_subpass)>;
29+
Entity::RenderingMode rendering_mode)>;
3030
using MaskFilterProc = std::function<std::shared_ptr<FilterContents>(
3131
FilterInput::Ref,
3232
bool is_solid_color,
@@ -101,7 +101,7 @@ struct Paint {
101101
std::shared_ptr<FilterContents> WithImageFilter(
102102
const FilterInput::Variant& input,
103103
const Matrix& effect_transform,
104-
bool is_subpass) const;
104+
Entity::RenderingMode rendering_mode) const;
105105

106106
private:
107107
std::shared_ptr<Contents> WithColorFilter(

impeller/aiks/paint_pass_delegate.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ std::shared_ptr<Contents> PaintPassDelegate::CreateContentsForSubpassTarget(
5151
std::shared_ptr<FilterContents> PaintPassDelegate::WithImageFilter(
5252
const FilterInput::Variant& input,
5353
const Matrix& effect_transform) const {
54-
return paint_.WithImageFilter(input, effect_transform, true);
54+
return paint_.WithImageFilter(input, effect_transform,
55+
Entity::RenderingMode::kSubpass);
5556
}
5657

5758
/// OpacityPeepholePassDelegate
@@ -151,7 +152,8 @@ OpacityPeepholePassDelegate::CreateContentsForSubpassTarget(
151152
std::shared_ptr<FilterContents> OpacityPeepholePassDelegate::WithImageFilter(
152153
const FilterInput::Variant& input,
153154
const Matrix& effect_transform) const {
154-
return paint_.WithImageFilter(input, effect_transform, true);
155+
return paint_.WithImageFilter(input, effect_transform,
156+
Entity::RenderingMode::kSubpass);
155157
}
156158

157159
} // namespace impeller

impeller/entity/contents/filters/filter_contents.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,9 @@ void FilterContents::SetLeafInputs(const FilterInput::Vector& inputs) {
298298
}
299299
}
300300

301-
void FilterContents::SetIsForSubpass(bool is_subpass) {
301+
void FilterContents::SetRenderingMode(Entity::RenderingMode rendering_mode) {
302302
for (auto& input : inputs_) {
303-
input->SetIsForSubpass(is_subpass);
303+
input->SetRenderingMode(rendering_mode);
304304
}
305305
}
306306

impeller/entity/contents/filters/filter_contents.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class FilterContents : public Contents {
157157
/// that the current transformation matrix of the entity is not stored
158158
/// in the Entity transformation matrix. Instead, the effect transform
159159
/// is used in this case.
160-
virtual void SetIsForSubpass(bool is_subpass);
160+
virtual void SetRenderingMode(Entity::RenderingMode rendering_mode);
161161

162162
private:
163163
virtual std::optional<Rect> GetFilterCoverage(

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ void FilterContentsFilterInput::SetEffectTransform(const Matrix& matrix) {
7575
filter_->SetEffectTransform(matrix);
7676
}
7777

78-
void FilterContentsFilterInput::SetIsForSubpass(bool is_for_subpass) {
79-
filter_->SetIsForSubpass(is_for_subpass);
78+
void FilterContentsFilterInput::SetRenderingMode(
79+
Entity::RenderingMode rendering_mode) {
80+
filter_->SetRenderingMode(rendering_mode);
8081
}
8182

8283
} // namespace impeller

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class FilterContentsFilterInput final : public FilterInput {
4949
virtual void SetEffectTransform(const Matrix& matrix) override;
5050

5151
// |FilterInput|
52-
virtual void SetIsForSubpass(bool is_for_subpass) override;
52+
virtual void SetRenderingMode(Entity::RenderingMode rendering_mode) override;
5353

5454
private:
5555
explicit FilterContentsFilterInput(std::shared_ptr<FilterContents> filter);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,6 @@ void FilterInput::SetLeafInputs(const FilterInput::Vector& inputs) {}
8888

8989
void FilterInput::SetEffectTransform(const Matrix& matrix) {}
9090

91-
void FilterInput::SetIsForSubpass(bool is_for_subpass) {}
91+
void FilterInput::SetRenderingMode(Entity::RenderingMode rendering_mode) {}
9292

9393
} // namespace impeller

impeller/entity/contents/filters/inputs/filter_input.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class FilterInput {
8585
virtual void SetEffectTransform(const Matrix& matrix);
8686

8787
/// @brief Turns on subpass mode for filter inputs.
88-
virtual void SetIsForSubpass(bool is_for_subpass);
88+
virtual void SetRenderingMode(Entity::RenderingMode rendering_mode);
8989
};
9090

9191
} // namespace impeller

impeller/entity/contents/filters/matrix_filter_contents.cc

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ void MatrixFilterContents::SetMatrix(Matrix matrix) {
1414
matrix_ = matrix;
1515
}
1616

17-
void MatrixFilterContents::SetIsForSubpass(bool is_subpass) {
18-
is_for_subpass_ = is_subpass;
19-
FilterContents::SetIsForSubpass(is_subpass);
17+
void MatrixFilterContents::SetRenderingMode(
18+
Entity::RenderingMode rendering_mode) {
19+
rendering_mode_ = rendering_mode;
20+
FilterContents::SetRenderingMode(rendering_mode);
2021
}
2122

2223
bool MatrixFilterContents::IsTranslationOnly() const {
@@ -54,8 +55,9 @@ std::optional<Entity> MatrixFilterContents::RenderFilter(
5455
// mentioned above). And so we sneak the subpass's captured CTM in through the
5556
// effect transform.
5657

57-
auto transform =
58-
is_for_subpass_ ? effect_transform : entity.GetTransformation();
58+
auto transform = rendering_mode_ == Entity::RenderingMode::kSubpass
59+
? effect_transform
60+
: entity.GetTransformation();
5961
snapshot->transform = transform * //
6062
matrix_ * //
6163
transform.Invert() * //
@@ -78,8 +80,9 @@ std::optional<Rect> MatrixFilterContents::GetFilterCoverage(
7880
if (!coverage.has_value()) {
7981
return std::nullopt;
8082
}
81-
auto& m =
82-
is_for_subpass_ ? effect_transform : inputs[0]->GetTransform(entity);
83+
auto& m = rendering_mode_ == Entity::RenderingMode::kSubpass
84+
? effect_transform
85+
: inputs[0]->GetTransform(entity);
8386
auto transform = m * //
8487
matrix_ * //
8588
m.Invert(); //

impeller/entity/contents/filters/matrix_filter_contents.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class MatrixFilterContents final : public FilterContents {
1818
void SetMatrix(Matrix matrix);
1919

2020
// |FilterContents|
21-
void SetIsForSubpass(bool is_for_subpass) override;
21+
void SetRenderingMode(Entity::RenderingMode rendering_mode) override;
2222

2323
// |FilterContents|
2424
bool IsTranslationOnly() const override;
@@ -43,7 +43,7 @@ class MatrixFilterContents final : public FilterContents {
4343

4444
Matrix matrix_;
4545
SamplerDescriptor sampler_descriptor_ = {};
46-
bool is_for_subpass_ = false;
46+
Entity::RenderingMode rendering_mode_ = Entity::RenderingMode::kDirect;
4747

4848
FML_DISALLOW_COPY_AND_ASSIGN(MatrixFilterContents);
4949
};

impeller/entity/entity.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ class Entity {
2323
static constexpr BlendMode kLastPipelineBlendMode = BlendMode::kModulate;
2424
static constexpr BlendMode kLastAdvancedBlendMode = BlendMode::kLuminosity;
2525

26+
enum class RenderingMode {
27+
/// In direct mode, the Entity's transform is used as the current
28+
/// local-to-screen transformation matrix.
29+
kDirect,
30+
/// In subpass mode, the Entity passed through the filter is in screen space
31+
/// rather than local space, and so some filters (namely,
32+
/// MatrixFilterContents) need to interpret the given EffectTransform as the
33+
/// current transformation matrix.
34+
kSubpass,
35+
};
36+
2637
/// An enum to define how to repeat, fold, or omit colors outside of the
2738
/// typically defined range of the source of the colors (such as the
2839
/// bounds of an image or the defining geometry of a gradient).

impeller/entity/entity_pass.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,9 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
530530
auto texture = pass_context.GetTexture();
531531
// Render the backdrop texture before any of the pass elements.
532532
const auto& proc = subpass->backdrop_filter_proc_;
533-
subpass_backdrop_filter_contents = proc(
534-
FilterInput::Make(std::move(texture)), subpass->xformation_.Basis(),
535-
/*is_subpass*/ true);
533+
subpass_backdrop_filter_contents =
534+
proc(FilterInput::Make(std::move(texture)),
535+
subpass->xformation_.Basis(), Entity::RenderingMode::kSubpass);
536536

537537
// The subpass will need to read from the current pass texture when
538538
// rendering the backdrop, so if there's an active pass, end it prior to

impeller/entity/entity_pass.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class EntityPass {
4141
using BackdropFilterProc = std::function<std::shared_ptr<FilterContents>(
4242
FilterInput::Ref,
4343
const Matrix& effect_transform,
44-
bool is_subpass)>;
44+
Entity::RenderingMode rendering_mode)>;
4545

4646
struct StencilCoverageLayer {
4747
std::optional<Rect> coverage;

0 commit comments

Comments
 (0)