| 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 |
| 26 |
| 27 // When 'cropped' is set we apply a cropRect to the blurImageFilter. The crop re
ct is an inset of |
| 28 // the source's natural dimensions. This is intended to exercise blurring a larg
er source bitmap |
| 29 // to a smaller destination bitmap. |
| 30 |
| 31 // When 'expanded' is set we apply a cropRect to the input of the blurImageFilte
r (a noOp |
| 32 // offsetImageFilter). The crop rect in this case is an inset of the source's na
tural dimensions. |
| 33 // An additional crop rect is applied to the blurImageFilter that is just the na
tural dimensions |
| 34 // of the source (not inset). This is intended to exercise blurring a smaller so
urce bitmap to a |
| 35 // larger destination. |
| 36 |
| 25 class BlurImageFilterBench : public Benchmark { | 37 class BlurImageFilterBench : public Benchmark { |
| 26 public: | 38 public: |
| 27 BlurImageFilterBench(SkScalar sigmaX, SkScalar sigmaY, bool small, bool cro
pped) : | 39 BlurImageFilterBench(SkScalar sigmaX, SkScalar sigmaY, bool small, bool cro
pped, |
| 28 fIsSmall(small), fIsCropped(cropped), fInitialized(false), fSigmaX(sigma
X), fSigmaY(sigmaY) { | 40 bool expanded) |
| 29 fName.printf("blur_image_filter_%s%s_%.2f_%.2f", fIsSmall ? "small" : "l
arge", | 41 : fIsSmall(small) |
| 30 fIsCropped ? "_cropped" : "", SkScalarToFloat(sigmaX), SkScalarToFlo
at(sigmaY)); | 42 , fIsCropped(cropped) |
| 43 , fIsExpanded(expanded) |
| 44 , fInitialized(false) |
| 45 , fSigmaX(sigmaX) |
| 46 , fSigmaY(sigmaY) { |
| 47 fName.printf("blur_image_filter_%s%s%s_%.2f_%.2f", |
| 48 fIsSmall ? "small" : "large", |
| 49 fIsCropped ? "_cropped" : "", |
| 50 fIsExpanded ? "_expanded" : "", |
| 51 SkScalarToFloat(sigmaX), SkScalarToFloat(sigmaY)); |
| 52 SkASSERT(!fIsExpanded || fIsCropped); // never want expansion w/o croppi
ng |
| 31 } | 53 } |
| 32 | 54 |
| 33 protected: | 55 protected: |
| 34 const char* onGetName() override { | 56 const char* onGetName() override { |
| 35 return fName.c_str(); | 57 return fName.c_str(); |
| 36 } | 58 } |
| 37 | 59 |
| 38 void onDelayedSetup() override { | 60 void onDelayedSetup() override { |
| 39 if (!fInitialized) { | 61 if (!fInitialized) { |
| 40 make_checkerboard(); | 62 make_checkerboard(); |
| 41 fInitialized = true; | 63 fInitialized = true; |
| 42 } | 64 } |
| 43 } | 65 } |
| 44 | 66 |
| 45 void onDraw(int loops, SkCanvas* canvas) override { | 67 void onDraw(int loops, SkCanvas* canvas) override { |
| 46 SkPaint paint; | 68 SkPaint paint; |
| 47 static const SkScalar kX = 0; | 69 static const SkScalar kX = 0; |
| 48 static const SkScalar kY = 0; | 70 static const SkScalar kY = 0; |
| 49 const SkRect bmpRect = SkRect::MakeXYWH(kX, kY, | 71 const SkRect bmpRect = SkRect::MakeXYWH(kX, kY, |
| 50 SkIntToScalar(fCheckerboard.widt
h()), | 72 SkIntToScalar(fCheckerboard.widt
h()), |
| 51 SkIntToScalar(fCheckerboard.heig
ht())); | 73 SkIntToScalar(fCheckerboard.heig
ht())); |
| 52 const SkImageFilter::CropRect cropRect = | 74 const SkImageFilter::CropRect cropRect(bmpRect.makeInset(10.f, 10.f)); |
| 53 SkImageFilter::CropRect(bmpRect.makeInse
t(10.f, 10.f)); | 75 const SkImageFilter::CropRect cropRectLarge(bmpRect); |
| 54 const SkImageFilter::CropRect* crop = fIsCropped ? &cropRect : nullptr; | 76 SkAutoTUnref<SkImageFilter> noOpCropped(SkOffsetImageFilter::Create(0, 0
, nullptr, |
| 77 &cropRect)); |
| 55 | 78 |
| 56 paint.setImageFilter(SkBlurImageFilter::Create(fSigmaX, fSigmaY, nullptr
, crop))->unref(); | 79 SkImageFilter* input = fIsExpanded ? noOpCropped.get() : nullptr; |
| 80 |
| 81 const SkImageFilter::CropRect* crop = |
| 82 fIsExpanded ? &cropRectLarge : fIsCropped ? &cropRect : nullptr; |
| 83 paint.setImageFilter(SkBlurImageFilter::Create(fSigmaX, fSigmaY, input,
crop))->unref(); |
| 57 | 84 |
| 58 for (int i = 0; i < loops; i++) { | 85 for (int i = 0; i < loops; i++) { |
| 59 canvas->drawBitmap(fCheckerboard, kX, kY, &paint); | 86 canvas->drawBitmap(fCheckerboard, kX, kY, &paint); |
| 60 } | 87 } |
| 61 } | 88 } |
| 62 | 89 |
| 63 private: | 90 private: |
| 64 void make_checkerboard() { | 91 void make_checkerboard() { |
| 65 const int w = fIsSmall ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE; | 92 const int w = fIsSmall ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE; |
| 66 const int h = fIsSmall ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARGE; | 93 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); | 107 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); |
| 81 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); | 108 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); |
| 82 canvas.restore(); | 109 canvas.restore(); |
| 83 } | 110 } |
| 84 } | 111 } |
| 85 } | 112 } |
| 86 | 113 |
| 87 SkString fName; | 114 SkString fName; |
| 88 bool fIsSmall; | 115 bool fIsSmall; |
| 89 bool fIsCropped; | 116 bool fIsCropped; |
| 117 bool fIsExpanded; |
| 90 bool fInitialized; | 118 bool fInitialized; |
| 91 SkBitmap fCheckerboard; | 119 SkBitmap fCheckerboard; |
| 92 SkScalar fSigmaX, fSigmaY; | 120 SkScalar fSigmaX, fSigmaY; |
| 93 typedef Benchmark INHERITED; | 121 typedef Benchmark INHERITED; |
| 94 }; | 122 }; |
| 95 | 123 |
| 96 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, 0, false, false);) | 124 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);) | 125 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);) | 126 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);) | 127 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);) | 128 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);) | 129 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);) | 130 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);) | 131 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);) | 132 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);) | 133 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);) | 134 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);) | 135 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, fals
e, false, false);) |
| 108 | 136 |
| 109 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, 0, false, true);) | 137 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);) | 138 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);) | 139 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);) | 140 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);) | 141 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);) | 142 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);) | 143 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);) | 144 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);) | 145 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);) | 146 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);) | 147 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);) | 148 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, fals
e, true, false);) |
| 149 |
| 150 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, 0, false, true, true
);) |
| 151 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, 0, false, true, true
);) |
| 152 DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_LARGE, false, true, true
);) |
| 153 DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_SMALL, false, true, true
);) |
| 154 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, true
, true, true);) |
| 155 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_MINI, BLUR_SIGMA_MINI, fals
e, true, true);) |
| 156 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, tr
ue, true, true);) |
| 157 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, fa
lse, true, true);) |
| 158 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, tr
ue, true, true);) |
| 159 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, fa
lse, true, true);) |
| 160 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, true
, true, true);) |
| 161 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, fals
e, true, true);) |
| OLD | NEW |