Skip to content

Commit

Permalink
[web] injectPlatformView into correct flutterView (#56334)
Browse files Browse the repository at this point in the history
Makes SceneView inject platform views in the current `flutterView`, instead of the `implicitView`.

This enables platform views in multi-view mode for the Skwasm renderer.

Fixes flutter/flutter#157958

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
  • Loading branch information
ditman authored Nov 5, 2024
1 parent 677fb9c commit cb8f2eb
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 8 deletions.
7 changes: 2 additions & 5 deletions lib/web_ui/lib/src/engine/scene_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,8 @@ class EngineSceneView {
}

for (final PlatformView view in slice.platformViews) {
// TODO(harryterkelsen): Inject the FlutterView instance from `renderScene`,
// instead of using `EnginePlatformDispatcher...implicitView` directly,
// or make the FlutterView "register" like in canvaskit.
// Ensure the platform view contents are injected in the DOM.
EnginePlatformDispatcher.instance.implicitView?.dom.injectPlatformView(view.viewId);
// Ensure the contents of the platform view are injected into the DOM.
flutterView.dom.injectPlatformView(view.viewId);

// Attempt to reuse a container for the existing view
PlatformViewContainer? container;
Expand Down
65 changes: 62 additions & 3 deletions lib/web_ui/test/engine/scene_view_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class StubPictureRenderer implements PictureRenderer {
}

class StubFlutterView implements EngineFlutterView {
// Overridden in some tests
@override
DomManager dom = StubDomManager();

@override
double get devicePixelRatio => throw UnimplementedError();

Expand Down Expand Up @@ -128,9 +132,6 @@ class StubFlutterView implements EngineFlutterView {
throw UnimplementedError();
}

@override
DomManager get dom => throw UnimplementedError();

@override
EmbeddingStrategy get embeddingStrategy => throw UnimplementedError();

Expand Down Expand Up @@ -274,4 +275,62 @@ void testMain() {
expect(stubPictureRenderer.renderedPictures.length, 1);
expect(stubPictureRenderer.clipRequests.containsKey(picture), true);
});

test('SceneView places platform view contents in the DOM', () async {
const int expectedPlatformViewId = 1234;

int? injectedViewId;
final DomManager stubDomManager = StubDomManager()
..injectPlatformViewOverride = (int viewId) {
injectedViewId = viewId;
};
sceneView = EngineSceneView(
stubPictureRenderer,
StubFlutterView()..dom = stubDomManager,
);

final PlatformView platformView = PlatformView(expectedPlatformViewId,
const ui.Rect.fromLTWH(50, 80, 100, 120), const PlatformViewStyling());

final EngineRootLayer rootLayer = EngineRootLayer();
rootLayer.slices.add(
LayerSlice(StubPicture(ui.Rect.zero), <PlatformView>[platformView]));
final EngineScene scene = EngineScene(rootLayer);
await sceneView.renderScene(scene, null);

expect(
injectedViewId,
expectedPlatformViewId,
reason: 'SceneView should call injectPlatformView on its flutterView.dom',
);
});
}

class StubDomManager implements DomManager {
void Function(int platformViewId) injectPlatformViewOverride = (int id) {};
@override
void injectPlatformView(int platformViewId) {
injectPlatformViewOverride(platformViewId);
}

@override
DomElement get platformViewsHost => throw UnimplementedError();

@override
DomShadowRoot get renderingHost => throw UnimplementedError();

@override
DomElement get rootElement => throw UnimplementedError();

@override
DomElement get sceneHost => throw UnimplementedError();

@override
DomElement get semanticsHost => throw UnimplementedError();

@override
void setScene(DomElement sceneElement) {}

@override
DomElement get textEditingHost => throw UnimplementedError();
}

0 comments on commit cb8f2eb

Please sign in to comment.