| 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 "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| 11 #include "SkColorFilterImageFilter.h" | 11 #include "SkColorFilterImageFilter.h" |
| 12 #include "SkColorMatrixFilter.h" | 12 #include "SkColorMatrixFilter.h" |
| 13 #include "SkGradientShader.h" | 13 #include "SkGradientShader.h" |
| 14 #include "SkImageFilter.h" | 14 #include "SkImageFilter.h" |
| 15 #include "SkTableColorFilter.h" | 15 #include "SkTableColorFilter.h" |
| 16 | 16 |
| 17 // Chains several matrix color filters image filter or several | 17 // Chains several matrix color filters image filter or several |
| 18 // table filter image filters and draws a bitmap. | 18 // table filter image filters and draws a bitmap. |
| 19 // This bench shows an improvement in performance and memory | 19 // This bench shows an improvement in performance and memory |
| 20 // when collapsing matrices or tables is implemented since all | 20 // when collapsing matrices or tables is implemented since all |
| 21 // the passes are collapsed in one. | 21 // the passes are collapsed in one. |
| 22 | 22 |
| 23 class BaseImageFilterCollapseBench : public Benchmark { | 23 class BaseImageFilterCollapseBench : public Benchmark { |
| 24 public: | 24 public: |
| 25 BaseImageFilterCollapseBench(): fImageFilter(NULL) {} | 25 BaseImageFilterCollapseBench(): fImageFilter(nullptr) {} |
| 26 ~BaseImageFilterCollapseBench() { | 26 ~BaseImageFilterCollapseBench() { |
| 27 SkSafeUnref(fImageFilter); | 27 SkSafeUnref(fImageFilter); |
| 28 } | 28 } |
| 29 | 29 |
| 30 protected: | 30 protected: |
| 31 void doPreDraw(SkColorFilter* colorFilters[], int nFilters) { | 31 void doPreDraw(SkColorFilter* colorFilters[], int nFilters) { |
| 32 // Create a chain of ImageFilters from colorFilters | 32 // Create a chain of ImageFilters from colorFilters |
| 33 fImageFilter = NULL; | 33 fImageFilter = nullptr; |
| 34 for(int i = nFilters; i --> 0;) { | 34 for(int i = nFilters; i --> 0;) { |
| 35 SkAutoTUnref<SkImageFilter> filter( | 35 SkAutoTUnref<SkImageFilter> filter( |
| 36 SkColorFilterImageFilter::Create(colorFilters[i], fImage
Filter, NULL) | 36 SkColorFilterImageFilter::Create(colorFilters[i], fImage
Filter, nullptr) |
| 37 ); | 37 ); |
| 38 SkRefCnt_SafeAssign(fImageFilter, filter.get()); | 38 SkRefCnt_SafeAssign(fImageFilter, filter.get()); |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 | 41 |
| 42 void onDraw(const int loops, SkCanvas* canvas) override { | 42 void onDraw(const int loops, SkCanvas* canvas) override { |
| 43 makeBitmap(); | 43 makeBitmap(); |
| 44 | 44 |
| 45 for(int i = 0; i < loops; i++) { | 45 for(int i = 0; i < loops; i++) { |
| 46 SkPaint paint; | 46 SkPaint paint; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 60 fBitmap.eraseColor(SK_ColorTRANSPARENT); | 60 fBitmap.eraseColor(SK_ColorTRANSPARENT); |
| 61 | 61 |
| 62 SkCanvas canvas(fBitmap); | 62 SkCanvas canvas(fBitmap); |
| 63 SkPaint paint; | 63 SkPaint paint; |
| 64 SkPoint pts[] = { {0, 0}, {SkIntToScalar(W), SkIntToScalar(H)} }; | 64 SkPoint pts[] = { {0, 0}, {SkIntToScalar(W), SkIntToScalar(H)} }; |
| 65 SkColor colors[] = { | 65 SkColor colors[] = { |
| 66 SK_ColorBLACK, SK_ColorGREEN, SK_ColorCYAN, | 66 SK_ColorBLACK, SK_ColorGREEN, SK_ColorCYAN, |
| 67 SK_ColorRED, 0, SK_ColorBLUE, SK_ColorWHITE | 67 SK_ColorRED, 0, SK_ColorBLUE, SK_ColorWHITE |
| 68 }; | 68 }; |
| 69 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear( | 69 SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear( |
| 70 pts, colors, NULL, SK_ARRAY_COUNT(colors), SkShader::kClamp_
TileMode | 70 pts, colors, nullptr, SK_ARRAY_COUNT(colors), SkShader::kCla
mp_TileMode |
| 71 )); | 71 )); |
| 72 paint.setShader(shader); | 72 paint.setShader(shader); |
| 73 canvas.drawPaint(paint); | 73 canvas.drawPaint(paint); |
| 74 } | 74 } |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 class TableCollapseBench: public BaseImageFilterCollapseBench { | 77 class TableCollapseBench: public BaseImageFilterCollapseBench { |
| 78 public: | 78 public: |
| 79 virtual ~TableCollapseBench() {} | 79 virtual ~TableCollapseBench() {} |
| 80 | 80 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 doPreDraw(colorFilters, SK_ARRAY_COUNT(colorFilters)); | 149 doPreDraw(colorFilters, SK_ARRAY_COUNT(colorFilters)); |
| 150 | 150 |
| 151 for(unsigned i = 0; i < SK_ARRAY_COUNT(colorFilters); i++) { | 151 for(unsigned i = 0; i < SK_ARRAY_COUNT(colorFilters); i++) { |
| 152 colorFilters[i]->unref(); | 152 colorFilters[i]->unref(); |
| 153 } | 153 } |
| 154 } | 154 } |
| 155 }; | 155 }; |
| 156 | 156 |
| 157 DEF_BENCH(return new TableCollapseBench;) | 157 DEF_BENCH(return new TableCollapseBench;) |
| 158 DEF_BENCH(return new MatrixCollapseBench;) | 158 DEF_BENCH(return new MatrixCollapseBench;) |
| OLD | NEW |