Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic view management for engine classes #42991

Merged
merged 65 commits into from Aug 17, 2023

Conversation

dkwingsmt
Copy link
Contributor

@dkwingsmt dkwingsmt commented Jun 19, 2023

This PR is part of the multiview engine project. For a complete roadmap, see this doc.


This PR adds view management to all engine classes that need it. View management here basically means AddView and RemoveView methods, and most importantly, how to handle the implicit view.

The implicit view is a special view that's handled differently than all the other "regular views", since it keeps the behavior of the current single view of Flutter. Detailed introduction can be found in Settings.implicit_view_enabled.

The following two graphs show the difference between initializing with/without the implicit view and creating regular views.

image image image

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 Hixie said 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.

common/settings.h Outdated Show resolved Hide resolved
lib/ui/hooks.dart Outdated Show resolved Hide resolved
lib/ui/hooks.dart Outdated Show resolved Hide resolved
lib/ui/natives.dart Outdated Show resolved Hide resolved
Comment on lines 92 to 95
FML_DCHECK(view_id != kFlutterImplicitViewId)
<< "The implicit view #" << view_id << " should never be removed.";
size_t erased_elements = windows_.erase(view_id);
FML_DCHECK(erased_elements != 0) << "View #" << view_id << " doesn't exist.";
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these be DCHECK or CHECKs?

DCHECK will only run in a local unopt engine build. Flutter developers will never see these.

It seems like this should always be an error log at the least. Alternatively, it could be a DCHECK and an error log with a fizzle, e.g.

