2 * Copyright 2012 The Android Open Source Project
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "SkMatrixConvolutionImageFilter.h"
10 #include "SkColorPriv.h"
11 #include "SkReadBuffer.h"
12 #include "SkWriteBuffer.h"
14 #include "SkUnPreMultiply.h"
17 #include "gl/GrGLEffect.h"
18 #include "effects/GrSingleTextureEffect.h"
19 #include "GrTBackendEffectFactory.h"
20 #include "GrTexture.h"
24 static bool tile_mode_is_valid(SkMatrixConvolutionImageFilter::TileMode tileMode) {
26 case SkMatrixConvolutionImageFilter::kClamp_TileMode:
27 case SkMatrixConvolutionImageFilter::kRepeat_TileMode:
28 case SkMatrixConvolutionImageFilter::kClampToBlack_TileMode:
36 SkMatrixConvolutionImageFilter::SkMatrixConvolutionImageFilter(
37 const SkISize& kernelSize,
38 const SkScalar* kernel,
41 const SkIPoint& target,
45 const CropRect* cropRect)
46 : INHERITED(input, cropRect),
47 fKernelSize(kernelSize),
52 fConvolveAlpha(convolveAlpha) {
53 uint32_t size = fKernelSize.fWidth * fKernelSize.fHeight;
54 fKernel = SkNEW_ARRAY(SkScalar, size);
55 memcpy(fKernel, kernel, size * sizeof(SkScalar));
56 SkASSERT(kernelSize.fWidth >= 1 && kernelSize.fHeight >= 1);
57 SkASSERT(target.fX >= 0 && target.fX < kernelSize.fWidth);
58 SkASSERT(target.fY >= 0 && target.fY < kernelSize.fHeight);
61 SkMatrixConvolutionImageFilter::SkMatrixConvolutionImageFilter(SkReadBuffer& buffer)
62 : INHERITED(1, buffer) {
63 // We need to be able to read at most SK_MaxS32 bytes, so divide that
64 // by the size of a scalar to know how many scalars we can read.
65 static const int32_t kMaxSize = SK_MaxS32 / sizeof(SkScalar);
66 fKernelSize.fWidth = buffer.readInt();
67 fKernelSize.fHeight = buffer.readInt();
68 if ((fKernelSize.fWidth >= 1) && (fKernelSize.fHeight >= 1) &&
69 // Make sure size won't be larger than a signed int,
70 // which would still be extremely large for a kernel,
71 // but we don't impose a hard limit for kernel size
72 (kMaxSize / fKernelSize.fWidth >= fKernelSize.fHeight)) {
73 size_t size = fKernelSize.fWidth * fKernelSize.fHeight;
74 fKernel = SkNEW_ARRAY(SkScalar, size);
75 SkDEBUGCODE(bool success =) buffer.readScalarArray(fKernel, size);
80 fGain = buffer.readScalar();
81 fBias = buffer.readScalar();
82 fTarget.fX = buffer.readInt();
83 fTarget.fY = buffer.readInt();
84 fTileMode = (TileMode) buffer.readInt();
85 fConvolveAlpha = buffer.readBool();
86 buffer.validate((fKernel != 0) &&
87 SkScalarIsFinite(fGain) &&
88 SkScalarIsFinite(fBias) &&
89 tile_mode_is_valid(fTileMode));
92 void SkMatrixConvolutionImageFilter::flatten(SkWriteBuffer& buffer) const {
93 this->INHERITED::flatten(buffer);
94 buffer.writeInt(fKernelSize.fWidth);
95 buffer.writeInt(fKernelSize.fHeight);
96 buffer.writeScalarArray(fKernel, fKernelSize.fWidth * fKernelSize.fHeight);
97 buffer.writeScalar(fGain);
98 buffer.writeScalar(fBias);
99 buffer.writeInt(fTarget.fX);
100 buffer.writeInt(fTarget.fY);
101 buffer.writeInt((int) fTileMode);
102 buffer.writeBool(fConvolveAlpha);
105 SkMatrixConvolutionImageFilter::~SkMatrixConvolutionImageFilter() {
109 class UncheckedPixelFetcher {
111 static inline SkPMColor fetch(const SkBitmap& src, int x, int y, const SkIRect& bounds) {
112 return *src.getAddr32(x, y);
116 class ClampPixelFetcher {
118 static inline SkPMColor fetch(const SkBitmap& src, int x, int y, const SkIRect& bounds) {
119 x = SkPin32(x, bounds.fLeft, bounds.fRight - 1);
120 y = SkPin32(y, bounds.fTop, bounds.fBottom - 1);
121 return *src.getAddr32(x, y);
125 class RepeatPixelFetcher {
127 static inline SkPMColor fetch(const SkBitmap& src, int x, int y, const SkIRect& bounds) {
128 x = (x - bounds.left()) % bounds.width() + bounds.left();
129 y = (y - bounds.top()) % bounds.height() + bounds.top();
130 if (x < bounds.left()) {
133 if (y < bounds.top()) {
134 y += bounds.height();
136 return *src.getAddr32(x, y);
140 class ClampToBlackPixelFetcher {
142 static inline SkPMColor fetch(const SkBitmap& src, int x, int y, const SkIRect& bounds) {
143 if (x < bounds.fLeft || x >= bounds.fRight || y < bounds.fTop || y >= bounds.fBottom) {
146 return *src.getAddr32(x, y);
151 template<class PixelFetcher, bool convolveAlpha>
152 void SkMatrixConvolutionImageFilter::filterPixels(const SkBitmap& src,
155 const SkIRect& bounds) const {
156 for (int y = rect.fTop; y < rect.fBottom; ++y) {
157 SkPMColor* dptr = result->getAddr32(rect.fLeft - bounds.fLeft, y - bounds.fTop);
158 for (int x = rect.fLeft; x < rect.fRight; ++x) {
159 SkScalar sumA = 0, sumR = 0, sumG = 0, sumB = 0;
160 for (int cy = 0; cy < fKernelSize.fHeight; cy++) {
161 for (int cx = 0; cx < fKernelSize.fWidth; cx++) {
162 SkPMColor s = PixelFetcher::fetch(src,
166 SkScalar k = fKernel[cy * fKernelSize.fWidth + cx];
168 sumA += SkScalarMul(SkIntToScalar(SkGetPackedA32(s)), k);
170 sumR += SkScalarMul(SkIntToScalar(SkGetPackedR32(s)), k);
171 sumG += SkScalarMul(SkIntToScalar(SkGetPackedG32(s)), k);
172 sumB += SkScalarMul(SkIntToScalar(SkGetPackedB32(s)), k);
175 int a = convolveAlpha
176 ? SkClampMax(SkScalarFloorToInt(SkScalarMul(sumA, fGain) + fBias), 255)
178 int r = SkClampMax(SkScalarFloorToInt(SkScalarMul(sumR, fGain) + fBias), a);
179 int g = SkClampMax(SkScalarFloorToInt(SkScalarMul(sumG, fGain) + fBias), a);
180 int b = SkClampMax(SkScalarFloorToInt(SkScalarMul(sumB, fGain) + fBias), a);
181 if (!convolveAlpha) {
182 a = SkGetPackedA32(PixelFetcher::fetch(src, x, y, bounds));
183 *dptr++ = SkPreMultiplyARGB(a, r, g, b);
185 *dptr++ = SkPackARGB32(a, r, g, b);
191 template<class PixelFetcher>
192 void SkMatrixConvolutionImageFilter::filterPixels(const SkBitmap& src,
195 const SkIRect& bounds) const {
196 if (fConvolveAlpha) {
197 filterPixels<PixelFetcher, true>(src, result, rect, bounds);
199 filterPixels<PixelFetcher, false>(src, result, rect, bounds);
203 void SkMatrixConvolutionImageFilter::filterInteriorPixels(const SkBitmap& src,
206 const SkIRect& bounds) const {
207 filterPixels<UncheckedPixelFetcher>(src, result, rect, bounds);
210 void SkMatrixConvolutionImageFilter::filterBorderPixels(const SkBitmap& src,
213 const SkIRect& bounds) const {
215 case kClamp_TileMode:
216 filterPixels<ClampPixelFetcher>(src, result, rect, bounds);
218 case kRepeat_TileMode:
219 filterPixels<RepeatPixelFetcher>(src, result, rect, bounds);
221 case kClampToBlack_TileMode:
222 filterPixels<ClampToBlackPixelFetcher>(src, result, rect, bounds);
227 // FIXME: This should be refactored to SkImageFilterUtils for
228 // use by other filters. For now, we assume the input is always
229 // premultiplied and unpremultiply it
230 static SkBitmap unpremultiplyBitmap(const SkBitmap& src)
232 SkAutoLockPixels alp(src);
233 if (!src.getPixels()) {
237 result.setConfig(src.config(), src.width(), src.height());
238 result.allocPixels();
239 if (!result.getPixels()) {
242 for (int y = 0; y < src.height(); ++y) {
243 const uint32_t* srcRow = src.getAddr32(0, y);
244 uint32_t* dstRow = result.getAddr32(0, y);
245 for (int x = 0; x < src.width(); ++x) {
246 dstRow[x] = SkUnPreMultiply::PMColorToColor(srcRow[x]);
252 bool SkMatrixConvolutionImageFilter::onFilterImage(Proxy* proxy,
253 const SkBitmap& source,
254 const SkMatrix& matrix,
256 SkIPoint* offset) const {
257 SkBitmap src = source;
258 SkIPoint srcOffset = SkIPoint::Make(0, 0);
259 if (getInput(0) && !getInput(0)->filterImage(proxy, source, matrix, &src, &srcOffset)) {
263 if (src.config() != SkBitmap::kARGB_8888_Config) {
268 src.getBounds(&bounds);
269 bounds.offset(srcOffset);
270 if (!this->applyCropRect(&bounds, matrix)) {
274 if (!fConvolveAlpha && !src.isOpaque()) {
275 src = unpremultiplyBitmap(src);
278 SkAutoLockPixels alp(src);
279 if (!src.getPixels()) {
283 result->setConfig(src.config(), bounds.width(), bounds.height());
284 result->allocPixels();
285 if (!result->getPixels()) {
289 offset->fX = bounds.fLeft;
290 offset->fY = bounds.fTop;
291 bounds.offset(-srcOffset);
292 SkIRect interior = SkIRect::MakeXYWH(bounds.left() + fTarget.fX,
293 bounds.top() + fTarget.fY,
294 bounds.width() - fKernelSize.fWidth + 1,
295 bounds.height() - fKernelSize.fHeight + 1);
296 SkIRect top = SkIRect::MakeLTRB(bounds.left(), bounds.top(), bounds.right(), interior.top());
297 SkIRect bottom = SkIRect::MakeLTRB(bounds.left(), interior.bottom(),
298 bounds.right(), bounds.bottom());
299 SkIRect left = SkIRect::MakeLTRB(bounds.left(), interior.top(),
300 interior.left(), interior.bottom());
301 SkIRect right = SkIRect::MakeLTRB(interior.right(), interior.top(),
302 bounds.right(), interior.bottom());
303 filterBorderPixels(src, result, top, bounds);
304 filterBorderPixels(src, result, left, bounds);
305 filterInteriorPixels(src, result, interior, bounds);
306 filterBorderPixels(src, result, right, bounds);
307 filterBorderPixels(src, result, bottom, bounds);
313 ///////////////////////////////////////////////////////////////////////////////
315 class GrGLMatrixConvolutionEffect;
317 class GrMatrixConvolutionEffect : public GrSingleTextureEffect {
319 typedef SkMatrixConvolutionImageFilter::TileMode TileMode;
320 static GrEffectRef* Create(GrTexture* texture,
321 const SkIRect& bounds,
322 const SkISize& kernelSize,
323 const SkScalar* kernel,
326 const SkIPoint& target,
328 bool convolveAlpha) {
329 AutoEffectUnref effect(SkNEW_ARGS(GrMatrixConvolutionEffect, (texture,
338 return CreateEffectRef(effect);
340 virtual ~GrMatrixConvolutionEffect();
342 virtual void getConstantColorComponents(GrColor* color,
343 uint32_t* validFlags) const SK_OVERRIDE {
344 // TODO: Try to do better?
348 static const char* Name() { return "MatrixConvolution"; }
349 const SkIRect& bounds() const { return fBounds; }
350 const SkISize& kernelSize() const { return fKernelSize; }
351 const float* target() const { return fTarget; }
352 const float* kernel() const { return fKernel; }
353 float gain() const { return fGain; }
354 float bias() const { return fBias; }
355 TileMode tileMode() const { return fTileMode; }
356 bool convolveAlpha() const { return fConvolveAlpha; }
358 typedef GrGLMatrixConvolutionEffect GLEffect;
360 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
363 GrMatrixConvolutionEffect(GrTexture*,
364 const SkIRect& bounds,
365 const SkISize& kernelSize,
366 const SkScalar* kernel,
369 const SkIPoint& target,
373 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE;
384 GR_DECLARE_EFFECT_TEST;
386 typedef GrSingleTextureEffect INHERITED;
389 class GrGLMatrixConvolutionEffect : public GrGLEffect {
391 GrGLMatrixConvolutionEffect(const GrBackendEffectFactory& factory,
392 const GrDrawEffect& effect);
393 virtual void emitCode(GrGLShaderBuilder*,
396 const char* outputColor,
397 const char* inputColor,
398 const TransformedCoordsArray&,
399 const TextureSamplerArray&) SK_OVERRIDE;
401 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
403 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
406 typedef GrGLUniformManager::UniformHandle UniformHandle;
407 typedef SkMatrixConvolutionImageFilter::TileMode TileMode;
412 UniformHandle fBoundsUni;
413 UniformHandle fKernelUni;
414 UniformHandle fImageIncrementUni;
415 UniformHandle fTargetUni;
416 UniformHandle fGainUni;
417 UniformHandle fBiasUni;
419 typedef GrGLEffect INHERITED;
422 GrGLMatrixConvolutionEffect::GrGLMatrixConvolutionEffect(const GrBackendEffectFactory& factory,
423 const GrDrawEffect& drawEffect)
424 : INHERITED(factory) {
425 const GrMatrixConvolutionEffect& m = drawEffect.castEffect<GrMatrixConvolutionEffect>();
426 fKernelSize = m.kernelSize();
427 fTileMode = m.tileMode();
428 fConvolveAlpha = m.convolveAlpha();
431 static void appendTextureLookup(GrGLShaderBuilder* builder,
432 const GrGLShaderBuilder::TextureSampler& sampler,
435 SkMatrixConvolutionImageFilter::TileMode tileMode) {
436 SkString clampedCoord;
438 case SkMatrixConvolutionImageFilter::kClamp_TileMode:
439 clampedCoord.printf("clamp(%s, %s.xy, %s.zw)", coord, bounds, bounds);
440 coord = clampedCoord.c_str();
442 case SkMatrixConvolutionImageFilter::kRepeat_TileMode:
443 clampedCoord.printf("mod(%s - %s.xy, %s.zw - %s.xy) + %s.xy", coord, bounds, bounds, bounds, bounds);
444 coord = clampedCoord.c_str();
446 case SkMatrixConvolutionImageFilter::kClampToBlack_TileMode:
447 builder->fsCodeAppendf("clamp(%s, %s.xy, %s.zw) != %s ? vec4(0, 0, 0, 0) : ", coord, bounds, bounds, coord);
450 builder->fsAppendTextureLookup(sampler, coord);
453 void GrGLMatrixConvolutionEffect::emitCode(GrGLShaderBuilder* builder,
456 const char* outputColor,
457 const char* inputColor,
458 const TransformedCoordsArray& coords,
459 const TextureSamplerArray& samplers) {
460 sk_ignore_unused_variable(inputColor);
461 SkString coords2D = builder->ensureFSCoords2D(coords, 0);
462 fBoundsUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
463 kVec4f_GrSLType, "Bounds");
464 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
465 kVec2f_GrSLType, "ImageIncrement");
466 fKernelUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_Visibility,
469 fKernelSize.width() * fKernelSize.height());
470 fTargetUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
471 kVec2f_GrSLType, "Target");
472 fGainUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
473 kFloat_GrSLType, "Gain");
474 fBiasUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
475 kFloat_GrSLType, "Bias");
477 const char* bounds = builder->getUniformCStr(fBoundsUni);
478 const char* target = builder->getUniformCStr(fTargetUni);
479 const char* imgInc = builder->getUniformCStr(fImageIncrementUni);
480 const char* kernel = builder->getUniformCStr(fKernelUni);
481 const char* gain = builder->getUniformCStr(fGainUni);
482 const char* bias = builder->getUniformCStr(fBiasUni);
483 int kWidth = fKernelSize.width();
484 int kHeight = fKernelSize.height();
486 builder->fsCodeAppend("\t\tvec4 sum = vec4(0, 0, 0, 0);\n");
487 builder->fsCodeAppendf("\t\tvec2 coord = %s - %s * %s;\n", coords2D.c_str(), target, imgInc);
488 builder->fsCodeAppendf("\t\tfor (int y = 0; y < %d; y++) {\n", kHeight);
489 builder->fsCodeAppendf("\t\t\tfor (int x = 0; x < %d; x++) {\n", kWidth);
490 builder->fsCodeAppendf("\t\t\t\tfloat k = %s[y * %d + x];\n", kernel, kWidth);
491 builder->fsCodeAppendf("\t\t\t\tvec2 coord2 = coord + vec2(x, y) * %s;\n", imgInc);
492 builder->fsCodeAppend("\t\t\t\tvec4 c = ");
493 appendTextureLookup(builder, samplers[0], "coord2", bounds, fTileMode);
494 builder->fsCodeAppend(";\n");
495 if (!fConvolveAlpha) {
496 builder->fsCodeAppend("\t\t\t\tc.rgb /= c.a;\n");
498 builder->fsCodeAppend("\t\t\t\tsum += c * k;\n");
499 builder->fsCodeAppend("\t\t\t}\n");
500 builder->fsCodeAppend("\t\t}\n");
501 if (fConvolveAlpha) {
502 builder->fsCodeAppendf("\t\t%s = sum * %s + %s;\n", outputColor, gain, bias);
503 builder->fsCodeAppendf("\t\t%s.rgb = clamp(%s.rgb, 0.0, %s.a);\n",
504 outputColor, outputColor, outputColor);
506 builder->fsCodeAppend("\t\tvec4 c = ");
507 appendTextureLookup(builder, samplers[0], coords2D.c_str(), bounds, fTileMode);
508 builder->fsCodeAppend(";\n");
509 builder->fsCodeAppendf("\t\t%s.a = c.a;\n", outputColor);
510 builder->fsCodeAppendf("\t\t%s.rgb = sum.rgb * %s + %s;\n", outputColor, gain, bias);
511 builder->fsCodeAppendf("\t\t%s.rgb *= %s.a;\n", outputColor, outputColor);
517 int encodeXY(int x, int y) {
518 SkASSERT(x >= 1 && y >= 1 && x * y <= 32);
520 return 0x40 | encodeXY(y, x);
522 return (0x40 >> x) | (y - x);
527 GrGLEffect::EffectKey GrGLMatrixConvolutionEffect::GenKey(const GrDrawEffect& drawEffect,
529 const GrMatrixConvolutionEffect& m = drawEffect.castEffect<GrMatrixConvolutionEffect>();
530 EffectKey key = encodeXY(m.kernelSize().width(), m.kernelSize().height());
531 key |= m.tileMode() << 7;
532 key |= m.convolveAlpha() ? 1 << 9 : 0;
536 void GrGLMatrixConvolutionEffect::setData(const GrGLUniformManager& uman,
537 const GrDrawEffect& drawEffect) {
538 const GrMatrixConvolutionEffect& conv = drawEffect.castEffect<GrMatrixConvolutionEffect>();
539 GrTexture& texture = *conv.texture(0);
540 // the code we generated was for a specific kernel size
541 SkASSERT(conv.kernelSize() == fKernelSize);
542 SkASSERT(conv.tileMode() == fTileMode);
543 float imageIncrement[2];
544 float ySign = texture.origin() == kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f;
545 imageIncrement[0] = 1.0f / texture.width();
546 imageIncrement[1] = ySign / texture.height();
547 uman.set2fv(fImageIncrementUni, 1, imageIncrement);
548 uman.set2fv(fTargetUni, 1, conv.target());
549 uman.set1fv(fKernelUni, fKernelSize.width() * fKernelSize.height(), conv.kernel());
550 uman.set1f(fGainUni, conv.gain());
551 uman.set1f(fBiasUni, conv.bias());
552 const SkIRect& bounds = conv.bounds();
553 float left = (float) bounds.left() / texture.width();
554 float top = (float) bounds.top() / texture.height();
555 float right = (float) bounds.right() / texture.width();
556 float bottom = (float) bounds.bottom() / texture.height();
557 if (texture.origin() == kBottomLeft_GrSurfaceOrigin) {
558 uman.set4f(fBoundsUni, left, 1.0f - bottom, right, 1.0f - top);
560 uman.set4f(fBoundsUni, left, top, right, bottom);
564 GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(GrTexture* texture,
565 const SkIRect& bounds,
566 const SkISize& kernelSize,
567 const SkScalar* kernel,
570 const SkIPoint& target,
573 : INHERITED(texture, MakeDivByTextureWHMatrix(texture)),
575 fKernelSize(kernelSize),
576 fGain(SkScalarToFloat(gain)),
577 fBias(SkScalarToFloat(bias) / 255.0f),
579 fConvolveAlpha(convolveAlpha) {
580 fKernel = new float[kernelSize.width() * kernelSize.height()];
581 for (int i = 0; i < kernelSize.width() * kernelSize.height(); i++) {
582 fKernel[i] = SkScalarToFloat(kernel[i]);
584 fTarget[0] = static_cast<float>(target.x());
585 fTarget[1] = static_cast<float>(target.y());
586 this->setWillNotUseInputColor();
589 GrMatrixConvolutionEffect::~GrMatrixConvolutionEffect() {
593 const GrBackendEffectFactory& GrMatrixConvolutionEffect::getFactory() const {
594 return GrTBackendEffectFactory<GrMatrixConvolutionEffect>::getInstance();
597 bool GrMatrixConvolutionEffect::onIsEqual(const GrEffect& sBase) const {
598 const GrMatrixConvolutionEffect& s = CastEffect<GrMatrixConvolutionEffect>(sBase);
599 return this->texture(0) == s.texture(0) &&
600 fKernelSize == s.kernelSize() &&
601 !memcmp(fKernel, s.kernel(),
602 fKernelSize.width() * fKernelSize.height() * sizeof(float)) &&
605 fTarget == s.target() &&
606 fTileMode == s.tileMode() &&
607 fConvolveAlpha == s.convolveAlpha();
610 GR_DEFINE_EFFECT_TEST(GrMatrixConvolutionEffect);
612 // A little bit less than the minimum # uniforms required by DX9SM2 (32).
613 // Allows for a 5x5 kernel (or 25x1, for that matter).
614 #define MAX_KERNEL_SIZE 25
616 GrEffectRef* GrMatrixConvolutionEffect::TestCreate(SkRandom* random,
618 const GrDrawTargetCaps&,
619 GrTexture* textures[]) {
620 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
621 GrEffectUnitTest::kAlphaTextureIdx;
622 int width = random->nextRangeU(1, MAX_KERNEL_SIZE);
623 int height = random->nextRangeU(1, MAX_KERNEL_SIZE / width);
624 SkISize kernelSize = SkISize::Make(width, height);
625 SkAutoTDeleteArray<SkScalar> kernel(new SkScalar[width * height]);
626 for (int i = 0; i < width * height; i++) {
627 kernel.get()[i] = random->nextSScalar1();
629 SkScalar gain = random->nextSScalar1();
630 SkScalar bias = random->nextSScalar1();
631 SkIPoint target = SkIPoint::Make(random->nextRangeU(0, kernelSize.width()),
632 random->nextRangeU(0, kernelSize.height()));
633 SkIRect bounds = SkIRect::MakeXYWH(random->nextRangeU(0, textures[texIdx]->width()),
634 random->nextRangeU(0, textures[texIdx]->height()),
635 random->nextRangeU(0, textures[texIdx]->width()),
636 random->nextRangeU(0, textures[texIdx]->height()));
637 TileMode tileMode = static_cast<TileMode>(random->nextRangeU(0, 2));
638 bool convolveAlpha = random->nextBool();
639 return GrMatrixConvolutionEffect::Create(textures[texIdx],
650 bool SkMatrixConvolutionImageFilter::asNewEffect(GrEffectRef** effect,
653 const SkIRect& bounds
656 return fKernelSize.width() * fKernelSize.height() <= MAX_KERNEL_SIZE;
658 SkASSERT(fKernelSize.width() * fKernelSize.height() <= MAX_KERNEL_SIZE);
659 *effect = GrMatrixConvolutionEffect::Create(texture,
671 ///////////////////////////////////////////////////////////////////////////////