rileya@google.com | 1f45e93 | 2012-09-05 16:10:59 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 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 | */ |
| 8 | |
| 9 | #ifndef SkBBoxHierarchy_DEFINED |
| 10 | #define SkBBoxHierarchy_DEFINED |
| 11 | |
| 12 | #include "SkRect.h" |
| 13 | #include "SkTDArray.h" |
rileya@google.com | 4813458 | 2012-09-11 15:41:50 +0000 | [diff] [blame^] | 14 | #include "SkRefCnt.h" |
rileya@google.com | 1f45e93 | 2012-09-05 16:10:59 +0000 | [diff] [blame] | 15 | |
| 16 | /** |
| 17 | * Interface for a spatial data structure that associates user data pointers with axis-aligned |
| 18 | * bounding boxes, and allows efficient retrieval of intersections with query rectangles. |
| 19 | */ |
rileya@google.com | 4813458 | 2012-09-11 15:41:50 +0000 | [diff] [blame^] | 20 | class SkBBoxHierarchy : public SkRefCnt { |
rileya@google.com | 1f45e93 | 2012-09-05 16:10:59 +0000 | [diff] [blame] | 21 | public: |
rileya@google.com | 4813458 | 2012-09-11 15:41:50 +0000 | [diff] [blame^] | 22 | SK_DECLARE_INST_COUNT(SkBBoxHierarchy) |
rileya@google.com | 1f45e93 | 2012-09-05 16:10:59 +0000 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * Insert a data pointer and corresponding bounding box |
| 26 | * @param data The data pointer, may be NULL |
| 27 | * @param bounds The bounding box, should not be empty |
| 28 | * @param defer Whether or not it is acceptable to delay insertion of this element (building up |
| 29 | * an entire spatial data structure at once is often faster and produces better |
| 30 | * structures than repeated inserts) until flushDeferredInserts is called or the first |
| 31 | * search. |
| 32 | */ |
| 33 | virtual void insert(void* data, const SkIRect& bounds, bool defer = false) = 0; |
| 34 | |
| 35 | /** |
| 36 | * If any insertions have been deferred, this forces them to be inserted |
| 37 | */ |
| 38 | virtual void flushDeferredInserts() = 0; |
| 39 | |
| 40 | /** |
| 41 | * Populate 'results' with data pointers corresponding to bounding boxes that intersect 'query' |
| 42 | */ |
| 43 | virtual void search(const SkIRect& query, SkTDArray<void*>* results) = 0; |
| 44 | |
| 45 | virtual void clear() = 0; |
| 46 | |
| 47 | /** |
| 48 | * Gets the number of insertions |
| 49 | */ |
| 50 | virtual int getCount() const = 0; |
rileya@google.com | 4813458 | 2012-09-11 15:41:50 +0000 | [diff] [blame^] | 51 | |
| 52 | private: |
| 53 | typedef SkRefCnt INHERITED; |
rileya@google.com | 1f45e93 | 2012-09-05 16:10:59 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | #endif |
| 57 | |