if (view_id == kFlutterImplicitViewId) {
  FML_LOG(ERROR) << "The implicit view #" << view_id << " cannot be removed.";
  FML_DCHECK(false);
  return;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Similar comment for the other DCHECK on 95

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've changed one of them to the "if" pattern you suggested. I think both should stay DCHECK since they should never happen if Shell is implemented correctly, and serve as debug-only assertions. I changed the first check to an if to prevent the implicit view being deleted, but didn't for the second check so to make sure the message is always sent to the Dart VM

Comment on lines 31 to 32
tonic::CheckAndHandleError(tonic::DartInvokeField(
library_.value(), "_addView",
Copy link
Contributor

Choose a reason for hiding this comment

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

Please cache the field lookup somewhere, see how that's done in PlatformConfiguration::DidCreateIsolate.

tonic::ToDart(metrics.physical_display_features_type),
tonic::ToDart(metrics.physical_display_features_state),
tonic::ToDart(metrics.display_id),
tonic::ToDart(viewport_metrics_.device_pixel_ratio),
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably get cached as well (The lookup of _updateWindowMetrics).

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

Couple more issues but after that I think should be good to go

@dkwingsmt
Copy link
Contributor Author

I've also removed Window, but merging it to PlatformConfiguration. We've always wanted to do this, not only because Window has only one actual property (view_configuration) but also that the name is obsolete. I found any ways to cache the two methods would be more verbose than just throwing the class away right now.

dkwingsmt added a commit that referenced this pull request Aug 17, 2023
#44787)

This PR moves the code that parses `viewConfiguration` from
`PlatformDispatcher` to `_hooks`. This makes `PlatformDispatcher`'s API
cleaner by hiding the encoding implementation of `ViewConfiguration` in
`_hooks`, and allows more APIs to pass view configuration, such as the
`addView` that will be introduced in
#42991.

This PR should not need unit tests since it's just a refactor, and the
code path that contains `_updateWindowMetrics` has been tested in
existing unit tests.

## 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 Hixie said 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].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
// the implicit view. The multi-view APIs can operate all views, including the
// implicit view if the target ID is `kFlutterImplicitViewId`, unless specified
// otherwise.
constexpr int64_t kFlutterImplicitViewId = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Consider moving this to window.h or platform_configuration.h.

@dkwingsmt dkwingsmt added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 17, 2023
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 17, 2023
@auto-submit
Copy link
Contributor

auto-submit bot commented Aug 17, 2023

auto label is removed for flutter/engine/42991, due to - The status or check suite Linux linux_android_aot_engine has failed. Please fix the issues identified (or deflake) before re-applying this label.

@dkwingsmt dkwingsmt added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 17, 2023
@auto-submit auto-submit bot merged commit 5019d6d into flutter:main Aug 17, 2023
29 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 17, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Aug 17, 2023
…132797)

flutter/engine@5336702...5019d6d

2023-08-17 dkwingsmt@users.noreply.github.com Basic view management for engine classes (flutter/engine#42991)
2023-08-17 skia-flutter-autoroll@skia.org Roll Skia from d0d390f9310d to bfd45173e5e3 (5 revisions) (flutter/engine#44820)
2023-08-17 matanlurey@users.noreply.github.com Implement 2 suggested Clang Tidy fixes we don't look for yet. (flutter/engine#44816)
2023-08-17 louiseh0313@gmail.com Add share to selection controls (flutter/engine#44554)
2023-08-17 zanderso@users.noreply.github.com Adds new builders for partial clang-tidy checks. (flutter/engine#44811)
2023-08-17 41930132+hellohuanlin@users.noreply.github.com [ios][ios17]fix auto correction highlight on top left corner (flutter/engine#44779)
2023-08-17 109111084+yaakovschectman@users.noreply.github.com [Windows] Delay enabling app lifecycle states until requested (flutter/engine#44238)
2023-08-17 dkwingsmt@users.noreply.github.com Move `viewConfiguration` parsing from `PlatformDispatcher` to `_hooks` (flutter/engine#44787)
2023-08-17 skia-flutter-autoroll@skia.org Roll Dart SDK from 92c32df13d31 to 7e4e5796ee99 (2 revisions) (flutter/engine#44810)
2023-08-17 skia-flutter-autoroll@skia.org Roll Skia from c4805a975ab3 to d0d390f9310d (2 revisions) (flutter/engine#44807)
2023-08-17 skia-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from cPncZK6z8HmuOmQr_... to 7xOzci7fempFgHNk9... (flutter/engine#44809)
2023-08-17 skia-flutter-autoroll@skia.org Roll Skia from efb5a5e0b78b to c4805a975ab3 (2 revisions) (flutter/engine#44795)
2023-08-17 skia-flutter-autoroll@skia.org Roll Skia from 11cb8cdd37c1 to efb5a5e0b78b (1 revision) (flutter/engine#44792)
2023-08-17 matanlurey@users.noreply.github.com Passthrough stderr results of clang_tidy when --enable-check-profile. (flutter/engine#44789)
2023-08-17 skia-flutter-autoroll@skia.org Roll Dart SDK from d6e1fca5dbdf to 92c32df13d31 (1 revision) (flutter/engine#44788)

Also rolling transitive DEPS:
  fuchsia/sdk/core/linux-amd64 from cPncZK6z8Hmu to 7xOzci7fempF

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 jsimmons@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://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
gaaclarke pushed a commit to gaaclarke/engine that referenced this pull request Aug 30, 2023
flutter#44787)

This PR moves the code that parses `viewConfiguration` from
`PlatformDispatcher` to `_hooks`. This makes `PlatformDispatcher`'s API
cleaner by hiding the encoding implementation of `ViewConfiguration` in
`_hooks`, and allows more APIs to pass view configuration, such as the
`addView` that will be introduced in
flutter#42991.

This PR should not need unit tests since it's just a refactor, and the
code path that contains `_updateWindowMetrics` has been tested in
existing unit tests.

## 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 Hixie said 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].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
gaaclarke pushed a commit to gaaclarke/engine that referenced this pull request Aug 30, 2023
_This PR is part of the multiview engine project. For a complete roadmap, see [this doc](https://docs.google.com/document/d/10APhzRDR7XqjWdbYWpFfKur7DPiz_HvSKNcLvcyA9vg/edit?resourcekey=0-DfGcg4-XWRMMZF__C1nmcA)._

------

This PR adds view management to all engine classes that need it. View management here basically means `AddView` and `RemoveView` methods, and most importantly, how to handle the implicit view.

The implicit view is a special view that's handled differently than all the other "regular views", since it keeps the behavior of the current single view of Flutter. Detailed introduction can be found in `Settings.implicit_view_enabled`.

The following two graphs show the difference between initializing with/without the implicit view and creating regular views.

<img width="879" alt="image" src="https://github.com/flutter/engine/assets/1596656/31244685-d9d3-4c9a-9a9e-6e8540a5711e">

<img width="864" alt="image" src="https://github.com/flutter/engine/assets/1596656/e2dd4b8c-57e3-428d-8547-834fb270052b">

<img width="860" alt="image" src="https://github.com/flutter/engine/assets/1596656/58dae687-8c17-434e-ae24-a48c2d8fa5fa">

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App platform-android platform-fuchsia platform-ios
Projects
Status: Done
4 participants