[canvaskit] Only dispose views to release overlays as long as there are overlays available (flutter/engine#30274)

This commit is contained in:
Harry Terkelsen
2021-12-13 09:51:36 -08:00
committed by GitHub
parent ce1c91dc5e
commit 4b41bad357
3 changed files with 52 additions and 2 deletions

View File

@@ -651,7 +651,8 @@ class HtmlViewEmbedder {
// them. Otherwise, we will need to release overlays from the unchanged
// segment of view ids.
if (diffResult.viewsToAdd.length > availableOverlays) {
int viewsToDispose = diffResult.viewsToAdd.length - availableOverlays;
int viewsToDispose = math.min(SurfaceFactory.instance.maximumOverlays,
diffResult.viewsToAdd.length - availableOverlays);
// The first `maximumSurfaces` views in the previous composition order
// had an overlay.
int index = SurfaceFactory.instance.maximumOverlays -

View File

@@ -166,8 +166,10 @@ external JsFlutterConfiguration? get _jsConfiguration;
class JsFlutterConfiguration {
external String? get canvasKitBaseUrl;
external bool? get canvasKitForceCpuOnly;
external int? get canvasKitMaximumSurfaces;
external bool? get debugShowSemanticsNodes;
external int? get canvasKitMaximumSurfaces;
external set canvasKitMaximumSurfaces(int? maxSurfaces);
}
/// A JavaScript entrypoint that allows developer to set rendering backend

View File

@@ -601,6 +601,53 @@ void testMain() {
HtmlViewEmbedder.debugDisableOverlays = false;
});
test('works correctly with max overlays == 2', () async {
debugSetConfiguration(FlutterConfiguration(
JsFlutterConfiguration()..canvasKitMaximumSurfaces = 2));
SurfaceFactory.instance.debugClear();
expect(SurfaceFactory.instance.maximumSurfaces, 2);
expect(SurfaceFactory.instance.maximumOverlays, 0);
ui.platformViewRegistry.registerViewFactory(
'test-platform-view',
(int viewId) => html.DivElement()..id = 'view-0',
);
await createPlatformView(0, 'test-platform-view');
await createPlatformView(1, 'test-platform-view');
final EnginePlatformDispatcher dispatcher =
ui.window.platformDispatcher as EnginePlatformDispatcher;
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(
flutterViewEmbedder.glassPaneShadow!
.querySelectorAll('flt-platform-view-slot'),
hasLength(1));
sb = LayerSceneBuilder();
sb.pushOffset(0, 0);
sb.addPlatformView(1, width: 10, height: 10);
sb.addPlatformView(0, width: 10, height: 10);
sb.pop();
// The below line should not throw an error.
dispatcher.rasterizer!.draw(sb.build().layerTree);
expect(
flutterViewEmbedder.glassPaneShadow!
.querySelectorAll('flt-platform-view-slot'),
hasLength(2));
// Reset configuration
debugSetConfiguration(FlutterConfiguration(null));
});
test(
'correctly renders when overlays are disabled and a subset '
'of views is used', () async {