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

[web] add test for inefficient overlay allocation #53284

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions lib/web_ui/test/canvaskit/embedded_views_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,78 @@ void testMain() {
]);
});

test('sinks platform view under the canvas if it does not overlap with the picture',
() async {
ui_web.platformViewRegistry.registerViewFactory(
'test-view',
(int viewId) => createDomHTMLDivElement()..className = 'platform-view',
);

CkPicture rectPicture(double l, double t, double w, double h) {
final ui.Rect rect = ui.Rect.fromLTWH(l, t, w, h);
return paintPicture(rect, (CkCanvas canvas) {
canvas.drawRect(
rect, CkPaint()..color = const ui.Color.fromARGB(255, 255, 0, 0));
});
}

await createPlatformView(0, 'test-view');
await createPlatformView(1, 'test-view');

expect(PlatformViewManager.instance.isVisible(0), isTrue);
expect(PlatformViewManager.instance.isVisible(1), isTrue);

final LayerSceneBuilder sb = LayerSceneBuilder();

// First picture-view-picture stack.
{
sb.pushOffset(0, 0);
sb.addPicture(
ui.Offset.zero,
rectPicture(0, 0, 10, 10),
);
sb.addPlatformView(
0,
width: 10,
height: 10,
);
sb.addPicture(
ui.Offset.zero,
rectPicture(2, 2, 5, 5),
);
sb.pop();
}

// Second picture-view-picture stack that does not overlap with the first one.
{
sb.pushOffset(20, 0);
sb.addPicture(
ui.Offset.zero,
rectPicture(0, 0, 10, 10),
);
sb.addPlatformView(
1,
width: 10,
height: 10,
);
sb.addPicture(
ui.Offset.zero,
rectPicture(2, 2, 5, 5),
);
sb.pop();
}

final LayerScene scene1 = sb.build();
await renderScene(scene1);
_expectSceneMatches(<_EmbeddedViewMarker>[
_overlay,
_platformView,
_overlay,
_platformView,
_overlay,
]);
});

test('optimizes overlays correctly with transforms and clips', () async {
ui_web.platformViewRegistry.registerViewFactory(
'test-view',
Expand Down