Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
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
22 changes: 15 additions & 7 deletions lib/web_ui/lib/src/engine/canvaskit/embedded_views.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ class HtmlViewEmbedder {
/// This causes all drawing to go to a single canvas, with all of the platform
/// views rendered over top. This may result in incorrect rendering with
/// platform views.
static const bool disableOverlays = maximumSurfaces <= 1;
static bool get disableOverlays =>
debugDisableOverlays || maximumSurfaces <= 1;

/// Force the view embedder to disable overlays.
///
/// This should never be used outside of tests.
static bool debugDisableOverlays = false;

/// The set of platform views using the backup surface.
final Set<int> _viewsUsingBackupSurface = <int>{};
Expand Down Expand Up @@ -170,12 +176,14 @@ class HtmlViewEmbedder {
CkCanvas? compositeEmbeddedView(int viewId) {
final int compositedViewCount = _compositionOrder.length;
_compositionOrder.add(viewId);
if (compositedViewCount < _pictureRecordersCreatedDuringPreroll.length) {
_pictureRecorders[viewId] =
_pictureRecordersCreatedDuringPreroll[compositedViewCount];
} else {
_viewsUsingBackupSurface.add(viewId);
_pictureRecorders[viewId] = _backupPictureRecorder!;
if (!disableOverlays) {
if (compositedViewCount < _pictureRecordersCreatedDuringPreroll.length) {
_pictureRecorders[viewId] =
_pictureRecordersCreatedDuringPreroll[compositedViewCount];
} else {
_viewsUsingBackupSurface.add(viewId);
_pictureRecorders[viewId] = _backupPictureRecorder!;
}
}

// Do nothing if this view doesn't need to be composited.
Expand Down
26 changes: 25 additions & 1 deletion lib/web_ui/test/canvaskit/embedded_views_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -574,10 +574,34 @@ void testMain() {
// The below line should not throw an error.
dispatcher.rasterizer!.draw(sb.build().layerTree);
expect(
domRenderer.glassPaneElement!
domRenderer.glassPaneShadow!
.querySelectorAll('flt-platform-view-slot'),
isEmpty);
});

test('does not crash when overlays are disabled', () async {
HtmlViewEmbedder.debugDisableOverlays = true;
ui.platformViewRegistry.registerViewFactory(
'test-platform-view',
(int viewId) => html.DivElement()..id = 'view-0',
);
await _createPlatformView(0, 'test-platform-view');

final EnginePlatformDispatcher dispatcher =
ui.window.platformDispatcher as EnginePlatformDispatcher;

final LayerSceneBuilder sb = LayerSceneBuilder();
sb.pushOffset(0, 0);
sb.addPlatformView(0, width: 10, height: 10);
sb.pop();
// The below line should not throw an error.
dispatcher.rasterizer!.draw(sb.build().layerTree);
expect(
domRenderer.glassPaneShadow!
.querySelectorAll('flt-platform-view-slot'),
hasLength(1));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should also count <flt-canvas-container>s (there should be 2, right?).

HtmlViewEmbedder.debugDisableOverlays = false;
});
// TODO(dit): https://github.com/flutter/flutter/issues/60040
}, skip: isIosSafari);
}
Expand Down