Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: bench/nanobench.cpp

Issue 1568913002: Make CodecBench test kPremul and kUnpremul (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Silent for opaque images Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« bench/CodecBench.cpp ('K') | « bench/CodecBenchPriv.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 BenchmarkStream() : fBenches(BenchRegistry::Head()) 557 BenchmarkStream() : fBenches(BenchRegistry::Head())
558 , fGMs(skiagm::GMRegistry::Head()) 558 , fGMs(skiagm::GMRegistry::Head())
559 , fCurrentRecording(0) 559 , fCurrentRecording(0)
560 , fCurrentScale(0) 560 , fCurrentScale(0)
561 , fCurrentSKP(0) 561 , fCurrentSKP(0)
562 , fCurrentUseMPD(0) 562 , fCurrentUseMPD(0)
563 , fCurrentCodec(0) 563 , fCurrentCodec(0)
564 , fCurrentImage(0) 564 , fCurrentImage(0)
565 , fCurrentBRDImage(0) 565 , fCurrentBRDImage(0)
566 , fCurrentColorType(0) 566 , fCurrentColorType(0)
567 , fCurrentAlphaType(0)
567 , fCurrentSubsetType(0) 568 , fCurrentSubsetType(0)
568 , fCurrentBRDStrategy(0) 569 , fCurrentBRDStrategy(0)
569 , fCurrentBRDSampleSize(0) 570 , fCurrentBRDSampleSize(0)
570 , fCurrentAnimSKP(0) { 571 , fCurrentAnimSKP(0) {
571 for (int i = 0; i < FLAGS_skps.count(); i++) { 572 for (int i = 0; i < FLAGS_skps.count(); i++) {
572 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { 573 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) {
573 fSKPs.push_back() = FLAGS_skps[i]; 574 fSKPs.push_back() = FLAGS_skps[i];
574 } else { 575 } else {
575 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); 576 SkOSFile::Iter it(FLAGS_skps[i], ".skp");
576 SkString path; 577 SkString path;
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); 746 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
746 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); 747 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
747 if (!codec) { 748 if (!codec) {
748 // Nothing to time. 749 // Nothing to time.
749 SkDebugf("Cannot find codec for %s\n", path.c_str()); 750 SkDebugf("Cannot find codec for %s\n", path.c_str());
750 continue; 751 continue;
751 } 752 }
752 753
753 while (fCurrentColorType < fColorTypes.count()) { 754 while (fCurrentColorType < fColorTypes.count()) {
754 const SkColorType colorType = fColorTypes[fCurrentColorType]; 755 const SkColorType colorType = fColorTypes[fCurrentColorType];
755 fCurrentColorType++;
756 756
757 // Make sure we can decode to this color type. 757 SkAlphaType alphaType = codec->getInfo().alphaType();
758 SkImageInfo info = codec->getInfo().makeColorType(colorType); 758 switch (alphaType) {
759 SkAlphaType alphaType; 759 case kOpaque_SkAlphaType:
760 if (!SkColorTypeValidateAlphaType(colorType, info.alphaType(), 760 // We only need to test one alpha type (opaque).
761 &alphaType)) { 761 fCurrentColorType++;
762 continue; 762 break;
763 } 763 case kUnpremul_SkAlphaType:
764 if (alphaType != info.alphaType()) { 764 case kPremul_SkAlphaType:
765 info = info.makeAlphaType(alphaType); 765 if (0 == fCurrentAlphaType) {
766 // Test unpremul first.
767 alphaType = kUnpremul_SkAlphaType;
768 fCurrentAlphaType++;
769 } else {
770 // Test premul.
771 alphaType = kPremul_SkAlphaType;
772 fCurrentAlphaType = 0;
773 fCurrentColorType++;
774 }
775 break;
776 default:
777 SkASSERT(false);
778 fCurrentColorType++;
779 break;
766 } 780 }
767 781
782 // Make sure we can decode to this color type and alpha type.
783 SkImageInfo info =
784 codec->getInfo().makeColorType(colorType).makeAlphaType( alphaType);
768 const size_t rowBytes = info.minRowBytes(); 785 const size_t rowBytes = info.minRowBytes();
769 SkAutoMalloc storage(info.getSafeSize(rowBytes)); 786 SkAutoMalloc storage(info.getSafeSize(rowBytes));
770 787
771 // Used if fCurrentColorType is kIndex_8_SkColorType 788 // Used if fCurrentColorType is kIndex_8_SkColorType
772 int colorCount = 256; 789 int colorCount = 256;
773 SkPMColor colors[256]; 790 SkPMColor colors[256];
774 791
775 const SkCodec::Result result = codec->getPixels( 792 const SkCodec::Result result = codec->getPixels(
776 info, storage.get(), rowBytes, nullptr, colors, 793 info, storage.get(), rowBytes, nullptr, colors,
777 &colorCount); 794 &colorCount);
778 switch (result) { 795 switch (result) {
779 case SkCodec::kSuccess: 796 case SkCodec::kSuccess:
780 case SkCodec::kIncompleteInput: 797 case SkCodec::kIncompleteInput:
781 return new CodecBench(SkOSPath::Basename(path.c_str()), 798 return new CodecBench(SkOSPath::Basename(path.c_str()),
782 encoded, colorType); 799 encoded, colorType, alphaType);
783 case SkCodec::kInvalidConversion: 800 case SkCodec::kInvalidConversion:
784 // This is okay. Not all conversions are valid. 801 // This is okay. Not all conversions are valid.
785 break; 802 break;
786 default: 803 default:
787 // This represents some sort of failure. 804 // This represents some sort of failure.
788 SkASSERT(false); 805 SkASSERT(false);
789 break; 806 break;
790 } 807 }
791 } 808 }
792 fCurrentColorType = 0; 809 fCurrentColorType = 0;
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 const char* fSourceType; // What we're benching: bench, GM, SKP, ... 982 const char* fSourceType; // What we're benching: bench, GM, SKP, ...
966 const char* fBenchType; // How we bench it: micro, recording, playback, .. . 983 const char* fBenchType; // How we bench it: micro, recording, playback, .. .
967 int fCurrentRecording; 984 int fCurrentRecording;
968 int fCurrentScale; 985 int fCurrentScale;
969 int fCurrentSKP; 986 int fCurrentSKP;
970 int fCurrentUseMPD; 987 int fCurrentUseMPD;
971 int fCurrentCodec; 988 int fCurrentCodec;
972 int fCurrentImage; 989 int fCurrentImage;
973 int fCurrentBRDImage; 990 int fCurrentBRDImage;
974 int fCurrentColorType; 991 int fCurrentColorType;
992 int fCurrentAlphaType;
975 int fCurrentSubsetType; 993 int fCurrentSubsetType;
976 int fCurrentBRDStrategy; 994 int fCurrentBRDStrategy;
977 int fCurrentBRDSampleSize; 995 int fCurrentBRDSampleSize;
978 int fCurrentAnimSKP; 996 int fCurrentAnimSKP;
979 }; 997 };
980 998
981 // Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung. 999 // Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung.
982 // This prints something every once in a while so that it knows we're still work ing. 1000 // This prints something every once in a while so that it knows we're still work ing.
983 static void start_keepalive() { 1001 static void start_keepalive() {
984 struct Loop { 1002 struct Loop {
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 1245
1228 return 0; 1246 return 0;
1229 } 1247 }
1230 1248
1231 #if !defined SK_BUILD_FOR_IOS 1249 #if !defined SK_BUILD_FOR_IOS
1232 int main(int argc, char** argv) { 1250 int main(int argc, char** argv) {
1233 SkCommandLineFlags::Parse(argc, argv); 1251 SkCommandLineFlags::Parse(argc, argv);
1234 return nanobench_main(); 1252 return nanobench_main();
1235 } 1253 }
1236 #endif 1254 #endif
OLDNEW
« bench/CodecBench.cpp ('K') | « bench/CodecBenchPriv.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698