| OLD | NEW |
| 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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 | 268 |
| 269 TilingData::BaseIterator::BaseIterator(const TilingData* tiling_data) | 269 TilingData::BaseIterator::BaseIterator(const TilingData* tiling_data) |
| 270 : tiling_data_(tiling_data), | 270 : tiling_data_(tiling_data), |
| 271 index_x_(-1), | 271 index_x_(-1), |
| 272 index_y_(-1) { | 272 index_y_(-1) { |
| 273 } | 273 } |
| 274 | 274 |
| 275 TilingData::Iterator::Iterator() : BaseIterator(NULL) { done(); } | 275 TilingData::Iterator::Iterator() : BaseIterator(NULL) { done(); } |
| 276 | 276 |
| 277 TilingData::Iterator::Iterator(const TilingData* tiling_data, | 277 TilingData::Iterator::Iterator(const TilingData* tiling_data, |
| 278 const gfx::Rect& tiling_rect) | 278 const gfx::Rect& tiling_rect, |
| 279 : BaseIterator(tiling_data), | 279 bool include_borders) |
| 280 left_(-1), | 280 : BaseIterator(tiling_data), left_(-1), right_(-1), bottom_(-1) { |
| 281 right_(-1), | |
| 282 bottom_(-1) { | |
| 283 if (tiling_data_->num_tiles_x() <= 0 || tiling_data_->num_tiles_y() <= 0) { | 281 if (tiling_data_->num_tiles_x() <= 0 || tiling_data_->num_tiles_y() <= 0) { |
| 284 done(); | 282 done(); |
| 285 return; | 283 return; |
| 286 } | 284 } |
| 287 | 285 |
| 288 gfx::Rect rect(tiling_rect); | 286 gfx::Rect rect(tiling_rect); |
| 289 rect.Intersect(gfx::Rect(tiling_data_->total_size())); | 287 rect.Intersect(gfx::Rect(tiling_data_->total_size())); |
| 290 index_x_ = tiling_data_->FirstBorderTileXIndexFromSrcCoord(rect.x()); | 288 |
| 291 index_y_ = tiling_data_->FirstBorderTileYIndexFromSrcCoord(rect.y()); | 289 gfx::Rect top_left_tile; |
| 290 if (include_borders) { |
| 291 index_x_ = tiling_data_->FirstBorderTileXIndexFromSrcCoord(rect.x()); |
| 292 index_y_ = tiling_data_->FirstBorderTileYIndexFromSrcCoord(rect.y()); |
| 293 right_ = tiling_data_->LastBorderTileXIndexFromSrcCoord(rect.right() - 1); |
| 294 bottom_ = tiling_data_->LastBorderTileYIndexFromSrcCoord(rect.bottom() - 1); |
| 295 top_left_tile = tiling_data_->TileBoundsWithBorder(index_x_, index_y_); |
| 296 } else { |
| 297 index_x_ = tiling_data_->TileXIndexFromSrcCoord(rect.x()); |
| 298 index_y_ = tiling_data_->TileYIndexFromSrcCoord(rect.y()); |
| 299 right_ = tiling_data_->TileXIndexFromSrcCoord(rect.right() - 1); |
| 300 bottom_ = tiling_data_->TileYIndexFromSrcCoord(rect.bottom() - 1); |
| 301 top_left_tile = tiling_data_->TileBounds(index_x_, index_y_); |
| 302 } |
| 292 left_ = index_x_; | 303 left_ = index_x_; |
| 293 right_ = tiling_data_->LastBorderTileXIndexFromSrcCoord(rect.right() - 1); | |
| 294 bottom_ = tiling_data_->LastBorderTileYIndexFromSrcCoord(rect.bottom() - 1); | |
| 295 | 304 |
| 296 // Index functions always return valid indices, so explicitly check | 305 // Index functions always return valid indices, so explicitly check |
| 297 // for non-intersecting rects. | 306 // for non-intersecting rects. |
| 298 gfx::Rect new_rect = tiling_data_->TileBoundsWithBorder(index_x_, index_y_); | 307 if (!top_left_tile.Intersects(rect)) |
| 299 if (!new_rect.Intersects(rect)) | |
| 300 done(); | 308 done(); |
| 301 } | 309 } |
| 302 | 310 |
| 303 TilingData::Iterator& TilingData::Iterator::operator++() { | 311 TilingData::Iterator& TilingData::Iterator::operator++() { |
| 304 if (!*this) | 312 if (!*this) |
| 305 return *this; | 313 return *this; |
| 306 | 314 |
| 307 index_x_++; | 315 index_x_++; |
| 308 if (index_x_ > right_) { | 316 if (index_x_ > right_) { |
| 309 index_x_ = left_; | 317 index_x_ = left_; |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 current_step_ = 0; | 644 current_step_ = 0; |
| 637 direction_ = static_cast<Direction>((direction_ + 1) % 4); | 645 direction_ = static_cast<Direction>((direction_ + 1) % 4); |
| 638 | 646 |
| 639 if (direction_ == RIGHT || direction_ == LEFT) { | 647 if (direction_ == RIGHT || direction_ == LEFT) { |
| 640 ++vertical_step_count_; | 648 ++vertical_step_count_; |
| 641 ++horizontal_step_count_; | 649 ++horizontal_step_count_; |
| 642 } | 650 } |
| 643 } | 651 } |
| 644 | 652 |
| 645 } // namespace cc | 653 } // namespace cc |
| OLD | NEW |