-
Notifications
You must be signed in to change notification settings - Fork 6k
Make the filter_ in mutator shared_ptr #34944
Make the filter_ in mutator shared_ptr #34944
Conversation
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.
Just a couple of nits about unnecessary calls to shared() in places that don't need them. You should only have to call "shared()" when you initially accept the DlImageFilter& reference into the system and after that just keep sharing/transferring/using the same shared_ptr.
flow/embedded_views.h
Outdated
@@ -56,7 +56,7 @@ class Mutator { | |||
alpha_ = other.alpha_; | |||
break; | |||
case kBackdropFilter: | |||
filter_ = other.filter_; | |||
filter_ = other.filter_->shared(); |
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.
For the copy constructor you can just copy the shared_ptr without having to recreate it with the shared() method.
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.
What do you mean by copy the shared_ptr?
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.
filter_ = other.filter_
Why do you call shared() there? You already have a shared_ptr.
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.
Does filter_ = other.filter_
deep copy the raw pointer inside the shared_ptr? The idea of this copy constructor is that the filters are different objects, changing the value of the original filter will not affect the value of the copied filter.
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.
No deep copy. It points to a new filter. It no longer points to the old filter.
@@ -119,15 +119,18 @@ class Mutator { | |||
private: | |||
MutatorType type_; | |||
|
|||
// TODO(cyanglaz): Remove union. | |||
// https://github.com/flutter/flutter/issues/108470 |
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.
Is the SkPath object guaranteed to survive the lifecycle of the mutator? It might be safer to copy the SkPath using a copy constructor since the SkPath copy constructor is documented to be very fast and copy-safe.
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.
https://api.skia.org/classSkPath.html#aa30a9363d49c092958d48e30608df367
The SkPath object is 16 bytes I think so the object takes up similar room to SkRect and much less than SkRRect or SkMatrix.
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.
Is the SkPath object guaranteed to survive the lifecycle of the mutator? It might be safer to copy the SkPath using a copy constructor since the SkPath copy constructor is documented to be very fast and copy-safe.
Yeah storing a copy of SkPath is fine with me, but I think shared_ptr for all the them is probably more consistent and fast/light weight too.
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.
SkPath is kind of its own shared_ptr for all of the data that matters...
flow/embedded_views.h
Outdated
@@ -98,7 +98,7 @@ class Mutator { | |||
case kOpacity: | |||
return alpha_ == other.alpha_; | |||
case kBackdropFilter: | |||
return *filter_ == *other.filter_; | |||
return *filter_ == *other.filter_->shared(); |
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.
No need to call shared here as far as I can tell...?
Updated per review comments. @flar PTAL |
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.
LGTM, you might want to run it by @chinmaygarde or @jason-simmons as some of the places you copy the shared_ptr might benefit from an "std::move" which will avoid unnecessary inc/decreffing.
The same filters are also used to filter none-PlatformView contents so I don't think std::move would be safe. Using std::move will make the code to be dependent on making sure the none-PlatformView part is done with the filter before passing the filter to the stack. |
It doesn't move the original. The call to your method already did one incref, a move macro just avoids a second incref/decref pair by "moving" your copy to the field. You hand off your ref to the field rather than create a new ref for the field and then drop your ref separately. It's a very minor optimization if this code isn't used that often. |
Storing raw filter_ pointers of DlImageFilter in union caused some issue where all the pointers are pointing to the same address in the stack.
This PR moves the filter_ object out of union so we can simply making the filter_ a shared_ptr.
This is to unblock flutter/flutter#43902
The real fix for Mutators should be: flutter/flutter#108470
Pre-launch Checklist
writing and running engine tests.
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.