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" |
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 | 783 |
784 fCurrentAnimSKP++; | 784 fCurrentAnimSKP++; |
785 SkString name = SkOSPath::Basename(path.c_str()); | 785 SkString name = SkOSPath::Basename(path.c_str()); |
786 SkAutoTUnref<SKPAnimationBench::Animation> animation( | 786 SkAutoTUnref<SKPAnimationBench::Animation> animation( |
787 SKPAnimationBench::CreateZoomAnimation(fZoomMax, fZoomPeriod
Ms)); | 787 SKPAnimationBench::CreateZoomAnimation(fZoomMax, fZoomPeriod
Ms)); |
788 return new SKPAnimationBench(name.c_str(), pic.get(), fClip, ani
mation, | 788 return new SKPAnimationBench(name.c_str(), pic.get(), fClip, ani
mation, |
789 FLAGS_loopSKP); | 789 FLAGS_loopSKP); |
790 } | 790 } |
791 } | 791 } |
792 | 792 |
793 | |
794 for (; fCurrentCodec < fImages.count(); fCurrentCodec++) { | 793 for (; fCurrentCodec < fImages.count(); fCurrentCodec++) { |
| 794 fSourceType = "image"; |
| 795 fBenchType = "skcodec"; |
795 const SkString& path = fImages[fCurrentCodec]; | 796 const SkString& path = fImages[fCurrentCodec]; |
796 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); | 797 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
797 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | 798 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
798 if (!codec) { | 799 if (!codec) { |
799 // Nothing to time. | 800 // Nothing to time. |
800 SkDebugf("Cannot find codec for %s\n", path.c_str()); | 801 SkDebugf("Cannot find codec for %s\n", path.c_str()); |
801 continue; | 802 continue; |
802 } | 803 } |
803 | 804 |
804 while (fCurrentColorType < fColorTypes.count()) { | 805 while (fCurrentColorType < fColorTypes.count()) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 // This represents some sort of failure. | 839 // This represents some sort of failure. |
839 SkASSERT(false); | 840 SkASSERT(false); |
840 break; | 841 break; |
841 } | 842 } |
842 } | 843 } |
843 fCurrentColorType = 0; | 844 fCurrentColorType = 0; |
844 } | 845 } |
845 | 846 |
846 // Run the DecodingBenches | 847 // Run the DecodingBenches |
847 while (fCurrentImage < fImages.count()) { | 848 while (fCurrentImage < fImages.count()) { |
| 849 fSourceType = "image"; |
| 850 fBenchType = "skimagedecoder"; |
848 while (fCurrentColorType < fColorTypes.count()) { | 851 while (fCurrentColorType < fColorTypes.count()) { |
849 const SkString& path = fImages[fCurrentImage]; | 852 const SkString& path = fImages[fCurrentImage]; |
850 SkColorType colorType = fColorTypes[fCurrentColorType]; | 853 SkColorType colorType = fColorTypes[fCurrentColorType]; |
851 fCurrentColorType++; | 854 fCurrentColorType++; |
852 // Check if the image decodes to the right color type | 855 // Check if the image decodes to the right color type |
853 // before creating the benchmark | 856 // before creating the benchmark |
854 SkBitmap bitmap; | 857 SkBitmap bitmap; |
855 if (SkImageDecoder::DecodeFile(path.c_str(), &bitmap, | 858 if (SkImageDecoder::DecodeFile(path.c_str(), &bitmap, |
856 colorType, SkImageDecoder::kDecodePixels_Mode) | 859 colorType, SkImageDecoder::kDecodePixels_Mode) |
857 && bitmap.colorType() == colorType) { | 860 && bitmap.colorType() == colorType) { |
858 return new DecodingBench(path, colorType); | 861 return new DecodingBench(path, colorType); |
859 } | 862 } |
860 } | 863 } |
861 fCurrentColorType = 0; | 864 fCurrentColorType = 0; |
862 fCurrentImage++; | 865 fCurrentImage++; |
863 } | 866 } |
864 | 867 |
865 // Run the SubsetBenches | 868 // Run the SubsetBenches |
866 bool useCodecOpts[] = { true, false }; | 869 bool useCodecOpts[] = { true, false }; |
867 while (fUseCodec < 2) { | 870 while (fUseCodec < 2) { |
868 bool useCodec = useCodecOpts[fUseCodec]; | 871 bool useCodec = useCodecOpts[fUseCodec]; |
| 872 fSourceType = "image"; |
| 873 fBenchType = useCodec ? "skcodec" : "skimagedecoder"; |
869 while (fCurrentSubsetImage < fImages.count()) { | 874 while (fCurrentSubsetImage < fImages.count()) { |
870 while (fCurrentColorType < fColorTypes.count()) { | 875 while (fCurrentColorType < fColorTypes.count()) { |
871 const SkString& path = fImages[fCurrentSubsetImage]; | 876 const SkString& path = fImages[fCurrentSubsetImage]; |
872 SkColorType colorType = fColorTypes[fCurrentColorType]; | 877 SkColorType colorType = fColorTypes[fCurrentColorType]; |
873 while (fCurrentSubsetType <= kLast_SubsetType) { | 878 while (fCurrentSubsetType <= kLast_SubsetType) { |
874 int width = 0; | 879 int width = 0; |
875 int height = 0; | 880 int height = 0; |
876 int currentSubsetType = fCurrentSubsetType++; | 881 int currentSubsetType = fCurrentSubsetType++; |
877 if (valid_subset_bench(path, colorType, useCodec, &width
, &height)) { | 882 if (valid_subset_bench(path, colorType, useCodec, &width
, &height)) { |
878 switch (currentSubsetType) { | 883 switch (currentSubsetType) { |
(...skipping 28 matching lines...) Expand all Loading... |
907 } | 912 } |
908 fCurrentColorType = 0; | 913 fCurrentColorType = 0; |
909 fCurrentSubsetImage++; | 914 fCurrentSubsetImage++; |
910 } | 915 } |
911 fCurrentSubsetImage = 0; | 916 fCurrentSubsetImage = 0; |
912 fUseCodec++; | 917 fUseCodec++; |
913 } | 918 } |
914 | 919 |
915 // Run the BRDBenches | 920 // Run the BRDBenches |
916 // We will benchmark multiple BRD strategies. | 921 // We will benchmark multiple BRD strategies. |
917 const SkBitmapRegionDecoderInterface::Strategy strategies[] = { | 922 static const struct { |
918 SkBitmapRegionDecoderInterface::kOriginal_Strategy, | 923 SkBitmapRegionDecoderInterface::Strategy fStrategy; |
919 SkBitmapRegionDecoderInterface::kCanvas_Strategy, | 924 const char* fName; |
| 925 } strategies[] = { |
| 926 { SkBitmapRegionDecoderInterface::kOriginal_Strategy, "BRD" }, |
| 927 { SkBitmapRegionDecoderInterface::kCanvas_Strategy, "BRD_canvas"
}, |
920 }; | 928 }; |
921 | 929 |
922 // We intend to create benchmarks that model the use cases in | 930 // We intend to create benchmarks that model the use cases in |
923 // android/libraries/social/tiledimage. In this library, an image is de
coded in 512x512 | 931 // android/libraries/social/tiledimage. In this library, an image is de
coded in 512x512 |
924 // tiles. The image can be translated freely, so the location of a tile
may be anywhere in | 932 // tiles. The image can be translated freely, so the location of a tile
may be anywhere in |
925 // the image. For that reason, we will benchmark decodes in five repres
entative locations | 933 // the image. For that reason, we will benchmark decodes in five repres
entative locations |
926 // in the image. Additionally, this use case utilizes power of two scal
ing, so we will | 934 // in the image. Additionally, this use case utilizes power of two scal
ing, so we will |
927 // test on power of two sample sizes. The output tile is always 512x512
, so, when a | 935 // test on power of two sample sizes. The output tile is always 512x512
, so, when a |
928 // sampleSize is used, the size of the subset that is decoded is always | 936 // sampleSize is used, the size of the subset that is decoded is always |
929 // (sampleSize*512)x(sampleSize*512). | 937 // (sampleSize*512)x(sampleSize*512). |
930 // There are a few good reasons to only test on power of two sample size
s at this time: | 938 // There are a few good reasons to only test on power of two sample size
s at this time: |
931 // JPEG decodes using kOriginal_Strategy are broken for non-powers o
f two. | 939 // JPEG decodes using kOriginal_Strategy are broken for non-powers o
f two. |
932 // skbug.com/4319 | 940 // skbug.com/4319 |
933 // All use cases we are aware of only scale by powers of two. | 941 // All use cases we are aware of only scale by powers of two. |
934 // PNG decodes use the indicated sampling strategy regardless of the
sample size, so | 942 // PNG decodes use the indicated sampling strategy regardless of the
sample size, so |
935 // these tests are sufficient to provide good coverage of our sc
aling options. | 943 // these tests are sufficient to provide good coverage of our sc
aling options. |
936 const uint32_t sampleSizes[] = { 1, 2, 4, 8, 16 }; | 944 const uint32_t sampleSizes[] = { 1, 2, 4, 8, 16 }; |
937 const uint32_t minOutputSize = 512; | 945 const uint32_t minOutputSize = 512; |
938 while (fCurrentBRDImage < fImages.count()) { | 946 while (fCurrentBRDImage < fImages.count()) { |
939 while (fCurrentBRDStrategy < (int) SK_ARRAY_COUNT(strategies)) { | 947 while (fCurrentBRDStrategy < (int) SK_ARRAY_COUNT(strategies)) { |
| 948 fSourceType = "image"; |
| 949 fBenchType = strategies[fCurrentBRDStrategy].fName; |
940 while (fCurrentColorType < fColorTypes.count()) { | 950 while (fCurrentColorType < fColorTypes.count()) { |
941 while (fCurrentBRDSampleSize < (int) SK_ARRAY_COUNT(sampleSi
zes)) { | 951 while (fCurrentBRDSampleSize < (int) SK_ARRAY_COUNT(sampleSi
zes)) { |
942 while (fCurrentSubsetType <= kLastSingle_SubsetType) { | 952 while (fCurrentSubsetType <= kLastSingle_SubsetType) { |
943 const SkString& path = fImages[fCurrentBRDImage]; | 953 const SkString& path = fImages[fCurrentBRDImage]; |
944 const SkBitmapRegionDecoderInterface::Strategy strat
egy = | 954 const SkBitmapRegionDecoderInterface::Strategy strat
egy = |
945 strategies[fCurrentBRDStrategy]; | 955 strategies[fCurrentBRDStrategy].fStrategy; |
946 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName
(path.c_str())); | 956 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName
(path.c_str())); |
947 const SkColorType colorType = fColorTypes[fCurrentCo
lorType]; | 957 const SkColorType colorType = fColorTypes[fCurrentCo
lorType]; |
948 uint32_t sampleSize = sampleSizes[fCurrentBRDSampleS
ize]; | 958 uint32_t sampleSize = sampleSizes[fCurrentBRDSampleS
ize]; |
949 int currentSubsetType = fCurrentSubsetType++; | 959 int currentSubsetType = fCurrentSubsetType++; |
950 | 960 |
951 int width = 0; | 961 int width = 0; |
952 int height = 0; | 962 int height = 0; |
953 if (!valid_brd_bench(encoded.get(), strategy, colorT
ype, sampleSize, | 963 if (!valid_brd_bench(encoded.get(), strategy, colorT
ype, sampleSize, |
954 minOutputSize, &width, &height)) { | 964 minOutputSize, &width, &height)) { |
955 break; | 965 break; |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1292 | 1302 |
1293 return 0; | 1303 return 0; |
1294 } | 1304 } |
1295 | 1305 |
1296 #if !defined SK_BUILD_FOR_IOS | 1306 #if !defined SK_BUILD_FOR_IOS |
1297 int main(int argc, char** argv) { | 1307 int main(int argc, char** argv) { |
1298 SkCommandLineFlags::Parse(argc, argv); | 1308 SkCommandLineFlags::Parse(argc, argv); |
1299 return nanobench_main(); | 1309 return nanobench_main(); |
1300 } | 1310 } |
1301 #endif | 1311 #endif |
OLD | NEW |