Skip to content

Commit bbd1997

Browse files
author
Chris Yang
authored
Make the filter_ in mutator shared_ptr (flutter#34944)
1 parent ca4d66a commit bbd1997

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

flow/embedded_views.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ void MutatorsStack::PushOpacity(const int& alpha) {
3636
vector_.push_back(element);
3737
};
3838

39-
void MutatorsStack::PushBackdropFilter(const DlImageFilter& filter) {
39+
void MutatorsStack::PushBackdropFilter(
40+
std::shared_ptr<const DlImageFilter> filter) {
4041
std::shared_ptr<Mutator> element = std::make_shared<Mutator>(filter);
4142
vector_.push_back(element);
4243
};

flow/embedded_views.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ class Mutator {
7070
explicit Mutator(const SkMatrix& matrix)
7171
: type_(kTransform), matrix_(matrix) {}
7272
explicit Mutator(const int& alpha) : type_(kOpacity), alpha_(alpha) {}
73-
explicit Mutator(const DlImageFilter& filter)
74-
: type_(kBackdropFilter), filter_(&filter) {}
73+
explicit Mutator(std::shared_ptr<const DlImageFilter> filter)
74+
: type_(kBackdropFilter), filter_(filter) {}
7575

7676
const MutatorType& GetType() const { return type_; }
7777
const SkRect& GetRect() const { return rect_; }
@@ -119,15 +119,18 @@ class Mutator {
119119
private:
120120
MutatorType type_;
121121

122+
// TODO(cyanglaz): Remove union.
123+
// https://github.com/flutter/flutter/issues/108470
122124
union {
123125
SkRect rect_;
124126
SkRRect rrect_;
125127
SkMatrix matrix_;
126128
SkPath* path_;
127129
int alpha_;
128-
const DlImageFilter* filter_;
129130
};
130131

132+
std::shared_ptr<const DlImageFilter> filter_;
133+
131134
}; // Mutator
132135

133136
// A stack of mutators that can be applied to an embedded platform view.
@@ -148,7 +151,7 @@ class MutatorsStack {
148151
void PushClipPath(const SkPath& path);
149152
void PushTransform(const SkMatrix& matrix);
150153
void PushOpacity(const int& alpha);
151-
void PushBackdropFilter(const DlImageFilter& filter);
154+
void PushBackdropFilter(std::shared_ptr<const DlImageFilter> filter);
152155

153156
// Removes the `Mutator` on the top of the stack
154157
// and destroys it.

flow/mutators_stack_unittests.cc

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,21 @@ TEST(MutatorsStack, PushOpacity) {
9191

9292
TEST(MutatorsStack, PushBackdropFilter) {
9393
MutatorsStack stack;
94-
auto filter = DlBlurImageFilter(5, 5, DlTileMode::kClamp);
95-
stack.PushBackdropFilter(filter);
96-
auto iter = stack.Bottom();
97-
ASSERT_TRUE(iter->get()->GetType() == MutatorType::kBackdropFilter);
98-
ASSERT_TRUE(iter->get()->GetFilter() == filter);
94+
const int num_of_mutators = 10;
95+
for (int i = 0; i < num_of_mutators; i++) {
96+
auto filter = std::make_shared<DlBlurImageFilter>(i, 5, DlTileMode::kClamp);
97+
stack.PushBackdropFilter(filter);
98+
}
99+
100+
auto iter = stack.Begin();
101+
int i = 0;
102+
while (iter != stack.End()) {
103+
ASSERT_EQ(iter->get()->GetType(), MutatorType::kBackdropFilter);
104+
ASSERT_EQ(iter->get()->GetFilter().asBlur()->sigma_x(), i);
105+
++iter;
106+
++i;
107+
}
108+
ASSERT_EQ(i, num_of_mutators);
99109
}
100110

101111
TEST(MutatorsStack, Pop) {

0 commit comments

Comments
 (0)