2012-09-18 20:32:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2012-09-18 20:32:34 +00:00
|
|
|
#include "SkCanvas.h"
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "SkMatrixConvolutionImageFilter.h"
|
2012-09-18 20:32:34 +00:00
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
|
2016-04-12 22:52:52 +00:00
|
|
|
static const char* name(SkMatrixConvolutionImageFilter::TileMode mode) {
|
|
|
|
switch (mode) {
|
|
|
|
case SkMatrixConvolutionImageFilter::kClamp_TileMode: return "clamp";
|
|
|
|
case SkMatrixConvolutionImageFilter::kRepeat_TileMode: return "repeat";
|
|
|
|
case SkMatrixConvolutionImageFilter::kClampToBlack_TileMode: return "clampToBlack";
|
|
|
|
}
|
|
|
|
return "oops";
|
|
|
|
}
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class MatrixConvolutionBench : public Benchmark {
|
2012-09-18 20:32:34 +00:00
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
MatrixConvolutionBench(SkMatrixConvolutionImageFilter::TileMode tileMode, bool convolveAlpha)
|
2016-04-12 22:52:52 +00:00
|
|
|
: fName(SkStringPrintf("matrixconvolution_%s%s",
|
|
|
|
name(tileMode),
|
|
|
|
convolveAlpha ? "" : "_noConvolveAlpha")) {
|
2012-09-18 20:32:34 +00:00
|
|
|
SkISize kernelSize = SkISize::Make(3, 3);
|
|
|
|
SkScalar kernel[9] = {
|
|
|
|
SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
|
|
|
|
SkIntToScalar( 1), SkIntToScalar(-7), SkIntToScalar( 1),
|
|
|
|
SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
|
|
|
|
};
|
2013-11-25 19:44:07 +00:00
|
|
|
SkScalar gain = 0.3f, bias = SkIntToScalar(100);
|
2014-03-12 16:36:08 +00:00
|
|
|
SkIPoint kernelOffset = SkIPoint::Make(1, 1);
|
2016-04-12 22:52:52 +00:00
|
|
|
fFilter = SkMatrixConvolutionImageFilter::Make(kernelSize, kernel, gain, bias,
|
2016-04-08 15:01:20 +00:00
|
|
|
kernelOffset, tileMode, convolveAlpha,
|
|
|
|
nullptr);
|
2012-09-18 20:32:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() {
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
virtual void onDraw(int loops, SkCanvas* canvas) {
|
2012-09-18 20:32:34 +00:00
|
|
|
SkPaint paint;
|
|
|
|
this->setupPaint(&paint);
|
|
|
|
paint.setAntiAlias(true);
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2012-09-18 20:32:34 +00:00
|
|
|
SkRect r = SkRect::MakeWH(rand.nextUScalar1() * 400,
|
|
|
|
rand.nextUScalar1() * 400);
|
|
|
|
paint.setImageFilter(fFilter);
|
|
|
|
canvas->drawOval(r, paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-04-08 15:01:20 +00:00
|
|
|
sk_sp<SkImageFilter> fFilter;
|
2012-09-18 20:32:34 +00:00
|
|
|
SkString fName;
|
2016-04-08 15:01:20 +00:00
|
|
|
|
|
|
|
typedef Benchmark INHERITED;
|
2012-09-18 20:32:34 +00:00
|
|
|
};
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new MatrixConvolutionBench(SkMatrixConvolutionImageFilter::kClamp_TileMode, true); )
|
|
|
|
DEF_BENCH( return new MatrixConvolutionBench(SkMatrixConvolutionImageFilter::kRepeat_TileMode, true); )
|
|
|
|
DEF_BENCH( return new MatrixConvolutionBench(SkMatrixConvolutionImageFilter::kClampToBlack_TileMode, true); )
|
|
|
|
DEF_BENCH( return new MatrixConvolutionBench(SkMatrixConvolutionImageFilter::kClampToBlack_TileMode, false); )
|