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 #include "SkTileGrid.h" | 9 #include "SkTileGrid.h" |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 } | 26 } |
27 | 27 |
28 SkTileGrid::~SkTileGrid() { | 28 SkTileGrid::~SkTileGrid() { |
29 SkDELETE_ARRAY(fTileData); | 29 SkDELETE_ARRAY(fTileData); |
30 } | 30 } |
31 | 31 |
32 int SkTileGrid::tileCount(int x, int y) { | 32 int SkTileGrid::tileCount(int x, int y) { |
33 return this->tile(x, y).count(); | 33 return this->tile(x, y).count(); |
34 } | 34 } |
35 | 35 |
| 36 const SkTDArray<void *>& SkTileGrid::tile(int x, int y) const { |
| 37 return fTileData[y * fXTileCount + x]; |
| 38 } |
| 39 |
36 SkTDArray<void *>& SkTileGrid::tile(int x, int y) { | 40 SkTDArray<void *>& SkTileGrid::tile(int x, int y) { |
37 return fTileData[y * fXTileCount + x]; | 41 return fTileData[y * fXTileCount + x]; |
38 } | 42 } |
39 | 43 |
40 void SkTileGrid::insert(void* data, const SkIRect& bounds, bool) { | 44 void SkTileGrid::insert(void* data, const SkIRect& bounds, bool) { |
41 SkASSERT(!bounds.isEmpty()); | 45 SkASSERT(!bounds.isEmpty()); |
42 SkIRect dilatedBounds = bounds; | 46 SkIRect dilatedBounds = bounds; |
43 dilatedBounds.outset(fInfo.fMargin.width(), fInfo.fMargin.height()); | 47 dilatedBounds.outset(fInfo.fMargin.width(), fInfo.fMargin.height()); |
44 dilatedBounds.offset(fInfo.fOffset); | 48 dilatedBounds.offset(fInfo.fOffset); |
45 if (!SkIRect::Intersects(dilatedBounds, fGridBounds)) { | 49 if (!SkIRect::Intersects(dilatedBounds, fGridBounds)) { |
(...skipping 12 matching lines...) Expand all Loading... |
58 fYTileCount -1), 0); | 62 fYTileCount -1), 0); |
59 | 63 |
60 for (int x = minTileX; x <= maxTileX; x++) { | 64 for (int x = minTileX; x <= maxTileX; x++) { |
61 for (int y = minTileY; y <= maxTileY; y++) { | 65 for (int y = minTileY; y <= maxTileY; y++) { |
62 this->tile(x, y).push(data); | 66 this->tile(x, y).push(data); |
63 } | 67 } |
64 } | 68 } |
65 fInsertionCount++; | 69 fInsertionCount++; |
66 } | 70 } |
67 | 71 |
68 void SkTileGrid::search(const SkIRect& query, SkTDArray<void*>* results) { | 72 void SkTileGrid::search(const SkIRect& query, SkTDArray<void*>* results) const { |
69 SkIRect adjustedQuery = query; | 73 SkIRect adjustedQuery = query; |
70 // The inset is to counteract the outset that was applied in 'insert' | 74 // The inset is to counteract the outset that was applied in 'insert' |
71 // The outset/inset is to optimize for lookups of size | 75 // The outset/inset is to optimize for lookups of size |
72 // 'tileInterval + 2 * margin' that are aligned with the tile grid. | 76 // 'tileInterval + 2 * margin' that are aligned with the tile grid. |
73 adjustedQuery.inset(fInfo.fMargin.width(), fInfo.fMargin.height()); | 77 adjustedQuery.inset(fInfo.fMargin.width(), fInfo.fMargin.height()); |
74 adjustedQuery.offset(fInfo.fOffset); | 78 adjustedQuery.offset(fInfo.fOffset); |
75 adjustedQuery.sort(); // in case the inset inverted the rectangle | 79 adjustedQuery.sort(); // in case the inset inverted the rectangle |
76 // Convert the query rectangle from device coordinates to tile coordinates | 80 // Convert the query rectangle from device coordinates to tile coordinates |
77 // by rounding outwards to the nearest tile boundary so that the resulting t
ile | 81 // by rounding outwards to the nearest tile boundary so that the resulting t
ile |
78 // region includes the query rectangle. (using truncating division to "floor
") | 82 // region includes the query rectangle. (using truncating division to "floor
") |
(...skipping 10 matching lines...) Expand all Loading... |
89 tileEndY = SkPin32(tileEndY, tileStartY+1, fYTileCount); | 93 tileEndY = SkPin32(tileEndY, tileStartY+1, fYTileCount); |
90 | 94 |
91 int queryTileCount = (tileEndX - tileStartX) * (tileEndY - tileStartY); | 95 int queryTileCount = (tileEndX - tileStartX) * (tileEndY - tileStartY); |
92 SkASSERT(queryTileCount); | 96 SkASSERT(queryTileCount); |
93 if (queryTileCount == 1) { | 97 if (queryTileCount == 1) { |
94 *results = this->tile(tileStartX, tileStartY); | 98 *results = this->tile(tileStartX, tileStartY); |
95 } else { | 99 } else { |
96 results->reset(); | 100 results->reset(); |
97 SkAutoSTArray<kStackAllocationTileCount, int> curPositions(queryTileCoun
t); | 101 SkAutoSTArray<kStackAllocationTileCount, int> curPositions(queryTileCoun
t); |
98 SkAutoSTArray<kStackAllocationTileCount, SkTDArray<void *>*> storage(que
ryTileCount); | 102 SkAutoSTArray<kStackAllocationTileCount, SkTDArray<void *>*> storage(que
ryTileCount); |
99 SkTDArray<void *>** tileRange = storage.get(); | 103 const SkTDArray<void *>** tileRange = const_cast<const SkTDArray<void*>*
*>(storage.get()); |
100 int tile = 0; | 104 int tile = 0; |
101 for (int x = tileStartX; x < tileEndX; ++x) { | 105 for (int x = tileStartX; x < tileEndX; ++x) { |
102 for (int y = tileStartY; y < tileEndY; ++y) { | 106 for (int y = tileStartY; y < tileEndY; ++y) { |
103 tileRange[tile] = &this->tile(x, y); | 107 tileRange[tile] = &this->tile(x, y); |
104 curPositions[tile] = tileRange[tile]->count() ? 0 : kTileFinishe
d; | 108 curPositions[tile] = tileRange[tile]->count() ? 0 : kTileFinishe
d; |
105 ++tile; | 109 ++tile; |
106 } | 110 } |
107 } | 111 } |
108 void *nextElement; | 112 void *nextElement; |
109 while(NULL != (nextElement = fNextDatumFunction(tileRange, curPositions)
)) { | 113 while(NULL != (nextElement = fNextDatumFunction(tileRange, curPositions)
)) { |
(...skipping 13 matching lines...) Expand all Loading... |
123 } | 127 } |
124 | 128 |
125 void SkTileGrid::rewindInserts() { | 129 void SkTileGrid::rewindInserts() { |
126 SkASSERT(fClient); | 130 SkASSERT(fClient); |
127 for (int i = 0; i < fTileCount; ++i) { | 131 for (int i = 0; i < fTileCount; ++i) { |
128 while (!fTileData[i].isEmpty() && fClient->shouldRewind(fTileData[i].top
())) { | 132 while (!fTileData[i].isEmpty() && fClient->shouldRewind(fTileData[i].top
())) { |
129 fTileData[i].pop(); | 133 fTileData[i].pop(); |
130 } | 134 } |
131 } | 135 } |
132 } | 136 } |
OLD | NEW |