| 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 "SubsetSingleBench.h" | 9 #include "SubsetSingleBench.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 an input width, height, left, and top to decode a single subset. | 20 * It uses an input width, height, left, and top to decode a single subset. |
| 22 * | 21 * |
| 23 */ | 22 */ |
| 24 | 23 |
| 25 SubsetSingleBench::SubsetSingleBench(const SkString& path, | 24 SubsetSingleBench::SubsetSingleBench(const SkString& path, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 return kNonRendering_Backend == backend; | 57 return kNonRendering_Backend == backend; |
| 59 } | 58 } |
| 60 | 59 |
| 61 void SubsetSingleBench::onDraw(const int n, SkCanvas* canvas) { | 60 void SubsetSingleBench::onDraw(const int n, SkCanvas* canvas) { |
| 62 // When the color type is kIndex8, we will need to store the color table. I
f it is | 61 // When the color type is kIndex8, we will need to store the color table. I
f it is |
| 63 // used, it will be initialized by the codec. | 62 // used, it will be initialized by the codec. |
| 64 int colorCount; | 63 int colorCount; |
| 65 SkPMColor colors[256]; | 64 SkPMColor colors[256]; |
| 66 if (fUseCodec) { | 65 if (fUseCodec) { |
| 67 for (int count = 0; count < n; count++) { | 66 for (int count = 0; count < n; count++) { |
| 68 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder( | 67 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica
te())); |
| 69 SkScanlineDecoder::NewFromStream(fStream->duplicate())); | 68 const SkImageInfo info = codec->getInfo().makeColorType(fColorType); |
| 70 const SkImageInfo info = scanlineDecoder->getInfo().makeColorType(fC
olorType); | |
| 71 SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes()]); | 69 SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes()]); |
| 72 scanlineDecoder->start(info, nullptr, colors, &colorCount); | 70 codec->startScanlineDecode(info, nullptr, colors, &colorCount); |
| 73 | 71 |
| 74 SkBitmap bitmap; | 72 SkBitmap bitmap; |
| 75 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); | 73 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); |
| 76 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); | 74 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); |
| 77 | 75 |
| 78 scanlineDecoder->skipScanlines(fOffsetTop); | 76 codec->skipScanlines(fOffsetTop); |
| 79 uint32_t bpp = info.bytesPerPixel(); | 77 uint32_t bpp = info.bytesPerPixel(); |
| 80 for (uint32_t y = 0; y < fSubsetHeight; y++) { | 78 for (uint32_t y = 0; y < fSubsetHeight; y++) { |
| 81 scanlineDecoder->getScanlines(row.get(), 1, 0); | 79 codec->getScanlines(row.get(), 1, 0); |
| 82 memcpy(bitmap.getAddr(0, y), row.get() + fOffsetLeft * bpp, | 80 memcpy(bitmap.getAddr(0, y), row.get() + fOffsetLeft * bpp, |
| 83 fSubsetWidth * bpp); | 81 fSubsetWidth * bpp); |
| 84 } | 82 } |
| 85 } | 83 } |
| 86 } else { | 84 } else { |
| 87 for (int count = 0; count < n; count++) { | 85 for (int count = 0; count < n; count++) { |
| 88 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea
m)); | 86 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea
m)); |
| 89 int width, height; | 87 int width, height; |
| 90 decoder->buildTileIndex(fStream->duplicate(), &width, &height); | 88 decoder->buildTileIndex(fStream->duplicate(), &width, &height); |
| 91 SkBitmap bitmap; | 89 SkBitmap bitmap; |
| 92 SkIRect rect = SkIRect::MakeXYWH(fOffsetLeft, fOffsetTop, fSubsetWid
th, | 90 SkIRect rect = SkIRect::MakeXYWH(fOffsetLeft, fOffsetTop, fSubsetWid
th, |
| 93 fSubsetHeight); | 91 fSubsetHeight); |
| 94 decoder->decodeSubset(&bitmap, rect, fColorType); | 92 decoder->decodeSubset(&bitmap, rect, fColorType); |
| 95 } | 93 } |
| 96 } | 94 } |
| 97 } | 95 } |
| OLD | NEW |