Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also null it out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't because skSurface is final. It should be garbage collected anyways after overlay

}
_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;
}