| Index: tools/PictureRenderingFlags.cpp
|
| diff --git a/tools/PictureRenderingFlags.cpp b/tools/PictureRenderingFlags.cpp
|
| index d8522013cf2c5a177b860e406635b10d2eec5d3d..3b0bea4c961e34c8e06ce8a89b9399d8ae8cce86 100644
|
| --- a/tools/PictureRenderingFlags.cpp
|
| +++ b/tools/PictureRenderingFlags.cpp
|
| @@ -11,7 +11,19 @@
|
| #include "PictureRenderer.h"
|
| #include "picture_utils.h"
|
|
|
| +#include "SkBitmapFactory.h"
|
| +#include "SkData.h"
|
| #include "SkFlags.h"
|
| +#include "SkLruImageCache.h"
|
| +#include "SkImage.h"
|
| +#include "SkImageDecoder.h"
|
| +#include "SkString.h"
|
| +
|
| +#ifdef SK_BUILD_FOR_MAC
|
| + #include "SkMacImageCache.h"
|
| +#elif defined(SK_BUILD_FOR_ANDROID)
|
| + #include "SkAshmemImageCache.h"
|
| +#endif
|
|
|
| // Alphabetized list of flags used by this file or bench_ and render_pictures.
|
| DEFINE_string(bbh, "none", "bbhType [width height]: Set the bounding box hierarchy type to "
|
| @@ -57,6 +69,9 @@ DEFINE_string(r, "", "skp files or directories of skp files to process.");
|
| DEFINE_double(scale, 1, "Set the scale factor.");
|
| DEFINE_string(tiles, "", "Used with --mode copyTile to specify number of tiles per larger tile "
|
| "in the x and y directions.");
|
| +DEFINE_bool(useVolatileCache, false, "Use a volatile cache for deferred image decoding pixels. "
|
| + "Only meaningful if --deferImageDecoding is set to true and the platform has an "
|
| + "implementation.");
|
| DEFINE_string(viewport, "", "width height: Set the viewport.");
|
|
|
| sk_tools::PictureRenderer* parseRenderer(SkString& error, PictureTool tool) {
|
| @@ -309,3 +324,29 @@ sk_tools::PictureRenderer* parseRenderer(SkString& error, PictureTool tool) {
|
| return renderer.detach();
|
| }
|
|
|
| +SkLruImageCache gLruImageCache(1024*1024);
|
| +
|
| +static SkImageCache* cache_selector(const SkImage::Info& info) {
|
| + if (info.fWidth * info.fHeight > 32 * 1024) {
|
| +#ifdef SK_BUILD_FOR_MAC
|
| + return SkMacImageCache::GetMacImageCache();
|
| +#elif defined(SK_BUILD_FOR_ANDROID)
|
| + return SkAshmemImageCache::GetAshmemImageCache();
|
| +#endif
|
| + }
|
| + return &gLruImageCache;
|
| +}
|
| +
|
| +bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap);
|
| +bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap) {
|
| + void* copiedBuffer = sk_malloc_throw(size);
|
| + memcpy(copiedBuffer, buffer, size);
|
| + SkAutoDataUnref data(SkData::NewFromMalloc(copiedBuffer, size));
|
| + SkBitmapFactory factory(&SkImageDecoder::DecodeMemoryToTarget);
|
| + if (FLAGS_useVolatileCache) {
|
| + factory.setCacheSelector(&cache_selector);
|
| + } else {
|
| + factory.setImageCache(&gLruImageCache);
|
| + }
|
| + return factory.installPixelRef(data, bitmap);
|
| +}
|
|
|