-
Notifications
You must be signed in to change notification settings - Fork 6k
[web] Explicit initialization of the implicit view #47921
Conversation
Yes! This is great. There are a couple of tests still failing, but they all seem related to missing a call to |
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most likely,
initializeEngineUiwill do nothing, since all it does now isensureFlutterViewEmbedderInitialized(), 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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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);
}
}There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.'); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated error message.
fc8a6cb to
011cd9b
Compare
| _initializationState = DebugEngineInitializationState.initializingUi; | ||
|
|
||
| RawKeyboard.initialize(onMacOs: operatingSystem == OperatingSystem.macOs); | ||
| ensureImplicitViewInitialized(); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.', | ||
| ); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
auto label is removed for flutter/engine/47921, due to Pull request flutter/engine/47921 is not in a mergeable state. |
…138420) flutter/engine@1b3fd80...777dcb9 2023-11-14 [email protected] [web] Explicit initialization of the implicit view (flutter/engine#47921) 2023-11-14 [email protected] Roll Skia from b7d581997f2b to a811132be321 (1 revision) (flutter/engine#48019) 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
window).windowin tests:PlatformDispatcheranyway (e.g.sendPlatformMessage).Part of flutter/flutter#134443