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

Side by Side Diff: bench/DecodingBench.cpp

Issue 918673002: Adding new benchmark to test image decoding performance. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Missed a few minor comments (sorry!) 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 "DecodingBench.h"
9 #include "SkImageDecoder.h"
10 #include "SkOSFile.h"
11 #include "SkStream.h"
12
13 /*
14 *
15 * This benchmark is designed to test the performance of image decoding.
16 * It is invoked from the nanobench.cpp file.
17 *
18 */
19 DecodingBench::DecodingBench(SkString path, SkColorType colorType)
20 : fPath(path)
21 , fColorType(colorType)
22 {
23 // Parse filename and the color type to give the benchmark a useful name
24 SkString baseName = SkOSPath::Basename(path.c_str());
25 const char* colorName;
26 switch(colorType) {
27 case kN32_SkColorType:
28 colorName = "N32";
29 break;
30 case kRGB_565_SkColorType:
31 colorName = "565";
32 break;
33 case kAlpha_8_SkColorType:
34 colorName = "Alpha8";
35 break;
36 default:
37 colorName = "Unknown";
38 }
39 fName.printf("Decode_%s_%s", baseName.c_str(), colorName);
40 }
41
42 const char* DecodingBench::onGetName() {
43 return fName.c_str();
44 }
45
46 bool DecodingBench::isSuitableFor(Backend backend) {
47 return kNonRendering_Backend == backend;
48 }
49
50 void DecodingBench::onDraw(const int n, SkCanvas* canvas) {
51 // Perform setup for the decode
52 SkAutoTDelete<SkStreamRewindable> stream(
scroggo 2015/02/12 19:53:28 I was thinking more like what DM does: Read the fi
msarett 2015/02/12 22:05:45 Yes this makes significantly more sense.
53 SkStream::NewFromFile(fPath.c_str()));
54 SkImageDecoder* decoder = SkImageDecoder::Factory(stream);
55 SkBitmap bitmap;
56
57 // Decode each image file n times
58 for (int i = 0; i < n; i++) {
59 decoder->decode(stream, &bitmap, fColorType,
60 SkImageDecoder::kDecodePixels_Mode);
61 stream->rewind();
62 }
63
64 // Clean up after the decode
65 delete decoder;
66 }
OLDNEW
« no previous file with comments | « bench/DecodingBench.h ('k') | bench/DecodingSubsetBench.h » ('j') | bench/nanobench.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698