senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkMorphologyImageFilter.h" |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 9 | |
djsollen@google.com | 64a0ec3 | 2012-06-12 15:17:27 +0000 | [diff] [blame] | 10 | #include "SkBitmap.h" |
Cary Clark | a4083c9 | 2017-09-15 11:59:23 -0400 | [diff] [blame^] | 11 | #include "SkColorData.h" |
Mike Reed | 6d9f429 | 2017-07-06 12:32:55 -0400 | [diff] [blame] | 12 | #include "SkColorSpaceXformer.h" |
mtklein | d029ded | 2015-08-04 14:09:09 -0700 | [diff] [blame] | 13 | #include "SkOpts.h" |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 14 | #include "SkReadBuffer.h" |
djsollen@google.com | c73dd5c | 2012-08-07 15:54:32 +0000 | [diff] [blame] | 15 | #include "SkRect.h" |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 16 | #include "SkSpecialImage.h" |
mtklein | d029ded | 2015-08-04 14:09:09 -0700 | [diff] [blame] | 17 | #include "SkWriteBuffer.h" |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 18 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 19 | #if SK_SUPPORT_GPU |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 20 | #include "../private/GrGLSL.h" |
senorblanco@chromium.org | 302cffb | 2012-08-01 20:16:34 +0000 | [diff] [blame] | 21 | #include "GrContext.h" |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 22 | #include "GrCoordTransform.h" |
csmartdalton | 02fa32c | 2016-08-19 13:29:27 -0700 | [diff] [blame] | 23 | #include "GrFixedClip.h" |
Robert Phillips | 7f6cd90 | 2016-11-10 17:03:43 -0500 | [diff] [blame] | 24 | #include "GrRenderTargetContext.h" |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 25 | #include "GrTexture.h" |
Robert Phillips | 7f6cd90 | 2016-11-10 17:03:43 -0500 | [diff] [blame] | 26 | #include "GrTextureProxy.h" |
robertphillips | 1de87df | 2016-01-14 06:03:29 -0800 | [diff] [blame] | 27 | #include "SkGr.h" |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 28 | #include "glsl/GrGLSLFragmentProcessor.h" |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame] | 29 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 30 | #include "glsl/GrGLSLProgramDataManager.h" |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 31 | #include "glsl/GrGLSLUniformHandler.h" |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 32 | #endif |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 33 | |
robertphillips | 225db44 | 2016-04-17 14:27:05 -0700 | [diff] [blame] | 34 | sk_sp<SkImageFilter> SkDilateImageFilter::Make(int radiusX, int radiusY, |
| 35 | sk_sp<SkImageFilter> input, |
| 36 | const CropRect* cropRect) { |
| 37 | if (radiusX < 0 || radiusY < 0) { |
| 38 | return nullptr; |
| 39 | } |
| 40 | return sk_sp<SkImageFilter>(new SkDilateImageFilter(radiusX, radiusY, |
| 41 | std::move(input), |
| 42 | cropRect)); |
| 43 | } |
| 44 | |
| 45 | |
| 46 | sk_sp<SkImageFilter> SkErodeImageFilter::Make(int radiusX, int radiusY, |
| 47 | sk_sp<SkImageFilter> input, |
| 48 | const CropRect* cropRect) { |
| 49 | if (radiusX < 0 || radiusY < 0) { |
| 50 | return nullptr; |
| 51 | } |
| 52 | return sk_sp<SkImageFilter>(new SkErodeImageFilter(radiusX, radiusY, |
| 53 | std::move(input), |
| 54 | cropRect)); |
| 55 | } |
| 56 | |
senorblanco@chromium.org | 2bfe36b | 2014-01-20 19:58:28 +0000 | [diff] [blame] | 57 | SkMorphologyImageFilter::SkMorphologyImageFilter(int radiusX, |
| 58 | int radiusY, |
robertphillips | fc11b0a | 2016-04-05 09:09:36 -0700 | [diff] [blame] | 59 | sk_sp<SkImageFilter> input, |
senorblanco | 24e06d5 | 2015-03-18 12:11:33 -0700 | [diff] [blame] | 60 | const CropRect* cropRect) |
robertphillips | fc11b0a | 2016-04-05 09:09:36 -0700 | [diff] [blame] | 61 | : INHERITED(&input, 1, cropRect) |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 62 | , fRadius(SkISize::Make(radiusX, radiusY)) { |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 63 | } |
| 64 | |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 65 | void SkMorphologyImageFilter::flatten(SkWriteBuffer& buffer) const { |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 66 | this->INHERITED::flatten(buffer); |
tomhudson@google.com | 7558925 | 2012-04-10 17:42:21 +0000 | [diff] [blame] | 67 | buffer.writeInt(fRadius.fWidth); |
| 68 | buffer.writeInt(fRadius.fHeight); |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 69 | } |
| 70 | |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 71 | static void call_proc_X(SkMorphologyImageFilter::Proc procX, |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 72 | const SkBitmap& src, SkBitmap* dst, |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 73 | int radiusX, const SkIRect& bounds) { |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 74 | procX(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0), |
senorblanco@chromium.org | 0ded88d | 2014-01-24 15:43:50 +0000 | [diff] [blame] | 75 | radiusX, bounds.width(), bounds.height(), |
| 76 | src.rowBytesAsPixels(), dst->rowBytesAsPixels()); |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 77 | } |
| 78 | |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 79 | static void call_proc_Y(SkMorphologyImageFilter::Proc procY, |
| 80 | const SkPMColor* src, int srcRowBytesAsPixels, SkBitmap* dst, |
| 81 | int radiusY, const SkIRect& bounds) { |
| 82 | procY(src, dst->getAddr32(0, 0), |
senorblanco@chromium.org | 0ded88d | 2014-01-24 15:43:50 +0000 | [diff] [blame] | 83 | radiusY, bounds.height(), bounds.width(), |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 84 | srcRowBytesAsPixels, dst->rowBytesAsPixels()); |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 85 | } |
| 86 | |
senorblanco | e5e7984 | 2016-03-21 14:51:59 -0700 | [diff] [blame] | 87 | SkRect SkMorphologyImageFilter::computeFastBounds(const SkRect& src) const { |
| 88 | SkRect bounds = this->getInput(0) ? this->getInput(0)->computeFastBounds(src) : src; |
| 89 | bounds.outset(SkIntToScalar(fRadius.width()), SkIntToScalar(fRadius.height())); |
| 90 | return bounds; |
senorblanco@chromium.org | 336d1d7 | 2014-01-27 21:03:17 +0000 | [diff] [blame] | 91 | } |
| 92 | |
senorblanco | e5e7984 | 2016-03-21 14:51:59 -0700 | [diff] [blame] | 93 | SkIRect SkMorphologyImageFilter::onFilterNodeBounds(const SkIRect& src, const SkMatrix& ctm, |
| 94 | MapDirection) const { |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 95 | SkVector radius = SkVector::Make(SkIntToScalar(this->radius().width()), |
| 96 | SkIntToScalar(this->radius().height())); |
| 97 | ctm.mapVectors(&radius, 1); |
senorblanco | e5e7984 | 2016-03-21 14:51:59 -0700 | [diff] [blame] | 98 | return src.makeOutset(SkScalarCeilToInt(radius.x()), SkScalarCeilToInt(radius.y())); |
senorblanco@chromium.org | c4b12f1 | 2014-02-05 17:51:22 +0000 | [diff] [blame] | 99 | } |
| 100 | |
reed | 60c9b58 | 2016-04-03 09:11:13 -0700 | [diff] [blame] | 101 | sk_sp<SkFlattenable> SkErodeImageFilter::CreateProc(SkReadBuffer& buffer) { |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 102 | SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
| 103 | const int width = buffer.readInt(); |
| 104 | const int height = buffer.readInt(); |
robertphillips | fc11b0a | 2016-04-05 09:09:36 -0700 | [diff] [blame] | 105 | return Make(width, height, common.getInput(0), &common.cropRect()); |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 106 | } |
| 107 | |
reed | 60c9b58 | 2016-04-03 09:11:13 -0700 | [diff] [blame] | 108 | sk_sp<SkFlattenable> SkDilateImageFilter::CreateProc(SkReadBuffer& buffer) { |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 109 | SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
| 110 | const int width = buffer.readInt(); |
| 111 | const int height = buffer.readInt(); |
robertphillips | fc11b0a | 2016-04-05 09:09:36 -0700 | [diff] [blame] | 112 | return Make(width, height, common.getInput(0), &common.cropRect()); |
reed | 9fa60da | 2014-08-21 07:59:51 -0700 | [diff] [blame] | 113 | } |
| 114 | |
robertphillips | f3f5bad | 2014-12-19 13:49:15 -0800 | [diff] [blame] | 115 | #ifndef SK_IGNORE_TO_STRING |
| 116 | void SkErodeImageFilter::toString(SkString* str) const { |
| 117 | str->appendf("SkErodeImageFilter: ("); |
| 118 | str->appendf("radius: (%d,%d)", this->radius().fWidth, this->radius().fHeight); |
| 119 | str->append(")"); |
| 120 | } |
| 121 | #endif |
| 122 | |
| 123 | #ifndef SK_IGNORE_TO_STRING |
| 124 | void SkDilateImageFilter::toString(SkString* str) const { |
| 125 | str->appendf("SkDilateImageFilter: ("); |
| 126 | str->appendf("radius: (%d,%d)", this->radius().fWidth, this->radius().fHeight); |
| 127 | str->append(")"); |
| 128 | } |
| 129 | #endif |
| 130 | |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 131 | #if SK_SUPPORT_GPU |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 132 | |
| 133 | /////////////////////////////////////////////////////////////////////////////// |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 134 | /** |
| 135 | * Morphology effects. Depending upon the type of morphology, either the |
| 136 | * component-wise min (Erode_Type) or max (Dilate_Type) of all pixels in the |
| 137 | * kernel is selected as the new color. The new color is modulated by the input |
| 138 | * color. |
| 139 | */ |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 140 | class GrMorphologyEffect : public GrFragmentProcessor { |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 141 | public: |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 142 | enum class Direction { kX, kY }; |
| 143 | enum class Type { kErode, kDilate }; |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 144 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 145 | static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy, Direction dir, |
| 146 | int radius, Type type) { |
| 147 | return std::unique_ptr<GrFragmentProcessor>( |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 148 | new GrMorphologyEffect(std::move(proxy), dir, radius, type, nullptr)); |
Robert Phillips | dbc8eeb | 2017-02-21 10:04:31 -0500 | [diff] [blame] | 149 | } |
| 150 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 151 | static std::unique_ptr<GrFragmentProcessor> Make(sk_sp<GrTextureProxy> proxy, Direction dir, |
| 152 | int radius, Type type, const float bounds[2]) { |
| 153 | return std::unique_ptr<GrFragmentProcessor>( |
| 154 | new GrMorphologyEffect(std::move(proxy), dir, radius, type, bounds)); |
Robert Phillips | dbc8eeb | 2017-02-21 10:04:31 -0500 | [diff] [blame] | 155 | } |
| 156 | |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 157 | Type type() const { return fType; } |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 158 | bool useRange() const { return fUseRange; } |
| 159 | const float* range() const { return fRange; } |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 160 | Direction direction() const { return fDirection; } |
| 161 | int radius() const { return fRadius; } |
| 162 | int width() const { return 2 * fRadius + 1; } |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 163 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 164 | const char* name() const override { return "Morphology"; } |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 165 | |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 166 | std::unique_ptr<GrFragmentProcessor> clone() const override { |
| 167 | return std::unique_ptr<GrFragmentProcessor>(new GrMorphologyEffect(*this)); |
Brian Salomon | 13054a0 | 2017-07-28 10:15:47 -0400 | [diff] [blame] | 168 | } |
| 169 | |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 170 | private: |
| 171 | GrCoordTransform fCoordTransform; |
| 172 | TextureSampler fTextureSampler; |
| 173 | Direction fDirection; |
| 174 | int fRadius; |
| 175 | Type fType; |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 176 | bool fUseRange; |
| 177 | float fRange[2]; |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 178 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 179 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 180 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 181 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
wangyix | 4b3050b | 2015-08-04 07:59:37 -0700 | [diff] [blame] | 182 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 183 | bool onIsEqual(const GrFragmentProcessor&) const override; |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 184 | |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 185 | GrMorphologyEffect(sk_sp<GrTextureProxy>, Direction, int radius, Type, const float range[2]); |
Brian Salomon | 3f6f965 | 2017-07-28 07:34:05 -0400 | [diff] [blame] | 186 | explicit GrMorphologyEffect(const GrMorphologyEffect&); |
Robert Phillips | dbc8eeb | 2017-02-21 10:04:31 -0500 | [diff] [blame] | 187 | |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 188 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 189 | |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 190 | typedef GrFragmentProcessor INHERITED; |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 191 | }; |
| 192 | |
| 193 | /////////////////////////////////////////////////////////////////////////////// |
| 194 | |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 195 | class GrGLMorphologyEffect : public GrGLSLFragmentProcessor { |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 196 | public: |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 197 | void emitCode(EmitArgs&) override; |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 198 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 199 | static inline void GenKey(const GrProcessor&, const GrShaderCaps&, GrProcessorKeyBuilder*); |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 200 | |
wangyix | b1daa86 | 2015-08-18 11:29:31 -0700 | [diff] [blame] | 201 | protected: |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 202 | void onSetData(const GrGLSLProgramDataManager&, const GrFragmentProcessor&) override; |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 203 | |
| 204 | private: |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 205 | GrGLSLProgramDataManager::UniformHandle fPixelSizeUni; |
| 206 | GrGLSLProgramDataManager::UniformHandle fRangeUni; |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 207 | |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 208 | typedef GrGLSLFragmentProcessor INHERITED; |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 209 | }; |
| 210 | |
wangyix | 7c157a9 | 2015-07-22 15:08:53 -0700 | [diff] [blame] | 211 | void GrGLMorphologyEffect::emitCode(EmitArgs& args) { |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 212 | const GrMorphologyEffect& me = args.fFp.cast<GrMorphologyEffect>(); |
| 213 | |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 214 | GrGLSLUniformHandler* uniformHandler = args.fUniformHandler; |
Brian Salomon | 1d816b9 | 2017-08-17 11:07:59 -0400 | [diff] [blame] | 215 | fPixelSizeUni = uniformHandler->addUniform(kFragment_GrShaderFlag, |
| 216 | kFloat_GrSLType, kDefault_GrSLPrecision, |
| 217 | "PixelSize"); |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 218 | const char* pixelSizeInc = uniformHandler->getUniformCStr(fPixelSizeUni); |
Brian Salomon | 1d816b9 | 2017-08-17 11:07:59 -0400 | [diff] [blame] | 219 | fRangeUni = uniformHandler->addUniform(kFragment_GrShaderFlag, |
| 220 | kVec2f_GrSLType, kDefault_GrSLPrecision, |
| 221 | "Range"); |
egdaniel | 7ea439b | 2015-12-03 09:20:44 -0800 | [diff] [blame] | 222 | const char* range = uniformHandler->getUniformCStr(fRangeUni); |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 223 | |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 224 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
bsalomon | 1a1aa93 | 2016-09-12 09:30:36 -0700 | [diff] [blame] | 225 | SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]); |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 226 | const char* func; |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 227 | switch (me.type()) { |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 228 | case GrMorphologyEffect::Type::kErode: |
Brian Salomon | 1d816b9 | 2017-08-17 11:07:59 -0400 | [diff] [blame] | 229 | fragBuilder->codeAppendf("\t\t%s = float4(1, 1, 1, 1);\n", args.fOutputColor); |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 230 | func = "min"; |
| 231 | break; |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 232 | case GrMorphologyEffect::Type::kDilate: |
Brian Salomon | 1d816b9 | 2017-08-17 11:07:59 -0400 | [diff] [blame] | 233 | fragBuilder->codeAppendf("\t\t%s = float4(0, 0, 0, 0);\n", args.fOutputColor); |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 234 | func = "max"; |
| 235 | break; |
| 236 | default: |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 237 | SK_ABORT("Unexpected type"); |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 238 | func = ""; // suppress warning |
| 239 | break; |
| 240 | } |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 241 | |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 242 | const char* dir; |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 243 | switch (me.direction()) { |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 244 | case GrMorphologyEffect::Direction::kX: |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 245 | dir = "x"; |
| 246 | break; |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 247 | case GrMorphologyEffect::Direction::kY: |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 248 | dir = "y"; |
| 249 | break; |
| 250 | default: |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 251 | SK_ABORT("Unknown filter direction."); |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 252 | dir = ""; // suppress warning |
| 253 | } |
| 254 | |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 255 | int width = me.width(); |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 256 | |
Ethan Nicholas | 5af9ea3 | 2017-07-28 15:19:46 -0400 | [diff] [blame] | 257 | // float2 coord = coord2D; |
Brian Salomon | 1d816b9 | 2017-08-17 11:07:59 -0400 | [diff] [blame] | 258 | fragBuilder->codeAppendf("\t\tfloat2 coord = %s;\n", coords2D.c_str()); |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 259 | // coord.x -= radius * pixelSize; |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 260 | fragBuilder->codeAppendf("\t\tcoord.%s -= %d.0 * %s; \n", dir, me.radius(), pixelSizeInc); |
| 261 | if (me.useRange()) { |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 262 | // highBound = min(highBound, coord.x + (width-1) * pixelSize); |
Brian Salomon | 1d816b9 | 2017-08-17 11:07:59 -0400 | [diff] [blame] | 263 | fragBuilder->codeAppendf("\t\tfloat highBound = min(%s.y, coord.%s + %f * %s);", |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 264 | range, dir, float(width - 1), pixelSizeInc); |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 265 | // coord.x = max(lowBound, coord.x); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 266 | fragBuilder->codeAppendf("\t\tcoord.%s = max(%s.x, coord.%s);", dir, range, dir); |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 267 | } |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 268 | fragBuilder->codeAppendf("\t\tfor (int i = 0; i < %d; i++) {\n", width); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 269 | fragBuilder->codeAppendf("\t\t\t%s = %s(%s, ", args.fOutputColor, func, args.fOutputColor); |
cdalton | 3f6f76f | 2016-04-11 12:18:09 -0700 | [diff] [blame] | 270 | fragBuilder->appendTextureLookup(args.fTexSamplers[0], "coord"); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 271 | fragBuilder->codeAppend(");\n"); |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 272 | // coord.x += pixelSize; |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 273 | fragBuilder->codeAppendf("\t\t\tcoord.%s += %s;\n", dir, pixelSizeInc); |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 274 | if (me.useRange()) { |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 275 | // coord.x = min(highBound, coord.x); |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 276 | fragBuilder->codeAppendf("\t\t\tcoord.%s = min(highBound, coord.%s);", dir, dir); |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 277 | } |
egdaniel | 4ca2e60 | 2015-11-18 08:01:26 -0800 | [diff] [blame] | 278 | fragBuilder->codeAppend("\t\t}\n"); |
Ethan Nicholas | 2983f40 | 2017-05-08 09:36:08 -0400 | [diff] [blame] | 279 | fragBuilder->codeAppendf("%s *= %s;\n", args.fOutputColor, args.fInputColor); |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 280 | } |
| 281 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 282 | void GrGLMorphologyEffect::GenKey(const GrProcessor& proc, |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 283 | const GrShaderCaps&, GrProcessorKeyBuilder* b) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 284 | const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>(); |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 285 | uint32_t key = static_cast<uint32_t>(m.radius()); |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 286 | key |= (static_cast<uint32_t>(m.type()) << 8); |
| 287 | key |= (static_cast<uint32_t>(m.direction()) << 9); |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 288 | if (m.useRange()) { |
| 289 | key |= 1 << 10; |
| 290 | } |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 291 | b->add32(key); |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 292 | } |
| 293 | |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 294 | void GrGLMorphologyEffect::onSetData(const GrGLSLProgramDataManager& pdman, |
Brian Salomon | ab015ef | 2017-04-04 10:15:51 -0400 | [diff] [blame] | 295 | const GrFragmentProcessor& proc) { |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 296 | const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>(); |
Robert Phillips | c686ce3 | 2017-07-21 14:12:29 -0400 | [diff] [blame] | 297 | GrSurfaceProxy* proxy = m.textureSampler(0).proxy(); |
| 298 | GrTexture& texture = *proxy->priv().peekTexture(); |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 299 | |
| 300 | float pixelSize = 0.0f; |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 301 | switch (m.direction()) { |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 302 | case GrMorphologyEffect::Direction::kX: |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 303 | pixelSize = 1.0f / texture.width(); |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 304 | break; |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 305 | case GrMorphologyEffect::Direction::kY: |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 306 | pixelSize = 1.0f / texture.height(); |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 307 | break; |
| 308 | default: |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 309 | SK_ABORT("Unknown filter direction."); |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 310 | } |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 311 | pdman.set1f(fPixelSizeUni, pixelSize); |
| 312 | |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 313 | if (m.useRange()) { |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 314 | const float* range = m.range(); |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 315 | if (GrMorphologyEffect::Direction::kY == m.direction() && |
Robert Phillips | c686ce3 | 2017-07-21 14:12:29 -0400 | [diff] [blame] | 316 | proxy->origin() == kBottomLeft_GrSurfaceOrigin) { |
Robert Phillips | 7f6cd90 | 2016-11-10 17:03:43 -0500 | [diff] [blame] | 317 | pdman.set2f(fRangeUni, 1.0f - (range[1]*pixelSize), 1.0f - (range[0]*pixelSize)); |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 318 | } else { |
Robert Phillips | 7f6cd90 | 2016-11-10 17:03:43 -0500 | [diff] [blame] | 319 | pdman.set2f(fRangeUni, range[0] * pixelSize, range[1] * pixelSize); |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 320 | } |
| 321 | } |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | /////////////////////////////////////////////////////////////////////////////// |
| 325 | |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 326 | GrMorphologyEffect::GrMorphologyEffect(sk_sp<GrTextureProxy> proxy, |
Robert Phillips | dbc8eeb | 2017-02-21 10:04:31 -0500 | [diff] [blame] | 327 | Direction direction, |
| 328 | int radius, |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 329 | Type type, |
Robert Phillips | dbc8eeb | 2017-02-21 10:04:31 -0500 | [diff] [blame] | 330 | const float range[2]) |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 331 | : INHERITED(ModulateByConfigOptimizationFlags(proxy->config())) |
| 332 | , fCoordTransform(proxy.get()) |
| 333 | , fTextureSampler(std::move(proxy)) |
| 334 | , fDirection(direction) |
| 335 | , fRadius(radius) |
Robert Phillips | dbc8eeb | 2017-02-21 10:04:31 -0500 | [diff] [blame] | 336 | , fType(type) |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 337 | , fUseRange(SkToBool(range)) { |
Robert Phillips | dbc8eeb | 2017-02-21 10:04:31 -0500 | [diff] [blame] | 338 | this->initClassID<GrMorphologyEffect>(); |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 339 | this->addCoordTransform(&fCoordTransform); |
| 340 | this->addTextureSampler(&fTextureSampler); |
| 341 | if (fUseRange) { |
| 342 | fRange[0] = range[0]; |
| 343 | fRange[1] = range[1]; |
| 344 | } |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 345 | } |
| 346 | |
Brian Salomon | 3f6f965 | 2017-07-28 07:34:05 -0400 | [diff] [blame] | 347 | GrMorphologyEffect::GrMorphologyEffect(const GrMorphologyEffect& that) |
| 348 | : INHERITED(that.optimizationFlags()) |
| 349 | , fCoordTransform(that.fCoordTransform) |
| 350 | , fTextureSampler(that.fTextureSampler) |
| 351 | , fDirection(that.fDirection) |
| 352 | , fRadius(that.fRadius) |
| 353 | , fType(that.fType) |
| 354 | , fUseRange(that.fUseRange) { |
| 355 | this->initClassID<GrMorphologyEffect>(); |
| 356 | this->addCoordTransform(&fCoordTransform); |
| 357 | this->addTextureSampler(&fTextureSampler); |
| 358 | if (that.fUseRange) { |
| 359 | fRange[0] = that.fRange[0]; |
| 360 | fRange[1] = that.fRange[1]; |
| 361 | } |
| 362 | } |
| 363 | |
Brian Salomon | 94efbf5 | 2016-11-29 13:43:05 -0500 | [diff] [blame] | 364 | void GrMorphologyEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 365 | GrProcessorKeyBuilder* b) const { |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 366 | GrGLMorphologyEffect::GenKey(*this, caps, b); |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 367 | } |
| 368 | |
egdaniel | 57d3b03 | 2015-11-13 11:57:27 -0800 | [diff] [blame] | 369 | GrGLSLFragmentProcessor* GrMorphologyEffect::onCreateGLSLInstance() const { |
robertphillips | bf536af | 2016-02-04 06:11:53 -0800 | [diff] [blame] | 370 | return new GrGLMorphologyEffect; |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 371 | } |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 372 | bool GrMorphologyEffect::onIsEqual(const GrFragmentProcessor& sBase) const { |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 373 | const GrMorphologyEffect& s = sBase.cast<GrMorphologyEffect>(); |
bsalomon | 420d7e9 | 2014-10-16 09:18:09 -0700 | [diff] [blame] | 374 | return (this->radius() == s.radius() && |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 375 | this->direction() == s.direction() && |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 376 | this->useRange() == s.useRange() && |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 377 | this->type() == s.type()); |
| 378 | } |
| 379 | |
| 380 | /////////////////////////////////////////////////////////////////////////////// |
| 381 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 382 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrMorphologyEffect); |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 383 | |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 384 | #if GR_TEST_UTILS |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 385 | std::unique_ptr<GrFragmentProcessor> GrMorphologyEffect::TestCreate(GrProcessorTestData* d) { |
Robert Phillips | dbc8eeb | 2017-02-21 10:04:31 -0500 | [diff] [blame] | 386 | int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx |
| 387 | : GrProcessorUnitTest::kAlphaTextureIdx; |
| 388 | sk_sp<GrTextureProxy> proxy = d->textureProxy(texIdx); |
| 389 | |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 390 | Direction dir = d->fRandom->nextBool() ? Direction::kX : Direction::kY; |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 391 | static const int kMaxRadius = 10; |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame] | 392 | int radius = d->fRandom->nextRangeU(1, kMaxRadius); |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 393 | Type type = d->fRandom->nextBool() ? GrMorphologyEffect::Type::kErode |
| 394 | : GrMorphologyEffect::Type::kDilate; |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 395 | |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 396 | return GrMorphologyEffect::Make(std::move(proxy), dir, radius, type); |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 397 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 398 | #endif |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 399 | |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 400 | static void apply_morphology_rect(GrRenderTargetContext* renderTargetContext, |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 401 | const GrClip& clip, |
Robert Phillips | 32f2818 | 2017-02-28 16:20:03 -0500 | [diff] [blame] | 402 | sk_sp<GrTextureProxy> proxy, |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 403 | const SkIRect& srcRect, |
| 404 | const SkIRect& dstRect, |
| 405 | int radius, |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 406 | GrMorphologyEffect::Type morphType, |
Robert Phillips | 7f6cd90 | 2016-11-10 17:03:43 -0500 | [diff] [blame] | 407 | const float bounds[2], |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 408 | GrMorphologyEffect::Direction direction) { |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 409 | GrPaint paint; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 410 | paint.setGammaCorrect(renderTargetContext->isGammaCorrect()); |
Robert Phillips | 32f2818 | 2017-02-28 16:20:03 -0500 | [diff] [blame] | 411 | |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 412 | paint.addColorFragmentProcessor(GrMorphologyEffect::Make(std::move(proxy), |
Robert Phillips | 32f2818 | 2017-02-28 16:20:03 -0500 | [diff] [blame] | 413 | direction, radius, morphType, |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 414 | bounds)); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 415 | paint.setPorterDuffXPFactory(SkBlendMode::kSrc); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 416 | renderTargetContext->fillRectToRect(clip, std::move(paint), GrAA::kNo, SkMatrix::I(), |
| 417 | SkRect::Make(dstRect), SkRect::Make(srcRect)); |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 418 | } |
| 419 | |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 420 | static void apply_morphology_rect_no_bounds(GrRenderTargetContext* renderTargetContext, |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 421 | const GrClip& clip, |
Robert Phillips | 32f2818 | 2017-02-28 16:20:03 -0500 | [diff] [blame] | 422 | sk_sp<GrTextureProxy> proxy, |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 423 | const SkIRect& srcRect, |
| 424 | const SkIRect& dstRect, |
| 425 | int radius, |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 426 | GrMorphologyEffect::Type morphType, |
| 427 | GrMorphologyEffect::Direction direction) { |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 428 | GrPaint paint; |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 429 | paint.setGammaCorrect(renderTargetContext->isGammaCorrect()); |
Robert Phillips | 32f2818 | 2017-02-28 16:20:03 -0500 | [diff] [blame] | 430 | |
Robert Phillips | fbcef6e | 2017-06-15 12:07:18 -0400 | [diff] [blame] | 431 | paint.addColorFragmentProcessor(GrMorphologyEffect::Make(std::move(proxy), |
Robert Phillips | 32f2818 | 2017-02-28 16:20:03 -0500 | [diff] [blame] | 432 | direction, radius, morphType)); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 433 | paint.setPorterDuffXPFactory(SkBlendMode::kSrc); |
Brian Salomon | 82f4431 | 2017-01-11 13:42:54 -0500 | [diff] [blame] | 434 | renderTargetContext->fillRectToRect(clip, std::move(paint), GrAA::kNo, SkMatrix::I(), |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 435 | SkRect::Make(dstRect), SkRect::Make(srcRect)); |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 436 | } |
| 437 | |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 438 | static void apply_morphology_pass(GrRenderTargetContext* renderTargetContext, |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 439 | const GrClip& clip, |
Robert Phillips | 32f2818 | 2017-02-28 16:20:03 -0500 | [diff] [blame] | 440 | sk_sp<GrTextureProxy> textureProxy, |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 441 | const SkIRect& srcRect, |
| 442 | const SkIRect& dstRect, |
| 443 | int radius, |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 444 | GrMorphologyEffect::Type morphType, |
| 445 | GrMorphologyEffect::Direction direction) { |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 446 | float bounds[2] = { 0.0f, 1.0f }; |
| 447 | SkIRect lowerSrcRect = srcRect, lowerDstRect = dstRect; |
| 448 | SkIRect middleSrcRect = srcRect, middleDstRect = dstRect; |
| 449 | SkIRect upperSrcRect = srcRect, upperDstRect = dstRect; |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 450 | if (direction == GrMorphologyEffect::Direction::kX) { |
Robert Phillips | 7f6cd90 | 2016-11-10 17:03:43 -0500 | [diff] [blame] | 451 | bounds[0] = SkIntToScalar(srcRect.left()) + 0.5f; |
| 452 | bounds[1] = SkIntToScalar(srcRect.right()) - 0.5f; |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 453 | lowerSrcRect.fRight = srcRect.left() + radius; |
| 454 | lowerDstRect.fRight = dstRect.left() + radius; |
| 455 | upperSrcRect.fLeft = srcRect.right() - radius; |
| 456 | upperDstRect.fLeft = dstRect.right() - radius; |
| 457 | middleSrcRect.inset(radius, 0); |
| 458 | middleDstRect.inset(radius, 0); |
| 459 | } else { |
Robert Phillips | 7f6cd90 | 2016-11-10 17:03:43 -0500 | [diff] [blame] | 460 | bounds[0] = SkIntToScalar(srcRect.top()) + 0.5f; |
| 461 | bounds[1] = SkIntToScalar(srcRect.bottom()) - 0.5f; |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 462 | lowerSrcRect.fBottom = srcRect.top() + radius; |
| 463 | lowerDstRect.fBottom = dstRect.top() + radius; |
| 464 | upperSrcRect.fTop = srcRect.bottom() - radius; |
| 465 | upperDstRect.fTop = dstRect.bottom() - radius; |
| 466 | middleSrcRect.inset(0, radius); |
| 467 | middleDstRect.inset(0, radius); |
| 468 | } |
| 469 | if (middleSrcRect.fLeft - middleSrcRect.fRight >= 0) { |
| 470 | // radius covers srcRect; use bounds over entire draw |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 471 | apply_morphology_rect(renderTargetContext, clip, std::move(textureProxy), |
Robert Phillips | 7f6cd90 | 2016-11-10 17:03:43 -0500 | [diff] [blame] | 472 | srcRect, dstRect, radius, morphType, bounds, direction); |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 473 | } else { |
| 474 | // Draw upper and lower margins with bounds; middle without. |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 475 | apply_morphology_rect(renderTargetContext, clip, textureProxy, |
Robert Phillips | 7f6cd90 | 2016-11-10 17:03:43 -0500 | [diff] [blame] | 476 | lowerSrcRect, lowerDstRect, radius, morphType, bounds, direction); |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 477 | apply_morphology_rect(renderTargetContext, clip, textureProxy, |
Robert Phillips | 7f6cd90 | 2016-11-10 17:03:43 -0500 | [diff] [blame] | 478 | upperSrcRect, upperDstRect, radius, morphType, bounds, direction); |
Robert Phillips | 296b1cc | 2017-03-15 10:42:12 -0400 | [diff] [blame] | 479 | apply_morphology_rect_no_bounds(renderTargetContext, clip, std::move(textureProxy), |
Robert Phillips | 7f6cd90 | 2016-11-10 17:03:43 -0500 | [diff] [blame] | 480 | middleSrcRect, middleDstRect, radius, morphType, direction); |
cwallez | 80a61df | 2015-01-26 12:20:14 -0800 | [diff] [blame] | 481 | } |
| 482 | } |
| 483 | |
brianosman | 2a75e5d | 2016-09-22 07:15:37 -0700 | [diff] [blame] | 484 | static sk_sp<SkSpecialImage> apply_morphology( |
| 485 | GrContext* context, |
| 486 | SkSpecialImage* input, |
| 487 | const SkIRect& rect, |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 488 | GrMorphologyEffect::Type morphType, |
brianosman | 2a75e5d | 2016-09-22 07:15:37 -0700 | [diff] [blame] | 489 | SkISize radius, |
| 490 | const SkImageFilter::OutputProperties& outputProperties) { |
Robert Phillips | 8e1c4e6 | 2017-02-19 12:27:01 -0500 | [diff] [blame] | 491 | sk_sp<GrTextureProxy> srcTexture(input->asTextureProxyRef(context)); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 492 | SkASSERT(srcTexture); |
brianosman | 2a75e5d | 2016-09-22 07:15:37 -0700 | [diff] [blame] | 493 | sk_sp<SkColorSpace> colorSpace = sk_ref_sp(outputProperties.colorSpace()); |
brianosman | 2695eaa | 2016-09-21 06:45:09 -0700 | [diff] [blame] | 494 | GrPixelConfig config = GrRenderableConfigForColorSpace(colorSpace.get()); |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 495 | |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 496 | // setup new clip |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 497 | const GrFixedClip clip(SkIRect::MakeWH(srcTexture->width(), srcTexture->height())); |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 498 | |
robertphillips | d4c741e | 2016-04-28 09:55:15 -0700 | [diff] [blame] | 499 | const SkIRect dstRect = SkIRect::MakeWH(rect.width(), rect.height()); |
senorblanco@chromium.org | 8fcad98 | 2013-09-17 13:41:43 +0000 | [diff] [blame] | 500 | SkIRect srcRect = rect; |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 501 | |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 502 | SkASSERT(radius.width() > 0 || radius.height() > 0); |
| 503 | |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 504 | if (radius.fWidth > 0) { |
Robert Phillips | 7f6cd90 | 2016-11-10 17:03:43 -0500 | [diff] [blame] | 505 | sk_sp<GrRenderTargetContext> dstRTContext(context->makeDeferredRenderTargetContext( |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 506 | SkBackingFit::kApprox, rect.width(), rect.height(), config, colorSpace)); |
Robert Phillips | 7f6cd90 | 2016-11-10 17:03:43 -0500 | [diff] [blame] | 507 | if (!dstRTContext) { |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 508 | return nullptr; |
robertphillips | ff0ca5e | 2015-07-22 11:54:44 -0700 | [diff] [blame] | 509 | } |
| 510 | |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 511 | apply_morphology_pass(dstRTContext.get(), clip, std::move(srcTexture), srcRect, dstRect, |
| 512 | radius.fWidth, morphType, GrMorphologyEffect::Direction::kX); |
senorblanco@chromium.org | 8fcad98 | 2013-09-17 13:41:43 +0000 | [diff] [blame] | 513 | SkIRect clearRect = SkIRect::MakeXYWH(dstRect.fLeft, dstRect.fBottom, |
| 514 | dstRect.width(), radius.fHeight); |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 515 | GrColor clearColor = |
| 516 | GrMorphologyEffect::Type::kErode == morphType ? SK_ColorWHITE : SK_ColorTRANSPARENT; |
Robert Phillips | 7f6cd90 | 2016-11-10 17:03:43 -0500 | [diff] [blame] | 517 | dstRTContext->clear(&clearRect, clearColor, false); |
robertphillips | ff0ca5e | 2015-07-22 11:54:44 -0700 | [diff] [blame] | 518 | |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 519 | srcTexture = dstRTContext->asTextureProxyRef(); |
senorblanco@chromium.org | 8fcad98 | 2013-09-17 13:41:43 +0000 | [diff] [blame] | 520 | srcRect = dstRect; |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 521 | } |
| 522 | if (radius.fHeight > 0) { |
Robert Phillips | 7f6cd90 | 2016-11-10 17:03:43 -0500 | [diff] [blame] | 523 | sk_sp<GrRenderTargetContext> dstRTContext(context->makeDeferredRenderTargetContext( |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 524 | SkBackingFit::kApprox, rect.width(), rect.height(), config, colorSpace)); |
Robert Phillips | 7f6cd90 | 2016-11-10 17:03:43 -0500 | [diff] [blame] | 525 | if (!dstRTContext) { |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 526 | return nullptr; |
robertphillips | ff0ca5e | 2015-07-22 11:54:44 -0700 | [diff] [blame] | 527 | } |
| 528 | |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 529 | apply_morphology_pass(dstRTContext.get(), clip, std::move(srcTexture), srcRect, dstRect, |
| 530 | radius.fHeight, morphType, GrMorphologyEffect::Direction::kY); |
robertphillips | ff0ca5e | 2015-07-22 11:54:44 -0700 | [diff] [blame] | 531 | |
Robert Phillips | f200a90 | 2017-01-30 13:27:37 -0500 | [diff] [blame] | 532 | srcTexture = dstRTContext->asTextureProxyRef(); |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 533 | } |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 534 | |
Robert Phillips | 7f6cd90 | 2016-11-10 17:03:43 -0500 | [diff] [blame] | 535 | return SkSpecialImage::MakeDeferredFromGpu(context, |
| 536 | SkIRect::MakeWH(rect.width(), rect.height()), |
| 537 | kNeedNewImageUniqueID_SpecialImage, |
| 538 | std::move(srcTexture), std::move(colorSpace), |
| 539 | &input->props()); |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 540 | } |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 541 | #endif |
senorblanco@chromium.org | 84207c4 | 2012-08-22 20:51:19 +0000 | [diff] [blame] | 542 | |
robertphillips | 40d8d62 | 2016-03-30 08:09:56 -0700 | [diff] [blame] | 543 | sk_sp<SkSpecialImage> SkMorphologyImageFilter::onFilterImage(SkSpecialImage* source, |
| 544 | const Context& ctx, |
| 545 | SkIPoint* offset) const { |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 546 | SkIPoint inputOffset = SkIPoint::Make(0, 0); |
| 547 | sk_sp<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputOffset)); |
| 548 | if (!input) { |
| 549 | return nullptr; |
senorblanco@chromium.org | c2594f4 | 2013-01-30 19:08:47 +0000 | [diff] [blame] | 550 | } |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 551 | |
senorblanco@chromium.org | c2594f4 | 2013-01-30 19:08:47 +0000 | [diff] [blame] | 552 | SkIRect bounds; |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 553 | input = this->applyCropRect(this->mapContext(ctx), input.get(), &inputOffset, &bounds); |
| 554 | if (!input) { |
| 555 | return nullptr; |
senorblanco@chromium.org | 8fcad98 | 2013-09-17 13:41:43 +0000 | [diff] [blame] | 556 | } |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 557 | |
senorblanco@chromium.org | 2bfe36b | 2014-01-20 19:58:28 +0000 | [diff] [blame] | 558 | SkVector radius = SkVector::Make(SkIntToScalar(this->radius().width()), |
| 559 | SkIntToScalar(this->radius().height())); |
senorblanco@chromium.org | 4cb543d | 2014-03-14 15:44:01 +0000 | [diff] [blame] | 560 | ctx.ctm().mapVectors(&radius, 1); |
senorblanco@chromium.org | 2bfe36b | 2014-01-20 19:58:28 +0000 | [diff] [blame] | 561 | int width = SkScalarFloorToInt(radius.fX); |
| 562 | int height = SkScalarFloorToInt(radius.fY); |
senorblanco@chromium.org | 8fcad98 | 2013-09-17 13:41:43 +0000 | [diff] [blame] | 563 | |
| 564 | if (width < 0 || height < 0) { |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 565 | return nullptr; |
senorblanco@chromium.org | 8fcad98 | 2013-09-17 13:41:43 +0000 | [diff] [blame] | 566 | } |
| 567 | |
senorblanco@chromium.org | 2bfe36b | 2014-01-20 19:58:28 +0000 | [diff] [blame] | 568 | SkIRect srcBounds = bounds; |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 569 | srcBounds.offset(-inputOffset); |
| 570 | |
| 571 | if (0 == width && 0 == height) { |
senorblanco@chromium.org | 6776b82 | 2014-01-03 21:48:22 +0000 | [diff] [blame] | 572 | offset->fX = bounds.left(); |
| 573 | offset->fY = bounds.top(); |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 574 | return input->makeSubset(srcBounds); |
senorblanco@chromium.org | 8fcad98 | 2013-09-17 13:41:43 +0000 | [diff] [blame] | 575 | } |
| 576 | |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 577 | #if SK_SUPPORT_GPU |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 578 | if (source->isTextureBacked()) { |
| 579 | GrContext* context = source->getContext(); |
| 580 | |
Brian Osman | 615d66d | 2016-12-29 09:18:20 -0500 | [diff] [blame] | 581 | // Ensure the input is in the destination color space. Typically applyCropRect will have |
| 582 | // called pad_image to account for our dilation of bounds, so the result will already be |
| 583 | // moved to the destination color space. If a filter DAG avoids that, then we use this |
| 584 | // fall-back, which saves us from having to do the xform during the filter itself. |
| 585 | input = ImageToColorSpace(input.get(), ctx.outputProperties()); |
Brian Osman | 320573f | 2016-12-21 13:36:02 -0500 | [diff] [blame] | 586 | |
Brian Salomon | b133ffe | 2017-07-27 11:53:21 -0400 | [diff] [blame] | 587 | auto type = (kDilate_Op == this->op()) ? GrMorphologyEffect::Type::kDilate |
| 588 | : GrMorphologyEffect::Type::kErode; |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 589 | sk_sp<SkSpecialImage> result(apply_morphology(context, input.get(), srcBounds, type, |
brianosman | 2a75e5d | 2016-09-22 07:15:37 -0700 | [diff] [blame] | 590 | SkISize::Make(width, height), |
| 591 | ctx.outputProperties())); |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 592 | if (result) { |
| 593 | offset->fX = bounds.left(); |
| 594 | offset->fY = bounds.top(); |
| 595 | } |
| 596 | return result; |
| 597 | } |
| 598 | #endif |
| 599 | |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 600 | SkBitmap inputBM; |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 601 | |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 602 | if (!input->getROPixels(&inputBM)) { |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 603 | return nullptr; |
| 604 | } |
| 605 | |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 606 | if (inputBM.colorType() != kN32_SkColorType) { |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 607 | return nullptr; |
| 608 | } |
| 609 | |
| 610 | SkImageInfo info = SkImageInfo::Make(bounds.width(), bounds.height(), |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 611 | inputBM.colorType(), inputBM.alphaType()); |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 612 | |
| 613 | SkBitmap dst; |
| 614 | if (!dst.tryAllocPixels(info)) { |
| 615 | return nullptr; |
| 616 | } |
| 617 | |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 618 | SkMorphologyImageFilter::Proc procX, procY; |
| 619 | |
robertphillips | 40d8d62 | 2016-03-30 08:09:56 -0700 | [diff] [blame] | 620 | if (kDilate_Op == this->op()) { |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 621 | procX = SkOpts::dilate_x; |
| 622 | procY = SkOpts::dilate_y; |
| 623 | } else { |
| 624 | procX = SkOpts::erode_x; |
| 625 | procY = SkOpts::erode_y; |
| 626 | } |
| 627 | |
| 628 | if (width > 0 && height > 0) { |
| 629 | SkBitmap tmp; |
| 630 | if (!tmp.tryAllocPixels(info)) { |
| 631 | return nullptr; |
| 632 | } |
| 633 | |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 634 | call_proc_X(procX, inputBM, &tmp, width, srcBounds); |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 635 | SkIRect tmpBounds = SkIRect::MakeWH(srcBounds.width(), srcBounds.height()); |
| 636 | call_proc_Y(procY, |
| 637 | tmp.getAddr32(tmpBounds.left(), tmpBounds.top()), tmp.rowBytesAsPixels(), |
| 638 | &dst, height, tmpBounds); |
| 639 | } else if (width > 0) { |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 640 | call_proc_X(procX, inputBM, &dst, width, srcBounds); |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 641 | } else if (height > 0) { |
| 642 | call_proc_Y(procY, |
robertphillips | 6461251 | 2016-04-08 12:10:42 -0700 | [diff] [blame] | 643 | inputBM.getAddr32(srcBounds.left(), srcBounds.top()), |
| 644 | inputBM.rowBytesAsPixels(), |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 645 | &dst, height, srcBounds); |
senorblanco@chromium.org | 8fcad98 | 2013-09-17 13:41:43 +0000 | [diff] [blame] | 646 | } |
senorblanco@chromium.org | 6776b82 | 2014-01-03 21:48:22 +0000 | [diff] [blame] | 647 | offset->fX = bounds.left(); |
| 648 | offset->fY = bounds.top(); |
robertphillips | f299e71 | 2016-03-25 04:49:22 -0700 | [diff] [blame] | 649 | |
robertphillips | 3e30227 | 2016-04-20 11:48:36 -0700 | [diff] [blame] | 650 | return SkSpecialImage::MakeFromRaster(SkIRect::MakeWH(bounds.width(), bounds.height()), |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 651 | dst, &source->props()); |
senorblanco@chromium.org | 05054f1 | 2012-03-02 21:05:45 +0000 | [diff] [blame] | 652 | } |
Matt Sarett | 6d72ed9 | 2017-04-10 16:35:33 -0400 | [diff] [blame] | 653 | |
Mike Reed | 6d9f429 | 2017-07-06 12:32:55 -0400 | [diff] [blame] | 654 | sk_sp<SkImageFilter> SkMorphologyImageFilter::onMakeColorSpace(SkColorSpaceXformer* xformer) const{ |
Matt Sarett | 6d72ed9 | 2017-04-10 16:35:33 -0400 | [diff] [blame] | 655 | SkASSERT(1 == this->countInputs()); |
Mike Reed | 6d9f429 | 2017-07-06 12:32:55 -0400 | [diff] [blame] | 656 | auto input = xformer->apply(this->getInput(0)); |
| 657 | if (input.get() != this->getInput(0)) { |
| 658 | return (SkMorphologyImageFilter::kDilate_Op == this->op()) |
| 659 | ? SkDilateImageFilter::Make(fRadius.width(), fRadius.height(), std::move(input), |
| 660 | this->getCropRectIfSet()) |
| 661 | : SkErodeImageFilter::Make(fRadius.width(), fRadius.height(), std::move(input), |
| 662 | this->getCropRectIfSet()); |
Matt Sarett | 6d72ed9 | 2017-04-10 16:35:33 -0400 | [diff] [blame] | 663 | } |
Mike Reed | 6d9f429 | 2017-07-06 12:32:55 -0400 | [diff] [blame] | 664 | return this->refMe(); |
Matt Sarett | 6d72ed9 | 2017-04-10 16:35:33 -0400 | [diff] [blame] | 665 | } |