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 "SkDisplacementMapEffect.h" |
11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
12 #include "SkMergeImageFilter.h" | 12 #include "SkMergeImageFilter.h" |
13 | 13 |
14 enum { kNumInputs = 5 }; | |
15 | 14 |
16 // Exercise a blur filter connected to 5 inputs of the same merge filter. | 15 // Exercise a blur filter connected to 5 inputs of the same merge filter. |
17 // This bench shows an improvement in performance once cacheing of re-used | 16 // This bench shows an improvement in performance once cacheing of re-used |
18 // nodes is implemented, since the DAG is no longer flattened to a tree. | 17 // nodes is implemented, since the DAG is no longer flattened to a tree. |
19 | |
20 class ImageFilterDAGBench : public Benchmark { | 18 class ImageFilterDAGBench : public Benchmark { |
21 public: | 19 public: |
22 ImageFilterDAGBench() {} | 20 ImageFilterDAGBench() {} |
23 | 21 |
24 protected: | 22 protected: |
25 const char* onGetName() override { | 23 const char* onGetName() override { |
26 return "image_filter_dag"; | 24 return "image_filter_dag"; |
27 } | 25 } |
28 | 26 |
29 void onDraw(int loops, SkCanvas* canvas) override { | 27 void onDraw(int loops, SkCanvas* canvas) override { |
| 28 const SkRect rect = SkRect::Make(SkIRect::MakeWH(400, 400)); |
| 29 |
30 for (int j = 0; j < loops; j++) { | 30 for (int j = 0; j < loops; j++) { |
31 SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(20.0f, 20
.0f)); | 31 sk_sp<SkImageFilter> blur(SkBlurImageFilter::Create(20.0f, 20.0f)); |
32 SkImageFilter* inputs[kNumInputs]; | 32 sk_sp<SkImageFilter> inputs[kNumInputs]; |
33 for (int i = 0; i < kNumInputs; ++i) { | 33 for (int i = 0; i < kNumInputs; ++i) { |
34 inputs[i] = blur.get(); | 34 inputs[i] = blur; |
35 } | 35 } |
36 SkAutoTUnref<SkImageFilter> merge(SkMergeImageFilter::Create(inputs,
kNumInputs)); | |
37 SkPaint paint; | 36 SkPaint paint; |
38 paint.setImageFilter(merge); | 37 paint.setImageFilter(SkMergeImageFilter::Make(inputs, kNumInputs)); |
39 SkRect rect = SkRect::Make(SkIRect::MakeWH(400, 400)); | |
40 canvas->drawRect(rect, paint); | 38 canvas->drawRect(rect, paint); |
41 } | 39 } |
42 } | 40 } |
43 | 41 |
44 private: | 42 private: |
| 43 static const int kNumInputs = 5; |
| 44 |
45 typedef Benchmark INHERITED; | 45 typedef Benchmark INHERITED; |
46 }; | 46 }; |
47 | 47 |
48 // Exercise a blur filter connected to both inputs of an SkDisplacementMapEffect
. | 48 // Exercise a blur filter connected to both inputs of an SkDisplacementMapEffect
. |
49 | 49 |
50 class ImageFilterDisplacedBlur : public Benchmark { | 50 class ImageFilterDisplacedBlur : public Benchmark { |
51 public: | 51 public: |
52 ImageFilterDisplacedBlur() {} | 52 ImageFilterDisplacedBlur() {} |
53 | 53 |
54 protected: | 54 protected: |
(...skipping 15 matching lines...) Expand all Loading... |
70 canvas->drawRect(rect, paint); | 70 canvas->drawRect(rect, paint); |
71 } | 71 } |
72 } | 72 } |
73 | 73 |
74 private: | 74 private: |
75 typedef Benchmark INHERITED; | 75 typedef Benchmark INHERITED; |
76 }; | 76 }; |
77 | 77 |
78 DEF_BENCH(return new ImageFilterDAGBench;) | 78 DEF_BENCH(return new ImageFilterDAGBench;) |
79 DEF_BENCH(return new ImageFilterDisplacedBlur;) | 79 DEF_BENCH(return new ImageFilterDisplacedBlur;) |
OLD | NEW |