diff options
author | Derek Sollenberger <djsollen@google.com> | 2014-12-04 15:20:29 -0500 |
---|---|---|
committer | Derek Sollenberger <djsollen@google.com> | 2015-01-09 13:56:56 -0500 |
commit | 3d4eed7f1aa99401dabe2e45b82f98fb4fc2d754 (patch) | |
tree | e727b03577a823f638cab2f76a8a1161b73662eb /libs/hwui/ResourceCache.h | |
parent | 83eb4443a9d24f2ae4a1e516354748850c10d06b (diff) | |
download | frameworks_base-3d4eed7f1aa99401dabe2e45b82f98fb4fc2d754.zip frameworks_base-3d4eed7f1aa99401dabe2e45b82f98fb4fc2d754.tar.gz frameworks_base-3d4eed7f1aa99401dabe2e45b82f98fb4fc2d754.tar.bz2 |
Update HWUI to store its own SkBitmap objects
This enables us to...
1) simplify the lifecycle/ownership between Java and HWUI
2) remove DisplayListRenderer::drawBitmapData and associated logic
3) track pixel lifecycle using standard SkPixelRef refcounting
4) Remove uncessary calls to ref/unref the bitmap's pixels and colorTable
Change-Id: I3c95078da20995444f6388a029414280fd654318
Diffstat (limited to 'libs/hwui/ResourceCache.h')
-rw-r--r-- | libs/hwui/ResourceCache.h | 53 |
1 files changed, 40 insertions, 13 deletions
diff --git a/libs/hwui/ResourceCache.h b/libs/hwui/ResourceCache.h index a252f6c..c6483ac 100644 --- a/libs/hwui/ResourceCache.h +++ b/libs/hwui/ResourceCache.h @@ -21,6 +21,7 @@ #include <SkBitmap.h> #include <SkPath.h> +#include <SkPixelRef.h> #include <utils/KeyedVector.h> #include <utils/Singleton.h> @@ -36,7 +37,6 @@ class Layer; * Type of Resource being cached */ enum ResourceType { - kBitmap, kNinePatch, kPath }; @@ -45,15 +45,45 @@ 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 class android::key_value_pair_t<BitmapKey, SkBitmap*>; +}; + class ANDROID_API ResourceCache: public Singleton<ResourceCache> { ResourceCache(); ~ResourceCache(); @@ -69,14 +99,15 @@ public: void lock(); void unlock(); + /** + * 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 incrementRefcount(const SkPath* resource); - void incrementRefcount(const SkBitmap* resource); void incrementRefcount(const Res_png_9patch* resource); - void incrementRefcountLocked(const SkPath* resource); - void incrementRefcountLocked(const SkBitmap* resource); - void incrementRefcountLocked(const Res_png_9patch* resource); - void decrementRefcount(const SkBitmap* resource); void decrementRefcount(const SkPath* resource); void decrementRefcount(const Res_png_9patch* resource); @@ -86,16 +117,11 @@ public: 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); @@ -115,6 +141,7 @@ private: mutable Mutex mLock; KeyedVector<const void*, ResourceReference*>* mCache; + KeyedVector<BitmapKey, SkBitmap*> mBitmapCache; }; }; // namespace uirenderer |