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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 132 |
133 src_position -= tiling_rect_.y(); | 133 src_position -= tiling_rect_.y(); |
134 | 134 |
135 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0); | 135 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0); |
136 int inner_tile_size = max_texture_size_.height() - 2 * border_texels_; | 136 int inner_tile_size = max_texture_size_.height() - 2 * border_texels_; |
137 int y = src_position / inner_tile_size; | 137 int y = src_position / inner_tile_size; |
138 return std::min(std::max(y, 0), num_tiles_y_ - 1); | 138 return std::min(std::max(y, 0), num_tiles_y_ - 1); |
139 } | 139 } |
140 | 140 |
141 gfx::Rect TilingData::ExpandRectToTileBoundsWithBorders( | 141 gfx::Rect TilingData::ExpandRectToTileBoundsWithBorders( |
142 const gfx::Rect rect) const { | 142 const gfx::Rect& rect) const { |
143 if (!rect.Intersects(tiling_rect_) || has_empty_bounds()) | 143 if (!rect.Intersects(tiling_rect_) || has_empty_bounds()) |
144 return gfx::Rect(); | 144 return gfx::Rect(); |
145 int index_x = FirstBorderTileXIndexFromSrcCoord(rect.x()); | 145 int index_x = FirstBorderTileXIndexFromSrcCoord(rect.x()); |
146 int index_y = FirstBorderTileYIndexFromSrcCoord(rect.y()); | 146 int index_y = FirstBorderTileYIndexFromSrcCoord(rect.y()); |
147 int index_right = LastBorderTileXIndexFromSrcCoord(rect.right()); | 147 int index_right = LastBorderTileXIndexFromSrcCoord(rect.right() - 1); |
148 int index_bottom = LastBorderTileYIndexFromSrcCoord(rect.bottom()); | 148 int index_bottom = LastBorderTileYIndexFromSrcCoord(rect.bottom() - 1); |
149 | 149 |
150 gfx::Rect rect_top_left(TileBoundsWithBorder(index_x, index_y)); | 150 gfx::Rect rect_top_left(TileBoundsWithBorder(index_x, index_y)); |
151 gfx::Rect rect_bottom_right(TileBoundsWithBorder(index_right, index_bottom)); | 151 gfx::Rect rect_bottom_right(TileBoundsWithBorder(index_right, index_bottom)); |
152 | 152 |
153 gfx::Rect expanded(rect_top_left); | 153 return gfx::UnionRects(rect_top_left, rect_bottom_right); |
154 expanded.Union(rect_bottom_right); | 154 } |
155 return expanded; | 155 |
| 156 gfx::Rect TilingData::ExpandRectToTileBounds(const gfx::Rect& rect) const { |
| 157 if (!rect.Intersects(tiling_rect_) || has_empty_bounds()) |
| 158 return gfx::Rect(); |
| 159 int index_x = FirstBorderTileXIndexFromSrcCoord(rect.x()); |
| 160 int index_y = FirstBorderTileYIndexFromSrcCoord(rect.y()); |
| 161 int index_right = LastBorderTileXIndexFromSrcCoord(rect.right() - 1); |
| 162 int index_bottom = LastBorderTileYIndexFromSrcCoord(rect.bottom() - 1); |
| 163 |
| 164 gfx::Rect rect_top_left(TileBounds(index_x, index_y)); |
| 165 gfx::Rect rect_bottom_right(TileBounds(index_right, index_bottom)); |
| 166 |
| 167 return gfx::UnionRects(rect_top_left, rect_bottom_right); |
156 } | 168 } |
157 | 169 |
158 gfx::Rect TilingData::TileBounds(int i, int j) const { | 170 gfx::Rect TilingData::TileBounds(int i, int j) const { |
159 AssertTile(i, j); | 171 AssertTile(i, j); |
160 int max_texture_size_x = max_texture_size_.width() - 2 * border_texels_; | 172 int max_texture_size_x = max_texture_size_.width() - 2 * border_texels_; |
161 int max_texture_size_y = max_texture_size_.height() - 2 * border_texels_; | 173 int max_texture_size_y = max_texture_size_.height() - 2 * border_texels_; |
162 | 174 |
163 int lo_x = tiling_rect_.x() + max_texture_size_x * i; | 175 int lo_x = tiling_rect_.x() + max_texture_size_x * i; |
164 if (i != 0) | 176 if (i != 0) |
165 lo_x += border_texels_; | 177 lo_x += border_texels_; |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 current_step_ = 0; | 681 current_step_ = 0; |
670 direction_ = static_cast<Direction>((direction_ + 1) % 4); | 682 direction_ = static_cast<Direction>((direction_ + 1) % 4); |
671 | 683 |
672 if (direction_ == RIGHT || direction_ == LEFT) { | 684 if (direction_ == RIGHT || direction_ == LEFT) { |
673 ++vertical_step_count_; | 685 ++vertical_step_count_; |
674 ++horizontal_step_count_; | 686 ++horizontal_step_count_; |
675 } | 687 } |
676 } | 688 } |
677 | 689 |
678 } // namespace cc | 690 } // namespace cc |
OLD | NEW |