-
Notifications
You must be signed in to change notification settings - Fork 6k
Create blanket backdrop filter mutator #34408
Changes from 23 commits
afbb37a
5103d9d
825fbc8
4b5c705
24c077f
e1a817d
d06155c
452a0b7
6b74e7d
455b87f
bc1d19b
4c0f2a5
55d328c
d080e8e
93accab
a9cd101
abc3a0e
7ad4a02
5d9657a
a741bb9
5712cdb
097740e
e0466c2
2525dde
2e1731c
964c43a
c6ef165
e8fd78f
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 |
|---|---|---|
|
|
@@ -21,7 +21,14 @@ | |
| namespace flutter { | ||
|
|
||
| // TODO(chinmaygarde): Make these enum names match the style guide. | ||
| enum MutatorType { clip_rect, clip_rrect, clip_path, transform, opacity }; | ||
| enum MutatorType { | ||
| clip_rect, | ||
| clip_rrect, | ||
| clip_path, | ||
| transform, | ||
| opacity, | ||
| backdrop_filter | ||
| }; | ||
|
|
||
| // Stores mutation information like clipping or transform. | ||
| // | ||
|
|
@@ -49,6 +56,9 @@ class Mutator { | |
| case opacity: | ||
| alpha_ = other.alpha_; | ||
| break; | ||
| case backdrop_filter: | ||
| filter_ = other.filter_; | ||
| break; | ||
| default: | ||
| break; | ||
| } | ||
|
|
@@ -61,12 +71,15 @@ class Mutator { | |
| explicit Mutator(const SkMatrix& matrix) | ||
| : type_(transform), matrix_(matrix) {} | ||
| explicit Mutator(const int& alpha) : type_(opacity), alpha_(alpha) {} | ||
| explicit Mutator(const DlImageFilter& filter) | ||
| : type_(backdrop_filter), 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); } | ||
|
|
||
|
|
@@ -85,6 +98,8 @@ class Mutator { | |
| return matrix_ == other.matrix_; | ||
| case opacity: | ||
| return alpha_ == other.alpha_; | ||
| case backdrop_filter: | ||
| return *filter_ == *other.filter_; | ||
|
dnfield marked this conversation as resolved.
|
||
| } | ||
|
|
||
| return false; | ||
|
|
@@ -111,6 +126,7 @@ class Mutator { | |
| SkMatrix matrix_; | ||
| SkPath* path_; | ||
| int alpha_; | ||
| const DlImageFilter* filter_; | ||
|
Contributor
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. 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.
Contributor
Author
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. Sounds good, I will make that change for the next PR. Thanks! |
||
| }; | ||
|
|
||
| }; // Mutator | ||
|
|
@@ -133,6 +149,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. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,6 +89,15 @@ TEST(MutatorsStack, PushOpacity) { | |
| ASSERT_TRUE(iter->get()->GetAlpha() == 240); | ||
| } | ||
|
|
||
| TEST(MutatorsStack, PushBackdropFilter) { | ||
|
Contributor
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. 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::backdrop_filter); | ||
| ASSERT_TRUE(iter->get()->GetFilter() == filter); | ||
| } | ||
|
|
||
| TEST(MutatorsStack, Pop) { | ||
| MutatorsStack stack; | ||
| SkMatrix matrix; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.