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
Show all changes
28 commits
Select commit Hold shift + click to select a range
afbb37a
Testing Preroll/Paint
JTKryptic Jun 16, 2022
5103d9d
Pushed opacity to platform view stack / Background Filter Proto 1
JTKryptic Jun 17, 2022
825fbc8
Create Backdrop Filter Mutator
JTKryptic Jun 23, 2022
4b5c705
Merge branch 'diff' into backdrop_filter_testing
JTKryptic Jun 23, 2022
24c077f
Removed Logs
JTKryptic Jun 23, 2022
e1a817d
Tests for PushFilter
JTKryptic Jun 27, 2022
d06155c
Backdrop Filter Mutator
JTKryptic Jun 27, 2022
452a0b7
Merge branch 'diff' into backdrop_filter_testing
JTKryptic Jun 27, 2022
6b74e7d
Formatting
JTKryptic Jun 27, 2022
455b87f
Merge branch 'backdrop_filter_testing'
JTKryptic Jun 27, 2022
bc1d19b
Format files
JTKryptic Jun 28, 2022
4c0f2a5
Merge branch 'main' into backdrop_filter_testing
JTKryptic Jun 28, 2022
55d328c
Delete backdrop_filter_diff
JTKryptic Jun 28, 2022
d080e8e
Code cleanup
JTKryptic Jun 29, 2022
93accab
Updating to DlImageFilter and code cleanup
JTKryptic Jun 29, 2022
a9cd101
Formatting
JTKryptic Jun 29, 2022
abc3a0e
bug fix
JTKryptic Jun 29, 2022
7ad4a02
Backdrop filter mutator
JTKryptic Jun 30, 2022
5d9657a
Update backdrop_filter_layer.cc
JTKryptic Jun 30, 2022
a741bb9
fix
JTKryptic Jul 7, 2022
5712cdb
Backdrop filter test fix
JTKryptic Jul 8, 2022
097740e
formatting
JTKryptic Jul 8, 2022
e0466c2
Switch type filter to pointer
JTKryptic Jul 8, 2022
2525dde
Enum style guide fix
JTKryptic Jul 13, 2022
2e1731c
Update embedded_views.h
JTKryptic Jul 13, 2022
964c43a
enum style guide fix 2
JTKryptic Jul 13, 2022
c6ef165
Merge remote-tracking branch 'origin/diff' into diff
JTKryptic Jul 13, 2022
e8fd78f
Merge remote-tracking branch 'origin/diff' into diff
JTKryptic Jul 13, 2022
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
5 changes: 5 additions & 0 deletions flow/embedded_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ void MutatorsStack::PushOpacity(const int& alpha) {
vector_.push_back(element);
};

void MutatorsStack::PushBackdropFilter(const DlImageFilter& filter) {
std::shared_ptr<Mutator> element = std::make_shared<Mutator>(filter);
vector_.push_back(element);
};

void MutatorsStack::Pop() {
vector_.pop_back();
};
Expand Down
60 changes: 38 additions & 22 deletions flow/embedded_views.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,53 +20,65 @@

