-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IOS Platform view transform/clipping #9075
Changes from all commits
853cbd6
72042cf
8489c08
647e66b
f7d7aaa
c0741b2
6e95d26
a3e1d61
4cf9f8a
1daacb0
04d1f40
5b05eb2
9b290cb
52a8252
3a899fa
cabc67a
4496b21
4bdae98
33513b9
e8926a5
3f4c586
d4f88f2
4eeb64f
6d78901
e494853
81e5c19
ea11fad
2c79050
0f70a44
32d2681
b874420
a1794de
2f0125c
d22acbd
2b08642
1599067
a027fa0
12ff43a
a9a660f
f4b9503
7c0fa63
2eb40d6
6d4c82c
7d1d0e5
46098a4
fa1248a
dd0eed8
50843a0
31ec192
3b6b3b0
b4b59ca
ee57e42
979d251
b45ad9a
b40944e
701afe5
551445d
8622d13
d46290e
8f86532
a5b7f8a
b0d3110
ff442ee
5f0a513
455a495
cf36c46
fd498ee
78acc1f
aeb56e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,25 +9,178 @@ | |
|
||
#include "flutter/fml/memory/ref_counted.h" | ||
#include "third_party/skia/include/core/SkCanvas.h" | ||
#include "third_party/skia/include/core/SkPath.h" | ||
#include "third_party/skia/include/core/SkPoint.h" | ||
#include "third_party/skia/include/core/SkRRect.h" | ||
#include "third_party/skia/include/core/SkRect.h" | ||
#include "third_party/skia/include/core/SkSize.h" | ||
|
||
namespace flutter { | ||
|
||
enum MutatorType { clip_rect, clip_rrect, clip_path, transform }; | ||
|
||
// Stores mutation information like clipping or transform. | ||
// | ||
// The `type` indicates the type of the mutation: clip_rect, transform and etc. | ||
// Each `type` is paired with an object that supports the mutation. For example, | ||
// if the `type` is clip_rect, `rect()` is used the represent the rect to be | ||
// clipped. One mutation object must only contain one type of mutation. | ||
class Mutator { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. document There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
public: | ||
Mutator(const Mutator& other) { | ||
type_ = other.type_; | ||
switch (other.type_) { | ||
case clip_rect: | ||
rect_ = other.rect_; | ||
break; | ||
case clip_rrect: | ||
rrect_ = other.rrect_; | ||
break; | ||
case clip_path: | ||
path_ = new SkPath(*other.path_); | ||
break; | ||
case transform: | ||
matrix_ = other.matrix_; | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
explicit Mutator(const SkRect& rect) : type_(clip_rect), rect_(rect) {} | ||
explicit Mutator(const SkRRect& rrect) : type_(clip_rrect), rrect_(rrect) {} | ||
explicit Mutator(const SkPath& path) | ||
: type_(clip_path), path_(new SkPath(path)) {} | ||
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_; } | ||
|
||
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; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
bool operator!=(const Mutator& other) const { return !operator==(other); } | ||
|
||
bool isClipType() { | ||
return type_ == clip_rect || type_ == clip_rrect || type_ == clip_path; | ||
} | ||
|
||
~Mutator() { | ||
if (type_ == clip_path) { | ||
delete path_; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use a unique pointer instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. f2f discussion: unique_ptr still needs to provide a destructor if it is inside a union, so we keep using a raw pointer. |
||
} | ||
}; | ||
|
||
private: | ||
MutatorType type_; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: A union will save a few bytes here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
union { | ||
SkRect rect_; | ||
SkRRect rrect_; | ||
SkMatrix matrix_; | ||
SkPath* path_; | ||
}; | ||
|
||
}; // Mutator | ||
|
||
// A stack of mutators that can be applied to an embedded platform view. | ||
// | ||
// The stack may include mutators like transforms and clips, each mutator | ||
// applies to all the mutators that are below it in the stack and to the | ||
// embedded view. | ||
// | ||
// For example consider the following stack: [T1, T2, T3], where T1 is the top | ||
// of the stack and T3 is the bottom of the stack. Applying this mutators stack | ||
// to a platform view P1 will result in T1(T2(T2(P1))). | ||
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); | ||
|
||
// Removes the `Mutator` on the top of the stack | ||
// and destroys it. | ||
void pop(); | ||
|
||
// Returns an iterator pointing to the top of the stack. | ||
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; | ||
|
||
bool operator==(const MutatorsStack& other) const { | ||
if (vector_.size() != other.vector_.size()) { | ||
return false; | ||
} | ||
for (size_t i = 0; i < vector_.size(); i++) { | ||
if (*vector_[i] != *other.vector_[i]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
bool operator!=(const MutatorsStack& other) const { | ||
return !operator==(other); | ||
} | ||
|
||
private: | ||
std::vector<std::shared_ptr<Mutator>> vector_; | ||
}; // MutatorsStack | ||
|
||
class EmbeddedViewParams { | ||
public: | ||
EmbeddedViewParams() = default; | ||
|
||
EmbeddedViewParams(const EmbeddedViewParams& other) { | ||
offsetPixels = other.offsetPixels; | ||
sizePoints = other.sizePoints; | ||
mutatorsStack = other.mutatorsStack; | ||
}; | ||
|
||
SkPoint offsetPixels; | ||
SkSize sizePoints; | ||
MutatorsStack mutatorsStack; | ||
|
||
bool operator==(const EmbeddedViewParams& other) const { | ||
return offsetPixels == other.offsetPixels && sizePoints == other.sizePoints; | ||
return offsetPixels == other.offsetPixels && | ||
sizePoints == other.sizePoints && | ||
mutatorsStack == other.mutatorsStack; | ||
} | ||
}; | ||
|
||
// This is only used on iOS when running in a non headless mode, | ||
// in this case ExternalViewEmbedder is a reference to the | ||
// FlutterPlatformViewsController which is owned by FlutterViewController. | ||
class ExternalViewEmbedder { | ||
// TODO(cyanglaz): Make embedder own the `EmbeddedViewParams`. | ||
|
||
public: | ||
ExternalViewEmbedder() = default; | ||
|
||
|
@@ -46,7 +199,8 @@ class ExternalViewEmbedder { | |
virtual ~ExternalViewEmbedder() = default; | ||
|
||
FML_DISALLOW_COPY_AND_ASSIGN(ExternalViewEmbedder); | ||
}; | ||
|
||
}; // ExternalViewEmbedder | ||
|
||
} // namespace flutter | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,10 +47,13 @@ TEST(PerformanceOverlayLayer, Gold) { | |
ASSERT_TRUE(surface != nullptr); | ||
|
||
flutter::TextureRegistry unused_texture_registry; | ||
|
||
flutter::MutatorsStack unused_stack; | ||
flutter::Layer::PaintContext paintContext = { | ||
nullptr, surface->getCanvas(), nullptr, nullptr, mock_stopwatch, | ||
mock_stopwatch, unused_texture_registry, nullptr, false}; | ||
nullptr, surface->getCanvas(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. one per line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is auto formatted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😟 really that's what clang format is doing? |
||
nullptr, nullptr, | ||
unused_stack, mock_stopwatch, | ||
mock_stopwatch, unused_texture_registry, | ||
nullptr, false}; | ||
|
||
// Specify font file to ensure the same font across different operation | ||
// systems. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we can save some copies by making it a vector of unique pointers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried it naively and caused some issue when trying to copy the stack to the params, reverting the change and adding a TODO and will work on it in future.