epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | #ifndef SkPathHeap_DEFINED |
| 9 | #define SkPathHeap_DEFINED |
| 10 | |
| 11 | #include "SkRefCnt.h" |
| 12 | #include "SkChunkAlloc.h" |
| 13 | #include "SkTDArray.h" |
| 14 | |
| 15 | class SkPath; |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 16 | class SkReadBuffer; |
| 17 | class SkWriteBuffer; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 18 | |
| 19 | class SkPathHeap : public SkRefCnt { |
| 20 | public: |
robertphillips@google.com | 4d73ac2 | 2012-06-13 18:54:08 +0000 | [diff] [blame] | 21 | SK_DECLARE_INST_COUNT(SkPathHeap) |
| 22 | |
| 23 | SkPathHeap(); |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 24 | SkPathHeap(SkReadBuffer&); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 25 | virtual ~SkPathHeap(); |
| 26 | |
reed@android.com | a6efe06 | 2010-03-05 18:46:37 +0000 | [diff] [blame] | 27 | /** Copy the path into the heap, and return the new total number of paths. |
| 28 | Thus, the returned value will be index+1, where index is the index of |
| 29 | this newly added (copied) path. |
| 30 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 31 | int append(const SkPath&); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 32 | |
commit-bot@chromium.org | 8c2ee59 | 2014-03-07 18:42:15 +0000 | [diff] [blame] | 33 | /** Add the specified path to the heap using its gen ID to de-duplicate. |
| 34 | Returns the path's index in the heap + 1. |
| 35 | */ |
| 36 | int insert(const SkPath&); |
| 37 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 38 | // called during picture-playback |
| 39 | int count() const { return fPaths.count(); } |
| 40 | const SkPath& operator[](int index) const { |
| 41 | return *fPaths[index]; |
| 42 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 43 | |
commit-bot@chromium.org | 8b0e8ac | 2014-01-30 18:58:24 +0000 | [diff] [blame] | 44 | void flatten(SkWriteBuffer&) const; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 45 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 46 | private: |
| 47 | // we store the paths in the heap (placement new) |
| 48 | SkChunkAlloc fHeap; |
| 49 | // we just store ptrs into fHeap here |
| 50 | SkTDArray<SkPath*> fPaths; |
robertphillips@google.com | 4d73ac2 | 2012-06-13 18:54:08 +0000 | [diff] [blame] | 51 | |
commit-bot@chromium.org | 8c2ee59 | 2014-03-07 18:42:15 +0000 | [diff] [blame] | 52 | class LookupEntry { |
| 53 | public: |
| 54 | LookupEntry(const SkPath& path); |
| 55 | |
| 56 | int storageSlot() const { return fStorageSlot; } |
| 57 | void setStorageSlot(int storageSlot) { fStorageSlot = storageSlot; } |
| 58 | |
| 59 | static bool Less(const LookupEntry& a, const LookupEntry& b) { |
| 60 | return a.fGenerationID < b.fGenerationID; |
| 61 | } |
| 62 | |
| 63 | private: |
| 64 | uint32_t fGenerationID; // the SkPath's generation ID |
| 65 | // the path's index in the heap + 1. It is 0 if the path is not yet in the heap. |
skia.committer@gmail.com | e62513f | 2014-03-08 03:02:06 +0000 | [diff] [blame] | 66 | int fStorageSlot; |
commit-bot@chromium.org | 8c2ee59 | 2014-03-07 18:42:15 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | SkTDArray<LookupEntry> fLookupTable; |
| 70 | |
| 71 | SkPathHeap::LookupEntry* addIfNotPresent(const SkPath& path); |
| 72 | |
robertphillips@google.com | 4d73ac2 | 2012-06-13 18:54:08 +0000 | [diff] [blame] | 73 | typedef SkRefCnt INHERITED; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | #endif |