Chromium Code Reviews| 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 "Resources.h" | |
| 9 #include "SkBlurImageFilter.h" | 10 #include "SkBlurImageFilter.h" |
| 10 #include "SkDisplacementMapEffect.h" | 11 #include "SkDisplacementMapEffect.h" |
| 11 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
| 12 #include "SkMergeImageFilter.h" | 13 #include "SkMergeImageFilter.h" |
| 13 | 14 |
| 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 class ImageFilterDAGBench : public Benchmark { | 19 class ImageFilterDAGBench : public Benchmark { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 38 canvas->drawRect(rect, paint); | 39 canvas->drawRect(rect, paint); |
| 39 } | 40 } |
| 40 } | 41 } |
| 41 | 42 |
| 42 private: | 43 private: |
| 43 static const int kNumInputs = 5; | 44 static const int kNumInputs = 5; |
| 44 | 45 |
| 45 typedef Benchmark INHERITED; | 46 typedef Benchmark INHERITED; |
| 46 }; | 47 }; |
| 47 | 48 |
| 49 class ImageMakeWithFilterDAGBench : public Benchmark { | |
| 50 public: | |
| 51 ImageMakeWithFilterDAGBench() {} | |
| 52 | |
| 53 protected: | |
| 54 const char* onGetName() override { | |
| 55 return "image_make_with_filter_dag"; | |
| 56 } | |
| 57 | |
| 58 void onDelayedSetup() override { | |
| 59 fImage = GetResourceAsImage("mandrill_512.png"); | |
| 60 } | |
| 61 | |
| 62 void onDraw(int loops, SkCanvas* canvas) override { | |
| 63 SkIRect subset = SkIRect::MakeSize(fImage->dimensions()); | |
| 64 SkIPoint offset = SkIPoint::Make(0, 0); | |
| 65 sk_sp<SkImage> image = fImage; | |
| 66 | |
| 67 for (int j = 0; j < loops; j++) { | |
| 68 sk_sp<SkImageFilter> blur(SkBlurImageFilter::Make(20.0f, 20.0f, null ptr)); | |
| 69 sk_sp<SkImageFilter> inputs[kNumInputs]; | |
| 70 for (int i = 0; i < kNumInputs; ++i) { | |
| 71 inputs[i] = blur; | |
| 72 } | |
| 73 sk_sp<SkImageFilter> mergeFilter = SkMergeImageFilter::Make(inputs, kNumInputs); | |
|
robertphillips
2016/09/21 15:50:24
The use of subset & offset here scares me a bit.
| |
| 74 image = image->makeWithFilter(mergeFilter.get(), subset, subset, &su bset, &offset); | |
| 75 SkASSERT(image && image->dimensions() == fImage->dimensions()); | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 private: | |
| 80 static const int kNumInputs = 5; | |
| 81 sk_sp<SkImage> fImage; | |
| 82 | |
| 83 typedef Benchmark INHERITED; | |
| 84 }; | |
| 85 | |
| 48 // Exercise a blur filter connected to both inputs of an SkDisplacementMapEffect . | 86 // Exercise a blur filter connected to both inputs of an SkDisplacementMapEffect . |
| 49 | 87 |
| 50 class ImageFilterDisplacedBlur : public Benchmark { | 88 class ImageFilterDisplacedBlur : public Benchmark { |
| 51 public: | 89 public: |
| 52 ImageFilterDisplacedBlur() {} | 90 ImageFilterDisplacedBlur() {} |
| 53 | 91 |
| 54 protected: | 92 protected: |
| 55 const char* onGetName() override { | 93 const char* onGetName() override { |
| 56 return "image_filter_displaced_blur"; | 94 return "image_filter_displaced_blur"; |
| 57 } | 95 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 70 SkRect rect = SkRect::Make(SkIRect::MakeWH(400, 400)); | 108 SkRect rect = SkRect::Make(SkIRect::MakeWH(400, 400)); |
| 71 canvas->drawRect(rect, paint); | 109 canvas->drawRect(rect, paint); |
| 72 } | 110 } |
| 73 } | 111 } |
| 74 | 112 |
| 75 private: | 113 private: |
| 76 typedef Benchmark INHERITED; | 114 typedef Benchmark INHERITED; |
| 77 }; | 115 }; |
| 78 | 116 |
| 79 DEF_BENCH(return new ImageFilterDAGBench;) | 117 DEF_BENCH(return new ImageFilterDAGBench;) |
| 118 DEF_BENCH(return new ImageMakeWithFilterDAGBench;) | |
| 80 DEF_BENCH(return new ImageFilterDisplacedBlur;) | 119 DEF_BENCH(return new ImageFilterDisplacedBlur;) |
| OLD | NEW |