| 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/geometry/rect.h" | 9 #include "ui/gfx/geometry/rect.h" |
| 10 #include "ui/gfx/geometry/vector2d.h" | 10 #include "ui/gfx/geometry/vector2d.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 116 } |
| 117 | 117 |
| 118 int TilingData::LastBorderTileYIndexFromSrcCoord(int src_position) const { | 118 int TilingData::LastBorderTileYIndexFromSrcCoord(int src_position) const { |
| 119 if (num_tiles_y_ <= 1) | 119 if (num_tiles_y_ <= 1) |
| 120 return 0; | 120 return 0; |
| 121 | 121 |
| 122 int y = src_position / borderless_max_texture_size_.height(); | 122 int y = src_position / borderless_max_texture_size_.height(); |
| 123 return std::min(std::max(y, 0), num_tiles_y_ - 1); | 123 return std::min(std::max(y, 0), num_tiles_y_ - 1); |
| 124 } | 124 } |
| 125 | 125 |
| 126 int TilingData::TileRealXIndexFromSrcCoord(int src_position) const { |
| 127 if (src_position < 0) |
| 128 src_position -= borderless_max_texture_size_.width(); |
| 129 |
| 130 return (src_position - border_texels_) / borderless_max_texture_size_.width(); |
| 131 } |
| 132 |
| 133 int TilingData::TileRealYIndexFromSrcCoord(int src_position) const { |
| 134 if (src_position < 0) |
| 135 src_position -= borderless_max_texture_size_.height(); |
| 136 |
| 137 return (src_position - border_texels_) / |
| 138 borderless_max_texture_size_.height(); |
| 139 } |
| 140 |
| 126 gfx::Rect TilingData::ExpandRectIgnoringBordersToTileBounds( | 141 gfx::Rect TilingData::ExpandRectIgnoringBordersToTileBounds( |
| 127 const gfx::Rect& rect) const { | 142 const gfx::Rect& rect) const { |
| 128 if (rect.IsEmpty() || has_empty_bounds()) | 143 if (rect.IsEmpty() || has_empty_bounds()) |
| 129 return gfx::Rect(); | 144 return gfx::Rect(); |
| 130 if (rect.x() > tiling_size_.width() || rect.y() > tiling_size_.height()) | 145 if (rect.x() > tiling_size_.width() || rect.y() > tiling_size_.height()) |
| 131 return gfx::Rect(); | 146 return gfx::Rect(); |
| 132 int index_x = TileXIndexFromSrcCoord(rect.x()); | 147 int index_x = TileXIndexFromSrcCoord(rect.x()); |
| 133 int index_y = TileYIndexFromSrcCoord(rect.y()); | 148 int index_y = TileYIndexFromSrcCoord(rect.y()); |
| 134 int index_right = TileXIndexFromSrcCoord(rect.right() - 1); | 149 int index_right = TileXIndexFromSrcCoord(rect.right() - 1); |
| 135 int index_bottom = TileYIndexFromSrcCoord(rect.bottom() - 1); | 150 int index_bottom = TileYIndexFromSrcCoord(rect.bottom() - 1); |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 | 484 |
| 470 TilingData::SpiralDifferenceIterator::SpiralDifferenceIterator() { | 485 TilingData::SpiralDifferenceIterator::SpiralDifferenceIterator() { |
| 471 done(); | 486 done(); |
| 472 } | 487 } |
| 473 | 488 |
| 474 TilingData::SpiralDifferenceIterator::SpiralDifferenceIterator( | 489 TilingData::SpiralDifferenceIterator::SpiralDifferenceIterator( |
| 475 const TilingData* tiling_data, | 490 const TilingData* tiling_data, |
| 476 const gfx::Rect& consider_rect, | 491 const gfx::Rect& consider_rect, |
| 477 const gfx::Rect& ignore_rect, | 492 const gfx::Rect& ignore_rect, |
| 478 const gfx::Rect& center_rect) | 493 const gfx::Rect& center_rect) |
| 479 : BaseDifferenceIterator(tiling_data, consider_rect, ignore_rect), | 494 : BaseDifferenceIterator(tiling_data, consider_rect, ignore_rect) { |
| 480 direction_(RIGHT), | |
| 481 delta_x_(1), | |
| 482 delta_y_(0), | |
| 483 current_step_(0), | |
| 484 horizontal_step_count_(0), | |
| 485 vertical_step_count_(0) { | |
| 486 if (!HasConsiderRect()) { | 495 if (!HasConsiderRect()) { |
| 487 done(); | 496 done(); |
| 488 return; | 497 return; |
| 489 } | 498 } |
| 490 | 499 |
| 491 // Determine around left, such that it is between -1 and num_tiles_x. | 500 if (tiling_data->max_texture_size().IsEmpty()) { |
| 492 int around_left = 0; | 501 done(); |
| 493 if (center_rect.x() < 0 || center_rect.IsEmpty()) | 502 return; |
| 494 around_left = -1; | |
| 495 else if (center_rect.x() >= tiling_data->tiling_size().width()) | |
| 496 around_left = tiling_data->num_tiles_x(); | |
| 497 else | |
| 498 around_left = tiling_data->TileXIndexFromSrcCoord(center_rect.x()); | |
| 499 | |
| 500 // Determine around top, such that it is between -1 and num_tiles_y. | |
| 501 int around_top = 0; | |
| 502 if (center_rect.y() < 0 || center_rect.IsEmpty()) | |
| 503 around_top = -1; | |
| 504 else if (center_rect.y() >= tiling_data->tiling_size().height()) | |
| 505 around_top = tiling_data->num_tiles_y(); | |
| 506 else | |
| 507 around_top = tiling_data->TileYIndexFromSrcCoord(center_rect.y()); | |
| 508 | |
| 509 // Determine around right, such that it is between -1 and num_tiles_x. | |
| 510 int right_src_coord = center_rect.right() - 1; | |
| 511 int around_right = 0; | |
| 512 if (right_src_coord < 0 || center_rect.IsEmpty()) { | |
| 513 around_right = -1; | |
| 514 } else if (right_src_coord >= tiling_data->tiling_size().width()) { | |
| 515 around_right = tiling_data->num_tiles_x(); | |
| 516 } else { | |
| 517 around_right = tiling_data->TileXIndexFromSrcCoord(right_src_coord); | |
| 518 } | 503 } |
| 519 | 504 |
| 520 // Determine around bottom, such that it is between -1 and num_tiles_y. | 505 // Default around rect is assumed to be at top-left corner of top-left |
| 521 int bottom_src_coord = center_rect.bottom() - 1; | 506 // tile index. |
| 507 int around_left = -2; |
| 508 int around_top = -2; |
| 509 int around_right = 0; |
| 522 int around_bottom = 0; | 510 int around_bottom = 0; |
| 523 if (bottom_src_coord < 0 || center_rect.IsEmpty()) { | 511 |
| 524 around_bottom = -1; | 512 if (!center_rect.IsEmpty()) { |
| 525 } else if (bottom_src_coord >= tiling_data->tiling_size().height()) { | 513 around_left = tiling_data->TileRealXIndexFromSrcCoord(center_rect.x()) - 1; |
| 526 around_bottom = tiling_data->num_tiles_y(); | 514 around_top = tiling_data->TileRealYIndexFromSrcCoord(center_rect.y()) - 1; |
| 527 } else { | 515 int right_src_coord = center_rect.right() - 1; |
| 528 around_bottom = tiling_data->TileYIndexFromSrcCoord(bottom_src_coord); | 516 around_right = tiling_data->TileRealXIndexFromSrcCoord(right_src_coord) + 1; |
| 517 int bottom_src_coord = center_rect.bottom() - 1; |
| 518 around_bottom = |
| 519 tiling_data->TileRealYIndexFromSrcCoord(bottom_src_coord) + 1; |
| 529 } | 520 } |
| 530 | 521 |
| 531 vertical_step_count_ = around_bottom - around_top + 1; | 522 pyramid_sequence_.Init(around_left, around_right, around_top, around_bottom, |
| 532 horizontal_step_count_ = around_right - around_left + 1; | 523 consider_left_, consider_right_, consider_top_, |
| 533 current_step_ = horizontal_step_count_ - 1; | 524 consider_bottom_, ignore_left_, ignore_right_, |
| 525 ignore_top_, ignore_bottom_, |
| 526 tiling_data->max_texture_size().width(), |
| 527 tiling_data->max_texture_size().height()); |
| 534 | 528 |
| 535 index_x_ = around_right; | 529 if (pyramid_sequence_.IsTraversed()) { |
| 536 index_y_ = around_bottom; | 530 done(); |
| 531 return; |
| 532 } |
| 537 | 533 |
| 538 // The current index is the bottom right of the around rect, which is also | 534 index_x_ = pyramid_sequence_.GetCurrentIndexX(); |
| 539 // ignored. So we have to advance. | 535 index_y_ = pyramid_sequence_.GetCurrentIndexY(); |
| 540 ++(*this); | 536 DCHECK(in_consider_rect() && !in_ignore_rect()); |
| 541 } | 537 } |
| 542 | 538 |
| 539 TilingData::SpiralDifferenceIterator::~SpiralDifferenceIterator() {} |
| 540 |
| 541 TilingData::SpiralDifferenceIterator::SpiralDifferenceIterator( |
| 542 const TilingData::SpiralDifferenceIterator& other) = default; |
| 543 |
| 544 TilingData::SpiralDifferenceIterator::SpiralDifferenceIterator( |
| 545 TilingData::SpiralDifferenceIterator&& other) = default; |
| 546 |
| 547 TilingData::SpiralDifferenceIterator& TilingData::SpiralDifferenceIterator:: |
| 548 operator=(const TilingData::SpiralDifferenceIterator& other) = default; |
| 549 |
| 550 TilingData::SpiralDifferenceIterator& TilingData::SpiralDifferenceIterator:: |
| 551 operator=(TilingData::SpiralDifferenceIterator&& other) = default; |
| 552 |
| 543 TilingData::SpiralDifferenceIterator& TilingData::SpiralDifferenceIterator:: | 553 TilingData::SpiralDifferenceIterator& TilingData::SpiralDifferenceIterator:: |
| 544 operator++() { | 554 operator++() { |
| 545 int cannot_hit_consider_count = 0; | 555 pyramid_sequence_.Advance(); |
| 546 while (cannot_hit_consider_count < 4) { | 556 pyramid_sequence_.UpdateCurrent(); |
| 547 if (needs_direction_switch()) | |
| 548 switch_direction(); | |
| 549 | 557 |
| 550 index_x_ += delta_x_; | 558 if (pyramid_sequence_.IsTraversed()) { |
| 551 index_y_ += delta_y_; | 559 done(); |
| 552 ++current_step_; | 560 return *this; |
| 553 | |
| 554 if (in_consider_rect()) { | |
| 555 cannot_hit_consider_count = 0; | |
| 556 | |
| 557 if (!in_ignore_rect()) | |
| 558 break; | |
| 559 | |
| 560 // Steps needed to reach the very edge of the ignore rect, while remaining | |
| 561 // inside (so that the continue would take us outside). | |
| 562 int steps_to_edge = 0; | |
| 563 switch (direction_) { | |
| 564 case UP: | |
| 565 steps_to_edge = index_y_ - ignore_top_; | |
| 566 break; | |
| 567 case LEFT: | |
| 568 steps_to_edge = index_x_ - ignore_left_; | |
| 569 break; | |
| 570 case DOWN: | |
| 571 steps_to_edge = ignore_bottom_ - index_y_; | |
| 572 break; | |
| 573 case RIGHT: | |
| 574 steps_to_edge = ignore_right_ - index_x_; | |
| 575 break; | |
| 576 } | |
| 577 | |
| 578 // We need to switch directions in |max_steps|. | |
| 579 int max_steps = current_step_count() - current_step_; | |
| 580 | |
| 581 int steps_to_take = std::min(steps_to_edge, max_steps); | |
| 582 DCHECK_GE(steps_to_take, 0); | |
| 583 | |
| 584 index_x_ += steps_to_take * delta_x_; | |
| 585 index_y_ += steps_to_take * delta_y_; | |
| 586 current_step_ += steps_to_take; | |
| 587 } else { | |
| 588 int max_steps = current_step_count() - current_step_; | |
| 589 int steps_to_take = max_steps; | |
| 590 bool can_hit_consider_rect = false; | |
| 591 switch (direction_) { | |
| 592 case UP: | |
| 593 if (valid_column() && consider_bottom_ < index_y_) | |
| 594 steps_to_take = index_y_ - consider_bottom_ - 1; | |
| 595 can_hit_consider_rect |= consider_right_ >= index_x_; | |
| 596 break; | |
| 597 case LEFT: | |
| 598 if (valid_row() && consider_right_ < index_x_) | |
| 599 steps_to_take = index_x_ - consider_right_ - 1; | |
| 600 can_hit_consider_rect |= consider_top_ <= index_y_; | |
| 601 break; | |
| 602 case DOWN: | |
| 603 if (valid_column() && consider_top_ > index_y_) | |
| 604 steps_to_take = consider_top_ - index_y_ - 1; | |
| 605 can_hit_consider_rect |= consider_left_ <= index_x_; | |
| 606 break; | |
| 607 case RIGHT: | |
| 608 if (valid_row() && consider_left_ > index_x_) | |
| 609 steps_to_take = consider_left_ - index_x_ - 1; | |
| 610 can_hit_consider_rect |= consider_bottom_ >= index_y_; | |
| 611 break; | |
| 612 } | |
| 613 steps_to_take = std::min(steps_to_take, max_steps); | |
| 614 DCHECK_GE(steps_to_take, 0); | |
| 615 | |
| 616 index_x_ += steps_to_take * delta_x_; | |
| 617 index_y_ += steps_to_take * delta_y_; | |
| 618 current_step_ += steps_to_take; | |
| 619 | |
| 620 if (can_hit_consider_rect) | |
| 621 cannot_hit_consider_count = 0; | |
| 622 else | |
| 623 ++cannot_hit_consider_count; | |
| 624 } | |
| 625 } | 561 } |
| 626 | 562 |
| 627 if (cannot_hit_consider_count >= 4) | 563 index_x_ = pyramid_sequence_.GetCurrentIndexX(); |
| 628 done(); | 564 index_y_ = pyramid_sequence_.GetCurrentIndexY(); |
| 565 |
| 566 DCHECK(in_consider_rect() && !in_ignore_rect()); |
| 629 return *this; | 567 return *this; |
| 630 } | 568 } |
| 631 | 569 |
| 632 bool TilingData::SpiralDifferenceIterator::needs_direction_switch() const { | |
| 633 return current_step_ >= current_step_count(); | |
| 634 } | |
| 635 | |
| 636 void TilingData::SpiralDifferenceIterator::switch_direction() { | |
| 637 // Note that delta_x_ and delta_y_ always remain between -1 and 1. | |
| 638 int new_delta_x_ = delta_y_; | |
| 639 delta_y_ = -delta_x_; | |
| 640 delta_x_ = new_delta_x_; | |
| 641 | |
| 642 current_step_ = 0; | |
| 643 direction_ = static_cast<Direction>((direction_ + 1) % 4); | |
| 644 | |
| 645 if (direction_ == RIGHT || direction_ == LEFT) { | |
| 646 ++vertical_step_count_; | |
| 647 ++horizontal_step_count_; | |
| 648 } | |
| 649 } | |
| 650 | |
| 651 TilingData::ReverseSpiralDifferenceIterator::ReverseSpiralDifferenceIterator() { | 570 TilingData::ReverseSpiralDifferenceIterator::ReverseSpiralDifferenceIterator() { |
| 652 done(); | 571 done(); |
| 653 } | 572 } |
| 654 | 573 |
| 655 TilingData::ReverseSpiralDifferenceIterator::ReverseSpiralDifferenceIterator( | 574 TilingData::ReverseSpiralDifferenceIterator::ReverseSpiralDifferenceIterator( |
| 656 const TilingData* tiling_data, | 575 const TilingData* tiling_data, |
| 657 const gfx::Rect& consider_rect, | 576 const gfx::Rect& consider_rect, |
| 658 const gfx::Rect& ignore_rect, | 577 const gfx::Rect& ignore_rect, |
| 659 const gfx::Rect& center_rect) | 578 const gfx::Rect& center_rect) |
| 660 : BaseDifferenceIterator(tiling_data, consider_rect, ignore_rect), | 579 : BaseDifferenceIterator(tiling_data, consider_rect, ignore_rect) { |
| 661 around_left_(-1), | |
| 662 around_top_(-1), | |
| 663 around_right_(-1), | |
| 664 around_bottom_(-1), | |
| 665 direction_(LEFT), | |
| 666 delta_x_(-1), | |
| 667 delta_y_(0), | |
| 668 current_step_(0), | |
| 669 horizontal_step_count_(0), | |
| 670 vertical_step_count_(0) { | |
| 671 if (!HasConsiderRect()) { | 580 if (!HasConsiderRect()) { |
| 672 done(); | 581 done(); |
| 673 return; | 582 return; |
| 674 } | 583 } |
| 675 | 584 |
| 676 // Determine around left, such that it is between -1 and num_tiles_x. | 585 if (tiling_data->max_texture_size().IsEmpty()) { |
| 677 if (center_rect.x() < 0 || center_rect.IsEmpty()) | 586 done(); |
| 678 around_left_ = -1; | 587 return; |
| 679 else if (center_rect.x() >= tiling_data->tiling_size().width()) | |
| 680 around_left_ = tiling_data->num_tiles_x(); | |
| 681 else | |
| 682 around_left_ = tiling_data->TileXIndexFromSrcCoord(center_rect.x()); | |
| 683 | |
| 684 // Determine around top, such that it is between -1 and num_tiles_y. | |
| 685 if (center_rect.y() < 0 || center_rect.IsEmpty()) | |
| 686 around_top_ = -1; | |
| 687 else if (center_rect.y() >= tiling_data->tiling_size().height()) | |
| 688 around_top_ = tiling_data->num_tiles_y(); | |
| 689 else | |
| 690 around_top_ = tiling_data->TileYIndexFromSrcCoord(center_rect.y()); | |
| 691 | |
| 692 // Determine around right, such that it is between -1 and num_tiles_x. | |
| 693 int right_src_coord = center_rect.right() - 1; | |
| 694 if (right_src_coord < 0 || center_rect.IsEmpty()) { | |
| 695 around_right_ = -1; | |
| 696 } else if (right_src_coord >= tiling_data->tiling_size().width()) { | |
| 697 around_right_ = tiling_data->num_tiles_x(); | |
| 698 } else { | |
| 699 around_right_ = tiling_data->TileXIndexFromSrcCoord(right_src_coord); | |
| 700 } | 588 } |
| 701 | 589 |
| 702 // Determine around bottom, such that it is between -1 and num_tiles_y. | 590 // Default around rect is assumed to be at top-left corner of top-left |
| 703 int bottom_src_coord = center_rect.bottom() - 1; | 591 // tile index. |
| 704 if (bottom_src_coord < 0 || center_rect.IsEmpty()) { | 592 int around_left = -2; |
| 705 around_bottom_ = -1; | 593 int around_top = -2; |
| 706 } else if (bottom_src_coord >= tiling_data->tiling_size().height()) { | 594 int around_right = 0; |
| 707 around_bottom_ = tiling_data->num_tiles_y(); | 595 int around_bottom = 0; |
| 708 } else { | 596 |
| 709 around_bottom_ = tiling_data->TileYIndexFromSrcCoord(bottom_src_coord); | 597 // TODO(prashant.n): Implement IndexRect for encapsulating indices. Implement |
| 598 // function in TilingData for getting IndexRect from the given Rect object. |
| 599 // crbug.com/624792 |
| 600 if (!center_rect.IsEmpty()) { |
| 601 around_left = tiling_data->TileRealXIndexFromSrcCoord(center_rect.x()) - 1; |
| 602 around_top = tiling_data->TileRealYIndexFromSrcCoord(center_rect.y()) - 1; |
| 603 int right_src_coord = center_rect.right() - 1; |
| 604 around_right = tiling_data->TileRealXIndexFromSrcCoord(right_src_coord) + 1; |
| 605 int bottom_src_coord = center_rect.bottom() - 1; |
| 606 around_bottom = |
| 607 tiling_data->TileRealYIndexFromSrcCoord(bottom_src_coord) + 1; |
| 710 } | 608 } |
| 711 | 609 |
| 712 // Figure out the maximum distance from the around edge to consider edge. | 610 pyramid_sequence_.Init(around_left, around_right, around_top, around_bottom, |
| 713 int max_distance = 0; | 611 consider_left_, consider_right_, consider_top_, |
| 714 max_distance = std::max(max_distance, around_top_ - consider_top_); | 612 consider_bottom_, ignore_left_, ignore_right_, |
| 715 max_distance = std::max(max_distance, around_left_ - consider_left_); | 613 ignore_top_, ignore_bottom_, |
| 716 max_distance = std::max(max_distance, consider_bottom_ - around_bottom_); | 614 tiling_data->max_texture_size().width(), |
| 717 max_distance = std::max(max_distance, consider_right_ - around_right_); | 615 tiling_data->max_texture_size().height()); |
| 718 | 616 |
| 719 // The step count is the length of the edge (around_right_ - around_left_ + 1) | 617 if (pyramid_sequence_.IsTraversed()) { |
| 720 // plus twice the max distance to pad (to the right and to the left). This way | 618 done(); |
| 721 // the initial rect is the size proportional to the center, but big enough | 619 return; |
| 722 // to cover the consider rect. | 620 } |
| 723 // | |
| 724 // C = consider rect | |
| 725 // A = around rect | |
| 726 // . = area of the padded around rect | |
| 727 // md = max distance (note in the picture below, there's md written vertically | |
| 728 // as well). | |
| 729 // I = initial starting position | |
| 730 // | |
| 731 // |md| |md| | |
| 732 // | |
| 733 // - .......... | |
| 734 // m .......... | |
| 735 // d .......... | |
| 736 // - CCCCCCC... | |
| 737 // CCCCAAC... | |
| 738 // CCCCAAC... | |
| 739 // - .......... | |
| 740 // m .......... | |
| 741 // d .......... | |
| 742 // - ..........I | |
| 743 vertical_step_count_ = around_bottom_ - around_top_ + 1 + 2 * max_distance; | |
| 744 horizontal_step_count_ = around_right_ - around_left_ + 1 + 2 * max_distance; | |
| 745 | 621 |
| 746 // Start with one to the right of the padded around rect. | 622 index_x_ = pyramid_sequence_.GetCurrentIndexX(); |
| 747 index_x_ = around_right_ + max_distance + 1; | 623 index_y_ = pyramid_sequence_.GetCurrentIndexY(); |
| 748 index_y_ = around_bottom_ + max_distance; | 624 DCHECK(in_consider_rect() && !in_ignore_rect()); |
| 749 | |
| 750 // The current index is outside a valid tile, so advance immediately. | |
| 751 ++(*this); | |
| 752 } | 625 } |
| 753 | 626 |
| 627 TilingData::ReverseSpiralDifferenceIterator:: |
| 628 ~ReverseSpiralDifferenceIterator() {} |
| 629 |
| 630 TilingData::ReverseSpiralDifferenceIterator::ReverseSpiralDifferenceIterator( |
| 631 const TilingData::ReverseSpiralDifferenceIterator& other) = default; |
| 632 |
| 633 TilingData::ReverseSpiralDifferenceIterator::ReverseSpiralDifferenceIterator( |
| 634 TilingData::ReverseSpiralDifferenceIterator&& other) = default; |
| 635 |
| 754 TilingData::ReverseSpiralDifferenceIterator& | 636 TilingData::ReverseSpiralDifferenceIterator& |
| 755 TilingData::ReverseSpiralDifferenceIterator:: | 637 TilingData::ReverseSpiralDifferenceIterator::operator=( |
| 756 operator++() { | 638 const TilingData::ReverseSpiralDifferenceIterator& other) = default; |
| 757 while (!in_around_rect()) { | |
| 758 if (needs_direction_switch()) | |
| 759 switch_direction(); | |
| 760 | 639 |
| 761 index_x_ += delta_x_; | 640 TilingData::ReverseSpiralDifferenceIterator& |
| 762 index_y_ += delta_y_; | 641 TilingData::ReverseSpiralDifferenceIterator::operator=( |
| 763 ++current_step_; | 642 TilingData::ReverseSpiralDifferenceIterator&& other) = default; |
| 764 | 643 |
| 765 if (in_around_rect()) { | 644 TilingData::ReverseSpiralDifferenceIterator& |
| 766 break; | 645 TilingData::ReverseSpiralDifferenceIterator::operator++() { |
| 767 } else if (in_consider_rect()) { | 646 pyramid_sequence_.Advance(); |
| 768 // If the tile is in the consider rect but not in ignore rect, then it's a | 647 pyramid_sequence_.UpdateCurrent(); |
| 769 // valid tile to visit. | |
| 770 if (!in_ignore_rect()) | |
| 771 break; | |
| 772 | 648 |
| 773 // Steps needed to reach the very edge of the ignore rect, while remaining | 649 if (pyramid_sequence_.IsTraversed()) { |
| 774 // inside it (so that the continue would take us outside). | 650 done(); |
| 775 int steps_to_edge = 0; | 651 return *this; |
| 776 switch (direction_) { | |
| 777 case UP: | |
| 778 steps_to_edge = index_y_ - ignore_top_; | |
| 779 break; | |
| 780 case LEFT: | |
| 781 steps_to_edge = index_x_ - ignore_left_; | |
| 782 break; | |
| 783 case DOWN: | |
| 784 steps_to_edge = ignore_bottom_ - index_y_; | |
| 785 break; | |
| 786 case RIGHT: | |
| 787 steps_to_edge = ignore_right_ - index_x_; | |
| 788 break; | |
| 789 } | |
| 790 | |
| 791 // We need to switch directions in |max_steps|. | |
| 792 int max_steps = current_step_count() - current_step_; | |
| 793 | |
| 794 int steps_to_take = std::min(steps_to_edge, max_steps); | |
| 795 DCHECK_GE(steps_to_take, 0); | |
| 796 | |
| 797 index_x_ += steps_to_take * delta_x_; | |
| 798 index_y_ += steps_to_take * delta_y_; | |
| 799 current_step_ += steps_to_take; | |
| 800 } else { | |
| 801 // We're not in the consider rect. | |
| 802 | |
| 803 int max_steps = current_step_count() - current_step_; | |
| 804 int steps_to_take = max_steps; | |
| 805 | |
| 806 // We might hit the consider rect before needing to switch directions: | |
| 807 // update steps to take. | |
| 808 switch (direction_) { | |
| 809 case UP: | |
| 810 if (valid_column() && consider_bottom_ < index_y_) | |
| 811 steps_to_take = index_y_ - consider_bottom_ - 1; | |
| 812 break; | |
| 813 case LEFT: | |
| 814 if (valid_row() && consider_right_ < index_x_) | |
| 815 steps_to_take = index_x_ - consider_right_ - 1; | |
| 816 break; | |
| 817 case DOWN: | |
| 818 if (valid_column() && consider_top_ > index_y_) | |
| 819 steps_to_take = consider_top_ - index_y_ - 1; | |
| 820 break; | |
| 821 case RIGHT: | |
| 822 if (valid_row() && consider_left_ > index_x_) | |
| 823 steps_to_take = consider_left_ - index_x_ - 1; | |
| 824 break; | |
| 825 } | |
| 826 steps_to_take = std::min(steps_to_take, max_steps); | |
| 827 DCHECK_GE(steps_to_take, 0); | |
| 828 | |
| 829 index_x_ += steps_to_take * delta_x_; | |
| 830 index_y_ += steps_to_take * delta_y_; | |
| 831 current_step_ += steps_to_take; | |
| 832 } | |
| 833 } | 652 } |
| 834 | 653 |
| 835 // Once we enter the around rect, we're done. | 654 index_x_ = pyramid_sequence_.GetCurrentIndexX(); |
| 836 if (in_around_rect()) | 655 index_y_ = pyramid_sequence_.GetCurrentIndexY(); |
| 837 done(); | 656 DCHECK(in_consider_rect() && !in_ignore_rect()); |
| 838 return *this; | 657 return *this; |
| 839 } | 658 } |
| 840 | 659 |
| 841 bool TilingData::ReverseSpiralDifferenceIterator::needs_direction_switch() | |
| 842 const { | |
| 843 return current_step_ >= current_step_count(); | |
| 844 } | |
| 845 | |
| 846 void TilingData::ReverseSpiralDifferenceIterator::switch_direction() { | |
| 847 // Note that delta_x_ and delta_y_ always remain between -1 and 1. | |
| 848 int new_delta_y_ = delta_x_; | |
| 849 delta_x_ = -delta_y_; | |
| 850 delta_y_ = new_delta_y_; | |
| 851 | |
| 852 current_step_ = 0; | |
| 853 direction_ = static_cast<Direction>((direction_ + 1) % 4); | |
| 854 | |
| 855 if (direction_ == UP || direction_ == DOWN) { | |
| 856 --vertical_step_count_; | |
| 857 --horizontal_step_count_; | |
| 858 | |
| 859 // We should always end up in an around rect at some point. | |
| 860 // Since the direction is now vertical, we have to ensure that we will | |
| 861 // advance. | |
| 862 DCHECK_GE(horizontal_step_count_, 1); | |
| 863 DCHECK_GE(vertical_step_count_, 1); | |
| 864 } | |
| 865 } | |
| 866 | |
| 867 } // namespace cc | 660 } // namespace cc |
| OLD | NEW |