blob: 6625a846fe34573524b5bb88de23ae2066900b95 [file] [log] [blame]
rileya@google.com1f45e932012-09-05 16:10:59 +00001
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.com48134582012-09-11 15:41:50 +000014#include "SkRefCnt.h"
rileya@google.com1f45e932012-09-05 16:10:59 +000015
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.com48134582012-09-11 15:41:50 +000020class SkBBoxHierarchy : public SkRefCnt {
rileya@google.com1f45e932012-09-05 16:10:59 +000021public:
rileya@google.com48134582012-09-11 15:41:50 +000022 SK_DECLARE_INST_COUNT(SkBBoxHierarchy)
rileya@google.com1f45e932012-09-05 16:10:59 +000023
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.com48134582012-09-11 15:41:50 +000051
52private:
53 typedef SkRefCnt INHERITED;
rileya@google.com1f45e932012-09-05 16:10:59 +000054};
55
56#endif
57