diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkPathHeap.cpp | 33 | ||||
-rw-r--r-- | src/core/SkPathHeap.h | 26 | ||||
-rw-r--r-- | src/core/SkPictureRecord.cpp | 4 |
3 files changed, 63 insertions, 0 deletions
diff --git a/src/core/SkPathHeap.cpp b/src/core/SkPathHeap.cpp index a8271e1fa2..d71257d731 100644 --- a/src/core/SkPathHeap.cpp +++ b/src/core/SkPathHeap.cpp @@ -9,6 +9,7 @@ #include "SkPath.h" #include "SkStream.h" #include "SkReadBuffer.h" +#include "SkTSearch.h" #include "SkWriteBuffer.h" #include <new> @@ -49,6 +50,38 @@ int SkPathHeap::append(const SkPath& path) { return fPaths.count(); } +SkPathHeap::LookupEntry::LookupEntry(const SkPath& path) + : fGenerationID(path.getGenerationID()), fStorageSlot(0) { +} + +SkPathHeap::LookupEntry* SkPathHeap::addIfNotPresent(const SkPath& path) { + LookupEntry searchKey(path); + int index = SkTSearch<const LookupEntry, LookupEntry::Less>( + fLookupTable.begin(), + fLookupTable.count(), + searchKey, + sizeof(LookupEntry)); + if (index < 0) { + index = ~index; + *fLookupTable.insert(index) = LookupEntry(path); + } + + return &fLookupTable[index];; +} + +int SkPathHeap::insert(const SkPath& path) { + SkPathHeap::LookupEntry* entry = this->addIfNotPresent(path); + + if (entry->storageSlot() > 0) { + return entry->storageSlot(); + } + + int newSlot = this->append(path); + SkASSERT(newSlot > 0); + entry->setStorageSlot(newSlot); + return newSlot; +} + void SkPathHeap::flatten(SkWriteBuffer& buffer) const { int count = fPaths.count(); diff --git a/src/core/SkPathHeap.h b/src/core/SkPathHeap.h index e3b0f7a84f..7fdcdd93e0 100644 --- a/src/core/SkPathHeap.h +++ b/src/core/SkPathHeap.h @@ -30,6 +30,11 @@ public: */ int append(const SkPath&); + /** Add the specified path to the heap using its gen ID to de-duplicate. + Returns the path's index in the heap + 1. + */ + int insert(const SkPath&); + // called during picture-playback int count() const { return fPaths.count(); } const SkPath& operator[](int index) const { @@ -44,6 +49,27 @@ private: // we just store ptrs into fHeap here SkTDArray<SkPath*> fPaths; + class LookupEntry { + public: + LookupEntry(const SkPath& path); + + int storageSlot() const { return fStorageSlot; } + void setStorageSlot(int storageSlot) { fStorageSlot = storageSlot; } + + static bool Less(const LookupEntry& a, const LookupEntry& b) { + return a.fGenerationID < b.fGenerationID; + } + + private: + uint32_t fGenerationID; // the SkPath's generation ID + // the path's index in the heap + 1. It is 0 if the path is not yet in the heap. + int fStorageSlot; + }; + + SkTDArray<LookupEntry> fLookupTable; + + SkPathHeap::LookupEntry* addIfNotPresent(const SkPath& path); + typedef SkRefCnt INHERITED; }; diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp index b9e8b93843..08b69b8527 100644 --- a/src/core/SkPictureRecord.cpp +++ b/src/core/SkPictureRecord.cpp @@ -1672,7 +1672,11 @@ int SkPictureRecord::addPathToHeap(const SkPath& path) { if (NULL == fPathHeap) { fPathHeap = SkNEW(SkPathHeap); } +#ifdef SK_DEDUP_PICTURE_PATHS + return fPathHeap->insert(path); +#else return fPathHeap->append(path); +#endif } void SkPictureRecord::addPath(const SkPath& path) { |