Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Unified Diff: src/effects/SkMatrixConvolutionImageFilter.cpp

Issue 1881903004: Rewriting MatrixConvolution image filter with SSE and AVX2 Base URL: https://skia.googlesource.com/skia@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/effects/SkMatrixConvolutionImageFilter.cpp
diff --git a/src/effects/SkMatrixConvolutionImageFilter.cpp b/src/effects/SkMatrixConvolutionImageFilter.cpp
index 2a32fd5cdcebcfa9ac58e227a2af53c49104d419..20bee4ccd74f080cf06b1931c4531d60418a6026 100644
--- a/src/effects/SkMatrixConvolutionImageFilter.cpp
+++ b/src/effects/SkMatrixConvolutionImageFilter.cpp
@@ -13,6 +13,7 @@
#include "SkWriteBuffer.h"
#include "SkRect.h"
#include "SkUnPreMultiply.h"
+#include "SkOpts.h"
#if SK_SUPPORT_GPU
#include "effects/GrMatrixConvolutionEffect.h"
@@ -117,13 +118,6 @@ SkMatrixConvolutionImageFilter::~SkMatrixConvolutionImageFilter() {
delete[] fKernel;
}
-class UncheckedPixelFetcher {
-public:
- static inline SkPMColor fetch(const SkBitmap& src, int x, int y, const SkIRect& bounds) {
- return *src.getAddr32(x, y);
- }
-};
-
class ClampPixelFetcher {
public:
static inline SkPMColor fetch(const SkBitmap& src, int x, int y, const SkIRect& bounds) {
@@ -159,7 +153,7 @@ public:
}
};
-template<class PixelFetcher, bool convolveAlpha>
+template<class PixelFetcher>
void SkMatrixConvolutionImageFilter::filterPixels(const SkBitmap& src,
SkBitmap* result,
const SkIRect& r,
@@ -179,7 +173,7 @@ void SkMatrixConvolutionImageFilter::filterPixels(const SkBitmap& src,
y + cy - fKernelOffset.fY,
bounds);
SkScalar k = fKernel[cy * fKernelSize.fWidth + cx];
- if (convolveAlpha) {
+ if (fConvolveAlpha) {
Stephen White 2016/04/12 20:01:58 IIRC, this did actually have a measurable impact w
sumA += SkScalarMul(SkIntToScalar(SkGetPackedA32(s)), k);
}
sumR += SkScalarMul(SkIntToScalar(SkGetPackedR32(s)), k);
@@ -187,13 +181,13 @@ void SkMatrixConvolutionImageFilter::filterPixels(const SkBitmap& src,
sumB += SkScalarMul(SkIntToScalar(SkGetPackedB32(s)), k);
}
}
- int a = convolveAlpha
+ int a = fConvolveAlpha
? SkClampMax(SkScalarFloorToInt(SkScalarMul(sumA, fGain) + fBias), 255)
: 255;
int r = SkClampMax(SkScalarFloorToInt(SkScalarMul(sumR, fGain) + fBias), a);
int g = SkClampMax(SkScalarFloorToInt(SkScalarMul(sumG, fGain) + fBias), a);
int b = SkClampMax(SkScalarFloorToInt(SkScalarMul(sumB, fGain) + fBias), a);
- if (!convolveAlpha) {
+ if (!fConvolveAlpha) {
a = SkGetPackedA32(PixelFetcher::fetch(src, x, y, bounds));
*dptr++ = SkPreMultiplyARGB(a, r, g, b);
} else {
@@ -203,23 +197,22 @@ void SkMatrixConvolutionImageFilter::filterPixels(const SkBitmap& src,
}
}
-template<class PixelFetcher>
-void SkMatrixConvolutionImageFilter::filterPixels(const SkBitmap& src,
- SkBitmap* result,
- const SkIRect& rect,
- const SkIRect& bounds) const {
- if (fConvolveAlpha) {
- filterPixels<PixelFetcher, true>(src, result, rect, bounds);
- } else {
- filterPixels<PixelFetcher, false>(src, result, rect, bounds);
- }
-}
void SkMatrixConvolutionImageFilter::filterInteriorPixels(const SkBitmap& src,
SkBitmap* result,
const SkIRect& rect,
const SkIRect& bounds) const {
- filterPixels<UncheckedPixelFetcher>(src, result, rect, bounds);
+ SkOpts::matrix_convolution_image_filter_filter_pixels(
+ src,
Stephen White 2016/04/12 20:01:58 Please use spaces instead of tabs.
+ result,
+ rect,
+ bounds,
+ fConvolveAlpha,
+ fKernel,
+ fKernelSize,
+ fKernelOffset,
+ fGain,
+ fBias);
}
void SkMatrixConvolutionImageFilter::filterBorderPixels(const SkBitmap& src,

Powered by Google App Engine
This is Rietveld 408576698