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

Conversation

jonahwilliams
Copy link
Contributor

@jonahwilliams jonahwilliams commented Jul 20, 2024

This removes support for "unobstructed platform views" on iOS - instead prefering to use the Android strategy of minimizing overlay layers, as this is generally more performant.

@jonahwilliams jonahwilliams marked this pull request as ready for review July 22, 2024 14:55
@jonahwilliams jonahwilliams changed the title share slicing logic across iOS and Android. share platform view slicing logic across iOS and Android. Jul 22, 2024
@hellohuanlin
Copy link
Contributor

instead prefering to use the Android strategy of minimizing overlay layers, as this is generally more performant.

By Android strategy, do you mean having a global limit of overlay count?

@jonahwilliams
Copy link
Contributor Author

AFAIK there is no global limit on the number of overlays, but we create at most one overlay per embedder view slice.

const std::unordered_map<int64_t, SkRect>& view_rects) {
std::unordered_map<int64_t, SkRect> overlay_layers;

auto current_frame_view_count = composition_order.size();
Copy link
Contributor

Choose a reason for hiding this comment

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

just so that i understand - this count is the count of platform views right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct

// Limit the number of native views, so it doesn't grow forever.
//
// In this case, the rects are merged into a single one that is the union
// of all the rects.
Copy link
Contributor

Choose a reason for hiding this comment

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

iOS used to have 2 overlays per platform view as the limit. Do you have any context why we picked 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as far as I can tell it was aribtrarily chosen

Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if there are any benefit of having multiple overlays despite of the performance overhead. Otherwise it's odd that we picked 2 before. @cbracken do you recall?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

its possible that at one point the overlay surfaces weren't screen sized, so shrinking the overlays as small as possible improved performance. overlay sizes aren;t stable however, which is what lead to using the frame size in all cases - which defeats the purpose of minimizing overlay size.

Copy link
Member

Choose a reason for hiding this comment

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

Talked to @jonahwilliams about this this morning but no, I don't recall this splitting logic at all and it's surprising to me that we're doing it -- adding layers should harm performance if anything. Could be something like what Jonah is suggesting.

Copy link
Contributor

Choose a reason for hiding this comment

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

the subpixel overlap issue

Do you mean this? flutter/flutter#143420

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha. This PR should move the metrics on both iOS (by reducing the limit from 2 to 1) and Android (by fixing the 1 px overlay). Do you think I should make our ads benchmark work on Android (should be a quick change? CC @jmagman correct me if it's not), so that we can measure both?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Almost all Android PVs will use TLHC by default, which does not use platform view slicing. There is work this year to make android PVs work more like iOS by default, but without any of the terrible downsides of the current approach.

Copy link
Contributor

Choose a reason for hiding this comment

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

This means we don't need the Android benchmark to run for this PR (since it's not the implementation used in Android yet), but we may need it later down the road, right? (flutter/flutter#152200)


namespace flutter {

/// @brief Compute the required overlay layers and clip the view slices
Copy link
Member

Choose a reason for hiding this comment

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

Can this documentation be elaborated? What are the integer handles? How are they created. What is the rect that is returned? The embedder view slice is also not documented so there are no breadcrumbs there either.

Can these go in a struct with a custom hasher and equality checker?

If this is just moving code around and you want to limit scope, then we could probably do it in a followup. Just that from the perspective of someone not super familiar with slicing, this reads a bit dense.

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 agree for the most part, the platform view code is not very abstracted - lots of vecs/maps with the integer id keys that should be refactored. I'd like to do that sort of gradually though, since its very related to the work in

#53882 and #53826

Copy link
Member

Choose a reason for hiding this comment

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

sgtm

@jonahwilliams
Copy link
Contributor Author

ping @chinmaygarde @cbracken @hellohuanlin can you either approve or make suggestions? This patch is blocking very high priority work.

@hellohuanlin
Copy link
Contributor

Sorry for the delay. Will take another look today!

Copy link
Member

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

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

Ah, didn't realize you were blocked without pending following.

I'm not super comfortable with this code but gradually refactoring and documenting this code works for me. Looks fine to me and a lot of it is moving stuff to be shared. For this reason, happy to LGTM but please me know if I should focus on something specific.

@hellohuanlin
Copy link
Contributor

@jonahwilliams let me quickly pull the code and check if the overlay merging logic still works on iOS.

Copy link
Contributor

@hellohuanlin hellohuanlin left a comment

Choose a reason for hiding this comment

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

Confirmed the overlay merging logic worked! Hopefully this can move our benchmark a bit

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 24, 2024
@auto-submit auto-submit bot merged commit 3bba8a4 into flutter:main Jul 24, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Jul 24, 2024
…152260)

flutter/engine@490576d...c2f489d

2024-07-24 [email protected] Fix embedder comments about struct_size (flutter/engine#54077)
2024-07-24 [email protected] share platform view slicing logic across iOS and Android. (flutter/engine#54010)
2024-07-24 [email protected] [skwasm] Fix platform view occlusion logic. (flutter/engine#54061)
2024-07-24 [email protected] Roll Skia from 25f26f673502 to c11932925658 (4 revisions) (flutter/engine#54081)
2024-07-24 [email protected] Upgrade Engine Android SDK to 35 (flutter/engine#53574)
2024-07-24 [email protected] Roll Skia from a9b1043eb23e to 25f26f673502 (1 revision) (flutter/engine#54079)

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#152260)

flutter/engine@490576d...c2f489d

2024-07-24 [email protected] Fix embedder comments about struct_size (flutter/engine#54077)
2024-07-24 [email protected] share platform view slicing logic across iOS and Android. (flutter/engine#54010)
2024-07-24 [email protected] [skwasm] Fix platform view occlusion logic. (flutter/engine#54061)
2024-07-24 [email protected] Roll Skia from 25f26f673502 to c11932925658 (4 revisions) (flutter/engine#54081)
2024-07-24 [email protected] Upgrade Engine Android SDK to 35 (flutter/engine#53574)
2024-07-24 [email protected] Roll Skia from a9b1043eb23e to 25f26f673502 (1 revision) (flutter/engine#54079)

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#152260)

flutter/engine@490576d...c2f489d

2024-07-24 [email protected] Fix embedder comments about struct_size (flutter/engine#54077)
2024-07-24 [email protected] share platform view slicing logic across iOS and Android. (flutter/engine#54010)
2024-07-24 [email protected] [skwasm] Fix platform view occlusion logic. (flutter/engine#54061)
2024-07-24 [email protected] Roll Skia from 25f26f673502 to c11932925658 (4 revisions) (flutter/engine#54081)
2024-07-24 [email protected] Upgrade Engine Android SDK to 35 (flutter/engine#53574)
2024-07-24 [email protected] Roll Skia from a9b1043eb23e to 25f26f673502 (1 revision) (flutter/engine#54079)

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-android platform-ios
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants