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

[macOS] Consolidate view management #52254

Merged
merged 7 commits into from
Apr 19, 2024

Conversation

dkwingsmt
Copy link
Contributor

This PR improves view management logic of the macOS FlutterEngine class.

  • View operation assertions are now centralized in registerViewController: and deregisterViewControllerForIdentifier:.
  • addViewController now directly calls .viewController = on implicit views, so that it matches its verbatim description.
  • The doc for addViewController correctly reflects the fact that it doesn't support multiple views yet.

Additionally, a useless (for now) member variable is removed.

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

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Comment on lines 784 to 785
// The controller might be nil, because the engine only stores a weak ref, and
// this method might have been called from the controller's dealloc.
Copy link
Member

Choose a reason for hiding this comment

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

Consider something like:

Suggested change
// The controller might be nil, because the engine only stores a weak ref, and
// this method might have been called from the controller's dealloc.
// The controller can be nil. The engine stores only a weak ref, this method could have been called from the controller's dealloc.

I don't feel strongly, feel free to keep as is

[controller setUpWithEngine:self
viewIdentifier:viewIdentifier
threadSynchronizer:_threadSynchronizer];
NSAssert(controller.viewIdentifier == viewIdentifier, @"Failed to assign view ID.");
[_viewControllers setObject:controller forKey:@(viewIdentifier)];
NSAssert(controller.attached && controller.engine == self,
Copy link
Member

Choose a reason for hiding this comment

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

Should we separate the "attached to an unexpected engine" to a separate assertion? Currently, the assertion message you'll get for this scenario would be confusing.

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 combined them initially because the "suggestion" part is too long. I now moved the "suggestion" part to in-code comment and only left the symptom to the assertion. Let me know if they still feel off.

[controller setUpWithEngine:self
viewIdentifier:viewIdentifier
threadSynchronizer:_threadSynchronizer];
NSAssert(controller.viewIdentifier == viewIdentifier, @"Failed to assign view ID.");
[_viewControllers setObject:controller forKey:@(viewIdentifier)];
NSAssert(controller.attached && controller.engine == self,
@"The FlutterViewController unexpectedly stays unattached after being added. "
Copy link
Member

Choose a reason for hiding this comment

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

This assertion message makes sense when you're reading this code, but it might be a little confusing if you see this in the command line without any other context.

Perhaps consider expanding the message to explain this is attaching/adding to the engine. Consider something like:

The FlutterViewController should switch to the attached mode after it is added to a FlutterEngine.

Same comment for the other similar assertions

Copy link
Member

@loic-sharma loic-sharma left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

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

LGTM stamp from a Japanese personal seal

@dkwingsmt dkwingsmt merged commit 6fad27b into flutter:main Apr 19, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Apr 19, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Apr 20, 2024
…147095)

flutter/engine@55670b7...3db86b3

2024-04-19 skia-flutter-autoroll@skia.org Roll Dart SDK from 2ff00e4eb759 to d882ce089110 (1 revision) (flutter/engine#52272)
2024-04-19 dkwingsmt@users.noreply.github.com [macOS] Consolidate view management (flutter/engine#52254)
2024-04-19 skia-flutter-autoroll@skia.org Roll Skia from f4a214ecf197 to 1910252ea26a (3 revisions) (flutter/engine#52269)
2024-04-19 jonahwilliams@google.com [Impeller] add non-emulated advanced blend support to experimental canvas (flutter/engine#52245)

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://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
gilnobrega pushed a commit to gilnobrega/flutter that referenced this pull request Apr 22, 2024
…lutter#147095)

flutter/engine@55670b7...3db86b3

2024-04-19 skia-flutter-autoroll@skia.org Roll Dart SDK from 2ff00e4eb759 to d882ce089110 (1 revision) (flutter/engine#52272)
2024-04-19 dkwingsmt@users.noreply.github.com [macOS] Consolidate view management (flutter/engine#52254)
2024-04-19 skia-flutter-autoroll@skia.org Roll Skia from f4a214ecf197 to 1910252ea26a (3 revisions) (flutter/engine#52269)
2024-04-19 jonahwilliams@google.com [Impeller] add non-emulated advanced blend support to experimental canvas (flutter/engine#52245)

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://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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants