Some small cleanups for image filter code.
Use the 2-param flavour of mapVector instead of the 3-param, where possible.
Add an SkMatrixImageFilter test case to the tiling unit test.
R=junov@chromium.org
Review URL: https://codereview.chromium.org/277543002
git-svn-id: http://skia.googlecode.com/svn/trunk@14630 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/effects/SkBlurImageFilter.cpp b/src/effects/SkBlurImageFilter.cpp
index 63990ab..00064d4 100644
--- a/src/effects/SkBlurImageFilter.cpp
+++ b/src/effects/SkBlurImageFilter.cpp
@@ -169,8 +169,8 @@
return false;
}
- SkVector sigma, localSigma = SkVector::Make(fSigma.width(), fSigma.height());
- ctx.ctm().mapVectors(&sigma, &localSigma, 1);
+ SkVector sigma = SkVector::Make(fSigma.width(), fSigma.height());
+ ctx.ctm().mapVectors(&sigma, 1);
sigma.fX = SkMinScalar(sigma.fX, MAX_SIGMA);
sigma.fY = SkMinScalar(sigma.fY, MAX_SIGMA);
@@ -249,8 +249,8 @@
if (getInput(0) && !getInput(0)->filterBounds(src, ctm, &bounds)) {
return false;
}
- SkVector sigma, localSigma = SkVector::Make(fSigma.width(), fSigma.height());
- ctm.mapVectors(&sigma, &localSigma, 1);
+ SkVector sigma = SkVector::Make(fSigma.width(), fSigma.height());
+ ctm.mapVectors(&sigma, 1);
bounds.outset(SkScalarCeilToInt(SkScalarMul(sigma.x(), SkIntToScalar(3))),
SkScalarCeilToInt(SkScalarMul(sigma.y(), SkIntToScalar(3))));
*dst = bounds;
@@ -270,8 +270,8 @@
return false;
}
GrTexture* source = input.getTexture();
- SkVector sigma, localSigma = SkVector::Make(fSigma.width(), fSigma.height());
- ctx.ctm().mapVectors(&sigma, &localSigma, 1);
+ SkVector sigma = SkVector::Make(fSigma.width(), fSigma.height());
+ ctx.ctm().mapVectors(&sigma, 1);
sigma.fX = SkMinScalar(sigma.fX, MAX_SIGMA);
sigma.fY = SkMinScalar(sigma.fY, MAX_SIGMA);
offset->fX = rect.fLeft;
diff --git a/src/effects/SkDropShadowImageFilter.cpp b/src/effects/SkDropShadowImageFilter.cpp
index 66a4e8b..032acec 100644
--- a/src/effects/SkDropShadowImageFilter.cpp
+++ b/src/effects/SkDropShadowImageFilter.cpp
@@ -81,8 +81,8 @@
}
SkCanvas canvas(device.get());
- SkVector sigma, localSigma = SkVector::Make(fSigmaX, fSigmaY);
- ctx.ctm().mapVectors(&sigma, &localSigma, 1);
+ SkVector sigma = SkVector::Make(fSigmaX, fSigmaY);
+ ctx.ctm().mapVectors(&sigma, 1);
sigma.fX = SkMaxScalar(0, sigma.fX);
sigma.fY = SkMaxScalar(0, sigma.fY);
SkAutoTUnref<SkImageFilter> blurFilter(SkBlurImageFilter::Create(sigma.fX, sigma.fY));
@@ -92,8 +92,8 @@
paint.setImageFilter(blurFilter.get());
paint.setColorFilter(colorFilter.get());
paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
- SkVector offsetVec, localOffsetVec = SkVector::Make(fDx, fDy);
- ctx.ctm().mapVectors(&offsetVec, &localOffsetVec, 1);
+ SkVector offsetVec = SkVector::Make(fDx, fDy);
+ ctx.ctm().mapVectors(&offsetVec, 1);
canvas.translate(SkIntToScalar(srcOffset.fX - bounds.fLeft),
SkIntToScalar(srcOffset.fY - bounds.fTop));
canvas.drawBitmap(src, offsetVec.fX, offsetVec.fY, &paint);
@@ -124,12 +124,12 @@
if (getInput(0) && !getInput(0)->filterBounds(src, ctm, &bounds)) {
return false;
}
- SkVector offsetVec, localOffsetVec = SkVector::Make(fDx, fDy);
- ctm.mapVectors(&offsetVec, &localOffsetVec, 1);
+ SkVector offsetVec = SkVector::Make(fDx, fDy);
+ ctm.mapVectors(&offsetVec, 1);
bounds.offset(-SkScalarCeilToInt(offsetVec.x()),
-SkScalarCeilToInt(offsetVec.y()));
- SkVector sigma, localSigma = SkVector::Make(fSigmaX, fSigmaY);
- ctm.mapVectors(&sigma, &localSigma, 1);
+ SkVector sigma = SkVector::Make(fSigmaX, fSigmaY);
+ ctm.mapVectors(&sigma, 1);
bounds.outset(SkScalarCeilToInt(SkScalarMul(sigma.x(), SkIntToScalar(3))),
SkScalarCeilToInt(SkScalarMul(sigma.y(), SkIntToScalar(3))));
bounds.join(src);
diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp
index 91b2c09..613ec30 100644
--- a/tests/ImageFilterTest.cpp
+++ b/tests/ImageFilterTest.cpp
@@ -300,6 +300,9 @@
SkScalar gain = SK_Scalar1, bias = 0;
SkAutoTUnref<SkImageFilter> gradient_source(SkBitmapSource::Create(make_gradient_circle(64, 64)));
+ SkMatrix matrix;
+ matrix.setTranslate(SK_Scalar1, SK_Scalar1);
+ matrix.postRotate(SkIntToScalar(45), SK_Scalar1, SK_Scalar1);
struct {
const char* fName;
@@ -327,6 +330,7 @@
{ "erode", SkErodeImageFilter::Create(2, 3) },
{ "tile", SkTileImageFilter::Create(SkRect::MakeXYWH(0, 0, 50, 50),
SkRect::MakeXYWH(0, 0, 100, 100), NULL) },
+ { "matrix", SkMatrixImageFilter::Create(matrix, SkPaint::kLow_FilterLevel) },
};
SkBitmap untiledResult, tiledResult;