OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 <ctype.h> | 8 #include <ctype.h> |
9 | 9 |
10 #include "Benchmark.h" | 10 #include "Benchmark.h" |
11 #include "CrashHandler.h" | 11 #include "CrashHandler.h" |
| 12 #include "DecodingBench.h" |
| 13 #include "DecodingSubsetBench.h" |
12 #include "GMBench.h" | 14 #include "GMBench.h" |
13 #include "ProcStats.h" | 15 #include "ProcStats.h" |
14 #include "ResultsWriter.h" | 16 #include "ResultsWriter.h" |
15 #include "RecordingBench.h" | 17 #include "RecordingBench.h" |
16 #include "SKPBench.h" | 18 #include "SKPBench.h" |
17 #include "Stats.h" | 19 #include "Stats.h" |
18 #include "Timer.h" | 20 #include "Timer.h" |
19 | 21 |
20 #include "SkBBoxHierarchy.h" | 22 #include "SkBBoxHierarchy.h" |
21 #include "SkCanvas.h" | 23 #include "SkCanvas.h" |
22 #include "SkCommonFlags.h" | 24 #include "SkCommonFlags.h" |
| 25 #include "SkData.h" |
23 #include "SkForceLinking.h" | 26 #include "SkForceLinking.h" |
24 #include "SkGraphics.h" | 27 #include "SkGraphics.h" |
25 #include "SkOSFile.h" | 28 #include "SkOSFile.h" |
26 #include "SkPictureRecorder.h" | 29 #include "SkPictureRecorder.h" |
27 #include "SkPictureUtils.h" | 30 #include "SkPictureUtils.h" |
28 #include "SkString.h" | 31 #include "SkString.h" |
29 #include "SkSurface.h" | 32 #include "SkSurface.h" |
30 #include "SkTaskGroup.h" | 33 #include "SkTaskGroup.h" |
31 | 34 |
32 #if SK_SUPPORT_GPU | 35 #if SK_SUPPORT_GPU |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 } | 435 } |
433 #endif | 436 #endif |
434 | 437 |
435 class BenchmarkStream { | 438 class BenchmarkStream { |
436 public: | 439 public: |
437 BenchmarkStream() : fBenches(BenchRegistry::Head()) | 440 BenchmarkStream() : fBenches(BenchRegistry::Head()) |
438 , fGMs(skiagm::GMRegistry::Head()) | 441 , fGMs(skiagm::GMRegistry::Head()) |
439 , fCurrentRecording(0) | 442 , fCurrentRecording(0) |
440 , fCurrentScale(0) | 443 , fCurrentScale(0) |
441 , fCurrentSKP(0) | 444 , fCurrentSKP(0) |
442 , fCurrentUseMPD(0) { | 445 , fCurrentUseMPD(0) |
| 446 , fCurrentImage(0) |
| 447 , fCurrentSubsetImage(0) |
| 448 , fCurrentColorType(0) |
| 449 , fDivisor(2) { |
443 for (int i = 0; i < FLAGS_skps.count(); i++) { | 450 for (int i = 0; i < FLAGS_skps.count(); i++) { |
444 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { | 451 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { |
445 fSKPs.push_back() = FLAGS_skps[i]; | 452 fSKPs.push_back() = FLAGS_skps[i]; |
446 } else { | 453 } else { |
447 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); | 454 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); |
448 SkString path; | 455 SkString path; |
449 while (it.next(&path)) { | 456 while (it.next(&path)) { |
450 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str
()); | 457 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str
()); |
451 } | 458 } |
452 } | 459 } |
453 } | 460 } |
454 | 461 |
455 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d", | 462 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d", |
456 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom
)) { | 463 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom
)) { |
457 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0
]); | 464 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0
]); |
458 exit(1); | 465 exit(1); |
459 } | 466 } |
460 | 467 |
461 for (int i = 0; i < FLAGS_scales.count(); i++) { | 468 for (int i = 0; i < FLAGS_scales.count(); i++) { |
462 if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) { | 469 if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) { |
463 SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS
_scales[i]); | 470 SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS
_scales[i]); |
464 exit(1); | 471 exit(1); |
465 } | 472 } |
466 } | 473 } |
467 | 474 |
468 fUseMPDs.push_back() = false; | 475 fUseMPDs.push_back() = false; |
469 if (FLAGS_mpd) { | 476 if (FLAGS_mpd) { |
470 fUseMPDs.push_back() = true; | 477 fUseMPDs.push_back() = true; |
471 } | 478 } |
| 479 |
| 480 // Prepare the images for decoding |
| 481 for (int i = 0; i < FLAGS_images.count(); i++) { |
| 482 const char* flag = FLAGS_images[i]; |
| 483 if (sk_isdir(flag)) { |
| 484 // If the value passed in is a directory, add all the images |
| 485 SkOSFile::Iter it(flag); |
| 486 SkString file; |
| 487 while (it.next(&file)) { |
| 488 fImages.push_back() = SkOSPath::Join(flag, file.c_str()); |
| 489 } |
| 490 } else if (sk_exists(flag)) { |
| 491 // Also add the value if it is a single image |
| 492 fImages.push_back() = flag; |
| 493 } |
| 494 } |
| 495 |
| 496 // Choose the candidate color types for image decoding |
| 497 const SkColorType colorTypes[] = |
| 498 { kN32_SkColorType, kRGB_565_SkColorType, kAlpha_8_SkColorType }; |
| 499 fColorTypes.push_back_n(SK_ARRAY_COUNT(colorTypes), colorTypes); |
472 } | 500 } |
473 | 501 |
474 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) { | 502 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) { |
475 // Not strictly necessary, as it will be checked again later, | 503 // Not strictly necessary, as it will be checked again later, |
476 // but helps to avoid a lot of pointless work if we're going to skip it. | 504 // but helps to avoid a lot of pointless work if we're going to skip it. |
477 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) { | 505 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) { |
478 return false; | 506 return false; |
479 } | 507 } |
480 | 508 |
481 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path)); | 509 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path)); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 (name.c_str(), pic.get(), fClip, | 583 (name.c_str(), pic.get(), fClip, |
556 fScales[fCurrentScale], fUseMPDs[fCurrentUseMPD++])
); | 584 fScales[fCurrentScale], fUseMPDs[fCurrentUseMPD++])
); |
557 } | 585 } |
558 fCurrentUseMPD = 0; | 586 fCurrentUseMPD = 0; |
559 fCurrentSKP++; | 587 fCurrentSKP++; |
560 } | 588 } |
561 fCurrentSKP = 0; | 589 fCurrentSKP = 0; |
562 fCurrentScale++; | 590 fCurrentScale++; |
563 } | 591 } |
564 | 592 |
| 593 // Run the DecodingBenches |
| 594 while (fCurrentImage < fImages.count()) { |
| 595 while (fCurrentColorType < fColorTypes.count()) { |
| 596 const SkString& path = fImages[fCurrentImage]; |
| 597 SkColorType colorType = fColorTypes[fCurrentColorType]; |
| 598 fCurrentColorType++; |
| 599 // Check if the image decodes before creating the benchmark |
| 600 SkBitmap bitmap; |
| 601 if (SkImageDecoder::DecodeFile(path.c_str(), &bitmap, |
| 602 colorType, SkImageDecoder::kDecodePixels_Mode)) { |
| 603 return new DecodingBench(path, colorType); |
| 604 } |
| 605 } |
| 606 fCurrentColorType = 0; |
| 607 fCurrentImage++; |
| 608 } |
| 609 |
| 610 // Run the DecodingSubsetBenches |
| 611 while (fCurrentSubsetImage < fImages.count()) { |
| 612 while (fCurrentColorType < fColorTypes.count()) { |
| 613 const SkString& path = fImages[fCurrentSubsetImage]; |
| 614 SkColorType colorType = fColorTypes[fCurrentColorType]; |
| 615 fCurrentColorType++; |
| 616 // Check if the image decodes before creating the benchmark |
| 617 SkAutoTUnref<SkData> encoded( |
| 618 SkData::NewFromFileName(path.c_str())); |
| 619 SkAutoTDelete<SkMemoryStream> stream( |
| 620 new SkMemoryStream(encoded)); |
| 621 SkAutoTDelete<SkImageDecoder> |
| 622 decoder(SkImageDecoder::Factory(stream.get())); |
| 623 if (!decoder) { |
| 624 SkDebugf("Cannot find decoder for %s\n", path.c_str()); |
| 625 } else { |
| 626 stream->rewind(); |
| 627 int w, h; |
| 628 bool success; |
| 629 if (!decoder->buildTileIndex(stream.detach(), &w, &h) |
| 630 || w*h == 1) { |
| 631 // This is not an error, but in this case we still |
| 632 // do not want to run the benchmark. |
| 633 success = false; |
| 634 } else if (fDivisor > w || fDivisor > h) { |
| 635 SkDebugf("Divisor %d is too big for %s %dx%d\n", |
| 636 fDivisor, path.c_str(), w, h); |
| 637 success = false; |
| 638 } else { |
| 639 const int sW = w / fDivisor; |
| 640 const int sH = h / fDivisor; |
| 641 SkBitmap bitmap; |
| 642 success = true; |
| 643 for (int y = 0; y < h; y += sH) { |
| 644 for (int x = 0; x < w; x += sW) { |
| 645 SkIRect rect = SkIRect::MakeXYWH(x, y, sW, sH); |
| 646 success &= decoder->decodeSubset(&bitmap, rect, |
| 647 colorType); |
| 648 } |
| 649 } |
| 650 } |
| 651 // Create the benchmark if successful |
| 652 if (success) { |
| 653 return new DecodingSubsetBench(path, colorType, |
| 654 fDivisor); |
| 655 } |
| 656 } |
| 657 } |
| 658 fCurrentColorType = 0; |
| 659 fCurrentSubsetImage++; |
| 660 } |
| 661 |
565 return NULL; | 662 return NULL; |
566 } | 663 } |
567 | 664 |
568 void fillCurrentOptions(ResultsWriter* log) const { | 665 void fillCurrentOptions(ResultsWriter* log) const { |
569 log->configOption("source_type", fSourceType); | 666 log->configOption("source_type", fSourceType); |
570 log->configOption("bench_type", fBenchType); | 667 log->configOption("bench_type", fBenchType); |
571 if (0 == strcmp(fSourceType, "skp")) { | 668 if (0 == strcmp(fSourceType, "skp")) { |
572 log->configOption("clip", | 669 log->configOption("clip", |
573 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, | 670 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, |
574 fClip.fRight, fClip.fBottom).c
_str()); | 671 fClip.fRight, fClip.fBottom).c
_str()); |
575 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentSc
ale]).c_str()); | 672 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentSc
ale]).c_str()); |
576 if (fCurrentUseMPD > 0) { | 673 if (fCurrentUseMPD > 0) { |
577 SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD); | 674 SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD); |
578 log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD-
1] ? "true" : "false"); | 675 log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD-
1] ? "true" : "false"); |
579 } | 676 } |
580 } | 677 } |
581 if (0 == strcmp(fBenchType, "recording")) { | 678 if (0 == strcmp(fBenchType, "recording")) { |
582 log->metric("bytes", fSKPBytes); | 679 log->metric("bytes", fSKPBytes); |
583 log->metric("ops", fSKPOps); | 680 log->metric("ops", fSKPOps); |
584 } | 681 } |
585 } | 682 } |
586 | 683 |
587 private: | 684 private: |
588 const BenchRegistry* fBenches; | 685 const BenchRegistry* fBenches; |
589 const skiagm::GMRegistry* fGMs; | 686 const skiagm::GMRegistry* fGMs; |
590 SkIRect fClip; | 687 SkIRect fClip; |
591 SkTArray<SkScalar> fScales; | 688 SkTArray<SkScalar> fScales; |
592 SkTArray<SkString> fSKPs; | 689 SkTArray<SkString> fSKPs; |
593 SkTArray<bool> fUseMPDs; | 690 SkTArray<bool> fUseMPDs; |
| 691 SkTArray<SkString> fImages; |
| 692 SkTArray<SkColorType> fColorTypes; |
594 | 693 |
595 double fSKPBytes, fSKPOps; | 694 double fSKPBytes, fSKPOps; |
596 | 695 |
597 const char* fSourceType; // What we're benching: bench, GM, SKP, ... | 696 const char* fSourceType; // What we're benching: bench, GM, SKP, ... |
598 const char* fBenchType; // How we bench it: micro, recording, playback, ..
. | 697 const char* fBenchType; // How we bench it: micro, recording, playback, ..
. |
599 int fCurrentRecording; | 698 int fCurrentRecording; |
600 int fCurrentScale; | 699 int fCurrentScale; |
601 int fCurrentSKP; | 700 int fCurrentSKP; |
602 int fCurrentUseMPD; | 701 int fCurrentUseMPD; |
| 702 int fCurrentImage; |
| 703 int fCurrentSubsetImage; |
| 704 int fCurrentColorType; |
| 705 const int fDivisor; |
603 }; | 706 }; |
604 | 707 |
605 int nanobench_main(); | 708 int nanobench_main(); |
606 int nanobench_main() { | 709 int nanobench_main() { |
607 SetupCrashHandler(); | 710 SetupCrashHandler(); |
608 SkAutoGraphics ag; | 711 SkAutoGraphics ag; |
609 SkTaskGroup::Enabler enabled; | 712 SkTaskGroup::Enabler enabled; |
610 | 713 |
611 #if SK_SUPPORT_GPU | 714 #if SK_SUPPORT_GPU |
612 GrContext::Options grContextOpts; | 715 GrContext::Options grContextOpts; |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 | 896 |
794 return 0; | 897 return 0; |
795 } | 898 } |
796 | 899 |
797 #if !defined SK_BUILD_FOR_IOS | 900 #if !defined SK_BUILD_FOR_IOS |
798 int main(int argc, char** argv) { | 901 int main(int argc, char** argv) { |
799 SkCommandLineFlags::Parse(argc, argv); | 902 SkCommandLineFlags::Parse(argc, argv); |
800 return nanobench_main(); | 903 return nanobench_main(); |
801 } | 904 } |
802 #endif | 905 #endif |
OLD | NEW |