diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/PictureRenderingFlags.cpp | 59 | ||||
-rw-r--r-- | tools/PictureRenderingFlags.h | 2 | ||||
-rw-r--r-- | tools/bench_pictures_main.cpp | 24 | ||||
-rw-r--r-- | tools/render_pictures_main.cpp | 35 |
4 files changed, 69 insertions, 51 deletions
diff --git a/tools/PictureRenderingFlags.cpp b/tools/PictureRenderingFlags.cpp index 3cb1e96b74..29046aec71 100644 --- a/tools/PictureRenderingFlags.cpp +++ b/tools/PictureRenderingFlags.cpp @@ -11,7 +11,14 @@ #include "PictureRenderer.h" #include "picture_utils.h" +#include "SkBitmapFactory.h" +#include "SkData.h" #include "SkFlags.h" +#include "SkImage.h" +#include "SkImageDecoder.h" +#include "SkLruImageCache.h" +#include "SkPurgeableImageCache.h" +#include "SkString.h" // 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 +64,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) { @@ -308,3 +318,52 @@ sk_tools::PictureRenderer* parseRenderer(SkString& error, PictureTool tool) { return renderer.detach(); } + +SkLruImageCache gLruImageCache(1024*1024); + +// Simple cache selector to choose between a purgeable cache for large images and the standard one +// for smaller images. +class MyCacheSelector : public SkBitmapFactory::CacheSelector { + +public: + MyCacheSelector() { + fPurgeableImageCache = SkPurgeableImageCache::Create(); + } + + ~MyCacheSelector() { + SkSafeUnref(fPurgeableImageCache); + } + + virtual SkImageCache* selectCache(const SkImage::Info& info) SK_OVERRIDE { + if (info.fWidth * info.fHeight > 32 * 1024 && fPurgeableImageCache != NULL) { + return fPurgeableImageCache; + } + return &gLruImageCache; + } +private: + SkImageCache* fPurgeableImageCache; +}; + +static MyCacheSelector gCacheSelector; +static SkBitmapFactory gFactory(&SkImageDecoder::DecodeMemoryToTarget); + +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)); + + static bool gOnce; + if (!gOnce) { + // Only use the cache selector if there is a purgeable image cache to use for large + // images. + if (FLAGS_useVolatileCache && SkAutoTUnref<SkImageCache>( + SkPurgeableImageCache::Create()).get() != NULL) { + gFactory.setCacheSelector(&gCacheSelector); + } else { + gFactory.setImageCache(&gLruImageCache); + } + gOnce = true; + } + return gFactory.installPixelRef(data, bitmap); +} diff --git a/tools/PictureRenderingFlags.h b/tools/PictureRenderingFlags.h index 9e49d30dfb..e8909f9f4c 100644 --- a/tools/PictureRenderingFlags.h +++ b/tools/PictureRenderingFlags.h @@ -8,7 +8,7 @@ #ifndef PICTURE_RENDERING_FLAGS #define PICTURE_RENDERING_FLAGS -#include "SkString.h" +class SkString; namespace sk_tools { class PictureRenderer; diff --git a/tools/bench_pictures_main.cpp b/tools/bench_pictures_main.cpp index d027db9633..31ef48449a 100644 --- a/tools/bench_pictures_main.cpp +++ b/tools/bench_pictures_main.cpp @@ -10,16 +10,17 @@ #include "PictureBenchmark.h" #include "PictureRenderingFlags.h" #include "SkBenchLogger.h" -#include "SkBitmapFactory.h" -#include "SkCanvas.h" #include "SkFlags.h" #include "SkGraphics.h" #include "SkImageDecoder.h" +#if LAZY_CACHE_STATS + #include "SkLazyPixelRef.h" +#endif +#include "SkLruImageCache.h" #include "SkMath.h" #include "SkOSFile.h" #include "SkPicture.h" #include "SkStream.h" -#include "SkTArray.h" #include "picture_utils.h" @@ -142,20 +143,9 @@ static SkString filterFlagsUsage() { return result; } -#include "SkData.h" -#include "SkLruImageCache.h" -#include "SkLazyPixelRef.h" - -static SkLruImageCache gLruImageCache(1024*1024); - -static 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); - factory.setImageCache(&gLruImageCache); - return factory.installPixelRef(data, bitmap); -} +// These are defined in PictureRenderingFlags.cpp +extern SkLruImageCache gLruImageCache; +extern bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap); #if LAZY_CACHE_STATS static int32_t gTotalCacheHits; diff --git a/tools/render_pictures_main.cpp b/tools/render_pictures_main.cpp index b289d39fc7..5e0ac99945 100644 --- a/tools/render_pictures_main.cpp +++ b/tools/render_pictures_main.cpp @@ -7,8 +7,6 @@ #include "CopyTilesRenderer.h" #include "SkBitmap.h" -#include "SkBitmapFactory.h" -#include "SkCanvas.h" #include "SkDevice.h" #include "SkFlags.h" #include "SkGraphics.h" @@ -19,7 +17,6 @@ #include "SkPicture.h" #include "SkStream.h" #include "SkString.h" -#include "SkTArray.h" #include "PictureRenderer.h" #include "PictureRenderingFlags.h" #include "picture_utils.h" @@ -45,36 +42,8 @@ static void make_output_filepath(SkString* path, const SkString& dir, path->remove(path->size() - 4, 4); } -#include "SkData.h" -#include "SkLruImageCache.h" - -static SkLruImageCache gLruImageCache(1024*1024); - -#ifdef SK_BUILD_FOR_ANDROID -#include "SkAshmemImageCache.h" -#include "SkImage.h" - -static SkImageCache* cache_selector(const SkImage::Info& info) { - if (info.fWidth * info.fHeight > 32 * 1024) { - return SkAshmemImageCache::GetAshmemImageCache(); - } - return &gLruImageCache; -} - -#endif - -static 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); -#ifdef SK_BUILD_FOR_ANDROID - factory.setCacheSelector(&cache_selector); -#else - factory.setImageCache(&gLruImageCache); -#endif - return factory.installPixelRef(data, bitmap); -} +// Defined in PictureRenderingFlags.cpp +extern bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap); static bool render_picture(const SkString& inputPath, const SkString* outputDir, sk_tools::PictureRenderer& renderer, |