-
Notifications
You must be signed in to change notification settings - Fork 6k
Allow Tile mode for blur filter and add new decal TileMode #22982
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3137,10 +3137,11 @@ class _ColorFilter extends NativeFieldWrapperClass2 { | |
| /// this class as a child layer filter. | ||
| abstract class ImageFilter { | ||
| /// Creates an image filter that applies a Gaussian blur. | ||
| factory ImageFilter.blur({ double sigmaX = 0.0, double sigmaY = 0.0 }) { | ||
| factory ImageFilter.blur({ double sigmaX = 0.0, double sigmaY = 0.0, TileMode tileMode = TileMode.clamp }) { | ||
| assert(sigmaX != null); // ignore: unnecessary_null_comparison | ||
| assert(sigmaY != null); // ignore: unnecessary_null_comparison | ||
| return _GaussianBlurImageFilter(sigmaX: sigmaX, sigmaY: sigmaY); | ||
| assert(tileMode != null); // ignore: unnecessary_null_comparison | ||
| return _GaussianBlurImageFilter(sigmaX: sigmaX, sigmaY: sigmaY, tileMode: tileMode); | ||
| } | ||
|
|
||
| /// Creates an image filter that applies a matrix transformation. | ||
|
|
@@ -3206,29 +3207,40 @@ class _MatrixImageFilter implements ImageFilter { | |
| } | ||
|
|
||
| class _GaussianBlurImageFilter implements ImageFilter { | ||
| _GaussianBlurImageFilter({ required this.sigmaX, required this.sigmaY }); | ||
| _GaussianBlurImageFilter({ required this.sigmaX, required this.sigmaY, required this.tileMode }); | ||
|
|
||
| final double sigmaX; | ||
| final double sigmaY; | ||
| final TileMode tileMode; | ||
|
|
||
| // MakeBlurFilter | ||
| late final _ImageFilter nativeFilter = _ImageFilter.blur(this); | ||
| @override | ||
| _ImageFilter _toNativeImageFilter() => nativeFilter; | ||
|
|
||
| String get _modeString { | ||
| switch(tileMode) { | ||
| case TileMode.clamp: return 'clamp'; | ||
| case TileMode.mirror: return 'mirror'; | ||
| case TileMode.repeated: return 'repeated'; | ||
| case TileMode.decal: return 'decal'; | ||
| } | ||
| } | ||
|
|
||
| @override | ||
| String get _shortDescription => 'blur($sigmaX, $sigmaY)'; | ||
| String get _shortDescription => 'blur($sigmaX, $sigmaY, $_modeString)'; | ||
|
|
||
| @override | ||
| String toString() => 'ImageFilter.blur($sigmaX, $sigmaY)'; | ||
| String toString() => 'ImageFilter.blur($sigmaX, $sigmaY, $_modeString)'; | ||
|
|
||
| @override | ||
| bool operator ==(Object other) { | ||
| if (other.runtimeType != runtimeType) | ||
| return false; | ||
| return other is _GaussianBlurImageFilter | ||
| && other.sigmaX == sigmaX | ||
| && other.sigmaY == sigmaY; | ||
| && other.sigmaY == sigmaY | ||
| && other.tileMode == tileMode; | ||
| } | ||
|
|
||
| @override | ||
|
|
@@ -3278,9 +3290,9 @@ class _ImageFilter extends NativeFieldWrapperClass2 { | |
| : assert(filter != null), // ignore: unnecessary_null_comparison | ||
| creator = filter { // ignore: prefer_initializing_formals | ||
| _constructor(); | ||
| _initBlur(filter.sigmaX, filter.sigmaY); | ||
| _initBlur(filter.sigmaX, filter.sigmaY, filter.tileMode.index); | ||
| } | ||
| void _initBlur(double sigmaX, double sigmaY) native 'ImageFilter_initBlur'; | ||
| void _initBlur(double sigmaX, double sigmaY, int tileMode) native 'ImageFilter_initBlur'; | ||
|
|
||
| /// Creates an image filter that applies a matrix transformation. | ||
| /// | ||
|
|
@@ -3330,14 +3342,21 @@ class Shader extends NativeFieldWrapperClass2 { | |
| Shader._(); | ||
| } | ||
|
|
||
| /// Defines what happens at the edge of the gradient. | ||
| /// Defines what happens at the edge of a gradient or the sampling of a source image | ||
| /// in an [ImageFilter]. | ||
| /// | ||
| /// A gradient is defined along a finite inner area. In the case of a linear | ||
| /// gradient, it's between the parallel lines that are orthogonal to the line | ||
| /// drawn between two points. In the case of radial gradients, it's the disc | ||
| /// that covers the circle centered on a particular point up to a given radius. | ||
| /// | ||
| /// This enum is used to define how the gradient should paint the regions | ||
| /// An image filter reads source samples from a source image and performs operations | ||
| /// on those samples to produce a result image. The bounds of the source image contain | ||
| /// the pixels over which it is defined, but the operation performed by the image | ||
| /// filter may need to combine those samples with other samples read from outside | ||
| /// the image - particularly in the case of a blur operation. | ||
| /// | ||
| /// This enum is used to define how the gradient or image filter should treat the regions | ||
| /// outside that defined inner area. | ||
| /// | ||
| /// See also: | ||
|
|
@@ -3349,13 +3368,16 @@ class Shader extends NativeFieldWrapperClass2 { | |
| /// * [dart:ui.Gradient], the low-level class used when dealing with the | ||
| /// [Paint.shader] property directly, with its [Gradient.linear] and | ||
| /// [Gradient.radial] constructors. | ||
| // These enum values must be kept in sync with SkShader::TileMode. | ||
| // These enum values must be kept in sync with SkTileMode. | ||
| enum TileMode { | ||
| /// Edge is clamped to the final color. | ||
| /// | ||
| /// The gradient will paint the all the regions outside the inner area with | ||
| /// the color of the point closest to that region. | ||
| /// the color of the point closest to that region. An image filter will continue | ||
| /// to read the nearest edge pixel of an image for all samples required from | ||
| /// outside the source image. | ||
| /// | ||
| ///  | ||
| ///  | ||
| clamp, | ||
|
|
||
|
|
@@ -3365,6 +3387,9 @@ enum TileMode { | |
| /// to 2.0, 2.0 to 3.0, and so forth (and for linear gradients, similarly from | ||
| /// -1.0 to 0.0, -2.0 to -1.0, etc). | ||
| /// | ||
| /// An image filter will treat the image as tiled across the sample space from | ||
| /// which it is reading. | ||
| /// | ||
| ///  | ||
| ///  | ||
| repeated, | ||
|
|
@@ -3376,9 +3401,19 @@ enum TileMode { | |
| /// 4.0 to 3.0, and so forth (and for linear gradients, similarly from in the | ||
| /// negative direction). | ||
| /// | ||
| /// An image filter will treat the image as tiled in an alternating forwards and | ||
| /// backwards or upwards and downwards direction across the sample space from which | ||
| /// it is reading. | ||
| /// | ||
| ///  | ||
| ///  | ||
| mirror, | ||
|
|
||
| /// Edge is transparent black. | ||
|
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. nit: maybe "Extrapolates the source image with transparent black (0x00000000) pixels, when the image filter samples outside of the bounds of the source image"?
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. The rest of the entries are documented as "Edge is ...". I agree that I don't like the way that is all phrased. I'll look for some better wording for all of them.
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. Updates pushed... |
||
| /// | ||
| /// The gradient or image sampling operation will evaluate as transparent black pixels | ||
| /// all regions outside of the image or primary gradient area. | ||
| decal, | ||
|
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. I guess decal is as good a name for this as any, and has the advantage of matching Skia. |
||
| } | ||
|
|
||
| Int32List _encodeColorList(List<Color> colors) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,4 +10,5 @@ enum TileMode { | |
| clamp, | ||
| repeated, | ||
| mirror, | ||
| decal, | ||
| } | ||
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.
nit: "An image filter will treat the image ..." makes me think
TileModeis a property of the image, not the filter.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.
"An image filter will treat its source as ..."?
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.
Updates pushed...