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
[canvaskit] Add dilate and erode imagefilters #48553
Merged
harryterkelsen
merged 6 commits into
flutter:main
from
harryterkelsen:canvaskit-erode-and-dilate-imagefilter
May 22, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
03c7cbc
Add dilate and erode imagefilters
harryterkelsen 4bbf2ec
Add canvaskit_api tests
harryterkelsen 7a75651
Merge branch 'main' into canvaskit-erode-and-dilate-imagefilter
harryterkelsen a56958e
Merge branch 'main' into canvaskit-erode-and-dilate-imagefilter
harryterkelsen 916abf4
Merge branch 'main' into canvaskit-erode-and-dilate-imagefilter
harryterkelsen 29d2e25
Merge branch 'main' into canvaskit-erode-and-dilate-imagefilter
harryterkelsen 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 |
|---|---|---|
|
|
@@ -40,6 +40,11 @@ abstract class CkImageFilter implements CkManagedSkImageFilterConvertible { | |
| factory CkImageFilter.matrix( | ||
| {required Float64List matrix, | ||
| required ui.FilterQuality filterQuality}) = _CkMatrixImageFilter; | ||
| factory CkImageFilter.dilate( | ||
| {required double radiusX, | ||
| required double radiusY}) = _CkDilateImageFilter; | ||
| factory CkImageFilter.erode( | ||
| {required double radiusX, required double radiusY}) = _CkErodeImageFilter; | ||
| factory CkImageFilter.compose( | ||
| {required CkImageFilter outer, | ||
| required CkImageFilter inner}) = _CkComposeImageFilter; | ||
|
|
@@ -94,10 +99,9 @@ class _CkBlurImageFilter extends CkImageFilter { | |
| final SkImageFilter skImageFilter; | ||
| if (sigmaX == 0 && sigmaY == 0) { | ||
| skImageFilter = canvasKit.ImageFilter.MakeMatrixTransform( | ||
| toSkMatrixFromFloat32(Matrix4.identity().storage), | ||
| toSkFilterOptions(ui.FilterQuality.none), | ||
| null | ||
| ); | ||
| toSkMatrixFromFloat32(Matrix4.identity().storage), | ||
| toSkFilterOptions(ui.FilterQuality.none), | ||
| null); | ||
| } else { | ||
| skImageFilter = canvasKit.ImageFilter.MakeBlur( | ||
| sigmaX, | ||
|
|
@@ -146,7 +150,8 @@ class _CkMatrixImageFilter extends CkImageFilter { | |
| : matrix = Float64List.fromList(matrix), | ||
| _transform = Matrix4.fromFloat32List(toMatrix32(matrix)), | ||
| super._() { | ||
| final SkImageFilter skImageFilter = canvasKit.ImageFilter.MakeMatrixTransform( | ||
| final SkImageFilter skImageFilter = | ||
| canvasKit.ImageFilter.MakeMatrixTransform( | ||
| toSkMatrixFromFloat64(matrix), | ||
| toSkFilterOptions(filterQuality), | ||
| null, | ||
|
|
@@ -185,6 +190,86 @@ class _CkMatrixImageFilter extends CkImageFilter { | |
| Matrix4 get transform => _transform; | ||
| } | ||
|
|
||
| class _CkDilateImageFilter extends CkImageFilter { | ||
| _CkDilateImageFilter({required this.radiusX, required this.radiusY}) | ||
| : super._() { | ||
| final SkImageFilter skImageFilter = canvasKit.ImageFilter.MakeDilate( | ||
| radiusX, | ||
| radiusY, | ||
| null, | ||
| ); | ||
| _ref = UniqueRef<SkImageFilter>(this, skImageFilter, 'ImageFilter.dilate'); | ||
| } | ||
|
|
||
| final double radiusX; | ||
| final double radiusY; | ||
|
|
||
| late final UniqueRef<SkImageFilter> _ref; | ||
|
|
||
| @override | ||
| void imageFilter(SkImageFilterBorrow borrow) { | ||
| borrow(_ref.nativeObject); | ||
| } | ||
|
|
||
| @override | ||
| bool operator ==(Object other) { | ||
| if (runtimeType != other.runtimeType) { | ||
| return false; | ||
| } | ||
| return other is _CkDilateImageFilter && | ||
| other.radiusX == radiusX && | ||
| other.radiusY == radiusY; | ||
| } | ||
|
|
||
| @override | ||
| int get hashCode => Object.hash(radiusX, radiusY); | ||
|
|
||
| @override | ||
| String toString() { | ||
| return 'ImageFilter.dilate($radiusX, $radiusY)'; | ||
| } | ||
| } | ||
|
|
||
| class _CkErodeImageFilter extends CkImageFilter { | ||
| _CkErodeImageFilter({required this.radiusX, required this.radiusY}) | ||
| : super._() { | ||
| final SkImageFilter skImageFilter = canvasKit.ImageFilter.MakeErode( | ||
| radiusX, | ||
| radiusY, | ||
| null, | ||
| ); | ||
| _ref = UniqueRef<SkImageFilter>(this, skImageFilter, 'ImageFilter.erode'); | ||
|
Contributor
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 question about disposal here.
Contributor
Author
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 answer. |
||
| } | ||
|
|
||
| final double radiusX; | ||
| final double radiusY; | ||
|
|
||
| late final UniqueRef<SkImageFilter> _ref; | ||
|
|
||
| @override | ||
| void imageFilter(SkImageFilterBorrow borrow) { | ||
| borrow(_ref.nativeObject); | ||
| } | ||
|
|
||
| @override | ||
| bool operator ==(Object other) { | ||
| if (runtimeType != other.runtimeType) { | ||
| return false; | ||
| } | ||
| return other is _CkErodeImageFilter && | ||
| other.radiusX == radiusX && | ||
| other.radiusY == radiusY; | ||
| } | ||
|
|
||
| @override | ||
| int get hashCode => Object.hash(radiusX, radiusY); | ||
|
|
||
| @override | ||
| String toString() { | ||
| return 'ImageFilter.erode($radiusX, $radiusY)'; | ||
| } | ||
| } | ||
|
|
||
| class _CkComposeImageFilter extends CkImageFilter { | ||
| _CkComposeImageFilter({required this.outer, required this.inner}) | ||
| : super._() { | ||
|
|
||
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
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.
Who is responsible for calling
_ref.dispose()? Or do we leak these and let GC handle the clean-up?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.
We let GC handle it. Like
ui.Paint,ui.ImageFiltercan be created by the user and doesn't have adisposemethod. There are no places in the engine where we create a temporaryImageFilterto make use of explicit disposal.