OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkDisplacementMapEffect.h" |
10 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
11 #include "SkMergeImageFilter.h" | 12 #include "SkMergeImageFilter.h" |
12 | 13 |
13 enum { kNumInputs = 5 }; | 14 enum { kNumInputs = 5 }; |
14 | 15 |
15 // Exercise a blur filter connected to 5 inputs of the same merge filter. | 16 // Exercise a blur filter connected to 5 inputs of the same merge filter. |
16 // This bench shows an improvement in performance once cacheing of re-used | 17 // This bench shows an improvement in performance once cacheing of re-used |
17 // nodes is implemented, since the DAG is no longer flattened to a tree. | 18 // nodes is implemented, since the DAG is no longer flattened to a tree. |
18 | 19 |
19 class ImageFilterDAGBench : public Benchmark { | 20 class ImageFilterDAGBench : public Benchmark { |
(...skipping 17 matching lines...) Expand all Loading... |
37 paint.setImageFilter(merge); | 38 paint.setImageFilter(merge); |
38 SkRect rect = SkRect::Make(SkIRect::MakeWH(400, 400)); | 39 SkRect rect = SkRect::Make(SkIRect::MakeWH(400, 400)); |
39 canvas->drawRect(rect, paint); | 40 canvas->drawRect(rect, paint); |
40 } | 41 } |
41 } | 42 } |
42 | 43 |
43 private: | 44 private: |
44 typedef Benchmark INHERITED; | 45 typedef Benchmark INHERITED; |
45 }; | 46 }; |
46 | 47 |
| 48 // Exercise a blur filter connected to both inputs of an SkDisplacementMapEffect
. |
| 49 |
| 50 class ImageFilterDisplacedBlur : public Benchmark { |
| 51 public: |
| 52 ImageFilterDisplacedBlur() {} |
| 53 |
| 54 protected: |
| 55 const char* onGetName() override { |
| 56 return "image_filter_displaced_blur"; |
| 57 } |
| 58 |
| 59 void onDraw(int loops, SkCanvas* canvas) override { |
| 60 for (int j = 0; j < loops; j++) { |
| 61 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(4.0f, 4.0
f)); |
| 62 SkDisplacementMapEffect::ChannelSelectorType xSelector = SkDisplacem
entMapEffect::kR_ChannelSelectorType; |
| 63 SkDisplacementMapEffect::ChannelSelectorType ySelector = SkDisplacem
entMapEffect::kB_ChannelSelectorType; |
| 64 SkScalar scale = 2; |
| 65 SkAutoTUnref<SkImageFilter> displ(SkDisplacementMapEffect::Create(xS
elector, ySelector, scale, |
| 66 bl
ur.get(), blur.get())); |
| 67 SkPaint paint; |
| 68 paint.setImageFilter(displ); |
| 69 SkRect rect = SkRect::Make(SkIRect::MakeWH(400, 400)); |
| 70 canvas->drawRect(rect, paint); |
| 71 } |
| 72 } |
| 73 |
| 74 private: |
| 75 typedef Benchmark INHERITED; |
| 76 }; |
| 77 |
47 DEF_BENCH(return new ImageFilterDAGBench;) | 78 DEF_BENCH(return new ImageFilterDAGBench;) |
| 79 DEF_BENCH(return new ImageFilterDisplacedBlur;) |
OLD | NEW |