OLD | NEW |
---|---|
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(SkOSPath::SkBasename(filename)); |
31 if (skipZeroes) { | |
32 fName.append("_skip_zeroes"); | |
33 } | |
29 fIsRendering = false; | 34 fIsRendering = false; |
30 } | 35 } |
31 | 36 |
37 ~SkipZeroesBench() { | |
38 SkDELETE(fDecoder); | |
39 } | |
32 protected: | 40 protected: |
33 virtual const char* onGetName() SK_OVERRIDE { | 41 virtual const char* onGetName() SK_OVERRIDE { |
34 return fName.c_str(); | 42 return fName.c_str(); |
35 } | 43 } |
36 | 44 |
37 virtual void onPreDraw() SK_OVERRIDE { | 45 virtual void onPreDraw() SK_OVERRIDE { |
38 SkFILEStream fileStream(fFilename.c_str()); | 46 SkFILEStream fileStream(fFilename.c_str()); |
39 fValid = fileStream.isValid() && fileStream.getLength() > 0; | 47 fValid = fileStream.isValid() && fileStream.getLength() > 0; |
40 if (fValid) { | 48 if (fValid) { |
41 const size_t size = fileStream.getLength(); | 49 const size_t size = fileStream.getLength(); |
42 void* data = sk_malloc_throw(size); | 50 void* data = sk_malloc_throw(size); |
43 if (fileStream.read(data, size) < size) { | 51 if (fileStream.read(data, size) < size) { |
44 fValid = false; | 52 fValid = false; |
45 } else { | 53 } else { |
46 SkAutoTUnref<SkData> skdata(SkData::NewFromMalloc(data, size)); | 54 SkAutoTUnref<SkData> skdata(SkData::NewFromMalloc(data, size)); |
47 fStream.setData(skdata.get()); | 55 fStream.setData(skdata.get()); |
56 fDecoder = SkImageDecoder::Factory(&fStream); | |
57 if (fDecoder) { | |
58 fDecoder->setSkipWritingZeroes(fSkipZeroes); | |
59 } else { | |
60 fValid = false; | |
61 } | |
48 } | 62 } |
49 } | 63 } |
50 } | 64 } |
51 | 65 |
52 virtual void onDraw(SkCanvas*) SK_OVERRIDE { | 66 virtual void onDraw(SkCanvas*) SK_OVERRIDE { |
53 #ifdef SK_DEBUG | 67 #ifdef SK_DEBUG |
54 if (!fValid) { | 68 if (!fValid) { |
55 SkDebugf("stream was invalid: %s\n", fName.c_str()); | 69 SkDebugf("stream was invalid: %s\n", fName.c_str()); |
56 return; | 70 return; |
57 } | 71 } |
58 #endif | 72 #endif |
59 // Decode a bunch of times | 73 // Decode a bunch of times |
60 SkBitmap bm; | 74 SkBitmap bm; |
61 for (int i = 0; i < this->getLoops(); ++i) { | 75 for (int i = 0; i < this->getLoops(); ++i) { |
62 SkDEBUGCODE(bool success =) SkImageDecoder::DecodeStream(&fStream, & bm); | 76 SkDEBUGCODE(bool success =) fDecoder->decode(&fStream, &bm, SkImageD ecoder::kDecodePixels_Mode); |
63 #ifdef SK_DEBUG | 77 #ifdef SK_DEBUG |
64 if (!success) { | 78 if (!success) { |
65 SkDebugf("failed to decode %s\n", fName.c_str()); | 79 SkDebugf("failed to decode %s\n", fName.c_str()); |
66 return; | 80 return; |
67 } | 81 } |
68 #endif | 82 #endif |
69 SkDEBUGCODE(success =) fStream.rewind(); | 83 SkDEBUGCODE(success =) fStream.rewind(); |
70 #ifdef SK_DEBUG | 84 #ifdef SK_DEBUG |
71 if (!success) { | 85 if (!success) { |
72 SkDebugf("failed to rewind %s\n", fName.c_str()); | 86 SkDebugf("failed to rewind %s\n", fName.c_str()); |
73 return; | 87 return; |
74 } | 88 } |
75 #endif | 89 #endif |
76 } | 90 } |
77 } | 91 } |
78 | 92 |
79 private: | 93 private: |
80 SkString fName; | 94 SkString fName; |
95 SkImageDecoder* fDecoder; | |
81 const SkString fFilename; | 96 const SkString fFilename; |
82 SkMemoryStream fStream; | 97 SkMemoryStream fStream; |
98 bool fSkipZeroes; | |
83 bool fValid; | 99 bool fValid; |
84 | 100 |
85 typedef SkBenchmark INHERITED; | 101 typedef SkBenchmark INHERITED; |
86 }; | 102 }; |
87 | 103 |
88 // These are files which call decodePalette | 104 //DEF_BENCH( return SkNEW_ARGS(SkipZeroesBench, ("/sdcard/skia/images/arrow.png" , true))); |
djsollen
2013/09/19 19:41:17
seems like we should be able to supply a resources
scroggo
2013/09/19 21:07:21
I can add this next week. Also as a note to myself
| |
89 //DEF_BENCH( return SkNEW_ARGS(ImageDecodeBench, ("/usr/local/google/home/scrogg o/Downloads/images/hal_163x90.png")); ) | 105 //DEF_BENCH( return SkNEW_ARGS(SkipZeroesBench, ("/sdcard/skia/images/arrow.png" , false))); |
90 //DEF_BENCH( return SkNEW_ARGS(ImageDecodeBench, ("/usr/local/google/home/scrogg o/Downloads/images/box_19_top-left.png")); ) | |
OLD | NEW |