OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "Benchmark.h" | 8 #include "Benchmark.h" |
9 #include "SkBlurImageFilter.h" | 9 #include "SkBlurImageFilter.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
11 #include "SkPaint.h" | 11 #include "SkPaint.h" |
12 #include "SkRandom.h" | 12 #include "SkRandom.h" |
13 #include "SkShader.h" | 13 #include "SkShader.h" |
14 #include "SkString.h" | 14 #include "SkString.h" |
15 | 15 |
16 #define FILTER_WIDTH_SMALL 32 | 16 #define FILTER_WIDTH_SMALL 32 |
17 #define FILTER_HEIGHT_SMALL 32 | 17 #define FILTER_HEIGHT_SMALL 32 |
18 #define FILTER_WIDTH_LARGE 256 | 18 #define FILTER_WIDTH_LARGE 256 |
19 #define FILTER_HEIGHT_LARGE 256 | 19 #define FILTER_HEIGHT_LARGE 256 |
20 #define BLUR_SIGMA_MINI 0.5f | 20 #define BLUR_SIGMA_MINI 0.5f |
21 #define BLUR_SIGMA_SMALL 1.0f | 21 #define BLUR_SIGMA_SMALL 1.0f |
22 #define BLUR_SIGMA_LARGE 10.0f | 22 #define BLUR_SIGMA_LARGE 10.0f |
23 #define BLUR_SIGMA_HUGE 80.0f | 23 #define BLUR_SIGMA_HUGE 80.0f |
24 | 24 |
25 class BlurImageFilterBench : public Benchmark { | 25 class BlurImageFilterBench : public Benchmark { |
26 public: | 26 public: |
27 BlurImageFilterBench(SkScalar sigmaX, SkScalar sigmaY, bool small) : | 27 BlurImageFilterBench(SkScalar sigmaX, SkScalar sigmaY, bool small, bool cro
pped) : |
28 fIsSmall(small), fInitialized(false), fSigmaX(sigmaX), fSigmaY(sigmaY) { | 28 fIsSmall(small), fIsCropped(cropped), fInitialized(false), fSigmaX(sigma
X), fSigmaY(sigmaY) { |
29 fName.printf("blur_image_filter_%s_%.2f_%.2f", fIsSmall ? "small" : "lar
ge", | 29 fName.printf("blur_image_filter_%s%s_%.2f_%.2f", fIsSmall ? "small" : "l
arge", |
30 SkScalarToFloat(sigmaX), SkScalarToFloat(sigmaY)); | 30 fIsCropped ? "_cropped" : "", SkScalarToFloat(sigmaX), SkScalarToFlo
at(sigmaY)); |
31 } | 31 } |
32 | 32 |
33 protected: | 33 protected: |
34 const char* onGetName() override { | 34 const char* onGetName() override { |
35 return fName.c_str(); | 35 return fName.c_str(); |
36 } | 36 } |
37 | 37 |
38 void onPreDraw() override { | 38 void onPreDraw() override { |
39 if (!fInitialized) { | 39 if (!fInitialized) { |
40 make_checkerboard(); | 40 make_checkerboard(); |
41 fInitialized = true; | 41 fInitialized = true; |
42 } | 42 } |
43 } | 43 } |
44 | 44 |
45 void onDraw(const int loops, SkCanvas* canvas) override { | 45 void onDraw(const int loops, SkCanvas* canvas) override { |
46 SkPaint paint; | 46 SkPaint paint; |
47 paint.setImageFilter(SkBlurImageFilter::Create(fSigmaX, fSigmaY))->unref
(); | 47 static const SkScalar kX = 0; |
| 48 static const SkScalar kY = 0; |
| 49 const SkRect bmpRect = SkRect::MakeXYWH(kX, kY, |
| 50 SkIntToScalar(fCheckerboard.widt
h()), |
| 51 SkIntToScalar(fCheckerboard.heig
ht())); |
| 52 const SkImageFilter::CropRect cropRect = |
| 53 SkImageFilter::CropRect(bmpRect.makeInse
t(10.f, 10.f)); |
| 54 const SkImageFilter::CropRect* crop = fIsCropped ? &cropRect : NULL; |
| 55 |
| 56 paint.setImageFilter(SkBlurImageFilter::Create(fSigmaX, fSigmaY, NULL, c
rop))->unref(); |
48 | 57 |
49 for (int i = 0; i < loops; i++) { | 58 for (int i = 0; i < loops; i++) { |
50 canvas->drawBitmap(fCheckerboard, 0, 0, &paint); | 59 canvas->drawBitmap(fCheckerboard, kX, kY, &paint); |
51 } | 60 } |
52 } | 61 } |
53 | 62 |
54 private: | 63 private: |
55 void make_checkerboard() { | 64 void make_checkerboard() { |
56 const int w = fIsSmall ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE; | 65 const int w = fIsSmall ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE; |
57 const int h = fIsSmall ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARGE; | 66 const int h = fIsSmall ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARGE; |
58 fCheckerboard.allocN32Pixels(w, h); | 67 fCheckerboard.allocN32Pixels(w, h); |
59 SkCanvas canvas(fCheckerboard); | 68 SkCanvas canvas(fCheckerboard); |
60 canvas.clear(0x00000000); | 69 canvas.clear(0x00000000); |
61 SkPaint darkPaint; | 70 SkPaint darkPaint; |
62 darkPaint.setColor(0xFF804020); | 71 darkPaint.setColor(0xFF804020); |
63 SkPaint lightPaint; | 72 SkPaint lightPaint; |
64 lightPaint.setColor(0xFF244484); | 73 lightPaint.setColor(0xFF244484); |
65 for (int y = 0; y < h; y += 16) { | 74 for (int y = 0; y < h; y += 16) { |
66 for (int x = 0; x < w; x += 16) { | 75 for (int x = 0; x < w; x += 16) { |
67 canvas.save(); | 76 canvas.save(); |
68 canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); | 77 canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); |
69 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint); | 78 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint); |
70 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint); | 79 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint); |
71 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); | 80 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); |
72 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); | 81 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); |
73 canvas.restore(); | 82 canvas.restore(); |
74 } | 83 } |
75 } | 84 } |
76 } | 85 } |
77 | 86 |
78 SkString fName; | 87 SkString fName; |
79 bool fIsSmall; | 88 bool fIsSmall; |
| 89 bool fIsCropped; |
80 bool fInitialized; | 90 bool fInitialized; |
81 SkBitmap fCheckerboard; | 91 SkBitmap fCheckerboard; |
82 SkScalar fSigmaX, fSigmaY; | 92 SkScalar fSigmaX, fSigmaY; |
83 typedef Benchmark INHERITED; | 93 typedef Benchmark INHERITED; |
84 }; | 94 }; |
85 | 95 |
86 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, 0, false);) | 96 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, 0, false, false);) |
87 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, 0, false);) | 97 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, 0, false, false);) |
88 DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_LARGE, false);) | 98 DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_LARGE, false, false);) |
89 DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_SMALL, false);) | 99 DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_SMALL, false, false);) |
90 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, true
);) | 100 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, true
, false);) |
91 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, fals
e);) | 101 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, fals
e, false);) |
92 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, tr
ue);) | 102 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, tr
ue, false);) |
93 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, fa
lse);) | 103 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, fa
lse, false);) |
94 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, tr
ue);) | 104 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, tr
ue, false);) |
95 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, fa
lse);) | 105 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, fa
lse, false);) |
96 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, true
);) | 106 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, true
, false);) |
97 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, fals
e);) | 107 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, fals
e, false);) |
| 108 |
| 109 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, 0, false, true);) |
| 110 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, 0, false, true);) |
| 111 DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_LARGE, false, true);) |
| 112 DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_SMALL, false, true);) |
| 113 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, true
, true);) |
| 114 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, fals
e, true);) |
| 115 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, tr
ue, true);) |
| 116 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, fa
lse, true);) |
| 117 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, tr
ue, true);) |
| 118 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, fa
lse, true);) |
| 119 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, true
, true);) |
| 120 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, fals
e, true);) |
OLD | NEW |