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" |
11 #include "SkImageSource.h" | 11 #include "SkImageSource.h" |
12 #include "SkSurface.h" | 12 #include "SkSurface.h" |
13 | 13 |
14 #define FILTER_WIDTH_SMALL 32 | 14 #define FILTER_WIDTH_SMALL 32 |
15 #define FILTER_HEIGHT_SMALL 32 | 15 #define FILTER_HEIGHT_SMALL 32 |
16 #define FILTER_WIDTH_LARGE 256 | 16 #define FILTER_WIDTH_LARGE 256 |
17 #define FILTER_HEIGHT_LARGE 256 | 17 #define FILTER_HEIGHT_LARGE 256 |
18 | 18 |
19 class DisplacementBaseBench : public Benchmark { | 19 class DisplacementBaseBench : public Benchmark { |
20 public: | 20 public: |
21 DisplacementBaseBench(bool small) : | 21 DisplacementBaseBench(bool small) : fInitialized(false), fIsSmall(small) { } |
22 fInitialized(false), fIsSmall(small) { | |
23 } | |
24 | 22 |
25 protected: | 23 protected: |
26 void onDelayedSetup() override { | 24 void onDelayedSetup() override { |
27 if (!fInitialized) { | 25 if (!fInitialized) { |
28 this->makeBitmap(); | 26 this->makeBitmap(); |
29 this->makeCheckerboard(); | 27 this->makeCheckerboard(); |
30 fInitialized = true; | 28 fInitialized = true; |
31 } | 29 } |
32 } | 30 } |
33 | 31 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 sk_sp<SkImage> fCheckerboard; | 83 sk_sp<SkImage> fCheckerboard; |
86 | 84 |
87 private: | 85 private: |
88 bool fInitialized; | 86 bool fInitialized; |
89 bool fIsSmall; | 87 bool fIsSmall; |
90 typedef Benchmark INHERITED; | 88 typedef Benchmark INHERITED; |
91 }; | 89 }; |
92 | 90 |
93 class DisplacementZeroBench : public DisplacementBaseBench { | 91 class DisplacementZeroBench : public DisplacementBaseBench { |
94 public: | 92 public: |
95 DisplacementZeroBench(bool small) : INHERITED(small) { | 93 DisplacementZeroBench(bool small) : INHERITED(small) { } |
96 } | |
97 | 94 |
98 protected: | 95 protected: |
99 const char* onGetName() override { | 96 const char* onGetName() override { |
100 return this->isSmall() ? "displacement_zero_small" : "displacement_zero_
large"; | 97 return this->isSmall() ? "displacement_zero_small" : "displacement_zero_
large"; |
101 } | 98 } |
102 | 99 |
103 void onDraw(int loops, SkCanvas* canvas) override { | 100 void onDraw(int loops, SkCanvas* canvas) override { |
104 SkPaint paint; | 101 SkPaint paint; |
105 sk_sp<SkImageFilter> displ(SkImageSource::Make(fCheckerboard)); | 102 sk_sp<SkImageFilter> displ(SkImageSource::Make(fCheckerboard)); |
106 // No displacement effect | 103 // No displacement effect |
107 paint.setImageFilter(SkDisplacementMapEffect::Create( | 104 paint.setImageFilter(SkDisplacementMapEffect::Make( |
108 SkDisplacementMapEffect::kR_ChannelSelectorType, | 105 SkDisplacementMapEffect::kR_Chan
nelSelectorType, |
109 SkDisplacementMapEffect::kG_ChannelSelectorType, 0.0f, displ.get()))
->unref(); | 106 SkDisplacementMapEffect::kG_Chan
nelSelectorType, |
| 107 0.0f, std::move(displ), nullptr)
); |
110 | 108 |
111 for (int i = 0; i < loops; i++) { | 109 for (int i = 0; i < loops; i++) { |
112 this->drawClippedBitmap(canvas, 0, 0, paint); | 110 this->drawClippedBitmap(canvas, 0, 0, paint); |
113 } | 111 } |
114 } | 112 } |
115 | 113 |
116 private: | 114 private: |
117 typedef DisplacementBaseBench INHERITED; | 115 typedef DisplacementBaseBench INHERITED; |
118 }; | 116 }; |
119 | 117 |
120 class DisplacementAlphaBench : public DisplacementBaseBench { | 118 class DisplacementAlphaBench : public DisplacementBaseBench { |
121 public: | 119 public: |
122 DisplacementAlphaBench(bool small) : INHERITED(small) { | 120 DisplacementAlphaBench(bool small) : INHERITED(small) { } |
123 } | |
124 | 121 |
125 protected: | 122 protected: |
126 const char* onGetName() override { | 123 const char* onGetName() override { |
127 return isSmall() ? "displacement_alpha_small" : "displacement_alpha_larg
e"; | 124 return isSmall() ? "displacement_alpha_small" : "displacement_alpha_larg
e"; |
128 } | 125 } |
129 | 126 |
130 void onDraw(int loops, SkCanvas* canvas) override { | 127 void onDraw(int loops, SkCanvas* canvas) override { |
131 SkPaint paint; | 128 SkPaint paint; |
132 sk_sp<SkImageFilter> displ(SkImageSource::Make(fCheckerboard)); | 129 sk_sp<SkImageFilter> displ(SkImageSource::Make(fCheckerboard)); |
133 // Displacement, with 1 alpha component (which isn't pre-multiplied) | 130 // Displacement, with 1 alpha component (which isn't pre-multiplied) |
134 paint.setImageFilter(SkDisplacementMapEffect::Create( | 131 paint.setImageFilter(SkDisplacementMapEffect::Make( |
135 SkDisplacementMapEffect::kB_ChannelSelectorType, | 132 SkDisplacementMapEffect::kB_Chan
nelSelectorType, |
136 SkDisplacementMapEffect::kA_ChannelSelectorType, 16.0f, displ.get())
)->unref(); | 133 SkDisplacementMapEffect::kA_Chan
nelSelectorType, |
| 134 16.0f, std::move(displ), nullptr
)); |
137 for (int i = 0; i < loops; i++) { | 135 for (int i = 0; i < loops; i++) { |
138 drawClippedBitmap(canvas, 100, 0, paint); | 136 this->drawClippedBitmap(canvas, 100, 0, paint); |
139 } | 137 } |
140 } | 138 } |
141 | 139 |
142 private: | 140 private: |
143 typedef DisplacementBaseBench INHERITED; | 141 typedef DisplacementBaseBench INHERITED; |
144 }; | 142 }; |
145 | 143 |
146 class DisplacementFullBench : public DisplacementBaseBench { | 144 class DisplacementFullBench : public DisplacementBaseBench { |
147 public: | 145 public: |
148 DisplacementFullBench(bool small) : INHERITED(small) { | 146 DisplacementFullBench(bool small) : INHERITED(small) { } |
149 } | |
150 | 147 |
151 protected: | 148 protected: |
152 const char* onGetName() override { | 149 const char* onGetName() override { |
153 return isSmall() ? "displacement_full_small" : "displacement_full_large"
; | 150 return isSmall() ? "displacement_full_small" : "displacement_full_large"
; |
154 } | 151 } |
155 | 152 |
156 void onDraw(int loops, SkCanvas* canvas) override { | 153 void onDraw(int loops, SkCanvas* canvas) override { |
157 SkPaint paint; | 154 SkPaint paint; |
158 sk_sp<SkImageFilter> displ(SkImageSource::Make(fCheckerboard)); | 155 sk_sp<SkImageFilter> displ(SkImageSource::Make(fCheckerboard)); |
159 // Displacement, with 2 non-alpha components | 156 // Displacement, with 2 non-alpha components |
160 paint.setImageFilter(SkDisplacementMapEffect::Create( | 157 paint.setImageFilter(SkDisplacementMapEffect::Make( |
161 SkDisplacementMapEffect::kR_ChannelSelectorType, | 158 SkDisplacementMapEffect::kR_Chan
nelSelectorType, |
162 SkDisplacementMapEffect::kB_ChannelSelectorType, 32.0f, displ.get())
)->unref(); | 159 SkDisplacementMapEffect::kB_Chan
nelSelectorType, |
| 160 32.0f, std::move(displ), nullptr
)); |
163 for (int i = 0; i < loops; ++i) { | 161 for (int i = 0; i < loops; ++i) { |
164 this->drawClippedBitmap(canvas, 200, 0, paint); | 162 this->drawClippedBitmap(canvas, 200, 0, paint); |
165 } | 163 } |
166 } | 164 } |
167 | 165 |
168 private: | 166 private: |
169 typedef DisplacementBaseBench INHERITED; | 167 typedef DisplacementBaseBench INHERITED; |
170 }; | 168 }; |
171 | 169 |
172 /////////////////////////////////////////////////////////////////////////////// | 170 /////////////////////////////////////////////////////////////////////////////// |
173 | 171 |
174 DEF_BENCH( return new DisplacementZeroBench(true); ) | 172 DEF_BENCH( return new DisplacementZeroBench(true); ) |
175 DEF_BENCH( return new DisplacementAlphaBench(true); ) | 173 DEF_BENCH( return new DisplacementAlphaBench(true); ) |
176 DEF_BENCH( return new DisplacementFullBench(true); ) | 174 DEF_BENCH( return new DisplacementFullBench(true); ) |
177 DEF_BENCH( return new DisplacementZeroBench(false); ) | 175 DEF_BENCH( return new DisplacementZeroBench(false); ) |
178 DEF_BENCH( return new DisplacementAlphaBench(false); ) | 176 DEF_BENCH( return new DisplacementAlphaBench(false); ) |
179 DEF_BENCH( return new DisplacementFullBench(false); ) | 177 DEF_BENCH( return new DisplacementFullBench(false); ) |
OLD | NEW |