aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar halcanary@google.com <halcanary@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-12-05 18:31:42 +0000
committerGravatar halcanary@google.com <halcanary@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-12-05 18:31:42 +0000
commit2c7c7ee47d75e7815ea8db05e924ab55958cb402 (patch)
treee6b7221c8f6a6d3b9d548c923499f3cf23f79634 /tools
parent3e0446ccbfbeadd0d02d417cb68e950d6c92f8e1 (diff)
Big Cleanup: SkBitmapFactory, SkLazyPixelRef, SkImageCache
Removed SkBitmapFactory since no clients were using it. New cache selection mechanism can simply pass a SkDiscardableMemory::Factory into the SkDiscardablePixelRef if non-default SkDiscardableMemory should be used. Removed BitmapFactoryTest. SkDiscardableMemory::Factory interface. Android will need this functionality in the future inside their BitmapFactory. Removed SkLazyPixelRef, since it's functionality is now subsumed into SkDiscardablePixelRef. Removed LazyPixelRef test. Modified SkDiscardablePixelRef to optionally allow it to use a SkDiscardableMemory::Factory. This tiny change makes it a replacement for SkLazyPixelRef. This functioanlity is also necessary for moving Android over to SkDiscardablePixelRef from SkImageRef in a later CL. Added a test for this. SkDecodingImageGenerator::Install can optionally pass a factory in to SkDiscardablePixelRef. Removed SkImageCache, SkLruImageCache, and SkPurgeableImageCache. This functionality can be handled much more cleanly by SkDiscardableMemory. New SkDiscardableMemoryPool class to replace SkLruImageCache. In a later CL, we will replace SkImageRef_GlobalPool (used by android) as well. This is a concrete implementation of SkDiscardableMemory::Factory. Added a test for this. modified gm/factory.cpp to remove dependnce on SkBitmapFactory + SkLruImageCache. Now uses SkDecodingImageGenerator + SkDiscardablePixelRef + SkDiscardableMemoryPool. SkImageDecoder::Target replaces SkBitmapFactory::Target. The DecodeMemoryToTarget function may disappear in the future. Moved SkLazyCachingPixelRef::DecodeProc replaces SkBitmapFactory::DecodeProc. This is a short term change, since another CL changes SkLazyCachingPixelRef to use SkImageGenerator instead of DecodeProc. Modified DrawBitmapRectTest to use SkDiscardablePixelRef instead of SkLazyPixelRef. tools/LazyDecodeBitmap.cpp now uses SkDecodingImageGenerator + SkDiscardablePixelRef instead of a SkBitmapFactory. bench_pictures uses the Global SkDiscardableMemoryPool instead of a global gLruImageCache. R=reed@google.com, scroggo@google.com Review URL: https://codereview.chromium.org/103033002 git-svn-id: http://skia.googlecode.com/svn/trunk@12515 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tools')
-rw-r--r--tools/LazyDecodeBitmap.cpp75
-rw-r--r--tools/PictureRenderingFlags.cpp1
-rw-r--r--tools/bench_pictures_main.cpp23
3 files changed, 32 insertions, 67 deletions
diff --git a/tools/LazyDecodeBitmap.cpp b/tools/LazyDecodeBitmap.cpp
index c0b7eea724..9e850e5753 100644
--- a/tools/LazyDecodeBitmap.cpp
+++ b/tools/LazyDecodeBitmap.cpp
@@ -7,70 +7,41 @@
#include "LazyDecodeBitmap.h"
-#include "PictureRenderingFlags.h" // --deferImageDecoding is defined here.
-#include "SkBitmap.h"
#include "SkData.h"
-#include "SkImageDecoder.h"
+#include "SkDecodingImageGenerator.h"
+#include "SkDiscardableMemoryPool.h"
+#include "SkDiscardablePixelRef.h"
#include "SkForceLinking.h"
-#include "SkLruImageCache.h"
-#include "SkPurgeableImageCache.h"
+
#include "SkCommandLineFlags.h"
__SK_FORCE_IMAGE_DECODER_LINKING;
+// TODO(halcanary) Use this flag when ashmem-backed discardable memory lands.
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.");
-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
diff --git a/tools/PictureRenderingFlags.cpp b/tools/PictureRenderingFlags.cpp
index 67a6a3d0aa..2aae77f9ac 100644
--- a/tools/PictureRenderingFlags.cpp
+++ b/tools/PictureRenderingFlags.cpp
@@ -10,7 +10,6 @@
#include "CopyTilesRenderer.h"
#include "PictureRenderer.h"
#include "picture_utils.h"
-#include "SkBitmapFactory.h"
#include "SkCommandLineFlags.h"
#include "SkData.h"
#include "SkImage.h"
diff --git a/tools/bench_pictures_main.cpp b/tools/bench_pictures_main.cpp
index 31d432daa9..1f3b0c0225 100644
--- a/tools/bench_pictures_main.cpp
+++ b/tools/bench_pictures_main.cpp
@@ -12,12 +12,9 @@
#include "PictureRenderingFlags.h"
#include "SkBenchLogger.h"
#include "SkCommandLineFlags.h"
+#include "SkDiscardableMemoryPool.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"
@@ -143,9 +140,6 @@ static SkString filterFlagsUsage() {
return result;
}
-// Defined in LazyDecodeBitmap.cpp
-extern SkLruImageCache gLruImageCache;
-
#if LAZY_CACHE_STATS
static int32_t gTotalCacheHits;
static int32_t gTotalCacheMisses;
@@ -163,11 +157,12 @@ static bool run_single_benchmark(const SkString& inputPath,
return false;
}
+ SkDiscardableMemoryPool* pool = SkGetGlobalDiscardableMemoryPool();
// Since the old picture has been deleted, all pixels should be cleared.
- SkASSERT(gLruImageCache.getImageCacheUsed() == 0);
+ SkASSERT(pool->getRAMUsed() == 0);
if (FLAGS_countRAM) {
- // Set the limit to zero, so all pixels will be kept
- gLruImageCache.setImageCacheLimit(0);
+ pool->setRAMBudget(SK_MaxU32);
+ // Set the limit to max, so all pixels will be kept
}
SkPicture::InstallPixelRefProc proc;
@@ -197,9 +192,9 @@ static bool run_single_benchmark(const SkString& inputPath,
#if LAZY_CACHE_STATS
if (FLAGS_trackDeferredCaching) {
- int32_t cacheHits = SkLazyPixelRef::GetCacheHits();
- int32_t cacheMisses = SkLazyPixelRef::GetCacheMisses();
- SkLazyPixelRef::ResetCacheStats();
+ int32_t cacheHits = pool->fCacheHits;
+ int32_t cacheMisses = pool->fCacheMisses;
+ pool->fCacheHits = pool->fCacheMisses = 0;
SkString hitString;
hitString.printf("Cache hit rate: %f\n", (double) cacheHits / (cacheHits + cacheMisses));
gLogger.logProgress(hitString);
@@ -209,7 +204,7 @@ static bool run_single_benchmark(const SkString& inputPath,
#endif
if (FLAGS_countRAM) {
SkString ramCount("RAM used for bitmaps: ");
- size_t bytes = gLruImageCache.getImageCacheUsed();
+ size_t bytes = pool->getRAMUsed();
if (bytes > 1024) {
size_t kb = bytes / 1024;
if (kb > 1024) {