aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkBitmapHeap.h
diff options
context:
space:
mode:
authorGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-14 15:20:01 +0000
committerGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-08-14 15:20:01 +0000
commit3e26bd0c357d849ff40b092decd7a5c46ec2ada4 (patch)
treed8ba75d3d1c99f4af9eb15b314023e1b6728fd11 /src/core/SkBitmapHeap.h
parent6d552ee5f56e76da6ba244df0f0df2234f2d8977 (diff)
Check in r5063 again, along with fix for tests.
Thank you to Android build, for catching the problem, which would show up elsewhere. Now we access entry->fStorageSlot before deleting entry. (Original message:) Use the SkBitmapHeap to handle SkBitmaps in SkGPipe cross process. Required moving the LRU handles from SkBitmapHeapEntry to LookupEntry. Allows simplification of drawBitmap* calls in SkGPipeCanvas. Review URL: https://codereview.appspot.com/6453113 git-svn-id: http://skia.googlecode.com/svn/trunk@5081 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core/SkBitmapHeap.h')
-rw-r--r--src/core/SkBitmapHeap.h86
1 files changed, 47 insertions, 39 deletions
diff --git a/src/core/SkBitmapHeap.h b/src/core/SkBitmapHeap.h
index 3c00b5211b..71c340539f 100644
--- a/src/core/SkBitmapHeap.h
+++ b/src/core/SkBitmapHeap.h
@@ -39,16 +39,12 @@ private:
int32_t fSlot;
int32_t fRefCount;
- uint32_t fGenerationID;
SkBitmap fBitmap;
// Keep track of the bytes allocated for this bitmap. When replacing the
// bitmap or removing this HeapEntry we know how much memory has been
// reclaimed.
size_t fBytesAllocated;
- // TODO: Generalize the LRU caching mechanism
- SkBitmapHeapEntry* fMoreRecentlyUsed;
- SkBitmapHeapEntry* fLessRecentlyUsed;
friend class SkBitmapHeap;
};
@@ -176,7 +172,8 @@ public:
* Returns a count of the number of items currently in the heap
*/
int count() const {
- SkASSERT(fExternalStorage != NULL || fStorage.count() == fLookupTable.count());
+ SkASSERT(fExternalStorage != NULL ||
+ fStorage.count() - fUnusedSlots.count() == fLookupTable.count());
return fLookupTable.count();
}
@@ -197,43 +194,39 @@ public:
private:
struct LookupEntry {
- LookupEntry(const SkBitmap& bm, uint32_t genId = 0) {
- fGenerationId = 0 == genId ? bm.getGenerationID() : genId;
- fPixelOffset = bm.pixelRefOffset();
- fWidth = bm.width();
- fHeight = bm.height();
- }
- uint32_t fGenerationId; // SkPixelRef GenerationID.
- size_t fPixelOffset;
- uint32_t fWidth;
- uint32_t fHeight;
+ LookupEntry(const SkBitmap& bm)
+ : fGenerationId(bm.getGenerationID())
+ , fPixelOffset(bm.pixelRefOffset())
+ , fWidth(bm.width())
+ , fHeight(bm.height())
+ , fMoreRecentlyUsed(NULL)
+ , fLessRecentlyUsed(NULL){}
+
+ const uint32_t fGenerationId; // SkPixelRef GenerationID.
+ const size_t fPixelOffset;
+ const uint32_t fWidth;
+ const uint32_t fHeight;
+
+ // TODO: Generalize the LRU caching mechanism
+ LookupEntry* fMoreRecentlyUsed;
+ LookupEntry* fLessRecentlyUsed;
uint32_t fStorageSlot; // slot of corresponding bitmap in fStorage.
- bool operator < (const LookupEntry& other) const {
- if (this->fGenerationId != other.fGenerationId) {
- return this->fGenerationId < other.fGenerationId;
- } else if(this->fPixelOffset != other.fPixelOffset) {
- return this->fPixelOffset < other.fPixelOffset;
- } else if(this->fWidth != other.fWidth) {
- return this->fWidth < other.fWidth;
- } else {
- return this->fHeight < other.fHeight;
- }
- }
- bool operator != (const LookupEntry& other) const {
- return this->fGenerationId != other.fGenerationId
- || this->fPixelOffset != other.fPixelOffset
- || this->fWidth != other.fWidth
- || this->fHeight != other.fHeight;
- }
+ /**
+ * Compare two LookupEntry pointers, returning -1, 0, 1 for sorting.
+ */
+ static int Compare(const LookupEntry* a, const LookupEntry* b);
};
/**
- * Remove the entry from the lookup table.
+ * Remove the entry from the lookup table. Also deletes the entry pointed
+ * to by the table. Therefore, if a pointer to that one was passed in, the
+ * pointer should no longer be used, since the object to which it points has
+ * been deleted.
* @return The index in the lookup table of the entry before removal.
*/
- int removeEntryFromLookupTable(const SkBitmapHeapEntry&);
+ int removeEntryFromLookupTable(LookupEntry*);
/**
* Searches for the bitmap in the lookup table and returns the bitmaps index within the table.
@@ -245,12 +238,27 @@ private:
*/
int findInLookupTable(const LookupEntry& key, SkBitmapHeapEntry** entry);
- SkBitmapHeapEntry* findEntryToReplace(const SkBitmap& replacement);
+ LookupEntry* findEntryToReplace(const SkBitmap& replacement);
bool copyBitmap(const SkBitmap& originalBitmap, SkBitmap& copiedBitmap);
- void setMostRecentlyUsed(SkBitmapHeapEntry* entry);
+
+ /**
+ * Remove a LookupEntry from the LRU, in preparation for either deleting or appending as most
+ * recent. Points the LookupEntry's old neighbors at each other, and sets fLeastRecentlyUsed
+ * (if there is still an entry left). Sets LookupEntry's fMoreRecentlyUsed to NULL and leaves
+ * its fLessRecentlyUsed unmodified.
+ */
+ void removeFromLRU(LookupEntry* entry);
+
+ /**
+ * Append a LookupEntry to the end of the LRU cache, marking it as the most
+ * recently used. Assumes that the LookupEntry is already in fLookupTable,
+ * but is not in the LRU cache. If it is in the cache, removeFromLRU should
+ * be called first.
+ */
+ void appendToLRU(LookupEntry*);
// searchable index that maps to entries in the heap
- SkTDArray<LookupEntry> fLookupTable;
+ SkTDArray<LookupEntry*> fLookupTable;
// heap storage
SkTDArray<SkBitmapHeapEntry*> fStorage;
@@ -259,8 +267,8 @@ private:
SkTDArray<int> fUnusedSlots;
ExternalStorage* fExternalStorage;
- SkBitmapHeapEntry* fMostRecentlyUsed;
- SkBitmapHeapEntry* fLeastRecentlyUsed;
+ LookupEntry* fMostRecentlyUsed;
+ LookupEntry* fLeastRecentlyUsed;
const int32_t fPreferredCount;
const int32_t fOwnerCount;