diff options
Diffstat (limited to 'chromium/third_party/skia/src/core/SkPathHeap.cpp')
-rw-r--r-- | chromium/third_party/skia/src/core/SkPathHeap.cpp | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/chromium/third_party/skia/src/core/SkPathHeap.cpp b/chromium/third_party/skia/src/core/SkPathHeap.cpp index c6e2129e9ed..84ffb04b80e 100644 --- a/chromium/third_party/skia/src/core/SkPathHeap.cpp +++ b/chromium/third_party/skia/src/core/SkPathHeap.cpp @@ -8,7 +8,9 @@ #include "SkPathHeap.h" #include "SkPath.h" #include "SkStream.h" -#include "SkFlattenableBuffers.h" +#include "SkReadBuffer.h" +#include "SkTSearch.h" +#include "SkWriteBuffer.h" #include <new> #define kPathCount 64 @@ -16,7 +18,7 @@ SkPathHeap::SkPathHeap() : fHeap(kPathCount * sizeof(SkPath)) { } -SkPathHeap::SkPathHeap(SkFlattenableReadBuffer& buffer) +SkPathHeap::SkPathHeap(SkReadBuffer& buffer) : fHeap(kPathCount * sizeof(SkPath)) { const int count = buffer.readInt(); @@ -48,7 +50,39 @@ int SkPathHeap::append(const SkPath& path) { return fPaths.count(); } -void SkPathHeap::flatten(SkFlattenableWriteBuffer& buffer) const { +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(); buffer.writeInt(count); |