2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 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"
|
2013-09-06 14:16:12 +00:00
|
|
|
#include "SkBlurMask.h"
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "SkBlurMaskFilter.h"
|
2011-07-14 19:03:58 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkShader.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
|
2014-08-11 20:55:34 +00:00
|
|
|
#define MINI 0.01f
|
2011-07-14 19:03:58 +00:00
|
|
|
#define SMALL SkIntToScalar(2)
|
2013-11-25 19:44:07 +00:00
|
|
|
#define REAL 1.5f
|
2011-07-14 19:03:58 +00:00
|
|
|
#define BIG SkIntToScalar(10)
|
2013-11-25 19:44:07 +00:00
|
|
|
#define REALBIG 100.5f
|
2011-07-14 19:03:58 +00:00
|
|
|
|
|
|
|
static const char* gStyleName[] = {
|
|
|
|
"normal",
|
|
|
|
"solid",
|
|
|
|
"outer",
|
|
|
|
"inner"
|
|
|
|
};
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class BlurBench : public Benchmark {
|
2011-07-14 19:03:58 +00:00
|
|
|
SkScalar fRadius;
|
2014-04-28 16:25:35 +00:00
|
|
|
SkBlurStyle fStyle;
|
|
|
|
uint32_t fFlags;
|
2011-07-14 19:03:58 +00:00
|
|
|
SkString fName;
|
|
|
|
|
|
|
|
public:
|
2014-04-28 16:25:35 +00:00
|
|
|
BlurBench(SkScalar rad, SkBlurStyle bs, uint32_t flags = 0) {
|
2011-07-14 19:03:58 +00:00
|
|
|
fRadius = rad;
|
|
|
|
fStyle = bs;
|
2012-11-29 17:09:27 +00:00
|
|
|
fFlags = flags;
|
2011-07-14 19:03:58 +00:00
|
|
|
const char* name = rad > 0 ? gStyleName[bs] : "none";
|
2013-09-07 07:01:16 +00:00
|
|
|
const char* quality = flags & SkBlurMaskFilter::kHighQuality_BlurFlag ? "high_quality"
|
2013-09-06 14:16:12 +00:00
|
|
|
: "low_quality";
|
2011-11-22 15:58:06 +00:00
|
|
|
if (SkScalarFraction(rad) != 0) {
|
2012-11-29 17:09:27 +00:00
|
|
|
fName.printf("blur_%.2f_%s_%s", SkScalarToFloat(rad), name, quality);
|
2011-11-22 15:58:06 +00:00
|
|
|
} else {
|
2013-12-17 19:22:07 +00:00
|
|
|
fName.printf("blur_%d_%s_%s", SkScalarRoundToInt(rad), name, quality);
|
2011-11-22 15:58:06 +00:00
|
|
|
}
|
2011-07-14 19:03:58 +00:00
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2011-07-14 19:03:58 +00:00
|
|
|
protected:
|
|
|
|
virtual const char* onGetName() {
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
virtual void onDraw(const int loops, SkCanvas* canvas) {
|
2011-07-14 19:03:58 +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++) {
|
2011-07-14 19:03:58 +00:00
|
|
|
SkRect r = SkRect::MakeWH(rand.nextUScalar1() * 400,
|
|
|
|
rand.nextUScalar1() * 400);
|
|
|
|
r.offset(fRadius, fRadius);
|
|
|
|
|
|
|
|
if (fRadius > 0) {
|
2013-09-07 07:01:16 +00:00
|
|
|
SkMaskFilter* mf = SkBlurMaskFilter::Create(fStyle,
|
|
|
|
SkBlurMask::ConvertRadiusToSigma(fRadius),
|
2013-09-06 14:16:12 +00:00
|
|
|
fFlags);
|
2011-07-14 19:03:58 +00:00
|
|
|
paint.setMaskFilter(mf)->unref();
|
|
|
|
}
|
|
|
|
canvas->drawOval(r, paint);
|
|
|
|
}
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2011-07-14 19:03:58 +00:00
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2011-07-14 19:03:58 +00:00
|
|
|
};
|
|
|
|
|
2014-08-11 20:55:34 +00:00
|
|
|
DEF_BENCH(return new BlurBench(MINI, kNormal_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(MINI, kSolid_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(MINI, kOuter_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(MINI, kInner_SkBlurStyle);)
|
|
|
|
|
2014-04-28 16:25:35 +00:00
|
|
|
DEF_BENCH(return new BlurBench(SMALL, kNormal_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(SMALL, kSolid_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(SMALL, kOuter_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(SMALL, kInner_SkBlurStyle);)
|
2012-11-08 20:51:57 +00:00
|
|
|
|
2014-04-28 16:25:35 +00:00
|
|
|
DEF_BENCH(return new BlurBench(BIG, kNormal_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(BIG, kSolid_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(BIG, kOuter_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(BIG, kInner_SkBlurStyle);)
|
2012-11-08 20:51:57 +00:00
|
|
|
|
2014-04-28 16:25:35 +00:00
|
|
|
DEF_BENCH(return new BlurBench(REALBIG, kNormal_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(REALBIG, kSolid_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(REALBIG, kOuter_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(REALBIG, kInner_SkBlurStyle);)
|
2012-11-29 17:09:27 +00:00
|
|
|
|
2014-04-28 16:25:35 +00:00
|
|
|
DEF_BENCH(return new BlurBench(REAL, kNormal_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(REAL, kSolid_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(REAL, kOuter_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(REAL, kInner_SkBlurStyle);)
|
2012-11-08 20:51:57 +00:00
|
|
|
|
2014-08-11 20:55:34 +00:00
|
|
|
DEF_BENCH(return new BlurBench(MINI, kNormal_SkBlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);)
|
|
|
|
|
2014-04-28 16:25:35 +00:00
|
|
|
DEF_BENCH(return new BlurBench(SMALL, kNormal_SkBlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);)
|
2012-11-29 17:09:27 +00:00
|
|
|
|
2014-04-28 16:25:35 +00:00
|
|
|
DEF_BENCH(return new BlurBench(BIG, kNormal_SkBlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);)
|
2012-11-29 17:09:27 +00:00
|
|
|
|
2014-04-28 16:25:35 +00:00
|
|
|
DEF_BENCH(return new BlurBench(REALBIG, kNormal_SkBlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);)
|
2012-11-29 17:09:27 +00:00
|
|
|
|
2014-04-28 16:25:35 +00:00
|
|
|
DEF_BENCH(return new BlurBench(REAL, kNormal_SkBlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);)
|
2012-11-29 17:09:27 +00:00
|
|
|
|
2014-04-28 16:25:35 +00:00
|
|
|
DEF_BENCH(return new BlurBench(0, kNormal_SkBlurStyle);)
|