[web] Fix child removal after reuse by other BitmapCanvas (flutter/engine#18604)

* Fix child removal after reuse by other BitmapCanvas
* Address review comments
This commit is contained in:
Ferhat
2020-05-26 17:28:49 -07:00
committed by GitHub
parent fca990583a
commit 63c42cd0d9
2 changed files with 11 additions and 4 deletions

View File

@@ -118,7 +118,7 @@ class BitmapCanvas extends EngineCanvas {
}
/// Setup cache for reusing DOM elements across frames.
set elementCache(CrossFrameCache<html.HtmlElement> cache) {
void setElementCache(CrossFrameCache<html.HtmlElement> cache) {
_elementCache = cache;
}
@@ -178,7 +178,11 @@ class BitmapCanvas extends EngineCanvas {
_canvasPool.clear();
final int len = _children.length;
for (int i = 0; i < len; i++) {
_children[i].remove();
html.Element child = _children[i];
// Don't remove children that have been reused by CrossFrameCache.
if (child.parent == rootElement) {
child.remove();
}
}
_children.clear();
_cachedLastStyle = null;

View File

@@ -244,6 +244,7 @@ class PersistedStandardPicture extends PersistedPicture {
}
oldCanvas.bounds = _optimalLocalCullRect;
_canvas = oldCanvas;
oldCanvas.setElementCache(_elementCache);
_canvas.clear();
picture.recordingCanvas.apply(_canvas, _optimalLocalCullRect);
} else {
@@ -258,6 +259,8 @@ class PersistedStandardPicture extends PersistedPicture {
canvasSize: _optimalLocalCullRect.size,
paintCallback: () {
_canvas = _findOrCreateCanvas(_optimalLocalCullRect);
assert(_canvas is BitmapCanvas
&& (_canvas as BitmapCanvas)._elementCache == _elementCache);
if (_debugExplainSurfaceStats) {
final BitmapCanvas bitmapCanvas = _canvas;
_surfaceStatsFor(this).paintPixelCount +=
@@ -332,7 +335,7 @@ class PersistedStandardPicture extends PersistedPicture {
DebugCanvasReuseOverlay.instance.reusedCount++;
}
bestRecycledCanvas.bounds = bounds;
bestRecycledCanvas.elementCache = _elementCache;
bestRecycledCanvas.setElementCache(_elementCache);
return bestRecycledCanvas;
}
@@ -340,7 +343,7 @@ class PersistedStandardPicture extends PersistedPicture {
DebugCanvasReuseOverlay.instance.createdCount++;
}
final BitmapCanvas canvas = BitmapCanvas(bounds);
canvas.elementCache = _elementCache;
canvas.setElementCache(_elementCache);
if (_debugExplainSurfaceStats) {
_surfaceStatsFor(this)
..allocateBitmapCanvasCount += 1