[canvaskit] Fix bug when overlays are disabled (flutter/engine#28790)
This commit is contained in:
@@ -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>{};
|
||||
@@ -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.
|
||||
|
||||
@@ -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));
|
||||
HtmlViewEmbedder.debugDisableOverlays = false;
|
||||
});
|
||||
// TODO(dit): https://github.com/flutter/flutter/issues/60040
|
||||
}, skip: isIosSafari);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user