Skip to content

Commit cea2c36

Browse files
author
Chris Yang
authored
Mutators Stack refactoring (flutter#9663)
Rename methods in the MutatorsStack to Pascal case to match standard cpp style Refactor the operator== for Mutator class
1 parent 6a8782f commit cea2c36

8 files changed

Lines changed: 97 additions & 99 deletions

File tree

‎flow/embedded_views.cc‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,37 @@ bool ExternalViewEmbedder::SubmitFrame(GrContext* context) {
1010
return false;
1111
};
1212

13-
void MutatorsStack::pushClipRect(const SkRect& rect) {
13+
void MutatorsStack::PushClipRect(const SkRect& rect) {
1414
std::shared_ptr<Mutator> element = std::make_shared<Mutator>(rect);
1515
vector_.push_back(element);
1616
};
1717

18-
void MutatorsStack::pushClipRRect(const SkRRect& rrect) {
18+
void MutatorsStack::PushClipRRect(const SkRRect& rrect) {
1919
std::shared_ptr<Mutator> element = std::make_shared<Mutator>(rrect);
2020
vector_.push_back(element);
2121
};
2222

23-
void MutatorsStack::pushClipPath(const SkPath& path) {
23+
void MutatorsStack::PushClipPath(const SkPath& path) {
2424
std::shared_ptr<Mutator> element = std::make_shared<Mutator>(path);
2525
vector_.push_back(element);
2626
};
2727

28-
void MutatorsStack::pushTransform(const SkMatrix& matrix) {
28+
void MutatorsStack::PushTransform(const SkMatrix& matrix) {
2929
std::shared_ptr<Mutator> element = std::make_shared<Mutator>(matrix);
3030
vector_.push_back(element);
3131
};
3232

33-
void MutatorsStack::pop() {
33+
void MutatorsStack::Pop() {
3434
vector_.pop_back();
3535
};
3636

3737
const std::vector<std::shared_ptr<Mutator>>::const_reverse_iterator
38-
MutatorsStack::top() const {
38+
MutatorsStack::Top() const {
3939
return vector_.rend();
4040
};
4141

4242
const std::vector<std::shared_ptr<Mutator>>::const_reverse_iterator
43-
MutatorsStack::bottom() const {
43+
MutatorsStack::Bottom() const {
4444
return vector_.rbegin();
4545
};
4646

‎flow/embedded_views.h‎

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,35 +54,33 @@ class Mutator {
5454
explicit Mutator(const SkMatrix& matrix)
5555
: type_(transform), matrix_(matrix) {}
5656

57-
const MutatorType& type() const { return type_; }
58-
const SkRect& rect() const { return rect_; }
59-
const SkRRect& rrect() const { return rrect_; }
60-
const SkPath& path() const { return *path_; }
61-
const SkMatrix& matrix() const { return matrix_; }
57+
const MutatorType& GetType() const { return type_; }
58+
const SkRect& GetRect() const { return rect_; }
59+
const SkRRect& GetRRect() const { return rrect_; }
60+
const SkPath& GetPath() const { return *path_; }
61+
const SkMatrix& GetMatrix() const { return matrix_; }
6262

6363
bool operator==(const Mutator& other) const {
6464
if (type_ != other.type_) {
6565
return false;
6666
}
67-
if (type_ == clip_rect && rect_ == other.rect_) {
68-
return true;
69-
}
70-
if (type_ == clip_rrect && rrect_ == other.rrect_) {
71-
return true;
72-
}
73-
if (type_ == clip_path && *path_ == *other.path_) {
74-
return true;
75-
}
76-
if (type_ == transform && matrix_ == other.matrix_) {
77-
return true;
67+
switch (type_) {
68+
case clip_rect:
69+
return rect_ == other.rect_;
70+
case clip_rrect:
71+
return rrect_ == other.rrect_;
72+
case clip_path:
73+
return *path_ == *other.path_;
74+
case transform:
75+
return matrix_ == other.matrix_;
7876
}
7977

8078
return false;
8179
}
8280

8381
bool operator!=(const Mutator& other) const { return !operator==(other); }
8482

85-
bool isClipType() {
83+
bool IsClipType() {
8684
return type_ == clip_rect || type_ == clip_rrect || type_ == clip_path;
8785
}
8886

@@ -117,20 +115,20 @@ class MutatorsStack {
117115
public:
118116
MutatorsStack() = default;
119117

120-
void pushClipRect(const SkRect& rect);
121-
void pushClipRRect(const SkRRect& rrect);
122-
void pushClipPath(const SkPath& path);
123-
void pushTransform(const SkMatrix& matrix);
118+
void PushClipRect(const SkRect& rect);
119+
void PushClipRRect(const SkRRect& rrect);
120+
void PushClipPath(const SkPath& path);
121+
void PushTransform(const SkMatrix& matrix);
124122

125123
// Removes the `Mutator` on the top of the stack
126124
// and destroys it.
127-
void pop();
125+
void Pop();
128126

129127
// Returns an iterator pointing to the top of the stack.
130-
const std::vector<std::shared_ptr<Mutator>>::const_reverse_iterator top()
128+
const std::vector<std::shared_ptr<Mutator>>::const_reverse_iterator Top()
131129
const;
132130
// Returns an iterator pointing to the bottom of the stack.
133-
const std::vector<std::shared_ptr<Mutator>>::const_reverse_iterator bottom()
131+
const std::vector<std::shared_ptr<Mutator>>::const_reverse_iterator Bottom()
134132
const;
135133

136134
bool operator==(const MutatorsStack& other) const {

‎flow/layers/clip_path_layer.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ void ClipPathLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
2323
SkRect previous_cull_rect = context->cull_rect;
2424
SkRect clip_path_bounds = clip_path_.getBounds();
2525
if (context->cull_rect.intersect(clip_path_bounds)) {
26-
context->mutators_stack.pushClipPath(clip_path_);
26+
context->mutators_stack.PushClipPath(clip_path_);
2727
SkRect child_paint_bounds = SkRect::MakeEmpty();
2828
PrerollChildren(context, matrix, &child_paint_bounds);
2929

3030
if (child_paint_bounds.intersect(clip_path_bounds)) {
3131
set_paint_bounds(child_paint_bounds);
3232
}
33-
context->mutators_stack.pop();
33+
context->mutators_stack.Pop();
3434
}
3535
context->cull_rect = previous_cull_rect;
3636
}

‎flow/layers/clip_rect_layer.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ ClipRectLayer::~ClipRectLayer() = default;
1616
void ClipRectLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
1717
SkRect previous_cull_rect = context->cull_rect;
1818
if (context->cull_rect.intersect(clip_rect_)) {
19-
context->mutators_stack.pushClipRect(clip_rect_);
19+
context->mutators_stack.PushClipRect(clip_rect_);
2020
SkRect child_paint_bounds = SkRect::MakeEmpty();
2121
PrerollChildren(context, matrix, &child_paint_bounds);
2222

2323
if (child_paint_bounds.intersect(clip_rect_)) {
2424
set_paint_bounds(child_paint_bounds);
2525
}
26-
context->mutators_stack.pop();
26+
context->mutators_stack.Pop();
2727
}
2828
context->cull_rect = previous_cull_rect;
2929
}

‎flow/layers/clip_rrect_layer.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ void ClipRRectLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
1717
SkRect previous_cull_rect = context->cull_rect;
1818
SkRect clip_rrect_bounds = clip_rrect_.getBounds();
1919
if (context->cull_rect.intersect(clip_rrect_bounds)) {
20-
context->mutators_stack.pushClipRRect(clip_rrect_);
20+
context->mutators_stack.PushClipRRect(clip_rrect_);
2121
SkRect child_paint_bounds = SkRect::MakeEmpty();
2222
PrerollChildren(context, matrix, &child_paint_bounds);
2323

2424
if (child_paint_bounds.intersect(clip_rrect_bounds)) {
2525
set_paint_bounds(child_paint_bounds);
2626
}
27-
context->mutators_stack.pop();
27+
context->mutators_stack.Pop();
2828
}
2929
context->cull_rect = previous_cull_rect;
3030
}

‎flow/layers/transform_layer.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ TransformLayer::~TransformLayer() = default;
2929
void TransformLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
3030
SkMatrix child_matrix;
3131
child_matrix.setConcat(matrix, transform_);
32-
context->mutators_stack.pushTransform(transform_);
32+
context->mutators_stack.PushTransform(transform_);
3333
SkRect previous_cull_rect = context->cull_rect;
3434
SkMatrix inverse_transform_;
3535
// Perspective projections don't produce rectangles that are useful for
@@ -47,7 +47,7 @@ void TransformLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
4747
set_paint_bounds(child_paint_bounds);
4848

4949
context->cull_rect = previous_cull_rect;
50-
context->mutators_stack.pop();
50+
context->mutators_stack.Pop();
5151
}
5252

5353
#if defined(OS_FUCHSIA)

‎flow/mutators_stack_unittests.cc‎

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,83 +17,83 @@ TEST(MutatorsStack, CopyConstructor) {
1717
MutatorsStack stack;
1818
auto rrect = SkRRect::MakeEmpty();
1919
auto rect = SkRect::MakeEmpty();
20-
stack.pushClipRect(rect);
21-
stack.pushClipRRect(rrect);
20+
stack.PushClipRect(rect);
21+
stack.PushClipRRect(rrect);
2222
MutatorsStack copy = MutatorsStack(stack);
2323
ASSERT_TRUE(copy == stack);
2424
}
2525

2626
TEST(MutatorsStack, PushClipRect) {
2727
MutatorsStack stack;
2828
auto rect = SkRect::MakeEmpty();
29-
stack.pushClipRect(rect);
30-
auto iter = stack.bottom();
31-
ASSERT_TRUE(iter->get()->type() == MutatorType::clip_rect);
32-
ASSERT_TRUE(iter->get()->rect() == rect);
29+
stack.PushClipRect(rect);
30+
auto iter = stack.Bottom();
31+
ASSERT_TRUE(iter->get()->GetType() == MutatorType::clip_rect);
32+
ASSERT_TRUE(iter->get()->GetRect() == rect);
3333
}
3434

3535
TEST(MutatorsStack, PushClipRRect) {
3636
MutatorsStack stack;
3737
auto rrect = SkRRect::MakeEmpty();
38-
stack.pushClipRRect(rrect);
39-
auto iter = stack.bottom();
40-
ASSERT_TRUE(iter->get()->type() == MutatorType::clip_rrect);
41-
ASSERT_TRUE(iter->get()->rrect() == rrect);
38+
stack.PushClipRRect(rrect);
39+
auto iter = stack.Bottom();
40+
ASSERT_TRUE(iter->get()->GetType() == MutatorType::clip_rrect);
41+
ASSERT_TRUE(iter->get()->GetRRect() == rrect);
4242
}
4343

4444
TEST(MutatorsStack, PushClipPath) {
4545
flutter::MutatorsStack stack;
4646
SkPath path;
47-
stack.pushClipPath(path);
48-
auto iter = stack.bottom();
49-
ASSERT_TRUE(iter->get()->type() == flutter::MutatorType::clip_path);
50-
ASSERT_TRUE(iter->get()->path() == path);
47+
stack.PushClipPath(path);
48+
auto iter = stack.Bottom();
49+
ASSERT_TRUE(iter->get()->GetType() == flutter::MutatorType::clip_path);
50+
ASSERT_TRUE(iter->get()->GetPath() == path);
5151
}
5252

5353
TEST(MutatorsStack, PushTransform) {
5454
MutatorsStack stack;
5555
SkMatrix matrix;
5656
matrix.setIdentity();
57-
stack.pushTransform(matrix);
58-
auto iter = stack.bottom();
59-
ASSERT_TRUE(iter->get()->type() == MutatorType::transform);
60-
ASSERT_TRUE(iter->get()->matrix() == matrix);
57+
stack.PushTransform(matrix);
58+
auto iter = stack.Bottom();
59+
ASSERT_TRUE(iter->get()->GetType() == MutatorType::transform);
60+
ASSERT_TRUE(iter->get()->GetMatrix() == matrix);
6161
}
6262

6363
TEST(MutatorsStack, Pop) {
6464
MutatorsStack stack;
6565
SkMatrix matrix;
6666
matrix.setIdentity();
67-
stack.pushTransform(matrix);
68-
stack.pop();
69-
auto iter = stack.bottom();
70-
ASSERT_TRUE(iter == stack.top());
67+
stack.PushTransform(matrix);
68+
stack.Pop();
69+
auto iter = stack.Bottom();
70+
ASSERT_TRUE(iter == stack.Top());
7171
}
7272

7373
TEST(MutatorsStack, Traversal) {
7474
MutatorsStack stack;
7575
SkMatrix matrix;
7676
matrix.setIdentity();
77-
stack.pushTransform(matrix);
77+
stack.PushTransform(matrix);
7878
auto rect = SkRect::MakeEmpty();
79-
stack.pushClipRect(rect);
79+
stack.PushClipRect(rect);
8080
auto rrect = SkRRect::MakeEmpty();
81-
stack.pushClipRRect(rrect);
82-
auto iter = stack.bottom();
81+
stack.PushClipRRect(rrect);
82+
auto iter = stack.Bottom();
8383
int index = 0;
84-
while (iter != stack.top()) {
84+
while (iter != stack.Top()) {
8585
switch (index) {
8686
case 0:
87-
ASSERT_TRUE(iter->get()->type() == MutatorType::clip_rrect);
88-
ASSERT_TRUE(iter->get()->rrect() == rrect);
87+
ASSERT_TRUE(iter->get()->GetType() == MutatorType::clip_rrect);
88+
ASSERT_TRUE(iter->get()->GetRRect() == rrect);
8989
break;
9090
case 1:
91-
ASSERT_TRUE(iter->get()->type() == MutatorType::clip_rect);
92-
ASSERT_TRUE(iter->get()->rect() == rect);
91+
ASSERT_TRUE(iter->get()->GetType() == MutatorType::clip_rect);
92+
ASSERT_TRUE(iter->get()->GetRect() == rect);
9393
break;
9494
case 2:
95-
ASSERT_TRUE(iter->get()->type() == MutatorType::transform);
96-
ASSERT_TRUE(iter->get()->matrix() == matrix);
95+
ASSERT_TRUE(iter->get()->GetType() == MutatorType::transform);
96+
ASSERT_TRUE(iter->get()->GetMatrix() == matrix);
9797
break;
9898
default:
9999
break;
@@ -106,48 +106,48 @@ TEST(MutatorsStack, Traversal) {
106106
TEST(MutatorsStack, Equality) {
107107
MutatorsStack stack;
108108
SkMatrix matrix = SkMatrix::MakeScale(1, 1);
109-
stack.pushTransform(matrix);
109+
stack.PushTransform(matrix);
110110
SkRect rect = SkRect::MakeEmpty();
111-
stack.pushClipRect(rect);
111+
stack.PushClipRect(rect);
112112
SkRRect rrect = SkRRect::MakeEmpty();
113-
stack.pushClipRRect(rrect);
113+
stack.PushClipRRect(rrect);
114114
SkPath path;
115-
stack.pushClipPath(path);
115+
stack.PushClipPath(path);
116116

117117
MutatorsStack stackOther;
118118
SkMatrix matrixOther = SkMatrix::MakeScale(1, 1);
119-
stackOther.pushTransform(matrixOther);
119+
stackOther.PushTransform(matrixOther);
120120
SkRect rectOther = SkRect::MakeEmpty();
121-
stackOther.pushClipRect(rectOther);
121+
stackOther.PushClipRect(rectOther);
122122
SkRRect rrectOther = SkRRect::MakeEmpty();
123-
stackOther.pushClipRRect(rrectOther);
123+
stackOther.PushClipRRect(rrectOther);
124124
SkPath otherPath;
125-
stackOther.pushClipPath(otherPath);
125+
stackOther.PushClipPath(otherPath);
126126

127127
ASSERT_TRUE(stack == stackOther);
128128
}
129129

130130
TEST(Mutator, Initialization) {
131131
SkRect rect = SkRect::MakeEmpty();
132132
Mutator mutator = Mutator(rect);
133-
ASSERT_TRUE(mutator.type() == MutatorType::clip_rect);
134-
ASSERT_TRUE(mutator.rect() == rect);
133+
ASSERT_TRUE(mutator.GetType() == MutatorType::clip_rect);
134+
ASSERT_TRUE(mutator.GetRect() == rect);
135135

136136
SkRRect rrect = SkRRect::MakeEmpty();
137137
Mutator mutator2 = Mutator(rrect);
138-
ASSERT_TRUE(mutator2.type() == MutatorType::clip_rrect);
139-
ASSERT_TRUE(mutator2.rrect() == rrect);
138+
ASSERT_TRUE(mutator2.GetType() == MutatorType::clip_rrect);
139+
ASSERT_TRUE(mutator2.GetRRect() == rrect);
140140

141141
SkPath path;
142142
Mutator mutator3 = Mutator(path);
143-
ASSERT_TRUE(mutator3.type() == MutatorType::clip_path);
144-
ASSERT_TRUE(mutator3.path() == path);
143+
ASSERT_TRUE(mutator3.GetType() == MutatorType::clip_path);
144+
ASSERT_TRUE(mutator3.GetPath() == path);
145145

146146
SkMatrix matrix;
147147
matrix.setIdentity();
148148
Mutator mutator4 = Mutator(matrix);
149-
ASSERT_TRUE(mutator4.type() == MutatorType::transform);
150-
ASSERT_TRUE(mutator4.matrix() == matrix);
149+
ASSERT_TRUE(mutator4.GetType() == MutatorType::transform);
150+
ASSERT_TRUE(mutator4.GetMatrix() == matrix);
151151
}
152152

153153
TEST(Mutator, CopyConstructor) {

0 commit comments

Comments
 (0)