Add a new gm for large kernel matrix convolution

As a precursor to 263495, we need test coverage for this.

According to Skia Gold, the current matrix convolution implementation test is showing very different results on CPU & GPU. On the CPU, the last test case turns blue! See closest negative here: https://gold.skia.org/search?fdiffmax=-1&fref=false&frgbamax=255&frgbamin=0&head=true&include=false&limit=50&master=false&match=name&metric=combined&neg=true&new_clstore=true&offset=0&pos=true&query=cpu_or_gpu%3DGPU%26name%3Dmatrixconvolution_color%26source_type%3Dgm&sort=desc&unt=true

Change-Id: I4569e0fd0ec953dc75dbb99516d69741514efb60
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/264517
Auto-Submit: Adlai Holler <adlai@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
Adlai Holler 2020-01-14 21:02:37 -08:00 committed by Skia Commit-Bot
parent 7655168e68
commit bd1466cd4e

View File

@ -24,12 +24,20 @@
#include "include/effects/SkImageFilters.h"
#include "tools/ToolUtils.h"
#include <vector>
namespace skiagm {
enum KernelFixture {
kBasic_KernelFixture,
kLarge_KernelFixture
};
class MatrixConvolutionGM : public GM {
public:
MatrixConvolutionGM(SkColor colorOne, SkColor colorTwo, const char* nameSuffix)
: fNameSuffix(nameSuffix) {
MatrixConvolutionGM(SkColor colorOne, SkColor colorTwo, KernelFixture kernelFixture, const char* nameSuffix)
: fNameSuffix(nameSuffix),
fKernelFixture(kernelFixture) {
this->setBGColor(0x00000000);
fColors[0] = colorOne;
fColors[1] = colorTwo;
@ -61,20 +69,32 @@ protected:
return SkISize::Make(500, 300);
}
sk_sp<SkImageFilter> makeFilter(const SkIPoint &kernelOffset, SkTileMode tileMode,
bool convolveAlpha, const SkIRect *cropRect = nullptr) {
switch (fKernelFixture) {
case kBasic_KernelFixture: {
// All 1s except center value, which is -7 (sum of 1).
std::vector<SkScalar> kernel(9, SkIntToScalar(1));
kernel[4] = SkIntToScalar(-7);
return SkImageFilters::MatrixConvolution({3,3}, kernel.data(), /* gain */ 0.3f, /* bias */ SkIntToScalar(100), kernelOffset, tileMode, convolveAlpha, nullptr, cropRect);
}
case kLarge_KernelFixture: {
// Intentionally go over the MAX_KERNEL_SIZE limit and trigger CPU fallback.
// All 1s except center value, which is -47 (sum of 1).
std::vector<SkScalar> kernel(49, SkIntToScalar(1));
kernel[24] = SkIntToScalar(-47);
return SkImageFilters::MatrixConvolution({7,7}, kernel.data(), /* gain */ 0.3f, /* bias */ SkIntToScalar(100), kernelOffset, tileMode, convolveAlpha, nullptr, cropRect);
}
default:
return nullptr;
}
}
void draw(SkCanvas* canvas, int x, int y, const SkIPoint& kernelOffset,
SkTileMode tileMode, bool convolveAlpha,
const SkIRect* cropRect = nullptr) {
SkScalar kernel[9] = {
SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1),
SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
};
SkISize kernelSize = SkISize::Make(3, 3);
SkScalar gain = 0.3f, bias = SkIntToScalar(100);
SkPaint paint;
paint.setImageFilter(SkImageFilters::MatrixConvolution(kernelSize, kernel, gain, bias,
kernelOffset, tileMode,
convolveAlpha, nullptr, cropRect));
paint.setImageFilter(this->makeFilter(kernelOffset, tileMode, convolveAlpha, cropRect));
canvas->save();
canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
const SkRect layerBounds = SkRect::MakeIWH(fBitmap.width(), fBitmap.height());
@ -117,13 +137,16 @@ private:
SkBitmap fBitmap;
SkColor fColors[2];
const char* fNameSuffix;
KernelFixture fKernelFixture;
typedef GM INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
DEF_GM(return new MatrixConvolutionGM(0xFFFFFFFF, 0x40404040, "");)
DEF_GM(return new MatrixConvolutionGM(0xFFFF0000, 0xFF00FF00, "_color");)
DEF_GM(return new MatrixConvolutionGM(0xFFFFFFFF, 0x40404040, KernelFixture::kBasic_KernelFixture, "");)
DEF_GM(return new MatrixConvolutionGM(0xFFFF0000, 0xFF00FF00, KernelFixture::kBasic_KernelFixture, "_color");)
DEF_GM(return new MatrixConvolutionGM(0xFFFFFFFF, 0x40404040, KernelFixture::kLarge_KernelFixture, "_big");)
DEF_GM(return new MatrixConvolutionGM(0xFFFF0000, 0xFF00FF00, KernelFixture::kLarge_KernelFixture, "_big_color");)
}