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

Side by Side Diff: bench/nanobench.cpp

Issue 1051973002: Test SkCodec to kIndex8 in nanobench. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Remove extra newline. Created 5 years, 8 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.h ('K') | « bench/DecodingBench.cpp ('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 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 fImages.push_back() = SkOSPath::Join(flag, file.c_str()); 533 fImages.push_back() = SkOSPath::Join(flag, file.c_str());
534 } 534 }
535 } else if (sk_exists(flag)) { 535 } else if (sk_exists(flag)) {
536 // Also add the value if it is a single image 536 // Also add the value if it is a single image
537 fImages.push_back() = flag; 537 fImages.push_back() = flag;
538 } 538 }
539 } 539 }
540 540
541 // Choose the candidate color types for image decoding 541 // Choose the candidate color types for image decoding
542 const SkColorType colorTypes[] = 542 const SkColorType colorTypes[] =
543 { kN32_SkColorType, kRGB_565_SkColorType, kAlpha_8_SkColorType }; 543 { kN32_SkColorType, kRGB_565_SkColorType, kAlpha_8_SkColorType, kInd ex_8_SkColorType };
544 fColorTypes.push_back_n(SK_ARRAY_COUNT(colorTypes), colorTypes); 544 fColorTypes.push_back_n(SK_ARRAY_COUNT(colorTypes), colorTypes);
545 } 545 }
546 546
547 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) { 547 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) {
548 // Not strictly necessary, as it will be checked again later, 548 // Not strictly necessary, as it will be checked again later,
549 // but helps to avoid a lot of pointless work if we're going to skip it. 549 // but helps to avoid a lot of pointless work if we're going to skip it.
550 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) { 550 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) {
551 return false; 551 return false;
552 } 552 }
553 553
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 637
638 for (; fCurrentCodec < fImages.count(); fCurrentCodec++) { 638 for (; fCurrentCodec < fImages.count(); fCurrentCodec++) {
639 const SkString& path = fImages[fCurrentCodec]; 639 const SkString& path = fImages[fCurrentCodec];
640 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); 640 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
641 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); 641 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
642 SkASSERT(codec); 642 SkASSERT(codec);
643 if (!codec) { 643 if (!codec) {
644 // Nothing to time. 644 // Nothing to time.
645 continue; 645 continue;
646 } 646 }
647
647 while (fCurrentColorType < fColorTypes.count()) { 648 while (fCurrentColorType < fColorTypes.count()) {
648 SkColorType colorType = fColorTypes[fCurrentColorType]; 649 const SkColorType colorType = fColorTypes[fCurrentColorType];
649 fCurrentColorType++; 650 fCurrentColorType++;
651
650 // Make sure we can decode to this color type. 652 // Make sure we can decode to this color type.
651 SkBitmap bitmap;
652 SkImageInfo info = codec->getInfo().makeColorType(colorType); 653 SkImageInfo info = codec->getInfo().makeColorType(colorType);
653 bitmap.allocPixels(info); 654 SkAlphaType alphaType;
655 if (!SkColorTypeValidateAlphaType(colorType, info.alphaType(),
656 &alphaType)) {
657 continue;
658 }
659 if (alphaType != info.alphaType()) {
660 info = info.makeAlphaType(alphaType);
661 }
662
663 const size_t rowBytes = info.minRowBytes();
664 SkAutoMalloc storage(info.getSafeSize(rowBytes));
665
666 // Used if fCurrentColorType is kIndex_8_SkColorType
667 int colorCount = 256;
668 SkPMColor colors[256];
669
654 const SkImageGenerator::Result result = codec->getPixels( 670 const SkImageGenerator::Result result = codec->getPixels(
655 bitmap.info(), bitmap.getPixels(), bitmap.rowBytes()); 671 info, storage.get(), rowBytes, NULL, colors,
672 &colorCount);
656 switch (result) { 673 switch (result) {
657 case SkImageGenerator::kSuccess: 674 case SkImageGenerator::kSuccess:
658 case SkImageGenerator::kIncompleteInput: 675 case SkImageGenerator::kIncompleteInput:
659 return new CodecBench(SkOSPath::Basename(path.c_str()), 676 return new CodecBench(SkOSPath::Basename(path.c_str()),
660 encoded, colorType); 677 encoded, colorType);
661 case SkImageGenerator::kInvalidConversion: 678 case SkImageGenerator::kInvalidConversion:
662 // This is okay. Not all conversions are valid. 679 // This is okay. Not all conversions are valid.
663 break; 680 break;
664 case SkImageGenerator::kCouldNotRewind: 681 case SkImageGenerator::kCouldNotRewind:
665 // FIXME: This is due to a bug in some implementations 682 // FIXME: This is due to a bug in some implementations
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 996
980 return 0; 997 return 0;
981 } 998 }
982 999
983 #if !defined SK_BUILD_FOR_IOS 1000 #if !defined SK_BUILD_FOR_IOS
984 int main(int argc, char** argv) { 1001 int main(int argc, char** argv) {
985 SkCommandLineFlags::Parse(argc, argv); 1002 SkCommandLineFlags::Parse(argc, argv);
986 return nanobench_main(); 1003 return nanobench_main();
987 } 1004 }
988 #endif 1005 #endif
OLDNEW
« bench/CodecBench.h ('K') | « bench/DecodingBench.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698