Skip to content

Commit

Permalink
[CanvasKit] Dispose the overlay surface when a platform view is dispo…
Browse files Browse the repository at this point in the history
…sed (#19546)
  • Loading branch information
Harry Terkelsen authored Jul 7, 2020
1 parent 3fe5edf commit a15bc1b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
21 changes: 12 additions & 9 deletions lib/web_ui/lib/src/engine/compositor/embedded_views.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.


part of engine;

/// This composites HTML views into the [ui.Scene].
Expand Down Expand Up @@ -255,7 +254,8 @@ class HtmlViewEmbedder {
final CkPath path = CkPath();
path.addRRect(mutator.rrect!);
_ensureSvgPathDefs();
html.Element pathDefs = _svgPathDefs!.querySelector('#sk_path_defs')!;
html.Element pathDefs =
_svgPathDefs!.querySelector('#sk_path_defs')!;
_clipPathCount += 1;
html.Element newClipPath =
html.Element.html('<clipPath id="svgClip$_clipPathCount">'
Expand All @@ -266,7 +266,8 @@ class HtmlViewEmbedder {
} else if (mutator.path != null) {
final CkPath path = mutator.path as CkPath;
_ensureSvgPathDefs();
html.Element pathDefs = _svgPathDefs!.querySelector('#sk_path_defs')!;
html.Element pathDefs =
_svgPathDefs!.querySelector('#sk_path_defs')!;
_clipPathCount += 1;
html.Element newClipPath =
html.Element.html('<clipPath id="svgClip$_clipPathCount">'
Expand Down Expand Up @@ -369,6 +370,8 @@ class HtmlViewEmbedder {
if (_overlays[viewId] != null) {
final Overlay overlay = _overlays[viewId]!;
overlay.surface.htmlElement?.remove();
overlay.surface.htmlElement = null;
overlay.skSurface?.dispose();
}
_overlays.remove(viewId);
_currentCompositionParams.remove(viewId);
Expand Down Expand Up @@ -402,10 +405,10 @@ class EmbeddedViewParams {
if (identical(this, other)) {
return true;
}
return other is EmbeddedViewParams
&& other.offset == offset
&& other.size == size
&& other.mutators == mutators;
return other is EmbeddedViewParams &&
other.offset == offset &&
other.size == size &&
other.mutators == mutators;
}

int get hashCode => ui.hashValues(offset, size, mutators);
Expand Down Expand Up @@ -524,8 +527,8 @@ class MutatorsStack extends Iterable<Mutator> {
if (identical(other, this)) {
return true;
}
return other is MutatorsStack
&& _listEquals<Mutator>(other._mutators, _mutators);
return other is MutatorsStack &&
_listEquals<Mutator>(other._mutators, _mutators);
}

int get hashCode => ui.hashList(_mutators);
Expand Down
10 changes: 9 additions & 1 deletion lib/web_ui/lib/src/engine/compositor/surface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class Surface {
}

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

void dispose() {
if (_isDisposed) {
return;
}
// Only resources from the current context can be disposed.
canvasKit.callMethod('setCurrentContext', <int>[_glContext]);
_surface.callMethod('dispose');
_grContext.callMethod('releaseResourcesAndAbandonContext');
_grContext.callMethod('delete');
_isDisposed = true;
}

bool _isDisposed = false;
}

0 comments on commit a15bc1b

Please sign in to comment.