OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SkBenchmark.h" | 8 #include "SkBenchmark.h" |
| 9 #include "SkBlurMask.h" |
9 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
10 #include "SkPaint.h" | 11 #include "SkPaint.h" |
11 #include "SkRandom.h" | 12 #include "SkRandom.h" |
12 #include "SkShader.h" | 13 #include "SkShader.h" |
13 #include "SkString.h" | 14 #include "SkString.h" |
14 #include "SkBlurMaskFilter.h" | 15 #include "SkBlurMaskFilter.h" |
15 | 16 |
16 #define SMALL SkIntToScalar(2) | 17 #define SMALL SkIntToScalar(2) |
17 #define REAL SkFloatToScalar(1.5f) | 18 #define REAL SkFloatToScalar(1.5f) |
18 #define BIG SkIntToScalar(10) | 19 #define BIG SkIntToScalar(10) |
19 #define REALBIG SkFloatToScalar(100.5f) | 20 #define REALBIG SkFloatToScalar(100.5f) |
20 | 21 |
21 static const char* gStyleName[] = { | 22 static const char* gStyleName[] = { |
22 "normal", | 23 "normal", |
23 "solid", | 24 "solid", |
24 "outer", | 25 "outer", |
25 "inner" | 26 "inner" |
26 }; | 27 }; |
27 | 28 |
28 class BlurBench : public SkBenchmark { | 29 class BlurBench : public SkBenchmark { |
29 SkScalar fRadius; | 30 SkScalar fRadius; |
30 SkBlurMaskFilter::BlurStyle fStyle; | 31 SkBlurMaskFilter::BlurStyle fStyle; |
31 uint32_t fFlags; | 32 uint32_t fFlags; |
32 SkString fName; | 33 SkString fName; |
33 | 34 |
34 public: | 35 public: |
35 BlurBench(void* param, SkScalar rad, SkBlurMaskFilter::BlurStyle bs, uint32_
t flags = 0) : INHERITED(param) { | 36 BlurBench(void* param, SkScalar rad, SkBlurMaskFilter::BlurStyle bs, uint32_
t flags = 0) |
| 37 : INHERITED(param) { |
36 fRadius = rad; | 38 fRadius = rad; |
37 fStyle = bs; | 39 fStyle = bs; |
38 fFlags = flags; | 40 fFlags = flags; |
39 const char* name = rad > 0 ? gStyleName[bs] : "none"; | 41 const char* name = rad > 0 ? gStyleName[bs] : "none"; |
40 const char* quality = flags & SkBlurMaskFilter::kHighQuality_BlurFlag ?
"high_quality" : "low_quality"; | 42 const char* quality = flags & SkBlurMaskFilter::kHighQuality_BlurFlag ?
"high_quality" |
| 43 :
"low_quality"; |
41 if (SkScalarFraction(rad) != 0) { | 44 if (SkScalarFraction(rad) != 0) { |
42 fName.printf("blur_%.2f_%s_%s", SkScalarToFloat(rad), name, quality)
; | 45 fName.printf("blur_%.2f_%s_%s", SkScalarToFloat(rad), name, quality)
; |
43 } else { | 46 } else { |
44 fName.printf("blur_%d_%s_%s", SkScalarRound(rad), name, quality); | 47 fName.printf("blur_%d_%s_%s", SkScalarRound(rad), name, quality); |
45 } | 48 } |
46 } | 49 } |
47 | 50 |
48 protected: | 51 protected: |
49 virtual const char* onGetName() { | 52 virtual const char* onGetName() { |
50 return fName.c_str(); | 53 return fName.c_str(); |
51 } | 54 } |
52 | 55 |
53 virtual void onDraw(SkCanvas* canvas) { | 56 virtual void onDraw(SkCanvas* canvas) { |
54 SkPaint paint; | 57 SkPaint paint; |
55 this->setupPaint(&paint); | 58 this->setupPaint(&paint); |
56 | 59 |
57 paint.setAntiAlias(true); | 60 paint.setAntiAlias(true); |
58 | 61 |
59 SkRandom rand; | 62 SkRandom rand; |
60 for (int i = 0; i < SkBENCHLOOP(10); i++) { | 63 for (int i = 0; i < SkBENCHLOOP(10); i++) { |
61 SkRect r = SkRect::MakeWH(rand.nextUScalar1() * 400, | 64 SkRect r = SkRect::MakeWH(rand.nextUScalar1() * 400, |
62 rand.nextUScalar1() * 400); | 65 rand.nextUScalar1() * 400); |
63 r.offset(fRadius, fRadius); | 66 r.offset(fRadius, fRadius); |
64 | 67 |
65 if (fRadius > 0) { | 68 if (fRadius > 0) { |
66 SkMaskFilter* mf = SkBlurMaskFilter::Create(fRadius, fStyle, fFl
ags); | 69 SkMaskFilter* mf = SkBlurMaskFilter::Create(fStyle, |
| 70 SkBlurMask::ConvertRadiusToSigma(fRa
dius), |
| 71 fFlags); |
67 paint.setMaskFilter(mf)->unref(); | 72 paint.setMaskFilter(mf)->unref(); |
68 } | 73 } |
69 canvas->drawOval(r, paint); | 74 canvas->drawOval(r, paint); |
70 } | 75 } |
71 } | 76 } |
72 | 77 |
73 private: | 78 private: |
74 typedef SkBenchmark INHERITED; | 79 typedef SkBenchmark INHERITED; |
75 }; | 80 }; |
76 | 81 |
(...skipping 19 matching lines...) Expand all Loading... |
96 | 101 |
97 DEF_BENCH(return new BlurBench(p, SMALL, SkBlurMaskFilter::kNormal_BlurStyle, Sk
BlurMaskFilter::kHighQuality_BlurFlag);) | 102 DEF_BENCH(return new BlurBench(p, SMALL, SkBlurMaskFilter::kNormal_BlurStyle, Sk
BlurMaskFilter::kHighQuality_BlurFlag);) |
98 | 103 |
99 DEF_BENCH(return new BlurBench(p, BIG, SkBlurMaskFilter::kNormal_BlurStyle, SkBl
urMaskFilter::kHighQuality_BlurFlag);) | 104 DEF_BENCH(return new BlurBench(p, BIG, SkBlurMaskFilter::kNormal_BlurStyle, SkBl
urMaskFilter::kHighQuality_BlurFlag);) |
100 | 105 |
101 DEF_BENCH(return new BlurBench(p, REALBIG, SkBlurMaskFilter::kNormal_BlurStyle,
SkBlurMaskFilter::kHighQuality_BlurFlag);) | 106 DEF_BENCH(return new BlurBench(p, REALBIG, SkBlurMaskFilter::kNormal_BlurStyle,
SkBlurMaskFilter::kHighQuality_BlurFlag);) |
102 | 107 |
103 DEF_BENCH(return new BlurBench(p, REAL, SkBlurMaskFilter::kNormal_BlurStyle, SkB
lurMaskFilter::kHighQuality_BlurFlag);) | 108 DEF_BENCH(return new BlurBench(p, REAL, SkBlurMaskFilter::kNormal_BlurStyle, SkB
lurMaskFilter::kHighQuality_BlurFlag);) |
104 | 109 |
105 DEF_BENCH(return new BlurBench(p, 0, SkBlurMaskFilter::kNormal_BlurStyle);) | 110 DEF_BENCH(return new BlurBench(p, 0, SkBlurMaskFilter::kNormal_BlurStyle);) |
OLD | NEW |