Chromium Code Reviews| 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 "SubsetDivisorBench.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 a divisor to decode the entire image in a grid of divisor x divisor b locks. | |
| 20 * | |
| 21 */ | |
| 22 | |
| 23 SubsetDivisorBench::SubsetDivisorBench(const SkString& path, | |
| 24 SkColorType colorType, | |
| 25 uint32_t divisor, | |
| 26 bool useCodec) | |
| 27 : fColorType(colorType) | |
| 28 , fDivisor(divisor) | |
| 29 , fUseCodec(useCodec) | |
| 30 { | |
| 31 // Parse the filename | |
| 32 SkString baseName = SkOSPath::Basename(path.c_str()); | |
| 33 | |
| 34 // Choose an informative color name | |
| 35 const char* colorName = get_color_name(fColorType); | |
| 36 | |
| 37 fName.printf("%sSubsetDivisor_%dx%d_%s_%s", fUseCodec ? "Codec" : "Image", f Divisor, fDivisor, | |
| 38 baseName.c_str(), colorName); | |
| 39 | |
| 40 // Perform the decode setup | |
| 41 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); | |
| 42 fStream.reset(new SkMemoryStream(encoded)); | |
| 43 } | |
| 44 | |
| 45 const char* SubsetDivisorBench::onGetName() { | |
| 46 return fName.c_str(); | |
| 47 } | |
| 48 | |
| 49 bool SubsetDivisorBench::isSuitableFor(Backend backend) { | |
| 50 return kNonRendering_Backend == backend; | |
| 51 } | |
| 52 | |
| 53 void SubsetDivisorBench::onDraw(const int n, SkCanvas* canvas) { | |
| 54 if (fUseCodec) { | |
| 55 for (int count = 0; count < n; count++) { | |
| 56 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica te())); | |
| 57 const SkImageInfo info = codec->getInfo(); | |
| 58 SkAutoTDeleteArray<uint8_t> row(SkNEW_ARRAY(uint8_t, info.minRowByte s())); | |
| 59 SkScanlineDecoder* scanlineDecoder = | |
| 60 codec->getScanlineDecoder(info.makeColorType(fColorType)); | |
| 61 | |
| 62 const uint32_t subsetWidth = info.width() / fDivisor; | |
| 63 const uint32_t subsetHeight = info.height() / fDivisor; | |
| 64 const uint32_t maxSubsetWidth = subsetWidth + info.width() % fDiviso r; | |
| 65 const uint32_t maxSubsetHeight = subsetHeight + info.height() % fDiv isor; | |
| 66 SkBitmap bitmap; | |
| 67 // Note that we use the same bitmap for all of the subsets. | |
| 68 // It might be slightly larger than necessary for some of the subset s. | |
| 69 bitmap.allocPixels(info.makeWH(maxSubsetWidth, maxSubsetHeight)); | |
| 70 | |
| 71 for (uint32_t blockX = 0; blockX < fDivisor; blockX++) { | |
| 72 for (uint32_t blockY = 0; blockY < fDivisor; blockY++) { | |
| 73 scanlineDecoder->skipScanlines(blockY * subsetHeight); | |
| 74 const uint32_t currSubsetWidth = | |
| 75 (blockX == fDivisor - 1) ? maxSubsetWidth : subsetWi dth; | |
| 76 const uint32_t currSubsetHeight = | |
| 77 (blockY == fDivisor - 1) ? maxSubsetHeight : subsetH eight; | |
| 78 const uint32_t bpp = info.bytesPerPixel(); | |
| 79 for (uint32_t y = 0; y < currSubsetHeight; y++) { | |
| 80 scanlineDecoder->getScanlines(row.get(), 1, 0); | |
| 81 memcpy(bitmap.getAddr(0, y), row.get() + blockX * subset Width * bpp, | |
| 82 currSubsetWidth * bpp); | |
| 83 } | |
| 84 } | |
| 85 } | |
| 86 } | |
| 87 } else { | |
| 88 SkPMColor colors[256]; | |
| 89 SkColorTable* colorTable = SkNEW_ARGS(SkColorTable, (colors, 0)); | |
|
scroggo
2015/06/04 13:50:04
Maybe add a comment that it's okay for these color
msarett
2015/06/08 16:28:33
Done.
| |
| 90 for (int count = 0; count < n; count++) { | |
| 91 int width, height; | |
| 92 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea m)); | |
| 93 decoder->buildTileIndex(fStream->duplicate(), &width, &height); | |
| 94 | |
| 95 const uint32_t subsetWidth = width / fDivisor; | |
| 96 const uint32_t subsetHeight = height / fDivisor; | |
| 97 const uint32_t maxSubsetWidth = subsetWidth + width % fDivisor; | |
| 98 const uint32_t maxSubsetHeight = subsetHeight + height % fDivisor; | |
| 99 SkBitmap bitmap; | |
| 100 // Note that we use the same bitmap for all of the subsets. | |
| 101 // It might be slightly larger than necessary for some of the subset s. | |
| 102 // If we do not include this step, decodeSubset() would allocate spa ce | |
| 103 // for the pixels automatically, but this would not allow us to reus e the | |
| 104 // same bitmap as the other subsets. We want to reuse the same bitm ap | |
| 105 // because it gives a more fair comparison with SkCodec and is a com mon | |
| 106 // use case of BitmapRegionDecoder.; | |
|
scroggo
2015/06/04 13:50:04
Semicolon not needed here.
msarett
2015/06/08 16:28:33
Done.
| |
| 107 bitmap.allocPixels(SkImageInfo::Make(maxSubsetWidth, maxSubsetHeight , | |
| 108 fColorType, kOpaque_SkAlphaType), NULL, colorTable); | |
| 109 | |
| 110 for (uint32_t blockX = 0; blockX < fDivisor; blockX++) { | |
| 111 for (uint32_t blockY = 0; blockY < fDivisor; blockY++) { | |
| 112 const uint32_t currSubsetWidth = | |
| 113 (blockX == fDivisor - 1) ? maxSubsetWidth : subsetWi dth; | |
| 114 const uint32_t currSubsetHeight = | |
| 115 (blockY == fDivisor - 1) ? maxSubsetHeight : subsetH eight; | |
| 116 SkIRect rect = SkIRect::MakeXYWH(blockX * subsetWidth, | |
| 117 blockY * subsetHeight, currSubsetWidth, currSubsetHe ight); | |
| 118 decoder->decodeSubset(&bitmap, rect, fColorType); | |
| 119 } | |
| 120 } | |
| 121 } | |
| 122 } | |
| 123 } | |
| OLD | NEW |