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 "Benchmark.h" | 8 #include "Benchmark.h" |
9 #include "Resources.h" | 9 #include "Resources.h" |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 , fSkipZeroes(skipZeroes) | 29 , fSkipZeroes(skipZeroes) |
30 , fValid(false) { | 30 , fValid(false) { |
31 fName.append(filename); | 31 fName.append(filename); |
32 if (skipZeroes) { | 32 if (skipZeroes) { |
33 fName.append("_skip_zeroes"); | 33 fName.append("_skip_zeroes"); |
34 } else { | 34 } else { |
35 fName.append("_write_zeroes"); | 35 fName.append("_write_zeroes"); |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 virtual bool isSuitableFor(Backend backend) SK_OVERRIDE { | 39 bool isSuitableFor(Backend backend) SK_OVERRIDE { |
40 return backend == kNonRendering_Backend; | 40 return backend == kNonRendering_Backend; |
41 } | 41 } |
42 | 42 |
43 protected: | 43 protected: |
44 virtual const char* onGetName() SK_OVERRIDE { | 44 const char* onGetName() SK_OVERRIDE { |
45 return fName.c_str(); | 45 return fName.c_str(); |
46 } | 46 } |
47 | 47 |
48 virtual void onPreDraw() SK_OVERRIDE { | 48 void onPreDraw() SK_OVERRIDE { |
49 SkString resourcePath = GetResourcePath(); | 49 SkString resourcePath = GetResourcePath(); |
50 if (resourcePath.isEmpty()) { | 50 if (resourcePath.isEmpty()) { |
51 fValid = false; | 51 fValid = false; |
52 return; | 52 return; |
53 } | 53 } |
54 | 54 |
55 SkString fullPath = SkOSPath::Join(resourcePath.c_str(), fFilename.c_str
()); | 55 SkString fullPath = SkOSPath::Join(resourcePath.c_str(), fFilename.c_str
()); |
56 SkFILEStream fileStream(fullPath.c_str()); | 56 SkFILEStream fileStream(fullPath.c_str()); |
57 fValid = fileStream.isValid() && fileStream.getLength() > 0; | 57 fValid = fileStream.isValid() && fileStream.getLength() > 0; |
58 if (fValid) { | 58 if (fValid) { |
59 const size_t size = fileStream.getLength(); | 59 const size_t size = fileStream.getLength(); |
60 void* data = sk_malloc_throw(size); | 60 void* data = sk_malloc_throw(size); |
61 if (fileStream.read(data, size) < size) { | 61 if (fileStream.read(data, size) < size) { |
62 fValid = false; | 62 fValid = false; |
63 } else { | 63 } else { |
64 SkAutoTUnref<SkData> skdata(SkData::NewFromMalloc(data, size)); | 64 SkAutoTUnref<SkData> skdata(SkData::NewFromMalloc(data, size)); |
65 fStream.setData(skdata.get()); | 65 fStream.setData(skdata.get()); |
66 fDecoder.reset(SkImageDecoder::Factory(&fStream)); | 66 fDecoder.reset(SkImageDecoder::Factory(&fStream)); |
67 if (fDecoder.get()) { | 67 if (fDecoder.get()) { |
68 fDecoder->setSkipWritingZeroes(fSkipZeroes); | 68 fDecoder->setSkipWritingZeroes(fSkipZeroes); |
69 } else { | 69 } else { |
70 fValid = false; | 70 fValid = false; |
71 } | 71 } |
72 } | 72 } |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
76 virtual void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { | 76 void onDraw(const int loops, SkCanvas*) SK_OVERRIDE { |
77 if (!fValid) { | 77 if (!fValid) { |
78 #ifdef SK_DEBUG | 78 #ifdef SK_DEBUG |
79 SkDebugf("stream was invalid: %s\n", fFilename.c_str()); | 79 SkDebugf("stream was invalid: %s\n", fFilename.c_str()); |
80 #endif | 80 #endif |
81 return; | 81 return; |
82 } | 82 } |
83 // Decode a bunch of times | 83 // Decode a bunch of times |
84 SkBitmap bm; | 84 SkBitmap bm; |
85 for (int i = 0; i < loops; ++i) { | 85 for (int i = 0; i < loops; ++i) { |
86 SkDEBUGCODE(SkImageDecoder::Result result =) fDecoder->decode(&fStre
am, &bm, | 86 SkDEBUGCODE(SkImageDecoder::Result result =) fDecoder->decode(&fStre
am, &bm, |
(...skipping 21 matching lines...) Expand all Loading... |
108 SkMemoryStream fStream; | 108 SkMemoryStream fStream; |
109 bool fSkipZeroes; | 109 bool fSkipZeroes; |
110 bool fValid; | 110 bool fValid; |
111 | 111 |
112 typedef Benchmark INHERITED; | 112 typedef Benchmark INHERITED; |
113 }; | 113 }; |
114 | 114 |
115 // Enable the true version once the feature is checked in. | 115 // Enable the true version once the feature is checked in. |
116 DEF_BENCH( return SkNEW_ARGS(SkipZeroesBench, ("arrow.png", true))); | 116 DEF_BENCH( return SkNEW_ARGS(SkipZeroesBench, ("arrow.png", true))); |
117 DEF_BENCH( return SkNEW_ARGS(SkipZeroesBench, ("arrow.png", false))); | 117 DEF_BENCH( return SkNEW_ARGS(SkipZeroesBench, ("arrow.png", false))); |
OLD | NEW |