2013-01-04 20:29:03 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2013-01-07 21:54:25 +00:00
|
|
|
|
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/SkShader.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
|
|
|
#include "src/core/SkBlurMask.h"
|
2013-01-04 20:29:03 +00:00
|
|
|
|
|
|
|
#define SMALL SkIntToScalar(2)
|
2013-11-25 19:44:07 +00:00
|
|
|
#define REAL 1.5f
|
2013-09-06 14:16:12 +00:00
|
|
|
static const SkScalar kMedium = SkIntToScalar(5);
|
2013-01-04 20:29:03 +00:00
|
|
|
#define BIG SkIntToScalar(10)
|
2013-09-06 14:16:12 +00:00
|
|
|
static const SkScalar kMedBig = SkIntToScalar(20);
|
2013-11-25 19:44:07 +00:00
|
|
|
#define REALBIG 30.5f
|
2013-01-04 20:29:03 +00:00
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class BlurRectBench: public Benchmark {
|
2013-02-07 18:58:35 +00:00
|
|
|
int fLoopCount;
|
2013-01-04 20:29:03 +00:00
|
|
|
SkScalar fRadius;
|
|
|
|
SkString fName;
|
|
|
|
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
BlurRectBench(SkScalar rad) {
|
2013-01-04 20:29:03 +00:00
|
|
|
fRadius = rad;
|
2013-02-07 18:58:35 +00:00
|
|
|
|
|
|
|
if (fRadius > SkIntToScalar(25)) {
|
|
|
|
fLoopCount = 100;
|
|
|
|
} else if (fRadius > SkIntToScalar(5)) {
|
|
|
|
fLoopCount = 1000;
|
|
|
|
} else {
|
|
|
|
fLoopCount = 10000;
|
|
|
|
}
|
2013-01-04 20:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() {
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
2013-01-05 02:02:05 +00:00
|
|
|
|
2013-01-04 20:29:03 +00:00
|
|
|
SkScalar radius() const {
|
|
|
|
return fRadius;
|
|
|
|
}
|
2013-01-05 02:02:05 +00:00
|
|
|
|
2013-01-07 21:54:25 +00:00
|
|
|
void setName(const SkString& name) {
|
2013-01-04 20:29:03 +00:00
|
|
|
fName = name;
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
virtual void onDraw(int loops, SkCanvas*) {
|
2013-01-04 20:29:03 +00:00
|
|
|
SkPaint paint;
|
|
|
|
this->setupPaint(&paint);
|
|
|
|
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
|
2013-01-07 21:54:25 +00:00
|
|
|
SkScalar pad = fRadius*3/2 + SK_Scalar1;
|
|
|
|
SkRect r = SkRect::MakeWH(2 * pad + SK_Scalar1, 2 * pad + SK_Scalar1);
|
2013-01-05 02:02:05 +00:00
|
|
|
|
2013-01-07 21:54:25 +00:00
|
|
|
preBenchSetup(r);
|
2013-01-05 02:02:05 +00:00
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2015-12-17 19:33:12 +00:00
|
|
|
this->makeBlurryRect(r);
|
2013-01-04 20:29:03 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-05 02:02:05 +00:00
|
|
|
|
2013-01-07 21:54:25 +00:00
|
|
|
virtual void makeBlurryRect(const SkRect&) = 0;
|
|
|
|
virtual void preBenchSetup(const SkRect&) {}
|
2013-01-04 20:29:03 +00:00
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-01-04 20:29:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BlurRectDirectBench: public BlurRectBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
BlurRectDirectBench(SkScalar rad) : INHERITED(rad) {
|
2013-01-04 20:29:03 +00:00
|
|
|
SkString name;
|
2013-01-05 02:02:05 +00:00
|
|
|
|
2013-01-04 20:29:03 +00:00
|
|
|
if (SkScalarFraction(rad) != 0) {
|
|
|
|
name.printf("blurrect_direct_%.2f", SkScalarToFloat(rad));
|
|
|
|
} else {
|
2013-02-20 16:42:06 +00:00
|
|
|
name.printf("blurrect_direct_%d", SkScalarRoundToInt(rad));
|
2013-01-04 20:29:03 +00:00
|
|
|
}
|
2013-01-05 02:02:05 +00:00
|
|
|
|
2013-09-06 14:16:12 +00:00
|
|
|
this->setName(name);
|
2013-01-04 20:29:03 +00:00
|
|
|
}
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
void makeBlurryRect(const SkRect& r) override {
|
2013-01-04 20:29:03 +00:00
|
|
|
SkMask mask;
|
2015-12-17 19:33:12 +00:00
|
|
|
if (!SkBlurMask::BlurRect(SkBlurMask::ConvertRadiusToSigma(this->radius()),
|
|
|
|
&mask, r, kNormal_SkBlurStyle)) {
|
2016-03-29 16:03:52 +00:00
|
|
|
return;
|
2015-12-17 19:33:12 +00:00
|
|
|
}
|
2013-01-11 20:54:44 +00:00
|
|
|
SkMask::FreeImage(mask.fImage);
|
2013-01-04 20:29:03 +00:00
|
|
|
}
|
2013-02-20 16:42:06 +00:00
|
|
|
private:
|
|
|
|
typedef BlurRectBench INHERITED;
|
2013-01-04 20:29:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class BlurRectSeparableBench: public BlurRectBench {
|
2013-02-20 16:42:06 +00:00
|
|
|
|
2013-01-04 20:29:03 +00:00
|
|
|
public:
|
2015-12-17 19:33:12 +00:00
|
|
|
BlurRectSeparableBench(SkScalar rad) : INHERITED(rad) { }
|
2013-01-11 20:54:44 +00:00
|
|
|
|
2017-03-22 16:05:03 +00:00
|
|
|
~BlurRectSeparableBench() override {
|
2013-01-11 20:54:44 +00:00
|
|
|
SkMask::FreeImage(fSrcMask.fImage);
|
2013-01-04 20:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
void preBenchSetup(const SkRect& r) override {
|
2013-01-11 20:54:44 +00:00
|
|
|
SkMask::FreeImage(fSrcMask.fImage);
|
|
|
|
|
2013-01-07 21:54:25 +00:00
|
|
|
r.roundOut(&fSrcMask.fBounds);
|
2013-01-04 20:29:03 +00:00
|
|
|
fSrcMask.fFormat = SkMask::kA8_Format;
|
2013-01-07 21:54:25 +00:00
|
|
|
fSrcMask.fRowBytes = fSrcMask.fBounds.width();
|
|
|
|
fSrcMask.fImage = SkMask::AllocImage(fSrcMask.computeTotalImageSize());
|
2013-01-05 02:02:05 +00:00
|
|
|
|
2013-01-07 21:54:25 +00:00
|
|
|
memset(fSrcMask.fImage, 0xff, fSrcMask.computeTotalImageSize());
|
2013-01-04 20:29:03 +00:00
|
|
|
}
|
2013-02-21 07:15:03 +00:00
|
|
|
|
2013-02-20 16:42:06 +00:00
|
|
|
SkMask fSrcMask;
|
|
|
|
private:
|
|
|
|
typedef BlurRectBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class BlurRectBoxFilterBench: public BlurRectSeparableBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
BlurRectBoxFilterBench(SkScalar rad) : INHERITED(rad) {
|
2013-02-20 16:42:06 +00:00
|
|
|
SkString name;
|
2013-09-06 14:16:12 +00:00
|
|
|
|
2013-02-20 16:42:06 +00:00
|
|
|
if (SkScalarFraction(rad) != 0) {
|
|
|
|
name.printf("blurrect_boxfilter_%.2f", SkScalarToFloat(rad));
|
|
|
|
} else {
|
|
|
|
name.printf("blurrect_boxfilter_%d", SkScalarRoundToInt(rad));
|
|
|
|
}
|
2013-09-06 14:16:12 +00:00
|
|
|
|
|
|
|
this->setName(name);
|
2013-02-20 16:42:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2013-01-05 02:02:05 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void makeBlurryRect(const SkRect&) override {
|
2013-01-04 20:29:03 +00:00
|
|
|
SkMask mask;
|
2015-12-17 19:33:12 +00:00
|
|
|
if (!SkBlurMask::BoxBlur(&mask, fSrcMask, SkBlurMask::ConvertRadiusToSigma(this->radius()),
|
2018-03-14 17:01:17 +00:00
|
|
|
kNormal_SkBlurStyle)) {
|
2015-12-17 19:33:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-01-11 20:54:44 +00:00
|
|
|
SkMask::FreeImage(mask.fImage);
|
2013-01-04 20:29:03 +00:00
|
|
|
}
|
2013-02-20 16:42:06 +00:00
|
|
|
private:
|
|
|
|
typedef BlurRectSeparableBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class BlurRectGaussianBench: public BlurRectSeparableBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
BlurRectGaussianBench(SkScalar rad) : INHERITED(rad) {
|
2013-02-20 16:42:06 +00:00
|
|
|
SkString name;
|
2013-09-06 14:16:12 +00:00
|
|
|
|
2013-02-20 16:42:06 +00:00
|
|
|
if (SkScalarFraction(rad) != 0) {
|
|
|
|
name.printf("blurrect_gaussian_%.2f", SkScalarToFloat(rad));
|
|
|
|
} else {
|
|
|
|
name.printf("blurrect_gaussian_%d", SkScalarRoundToInt(rad));
|
|
|
|
}
|
2013-09-07 07:01:16 +00:00
|
|
|
|
2013-09-06 14:16:12 +00:00
|
|
|
this->setName(name);
|
2013-02-20 16:42:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void makeBlurryRect(const SkRect&) override {
|
2013-02-20 16:42:06 +00:00
|
|
|
SkMask mask;
|
2015-12-17 19:33:12 +00:00
|
|
|
if (!SkBlurMask::BlurGroundTruth(SkBlurMask::ConvertRadiusToSigma(this->radius()),
|
|
|
|
&mask, fSrcMask, kNormal_SkBlurStyle)) {
|
|
|
|
return;
|
|
|
|
}
|
2013-02-20 16:42:06 +00:00
|
|
|
SkMask::FreeImage(mask.fImage);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef BlurRectSeparableBench INHERITED;
|
2013-01-04 20:29:03 +00:00
|
|
|
};
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH(return new BlurRectBoxFilterBench(SMALL);)
|
|
|
|
DEF_BENCH(return new BlurRectBoxFilterBench(BIG);)
|
|
|
|
DEF_BENCH(return new BlurRectBoxFilterBench(REALBIG);)
|
|
|
|
DEF_BENCH(return new BlurRectBoxFilterBench(REAL);)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(SMALL);)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(BIG);)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(REALBIG);)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(REAL);)
|
|
|
|
DEF_BENCH(return new BlurRectDirectBench(SMALL);)
|
|
|
|
DEF_BENCH(return new BlurRectDirectBench(BIG);)
|
|
|
|
DEF_BENCH(return new BlurRectDirectBench(REALBIG);)
|
|
|
|
DEF_BENCH(return new BlurRectDirectBench(REAL);)
|
|
|
|
|
|
|
|
DEF_BENCH(return new BlurRectDirectBench(kMedium);)
|
|
|
|
DEF_BENCH(return new BlurRectDirectBench(kMedBig);)
|
|
|
|
|
|
|
|
DEF_BENCH(return new BlurRectBoxFilterBench(kMedium);)
|
|
|
|
DEF_BENCH(return new BlurRectBoxFilterBench(kMedBig);)
|
2013-02-20 16:42:06 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
// disable Gaussian benchmarks; the algorithm works well enough
|
|
|
|
// and serves as a baseline for ground truth, but it's too slow
|
|
|
|
// to use in production for non-trivial radii, so no real point
|
|
|
|
// in having the bots benchmark it all the time.
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(1));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(2));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(3));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(4));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(5));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(6));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(7));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(8));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(9));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(10));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(11));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(12));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(13));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(14));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(15));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(16));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(17));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(18));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(19));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(SkIntToScalar(20));)
|
2013-02-20 16:42:06 +00:00
|
|
|
#endif
|