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

Side by Side Diff: bench/nanobench.cpp

Issue 1344993003: Add nanobench tests for BitmapRegionDecoder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Move buildTileIndex to onPreDraw Created 5 years, 3 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
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"
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 "SubsetSingleBench.h" 23 #include "SubsetSingleBench.h"
24 #include "SubsetTranslateBench.h" 24 #include "SubsetTranslateBench.h"
25 #include "SubsetZoomBench.h" 25 #include "SubsetZoomBench.h"
26 #include "Stats.h" 26 #include "Stats.h"
27 #include "Timer.h" 27 #include "Timer.h"
28 28
29 #include "SkBitmapRegionDecoderInterface.h"
29 #include "SkBBoxHierarchy.h" 30 #include "SkBBoxHierarchy.h"
30 #include "SkCanvas.h" 31 #include "SkCanvas.h"
31 #include "SkCodec.h" 32 #include "SkCodec.h"
33 #include "SkCodecBenchPriv.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"
39 #include "SkScanlineDecoder.h" 41 #include "SkScanlineDecoder.h"
40 #include "SkString.h" 42 #include "SkString.h"
41 #include "SkSurface.h" 43 #include "SkSurface.h"
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 // unused otherwise. 520 // unused otherwise.
519 SkPMColor colors[256]; 521 SkPMColor colors[256];
520 int colorCount; 522 int colorCount;
521 const SkImageInfo info = codec->getInfo().makeColorType(colorType); 523 const SkImageInfo info = codec->getInfo().makeColorType(colorType);
522 SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes()]); 524 SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes()]);
523 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(SkScanlineDecoder::NewF romData(encoded)); 525 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder(SkScanlineDecoder::NewF romData(encoded));
524 if (nullptr == scanlineDecoder || scanlineDecoder->start(info, nullptr, 526 if (nullptr == scanlineDecoder || scanlineDecoder->start(info, nullptr,
525 colors, &colorCount) != SkCodec::kSuccess) 527 colors, &colorCount) != SkCodec::kSuccess)
526 { 528 {
527 SkDebugf("Could not create scanline decoder for %s with color type % s. " 529 SkDebugf("Could not create scanline decoder for %s with color type % s. "
528 "Skipping bench.\n", path.c_str(), get_color_name(colorType) ); 530 "Skipping bench.\n", path.c_str(), color_type_to_str(colorTy pe));
529 return false; 531 return false;
530 } 532 }
531 *width = info.width(); 533 *width = info.width();
532 *height = info.height(); 534 *height = info.height();
533 } else { 535 } else {
534 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream)); 536 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream));
535 if (nullptr == decoder) { 537 if (nullptr == decoder) {
536 SkDebugf("Could not create decoder for %s. Skipping bench.\n", path .c_str()); 538 SkDebugf("Could not create decoder for %s. Skipping bench.\n", path .c_str());
537 return false; 539 return false;
538 } 540 }
539 //FIXME: See skbug.com/3921 541 //FIXME: See skbug.com/3921
540 if (kIndex_8_SkColorType == colorType || kGray_8_SkColorType == colorTyp e) { 542 if (kIndex_8_SkColorType == colorType || kGray_8_SkColorType == colorTyp e) {
541 SkDebugf("Cannot use image subset decoder for %s with color type %s. " 543 SkDebugf("Cannot use image subset decoder for %s with color type %s. "
542 "Skipping bench.\n", path.c_str(), get_color_name(colorType) ); 544 "Skipping bench.\n", path.c_str(), color_type_to_str(colorTy pe));
543 return false; 545 return false;
544 } 546 }
545 if (!decoder->buildTileIndex(stream.detach(), width, height)) { 547 if (!decoder->buildTileIndex(stream.detach(), width, height)) {
546 SkDebugf("Could not build tile index for %s. Skipping bench.\n", pa th.c_str()); 548 SkDebugf("Could not build tile index for %s. Skipping bench.\n", pa th.c_str());
547 return false; 549 return false;
548 } 550 }
549 } 551 }
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
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
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(
934 SkOSPath::Basename(path.c_str()).c_str(), en coded.get(),
935 strategy, colorType, sampleSize, subset);
936 } else {
937 break;
938 }
939 }
940 fCurrentBRDSampleSize = 0;
941 fCurrentColorType++;
942 }
943 fCurrentColorType = 0;
944 fCurrentBRDStrategy++;
945 }
946 fCurrentBRDStrategy = 0;
947 fCurrentBRDImage++;
948 }
949
879 return nullptr; 950 return nullptr;
880 } 951 }
881 952
882 void fillCurrentOptions(ResultsWriter* log) const { 953 void fillCurrentOptions(ResultsWriter* log) const {
883 log->configOption("source_type", fSourceType); 954 log->configOption("source_type", fSourceType);
884 log->configOption("bench_type", fBenchType); 955 log->configOption("bench_type", fBenchType);
885 if (0 == strcmp(fSourceType, "skp")) { 956 if (0 == strcmp(fSourceType, "skp")) {
886 log->configOption("clip", 957 log->configOption("clip",
887 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, 958 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop,
888 fClip.fRight, fClip.fBottom).c _str()); 959 fClip.fRight, fClip.fBottom).c _str());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 996
926 const char* fSourceType; // What we're benching: bench, GM, SKP, ... 997 const char* fSourceType; // What we're benching: bench, GM, SKP, ...
927 const char* fBenchType; // How we bench it: micro, recording, playback, .. . 998 const char* fBenchType; // How we bench it: micro, recording, playback, .. .
928 int fCurrentRecording; 999 int fCurrentRecording;
929 int fCurrentScale; 1000 int fCurrentScale;
930 int fCurrentSKP; 1001 int fCurrentSKP;
931 int fCurrentUseMPD; 1002 int fCurrentUseMPD;
932 int fCurrentCodec; 1003 int fCurrentCodec;
933 int fCurrentImage; 1004 int fCurrentImage;
934 int fCurrentSubsetImage; 1005 int fCurrentSubsetImage;
1006 int fCurrentBRDImage;
935 int fCurrentColorType; 1007 int fCurrentColorType;
936 int fCurrentSubsetType; 1008 int fCurrentSubsetType;
937 int fUseCodec; 1009 int fUseCodec;
1010 int fCurrentBRDStrategy;
1011 int fCurrentBRDSampleSize;
938 int fCurrentAnimSKP; 1012 int fCurrentAnimSKP;
939 }; 1013 };
940 1014
941 int nanobench_main(); 1015 int nanobench_main();
942 int nanobench_main() { 1016 int nanobench_main() {
943 SetupCrashHandler(); 1017 SetupCrashHandler();
944 SkAutoGraphics ag; 1018 SkAutoGraphics ag;
945 SkTaskGroup::Enabler enabled(FLAGS_threads); 1019 SkTaskGroup::Enabler enabled(FLAGS_threads);
946 1020
947 #if SK_SUPPORT_GPU 1021 #if SK_SUPPORT_GPU
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 1235
1162 return 0; 1236 return 0;
1163 } 1237 }
1164 1238
1165 #if !defined SK_BUILD_FOR_IOS 1239 #if !defined SK_BUILD_FOR_IOS
1166 int main(int argc, char** argv) { 1240 int main(int argc, char** argv) {
1167 SkCommandLineFlags::Parse(argc, argv); 1241 SkCommandLineFlags::Parse(argc, argv);
1168 return nanobench_main(); 1242 return nanobench_main();
1169 } 1243 }
1170 #endif 1244 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698