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

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

Issue 235753002: cc: Give TilingData a Rect instead of a Size (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Git cl format Created 6 years, 8 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 10 matching lines...) Expand all
21 1 + (total_size - 1 - 2 * border_texels) / 21 1 + (total_size - 1 - 2 * border_texels) /
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( 31 TilingData::TilingData(const gfx::Size& max_texture_size,
32 const gfx::Size& max_texture_size, 32 const gfx::Rect& tiling_rect,
33 const gfx::Size& total_size, 33 bool has_border_texels)
34 bool has_border_texels)
35 : max_texture_size_(max_texture_size), 34 : max_texture_size_(max_texture_size),
36 total_size_(total_size), 35 tiling_rect_(tiling_rect),
37 border_texels_(has_border_texels ? 1 : 0) { 36 border_texels_(has_border_texels ? 1 : 0) {
38 RecomputeNumTiles(); 37 RecomputeNumTiles();
39 } 38 }
40 39
41 TilingData::TilingData( 40 TilingData::TilingData(const gfx::Size& max_texture_size,
42 const gfx::Size& max_texture_size, 41 const gfx::Rect& tiling_rect,
43 const gfx::Size& total_size, 42 int border_texels)
44 int border_texels)
45 : max_texture_size_(max_texture_size), 43 : max_texture_size_(max_texture_size),
46 total_size_(total_size), 44 tiling_rect_(tiling_rect),
47 border_texels_(border_texels) { 45 border_texels_(border_texels) {
48 RecomputeNumTiles(); 46 RecomputeNumTiles();
49 } 47 }
50 48
51 void TilingData::SetTotalSize(const gfx::Size& total_size) { 49 void TilingData::SetTilingRect(const gfx::Rect& tiling_rect) {
52 total_size_ = total_size; 50 tiling_rect_ = tiling_rect;
53 RecomputeNumTiles(); 51 RecomputeNumTiles();
54 } 52 }
55 53
56 void TilingData::SetMaxTextureSize(const gfx::Size& max_texture_size) { 54 void TilingData::SetMaxTextureSize(const gfx::Size& max_texture_size) {
57 max_texture_size_ = max_texture_size; 55 max_texture_size_ = max_texture_size;
58 RecomputeNumTiles(); 56 RecomputeNumTiles();
59 } 57 }
60 58
61 void TilingData::SetHasBorderTexels(bool has_border_texels) { 59 void TilingData::SetHasBorderTexels(bool has_border_texels) {
62 border_texels_ = has_border_texels ? 1 : 0; 60 border_texels_ = has_border_texels ? 1 : 0;
63 RecomputeNumTiles(); 61 RecomputeNumTiles();
64 } 62 }
65 63
66 void TilingData::SetBorderTexels(int border_texels) { 64 void TilingData::SetBorderTexels(int border_texels) {
67 border_texels_ = border_texels; 65 border_texels_ = border_texels;
68 RecomputeNumTiles(); 66 RecomputeNumTiles();
69 } 67 }
70 68
71 int TilingData::TileXIndexFromSrcCoord(int src_position) const { 69 int TilingData::TileXIndexFromSrcCoord(int src_position) const {
72 if (num_tiles_x_ <= 1) 70 if (num_tiles_x_ <= 1)
73 return 0; 71 return 0;
74 72
73 src_position -= tiling_rect_.x();
74
75 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0); 75 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0);
76 int x = (src_position - border_texels_) / 76 int x = (src_position - border_texels_) /
77 (max_texture_size_.width() - 2 * border_texels_); 77 (max_texture_size_.width() - 2 * border_texels_);
78 return std::min(std::max(x, 0), num_tiles_x_ - 1); 78 return std::min(std::max(x, 0), num_tiles_x_ - 1);
79 } 79 }
80 80
81 int TilingData::TileYIndexFromSrcCoord(int src_position) const { 81 int TilingData::TileYIndexFromSrcCoord(int src_position) const {
82 if (num_tiles_y_ <= 1) 82 if (num_tiles_y_ <= 1)
83 return 0; 83 return 0;
84 84
85 src_position -= tiling_rect_.y();
86
85 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0); 87 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0);
86 int y = (src_position - border_texels_) / 88 int y = (src_position - border_texels_) /
87 (max_texture_size_.height() - 2 * border_texels_); 89 (max_texture_size_.height() - 2 * border_texels_);
88 return std::min(std::max(y, 0), num_tiles_y_ - 1); 90 return std::min(std::max(y, 0), num_tiles_y_ - 1);
89 } 91 }
90 92
91 int TilingData::FirstBorderTileXIndexFromSrcCoord(int src_position) const { 93 int TilingData::FirstBorderTileXIndexFromSrcCoord(int src_position) const {
92 if (num_tiles_x_ <= 1) 94 if (num_tiles_x_ <= 1)
93 return 0; 95 return 0;
94 96
97 src_position -= tiling_rect_.x();
98
95 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0); 99 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0);
96 int inner_tile_size = max_texture_size_.width() - 2 * border_texels_; 100 int inner_tile_size = max_texture_size_.width() - 2 * border_texels_;
97 int x = (src_position - 2 * border_texels_) / inner_tile_size; 101 int x = (src_position - 2 * border_texels_) / inner_tile_size;
98 return std::min(std::max(x, 0), num_tiles_x_ - 1); 102 return std::min(std::max(x, 0), num_tiles_x_ - 1);
99 } 103 }
100 104
101 int TilingData::FirstBorderTileYIndexFromSrcCoord(int src_position) const { 105 int TilingData::FirstBorderTileYIndexFromSrcCoord(int src_position) const {
102 if (num_tiles_y_ <= 1) 106 if (num_tiles_y_ <= 1)
103 return 0; 107 return 0;
104 108
109 src_position -= tiling_rect_.y();
110
105 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0); 111 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0);
106 int inner_tile_size = max_texture_size_.height() - 2 * border_texels_; 112 int inner_tile_size = max_texture_size_.height() - 2 * border_texels_;
107 int y = (src_position - 2 * border_texels_) / inner_tile_size; 113 int y = (src_position - 2 * border_texels_) / inner_tile_size;
108 return std::min(std::max(y, 0), num_tiles_y_ - 1); 114 return std::min(std::max(y, 0), num_tiles_y_ - 1);
109 } 115 }
110 116
111 int TilingData::LastBorderTileXIndexFromSrcCoord(int src_position) const { 117 int TilingData::LastBorderTileXIndexFromSrcCoord(int src_position) const {
112 if (num_tiles_x_ <= 1) 118 if (num_tiles_x_ <= 1)
113 return 0; 119 return 0;
114 120
121 src_position -= tiling_rect_.x();
122
115 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0); 123 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0);
116 int inner_tile_size = max_texture_size_.width() - 2 * border_texels_; 124 int inner_tile_size = max_texture_size_.width() - 2 * border_texels_;
117 int x = src_position / inner_tile_size; 125 int x = src_position / inner_tile_size;
118 return std::min(std::max(x, 0), num_tiles_x_ - 1); 126 return std::min(std::max(x, 0), num_tiles_x_ - 1);
119 } 127 }
120 128
121 int TilingData::LastBorderTileYIndexFromSrcCoord(int src_position) const { 129 int TilingData::LastBorderTileYIndexFromSrcCoord(int src_position) const {
122 if (num_tiles_y_ <= 1) 130 if (num_tiles_y_ <= 1)
123 return 0; 131 return 0;
124 132
133 src_position -= tiling_rect_.y();
134
125 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0); 135 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0);
126 int inner_tile_size = max_texture_size_.height() - 2 * border_texels_; 136 int inner_tile_size = max_texture_size_.height() - 2 * border_texels_;
127 int y = src_position / inner_tile_size; 137 int y = src_position / inner_tile_size;
128 return std::min(std::max(y, 0), num_tiles_y_ - 1); 138 return std::min(std::max(y, 0), num_tiles_y_ - 1);
129 } 139 }
130 140
131 gfx::Rect TilingData::TileBounds(int i, int j) const { 141 gfx::Rect TilingData::TileBounds(int i, int j) const {
132 AssertTile(i, j); 142 AssertTile(i, j);
133 int max_texture_size_x = max_texture_size_.width() - 2 * border_texels_; 143 int max_texture_size_x = max_texture_size_.width() - 2 * border_texels_;
134 int max_texture_size_y = max_texture_size_.height() - 2 * border_texels_; 144 int max_texture_size_y = max_texture_size_.height() - 2 * border_texels_;
135 int total_size_x = total_size_.width();
136 int total_size_y = total_size_.height();
137 145
138 int lo_x = max_texture_size_x * i; 146 int lo_x = tiling_rect_.x() + max_texture_size_x * i;
139 if (i != 0) 147 if (i != 0)
140 lo_x += border_texels_; 148 lo_x += border_texels_;
141 149
142 int lo_y = max_texture_size_y * j; 150 int lo_y = tiling_rect_.y() + max_texture_size_y * j;
143 if (j != 0) 151 if (j != 0)
144 lo_y += border_texels_; 152 lo_y += border_texels_;
145 153
146 int hi_x = max_texture_size_x * (i + 1) + border_texels_; 154 int hi_x = tiling_rect_.x() + max_texture_size_x * (i + 1) + border_texels_;
147 if (i + 1 == num_tiles_x_) 155 if (i + 1 == num_tiles_x_)
148 hi_x += border_texels_; 156 hi_x += border_texels_;
149 157
150 int hi_y = max_texture_size_y * (j + 1) + border_texels_; 158 int hi_y = tiling_rect_.y() + max_texture_size_y * (j + 1) + border_texels_;
151 if (j + 1 == num_tiles_y_) 159 if (j + 1 == num_tiles_y_)
152 hi_y += border_texels_; 160 hi_y += border_texels_;
153 161
154 hi_x = std::min(hi_x, total_size_x); 162 hi_x = std::min(hi_x, tiling_rect_.right());
155 hi_y = std::min(hi_y, total_size_y); 163 hi_y = std::min(hi_y, tiling_rect_.bottom());
156 164
157 int x = lo_x; 165 int x = lo_x;
158 int y = lo_y; 166 int y = lo_y;
159 int width = hi_x - lo_x; 167 int width = hi_x - lo_x;
160 int height = hi_y - lo_y; 168 int height = hi_y - lo_y;
161 DCHECK_GE(x, 0); 169 DCHECK_GE(x, tiling_rect_.x());
162 DCHECK_GE(y, 0); 170 DCHECK_GE(y, tiling_rect_.y());
163 DCHECK_GE(width, 0); 171 DCHECK_GE(width, 0);
164 DCHECK_GE(height, 0); 172 DCHECK_GE(height, 0);
165 DCHECK_LE(x, total_size_.width()); 173 DCHECK_LE(x, tiling_rect_.right());
166 DCHECK_LE(y, total_size_.height()); 174 DCHECK_LE(y, tiling_rect_.bottom());
167 return gfx::Rect(x, y, width, height); 175 return gfx::Rect(x, y, width, height);
168 } 176 }
169 177
170 gfx::Rect TilingData::TileBoundsWithBorder(int i, int j) const { 178 gfx::Rect TilingData::TileBoundsWithBorder(int i, int j) const {
171 AssertTile(i, j); 179 AssertTile(i, j);
172 int max_texture_size_x = max_texture_size_.width() - 2 * border_texels_; 180 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_; 181 int max_texture_size_y = max_texture_size_.height() - 2 * border_texels_;
174 int total_size_x = total_size_.width();
175 int total_size_y = total_size_.height();
176 182
177 int lo_x = max_texture_size_x * i; 183 int lo_x = tiling_rect_.x() + max_texture_size_x * i;
178 int lo_y = max_texture_size_y * j; 184 int lo_y = tiling_rect_.y() + max_texture_size_y * j;
179 185
180 int hi_x = lo_x + max_texture_size_x + 2 * border_texels_; 186 int hi_x = lo_x + max_texture_size_x + 2 * border_texels_;
181 int hi_y = lo_y + max_texture_size_y + 2 * border_texels_; 187 int hi_y = lo_y + max_texture_size_y + 2 * border_texels_;
182 188
183 hi_x = std::min(hi_x, total_size_x); 189 hi_x = std::min(hi_x, tiling_rect_.right());
184 hi_y = std::min(hi_y, total_size_y); 190 hi_y = std::min(hi_y, tiling_rect_.bottom());
185 191
186 int x = lo_x; 192 int x = lo_x;
187 int y = lo_y; 193 int y = lo_y;
188 int width = hi_x - lo_x; 194 int width = hi_x - lo_x;
189 int height = hi_y - lo_y; 195 int height = hi_y - lo_y;
190 DCHECK_GE(x, 0); 196 DCHECK_GE(x, tiling_rect_.x());
191 DCHECK_GE(y, 0); 197 DCHECK_GE(y, tiling_rect_.y());
192 DCHECK_GE(width, 0); 198 DCHECK_GE(width, 0);
193 DCHECK_GE(height, 0); 199 DCHECK_GE(height, 0);
194 DCHECK_LE(x, total_size_.width()); 200 DCHECK_LE(x, tiling_rect_.right());
195 DCHECK_LE(y, total_size_.height()); 201 DCHECK_LE(y, tiling_rect_.bottom());
196 return gfx::Rect(x, y, width, height); 202 return gfx::Rect(x, y, width, height);
197 } 203 }
198 204
199 int TilingData::TilePositionX(int x_index) const { 205 int TilingData::TilePositionX(int x_index) const {
200 DCHECK_GE(x_index, 0); 206 DCHECK_GE(x_index, 0);
201 DCHECK_LT(x_index, num_tiles_x_); 207 DCHECK_LT(x_index, num_tiles_x_);
202 208
203 int pos = (max_texture_size_.width() - 2 * border_texels_) * x_index; 209 int pos = (max_texture_size_.width() - 2 * border_texels_) * x_index;
204 if (x_index != 0) 210 if (x_index != 0)
205 pos += border_texels_; 211 pos += border_texels_;
206 212
213 pos += tiling_rect_.x();
214
207 return pos; 215 return pos;
208 } 216 }
209 217
210 int TilingData::TilePositionY(int y_index) const { 218 int TilingData::TilePositionY(int y_index) const {
211 DCHECK_GE(y_index, 0); 219 DCHECK_GE(y_index, 0);
212 DCHECK_LT(y_index, num_tiles_y_); 220 DCHECK_LT(y_index, num_tiles_y_);
213 221
214 int pos = (max_texture_size_.height() - 2 * border_texels_) * y_index; 222 int pos = (max_texture_size_.height() - 2 * border_texels_) * y_index;
215 if (y_index != 0) 223 if (y_index != 0)
216 pos += border_texels_; 224 pos += border_texels_;
217 225
226 pos += tiling_rect_.y();
227
218 return pos; 228 return pos;
219 } 229 }
220 230
221 int TilingData::TileSizeX(int x_index) const { 231 int TilingData::TileSizeX(int x_index) const {
222 DCHECK_GE(x_index, 0); 232 DCHECK_GE(x_index, 0);
223 DCHECK_LT(x_index, num_tiles_x_); 233 DCHECK_LT(x_index, num_tiles_x_);
224 234
225 if (!x_index && num_tiles_x_ == 1) 235 if (!x_index && num_tiles_x_ == 1)
226 return total_size_.width(); 236 return tiling_rect_.width();
227 if (!x_index && num_tiles_x_ > 1) 237 if (!x_index && num_tiles_x_ > 1)
228 return max_texture_size_.width() - border_texels_; 238 return max_texture_size_.width() - border_texels_;
229 if (x_index < num_tiles_x_ - 1) 239 if (x_index < num_tiles_x_ - 1)
230 return max_texture_size_.width() - 2 * border_texels_; 240 return max_texture_size_.width() - 2 * border_texels_;
231 if (x_index == num_tiles_x_ - 1) 241 if (x_index == num_tiles_x_ - 1)
232 return total_size_.width() - TilePositionX(x_index); 242 return tiling_rect_.right() - TilePositionX(x_index);
233 243
234 NOTREACHED(); 244 NOTREACHED();
235 return 0; 245 return 0;
236 } 246 }
237 247
238 int TilingData::TileSizeY(int y_index) const { 248 int TilingData::TileSizeY(int y_index) const {
239 DCHECK_GE(y_index, 0); 249 DCHECK_GE(y_index, 0);
240 DCHECK_LT(y_index, num_tiles_y_); 250 DCHECK_LT(y_index, num_tiles_y_);
241 251
242 if (!y_index && num_tiles_y_ == 1) 252 if (!y_index && num_tiles_y_ == 1)
243 return total_size_.height(); 253 return tiling_rect_.height();
244 if (!y_index && num_tiles_y_ > 1) 254 if (!y_index && num_tiles_y_ > 1)
245 return max_texture_size_.height() - border_texels_; 255 return max_texture_size_.height() - border_texels_;
246 if (y_index < num_tiles_y_ - 1) 256 if (y_index < num_tiles_y_ - 1)
247 return max_texture_size_.height() - 2 * border_texels_; 257 return max_texture_size_.height() - 2 * border_texels_;
248 if (y_index == num_tiles_y_ - 1) 258 if (y_index == num_tiles_y_ - 1)
249 return total_size_.height() - TilePositionY(y_index); 259 return tiling_rect_.bottom() - TilePositionY(y_index);
250 260
251 NOTREACHED(); 261 NOTREACHED();
252 return 0; 262 return 0;
253 } 263 }
254 264
255 gfx::Vector2d TilingData::TextureOffset(int x_index, int y_index) const { 265 gfx::Vector2d TilingData::TextureOffset(int x_index, int y_index) const {
256 int left = (!x_index || num_tiles_x_ == 1) ? 0 : border_texels_; 266 int left = (!x_index || num_tiles_x_ == 1) ? 0 : border_texels_;
257 int top = (!y_index || num_tiles_y_ == 1) ? 0 : border_texels_; 267 int top = (!y_index || num_tiles_y_ == 1) ? 0 : border_texels_;
258 268
259 return gfx::Vector2d(left, top); 269 return gfx::Vector2d(left, top);
260 } 270 }
261 271
262 void TilingData::RecomputeNumTiles() { 272 void TilingData::RecomputeNumTiles() {
263 num_tiles_x_ = ComputeNumTiles( 273 num_tiles_x_ = ComputeNumTiles(
264 max_texture_size_.width(), total_size_.width(), border_texels_); 274 max_texture_size_.width(), tiling_rect_.width(), border_texels_);
265 num_tiles_y_ = ComputeNumTiles( 275 num_tiles_y_ = ComputeNumTiles(
266 max_texture_size_.height(), total_size_.height(), border_texels_); 276 max_texture_size_.height(), tiling_rect_.height(), border_texels_);
267 } 277 }
268 278
269 TilingData::BaseIterator::BaseIterator(const TilingData* tiling_data) 279 TilingData::BaseIterator::BaseIterator(const TilingData* tiling_data)
270 : tiling_data_(tiling_data), 280 : tiling_data_(tiling_data),
271 index_x_(-1), 281 index_x_(-1),
272 index_y_(-1) { 282 index_y_(-1) {
273 } 283 }
274 284
275 TilingData::Iterator::Iterator() : BaseIterator(NULL) { done(); } 285 TilingData::Iterator::Iterator() : BaseIterator(NULL) { done(); }
276 286
277 TilingData::Iterator::Iterator(const TilingData* tiling_data, 287 TilingData::Iterator::Iterator(const TilingData* tiling_data,
278 const gfx::Rect& tiling_rect, 288 const gfx::Rect& tiling_rect,
279 bool include_borders) 289 bool include_borders)
280 : BaseIterator(tiling_data), left_(-1), right_(-1), bottom_(-1) { 290 : BaseIterator(tiling_data), left_(-1), right_(-1), bottom_(-1) {
281 if (tiling_data_->num_tiles_x() <= 0 || tiling_data_->num_tiles_y() <= 0) { 291 if (tiling_data_->num_tiles_x() <= 0 || tiling_data_->num_tiles_y() <= 0) {
282 done(); 292 done();
283 return; 293 return;
284 } 294 }
285 295
286 gfx::Rect rect(tiling_rect); 296 gfx::Rect rect(tiling_rect);
287 rect.Intersect(gfx::Rect(tiling_data_->total_size())); 297 rect.Intersect(tiling_data_->tiling_rect());
288 298
289 gfx::Rect top_left_tile; 299 gfx::Rect top_left_tile;
290 if (include_borders) { 300 if (include_borders) {
291 index_x_ = tiling_data_->FirstBorderTileXIndexFromSrcCoord(rect.x()); 301 index_x_ = tiling_data_->FirstBorderTileXIndexFromSrcCoord(rect.x());
292 index_y_ = tiling_data_->FirstBorderTileYIndexFromSrcCoord(rect.y()); 302 index_y_ = tiling_data_->FirstBorderTileYIndexFromSrcCoord(rect.y());
293 right_ = tiling_data_->LastBorderTileXIndexFromSrcCoord(rect.right() - 1); 303 right_ = tiling_data_->LastBorderTileXIndexFromSrcCoord(rect.right() - 1);
294 bottom_ = tiling_data_->LastBorderTileYIndexFromSrcCoord(rect.bottom() - 1); 304 bottom_ = tiling_data_->LastBorderTileYIndexFromSrcCoord(rect.bottom() - 1);
295 top_left_tile = tiling_data_->TileBoundsWithBorder(index_x_, index_y_); 305 top_left_tile = tiling_data_->TileBoundsWithBorder(index_x_, index_y_);
296 } else { 306 } else {
297 index_x_ = tiling_data_->TileXIndexFromSrcCoord(rect.x()); 307 index_x_ = tiling_data_->TileXIndexFromSrcCoord(rect.x());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 consider_bottom_(-1), 344 consider_bottom_(-1),
335 ignore_left_(-1), 345 ignore_left_(-1),
336 ignore_top_(-1), 346 ignore_top_(-1),
337 ignore_right_(-1), 347 ignore_right_(-1),
338 ignore_bottom_(-1) { 348 ignore_bottom_(-1) {
339 if (tiling_data_->num_tiles_x() <= 0 || tiling_data_->num_tiles_y() <= 0) { 349 if (tiling_data_->num_tiles_x() <= 0 || tiling_data_->num_tiles_y() <= 0) {
340 done(); 350 done();
341 return; 351 return;
342 } 352 }
343 353
344 gfx::Rect bounds(tiling_data_->total_size());
345 gfx::Rect consider(consider_rect); 354 gfx::Rect consider(consider_rect);
346 gfx::Rect ignore(ignore_rect); 355 gfx::Rect ignore(ignore_rect);
347 consider.Intersect(bounds); 356 consider.Intersect(tiling_data_->tiling_rect());
348 ignore.Intersect(bounds); 357 ignore.Intersect(tiling_data_->tiling_rect());
349 if (consider.IsEmpty()) { 358 if (consider.IsEmpty()) {
350 done(); 359 done();
351 return; 360 return;
352 } 361 }
353 362
354 consider_left_ = 363 consider_left_ =
355 tiling_data_->FirstBorderTileXIndexFromSrcCoord(consider.x()); 364 tiling_data_->FirstBorderTileXIndexFromSrcCoord(consider.x());
356 consider_top_ = 365 consider_top_ =
357 tiling_data_->FirstBorderTileYIndexFromSrcCoord(consider.y()); 366 tiling_data_->FirstBorderTileYIndexFromSrcCoord(consider.y());
358 consider_right_ = 367 consider_right_ =
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 delta_x_(1), 451 delta_x_(1),
443 delta_y_(0), 452 delta_y_(0),
444 current_step_(0), 453 current_step_(0),
445 horizontal_step_count_(0), 454 horizontal_step_count_(0),
446 vertical_step_count_(0) { 455 vertical_step_count_(0) {
447 if (tiling_data_->num_tiles_x() <= 0 || tiling_data_->num_tiles_y() <= 0) { 456 if (tiling_data_->num_tiles_x() <= 0 || tiling_data_->num_tiles_y() <= 0) {
448 done(); 457 done();
449 return; 458 return;
450 } 459 }
451 460
452 gfx::Rect bounds(tiling_data_->total_size());
453 gfx::Rect consider(consider_rect); 461 gfx::Rect consider(consider_rect);
454 gfx::Rect ignore(ignore_rect); 462 gfx::Rect ignore(ignore_rect);
455 gfx::Rect center(center_rect); 463 gfx::Rect center(center_rect);
456 consider.Intersect(bounds); 464 consider.Intersect(tiling_data_->tiling_rect());
457 ignore.Intersect(bounds); 465 ignore.Intersect(tiling_data_->tiling_rect());
458 if (consider.IsEmpty()) { 466 if (consider.IsEmpty()) {
459 done(); 467 done();
460 return; 468 return;
461 } 469 }
462 470
463 consider_left_ = 471 consider_left_ =
464 tiling_data_->FirstBorderTileXIndexFromSrcCoord(consider.x()); 472 tiling_data_->FirstBorderTileXIndexFromSrcCoord(consider.x());
465 consider_top_ = tiling_data_->FirstBorderTileYIndexFromSrcCoord(consider.y()); 473 consider_top_ = tiling_data_->FirstBorderTileYIndexFromSrcCoord(consider.y());
466 consider_right_ = 474 consider_right_ =
467 tiling_data_->LastBorderTileXIndexFromSrcCoord(consider.right() - 1); 475 tiling_data_->LastBorderTileXIndexFromSrcCoord(consider.right() - 1);
(...skipping 16 matching lines...) Expand all
484 } 492 }
485 493
486 if (ignore_left_ == consider_left_ && ignore_right_ == consider_right_ && 494 if (ignore_left_ == consider_left_ && ignore_right_ == consider_right_ &&
487 ignore_top_ == consider_top_ && ignore_bottom_ == consider_bottom_) { 495 ignore_top_ == consider_top_ && ignore_bottom_ == consider_bottom_) {
488 done(); 496 done();
489 return; 497 return;
490 } 498 }
491 499
492 // Determine around left, such that it is between -1 and num_tiles_x. 500 // Determine around left, such that it is between -1 and num_tiles_x.
493 int around_left = 0; 501 int around_left = 0;
494 if (center.x() < 0 || center.IsEmpty()) 502 if (center.x() < tiling_data->tiling_rect().x() || center.IsEmpty())
495 around_left = -1; 503 around_left = -1;
496 else if (center.x() > tiling_data->total_size().width()) 504 else if (center.x() > tiling_data->tiling_rect().right())
497 around_left = tiling_data->num_tiles_x(); 505 around_left = tiling_data->num_tiles_x();
498 else 506 else
499 around_left = tiling_data->FirstBorderTileXIndexFromSrcCoord(center.x()); 507 around_left = tiling_data->FirstBorderTileXIndexFromSrcCoord(center.x());
500 508
501 // Determine around top, such that it is between -1 and num_tiles_y. 509 // Determine around top, such that it is between -1 and num_tiles_y.
502 int around_top = 0; 510 int around_top = 0;
503 if (center.y() < 0 || center.IsEmpty()) 511 if (center.y() < tiling_data->tiling_rect().y() || center.IsEmpty())
504 around_top = -1; 512 around_top = -1;
505 else if (center.y() > tiling_data->total_size().height()) 513 else if (center.y() > tiling_data->tiling_rect().bottom())
506 around_top = tiling_data->num_tiles_y(); 514 around_top = tiling_data->num_tiles_y();
507 else 515 else
508 around_top = tiling_data->FirstBorderTileYIndexFromSrcCoord(center.y()); 516 around_top = tiling_data->FirstBorderTileYIndexFromSrcCoord(center.y());
509 517
510 // Determine around right, such that it is between -1 and num_tiles_x. 518 // Determine around right, such that it is between -1 and num_tiles_x.
511 int right_src_coord = center.right() - 1; 519 int right_src_coord = center.right() - 1;
512 int around_right = 0; 520 int around_right = 0;
513 if (right_src_coord < 0 || center.IsEmpty()) { 521 if (right_src_coord < tiling_data->tiling_rect().x() || center.IsEmpty()) {
514 around_right = -1; 522 around_right = -1;
515 } else if (right_src_coord > tiling_data->total_size().width()) { 523 } else if (right_src_coord > tiling_data->tiling_rect().right()) {
516 around_right = tiling_data->num_tiles_x(); 524 around_right = tiling_data->num_tiles_x();
517 } else { 525 } else {
518 around_right = 526 around_right =
519 tiling_data->LastBorderTileXIndexFromSrcCoord(right_src_coord); 527 tiling_data->LastBorderTileXIndexFromSrcCoord(right_src_coord);
520 } 528 }
521 529
522 // Determine around bottom, such that it is between -1 and num_tiles_y. 530 // Determine around bottom, such that it is between -1 and num_tiles_y.
523 int bottom_src_coord = center.bottom() - 1; 531 int bottom_src_coord = center.bottom() - 1;
524 int around_bottom = 0; 532 int around_bottom = 0;
525 if (bottom_src_coord < 0 || center.IsEmpty()) { 533 if (bottom_src_coord < tiling_data->tiling_rect().y() || center.IsEmpty()) {
526 around_bottom = -1; 534 around_bottom = -1;
527 } else if (bottom_src_coord > tiling_data->total_size().height()) { 535 } else if (bottom_src_coord > tiling_data->tiling_rect().bottom()) {
528 around_bottom = tiling_data->num_tiles_y(); 536 around_bottom = tiling_data->num_tiles_y();
529 } else { 537 } else {
530 around_bottom = 538 around_bottom =
531 tiling_data->LastBorderTileYIndexFromSrcCoord(bottom_src_coord); 539 tiling_data->LastBorderTileYIndexFromSrcCoord(bottom_src_coord);
532 } 540 }
533 541
534 vertical_step_count_ = around_bottom - around_top + 1; 542 vertical_step_count_ = around_bottom - around_top + 1;
535 horizontal_step_count_ = around_right - around_left + 1; 543 horizontal_step_count_ = around_right - around_left + 1;
536 current_step_ = horizontal_step_count_ - 1; 544 current_step_ = horizontal_step_count_ - 1;
537 545
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 current_step_ = 0; 652 current_step_ = 0;
645 direction_ = static_cast<Direction>((direction_ + 1) % 4); 653 direction_ = static_cast<Direction>((direction_ + 1) % 4);
646 654
647 if (direction_ == RIGHT || direction_ == LEFT) { 655 if (direction_ == RIGHT || direction_ == LEFT) {
648 ++vertical_step_count_; 656 ++vertical_step_count_;
649 ++horizontal_step_count_; 657 ++horizontal_step_count_;
650 } 658 }
651 } 659 }
652 660
653 } // namespace cc 661 } // 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