OLD | NEW |
---|---|
(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 "SubsetTranslateBench.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 input dimensions to decode the entire image where each block is susbe tW x subsetH. | |
20 * | |
21 */ | |
22 | |
23 SubsetTranslateBench::SubsetTranslateBench(const SkString& path, | |
24 SkColorType colorType, | |
25 uint32_t subsetWidth, | |
26 uint32_t subsetHeight, | |
27 bool useCodec) | |
28 : fColorType(colorType) | |
29 , fSubsetWidth(subsetWidth) | |
30 , fSubsetHeight(subsetHeight) | |
31 , fUseCodec(useCodec) | |
32 { | |
33 // Parse the filename | |
34 SkString baseName = SkOSPath::Basename(path.c_str()); | |
35 | |
36 // Choose an informative color name | |
37 const char* colorName = get_color_name(fColorType); | |
38 | |
39 fName.printf("%sSubsetTranslate_%dx%d_%s_%s", fUseCodec ? "Codec" : "Image", fSubsetWidth, | |
40 fSubsetHeight, baseName.c_str(), colorName); | |
41 | |
42 // Perform the decode setup | |
43 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); | |
44 fStream.reset(new SkMemoryStream(encoded)); | |
45 } | |
46 | |
47 const char* SubsetTranslateBench::onGetName() { | |
48 return fName.c_str(); | |
49 } | |
50 | |
51 bool SubsetTranslateBench::isSuitableFor(Backend backend) { | |
52 return kNonRendering_Backend == backend; | |
53 } | |
54 | |
55 void SubsetTranslateBench::onDraw(const int n, SkCanvas* canvas) { | |
56 if (fUseCodec) { | |
57 for (int count = 0; count < n; count++) { | |
58 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica te())); | |
59 const SkImageInfo info = codec->getInfo(); | |
60 SkAutoTDeleteArray<uint8_t> row(SkNEW_ARRAY(uint8_t, info.minRowByte s())); | |
61 SkScanlineDecoder* scanlineDecoder = | |
62 codec->getScanlineDecoder(info.makeColorType(fColorType)); | |
63 | |
64 SkBitmap bitmap; | |
65 // Note that we use the same bitmap for all of the subsets. | |
66 // It might be larger than necessary for the end subsets. | |
67 bitmap.allocPixels(info.makeWH(fSubsetWidth, fSubsetHeight)); | |
68 | |
69 for (int x = 0; x < info.width(); x += fSubsetWidth) { | |
70 for (int y = 0; y < info.height(); y += fSubsetHeight) { | |
71 scanlineDecoder->skipScanlines(y); | |
72 const uint32_t currSubsetWidth = | |
73 x + (int) fSubsetWidth > info.width() ? | |
74 info.width() - x : fSubsetWidth; | |
75 const uint32_t currSubsetHeight = | |
76 y + (int) fSubsetHeight > info.height() ? | |
77 info.height() - y : fSubsetHeight; | |
78 const uint32_t bpp = info.bytesPerPixel(); | |
79 for (uint32_t y = 0; y < currSubsetHeight; y++) { | |
80 scanlineDecoder->getScanlines(row.get(), 1, 0); | |
81 memcpy(bitmap.getAddr(0, y), row.get() + x * bpp, | |
82 currSubsetWidth * bpp); | |
83 } | |
84 } | |
85 } | |
86 } | |
87 } else { | |
88 SkPMColor colors[256]; | |
89 SkColorTable* colorTable = SkNEW_ARGS(SkColorTable, (colors, 0)); | |
scroggo
2015/06/04 13:50:04
Similar comment explaining why we're using uniniti
msarett
2015/06/08 16:28:33
Done.
| |
90 for (int count = 0; count < n; count++) { | |
91 int width, height; | |
92 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea m)); | |
93 decoder->buildTileIndex(fStream->duplicate(), &width, &height); | |
94 SkBitmap bitmap; | |
95 // Note that we use the same bitmap for all of the subsets. | |
96 // It might be larger than necessary for the end subsets. | |
97 // If we do not include this step, decodeSubset() would allocate spa ce | |
98 // for the pixels automatically, but this would not allow us to reus e the | |
99 // same bitmap as the other subsets. We want to reuse the same bitm ap | |
100 // because it gives a more fair comparison with SkCodec and is a com mon | |
101 // use case of BitmapRegionDecoder. | |
102 bitmap.allocPixels(SkImageInfo::Make(fSubsetWidth, fSubsetHeight, | |
103 fColorType, kOpaque_SkAlphaType), NULL, colorTable); | |
104 | |
105 for (int x = 0; x < width; x += fSubsetWidth) { | |
106 for (int y = 0; y < height; y += fSubsetHeight) { | |
107 const uint32_t currSubsetWidth = x + (int) fSubsetWidth > wi dth ? | |
108 width - x : fSubsetWidth; | |
109 const uint32_t currSubsetHeight = y + (int) fSubsetHeight > height ? | |
110 height - y : fSubsetHeight; | |
111 SkIRect rect = SkIRect::MakeXYWH(x, y, currSubsetWidth, | |
112 currSubsetHeight); | |
113 decoder->decodeSubset(&bitmap, rect, fColorType); | |
114 } | |
115 } | |
116 } | |
117 } | |
118 } | |
OLD | NEW |