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"
|
|
|
|
|
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)
|
|
|
|
: fName("matrixconvolution") {
|
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);
|
|
|
|
fFilter = SkMatrixConvolutionImageFilter::Create(kernelSize, kernel, gain, bias, kernelOffset, tileMode, convolveAlpha);
|
2012-09-18 20:32:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~MatrixConvolutionBench() {
|
|
|
|
fFilter->unref();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() {
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
virtual void onDraw(const 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:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-09-18 20:32:34 +00:00
|
|
|
SkMatrixConvolutionImageFilter* fFilter;
|
|
|
|
SkString fName;
|
|
|
|
};
|
|
|
|
|
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); )
|