1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2011 Google Inc. 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 7ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com */ 88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkPathHeap_DEFINED 98a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkPathHeap_DEFINED 108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRefCnt.h" 128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkChunkAlloc.h" 138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkTDArray.h" 148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPath; 168b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.orgclass SkReadBuffer; 178b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.orgclass SkWriteBuffer; 188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPathHeap : public SkRefCnt { 208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic: 214d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com SK_DECLARE_INST_COUNT(SkPathHeap) 224d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com 234d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com SkPathHeap(); 248b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org SkPathHeap(SkReadBuffer&); 258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com virtual ~SkPathHeap(); 268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 27a6efe069040970a4d3b05e88484de4f82141f6e0reed@android.com /** Copy the path into the heap, and return the new total number of paths. 28a6efe069040970a4d3b05e88484de4f82141f6e0reed@android.com Thus, the returned value will be index+1, where index is the index of 29a6efe069040970a4d3b05e88484de4f82141f6e0reed@android.com this newly added (copied) path. 30a6efe069040970a4d3b05e88484de4f82141f6e0reed@android.com */ 318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int append(const SkPath&); 32fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 338c2ee5963505cdbe128f68d67f064a3901d22a3ccommit-bot@chromium.org /** Add the specified path to the heap using its gen ID to de-duplicate. 348c2ee5963505cdbe128f68d67f064a3901d22a3ccommit-bot@chromium.org Returns the path's index in the heap + 1. 358c2ee5963505cdbe128f68d67f064a3901d22a3ccommit-bot@chromium.org */ 368c2ee5963505cdbe128f68d67f064a3901d22a3ccommit-bot@chromium.org int insert(const SkPath&); 378c2ee5963505cdbe128f68d67f064a3901d22a3ccommit-bot@chromium.org 388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // called during picture-playback 398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com int count() const { return fPaths.count(); } 408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com const SkPath& operator[](int index) const { 418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com return *fPaths[index]; 428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com } 43fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 448b0e8ac5f582de80356019406e2975079bf0829dcommit-bot@chromium.org void flatten(SkWriteBuffer&) const; 45fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate: 478a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // we store the paths in the heap (placement new) 488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkChunkAlloc fHeap; 498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com // we just store ptrs into fHeap here 508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com SkTDArray<SkPath*> fPaths; 514d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com 528c2ee5963505cdbe128f68d67f064a3901d22a3ccommit-bot@chromium.org class LookupEntry { 538c2ee5963505cdbe128f68d67f064a3901d22a3ccommit-bot@chromium.org public: 548c2ee5963505cdbe128f68d67f064a3901d22a3ccommit-bot@chromium.org LookupEntry(const SkPath& path); 558c2ee5963505cdbe128f68d67f064a3901d22a3ccommit-bot@chromium.org 568c2ee5963505cdbe128f68d67f064a3901d22a3ccommit-bot@chromium.org int storageSlot() const { return fStorageSlot; } 578c2ee5963505cdbe128f68d67f064a3901d22a3ccommit-bot@chromium.org void setStorageSlot(int storageSlot) { fStorageSlot = storageSlot; } 588c2ee5963505cdbe128f68d67f064a3901d22a3ccommit-bot@chromium.org 598c2ee5963505cdbe128f68d67f064a3901d22a3ccommit-bot@chromium.org static bool Less(const LookupEntry& a, const LookupEntry& b) { 608c2ee5963505cdbe128f68d67f064a3901d22a3ccommit-bot@chromium.org return a.fGenerationID < b.fGenerationID; 618c2ee5963505cdbe128f68d67f064a3901d22a3ccommit-bot@chromium.org } 628c2ee5963505cdbe128f68d67f064a3901d22a3ccommit-bot@chromium.org 638c2ee5963505cdbe128f68d67f064a3901d22a3ccommit-bot@chromium.org private: 648c2ee5963505cdbe128f68d67f064a3901d22a3ccommit-bot@chromium.org uint32_t fGenerationID; // the SkPath's generation ID 658c2ee5963505cdbe128f68d67f064a3901d22a3ccommit-bot@chromium.org // the path's index in the heap + 1. It is 0 if the path is not yet in the heap. 66e62513fb9274b65bcd9fecf61acc418dd3949df5skia.committer@gmail.com int fStorageSlot; 678c2ee5963505cdbe128f68d67f064a3901d22a3ccommit-bot@chromium.org }; 688c2ee5963505cdbe128f68d67f064a3901d22a3ccommit-bot@chromium.org 698c2ee5963505cdbe128f68d67f064a3901d22a3ccommit-bot@chromium.org SkTDArray<LookupEntry> fLookupTable; 708c2ee5963505cdbe128f68d67f064a3901d22a3ccommit-bot@chromium.org 718c2ee5963505cdbe128f68d67f064a3901d22a3ccommit-bot@chromium.org SkPathHeap::LookupEntry* addIfNotPresent(const SkPath& path); 728c2ee5963505cdbe128f68d67f064a3901d22a3ccommit-bot@chromium.org 734d73ac22a1b99402fc8cff78a4eb4b27aa8fe019robertphillips@google.com typedef SkRefCnt INHERITED; 748a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com}; 758a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com 768a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif 77