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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 } | 46 } |
47 | 47 |
48 const char* SubsetTranslateBench::onGetName() { | 48 const char* SubsetTranslateBench::onGetName() { |
49 return fName.c_str(); | 49 return fName.c_str(); |
50 } | 50 } |
51 | 51 |
52 bool SubsetTranslateBench::isSuitableFor(Backend backend) { | 52 bool SubsetTranslateBench::isSuitableFor(Backend backend) { |
53 return kNonRendering_Backend == backend; | 53 return kNonRendering_Backend == backend; |
54 } | 54 } |
55 | 55 |
56 // Allows allocating the bitmap first, and then writing to them later (in startS canlineDecode) | |
57 static SkPMColor* get_colors(SkBitmap* bm) { | |
58 SkColorTable* ct = bm->getColorTable(); | |
59 if (!ct) { | |
60 return nullptr; | |
61 } | |
62 | |
63 return const_cast<SkPMColor*>(ct->readColors()); | |
64 } | |
65 | |
56 void SubsetTranslateBench::onDraw(int n, SkCanvas* canvas) { | 66 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 | 67 // 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. | 68 // used, it will be initialized by the codec. |
59 int colorCount; | 69 int colorCount = 256; |
scroggo
2015/10/08 18:29:08
I'm cheating a little bit here. Setting this value
msarett
2015/10/08 18:52:41
Yes I think it is almost always 256. Rare bmps ma
| |
60 SkPMColor colors[256]; | 70 SkPMColor colors[256]; |
61 if (fUseCodec) { | 71 if (fUseCodec) { |
62 for (int count = 0; count < n; count++) { | 72 for (int count = 0; count < n; count++) { |
63 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica te())); | 73 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica te())); |
64 const SkImageInfo info = codec->getInfo().makeColorType(fColorType); | 74 const SkImageInfo info = codec->getInfo().makeColorType(fColorType); |
65 SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes()]); | 75 SkAutoTDeleteArray<uint8_t> row(nullptr); |
66 codec->startScanlineDecode(info, nullptr, colors, &colorCount); | 76 if (codec->getScanlineOrder() == SkCodec::kTopDown_SkScanlineOrder) { |
77 row.reset(new uint8_t[info.minRowBytes()]); | |
78 } | |
67 | 79 |
68 SkBitmap bitmap; | 80 SkBitmap bitmap; |
69 // Note that we use the same bitmap for all of the subsets. | 81 // Note that we use the same bitmap for all of the subsets. |
70 // It might be larger than necessary for the end subsets. | 82 // It might be larger than necessary for the end subsets. |
71 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); | 83 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); |
72 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); | 84 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); |
73 | 85 |
86 const uint32_t bpp = info.bytesPerPixel(); | |
87 | |
74 for (int x = 0; x < info.width(); x += fSubsetWidth) { | 88 for (int x = 0; x < info.width(); x += fSubsetWidth) { |
75 for (int y = 0; y < info.height(); y += fSubsetHeight) { | 89 for (int y = 0; y < info.height(); y += fSubsetHeight) { |
76 codec->skipScanlines(y); | 90 SkDEBUGCODE(SkCodec::Result result =) |
91 codec->startScanlineDecode(info, nullptr, get_colors(&bitmap ), &colorCount); | |
scroggo
2015/10/08 18:29:08
Note that I'm using the colors from the bitmap's c
msarett
2015/10/08 18:52:41
Acknowledged.
| |
92 SkASSERT(SkCodec::kSuccess == result); | |
93 | |
94 SkDEBUGCODE(result =) codec->skipScanlines(y); | |
95 SkASSERT(SkCodec::kSuccess == result); | |
96 | |
77 const uint32_t currSubsetWidth = | 97 const uint32_t currSubsetWidth = |
78 x + (int) fSubsetWidth > info.width() ? | 98 x + (int) fSubsetWidth > info.width() ? |
79 info.width() - x : fSubsetWidth; | 99 info.width() - x : fSubsetWidth; |
80 const uint32_t currSubsetHeight = | 100 const uint32_t currSubsetHeight = |
81 y + (int) fSubsetHeight > info.height() ? | 101 y + (int) fSubsetHeight > info.height() ? |
82 info.height() - y : fSubsetHeight; | 102 info.height() - y : fSubsetHeight; |
83 const uint32_t bpp = info.bytesPerPixel(); | 103 |
84 for (uint32_t y = 0; y < currSubsetHeight; y++) { | 104 switch (codec->getScanlineOrder()) { |
85 codec->getScanlines(row.get(), 1, 0); | 105 case SkCodec::kTopDown_SkScanlineOrder: |
86 memcpy(bitmap.getAddr(0, y), row.get() + x * bpp, | 106 for (uint32_t y = 0; y < currSubsetHeight; y++) { |
87 currSubsetWidth * bpp); | 107 SkDEBUGCODE(result =) codec->getScanlines(row.ge t(), 1, 0); |
108 SkASSERT(SkCodec::kSuccess == result); | |
109 | |
110 memcpy(bitmap.getAddr(0, y), row.get() + x * bpp , | |
111 currSubsetWidth * bpp); | |
112 } | |
113 break; | |
114 case SkCodec::kNone_SkScanlineOrder: { | |
115 // decode all scanlines that intersect the subset, a nd copy the subset | |
116 // into the output. | |
117 SkImageInfo stripeInfo = info.makeWH(info.width(), c urrSubsetHeight); | |
118 SkBitmap stripeBm; | |
119 alloc_pixels(&stripeBm, stripeInfo, colors, colorCou nt); | |
120 | |
121 SkDEBUGCODE(result =) codec->getScanlines(stripeBm.g etPixels(), | |
122 currSubsetHeight, stripeBm.rowBytes()); | |
123 SkASSERT(SkCodec::kSuccess == result); | |
124 | |
125 for (uint32_t subsetY = 0; subsetY < currSubsetHeigh t; subsetY++) { | |
126 memcpy(bitmap.getAddr(0, subsetY), stripeBm.getA ddr(x, subsetY), | |
127 currSubsetWidth * bpp); | |
128 } | |
129 break; | |
130 } | |
131 default: | |
132 // We currently are only testing kTopDown and kNone, which are the only | |
133 // two used by the subsets we care about. skbug.com/ 4428 | |
134 SkASSERT(false); | |
88 } | 135 } |
89 } | 136 } |
90 } | 137 } |
91 } | 138 } |
92 } else { | 139 } else { |
93 // We create a color table here to satisfy allocPixels() when the output | 140 // 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 | 141 // type is kIndex8. It's okay that this is uninitialized since we never |
95 // use it. | 142 // use it. |
96 SkColorTable* colorTable = new SkColorTable(colors, 0); | 143 SkColorTable* colorTable = new SkColorTable(colors, 0); |
97 for (int count = 0; count < n; count++) { | 144 for (int count = 0; count < n; count++) { |
98 int width, height; | 145 int width, height; |
99 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea m)); | 146 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea m)); |
100 decoder->buildTileIndex(fStream->duplicate(), &width, &height); | 147 SkAssertResult(decoder->buildTileIndex(fStream->duplicate(), &width, &height)); |
101 SkBitmap bitmap; | 148 SkBitmap bitmap; |
102 // Note that we use the same bitmap for all of the subsets. | 149 // Note that we use the same bitmap for all of the subsets. |
103 // It might be larger than necessary for the end subsets. | 150 // It might be larger than necessary for the end subsets. |
104 // If we do not include this step, decodeSubset() would allocate spa ce | 151 // 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 | 152 // 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 | 153 // 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 | 154 // because it gives a more fair comparison with SkCodec and is a com mon |
108 // use case of BitmapRegionDecoder. | 155 // use case of BitmapRegionDecoder. |
109 bitmap.allocPixels(SkImageInfo::Make(fSubsetWidth, fSubsetHeight, | 156 bitmap.allocPixels(SkImageInfo::Make(fSubsetWidth, fSubsetHeight, |
110 fColorType, kOpaque_SkAlphaType), nullptr, colorTable); | 157 fColorType, kOpaque_SkAlphaType), nullptr, colorTable); |
111 | 158 |
112 for (int x = 0; x < width; x += fSubsetWidth) { | 159 for (int x = 0; x < width; x += fSubsetWidth) { |
113 for (int y = 0; y < height; y += fSubsetHeight) { | 160 for (int y = 0; y < height; y += fSubsetHeight) { |
114 const uint32_t currSubsetWidth = x + (int) fSubsetWidth > wi dth ? | 161 const uint32_t currSubsetWidth = x + (int) fSubsetWidth > wi dth ? |
115 width - x : fSubsetWidth; | 162 width - x : fSubsetWidth; |
116 const uint32_t currSubsetHeight = y + (int) fSubsetHeight > height ? | 163 const uint32_t currSubsetHeight = y + (int) fSubsetHeight > height ? |
117 height - y : fSubsetHeight; | 164 height - y : fSubsetHeight; |
118 SkIRect rect = SkIRect::MakeXYWH(x, y, currSubsetWidth, | 165 SkIRect rect = SkIRect::MakeXYWH(x, y, currSubsetWidth, |
119 currSubsetHeight); | 166 currSubsetHeight); |
120 decoder->decodeSubset(&bitmap, rect, fColorType); | 167 SkAssertResult(decoder->decodeSubset(&bitmap, rect, fColorTy pe)); |
121 } | 168 } |
122 } | 169 } |
123 } | 170 } |
124 } | 171 } |
125 } | 172 } |
OLD | NEW |