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