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

Unified Diff: tools/LazyDecodeBitmap.cpp

Issue 103033002: Big Cleanup: SkBitmapFactory, SkLazyPixelRef, SkImageCache (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years 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
Index: tools/LazyDecodeBitmap.cpp
diff --git a/tools/LazyDecodeBitmap.cpp b/tools/LazyDecodeBitmap.cpp
index c0b7eea724fa621325b539c6dfd8dc7fb144854d..ef64b0fde4d0013fc56327bd975f63a2f7b53371 100644
--- a/tools/LazyDecodeBitmap.cpp
+++ b/tools/LazyDecodeBitmap.cpp
@@ -7,70 +7,34 @@
#include "LazyDecodeBitmap.h"
-#include "PictureRenderingFlags.h" // --deferImageDecoding is defined here.
-#include "SkBitmap.h"
#include "SkData.h"
-#include "SkImageDecoder.h"
+#include "SkDecodingImageGenerator.h"
+#include "SkDiscardablePixelRef.h"
#include "SkForceLinking.h"
-#include "SkLruImageCache.h"
-#include "SkPurgeableImageCache.h"
-#include "SkCommandLineFlags.h"
+#include "SkDiscardableMemoryPool.h"
__SK_FORCE_IMAGE_DECODER_LINKING;
-DEFINE_bool(useVolatileCache, false, "Use a volatile cache for deferred image decoding pixels. "
scroggo 2013/12/03 23:00:01 You'll need to modify buildbot/slave/skia_slave_sc
hal.canary 2013/12/04 00:01:36 Okay. We may want to keep useVolatileCache for An
- "Only meaningful if --deferImageDecoding is set to true and the platform has an "
- "implementation.");
-
-SkLruImageCache gLruImageCache(1024 * 1024);
-
-namespace sk_tools {
-
-// Simple cache selector to choose between a purgeable cache for large images and the standard one
-// for smaller images.
-//
-class CacheSelector : public SkBitmapFactory::CacheSelector {
-
-public:
- CacheSelector() {
- fPurgeableImageCache = SkPurgeableImageCache::Create();
- }
-
- ~CacheSelector() {
- SkSafeUnref(fPurgeableImageCache);
+// Fits SkPicture::InstallPixelRefProc call signature.
+// Used in SkPicturePlayback::CreateFromStream
+bool sk_tools::LazyDecodeBitmap(const void* src,
+ size_t length,
+ SkBitmap* dst) {
+ SkAutoDataUnref data(SkData::NewWithCopy(src, length));
+ if (NULL == data.get()) {
+ return false;
}
- virtual SkImageCache* selectCache(const SkImageInfo& info) SK_OVERRIDE {
- if (info.fWidth * info.fHeight > 32 * 1024 && fPurgeableImageCache != NULL) {
- return fPurgeableImageCache;
- }
- return &gLruImageCache;
+ SkAutoTDelete<SkImageGenerator> gen(SkNEW_ARGS(SkDecodingImageGenerator,
+ (data)));
+ SkImageInfo info;
+ if (!gen->getInfo(&info)) {
+ return false;
}
-private:
- SkImageCache* fPurgeableImageCache;
-};
-
-static CacheSelector gCacheSelector;
-static SkBitmapFactory gFactory(&SkImageDecoder::DecodeMemoryToTarget);
-
-bool LazyDecodeBitmap(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;
+ SkDiscardableMemory::Factory* pool = NULL;
+ if (info.fWidth * info.fHeight > 32 * 1024) {
+ // how to do switching with SkDiscardableMemory.
+ pool = SkGetGlobalDiscardableMemoryPool();
}
- return gFactory.installPixelRef(data, bitmap);
+ return SkDiscardablePixelRef::Install(gen.detach(), dst, pool);
}
-
-} // namespace sk_tools

Powered by Google App Engine
This is Rietveld 408576698