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 "nanobench.h" | 10 #include "nanobench.h" |
11 | 11 |
12 #include "Benchmark.h" | 12 #include "Benchmark.h" |
13 #include "BitmapRegionDecoderBench.h" | |
13 #include "CodecBench.h" | 14 #include "CodecBench.h" |
14 #include "CrashHandler.h" | 15 #include "CrashHandler.h" |
15 #include "DecodingBench.h" | 16 #include "DecodingBench.h" |
16 #include "GMBench.h" | 17 #include "GMBench.h" |
17 #include "ProcStats.h" | 18 #include "ProcStats.h" |
18 #include "ResultsWriter.h" | 19 #include "ResultsWriter.h" |
19 #include "RecordingBench.h" | 20 #include "RecordingBench.h" |
20 #include "SKPAnimationBench.h" | 21 #include "SKPAnimationBench.h" |
21 #include "SKPBench.h" | 22 #include "SKPBench.h" |
22 #include "SubsetBenchPriv.h" | 23 #include "SubsetBenchPriv.h" |
23 #include "SubsetSingleBench.h" | 24 #include "SubsetSingleBench.h" |
24 #include "SubsetTranslateBench.h" | 25 #include "SubsetTranslateBench.h" |
25 #include "SubsetZoomBench.h" | 26 #include "SubsetZoomBench.h" |
26 #include "Stats.h" | 27 #include "Stats.h" |
27 #include "Timer.h" | 28 #include "Timer.h" |
28 | 29 |
30 #include "SkBitmapRegionDecoderInterface.h" | |
29 #include "SkBBoxHierarchy.h" | 31 #include "SkBBoxHierarchy.h" |
30 #include "SkCanvas.h" | 32 #include "SkCanvas.h" |
31 #include "SkCodec.h" | 33 #include "SkCodec.h" |
32 #include "SkCommonFlags.h" | 34 #include "SkCommonFlags.h" |
33 #include "SkData.h" | 35 #include "SkData.h" |
34 #include "SkForceLinking.h" | 36 #include "SkForceLinking.h" |
35 #include "SkGraphics.h" | 37 #include "SkGraphics.h" |
36 #include "SkOSFile.h" | 38 #include "SkOSFile.h" |
37 #include "SkPictureRecorder.h" | 39 #include "SkPictureRecorder.h" |
38 #include "SkPictureUtils.h" | 40 #include "SkPictureUtils.h" |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
550 | 552 |
551 // Check if the image is large enough for a meaningful subset benchmark. | 553 // Check if the image is large enough for a meaningful subset benchmark. |
552 if (*width <= 512 && *height <= 512) { | 554 if (*width <= 512 && *height <= 512) { |
553 // This should not print a message since it is not an error. | 555 // This should not print a message since it is not an error. |
554 return false; | 556 return false; |
555 } | 557 } |
556 | 558 |
557 return true; | 559 return true; |
558 } | 560 } |
559 | 561 |
562 static bool valid_brd_bench(SkData* encoded, SkBitmapRegionDecoderInterface::Str ategy strategy, | |
563 SkColorType colorType, SkIRect* subset) { | |
564 SkStreamRewindable* stream = new SkMemoryStream(encoded); | |
565 SkAutoTDelete<SkBitmapRegionDecoderInterface> brd( | |
566 SkBitmapRegionDecoderInterface::CreateBitmapRegionDecoder(stream, st rategy)); | |
567 if (nullptr == brd.get()) { | |
568 // This is indicates that subset decoding is not supported for a particu lar image format. | |
569 return false; | |
570 } | |
571 | |
572 SkAutoTDelete<SkBitmap> bitmap(brd->decodeRegion(0, 0, brd->width(), brd->he ight(), 1, | |
573 colorType)); | |
574 if (nullptr == bitmap.get() || colorType != bitmap->colorType()) { | |
575 // This indicates that conversion to the requested color type is not sup ported for the | |
576 // particular image. | |
577 return false; | |
578 } | |
579 | |
580 // We can set the subset rect here, since we now know the height of the imag e. We will choose | |
scroggo
2015/09/17 20:05:38
Since we're only decoding one subset, and we're co
msarett
2015/09/18 13:22:30
Yeah you're right, this is unfair. I should give
scroggo
2015/09/18 15:07:23
I'm starting to wonder whether we want to include
msarett
2015/09/18 17:41:17
I think we do want to include SkImageDecoder. I f
| |
581 // the maximum size square subset centered at the center of the image. | |
582 uint32_t dimension = SkTMin(brd->width(), brd->height()); | |
583 uint32_t left = (brd->width() - dimension) / 2; | |
584 uint32_t top = (brd->height() - dimension) / 2; | |
585 *subset = SkIRect::MakeXYWH(left, top, dimension, dimension); | |
586 return true; | |
587 } | |
588 | |
560 static void cleanup_run(Target* target) { | 589 static void cleanup_run(Target* target) { |
561 delete target; | 590 delete target; |
562 #if SK_SUPPORT_GPU | 591 #if SK_SUPPORT_GPU |
563 if (FLAGS_abandonGpuContext) { | 592 if (FLAGS_abandonGpuContext) { |
564 gGrFactory->abandonContexts(); | 593 gGrFactory->abandonContexts(); |
565 } | 594 } |
566 if (FLAGS_resetGpuContext || FLAGS_abandonGpuContext) { | 595 if (FLAGS_resetGpuContext || FLAGS_abandonGpuContext) { |
567 gGrFactory->destroyContexts(); | 596 gGrFactory->destroyContexts(); |
568 } | 597 } |
569 #endif | 598 #endif |
570 } | 599 } |
571 | 600 |
572 class BenchmarkStream { | 601 class BenchmarkStream { |
573 public: | 602 public: |
574 BenchmarkStream() : fBenches(BenchRegistry::Head()) | 603 BenchmarkStream() : fBenches(BenchRegistry::Head()) |
575 , fGMs(skiagm::GMRegistry::Head()) | 604 , fGMs(skiagm::GMRegistry::Head()) |
576 , fCurrentRecording(0) | 605 , fCurrentRecording(0) |
577 , fCurrentScale(0) | 606 , fCurrentScale(0) |
578 , fCurrentSKP(0) | 607 , fCurrentSKP(0) |
579 , fCurrentUseMPD(0) | 608 , fCurrentUseMPD(0) |
580 , fCurrentCodec(0) | 609 , fCurrentCodec(0) |
581 , fCurrentImage(0) | 610 , fCurrentImage(0) |
582 , fCurrentSubsetImage(0) | 611 , fCurrentSubsetImage(0) |
612 , fCurrentBRDImage(0) | |
583 , fCurrentColorType(0) | 613 , fCurrentColorType(0) |
584 , fCurrentSubsetType(0) | 614 , fCurrentSubsetType(0) |
585 , fUseCodec(0) | 615 , fUseCodec(0) |
616 , fCurrentBRDStrategy(0) | |
617 , fCurrentBRDSampleSize(0) | |
586 , fCurrentAnimSKP(0) { | 618 , fCurrentAnimSKP(0) { |
587 for (int i = 0; i < FLAGS_skps.count(); i++) { | 619 for (int i = 0; i < FLAGS_skps.count(); i++) { |
588 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { | 620 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { |
589 fSKPs.push_back() = FLAGS_skps[i]; | 621 fSKPs.push_back() = FLAGS_skps[i]; |
590 } else { | 622 } else { |
591 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); | 623 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); |
592 SkString path; | 624 SkString path; |
593 while (it.next(&path)) { | 625 while (it.next(&path)) { |
594 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str ()); | 626 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str ()); |
595 } | 627 } |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
869 fCurrentSubsetType = 0; | 901 fCurrentSubsetType = 0; |
870 fCurrentColorType++; | 902 fCurrentColorType++; |
871 } | 903 } |
872 fCurrentColorType = 0; | 904 fCurrentColorType = 0; |
873 fCurrentSubsetImage++; | 905 fCurrentSubsetImage++; |
874 } | 906 } |
875 fCurrentSubsetImage = 0; | 907 fCurrentSubsetImage = 0; |
876 fUseCodec++; | 908 fUseCodec++; |
877 } | 909 } |
878 | 910 |
911 // Run the BRDBenches | |
912 // We will benchmark multiple BRD strategies. | |
913 const SkBitmapRegionDecoderInterface::Strategy strategies[] = { | |
914 SkBitmapRegionDecoderInterface::kOriginal_Strategy, | |
915 SkBitmapRegionDecoderInterface::kCanvas_Strategy, | |
916 }; | |
917 // We will focus on these sample sizes, since they are most often used i n real code. | |
918 const uint32_t sampleSizes[] = { 1, 2, 4, 8 }; | |
919 while (fCurrentBRDImage < fImages.count()) { | |
920 while (fCurrentBRDStrategy < (int) SK_ARRAY_COUNT(strategies)) { | |
921 while (fCurrentColorType < fColorTypes.count()) { | |
922 while (fCurrentBRDSampleSize < (int) SK_ARRAY_COUNT(sampleSi zes)) { | |
923 const SkString& path = fImages[fCurrentBRDImage]; | |
924 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(pat h.c_str())); | |
925 const SkBitmapRegionDecoderInterface::Strategy strategy = | |
926 strategies[fCurrentBRDStrategy]; | |
927 const SkColorType colorType = fColorTypes[fCurrentColorT ype]; | |
928 uint32_t sampleSize = sampleSizes[fCurrentBRDSampleSize] ; | |
929 fCurrentBRDSampleSize++; | |
930 | |
931 SkIRect subset; | |
932 if (valid_brd_bench(encoded.get(), strategy, colorType, &subset)) { | |
933 return new BitmapRegionDecoderBench(SkOSPath::Basena me(path.c_str()), | |
934 encoded.get(), strategy, colorType, sampleSi ze, subset); | |
935 } else { | |
936 break; | |
937 } | |
938 } | |
939 fCurrentBRDSampleSize = 0; | |
940 fCurrentColorType++; | |
941 } | |
942 fCurrentColorType = 0; | |
943 fCurrentBRDStrategy++; | |
944 } | |
945 fCurrentBRDStrategy = 0; | |
946 fCurrentBRDImage++; | |
947 } | |
948 | |
879 return nullptr; | 949 return nullptr; |
880 } | 950 } |
881 | 951 |
882 void fillCurrentOptions(ResultsWriter* log) const { | 952 void fillCurrentOptions(ResultsWriter* log) const { |
883 log->configOption("source_type", fSourceType); | 953 log->configOption("source_type", fSourceType); |
884 log->configOption("bench_type", fBenchType); | 954 log->configOption("bench_type", fBenchType); |
885 if (0 == strcmp(fSourceType, "skp")) { | 955 if (0 == strcmp(fSourceType, "skp")) { |
886 log->configOption("clip", | 956 log->configOption("clip", |
887 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, | 957 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, |
888 fClip.fRight, fClip.fBottom).c _str()); | 958 fClip.fRight, fClip.fBottom).c _str()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
925 | 995 |
926 const char* fSourceType; // What we're benching: bench, GM, SKP, ... | 996 const char* fSourceType; // What we're benching: bench, GM, SKP, ... |
927 const char* fBenchType; // How we bench it: micro, recording, playback, .. . | 997 const char* fBenchType; // How we bench it: micro, recording, playback, .. . |
928 int fCurrentRecording; | 998 int fCurrentRecording; |
929 int fCurrentScale; | 999 int fCurrentScale; |
930 int fCurrentSKP; | 1000 int fCurrentSKP; |
931 int fCurrentUseMPD; | 1001 int fCurrentUseMPD; |
932 int fCurrentCodec; | 1002 int fCurrentCodec; |
933 int fCurrentImage; | 1003 int fCurrentImage; |
934 int fCurrentSubsetImage; | 1004 int fCurrentSubsetImage; |
1005 int fCurrentBRDImage; | |
935 int fCurrentColorType; | 1006 int fCurrentColorType; |
936 int fCurrentSubsetType; | 1007 int fCurrentSubsetType; |
937 int fUseCodec; | 1008 int fUseCodec; |
1009 int fCurrentBRDStrategy; | |
1010 int fCurrentBRDSampleSize; | |
938 int fCurrentAnimSKP; | 1011 int fCurrentAnimSKP; |
939 }; | 1012 }; |
940 | 1013 |
941 int nanobench_main(); | 1014 int nanobench_main(); |
942 int nanobench_main() { | 1015 int nanobench_main() { |
943 SetupCrashHandler(); | 1016 SetupCrashHandler(); |
944 SkAutoGraphics ag; | 1017 SkAutoGraphics ag; |
945 SkTaskGroup::Enabler enabled(FLAGS_threads); | 1018 SkTaskGroup::Enabler enabled(FLAGS_threads); |
946 | 1019 |
947 #if SK_SUPPORT_GPU | 1020 #if SK_SUPPORT_GPU |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1161 | 1234 |
1162 return 0; | 1235 return 0; |
1163 } | 1236 } |
1164 | 1237 |
1165 #if !defined SK_BUILD_FOR_IOS | 1238 #if !defined SK_BUILD_FOR_IOS |
1166 int main(int argc, char** argv) { | 1239 int main(int argc, char** argv) { |
1167 SkCommandLineFlags::Parse(argc, argv); | 1240 SkCommandLineFlags::Parse(argc, argv); |
1168 return nanobench_main(); | 1241 return nanobench_main(); |
1169 } | 1242 } |
1170 #endif | 1243 #endif |
OLD | NEW |