OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 <memory> | 8 #include <memory> |
9 #include "SkColor.h" | 9 #include "SkColor.h" |
10 #include "SkLinearBitmapPipeline.h" | 10 #include "SkLinearBitmapPipeline.h" |
11 #include "SkBitmapProcShader.h" | 11 #include "SkBitmapProcShader.h" |
12 #include "SkPM4f.h" | 12 #include "SkPM4f.h" |
13 #include "Benchmark.h" | 13 #include "Benchmark.h" |
14 #include "SkShader.h" | 14 #include "SkShader.h" |
15 #include "SkImage.h" | 15 #include "SkImage.h" |
16 | 16 |
17 struct CommonBitmapFPBenchmark : public Benchmark { | 17 struct CommonBitmapFPBenchmark : public Benchmark { |
18 CommonBitmapFPBenchmark( | 18 CommonBitmapFPBenchmark( |
19 SkISize srcSize, | 19 SkISize srcSize, |
20 SkColorProfileType colorProfile, | 20 bool isSRGB, |
21 SkMatrix m, | 21 SkMatrix m, |
22 bool useBilerp, | 22 bool useBilerp, |
23 SkShader::TileMode xTile, | 23 SkShader::TileMode xTile, |
24 SkShader::TileMode yTile) | 24 SkShader::TileMode yTile) |
25 : fColorProfile(colorProfile) | 25 : fIsSRGB(isSRGB) |
26 , fM{m} | 26 , fM{m} |
27 , fUseBilerp{useBilerp} | 27 , fUseBilerp{useBilerp} |
28 , fXTile{xTile} | 28 , fXTile{xTile} |
29 , fYTile{yTile} { | 29 , fYTile{yTile} { |
30 fSrcSize = srcSize; | 30 fSrcSize = srcSize; |
31 } | 31 } |
32 | 32 |
33 static SkString tileName(const char* pre, SkShader::TileMode mode) { | 33 static SkString tileName(const char* pre, SkShader::TileMode mode) { |
34 SkString name{pre}; | 34 SkString name{pre}; |
35 switch (mode) { | 35 switch (mode) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 fBitmap.reset(new uint32_t[width * height]); | 82 fBitmap.reset(new uint32_t[width * height]); |
83 for (int y = 0; y < height; y++) { | 83 for (int y = 0; y < height; y++) { |
84 for (int x = 0; x < width; x++) { | 84 for (int x = 0; x < width; x++) { |
85 fBitmap[y * width + x] = (y << 8) + x + (128<<24); | 85 fBitmap[y * width + x] = (y << 8) + x + (128<<24); |
86 } | 86 } |
87 } | 87 } |
88 | 88 |
89 bool trash = fM.invert(&fInvert); | 89 bool trash = fM.invert(&fInvert); |
90 sk_ignore_unused_variable(trash); | 90 sk_ignore_unused_variable(trash); |
91 | 91 |
92 fInfo = SkImageInfo::MakeN32Premul(width, height, fColorProfile); | 92 fInfo = SkImageInfo::MakeN32Premul(width, height, fIsSRGB ? |
| 93 SkColorSpace::NewNamed(SkColorSpace::kSRG
B_Named) : nullptr); |
93 } | 94 } |
94 | 95 |
95 bool isSuitableFor(Backend backend) override { | 96 bool isSuitableFor(Backend backend) override { |
96 return backend == kNonRendering_Backend; | 97 return backend == kNonRendering_Backend; |
97 } | 98 } |
98 | 99 |
99 virtual SkString BaseName() = 0; | 100 virtual SkString BaseName() = 0; |
100 | 101 |
101 SkString fName; | 102 SkString fName; |
102 SkISize fSrcSize; | 103 SkISize fSrcSize; |
103 SkColorProfileType fColorProfile; | 104 bool fIsSRGB; |
104 SkMatrix fM; | 105 SkMatrix fM; |
105 SkMatrix fInvert; | 106 SkMatrix fInvert; |
106 bool fUseBilerp; | 107 bool fUseBilerp; |
107 SkShader::TileMode fXTile; | 108 SkShader::TileMode fXTile; |
108 SkShader::TileMode fYTile; | 109 SkShader::TileMode fYTile; |
109 SkImageInfo fInfo; | 110 SkImageInfo fInfo; |
110 std::unique_ptr<uint32_t[]> fBitmap; | 111 std::unique_ptr<uint32_t[]> fBitmap; |
111 }; | 112 }; |
112 | 113 |
113 struct SkBitmapFPGeneral final : public CommonBitmapFPBenchmark { | 114 struct SkBitmapFPGeneral final : public CommonBitmapFPBenchmark { |
114 SkBitmapFPGeneral( | 115 SkBitmapFPGeneral( |
115 SkISize srcSize, | 116 SkISize srcSize, |
116 SkColorProfileType colorProfile, | 117 bool isSRGB, |
117 SkMatrix m, | 118 SkMatrix m, |
118 bool useBilerp, | 119 bool useBilerp, |
119 SkShader::TileMode xTile, | 120 SkShader::TileMode xTile, |
120 SkShader::TileMode yTile) | 121 SkShader::TileMode yTile) |
121 : CommonBitmapFPBenchmark(srcSize, colorProfile, m, useBilerp, xTile
, yTile) { } | 122 : CommonBitmapFPBenchmark(srcSize, isSRGB, m, useBilerp, xTile, yTil
e) { } |
122 | 123 |
123 SkString BaseName() override { | 124 SkString BaseName() override { |
124 SkString name; | 125 SkString name; |
125 if (fInfo.isSRGB()) { | 126 if (fInfo.gammaCloseToSRGB()) { |
126 name.set("sRGB"); | 127 name.set("sRGB"); |
127 } else { | 128 } else { |
128 name.set("Linr"); | 129 name.set("Linr"); |
129 } | 130 } |
130 return name; | 131 return name; |
131 } | 132 } |
132 | 133 |
133 void onDraw(int loops, SkCanvas*) override { | 134 void onDraw(int loops, SkCanvas*) override { |
134 int width = fSrcSize.fWidth; | 135 int width = fSrcSize.fWidth; |
135 int height = fSrcSize.fHeight; | 136 int height = fSrcSize.fHeight; |
(...skipping 16 matching lines...) Expand all Loading... |
152 | 153 |
153 for (int n = 0; n < 1000*loops; n++) { | 154 for (int n = 0; n < 1000*loops; n++) { |
154 pipeline.shadeSpan4f(3, 6, FPbuffer, count); | 155 pipeline.shadeSpan4f(3, 6, FPbuffer, count); |
155 } | 156 } |
156 } | 157 } |
157 }; | 158 }; |
158 | 159 |
159 struct SkBitmapFPOrigShader : public CommonBitmapFPBenchmark { | 160 struct SkBitmapFPOrigShader : public CommonBitmapFPBenchmark { |
160 SkBitmapFPOrigShader( | 161 SkBitmapFPOrigShader( |
161 SkISize srcSize, | 162 SkISize srcSize, |
162 SkColorProfileType colorProfile, | 163 bool isSRGB, |
163 SkMatrix m, | 164 SkMatrix m, |
164 bool useBilerp, | 165 bool useBilerp, |
165 SkShader::TileMode xTile, | 166 SkShader::TileMode xTile, |
166 SkShader::TileMode yTile) | 167 SkShader::TileMode yTile) |
167 : CommonBitmapFPBenchmark(srcSize, colorProfile, m, useBilerp, xTile
, yTile) { } | 168 : CommonBitmapFPBenchmark(srcSize, isSRGB, m, useBilerp, xTile, yTil
e) { } |
168 | 169 |
169 SkString BaseName() override { | 170 SkString BaseName() override { |
170 SkString name{"Orig"}; | 171 SkString name{"Orig"}; |
171 return name; | 172 return name; |
172 } | 173 } |
173 | 174 |
174 void onPreDraw(SkCanvas* c) override { | 175 void onPreDraw(SkCanvas* c) override { |
175 CommonBitmapFPBenchmark::onPreDraw(c); | 176 CommonBitmapFPBenchmark::onPreDraw(c); |
176 | 177 |
177 fImage = SkImage::MakeRasterCopy( | 178 fImage = SkImage::MakeRasterCopy( |
(...skipping 27 matching lines...) Expand all Loading... |
205 for (int n = 0; n < 1000*loops; n++) { | 206 for (int n = 0; n < 1000*loops; n++) { |
206 ctx->shadeSpan(3, 6, buffer4b, count); | 207 ctx->shadeSpan(3, 6, buffer4b, count); |
207 } | 208 } |
208 | 209 |
209 ctx->~Context(); | 210 ctx->~Context(); |
210 } | 211 } |
211 SkPaint fPaint; | 212 SkPaint fPaint; |
212 sk_sp<SkImage> fImage; | 213 sk_sp<SkImage> fImage; |
213 }; | 214 }; |
214 | 215 |
| 216 const bool gSRGB = true; |
| 217 const bool gLinearRGB = false; |
215 static SkISize srcSize = SkISize::Make(120, 100); | 218 static SkISize srcSize = SkISize::Make(120, 100); |
216 static SkMatrix mI = SkMatrix::I(); | 219 static SkMatrix mI = SkMatrix::I(); |
217 DEF_BENCH(return new SkBitmapFPGeneral( | 220 DEF_BENCH(return new SkBitmapFPGeneral( |
218 srcSize, kSRGB_SkColorProfileType, mI, false, | 221 srcSize, gSRGB, mI, false, |
219 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) | 222 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) |
220 | 223 |
221 DEF_BENCH(return new SkBitmapFPGeneral( | 224 DEF_BENCH(return new SkBitmapFPGeneral( |
222 srcSize, kLinear_SkColorProfileType, mI, false, | 225 srcSize, gLinearRGB, mI, false, |
223 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) | 226 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) |
224 | 227 |
225 DEF_BENCH(return new SkBitmapFPOrigShader( | 228 DEF_BENCH(return new SkBitmapFPOrigShader( |
226 srcSize, kLinear_SkColorProfileType, mI, false, | 229 srcSize, gLinearRGB, mI, false, |
227 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) | 230 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) |
228 | 231 |
229 DEF_BENCH(return new SkBitmapFPGeneral( | 232 DEF_BENCH(return new SkBitmapFPGeneral( |
230 srcSize, kSRGB_SkColorProfileType, mI, true, | 233 srcSize, gSRGB, mI, true, |
231 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) | 234 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) |
232 | 235 |
233 DEF_BENCH(return new SkBitmapFPGeneral( | 236 DEF_BENCH(return new SkBitmapFPGeneral( |
234 srcSize, kLinear_SkColorProfileType, mI, true, | 237 srcSize, gLinearRGB, mI, true, |
235 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) | 238 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) |
236 | 239 |
237 DEF_BENCH(return new SkBitmapFPOrigShader( | 240 DEF_BENCH(return new SkBitmapFPOrigShader( |
238 srcSize, kLinear_SkColorProfileType, mI, true, | 241 srcSize, gLinearRGB, mI, true, |
239 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) | 242 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) |
240 | 243 |
241 static SkMatrix mS = SkMatrix::MakeScale(2.7f, 2.7f); | 244 static SkMatrix mS = SkMatrix::MakeScale(2.7f, 2.7f); |
242 DEF_BENCH(return new SkBitmapFPGeneral( | 245 DEF_BENCH(return new SkBitmapFPGeneral( |
243 srcSize, kSRGB_SkColorProfileType, mS, false, | 246 srcSize, gSRGB, mS, false, |
244 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) | 247 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) |
245 | 248 |
246 DEF_BENCH(return new SkBitmapFPGeneral( | 249 DEF_BENCH(return new SkBitmapFPGeneral( |
247 srcSize, kLinear_SkColorProfileType, mS, false, | 250 srcSize, gLinearRGB, mS, false, |
248 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) | 251 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) |
249 | 252 |
250 DEF_BENCH(return new SkBitmapFPOrigShader( | 253 DEF_BENCH(return new SkBitmapFPOrigShader( |
251 srcSize, kLinear_SkColorProfileType, mS, false, | 254 srcSize, gLinearRGB, mS, false, |
252 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) | 255 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) |
253 | 256 |
254 DEF_BENCH(return new SkBitmapFPGeneral( | 257 DEF_BENCH(return new SkBitmapFPGeneral( |
255 srcSize, kSRGB_SkColorProfileType, mS, true, | 258 srcSize, gSRGB, mS, true, |
256 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) | 259 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) |
257 | 260 |
258 DEF_BENCH(return new SkBitmapFPGeneral( | 261 DEF_BENCH(return new SkBitmapFPGeneral( |
259 srcSize, kLinear_SkColorProfileType, mS, true, | 262 srcSize, gLinearRGB, mS, true, |
260 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) | 263 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) |
261 | 264 |
262 DEF_BENCH(return new SkBitmapFPOrigShader( | 265 DEF_BENCH(return new SkBitmapFPOrigShader( |
263 srcSize, kLinear_SkColorProfileType, mS, true, | 266 srcSize, gLinearRGB, mS, true, |
264 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) | 267 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) |
265 | 268 |
266 // Repeat | 269 // Repeat |
267 DEF_BENCH(return new SkBitmapFPGeneral( | 270 DEF_BENCH(return new SkBitmapFPGeneral( |
268 srcSize, kSRGB_SkColorProfileType, mS, false, | 271 srcSize, gSRGB, mS, false, |
269 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);) | 272 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);) |
270 | 273 |
271 DEF_BENCH(return new SkBitmapFPGeneral( | 274 DEF_BENCH(return new SkBitmapFPGeneral( |
272 srcSize, kLinear_SkColorProfileType, mS, false, | 275 srcSize, gLinearRGB, mS, false, |
273 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);) | 276 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);) |
274 | 277 |
275 DEF_BENCH(return new SkBitmapFPOrigShader( | 278 DEF_BENCH(return new SkBitmapFPOrigShader( |
276 srcSize, kLinear_SkColorProfileType, mS, false, | 279 srcSize, gLinearRGB, mS, false, |
277 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);) | 280 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);) |
278 | 281 |
279 DEF_BENCH(return new SkBitmapFPGeneral( | 282 DEF_BENCH(return new SkBitmapFPGeneral( |
280 srcSize, kSRGB_SkColorProfileType, mS, true, | 283 srcSize, gSRGB, mS, true, |
281 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);) | 284 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);) |
282 | 285 |
283 DEF_BENCH(return new SkBitmapFPGeneral( | 286 DEF_BENCH(return new SkBitmapFPGeneral( |
284 srcSize, kLinear_SkColorProfileType, mS, true, | 287 srcSize, gLinearRGB, mS, true, |
285 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);) | 288 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);) |
286 | 289 |
287 DEF_BENCH(return new SkBitmapFPOrigShader( | 290 DEF_BENCH(return new SkBitmapFPOrigShader( |
288 srcSize, kLinear_SkColorProfileType, mS, true, | 291 srcSize, gLinearRGB, mS, true, |
289 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);) | 292 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);) |
290 | 293 |
291 static SkMatrix rotate(SkScalar r) { | 294 static SkMatrix rotate(SkScalar r) { |
292 SkMatrix m; | 295 SkMatrix m; |
293 m.setRotate(30); | 296 m.setRotate(30); |
294 return m; | 297 return m; |
295 } | 298 } |
296 | 299 |
297 static SkMatrix mR = rotate(30); | 300 static SkMatrix mR = rotate(30); |
298 DEF_BENCH(return new SkBitmapFPGeneral( | 301 DEF_BENCH(return new SkBitmapFPGeneral( |
299 srcSize, kSRGB_SkColorProfileType, mR, false, | 302 srcSize, gSRGB, mR, false, |
300 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) | 303 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) |
301 | 304 |
302 DEF_BENCH(return new SkBitmapFPGeneral( | 305 DEF_BENCH(return new SkBitmapFPGeneral( |
303 srcSize, kLinear_SkColorProfileType, mR, false, | 306 srcSize, gLinearRGB, mR, false, |
304 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) | 307 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) |
305 | 308 |
306 DEF_BENCH(return new SkBitmapFPOrigShader( | 309 DEF_BENCH(return new SkBitmapFPOrigShader( |
307 srcSize, kLinear_SkColorProfileType, mR, false, | 310 srcSize, gLinearRGB, mR, false, |
308 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) | 311 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) |
309 | 312 |
310 DEF_BENCH(return new SkBitmapFPGeneral( | 313 DEF_BENCH(return new SkBitmapFPGeneral( |
311 srcSize, kSRGB_SkColorProfileType, mR, true, | 314 srcSize, gSRGB, mR, true, |
312 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) | 315 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) |
313 | 316 |
314 DEF_BENCH(return new SkBitmapFPGeneral( | 317 DEF_BENCH(return new SkBitmapFPGeneral( |
315 srcSize, kLinear_SkColorProfileType, mR, true, | 318 srcSize, gLinearRGB, mR, true, |
316 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) | 319 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) |
317 | 320 |
318 DEF_BENCH(return new SkBitmapFPOrigShader( | 321 DEF_BENCH(return new SkBitmapFPOrigShader( |
319 srcSize, kLinear_SkColorProfileType, mR, true, | 322 srcSize, gLinearRGB, mR, true, |
320 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) | 323 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);) |
321 | 324 |
322 // Repeat | 325 // Repeat |
323 DEF_BENCH(return new SkBitmapFPGeneral( | 326 DEF_BENCH(return new SkBitmapFPGeneral( |
324 srcSize, kSRGB_SkColorProfileType, mR, false, | 327 srcSize, gSRGB, mR, false, |
325 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);) | 328 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);) |
326 | 329 |
327 DEF_BENCH(return new SkBitmapFPGeneral( | 330 DEF_BENCH(return new SkBitmapFPGeneral( |
328 srcSize, kLinear_SkColorProfileType, mR, false, | 331 srcSize, gLinearRGB, mR, false, |
329 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);) | 332 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);) |
330 | 333 |
331 DEF_BENCH(return new SkBitmapFPOrigShader( | 334 DEF_BENCH(return new SkBitmapFPOrigShader( |
332 srcSize, kLinear_SkColorProfileType, mR, false, | 335 srcSize, gLinearRGB, mR, false, |
333 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);) | 336 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);) |
334 | 337 |
335 DEF_BENCH(return new SkBitmapFPGeneral( | 338 DEF_BENCH(return new SkBitmapFPGeneral( |
336 srcSize, kSRGB_SkColorProfileType, mR, true, | 339 srcSize, gSRGB, mR, true, |
337 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);) | 340 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);) |
338 | 341 |
339 DEF_BENCH(return new SkBitmapFPGeneral( | 342 DEF_BENCH(return new SkBitmapFPGeneral( |
340 srcSize, kLinear_SkColorProfileType, mR, true, | 343 srcSize, gLinearRGB, mR, true, |
341 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);) | 344 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);) |
342 | 345 |
343 DEF_BENCH(return new SkBitmapFPOrigShader( | 346 DEF_BENCH(return new SkBitmapFPOrigShader( |
344 srcSize, kLinear_SkColorProfileType, mR, true, | 347 srcSize, gLinearRGB, mR, true, |
345 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);) | 348 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode);) |
OLD | NEW |