Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2015 The Android Open Source Project | |
| 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 #ifndef SubsetBenchPriv_DEFINED | |
| 9 #define SubsetBenchPriv_DEFINED | |
| 10 | |
| 11 #include "SkCodec.h" | |
| 12 #include "SkImageGenerator.h" | |
| 13 | |
| 14 /* | |
| 15 * Returns true if a subset decode succeeds, false otherwise | |
| 16 */ | |
| 17 static bool valid_subset_bench(SkMemoryStream* stream, SkColorType colorType, bo ol useCodec) { | |
|
scroggo
2015/06/01 17:25:14
Does this need to be an SkMemoryStream? In general
msarett
2015/06/01 20:37:01
Yes, I think this makes a lot more sense.
| |
| 18 if (useCodec) { | |
| 19 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream->duplicate()) ); | |
|
scroggo
2015/06/01 17:25:14
Not sure whether we need to duplicate the stream h
msarett
2015/06/01 20:37:01
Acknowledged.
| |
| 20 if (NULL == codec) { | |
| 21 return false; | |
|
scroggo
2015/06/01 17:25:14
Can you add a debug statement? This seems like a b
msarett
2015/06/01 20:37:01
I agree! Adding informative error messages throug
| |
| 22 } | |
| 23 | |
| 24 const SkImageInfo info = codec->getInfo(); | |
| 25 SkAutoTDeleteArray<uint8_t> row(SkNEW_ARRAY(uint8_t, info.minRowBytes()) ); | |
| 26 SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder(info); | |
| 27 if (NULL == scanlineDecoder) { | |
| 28 return false; | |
|
scroggo
2015/06/01 17:25:14
Maybe add a debug statement here, as well?
msarett
2015/06/01 20:37:01
Done.
| |
| 29 } | |
| 30 | |
| 31 const uint32_t subsetWidth = info.width() / 2; | |
|
scroggo
2015/06/01 17:25:14
It seems somewhat weird that we decode an arbitrar
msarett
2015/06/01 20:37:01
Yeah I thought this was awkward too. I didn't wan
| |
| 32 const uint32_t subsetHeight = info.height() / 2; | |
| 33 SkBitmap bitmap; | |
| 34 if (!bitmap.tryAllocPixels(info.makeWH(subsetWidth, subsetHeight))) { | |
| 35 SkDebugf("Could not allocate memory. Aborting bench.\n"); | |
|
scroggo
2015/06/01 17:25:14
Skipping*
msarett
2015/06/01 20:37:01
Acknowledged.
| |
| 36 return false; | |
| 37 } | |
| 38 | |
| 39 if (SkImageGenerator::kSuccess != scanlineDecoder->skipScanlines(subsetH eight)) { | |
|
scroggo
2015/06/01 17:25:14
We probably want a debug statement here, too. Alth
msarett
2015/06/01 20:37:01
Acknowledged.
| |
| 40 return false; | |
| 41 } | |
| 42 uint32_t bpp = info.bytesPerPixel(); | |
| 43 for (uint32_t y = 0; y < subsetHeight; y++) { | |
| 44 if (SkImageGenerator::kSuccess != scanlineDecoder->getScanlines(row. get(), 1, 0)) { | |
| 45 return false; | |
| 46 } | |
| 47 memcpy(bitmap.getAddr(0, y), row.get(), subsetWidth * bpp); | |
|
scroggo
2015/06/01 17:25:14
This seems unnecessary. We're trying to make sure
msarett
2015/06/01 20:37:01
Acknowledged.
| |
| 48 } | |
| 49 } else { | |
| 50 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream)); | |
| 51 if (NULL == decoder) { | |
| 52 return false; | |
| 53 } | |
| 54 int width, height; | |
| 55 if (!decoder->buildTileIndex(stream->duplicate(), &width, &height)) { | |
|
scroggo
2015/06/01 17:25:14
If width and height are not 1, isn't this a bug fo
msarett
2015/06/01 20:37:02
Acknowledged.
| |
| 56 return false; | |
| 57 } | |
| 58 const uint32_t subsetWidth = width / 2; | |
| 59 const uint32_t subsetHeight = height / 2; | |
| 60 SkBitmap bitmap; | |
| 61 SkIRect rect = SkIRect::MakeXYWH(subsetWidth, subsetHeight, subsetWidth, | |
| 62 subsetHeight); | |
| 63 if (!decoder->decodeSubset(&bitmap, rect, colorType)) { | |
| 64 return false; | |
| 65 } | |
| 66 } | |
| 67 return true; | |
| 68 } | |
| 69 | |
| 70 #endif // SubsetBenchPriv_DEFINED | |
| OLD | NEW |