-
Notifications
You must be signed in to change notification settings - Fork 6k
[skwasm] Implement platform view clipping. #54201
[skwasm] Implement platform view clipping. #54201
Conversation
|
Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change). If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review. |
| } | ||
|
|
||
| @override | ||
| ScenePath get asPath => ui.Path() as ScenePath; |
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.
Maybe throw instead? I see you already have a few if (PlatformViewNoClip) do nothing. If this code is reached, maybe it's a bug?
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 guess it doesn't really matter, but this seems like a more consistent and sane behavior to me than throwing. Sure, the surrounding code never calls this, but that happens to be an implementation detail of the surrounding code and not a contract of this class itself.
|
|
||
| @override | ||
| bool operator ==(Object other) { | ||
| if (identical(this, other) || (other.runtimeType == runtimeType)) { |
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.
It's a sealed class hierarchy, so I think it can be other.runtimeType == PlatformViewNoClip.
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.
PS: Also shocked to learn that the language doesn't do identical check automatically. It would be so much cheaper to do it before calling the polymorphic operator ==.
| } | ||
|
|
||
| @override | ||
| int get hashCode => runtimeType.hashCode; |
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.
same here: could be PlatformViewNoClip.hashCode, maybe even just 42 :)
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 think I actually tried this, but PlatformViewNoClip.hashCode doesn't actually work because the language will attempt to call a static method called hashCode which doesn't exist. I also feel like hashing the runtime type is better than assigning an arbitrary value, because some other equally cute person might return 42 for their class which is also a singleton type, and if they end up in a very generic (i.e. <Object>) hashed collection together they will have a hash collision. Is this class likely to be put in a hashed collection with other random singleton classes? No. In practice it isn't even put in a hashed collection at all, but the language wants me to implement this if I implement operator==, so this is all theoretical and probably will never matter anyway.
|
|
||
| bool covers(ui.Rect rect); | ||
|
|
||
| ScenePath get asPath; |
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: the as prefix usually implies a view over another object. However, this returns a new path, i.e. it's a conversion to a path. For that we usually use the to prefix, i.e. toPath.
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.
Good point. I'll change it.
|
|
||
| @override | ||
| bool covers(ui.Rect other) { | ||
| return rect.left <= other.left && |
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.
Can you please leave a comment for the future Yegor, who is going to come here feeling all clever and replace it with rect.contains(other) and cause a bug because this logic is inclusive on all sides, but Rect.contains is exclusive at right and bottom?
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.
Actually I think we should use rect.contains. I'm not sure why I didn't just use it here.
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.
Ah, the reason I didn't use it is because rect.contains(ui.Rect) doesn't exist. rect.contains takes a single offset.
| } | ||
|
|
||
| abstract class ScenePath implements ui.Path { | ||
| // In order to properly clip platform views with paths, we need to be able to get an |
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: s/an/a/
| DomElement get container; | ||
|
|
||
| void updateContents(); | ||
| void dispose(); |
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.
A doc comment explaining who is responsible for calling this method would be helpful.
| final double top = clip.rect.top / devicePixelRatio; | ||
| final double right = clip.rect.right / devicePixelRatio; | ||
| final double bottom = clip.rect.bottom / devicePixelRatio; | ||
| final double left = clip.rect.left / devicePixelRatio; |
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: it's ok to omit types in new code (or maybe even drive-by remove unnecessary types in existing code).
| } | ||
| } | ||
|
|
||
| class SVGClipRegistry { |
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.
Do we still need the SVG registry? According to MDN Safari implemented clip-path: path(...) in 13:
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.
Omg seriously? Ugh, I can't believe I spent all this effort writing this class and implementing disposal methods and stuff, haha. I'll remove this and simplify.
| switch (clip) { | ||
| case PlatformViewNoClip(): | ||
| clipPath = null; | ||
| return ''; |
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.
The function could instead return null, and the place that applies the clip could avoid setting the property to an empty string unnecessarily.
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.
The container can be reused when the styling changes, so we actually do need to set the property to an empty string if the clipping goes away.
| case PlatformViewPathClip(): | ||
| clipPath = clip.path; | ||
| return 'url(#$_clipPathId)'; | ||
| print('$_clipPathString'); |
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.
Debug print leftover?
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.
Whoops I'll remove it
|
Is there an associated issue w/ this? |
|
auto label is removed for flutter/engine/54201, due to - The status or check suite Linux local_engine_builds has failed. Please fix the issues identified (or deflake) before re-applying this label. |
I'll add it to the description |
…152718) flutter/engine@1cbe88e...ab3f177 2024-08-01 [email protected] Roll Fuchsia Linux SDK from uF76DfQgigt4utdBv... to vpJQheqicAUK_qjD-... (flutter/engine#54295) 2024-08-01 [email protected] [skwasm] Implement platform view clipping. (flutter/engine#54201) 2024-08-01 [email protected] Roll Skia from ddb6901e6141 to 5c229d4d20bb (3 revisions) (flutter/engine#54288) 2024-08-01 [email protected] Use `InetAddress.getLoopback()` versus a string. (flutter/engine#54289) Also rolling transitive DEPS: fuchsia/sdk/core/linux-amd64 from uF76DfQgigt4 to vpJQheqicAUK If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…lutter#152718) flutter/engine@1cbe88e...ab3f177 2024-08-01 [email protected] Roll Fuchsia Linux SDK from uF76DfQgigt4utdBv... to vpJQheqicAUK_qjD-... (flutter/engine#54295) 2024-08-01 [email protected] [skwasm] Implement platform view clipping. (flutter/engine#54201) 2024-08-01 [email protected] Roll Skia from ddb6901e6141 to 5c229d4d20bb (3 revisions) (flutter/engine#54288) 2024-08-01 [email protected] Use `InetAddress.getLoopback()` versus a string. (flutter/engine#54289) Also rolling transitive DEPS: fuchsia/sdk/core/linux-amd64 from uF76DfQgigt4 to vpJQheqicAUK If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…lutter#152718) flutter/engine@1cbe88e...ab3f177 2024-08-01 [email protected] Roll Fuchsia Linux SDK from uF76DfQgigt4utdBv... to vpJQheqicAUK_qjD-... (flutter/engine#54295) 2024-08-01 [email protected] [skwasm] Implement platform view clipping. (flutter/engine#54201) 2024-08-01 [email protected] Roll Skia from ddb6901e6141 to 5c229d4d20bb (3 revisions) (flutter/engine#54288) 2024-08-01 [email protected] Use `InetAddress.getLoopback()` versus a string. (flutter/engine#54289) Also rolling transitive DEPS: fuchsia/sdk/core/linux-amd64 from uF76DfQgigt4 to vpJQheqicAUK If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
This implements platform view clipping for the Skwasm renderer.
This fixes flutter/flutter#133466