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 |
(...skipping 15 matching lines...) Expand all Loading... |
26 class SkTileGrid : public SkBBoxHierarchy { | 26 class SkTileGrid : public SkBBoxHierarchy { |
27 public: | 27 public: |
28 enum { | 28 enum { |
29 // Number of tiles for which data is allocated on the stack in | 29 // Number of tiles for which data is allocated on the stack in |
30 // SkTileGrid::search. If malloc becomes a bottleneck, we may consider | 30 // SkTileGrid::search. If malloc becomes a bottleneck, we may consider |
31 // increasing this number. Typical large web page, say 2k x 16k, would | 31 // increasing this number. Typical large web page, say 2k x 16k, would |
32 // require 512 tiles of size 256 x 256 pixels. | 32 // require 512 tiles of size 256 x 256 pixels. |
33 kStackAllocationTileCount = 1024 | 33 kStackAllocationTileCount = 1024 |
34 }; | 34 }; |
35 | 35 |
36 typedef void* (*SkTileGridNextDatumFunctionPtr)( | 36 SkTileGrid(int xTileCount, int yTileCount, const SkTileGridFactory::TileGrid
Info& info); |
37 const SkTDArray<void*>** tileData, | |
38 SkAutoSTArray<kStackAllocationTileCount, int>& tileIndices); | |
39 | |
40 SkTileGrid(int xTileCount, int yTileCount, const SkTileGridFactory::TileGrid
Info& info, | |
41 SkTileGridNextDatumFunctionPtr nextDatumFunction); | |
42 | 37 |
43 virtual ~SkTileGrid(); | 38 virtual ~SkTileGrid(); |
44 | 39 |
45 /** | 40 /** |
46 * Insert a data pointer and corresponding bounding box | 41 * Insert a data pointer and corresponding bounding box |
47 * @param data The data pointer, may be NULL | 42 * @param data The data pointer, may be NULL |
48 * @param bounds The bounding box, should not be empty | 43 * @param bounds The bounding box, should not be empty |
49 * @param defer Ignored, TileArray does not defer insertions | 44 * @param defer Ignored, TileArray does not defer insertions |
50 */ | 45 */ |
51 virtual void insert(void* data, const SkIRect& bounds, bool) SK_OVERRIDE; | 46 virtual void insert(void* data, const SkIRect& bounds, bool) SK_OVERRIDE; |
(...skipping 26 matching lines...) Expand all Loading... |
78 | 73 |
79 private: | 74 private: |
80 const SkTDArray<void*>& tile(int x, int y) const; | 75 const SkTDArray<void*>& tile(int x, int y) const; |
81 SkTDArray<void*>& tile(int x, int y); | 76 SkTDArray<void*>& tile(int x, int y); |
82 | 77 |
83 int fXTileCount, fYTileCount, fTileCount; | 78 int fXTileCount, fYTileCount, fTileCount; |
84 SkTileGridFactory::TileGridInfo fInfo; | 79 SkTileGridFactory::TileGridInfo fInfo; |
85 SkTDArray<void*>* fTileData; | 80 SkTDArray<void*>* fTileData; |
86 int fInsertionCount; | 81 int fInsertionCount; |
87 SkIRect fGridBounds; | 82 SkIRect fGridBounds; |
88 SkTileGridNextDatumFunctionPtr fNextDatumFunction; | |
89 | 83 |
90 typedef SkBBoxHierarchy INHERITED; | 84 typedef SkBBoxHierarchy INHERITED; |
91 }; | 85 }; |
92 | 86 |
93 /** | |
94 * Generic implementation for SkTileGridNextDatumFunctionPtr. user code may inst
antiate | |
95 * this template to get a valid SkTileGridNextDatumFunction implementation | |
96 * | |
97 * Returns the next element of tileData[i][tileIndices[i]] for all i and advance
s | |
98 * tileIndices[] past them. The order in which data are returned by successive | |
99 * calls to this method must reflect the order in which the were originally | |
100 * recorded into the tile grid. | |
101 * | |
102 * \param tileData array of pointers to arrays of tile data | |
103 * \param tileIndices per-tile data indices, indices are incremented for tiles t
hat contain | |
104 * the next datum. | |
105 * \tparam T a type to which it is safe to cast a datum and that has an operator
< | |
106 * such that 'a < b' is true if 'a' was inserted into the tile grid before '
b'. | |
107 */ | |
108 template <typename T> | |
109 void* SkTileGridNextDatum(const SkTDArray<void*>** tileData, | |
110 SkAutoSTArray<SkTileGrid::kStackAllocationTileCount, i
nt>& tileIndices) { | |
111 T* minVal = NULL; | |
112 int tileCount = tileIndices.count(); | |
113 int minIndex = tileCount; | |
114 int maxIndex = 0; | |
115 // Find the next Datum; track where it's found so we reduce the size of the
second loop. | |
116 for (int tile = 0; tile < tileCount; ++tile) { | |
117 int pos = tileIndices[tile]; | |
118 if (pos != SkTileGrid::kTileFinished) { | |
119 T* candidate = (T*)(*tileData[tile])[pos]; | |
120 if (NULL == minVal || (*candidate) < (*minVal)) { | |
121 minVal = candidate; | |
122 minIndex = tile; | |
123 maxIndex = tile; | |
124 } else if (!((*minVal) < (*candidate))) { | |
125 // We don't require operator==; if !(candidate<minVal) && !(minV
al<candidate), | |
126 // candidate==minVal and we have to add this tile to the range s
earched. | |
127 maxIndex = tile; | |
128 } | |
129 } | |
130 } | |
131 // Increment indices past the next datum | |
132 if (minVal != NULL) { | |
133 for (int tile = minIndex; tile <= maxIndex; ++tile) { | |
134 int pos = tileIndices[tile]; | |
135 if (pos != SkTileGrid::kTileFinished && (*tileData[tile])[pos] == mi
nVal) { | |
136 if (++(tileIndices[tile]) >= tileData[tile]->count()) { | |
137 tileIndices[tile] = SkTileGrid::kTileFinished; | |
138 } | |
139 } | |
140 } | |
141 return minVal; | |
142 } | |
143 return NULL; | |
144 } | |
145 | |
146 #endif | 87 #endif |
OLD | NEW |