| 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 "SubsetTranslateBench.h" | 8 #include "SubsetTranslateBench.h" |
| 9 #include "SubsetBenchPriv.h" | 9 #include "SubsetBenchPriv.h" |
| 10 #include "SkData.h" | 10 #include "SkData.h" |
| 11 #include "SkCodec.h" | 11 #include "SkCodec.h" |
| 12 #include "SkImageDecoder.h" | 12 #include "SkImageDecoder.h" |
| 13 #include "SkOSFile.h" | 13 #include "SkOSFile.h" |
| 14 #include "SkScanlineDecoder.h" | |
| 15 #include "SkStream.h" | 14 #include "SkStream.h" |
| 16 | 15 |
| 17 /* | 16 /* |
| 18 * | 17 * |
| 19 * This benchmark is designed to test the performance of subset decoding. | 18 * This benchmark is designed to test the performance of subset decoding. |
| 20 * It uses input dimensions to decode the entire image where each block is susbe
tW x subsetH. | 19 * It uses input dimensions to decode the entire image where each block is susbe
tW x subsetH. |
| 21 * | 20 * |
| 22 */ | 21 */ |
| 23 | 22 |
| 24 SubsetTranslateBench::SubsetTranslateBench(const SkString& path, | 23 SubsetTranslateBench::SubsetTranslateBench(const SkString& path, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 53 return kNonRendering_Backend == backend; | 52 return kNonRendering_Backend == backend; |
| 54 } | 53 } |
| 55 | 54 |
| 56 void SubsetTranslateBench::onDraw(const int n, SkCanvas* canvas) { | 55 void SubsetTranslateBench::onDraw(const int n, SkCanvas* canvas) { |
| 57 // When the color type is kIndex8, we will need to store the color table. I
f it is | 56 // 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. | 57 // used, it will be initialized by the codec. |
| 59 int colorCount; | 58 int colorCount; |
| 60 SkPMColor colors[256]; | 59 SkPMColor colors[256]; |
| 61 if (fUseCodec) { | 60 if (fUseCodec) { |
| 62 for (int count = 0; count < n; count++) { | 61 for (int count = 0; count < n; count++) { |
| 63 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder( | 62 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica
te())); |
| 64 SkScanlineDecoder::NewFromStream(fStream->duplicate())); | 63 const SkImageInfo info = codec->getInfo().makeColorType(fColorType); |
| 65 const SkImageInfo info = scanlineDecoder->getInfo().makeColorType(fC
olorType); | |
| 66 SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes()]); | 64 SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes()]); |
| 67 scanlineDecoder->start(info, nullptr, colors, &colorCount); | 65 codec->start(info, nullptr, colors, &colorCount); |
| 68 | 66 |
| 69 SkBitmap bitmap; | 67 SkBitmap bitmap; |
| 70 // Note that we use the same bitmap for all of the subsets. | 68 // Note that we use the same bitmap for all of the subsets. |
| 71 // It might be larger than necessary for the end subsets. | 69 // It might be larger than necessary for the end subsets. |
| 72 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); | 70 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); |
| 73 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); | 71 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); |
| 74 | 72 |
| 75 for (int x = 0; x < info.width(); x += fSubsetWidth) { | 73 for (int x = 0; x < info.width(); x += fSubsetWidth) { |
| 76 for (int y = 0; y < info.height(); y += fSubsetHeight) { | 74 for (int y = 0; y < info.height(); y += fSubsetHeight) { |
| 77 scanlineDecoder->skipScanlines(y); | 75 codec->skipScanlines(y); |
| 78 const uint32_t currSubsetWidth = | 76 const uint32_t currSubsetWidth = |
| 79 x + (int) fSubsetWidth > info.width() ? | 77 x + (int) fSubsetWidth > info.width() ? |
| 80 info.width() - x : fSubsetWidth; | 78 info.width() - x : fSubsetWidth; |
| 81 const uint32_t currSubsetHeight = | 79 const uint32_t currSubsetHeight = |
| 82 y + (int) fSubsetHeight > info.height() ? | 80 y + (int) fSubsetHeight > info.height() ? |
| 83 info.height() - y : fSubsetHeight; | 81 info.height() - y : fSubsetHeight; |
| 84 const uint32_t bpp = info.bytesPerPixel(); | 82 const uint32_t bpp = info.bytesPerPixel(); |
| 85 for (uint32_t y = 0; y < currSubsetHeight; y++) { | 83 for (uint32_t y = 0; y < currSubsetHeight; y++) { |
| 86 scanlineDecoder->getScanlines(row.get(), 1, 0); | 84 codec->getScanlines(row.get(), 1, 0); |
| 87 memcpy(bitmap.getAddr(0, y), row.get() + x * bpp, | 85 memcpy(bitmap.getAddr(0, y), row.get() + x * bpp, |
| 88 currSubsetWidth * bpp); | 86 currSubsetWidth * bpp); |
| 89 } | 87 } |
| 90 } | 88 } |
| 91 } | 89 } |
| 92 } | 90 } |
| 93 } else { | 91 } else { |
| 94 // We create a color table here to satisfy allocPixels() when the output | 92 // We create a color table here to satisfy allocPixels() when the output |
| 95 // type is kIndex8. It's okay that this is uninitialized since we never | 93 // type is kIndex8. It's okay that this is uninitialized since we never |
| 96 // use it. | 94 // use it. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 117 const uint32_t currSubsetHeight = y + (int) fSubsetHeight >
height ? | 115 const uint32_t currSubsetHeight = y + (int) fSubsetHeight >
height ? |
| 118 height - y : fSubsetHeight; | 116 height - y : fSubsetHeight; |
| 119 SkIRect rect = SkIRect::MakeXYWH(x, y, currSubsetWidth, | 117 SkIRect rect = SkIRect::MakeXYWH(x, y, currSubsetWidth, |
| 120 currSubsetHeight); | 118 currSubsetHeight); |
| 121 decoder->decodeSubset(&bitmap, rect, fColorType); | 119 decoder->decodeSubset(&bitmap, rect, fColorType); |
| 122 } | 120 } |
| 123 } | 121 } |
| 124 } | 122 } |
| 125 } | 123 } |
| 126 } | 124 } |
| OLD | NEW |