namespace flutter {

// TODO(chinmaygarde): Make these enum names match the style guide.
enum MutatorType { clip_rect, clip_rrect, clip_path, transform, opacity };
enum MutatorType {
kClipRect,
kClipRRect,
kClipPath,
kTransform,
kOpacity,
kBackdropFilter
};

// Stores mutation information like clipping or transform.
// Stores mutation information like clipping or kTransform.
//
// The `type` indicates the type of the mutation: clip_rect, transform and etc.
// The `type` indicates the type of the mutation: kClipRect, kTransform 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
// if the `type` is kClipRect, `rect()` is used the represent the rect to be
// clipped. One mutation object must only contain one type of mutation.
class Mutator {
public:
Mutator(const Mutator& other) {
type_ = other.type_;
switch (other.type_) {
case clip_rect:
case kClipRect:
rect_ = other.rect_;
break;
case clip_rrect:
case kClipRRect:
rrect_ = other.rrect_;
break;
case clip_path:
case kClipPath:
path_ = new SkPath(*other.path_);
break;
case transform:
case kTransform:
matrix_ = other.matrix_;
break;
case opacity:
case kOpacity:
alpha_ = other.alpha_;
break;
case kBackdropFilter:
filter_ = other.filter_;
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 SkRect& rect) : type_(kClipRect), rect_(rect) {}
explicit Mutator(const SkRRect& rrect) : type_(kClipRRect), rrect_(rrect) {}
explicit Mutator(const SkPath& path)
: type_(clip_path), path_(new SkPath(path)) {}
: type_(kClipPath), path_(new SkPath(path)) {}
explicit Mutator(const SkMatrix& matrix)
: type_(transform), matrix_(matrix) {}
explicit Mutator(const int& alpha) : type_(opacity), alpha_(alpha) {}
: type_(kTransform), matrix_(matrix) {}
explicit Mutator(const int& alpha) : type_(kOpacity), alpha_(alpha) {}
explicit Mutator(const DlImageFilter& filter)
: type_(kBackdropFilter), filter_(&filter) {}

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_; }
const DlImageFilter& GetFilter() const { return *filter_; }
const int& GetAlpha() const { return alpha_; }
float GetAlphaFloat() const { return (alpha_ / 255.0); }

Expand All @@ -75,16 +87,18 @@ class Mutator {
return false;
}
switch (type_) {
case clip_rect:
case kClipRect:
return rect_ == other.rect_;
case clip_rrect:
case kClipRRect:
return rrect_ == other.rrect_;
case clip_path:
case kClipPath:
return *path_ == *other.path_;
case transform:
case kTransform:
return matrix_ == other.matrix_;
case opacity:
case kOpacity:
return alpha_ == other.alpha_;
case kBackdropFilter:
return *filter_ == *other.filter_;
}

return false;
Expand All @@ -93,11 +107,11 @@ class Mutator {
bool operator!=(const Mutator& other) const { return !operator==(other); }

bool IsClipType() {
return type_ == clip_rect || type_ == clip_rrect || type_ == clip_path;
return type_ == kClipRect || type_ == kClipRRect || type_ == kClipPath;
}

~Mutator() {
if (type_ == clip_path) {
if (type_ == kClipPath) {
delete path_;
}
};
Expand All @@ -111,6 +125,7 @@ class Mutator {
SkMatrix matrix_;
SkPath* path_;
int alpha_;
const DlImageFilter* filter_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be stored as std::shared_ptr. The lifecycle is probably not going to fail with the current architecture, but we should be safe.

Also the SkPath object is supposed to be fast-copy in that it shares the underlying storage and marks the origin object as copy-on-write. Given that our paths never change, we could probably store an SkPath rather than a pointer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I will make that change for the next PR. Thanks!

};

}; // Mutator
Expand All @@ -133,6 +148,7 @@ class MutatorsStack {
void PushClipPath(const SkPath& path);
void PushTransform(const SkMatrix& matrix);
void PushOpacity(const int& alpha);
void PushBackdropFilter(const DlImageFilter& filter);

// Removes the `Mutator` on the top of the stack
// and destroys it.
Expand Down
39 changes: 24 additions & 15 deletions flow/mutators_stack_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ TEST(MutatorsStack, CopyAndUpdateTheCopy) {
ASSERT_TRUE(copy.is_empty());
ASSERT_TRUE(!stack.is_empty());
auto iter = stack.Bottom();
ASSERT_TRUE(iter->get()->GetType() == MutatorType::clip_rrect);
ASSERT_TRUE(iter->get()->GetType() == MutatorType::kClipRRect);
ASSERT_TRUE(iter->get()->GetRRect() == rrect);
++iter;
ASSERT_TRUE(iter->get()->GetType() == MutatorType::clip_rect);
ASSERT_TRUE(iter->get()->GetType() == MutatorType::kClipRect);
ASSERT_TRUE(iter->get()->GetRect() == rect);
}

Expand All @@ -48,7 +48,7 @@ TEST(MutatorsStack, PushClipRect) {
auto rect = SkRect::MakeEmpty();
stack.PushClipRect(rect);
auto iter = stack.Bottom();
ASSERT_TRUE(iter->get()->GetType() == MutatorType::clip_rect);
ASSERT_TRUE(iter->get()->GetType() == MutatorType::kClipRect);
ASSERT_TRUE(iter->get()->GetRect() == rect);
}

Expand All @@ -57,7 +57,7 @@ TEST(MutatorsStack, PushClipRRect) {
auto rrect = SkRRect::MakeEmpty();
stack.PushClipRRect(rrect);
auto iter = stack.Bottom();
ASSERT_TRUE(iter->get()->GetType() == MutatorType::clip_rrect);
ASSERT_TRUE(iter->get()->GetType() == MutatorType::kClipRRect);
ASSERT_TRUE(iter->get()->GetRRect() == rrect);
}

Expand All @@ -66,7 +66,7 @@ TEST(MutatorsStack, PushClipPath) {
SkPath path;
stack.PushClipPath(path);
auto iter = stack.Bottom();
ASSERT_TRUE(iter->get()->GetType() == flutter::MutatorType::clip_path);
ASSERT_TRUE(iter->get()->GetType() == flutter::MutatorType::kClipPath);
ASSERT_TRUE(iter->get()->GetPath() == path);
}

Expand All @@ -76,7 +76,7 @@ TEST(MutatorsStack, PushTransform) {
matrix.setIdentity();
stack.PushTransform(matrix);
auto iter = stack.Bottom();
ASSERT_TRUE(iter->get()->GetType() == MutatorType::transform);
ASSERT_TRUE(iter->get()->GetType() == MutatorType::kTransform);
ASSERT_TRUE(iter->get()->GetMatrix() == matrix);
}

Expand All @@ -85,10 +85,19 @@ TEST(MutatorsStack, PushOpacity) {
int alpha = 240;
stack.PushOpacity(alpha);
auto iter = stack.Bottom();
ASSERT_TRUE(iter->get()->GetType() == MutatorType::opacity);
ASSERT_TRUE(iter->get()->GetType() == MutatorType::kOpacity);
ASSERT_TRUE(iter->get()->GetAlpha() == 240);
}

TEST(MutatorsStack, PushBackdropFilter) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It couldn't hurt to add a test to confirm that the == method on the mutators works for all types, including if they are fed copies of the original data (i.e. they compare by content rather than reference).

MutatorsStack stack;
auto filter = DlBlurImageFilter(5, 5, DlTileMode::kClamp);
stack.PushBackdropFilter(filter);
auto iter = stack.Bottom();
ASSERT_TRUE(iter->get()->GetType() == MutatorType::kBackdropFilter);
ASSERT_TRUE(iter->get()->GetFilter() == filter);
}

TEST(MutatorsStack, Pop) {
MutatorsStack stack;
SkMatrix matrix;
Expand All @@ -113,15 +122,15 @@ TEST(MutatorsStack, Traversal) {
while (iter != stack.Top()) {
switch (index) {
case 0:
ASSERT_TRUE(iter->get()->GetType() == MutatorType::clip_rrect);
ASSERT_TRUE(iter->get()->GetType() == MutatorType::kClipRRect);
ASSERT_TRUE(iter->get()->GetRRect() == rrect);
break;
case 1:
ASSERT_TRUE(iter->get()->GetType() == MutatorType::clip_rect);
ASSERT_TRUE(iter->get()->GetType() == MutatorType::kClipRect);
ASSERT_TRUE(iter->get()->GetRect() == rect);
break;
case 2:
ASSERT_TRUE(iter->get()->GetType() == MutatorType::transform);
ASSERT_TRUE(iter->get()->GetType() == MutatorType::kTransform);
ASSERT_TRUE(iter->get()->GetMatrix() == matrix);
break;
default:
Expand Down Expand Up @@ -163,28 +172,28 @@ TEST(MutatorsStack, Equality) {
TEST(Mutator, Initialization) {
SkRect rect = SkRect::MakeEmpty();
Mutator mutator = Mutator(rect);
ASSERT_TRUE(mutator.GetType() == MutatorType::clip_rect);
ASSERT_TRUE(mutator.GetType() == MutatorType::kClipRect);
ASSERT_TRUE(mutator.GetRect() == rect);

SkRRect rrect = SkRRect::MakeEmpty();
Mutator mutator2 = Mutator(rrect);
ASSERT_TRUE(mutator2.GetType() == MutatorType::clip_rrect);
ASSERT_TRUE(mutator2.GetType() == MutatorType::kClipRRect);
ASSERT_TRUE(mutator2.GetRRect() == rrect);

SkPath path;
Mutator mutator3 = Mutator(path);
ASSERT_TRUE(mutator3.GetType() == MutatorType::clip_path);
ASSERT_TRUE(mutator3.GetType() == MutatorType::kClipPath);
ASSERT_TRUE(mutator3.GetPath() == path);

SkMatrix matrix;
matrix.setIdentity();
Mutator mutator4 = Mutator(matrix);
ASSERT_TRUE(mutator4.GetType() == MutatorType::transform);
ASSERT_TRUE(mutator4.GetType() == MutatorType::kTransform);
ASSERT_TRUE(mutator4.GetMatrix() == matrix);

int alpha = 240;
Mutator mutator5 = Mutator(alpha);
ASSERT_TRUE(mutator5.GetType() == MutatorType::opacity);
ASSERT_TRUE(mutator5.GetType() == MutatorType::kOpacity);
}

TEST(Mutator, CopyConstructor) {
Expand Down
11 changes: 6 additions & 5 deletions shell/platform/android/platform_view_android_jni_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@ void PlatformViewAndroidJNIImpl::FlutterViewOnDisplayPlatformView(
mutators_stack.Begin();
while (iter != mutators_stack.End()) {
switch ((*iter)->GetType()) {
case transform: {
case kTransform: {
const SkMatrix& matrix = (*iter)->GetMatrix();
SkScalar matrix_array[9];
matrix.get9(matrix_array);
Expand All @@ -1425,15 +1425,15 @@ void PlatformViewAndroidJNIImpl::FlutterViewOnDisplayPlatformView(
transformMatrix.obj());
break;
}
case clip_rect: {
case kClipRect: {
const SkRect& rect = (*iter)->GetRect();
env->CallVoidMethod(
mutatorsStack, g_mutators_stack_push_cliprect_method,
static_cast<int>(rect.left()), static_cast<int>(rect.top()),
static_cast<int>(rect.right()), static_cast<int>(rect.bottom()));
break;
}
case clip_rrect: {
case kClipRRect: {
const SkRRect& rrect = (*iter)->GetRRect();
const SkRect& rect = rrect.rect();
const SkVector& upper_left = rrect.radii(SkRRect::kUpperLeft_Corner);
Expand All @@ -1455,8 +1455,9 @@ void PlatformViewAndroidJNIImpl::FlutterViewOnDisplayPlatformView(
}
// TODO(cyanglaz): Implement other mutators.
// https://github.com/flutter/flutter/issues/58426
case clip_path:
case opacity:
case kClipPath:
case kOpacity:
case kBackdropFilter:
break;
}
++iter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,23 +405,25 @@ - (BOOL)flt_hasFirstResponderInViewHierarchySubtree {
auto iter = mutators_stack.Begin();
while (iter != mutators_stack.End()) {
switch ((*iter)->GetType()) {
case transform: {
case kTransform: {
CATransform3D transform = GetCATransform3DFromSkMatrix((*iter)->GetMatrix());
finalTransform = CATransform3DConcat(transform, finalTransform);
break;
}
case clip_rect:
case kClipRect:
[maskView clipRect:(*iter)->GetRect() matrix:finalTransform];
break;
case clip_rrect:
case kClipRRect:
[maskView clipRRect:(*iter)->GetRRect() matrix:finalTransform];
break;
case clip_path:
case kClipPath:
[maskView clipPath:(*iter)->GetPath() matrix:finalTransform];
break;
case opacity:
case kOpacity:
embedded_view.alpha = (*iter)->GetAlphaFloat() * embedded_view.alpha;
break;
case kBackdropFilter:
break;
}
++iter;
}
Expand Down
12 changes: 7 additions & 5 deletions shell/platform/embedder/embedder_layers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,30 +115,30 @@ void EmbedderLayers::PushPlatformViewLayer(
for (auto i = mutators.Bottom(); i != mutators.Top(); ++i) {
const auto& mutator = *i;
switch (mutator->GetType()) {
case MutatorType::clip_rect: {
case MutatorType::kClipRect: {
mutations_array.push_back(
mutations_referenced_
.emplace_back(ConvertMutation(mutator->GetRect()))
.get());
} break;
case MutatorType::clip_rrect: {
case MutatorType::kClipRRect: {
mutations_array.push_back(
mutations_referenced_
.emplace_back(ConvertMutation(mutator->GetRRect()))
.get());
} break;
case MutatorType::clip_path: {
case MutatorType::kClipPath: {
// Unsupported mutation.
} break;
case MutatorType::transform: {
case MutatorType::kTransform: {
const auto& matrix = mutator->GetMatrix();
if (!matrix.isIdentity()) {
mutations_array.push_back(
mutations_referenced_.emplace_back(ConvertMutation(matrix))
.get());
}
} break;
case MutatorType::opacity: {
case MutatorType::kOpacity: {
const double opacity =
std::clamp(mutator->GetAlphaFloat(), 0.0f, 1.0f);
if (opacity < 1.0) {
Expand All @@ -147,6 +147,8 @@ void EmbedderLayers::PushPlatformViewLayer(
.get());
}
} break;
case MutatorType::kBackdropFilter:
break;
}
}

Expand Down
Loading