diff options
Diffstat (limited to 'libs/hwui/ResourceCache.h')
| -rw-r--r-- | libs/hwui/ResourceCache.h | 63 |
1 files changed, 42 insertions, 21 deletions
diff --git a/libs/hwui/ResourceCache.h b/libs/hwui/ResourceCache.h index f12f2a4..fae55d1 100644 --- a/libs/hwui/ResourceCache.h +++ b/libs/hwui/ResourceCache.h @@ -20,39 +20,68 @@ #include <cutils/compiler.h> #include <SkBitmap.h> +#include <SkPixelRef.h> #include <utils/KeyedVector.h> #include <utils/Singleton.h> #include <androidfw/ResourceTypes.h> -#include "Layer.h" - namespace android { namespace uirenderer { +class Layer; + /** * Type of Resource being cached */ enum ResourceType { - kBitmap, kNinePatch, - kPath }; class ResourceReference { public: ResourceReference(ResourceType type) { - refCount = 0; recycled = false; destroyed = false; resourceType = type; + refCount = 0; destroyed = false; resourceType = type; } int refCount; - bool recycled; bool destroyed; ResourceType resourceType; }; +class BitmapKey { +public: + BitmapKey(const SkBitmap* bitmap) + : mRefCount(1) + , mBitmapDimensions(bitmap->dimensions()) + , mPixelRefOrigin(bitmap->pixelRefOrigin()) + , mPixelRefStableID(bitmap->pixelRef()->getStableID()) { } + + void operator=(const BitmapKey& other); + bool operator==(const BitmapKey& other) const; + bool operator<(const BitmapKey& other) const; + +private: + // This constructor is only used by the KeyedVector implementation + BitmapKey() + : mRefCount(-1) + , mBitmapDimensions(SkISize::Make(0,0)) + , mPixelRefOrigin(SkIPoint::Make(0,0)) + , mPixelRefStableID(0) { } + + // reference count of all HWUI object using this bitmap + mutable int mRefCount; + + SkISize mBitmapDimensions; + SkIPoint mPixelRefOrigin; + uint32_t mPixelRefStableID; + + friend class ResourceCache; + friend struct android::key_value_pair_t<BitmapKey, SkBitmap*>; +}; + class ANDROID_API ResourceCache: public Singleton<ResourceCache> { ResourceCache(); ~ResourceCache(); @@ -68,33 +97,24 @@ public: void lock(); void unlock(); - void incrementRefcount(const SkPath* resource); - void incrementRefcount(const SkBitmap* resource); - void incrementRefcount(const Res_png_9patch* resource); + /** + * The cache stores a copy of the provided resource or refs an existing resource + * if the bitmap has previously been inserted and returns the cached copy. + */ + const SkBitmap* insert(const SkBitmap* resource); - void incrementRefcountLocked(const SkPath* resource); - void incrementRefcountLocked(const SkBitmap* resource); - void incrementRefcountLocked(const Res_png_9patch* resource); + void incrementRefcount(const Res_png_9patch* resource); void decrementRefcount(const SkBitmap* resource); - void decrementRefcount(const SkPath* resource); void decrementRefcount(const Res_png_9patch* resource); void decrementRefcountLocked(const SkBitmap* resource); - void decrementRefcountLocked(const SkPath* resource); void decrementRefcountLocked(const Res_png_9patch* resource); - void destructor(SkPath* resource); - void destructor(const SkBitmap* resource); void destructor(Res_png_9patch* resource); - void destructorLocked(SkPath* resource); - void destructorLocked(const SkBitmap* resource); void destructorLocked(Res_png_9patch* resource); - bool recycle(SkBitmap* resource); - bool recycleLocked(SkBitmap* resource); - private: void deleteResourceReferenceLocked(const void* resource, ResourceReference* ref); @@ -114,6 +134,7 @@ private: mutable Mutex mLock; KeyedVector<const void*, ResourceReference*>* mCache; + KeyedVector<BitmapKey, SkBitmap*> mBitmapCache; }; }; // namespace uirenderer |
