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

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

Issue 188863002: cc: Spiral iterator fix for negative center. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 void TilingData::SetHasBorderTexels(bool has_border_texels) { 61 void TilingData::SetHasBorderTexels(bool has_border_texels) {
62 border_texels_ = has_border_texels ? 1 : 0; 62 border_texels_ = has_border_texels ? 1 : 0;
63 RecomputeNumTiles(); 63 RecomputeNumTiles();
64 } 64 }
65 65
66 void TilingData::SetBorderTexels(int border_texels) { 66 void TilingData::SetBorderTexels(int border_texels) {
67 border_texels_ = border_texels; 67 border_texels_ = border_texels;
68 RecomputeNumTiles(); 68 RecomputeNumTiles();
69 } 69 }
70 70
71 std::pair<int, int> TilingData::UnclampedFirstBorderTileIndexFromSrcCoord(
72 int x,
73 int y) const {
74 int inner_tile_width = max_texture_size_.width() - 2 * border_texels_;
75 int result_x = (x - 2 * border_texels_) / inner_tile_width;
76
77 int inner_tile_height = max_texture_size_.height() - 2 * border_texels_;
78 int result_y = (y - 2 * border_texels_) / inner_tile_height;
79
80 return std::make_pair(result_x, result_y);
81 }
82
83 std::pair<int, int> TilingData::UnclampedLastBorderTileIndexFromSrcCoord(
84 int x,
85 int y) const {
86 int inner_tile_width = max_texture_size_.width() - 2 * border_texels_;
87 int result_x = x / inner_tile_width;
88
89 int inner_tile_height = max_texture_size_.height() - 2 * border_texels_;
90 int result_y = y / inner_tile_height;
91
92 return std::make_pair(result_x, result_y);
93 }
94
95 int TilingData::TileXIndexFromSrcCoord(int src_position) const { 71 int TilingData::TileXIndexFromSrcCoord(int src_position) const {
96 if (num_tiles_x_ <= 1) 72 if (num_tiles_x_ <= 1)
97 return 0; 73 return 0;
98 74
99 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0); 75 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0);
100 int x = (src_position - border_texels_) / 76 int x = (src_position - border_texels_) /
101 (max_texture_size_.width() - 2 * border_texels_); 77 (max_texture_size_.width() - 2 * border_texels_);
102 return std::min(std::max(x, 0), num_tiles_x_ - 1); 78 return std::min(std::max(x, 0), num_tiles_x_ - 1);
103 } 79 }
104 80
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 ignore_right_ = std::min(ignore_right_, consider_right_); 467 ignore_right_ = std::min(ignore_right_, consider_right_);
492 ignore_bottom_ = std::min(ignore_bottom_, consider_bottom_); 468 ignore_bottom_ = std::min(ignore_bottom_, consider_bottom_);
493 } 469 }
494 470
495 if (ignore_left_ == consider_left_ && ignore_right_ == consider_right_ && 471 if (ignore_left_ == consider_left_ && ignore_right_ == consider_right_ &&
496 ignore_top_ == consider_top_ && ignore_bottom_ == consider_bottom_) { 472 ignore_top_ == consider_top_ && ignore_bottom_ == consider_bottom_) {
497 done(); 473 done();
498 return; 474 return;
499 } 475 }
500 476
501 std::pair<int, int> around_left_top = 477 // Determine around left, such that it is between -1 and num_tiles_x.
502 tiling_data->UnclampedFirstBorderTileIndexFromSrcCoord(center.x(), 478 int around_left = 0;
503 center.y()); 479 if (center.x() < 0 || center.IsEmpty())
504 std::pair<int, int> around_right_bottom = 480 around_left = -1;
505 tiling_data->UnclampedLastBorderTileIndexFromSrcCoord( 481 else if (center.x() > tiling_data->total_size().width())
506 center.right() - 1, center.bottom() - 1); 482 around_left = tiling_data->num_tiles_x();
483 else
484 around_left = tiling_data->FirstBorderTileXIndexFromSrcCoord(center.x());
507 485
508 if (center.IsEmpty()) { 486 // Determine around top, such that it is between -1 and num_tiles_y.
509 around_left_top = std::make_pair(-1, -1); 487 int around_top = 0;
510 around_right_bottom = std::make_pair(-1, -1); 488 if (center.y() < 0 || center.IsEmpty())
489 around_top = -1;
490 else if (center.y() > tiling_data->total_size().height())
491 around_top = tiling_data->num_tiles_y();
492 else
493 around_top = tiling_data->FirstBorderTileYIndexFromSrcCoord(center.y());
494
495 // Determine around right, such that it is between -1 and num_tiles_x.
496 int right_src_coord = center.right() - 1;
497 int around_right = 0;
498 if (right_src_coord < 0 || center.IsEmpty()) {
499 around_right = -1;
500 } else if (right_src_coord > tiling_data->total_size().width()) {
501 around_right = tiling_data->num_tiles_x();
502 } else {
503 around_right =
504 tiling_data->LastBorderTileXIndexFromSrcCoord(right_src_coord);
511 } 505 }
512 506
513 int around_left = std::max( 507 // Determine around bottom, such that it is between -1 and num_tiles_y.
514 -1, std::min(tiling_data_->num_tiles_x(), around_left_top.first)); 508 int bottom_src_coord = center.bottom() - 1;
515 int around_top = std::max( 509 int around_bottom = 0;
516 -1, std::min(tiling_data_->num_tiles_y(), around_left_top.second)); 510 if (bottom_src_coord < 0 || center.IsEmpty()) {
517 int around_right = std::max( 511 around_bottom = -1;
518 -1, std::min(tiling_data_->num_tiles_x(), around_right_bottom.first)); 512 } else if (bottom_src_coord > tiling_data->total_size().height()) {
519 int around_bottom = std::max( 513 around_bottom = tiling_data->num_tiles_y();
520 -1, std::min(tiling_data_->num_tiles_y(), around_right_bottom.second)); 514 } else {
515 around_bottom =
516 tiling_data->LastBorderTileYIndexFromSrcCoord(bottom_src_coord);
517 }
521 518
522 vertical_step_count_ = around_bottom - around_top + 1; 519 vertical_step_count_ = around_bottom - around_top + 1;
523 horizontal_step_count_ = around_right - around_left + 1; 520 horizontal_step_count_ = around_right - around_left + 1;
524 current_step_ = horizontal_step_count_ - 1; 521 current_step_ = horizontal_step_count_ - 1;
525 522
526 index_x_ = around_right; 523 index_x_ = around_right;
527 index_y_ = around_bottom; 524 index_y_ = around_bottom;
528 525
529 // The current index is the bottom right of the around rect, which is also 526 // The current index is the bottom right of the around rect, which is also
530 // ignored. So we have to advance. 527 // ignored. So we have to advance.
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 current_step_ = 0; 629 current_step_ = 0;
633 direction_ = static_cast<Direction>((direction_ + 1) % 4); 630 direction_ = static_cast<Direction>((direction_ + 1) % 4);
634 631
635 if (direction_ == RIGHT || direction_ == LEFT) { 632 if (direction_ == RIGHT || direction_ == LEFT) {
636 ++vertical_step_count_; 633 ++vertical_step_count_;
637 ++horizontal_step_count_; 634 ++horizontal_step_count_;
638 } 635 }
639 } 636 }
640 637
641 } // namespace cc 638 } // 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