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

Conversation

@mdebbar
Copy link
Contributor

@mdebbar mdebbar commented Nov 10, 2023

  • An explicit API for initializing the implicit view (aka window).
  • The explicit API is being called during the engine initialization for now, but we could simply remove that or make it conditional.
  • Remove direct usages of window in tests:
    • Most of the usages were being delegated to PlatformDispatcher anyway (e.g. sendPlatformMessage).
    • This makes it clearer which tests depend on the implicit view (there are still hidden/indirect dependencies though).

Part of flutter/flutter#134443

@mdebbar mdebbar requested review from ditman and yjbanov November 10, 2023 19:10
@github-actions github-actions bot added the platform-web Code specifically for the web engine label Nov 10, 2023
@ditman
Copy link
Member

ditman commented Nov 10, 2023

This makes it clearer which tests depend on the implicit view (there are still hidden/indirect dependencies though).

Yes! This is great. There are a couple of tests still failing, but they all seem related to missing a call to ensureImplicitViewInitialized() somewhere in their setup.

@mdebbar
Copy link
Contributor Author

mdebbar commented Nov 10, 2023

There are a couple of tests still failing, but they all seem related to missing a call to ensureImplicitViewInitialized() somewhere in their setup.

Exactly. These are examples of tests that have a hidden/indirect dependency on the implicit view (2 of them were because the flutter view embedder requires the existence of the implicit view).

_flutterViewEmbedder ??=
FlutterViewEmbedder(hostElement: configuration.hostElement);
FlutterViewEmbedder ensureFlutterViewEmbedderInitialized() {
// FlutterViewEmbedder needs the implicit view to be initialized.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated comment.

_initializationState = DebugEngineInitializationState.initializingUi;

RawKeyboard.initialize(onMacOs: operatingSystem == OperatingSystem.macOs);
ensureImplicitViewInitialized();
Copy link
Contributor

Choose a reason for hiding this comment

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

Will initializeEngineUi henceforth be used to initialize in the single-view mode?

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 haven't thought that far yet, but the way I see it is initializeEngineUi will be used for all modes. And instead of calling ensureImplicitViewInitialized unconditionally (like I'm doing here), it will be guarded by whatever conditions that dictate the need for the implicit view.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool. When/if this changes, we should also update the dartdocs above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, maybe we should delay the call to initializeEngineUi until the first view is added? cc @ditman

Copy link
Member

Choose a reason for hiding this comment

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

Most likely, initializeEngineUi will do nothing, since all it does now is ensureFlutterViewEmbedderInitialized(), attach a global keyboard handler (and change the state of the lifecycle of the engine initialization)! code.

Everything it does seems that will eventually be gobbled up by createView(viewOptions), right?

We can leave the method here for the "implicitView" modes, (that's where we can "createView" for the implicitView), but in multiview mode this can just let the state machine of the engine advance, and noop the rest.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most likely, initializeEngineUi will do nothing, since all it does now is ensureFlutterViewEmbedderInitialized(), attach a global keyboard handler

Well, there are many things hidden behind that ensureFlutterViewEmbedderInitialized(). E.g. keyboard, pointers, resize, a11y, etc.

I think we can use initializeEngineUi for initializing the global stuff (e.g. a11y announcements).

///
/// Nothing happens if the view is not already registered.
void unregisterView(EngineFlutterView view) {
viewData.remove(view.viewId);
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 need to call dispose on the view?

Copy link
Contributor Author

@mdebbar mdebbar Nov 13, 2023

Choose a reason for hiding this comment

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

There's no dispose on view (yet). But if there was a FlutterView.dispose method, then here's how it would look like:

class EngineFlutterView implements ui.FlutterView {
  EngineFlutterView(...) {
    // This already exists.
    platformDispatcher.registerView(this);
  }

  void dispose() {
    // This doesn't exists yet, but this is what `dispose` would look like if we ever add one (I think we will).
    platformDispatcher.unregisterView(this);
  }
}

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 guess what I'm saying is: if we ever have a FlutterView.dispose, then FlutterView.dispose should call PlatformDispatcher.unregisterView and not vice versa.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ha-ha. Gotcha.

EngineFlutterWindow(kImplicitViewId, EnginePlatformDispatcher.instance);
EngineFlutterWindow get window {
if (_window == null) {
throw StateError('Trying to access the implicit flutter view, but it has not been initialized.');
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a scenario where in multi-view mode we also have an implicit view? If not, maybe the error message should talk along the lines of "Implicit Flutter view is not available. Flutter is running in multi-view mode."

nit: s/flutter/Flutter/ (it's a proper name)

Copy link
Member

Choose a reason for hiding this comment

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

Is there a scenario where in multi-view mode we also have an implicit view?

I'm trying to avoid this, and only use the implicit view in the modes that exist right now (single view)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated error message.

@mdebbar mdebbar requested a review from yjbanov November 13, 2023 18:46
_initializationState = DebugEngineInitializationState.initializingUi;

RawKeyboard.initialize(onMacOs: operatingSystem == OperatingSystem.macOs);
ensureImplicitViewInitialized();
Copy link
Contributor

Choose a reason for hiding this comment

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

Cool. When/if this changes, we should also update the dartdocs above.

///
/// Nothing happens if the view is not already registered.
void unregisterView(EngineFlutterView view) {
viewData.remove(view.viewId);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ha-ha. Gotcha.

throw StateError(
'Trying to access the implicit FlutterView, but it is not available.\n'
'Note: the implicit FlutterView is not available in multi-view mode.',
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the expression below needs a ! anyway, can we make it an assert so the error message can be tree shaken off?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@mdebbar mdebbar added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 13, 2023
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 13, 2023
@auto-submit
Copy link
Contributor

auto-submit bot commented Nov 13, 2023

auto label is removed for flutter/engine/47921, due to Pull request flutter/engine/47921 is not in a mergeable state.

@mdebbar mdebbar added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 14, 2023
@auto-submit auto-submit bot merged commit 777dcb9 into flutter:main Nov 14, 2023
@mdebbar mdebbar deleted the init_implicit_view branch November 14, 2023 16:15
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 14, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Nov 14, 2023
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