1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/core/SkBBoxHierarchy.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,98 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2012 Google Inc. 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 +#ifndef SkBBoxHierarchy_DEFINED 1.13 +#define SkBBoxHierarchy_DEFINED 1.14 + 1.15 +#include "SkRect.h" 1.16 +#include "SkTDArray.h" 1.17 +#include "SkRefCnt.h" 1.18 + 1.19 +/** 1.20 + * Interface for a client class that implements utility methods needed 1.21 + * by SkBBoxHierarchy that require intrinsic knowledge of the data 1.22 + * object type that is stored in the bounding box hierarchy. 1.23 + */ 1.24 +class SkBBoxHierarchyClient { 1.25 +public: 1.26 + virtual ~SkBBoxHierarchyClient() {} 1.27 + 1.28 + /** 1.29 + * Implements a rewind stop condition used by rewindInserts 1.30 + * Must returns true if 'data' points to an object that should be re-wound 1.31 + * by rewinfInserts. 1.32 + */ 1.33 + virtual bool shouldRewind(void* data) = 0; 1.34 +}; 1.35 + 1.36 +/** 1.37 + * Interface for a spatial data structure that associates user data pointers with axis-aligned 1.38 + * bounding boxes, and allows efficient retrieval of intersections with query rectangles. 1.39 + */ 1.40 +class SkBBoxHierarchy : public SkRefCnt { 1.41 +public: 1.42 + SK_DECLARE_INST_COUNT(SkBBoxHierarchy) 1.43 + 1.44 + SkBBoxHierarchy() : fClient(NULL) {} 1.45 + 1.46 + /** 1.47 + * Insert a data pointer and corresponding bounding box 1.48 + * @param data The data pointer, may be NULL 1.49 + * @param bounds The bounding box, should not be empty 1.50 + * @param defer Whether or not it is acceptable to delay insertion of this element (building up 1.51 + * an entire spatial data structure at once is often faster and produces better 1.52 + * structures than repeated inserts) until flushDeferredInserts is called or the first 1.53 + * search. 1.54 + */ 1.55 + virtual void insert(void* data, const SkIRect& bounds, bool defer = false) = 0; 1.56 + 1.57 + /** 1.58 + * If any insertions have been deferred, this forces them to be inserted 1.59 + */ 1.60 + virtual void flushDeferredInserts() = 0; 1.61 + 1.62 + /** 1.63 + * Populate 'results' with data pointers corresponding to bounding boxes that intersect 'query' 1.64 + */ 1.65 + virtual void search(const SkIRect& query, SkTDArray<void*>* results) = 0; 1.66 + 1.67 + virtual void clear() = 0; 1.68 + 1.69 + /** 1.70 + * Gets the number of insertions actually made (does not include deferred insertions) 1.71 + */ 1.72 + virtual int getCount() const = 0; 1.73 + 1.74 + /** 1.75 + * Returns the depth of the currently allocated tree. The root node counts for 1 level, 1.76 + * so it should be 1 or more if there's a root node. This information provides details 1.77 + * about the underlying structure, which is useful mainly for testing purposes. 1.78 + * 1.79 + * Returns 0 if there are currently no nodes in the tree. 1.80 + * Returns -1 if the structure isn't a tree. 1.81 + */ 1.82 + virtual int getDepth() const = 0; 1.83 + 1.84 + /** 1.85 + * Rewinds all the most recently inserted data elements until an element 1.86 + * is encountered for which client->shouldRewind(data) returns false. May 1.87 + * not rewind elements that were inserted prior to the last call to 1.88 + * flushDeferredInserts. 1.89 + */ 1.90 + virtual void rewindInserts() = 0; 1.91 + 1.92 + void setClient(SkBBoxHierarchyClient* client) { fClient = client; } 1.93 + 1.94 +protected: 1.95 + SkBBoxHierarchyClient* fClient; 1.96 + 1.97 +private: 1.98 + typedef SkRefCnt INHERITED; 1.99 +}; 1.100 + 1.101 +#endif