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

Side by Side Diff: bench/SkipZeroesBench.cpp

Issue 24440002: Bench baseline for mostly 0 image. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Respond to comments and prevent crash. Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « bench/SkBenchmark.cpp ('k') | bench/benchmain.cpp » ('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 2013 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 "SkBenchmark.h"
9 #include "SkBitmap.h"
10 #include "SkData.h"
11 #include "SkForceLinking.h"
12 #include "SkImageDecoder.h"
13 #include "SkOSFile.h"
14 #include "SkStream.h"
15 #include "SkString.h"
16
17 __SK_FORCE_IMAGE_DECODER_LINKING;
18
19 class SkCanvas;
20
21 class SkipZeroesBench : public SkBenchmark {
22 public:
23 SkipZeroesBench(const char* filename, bool skipZeroes)
24 : fName("SkipZeroes_")
25 , fDecoder(NULL)
26 , fFilename(filename)
27 , fStream()
28 , fSkipZeroes(skipZeroes)
29 , fValid(false) {
30 fName.append(filename);
31 if (skipZeroes) {
32 fName.append("_skip_zeroes");
33 } else {
34 fName.append("_write_zeroes");
35 }
36 fIsRendering = false;
37 }
38
39 protected:
40 virtual const char* onGetName() SK_OVERRIDE {
41 return fName.c_str();
42 }
43
44 virtual void onPreDraw() SK_OVERRIDE {
45 const char* resPath = GetResourcePath().c_str();
46 if (NULL == resPath) {
47 fValid = false;
48 return;
49 }
50
51 SkString fullPath = SkOSPath::SkPathJoin(resPath, fFilename.c_str());
52 SkFILEStream fileStream(fullPath.c_str());
53 fValid = fileStream.isValid() && fileStream.getLength() > 0;
54 if (fValid) {
55 const size_t size = fileStream.getLength();
56 void* data = sk_malloc_throw(size);
57 if (fileStream.read(data, size) < size) {
58 fValid = false;
59 } else {
60 SkAutoTUnref<SkData> skdata(SkData::NewFromMalloc(data, size));
61 fStream.setData(skdata.get());
62 fDecoder.reset(SkImageDecoder::Factory(&fStream));
63 if (fDecoder.get()) {
64 // Disabling until the feature is checked in.
65 // See https://codereview.chromium.org/24269006/
66 //fDecoder->setSkipWritingZeroes(fSkipZeroes);
67 } else {
68 fValid = false;
69 }
70 }
71 }
72 }
73
74 virtual void onDraw(SkCanvas*) SK_OVERRIDE {
75 if (!fValid) {
76 #ifdef SK_DEBUG
77 SkDebugf("stream was invalid: %s\n", fFilename.c_str());
78 #endif
79 return;
80 }
81 // Decode a bunch of times
82 SkBitmap bm;
83 for (int i = 0; i < this->getLoops(); ++i) {
84 SkDEBUGCODE(bool success =) fDecoder->decode(&fStream, &bm,
85 SkImageDecoder::kDecode Pixels_Mode);
86 #ifdef SK_DEBUG
87 if (!success) {
88 SkDebugf("failed to decode %s\n", fFilename.c_str());
89 return;
90 }
91 #endif
92 SkDEBUGCODE(success =) fStream.rewind();
93 #ifdef SK_DEBUG
94 if (!success) {
95 SkDebugf("failed to rewind %s\n", fFilename.c_str());
96 return;
97 }
98 #endif
99 }
100 }
101
102 private:
103 SkString fName;
104 SkAutoTDelete<SkImageDecoder> fDecoder;
105 const SkString fFilename;
106 SkMemoryStream fStream;
107 bool fSkipZeroes;
108 bool fValid;
109
110 typedef SkBenchmark INHERITED;
111 };
112
113 // Enable the true version once the feature is checked in.
114 //DEF_BENCH( return SkNEW_ARGS(SkipZeroesBench, ("arrow.png", true)));
115 DEF_BENCH( return SkNEW_ARGS(SkipZeroesBench, ("arrow.png", false)));
OLDNEW
« no previous file with comments | « bench/SkBenchmark.cpp ('k') | bench/benchmain.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698