This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Implement Image.clone for CanvasKit #21555
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cd9cb1b
Implement Image.clone for CanvasKit
dnfield 1b3ae46
fix tests
dnfield a1deae3
Update skia_objects_cache_test.dart
dnfield 49ed2fa
Make SkiaObjectBox refcounted, fix test
dnfield 4594551
isDeleted/isAliasOf embind
dnfield 38f0221
asserts
dnfield f1727e0
copy paste error...
dnfield File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,8 +43,15 @@ class CkAnimatedImage implements ui.Image { | |
// being garbage-collected, or by an explicit call to [delete]. | ||
late final SkiaObjectBox box; | ||
|
||
CkAnimatedImage(this._skAnimatedImage) { | ||
box = SkiaObjectBox(this, _skAnimatedImage as SkDeletable); | ||
CkAnimatedImage(SkAnimatedImage skAnimatedImage) : this._(skAnimatedImage, null); | ||
|
||
CkAnimatedImage._(this._skAnimatedImage, SkiaObjectBox? boxToClone) { | ||
if (boxToClone != null) { | ||
assert(boxToClone.skObject == _skAnimatedImage); | ||
box = boxToClone.clone(this); | ||
} else { | ||
box = SkiaObjectBox(this, _skAnimatedImage as SkDeletable); | ||
} | ||
} | ||
|
||
@override | ||
|
@@ -53,13 +60,17 @@ class CkAnimatedImage implements ui.Image { | |
} | ||
|
||
@override | ||
ui.Image clone() => this; | ||
ui.Image clone() => CkAnimatedImage._(_skAnimatedImage, box); | ||
|
||
@override | ||
bool isCloneOf(ui.Image other) => other == this; | ||
bool isCloneOf(ui.Image other) { | ||
return other is CkAnimatedImage | ||
&& other._skAnimatedImage.isAliasOf(_skAnimatedImage); | ||
} | ||
|
||
@override | ||
List<StackTrace>? debugGetOpenHandleStackTraces() => null; | ||
List<StackTrace>? debugGetOpenHandleStackTraces() => box.debugGetStackTraces(); | ||
|
||
int get frameCount => _skAnimatedImage.getFrameCount(); | ||
|
||
/// Decodes the next frame and returns the frame duration. | ||
|
@@ -116,8 +127,15 @@ class CkImage implements ui.Image { | |
// being garbage-collected, or by an explicit call to [delete]. | ||
late final SkiaObjectBox box; | ||
|
||
CkImage(this.skImage) { | ||
box = SkiaObjectBox(this, skImage as SkDeletable); | ||
CkImage(SkImage skImage) : this._(skImage, null); | ||
|
||
CkImage._(this.skImage, SkiaObjectBox? boxToClone) { | ||
if (boxToClone != null) { | ||
assert(boxToClone.skObject == skImage); | ||
box = boxToClone.clone(this); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment as in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added these asserts |
||
} else { | ||
box = SkiaObjectBox(this, skImage as SkDeletable); | ||
} | ||
} | ||
|
||
@override | ||
|
@@ -126,13 +144,16 @@ class CkImage implements ui.Image { | |
} | ||
|
||
@override | ||
ui.Image clone() => this; | ||
ui.Image clone() => CkImage._(skImage, box); | ||
|
||
@override | ||
bool isCloneOf(ui.Image other) => other == this; | ||
bool isCloneOf(ui.Image other) { | ||
return other is CkImage | ||
&& other.skImage.isAliasOf(skImage); | ||
} | ||
|
||
@override | ||
List<StackTrace>? debugGetOpenHandleStackTraces() => null; | ||
List<StackTrace>? debugGetOpenHandleStackTraces() => box.debugGetStackTraces(); | ||
|
||
@override | ||
int get width => skImage.width(); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we assert that the image in
boxToClone
and_skAnimatedImage
are the same?Alternatively, we could split this into two specialized constructors.