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
|
|
|
|
2013-01-04 20:29:03 +00:00
|
|
|
#include "SkBenchmark.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkShader.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
#include "SkBlurMask.h"
|
|
|
|
|
|
|
|
#define SMALL SkIntToScalar(2)
|
|
|
|
#define REAL SkFloatToScalar(1.5f)
|
|
|
|
#define BIG SkIntToScalar(10)
|
|
|
|
#define REALBIG SkFloatToScalar(30.5f)
|
|
|
|
|
|
|
|
class BlurRectBench: public SkBenchmark {
|
2013-02-07 18:58:35 +00:00
|
|
|
int fLoopCount;
|
2013-01-04 20:29:03 +00:00
|
|
|
SkScalar fRadius;
|
|
|
|
SkString fName;
|
|
|
|
|
|
|
|
public:
|
|
|
|
BlurRectBench(void *param, SkScalar rad) : INHERITED(param) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-03-05 18:50:01 +00:00
|
|
|
virtual void onDraw(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-02-07 18:58:35 +00:00
|
|
|
for (int i = 0; i < SkBENCHLOOP(fLoopCount); i++) {
|
2013-01-07 21:54:25 +00:00
|
|
|
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:
|
|
|
|
typedef SkBenchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BlurRectDirectBench: public BlurRectBench {
|
|
|
|
public:
|
2013-02-20 16:42:06 +00:00
|
|
|
BlurRectDirectBench(void *param, SkScalar rad) : INHERITED(param, 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-01-07 21:54:25 +00:00
|
|
|
setName(name);
|
2013-01-04 20:29:03 +00:00
|
|
|
}
|
|
|
|
protected:
|
2013-01-07 21:54:25 +00:00
|
|
|
virtual void makeBlurryRect(const SkRect& r) SK_OVERRIDE {
|
2013-01-04 20:29:03 +00:00
|
|
|
SkMask mask;
|
2013-02-20 16:42:06 +00:00
|
|
|
SkBlurMask::BlurRect(&mask, r, this->radius(), SkBlurMask::kNormal_Style);
|
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:
|
2013-02-20 16:42:06 +00:00
|
|
|
BlurRectSeparableBench(void *param, SkScalar rad) : INHERITED(param, rad) {
|
2013-01-11 20:54:44 +00:00
|
|
|
fSrcMask.fImage = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
~BlurRectSeparableBench() {
|
|
|
|
SkMask::FreeImage(fSrcMask.fImage);
|
2013-01-04 20:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2013-01-07 21:54:25 +00:00
|
|
|
virtual void preBenchSetup(const SkRect& r) SK_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:
|
|
|
|
BlurRectBoxFilterBench(void *param, SkScalar rad) : INHERITED(param, rad) {
|
|
|
|
SkString name;
|
|
|
|
if (SkScalarFraction(rad) != 0) {
|
|
|
|
name.printf("blurrect_boxfilter_%.2f", SkScalarToFloat(rad));
|
|
|
|
} else {
|
|
|
|
name.printf("blurrect_boxfilter_%d", SkScalarRoundToInt(rad));
|
|
|
|
}
|
|
|
|
setName(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2013-01-05 02:02:05 +00:00
|
|
|
|
2013-03-05 18:50:01 +00:00
|
|
|
virtual void makeBlurryRect(const SkRect&) SK_OVERRIDE {
|
2013-01-04 20:29:03 +00:00
|
|
|
SkMask mask;
|
2013-02-20 16:42:06 +00:00
|
|
|
mask.fImage = NULL;
|
2013-06-11 15:23:42 +00:00
|
|
|
SkBlurMask::Blur(&mask, fSrcMask, this->radius(),
|
2013-01-07 21:54:25 +00:00
|
|
|
SkBlurMask::kNormal_Style,
|
|
|
|
SkBlurMask::kHigh_Quality);
|
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:
|
|
|
|
BlurRectGaussianBench(void *param, SkScalar rad) : INHERITED(param, rad) {
|
|
|
|
SkString name;
|
|
|
|
if (SkScalarFraction(rad) != 0) {
|
|
|
|
name.printf("blurrect_gaussian_%.2f", SkScalarToFloat(rad));
|
|
|
|
} else {
|
|
|
|
name.printf("blurrect_gaussian_%d", SkScalarRoundToInt(rad));
|
|
|
|
}
|
|
|
|
setName(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2013-03-05 18:50:01 +00:00
|
|
|
virtual void makeBlurryRect(const SkRect&) SK_OVERRIDE {
|
2013-02-20 16:42:06 +00:00
|
|
|
SkMask mask;
|
|
|
|
mask.fImage = NULL;
|
|
|
|
SkBlurMask::BlurGroundTruth(&mask, fSrcMask, this->radius(),
|
|
|
|
SkBlurMask::kNormal_Style);
|
|
|
|
SkMask::FreeImage(mask.fImage);
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef BlurRectSeparableBench INHERITED;
|
2013-01-04 20:29:03 +00:00
|
|
|
};
|
|
|
|
|
2013-02-20 16:42:06 +00:00
|
|
|
DEF_BENCH(return new BlurRectBoxFilterBench(p, SMALL);)
|
|
|
|
DEF_BENCH(return new BlurRectBoxFilterBench(p, BIG);)
|
|
|
|
DEF_BENCH(return new BlurRectBoxFilterBench(p, REALBIG);)
|
|
|
|
DEF_BENCH(return new BlurRectBoxFilterBench(p, REAL);)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(p, SMALL);)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(p, BIG);)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(p, REALBIG);)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(p, REAL);)
|
2013-01-04 20:29:03 +00:00
|
|
|
DEF_BENCH(return new BlurRectDirectBench(p, SMALL);)
|
|
|
|
DEF_BENCH(return new BlurRectDirectBench(p, BIG);)
|
|
|
|
DEF_BENCH(return new BlurRectDirectBench(p, REALBIG);)
|
|
|
|
DEF_BENCH(return new BlurRectDirectBench(p, REAL);)
|
2013-02-20 16:42:06 +00:00
|
|
|
|
|
|
|
DEF_BENCH(return new BlurRectDirectBench(p, SkIntToScalar(5));)
|
|
|
|
DEF_BENCH(return new BlurRectDirectBench(p, SkIntToScalar(20));)
|
|
|
|
|
|
|
|
DEF_BENCH(return new BlurRectBoxFilterBench(p, SkIntToScalar(5));)
|
|
|
|
DEF_BENCH(return new BlurRectBoxFilterBench(p, SkIntToScalar(20));)
|
|
|
|
|
|
|
|
#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.
|
|
|
|
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(1));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(2));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(3));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(4));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(5));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(6));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(7));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(8));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(9));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(10));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(11));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(12));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(13));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(14));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(15));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(16));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(17));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(18));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(19));)
|
|
|
|
DEF_BENCH(return new BlurRectGaussianBench(p, SkIntToScalar(20));)
|
|
|
|
#endif
|