OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkTileGrid_DEFINED | 8 #ifndef SkTileGrid_DEFINED |
9 #define SkTileGrid_DEFINED | 9 #define SkTileGrid_DEFINED |
10 | 10 |
11 #include "SkBBHFactory.h" | 11 #include "SkBBHFactory.h" |
12 #include "SkBBoxHierarchy.h" | 12 #include "SkBBoxHierarchy.h" |
13 | 13 |
14 /** | 14 /** |
15 * Subclass of SkBBoxHierarchy that stores elements in buckets that correspond | 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 | 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. | 17 * structure that will be use in search() calls is known prior to insertion. |
18 */ | 18 */ |
19 class SkTileGrid : public SkBBoxHierarchy { | 19 class SkTileGrid : public SkBBoxHierarchy { |
20 public: | 20 public: |
21 SkTileGrid(int xTiles, int yTiles, const SkTileGridFactory::TileGridInfo& in
fo); | 21 SkTileGrid(int xTiles, int yTiles, const SkTileGridFactory::TileGridInfo& in
fo); |
22 | |
23 virtual ~SkTileGrid(); | 22 virtual ~SkTileGrid(); |
24 | 23 |
25 /** | 24 virtual void insert(SkAutoTMalloc<SkRect>* boundsArray, int N) SK_OVERRIDE; |
26 * Insert a opIndex value and corresponding bounding box | |
27 * @param opIndex | |
28 * @param bounds The bounding box, should not be empty. | |
29 * @param defer Ignored; SkTileGrid does not defer insertions. | |
30 */ | |
31 virtual void insert(unsigned opIndex, const SkRect& bounds, bool) SK_OVERRID
E; | |
32 | |
33 /** | |
34 * Populate 'results' with opIndexes corresponding to bounding boxes that in
tersect 'query'. | |
35 * This will be fastest if the query is an exact match to a single grid tile
. | |
36 */ | |
37 virtual void search(const SkRect& query, SkTDArray<unsigned>* results) const
SK_OVERRIDE; | 25 virtual void search(const SkRect& query, SkTDArray<unsigned>* results) const
SK_OVERRIDE; |
38 | 26 |
39 // For testing. | 27 // For testing. |
40 int tileCount(int x, int y) { return fTiles[y * fXTiles + x].count(); } | 28 int tileCount(int x, int y) { return fTiles[y * fXTiles + x].count(); } |
41 | 29 |
42 virtual void reserve(unsigned opCount) SK_OVERRIDE; | 30 private: |
43 virtual void flushDeferredInserts() SK_OVERRIDE; | 31 void reserve(int); |
| 32 void shrinkToFit(); |
44 | 33 |
45 private: | |
46 void commonAdjust(SkRect*) const; | 34 void commonAdjust(SkRect*) const; |
47 void userToGrid(const SkRect&, SkIRect* grid) const; | 35 void userToGrid(const SkRect&, SkIRect* grid) const; |
48 | 36 |
49 const int fXTiles, fYTiles; | 37 const int fXTiles, fYTiles; |
50 const SkScalar fInvWidth, fInvHeight; | 38 const SkScalar fInvWidth, fInvHeight; |
51 const SkScalar fMarginWidth, fMarginHeight; | 39 const SkScalar fMarginWidth, fMarginHeight; |
52 const SkPoint fOffset; | 40 const SkPoint fOffset; |
53 const SkRect fGridBounds; | 41 const SkRect fGridBounds; |
54 | 42 |
55 // (fXTiles * fYTiles) SkTDArrays, each listing ops overlapping that tile in
order. | 43 // (fXTiles * fYTiles) SkTDArrays, each listing ops overlapping that tile in
order. |
56 SkTDArray<unsigned>* fTiles; | 44 SkTDArray<unsigned>* fTiles; |
57 | 45 |
58 typedef SkBBoxHierarchy INHERITED; | 46 typedef SkBBoxHierarchy INHERITED; |
59 }; | 47 }; |
60 | 48 |
61 #endif | 49 #endif |
OLD | NEW |