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

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: Created 7 years, 3 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
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBenchmark.h" 8 #include "SkBenchmark.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkData.h" 10 #include "SkData.h"
11 #include "SkForceLinking.h" 11 #include "SkForceLinking.h"
12 #include "SkImageDecoder.h" 12 #include "SkImageDecoder.h"
13 #include "SkOSFile.h" 13 #include "SkOSFile.h"
14 #include "SkStream.h" 14 #include "SkStream.h"
15 #include "SkString.h" 15 #include "SkString.h"
16 16
17 __SK_FORCE_IMAGE_DECODER_LINKING; 17 __SK_FORCE_IMAGE_DECODER_LINKING;
18 18
19 class SkCanvas; 19 class SkCanvas;
20 20
21 class ImageDecodeBench : public SkBenchmark { 21 class SkipZeroesBench : public SkBenchmark {
22 public: 22 public:
23 ImageDecodeBench(void* p, const char* filename) 23 SkipZeroesBench(const char* filename, bool skipZeroes)
24 : fName("image_decode_") 24 : fName("SkipZeroes_")
25 , fDecoder(NULL)
25 , fFilename(filename) 26 , fFilename(filename)
26 , fStream() 27 , fStream()
28 , fSkipZeroes(skipZeroes)
27 , fValid(false) { 29 , fValid(false) {
28 fName.append(SkOSPath::SkBasename(filename)); 30 fName.append(filename);
31 if (skipZeroes) {
32 fName.append("_skip_zeroes");
33 } else {
34 fName.append("_write_zeroes");
35 }
29 fIsRendering = false; 36 fIsRendering = false;
30 } 37 }
31 38
39 ~SkipZeroesBench() {
40 SkDELETE(fDecoder);
41 }
32 protected: 42 protected:
33 virtual const char* onGetName() SK_OVERRIDE { 43 virtual const char* onGetName() SK_OVERRIDE {
34 return fName.c_str(); 44 return fName.c_str();
35 } 45 }
36 46
37 virtual void onPreDraw() SK_OVERRIDE { 47 virtual void onPreDraw() SK_OVERRIDE {
38 SkFILEStream fileStream(fFilename.c_str()); 48 SkString fullPath = SkOSPath::SkPathJoin(GetResourcePath().c_str(), fFil ename.c_str());
49 SkFILEStream fileStream(fullPath.c_str());
39 fValid = fileStream.isValid() && fileStream.getLength() > 0; 50 fValid = fileStream.isValid() && fileStream.getLength() > 0;
40 if (fValid) { 51 if (fValid) {
41 const size_t size = fileStream.getLength(); 52 const size_t size = fileStream.getLength();
42 void* data = sk_malloc_throw(size); 53 void* data = sk_malloc_throw(size);
43 if (fileStream.read(data, size) < size) { 54 if (fileStream.read(data, size) < size) {
44 fValid = false; 55 fValid = false;
45 } else { 56 } else {
46 SkAutoTUnref<SkData> skdata(SkData::NewFromMalloc(data, size)); 57 SkAutoTUnref<SkData> skdata(SkData::NewFromMalloc(data, size));
47 fStream.setData(skdata.get()); 58 fStream.setData(skdata.get());
59 fDecoder = SkImageDecoder::Factory(&fStream);
60 if (fDecoder) {
61 // Disabling until the feature is checked in.
62 // See https://codereview.chromium.org/24269006/
63 //fDecoder->setSkipWritingZeroes(fSkipZeroes);
64 } else {
65 fValid = false;
66 }
48 } 67 }
49 } 68 }
50 } 69 }
51 70
52 virtual void onDraw(SkCanvas*) SK_OVERRIDE { 71 virtual void onDraw(SkCanvas*) SK_OVERRIDE {
53 #ifdef SK_DEBUG 72 #ifdef SK_DEBUG
54 if (!fValid) { 73 if (!fValid) {
55 SkDebugf("stream was invalid: %s\n", fName.c_str()); 74 SkDebugf("stream was invalid: %s\n", fName.c_str());
56 return; 75 return;
57 } 76 }
58 #endif 77 #endif
59 // Decode a bunch of times 78 // Decode a bunch of times
60 SkBitmap bm; 79 SkBitmap bm;
61 for (int i = 0; i < this->getLoops(); ++i) { 80 for (int i = 0; i < this->getLoops(); ++i) {
62 SkDEBUGCODE(bool success =) SkImageDecoder::DecodeStream(&fStream, & bm); 81 SkDEBUGCODE(bool success =) fDecoder->decode(&fStream, &bm,
82 SkImageDecoder::kDecode Pixels_Mode);
63 #ifdef SK_DEBUG 83 #ifdef SK_DEBUG
64 if (!success) { 84 if (!success) {
65 SkDebugf("failed to decode %s\n", fName.c_str()); 85 SkDebugf("failed to decode %s\n", fName.c_str());
66 return; 86 return;
67 } 87 }
68 #endif 88 #endif
69 SkDEBUGCODE(success =) fStream.rewind(); 89 SkDEBUGCODE(success =) fStream.rewind();
70 #ifdef SK_DEBUG 90 #ifdef SK_DEBUG
71 if (!success) { 91 if (!success) {
72 SkDebugf("failed to rewind %s\n", fName.c_str()); 92 SkDebugf("failed to rewind %s\n", fName.c_str());
73 return; 93 return;
74 } 94 }
75 #endif 95 #endif
76 } 96 }
77 } 97 }
78 98
79 private: 99 private:
80 SkString fName; 100 SkString fName;
101 SkImageDecoder* fDecoder;
mtklein 2013/09/25 13:48:32 SkAutoTDelete?
scroggo 2013/09/25 17:54:57 Done.
81 const SkString fFilename; 102 const SkString fFilename;
82 SkMemoryStream fStream; 103 SkMemoryStream fStream;
104 bool fSkipZeroes;
83 bool fValid; 105 bool fValid;
84 106
85 typedef SkBenchmark INHERITED; 107 typedef SkBenchmark INHERITED;
86 }; 108 };
87 109
88 // These are files which call decodePalette 110 // Enable the true version once the feature is checked in.
89 //DEF_BENCH( return SkNEW_ARGS(ImageDecodeBench, ("/usr/local/google/home/scrogg o/Downloads/images/hal_163x90.png")); ) 111 //DEF_BENCH( return SkNEW_ARGS(SkipZeroesBench, ("arrow.png", true)));
90 //DEF_BENCH( return SkNEW_ARGS(ImageDecodeBench, ("/usr/local/google/home/scrogg o/Downloads/images/box_19_top-left.png")); ) 112 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