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

Side by Side Diff: bench/DecodingSubsetBench.cpp

Issue 918673002: Adding new benchmark to test image decoding performance. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fail less loudly, subset error message only printed once. Created 5 years, 10 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 "DecodingSubsetBench.h"
9 #include "SkData.h"
10 #include "SkImageDecoder.h"
11 #include "SkOSFile.h"
12 #include "SkStream.h"
13
14 /*
15 *
16 * This benchmark is designed to test the performance of image decoding.
17 * It is invoked from the nanobench.cpp file.
18 *
19 */
20 DecodingSubsetBench::DecodingSubsetBench(SkString path, SkColorType colorType,
21 const int divisor)
22 : fPath(path)
23 , fColorType(colorType)
24 , fDivisor(divisor)
25 {
26 // Parse filename and the color type to give the benchmark a useful name
27 SkString baseName = SkOSPath::Basename(path.c_str());
28 const char* colorName;
29 switch(colorType) {
30 case kN32_SkColorType:
31 colorName = "N32";
32 break;
33 case kRGB_565_SkColorType:
34 colorName = "565";
35 break;
36 case kAlpha_8_SkColorType:
37 colorName = "Alpha8";
38 break;
39 default:
40 colorName = "Unknown";
41 }
42 fName.printf("DecodeSubset_%dx%d_%s_%s", fDivisor, fDivisor,
43 baseName.c_str(), colorName);
44 }
45
46 const char* DecodingSubsetBench::onGetName() {
47 return fName.c_str();
48 }
49
50 bool DecodingSubsetBench::isSuitableFor(Backend backend) {
51 return kNonRendering_Backend == backend;
52 }
53
54 void DecodingSubsetBench::onDraw(const int n, SkCanvas* canvas) {
55 // Perform the decode setup
56 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
57 SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded));
58 SkAutoTDelete<SkImageDecoder>
59 decoder(SkImageDecoder::Factory(stream.get()));
60
61 // Repeat the subset decode n times
62 for (int i = 0; i < n; i++) {
63 stream->rewind();
64 int w, h;
65 decoder->buildTileIndex(stream.detach(), &w, &h);
66 // Divide the image into subsets and decode each subset
67 const int sW = w / fDivisor;
68 const int sH = h / fDivisor;
69 for (int y = 0; y < h; y += sH) {
70 for (int x = 0; x < w; x += sW) {
71 SkBitmap bitmap;
72 SkIRect rect = SkIRect::MakeXYWH(x, y, sW, sH);
73 decoder->decodeSubset(&bitmap, rect, fColorType);
74 }
75 }
76 }
77 }
OLDNEW
« no previous file with comments | « bench/DecodingSubsetBench.h ('k') | bench/ImageDecodeBench.cpp » ('j') | bench/nanobench.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698