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

Side by Side Diff: bench/SubsetDivisorBench.cpp

Issue 1160953002: Subset decoding benchmarks (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Separate subclass for each benchmark Created 5 years, 6 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
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SubsetDivisorBench.h"
9 #include "SubsetBenchPriv.h"
10 #include "SkData.h"
11 #include "SkCodec.h"
12 #include "SkImageDecoder.h"
13 #include "SkOSFile.h"
14 #include "SkStream.h"
15
16 /*
17 *
18 * This benchmark is designed to test the performance of subset decoding.
19 * It uses a divisor to decode the entire image in a grid of divisor x divisor b locks.
20 *
21 */
22
23 SubsetDivisorBench* SubsetDivisorBench::Create(SkString* path,
24 SkColorType colorType,
25 uint32_t divisor,
26 bool useCodec) {
27 // Check that the decode will succeed
28 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path->c_str()));
29 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded));
30 if (!valid_subset_bench(stream, colorType, useCodec)) {
31 return NULL;
32 }
33 return new SubsetDivisorBench(path, colorType, divisor, useCodec);
34 }
35
36 SubsetDivisorBench::SubsetDivisorBench(SkString* path,
37 SkColorType colorType,
38 uint32_t divisor,
39 bool useCodec)
40 : fColorType(colorType)
41 , fDivisor(divisor)
42 , fUseCodec(useCodec)
43 {
44 // Parse the filename
45 SkString baseName = SkOSPath::Basename(path->c_str());
46
47 // Choose an informative color name
48 const char* colorName;
49 switch(fColorType) {
50 case kN32_SkColorType:
51 colorName = "N32";
52 break;
53 case kRGB_565_SkColorType:
54 colorName = "565";
55 break;
56 case kGray_8_SkColorType:
57 colorName = "Gray8";
58 break;
59 case kIndex_8_SkColorType:
60 colorName = "Gray8";
scroggo 2015/06/01 17:25:14 Index8* This whole block should probably go insid
msarett 2015/06/01 20:37:02 Done.
61 break;
62 case kAlpha_8_SkColorType:
63 colorName = "Alpha8";
64 break;
65 default:
66 colorName = "Unknown";
67 }
68 fName.printf("%sSubsetDivisor_%dx%d_%s_%s", fUseCodec ? "Codec" : "Image", f Divisor, fDivisor,
69 baseName.c_str(), colorName);
70
71 // Perform the decode setup
72 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path->c_str()));
73 fStream.reset(new SkMemoryStream(encoded));
74 }
75
76 const char* SubsetDivisorBench::onGetName() {
77 return fName.c_str();
78 }
79
80 bool SubsetDivisorBench::isSuitableFor(Backend backend) {
81 return kNonRendering_Backend == backend;
82 }
83
84 void SubsetDivisorBench::onDraw(const int n, SkCanvas* canvas) {
85 if (fUseCodec) {
86 for (int count = 0; count < n; count++) {
87 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica te()));
88 const SkImageInfo info = codec->getInfo();
89 SkAutoTDeleteArray<uint8_t> row(SkNEW_ARRAY(uint8_t, info.minRowByte s()));
90 SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(info) ;
91
92 const uint32_t subsetWidth = info.width() / fDivisor;
93 const uint32_t subsetHeight = info.height() / fDivisor;
94 const uint32_t maxSubsetWidth = subsetWidth + info.width() % fDiviso r;
95 const uint32_t maxSubsetHeight = subsetHeight + info.height() % fDiv isor;
96 SkBitmap bitmap;
97 // Note that we use the same bitmap for all of the subsets.
98 // It might be slightly larger than necessary for some of the subset s.
99 if (!bitmap.tryAllocPixels(info.makeWH(maxSubsetWidth, maxSubsetHeig ht))) {
scroggo 2015/06/01 17:25:14 Inside the benches, maybe we should call bitmap.al
msarett 2015/06/01 20:37:02 Yes this makes sense. And it has the additional b
100 SkDebugf("Could not allocate memory. Aborting bench.\n");
101 return;
102 }
103
104 for (uint32_t blockX = 0; blockX < fDivisor; blockX++) {
105 for (uint32_t blockY = 0; blockY < fDivisor; blockY++) {
106 scanlineDecoder->skipScanlines(blockY * subsetHeight);
107 const uint32_t currSubsetWidth =
108 (blockX == fDivisor - 1) ? maxSubsetWidth : subsetWi dth;
109 const uint32_t currSubsetHeight =
110 (blockY == fDivisor - 1) ? maxSubsetHeight : subsetH eight;
111 const uint32_t bpp = info.bytesPerPixel();
112 for (uint32_t y = 0; y < currSubsetHeight; y++) {
113 scanlineDecoder->getScanlines(row.get(), 1, 0);
114 memcpy(bitmap.getAddr(0, y), row.get() + blockX * subset Width * bpp,
115 currSubsetWidth * bpp);
116 }
117 }
118 }
119 }
120 } else {
121 for (int count = 0; count < n; count++) {
122 int width, height;
123 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea m));
124 decoder->buildTileIndex(fStream->duplicate(), &width, &height);
125
126 const uint32_t subsetWidth = width / fDivisor;
127 const uint32_t subsetHeight = height / fDivisor;
128 const uint32_t maxSubsetWidth = subsetWidth + width % fDivisor;
129 const uint32_t maxSubsetHeight = subsetHeight + height % fDivisor;
130 SkBitmap bitmap;
131 // Note that we use the same bitmap for all of the subsets.
132 // It might be slightly larger than necessary for some of the subset s.
133 if (!bitmap.tryAllocPixels(SkImageInfo::Make(maxSubsetWidth, maxSubs etHeight,
134 fColorType, kOpaque_SkAlphaType))) {
135 SkDebugf("Could not allocate memory. Aborting bench.\n");
136 return;
137 }
138
139 for (uint32_t blockX = 0; blockX < fDivisor; blockX++) {
140 for (uint32_t blockY = 0; blockY < fDivisor; blockY++) {
141 const uint32_t currSubsetWidth =
142 (blockX == fDivisor - 1) ? maxSubsetWidth : subsetWi dth;
143 const uint32_t currSubsetHeight =
144 (blockY == fDivisor - 1) ? maxSubsetHeight : subsetH eight;
145 SkIRect rect = SkIRect::MakeXYWH(blockX * subsetWidth,
146 blockY * subsetHeight, currSubsetWidth, currSubsetHe ight);
147 decoder->decodeSubset(&bitmap, rect, fColorType);
148 }
149 }
150 }
151 }
152 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698