Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions flow/embedded_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

Expand Down
46 changes: 22 additions & 24 deletions flow/embedded_views.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,35 +54,33 @@ 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;
}

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

bool isClipType() {
bool IsClipType() {
return type_ == clip_rect || type_ == clip_rrect || type_ == clip_path;
}

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions flow/layers/clip_path_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions flow/layers/clip_rect_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions flow/layers/clip_rrect_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions flow/layers/transform_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
98 changes: 49 additions & 49 deletions flow/mutators_stack_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,83 +17,83 @@ 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);
}

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;
Expand All @@ -106,48 +106,48 @@ 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);
}

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) {
Expand Down
Loading