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 "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 * 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. |
22 * | 21 * |
23 */ | 22 */ |
24 | 23 |
25 SubsetZoomBench::SubsetZoomBench(const SkString& path, | 24 SubsetZoomBench::SubsetZoomBench(const SkString& path, |
(...skipping 28 matching lines...) Expand all Loading... |
54 return kNonRendering_Backend == backend; | 53 return kNonRendering_Backend == backend; |
55 } | 54 } |
56 | 55 |
57 void SubsetZoomBench::onDraw(const int n, SkCanvas* canvas) { | 56 void SubsetZoomBench::onDraw(const int n, SkCanvas* canvas) { |
58 // When the color type is kIndex8, we will need to store the color table. I
f it is | 57 // When the color type is kIndex8, we will need to store the color table. I
f it is |
59 // used, it will be initialized by the codec. | 58 // used, it will be initialized by the codec. |
60 int colorCount; | 59 int colorCount; |
61 SkPMColor colors[256]; | 60 SkPMColor colors[256]; |
62 if (fUseCodec) { | 61 if (fUseCodec) { |
63 for (int count = 0; count < n; count++) { | 62 for (int count = 0; count < n; count++) { |
64 SkAutoTDelete<SkScanlineDecoder> scanlineDecoder( | 63 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica
te())); |
65 SkScanlineDecoder::NewFromStream(fStream->duplicate())); | 64 const SkImageInfo info = codec->getInfo().makeColorType(fColorType); |
66 const SkImageInfo info = scanlineDecoder->getInfo().makeColorType(fC
olorType); | |
67 SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes()]); | 65 SkAutoTDeleteArray<uint8_t> row(new uint8_t[info.minRowBytes()]); |
68 scanlineDecoder->start(info, nullptr, colors, &colorCount); | 66 codec->startScanlineDecode(info, nullptr, colors, &colorCount); |
69 | 67 |
70 const int centerX = info.width() / 2; | 68 const int centerX = info.width() / 2; |
71 const int centerY = info.height() / 2; | 69 const int centerY = info.height() / 2; |
72 int w = fSubsetWidth; | 70 int w = fSubsetWidth; |
73 int h = fSubsetHeight; | 71 int h = fSubsetHeight; |
74 do { | 72 do { |
75 const int subsetStartX = SkTMax(0, centerX - w / 2); | 73 const int subsetStartX = SkTMax(0, centerX - w / 2); |
76 const int subsetStartY = SkTMax(0, centerY - h / 2); | 74 const int subsetStartY = SkTMax(0, centerY - h / 2); |
77 const int subsetWidth = SkTMin(w, info.width() - subsetStartX); | 75 const int subsetWidth = SkTMin(w, info.width() - subsetStartX); |
78 const int subsetHeight = SkTMin(h, info.height() - subsetStartY)
; | 76 const int subsetHeight = SkTMin(h, info.height() - subsetStartY)
; |
79 // Note that if we subsetted and scaled in a single step, we cou
ld use the | 77 // Note that if we subsetted and scaled in a single step, we cou
ld use the |
80 // same bitmap - as is often done in actual use cases. | 78 // same bitmap - as is often done in actual use cases. |
81 SkBitmap bitmap; | 79 SkBitmap bitmap; |
82 SkImageInfo subsetInfo = info.makeWH(subsetWidth, subsetHeight); | 80 SkImageInfo subsetInfo = info.makeWH(subsetWidth, subsetHeight); |
83 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); | 81 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); |
84 | 82 |
85 uint32_t bpp = info.bytesPerPixel(); | 83 uint32_t bpp = info.bytesPerPixel(); |
86 scanlineDecoder->skipScanlines(subsetStartY); | 84 codec->skipScanlines(subsetStartY); |
87 for (int y = 0; y < subsetHeight; y++) { | 85 for (int y = 0; y < subsetHeight; y++) { |
88 scanlineDecoder->getScanlines(row.get(), 1, 0); | 86 codec->getScanlines(row.get(), 1, 0); |
89 memcpy(bitmap.getAddr(0, y), row.get() + subsetStartX * bpp, | 87 memcpy(bitmap.getAddr(0, y), row.get() + subsetStartX * bpp, |
90 subsetWidth * bpp); | 88 subsetWidth * bpp); |
91 } | 89 } |
92 w <<= 1; | 90 w <<= 1; |
93 h <<= 1; | 91 h <<= 1; |
94 } while (w < 2 * info.width() || h < 2 * info.height()); | 92 } while (w < 2 * info.width() || h < 2 * info.height()); |
95 } | 93 } |
96 } else { | 94 } else { |
97 for (int count = 0; count < n; count++) { | 95 for (int count = 0; count < n; count++) { |
98 int width, height; | 96 int width, height; |
(...skipping 12 matching lines...) Expand all Loading... |
111 SkBitmap bitmap; | 109 SkBitmap bitmap; |
112 SkIRect rect = SkIRect::MakeXYWH(subsetStartX, subsetStartY, sub
setWidth, | 110 SkIRect rect = SkIRect::MakeXYWH(subsetStartX, subsetStartY, sub
setWidth, |
113 subsetHeight); | 111 subsetHeight); |
114 decoder->decodeSubset(&bitmap, rect, fColorType); | 112 decoder->decodeSubset(&bitmap, rect, fColorType); |
115 w <<= 1; | 113 w <<= 1; |
116 h <<= 1; | 114 h <<= 1; |
117 } while (w < 2 * width || h < 2 * height); | 115 } while (w < 2 * width || h < 2 * height); |
118 } | 116 } |
119 } | 117 } |
120 } | 118 } |
OLD | NEW |