SkBBoxHierarchy.h revision 4813458d89fb276680168848bd861b307cf83f51
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"
14#include "SkRefCnt.h"
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 */
20class SkBBoxHierarchy : public SkRefCnt {
21public:
22    SK_DECLARE_INST_COUNT(SkBBoxHierarchy)
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;
51
52private:
53    typedef SkRefCnt INHERITED;
54};
55
56#endif
57
58