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

[ios][platform_view] fix platform view clipping path intersection #54820

Conversation

hellohuanlin
Copy link
Contributor

@hellohuanlin hellohuanlin commented Aug 28, 2024

It turns out that when there are multiple paths to clip, they are unioned together, rather than intersected. But clipping paths need to be intersected.

There isn't any good way to intersect arbitrary paths. However, it is easy to intersect rect paths, which is the most common use case. Then we simply fallback to software rendering if we have to intersect non-rect paths. That is:

Case 1 Only 1 clipping path (either rect path or arbitrary path):
Hardware rendering. This should be the most common use case

Case 2 Multiple rect clipping path:
Hardware rendering. This is also common, and it's the linked issue that we are fixing.

Case 3 Other complex case (multiple non-rect clipping path)
Fallback to software rendering. This should be rare.

After #53826, we don't have a working benchmark that measures the main thread anymore. However, this PR shouldn't impact our ad benchmark, since it only has 1 clipping path. I will verify manually by checking Instruments and make sure no software rendering is happening. But we really should make the benchmark working again, not just for performance improvement, but also for monitoring regression.

List which issues are fixed by this PR. You must list at least one issue.

Fixes flutter/flutter#153904

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

working copy

also only 1 shape is fine
Copy link
Member

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

You could also create multiple CAShape layers instead

@hellohuanlin
Copy link
Contributor Author

hellohuanlin commented Aug 30, 2024

It's pretty hard to review the scenario tests, so I made a video.

The existing scenarios only clip a single path. So I added a "multi paths" version for each scenario, and made sure the resulting clip is the intersection of the paths (rather than the union).

golden.files.walk.through.mp4

@hellohuanlin
Copy link
Contributor Author

You could also create multiple CAShape layers instead

After some research, it seems the only possible way is to have nested parents, each taking one shape layer as the mask. I don't think it's possible to just have one single mask that is the intersection of multiple shape layers. So this will require much larger change, and make the already complex view hierarchy more complex.

@hellohuanlin
Copy link
Contributor Author

Verified the scrolling ad banner example still runs smoothly on device, and avoids software rendering related instructions (by looking at the Instruments).

@hellohuanlin
Copy link
Contributor Author

Verified the linked issue worked after this fix

Screenshot 2024-08-30 at 2 15 38 PM

@hellohuanlin hellohuanlin force-pushed the pv_clipping_path_intersect_rather_than_union branch from c75d430 to f075b4c Compare August 30, 2024 21:24
@hellohuanlin hellohuanlin requested a review from cbracken August 31, 2024 17:13
@hellohuanlin hellohuanlin marked this pull request as ready for review August 31, 2024 17:13
@nateshmbhat
Copy link

Eagerly waiting for this PR to be merged. Our video player ui broke after we upgraded to 3.24. 🙏🏻

@@ -358,14 +358,23 @@ final _skipTestsForImpeller = [
'ScenariosUITests/MultiplePlatformViewsTest/testPlatformView',
'ScenariosUITests/NonFullScreenFlutterViewPlatformViewUITests/testPlatformView',
'ScenariosUITests/PlatformViewMutationClipPathTests/testPlatformView',
'ScenariosUITests/PlatformViewMutationClipPathMultipleClipsTests/testPlatformView',
Copy link
Member

Choose a reason for hiding this comment

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

Oh I didn't realize these were skipped for impeller... flutter/flutter#131888 (comment)

Copy link
Member

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

Approach makes sense. Its unfortunate to lose the hardware acceleration, but in most cases I suspect we'll only ever have rect clips.

Skia paths do have some ability to compute intersections/overlaps via skia path ops, which we definitely have access to: https://api.skia.org/SkPathOps_8h.html

Have you looked at using these methods to compute the path intersections?

Copy link
Member

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

LGTM

@hellohuanlin hellohuanlin added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 3, 2024
@auto-submit auto-submit bot merged commit 1e74e9a into flutter:main Sep 3, 2024
32 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 3, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Sep 3, 2024
…154583)

flutter/engine@e042202...1e74e9a

2024-09-03 [email protected] [ios][platform_view] fix platform view clipping path intersection (flutter/engine#54820)
2024-09-03 [email protected] [Impeller] Add all requested glyphs if TypographerContextSkia needs to create a new atlas (flutter/engine#54912)

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
@kishangohel
Copy link

@hellohuanlin can we cherry-picked this to the current stable channel? As it's most required fixed ASAP

@hellohuanlin
Copy link
Contributor Author

Yes we should cherry pick this. Thanks for creating the request.

@jmagman jmagman added the cp: stable cherry pick to the stable release candidate branch label Sep 6, 2024
@flutteractionsbot
Copy link

Failed to create CP due to merge conflicts.
You will need to create the PR manually. See the cherrypick wiki for more info.

jmagman pushed a commit to jmagman/engine that referenced this pull request Sep 6, 2024
…utter#54820)

It turns out that when there are multiple paths to clip, they are unioned together, rather than intersected. But clipping paths need to be intersected.

There isn't any good way to intersect arbitrary paths. However, it is easy to intersect rect paths, which is the most common use case. Then we simply fallback to software rendering if we have to intersect non-rect paths. That is:

**Case 1** Only 1 clipping path (either rect path or arbitrary path):
Hardware rendering. This should be the most common use case

**Case 2** Multiple rect clipping path:
Hardware rendering. This is also common, and it's the linked issue that we are fixing.

**Case 3** Other complex case (multiple non-rect clipping path)
Fallback to software rendering. This should be rare.

After flutter#53826, we don't have a working benchmark that measures the main thread anymore. However, this PR shouldn't impact our ad benchmark, since it only has 1 clipping path. I will verify manually by checking Instruments and make sure no software rendering is happening. But we really should make the benchmark working again, not just for performance improvement, but also for monitoring regression.

*List which issues are fixed by this PR. You must list at least one issue.*

Fixes flutter/flutter#153904

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
auto-submit bot pushed a commit that referenced this pull request Sep 11, 2024
#54820 on stable branch.

That PR was using some of the symbol changes in #54335, so I had so switch some back: e0a630d

Cherry-pick request: flutter/flutter#154712

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
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 cp: stable cherry pick to the stable release candidate branch platform-ios
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[iOS] Platform views is rendered above another widget when scrolling
6 participants