OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "CodecBenchPriv.h" | 8 #include "CodecBenchPriv.h" |
9 #include "SubsetTranslateBench.h" | 9 #include "SubsetTranslateBench.h" |
10 #include "SubsetBenchPriv.h" | 10 #include "SubsetBenchPriv.h" |
11 #include "SkData.h" | 11 #include "SkData.h" |
12 #include "SkCodec.h" | 12 #include "SkCodec.h" |
13 #include "SkImageDecoder.h" | 13 #include "SkImageDecoder.h" |
14 #include "SkOSFile.h" | 14 #include "SkOSFile.h" |
15 #include "SkScanlineDecoder.h" | |
16 #include "SkStream.h" | 15 #include "SkStream.h" |
17 | 16 |
18 /* | 17 /* |
19 * | 18 * |
20 * This benchmark is designed to test the performance of subset decoding. | 19 * This benchmark is designed to test the performance of subset decoding. |
21 * It uses input dimensions to decode the entire image where each block is susbe
tW x subsetH. | 20 * It uses input dimensions to decode the entire image where each block is susbe
tW x subsetH. |
22 * | 21 * |
23 */ | 22 */ |
24 | 23 |
25 SubsetTranslateBench::SubsetTranslateBench(const SkString& path, | 24 SubsetTranslateBench::SubsetTranslateBench(const SkString& path, |
(...skipping 28 matching lines...) Expand all Loading... |
54 return kNonRendering_Backend == backend; | 53 return kNonRendering_Backend == backend; |
55 } | 54 } |
56 | 55 |
57 void SubsetTranslateBench::onDraw(const int n, SkCanvas* canvas) { | 56 void SubsetTranslateBench::onDraw(const int n, SkCanvas* canvas) { |
58 // When the color type is kIndex8, we will need to store the color table. I
f it is | 57 // When the color type is kIndex8, we will need to store the color table. I
f it is |
59 // used, it will be initialized by the codec. | 58 // used, it will be initialized by the codec. |
60 int colorCount; | 59 int colorCount; |
61 SkPMColor colors[256]; | 60 SkPMColor colors[256]; |
62 if (fUseCodec) { | 61 if (fUseCodec) { |
63 for (int count = 0; count < n; count++) { | 62 for (int count = 0; count < n; count++) { |
64 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder( | 63 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica
te())); |
65 SkScanlineDecoder::NewFromStream(fStream->duplicate())); | 64 const SkImageInfo info = codec->getInfo().makeColorType(fColorType); |
66 const SkImageInfo info = scanlineDecoder->getInfo().makeColorType(fC
olorType); | |
67 SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes()]); | 65 SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes()]); |
68 scanlineDecoder->start(info, nullptr, colors, &colorCount); | 66 codec->startScanlineDecode(info, nullptr, colors, &colorCount); |
69 | 67 |
70 SkBitmap bitmap; | 68 SkBitmap bitmap; |
71 // Note that we use the same bitmap for all of the subsets. | 69 // Note that we use the same bitmap for all of the subsets. |
72 // It might be larger than necessary for the end subsets. | 70 // It might be larger than necessary for the end subsets. |
73 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); | 71 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); |
74 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); | 72 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); |
75 | 73 |
76 for (int x = 0; x < info.width(); x += fSubsetWidth) { | 74 for (int x = 0; x < info.width(); x += fSubsetWidth) { |
77 for (int y = 0; y < info.height(); y += fSubsetHeight) { | 75 for (int y = 0; y < info.height(); y += fSubsetHeight) { |
78 scanlineDecoder->skipScanlines(y); | 76 codec->skipScanlines(y); |
79 const uint32_t currSubsetWidth = | 77 const uint32_t currSubsetWidth = |
80 x + (int) fSubsetWidth > info.width() ? | 78 x + (int) fSubsetWidth > info.width() ? |
81 info.width() - x : fSubsetWidth; | 79 info.width() - x : fSubsetWidth; |
82 const uint32_t currSubsetHeight = | 80 const uint32_t currSubsetHeight = |
83 y + (int) fSubsetHeight > info.height() ? | 81 y + (int) fSubsetHeight > info.height() ? |
84 info.height() - y : fSubsetHeight; | 82 info.height() - y : fSubsetHeight; |
85 const uint32_t bpp = info.bytesPerPixel(); | 83 const uint32_t bpp = info.bytesPerPixel(); |
86 for (uint32_t y = 0; y < currSubsetHeight; y++) { | 84 for (uint32_t y = 0; y < currSubsetHeight; y++) { |
87 scanlineDecoder->getScanlines(row.get(), 1, 0); | 85 codec->getScanlines(row.get(), 1, 0); |
88 memcpy(bitmap.getAddr(0, y), row.get() + x * bpp, | 86 memcpy(bitmap.getAddr(0, y), row.get() + x * bpp, |
89 currSubsetWidth * bpp); | 87 currSubsetWidth * bpp); |
90 } | 88 } |
91 } | 89 } |
92 } | 90 } |
93 } | 91 } |
94 } else { | 92 } else { |
95 // We create a color table here to satisfy allocPixels() when the output | 93 // We create a color table here to satisfy allocPixels() when the output |
96 // type is kIndex8. It's okay that this is uninitialized since we never | 94 // type is kIndex8. It's okay that this is uninitialized since we never |
97 // use it. | 95 // use it. |
(...skipping 20 matching lines...) Expand all Loading... |
118 const uint32_t currSubsetHeight = y + (int) fSubsetHeight >
height ? | 116 const uint32_t currSubsetHeight = y + (int) fSubsetHeight >
height ? |
119 height - y : fSubsetHeight; | 117 height - y : fSubsetHeight; |
120 SkIRect rect = SkIRect::MakeXYWH(x, y, currSubsetWidth, | 118 SkIRect rect = SkIRect::MakeXYWH(x, y, currSubsetWidth, |
121 currSubsetHeight); | 119 currSubsetHeight); |
122 decoder->decodeSubset(&bitmap, rect, fColorType); | 120 decoder->decodeSubset(&bitmap, rect, fColorType); |
123 } | 121 } |
124 } | 122 } |
125 } | 123 } |
126 } | 124 } |
127 } | 125 } |
OLD | NEW |