Skip to content
This repository has been archived by the owner on Feb 25, 2025. It is now read-only.

Commit

Permalink
Dispose pictures created in HtmlViewEmbedder.submitFrame (#57102)
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-simmons authored Dec 11, 2024
1 parent 23c4966 commit b59afdf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/web_ui/lib/src/engine/canvaskit/embedded_views.dart
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ class HtmlViewEmbedder {
.endRecording();
await rasterizer.rasterizeToCanvas(
renderCanvas.displayCanvas!, <CkPicture>[renderPicture]);
renderPicture.dispose();
}

for (final CkPictureRecorder recorder
Expand Down
31 changes: 31 additions & 0 deletions lib/web_ui/test/canvaskit/embedded_views_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ void testMain() {
tearDown(() {
PlatformViewManager.instance.debugClear();
CanvasKitRenderer.instance.debugClear();
Instrumentation.enabled = false;
});

test('embeds interactive platform views', () async {
Expand Down Expand Up @@ -1574,6 +1575,36 @@ void testMain() {
expect(picturesPerCanvasInSecondRendering, <int>[19]);
debugOverrideJsConfiguration(null);
});

test('disposes render pictures', () async {
Instrumentation.enabled = true;
Instrumentation.instance.debugCounters.clear();

ui_web.platformViewRegistry.registerViewFactory(
'test-view',
(int viewId) => createDomHTMLDivElement()..className = 'platform-view',
);

CkPicture rectPicture(ui.Rect rect) {
return paintPicture(rect, (CkCanvas canvas) {
canvas.drawRect(
rect, CkPaint()..color = const ui.Color.fromARGB(255, 255, 0, 0));
});
}
final CkPicture picture = rectPicture(const ui.Rect.fromLTWH(0, 0, 20, 20));

await createPlatformView(0, 'test-view');

final LayerSceneBuilder sb = LayerSceneBuilder();
sb.addPicture(ui.Offset.zero, picture);
sb.addPlatformView(0, width: 20, height: 20);
final LayerScene scene = sb.build();
await renderScene(scene);

picture.dispose();
final Map<String, int> debugCounters = Instrumentation.instance.debugCounters;
expect(debugCounters['Picture Created'], debugCounters['Picture Deleted']);
});
});
}

Expand Down

0 comments on commit b59afdf

Please sign in to comment.