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.
|
|
|
|
*/
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkString.h"
|
2019-08-05 15:25:23 +00:00
|
|
|
#include "include/core/SkTileMode.h"
|
|
|
|
#include "include/effects/SkImageFilters.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/utils/SkRandom.h"
|
2012-09-18 20:32:34 +00:00
|
|
|
|
2019-08-05 15:25:23 +00:00
|
|
|
#include "tools/ToolUtils.h"
|
2016-04-12 22:52:52 +00:00
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class MatrixConvolutionBench : public Benchmark {
|
2012-09-18 20:32:34 +00:00
|
|
|
public:
|
2019-08-05 15:25:23 +00:00
|
|
|
MatrixConvolutionBench(SkTileMode tileMode, bool convolveAlpha)
|
2016-04-12 22:52:52 +00:00
|
|
|
: fName(SkStringPrintf("matrixconvolution_%s%s",
|
2019-08-05 15:25:23 +00:00
|
|
|
ToolUtils::tilemode_name(tileMode),
|
2016-04-12 22:52:52 +00:00
|
|
|
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);
|
2019-08-05 15:25:23 +00:00
|
|
|
fFilter = SkImageFilters::MatrixConvolution(kernelSize, kernel, gain, bias,
|
|
|
|
kernelOffset, tileMode, convolveAlpha, nullptr);
|
2012-09-18 20:32:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2019-08-05 15:25:23 +00:00
|
|
|
const char* onGetName() override {
|
2012-09-18 20:32:34 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2019-08-05 15:25:23 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2012-09-18 20:32:34 +00:00
|
|
|
SkPaint paint;
|
|
|
|
this->setupPaint(&paint);
|
2019-08-05 15:25:23 +00:00
|
|
|
paint.setImageFilter(fFilter);
|
2012-09-18 20:32:34 +00:00
|
|
|
paint.setAntiAlias(true);
|
2019-08-05 15:25:23 +00:00
|
|
|
|
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);
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2019-08-05 15:25:23 +00:00
|
|
|
DEF_BENCH( return new MatrixConvolutionBench(SkTileMode::kClamp, true); )
|
|
|
|
DEF_BENCH( return new MatrixConvolutionBench(SkTileMode::kRepeat, true); )
|
|
|
|
DEF_BENCH( return new MatrixConvolutionBench(SkTileMode::kMirror, true); )
|
|
|
|
DEF_BENCH( return new MatrixConvolutionBench(SkTileMode::kDecal, true); )
|
|
|
|
DEF_BENCH( return new MatrixConvolutionBench(SkTileMode::kDecal, false); )
|