[canvaskit] Fix overlay reorganization for edge case with only 1 overlay (flutter/engine#53006)

When there is only 1 overlay, move pictures in the reduced rendering to the last canvas instead of the second-to-last.

Fixes a bug in https://github.com/flutter/engine/pull/51397

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
Harry Terkelsen
2024-05-24 11:00:06 -07:00
committed by GitHub
parent 7615b27ee5
commit 1f57178c37
2 changed files with 65 additions and 2 deletions

View File

@@ -504,8 +504,8 @@ class HtmlViewEmbedder {
}
// Add all the pictures from the deleted canvases to the second-to-last
// canvas.
sawLastCanvas = false;
// canvas (or the last canvas if there is only one).
sawLastCanvas = (maximumCanvases == 1);
for (int i = modifiedEntities.length - 1; i > 0; i--) {
final RenderingEntity entity = modifiedEntities[i];
if (entity is RenderingRenderCanvas) {

View File

@@ -1315,6 +1315,69 @@ void testMain() {
.map((RenderingRenderCanvas canvas) => canvas.pictures.length)
.toList();
expect(numPicturesPerCanvas, <int>[1, 1, 1, 1, 1, 1, 12, 1]);
// It should also work when the maximum canvases is just one.
debugOverrideJsConfiguration(<String, Object?>{
'canvasKitMaximumSurfaces': 1,
}.jsify() as JsFlutterConfiguration?);
// Render scene with 20 pictures. Check that the last canvas contains the
// pictures from the canvases that were deleted.
await renderTestScene(<int>[
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
]);
_expectSceneMatches(<_EmbeddedViewMarker>[
_platformView,
_platformView,
_platformView,
_platformView,
_platformView,
_platformView,
_platformView,
_platformView,
_platformView,
_platformView,
_platformView,
_platformView,
_platformView,
_platformView,
_platformView,
_platformView,
_platformView,
_platformView,
_overlay,
_platformView,
]);
// The last canvas should have all the pictures.
final Rendering secondRendering = CanvasKitRenderer.instance
.debugGetRasterizerForView(implicitView)!
.viewEmbedder
.debugActiveRendering;
final List<int> picturesPerCanvasInSecondRendering = secondRendering
.canvases
.map((RenderingRenderCanvas canvas) => canvas.pictures.length)
.toList();
expect(picturesPerCanvasInSecondRendering, <int>[19]);
debugOverrideJsConfiguration(null);
});
});
}