Skip to content

Commit a15bc1b

Browse files
author
Harry Terkelsen
authored
[CanvasKit] Dispose the overlay surface when a platform view is disposed (#19546)
1 parent 3fe5edf commit a15bc1b

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

lib/web_ui/lib/src/engine/compositor/embedded_views.dart

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
65
part of engine;
76

87
/// This composites HTML views into the [ui.Scene].
@@ -255,7 +254,8 @@ class HtmlViewEmbedder {
255254
final CkPath path = CkPath();
256255
path.addRRect(mutator.rrect!);
257256
_ensureSvgPathDefs();
258-
html.Element pathDefs = _svgPathDefs!.querySelector('#sk_path_defs')!;
257+
html.Element pathDefs =
258+
_svgPathDefs!.querySelector('#sk_path_defs')!;
259259
_clipPathCount += 1;
260260
html.Element newClipPath =
261261
html.Element.html('<clipPath id="svgClip$_clipPathCount">'
@@ -266,7 +266,8 @@ class HtmlViewEmbedder {
266266
} else if (mutator.path != null) {
267267
final CkPath path = mutator.path as CkPath;
268268
_ensureSvgPathDefs();
269-
html.Element pathDefs = _svgPathDefs!.querySelector('#sk_path_defs')!;
269+
html.Element pathDefs =
270+
_svgPathDefs!.querySelector('#sk_path_defs')!;
270271
_clipPathCount += 1;
271272
html.Element newClipPath =
272273
html.Element.html('<clipPath id="svgClip$_clipPathCount">'
@@ -369,6 +370,8 @@ class HtmlViewEmbedder {
369370
if (_overlays[viewId] != null) {
370371
final Overlay overlay = _overlays[viewId]!;
371372
overlay.surface.htmlElement?.remove();
373+
overlay.surface.htmlElement = null;
374+
overlay.skSurface?.dispose();
372375
}
373376
_overlays.remove(viewId);
374377
_currentCompositionParams.remove(viewId);
@@ -402,10 +405,10 @@ class EmbeddedViewParams {
402405
if (identical(this, other)) {
403406
return true;
404407
}
405-
return other is EmbeddedViewParams
406-
&& other.offset == offset
407-
&& other.size == size
408-
&& other.mutators == mutators;
408+
return other is EmbeddedViewParams &&
409+
other.offset == offset &&
410+
other.size == size &&
411+
other.mutators == mutators;
409412
}
410413

411414
int get hashCode => ui.hashValues(offset, size, mutators);
@@ -524,8 +527,8 @@ class MutatorsStack extends Iterable<Mutator> {
524527
if (identical(other, this)) {
525528
return true;
526529
}
527-
return other is MutatorsStack
528-
&& _listEquals<Mutator>(other._mutators, _mutators);
530+
return other is MutatorsStack &&
531+
_listEquals<Mutator>(other._mutators, _mutators);
529532
}
530533

531534
int get hashCode => ui.hashList(_mutators);

lib/web_ui/lib/src/engine/compositor/surface.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class Surface {
134134
}
135135

136136
bool _presentSurface() {
137-
canvasKit.callMethod('setCurrentContext', <dynamic>[_surface!.context]);
137+
canvasKit.callMethod('setCurrentContext', <int>[_surface!.context]);
138138
_surface!.getCanvas().flush();
139139
return true;
140140
}
@@ -159,8 +159,16 @@ class CkSurface {
159159
int height() => _surface.callMethod('height');
160160

161161
void dispose() {
162+
if (_isDisposed) {
163+
return;
164+
}
165+
// Only resources from the current context can be disposed.
166+
canvasKit.callMethod('setCurrentContext', <int>[_glContext]);
162167
_surface.callMethod('dispose');
163168
_grContext.callMethod('releaseResourcesAndAbandonContext');
164169
_grContext.callMethod('delete');
170+
_isDisposed = true;
165171
}
172+
173+
bool _isDisposed = false;
166174
}

0 commit comments

Comments
 (0)