| 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 | 9 |
| 10 #include "BenchTimer.h" | 10 #include "BenchTimer.h" |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 | 341 |
| 342 int tool_main(int argc, char** argv); | 342 int tool_main(int argc, char** argv); |
| 343 int tool_main(int argc, char** argv) { | 343 int tool_main(int argc, char** argv) { |
| 344 #if SK_ENABLE_INST_COUNT | 344 #if SK_ENABLE_INST_COUNT |
| 345 gPrintInstCount = true; | 345 gPrintInstCount = true; |
| 346 #endif | 346 #endif |
| 347 SkAutoGraphics ag; | 347 SkAutoGraphics ag; |
| 348 | 348 |
| 349 SkTDict<const char*> defineDict(1024); | 349 SkTDict<const char*> defineDict(1024); |
| 350 int repeatDraw = 1; | 350 int repeatDraw = 1; |
| 351 bool logPerIter = false; | 351 |
| 352 int forceAlpha = 0xFF; | 352 int forceAlpha = 0xFF; |
| 353 bool forceAA = true; | 353 bool forceAA = true; |
| 354 bool forceFilter = false; | 354 bool forceFilter = false; |
| 355 SkTriState::State forceDither = SkTriState::kDefault; | 355 SkTriState::State forceDither = SkTriState::kDefault; |
| 356 bool timerWall = false; | 356 |
| 357 bool truncatedTimerWall = false; | 357 static const uint32_t kDefaultTimerTypes = TimerData::kCpu_Flag | TimerData:
:kGpu_Flag; |
| 358 bool timerCpu = true; | 358 static const TimerData::Result kDefaultTimerResult = TimerData::kAvg_Result; |
| 359 bool truncatedTimerCpu = false; | 359 uint32_t timerTypes = kDefaultTimerTypes; |
| 360 bool timerGpu = true; | 360 TimerData::Result timerResult = kDefaultTimerResult; |
| 361 |
| 361 bool doScale = false; | 362 bool doScale = false; |
| 362 bool doRotate = false; | 363 bool doRotate = false; |
| 363 bool doClip = false; | 364 bool doClip = false; |
| 364 bool printMin = false; | |
| 365 bool hasStrokeWidth = false; | 365 bool hasStrokeWidth = false; |
| 366 | 366 |
| 367 #if SK_SUPPORT_GPU | 367 #if SK_SUPPORT_GPU |
| 368 struct { | 368 struct { |
| 369 int fBytes; | 369 int fBytes; |
| 370 int fCount; | 370 int fCount; |
| 371 } gpuCacheSize = { -1, -1 }; // -1s mean use the default | 371 } gpuCacheSize = { -1, -1 }; // -1s mean use the default |
| 372 #endif | 372 #endif |
| 373 | 373 |
| 374 float strokeWidth; | 374 float strokeWidth; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 403 repeatDraw = atoi(*argv); | 403 repeatDraw = atoi(*argv); |
| 404 if (repeatDraw < 1) { | 404 if (repeatDraw < 1) { |
| 405 repeatDraw = 1; | 405 repeatDraw = 1; |
| 406 } | 406 } |
| 407 } else { | 407 } else { |
| 408 logger.logError("missing arg for --repeat\n"); | 408 logger.logError("missing arg for --repeat\n"); |
| 409 help(); | 409 help(); |
| 410 return -1; | 410 return -1; |
| 411 } | 411 } |
| 412 } else if (strcmp(*argv, "--logPerIter") == 0) { | 412 } else if (strcmp(*argv, "--logPerIter") == 0) { |
| 413 logPerIter = true; | 413 timerResult = TimerData::kPerIter_Result; |
| 414 } else if (strcmp(*argv, "--timers") == 0) { | 414 } else if (strcmp(*argv, "--timers") == 0) { |
| 415 argv++; | 415 argv++; |
| 416 if (argv < stop) { | 416 if (argv < stop) { |
| 417 timerWall = false; | 417 timerTypes = 0; |
| 418 truncatedTimerWall = false; | |
| 419 timerCpu = false; | |
| 420 truncatedTimerCpu = false; | |
| 421 timerGpu = false; | |
| 422 for (char* t = *argv; *t; ++t) { | 418 for (char* t = *argv; *t; ++t) { |
| 423 switch (*t) { | 419 switch (*t) { |
| 424 case 'w': timerWall = true; break; | 420 case 'w': timerTypes |= TimerData::kWall_Flag; break; |
| 425 case 'c': timerCpu = true; break; | 421 case 'c': timerTypes |= TimerData::kCpu_Flag; break; |
| 426 case 'W': truncatedTimerWall = true; break; | 422 case 'W': timerTypes |= TimerData::kTruncatedWall_Flag; brea
k; |
| 427 case 'C': truncatedTimerCpu = true; break; | 423 case 'C': timerTypes |= TimerData::kTruncatedCpu_Flag; break
; |
| 428 case 'g': timerGpu = true; break; | 424 case 'g': timerTypes |= TimerData::kGpu_Flag; break; |
| 429 } | 425 } |
| 430 } | 426 } |
| 431 } else { | 427 } else { |
| 432 logger.logError("missing arg for --timers\n"); | 428 logger.logError("missing arg for --timers\n"); |
| 433 help(); | 429 help(); |
| 434 return -1; | 430 return -1; |
| 435 } | 431 } |
| 436 } else if (!strcmp(*argv, "--rotate")) { | 432 } else if (!strcmp(*argv, "--rotate")) { |
| 437 doRotate = true; | 433 doRotate = true; |
| 438 } else if (!strcmp(*argv, "--scale")) { | 434 } else if (!strcmp(*argv, "--scale")) { |
| 439 doScale = true; | 435 doScale = true; |
| 440 } else if (!strcmp(*argv, "--clip")) { | 436 } else if (!strcmp(*argv, "--clip")) { |
| 441 doClip = true; | 437 doClip = true; |
| 442 } else if (!strcmp(*argv, "--min")) { | 438 } else if (!strcmp(*argv, "--min")) { |
| 443 printMin = true; | 439 timerResult = TimerData::kMin_Result; |
| 444 } else if (strcmp(*argv, "--forceAA") == 0) { | 440 } else if (strcmp(*argv, "--forceAA") == 0) { |
| 445 if (!parse_bool_arg(++argv, stop, &forceAA)) { | 441 if (!parse_bool_arg(++argv, stop, &forceAA)) { |
| 446 logger.logError("missing arg for --forceAA\n"); | 442 logger.logError("missing arg for --forceAA\n"); |
| 447 help(); | 443 help(); |
| 448 return -1; | 444 return -1; |
| 449 } | 445 } |
| 450 } else if (strcmp(*argv, "--forceFilter") == 0) { | 446 } else if (strcmp(*argv, "--forceFilter") == 0) { |
| 451 if (!parse_bool_arg(++argv, stop, &forceFilter)) { | 447 if (!parse_bool_arg(++argv, stop, &forceFilter)) { |
| 452 logger.logError("missing arg for --forceFilter\n"); | 448 logger.logError("missing arg for --forceFilter\n"); |
| 453 help(); | 449 help(); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 #endif | 637 #endif |
| 642 | 638 |
| 643 // report our current settings | 639 // report our current settings |
| 644 { | 640 { |
| 645 SkString str; | 641 SkString str; |
| 646 const char* deferredMode = benchMode == kDeferred_benchModes ? "yes" : | 642 const char* deferredMode = benchMode == kDeferred_benchModes ? "yes" : |
| 647 (benchMode == kDeferredSilent_benchModes ? "silent" : "no"); | 643 (benchMode == kDeferredSilent_benchModes ? "silent" : "no"); |
| 648 str.printf("skia bench: alpha=0x%02X antialias=%d filter=%d " | 644 str.printf("skia bench: alpha=0x%02X antialias=%d filter=%d " |
| 649 "deferred=%s logperiter=%d", | 645 "deferred=%s logperiter=%d", |
| 650 forceAlpha, forceAA, forceFilter, deferredMode, | 646 forceAlpha, forceAA, forceFilter, deferredMode, |
| 651 logPerIter); | 647 TimerData::kPerIter_Result == timerResult); |
| 652 str.appendf(" rotate=%d scale=%d clip=%d min=%d", | 648 str.appendf(" rotate=%d scale=%d clip=%d min=%d", |
| 653 doRotate, doScale, doClip, printMin); | 649 doRotate, doScale, doClip, TimerData::kMin_Result == timerRes
ult); |
| 654 str.appendf(" record=%d picturerecord=%d", | 650 str.appendf(" record=%d picturerecord=%d", |
| 655 benchMode == kRecord_benchModes, | 651 benchMode == kRecord_benchModes, |
| 656 benchMode == kPictureRecord_benchModes); | 652 benchMode == kPictureRecord_benchModes); |
| 657 const char * ditherName; | 653 const char * ditherName; |
| 658 switch (forceDither) { | 654 switch (forceDither) { |
| 659 case SkTriState::kDefault: ditherName = "default"; break; | 655 case SkTriState::kDefault: ditherName = "default"; break; |
| 660 case SkTriState::kTrue: ditherName = "true"; break; | 656 case SkTriState::kTrue: ditherName = "true"; break; |
| 661 case SkTriState::kFalse: ditherName = "false"; break; | 657 case SkTriState::kFalse: ditherName = "false"; break; |
| 662 default: ditherName = "<invalid>"; break; | 658 default: ditherName = "<invalid>"; break; |
| 663 } | 659 } |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 } | 872 } |
| 877 #if SK_SUPPORT_GPU | 873 #if SK_SUPPORT_GPU |
| 878 if (NULL != context) { | 874 if (NULL != context) { |
| 879 context->flush(); | 875 context->flush(); |
| 880 SK_GL(*glContext, Finish()); | 876 SK_GL(*glContext, Finish()); |
| 881 } | 877 } |
| 882 #endif | 878 #endif |
| 883 } | 879 } |
| 884 | 880 |
| 885 // record timer values for each repeat, and their sum | 881 // record timer values for each repeat, and their sum |
| 886 TimerData timerData(perIterTimeformat, normalTimeFormat); | 882 TimerData timerData(repeatDraw); |
| 887 for (int i = 0; i < repeatDraw; i++) { | 883 for (int i = 0; i < repeatDraw; i++) { |
| 888 if ((benchMode == kRecord_benchModes || benchMode == kPictur
eRecord_benchModes)) { | 884 if ((benchMode == kRecord_benchModes || benchMode == kPictur
eRecord_benchModes)) { |
| 889 // This will clear the recorded commands so that they do
not | 885 // This will clear the recorded commands so that they do
not |
| 890 // accumulate. | 886 // accumulate. |
| 891 canvas = pictureRecordTo.beginRecording(dim.fX, dim.fY, | 887 canvas = pictureRecordTo.beginRecording(dim.fX, dim.fY, |
| 892 SkPicture::kUsePathBoundsForClip_RecordingFlag); | 888 SkPicture::kUsePathBoundsForClip_RecordingFlag); |
| 893 } | 889 } |
| 894 | 890 |
| 895 timer->start(bench->getDurationScale()); | 891 timer->start(bench->getDurationScale()); |
| 896 if (NULL != canvas) { | 892 if (NULL != canvas) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 918 #if SK_SUPPORT_GPU | 914 #if SK_SUPPORT_GPU |
| 919 if (NULL != glContext) { | 915 if (NULL != glContext) { |
| 920 context->flush(); | 916 context->flush(); |
| 921 SK_GL(*glContext, Finish()); | 917 SK_GL(*glContext, Finish()); |
| 922 } | 918 } |
| 923 #endif | 919 #endif |
| 924 // stop the inclusive and gpu timers once all the GL calls | 920 // stop the inclusive and gpu timers once all the GL calls |
| 925 // have completed | 921 // have completed |
| 926 timer->end(); | 922 timer->end(); |
| 927 | 923 |
| 928 timerData.appendTimes(timer, repeatDraw - 1 == i); | 924 SkAssertResult(timerData.appendTimes(timer)); |
| 929 | 925 |
| 930 } | 926 } |
| 931 if (repeatDraw > 1) { | 927 if (repeatDraw > 1) { |
| 932 SkString result = timerData.getResult( | 928 const char* timeFormat; |
| 933 logPerIter, printMin, repeatDraw, config
Name, | 929 if (TimerData::kPerIter_Result == timerResult) { |
| 934 timerWall, truncatedTimerWall, timerCpu, | 930 timeFormat = perIterTimeformat.c_str(); |
| 935 truncatedTimerCpu, | 931 } else { |
| 936 timerGpu && NULL != context); | 932 timeFormat = normalTimeFormat.c_str(); |
| 933 } |
| 934 uint32_t filteredTimerTypes = timerTypes; |
| 935 if (NULL == context) { |
| 936 filteredTimerTypes &= ~TimerData::kGpu_Flag; |
| 937 } |
| 938 SkString result = timerData.getResult(timeFormat, |
| 939 timerResult, |
| 940 configName, |
| 941 filteredTimerTypes); |
| 937 logger.logProgress(result); | 942 logger.logProgress(result); |
| 938 } | 943 } |
| 939 if (outDir.size() > 0 && kNonRendering_Backend != backend) { | 944 if (outDir.size() > 0 && kNonRendering_Backend != backend) { |
| 940 saveFile(bench->getName(), configName, outDir.c_str(), | 945 saveFile(bench->getName(), configName, outDir.c_str(), |
| 941 device->accessBitmap(false)); | 946 device->accessBitmap(false)); |
| 942 } | 947 } |
| 943 } | 948 } |
| 944 } | 949 } |
| 945 if (loggedBenchStart) { | 950 if (loggedBenchStart) { |
| 946 logger.logProgress(SkString("\n")); | 951 logger.logProgress(SkString("\n")); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 966 } | 971 } |
| 967 | 972 |
| 968 return 0; | 973 return 0; |
| 969 } | 974 } |
| 970 | 975 |
| 971 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 976 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
| 972 int main(int argc, char * const argv[]) { | 977 int main(int argc, char * const argv[]) { |
| 973 return tool_main(argc, (char**) argv); | 978 return tool_main(argc, (char**) argv); |
| 974 } | 979 } |
| 975 #endif | 980 #endif |
| OLD | NEW |