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 #include "SkTileGrid.h" | 8 #include "SkTileGrid.h" |
9 | 9 |
10 SkTileGrid::SkTileGrid(int xTiles, int yTiles, const SkTileGridFactory::TileGrid
Info& info) | 10 SkTileGrid::SkTileGrid(int xTiles, int yTiles, const SkTileGridFactory::TileGrid
Info& info) |
11 : fXTiles(xTiles) | 11 : fXTiles(xTiles) |
12 , fYTiles(yTiles) | 12 , fYTiles(yTiles) |
13 , fInfo(info) | 13 , fInfo(info) |
14 , fCount(0) | 14 , fCount(0) |
15 , fTiles(SkNEW_ARRAY(SkTDArray<Entry>, xTiles * yTiles)) { | 15 , fTiles(SkNEW_ARRAY(SkTDArray<Entry>, xTiles * yTiles)) { |
16 // Margin is offset by 1 as a provision for AA and | 16 // Margin is offset by 1 as a provision for AA and |
17 // to cancel-out the outset applied by getClipDeviceBounds. | 17 // to cancel-out the outset applied by getClipDeviceBounds. |
18 fInfo.fMargin.fHeight++; | 18 fInfo.fMargin.fHeight++; |
19 fInfo.fMargin.fWidth++; | 19 fInfo.fMargin.fWidth++; |
20 } | 20 } |
21 | 21 |
22 SkTileGrid::~SkTileGrid() { | 22 SkTileGrid::~SkTileGrid() { |
23 SkDELETE_ARRAY(fTiles); | 23 SkDELETE_ARRAY(fTiles); |
24 } | 24 } |
25 | 25 |
26 void SkTileGrid::insert(void* data, const SkIRect& bounds, bool) { | 26 void SkTileGrid::insert(void* data, const SkRect& fbounds, bool) { |
27 SkASSERT(!bounds.isEmpty()); | 27 SkASSERT(!fbounds.isEmpty()); |
28 SkIRect dilatedBounds = bounds; | 28 SkIRect dilatedBounds; |
29 | 29 if (fbounds.isLargest()) { |
30 // Dilating the largest SkIRect will overflow. Other nearly-largest rects m
ay overflow too, | 30 // Dilating the largest SkIRect will overflow. Other nearly-largest rec
ts may overflow too, |
31 // but we don't make active use of them like we do the largest. | 31 // but we don't make active use of them like we do the largest. |
32 if (!bounds.isLargest()) { | 32 dilatedBounds.setLargest(); |
| 33 } else { |
| 34 fbounds.roundOut(&dilatedBounds); |
33 dilatedBounds.outset(fInfo.fMargin.width(), fInfo.fMargin.height()); | 35 dilatedBounds.outset(fInfo.fMargin.width(), fInfo.fMargin.height()); |
34 dilatedBounds.offset(fInfo.fOffset); | 36 dilatedBounds.offset(fInfo.fOffset); |
35 } | 37 } |
36 | 38 |
37 const SkIRect gridBounds = | 39 const SkIRect gridBounds = |
38 { 0, 0, fInfo.fTileInterval.width() * fXTiles, fInfo.fTileInterval.heigh
t() * fYTiles }; | 40 { 0, 0, fInfo.fTileInterval.width() * fXTiles, fInfo.fTileInterval.heigh
t() * fYTiles }; |
39 if (!SkIRect::Intersects(dilatedBounds, gridBounds)) { | 41 if (!SkIRect::Intersects(dilatedBounds, gridBounds)) { |
40 return; | 42 return; |
41 } | 43 } |
42 | 44 |
(...skipping 17 matching lines...) Expand all Loading... |
60 static int divide_ceil(int x, int y) { | 62 static int divide_ceil(int x, int y) { |
61 return (x + y - 1) / y; | 63 return (x + y - 1) / y; |
62 } | 64 } |
63 | 65 |
64 // Number of tiles for which data is allocated on the stack in | 66 // Number of tiles for which data is allocated on the stack in |
65 // SkTileGrid::search. If malloc becomes a bottleneck, we may consider | 67 // SkTileGrid::search. If malloc becomes a bottleneck, we may consider |
66 // increasing this number. Typical large web page, say 2k x 16k, would | 68 // increasing this number. Typical large web page, say 2k x 16k, would |
67 // require 512 tiles of size 256 x 256 pixels. | 69 // require 512 tiles of size 256 x 256 pixels. |
68 static const int kStackAllocationTileCount = 1024; | 70 static const int kStackAllocationTileCount = 1024; |
69 | 71 |
70 void SkTileGrid::search(const SkIRect& query, SkTDArray<void*>* results) const { | 72 void SkTileGrid::search(const SkRect& query, SkTDArray<void*>* results) const { |
71 SkIRect adjusted = query; | 73 SkIRect adjusted; |
| 74 query.roundOut(&adjusted); |
72 | 75 |
73 // The inset is to counteract the outset that was applied in 'insert' | 76 // The inset is to counteract the outset that was applied in 'insert' |
74 // The outset/inset is to optimize for lookups of size | 77 // The outset/inset is to optimize for lookups of size |
75 // 'tileInterval + 2 * margin' that are aligned with the tile grid. | 78 // 'tileInterval + 2 * margin' that are aligned with the tile grid. |
76 adjusted.inset(fInfo.fMargin.width(), fInfo.fMargin.height()); | 79 adjusted.inset(fInfo.fMargin.width(), fInfo.fMargin.height()); |
77 adjusted.offset(fInfo.fOffset); | 80 adjusted.offset(fInfo.fOffset); |
78 adjusted.sort(); // in case the inset inverted the rectangle | 81 adjusted.sort(); // in case the inset inverted the rectangle |
79 | 82 |
80 // Convert the query rectangle from device coordinates to tile coordinates | 83 // Convert the query rectangle from device coordinates to tile coordinates |
81 // by rounding outwards to the nearest tile boundary so that the resulting t
ile | 84 // by rounding outwards to the nearest tile boundary so that the resulting t
ile |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 } | 160 } |
158 | 161 |
159 void SkTileGrid::rewindInserts() { | 162 void SkTileGrid::rewindInserts() { |
160 SkASSERT(fClient); | 163 SkASSERT(fClient); |
161 for (int i = 0; i < fXTiles * fYTiles; i++) { | 164 for (int i = 0; i < fXTiles * fYTiles; i++) { |
162 while (!fTiles[i].isEmpty() && fClient->shouldRewind(fTiles[i].top().dat
a)) { | 165 while (!fTiles[i].isEmpty() && fClient->shouldRewind(fTiles[i].top().dat
a)) { |
163 fTiles[i].pop(); | 166 fTiles[i].pop(); |
164 } | 167 } |
165 } | 168 } |
166 } | 169 } |
OLD | NEW |