| 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 "LazyDecodeBitmap.h" | 10 #include "LazyDecodeBitmap.h" |
| 11 #include "PictureBenchmark.h" | 11 #include "PictureBenchmark.h" |
| 12 #include "PictureRenderingFlags.h" | 12 #include "PictureRenderingFlags.h" |
| 13 #include "SkBenchLogger.h" | 13 #include "SkBenchLogger.h" |
| 14 #include "SkCommandLineFlags.h" | 14 #include "SkCommandLineFlags.h" |
| 15 #include "SkDiscardableMemoryPool.h" |
| 15 #include "SkGraphics.h" | 16 #include "SkGraphics.h" |
| 16 #include "SkImageDecoder.h" | 17 #include "SkImageDecoder.h" |
| 17 #if LAZY_CACHE_STATS | |
| 18 #include "SkLazyPixelRef.h" | |
| 19 #endif | |
| 20 #include "SkLruImageCache.h" | |
| 21 #include "SkMath.h" | 18 #include "SkMath.h" |
| 22 #include "SkOSFile.h" | 19 #include "SkOSFile.h" |
| 23 #include "SkPicture.h" | 20 #include "SkPicture.h" |
| 24 #include "SkStream.h" | 21 #include "SkStream.h" |
| 25 #include "picture_utils.h" | 22 #include "picture_utils.h" |
| 26 | 23 |
| 27 SkBenchLogger gLogger; | 24 SkBenchLogger gLogger; |
| 28 | 25 |
| 29 // Flags used by this file, in alphabetical order. | 26 // Flags used by this file, in alphabetical order. |
| 30 DEFINE_bool(countRAM, false, "Count the RAM used for bitmap pixels in each skp f
ile"); | 27 DEFINE_bool(countRAM, false, "Count the RAM used for bitmap pixels in each skp f
ile"); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 result += "\n\t\t"; | 133 result += "\n\t\t"; |
| 137 len = result.size(); | 134 len = result.size(); |
| 138 } | 135 } |
| 139 if (index < kFilterFlagsCount - 1) { | 136 if (index < kFilterFlagsCount - 1) { |
| 140 result += " | "; | 137 result += " | "; |
| 141 } | 138 } |
| 142 } | 139 } |
| 143 return result; | 140 return result; |
| 144 } | 141 } |
| 145 | 142 |
| 146 // Defined in LazyDecodeBitmap.cpp | |
| 147 extern SkLruImageCache gLruImageCache; | |
| 148 | |
| 149 #if LAZY_CACHE_STATS | 143 #if LAZY_CACHE_STATS |
| 150 static int32_t gTotalCacheHits; | 144 static int32_t gTotalCacheHits; |
| 151 static int32_t gTotalCacheMisses; | 145 static int32_t gTotalCacheMisses; |
| 152 #endif | 146 #endif |
| 153 | 147 |
| 154 static bool run_single_benchmark(const SkString& inputPath, | 148 static bool run_single_benchmark(const SkString& inputPath, |
| 155 sk_tools::PictureBenchmark& benchmark) { | 149 sk_tools::PictureBenchmark& benchmark) { |
| 156 SkFILEStream inputStream; | 150 SkFILEStream inputStream; |
| 157 | 151 |
| 158 inputStream.setPath(inputPath.c_str()); | 152 inputStream.setPath(inputPath.c_str()); |
| 159 if (!inputStream.isValid()) { | 153 if (!inputStream.isValid()) { |
| 160 SkString err; | 154 SkString err; |
| 161 err.printf("Could not open file %s\n", inputPath.c_str()); | 155 err.printf("Could not open file %s\n", inputPath.c_str()); |
| 162 gLogger.logError(err); | 156 gLogger.logError(err); |
| 163 return false; | 157 return false; |
| 164 } | 158 } |
| 165 | 159 |
| 160 SkDiscardableMemoryPool* pool = SkGetGlobalDiscardableMemoryPool(); |
| 166 // Since the old picture has been deleted, all pixels should be cleared. | 161 // Since the old picture has been deleted, all pixels should be cleared. |
| 167 SkASSERT(gLruImageCache.getImageCacheUsed() == 0); | 162 SkASSERT(pool->getRAMUsed() == 0); |
| 168 if (FLAGS_countRAM) { | 163 if (FLAGS_countRAM) { |
| 169 // Set the limit to zero, so all pixels will be kept | 164 pool->setRAMBudget(SK_MaxU32); |
| 170 gLruImageCache.setImageCacheLimit(0); | 165 // Set the limit to max, so all pixels will be kept |
| 171 } | 166 } |
| 172 | 167 |
| 173 SkPicture::InstallPixelRefProc proc; | 168 SkPicture::InstallPixelRefProc proc; |
| 174 if (FLAGS_deferImageDecoding) { | 169 if (FLAGS_deferImageDecoding) { |
| 175 proc = &sk_tools::LazyDecodeBitmap; | 170 proc = &sk_tools::LazyDecodeBitmap; |
| 176 } else { | 171 } else { |
| 177 proc = &SkImageDecoder::DecodeMemory; | 172 proc = &SkImageDecoder::DecodeMemory; |
| 178 } | 173 } |
| 179 SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&inputStream, pr
oc)); | 174 SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&inputStream, pr
oc)); |
| 180 | 175 |
| 181 if (NULL == picture.get()) { | 176 if (NULL == picture.get()) { |
| 182 SkString err; | 177 SkString err; |
| 183 err.printf("Could not read an SkPicture from %s\n", inputPath.c_str()); | 178 err.printf("Could not read an SkPicture from %s\n", inputPath.c_str()); |
| 184 gLogger.logError(err); | 179 gLogger.logError(err); |
| 185 return false; | 180 return false; |
| 186 } | 181 } |
| 187 | 182 |
| 188 SkString filename; | 183 SkString filename; |
| 189 sk_tools::get_basename(&filename, inputPath); | 184 sk_tools::get_basename(&filename, inputPath); |
| 190 | 185 |
| 191 SkString result; | 186 SkString result; |
| 192 result.printf("running bench [%i %i] %s ", picture->width(), picture->height
(), | 187 result.printf("running bench [%i %i] %s ", picture->width(), picture->height
(), |
| 193 filename.c_str()); | 188 filename.c_str()); |
| 194 gLogger.logProgress(result); | 189 gLogger.logProgress(result); |
| 195 | 190 |
| 196 benchmark.run(picture); | 191 benchmark.run(picture); |
| 197 | 192 |
| 198 #if LAZY_CACHE_STATS | 193 #if LAZY_CACHE_STATS |
| 199 if (FLAGS_trackDeferredCaching) { | 194 if (FLAGS_trackDeferredCaching) { |
| 200 int32_t cacheHits = SkLazyPixelRef::GetCacheHits(); | 195 int32_t cacheHits = pool->fCacheHits; |
| 201 int32_t cacheMisses = SkLazyPixelRef::GetCacheMisses(); | 196 int32_t cacheMisses = pool->fCacheMisses; |
| 202 SkLazyPixelRef::ResetCacheStats(); | 197 pool->fCacheHits = pool->fCacheMisses = 0; |
| 203 SkString hitString; | 198 SkString hitString; |
| 204 hitString.printf("Cache hit rate: %f\n", (double) cacheHits / (cacheHits
+ cacheMisses)); | 199 hitString.printf("Cache hit rate: %f\n", (double) cacheHits / (cacheHits
+ cacheMisses)); |
| 205 gLogger.logProgress(hitString); | 200 gLogger.logProgress(hitString); |
| 206 gTotalCacheHits += cacheHits; | 201 gTotalCacheHits += cacheHits; |
| 207 gTotalCacheMisses += cacheMisses; | 202 gTotalCacheMisses += cacheMisses; |
| 208 } | 203 } |
| 209 #endif | 204 #endif |
| 210 if (FLAGS_countRAM) { | 205 if (FLAGS_countRAM) { |
| 211 SkString ramCount("RAM used for bitmaps: "); | 206 SkString ramCount("RAM used for bitmaps: "); |
| 212 size_t bytes = gLruImageCache.getImageCacheUsed(); | 207 size_t bytes = pool->getRAMUsed(); |
| 213 if (bytes > 1024) { | 208 if (bytes > 1024) { |
| 214 size_t kb = bytes / 1024; | 209 size_t kb = bytes / 1024; |
| 215 if (kb > 1024) { | 210 if (kb > 1024) { |
| 216 size_t mb = kb / 1024; | 211 size_t mb = kb / 1024; |
| 217 ramCount.appendf("%zi MB\n", mb); | 212 ramCount.appendf("%zi MB\n", mb); |
| 218 } else { | 213 } else { |
| 219 ramCount.appendf("%zi KB\n", kb); | 214 ramCount.appendf("%zi KB\n", kb); |
| 220 } | 215 } |
| 221 } else { | 216 } else { |
| 222 ramCount.appendf("%zi bytes\n", bytes); | 217 ramCount.appendf("%zi bytes\n", bytes); |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 } | 438 } |
| 444 #endif | 439 #endif |
| 445 return 0; | 440 return 0; |
| 446 } | 441 } |
| 447 | 442 |
| 448 #if !defined SK_BUILD_FOR_IOS | 443 #if !defined SK_BUILD_FOR_IOS |
| 449 int main(int argc, char * const argv[]) { | 444 int main(int argc, char * const argv[]) { |
| 450 return tool_main(argc, (char**) argv); | 445 return tool_main(argc, (char**) argv); |
| 451 } | 446 } |
| 452 #endif | 447 #endif |
| OLD | NEW |