SkBBoxHierarchy.h revision 4813458d89fb276680168848bd861b307cf83f51
11f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com
21f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com/*
31f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com * Copyright 2012 Google Inc.
41f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com *
51f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com * Use of this source code is governed by a BSD-style license that can be
61f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com * found in the LICENSE file.
71f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com */
81f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com
91f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com#ifndef SkBBoxHierarchy_DEFINED
101f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com#define SkBBoxHierarchy_DEFINED
111f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com
121f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com#include "SkRect.h"
131f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com#include "SkTDArray.h"
144813458d89fb276680168848bd861b307cf83f51rileya@google.com#include "SkRefCnt.h"
151f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com
161f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com/**
171f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com * Interface for a spatial data structure that associates user data pointers with axis-aligned
181f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com * bounding boxes, and allows efficient retrieval of intersections with query rectangles.
191f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com */
204813458d89fb276680168848bd861b307cf83f51rileya@google.comclass SkBBoxHierarchy : public SkRefCnt {
211f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.compublic:
224813458d89fb276680168848bd861b307cf83f51rileya@google.com    SK_DECLARE_INST_COUNT(SkBBoxHierarchy)
231f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com
241f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com    /**
251f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com     * Insert a data pointer and corresponding bounding box
261f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com     * @param data The data pointer, may be NULL
271f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com     * @param bounds The bounding box, should not be empty
281f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com     * @param defer Whether or not it is acceptable to delay insertion of this element (building up
291f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com     *        an entire spatial data structure at once is often faster and produces better
301f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com     *        structures than repeated inserts) until flushDeferredInserts is called or the first
311f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com     *        search.
321f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com     */
331f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com    virtual void insert(void* data, const SkIRect& bounds, bool defer = false) = 0;
341f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com
351f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com    /**
361f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com     * If any insertions have been deferred, this forces them to be inserted
371f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com     */
381f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com    virtual void flushDeferredInserts() = 0;
391f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com
401f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com    /**
411f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com     * Populate 'results' with data pointers corresponding to bounding boxes that intersect 'query'
421f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com     */
431f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com    virtual void search(const SkIRect& query, SkTDArray<void*>* results) = 0;
441f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com
451f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com    virtual void clear() = 0;
461f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com
471f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com    /**
481f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com     * Gets the number of insertions
491f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com     */
501f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com    virtual int getCount() const = 0;
514813458d89fb276680168848bd861b307cf83f51rileya@google.com
524813458d89fb276680168848bd861b307cf83f51rileya@google.comprivate:
534813458d89fb276680168848bd861b307cf83f51rileya@google.com    typedef SkRefCnt INHERITED;
541f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com};
551f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com
561f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com#endif
571f45e934b68a5985b2127ec871ff593c3bfc7c2erileya@google.com
58