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

Side by Side Diff: tools/PictureRenderingFlags.cpp

Issue 12433020: Improvements/additions to SkImageCache/SkLazyPixelRef. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Respond to comments. Created 7 years, 9 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
« no previous file with comments | « tools/PictureRenderingFlags.h ('k') | tools/bench_pictures_main.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "PictureRenderingFlags.h" 8 #include "PictureRenderingFlags.h"
9 9
10 #include "CopyTilesRenderer.h" 10 #include "CopyTilesRenderer.h"
11 #include "PictureRenderer.h" 11 #include "PictureRenderer.h"
12 #include "picture_utils.h" 12 #include "picture_utils.h"
13 13
14 #include "SkBitmapFactory.h"
15 #include "SkData.h"
14 #include "SkFlags.h" 16 #include "SkFlags.h"
17 #include "SkImage.h"
18 #include "SkImageDecoder.h"
19 #include "SkLruImageCache.h"
20 #include "SkPurgeableImageCache.h"
21 #include "SkString.h"
15 22
16 // Alphabetized list of flags used by this file or bench_ and render_pictures. 23 // Alphabetized list of flags used by this file or bench_ and render_pictures.
17 DEFINE_string(bbh, "none", "bbhType [width height]: Set the bounding box hierarc hy type to " 24 DEFINE_string(bbh, "none", "bbhType [width height]: Set the bounding box hierarc hy type to "
18 "be used. Accepted values are: none, rtree, grid. " 25 "be used. Accepted values are: none, rtree, grid. "
19 "Not compatible with --pipe. With value " 26 "Not compatible with --pipe. With value "
20 "'grid', width and height must be specified. 'grid' can " 27 "'grid', width and height must be specified. 'grid' can "
21 "only be used with modes tile, record, and " 28 "only be used with modes tile, record, and "
22 "playbackCreation."); 29 "playbackCreation.");
23 // Although this config does not support all the same options as gm, the names s hould be kept 30 // Although this config does not support all the same options as gm, the names s hould be kept
24 // consistent. 31 // consistent.
(...skipping 25 matching lines...) Expand all
50 "\tSkPicturePlayback.\n" 57 "\tSkPicturePlayback.\n"
51 "rerecord: (Only in render_pictures) Record the picture as a new s kp,\n" 58 "rerecord: (Only in render_pictures) Record the picture as a new s kp,\n"
52 "\twith the bitmaps PNG encoded.\n"); 59 "\twith the bitmaps PNG encoded.\n");
53 DEFINE_int32(multi, 1, "Set the number of threads for multi threaded drawing. " 60 DEFINE_int32(multi, 1, "Set the number of threads for multi threaded drawing. "
54 "If > 1, requires tiled rendering."); 61 "If > 1, requires tiled rendering.");
55 DEFINE_bool(pipe, false, "Use SkGPipe rendering. Currently incompatible with \"m ode\"."); 62 DEFINE_bool(pipe, false, "Use SkGPipe rendering. Currently incompatible with \"m ode\".");
56 DEFINE_string(r, "", "skp files or directories of skp files to process."); 63 DEFINE_string(r, "", "skp files or directories of skp files to process.");
57 DEFINE_double(scale, 1, "Set the scale factor."); 64 DEFINE_double(scale, 1, "Set the scale factor.");
58 DEFINE_string(tiles, "", "Used with --mode copyTile to specify number of tiles p er larger tile " 65 DEFINE_string(tiles, "", "Used with --mode copyTile to specify number of tiles p er larger tile "
59 "in the x and y directions."); 66 "in the x and y directions.");
67 DEFINE_bool(useVolatileCache, false, "Use a volatile cache for deferred image de coding pixels. "
68 "Only meaningful if --deferImageDecoding is set to true and the plat form has an "
69 "implementation.");
60 DEFINE_string(viewport, "", "width height: Set the viewport."); 70 DEFINE_string(viewport, "", "width height: Set the viewport.");
61 71
62 sk_tools::PictureRenderer* parseRenderer(SkString& error, PictureTool tool) { 72 sk_tools::PictureRenderer* parseRenderer(SkString& error, PictureTool tool) {
63 error.reset(); 73 error.reset();
64 74
65 if (FLAGS_multi <= 0) { 75 if (FLAGS_multi <= 0) {
66 error.printf("--multi must be > 0, was %i", FLAGS_multi); 76 error.printf("--multi must be > 0, was %i", FLAGS_multi);
67 return NULL; 77 return NULL;
68 } 78 }
69 79
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 if (FLAGS_pipe && sk_tools::PictureRenderer::kNone_BBoxHierarchyType != bbhType) { 311 if (FLAGS_pipe && sk_tools::PictureRenderer::kNone_BBoxHierarchyType != bbhType) {
302 error.printf("--pipe and --bbh cannot be used together\n"); 312 error.printf("--pipe and --bbh cannot be used together\n");
303 return NULL; 313 return NULL;
304 } 314 }
305 } 315 }
306 renderer->setBBoxHierarchyType(bbhType); 316 renderer->setBBoxHierarchyType(bbhType);
307 renderer->setScaleFactor(SkDoubleToScalar(FLAGS_scale)); 317 renderer->setScaleFactor(SkDoubleToScalar(FLAGS_scale));
308 318
309 return renderer.detach(); 319 return renderer.detach();
310 } 320 }
321
322 SkLruImageCache gLruImageCache(1024*1024);
323
324 // Simple cache selector to choose between a purgeable cache for large images an d the standard one
325 // for smaller images.
326 class MyCacheSelector : public SkBitmapFactory::CacheSelector {
327
328 public:
329 MyCacheSelector() {
330 fPurgeableImageCache = SkPurgeableImageCache::Create();
331 }
332
333 ~MyCacheSelector() {
334 SkSafeUnref(fPurgeableImageCache);
335 }
336
337 virtual SkImageCache* selectCache(const SkImage::Info& info) SK_OVERRIDE {
338 if (info.fWidth * info.fHeight > 32 * 1024 && fPurgeableImageCache != NU LL) {
339 return fPurgeableImageCache;
340 }
341 return &gLruImageCache;
342 }
343 private:
344 SkImageCache* fPurgeableImageCache;
345 };
346
347 static MyCacheSelector gCacheSelector;
348 static SkBitmapFactory gFactory(&SkImageDecoder::DecodeMemoryToTarget);
349
350 bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap);
351 bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap) {
352 void* copiedBuffer = sk_malloc_throw(size);
353 memcpy(copiedBuffer, buffer, size);
354 SkAutoDataUnref data(SkData::NewFromMalloc(copiedBuffer, size));
355
356 static bool gOnce;
357 if (!gOnce) {
358 // Only use the cache selector if there is a purgeable image cache to us e for large
359 // images.
360 if (FLAGS_useVolatileCache && SkAutoTUnref<SkImageCache>(
361 SkPurgeableImageCache::Create()).get() != NULL) {
362 gFactory.setCacheSelector(&gCacheSelector);
363 } else {
364 gFactory.setImageCache(&gLruImageCache);
365 }
366 gOnce = true;
367 }
368 return gFactory.installPixelRef(data, bitmap);
369 }
OLDNEW
« no previous file with comments | « tools/PictureRenderingFlags.h ('k') | tools/bench_pictures_main.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698