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

Side by Side Diff: bench/CodecBench.cpp

Issue 1044363002: Add timing SkCodec to nanobench. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: CodecBench decodes to fColorType, as intended. Created 5 years, 8 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
« no previous file with comments | « bench/CodecBench.h ('k') | bench/DecodingBench.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "CodecBench.h"
9 #include "SkBitmap.h"
10 #include "SkCodec.h"
11 #include "SkImageGenerator.h"
12 #include "SkOSFile.h"
13
14 CodecBench::CodecBench(SkString baseName, SkData* encoded, SkColorType colorType )
15 : fColorType(colorType)
16 , fData(SkRef(encoded))
17 {
18 // Parse filename and the color type to give the benchmark a useful name
19 const char* colorName;
20 switch(colorType) {
21 case kN32_SkColorType:
22 colorName = "N32";
23 break;
24 case kRGB_565_SkColorType:
25 colorName = "565";
26 break;
27 case kAlpha_8_SkColorType:
28 colorName = "Alpha8";
29 break;
30 default:
31 colorName = "Unknown";
32 }
33 fName.printf("Codec_%s_%s", baseName.c_str(), colorName);
34 #ifdef SK_DEBUG
35 // Ensure that we can create an SkCodec from this data.
36 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fData));
37 SkASSERT(codec);
38 #endif
39 }
40
41 const char* CodecBench::onGetName() {
42 return fName.c_str();
43 }
44
45 bool CodecBench::isSuitableFor(Backend backend) {
46 return kNonRendering_Backend == backend;
47 }
48
49 void CodecBench::onPreDraw() {
50 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fData));
51 fBitmap.allocPixels(codec->getInfo().makeColorType(fColorType));
52 }
53
54 void CodecBench::onDraw(const int n, SkCanvas* canvas) {
55 SkAutoTDelete<SkCodec> codec;
56 for (int i = 0; i < n; i++) {
57 codec.reset(SkCodec::NewFromData(fData));
58 #ifdef SK_DEBUG
59 const SkImageGenerator::Result result =
60 #endif
61 // fBitmap.info() was set to use fColorType in onPreDraw.
62 codec->getPixels(fBitmap.info(), fBitmap.getPixels(), fBitmap.rowBytes() );
63 SkASSERT(result == SkImageGenerator::kSuccess
64 || result == SkImageGenerator::kIncompleteInput);
65 }
66 }
OLDNEW
« no previous file with comments | « bench/CodecBench.h ('k') | bench/DecodingBench.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698