OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "BenchTimer.h" | 8 #include "BenchTimer.h" |
9 #include "CopyTilesRenderer.h" | 9 #include "CopyTilesRenderer.h" |
10 #include "PictureBenchmark.h" | 10 #include "PictureBenchmark.h" |
11 #include "PictureRenderingFlags.h" | 11 #include "PictureRenderingFlags.h" |
12 #include "SkBenchLogger.h" | 12 #include "SkBenchLogger.h" |
13 #include "SkBitmapFactory.h" | 13 #include "SkBitmapFactory.h" |
14 #include "SkCanvas.h" | 14 #include "SkCanvas.h" |
15 #include "SkFlags.h" | 15 #include "SkFlags.h" |
16 #include "SkGraphics.h" | 16 #include "SkGraphics.h" |
17 #include "SkImageDecoder.h" | 17 #include "SkImageDecoder.h" |
18 #include "SkMath.h" | 18 #include "SkMath.h" |
19 #include "SkOSFile.h" | 19 #include "SkOSFile.h" |
20 #include "SkPicture.h" | 20 #include "SkPicture.h" |
21 #include "SkStream.h" | 21 #include "SkStream.h" |
22 #include "SkTArray.h" | 22 #include "SkTArray.h" |
23 #include "picture_utils.h" | 23 #include "picture_utils.h" |
24 | 24 |
25 | 25 |
26 SkBenchLogger gLogger; | 26 SkBenchLogger gLogger; |
27 | 27 |
28 // Flags used by this file, in alphabetical order. | 28 // Flags used by this file, in alphabetical order. |
| 29 DEFINE_bool(countRAM, false, "Count the RAM used for bitmap pixels in each skp f
ile"); |
29 DECLARE_bool(deferImageDecoding); | 30 DECLARE_bool(deferImageDecoding); |
30 DEFINE_string(filter, "", | 31 DEFINE_string(filter, "", |
31 "type:flag : Enable canvas filtering to disable a paint flag, " | 32 "type:flag : Enable canvas filtering to disable a paint flag, " |
32 "use no blur or low quality blur, or use no hinting or " | 33 "use no blur or low quality blur, or use no hinting or " |
33 "slight hinting. For all flags except AAClip, specify the " | 34 "slight hinting. For all flags except AAClip, specify the " |
34 "type of primitive to effect, or choose all. for AAClip " | 35 "type of primitive to effect, or choose all. for AAClip " |
35 "alone, the filter affects all clips independent of type. " | 36 "alone, the filter affects all clips independent of type. " |
36 "Specific flags are listed above."); | 37 "Specific flags are listed above."); |
37 DEFINE_string(logFile, "", "Destination for writing log output, in addition to s
tdout."); | 38 DEFINE_string(logFile, "", "Destination for writing log output, in addition to s
tdout."); |
38 DEFINE_bool(logPerIter, false, "Log each repeat timer instead of mean."); | 39 DEFINE_bool(logPerIter, false, "Log each repeat timer instead of mean."); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 SkFILEStream inputStream; | 167 SkFILEStream inputStream; |
167 | 168 |
168 inputStream.setPath(inputPath.c_str()); | 169 inputStream.setPath(inputPath.c_str()); |
169 if (!inputStream.isValid()) { | 170 if (!inputStream.isValid()) { |
170 SkString err; | 171 SkString err; |
171 err.printf("Could not open file %s\n", inputPath.c_str()); | 172 err.printf("Could not open file %s\n", inputPath.c_str()); |
172 gLogger.logError(err); | 173 gLogger.logError(err); |
173 return false; | 174 return false; |
174 } | 175 } |
175 | 176 |
| 177 // Since the old picture has been deleted, all pixels should be cleared. |
| 178 SkASSERT(gLruImageCache.getImageCacheUsed() == 0); |
| 179 if (FLAGS_countRAM) { |
| 180 // Set the limit to zero, so all pixels will be kept |
| 181 gLruImageCache.setImageCacheLimit(0); |
| 182 } |
| 183 |
176 bool success = false; | 184 bool success = false; |
177 SkPicture* picture; | 185 SkPicture* picture; |
178 if (FLAGS_deferImageDecoding) { | 186 if (FLAGS_deferImageDecoding) { |
179 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &lazy_decode_bi
tmap)); | 187 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &lazy_decode_bi
tmap)); |
180 } else { | 188 } else { |
181 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &SkImageDecoder
::DecodeMemory)); | 189 picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &SkImageDecoder
::DecodeMemory)); |
182 } | 190 } |
183 SkAutoTDelete<SkPicture> ad(picture); | 191 SkAutoTDelete<SkPicture> ad(picture); |
184 | 192 |
185 if (!success) { | 193 if (!success) { |
(...skipping 11 matching lines...) Expand all Loading... |
197 filename.c_str()); | 205 filename.c_str()); |
198 gLogger.logProgress(result); | 206 gLogger.logProgress(result); |
199 | 207 |
200 benchmark.run(picture); | 208 benchmark.run(picture); |
201 | 209 |
202 #if LAZY_CACHE_STATS | 210 #if LAZY_CACHE_STATS |
203 if (FLAGS_trackDeferredCaching) { | 211 if (FLAGS_trackDeferredCaching) { |
204 int32_t cacheHits = SkLazyPixelRef::GetCacheHits(); | 212 int32_t cacheHits = SkLazyPixelRef::GetCacheHits(); |
205 int32_t cacheMisses = SkLazyPixelRef::GetCacheMisses(); | 213 int32_t cacheMisses = SkLazyPixelRef::GetCacheMisses(); |
206 SkLazyPixelRef::ResetCacheStats(); | 214 SkLazyPixelRef::ResetCacheStats(); |
207 SkDebugf("Cache hit rate: %f\n", (double) cacheHits / (cacheHits + cache
Misses)); | 215 SkString hitString; |
| 216 hitString.printf("Cache hit rate: %f\n", (double) cacheHits / (cacheHits
+ cacheMisses)); |
| 217 gLogger.logProgress(hitString); |
208 gTotalCacheHits += cacheHits; | 218 gTotalCacheHits += cacheHits; |
209 gTotalCacheMisses += cacheMisses; | 219 gTotalCacheMisses += cacheMisses; |
210 } | 220 } |
211 #endif | 221 #endif |
| 222 if (FLAGS_countRAM) { |
| 223 SkString ramCount("RAM used for bitmaps: "); |
| 224 size_t bytes = gLruImageCache.getImageCacheUsed(); |
| 225 if (bytes > 1024) { |
| 226 size_t kb = bytes / 1024; |
| 227 if (kb > 1024) { |
| 228 size_t mb = kb / 1024; |
| 229 ramCount.appendf("%zi MB\n", mb); |
| 230 } else { |
| 231 ramCount.appendf("%zi KB\n", kb); |
| 232 } |
| 233 } else { |
| 234 ramCount.appendf("%zi bytes\n", bytes); |
| 235 } |
| 236 gLogger.logProgress(ramCount); |
| 237 } |
212 | 238 |
213 return true; | 239 return true; |
214 } | 240 } |
215 | 241 |
216 static void setup_benchmark(sk_tools::PictureBenchmark* benchmark) { | 242 static void setup_benchmark(sk_tools::PictureBenchmark* benchmark) { |
217 sk_tools::PictureRenderer::DrawFilterFlags drawFilters[SkDrawFilter::kTypeCo
unt]; | 243 sk_tools::PictureRenderer::DrawFilterFlags drawFilters[SkDrawFilter::kTypeCo
unt]; |
218 sk_bzero(drawFilters, sizeof(drawFilters)); | 244 sk_bzero(drawFilters, sizeof(drawFilters)); |
219 | 245 |
220 if (FLAGS_filter.count() > 0) { | 246 if (FLAGS_filter.count() > 0) { |
221 const char* filters = FLAGS_filter[0]; | 247 const char* filters = FLAGS_filter[0]; |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 } | 450 } |
425 #endif | 451 #endif |
426 return 0; | 452 return 0; |
427 } | 453 } |
428 | 454 |
429 #if !defined SK_BUILD_FOR_IOS | 455 #if !defined SK_BUILD_FOR_IOS |
430 int main(int argc, char * const argv[]) { | 456 int main(int argc, char * const argv[]) { |
431 return tool_main(argc, (char**) argv); | 457 return tool_main(argc, (char**) argv); |
432 } | 458 } |
433 #endif | 459 #endif |
OLD | NEW |