blob: 29f0dfd1f35b6029e00e8e91340f0a9acc218141 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
tfarinaf168b862014-06-19 12:32:29 -07008#include "Benchmark.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +00009#include "SkBlurMask.h"
tfarinaf168b862014-06-19 12:32:29 -070010#include "SkBlurMaskFilter.h"
reed@google.com25df8882011-07-14 19:03:58 +000011#include "SkCanvas.h"
12#include "SkPaint.h"
13#include "SkRandom.h"
14#include "SkShader.h"
15#include "SkString.h"
reed@google.com25df8882011-07-14 19:03:58 +000016
joshualitt5acfea72014-08-11 13:55:34 -070017#define MINI 0.01f
reed@google.com25df8882011-07-14 19:03:58 +000018#define SMALL SkIntToScalar(2)
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +000019#define REAL 1.5f
reed@google.com25df8882011-07-14 19:03:58 +000020#define BIG SkIntToScalar(10)
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +000021#define REALBIG 100.5f
reed@google.com25df8882011-07-14 19:03:58 +000022
23static const char* gStyleName[] = {
24 "normal",
25 "solid",
26 "outer",
27 "inner"
28};
29
tfarinaf168b862014-06-19 12:32:29 -070030class BlurBench : public Benchmark {
reed@google.com25df8882011-07-14 19:03:58 +000031 SkScalar fRadius;
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000032 SkBlurStyle fStyle;
33 uint32_t fFlags;
reed@google.com25df8882011-07-14 19:03:58 +000034 SkString fName;
35
36public:
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000037 BlurBench(SkScalar rad, SkBlurStyle bs, uint32_t flags = 0) {
reed@google.com25df8882011-07-14 19:03:58 +000038 fRadius = rad;
39 fStyle = bs;
senorblanco@chromium.org91f489a2012-11-29 17:09:27 +000040 fFlags = flags;
reed@google.com25df8882011-07-14 19:03:58 +000041 const char* name = rad > 0 ? gStyleName[bs] : "none";
skia.committer@gmail.comb3ec29d2013-09-07 07:01:16 +000042 const char* quality = flags & SkBlurMaskFilter::kHighQuality_BlurFlag ? "high_quality"
robertphillips@google.comb7061172013-09-06 14:16:12 +000043 : "low_quality";
tomhudson@google.com8caac642011-11-22 15:58:06 +000044 if (SkScalarFraction(rad) != 0) {
senorblanco@chromium.org91f489a2012-11-29 17:09:27 +000045 fName.printf("blur_%.2f_%s_%s", SkScalarToFloat(rad), name, quality);
tomhudson@google.com8caac642011-11-22 15:58:06 +000046 } else {
reed@google.come1ca7052013-12-17 19:22:07 +000047 fName.printf("blur_%d_%s_%s", SkScalarRoundToInt(rad), name, quality);
tomhudson@google.com8caac642011-11-22 15:58:06 +000048 }
reed@google.com25df8882011-07-14 19:03:58 +000049 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000050
reed@google.com25df8882011-07-14 19:03:58 +000051protected:
52 virtual const char* onGetName() {
53 return fName.c_str();
54 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000055
mtkleina1ebeb22015-10-01 09:43:39 -070056 virtual void onDraw(int loops, SkCanvas* canvas) {
reed@google.com25df8882011-07-14 19:03:58 +000057 SkPaint paint;
58 this->setupPaint(&paint);
59
60 paint.setAntiAlias(true);
61
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +000062 SkRandom rand;
commit-bot@chromium.org33614712013-12-03 18:17:16 +000063 for (int i = 0; i < loops; i++) {
reed@google.com25df8882011-07-14 19:03:58 +000064 SkRect r = SkRect::MakeWH(rand.nextUScalar1() * 400,
65 rand.nextUScalar1() * 400);
66 r.offset(fRadius, fRadius);
67
68 if (fRadius > 0) {
skia.committer@gmail.comb3ec29d2013-09-07 07:01:16 +000069 SkMaskFilter* mf = SkBlurMaskFilter::Create(fStyle,
70 SkBlurMask::ConvertRadiusToSigma(fRadius),
robertphillips@google.comb7061172013-09-06 14:16:12 +000071 fFlags);
reed@google.com25df8882011-07-14 19:03:58 +000072 paint.setMaskFilter(mf)->unref();
73 }
74 canvas->drawOval(r, paint);
75 }
76 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000077
reed@google.com25df8882011-07-14 19:03:58 +000078private:
tfarinaf168b862014-06-19 12:32:29 -070079 typedef Benchmark INHERITED;
reed@google.com25df8882011-07-14 19:03:58 +000080};
81
joshualitt5acfea72014-08-11 13:55:34 -070082DEF_BENCH(return new BlurBench(MINI, kNormal_SkBlurStyle);)
83DEF_BENCH(return new BlurBench(MINI, kSolid_SkBlurStyle);)
84DEF_BENCH(return new BlurBench(MINI, kOuter_SkBlurStyle);)
85DEF_BENCH(return new BlurBench(MINI, kInner_SkBlurStyle);)
86
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000087DEF_BENCH(return new BlurBench(SMALL, kNormal_SkBlurStyle);)
88DEF_BENCH(return new BlurBench(SMALL, kSolid_SkBlurStyle);)
89DEF_BENCH(return new BlurBench(SMALL, kOuter_SkBlurStyle);)
90DEF_BENCH(return new BlurBench(SMALL, kInner_SkBlurStyle);)
reed@google.com25df8882011-07-14 19:03:58 +000091
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000092DEF_BENCH(return new BlurBench(BIG, kNormal_SkBlurStyle);)
93DEF_BENCH(return new BlurBench(BIG, kSolid_SkBlurStyle);)
94DEF_BENCH(return new BlurBench(BIG, kOuter_SkBlurStyle);)
95DEF_BENCH(return new BlurBench(BIG, kInner_SkBlurStyle);)
reed@google.com25df8882011-07-14 19:03:58 +000096
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000097DEF_BENCH(return new BlurBench(REALBIG, kNormal_SkBlurStyle);)
98DEF_BENCH(return new BlurBench(REALBIG, kSolid_SkBlurStyle);)
99DEF_BENCH(return new BlurBench(REALBIG, kOuter_SkBlurStyle);)
100DEF_BENCH(return new BlurBench(REALBIG, kInner_SkBlurStyle);)
senorblanco@chromium.org91f489a2012-11-29 17:09:27 +0000101
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000102DEF_BENCH(return new BlurBench(REAL, kNormal_SkBlurStyle);)
103DEF_BENCH(return new BlurBench(REAL, kSolid_SkBlurStyle);)
104DEF_BENCH(return new BlurBench(REAL, kOuter_SkBlurStyle);)
105DEF_BENCH(return new BlurBench(REAL, kInner_SkBlurStyle);)
tomhudson@google.com8caac642011-11-22 15:58:06 +0000106
joshualitt5acfea72014-08-11 13:55:34 -0700107DEF_BENCH(return new BlurBench(MINI, kNormal_SkBlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);)
108
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000109DEF_BENCH(return new BlurBench(SMALL, kNormal_SkBlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);)
senorblanco@chromium.org91f489a2012-11-29 17:09:27 +0000110
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000111DEF_BENCH(return new BlurBench(BIG, kNormal_SkBlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);)
senorblanco@chromium.org91f489a2012-11-29 17:09:27 +0000112
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000113DEF_BENCH(return new BlurBench(REALBIG, kNormal_SkBlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);)
senorblanco@chromium.org91f489a2012-11-29 17:09:27 +0000114
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000115DEF_BENCH(return new BlurBench(REAL, kNormal_SkBlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);)
senorblanco@chromium.org91f489a2012-11-29 17:09:27 +0000116
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000117DEF_BENCH(return new BlurBench(0, kNormal_SkBlurStyle);)