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

Conversation

@yjbanov
Copy link
Contributor

@yjbanov yjbanov commented Nov 16, 2020

Description

  • Make Image clones share the same SkiaObjectBox and track them using an int refCount (list of referrers is still available in debug mode, but in release mode we just increment/decrement refCount).
  • SkAnimatedImage stops implementing ui.Image (it doesn't need to).
  • Remove CkAnimatedImageCodec: it wasn't adding value; instead CkAnimagedImage now implements ui.Codec.
  • Call SkData.delete after converting it to a local Uint8List in toByteData, fixing a memory leak.

Related Issues

Progress towards flutter/flutter#67148.

Tests

Updated relevant existing tests.

Copy link
Contributor

@harryterkelsen harryterkelsen left a comment

Choose a reason for hiding this comment

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

LGTM. I didn't know we added this clone functionality to Image. What is the use case?

Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

Overall I think this makes sense, but I have concerns about using raw integer to do refcounting - it'd be very easy to break and makes each caller responsible for implementing the logic to not break it.

@override
void dispose() {
box.delete();
if (_disposed) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should probably throw here rather than make it idempotent. On the VM implementation, that's what we do, and in general in the framework we don't allow multiple-disposal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 144 to 146
if (_disposed) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

if (_refs.isEmpty) {
void unref(R debugWrapper) {
assert(!_isDeleted, 'Attempted to unref an already deleted Skia object.');
_refCount -= 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

this API frightens me. It'd be very easy for someone to make a mistake with it and call unref multiple times, which would artificially decrease the refcount.

I think we should still maintain a hash set of references, and only allow the caller to remove itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is handled by the assertion below, but I added an error message so we don't throw an empty AssertionError.

@yjbanov yjbanov requested a review from dnfield November 18, 2020 00:23
Copy link
Contributor

@dnfield dnfield left a comment

Choose a reason for hiding this comment

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

LGTM

@yjbanov yjbanov force-pushed the ck-image-ref-counting branch from 8cb07c1 to 9ef9577 Compare November 18, 2020 00:29
@yjbanov yjbanov added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Nov 18, 2020
@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label.

@fluttergithubbot fluttergithubbot removed the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Nov 18, 2020
@angjieli angjieli added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Nov 18, 2020
@yjbanov yjbanov merged commit 35a0b9f into flutter:master Nov 18, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Nov 18, 2020
chaselatta pushed a commit to chaselatta/engine that referenced this pull request Nov 30, 2020
…er#22549)

* Refactor SkiaObjectBox ref counting
* make CkAnimatedImage a Codec
* disallow double dispose; better assertion messages
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants