Mutators Stack refactoring (flutter/engine#9663)
Rename methods in the MutatorsStack to Pascal case to match standard cpp style Refactor the operator== for Mutator class
This commit is contained in:
@@ -10,37 +10,37 @@ bool ExternalViewEmbedder::SubmitFrame(GrContext* context) {
|
||||
return false;
|
||||
};
|
||||
|
||||
void MutatorsStack::pushClipRect(const SkRect& rect) {
|
||||
void MutatorsStack::PushClipRect(const SkRect& rect) {
|
||||
std::shared_ptr<Mutator> element = std::make_shared<Mutator>(rect);
|
||||
vector_.push_back(element);
|
||||
};
|
||||
|
||||
void MutatorsStack::pushClipRRect(const SkRRect& rrect) {
|
||||
void MutatorsStack::PushClipRRect(const SkRRect& rrect) {
|
||||
std::shared_ptr<Mutator> element = std::make_shared<Mutator>(rrect);
|
||||
vector_.push_back(element);
|
||||
};
|
||||
|
||||
void MutatorsStack::pushClipPath(const SkPath& path) {
|
||||
void MutatorsStack::PushClipPath(const SkPath& path) {
|
||||
std::shared_ptr<Mutator> element = std::make_shared<Mutator>(path);
|
||||
vector_.push_back(element);
|
||||
};
|
||||
|
||||
void MutatorsStack::pushTransform(const SkMatrix& matrix) {
|
||||
void MutatorsStack::PushTransform(const SkMatrix& matrix) {
|
||||
std::shared_ptr<Mutator> element = std::make_shared<Mutator>(matrix);
|
||||
vector_.push_back(element);
|
||||
};
|
||||
|
||||
void MutatorsStack::pop() {
|
||||
void MutatorsStack::Pop() {
|
||||
vector_.pop_back();
|
||||
};
|
||||
|
||||
const std::vector<std::shared_ptr<Mutator>>::const_reverse_iterator
|
||||
MutatorsStack::top() const {
|
||||
MutatorsStack::Top() const {
|
||||
return vector_.rend();
|
||||
};
|
||||
|
||||
const std::vector<std::shared_ptr<Mutator>>::const_reverse_iterator
|
||||
MutatorsStack::bottom() const {
|
||||
MutatorsStack::Bottom() const {
|
||||
return vector_.rbegin();
|
||||
};
|
||||
|
||||
|
||||
@@ -54,27 +54,25 @@ class Mutator {
|
||||
explicit Mutator(const SkMatrix& matrix)
|
||||
: type_(transform), matrix_(matrix) {}
|
||||
|
||||
const MutatorType& type() const { return type_; }
|
||||
const SkRect& rect() const { return rect_; }
|
||||
const SkRRect& rrect() const { return rrect_; }
|
||||
const SkPath& path() const { return *path_; }
|
||||
const SkMatrix& matrix() const { return matrix_; }
|
||||
const MutatorType& GetType() const { return type_; }
|
||||
const SkRect& GetRect() const { return rect_; }
|
||||
const SkRRect& GetRRect() const { return rrect_; }
|
||||
const SkPath& GetPath() const { return *path_; }
|
||||
const SkMatrix& GetMatrix() const { return matrix_; }
|
||||
|
||||
bool operator==(const Mutator& other) const {
|
||||
if (type_ != other.type_) {
|
||||
return false;
|
||||
}
|
||||
if (type_ == clip_rect && rect_ == other.rect_) {
|
||||
return true;
|
||||
}
|
||||
if (type_ == clip_rrect && rrect_ == other.rrect_) {
|
||||
return true;
|
||||
}
|
||||
if (type_ == clip_path && *path_ == *other.path_) {
|
||||
return true;
|
||||
}
|
||||
if (type_ == transform && matrix_ == other.matrix_) {
|
||||
return true;
|
||||
switch (type_) {
|
||||
case clip_rect:
|
||||
return rect_ == other.rect_;
|
||||
case clip_rrect:
|
||||
return rrect_ == other.rrect_;
|
||||
case clip_path:
|
||||
return *path_ == *other.path_;
|
||||
case transform:
|
||||
return matrix_ == other.matrix_;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -82,7 +80,7 @@ class Mutator {
|
||||
|
||||
bool operator!=(const Mutator& other) const { return !operator==(other); }
|
||||
|
||||
bool isClipType() {
|
||||
bool IsClipType() {
|
||||
return type_ == clip_rect || type_ == clip_rrect || type_ == clip_path;
|
||||
}
|
||||
|
||||
@@ -117,20 +115,20 @@ class MutatorsStack {
|
||||
public:
|
||||
MutatorsStack() = default;
|
||||
|
||||
void pushClipRect(const SkRect& rect);
|
||||
void pushClipRRect(const SkRRect& rrect);
|
||||
void pushClipPath(const SkPath& path);
|
||||
void pushTransform(const SkMatrix& matrix);
|
||||
void PushClipRect(const SkRect& rect);
|
||||
void PushClipRRect(const SkRRect& rrect);
|
||||
void PushClipPath(const SkPath& path);
|
||||
void PushTransform(const SkMatrix& matrix);
|
||||
|
||||
// Removes the `Mutator` on the top of the stack
|
||||
// and destroys it.
|
||||
void pop();
|
||||
void Pop();
|
||||
|
||||
// Returns an iterator pointing to the top of the stack.
|
||||
const std::vector<std::shared_ptr<Mutator>>::const_reverse_iterator top()
|
||||
const std::vector<std::shared_ptr<Mutator>>::const_reverse_iterator Top()
|
||||
const;
|
||||
// Returns an iterator pointing to the bottom of the stack.
|
||||
const std::vector<std::shared_ptr<Mutator>>::const_reverse_iterator bottom()
|
||||
const std::vector<std::shared_ptr<Mutator>>::const_reverse_iterator Bottom()
|
||||
const;
|
||||
|
||||
bool operator==(const MutatorsStack& other) const {
|
||||
|
||||
@@ -23,14 +23,14 @@ void ClipPathLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
|
||||
SkRect previous_cull_rect = context->cull_rect;
|
||||
SkRect clip_path_bounds = clip_path_.getBounds();
|
||||
if (context->cull_rect.intersect(clip_path_bounds)) {
|
||||
context->mutators_stack.pushClipPath(clip_path_);
|
||||
context->mutators_stack.PushClipPath(clip_path_);
|
||||
SkRect child_paint_bounds = SkRect::MakeEmpty();
|
||||
PrerollChildren(context, matrix, &child_paint_bounds);
|
||||
|
||||
if (child_paint_bounds.intersect(clip_path_bounds)) {
|
||||
set_paint_bounds(child_paint_bounds);
|
||||
}
|
||||
context->mutators_stack.pop();
|
||||
context->mutators_stack.Pop();
|
||||
}
|
||||
context->cull_rect = previous_cull_rect;
|
||||
}
|
||||
|
||||
@@ -16,14 +16,14 @@ ClipRectLayer::~ClipRectLayer() = default;
|
||||
void ClipRectLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
|
||||
SkRect previous_cull_rect = context->cull_rect;
|
||||
if (context->cull_rect.intersect(clip_rect_)) {
|
||||
context->mutators_stack.pushClipRect(clip_rect_);
|
||||
context->mutators_stack.PushClipRect(clip_rect_);
|
||||
SkRect child_paint_bounds = SkRect::MakeEmpty();
|
||||
PrerollChildren(context, matrix, &child_paint_bounds);
|
||||
|
||||
if (child_paint_bounds.intersect(clip_rect_)) {
|
||||
set_paint_bounds(child_paint_bounds);
|
||||
}
|
||||
context->mutators_stack.pop();
|
||||
context->mutators_stack.Pop();
|
||||
}
|
||||
context->cull_rect = previous_cull_rect;
|
||||
}
|
||||
|
||||
@@ -17,14 +17,14 @@ void ClipRRectLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
|
||||
SkRect previous_cull_rect = context->cull_rect;
|
||||
SkRect clip_rrect_bounds = clip_rrect_.getBounds();
|
||||
if (context->cull_rect.intersect(clip_rrect_bounds)) {
|
||||
context->mutators_stack.pushClipRRect(clip_rrect_);
|
||||
context->mutators_stack.PushClipRRect(clip_rrect_);
|
||||
SkRect child_paint_bounds = SkRect::MakeEmpty();
|
||||
PrerollChildren(context, matrix, &child_paint_bounds);
|
||||
|
||||
if (child_paint_bounds.intersect(clip_rrect_bounds)) {
|
||||
set_paint_bounds(child_paint_bounds);
|
||||
}
|
||||
context->mutators_stack.pop();
|
||||
context->mutators_stack.Pop();
|
||||
}
|
||||
context->cull_rect = previous_cull_rect;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ TransformLayer::~TransformLayer() = default;
|
||||
void TransformLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
|
||||
SkMatrix child_matrix;
|
||||
child_matrix.setConcat(matrix, transform_);
|
||||
context->mutators_stack.pushTransform(transform_);
|
||||
context->mutators_stack.PushTransform(transform_);
|
||||
SkRect previous_cull_rect = context->cull_rect;
|
||||
SkMatrix inverse_transform_;
|
||||
// Perspective projections don't produce rectangles that are useful for
|
||||
@@ -47,7 +47,7 @@ void TransformLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) {
|
||||
set_paint_bounds(child_paint_bounds);
|
||||
|
||||
context->cull_rect = previous_cull_rect;
|
||||
context->mutators_stack.pop();
|
||||
context->mutators_stack.Pop();
|
||||
}
|
||||
|
||||
#if defined(OS_FUCHSIA)
|
||||
|
||||
@@ -17,8 +17,8 @@ TEST(MutatorsStack, CopyConstructor) {
|
||||
MutatorsStack stack;
|
||||
auto rrect = SkRRect::MakeEmpty();
|
||||
auto rect = SkRect::MakeEmpty();
|
||||
stack.pushClipRect(rect);
|
||||
stack.pushClipRRect(rrect);
|
||||
stack.PushClipRect(rect);
|
||||
stack.PushClipRRect(rrect);
|
||||
MutatorsStack copy = MutatorsStack(stack);
|
||||
ASSERT_TRUE(copy == stack);
|
||||
}
|
||||
@@ -26,74 +26,74 @@ TEST(MutatorsStack, CopyConstructor) {
|
||||
TEST(MutatorsStack, PushClipRect) {
|
||||
MutatorsStack stack;
|
||||
auto rect = SkRect::MakeEmpty();
|
||||
stack.pushClipRect(rect);
|
||||
auto iter = stack.bottom();
|
||||
ASSERT_TRUE(iter->get()->type() == MutatorType::clip_rect);
|
||||
ASSERT_TRUE(iter->get()->rect() == rect);
|
||||
stack.PushClipRect(rect);
|
||||
auto iter = stack.Bottom();
|
||||
ASSERT_TRUE(iter->get()->GetType() == MutatorType::clip_rect);
|
||||
ASSERT_TRUE(iter->get()->GetRect() == rect);
|
||||
}
|
||||
|
||||
TEST(MutatorsStack, PushClipRRect) {
|
||||
MutatorsStack stack;
|
||||
auto rrect = SkRRect::MakeEmpty();
|
||||
stack.pushClipRRect(rrect);
|
||||
auto iter = stack.bottom();
|
||||
ASSERT_TRUE(iter->get()->type() == MutatorType::clip_rrect);
|
||||
ASSERT_TRUE(iter->get()->rrect() == rrect);
|
||||
stack.PushClipRRect(rrect);
|
||||
auto iter = stack.Bottom();
|
||||
ASSERT_TRUE(iter->get()->GetType() == MutatorType::clip_rrect);
|
||||
ASSERT_TRUE(iter->get()->GetRRect() == rrect);
|
||||
}
|
||||
|
||||
TEST(MutatorsStack, PushClipPath) {
|
||||
flutter::MutatorsStack stack;
|
||||
SkPath path;
|
||||
stack.pushClipPath(path);
|
||||
auto iter = stack.bottom();
|
||||
ASSERT_TRUE(iter->get()->type() == flutter::MutatorType::clip_path);
|
||||
ASSERT_TRUE(iter->get()->path() == path);
|
||||
stack.PushClipPath(path);
|
||||
auto iter = stack.Bottom();
|
||||
ASSERT_TRUE(iter->get()->GetType() == flutter::MutatorType::clip_path);
|
||||
ASSERT_TRUE(iter->get()->GetPath() == path);
|
||||
}
|
||||
|
||||
TEST(MutatorsStack, PushTransform) {
|
||||
MutatorsStack stack;
|
||||
SkMatrix matrix;
|
||||
matrix.setIdentity();
|
||||
stack.pushTransform(matrix);
|
||||
auto iter = stack.bottom();
|
||||
ASSERT_TRUE(iter->get()->type() == MutatorType::transform);
|
||||
ASSERT_TRUE(iter->get()->matrix() == matrix);
|
||||
stack.PushTransform(matrix);
|
||||
auto iter = stack.Bottom();
|
||||
ASSERT_TRUE(iter->get()->GetType() == MutatorType::transform);
|
||||
ASSERT_TRUE(iter->get()->GetMatrix() == matrix);
|
||||
}
|
||||
|
||||
TEST(MutatorsStack, Pop) {
|
||||
MutatorsStack stack;
|
||||
SkMatrix matrix;
|
||||
matrix.setIdentity();
|
||||
stack.pushTransform(matrix);
|
||||
stack.pop();
|
||||
auto iter = stack.bottom();
|
||||
ASSERT_TRUE(iter == stack.top());
|
||||
stack.PushTransform(matrix);
|
||||
stack.Pop();
|
||||
auto iter = stack.Bottom();
|
||||
ASSERT_TRUE(iter == stack.Top());
|
||||
}
|
||||
|
||||
TEST(MutatorsStack, Traversal) {
|
||||
MutatorsStack stack;
|
||||
SkMatrix matrix;
|
||||
matrix.setIdentity();
|
||||
stack.pushTransform(matrix);
|
||||
stack.PushTransform(matrix);
|
||||
auto rect = SkRect::MakeEmpty();
|
||||
stack.pushClipRect(rect);
|
||||
stack.PushClipRect(rect);
|
||||
auto rrect = SkRRect::MakeEmpty();
|
||||
stack.pushClipRRect(rrect);
|
||||
auto iter = stack.bottom();
|
||||
stack.PushClipRRect(rrect);
|
||||
auto iter = stack.Bottom();
|
||||
int index = 0;
|
||||
while (iter != stack.top()) {
|
||||
while (iter != stack.Top()) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
ASSERT_TRUE(iter->get()->type() == MutatorType::clip_rrect);
|
||||
ASSERT_TRUE(iter->get()->rrect() == rrect);
|
||||
ASSERT_TRUE(iter->get()->GetType() == MutatorType::clip_rrect);
|
||||
ASSERT_TRUE(iter->get()->GetRRect() == rrect);
|
||||
break;
|
||||
case 1:
|
||||
ASSERT_TRUE(iter->get()->type() == MutatorType::clip_rect);
|
||||
ASSERT_TRUE(iter->get()->rect() == rect);
|
||||
ASSERT_TRUE(iter->get()->GetType() == MutatorType::clip_rect);
|
||||
ASSERT_TRUE(iter->get()->GetRect() == rect);
|
||||
break;
|
||||
case 2:
|
||||
ASSERT_TRUE(iter->get()->type() == MutatorType::transform);
|
||||
ASSERT_TRUE(iter->get()->matrix() == matrix);
|
||||
ASSERT_TRUE(iter->get()->GetType() == MutatorType::transform);
|
||||
ASSERT_TRUE(iter->get()->GetMatrix() == matrix);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -106,23 +106,23 @@ TEST(MutatorsStack, Traversal) {
|
||||
TEST(MutatorsStack, Equality) {
|
||||
MutatorsStack stack;
|
||||
SkMatrix matrix = SkMatrix::MakeScale(1, 1);
|
||||
stack.pushTransform(matrix);
|
||||
stack.PushTransform(matrix);
|
||||
SkRect rect = SkRect::MakeEmpty();
|
||||
stack.pushClipRect(rect);
|
||||
stack.PushClipRect(rect);
|
||||
SkRRect rrect = SkRRect::MakeEmpty();
|
||||
stack.pushClipRRect(rrect);
|
||||
stack.PushClipRRect(rrect);
|
||||
SkPath path;
|
||||
stack.pushClipPath(path);
|
||||
stack.PushClipPath(path);
|
||||
|
||||
MutatorsStack stackOther;
|
||||
SkMatrix matrixOther = SkMatrix::MakeScale(1, 1);
|
||||
stackOther.pushTransform(matrixOther);
|
||||
stackOther.PushTransform(matrixOther);
|
||||
SkRect rectOther = SkRect::MakeEmpty();
|
||||
stackOther.pushClipRect(rectOther);
|
||||
stackOther.PushClipRect(rectOther);
|
||||
SkRRect rrectOther = SkRRect::MakeEmpty();
|
||||
stackOther.pushClipRRect(rrectOther);
|
||||
stackOther.PushClipRRect(rrectOther);
|
||||
SkPath otherPath;
|
||||
stackOther.pushClipPath(otherPath);
|
||||
stackOther.PushClipPath(otherPath);
|
||||
|
||||
ASSERT_TRUE(stack == stackOther);
|
||||
}
|
||||
@@ -130,24 +130,24 @@ TEST(MutatorsStack, Equality) {
|
||||
TEST(Mutator, Initialization) {
|
||||
SkRect rect = SkRect::MakeEmpty();
|
||||
Mutator mutator = Mutator(rect);
|
||||
ASSERT_TRUE(mutator.type() == MutatorType::clip_rect);
|
||||
ASSERT_TRUE(mutator.rect() == rect);
|
||||
ASSERT_TRUE(mutator.GetType() == MutatorType::clip_rect);
|
||||
ASSERT_TRUE(mutator.GetRect() == rect);
|
||||
|
||||
SkRRect rrect = SkRRect::MakeEmpty();
|
||||
Mutator mutator2 = Mutator(rrect);
|
||||
ASSERT_TRUE(mutator2.type() == MutatorType::clip_rrect);
|
||||
ASSERT_TRUE(mutator2.rrect() == rrect);
|
||||
ASSERT_TRUE(mutator2.GetType() == MutatorType::clip_rrect);
|
||||
ASSERT_TRUE(mutator2.GetRRect() == rrect);
|
||||
|
||||
SkPath path;
|
||||
Mutator mutator3 = Mutator(path);
|
||||
ASSERT_TRUE(mutator3.type() == MutatorType::clip_path);
|
||||
ASSERT_TRUE(mutator3.path() == path);
|
||||
ASSERT_TRUE(mutator3.GetType() == MutatorType::clip_path);
|
||||
ASSERT_TRUE(mutator3.GetPath() == path);
|
||||
|
||||
SkMatrix matrix;
|
||||
matrix.setIdentity();
|
||||
Mutator mutator4 = Mutator(matrix);
|
||||
ASSERT_TRUE(mutator4.type() == MutatorType::transform);
|
||||
ASSERT_TRUE(mutator4.matrix() == matrix);
|
||||
ASSERT_TRUE(mutator4.GetType() == MutatorType::transform);
|
||||
ASSERT_TRUE(mutator4.GetMatrix() == matrix);
|
||||
}
|
||||
|
||||
TEST(Mutator, CopyConstructor) {
|
||||
|
||||
@@ -205,10 +205,10 @@ std::vector<SkCanvas*> FlutterPlatformViewsController::GetCurrentCanvases() {
|
||||
}
|
||||
|
||||
int FlutterPlatformViewsController::CountClips(const MutatorsStack& mutators_stack) {
|
||||
std::vector<std::shared_ptr<Mutator>>::const_reverse_iterator iter = mutators_stack.bottom();
|
||||
std::vector<std::shared_ptr<Mutator>>::const_reverse_iterator iter = mutators_stack.Bottom();
|
||||
int clipCount = 0;
|
||||
while (iter != mutators_stack.top()) {
|
||||
if ((*iter)->isClipType()) {
|
||||
while (iter != mutators_stack.Top()) {
|
||||
if ((*iter)->IsClipType()) {
|
||||
clipCount++;
|
||||
}
|
||||
++iter;
|
||||
@@ -256,11 +256,11 @@ void FlutterPlatformViewsController::ApplyMutators(const MutatorsStack& mutators
|
||||
head.clipsToBounds = YES;
|
||||
ResetAnchor(head.layer);
|
||||
|
||||
std::vector<std::shared_ptr<Mutator>>::const_reverse_iterator iter = mutators_stack.bottom();
|
||||
while (iter != mutators_stack.top()) {
|
||||
switch ((*iter)->type()) {
|
||||
std::vector<std::shared_ptr<Mutator>>::const_reverse_iterator iter = mutators_stack.Bottom();
|
||||
while (iter != mutators_stack.Top()) {
|
||||
switch ((*iter)->GetType()) {
|
||||
case transform: {
|
||||
CATransform3D transform = GetCATransform3DFromSkMatrix((*iter)->matrix());
|
||||
CATransform3D transform = GetCATransform3DFromSkMatrix((*iter)->GetMatrix());
|
||||
head.layer.transform = CATransform3DConcat(head.layer.transform, transform);
|
||||
break;
|
||||
}
|
||||
@@ -269,10 +269,10 @@ void FlutterPlatformViewsController::ApplyMutators(const MutatorsStack& mutators
|
||||
case clip_path: {
|
||||
ChildClippingView* clipView = (ChildClippingView*)head.superview;
|
||||
clipView.layer.transform = CATransform3DIdentity;
|
||||
[clipView setClip:(*iter)->type()
|
||||
rect:(*iter)->rect()
|
||||
rrect:(*iter)->rrect()
|
||||
path:(*iter)->path()];
|
||||
[clipView setClip:(*iter)->GetType()
|
||||
rect:(*iter)->GetRect()
|
||||
rrect:(*iter)->GetRRect()
|
||||
path:(*iter)->GetPath()];
|
||||
head.clipsToBounds = YES;
|
||||
ResetAnchor(clipView.layer);
|
||||
head = clipView;
|
||||
|
||||
Reference in New Issue
Block a user