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 "cc/base/util.h" | |
9 #include "ui/gfx/rect.h" | 10 #include "ui/gfx/rect.h" |
10 #include "ui/gfx/vector2d.h" | 11 #include "ui/gfx/vector2d.h" |
11 | 12 |
12 namespace cc { | 13 namespace cc { |
13 | 14 |
14 static int ComputeNumTiles(int max_texture_size, | 15 static int ComputeNumTiles(int max_texture_size, |
15 int total_size, | 16 int total_size, |
16 int border_texels) { | 17 int border_texels) { |
17 if (max_texture_size - 2 * border_texels <= 0) | 18 if (max_texture_size - 2 * border_texels <= 0) |
18 return total_size > 0 && max_texture_size >= total_size ? 1 : 0; | 19 return total_size > 0 && max_texture_size >= total_size ? 1 : 0; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 | 66 |
66 void TilingData::SetBorderTexels(int border_texels) { | 67 void TilingData::SetBorderTexels(int border_texels) { |
67 border_texels_ = border_texels; | 68 border_texels_ = border_texels; |
68 RecomputeNumTiles(); | 69 RecomputeNumTiles(); |
69 } | 70 } |
70 | 71 |
71 std::pair<int, int> TilingData::UnclampedFirstBorderTileIndexFromSrcCoord( | 72 std::pair<int, int> TilingData::UnclampedFirstBorderTileIndexFromSrcCoord( |
72 int x, | 73 int x, |
73 int y) const { | 74 int y) const { |
74 int inner_tile_width = max_texture_size_.width() - 2 * border_texels_; | 75 int inner_tile_width = max_texture_size_.width() - 2 * border_texels_; |
75 int result_x = (x - 2 * border_texels_) / inner_tile_width; | 76 int result_x = |
77 RoundDown(x - 2 * border_texels_, inner_tile_width) / inner_tile_width; | |
enne (OOO)
2014/03/06 02:30:45
Why?
vmpstr
2014/03/07 18:22:23
I moved this to a separate patch. It's a bug in th
| |
76 | 78 |
77 int inner_tile_height = max_texture_size_.height() - 2 * border_texels_; | 79 int inner_tile_height = max_texture_size_.height() - 2 * border_texels_; |
78 int result_y = (y - 2 * border_texels_) / inner_tile_height; | 80 int result_y = |
81 RoundDown(y - 2 * border_texels_, inner_tile_height) / inner_tile_height; | |
79 | 82 |
80 return std::make_pair(result_x, result_y); | 83 return std::make_pair(result_x, result_y); |
81 } | 84 } |
82 | 85 |
83 std::pair<int, int> TilingData::UnclampedLastBorderTileIndexFromSrcCoord( | 86 std::pair<int, int> TilingData::UnclampedLastBorderTileIndexFromSrcCoord( |
84 int x, | 87 int x, |
85 int y) const { | 88 int y) const { |
86 int inner_tile_width = max_texture_size_.width() - 2 * border_texels_; | 89 int inner_tile_width = max_texture_size_.width() - 2 * border_texels_; |
87 int result_x = x / inner_tile_width; | 90 int result_x = RoundDown(x, inner_tile_width) / inner_tile_width; |
88 | 91 |
89 int inner_tile_height = max_texture_size_.height() - 2 * border_texels_; | 92 int inner_tile_height = max_texture_size_.height() - 2 * border_texels_; |
90 int result_y = y / inner_tile_height; | 93 int result_y = RoundDown(y, inner_tile_height) / inner_tile_height; |
91 | 94 |
92 return std::make_pair(result_x, result_y); | 95 return std::make_pair(result_x, result_y); |
93 } | 96 } |
94 | 97 |
95 int TilingData::TileXIndexFromSrcCoord(int src_position) const { | 98 int TilingData::TileXIndexFromSrcCoord(int src_position) const { |
96 if (num_tiles_x_ <= 1) | 99 if (num_tiles_x_ <= 1) |
97 return 0; | 100 return 0; |
98 | 101 |
99 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0); | 102 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0); |
100 int x = (src_position - border_texels_) / | 103 int x = (src_position - border_texels_) / |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 num_tiles_y_ = ComputeNumTiles( | 292 num_tiles_y_ = ComputeNumTiles( |
290 max_texture_size_.height(), total_size_.height(), border_texels_); | 293 max_texture_size_.height(), total_size_.height(), border_texels_); |
291 } | 294 } |
292 | 295 |
293 TilingData::BaseIterator::BaseIterator(const TilingData* tiling_data) | 296 TilingData::BaseIterator::BaseIterator(const TilingData* tiling_data) |
294 : tiling_data_(tiling_data), | 297 : tiling_data_(tiling_data), |
295 index_x_(-1), | 298 index_x_(-1), |
296 index_y_(-1) { | 299 index_y_(-1) { |
297 } | 300 } |
298 | 301 |
302 TilingData::Iterator::Iterator() : BaseIterator(NULL) { done(); } | |
303 | |
299 TilingData::Iterator::Iterator(const TilingData* tiling_data, | 304 TilingData::Iterator::Iterator(const TilingData* tiling_data, |
300 const gfx::Rect& tiling_rect) | 305 const gfx::Rect& tiling_rect) |
301 : BaseIterator(tiling_data), | 306 : BaseIterator(tiling_data), |
302 left_(-1), | 307 left_(-1), |
303 right_(-1), | 308 right_(-1), |
304 bottom_(-1) { | 309 bottom_(-1) { |
305 if (tiling_data_->num_tiles_x() <= 0 || tiling_data_->num_tiles_y() <= 0) { | 310 if (tiling_data_->num_tiles_x() <= 0 || tiling_data_->num_tiles_y() <= 0) { |
306 done(); | 311 done(); |
307 return; | 312 return; |
308 } | 313 } |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
426 } | 431 } |
427 } | 432 } |
428 | 433 |
429 if (index_y_ > consider_bottom_) | 434 if (index_y_ > consider_bottom_) |
430 done(); | 435 done(); |
431 } | 436 } |
432 | 437 |
433 return *this; | 438 return *this; |
434 } | 439 } |
435 | 440 |
441 TilingData::SpiralDifferenceIterator::SpiralDifferenceIterator() | |
442 : BaseIterator(NULL) { | |
443 done(); | |
444 } | |
445 | |
436 TilingData::SpiralDifferenceIterator::SpiralDifferenceIterator( | 446 TilingData::SpiralDifferenceIterator::SpiralDifferenceIterator( |
437 const TilingData* tiling_data, | 447 const TilingData* tiling_data, |
438 const gfx::Rect& consider_rect, | 448 const gfx::Rect& consider_rect, |
439 const gfx::Rect& ignore_rect, | 449 const gfx::Rect& ignore_rect, |
440 const gfx::Rect& center_rect) | 450 const gfx::Rect& center_rect) |
441 : BaseIterator(tiling_data), | 451 : BaseIterator(tiling_data), |
442 consider_left_(-1), | 452 consider_left_(-1), |
443 consider_top_(-1), | 453 consider_top_(-1), |
444 consider_right_(-1), | 454 consider_right_(-1), |
445 consider_bottom_(-1), | 455 consider_bottom_(-1), |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
632 current_step_ = 0; | 642 current_step_ = 0; |
633 direction_ = static_cast<Direction>((direction_ + 1) % 4); | 643 direction_ = static_cast<Direction>((direction_ + 1) % 4); |
634 | 644 |
635 if (direction_ == RIGHT || direction_ == LEFT) { | 645 if (direction_ == RIGHT || direction_ == LEFT) { |
636 ++vertical_step_count_; | 646 ++vertical_step_count_; |
637 ++horizontal_step_count_; | 647 ++horizontal_step_count_; |
638 } | 648 } |
639 } | 649 } |
640 | 650 |
641 } // namespace cc | 651 } // namespace cc |
OLD | NEW |