skia2/bench/MatrixConvolutionBench.cpp
John Stiles 7571f9e490 Replace 'typedef xxxxx INHERITED' with 'using INHERITED = xxxx;'.
Mechanically updated via Xcode "Replace Regular Expression":

  typedef (.*) INHERITED;
    -->
  using INHERITED = $1;

The ClangTidy approach generated an even larger CL which would have
required a significant amount of hand-tweaking to be usable.

Change-Id: I671dc9d9efdf6d60151325c8d4d13fad7e10a15b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/314999
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
2020-09-03 03:41:26 +00:00

88 lines
3.5 KiB
C++

/*
* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "bench/Benchmark.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkPaint.h"
#include "include/core/SkString.h"
#include "include/core/SkTileMode.h"
#include "include/effects/SkImageFilters.h"
#include "include/utils/SkRandom.h"
#include "tools/ToolUtils.h"
class MatrixConvolutionBench : public Benchmark {
public:
MatrixConvolutionBench(bool bigKernel, SkTileMode tileMode, bool convolveAlpha)
: fName(SkStringPrintf("matrixconvolution_%s%s%s",
bigKernel ? "bigKernel_" : "",
ToolUtils::tilemode_name(tileMode),
convolveAlpha ? "" : "_noConvolveAlpha")) {
if (bigKernel) {
SkISize kernelSize = SkISize::Make(9, 9);
SkScalar kernel[81];
for (int i = 0; i < 81; i++) {
kernel[i] = SkIntToScalar(1);
}
kernel[40] = SkIntToScalar(-79);
SkScalar gain = 0.3f, bias = SkIntToScalar(100);
SkIPoint kernelOffset = SkIPoint::Make(4, 4);
fFilter = SkImageFilters::MatrixConvolution(kernelSize, kernel, gain, bias,
kernelOffset, tileMode, convolveAlpha,
nullptr);
} else {
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),
};
SkScalar gain = 0.3f, bias = SkIntToScalar(100);
SkIPoint kernelOffset = SkIPoint::Make(1, 1);
fFilter = SkImageFilters::MatrixConvolution(kernelSize, kernel, gain, bias,
kernelOffset, tileMode, convolveAlpha,
nullptr);
}
}
protected:
const char* onGetName() override {
return fName.c_str();
}
void onDraw(int loops, SkCanvas* canvas) override {
SkPaint paint;
this->setupPaint(&paint);
paint.setImageFilter(fFilter);
paint.setAntiAlias(true);
SkRandom rand;
for (int i = 0; i < loops; i++) {
SkRect r = SkRect::MakeWH(rand.nextUScalar1() * 400,
rand.nextUScalar1() * 400);
canvas->drawOval(r, paint);
}
}
private:
sk_sp<SkImageFilter> fFilter;
SkString fName;
using INHERITED = Benchmark;
};
DEF_BENCH( return new MatrixConvolutionBench(false, SkTileMode::kClamp, true); )
DEF_BENCH( return new MatrixConvolutionBench(false, SkTileMode::kRepeat, true); )
DEF_BENCH( return new MatrixConvolutionBench(false, SkTileMode::kMirror, true); )
DEF_BENCH( return new MatrixConvolutionBench(false, SkTileMode::kDecal, true); )
DEF_BENCH( return new MatrixConvolutionBench(false, SkTileMode::kDecal, false); )
DEF_BENCH( return new MatrixConvolutionBench(true, SkTileMode::kClamp, true); )
DEF_BENCH( return new MatrixConvolutionBench(true, SkTileMode::kRepeat, true); )
DEF_BENCH( return new MatrixConvolutionBench(true, SkTileMode::kMirror, true); )
DEF_BENCH( return new MatrixConvolutionBench(true, SkTileMode::kDecal, true); )
DEF_BENCH( return new MatrixConvolutionBench(true, SkTileMode::kDecal, false); )