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 "SkOffsetImageFilter.h" | |
10 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
11 #include "SkPaint.h" | 12 #include "SkPaint.h" |
12 #include "SkRandom.h" | 13 #include "SkRandom.h" |
13 #include "SkShader.h" | 14 #include "SkShader.h" |
14 #include "SkString.h" | 15 #include "SkString.h" |
15 | 16 |
16 #define FILTER_WIDTH_SMALL 32 | 17 #define FILTER_WIDTH_SMALL 32 |
17 #define FILTER_HEIGHT_SMALL 32 | 18 #define FILTER_HEIGHT_SMALL 32 |
18 #define FILTER_WIDTH_LARGE 256 | 19 #define FILTER_WIDTH_LARGE 256 |
19 #define FILTER_HEIGHT_LARGE 256 | 20 #define FILTER_HEIGHT_LARGE 256 |
20 #define BLUR_SIGMA_MINI 0.5f | 21 #define BLUR_SIGMA_MINI 0.5f |
21 #define BLUR_SIGMA_SMALL 1.0f | 22 #define BLUR_SIGMA_SMALL 1.0f |
22 #define BLUR_SIGMA_LARGE 10.0f | 23 #define BLUR_SIGMA_LARGE 10.0f |
23 #define BLUR_SIGMA_HUGE 80.0f | 24 #define BLUR_SIGMA_HUGE 80.0f |
24 | 25 |
robertphillips
2015/10/30 17:09:14
// When 'cropped' is set we apply a cropRect to th
Stephen White
2015/10/30 20:05:46
Done.
| |
25 class BlurImageFilterBench : public Benchmark { | 26 class BlurImageFilterBench : public Benchmark { |
26 public: | 27 public: |
27 BlurImageFilterBench(SkScalar sigmaX, SkScalar sigmaY, bool small, bool cro pped) : | 28 BlurImageFilterBench(SkScalar sigmaX, SkScalar sigmaY, bool small, bool cro pped, |
28 fIsSmall(small), fIsCropped(cropped), fInitialized(false), fSigmaX(sigma X), fSigmaY(sigmaY) { | 29 bool expanded) : |
robertphillips
2015/10/30 17:09:14
knock this into the canonical "\n:X\n,Y {" formatt
Stephen White
2015/10/30 20:05:46
Done.
| |
29 fName.printf("blur_image_filter_%s%s_%.2f_%.2f", fIsSmall ? "small" : "l arge", | 30 fIsSmall(small), fIsCropped(cropped), fIsExpanded(expanded), fInitialize d(false), |
30 fIsCropped ? "_cropped" : "", SkScalarToFloat(sigmaX), SkScalarToFlo at(sigmaY)); | 31 fSigmaX(sigmaX), fSigmaY(sigmaY) { |
32 fName.printf("blur_image_filter_%s%s%s_%.2f_%.2f", | |
33 fIsSmall ? "small" : "large", | |
34 fIsCropped ? "_cropped" : "", | |
35 fIsExpanded ? "_expanded" : "", | |
36 SkScalarToFloat(sigmaX), SkScalarToFloat(sigmaY)); | |
robertphillips
2015/10/30 17:09:14
SkASSERT(!fIsExpanded || fIsCropped); // never wan
Stephen White
2015/10/30 20:05:46
Done.
| |
31 } | 37 } |
32 | 38 |
33 protected: | 39 protected: |
34 const char* onGetName() override { | 40 const char* onGetName() override { |
35 return fName.c_str(); | 41 return fName.c_str(); |
36 } | 42 } |
37 | 43 |
38 void onDelayedSetup() override { | 44 void onDelayedSetup() override { |
39 if (!fInitialized) { | 45 if (!fInitialized) { |
40 make_checkerboard(); | 46 make_checkerboard(); |
41 fInitialized = true; | 47 fInitialized = true; |
42 } | 48 } |
43 } | 49 } |
44 | 50 |
45 void onDraw(int loops, SkCanvas* canvas) override { | 51 void onDraw(int loops, SkCanvas* canvas) override { |
46 SkPaint paint; | 52 SkPaint paint; |
47 static const SkScalar kX = 0; | 53 static const SkScalar kX = 0; |
48 static const SkScalar kY = 0; | 54 static const SkScalar kY = 0; |
49 const SkRect bmpRect = SkRect::MakeXYWH(kX, kY, | 55 const SkRect bmpRect = SkRect::MakeXYWH(kX, kY, |
50 SkIntToScalar(fCheckerboard.widt h()), | 56 SkIntToScalar(fCheckerboard.widt h()), |
51 SkIntToScalar(fCheckerboard.heig ht())); | 57 SkIntToScalar(fCheckerboard.heig ht())); |
52 const SkImageFilter::CropRect cropRect = | 58 const SkImageFilter::CropRect cropRect(bmpRect.makeInset(10.f, 10.f)); |
53 SkImageFilter::CropRect(bmpRect.makeInse t(10.f, 10.f)); | 59 const SkImageFilter::CropRect cropRectLarge(bmpRect); |
54 const SkImageFilter::CropRect* crop = fIsCropped ? &cropRect : nullptr; | 60 SkAutoTUnref<SkImageFilter> noOpCropped(SkOffsetImageFilter::Create(0, 0 , nullptr, |
61 &cropRect)); | |
55 | 62 |
56 paint.setImageFilter(SkBlurImageFilter::Create(fSigmaX, fSigmaY, nullptr , crop))->unref(); | 63 SkImageFilter* input = fIsExpanded ? noOpCropped.get() : nullptr; |
64 | |
65 const SkImageFilter::CropRect* crop = | |
66 fIsExpanded ? &cropRectLarge : fIsCropped ? &cropRect : nullptr; | |
67 paint.setImageFilter(SkBlurImageFilter::Create(fSigmaX, fSigmaY, input, crop))->unref(); | |
57 | 68 |
58 for (int i = 0; i < loops; i++) { | 69 for (int i = 0; i < loops; i++) { |
59 canvas->drawBitmap(fCheckerboard, kX, kY, &paint); | 70 canvas->drawBitmap(fCheckerboard, kX, kY, &paint); |
60 } | 71 } |
61 } | 72 } |
62 | 73 |
63 private: | 74 private: |
64 void make_checkerboard() { | 75 void make_checkerboard() { |
65 const int w = fIsSmall ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE; | 76 const int w = fIsSmall ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE; |
66 const int h = fIsSmall ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARGE; | 77 const int h = fIsSmall ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARGE; |
(...skipping 13 matching lines...) Expand all Loading... | |
80 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); | 91 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); |
81 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); | 92 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); |
82 canvas.restore(); | 93 canvas.restore(); |
83 } | 94 } |
84 } | 95 } |
85 } | 96 } |
86 | 97 |
87 SkString fName; | 98 SkString fName; |
88 bool fIsSmall; | 99 bool fIsSmall; |
89 bool fIsCropped; | 100 bool fIsCropped; |
101 bool fIsExpanded; | |
90 bool fInitialized; | 102 bool fInitialized; |
91 SkBitmap fCheckerboard; | 103 SkBitmap fCheckerboard; |
92 SkScalar fSigmaX, fSigmaY; | 104 SkScalar fSigmaX, fSigmaY; |
93 typedef Benchmark INHERITED; | 105 typedef Benchmark INHERITED; |
94 }; | 106 }; |
95 | 107 |
96 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, 0, false, false);) | 108 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, 0, false, false, fal se);) |
97 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, 0, false, false);) | 109 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, 0, false, false, fal se);) |
98 DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_LARGE, false, false);) | 110 DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_LARGE, false, false, fal se);) |
99 DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_SMALL, false, false);) | 111 DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_SMALL, false, false, fal se);) |
100 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, true , false);) | 112 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, true , false, false);) |
101 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, fals e, false);) | 113 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, fals e, false, false);) |
102 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, tr ue, false);) | 114 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, tr ue, false, false);) |
103 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, fa lse, false);) | 115 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, fa lse, false, false);) |
104 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, tr ue, false);) | 116 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, tr ue, false, false);) |
105 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, fa lse, false);) | 117 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, fa lse, false, false);) |
106 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, true , false);) | 118 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, true , false, false);) |
107 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, fals e, false);) | 119 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, fals e, false, false);) |
108 | 120 |
109 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, 0, false, true);) | 121 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, 0, false, true, fals e);) |
110 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, 0, false, true);) | 122 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, 0, false, true, fals e);) |
111 DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_LARGE, false, true);) | 123 DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_LARGE, false, true, fals e);) |
112 DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_SMALL, false, true);) | 124 DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_SMALL, false, true, fals e);) |
113 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, true , true);) | 125 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, true , true, false);) |
114 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, fals e, true);) | 126 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, fals e, true, false);) |
115 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, tr ue, true);) | 127 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, tr ue, true, false);) |
116 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, fa lse, true);) | 128 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, fa lse, true, false);) |
117 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, tr ue, true);) | 129 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, tr ue, true, false);) |
118 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, fa lse, true);) | 130 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, fa lse, true, false);) |
119 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, true , true);) | 131 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, true , true, false);) |
120 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, fals e, true);) | 132 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, fals e, true, false);) |
133 | |
134 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, 0, false, true, true );) | |
135 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, 0, false, true, true );) | |
136 DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_LARGE, false, true, true );) | |
137 DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_SMALL, false, true, true );) | |
138 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, true , true, true);) | |
139 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, fals e, true, true);) | |
140 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, tr ue, true, true);) | |
141 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, fa lse, true, true);) | |
142 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, tr ue, true, true);) | |
143 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, fa lse, true, true);) | |
144 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, true , true, true);) | |
145 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, fals e, true, true);) | |
OLD | NEW |