OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #if SK_SUPPORT_GPU | 9 #if SK_SUPPORT_GPU |
10 #include "GrContext.h" | 10 #include "GrContext.h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 static void performScale(SkCanvas* canvas, int w, int h) { | 151 static void performScale(SkCanvas* canvas, int w, int h) { |
152 const SkScalar x = SkIntToScalar(w) / 2; | 152 const SkScalar x = SkIntToScalar(w) / 2; |
153 const SkScalar y = SkIntToScalar(h) / 2; | 153 const SkScalar y = SkIntToScalar(h) / 2; |
154 | 154 |
155 canvas->translate(x, y); | 155 canvas->translate(x, y); |
156 // just enough so we can't take the sprite case | 156 // just enough so we can't take the sprite case |
157 canvas->scale(SK_Scalar1 * 99/100, SK_Scalar1 * 99/100); | 157 canvas->scale(SK_Scalar1 * 99/100, SK_Scalar1 * 99/100); |
158 canvas->translate(-x, -y); | 158 canvas->translate(-x, -y); |
159 } | 159 } |
160 | 160 |
161 enum Backend { | |
162 kNonRendering_Backend, | |
163 kRaster_Backend, | |
164 kGPU_Backend, | |
165 kPDF_Backend, | |
166 }; | |
167 | |
168 static SkBaseDevice* make_device(SkBitmap::Config config, const SkIPoint& size, | 161 static SkBaseDevice* make_device(SkBitmap::Config config, const SkIPoint& size, |
169 Backend backend, int sampleCount, GrContext* co
ntext) { | 162 SkBenchmark::Backend backend, int sampleCount,
GrContext* context) { |
170 SkBaseDevice* device = NULL; | 163 SkBaseDevice* device = NULL; |
171 SkBitmap bitmap; | 164 SkBitmap bitmap; |
172 bitmap.setConfig(config, size.fX, size.fY); | 165 bitmap.setConfig(config, size.fX, size.fY); |
173 | 166 |
174 switch (backend) { | 167 switch (backend) { |
175 case kRaster_Backend: | 168 case SkBenchmark::kRaster_Backend: |
176 bitmap.allocPixels(); | 169 bitmap.allocPixels(); |
177 erase(bitmap); | 170 erase(bitmap); |
178 device = SkNEW_ARGS(SkBitmapDevice, (bitmap)); | 171 device = SkNEW_ARGS(SkBitmapDevice, (bitmap)); |
179 break; | 172 break; |
180 #if SK_SUPPORT_GPU | 173 #if SK_SUPPORT_GPU |
181 case kGPU_Backend: { | 174 case SkBenchmark::kGPU_Backend: { |
182 GrTextureDesc desc; | 175 GrTextureDesc desc; |
183 desc.fConfig = kSkia8888_GrPixelConfig; | 176 desc.fConfig = kSkia8888_GrPixelConfig; |
184 desc.fFlags = kRenderTarget_GrTextureFlagBit; | 177 desc.fFlags = kRenderTarget_GrTextureFlagBit; |
185 desc.fWidth = size.fX; | 178 desc.fWidth = size.fX; |
186 desc.fHeight = size.fY; | 179 desc.fHeight = size.fY; |
187 desc.fSampleCnt = sampleCount; | 180 desc.fSampleCnt = sampleCount; |
188 SkAutoTUnref<GrTexture> texture(context->createUncachedTexture(desc,
NULL, 0)); | 181 SkAutoTUnref<GrTexture> texture(context->createUncachedTexture(desc,
NULL, 0)); |
189 if (!texture) { | 182 if (!texture) { |
190 return NULL; | 183 return NULL; |
191 } | 184 } |
192 device = SkNEW_ARGS(SkGpuDevice, (context, texture.get())); | 185 device = SkNEW_ARGS(SkGpuDevice, (context, texture.get())); |
193 break; | 186 break; |
194 } | 187 } |
195 #endif | 188 #endif |
196 case kPDF_Backend: | 189 case SkBenchmark::kPDF_Backend: |
197 default: | 190 default: |
198 SkDEBUGFAIL("unsupported"); | 191 SkDEBUGFAIL("unsupported"); |
199 } | 192 } |
200 return device; | 193 return device; |
201 } | 194 } |
202 | 195 |
203 #if SK_SUPPORT_GPU | 196 #if SK_SUPPORT_GPU |
204 GrContextFactory gContextFactory; | 197 GrContextFactory gContextFactory; |
205 typedef GrContextFactory::GLContextType GLContextType; | 198 typedef GrContextFactory::GLContextType GLContextType; |
206 static const GLContextType kNative = GrContextFactory::kNative_GLContextType; | 199 static const GLContextType kNative = GrContextFactory::kNative_GLContextType; |
(...skipping 10 matching lines...) Expand all Loading... |
217 #ifdef SK_DEBUG | 210 #ifdef SK_DEBUG |
218 static const bool kIsDebug = true; | 211 static const bool kIsDebug = true; |
219 #else | 212 #else |
220 static const bool kIsDebug = false; | 213 static const bool kIsDebug = false; |
221 #endif | 214 #endif |
222 | 215 |
223 static const struct Config { | 216 static const struct Config { |
224 SkBitmap::Config config; | 217 SkBitmap::Config config; |
225 const char* name; | 218 const char* name; |
226 int sampleCount; | 219 int sampleCount; |
227 Backend backend; | 220 SkBenchmark::Backend backend; |
228 GLContextType contextType; | 221 GLContextType contextType; |
229 bool runByDefault; | 222 bool runByDefault; |
230 } gConfigs[] = { | 223 } gConfigs[] = { |
231 { SkBitmap::kNo_Config, "NONRENDERING", 0, kNonRendering_Backend, kNa
tive, true}, | 224 { SkBitmap::kNo_Config, "NONRENDERING", 0, SkBenchmark::kNonRendering
_Backend, kNative, true}, |
232 { SkBitmap::kARGB_8888_Config, "8888", 0, kRaster_Backend, kNa
tive, true}, | 225 { SkBitmap::kARGB_8888_Config, "8888", 0, SkBenchmark::kRaster_Backe
nd, kNative, true}, |
233 { SkBitmap::kRGB_565_Config, "565", 0, kRaster_Backend, kNa
tive, true}, | 226 { SkBitmap::kRGB_565_Config, "565", 0, SkBenchmark::kRaster_Backe
nd, kNative, true}, |
234 #if SK_SUPPORT_GPU | 227 #if SK_SUPPORT_GPU |
235 { SkBitmap::kARGB_8888_Config, "GPU", 0, kGPU_Backend, kNa
tive, true}, | 228 { SkBitmap::kARGB_8888_Config, "GPU", 0, SkBenchmark::kGPU_Backend,
kNative, true}, |
236 { SkBitmap::kARGB_8888_Config, "MSAA4", 4, kGPU_Backend, kNa
tive, false}, | 229 { SkBitmap::kARGB_8888_Config, "MSAA4", 4, SkBenchmark::kGPU_Backend,
kNative, false}, |
237 { SkBitmap::kARGB_8888_Config, "MSAA16", 16, kGPU_Backend, kNa
tive, false}, | 230 { SkBitmap::kARGB_8888_Config, "MSAA16", 16, SkBenchmark::kGPU_Backend,
kNative, false}, |
238 #if SK_ANGLE | 231 #if SK_ANGLE |
239 { SkBitmap::kARGB_8888_Config, "ANGLE", 0, kGPU_Backend, kAN
GLE, true}, | 232 { SkBitmap::kARGB_8888_Config, "ANGLE", 0, SkBenchmark::kGPU_Backend,
kANGLE, true}, |
240 #endif // SK_ANGLE | 233 #endif // SK_ANGLE |
241 { SkBitmap::kARGB_8888_Config, "Debug", 0, kGPU_Backend, kDe
bug, kIsDebug}, | 234 { SkBitmap::kARGB_8888_Config, "Debug", 0, SkBenchmark::kGPU_Backend,
kDebug, kIsDebug}, |
242 { SkBitmap::kARGB_8888_Config, "NULLGPU", 0, kGPU_Backend, kNu
ll, true}, | 235 { SkBitmap::kARGB_8888_Config, "NULLGPU", 0, SkBenchmark::kGPU_Backend,
kNull, true}, |
243 #endif // SK_SUPPORT_GPU | 236 #endif // SK_SUPPORT_GPU |
244 }; | 237 }; |
245 | 238 |
246 DEFINE_string(outDir, "", "If given, image of each bench will be put in outDir."
); | 239 DEFINE_string(outDir, "", "If given, image of each bench will be put in outDir."
); |
247 DEFINE_string(timers, "cg", "Timers to display. " | 240 DEFINE_string(timers, "cg", "Timers to display. " |
248 "Options: w(all) W(all, truncated) c(pu) C(pu, truncated) g(pu)"); | 241 "Options: w(all) W(all, truncated) c(pu) C(pu, truncated) g(pu)"); |
249 | 242 |
250 DEFINE_bool(rotate, false, "Rotate canvas before bench run?"); | 243 DEFINE_bool(rotate, false, "Rotate canvas before bench run?"); |
251 DEFINE_bool(scale, false, "Scale canvas before bench run?"); | 244 DEFINE_bool(scale, false, "Scale canvas before bench run?"); |
252 DEFINE_bool(clip, false, "Clip canvas before bench run?"); | 245 DEFINE_bool(clip, false, "Clip canvas before bench run?"); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 if (gConfigs[i].runByDefault) { | 336 if (gConfigs[i].runByDefault) { |
344 *configs.append() = i; | 337 *configs.append() = i; |
345 } | 338 } |
346 } | 339 } |
347 } | 340 } |
348 // Filter out things we can't run. | 341 // Filter out things we can't run. |
349 if (kNormal_BenchMode != benchMode) { | 342 if (kNormal_BenchMode != benchMode) { |
350 // Non-rendering configs only run in normal mode | 343 // Non-rendering configs only run in normal mode |
351 for (int i = 0; i < configs.count(); ++i) { | 344 for (int i = 0; i < configs.count(); ++i) { |
352 const Config& config = gConfigs[configs[i]]; | 345 const Config& config = gConfigs[configs[i]]; |
353 if (kNonRendering_Backend == config.backend) { | 346 if (SkBenchmark::kNonRendering_Backend == config.backend) { |
354 configs.remove(i, 1); | 347 configs.remove(i, 1); |
355 --i; | 348 --i; |
356 } | 349 } |
357 } | 350 } |
358 } | 351 } |
359 // Set the resource path. | 352 // Set the resource path. |
360 if (!FLAGS_resourcePath.isEmpty()) { | 353 if (!FLAGS_resourcePath.isEmpty()) { |
361 SkBenchmark::SetResourcePath(FLAGS_resourcePath[0]); | 354 SkBenchmark::SetResourcePath(FLAGS_resourcePath[0]); |
362 } | 355 } |
363 | 356 |
364 #if SK_SUPPORT_GPU | 357 #if SK_SUPPORT_GPU |
365 for (int i = 0; i < configs.count(); ++i) { | 358 for (int i = 0; i < configs.count(); ++i) { |
366 const Config& config = gConfigs[configs[i]]; | 359 const Config& config = gConfigs[configs[i]]; |
367 | 360 |
368 if (kGPU_Backend == config.backend) { | 361 if (SkBenchmark::kGPU_Backend == config.backend) { |
369 GrContext* context = gContextFactory.get(config.contextType); | 362 GrContext* context = gContextFactory.get(config.contextType); |
370 if (NULL == context) { | 363 if (NULL == context) { |
371 logger.logError(SkStringPrintf( | 364 logger.logError(SkStringPrintf( |
372 "Error creating GrContext for config %s. Config will be skip
ped.\n", | 365 "Error creating GrContext for config %s. Config will be skip
ped.\n", |
373 config.name)); | 366 config.name)); |
374 configs.remove(i); | 367 configs.remove(i); |
375 --i; | 368 --i; |
376 continue; | 369 continue; |
377 } | 370 } |
378 if (config.sampleCount > context->getMaxSampleCount()){ | 371 if (config.sampleCount > context->getMaxSampleCount()){ |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 str.append(" DEBUG"); | 413 str.append(" DEBUG"); |
421 #endif | 414 #endif |
422 str.append("\n"); | 415 str.append("\n"); |
423 logger.logProgress(str); | 416 logger.logProgress(str); |
424 | 417 |
425 | 418 |
426 // Set texture cache limits if non-default. | 419 // Set texture cache limits if non-default. |
427 for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); ++i) { | 420 for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); ++i) { |
428 #if SK_SUPPORT_GPU | 421 #if SK_SUPPORT_GPU |
429 const Config& config = gConfigs[i]; | 422 const Config& config = gConfigs[i]; |
430 if (kGPU_Backend != config.backend) { | 423 if (SkBenchmark::kGPU_Backend != config.backend) { |
431 continue; | 424 continue; |
432 } | 425 } |
433 GrContext* context = gContextFactory.get(config.contextType); | 426 GrContext* context = gContextFactory.get(config.contextType); |
434 if (NULL == context) { | 427 if (NULL == context) { |
435 continue; | 428 continue; |
436 } | 429 } |
437 | 430 |
438 size_t bytes; | 431 size_t bytes; |
439 int count; | 432 int count; |
440 context->getTextureCacheLimits(&count, &bytes); | 433 context->getTextureCacheLimits(&count, &bytes); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 bench->setForceAA(FLAGS_forceAA); | 466 bench->setForceAA(FLAGS_forceAA); |
474 bench->setForceFilter(FLAGS_forceFilter); | 467 bench->setForceFilter(FLAGS_forceFilter); |
475 bench->setDither(dither); | 468 bench->setDither(dither); |
476 AutoPrePostDraw appd(bench); | 469 AutoPrePostDraw appd(bench); |
477 | 470 |
478 bool loggedBenchName = false; | 471 bool loggedBenchName = false; |
479 for (int i = 0; i < configs.count(); ++i) { | 472 for (int i = 0; i < configs.count(); ++i) { |
480 const int configIndex = configs[i]; | 473 const int configIndex = configs[i]; |
481 const Config& config = gConfigs[configIndex]; | 474 const Config& config = gConfigs[configIndex]; |
482 | 475 |
483 if ((kNonRendering_Backend == config.backend) == bench->isRendering(
)) { | 476 if (!bench->isSuitableFor(config.backend)) { |
484 continue; | 477 continue; |
485 } | 478 } |
486 | 479 |
487 GrContext* context = NULL; | 480 GrContext* context = NULL; |
488 #if SK_SUPPORT_GPU | 481 #if SK_SUPPORT_GPU |
489 SkGLContextHelper* glContext = NULL; | 482 SkGLContextHelper* glContext = NULL; |
490 if (kGPU_Backend == config.backend) { | 483 if (SkBenchmark::kGPU_Backend == config.backend) { |
491 context = gContextFactory.get(config.contextType); | 484 context = gContextFactory.get(config.contextType); |
492 if (NULL == context) { | 485 if (NULL == context) { |
493 continue; | 486 continue; |
494 } | 487 } |
495 glContext = gContextFactory.getGLContext(config.contextType); | 488 glContext = gContextFactory.getGLContext(config.contextType); |
496 } | 489 } |
497 #endif | 490 #endif |
498 SkAutoTUnref<SkBaseDevice> device; | 491 SkAutoTUnref<SkBaseDevice> device; |
499 SkAutoTUnref<SkCanvas> canvas; | 492 SkAutoTUnref<SkCanvas> canvas; |
500 SkPicture recordFrom, recordTo; | 493 SkPicture recordFrom, recordTo; |
501 const SkIPoint dim = bench->getSize(); | 494 const SkIPoint dim = bench->getSize(); |
502 | 495 |
503 const SkPicture::RecordingFlags kRecordFlags = | 496 const SkPicture::RecordingFlags kRecordFlags = |
504 SkPicture::kUsePathBoundsForClip_RecordingFlag; | 497 SkPicture::kUsePathBoundsForClip_RecordingFlag; |
505 | 498 |
506 if (kNonRendering_Backend != config.backend) { | 499 if (SkBenchmark::kNonRendering_Backend != config.backend) { |
507 device.reset(make_device(config.config, | 500 device.reset(make_device(config.config, |
508 dim, | 501 dim, |
509 config.backend, | 502 config.backend, |
510 config.sampleCount, | 503 config.sampleCount, |
511 context)); | 504 context)); |
512 if (!device.get()) { | 505 if (!device.get()) { |
513 logger.logError(SkStringPrintf( | 506 logger.logError(SkStringPrintf( |
514 "Device creation failure for config %s. Will skip.\n", c
onfig.name)); | 507 "Device creation failure for config %s. Will skip.\n", c
onfig.name)); |
515 continue; | 508 continue; |
516 } | 509 } |
(...skipping 29 matching lines...) Expand all Loading... |
546 if (!loggedBenchName) { | 539 if (!loggedBenchName) { |
547 loggedBenchName = true; | 540 loggedBenchName = true; |
548 SkString str; | 541 SkString str; |
549 str.printf("running bench [%3d %3d] %*s ", | 542 str.printf("running bench [%3d %3d] %*s ", |
550 dim.fX, dim.fY, longestName, bench->getName()); | 543 dim.fX, dim.fY, longestName, bench->getName()); |
551 logger.logProgress(str); | 544 logger.logProgress(str); |
552 } | 545 } |
553 | 546 |
554 #if SK_SUPPORT_GPU | 547 #if SK_SUPPORT_GPU |
555 SkGLContextHelper* contextHelper = NULL; | 548 SkGLContextHelper* contextHelper = NULL; |
556 if (kGPU_Backend == config.backend) { | 549 if (SkBenchmark::kGPU_Backend == config.backend) { |
557 contextHelper = gContextFactory.getGLContext(config.contextType)
; | 550 contextHelper = gContextFactory.getGLContext(config.contextType)
; |
558 } | 551 } |
559 BenchTimer timer(contextHelper); | 552 BenchTimer timer(contextHelper); |
560 #else | 553 #else |
561 BenchTimer timer; | 554 BenchTimer timer; |
562 #endif | 555 #endif |
563 | 556 |
564 double previous = std::numeric_limits<double>::infinity(); | 557 double previous = std::numeric_limits<double>::infinity(); |
565 bool converged = false; | 558 bool converged = false; |
566 | 559 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 } | 651 } |
659 | 652 |
660 const double current = timer.fWall / loopsPerIter; | 653 const double current = timer.fWall / loopsPerIter; |
661 if (FLAGS_verbose && current > previous) { SkDebugf("↑"); } | 654 if (FLAGS_verbose && current > previous) { SkDebugf("↑"); } |
662 if (FLAGS_verbose) { SkDebugf("%.3g ", current); } | 655 if (FLAGS_verbose) { SkDebugf("%.3g ", current); } |
663 converged = HasConverged(previous, current, timer.fWall); | 656 converged = HasConverged(previous, current, timer.fWall); |
664 previous = current; | 657 previous = current; |
665 } while (!kIsDebug && !converged); | 658 } while (!kIsDebug && !converged); |
666 if (FLAGS_verbose) { SkDebugf("\n"); } | 659 if (FLAGS_verbose) { SkDebugf("\n"); } |
667 | 660 |
668 if (FLAGS_outDir.count() && kNonRendering_Backend != config.backend)
{ | 661 if (FLAGS_outDir.count() && SkBenchmark::kNonRendering_Backend != co
nfig.backend) { |
669 saveFile(bench->getName(), | 662 saveFile(bench->getName(), |
670 config.name, | 663 config.name, |
671 FLAGS_outDir[0], | 664 FLAGS_outDir[0], |
672 device->accessBitmap(false)); | 665 device->accessBitmap(false)); |
673 } | 666 } |
674 | 667 |
675 if (kIsDebug) { | 668 if (kIsDebug) { |
676 // Let's not mislead ourselves by looking at Debug build bench t
imes! | 669 // Let's not mislead ourselves by looking at Debug build bench t
imes! |
677 continue; | 670 continue; |
678 } | 671 } |
(...skipping 26 matching lines...) Expand all Loading... |
705 gContextFactory.destroyContexts(); | 698 gContextFactory.destroyContexts(); |
706 #endif | 699 #endif |
707 return 0; | 700 return 0; |
708 } | 701 } |
709 | 702 |
710 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 703 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
711 int main(int argc, char * const argv[]) { | 704 int main(int argc, char * const argv[]) { |
712 return tool_main(argc, (char**) argv); | 705 return tool_main(argc, (char**) argv); |
713 } | 706 } |
714 #endif | 707 #endif |
OLD | NEW |