senorblanco@chromium.org | 0d64356 | 2014-04-10 16:16:13 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkBenchmark.h" |
| 9 | #include "SkBlurImageFilter.h" |
| 10 | #include "SkMergeImageFilter.h" |
| 11 | #include "SkCanvas.h" |
| 12 | |
| 13 | enum { kNumInputs = 5 }; |
| 14 | |
| 15 | // 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 | // nodes is implemented, since the DAG is no longer flattened to a tree. |
| 18 | |
| 19 | class ImageFilterDAGBench : public SkBenchmark { |
| 20 | public: |
| 21 | ImageFilterDAGBench() { |
| 22 | } |
| 23 | |
| 24 | protected: |
| 25 | virtual const char* onGetName() SK_OVERRIDE { |
| 26 | return "image_filter_dag"; |
| 27 | } |
| 28 | |
| 29 | virtual void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE { |
| 30 | SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(20.0f, 20.0f)); |
| 31 | SkImageFilter* inputs[kNumInputs]; |
| 32 | for (int i = 0; i < kNumInputs; ++i) { |
| 33 | inputs[i] = blur.get(); |
| 34 | } |
| 35 | SkAutoTUnref<SkImageFilter> merge(SkMergeImageFilter::Create(inputs, kNumInputs)); |
| 36 | SkPaint paint; |
| 37 | paint.setImageFilter(merge); |
| 38 | SkRect rect = SkRect::Make(SkIRect::MakeWH(400, 400)); |
| 39 | canvas->drawRect(rect, paint); |
| 40 | } |
| 41 | |
| 42 | private: |
| 43 | typedef SkBenchmark INHERITED; |
| 44 | }; |
| 45 | |
| 46 | DEF_BENCH(return new ImageFilterDAGBench;) |