| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #ifndef SkBBoxHierarchy_DEFINED | 9 #ifndef SkBBoxHierarchy_DEFINED |
| 10 #define SkBBoxHierarchy_DEFINED | 10 #define SkBBoxHierarchy_DEFINED |
| 11 | 11 |
| 12 #include "SkRect.h" | 12 #include "SkRect.h" |
| 13 #include "SkTDArray.h" | 13 #include "SkTDArray.h" |
| 14 #include "SkRefCnt.h" | 14 #include "SkRefCnt.h" |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * Interface for a client class that implements utility methods needed | 17 * Interface for a spatial data structure that associates user data with axis-al
igned |
| 18 * by SkBBoxHierarchy that require intrinsic knowledge of the data | |
| 19 * object type that is stored in the bounding box hierarchy. | |
| 20 */ | |
| 21 class SkBBoxHierarchyClient { | |
| 22 public: | |
| 23 virtual ~SkBBoxHierarchyClient() {} | |
| 24 | |
| 25 /** | |
| 26 * Implements a rewind stop condition used by rewindInserts | |
| 27 * Must returns true if 'data' points to an object that should be re-wound | |
| 28 * by rewinfInserts. | |
| 29 */ | |
| 30 virtual bool shouldRewind(void* data) = 0; | |
| 31 }; | |
| 32 | |
| 33 /** | |
| 34 * Interface for a spatial data structure that associates user data pointers wit
h axis-aligned | |
| 35 * bounding boxes, and allows efficient retrieval of intersections with query re
ctangles. | 18 * bounding boxes, and allows efficient retrieval of intersections with query re
ctangles. |
| 36 */ | 19 */ |
| 37 class SkBBoxHierarchy : public SkRefCnt { | 20 class SkBBoxHierarchy : public SkRefCnt { |
| 38 public: | 21 public: |
| 39 SK_DECLARE_INST_COUNT(SkBBoxHierarchy) | 22 SK_DECLARE_INST_COUNT(SkBBoxHierarchy) |
| 40 | 23 |
| 41 SkBBoxHierarchy() : fClient(NULL) {} | 24 SkBBoxHierarchy() {} |
| 42 | 25 |
| 43 /** | 26 /** |
| 44 * Insert a data pointer and corresponding bounding box | 27 * Insert opIndex and corresponding bounding box |
| 45 * @param data The data pointer, may be NULL | 28 * @param opIndex Any value, will be returned in order. |
| 46 * @param bounds The bounding box, should not be empty | 29 * @param bounds The bounding box, should not be empty |
| 47 * @param defer Whether or not it is acceptable to delay insertion of this e
lement (building up | 30 * @param defer Whether or not it is acceptable to delay insertion of this e
lement (building up |
| 48 * an entire spatial data structure at once is often faster and produ
ces better | 31 * an entire spatial data structure at once is often faster and produ
ces better |
| 49 * structures than repeated inserts) until flushDeferredInserts is ca
lled or the first | 32 * structures than repeated inserts) until flushDeferredInserts is ca
lled or the first |
| 50 * search. | 33 * search. |
| 51 */ | 34 */ |
| 52 virtual void insert(void* data, const SkRect& bounds, bool defer = false) =
0; | 35 virtual void insert(unsigned opIndex, const SkRect& bounds, bool defer = fal
se) = 0; |
| 53 | 36 |
| 54 /** | 37 /** |
| 55 * If any insertions have been deferred, this forces them to be inserted | 38 * If any insertions have been deferred, this forces them to be inserted |
| 56 */ | 39 */ |
| 57 virtual void flushDeferredInserts() = 0; | 40 virtual void flushDeferredInserts() = 0; |
| 58 | 41 |
| 59 /** | 42 /** |
| 60 * Populate 'results' with data pointers corresponding to bounding boxes tha
t intersect 'query' | 43 * Populate results with sorted opIndex corresponding to bounding boxes that
intersect query. |
| 61 */ | 44 */ |
| 62 virtual void search(const SkRect& query, SkTDArray<void*>* results) const =
0; | 45 virtual void search(const SkRect& query, SkTDArray<unsigned>* results) const
= 0; |
| 63 | 46 |
| 64 virtual void clear() = 0; | 47 virtual void clear() = 0; |
| 65 | 48 |
| 66 /** | 49 /** |
| 67 * Gets the number of insertions actually made (does not include deferred in
sertions) | 50 * Gets the number of insertions actually made (does not include deferred in
sertions) |
| 68 */ | 51 */ |
| 69 virtual int getCount() const = 0; | 52 virtual int getCount() const = 0; |
| 70 | 53 |
| 71 /** | 54 /** |
| 72 * Returns the depth of the currently allocated tree. The root node counts f
or 1 level, | 55 * Returns the depth of the currently allocated tree. The root node counts f
or 1 level, |
| 73 * so it should be 1 or more if there's a root node. This information provid
es details | 56 * so it should be 1 or more if there's a root node. This information provid
es details |
| 74 * about the underlying structure, which is useful mainly for testing purpos
es. | 57 * about the underlying structure, which is useful mainly for testing purpos
es. |
| 75 * | 58 * |
| 76 * Returns 0 if there are currently no nodes in the tree. | 59 * Returns 0 if there are currently no nodes in the tree. |
| 77 * Returns -1 if the structure isn't a tree. | 60 * Returns -1 if the structure isn't a tree. |
| 78 */ | 61 */ |
| 79 virtual int getDepth() const = 0; | 62 virtual int getDepth() const = 0; |
| 80 | 63 |
| 81 /** | |
| 82 * Rewinds all the most recently inserted data elements until an element | |
| 83 * is encountered for which client->shouldRewind(data) returns false. May | |
| 84 * not rewind elements that were inserted prior to the last call to | |
| 85 * flushDeferredInserts. | |
| 86 */ | |
| 87 virtual void rewindInserts() = 0; | |
| 88 | |
| 89 void setClient(SkBBoxHierarchyClient* client) { fClient = client; } | |
| 90 | |
| 91 protected: | |
| 92 SkBBoxHierarchyClient* fClient; | |
| 93 | |
| 94 private: | 64 private: |
| 95 typedef SkRefCnt INHERITED; | 65 typedef SkRefCnt INHERITED; |
| 96 }; | 66 }; |
| 97 | 67 |
| 98 #endif | 68 #endif |
| OLD | NEW |