| 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 "SkOffsetImageFilter.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // When 'cropped' is set we apply a cropRect to the blurImageFilter. The crop re
ct is an inset of | 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 | 28 // the source's natural dimensions. This is intended to exercise blurring a larg
er source bitmap |
| 29 // to a smaller destination bitmap. | 29 // to a smaller destination bitmap. |
| 30 | 30 |
| 31 // When 'expanded' is set we apply a cropRect to the input of the blurImageFilte
r (a noOp | 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. | 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 | 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 | 34 // of the source (not inset). This is intended to exercise blurring a smaller so
urce bitmap to a |
| 35 // larger destination. | 35 // larger destination. |
| 36 | 36 |
| 37 static SkBitmap make_checkerboard(int width, int height) { |
| 38 SkBitmap bm; |
| 39 bm.allocN32Pixels(width, height); |
| 40 SkCanvas canvas(bm); |
| 41 canvas.clear(0x00000000); |
| 42 SkPaint darkPaint; |
| 43 darkPaint.setColor(0xFF804020); |
| 44 SkPaint lightPaint; |
| 45 lightPaint.setColor(0xFF244484); |
| 46 for (int y = 0; y < height; y += 16) { |
| 47 for (int x = 0; x < width; x += 16) { |
| 48 canvas.save(); |
| 49 canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); |
| 50 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint); |
| 51 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint); |
| 52 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); |
| 53 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); |
| 54 canvas.restore(); |
| 55 } |
| 56 } |
| 57 |
| 58 return bm; |
| 59 } |
| 60 |
| 37 class BlurImageFilterBench : public Benchmark { | 61 class BlurImageFilterBench : public Benchmark { |
| 38 public: | 62 public: |
| 39 BlurImageFilterBench(SkScalar sigmaX, SkScalar sigmaY, bool small, bool cro
pped, | 63 BlurImageFilterBench(SkScalar sigmaX, SkScalar sigmaY, bool small, bool cro
pped, |
| 40 bool expanded) | 64 bool expanded) |
| 41 : fIsSmall(small) | 65 : fIsSmall(small) |
| 42 , fIsCropped(cropped) | 66 , fIsCropped(cropped) |
| 43 , fIsExpanded(expanded) | 67 , fIsExpanded(expanded) |
| 44 , fInitialized(false) | 68 , fInitialized(false) |
| 45 , fSigmaX(sigmaX) | 69 , fSigmaX(sigmaX) |
| 46 , fSigmaY(sigmaY) { | 70 , fSigmaY(sigmaY) { |
| 47 fName.printf("blur_image_filter_%s%s%s_%.2f_%.2f", | 71 fName.printf("blur_image_filter_%s%s%s_%.2f_%.2f", |
| 48 fIsSmall ? "small" : "large", | 72 fIsSmall ? "small" : "large", |
| 49 fIsCropped ? "_cropped" : "", | 73 fIsCropped ? "_cropped" : "", |
| 50 fIsExpanded ? "_expanded" : "", | 74 fIsExpanded ? "_expanded" : "", |
| 51 SkScalarToFloat(sigmaX), SkScalarToFloat(sigmaY)); | 75 SkScalarToFloat(sigmaX), SkScalarToFloat(sigmaY)); |
| 52 SkASSERT(!fIsExpanded || fIsCropped); // never want expansion w/o croppi
ng | 76 SkASSERT(!fIsExpanded || fIsCropped); // never want expansion w/o croppi
ng |
| 53 } | 77 } |
| 54 | 78 |
| 55 protected: | 79 protected: |
| 56 const char* onGetName() override { | 80 const char* onGetName() override { |
| 57 return fName.c_str(); | 81 return fName.c_str(); |
| 58 } | 82 } |
| 59 | 83 |
| 60 void onDelayedSetup() override { | 84 void onDelayedSetup() override { |
| 61 if (!fInitialized) { | 85 if (!fInitialized) { |
| 62 make_checkerboard(); | 86 fCheckerboard = make_checkerboard(fIsSmall ? FILTER_WIDTH_SMALL : FI
LTER_WIDTH_LARGE, |
| 87 fIsSmall ? FILTER_HEIGHT_SMALL : F
ILTER_HEIGHT_LARGE); |
| 63 fInitialized = true; | 88 fInitialized = true; |
| 64 } | 89 } |
| 65 } | 90 } |
| 66 | 91 |
| 67 void onDraw(int loops, SkCanvas* canvas) override { | 92 void onDraw(int loops, SkCanvas* canvas) override { |
| 68 SkPaint paint; | |
| 69 static const SkScalar kX = 0; | 93 static const SkScalar kX = 0; |
| 70 static const SkScalar kY = 0; | 94 static const SkScalar kY = 0; |
| 71 const SkRect bmpRect = SkRect::MakeXYWH(kX, kY, | 95 const SkRect bmpRect = SkRect::MakeXYWH(kX, kY, |
| 72 SkIntToScalar(fCheckerboard.widt
h()), | 96 SkIntToScalar(fCheckerboard.widt
h()), |
| 73 SkIntToScalar(fCheckerboard.heig
ht())); | 97 SkIntToScalar(fCheckerboard.heig
ht())); |
| 74 const SkImageFilter::CropRect cropRect(bmpRect.makeInset(10.f, 10.f)); | 98 const SkImageFilter::CropRect cropRect(bmpRect.makeInset(10.f, 10.f)); |
| 75 const SkImageFilter::CropRect cropRectLarge(bmpRect); | 99 const SkImageFilter::CropRect cropRectLarge(bmpRect); |
| 76 sk_sp<SkImageFilter> noOpCropped(SkOffsetImageFilter::Make(0, 0, nullptr
, &cropRect)); | |
| 77 | 100 |
| 78 SkImageFilter* input = fIsExpanded ? noOpCropped.get() : nullptr; | 101 sk_sp<SkImageFilter> input = fIsExpanded |
| 102 ? SkOffsetImageFilter::Make(0, 0, nullpt
r, &cropRect) |
| 103 : nullptr; |
| 79 | 104 |
| 80 const SkImageFilter::CropRect* crop = | 105 const SkImageFilter::CropRect* crop = |
| 81 fIsExpanded ? &cropRectLarge : fIsCropped ? &cropRect : nullptr; | 106 fIsExpanded ? &cropRectLarge : fIsCropped ? &cropRect : nullptr; |
| 82 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(fSigmaX, fSig
maY, input, crop)); | 107 SkPaint paint; |
| 83 paint.setImageFilter(blur); | 108 paint.setImageFilter(SkBlurImageFilter::Make(fSigmaX, fSigmaY, std::move
(input), crop)); |
| 84 | 109 |
| 85 for (int i = 0; i < loops; i++) { | 110 for (int i = 0; i < loops; i++) { |
| 86 canvas->drawBitmap(fCheckerboard, kX, kY, &paint); | 111 canvas->drawBitmap(fCheckerboard, kX, kY, &paint); |
| 87 } | 112 } |
| 88 } | 113 } |
| 89 | 114 |
| 90 private: | 115 private: |
| 91 void make_checkerboard() { | |
| 92 const int w = fIsSmall ? FILTER_WIDTH_SMALL : FILTER_WIDTH_LARGE; | |
| 93 const int h = fIsSmall ? FILTER_HEIGHT_LARGE : FILTER_HEIGHT_LARGE; | |
| 94 fCheckerboard.allocN32Pixels(w, h); | |
| 95 SkCanvas canvas(fCheckerboard); | |
| 96 canvas.clear(0x00000000); | |
| 97 SkPaint darkPaint; | |
| 98 darkPaint.setColor(0xFF804020); | |
| 99 SkPaint lightPaint; | |
| 100 lightPaint.setColor(0xFF244484); | |
| 101 for (int y = 0; y < h; y += 16) { | |
| 102 for (int x = 0; x < w; x += 16) { | |
| 103 canvas.save(); | |
| 104 canvas.translate(SkIntToScalar(x), SkIntToScalar(y)); | |
| 105 canvas.drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint); | |
| 106 canvas.drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint); | |
| 107 canvas.drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); | |
| 108 canvas.drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); | |
| 109 canvas.restore(); | |
| 110 } | |
| 111 } | |
| 112 } | |
| 113 | 116 |
| 114 SkString fName; | 117 SkString fName; |
| 115 bool fIsSmall; | 118 bool fIsSmall; |
| 116 bool fIsCropped; | 119 bool fIsCropped; |
| 117 bool fIsExpanded; | 120 bool fIsExpanded; |
| 118 bool fInitialized; | 121 bool fInitialized; |
| 119 SkBitmap fCheckerboard; | 122 SkBitmap fCheckerboard; |
| 120 SkScalar fSigmaX, fSigmaY; | 123 SkScalar fSigmaX, fSigmaY; |
| 121 typedef Benchmark INHERITED; | 124 typedef Benchmark INHERITED; |
| 122 }; | 125 }; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 152 DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_LARGE, false, true, true
);) | 155 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
);) | 156 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);) | 157 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);) | 158 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);) | 159 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);) | 160 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);) | 161 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);) | 162 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);) | 163 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);) | 164 DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_HUGE, BLUR_SIGMA_HUGE, fals
e, true, true);) |
| OLD | NEW |