2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkTileGrid_DEFINED
9 #define SkTileGrid_DEFINED
11 #include "SkBBHFactory.h"
12 #include "SkBBoxHierarchy.h"
15 * Subclass of SkBBoxHierarchy that stores elements in buckets that correspond
16 * to tile regions, disposed in a regular grid. This is useful when the tile
17 * structure that will be use in search() calls is known prior to insertion.
19 class SkTileGrid : public SkBBoxHierarchy {
21 SkTileGrid(int xTiles, int yTiles, const SkTileGridFactory::TileGridInfo& info);
23 virtual ~SkTileGrid();
26 * Insert a data pointer and corresponding bounding box
27 * @param data An arbitrary data pointer, may be NULL.
28 * @param bounds The bounding box, should not be empty.
29 * @param defer Ignored; SkTileGrid does not defer insertions.
31 virtual void insert(void* data, const SkIRect& bounds, bool) SK_OVERRIDE;
33 virtual void flushDeferredInserts() SK_OVERRIDE {};
36 * Populate 'results' with data pointers corresponding to bounding boxes that intersect 'query'.
37 * This will be fastest if the query is an exact match to a single grid tile.
39 virtual void search(const SkIRect& query, SkTDArray<void*>* results) const SK_OVERRIDE;
41 virtual void clear() SK_OVERRIDE;
43 virtual int getCount() const SK_OVERRIDE { return fCount; }
45 virtual int getDepth() const SK_OVERRIDE { return -1; }
47 virtual void rewindInserts() SK_OVERRIDE;
50 int tileCount(int x, int y) { return fTiles[y * fXTiles + x].count(); }
54 size_t order; // Insertion order. Used to preserve order when merging multiple tiles.
58 const int fXTiles, fYTiles;
59 SkTileGridFactory::TileGridInfo fInfo;
62 // (fXTiles * fYTiles) SkTDArrays, each listing data overlapping that tile in insertion order.
63 SkTDArray<Entry>* fTiles;
65 typedef SkBBoxHierarchy INHERITED;