OLD | NEW |
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 "SkLruImageCache.h" |
| 18 #include "SkImage.h" |
| 19 #include "SkImageDecoder.h" |
| 20 #include "SkString.h" |
| 21 |
| 22 #ifdef SK_BUILD_FOR_MAC |
| 23 #include "SkMacImageCache.h" |
| 24 #elif defined(SK_BUILD_FOR_ANDROID) |
| 25 #include "SkAshmemImageCache.h" |
| 26 #endif |
15 | 27 |
16 // Alphabetized list of flags used by this file or bench_ and render_pictures. | 28 // 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 " | 29 DEFINE_string(bbh, "none", "bbhType [width height]: Set the bounding box hierarc
hy type to " |
18 "be used. Accepted values are: none, rtree, grid. " | 30 "be used. Accepted values are: none, rtree, grid. " |
19 "Not compatible with --pipe. With value " | 31 "Not compatible with --pipe. With value " |
20 "'grid', width and height must be specified. 'grid' can " | 32 "'grid', width and height must be specified. 'grid' can " |
21 "only be used with modes tile, record, and " | 33 "only be used with modes tile, record, and " |
22 "playbackCreation."); | 34 "playbackCreation."); |
23 // Although this config does not support all the same options as gm, the names s
hould be kept | 35 // Although this config does not support all the same options as gm, the names s
hould be kept |
24 // consistent. | 36 // consistent. |
(...skipping 25 matching lines...) Expand all Loading... |
50 "\tSkPicturePlayback.\n" | 62 "\tSkPicturePlayback.\n" |
51 "rerecord: (Only in render_pictures) Record the picture as a new s
kp,\n" | 63 "rerecord: (Only in render_pictures) Record the picture as a new s
kp,\n" |
52 "\twith the bitmaps PNG encoded.\n"); | 64 "\twith the bitmaps PNG encoded.\n"); |
53 DEFINE_int32(multi, 1, "Set the number of threads for multi threaded drawing. " | 65 DEFINE_int32(multi, 1, "Set the number of threads for multi threaded drawing. " |
54 "If > 1, requires tiled rendering."); | 66 "If > 1, requires tiled rendering."); |
55 DEFINE_bool(pipe, false, "Use SkGPipe rendering. Currently incompatible with \"m
ode\"."); | 67 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."); | 68 DEFINE_string(r, "", "skp files or directories of skp files to process."); |
57 DEFINE_double(scale, 1, "Set the scale factor."); | 69 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 " | 70 DEFINE_string(tiles, "", "Used with --mode copyTile to specify number of tiles p
er larger tile " |
59 "in the x and y directions."); | 71 "in the x and y directions."); |
| 72 DEFINE_bool(useVolatileCache, false, "Use a volatile cache for deferred image de
coding pixels. " |
| 73 "Only meaningful if --deferImageDecoding is set to true and the plat
form has an " |
| 74 "implementation."); |
60 DEFINE_string(viewport, "", "width height: Set the viewport."); | 75 DEFINE_string(viewport, "", "width height: Set the viewport."); |
61 | 76 |
62 sk_tools::PictureRenderer* parseRenderer(SkString& error, PictureTool tool) { | 77 sk_tools::PictureRenderer* parseRenderer(SkString& error, PictureTool tool) { |
63 error.reset(); | 78 error.reset(); |
64 | 79 |
65 if (FLAGS_multi <= 0) { | 80 if (FLAGS_multi <= 0) { |
66 error.printf("--multi must be > 0, was %i", FLAGS_multi); | 81 error.printf("--multi must be > 0, was %i", FLAGS_multi); |
67 return NULL; | 82 return NULL; |
68 } | 83 } |
69 | 84 |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 error.printf("--pipe and --bbh cannot be used together\n"); | 317 error.printf("--pipe and --bbh cannot be used together\n"); |
303 return NULL; | 318 return NULL; |
304 } | 319 } |
305 } | 320 } |
306 renderer->setBBoxHierarchyType(bbhType); | 321 renderer->setBBoxHierarchyType(bbhType); |
307 renderer->setScaleFactor(SkDoubleToScalar(FLAGS_scale)); | 322 renderer->setScaleFactor(SkDoubleToScalar(FLAGS_scale)); |
308 | 323 |
309 return renderer.detach(); | 324 return renderer.detach(); |
310 } | 325 } |
311 | 326 |
| 327 SkLruImageCache gLruImageCache(1024*1024); |
| 328 |
| 329 static SkImageCache* cache_selector(const SkImage::Info& info) { |
| 330 if (info.fWidth * info.fHeight > 32 * 1024) { |
| 331 #ifdef SK_BUILD_FOR_MAC |
| 332 return SkMacImageCache::GetMacImageCache(); |
| 333 #elif defined(SK_BUILD_FOR_ANDROID) |
| 334 return SkAshmemImageCache::GetAshmemImageCache(); |
| 335 #endif |
| 336 } |
| 337 return &gLruImageCache; |
| 338 } |
| 339 |
| 340 bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap); |
| 341 bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap) { |
| 342 void* copiedBuffer = sk_malloc_throw(size); |
| 343 memcpy(copiedBuffer, buffer, size); |
| 344 SkAutoDataUnref data(SkData::NewFromMalloc(copiedBuffer, size)); |
| 345 SkBitmapFactory factory(&SkImageDecoder::DecodeMemoryToTarget); |
| 346 if (FLAGS_useVolatileCache) { |
| 347 factory.setCacheSelector(&cache_selector); |
| 348 } else { |
| 349 factory.setImageCache(&gLruImageCache); |
| 350 } |
| 351 return factory.installPixelRef(data, bitmap); |
| 352 } |
OLD | NEW |