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 "CodecBenchPriv.h" | |
9 #include "SubsetZoomBench.h" | |
10 #include "SubsetBenchPriv.h" | |
11 #include "SkData.h" | |
12 #include "SkCodec.h" | |
13 #include "SkImageDecoder.h" | |
14 #include "SkOSFile.h" | |
15 #include "SkStream.h" | |
16 | |
17 /* | |
18 * | |
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. | |
21 * | |
22 */ | |
23 | |
24 SubsetZoomBench::SubsetZoomBench(const SkString& path, | |
25 SkColorType colorType, | |
26 uint32_t subsetWidth, | |
27 uint32_t subsetHeight) | |
28 : fColorType(colorType) | |
29 , fSubsetWidth(subsetWidth) | |
30 , fSubsetHeight(subsetHeight) | |
31 { | |
32 // Parse the filename | |
33 SkString baseName = SkOSPath::Basename(path.c_str()); | |
34 | |
35 // Choose an informative color name | |
36 const char* colorName = color_type_to_str(fColorType); | |
37 | |
38 fName.printf("CodecSubsetZoom_%dx%d_%s_%s", fSubsetWidth, | |
39 fSubsetHeight, baseName.c_str(), colorName); | |
40 | |
41 // Perform the decode setup | |
42 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); | |
43 fStream.reset(new SkMemoryStream(encoded)); | |
44 } | |
45 | |
46 const char* SubsetZoomBench::onGetName() { | |
47 return fName.c_str(); | |
48 } | |
49 | |
50 bool SubsetZoomBench::isSuitableFor(Backend backend) { | |
51 return kNonRendering_Backend == backend; | |
52 } | |
53 | |
54 void SubsetZoomBench::onDraw(int n, SkCanvas* canvas) { | |
55 // When the color type is kIndex8, we will need to store the color table. I
f it is | |
56 // used, it will be initialized by the codec. | |
57 int colorCount; | |
58 SkPMColor colors[256]; | |
59 for (int count = 0; count < n; count++) { | |
60 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplicate()
)); | |
61 SkASSERT(SkCodec::kOutOfOrder_SkScanlineOrder != codec->getScanlineOrder
()); | |
62 const SkImageInfo info = codec->getInfo().makeColorType(fColorType); | |
63 | |
64 const int centerX = info.width() / 2; | |
65 const int centerY = info.height() / 2; | |
66 int w = fSubsetWidth; | |
67 int h = fSubsetHeight; | |
68 do { | |
69 const int subsetStartX = SkTMax(0, centerX - w / 2); | |
70 const int subsetStartY = SkTMax(0, centerY - h / 2); | |
71 const int subsetWidth = SkTMin(w, info.width() - subsetStartX); | |
72 const int subsetHeight = SkTMin(h, info.height() - subsetStartY); | |
73 | |
74 // The scanline decoder will handle subsetting in the x-dimension. | |
75 SkIRect subset = SkIRect::MakeXYWH(subsetStartX, 0, subsetWidth, | |
76 codec->getInfo().height()); | |
77 SkCodec::Options options; | |
78 options.fSubset = ⊂ | |
79 | |
80 SkDEBUGCODE(SkCodec::Result result = ) | |
81 codec->startScanlineDecode(info, &options, colors, &colorCount); | |
82 SkASSERT(SkCodec::kSuccess == result); | |
83 | |
84 // Note that if we subsetted and scaled in a single step, we could u
se the | |
85 // same bitmap - as is often done in actual use cases. | |
86 SkBitmap bitmap; | |
87 SkImageInfo subsetInfo = info.makeWH(subsetWidth, subsetHeight); | |
88 alloc_pixels(&bitmap, subsetInfo, colors, colorCount); | |
89 | |
90 SkDEBUGCODE(bool success = ) codec->skipScanlines(subsetStartY); | |
91 SkASSERT(success); | |
92 | |
93 SkDEBUGCODE(int lines = ) codec->getScanlines(bitmap.getPixels(), | |
94 subsetHeight, bitmap.rowBytes()); | |
95 SkASSERT(subsetHeight == lines); | |
96 | |
97 w <<= 1; | |
98 h <<= 1; | |
99 } while (w < 2 * info.width() || h < 2 * info.height()); | |
100 } | |
101 } | |
OLD | NEW |