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

Side by Side Diff: tools/PictureRenderingFlags.cpp

Issue 19109002: Add the lazy decoder from PictureFlags to SkImageDecoder (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Add include 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
« no previous file with comments | « tools/LazyDecodeBitmap.cpp ('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
14 #include "SkBitmapFactory.h" 13 #include "SkBitmapFactory.h"
15 #include "SkCommandLineFlags.h" 14 #include "SkCommandLineFlags.h"
16 #include "SkData.h" 15 #include "SkData.h"
17 #include "SkImage.h" 16 #include "SkImage.h"
18 #include "SkImageDecoder.h" 17 #include "SkImageDecoder.h"
19 #include "SkLruImageCache.h"
20 #include "SkPurgeableImageCache.h"
21 #include "SkString.h" 18 #include "SkString.h"
22 19
23 // Alphabetized list of flags used by this file or bench_ and render_pictures. 20 // Alphabetized list of flags used by this file or bench_ and render_pictures.
24 DEFINE_string(bbh, "none", "bbhType [width height]: Set the bounding box hierarc hy type to " 21 DEFINE_string(bbh, "none", "bbhType [width height]: Set the bounding box hierarc hy type to "
25 "be used. Accepted values are: none, rtree, grid. " 22 "be used. Accepted values are: none, rtree, grid. "
26 "Not compatible with --pipe. With value " 23 "Not compatible with --pipe. With value "
27 "'grid', width and height must be specified. 'grid' can " 24 "'grid', width and height must be specified. 'grid' can "
28 "only be used with modes tile, record, and " 25 "only be used with modes tile, record, and "
29 "playbackCreation."); 26 "playbackCreation.");
30 // Although this config does not support all the same options as gm, the names s hould be kept 27 // Although this config does not support all the same options as gm, the names s hould be kept
(...skipping 26 matching lines...) Expand all
57 "\tSkPicturePlayback.\n" 54 "\tSkPicturePlayback.\n"
58 "rerecord: (Only in render_pictures) Record the picture as a new s kp,\n" 55 "rerecord: (Only in render_pictures) Record the picture as a new s kp,\n"
59 "\twith the bitmaps PNG encoded.\n"); 56 "\twith the bitmaps PNG encoded.\n");
60 DEFINE_int32(multi, 1, "Set the number of threads for multi threaded drawing. " 57 DEFINE_int32(multi, 1, "Set the number of threads for multi threaded drawing. "
61 "If > 1, requires tiled rendering."); 58 "If > 1, requires tiled rendering.");
62 DEFINE_bool(pipe, false, "Use SkGPipe rendering. Currently incompatible with \"m ode\"."); 59 DEFINE_bool(pipe, false, "Use SkGPipe rendering. Currently incompatible with \"m ode\".");
63 DEFINE_string2(readPath, r, "", "skp files or directories of skp files to proces s."); 60 DEFINE_string2(readPath, r, "", "skp files or directories of skp files to proces s.");
64 DEFINE_double(scale, 1, "Set the scale factor."); 61 DEFINE_double(scale, 1, "Set the scale factor.");
65 DEFINE_string(tiles, "", "Used with --mode copyTile to specify number of tiles p er larger tile " 62 DEFINE_string(tiles, "", "Used with --mode copyTile to specify number of tiles p er larger tile "
66 "in the x and y directions."); 63 "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.");
70 DEFINE_string(viewport, "", "width height: Set the viewport."); 64 DEFINE_string(viewport, "", "width height: Set the viewport.");
71 65
72 sk_tools::PictureRenderer* parseRenderer(SkString& error, PictureTool tool) { 66 sk_tools::PictureRenderer* parseRenderer(SkString& error, PictureTool tool) {
73 error.reset(); 67 error.reset();
74 68
75 if (FLAGS_multi <= 0) { 69 if (FLAGS_multi <= 0) {
76 error.printf("--multi must be > 0, was %i", FLAGS_multi); 70 error.printf("--multi must be > 0, was %i", FLAGS_multi);
77 return NULL; 71 return NULL;
78 } 72 }
79 73
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 error.printf("--pipe and --bbh cannot be used together\n"); 328 error.printf("--pipe and --bbh cannot be used together\n");
335 return NULL; 329 return NULL;
336 } 330 }
337 } 331 }
338 renderer->setBBoxHierarchyType(bbhType); 332 renderer->setBBoxHierarchyType(bbhType);
339 renderer->setScaleFactor(SkDoubleToScalar(FLAGS_scale)); 333 renderer->setScaleFactor(SkDoubleToScalar(FLAGS_scale));
340 334
341 return renderer.detach(); 335 return renderer.detach();
342 } 336 }
343 337
344 SkLruImageCache gLruImageCache(1024*1024);
345
346 // Simple cache selector to choose between a purgeable cache for large images an d the standard one
347 // for smaller images.
348 class MyCacheSelector : public SkBitmapFactory::CacheSelector {
349
350 public:
351 MyCacheSelector() {
352 fPurgeableImageCache = SkPurgeableImageCache::Create();
353 }
354
355 ~MyCacheSelector() {
356 SkSafeUnref(fPurgeableImageCache);
357 }
358
359 virtual SkImageCache* selectCache(const SkImage::Info& info) SK_OVERRIDE {
360 if (info.fWidth * info.fHeight > 32 * 1024 && fPurgeableImageCache != NU LL) {
361 return fPurgeableImageCache;
362 }
363 return &gLruImageCache;
364 }
365 private:
366 SkImageCache* fPurgeableImageCache;
367 };
368
369 static MyCacheSelector gCacheSelector;
370 static SkBitmapFactory gFactory(&SkImageDecoder::DecodeMemoryToTarget);
371
372 bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap);
373 bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap) {
374 void* copiedBuffer = sk_malloc_throw(size);
375 memcpy(copiedBuffer, buffer, size);
376 SkAutoDataUnref data(SkData::NewFromMalloc(copiedBuffer, size));
377
378 static bool gOnce;
379 if (!gOnce) {
380 // Only use the cache selector if there is a purgeable image cache to us e for large
381 // images.
382 if (FLAGS_useVolatileCache && SkAutoTUnref<SkImageCache>(
383 SkPurgeableImageCache::Create()).get() != NULL) {
384 gFactory.setCacheSelector(&gCacheSelector);
385 } else {
386 gFactory.setImageCache(&gLruImageCache);
387 }
388 gOnce = true;
389 }
390 return gFactory.installPixelRef(data, bitmap);
391 }
OLDNEW
« no previous file with comments | « tools/LazyDecodeBitmap.cpp ('k') | tools/bench_pictures_main.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698