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 "SubsetSingleBench.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 an input width, height, left, and top to decode a single subset. |
| 20 * |
| 21 */ |
| 22 |
| 23 SubsetSingleBench::SubsetSingleBench(const SkString& path, |
| 24 SkColorType colorType, |
| 25 uint32_t subsetWidth, |
| 26 uint32_t subsetHeight, |
| 27 uint32_t offsetLeft, |
| 28 uint32_t offsetTop, |
| 29 bool useCodec) |
| 30 : fColorType(colorType) |
| 31 , fSubsetWidth(subsetWidth) |
| 32 , fSubsetHeight(subsetHeight) |
| 33 , fOffsetLeft(offsetLeft) |
| 34 , fOffsetTop(offsetTop) |
| 35 , fUseCodec(useCodec) |
| 36 { |
| 37 // Parse the filename |
| 38 SkString baseName = SkOSPath::Basename(path.c_str()); |
| 39 |
| 40 // Choose an informative color name |
| 41 const char* colorName = get_color_name(fColorType); |
| 42 |
| 43 fName.printf("%sSubsetSingle_%dx%d +%d_+%d_%s_%s", fUseCodec ? "Codec" : "Im
age", fSubsetWidth, |
| 44 fSubsetHeight, fOffsetLeft, fOffsetTop, baseName.c_str(), colorName)
; |
| 45 |
| 46 // Perform the decode setup |
| 47 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
| 48 fStream.reset(new SkMemoryStream(encoded)); |
| 49 } |
| 50 |
| 51 const char* SubsetSingleBench::onGetName() { |
| 52 return fName.c_str(); |
| 53 } |
| 54 |
| 55 bool SubsetSingleBench::isSuitableFor(Backend backend) { |
| 56 return kNonRendering_Backend == backend; |
| 57 } |
| 58 |
| 59 void SubsetSingleBench::onDraw(const int n, SkCanvas* canvas) { |
| 60 // When the color type is kIndex8, we will need to store the color table. I
f it is |
| 61 // used, it will be initialized by the codec. |
| 62 int colorCount; |
| 63 SkPMColor colors[256]; |
| 64 if (fUseCodec) { |
| 65 for (int count = 0; count < n; count++) { |
| 66 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica
te())); |
| 67 const SkImageInfo info = codec->getInfo().makeColorType(fColorType); |
| 68 SkAutoTDeleteArray<uint8_t> row(SkNEW_ARRAY(uint8_t, info.minRowByte
s())); |
| 69 SkScanlineDecoder* scanlineDecoder = codec->getScanlineDecoder( |
| 70 info, NULL, colors, &colorCount); |
| 71 |
| 72 SkBitmap bitmap; |
| 73 bitmap.allocPixels(info.makeWH(fSubsetWidth, fSubsetHeight)); |
| 74 |
| 75 scanlineDecoder->skipScanlines(fOffsetTop); |
| 76 uint32_t bpp = info.bytesPerPixel(); |
| 77 for (uint32_t y = 0; y < fSubsetHeight; y++) { |
| 78 scanlineDecoder->getScanlines(row.get(), 1, 0); |
| 79 memcpy(bitmap.getAddr(0, y), row.get() + fOffsetLeft * bpp, |
| 80 fSubsetWidth * bpp); |
| 81 } |
| 82 } |
| 83 } else { |
| 84 for (int count = 0; count < n; count++) { |
| 85 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea
m)); |
| 86 int width, height; |
| 87 decoder->buildTileIndex(fStream->duplicate(), &width, &height); |
| 88 SkBitmap bitmap; |
| 89 SkIRect rect = SkIRect::MakeXYWH(fOffsetLeft, fOffsetTop, fSubsetWid
th, |
| 90 fSubsetHeight); |
| 91 decoder->decodeSubset(&bitmap, rect, fColorType); |
| 92 } |
| 93 } |
| 94 } |
OLD | NEW |