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

[web] Fix Scene clip bounds. Trigger resize on DPR Change. #50161

Merged
merged 12 commits into from
Feb 6, 2024

Conversation

ditman
Copy link
Member

@ditman ditman commented Jan 30, 2024

The Scene of the HTML renderer is passing incorrect size information to the engine, and when DPR<1, it can result in elements being culled off of the viewport.

In addition to that, when an app is embedded, not all changes in DPR cause a Resize event (only those some of the dimensions fails by a rounding error!), so this PR ensures that all DPR events in embedded trigger a resize event.

Issues

Fixes flutter/flutter#129182

Testing

Looking good at: https://dit-astral-test.web.app

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.

@flutter-dashboard

This comment was marked as outdated.

@github-actions github-actions bot added the platform-web Code specifically for the web engine label Jan 30, 2024
@ditman ditman changed the title [web] Scene must pass a logical size as its clip bounds. [web] Fix Scene clip bounds. Trigger resize on DPR Change. Jan 31, 2024
@ditman ditman requested review from mdebbar and yjbanov January 31, 2024 02:24
Copy link
Contributor

@mdebbar mdebbar left a comment

Choose a reason for hiding this comment

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

Overall, LGTM.

I can't speak for the html renderer changes though. I'm not sure where exactly we are supposed to used physical vs logical pixels. cc @yjbanov

@ditman ditman force-pushed the web-fix-html-cull branch from d4c7623 to 9f628f8 Compare January 31, 2024 23:04
@ditman
Copy link
Member Author

ditman commented Jan 31, 2024

I've added a couple of tests, one for the dpr stream itself, and another for the connection between the dpr stream and the size provider, I think this is ready to land.

@ditman ditman requested a review from mdebbar January 31, 2024 23:07
Copy link
Contributor

@mdebbar mdebbar left a comment

Choose a reason for hiding this comment

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

LGTM if LGT @yjbanov

@ditman ditman force-pushed the web-fix-html-cull branch from d83f941 to 90c71e4 Compare February 2, 2024 01:23

/// A singleton instance of DisplayDprStream.
static DisplayDprStream instance =
DisplayDprStream(EngineFlutterDisplay.instance);
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 want to continue with the singleton pattern? I was under the impression that we were removing all singletons except one top-level class (was it EnginePlatformDispatcher?), which would do a kind of dependency injection.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, we're still using the singleton pattern for things that are ONE only (browser globals). devicePixelRatio is determined by the browser window. This is similar to the "brightness/dark mode" detector, and implemented in an almost identical way.

(I tried to make this instance-based (by passing a Display), hoping that this API1 will be eventually usable, but it's still unclear to me from the docs how it can be used to monitor DPR changes, though!)

Footnotes

  1. https://developer.mozilla.org/en-US/docs/Web/API/Window_Management_API

Copy link
Contributor

@mdebbar mdebbar Feb 5, 2024

Choose a reason for hiding this comment

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

In one of our recent-ish discussions, we entertained the idea of keeping only ONE singleton in the engine (e.g. EnginePlatformDispatcher), and make all other singletons a member of this ONE singleton.

E.g. instead of DisplayDprStream.instance, we would have EnginePlatformDispatcher.instance.displayDprStream.

It was just a discussion though. We haven't made any real changes in the code base following that discussion. But I think at some point we should start moving to that pattern.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I understand now! Yes, I could move this to a singleton of the EnginePlatformDispatcher instead of being a loose object.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the litmus test is that code that consumes an external service should not go through a static to get a reference to that service. EnginePlatformDispatcher.instance.displayDprStream still accesses DisplayDprStream through a static getter. In fact, it may be worse, the code only needed a DisplayDprStream but it depends on EnginePlatformDispatcher, which vends more dependencies than it needs. It still has the same testability issues, where to mock out DisplayDprStream you need to mock out the EnginePlatformDispatcher.instance static getter.

I don't insist that this is fixed in this PR, unless we already switched modes to a singleton-free design.

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed this a little bit. The CustomElement dimensions provider now just requires a Stream passed by its constructor. For now, the abstract factory class of DimensionsProviders knows where to get that stream from (the singleton instance), but it's very likely that it could just be created from there.

Anyway, I'm going to autosubmit this, and if you find anything egregious, feel free to raise an issue or ping me so I can address it ASAP.

final StreamController<ui.Size> _onResizeStreamController =
StreamController<ui.Size>.broadcast();
late StreamSubscription<double>? _dprChangeStreamSubscription;
final StreamController<ui.Size?> _onResizeStreamController =
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also change the type to StreamController<void> or StreamController<Null>?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, I really really want this to be a StreamController<ui.Size>, it's just that we don't know how to implement it efficiently now :P

@ditman ditman added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 6, 2024
@auto-submit auto-submit bot merged commit 880bf52 into flutter:main Feb 6, 2024
@ditman ditman deleted the web-fix-html-cull branch February 6, 2024 01:48
@jonahwilliams jonahwilliams added the revert Label used to revert changes in a closed and merged pull request. label Feb 6, 2024
@jonahwilliams

This comment was marked as duplicate.

This comment was marked as resolved.

@auto-submit auto-submit bot removed the revert Label used to revert changes in a closed and merged pull request. label Feb 6, 2024
@jonahwilliams
Copy link
Member

Reason for revert: This is causing what looks like bogus goldens on the framework -> engine roll: flutter/flutter#142966

@jonahwilliams jonahwilliams added the revert Label used to revert changes in a closed and merged pull request. label Feb 6, 2024
auto-submit bot pushed a commit that referenced this pull request Feb 6, 2024
@auto-submit auto-submit bot removed the revert Label used to revert changes in a closed and merged pull request. label Feb 6, 2024
auto-submit bot added a commit that referenced this pull request Feb 6, 2024
…50404)

