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

Conversation

@harryterkelsen
Copy link
Contributor

Previously, when the number of display canvases exceeded the maximum amount, we would augment the rendering to reduce the number of canvases to the maximum amount, and move the pictures from the deleted canvases to the last canvas. However, this would cause ugly rendering in cases where pictures would render on top of the platform views they were supposed to be underneath.

This is especially noticeable when reproducing this bug: flutter/flutter#144854

This changes things slightly so that the pictures are moved to the second-to-last remaining canvas, so that platform views always render over the pictures they are supposed to.

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.

@github-actions github-actions bot added the platform-web Code specifically for the web engine label Mar 13, 2024
@harryterkelsen harryterkelsen requested a review from yjbanov March 13, 2024 23:28
@jezell
Copy link

jezell commented Mar 14, 2024

@harryterkelsen can this result in the opposite effect where too much is put on top of the platform view? and won't it make the platform view no longer able to receive events?

A while back I experimented with a PR that cut holes out of the canvas with a clear operation when their layer was rendered instead of paint operations and then placed the views behind the canvas. Maybe that could be a useful strategy here so that whatever is on top of that last one that should be behind gets erased and you don't get reverse artifacts.

On that subject,If now it is going to be possible to end up with views below the canvas (which I always thought was probably the better default as it has zero problems with overlay groups at the cost of disabling a few things that aren't usually used with overlay groups), it could maybe be useful to support that general concept for HtmlElementView to support this to allow users to control what happens with the platform views. Right now isVisible is a little confusing and misleading because it doesn't actually make anything invisible, it just puts it always on top of the canvas. It would probably make more sense to have:

enum HtmlElementViewPosition {
   above,
   below,
   alwaysOnTop /// replacement for isVisible, which is a lie
}

HtmlElementView.fromTagName(String tagName, position = HtmlElementViewPosition.below);

And then you wouldn't burn platform layers by default, and you could use one of the other options when you need the element to be clickable

@harryterkelsen
Copy link
Contributor Author

@jezell isVisible is supposed to just be a hint for when the platform view is actually invisible. In those cases we can safely elide an overlay for that platform view. I am also thinking of adding a flag for isOpaque for platform views (which would function similarly to alwaysOnTop) and allow optimizing for the cases where a platform view intersects with a Skia picture but completely obscures it.

@jezell
Copy link

jezell commented Mar 14, 2024

@harryterkelsen I get what it's supposed to be, I also get what it actually is :). While it may supposed to be something you use when stuff is invisible, it doesn't make anything invisible, so it's confusing. If it was alwaysOnTop, it would say exactly what it actually does and would also be more clear that you can use this to avoid creating platform layers. This came up for us recently using the HtmlElementView to embed iframes that we want invisible because they are only used for cross domain communication. Because it says isVisible, everyone expected the iframes wouldn't be displayed, but of course that's not what it does, it just renders them on top.

When this change gets merged, the engine will have three places it can put a view relative to the other canvases:

on top
between
beneath

While all three are valid places you might want to put them, one of them is misnamed as isInvisible, and one of them randomly happens only if you run out of platform views because the engine is trying to be smart and introduces undesirable side effects when it happens, so it's not clear it totally solves the problem.

I think it would probably be better if all of these options were surfaced directly by the HtmlElementView. If beneath was the default, it has less side effects than other two options (if only a couple of lines of code are added for the clear op during the rendering). Then, if you manually opted into between and ran out of layers it could work more like the overflow indicators, where instead of rendering the platform view at all, it renders a shape with an error indicating that you've run out of platform layers.

The problem right now is that this continual desire to insert the views between everything as the default keeps causing unpredictable behavior because it's a fundamentally problematic default. There is no real perfect solution to the problem, but the least problematic default would be something other than putting them between. None of these overlay group issues would be a big deal if they were something you opted into instead of being forced upon you by a problematic default.

@yjbanov
Copy link
Contributor

yjbanov commented Mar 18, 2024

@jezell I tried to capture your feature request (and we've been thinking about similar ideas that are documented in the issue too) here: flutter/flutter#145360

@yjbanov
Copy link
Contributor

yjbanov commented Mar 18, 2024

I think this change should still go in. We're essentially choosing the least bad option for the case where we already know that we ran out of overlays and will render incorrectly. We're trying to minimize the damage. Seems like the strategy @harryterkelsen picked would be best for the common case, no?

@jezell
Copy link

jezell commented Mar 19, 2024

@yjbanov I agree it's better than the current behavior until flutter/flutter#145360 lands

Copy link
Contributor

@yjbanov yjbanov left a comment

Choose a reason for hiding this comment

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

lgtm

@harryterkelsen harryterkelsen added the autosubmit Merge PR when tree becomes green via auto submit App label May 23, 2024
@auto-submit auto-submit bot merged commit ad12c5d into flutter:main May 23, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 23, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request May 23, 2024
…148993)

flutter/engine@2a48302...ad12c5d

2024-05-23 [email protected] Move pictures from deleted canvases to second-to-last canvas instead of last. (flutter/engine#51397)
2024-05-23 [email protected] Roll Skia from 8af1d36fbccb to 60ed6f47af08 (2 revisions) (flutter/engine#52999)
2024-05-23 [email protected] Roll Skia from 7fcb4edbd9b7 to 8af1d36fbccb (1 revision) (flutter/engine#52998)

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
auto-submit bot pushed a commit that referenced this pull request May 24, 2024
…lay (#53006)

When there is only 1 overlay, move pictures in the reduced rendering to the last canvas instead of the second-to-last.

Fixes a bug in #51397

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
victorsanni pushed a commit to victorsanni/flutter that referenced this pull request May 31, 2024
…lutter#148993)

flutter/engine@2a48302...ad12c5d

2024-05-23 [email protected] Move pictures from deleted canvases to second-to-last canvas instead of last. (flutter/engine#51397)
2024-05-23 [email protected] Roll Skia from 8af1d36fbccb to 60ed6f47af08 (2 revisions) (flutter/engine#52999)
2024-05-23 [email protected] Roll Skia from 7fcb4edbd9b7 to 8af1d36fbccb (1 revision) (flutter/engine#52998)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants