| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #ifndef SkTileGrid_DEFINED | 9 #ifndef SkTileGrid_DEFINED |
| 10 #define SkTileGrid_DEFINED | 10 #define SkTileGrid_DEFINED |
| 11 | 11 |
| 12 #include "SkBBHFactory.h" | 12 #include "SkBBHFactory.h" |
| 13 #include "SkBBoxHierarchy.h" | 13 #include "SkBBoxHierarchy.h" |
| 14 #include "SkPictureStateTree.h" | 14 #include "SkPictureStateTree.h" |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * Subclass of SkBBoxHierarchy that stores elements in buckets that correspond | 17 * Subclass of SkBBoxHierarchy that stores elements in buckets that correspond |
| 18 * to tile regions, disposed in a regular grid. This is useful when the tile | 18 * to tile regions, disposed in a regular grid. This is useful when the tile |
| 19 * structure that will be use in search() calls is known prior to insertion. | 19 * structure that will be use in search() calls is known prior to insertion. |
| 20 * Calls to search will return in constant time. | 20 * Calls to search will return in constant time. |
| 21 * | 21 * |
| 22 * Note: Current implementation of search() only supports looking-up regions | 22 * Note: Current implementation of search() only supports looking-up regions |
| 23 * that are an exact match to a single tile. Implementation could be augmented | 23 * that are an exact match to a single tile. Implementation could be augmented |
| 24 * to support arbitrary rectangles, but performance would be sub-optimal. | 24 * to support arbitrary rectangles, but performance would be sub-optimal. |
| 25 */ | 25 */ |
| 26 class SkTileGrid : public SkBBoxHierarchy { | 26 class SkTileGrid : public SkBBoxHierarchy { |
| 27 public: | 27 public: |
| 28 enum { | |
| 29 // Number of tiles for which data is allocated on the stack in | |
| 30 // SkTileGrid::search. If malloc becomes a bottleneck, we may consider | |
| 31 // increasing this number. Typical large web page, say 2k x 16k, would | |
| 32 // require 512 tiles of size 256 x 256 pixels. | |
| 33 kStackAllocationTileCount = 1024 | |
| 34 }; | |
| 35 | |
| 36 SkTileGrid(int xTileCount, int yTileCount, const SkTileGridFactory::TileGrid
Info& info); | 28 SkTileGrid(int xTileCount, int yTileCount, const SkTileGridFactory::TileGrid
Info& info); |
| 37 | 29 |
| 38 virtual ~SkTileGrid(); | 30 virtual ~SkTileGrid(); |
| 39 | 31 |
| 40 /** | 32 /** |
| 41 * Insert a data pointer and corresponding bounding box | 33 * Insert a data pointer and corresponding bounding box |
| 42 * @param data The data pointer, may be NULL | 34 * @param data The data pointer, may _NOT_ be NULL. |
| 43 * @param bounds The bounding box, should not be empty | 35 * @param bounds The bounding box, should not be empty. |
| 44 * @param defer Ignored, TileArray does not defer insertions | 36 * @param defer Ignored; SkTileGrid does not defer insertions. |
| 45 */ | 37 */ |
| 46 virtual void insert(void* data, const SkIRect& bounds, bool) SK_OVERRIDE; | 38 virtual void insert(void* data, const SkIRect& bounds, bool) SK_OVERRIDE; |
| 47 | 39 |
| 48 virtual void flushDeferredInserts() SK_OVERRIDE {}; | 40 virtual void flushDeferredInserts() SK_OVERRIDE {}; |
| 49 | 41 |
| 50 /** | 42 /** |
| 51 * Populate 'results' with data pointers corresponding to bounding boxes tha
t intersect 'query' | 43 * Populate 'results' with data pointers corresponding to bounding boxes tha
t intersect 'query'. |
| 52 * The query argument is expected to be an exact match to a tile of the grid | 44 * This will be fastest if the query is an exact match to a single grid tile
. |
| 53 */ | 45 */ |
| 54 virtual void search(const SkIRect& query, SkTDArray<void*>* results) const S
K_OVERRIDE; | 46 virtual void search(const SkIRect& query, SkTDArray<void*>* results) const S
K_OVERRIDE; |
| 55 | 47 |
| 56 virtual void clear() SK_OVERRIDE; | 48 virtual void clear() SK_OVERRIDE; |
| 57 | 49 |
| 58 /** | 50 /** |
| 59 * Gets the number of insertions | 51 * Gets the number of insertions |
| 60 */ | 52 */ |
| 61 virtual int getCount() const SK_OVERRIDE; | 53 virtual int getCount() const SK_OVERRIDE; |
| 62 | 54 |
| 63 virtual int getDepth() const SK_OVERRIDE { return -1; } | 55 virtual int getDepth() const SK_OVERRIDE { return -1; } |
| 64 | 56 |
| 65 virtual void rewindInserts() SK_OVERRIDE; | 57 virtual void rewindInserts() SK_OVERRIDE; |
| 66 | 58 |
| 67 // Used by search() and in SkTileGridHelper implementations | |
| 68 enum { | |
| 69 kTileFinished = -1, | |
| 70 }; | |
| 71 | |
| 72 int tileCount(int x, int y); // For testing only. | 59 int tileCount(int x, int y); // For testing only. |
| 73 | 60 |
| 74 private: | 61 private: |
| 75 const SkTDArray<void*>& tile(int x, int y) const; | 62 const SkTDArray<void*>& tile(int x, int y) const; |
| 76 SkTDArray<void*>& tile(int x, int y); | 63 SkTDArray<void*>& tile(int x, int y); |
| 77 | 64 |
| 78 int fXTileCount, fYTileCount, fTileCount; | 65 int fXTileCount, fYTileCount, fTileCount; |
| 79 SkTileGridFactory::TileGridInfo fInfo; | 66 SkTileGridFactory::TileGridInfo fInfo; |
| 80 SkTDArray<void*>* fTileData; | 67 SkTDArray<void*>* fTileData; |
| 81 int fInsertionCount; | 68 int fInsertionCount; |
| 82 SkIRect fGridBounds; | 69 SkIRect fGridBounds; |
| 83 | 70 |
| 84 typedef SkBBoxHierarchy INHERITED; | 71 typedef SkBBoxHierarchy INHERITED; |
| 85 }; | 72 }; |
| 86 | 73 |
| 87 #endif | 74 #endif |
| OLD | NEW |