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" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 | 55 |
56 void SubsetTranslateBench::onDraw(int n, SkCanvas* canvas) { | 56 void SubsetTranslateBench::onDraw(int n, SkCanvas* canvas) { |
57 // 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 |
58 // used, it will be initialized by the codec. | 58 // used, it will be initialized by the codec. |
59 int colorCount; | 59 int colorCount; |
60 SkPMColor colors[256]; | 60 SkPMColor colors[256]; |
61 if (fUseCodec) { | 61 if (fUseCodec) { |
62 for (int count = 0; count < n; count++) { | 62 for (int count = 0; count < n; count++) { |
63 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica te())); | 63 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica te())); |
64 const SkImageInfo info = codec->getInfo().makeColorType(fColorType); | 64 const SkImageInfo info = codec->getInfo().makeColorType(fColorType); |
65 SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes()]); | 65 SkAutoTDeleteArray<uint8_t> row(nullptr); |
66 codec->startScanlineDecode(info, nullptr, colors, &colorCount); | 66 if (codec->getScanlineOrder() == SkCodec::kTopDown_SkScanlineOrder) { |
67 row.reset(new uint8_t[info.minRowBytes()]); | |
68 } | |
67 | 69 |
68 SkBitmap bitmap; | 70 SkBitmap bitmap; |
69 // Note that we use the same bitmap for all of the subsets. | 71 // Note that we use the same bitmap for all of the subsets. |
70 // It might be larger than necessary for the end subsets. | 72 // It might be larger than necessary for the end subsets. |
71 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); | 73 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); |
72 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); | 74 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); |
scroggo
2015/10/08 18:29:08
The bots caught me - "colorCount" is now unitializ
| |
73 | 75 |
76 const uint32_t bpp = info.bytesPerPixel(); | |
77 | |
74 for (int x = 0; x < info.width(); x += fSubsetWidth) { | 78 for (int x = 0; x < info.width(); x += fSubsetWidth) { |
75 for (int y = 0; y < info.height(); y += fSubsetHeight) { | 79 for (int y = 0; y < info.height(); y += fSubsetHeight) { |
76 codec->skipScanlines(y); | 80 SkDEBUGCODE(SkCodec::Result result =) |
81 codec->startScanlineDecode(info, nullptr, colors, &colorCoun t); | |
82 SkASSERT(SkCodec::kSuccess == result); | |
83 | |
84 SkDEBUGCODE(result =) codec->skipScanlines(y); | |
85 SkASSERT(SkCodec::kSuccess == result); | |
86 | |
77 const uint32_t currSubsetWidth = | 87 const uint32_t currSubsetWidth = |
78 x + (int) fSubsetWidth > info.width() ? | 88 x + (int) fSubsetWidth > info.width() ? |
79 info.width() - x : fSubsetWidth; | 89 info.width() - x : fSubsetWidth; |
80 const uint32_t currSubsetHeight = | 90 const uint32_t currSubsetHeight = |
81 y + (int) fSubsetHeight > info.height() ? | 91 y + (int) fSubsetHeight > info.height() ? |
82 info.height() - y : fSubsetHeight; | 92 info.height() - y : fSubsetHeight; |
83 const uint32_t bpp = info.bytesPerPixel(); | 93 |
84 for (uint32_t y = 0; y < currSubsetHeight; y++) { | 94 switch (codec->getScanlineOrder()) { |
85 codec->getScanlines(row.get(), 1, 0); | 95 case SkCodec::kTopDown_SkScanlineOrder: |
86 memcpy(bitmap.getAddr(0, y), row.get() + x * bpp, | 96 for (uint32_t y = 0; y < currSubsetHeight; y++) { |
87 currSubsetWidth * bpp); | 97 SkDEBUGCODE(result =) codec->getScanlines(row.ge t(), 1, 0); |
98 SkASSERT(SkCodec::kSuccess == result); | |
99 | |
100 memcpy(bitmap.getAddr(0, y), row.get() + x * bpp , | |
101 currSubsetWidth * bpp); | |
102 } | |
103 break; | |
104 case SkCodec::kNone_SkScanlineOrder: { | |
105 // decode all scanlines that intersect the subset, a nd copy the subset | |
106 // into the output. | |
107 SkImageInfo stripeInfo = info.makeWH(info.width(), c urrSubsetHeight); | |
108 SkBitmap stripeBm; | |
109 alloc_pixels(&stripeBm, stripeInfo, colors, colorCou nt); | |
110 | |
111 SkDEBUGCODE(result =) codec->getScanlines(stripeBm.g etPixels(), | |
112 currSubsetHeight, stripeBm.rowBytes()); | |
113 SkASSERT(SkCodec::kSuccess == result); | |
114 | |
115 for (uint32_t subsetY = 0; subsetY < currSubsetHeigh t; subsetY++) { | |
116 memcpy(bitmap.getAddr(0, subsetY), stripeBm.getA ddr(x, subsetY), | |
117 currSubsetWidth * bpp); | |
118 } | |
119 break; | |
120 } | |
121 default: | |
122 // We currently are only testing kTopDown and kNone, which are the only | |
123 // two used by the subsets we care about. skbug.com/ 4428 | |
124 SkASSERT(false); | |
88 } | 125 } |
89 } | 126 } |
90 } | 127 } |
91 } | 128 } |
92 } else { | 129 } else { |
93 // We create a color table here to satisfy allocPixels() when the output | 130 // We create a color table here to satisfy allocPixels() when the output |
94 // type is kIndex8. It's okay that this is uninitialized since we never | 131 // type is kIndex8. It's okay that this is uninitialized since we never |
95 // use it. | 132 // use it. |
96 SkColorTable* colorTable = new SkColorTable(colors, 0); | 133 SkColorTable* colorTable = new SkColorTable(colors, 0); |
97 for (int count = 0; count < n; count++) { | 134 for (int count = 0; count < n; count++) { |
98 int width, height; | 135 int width, height; |
99 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea m)); | 136 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea m)); |
100 decoder->buildTileIndex(fStream->duplicate(), &width, &height); | 137 SkAssertResult(decoder->buildTileIndex(fStream->duplicate(), &width, &height)); |
101 SkBitmap bitmap; | 138 SkBitmap bitmap; |
102 // Note that we use the same bitmap for all of the subsets. | 139 // Note that we use the same bitmap for all of the subsets. |
103 // It might be larger than necessary for the end subsets. | 140 // It might be larger than necessary for the end subsets. |
104 // If we do not include this step, decodeSubset() would allocate spa ce | 141 // If we do not include this step, decodeSubset() would allocate spa ce |
105 // for the pixels automatically, but this would not allow us to reus e the | 142 // for the pixels automatically, but this would not allow us to reus e the |
106 // same bitmap as the other subsets. We want to reuse the same bitm ap | 143 // same bitmap as the other subsets. We want to reuse the same bitm ap |
107 // because it gives a more fair comparison with SkCodec and is a com mon | 144 // because it gives a more fair comparison with SkCodec and is a com mon |
108 // use case of BitmapRegionDecoder. | 145 // use case of BitmapRegionDecoder. |
109 bitmap.allocPixels(SkImageInfo::Make(fSubsetWidth, fSubsetHeight, | 146 bitmap.allocPixels(SkImageInfo::Make(fSubsetWidth, fSubsetHeight, |
110 fColorType, kOpaque_SkAlphaType), nullptr, colorTable); | 147 fColorType, kOpaque_SkAlphaType), nullptr, colorTable); |
111 | 148 |
112 for (int x = 0; x < width; x += fSubsetWidth) { | 149 for (int x = 0; x < width; x += fSubsetWidth) { |
113 for (int y = 0; y < height; y += fSubsetHeight) { | 150 for (int y = 0; y < height; y += fSubsetHeight) { |
114 const uint32_t currSubsetWidth = x + (int) fSubsetWidth > wi dth ? | 151 const uint32_t currSubsetWidth = x + (int) fSubsetWidth > wi dth ? |
115 width - x : fSubsetWidth; | 152 width - x : fSubsetWidth; |
116 const uint32_t currSubsetHeight = y + (int) fSubsetHeight > height ? | 153 const uint32_t currSubsetHeight = y + (int) fSubsetHeight > height ? |
117 height - y : fSubsetHeight; | 154 height - y : fSubsetHeight; |
118 SkIRect rect = SkIRect::MakeXYWH(x, y, currSubsetWidth, | 155 SkIRect rect = SkIRect::MakeXYWH(x, y, currSubsetWidth, |
119 currSubsetHeight); | 156 currSubsetHeight); |
120 decoder->decodeSubset(&bitmap, rect, fColorType); | 157 SkAssertResult(decoder->decodeSubset(&bitmap, rect, fColorTy pe)); |
121 } | 158 } |
122 } | 159 } |
123 } | 160 } |
124 } | 161 } |
125 } | 162 } |
OLD | NEW |