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

Side by Side Diff: tools/bench_pictures_main.cpp

Issue 19109002: Add the lazy decoder from PictureFlags to SkImageDecoder (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Remove unnecessary dependency Created 7 years, 5 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
OLDNEW
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 "SkCommandLineFlags.h" 13 #include "SkCommandLineFlags.h"
14 #include "SkForceLinking.h"
15 #include "SkGraphics.h" 14 #include "SkGraphics.h"
16 #include "SkImageDecoder.h" 15 #include "SkImageDecoder.h"
17 #if LAZY_CACHE_STATS 16 #if LAZY_CACHE_STATS
18 #include "SkLazyPixelRef.h" 17 #include "SkLazyPixelRef.h"
19 #endif 18 #endif
20 #include "SkLruImageCache.h" 19 #include "SkLruImageCache.h"
21 #include "SkMath.h" 20 #include "SkMath.h"
22 #include "SkOSFile.h" 21 #include "SkOSFile.h"
23 #include "SkPicture.h" 22 #include "SkPicture.h"
24 #include "SkStream.h" 23 #include "SkStream.h"
25 #include "picture_utils.h" 24 #include "picture_utils.h"
26 25
27 __SK_FORCE_IMAGE_DECODER_LINKING;
28
29 SkBenchLogger gLogger; 26 SkBenchLogger gLogger;
30 27
31 // Flags used by this file, in alphabetical order. 28 // Flags used by this file, in alphabetical order.
32 DEFINE_bool(countRAM, false, "Count the RAM used for bitmap pixels in each skp f ile"); 29 DEFINE_bool(countRAM, false, "Count the RAM used for bitmap pixels in each skp f ile");
33 DECLARE_bool(deferImageDecoding); 30 DECLARE_bool(deferImageDecoding);
34 DEFINE_string(filter, "", 31 DEFINE_string(filter, "",
35 "type:flag : Enable canvas filtering to disable a paint flag, " 32 "type:flag : Enable canvas filtering to disable a paint flag, "
36 "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 "
37 "slight hinting. For all flags except AAClip, specify the " 34 "slight hinting. For all flags except AAClip, specify the "
38 "type of primitive to effect, or choose all. for AAClip " 35 "type of primitive to effect, or choose all. for AAClip "
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 result += "\n\t\t"; 135 result += "\n\t\t";
139 len = result.size(); 136 len = result.size();
140 } 137 }
141 if (index < kFilterFlagsCount - 1) { 138 if (index < kFilterFlagsCount - 1) {
142 result += " | "; 139 result += " | ";
143 } 140 }
144 } 141 }
145 return result; 142 return result;
146 } 143 }
147 144
148 // These are defined in PictureRenderingFlags.cpp
149 extern SkLruImageCache gLruImageCache;
150 extern bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap );
151
152 #if LAZY_CACHE_STATS 145 #if LAZY_CACHE_STATS
153 static int32_t gTotalCacheHits; 146 static int32_t gTotalCacheHits;
154 static int32_t gTotalCacheMisses; 147 static int32_t gTotalCacheMisses;
155 #endif 148 #endif
156 149
157 static bool run_single_benchmark(const SkString& inputPath, 150 static bool run_single_benchmark(const SkString& inputPath,
158 sk_tools::PictureBenchmark& benchmark) { 151 sk_tools::PictureBenchmark& benchmark) {
159 SkFILEStream inputStream; 152 SkFILEStream inputStream;
160 153
161 inputStream.setPath(inputPath.c_str()); 154 inputStream.setPath(inputPath.c_str());
162 if (!inputStream.isValid()) { 155 if (!inputStream.isValid()) {
163 SkString err; 156 SkString err;
164 err.printf("Could not open file %s\n", inputPath.c_str()); 157 err.printf("Could not open file %s\n", inputPath.c_str());
165 gLogger.logError(err); 158 gLogger.logError(err);
166 return false; 159 return false;
167 } 160 }
168 161
169 // Since the old picture has been deleted, all pixels should be cleared. 162 // Since the old picture has been deleted, all pixels should be cleared.
170 SkASSERT(gLruImageCache.getImageCacheUsed() == 0); 163 SkLruImageCache* gLruImageCache = SkImageDecoder::getLruImageCache();
164 SkASSERT(gLruImageCache->getImageCacheUsed() == 0);
171 if (FLAGS_countRAM) { 165 if (FLAGS_countRAM) {
172 // Set the limit to zero, so all pixels will be kept 166 // Set the limit to zero, so all pixels will be kept
173 gLruImageCache.setImageCacheLimit(0); 167 gLruImageCache->setImageCacheLimit(0);
174 } 168 }
175 169
176 SkPicture::InstallPixelRefProc proc; 170 SkPicture::InstallPixelRefProc proc;
177 if (FLAGS_deferImageDecoding) { 171 if (FLAGS_deferImageDecoding) {
178 proc = &lazy_decode_bitmap; 172 proc = &SkImageDecoder::LazyDecodeBitmap;
179 } else { 173 } else {
180 proc = &SkImageDecoder::DecodeMemory; 174 proc = &SkImageDecoder::DecodeMemory;
181 } 175 }
182 SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&inputStream, pr oc)); 176 SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&inputStream, pr oc));
183 177
184 if (NULL == picture.get()) { 178 if (NULL == picture.get()) {
185 SkString err; 179 SkString err;
186 err.printf("Could not read an SkPicture from %s\n", inputPath.c_str()); 180 err.printf("Could not read an SkPicture from %s\n", inputPath.c_str());
187 gLogger.logError(err); 181 gLogger.logError(err);
188 return false; 182 return false;
(...skipping 16 matching lines...) Expand all
205 SkLazyPixelRef::ResetCacheStats(); 199 SkLazyPixelRef::ResetCacheStats();
206 SkString hitString; 200 SkString hitString;
207 hitString.printf("Cache hit rate: %f\n", (double) cacheHits / (cacheHits + cacheMisses)); 201 hitString.printf("Cache hit rate: %f\n", (double) cacheHits / (cacheHits + cacheMisses));
208 gLogger.logProgress(hitString); 202 gLogger.logProgress(hitString);
209 gTotalCacheHits += cacheHits; 203 gTotalCacheHits += cacheHits;
210 gTotalCacheMisses += cacheMisses; 204 gTotalCacheMisses += cacheMisses;
211 } 205 }
212 #endif 206 #endif
213 if (FLAGS_countRAM) { 207 if (FLAGS_countRAM) {
214 SkString ramCount("RAM used for bitmaps: "); 208 SkString ramCount("RAM used for bitmaps: ");
215 size_t bytes = gLruImageCache.getImageCacheUsed(); 209 size_t bytes = gLruImageCache->getImageCacheUsed();
216 if (bytes > 1024) { 210 if (bytes > 1024) {
217 size_t kb = bytes / 1024; 211 size_t kb = bytes / 1024;
218 if (kb > 1024) { 212 if (kb > 1024) {
219 size_t mb = kb / 1024; 213 size_t mb = kb / 1024;
220 ramCount.appendf("%zi MB\n", mb); 214 ramCount.appendf("%zi MB\n", mb);
221 } else { 215 } else {
222 ramCount.appendf("%zi KB\n", kb); 216 ramCount.appendf("%zi KB\n", kb);
223 } 217 }
224 } else { 218 } else {
225 ramCount.appendf("%zi bytes\n", bytes); 219 ramCount.appendf("%zi bytes\n", bytes);
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 } 435 }
442 #endif 436 #endif
443 return 0; 437 return 0;
444 } 438 }
445 439
446 #if !defined SK_BUILD_FOR_IOS 440 #if !defined SK_BUILD_FOR_IOS
447 int main(int argc, char * const argv[]) { 441 int main(int argc, char * const argv[]) {
448 return tool_main(argc, (char**) argv); 442 return tool_main(argc, (char**) argv);
449 } 443 }
450 #endif 444 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698