| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkDisplacementMapEffect.h" | 10 #include "SkDisplacementMapEffect.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 canvas->save(); | 60 canvas->save(); |
| 61 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); | 61 canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
| 62 canvas->drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint); | 62 canvas->drawRect(SkRect::MakeXYWH(0, 0, 8, 8), darkPaint); |
| 63 canvas->drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint); | 63 canvas->drawRect(SkRect::MakeXYWH(8, 0, 8, 8), lightPaint); |
| 64 canvas->drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); | 64 canvas->drawRect(SkRect::MakeXYWH(0, 8, 8, 8), lightPaint); |
| 65 canvas->drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); | 65 canvas->drawRect(SkRect::MakeXYWH(8, 8, 8, 8), darkPaint); |
| 66 canvas->restore(); | 66 canvas->restore(); |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 | 69 |
| 70 fCheckerboard.reset(surface->newImageSnapshot()); | 70 fCheckerboard = surface->makeImageSnapshot(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& paint)
{ | 73 void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& paint)
{ |
| 74 canvas->save(); | 74 canvas->save(); |
| 75 canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), | 75 canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), |
| 76 SkIntToScalar(fBitmap.width()), | 76 SkIntToScalar(fBitmap.width()), |
| 77 SkIntToScalar(fBitmap.height()))); | 77 SkIntToScalar(fBitmap.height()))); |
| 78 canvas->drawBitmap(fBitmap, SkIntToScalar(x), SkIntToScalar(y), &paint); | 78 canvas->drawBitmap(fBitmap, SkIntToScalar(x), SkIntToScalar(y), &paint); |
| 79 canvas->restore(); | 79 canvas->restore(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 inline bool isSmall() const { return fIsSmall; } | 82 inline bool isSmall() const { return fIsSmall; } |
| 83 | 83 |
| 84 SkBitmap fBitmap; | 84 SkBitmap fBitmap; |
| 85 SkAutoTUnref<SkImage> fCheckerboard; | 85 sk_sp<SkImage> fCheckerboard; |
| 86 | 86 |
| 87 private: | 87 private: |
| 88 bool fInitialized; | 88 bool fInitialized; |
| 89 bool fIsSmall; | 89 bool fIsSmall; |
| 90 typedef Benchmark INHERITED; | 90 typedef Benchmark INHERITED; |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 class DisplacementZeroBench : public DisplacementBaseBench { | 93 class DisplacementZeroBench : public DisplacementBaseBench { |
| 94 public: | 94 public: |
| 95 DisplacementZeroBench(bool small) : INHERITED(small) { | 95 DisplacementZeroBench(bool small) : INHERITED(small) { |
| 96 } | 96 } |
| 97 | 97 |
| 98 protected: | 98 protected: |
| 99 const char* onGetName() override { | 99 const char* onGetName() override { |
| 100 return this->isSmall() ? "displacement_zero_small" : "displacement_zero_
large"; | 100 return this->isSmall() ? "displacement_zero_small" : "displacement_zero_
large"; |
| 101 } | 101 } |
| 102 | 102 |
| 103 void onDraw(int loops, SkCanvas* canvas) override { | 103 void onDraw(int loops, SkCanvas* canvas) override { |
| 104 SkPaint paint; | 104 SkPaint paint; |
| 105 SkAutoTUnref<SkImageFilter> displ(SkImageSource::Create(fCheckerboard)); | 105 SkAutoTUnref<SkImageFilter> displ(SkImageSource::Create(fCheckerboard.ge
t())); |
| 106 // No displacement effect | 106 // No displacement effect |
| 107 paint.setImageFilter(SkDisplacementMapEffect::Create( | 107 paint.setImageFilter(SkDisplacementMapEffect::Create( |
| 108 SkDisplacementMapEffect::kR_ChannelSelectorType, | 108 SkDisplacementMapEffect::kR_ChannelSelectorType, |
| 109 SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ))->unre
f(); | 109 SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ))->unre
f(); |
| 110 | 110 |
| 111 for (int i = 0; i < loops; i++) { | 111 for (int i = 0; i < loops; i++) { |
| 112 this->drawClippedBitmap(canvas, 0, 0, paint); | 112 this->drawClippedBitmap(canvas, 0, 0, paint); |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 | 115 |
| 116 private: | 116 private: |
| 117 typedef DisplacementBaseBench INHERITED; | 117 typedef DisplacementBaseBench INHERITED; |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 class DisplacementAlphaBench : public DisplacementBaseBench { | 120 class DisplacementAlphaBench : public DisplacementBaseBench { |
| 121 public: | 121 public: |
| 122 DisplacementAlphaBench(bool small) : INHERITED(small) { | 122 DisplacementAlphaBench(bool small) : INHERITED(small) { |
| 123 } | 123 } |
| 124 | 124 |
| 125 protected: | 125 protected: |
| 126 const char* onGetName() override { | 126 const char* onGetName() override { |
| 127 return isSmall() ? "displacement_alpha_small" : "displacement_alpha_larg
e"; | 127 return isSmall() ? "displacement_alpha_small" : "displacement_alpha_larg
e"; |
| 128 } | 128 } |
| 129 | 129 |
| 130 void onDraw(int loops, SkCanvas* canvas) override { | 130 void onDraw(int loops, SkCanvas* canvas) override { |
| 131 SkPaint paint; | 131 SkPaint paint; |
| 132 SkAutoTUnref<SkImageFilter> displ(SkImageSource::Create(fCheckerboard)); | 132 SkAutoTUnref<SkImageFilter> displ(SkImageSource::Create(fCheckerboard.ge
t())); |
| 133 // Displacement, with 1 alpha component (which isn't pre-multiplied) | 133 // Displacement, with 1 alpha component (which isn't pre-multiplied) |
| 134 paint.setImageFilter(SkDisplacementMapEffect::Create( | 134 paint.setImageFilter(SkDisplacementMapEffect::Create( |
| 135 SkDisplacementMapEffect::kB_ChannelSelectorType, | 135 SkDisplacementMapEffect::kB_ChannelSelectorType, |
| 136 SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ))->unr
ef(); | 136 SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ))->unr
ef(); |
| 137 for (int i = 0; i < loops; i++) { | 137 for (int i = 0; i < loops; i++) { |
| 138 drawClippedBitmap(canvas, 100, 0, paint); | 138 drawClippedBitmap(canvas, 100, 0, paint); |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 private: | 142 private: |
| 143 typedef DisplacementBaseBench INHERITED; | 143 typedef DisplacementBaseBench INHERITED; |
| 144 }; | 144 }; |
| 145 | 145 |
| 146 class DisplacementFullBench : public DisplacementBaseBench { | 146 class DisplacementFullBench : public DisplacementBaseBench { |
| 147 public: | 147 public: |
| 148 DisplacementFullBench(bool small) : INHERITED(small) { | 148 DisplacementFullBench(bool small) : INHERITED(small) { |
| 149 } | 149 } |
| 150 | 150 |
| 151 protected: | 151 protected: |
| 152 const char* onGetName() override { | 152 const char* onGetName() override { |
| 153 return isSmall() ? "displacement_full_small" : "displacement_full_large"
; | 153 return isSmall() ? "displacement_full_small" : "displacement_full_large"
; |
| 154 } | 154 } |
| 155 | 155 |
| 156 void onDraw(int loops, SkCanvas* canvas) override { | 156 void onDraw(int loops, SkCanvas* canvas) override { |
| 157 SkPaint paint; | 157 SkPaint paint; |
| 158 SkAutoTUnref<SkImageFilter> displ(SkImageSource::Create(fCheckerboard)); | 158 SkAutoTUnref<SkImageFilter> displ(SkImageSource::Create(fCheckerboard.ge
t())); |
| 159 // Displacement, with 2 non-alpha components | 159 // Displacement, with 2 non-alpha components |
| 160 paint.setImageFilter(SkDisplacementMapEffect::Create( | 160 paint.setImageFilter(SkDisplacementMapEffect::Create( |
| 161 SkDisplacementMapEffect::kR_ChannelSelectorType, | 161 SkDisplacementMapEffect::kR_ChannelSelectorType, |
| 162 SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ))->unr
ef(); | 162 SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ))->unr
ef(); |
| 163 for (int i = 0; i < loops; ++i) { | 163 for (int i = 0; i < loops; ++i) { |
| 164 this->drawClippedBitmap(canvas, 200, 0, paint); | 164 this->drawClippedBitmap(canvas, 200, 0, paint); |
| 165 } | 165 } |
| 166 } | 166 } |
| 167 | 167 |
| 168 private: | 168 private: |
| 169 typedef DisplacementBaseBench INHERITED; | 169 typedef DisplacementBaseBench INHERITED; |
| 170 }; | 170 }; |
| 171 | 171 |
| 172 /////////////////////////////////////////////////////////////////////////////// | 172 /////////////////////////////////////////////////////////////////////////////// |
| 173 | 173 |
| 174 DEF_BENCH( return new DisplacementZeroBench(true); ) | 174 DEF_BENCH( return new DisplacementZeroBench(true); ) |
| 175 DEF_BENCH( return new DisplacementAlphaBench(true); ) | 175 DEF_BENCH( return new DisplacementAlphaBench(true); ) |
| 176 DEF_BENCH( return new DisplacementFullBench(true); ) | 176 DEF_BENCH( return new DisplacementFullBench(true); ) |
| 177 DEF_BENCH( return new DisplacementZeroBench(false); ) | 177 DEF_BENCH( return new DisplacementZeroBench(false); ) |
| 178 DEF_BENCH( return new DisplacementAlphaBench(false); ) | 178 DEF_BENCH( return new DisplacementAlphaBench(false); ) |
| 179 DEF_BENCH( return new DisplacementFullBench(false); ) | 179 DEF_BENCH( return new DisplacementFullBench(false); ) |
| OLD | NEW |