Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: bench/subset/SubsetZoomBench.cpp

Issue 1160953002: Subset decoding benchmarks (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Tested for multiple images and multiple color types on both codec and image decoder Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "SubsetZoomBench.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 * Choose subsets to mimic a user zooming in or out on a photo.
20 *
21 */
22
23 SubsetZoomBench::SubsetZoomBench(const SkString& path,
24 SkColorType colorType,
25 uint32_t subsetWidth,
26 uint32_t subsetHeight,
27 bool useCodec)
28 : fColorType(colorType)
29 , fSubsetWidth(subsetWidth)
30 , fSubsetHeight(subsetHeight)
31 , fUseCodec(useCodec)
32 {
33 // Parse the filename
34 SkString baseName = SkOSPath::Basename(path.c_str());
35
36 // Choose an informative color name
37 const char* colorName = get_color_name(fColorType);
38
39 fName.printf("%sSubsetZoom_%dx%d_%s_%s", fUseCodec ? "Codec" : "Image", fSub setWidth,
40 fSubsetHeight, baseName.c_str(), colorName);
41
42 // Perform the decode setup
43 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
44 fStream.reset(new SkMemoryStream(encoded));
45 }
46
47 const char* SubsetZoomBench::onGetName() {
48 return fName.c_str();
49 }
50
51 bool SubsetZoomBench::isSuitableFor(Backend backend) {
52 return kNonRendering_Backend == backend;
53 }
54
55 void SubsetZoomBench::onDraw(const int n, SkCanvas* canvas) {
56 if (fUseCodec) {
57 for (int count = 0; count < n; count++) {
58 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica te()));
59 const SkImageInfo info = codec->getInfo();
60 SkAutoTDeleteArray<uint8_t> row(SkNEW_ARRAY(uint8_t, info.minRowByte s()));
61 SkScanlineDecoder* scanlineDecoder =
62 codec->getScanlineDecoder(info.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 // Note that if we subsetted and scaled in a single step, we cou ld use the
74 // same bitmap - as is often done in actual use cases.
75 SkBitmap bitmap;
76 bitmap.allocPixels(info.makeWH(subsetWidth, subsetHeight));
77
78 uint32_t bpp = info.bytesPerPixel();
79 scanlineDecoder->skipScanlines(subsetStartY);
80 for (int y = 0; y < subsetHeight; y++) {
81 scanlineDecoder->getScanlines(row.get(), 1, 0);
82 memcpy(bitmap.getAddr(0, y), row.get() + subsetStartX * bpp,
83 subsetWidth * bpp);
84 }
85 w <<= 1;
86 h <<= 1;
87 } while (w < 2 * info.width() || h < 2 * info.height());
88 }
89 } else {
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 int centerX = width / 2;
96 const int centerY = height / 2;
97 int w = fSubsetWidth;
98 int h = fSubsetHeight;
99 do {
100 const int subsetStartX = SkTMax(0, centerX - w / 2);
101 const int subsetStartY = SkTMax(0, centerY - h / 2);
102 const int subsetWidth = SkTMin(w, width - subsetStartX);
103 const int subsetHeight = SkTMin(h, height - subsetStartY);
104 SkBitmap bitmap;
105 SkIRect rect = SkIRect::MakeXYWH(subsetStartX, subsetStartY, sub setWidth,
106 subsetHeight);
107 decoder->decodeSubset(&bitmap, rect, fColorType);
108 w <<= 1;
109 h <<= 1;
110 } while (w < 2 * width || h < 2 * height);
111 }
112 }
113 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698