Reverts #50161

Initiated by: jonahwilliams

Reason for reverting: This is causing what looks like bogus goldens on the framework -> engine roll: flutter/flutter#142966

Original PR Author: ditman

Reviewed By: {yjbanov, mdebbar}

This change reverts the following previous change:
Original Description:
The Scene of the HTML renderer is passing incorrect size information to the engine, and when DPR<1, it can result in elements being culled off of the viewport.

In addition to that, when an app is embedded, not all changes in DPR cause a Resize event (only those some of the dimensions fails by a rounding error!), so this PR ensures that all DPR events in embedded trigger a resize event.

### Issues

Fixes flutter/flutter#129182

### Testing

Looking good at: https://dit-astral-test.web.app

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Feb 6, 2024
…143005)

flutter/engine@8088863...07cdaab

2024-02-06 skia-flutter-autoroll@skia.org Roll Dart SDK from 29265c94a6e8 to 35269fa71956 (1 revision) (flutter/engine#50402)
2024-02-06 54558023+keyonghan@users.noreply.github.com Add use_rbe to gclient variables for Framework Smoke Tests (flutter/engine#50403)
2024-02-06 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Revert "Revert "[Fuchsia] Execute most of the testing/fuchsia/test_suites.yaml on debug and release builds""" (flutter/engine#50407)
2024-02-06 matanlurey@users.noreply.github.com Skip flaking test on Windows nobody is fixing. (flutter/engine#50401)
2024-02-06 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[web] Fix Scene clip bounds. Trigger resize on DPR Change." (flutter/engine#50404)
2024-02-06 6844906+zijiehe-google-com@users.noreply.github.com Revert "Revert "[Fuchsia] Execute most of the testing/fuchsia/test_suites.yaml on debug and release builds"" (flutter/engine#50295)
2024-02-06 chinmaygarde@google.com [Impeller] Specify if Angle or SwiftShader is being used in the title. (flutter/engine#50376)
2024-02-06 matanlurey@users.noreply.github.com Run all Android `scenario_app` tests, not just the smoke test. (flutter/engine#50400)
2024-02-06 skia-flutter-autoroll@skia.org Roll Dart SDK from b62066b42af0 to 29265c94a6e8 (10 revisions) (flutter/engine#50398)
2024-02-06 matanlurey@users.noreply.github.com Capture `FAILURES!!!` when running Android `scenario_app` tests. (flutter/engine#50255)
2024-02-06 jonnywang@google.com [fuchsia] Bump Fuchsia's API level to 16 (flutter/engine#50358)
2024-02-06 skia-flutter-autoroll@skia.org Roll Skia from 9e68ed6caf6d to 44106ee8edea (1 revision) (flutter/engine#50393)
2024-02-06 skia-flutter-autoroll@skia.org Roll Skia from c29a20702356 to 9e68ed6caf6d (1 revision) (flutter/engine#50392)
2024-02-06 jonahwilliams@google.com [Impeller] Cache RenderPass/Framebuffer objects on the resolve texture sources. (flutter/engine#50142)
2024-02-06 jason-simmons@users.noreply.github.com [Impeller] Do not skip the GLES render pass if the command list is empty (flutter/engine#50381)
2024-02-06 skia-flutter-autoroll@skia.org Roll Skia from cdf214adfb4d to c29a20702356 (54 revisions) (flutter/engine#50382)
2024-02-06 ditman@gmail.com [web] Fix Scene clip bounds. Trigger resize on DPR Change. (flutter/engine#50161)
2024-02-06 xilaizhang@google.com [github actions] add cherry pick workflow for engine repo (flutter/engine#50265)

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 chinmaygarde@google.com,rmistry@google.com,zra@google.com 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 added a commit to flutter/flutter that referenced this pull request Feb 6, 2024
…visions)" (#143025)

Reverts #143005

Initiated by: vashworth

Reason for reverting: `Linux technical_debt` started failing on this commit: https://ci.chromium.org/ui/p/flutter/builders/prod/Linux%20technical_debt__cost/16684/overview

Original PR Author: engine-flutter-autoroll

Reviewed By: {fluttergithubbot}

This change reverts the following previous change:
Original Description:

flutter/engine@8088863...07cdaab

2024-02-06 skia-flutter-autoroll@skia.org Roll Dart SDK from 29265c94a6e8 to 35269fa71956 (1 revision) (flutter/engine#50402)
2024-02-06 54558023+keyonghan@users.noreply.github.com Add use_rbe to gclient variables for Framework Smoke Tests (flutter/engine#50403)
2024-02-06 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Revert "Revert "[Fuchsia] Execute most of the testing/fuchsia/test_suites.yaml on debug and release builds""" (flutter/engine#50407)
2024-02-06 matanlurey@users.noreply.github.com Skip flaking test on Windows nobody is fixing. (flutter/engine#50401)
2024-02-06 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[web] Fix Scene clip bounds. Trigger resize on DPR Change." (flutter/engine#50404)
2024-02-06 6844906+zijiehe-google-com@users.noreply.github.com Revert "Revert "[Fuchsia] Execute most of the testing/fuchsia/test_suites.yaml on debug and release builds"" (flutter/engine#50295)
2024-02-06 chinmaygarde@google.com [Impeller] Specify if Angle or SwiftShader is being used in the title. (flutter/engine#50376)
2024-02-06 matanlurey@users.noreply.github.com Run all Android `scenario_app` tests, not just the smoke test. (flutter/engine#50400)
2024-02-06 skia-flutter-autoroll@skia.org Roll Dart SDK from b62066b42af0 to 29265c94a6e8 (10 revisions) (flutter/engine#50398)
2024-02-06 matanlurey@users.noreply.github.com Capture `FAILURES!!!` when running Android `scenario_app` tests. (flutter/engine#50255)
2024-02-06 jonnywang@google.com [fuchsia] Bump Fuchsia's API level to 16 (flutter/engine#50358)
2024-02-06 skia-flutter-autoroll@skia.org Roll Skia from 9e68ed6caf6d to 44106ee8edea (1 revision) (flutter/engine#50393)
2024-02-06 skia-flutter-autoroll@skia.org Roll Skia from c29a20702356 to 9e68ed6caf6d (1 revision) (flutter/engine#50392)
2024-02-06 jonahwilliams@google.com [Impeller] Cache RenderPass/Framebuffer objects on the resolve texture sources. (flutter/engine#50142)
2024-02-06 jason-simmons@users.noreply.github.com [Impeller] Do not skip the GLES render pass if the command list is empty (flutter/engine#50381)
2024-02-06 skia-flutter-autoroll@skia.org Roll Skia from cdf214adfb4d to c29a20702356 (54 revisions) (flutter/engine#50382)
2024-02-06 ditman@gmail.com [web] Fix Scene clip bounds. Trigger resize on DPR Change. (flutter/engine#50161)
2024-02-06 xilaizhang@google.com [github actions] add cherry pick workflow for engine repo (flutter/engine#50265)

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 chinmaygarde@google.com,rmistry@google.com,zra@google.com 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 to flutter/flutter that referenced this pull request Feb 7, 2024
…sions) (#143039)

Manual roll requested by zra@google.com

flutter/engine@8088863...1ac6beb

2024-02-07 skia-flutter-autoroll@skia.org Roll Skia from fd55a6bd3580 to 1b266b36a4c8 (1 revision) (flutter/engine#50423)
2024-02-06 skia-flutter-autoroll@skia.org Roll Skia from 44106ee8edea to fd55a6bd3580 (17 revisions) (flutter/engine#50420)
2024-02-06 bdero@google.com [Impeller] Fix pipeline attachment layout in CanRenderToTexture. (flutter/engine#50413)
2024-02-06 ian@hixie.ch Provide toStrings for Native objects (flutter/engine#50168)
2024-02-06 skia-flutter-autoroll@skia.org Roll Dart SDK from 29265c94a6e8 to 35269fa71956 (1 revision) (flutter/engine#50402)
2024-02-06 54558023+keyonghan@users.noreply.github.com Add use_rbe to gclient variables for Framework Smoke Tests (flutter/engine#50403)
2024-02-06 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Revert "Revert "[Fuchsia] Execute most of the testing/fuchsia/test_suites.yaml on debug and release builds""" (flutter/engine#50407)
2024-02-06 matanlurey@users.noreply.github.com Skip flaking test on Windows nobody is fixing. (flutter/engine#50401)
2024-02-06 98614782+auto-submit[bot]@users.noreply.github.com Reverts "[web] Fix Scene clip bounds. Trigger resize on DPR Change." (flutter/engine#50404)
2024-02-06 6844906+zijiehe-google-com@users.noreply.github.com Revert "Revert "[Fuchsia] Execute most of the testing/fuchsia/test_suites.yaml on debug and release builds"" (flutter/engine#50295)
2024-02-06 chinmaygarde@google.com [Impeller] Specify if Angle or SwiftShader is being used in the title. (flutter/engine#50376)
2024-02-06 matanlurey@users.noreply.github.com Run all Android `scenario_app` tests, not just the smoke test. (flutter/engine#50400)
2024-02-06 skia-flutter-autoroll@skia.org Roll Dart SDK from b62066b42af0 to 29265c94a6e8 (10 revisions) (flutter/engine#50398)
2024-02-06 matanlurey@users.noreply.github.com Capture `FAILURES!!!` when running Android `scenario_app` tests. (flutter/engine#50255)
2024-02-06 jonnywang@google.com [fuchsia] Bump Fuchsia's API level to 16 (flutter/engine#50358)
2024-02-06 skia-flutter-autoroll@skia.org Roll Skia from 9e68ed6caf6d to 44106ee8edea (1 revision) (flutter/engine#50393)
2024-02-06 skia-flutter-autoroll@skia.org Roll Skia from c29a20702356 to 9e68ed6caf6d (1 revision) (flutter/engine#50392)
2024-02-06 jonahwilliams@google.com [Impeller] Cache RenderPass/Framebuffer objects on the resolve texture sources. (flutter/engine#50142)
2024-02-06 jason-simmons@users.noreply.github.com [Impeller] Do not skip the GLES render pass if the command list is empty (flutter/engine#50381)
2024-02-06 skia-flutter-autoroll@skia.org Roll Skia from cdf214adfb4d to c29a20702356 (54 revisions) (flutter/engine#50382)
2024-02-06 ditman@gmail.com [web] Fix Scene clip bounds. Trigger resize on DPR Change. (flutter/engine#50161)
2024-02-06 xilaizhang@google.com [github actions] add cherry pick workflow for engine repo (flutter/engine#50265)

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 chinmaygarde@google.com,rmistry@google.com,zra@google.com 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 Feb 8, 2024
…50457)

## Changes

1. Reverts commit 9938df6, to re-land:
   * #50161
2. Adds a fix to the way the HTML Scene computes its bounds that should be compatible with the current imlementation of Flutter's Golden tests.

## Issues

* Fixes flutter/flutter#129182

## Testing

### Goldens

Verified locally that all the golden tests that caused this to roll back looked acceptable:

* [� goldens-check.zip](https://github.com/flutter/engine/files/14203071/goldens-check.zip)

### Test app

* Redeployed at:
  * https://dit-astral-test.web.app/?renderer=html (HTML, full screen)
  * https://dit-astral-test.web.app/?renderer=html&embedded=true (CK, embedded) 
  * https://dit-astral-test.web.app/?renderer=canvaskit (CK, full screen)
  * https://dit-astral-test.web.app/?renderer=canvaskit&embedded=true (CK, embedded) 

## Next steps

During the investigation of this rollback, we found some opportunities to improve our web tests in the repo. Tracking issue:

* flutter/flutter#143124

[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 platform-web Code specifically for the web engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Flutter Web] Widgets not resizing (disappear) with browser zoom in / out
4 participants