Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@eyebrowsoffire
Copy link
Contributor

@eyebrowsoffire eyebrowsoffire commented Jul 30, 2024

This implements platform view clipping for the Skwasm renderer.

This fixes flutter/flutter#133466

@github-actions github-actions bot added the platform-web Code specifically for the web engine label Jul 30, 2024
@flutter-dashboard
Copy link

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.

Changes reported for pull request #54201 at sha 24b99c0

}

@override
ScenePath get asPath => ui.Path() as ScenePath;
Copy link
Contributor

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?

Copy link
Contributor Author

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)) {
Copy link
Contributor

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.

Copy link
Contributor

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;
Copy link
Contributor

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 :)

Copy link
Contributor Author

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;
Copy link
Contributor

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.

Copy link
Contributor Author

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 &&
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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
Copy link
Contributor

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();
Copy link
Contributor

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;
Copy link
Contributor

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 {
Copy link
Contributor

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:

https://developer.mozilla.org/en-US/docs/Web/CSS/clip-path

Copy link
Contributor Author

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 '';
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@eyebrowsoffire eyebrowsoffire requested a review from yjbanov August 1, 2024 20:07
case PlatformViewPathClip():
clipPath = clip.path;
return 'url(#$_clipPathId)';
print('$_clipPathString');
Copy link
Contributor

Choose a reason for hiding this comment

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

Debug print leftover?

Copy link
Contributor Author

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

@eyebrowsoffire eyebrowsoffire added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 1, 2024
@kevmoo
Copy link
Contributor

kevmoo commented Aug 1, 2024

Is there an associated issue w/ this?

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 1, 2024
@auto-submit
Copy link
Contributor

auto-submit bot commented Aug 1, 2024

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.

@eyebrowsoffire
Copy link
Contributor Author

Is there an associated issue w/ this?

Yes. flutter/flutter#133466

I'll add it to the description

@eyebrowsoffire eyebrowsoffire added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 1, 2024
@auto-submit auto-submit bot merged commit 6648b3c into flutter:main Aug 1, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 1, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 1, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Aug 2, 2024
…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
TytaniumDev pushed a commit to TytaniumDev/flutter that referenced this pull request Aug 7, 2024
…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
Buchimi pushed a commit to Buchimi/flutter that referenced this pull request Sep 2, 2024
…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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

autosubmit Merge PR when tree becomes green via auto submit App platform-web Code specifically for the web engine will affect goldens

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement platform view clipping in Skwasm renderer

3 participants