| 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 "SkStream.h" | 15 #include "SkStream.h" |
| 16 | 16 |
| 17 /* | 17 /* |
| 18 * | 18 * |
| 19 * This benchmark is designed to test the performance of subset decoding. | 19 * This benchmark is designed to test the performance of subset decoding. |
| 20 * 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. |
| 21 * | 21 * |
| 22 */ | 22 */ |
| 23 | 23 |
| 24 SubsetSingleBench::SubsetSingleBench(const SkString& path, | 24 SubsetSingleBench::SubsetSingleBench(const SkString& path, |
| 25 SkColorType colorType, | 25 SkColorType colorType, |
| 26 uint32_t subsetWidth, | 26 uint32_t subsetWidth, |
| 27 uint32_t subsetHeight, | 27 uint32_t subsetHeight, |
| 28 uint32_t offsetLeft, | 28 uint32_t offsetLeft, |
| 29 uint32_t offsetTop, | 29 uint32_t offsetTop) |
| 30 bool useCodec) | |
| 31 : fColorType(colorType) | 30 : fColorType(colorType) |
| 32 , fSubsetWidth(subsetWidth) | 31 , fSubsetWidth(subsetWidth) |
| 33 , fSubsetHeight(subsetHeight) | 32 , fSubsetHeight(subsetHeight) |
| 34 , fOffsetLeft(offsetLeft) | 33 , fOffsetLeft(offsetLeft) |
| 35 , fOffsetTop(offsetTop) | 34 , fOffsetTop(offsetTop) |
| 36 , fUseCodec(useCodec) | |
| 37 { | 35 { |
| 38 // Parse the filename | 36 // Parse the filename |
| 39 SkString baseName = SkOSPath::Basename(path.c_str()); | 37 SkString baseName = SkOSPath::Basename(path.c_str()); |
| 40 | 38 |
| 41 // Choose an informative color name | 39 // Choose an informative color name |
| 42 const char* colorName = color_type_to_str(fColorType); | 40 const char* colorName = color_type_to_str(fColorType); |
| 43 | 41 |
| 44 fName.printf("%sSubsetSingle_%dx%d +%d_+%d_%s_%s", fUseCodec ? "Codec" : "Im
age", fSubsetWidth, | 42 fName.printf("CodecSubsetSingle_%dx%d +%d_+%d_%s_%s", fSubsetWidth, |
| 45 fSubsetHeight, fOffsetLeft, fOffsetTop, baseName.c_str(), colorName)
; | 43 fSubsetHeight, fOffsetLeft, fOffsetTop, baseName.c_str(), colorName)
; |
| 46 | 44 |
| 47 // Perform the decode setup | 45 // Perform the decode setup |
| 48 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); | 46 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
| 49 fStream.reset(new SkMemoryStream(encoded)); | 47 fStream.reset(new SkMemoryStream(encoded)); |
| 50 } | 48 } |
| 51 | 49 |
| 52 const char* SubsetSingleBench::onGetName() { | 50 const char* SubsetSingleBench::onGetName() { |
| 53 return fName.c_str(); | 51 return fName.c_str(); |
| 54 } | 52 } |
| 55 | 53 |
| 56 bool SubsetSingleBench::isSuitableFor(Backend backend) { | 54 bool SubsetSingleBench::isSuitableFor(Backend backend) { |
| 57 return kNonRendering_Backend == backend; | 55 return kNonRendering_Backend == backend; |
| 58 } | 56 } |
| 59 | 57 |
| 60 void SubsetSingleBench::onDraw(int n, SkCanvas* canvas) { | 58 void SubsetSingleBench::onDraw(int n, SkCanvas* canvas) { |
| 61 // When the color type is kIndex8, we will need to store the color table. I
f it is | 59 // When the color type is kIndex8, we will need to store the color table. I
f it is |
| 62 // used, it will be initialized by the codec. | 60 // used, it will be initialized by the codec. |
| 63 int colorCount; | 61 int colorCount; |
| 64 SkPMColor colors[256]; | 62 SkPMColor colors[256]; |
| 65 if (fUseCodec) { | 63 for (int count = 0; count < n; count++) { |
| 66 for (int count = 0; count < n; count++) { | 64 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplicate()
)); |
| 67 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica
te())); | 65 SkASSERT(SkCodec::kOutOfOrder_SkScanlineOrder != codec->getScanlineOrder
()); |
| 68 SkASSERT(SkCodec::kOutOfOrder_SkScanlineOrder != codec->getScanlineO
rder()); | 66 const SkImageInfo info = codec->getInfo().makeColorType(fColorType); |
| 69 const SkImageInfo info = codec->getInfo().makeColorType(fColorType); | |
| 70 | 67 |
| 71 // The scanline decoder will handle subsetting in the x-dimension. | 68 // The scanline decoder will handle subsetting in the x-dimension. |
| 72 SkIRect subset = SkIRect::MakeXYWH(fOffsetLeft, 0, fSubsetWidth, | 69 SkIRect subset = SkIRect::MakeXYWH(fOffsetLeft, 0, fSubsetWidth, |
| 73 codec->getInfo().height()); | 70 codec->getInfo().height()); |
| 74 SkCodec::Options options; | 71 SkCodec::Options options; |
| 75 options.fSubset = ⊂ | 72 options.fSubset = ⊂ |
| 76 | 73 |
| 77 SkDEBUGCODE(SkCodec::Result result =) | 74 SkDEBUGCODE(SkCodec::Result result =) |
| 78 codec->startScanlineDecode(info, &options, colors, &colorCount); | 75 codec->startScanlineDecode(info, &options, colors, &colorCount); |
| 79 SkASSERT(result == SkCodec::kSuccess); | 76 SkASSERT(result == SkCodec::kSuccess); |
| 80 | 77 |
| 81 SkBitmap bitmap; | 78 SkBitmap bitmap; |
| 82 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); | 79 SkImageInfo subsetInfo = info.makeWH(fSubsetWidth, fSubsetHeight); |
| 83 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); | 80 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); |
| 84 | 81 |
| 85 SkDEBUGCODE(bool success = ) codec->skipScanlines(fOffsetTop); | 82 SkDEBUGCODE(bool success = ) codec->skipScanlines(fOffsetTop); |
| 86 SkASSERT(success); | 83 SkASSERT(success); |
| 87 | 84 |
| 88 SkDEBUGCODE(uint32_t lines = ) codec->getScanlines(bitmap.getPixels(
), fSubsetHeight, | 85 SkDEBUGCODE(uint32_t lines = ) codec->getScanlines(bitmap.getPixels(), f
SubsetHeight, |
| 89 bitmap.rowBytes()); | 86 bitmap.rowBytes()); |
| 90 SkASSERT(lines == fSubsetHeight); | 87 SkASSERT(lines == fSubsetHeight); |
| 91 } | |
| 92 } else { | |
| 93 for (int count = 0; count < n; count++) { | |
| 94 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea
m)); | |
| 95 int width, height; | |
| 96 SkAssertResult(decoder->buildTileIndex(fStream->duplicate(), &width,
&height)); | |
| 97 SkBitmap bitmap; | |
| 98 SkIRect rect = SkIRect::MakeXYWH(fOffsetLeft, fOffsetTop, fSubsetWid
th, | |
| 99 fSubsetHeight); | |
| 100 SkAssertResult(decoder->decodeSubset(&bitmap, rect, fColorType)); | |
| 101 } | |
| 102 } | 88 } |
| 103 } | 89 } |
| OLD | NEW |