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

Side by Side Diff: bench/subset/SubsetSingleBench.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 "SubsetSingleBench.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 * It uses an input width, height, left, and top to decode a single subset.
20 *
21 */
22
23 SubsetSingleBench::SubsetSingleBench(const SkString& path,
24 SkColorType colorType,
25 uint32_t subsetWidth,
26 uint32_t subsetHeight,
27 uint32_t offsetLeft,
28 uint32_t offsetTop,
29 bool useCodec)
30 : fColorType(colorType)
31 , fSubsetWidth(subsetWidth)
32 , fSubsetHeight(subsetHeight)
33 , fOffsetLeft(offsetLeft)
34 , fOffsetTop(offsetTop)
35 , fUseCodec(useCodec)
36 {
37 // Parse the filename
38 SkString baseName = SkOSPath::Basename(path.c_str());
39
40 // Choose an informative color name
41 const char* colorName = get_color_name(fColorType);
42
43 fName.printf("%sSubsetSingle_%dx%d +%d_+%d_%s_%s", fUseCodec ? "Codec" : "Im age", fSubsetWidth,
44 fSubsetHeight, fOffsetLeft, fOffsetTop, baseName.c_str(), colorName) ;
45
46 // Perform the decode setup
47 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
48 fStream.reset(new SkMemoryStream(encoded));
49 }
50
51 const char* SubsetSingleBench::onGetName() {
52 return fName.c_str();
53 }
54
55 bool SubsetSingleBench::isSuitableFor(Backend backend) {
56 return kNonRendering_Backend == backend;
57 }
58
59 void SubsetSingleBench::onDraw(const int n, SkCanvas* canvas) {
60 if (fUseCodec) {
61 for (int count = 0; count < n; count++) {
62 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(fStream->duplica te()));
63 const SkImageInfo info = codec->getInfo();
64 SkAutoTDeleteArray<uint8_t> row(SkNEW_ARRAY(uint8_t, info.minRowByte s()));
65 SkScanlineDecoder* scanlineDecoder =
66 codec->getScanlineDecoder(info.makeColorType(fColorType));
67
68 SkBitmap bitmap;
69 bitmap.allocPixels(info.makeWH(fSubsetWidth, fSubsetHeight));
70
71 scanlineDecoder->skipScanlines(fOffsetTop);
72 uint32_t bpp = info.bytesPerPixel();
73 for (uint32_t y = 0; y < fSubsetHeight; y++) {
74 scanlineDecoder->getScanlines(row.get(), 1, 0);
75 memcpy(bitmap.getAddr(0, y), row.get() + fOffsetLeft * bpp,
76 fSubsetWidth * bpp);
77 }
78 }
79 } else {
80 for (int count = 0; count < n; count++) {
81 SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(fStrea m));
82 int width, height;
83 decoder->buildTileIndex(fStream->duplicate(), &width, &height);
84 SkBitmap bitmap;
85 SkIRect rect = SkIRect::MakeXYWH(fOffsetLeft, fOffsetTop, fSubsetWid th,
86 fSubsetHeight);
87 decoder->decodeSubset(&bitmap, rect, fColorType);
88 }
89 }
90 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698