Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: cc/base/tiling_data.cc

Issue 389973004: cc: Give TilingData back a Size instead of a Rect. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tilingsize: comments Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/base/tiling_data.h ('k') | cc/base/tiling_data_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 The Chromium Authors. All rights reserved. 1 // Copyright 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/base/tiling_data.h" 5 #include "cc/base/tiling_data.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ui/gfx/rect.h" 9 #include "ui/gfx/rect.h"
10 #include "ui/gfx/vector2d.h" 10 #include "ui/gfx/vector2d.h"
(...skipping 11 matching lines...) Expand all
22 (max_texture_size - 2 * border_texels)); 22 (max_texture_size - 2 * border_texels));
23 return total_size > 0 ? num_tiles : 0; 23 return total_size > 0 ? num_tiles : 0;
24 } 24 }
25 25
26 TilingData::TilingData() 26 TilingData::TilingData()
27 : border_texels_(0) { 27 : border_texels_(0) {
28 RecomputeNumTiles(); 28 RecomputeNumTiles();
29 } 29 }
30 30
31 TilingData::TilingData(const gfx::Size& max_texture_size, 31 TilingData::TilingData(const gfx::Size& max_texture_size,
32 const gfx::Rect& tiling_rect, 32 const gfx::Size& tiling_size,
33 bool has_border_texels) 33 bool has_border_texels)
34 : max_texture_size_(max_texture_size), 34 : max_texture_size_(max_texture_size),
35 tiling_rect_(tiling_rect), 35 tiling_size_(tiling_size),
36 border_texels_(has_border_texels ? 1 : 0) { 36 border_texels_(has_border_texels ? 1 : 0) {
37 RecomputeNumTiles(); 37 RecomputeNumTiles();
38 } 38 }
39 39
40 TilingData::TilingData(const gfx::Size& max_texture_size, 40 TilingData::TilingData(const gfx::Size& max_texture_size,
41 const gfx::Rect& tiling_rect, 41 const gfx::Size& tiling_size,
42 int border_texels) 42 int border_texels)
43 : max_texture_size_(max_texture_size), 43 : max_texture_size_(max_texture_size),
44 tiling_rect_(tiling_rect), 44 tiling_size_(tiling_size),
45 border_texels_(border_texels) { 45 border_texels_(border_texels) {
46 RecomputeNumTiles(); 46 RecomputeNumTiles();
47 } 47 }
48 48
49 void TilingData::SetTilingRect(const gfx::Rect& tiling_rect) { 49 void TilingData::SetTilingSize(const gfx::Size& tiling_size) {
50 tiling_rect_ = tiling_rect; 50 tiling_size_ = tiling_size;
51 RecomputeNumTiles(); 51 RecomputeNumTiles();
52 } 52 }
53 53
54 void TilingData::SetMaxTextureSize(const gfx::Size& max_texture_size) { 54 void TilingData::SetMaxTextureSize(const gfx::Size& max_texture_size) {
55 max_texture_size_ = max_texture_size; 55 max_texture_size_ = max_texture_size;
56 RecomputeNumTiles(); 56 RecomputeNumTiles();
57 } 57 }
58 58
59 void TilingData::SetHasBorderTexels(bool has_border_texels) { 59 void TilingData::SetHasBorderTexels(bool has_border_texels) {
60 border_texels_ = has_border_texels ? 1 : 0; 60 border_texels_ = has_border_texels ? 1 : 0;
61 RecomputeNumTiles(); 61 RecomputeNumTiles();
62 } 62 }
63 63
64 void TilingData::SetBorderTexels(int border_texels) { 64 void TilingData::SetBorderTexels(int border_texels) {
65 border_texels_ = border_texels; 65 border_texels_ = border_texels;
66 RecomputeNumTiles(); 66 RecomputeNumTiles();
67 } 67 }
68 68
69 int TilingData::TileXIndexFromSrcCoord(int src_position) const { 69 int TilingData::TileXIndexFromSrcCoord(int src_position) const {
70 if (num_tiles_x_ <= 1) 70 if (num_tiles_x_ <= 1)
71 return 0; 71 return 0;
72 72
73 src_position -= tiling_rect_.x();
74
75 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0); 73 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0);
76 int x = (src_position - border_texels_) / 74 int x = (src_position - border_texels_) /
77 (max_texture_size_.width() - 2 * border_texels_); 75 (max_texture_size_.width() - 2 * border_texels_);
78 return std::min(std::max(x, 0), num_tiles_x_ - 1); 76 return std::min(std::max(x, 0), num_tiles_x_ - 1);
79 } 77 }
80 78
81 int TilingData::TileYIndexFromSrcCoord(int src_position) const { 79 int TilingData::TileYIndexFromSrcCoord(int src_position) const {
82 if (num_tiles_y_ <= 1) 80 if (num_tiles_y_ <= 1)
83 return 0; 81 return 0;
84 82
85 src_position -= tiling_rect_.y();
86
87 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0); 83 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0);
88 int y = (src_position - border_texels_) / 84 int y = (src_position - border_texels_) /
89 (max_texture_size_.height() - 2 * border_texels_); 85 (max_texture_size_.height() - 2 * border_texels_);
90 return std::min(std::max(y, 0), num_tiles_y_ - 1); 86 return std::min(std::max(y, 0), num_tiles_y_ - 1);
91 } 87 }
92 88
93 int TilingData::FirstBorderTileXIndexFromSrcCoord(int src_position) const { 89 int TilingData::FirstBorderTileXIndexFromSrcCoord(int src_position) const {
94 if (num_tiles_x_ <= 1) 90 if (num_tiles_x_ <= 1)
95 return 0; 91 return 0;
96 92
97 src_position -= tiling_rect_.x();
98
99 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0); 93 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0);
100 int inner_tile_size = max_texture_size_.width() - 2 * border_texels_; 94 int inner_tile_size = max_texture_size_.width() - 2 * border_texels_;
101 int x = (src_position - 2 * border_texels_) / inner_tile_size; 95 int x = (src_position - 2 * border_texels_) / inner_tile_size;
102 return std::min(std::max(x, 0), num_tiles_x_ - 1); 96 return std::min(std::max(x, 0), num_tiles_x_ - 1);
103 } 97 }
104 98
105 int TilingData::FirstBorderTileYIndexFromSrcCoord(int src_position) const { 99 int TilingData::FirstBorderTileYIndexFromSrcCoord(int src_position) const {
106 if (num_tiles_y_ <= 1) 100 if (num_tiles_y_ <= 1)
107 return 0; 101 return 0;
108 102
109 src_position -= tiling_rect_.y();
110
111 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0); 103 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0);
112 int inner_tile_size = max_texture_size_.height() - 2 * border_texels_; 104 int inner_tile_size = max_texture_size_.height() - 2 * border_texels_;
113 int y = (src_position - 2 * border_texels_) / inner_tile_size; 105 int y = (src_position - 2 * border_texels_) / inner_tile_size;
114 return std::min(std::max(y, 0), num_tiles_y_ - 1); 106 return std::min(std::max(y, 0), num_tiles_y_ - 1);
115 } 107 }
116 108
117 int TilingData::LastBorderTileXIndexFromSrcCoord(int src_position) const { 109 int TilingData::LastBorderTileXIndexFromSrcCoord(int src_position) const {
118 if (num_tiles_x_ <= 1) 110 if (num_tiles_x_ <= 1)
119 return 0; 111 return 0;
120 112
121 src_position -= tiling_rect_.x();
122
123 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0); 113 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0);
124 int inner_tile_size = max_texture_size_.width() - 2 * border_texels_; 114 int inner_tile_size = max_texture_size_.width() - 2 * border_texels_;
125 int x = src_position / inner_tile_size; 115 int x = src_position / inner_tile_size;
126 return std::min(std::max(x, 0), num_tiles_x_ - 1); 116 return std::min(std::max(x, 0), num_tiles_x_ - 1);
127 } 117 }
128 118
129 int TilingData::LastBorderTileYIndexFromSrcCoord(int src_position) const { 119 int TilingData::LastBorderTileYIndexFromSrcCoord(int src_position) const {
130 if (num_tiles_y_ <= 1) 120 if (num_tiles_y_ <= 1)
131 return 0; 121 return 0;
132 122
133 src_position -= tiling_rect_.y();
134
135 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0); 123 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0);
136 int inner_tile_size = max_texture_size_.height() - 2 * border_texels_; 124 int inner_tile_size = max_texture_size_.height() - 2 * border_texels_;
137 int y = src_position / inner_tile_size; 125 int y = src_position / inner_tile_size;
138 return std::min(std::max(y, 0), num_tiles_y_ - 1); 126 return std::min(std::max(y, 0), num_tiles_y_ - 1);
139 } 127 }
140 128
141 gfx::Rect TilingData::ExpandRectIgnoringBordersToTileBoundsWithBorders( 129 gfx::Rect TilingData::ExpandRectIgnoringBordersToTileBoundsWithBorders(
142 const gfx::Rect& rect) const { 130 const gfx::Rect& rect) const {
143 if (!rect.Intersects(tiling_rect_) || has_empty_bounds()) 131 if (rect.IsEmpty() || has_empty_bounds())
132 return gfx::Rect();
133 if (rect.x() > tiling_size_.width() || rect.y() > tiling_size_.height())
144 return gfx::Rect(); 134 return gfx::Rect();
145 int index_x = TileXIndexFromSrcCoord(rect.x()); 135 int index_x = TileXIndexFromSrcCoord(rect.x());
146 int index_y = TileYIndexFromSrcCoord(rect.y()); 136 int index_y = TileYIndexFromSrcCoord(rect.y());
147 int index_right = TileXIndexFromSrcCoord(rect.right() - 1); 137 int index_right = TileXIndexFromSrcCoord(rect.right() - 1);
148 int index_bottom = TileYIndexFromSrcCoord(rect.bottom() - 1); 138 int index_bottom = TileYIndexFromSrcCoord(rect.bottom() - 1);
149 139
150 gfx::Rect rect_top_left(TileBoundsWithBorder(index_x, index_y)); 140 gfx::Rect rect_top_left(TileBoundsWithBorder(index_x, index_y));
151 gfx::Rect rect_bottom_right(TileBoundsWithBorder(index_right, index_bottom)); 141 gfx::Rect rect_bottom_right(TileBoundsWithBorder(index_right, index_bottom));
152 142
153 return gfx::UnionRects(rect_top_left, rect_bottom_right); 143 return gfx::UnionRects(rect_top_left, rect_bottom_right);
154 } 144 }
155 145
156 gfx::Rect TilingData::ExpandRectToTileBounds(const gfx::Rect& rect) const { 146 gfx::Rect TilingData::ExpandRectToTileBounds(const gfx::Rect& rect) const {
157 if (!rect.Intersects(tiling_rect_) || has_empty_bounds()) 147 if (rect.IsEmpty() || has_empty_bounds())
148 return gfx::Rect();
149 if (rect.x() > tiling_size_.width() || rect.y() > tiling_size_.height())
158 return gfx::Rect(); 150 return gfx::Rect();
159 int index_x = FirstBorderTileXIndexFromSrcCoord(rect.x()); 151 int index_x = FirstBorderTileXIndexFromSrcCoord(rect.x());
160 int index_y = FirstBorderTileYIndexFromSrcCoord(rect.y()); 152 int index_y = FirstBorderTileYIndexFromSrcCoord(rect.y());
161 int index_right = LastBorderTileXIndexFromSrcCoord(rect.right() - 1); 153 int index_right = LastBorderTileXIndexFromSrcCoord(rect.right() - 1);
162 int index_bottom = LastBorderTileYIndexFromSrcCoord(rect.bottom() - 1); 154 int index_bottom = LastBorderTileYIndexFromSrcCoord(rect.bottom() - 1);
163 155
164 gfx::Rect rect_top_left(TileBounds(index_x, index_y)); 156 gfx::Rect rect_top_left(TileBounds(index_x, index_y));
165 gfx::Rect rect_bottom_right(TileBounds(index_right, index_bottom)); 157 gfx::Rect rect_bottom_right(TileBounds(index_right, index_bottom));
166 158
167 return gfx::UnionRects(rect_top_left, rect_bottom_right); 159 return gfx::UnionRects(rect_top_left, rect_bottom_right);
168 } 160 }
169 161
170 gfx::Rect TilingData::TileBounds(int i, int j) const { 162 gfx::Rect TilingData::TileBounds(int i, int j) const {
171 AssertTile(i, j); 163 AssertTile(i, j);
172 int max_texture_size_x = max_texture_size_.width() - 2 * border_texels_; 164 int max_texture_size_x = max_texture_size_.width() - 2 * border_texels_;
173 int max_texture_size_y = max_texture_size_.height() - 2 * border_texels_; 165 int max_texture_size_y = max_texture_size_.height() - 2 * border_texels_;
174 166
175 int lo_x = tiling_rect_.x() + max_texture_size_x * i; 167 int lo_x = max_texture_size_x * i;
176 if (i != 0) 168 if (i != 0)
177 lo_x += border_texels_; 169 lo_x += border_texels_;
178 170
179 int lo_y = tiling_rect_.y() + max_texture_size_y * j; 171 int lo_y = max_texture_size_y * j;
180 if (j != 0) 172 if (j != 0)
181 lo_y += border_texels_; 173 lo_y += border_texels_;
182 174
183 int hi_x = tiling_rect_.x() + max_texture_size_x * (i + 1) + border_texels_; 175 int hi_x = max_texture_size_x * (i + 1) + border_texels_;
184 if (i + 1 == num_tiles_x_) 176 if (i + 1 == num_tiles_x_)
185 hi_x += border_texels_; 177 hi_x += border_texels_;
186 178
187 int hi_y = tiling_rect_.y() + max_texture_size_y * (j + 1) + border_texels_; 179 int hi_y = max_texture_size_y * (j + 1) + border_texels_;
188 if (j + 1 == num_tiles_y_) 180 if (j + 1 == num_tiles_y_)
189 hi_y += border_texels_; 181 hi_y += border_texels_;
190 182
191 hi_x = std::min(hi_x, tiling_rect_.right()); 183 hi_x = std::min(hi_x, tiling_size_.width());
192 hi_y = std::min(hi_y, tiling_rect_.bottom()); 184 hi_y = std::min(hi_y, tiling_size_.height());
193 185
194 int x = lo_x; 186 int x = lo_x;
195 int y = lo_y; 187 int y = lo_y;
196 int width = hi_x - lo_x; 188 int width = hi_x - lo_x;
197 int height = hi_y - lo_y; 189 int height = hi_y - lo_y;
198 DCHECK_GE(x, tiling_rect_.x()); 190 DCHECK_GE(x, 0);
199 DCHECK_GE(y, tiling_rect_.y()); 191 DCHECK_GE(y, 0);
200 DCHECK_GE(width, 0); 192 DCHECK_GE(width, 0);
201 DCHECK_GE(height, 0); 193 DCHECK_GE(height, 0);
202 DCHECK_LE(x, tiling_rect_.right()); 194 DCHECK_LE(x, tiling_size_.width());
203 DCHECK_LE(y, tiling_rect_.bottom()); 195 DCHECK_LE(y, tiling_size_.height());
204 return gfx::Rect(x, y, width, height); 196 return gfx::Rect(x, y, width, height);
205 } 197 }
206 198
207 gfx::Rect TilingData::TileBoundsWithBorder(int i, int j) const { 199 gfx::Rect TilingData::TileBoundsWithBorder(int i, int j) const {
208 AssertTile(i, j); 200 AssertTile(i, j);
209 int max_texture_size_x = max_texture_size_.width() - 2 * border_texels_; 201 int max_texture_size_x = max_texture_size_.width() - 2 * border_texels_;
210 int max_texture_size_y = max_texture_size_.height() - 2 * border_texels_; 202 int max_texture_size_y = max_texture_size_.height() - 2 * border_texels_;
211 203
212 int lo_x = tiling_rect_.x() + max_texture_size_x * i; 204 int lo_x = max_texture_size_x * i;
213 int lo_y = tiling_rect_.y() + max_texture_size_y * j; 205 int lo_y = max_texture_size_y * j;
214 206
215 int hi_x = lo_x + max_texture_size_x + 2 * border_texels_; 207 int hi_x = lo_x + max_texture_size_x + 2 * border_texels_;
216 int hi_y = lo_y + max_texture_size_y + 2 * border_texels_; 208 int hi_y = lo_y + max_texture_size_y + 2 * border_texels_;
217 209
218 hi_x = std::min(hi_x, tiling_rect_.right()); 210 hi_x = std::min(hi_x, tiling_size_.width());
219 hi_y = std::min(hi_y, tiling_rect_.bottom()); 211 hi_y = std::min(hi_y, tiling_size_.height());
220 212
221 int x = lo_x; 213 int x = lo_x;
222 int y = lo_y; 214 int y = lo_y;
223 int width = hi_x - lo_x; 215 int width = hi_x - lo_x;
224 int height = hi_y - lo_y; 216 int height = hi_y - lo_y;
225 DCHECK_GE(x, tiling_rect_.x()); 217 DCHECK_GE(x, 0);
226 DCHECK_GE(y, tiling_rect_.y()); 218 DCHECK_GE(y, 0);
227 DCHECK_GE(width, 0); 219 DCHECK_GE(width, 0);
228 DCHECK_GE(height, 0); 220 DCHECK_GE(height, 0);
229 DCHECK_LE(x, tiling_rect_.right()); 221 DCHECK_LE(x, tiling_size_.width());
230 DCHECK_LE(y, tiling_rect_.bottom()); 222 DCHECK_LE(y, tiling_size_.height());
231 return gfx::Rect(x, y, width, height); 223 return gfx::Rect(x, y, width, height);
232 } 224 }
233 225
234 int TilingData::TilePositionX(int x_index) const { 226 int TilingData::TilePositionX(int x_index) const {
235 DCHECK_GE(x_index, 0); 227 DCHECK_GE(x_index, 0);
236 DCHECK_LT(x_index, num_tiles_x_); 228 DCHECK_LT(x_index, num_tiles_x_);
237 229
238 int pos = (max_texture_size_.width() - 2 * border_texels_) * x_index; 230 int pos = (max_texture_size_.width() - 2 * border_texels_) * x_index;
239 if (x_index != 0) 231 if (x_index != 0)
240 pos += border_texels_; 232 pos += border_texels_;
241 233
242 pos += tiling_rect_.x();
243
244 return pos; 234 return pos;
245 } 235 }
246 236
247 int TilingData::TilePositionY(int y_index) const { 237 int TilingData::TilePositionY(int y_index) const {
248 DCHECK_GE(y_index, 0); 238 DCHECK_GE(y_index, 0);
249 DCHECK_LT(y_index, num_tiles_y_); 239 DCHECK_LT(y_index, num_tiles_y_);
250 240
251 int pos = (max_texture_size_.height() - 2 * border_texels_) * y_index; 241 int pos = (max_texture_size_.height() - 2 * border_texels_) * y_index;
252 if (y_index != 0) 242 if (y_index != 0)
253 pos += border_texels_; 243 pos += border_texels_;
254 244
255 pos += tiling_rect_.y();
256
257 return pos; 245 return pos;
258 } 246 }
259 247
260 int TilingData::TileSizeX(int x_index) const { 248 int TilingData::TileSizeX(int x_index) const {
261 DCHECK_GE(x_index, 0); 249 DCHECK_GE(x_index, 0);
262 DCHECK_LT(x_index, num_tiles_x_); 250 DCHECK_LT(x_index, num_tiles_x_);
263 251
264 if (!x_index && num_tiles_x_ == 1) 252 if (!x_index && num_tiles_x_ == 1)
265 return tiling_rect_.width(); 253 return tiling_size_.width();
266 if (!x_index && num_tiles_x_ > 1) 254 if (!x_index && num_tiles_x_ > 1)
267 return max_texture_size_.width() - border_texels_; 255 return max_texture_size_.width() - border_texels_;
268 if (x_index < num_tiles_x_ - 1) 256 if (x_index < num_tiles_x_ - 1)
269 return max_texture_size_.width() - 2 * border_texels_; 257 return max_texture_size_.width() - 2 * border_texels_;
270 if (x_index == num_tiles_x_ - 1) 258 if (x_index == num_tiles_x_ - 1)
271 return tiling_rect_.right() - TilePositionX(x_index); 259 return tiling_size_.width() - TilePositionX(x_index);
272 260
273 NOTREACHED(); 261 NOTREACHED();
274 return 0; 262 return 0;
275 } 263 }
276 264
277 int TilingData::TileSizeY(int y_index) const { 265 int TilingData::TileSizeY(int y_index) const {
278 DCHECK_GE(y_index, 0); 266 DCHECK_GE(y_index, 0);
279 DCHECK_LT(y_index, num_tiles_y_); 267 DCHECK_LT(y_index, num_tiles_y_);
280 268
281 if (!y_index && num_tiles_y_ == 1) 269 if (!y_index && num_tiles_y_ == 1)
282 return tiling_rect_.height(); 270 return tiling_size_.height();
283 if (!y_index && num_tiles_y_ > 1) 271 if (!y_index && num_tiles_y_ > 1)
284 return max_texture_size_.height() - border_texels_; 272 return max_texture_size_.height() - border_texels_;
285 if (y_index < num_tiles_y_ - 1) 273 if (y_index < num_tiles_y_ - 1)
286 return max_texture_size_.height() - 2 * border_texels_; 274 return max_texture_size_.height() - 2 * border_texels_;
287 if (y_index == num_tiles_y_ - 1) 275 if (y_index == num_tiles_y_ - 1)
288 return tiling_rect_.bottom() - TilePositionY(y_index); 276 return tiling_size_.height() - TilePositionY(y_index);
289 277
290 NOTREACHED(); 278 NOTREACHED();
291 return 0; 279 return 0;
292 } 280 }
293 281
294 gfx::Vector2d TilingData::TextureOffset(int x_index, int y_index) const { 282 gfx::Vector2d TilingData::TextureOffset(int x_index, int y_index) const {
295 int left = (!x_index || num_tiles_x_ == 1) ? 0 : border_texels_; 283 int left = (!x_index || num_tiles_x_ == 1) ? 0 : border_texels_;
296 int top = (!y_index || num_tiles_y_ == 1) ? 0 : border_texels_; 284 int top = (!y_index || num_tiles_y_ == 1) ? 0 : border_texels_;
297 285
298 return gfx::Vector2d(left, top); 286 return gfx::Vector2d(left, top);
299 } 287 }
300 288
301 void TilingData::RecomputeNumTiles() { 289 void TilingData::RecomputeNumTiles() {
302 num_tiles_x_ = ComputeNumTiles( 290 num_tiles_x_ = ComputeNumTiles(
303 max_texture_size_.width(), tiling_rect_.width(), border_texels_); 291 max_texture_size_.width(), tiling_size_.width(), border_texels_);
304 num_tiles_y_ = ComputeNumTiles( 292 num_tiles_y_ = ComputeNumTiles(
305 max_texture_size_.height(), tiling_rect_.height(), border_texels_); 293 max_texture_size_.height(), tiling_size_.height(), border_texels_);
306 } 294 }
307 295
308 TilingData::BaseIterator::BaseIterator(const TilingData* tiling_data) 296 TilingData::BaseIterator::BaseIterator(const TilingData* tiling_data)
309 : tiling_data_(tiling_data), 297 : tiling_data_(tiling_data),
310 index_x_(-1), 298 index_x_(-1),
311 index_y_(-1) { 299 index_y_(-1) {
312 } 300 }
313 301
314 TilingData::Iterator::Iterator() : BaseIterator(NULL) { done(); } 302 TilingData::Iterator::Iterator() : BaseIterator(NULL) { done(); }
315 303
316 TilingData::Iterator::Iterator(const TilingData* tiling_data, 304 TilingData::Iterator::Iterator(const TilingData* tiling_data,
317 const gfx::Rect& tiling_rect, 305 const gfx::Rect& consider_rect,
318 bool include_borders) 306 bool include_borders)
319 : BaseIterator(tiling_data), left_(-1), right_(-1), bottom_(-1) { 307 : BaseIterator(tiling_data), left_(-1), right_(-1), bottom_(-1) {
320 if (tiling_data_->num_tiles_x() <= 0 || tiling_data_->num_tiles_y() <= 0) { 308 if (tiling_data_->num_tiles_x() <= 0 || tiling_data_->num_tiles_y() <= 0) {
321 done(); 309 done();
322 return; 310 return;
323 } 311 }
324 312
325 gfx::Rect rect(tiling_rect); 313 gfx::Rect tiling_bounds_rect(tiling_data_->tiling_size());
326 rect.Intersect(tiling_data_->tiling_rect()); 314 gfx::Rect rect(consider_rect);
315 rect.Intersect(tiling_bounds_rect);
327 316
328 gfx::Rect top_left_tile; 317 gfx::Rect top_left_tile;
329 if (include_borders) { 318 if (include_borders) {
330 index_x_ = tiling_data_->FirstBorderTileXIndexFromSrcCoord(rect.x()); 319 index_x_ = tiling_data_->FirstBorderTileXIndexFromSrcCoord(rect.x());
331 index_y_ = tiling_data_->FirstBorderTileYIndexFromSrcCoord(rect.y()); 320 index_y_ = tiling_data_->FirstBorderTileYIndexFromSrcCoord(rect.y());
332 right_ = tiling_data_->LastBorderTileXIndexFromSrcCoord(rect.right() - 1); 321 right_ = tiling_data_->LastBorderTileXIndexFromSrcCoord(rect.right() - 1);
333 bottom_ = tiling_data_->LastBorderTileYIndexFromSrcCoord(rect.bottom() - 1); 322 bottom_ = tiling_data_->LastBorderTileYIndexFromSrcCoord(rect.bottom() - 1);
334 top_left_tile = tiling_data_->TileBoundsWithBorder(index_x_, index_y_); 323 top_left_tile = tiling_data_->TileBoundsWithBorder(index_x_, index_y_);
335 } else { 324 } else {
336 index_x_ = tiling_data_->TileXIndexFromSrcCoord(rect.x()); 325 index_x_ = tiling_data_->TileXIndexFromSrcCoord(rect.x());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 consider_bottom_(-1), 362 consider_bottom_(-1),
374 ignore_left_(-1), 363 ignore_left_(-1),
375 ignore_top_(-1), 364 ignore_top_(-1),
376 ignore_right_(-1), 365 ignore_right_(-1),
377 ignore_bottom_(-1) { 366 ignore_bottom_(-1) {
378 if (tiling_data_->num_tiles_x() <= 0 || tiling_data_->num_tiles_y() <= 0) { 367 if (tiling_data_->num_tiles_x() <= 0 || tiling_data_->num_tiles_y() <= 0) {
379 done(); 368 done();
380 return; 369 return;
381 } 370 }
382 371
372 gfx::Rect tiling_bounds_rect(tiling_data_->tiling_size());
383 gfx::Rect consider(consider_rect); 373 gfx::Rect consider(consider_rect);
384 gfx::Rect ignore(ignore_rect); 374 gfx::Rect ignore(ignore_rect);
385 consider.Intersect(tiling_data_->tiling_rect()); 375 consider.Intersect(tiling_bounds_rect);
386 ignore.Intersect(tiling_data_->tiling_rect()); 376 ignore.Intersect(tiling_bounds_rect);
387 if (consider.IsEmpty()) { 377 if (consider.IsEmpty()) {
388 done(); 378 done();
389 return; 379 return;
390 } 380 }
391 381
392 consider_left_ = 382 consider_left_ =
393 tiling_data_->FirstBorderTileXIndexFromSrcCoord(consider.x()); 383 tiling_data_->FirstBorderTileXIndexFromSrcCoord(consider.x());
394 consider_top_ = 384 consider_top_ =
395 tiling_data_->FirstBorderTileYIndexFromSrcCoord(consider.y()); 385 tiling_data_->FirstBorderTileYIndexFromSrcCoord(consider.y());
396 consider_right_ = 386 consider_right_ =
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 delta_x_(1), 470 delta_x_(1),
481 delta_y_(0), 471 delta_y_(0),
482 current_step_(0), 472 current_step_(0),
483 horizontal_step_count_(0), 473 horizontal_step_count_(0),
484 vertical_step_count_(0) { 474 vertical_step_count_(0) {
485 if (tiling_data_->num_tiles_x() <= 0 || tiling_data_->num_tiles_y() <= 0) { 475 if (tiling_data_->num_tiles_x() <= 0 || tiling_data_->num_tiles_y() <= 0) {
486 done(); 476 done();
487 return; 477 return;
488 } 478 }
489 479
480 gfx::Rect tiling_bounds_rect(tiling_data_->tiling_size());
490 gfx::Rect consider(consider_rect); 481 gfx::Rect consider(consider_rect);
491 gfx::Rect ignore(ignore_rect); 482 gfx::Rect ignore(ignore_rect);
492 gfx::Rect center(center_rect); 483 gfx::Rect center(center_rect);
493 consider.Intersect(tiling_data_->tiling_rect()); 484 consider.Intersect(tiling_bounds_rect);
494 ignore.Intersect(tiling_data_->tiling_rect()); 485 ignore.Intersect(tiling_bounds_rect);
495 if (consider.IsEmpty()) { 486 if (consider.IsEmpty()) {
496 done(); 487 done();
497 return; 488 return;
498 } 489 }
499 490
500 consider_left_ = 491 consider_left_ =
501 tiling_data_->FirstBorderTileXIndexFromSrcCoord(consider.x()); 492 tiling_data_->FirstBorderTileXIndexFromSrcCoord(consider.x());
502 consider_top_ = tiling_data_->FirstBorderTileYIndexFromSrcCoord(consider.y()); 493 consider_top_ = tiling_data_->FirstBorderTileYIndexFromSrcCoord(consider.y());
503 consider_right_ = 494 consider_right_ =
504 tiling_data_->LastBorderTileXIndexFromSrcCoord(consider.right() - 1); 495 tiling_data_->LastBorderTileXIndexFromSrcCoord(consider.right() - 1);
(...skipping 16 matching lines...) Expand all
521 } 512 }
522 513
523 if (ignore_left_ == consider_left_ && ignore_right_ == consider_right_ && 514 if (ignore_left_ == consider_left_ && ignore_right_ == consider_right_ &&
524 ignore_top_ == consider_top_ && ignore_bottom_ == consider_bottom_) { 515 ignore_top_ == consider_top_ && ignore_bottom_ == consider_bottom_) {
525 done(); 516 done();
526 return; 517 return;
527 } 518 }
528 519
529 // Determine around left, such that it is between -1 and num_tiles_x. 520 // Determine around left, such that it is between -1 and num_tiles_x.
530 int around_left = 0; 521 int around_left = 0;
531 if (center.x() < tiling_data->tiling_rect().x() || center.IsEmpty()) 522 if (center.x() < 0 || center.IsEmpty())
532 around_left = -1; 523 around_left = -1;
533 else if (center.x() > tiling_data->tiling_rect().right()) 524 else if (center.x() > tiling_data->tiling_size().width())
534 around_left = tiling_data->num_tiles_x(); 525 around_left = tiling_data->num_tiles_x();
535 else 526 else
536 around_left = tiling_data->FirstBorderTileXIndexFromSrcCoord(center.x()); 527 around_left = tiling_data->FirstBorderTileXIndexFromSrcCoord(center.x());
537 528
538 // Determine around top, such that it is between -1 and num_tiles_y. 529 // Determine around top, such that it is between -1 and num_tiles_y.
539 int around_top = 0; 530 int around_top = 0;
540 if (center.y() < tiling_data->tiling_rect().y() || center.IsEmpty()) 531 if (center.y() < 0 || center.IsEmpty())
541 around_top = -1; 532 around_top = -1;
542 else if (center.y() > tiling_data->tiling_rect().bottom()) 533 else if (center.y() > tiling_data->tiling_size().height())
543 around_top = tiling_data->num_tiles_y(); 534 around_top = tiling_data->num_tiles_y();
544 else 535 else
545 around_top = tiling_data->FirstBorderTileYIndexFromSrcCoord(center.y()); 536 around_top = tiling_data->FirstBorderTileYIndexFromSrcCoord(center.y());
546 537
547 // Determine around right, such that it is between -1 and num_tiles_x. 538 // Determine around right, such that it is between -1 and num_tiles_x.
548 int right_src_coord = center.right() - 1; 539 int right_src_coord = center.right() - 1;
549 int around_right = 0; 540 int around_right = 0;
550 if (right_src_coord < tiling_data->tiling_rect().x() || center.IsEmpty()) { 541 if (right_src_coord < 0 || center.IsEmpty()) {
551 around_right = -1; 542 around_right = -1;
552 } else if (right_src_coord > tiling_data->tiling_rect().right()) { 543 } else if (right_src_coord > tiling_data->tiling_size().width()) {
553 around_right = tiling_data->num_tiles_x(); 544 around_right = tiling_data->num_tiles_x();
554 } else { 545 } else {
555 around_right = 546 around_right =
556 tiling_data->LastBorderTileXIndexFromSrcCoord(right_src_coord); 547 tiling_data->LastBorderTileXIndexFromSrcCoord(right_src_coord);
557 } 548 }
558 549
559 // Determine around bottom, such that it is between -1 and num_tiles_y. 550 // Determine around bottom, such that it is between -1 and num_tiles_y.
560 int bottom_src_coord = center.bottom() - 1; 551 int bottom_src_coord = center.bottom() - 1;
561 int around_bottom = 0; 552 int around_bottom = 0;
562 if (bottom_src_coord < tiling_data->tiling_rect().y() || center.IsEmpty()) { 553 if (bottom_src_coord < 0 || center.IsEmpty()) {
563 around_bottom = -1; 554 around_bottom = -1;
564 } else if (bottom_src_coord > tiling_data->tiling_rect().bottom()) { 555 } else if (bottom_src_coord > tiling_data->tiling_size().height()) {
565 around_bottom = tiling_data->num_tiles_y(); 556 around_bottom = tiling_data->num_tiles_y();
566 } else { 557 } else {
567 around_bottom = 558 around_bottom =
568 tiling_data->LastBorderTileYIndexFromSrcCoord(bottom_src_coord); 559 tiling_data->LastBorderTileYIndexFromSrcCoord(bottom_src_coord);
569 } 560 }
570 561
571 vertical_step_count_ = around_bottom - around_top + 1; 562 vertical_step_count_ = around_bottom - around_top + 1;
572 horizontal_step_count_ = around_right - around_left + 1; 563 horizontal_step_count_ = around_right - around_left + 1;
573 current_step_ = horizontal_step_count_ - 1; 564 current_step_ = horizontal_step_count_ - 1;
574 565
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 current_step_ = 0; 672 current_step_ = 0;
682 direction_ = static_cast<Direction>((direction_ + 1) % 4); 673 direction_ = static_cast<Direction>((direction_ + 1) % 4);
683 674
684 if (direction_ == RIGHT || direction_ == LEFT) { 675 if (direction_ == RIGHT || direction_ == LEFT) {
685 ++vertical_step_count_; 676 ++vertical_step_count_;
686 ++horizontal_step_count_; 677 ++horizontal_step_count_;
687 } 678 }
688 } 679 }
689 680
690 } // namespace cc 681 } // namespace cc
OLDNEW
« no previous file with comments | « cc/base/tiling_data.h ('k') | cc/base/tiling_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698