diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/core/SkImageDecoder.h | 18 | ||||
-rw-r--r-- | include/lazy/SkBitmapFactory.h | 99 | ||||
-rw-r--r-- | include/lazy/SkImageCache.h | 132 | ||||
-rw-r--r-- | include/lazy/SkLruImageCache.h | 92 | ||||
-rw-r--r-- | include/lazy/SkPurgeableImageCache.h | 48 |
5 files changed, 16 insertions, 373 deletions
diff --git a/include/core/SkImageDecoder.h b/include/core/SkImageDecoder.h index b255e2ad25..43950adb67 100644 --- a/include/core/SkImageDecoder.h +++ b/include/core/SkImageDecoder.h @@ -11,7 +11,6 @@ #define SkImageDecoder_DEFINED #include "SkBitmap.h" -#include "SkBitmapFactory.h" #include "SkImage.h" #include "SkRect.h" #include "SkRefCnt.h" @@ -336,6 +335,21 @@ public: } /** + * Struct containing information about a pixel destination. + */ + struct Target { + /** + * Pre-allocated memory. + */ + void* fAddr; + + /** + * Rowbytes of the allocated memory. + */ + size_t fRowBytes; + }; + + /** * Decode memory. * @param info Output parameter. Returns info about the encoded image. * @param target Contains the address of pixel memory to decode into @@ -360,7 +374,7 @@ public: * </code> */ static bool DecodeMemoryToTarget(const void* buffer, size_t size, SkImageInfo* info, - const SkBitmapFactory::Target* target); + const Target* target); /** Decode the image stored in the specified SkStreamRewindable, and store the result in bitmap. Return true for success or false on failure. diff --git a/include/lazy/SkBitmapFactory.h b/include/lazy/SkBitmapFactory.h deleted file mode 100644 index 8a39a48a28..0000000000 --- a/include/lazy/SkBitmapFactory.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2012 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkBitmapFactory_DEFINED -#define SkBitmapFactory_DEFINED - -#include "SkImage.h" -#include "SkTypes.h" - -class SkBitmap; -class SkData; -class SkImageCache; - -/** - * Factory for creating a bitmap from encoded data. - */ -class SkBitmapFactory { - -public: - /** - * Struct containing information about a pixel destination. - */ - struct Target { - /** - * Pre-allocated memory. - */ - void* fAddr; - - /** - * Rowbytes of the allocated memory. - */ - size_t fRowBytes; - }; - - /** - * Signature for a function to decode an image from encoded data. - */ - typedef bool (*DecodeProc)(const void* data, size_t length, SkImageInfo*, const Target*); - - /** - * Create a bitmap factory which uses DecodeProc for decoding. - * @param DecodeProc Must not be NULL. - */ - SkBitmapFactory(DecodeProc); - - ~SkBitmapFactory(); - - /** - * Set an image cache to use on pixelrefs provided by installPixelRef. Mutually exclusive - * with fCacheSelector. - */ - void setImageCache(SkImageCache* cache); - - /** - * Sets up an SkBitmap from encoded data. On success, the SkBitmap will have its Config, - * width, height, rowBytes and pixelref set. If fImageCache is non-NULL, or if fCacheSelector - * is set and returns non-NULL, the pixelref will lazily decode, and that SkImageCache will - * handle the pixel memory. Otherwise installPixelRef will do an immediate decode. - * @param SkData Encoded data. - * @param SkBitmap to install the pixel ref on. - * @return bool Whether or not a pixel ref was successfully installed. - */ - bool installPixelRef(SkData*, SkBitmap*); - - /** - * An object for selecting an SkImageCache to use based on an SkImageInfo. - */ - class CacheSelector : public SkRefCnt { - - public: - SK_DECLARE_INST_COUNT(CacheSelector) - /** - * Return an SkImageCache to use based on the provided SkImageInfo. If the caller decides - * to hang on to the result, it will call ref, so the implementation should not add a ref - * as a result of this call. - */ - virtual SkImageCache* selectCache(const SkImageInfo&) = 0; - - private: - typedef SkRefCnt INHERITED; - }; - - /** - * Set the function to be used to select which SkImageCache to use. Mutually exclusive with - * fImageCache. - */ - void setCacheSelector(CacheSelector*); - -private: - DecodeProc fDecodeProc; - SkImageCache* fImageCache; - CacheSelector* fCacheSelector; -}; - -#endif // SkBitmapFactory_DEFINED diff --git a/include/lazy/SkImageCache.h b/include/lazy/SkImageCache.h deleted file mode 100644 index 6d30ae73f0..0000000000 --- a/include/lazy/SkImageCache.h +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2013 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkImageCache_DEFINED -#define SkImageCache_DEFINED - -#include "SkRefCnt.h" -#include "SkTypes.h" - -/** - * Interface for a cache that manages pixel memory. - */ -class SkImageCache : public SkRefCnt { - -public: - SK_DECLARE_INST_COUNT(SkImageCache) - - typedef intptr_t ID; - - /** - * Allocate memory whose lifetime is managed by the cache. On success, MUST be balanced with a - * call to releaseCache and a call to throwAwayCache. - * @param bytes Number of bytes needed. - * @param ID Output parameter which must not be NULL. On success, ID will be set to a value - * associated with that memory which can be used as a parameter to the other functions - * in SkImageCache. On failure, ID is unchanged. - * @return Pointer to the newly allocated memory, or NULL. This memory is safe to use until - * releaseCache is called with ID. - */ - virtual void* allocAndPinCache(size_t bytes, ID*) = 0; - - /** - * Output parameter for pinCache, stating whether the memory still contains the data it held - * when releaseCache was last called for the same ID. - */ - enum DataStatus { - /** - * The data has been purged, and therefore needs to be rewritten to the returned memory. - */ - kUninitialized_DataStatus, - - /** - * The memory still contains the data it held when releaseCache was last called with the - * same ID. - */ - kRetained_DataStatus, - }; - - /** - * Re-request the memory associated with ID and pin it so that it will not be reclaimed until - * the next call to releaseCache with the same ID. - * @param ID Unique ID for the memory block. - * @param status Output parameter which must not be NULL. On success (i.e. the return value is - * not NULL), status will be set to one of two states representing the cached memory. If - * status is set to kRetained_DataStatus, the memory contains the same data it did - * before releaseCache was called with this ID. If status is set to - * kUninitialized_DataStatus, the memory is still pinned, but the previous data is no - * longer available. If the return value is NULL, status is unchanged. - * @return Pointer: If non-NULL, points to the previously allocated memory, in which case - * this call must be balanced with a call to releaseCache. If NULL, the memory - * has been reclaimed, and throwAwayCache MUST NOT be called. - */ - virtual void* pinCache(ID, DataStatus* status) = 0; - - /** - * Inform the cache that it is safe to free the block of memory corresponding to ID. After - * calling this function, the pointer returned by allocAndPinCache or pinCache must not be - * used again. In order to access the same memory after this, pinCache must be called with - * the same ID. - * @param ID Unique ID for the memory block which is now safe to age out of the cache. - */ - virtual void releaseCache(ID) = 0; - - /** - * Inform the cache that the block of memory associated with ID will not be asked for again. - * After this call, ID is no longer valid. Must not be called while the associated memory is - * pinned. Must be called to balance a successful allocAndPinCache. - */ - virtual void throwAwayCache(ID) = 0; - - /** - * ID which does not correspond to any valid cache. - */ - static const ID UNINITIALIZED_ID = 0; - -#ifdef SK_DEBUG - /** - * Debug only status of a memory block. - */ - enum MemoryStatus { - /** - * It is safe to use the pointer returned by the most recent of allocAndPinCache(ID) or - * pinCache(ID) with the same ID. - */ - kPinned_MemoryStatus, - - /** - * The pointer returned by the most recent call to allocAndPinCache(ID) or pinCache(ID) has - * since been released by releaseCache(ID). In order to reuse it, pinCache(ID) must be - * called again. Note that after calling releaseCache(ID), the status of that particular - * ID may not be kUnpinned_MemoryStatus, depending on the implementation, but it will not - * be kPinned_MemoryStatus. - */ - kUnpinned_MemoryStatus, - - /** - * The memory associated with ID has been thrown away. No calls should be made using the - * same ID. - */ - kFreed_MemoryStatus, - }; - - /** - * Debug only function to get the status of a particular block of memory. Safe to call after - * throwAwayCache has been called with this ID. - */ - virtual MemoryStatus getMemoryStatus(intptr_t ID) const = 0; - - /** - * Debug only function to clear all unpinned caches. - */ - virtual void purgeAllUnpinnedCaches() = 0; -#endif - -private: - typedef SkRefCnt INHERITED; -}; -#endif // SkImageCache_DEFINED diff --git a/include/lazy/SkLruImageCache.h b/include/lazy/SkLruImageCache.h deleted file mode 100644 index 85095618b7..0000000000 --- a/include/lazy/SkLruImageCache.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2013 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkLruImageCache_DEFINED -#define SkLruImageCache_DEFINED - -#include "SkImageCache.h" -#include "SkThread.h" -#include "SkTInternalLList.h" - -class CachedPixels; - -/** - * SkImageCache implementation that uses an LRU cache to age out old images. - */ -class SkLruImageCache : public SkImageCache { - -public: - SK_DECLARE_INST_COUNT(SkLruImageCache) - - SkLruImageCache(size_t budget); - - virtual ~SkLruImageCache(); - -#ifdef SK_DEBUG - virtual MemoryStatus getMemoryStatus(ID) const SK_OVERRIDE; - virtual void purgeAllUnpinnedCaches() SK_OVERRIDE; -#endif - - /** - * Set the byte limit on cached pixels. If more bytes are used than this, the cache will free - * unpinned memory until under the new limit or until all unpinned memory is freed. This will - * never free pinned memory, so the cache can potentially remain over the limit. The limit is - * enforced each time memory is allocated or released. - * 0 is a special flag for an infinite budget. - * @return size_t The previous limit. - */ - size_t setImageCacheLimit(size_t newLimit); - - /** - * Return the number of bytes of memory currently in use by the cache. Can include memory that - * is no longer pinned, but has not been freed. - */ - size_t getImageCacheUsed() const { return fRamUsed; } - - virtual void* allocAndPinCache(size_t bytes, ID*) SK_OVERRIDE; - virtual void* pinCache(ID, SkImageCache::DataStatus*) SK_OVERRIDE; - virtual void releaseCache(ID) SK_OVERRIDE; - virtual void throwAwayCache(ID) SK_OVERRIDE; - -private: - // Linked list of recently used. Head is the most recently used, and tail is the least. - SkTInternalLList<CachedPixels> fLRU; - typedef SkTInternalLList<CachedPixels>::Iter Iter; - -#ifdef SK_DEBUG - // fMutex is mutable so that getMemoryStatus can be const - mutable -#endif - SkMutex fMutex; - size_t fRamBudget; - size_t fRamUsed; - - /** - * Find the CachedPixels represented by ID, or NULL if not in the cache. Mutex must be locked - * before calling. - */ - CachedPixels* findByID(ID) const; - - /** - * If over budget, throw away pixels which are not currently in use until below budget or there - * are no more pixels eligible to be thrown away. Mutex must be locked before calling. - */ - void purgeIfNeeded(); - - /** - * Purge until below limit. Mutex must be locked before calling. - */ - void purgeTilAtOrBelow(size_t limit); - - /** - * Remove a set of CachedPixels. Mutex must be locked before calling. - */ - void removePixels(CachedPixels*); - typedef SkImageCache INHERITED; -}; - -#endif // SkLruImageCache_DEFINED diff --git a/include/lazy/SkPurgeableImageCache.h b/include/lazy/SkPurgeableImageCache.h deleted file mode 100644 index a6889dfc03..0000000000 --- a/include/lazy/SkPurgeableImageCache.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2013 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkPurgeableImageCache_DEFINED -#define SkPurgeableImageCache_DEFINED - -#include "SkImageCache.h" - -#ifdef SK_DEBUG - #include "SkTDArray.h" -#endif - -/** - * Implementation for SkImageCache that uses system defined purgeable memory. - */ -class SkPurgeableImageCache : public SkImageCache { - -public: - SK_DECLARE_INST_COUNT(SkPurgeableImageCache) - - static SkImageCache* Create(); - - virtual void* allocAndPinCache(size_t bytes, ID*) SK_OVERRIDE; - virtual void* pinCache(ID, SkImageCache::DataStatus*) SK_OVERRIDE; - virtual void releaseCache(ID) SK_OVERRIDE; - virtual void throwAwayCache(ID) SK_OVERRIDE; - -#ifdef SK_DEBUG - virtual MemoryStatus getMemoryStatus(ID) const SK_OVERRIDE; - virtual void purgeAllUnpinnedCaches() SK_OVERRIDE; - virtual ~SkPurgeableImageCache(); -#endif - -private: - SkPurgeableImageCache(); - -#ifdef SK_DEBUG - SkTDArray<ID> fRecs; - int findRec(ID) const; -#endif - void removeRec(ID); - typedef SkImageCache INHERITED; -}; -#endif // SkPurgeableImageCache_DEFINED |