michael@0: michael@0: /* michael@0: * Copyright 2011 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: #ifndef SkPathHeap_DEFINED michael@0: #define SkPathHeap_DEFINED michael@0: michael@0: #include "SkRefCnt.h" michael@0: #include "SkChunkAlloc.h" michael@0: #include "SkTDArray.h" michael@0: michael@0: class SkPath; michael@0: class SkReadBuffer; michael@0: class SkWriteBuffer; michael@0: michael@0: class SkPathHeap : public SkRefCnt { michael@0: public: michael@0: SK_DECLARE_INST_COUNT(SkPathHeap) michael@0: michael@0: SkPathHeap(); michael@0: SkPathHeap(SkReadBuffer&); michael@0: virtual ~SkPathHeap(); michael@0: michael@0: /** Copy the path into the heap, and return the new total number of paths. michael@0: Thus, the returned value will be index+1, where index is the index of michael@0: this newly added (copied) path. michael@0: */ michael@0: int append(const SkPath&); michael@0: michael@0: /** Add the specified path to the heap using its gen ID to de-duplicate. michael@0: Returns the path's index in the heap + 1. michael@0: */ michael@0: int insert(const SkPath&); michael@0: michael@0: // called during picture-playback michael@0: int count() const { return fPaths.count(); } michael@0: const SkPath& operator[](int index) const { michael@0: return *fPaths[index]; michael@0: } michael@0: michael@0: void flatten(SkWriteBuffer&) const; michael@0: michael@0: private: michael@0: // we store the paths in the heap (placement new) michael@0: SkChunkAlloc fHeap; michael@0: // we just store ptrs into fHeap here michael@0: SkTDArray fPaths; michael@0: michael@0: class LookupEntry { michael@0: public: michael@0: LookupEntry(const SkPath& path); michael@0: michael@0: int storageSlot() const { return fStorageSlot; } michael@0: void setStorageSlot(int storageSlot) { fStorageSlot = storageSlot; } michael@0: michael@0: static bool Less(const LookupEntry& a, const LookupEntry& b) { michael@0: return a.fGenerationID < b.fGenerationID; michael@0: } michael@0: michael@0: private: michael@0: uint32_t fGenerationID; // the SkPath's generation ID michael@0: // the path's index in the heap + 1. It is 0 if the path is not yet in the heap. michael@0: int fStorageSlot; michael@0: }; michael@0: michael@0: SkTDArray fLookupTable; michael@0: michael@0: SkPathHeap::LookupEntry* addIfNotPresent(const SkPath& path); michael@0: michael@0: typedef SkRefCnt INHERITED; michael@0: }; michael@0: michael@0: #endif