| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 int TilingData::LastBorderTileYIndexFromSrcCoord(int src_position) const { | 119 int TilingData::LastBorderTileYIndexFromSrcCoord(int src_position) const { |
| 120 if (num_tiles_y_ <= 1) | 120 if (num_tiles_y_ <= 1) |
| 121 return 0; | 121 return 0; |
| 122 | 122 |
| 123 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0); | 123 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0); |
| 124 int inner_tile_size = max_texture_size_.height() - 2 * border_texels_; | 124 int inner_tile_size = max_texture_size_.height() - 2 * border_texels_; |
| 125 int y = src_position / inner_tile_size; | 125 int y = src_position / inner_tile_size; |
| 126 return std::min(std::max(y, 0), num_tiles_y_ - 1); | 126 return std::min(std::max(y, 0), num_tiles_y_ - 1); |
| 127 } | 127 } |
| 128 | 128 |
| 129 gfx::Rect TilingData::ExpandRectIgnoringBordersToTileBoundsWithBorders( | 129 gfx::Rect TilingData::ExpandRectIgnoringBordersToTileBounds( |
| 130 const gfx::Rect& rect) const { | 130 const gfx::Rect& rect) const { |
| 131 if (rect.IsEmpty() || has_empty_bounds()) | 131 if (rect.IsEmpty() || has_empty_bounds()) |
| 132 return gfx::Rect(); | 132 return gfx::Rect(); |
| 133 if (rect.x() > tiling_size_.width() || rect.y() > tiling_size_.height()) | 133 if (rect.x() > tiling_size_.width() || rect.y() > tiling_size_.height()) |
| 134 return gfx::Rect(); | 134 return gfx::Rect(); |
| 135 int index_x = TileXIndexFromSrcCoord(rect.x()); | 135 int index_x = TileXIndexFromSrcCoord(rect.x()); |
| 136 int index_y = TileYIndexFromSrcCoord(rect.y()); | 136 int index_y = TileYIndexFromSrcCoord(rect.y()); |
| 137 int index_right = TileXIndexFromSrcCoord(rect.right() - 1); | 137 int index_right = TileXIndexFromSrcCoord(rect.right() - 1); |
| 138 int index_bottom = TileYIndexFromSrcCoord(rect.bottom() - 1); | 138 int index_bottom = TileYIndexFromSrcCoord(rect.bottom() - 1); |
| 139 | 139 |
| 140 gfx::Rect rect_top_left(TileBoundsWithBorder(index_x, index_y)); | 140 gfx::Rect rect_top_left(TileBounds(index_x, index_y)); |
| 141 gfx::Rect rect_bottom_right(TileBoundsWithBorder(index_right, index_bottom)); | 141 gfx::Rect rect_bottom_right(TileBounds(index_right, index_bottom)); |
| 142 | 142 |
| 143 return gfx::UnionRects(rect_top_left, rect_bottom_right); | 143 return gfx::UnionRects(rect_top_left, rect_bottom_right); |
| 144 } | 144 } |
| 145 | 145 |
| 146 gfx::Rect TilingData::ExpandRectToTileBounds(const gfx::Rect& rect) const { | 146 gfx::Rect TilingData::ExpandRectToTileBounds(const gfx::Rect& rect) const { |
| 147 if (rect.IsEmpty() || has_empty_bounds()) | 147 if (rect.IsEmpty() || has_empty_bounds()) |
| 148 return gfx::Rect(); | 148 return gfx::Rect(); |
| 149 if (rect.x() > tiling_size_.width() || rect.y() > tiling_size_.height()) | 149 if (rect.x() > tiling_size_.width() || rect.y() > tiling_size_.height()) |
| 150 return gfx::Rect(); | 150 return gfx::Rect(); |
| 151 int index_x = FirstBorderTileXIndexFromSrcCoord(rect.x()); | 151 int index_x = FirstBorderTileXIndexFromSrcCoord(rect.x()); |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 gfx::Rect tiling_bounds_rect(tiling_data_->tiling_size()); | 372 gfx::Rect tiling_bounds_rect(tiling_data_->tiling_size()); |
| 373 gfx::Rect consider(consider_rect); | 373 gfx::Rect consider(consider_rect); |
| 374 gfx::Rect ignore(ignore_rect); | 374 gfx::Rect ignore(ignore_rect); |
| 375 consider.Intersect(tiling_bounds_rect); | 375 consider.Intersect(tiling_bounds_rect); |
| 376 ignore.Intersect(tiling_bounds_rect); | 376 ignore.Intersect(tiling_bounds_rect); |
| 377 if (consider.IsEmpty()) { | 377 if (consider.IsEmpty()) { |
| 378 done(); | 378 done(); |
| 379 return; | 379 return; |
| 380 } | 380 } |
| 381 | 381 |
| 382 consider_left_ = | 382 consider_left_ = tiling_data_->TileXIndexFromSrcCoord(consider.x()); |
| 383 tiling_data_->FirstBorderTileXIndexFromSrcCoord(consider.x()); | 383 consider_top_ = tiling_data_->TileYIndexFromSrcCoord(consider.y()); |
| 384 consider_top_ = | 384 consider_right_ = tiling_data_->TileXIndexFromSrcCoord(consider.right() - 1); |
| 385 tiling_data_->FirstBorderTileYIndexFromSrcCoord(consider.y()); | |
| 386 consider_right_ = | |
| 387 tiling_data_->LastBorderTileXIndexFromSrcCoord(consider.right() - 1); | |
| 388 consider_bottom_ = | 385 consider_bottom_ = |
| 389 tiling_data_->LastBorderTileYIndexFromSrcCoord(consider.bottom() - 1); | 386 tiling_data_->TileYIndexFromSrcCoord(consider.bottom() - 1); |
| 390 | 387 |
| 391 if (!ignore.IsEmpty()) { | 388 if (!ignore.IsEmpty()) { |
| 392 ignore_left_ = | 389 ignore_left_ = tiling_data_->TileXIndexFromSrcCoord(ignore.x()); |
| 393 tiling_data_->FirstBorderTileXIndexFromSrcCoord(ignore.x()); | 390 ignore_top_ = tiling_data_->TileYIndexFromSrcCoord(ignore.y()); |
| 394 ignore_top_ = | 391 ignore_right_ = tiling_data_->TileXIndexFromSrcCoord(ignore.right() - 1); |
| 395 tiling_data_->FirstBorderTileYIndexFromSrcCoord(ignore.y()); | 392 ignore_bottom_ = tiling_data_->TileYIndexFromSrcCoord(ignore.bottom() - 1); |
| 396 ignore_right_ = | |
| 397 tiling_data_->LastBorderTileXIndexFromSrcCoord(ignore.right() - 1); | |
| 398 ignore_bottom_ = | |
| 399 tiling_data_->LastBorderTileYIndexFromSrcCoord(ignore.bottom() - 1); | |
| 400 | 393 |
| 401 // Clamp ignore indices to consider indices. | 394 // Clamp ignore indices to consider indices. |
| 402 ignore_left_ = std::max(ignore_left_, consider_left_); | 395 ignore_left_ = std::max(ignore_left_, consider_left_); |
| 403 ignore_top_ = std::max(ignore_top_, consider_top_); | 396 ignore_top_ = std::max(ignore_top_, consider_top_); |
| 404 ignore_right_ = std::min(ignore_right_, consider_right_); | 397 ignore_right_ = std::min(ignore_right_, consider_right_); |
| 405 ignore_bottom_ = std::min(ignore_bottom_, consider_bottom_); | 398 ignore_bottom_ = std::min(ignore_bottom_, consider_bottom_); |
| 406 } | 399 } |
| 407 | 400 |
| 408 if (ignore_left_ == consider_left_ && ignore_right_ == consider_right_ && | 401 if (ignore_left_ == consider_left_ && ignore_right_ == consider_right_ && |
| 409 ignore_top_ == consider_top_ && ignore_bottom_ == consider_bottom_) { | 402 ignore_top_ == consider_top_ && ignore_bottom_ == consider_bottom_) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 gfx::Rect consider(consider_rect); | 474 gfx::Rect consider(consider_rect); |
| 482 gfx::Rect ignore(ignore_rect); | 475 gfx::Rect ignore(ignore_rect); |
| 483 gfx::Rect center(center_rect); | 476 gfx::Rect center(center_rect); |
| 484 consider.Intersect(tiling_bounds_rect); | 477 consider.Intersect(tiling_bounds_rect); |
| 485 ignore.Intersect(tiling_bounds_rect); | 478 ignore.Intersect(tiling_bounds_rect); |
| 486 if (consider.IsEmpty()) { | 479 if (consider.IsEmpty()) { |
| 487 done(); | 480 done(); |
| 488 return; | 481 return; |
| 489 } | 482 } |
| 490 | 483 |
| 491 consider_left_ = | 484 consider_left_ = tiling_data_->TileXIndexFromSrcCoord(consider.x()); |
| 492 tiling_data_->FirstBorderTileXIndexFromSrcCoord(consider.x()); | 485 consider_top_ = tiling_data_->TileYIndexFromSrcCoord(consider.y()); |
| 493 consider_top_ = tiling_data_->FirstBorderTileYIndexFromSrcCoord(consider.y()); | 486 consider_right_ = tiling_data_->TileXIndexFromSrcCoord(consider.right() - 1); |
| 494 consider_right_ = | |
| 495 tiling_data_->LastBorderTileXIndexFromSrcCoord(consider.right() - 1); | |
| 496 consider_bottom_ = | 487 consider_bottom_ = |
| 497 tiling_data_->LastBorderTileYIndexFromSrcCoord(consider.bottom() - 1); | 488 tiling_data_->TileYIndexFromSrcCoord(consider.bottom() - 1); |
| 498 | 489 |
| 499 if (!ignore.IsEmpty()) { | 490 if (!ignore.IsEmpty()) { |
| 500 ignore_left_ = tiling_data_->FirstBorderTileXIndexFromSrcCoord(ignore.x()); | 491 ignore_left_ = tiling_data_->TileXIndexFromSrcCoord(ignore.x()); |
| 501 ignore_top_ = tiling_data_->FirstBorderTileYIndexFromSrcCoord(ignore.y()); | 492 ignore_top_ = tiling_data_->TileYIndexFromSrcCoord(ignore.y()); |
| 502 ignore_right_ = | 493 ignore_right_ = tiling_data_->TileXIndexFromSrcCoord(ignore.right() - 1); |
| 503 tiling_data_->LastBorderTileXIndexFromSrcCoord(ignore.right() - 1); | 494 ignore_bottom_ = tiling_data_->TileYIndexFromSrcCoord(ignore.bottom() - 1); |
| 504 ignore_bottom_ = | |
| 505 tiling_data_->LastBorderTileYIndexFromSrcCoord(ignore.bottom() - 1); | |
| 506 | 495 |
| 507 // Clamp ignore indices to consider indices. | 496 // Clamp ignore indices to consider indices. |
| 508 ignore_left_ = std::max(ignore_left_, consider_left_); | 497 ignore_left_ = std::max(ignore_left_, consider_left_); |
| 509 ignore_top_ = std::max(ignore_top_, consider_top_); | 498 ignore_top_ = std::max(ignore_top_, consider_top_); |
| 510 ignore_right_ = std::min(ignore_right_, consider_right_); | 499 ignore_right_ = std::min(ignore_right_, consider_right_); |
| 511 ignore_bottom_ = std::min(ignore_bottom_, consider_bottom_); | 500 ignore_bottom_ = std::min(ignore_bottom_, consider_bottom_); |
| 512 } | 501 } |
| 513 | 502 |
| 514 if (ignore_left_ == consider_left_ && ignore_right_ == consider_right_ && | 503 if (ignore_left_ == consider_left_ && ignore_right_ == consider_right_ && |
| 515 ignore_top_ == consider_top_ && ignore_bottom_ == consider_bottom_) { | 504 ignore_top_ == consider_top_ && ignore_bottom_ == consider_bottom_) { |
| 516 done(); | 505 done(); |
| 517 return; | 506 return; |
| 518 } | 507 } |
| 519 | 508 |
| 520 // Determine around left, such that it is between -1 and num_tiles_x. | 509 // Determine around left, such that it is between -1 and num_tiles_x. |
| 521 int around_left = 0; | 510 int around_left = 0; |
| 522 if (center.x() < 0 || center.IsEmpty()) | 511 if (center.x() < 0 || center.IsEmpty()) |
| 523 around_left = -1; | 512 around_left = -1; |
| 524 else if (center.x() > tiling_data->tiling_size().width()) | 513 else if (center.x() > tiling_data->tiling_size().width()) |
| 525 around_left = tiling_data->num_tiles_x(); | 514 around_left = tiling_data->num_tiles_x(); |
| 526 else | 515 else |
| 527 around_left = tiling_data->FirstBorderTileXIndexFromSrcCoord(center.x()); | 516 around_left = tiling_data->TileXIndexFromSrcCoord(center.x()); |
| 528 | 517 |
| 529 // Determine around top, such that it is between -1 and num_tiles_y. | 518 // Determine around top, such that it is between -1 and num_tiles_y. |
| 530 int around_top = 0; | 519 int around_top = 0; |
| 531 if (center.y() < 0 || center.IsEmpty()) | 520 if (center.y() < 0 || center.IsEmpty()) |
| 532 around_top = -1; | 521 around_top = -1; |
| 533 else if (center.y() > tiling_data->tiling_size().height()) | 522 else if (center.y() > tiling_data->tiling_size().height()) |
| 534 around_top = tiling_data->num_tiles_y(); | 523 around_top = tiling_data->num_tiles_y(); |
| 535 else | 524 else |
| 536 around_top = tiling_data->FirstBorderTileYIndexFromSrcCoord(center.y()); | 525 around_top = tiling_data->TileYIndexFromSrcCoord(center.y()); |
| 537 | 526 |
| 538 // Determine around right, such that it is between -1 and num_tiles_x. | 527 // Determine around right, such that it is between -1 and num_tiles_x. |
| 539 int right_src_coord = center.right() - 1; | 528 int right_src_coord = center.right() - 1; |
| 540 int around_right = 0; | 529 int around_right = 0; |
| 541 if (right_src_coord < 0 || center.IsEmpty()) { | 530 if (right_src_coord < 0 || center.IsEmpty()) { |
| 542 around_right = -1; | 531 around_right = -1; |
| 543 } else if (right_src_coord > tiling_data->tiling_size().width()) { | 532 } else if (right_src_coord > tiling_data->tiling_size().width()) { |
| 544 around_right = tiling_data->num_tiles_x(); | 533 around_right = tiling_data->num_tiles_x(); |
| 545 } else { | 534 } else { |
| 546 around_right = | 535 around_right = tiling_data->TileXIndexFromSrcCoord(right_src_coord); |
| 547 tiling_data->LastBorderTileXIndexFromSrcCoord(right_src_coord); | |
| 548 } | 536 } |
| 549 | 537 |
| 550 // Determine around bottom, such that it is between -1 and num_tiles_y. | 538 // Determine around bottom, such that it is between -1 and num_tiles_y. |
| 551 int bottom_src_coord = center.bottom() - 1; | 539 int bottom_src_coord = center.bottom() - 1; |
| 552 int around_bottom = 0; | 540 int around_bottom = 0; |
| 553 if (bottom_src_coord < 0 || center.IsEmpty()) { | 541 if (bottom_src_coord < 0 || center.IsEmpty()) { |
| 554 around_bottom = -1; | 542 around_bottom = -1; |
| 555 } else if (bottom_src_coord > tiling_data->tiling_size().height()) { | 543 } else if (bottom_src_coord > tiling_data->tiling_size().height()) { |
| 556 around_bottom = tiling_data->num_tiles_y(); | 544 around_bottom = tiling_data->num_tiles_y(); |
| 557 } else { | 545 } else { |
| 558 around_bottom = | 546 around_bottom = tiling_data->TileYIndexFromSrcCoord(bottom_src_coord); |
| 559 tiling_data->LastBorderTileYIndexFromSrcCoord(bottom_src_coord); | |
| 560 } | 547 } |
| 561 | 548 |
| 562 vertical_step_count_ = around_bottom - around_top + 1; | 549 vertical_step_count_ = around_bottom - around_top + 1; |
| 563 horizontal_step_count_ = around_right - around_left + 1; | 550 horizontal_step_count_ = around_right - around_left + 1; |
| 564 current_step_ = horizontal_step_count_ - 1; | 551 current_step_ = horizontal_step_count_ - 1; |
| 565 | 552 |
| 566 index_x_ = around_right; | 553 index_x_ = around_right; |
| 567 index_y_ = around_bottom; | 554 index_y_ = around_bottom; |
| 568 | 555 |
| 569 // The current index is the bottom right of the around rect, which is also | 556 // The current index is the bottom right of the around rect, which is also |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 current_step_ = 0; | 659 current_step_ = 0; |
| 673 direction_ = static_cast<Direction>((direction_ + 1) % 4); | 660 direction_ = static_cast<Direction>((direction_ + 1) % 4); |
| 674 | 661 |
| 675 if (direction_ == RIGHT || direction_ == LEFT) { | 662 if (direction_ == RIGHT || direction_ == LEFT) { |
| 676 ++vertical_step_count_; | 663 ++vertical_step_count_; |
| 677 ++horizontal_step_count_; | 664 ++horizontal_step_count_; |
| 678 } | 665 } |
| 679 } | 666 } |
| 680 | 667 |
| 681 } // namespace cc | 668 } // namespace cc |
| OLD | NEW |