| 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 "SubsetZoomBench.h" | 9 #include "SubsetZoomBench.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 * Choose subsets to mimic a user zooming in or out on a photo. | 20 * Choose subsets to mimic a user zooming in or out on a photo. |
| 21 * | 21 * |
| 22 */ | 22 */ |
| 23 | 23 |
| 24 SubsetZoomBench::SubsetZoomBench(const SkString& path, | 24 SubsetZoomBench::SubsetZoomBench(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 bool useCodec) | |
| 29 : fColorType(colorType) | 28 : fColorType(colorType) |
| 30 , fSubsetWidth(subsetWidth) | 29 , fSubsetWidth(subsetWidth) |
| 31 , fSubsetHeight(subsetHeight) | 30 , fSubsetHeight(subsetHeight) |
| 32 , fUseCodec(useCodec) | |
| 33 { | 31 { |
| 34 // Parse the filename | 32 // Parse the filename |
| 35 SkString baseName = SkOSPath::Basename(path.c_str()); | 33 SkString baseName = SkOSPath::Basename(path.c_str()); |
| 36 | 34 |
| 37 // Choose an informative color name | 35 // Choose an informative color name |
| 38 const char* colorName = color_type_to_str(fColorType); | 36 const char* colorName = color_type_to_str(fColorType); |
| 39 | 37 |
| 40 fName.printf("%sSubsetZoom_%dx%d_%s_%s", fUseCodec ? "Codec" : "Image", fSub
setWidth, | 38 fName.printf("CodecSubsetZoom_%dx%d_%s_%s", fSubsetWidth, |
| 41 fSubsetHeight, baseName.c_str(), colorName); | 39 fSubsetHeight, baseName.c_str(), colorName); |
| 42 | 40 |
| 43 // Perform the decode setup | 41 // Perform the decode setup |
| 44 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); | 42 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
| 45 fStream.reset(new SkMemoryStream(encoded)); | 43 fStream.reset(new SkMemoryStream(encoded)); |
| 46 } | 44 } |
| 47 | 45 |
| 48 const char* SubsetZoomBench::onGetName() { | 46 const char* SubsetZoomBench::onGetName() { |
| 49 return fName.c_str(); | 47 return fName.c_str(); |
| 50 } | 48 } |
| 51 | 49 |
| 52 bool SubsetZoomBench::isSuitableFor(Backend backend) { | 50 bool SubsetZoomBench::isSuitableFor(Backend backend) { |
| 53 return kNonRendering_Backend == backend; | 51 return kNonRendering_Backend == backend; |
| 54 } | 52 } |
| 55 | 53 |
| 56 void SubsetZoomBench::onDraw(int n, SkCanvas* canvas) { | 54 void SubsetZoomBench::onDraw(int n, SkCanvas* canvas) { |
| 57 // When the color type is kIndex8, we will need to store the color table. I
f it is | 55 // 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. | 56 // used, it will be initialized by the codec. |
| 59 int colorCount; | 57 int colorCount; |
| 60 SkPMColor colors[256]; | 58 SkPMColor colors[256]; |
| 61 if (fUseCodec) { | 59 for (int count = 0; count < n; count++) { |
| 62 for (int count = 0; count < n; count++) { | 60 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplicate()
)); |
| 63 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica
te())); | 61 SkASSERT(SkCodec::kOutOfOrder_SkScanlineOrder != codec->getScanlineOrder
()); |
| 64 SkASSERT(SkCodec::kOutOfOrder_SkScanlineOrder != codec->getScanlineO
rder()); | 62 const SkImageInfo info = codec->getInfo().makeColorType(fColorType); |
| 65 const SkImageInfo info = codec->getInfo().makeColorType(fColorType); | |
| 66 | 63 |
| 67 const int centerX = info.width() / 2; | 64 const int centerX = info.width() / 2; |
| 68 const int centerY = info.height() / 2; | 65 const int centerY = info.height() / 2; |
| 69 int w = fSubsetWidth; | 66 int w = fSubsetWidth; |
| 70 int h = fSubsetHeight; | 67 int h = fSubsetHeight; |
| 71 do { | 68 do { |
| 72 const int subsetStartX = SkTMax(0, centerX - w / 2); | 69 const int subsetStartX = SkTMax(0, centerX - w / 2); |
| 73 const int subsetStartY = SkTMax(0, centerY - h / 2); | 70 const int subsetStartY = SkTMax(0, centerY - h / 2); |
| 74 const int subsetWidth = SkTMin(w, info.width() - subsetStartX); | 71 const int subsetWidth = SkTMin(w, info.width() - subsetStartX); |
| 75 const int subsetHeight = SkTMin(h, info.height() - subsetStartY)
; | 72 const int subsetHeight = SkTMin(h, info.height() - subsetStartY); |
| 76 | 73 |
| 77 // The scanline decoder will handle subsetting in the x-dimensio
n. | 74 // The scanline decoder will handle subsetting in the x-dimension. |
| 78 SkIRect subset = SkIRect::MakeXYWH(subsetStartX, 0, subsetWidth, | 75 SkIRect subset = SkIRect::MakeXYWH(subsetStartX, 0, subsetWidth, |
| 79 codec->getInfo().height()); | 76 codec->getInfo().height()); |
| 80 SkCodec::Options options; | 77 SkCodec::Options options; |
| 81 options.fSubset = ⊂ | 78 options.fSubset = ⊂ |
| 82 | 79 |
| 83 SkDEBUGCODE(SkCodec::Result result = ) | 80 SkDEBUGCODE(SkCodec::Result result = ) |
| 84 codec->startScanlineDecode(info, &options, colors, &colorCount); | 81 codec->startScanlineDecode(info, &options, colors, &colorCount); |
| 85 SkASSERT(SkCodec::kSuccess == result); | 82 SkASSERT(SkCodec::kSuccess == result); |
| 86 | 83 |
| 87 // Note that if we subsetted and scaled in a single step, we cou
ld use the | 84 // Note that if we subsetted and scaled in a single step, we could u
se the |
| 88 // same bitmap - as is often done in actual use cases. | 85 // same bitmap - as is often done in actual use cases. |
| 89 SkBitmap bitmap; | 86 SkBitmap bitmap; |
| 90 SkImageInfo subsetInfo = info.makeWH(subsetWidth, subsetHeight); | 87 SkImageInfo subsetInfo = info.makeWH(subsetWidth, subsetHeight); |
| 91 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); | 88 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); |
| 92 | 89 |
| 93 SkDEBUGCODE(bool success = ) codec->skipScanlines(subsetStartY); | 90 SkDEBUGCODE(bool success = ) codec->skipScanlines(subsetStartY); |
| 94 SkASSERT(success); | 91 SkASSERT(success); |
| 95 | 92 |
| 96 SkDEBUGCODE(int lines = ) codec->getScanlines(bitmap.getPixels()
, | 93 SkDEBUGCODE(int lines = ) codec->getScanlines(bitmap.getPixels(), |
| 97 subsetHeight, bitmap.rowBytes()); | 94 subsetHeight, bitmap.rowBytes()); |
| 98 SkASSERT(subsetHeight == lines); | 95 SkASSERT(subsetHeight == lines); |
| 99 | 96 |
| 100 w <<= 1; | 97 w <<= 1; |
| 101 h <<= 1; | 98 h <<= 1; |
| 102 } while (w < 2 * info.width() || h < 2 * info.height()); | 99 } while (w < 2 * info.width() || h < 2 * info.height()); |
| 103 } | |
| 104 } else { | |
| 105 for (int count = 0; count < n; count++) { | |
| 106 int width, height; | |
| 107 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea
m)); | |
| 108 SkAssertResult(decoder->buildTileIndex(fStream->duplicate(), &width,
&height)); | |
| 109 | |
| 110 const int centerX = width / 2; | |
| 111 const int centerY = height / 2; | |
| 112 int w = fSubsetWidth; | |
| 113 int h = fSubsetHeight; | |
| 114 do { | |
| 115 const int subsetStartX = SkTMax(0, centerX - w / 2); | |
| 116 const int subsetStartY = SkTMax(0, centerY - h / 2); | |
| 117 const int subsetWidth = SkTMin(w, width - subsetStartX); | |
| 118 const int subsetHeight = SkTMin(h, height - subsetStartY); | |
| 119 SkBitmap bitmap; | |
| 120 SkIRect rect = SkIRect::MakeXYWH(subsetStartX, subsetStartY, sub
setWidth, | |
| 121 subsetHeight); | |
| 122 SkAssertResult(decoder->decodeSubset(&bitmap, rect, fColorType))
; | |
| 123 w <<= 1; | |
| 124 h <<= 1; | |
| 125 } while (w < 2 * width || h < 2 * height); | |
| 126 } | |
| 127 } | 100 } |
| 128 } | 101 } |
| OLD | NEW |