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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/PictureRenderingFlags.h ('k') | tools/bench_pictures_main.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/PictureRenderingFlags.cpp
diff --git a/tools/PictureRenderingFlags.cpp b/tools/PictureRenderingFlags.cpp
index 3cb1e96b74b943f05de16abbfeaff9b6b3f858d6..29046aec7150c3fb5383772310cc1c38734c904f 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);
+}
« 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