Chromium Code Reviews| Index: cc/base/tiling_data.cc |
| diff --git a/cc/base/tiling_data.cc b/cc/base/tiling_data.cc |
| index 7573ec30574c6953b73ee7170856687e9f802feb..e545f52f052fc805f284809aea4c5a31300ab93c 100644 |
| --- a/cc/base/tiling_data.cc |
| +++ b/cc/base/tiling_data.cc |
| @@ -30,26 +30,26 @@ TilingData::TilingData() |
| TilingData::TilingData( |
| const gfx::Size& max_texture_size, |
| - const gfx::Size& total_size, |
| + const gfx::Rect& tiling_rect, |
| bool has_border_texels) |
| : max_texture_size_(max_texture_size), |
| - total_size_(total_size), |
| + tiling_rect_(tiling_rect), |
| border_texels_(has_border_texels ? 1 : 0) { |
| RecomputeNumTiles(); |
| } |
| TilingData::TilingData( |
| const gfx::Size& max_texture_size, |
| - const gfx::Size& total_size, |
| + const gfx::Rect& tiling_rect, |
| int border_texels) |
| : max_texture_size_(max_texture_size), |
| - total_size_(total_size), |
| + tiling_rect_(tiling_rect), |
| border_texels_(border_texels) { |
| RecomputeNumTiles(); |
| } |
| -void TilingData::SetTotalSize(const gfx::Size& total_size) { |
| - total_size_ = total_size; |
| +void TilingData::SetTilingRect(const gfx::Rect& tiling_rect) { |
| + tiling_rect_ = tiling_rect; |
| RecomputeNumTiles(); |
| } |
| @@ -72,6 +72,8 @@ int TilingData::TileXIndexFromSrcCoord(int src_position) const { |
| if (num_tiles_x_ <= 1) |
| return 0; |
| + src_position -= tiling_rect_.x(); |
| + |
| DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0); |
| int x = (src_position - border_texels_) / |
| (max_texture_size_.width() - 2 * border_texels_); |
| @@ -82,6 +84,8 @@ int TilingData::TileYIndexFromSrcCoord(int src_position) const { |
| if (num_tiles_y_ <= 1) |
| return 0; |
| + src_position -= tiling_rect_.y(); |
| + |
| DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0); |
| int y = (src_position - border_texels_) / |
| (max_texture_size_.height() - 2 * border_texels_); |
| @@ -92,6 +96,8 @@ int TilingData::FirstBorderTileXIndexFromSrcCoord(int src_position) const { |
| if (num_tiles_x_ <= 1) |
| return 0; |
| + src_position -= tiling_rect_.x(); |
| + |
| DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0); |
| int inner_tile_size = max_texture_size_.width() - 2 * border_texels_; |
| int x = (src_position - 2 * border_texels_) / inner_tile_size; |
| @@ -102,6 +108,8 @@ int TilingData::FirstBorderTileYIndexFromSrcCoord(int src_position) const { |
| if (num_tiles_y_ <= 1) |
| return 0; |
| + src_position -= tiling_rect_.y(); |
| + |
| DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0); |
| int inner_tile_size = max_texture_size_.height() - 2 * border_texels_; |
| int y = (src_position - 2 * border_texels_) / inner_tile_size; |
| @@ -112,6 +120,8 @@ int TilingData::LastBorderTileXIndexFromSrcCoord(int src_position) const { |
| if (num_tiles_x_ <= 1) |
| return 0; |
| + src_position -= tiling_rect_.x(); |
| + |
| DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0); |
| int inner_tile_size = max_texture_size_.width() - 2 * border_texels_; |
| int x = src_position / inner_tile_size; |
| @@ -122,6 +132,8 @@ int TilingData::LastBorderTileYIndexFromSrcCoord(int src_position) const { |
| if (num_tiles_y_ <= 1) |
| return 0; |
| + src_position -= tiling_rect_.y(); |
| + |
| DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0); |
| int inner_tile_size = max_texture_size_.height() - 2 * border_texels_; |
| int y = src_position / inner_tile_size; |
| @@ -132,8 +144,6 @@ gfx::Rect TilingData::TileBounds(int i, int j) const { |
| AssertTile(i, j); |
| int max_texture_size_x = max_texture_size_.width() - 2 * border_texels_; |
| int max_texture_size_y = max_texture_size_.height() - 2 * border_texels_; |
| - int total_size_x = total_size_.width(); |
| - int total_size_y = total_size_.height(); |
| int lo_x = max_texture_size_x * i; |
| if (i != 0) |
| @@ -151,8 +161,13 @@ gfx::Rect TilingData::TileBounds(int i, int j) const { |
| if (j + 1 == num_tiles_y_) |
| hi_y += border_texels_; |
| - hi_x = std::min(hi_x, total_size_x); |
| - hi_y = std::min(hi_y, total_size_y); |
| + lo_x += tiling_rect_.x(); |
| + hi_x += tiling_rect_.x(); |
| + lo_y += tiling_rect_.y(); |
| + hi_y += tiling_rect_.y(); |
| + |
| + hi_x = std::min(hi_x, tiling_rect_.right()); |
| + hi_y = std::min(hi_y, tiling_rect_.bottom()); |
| int x = lo_x; |
| int y = lo_y; |
| @@ -162,8 +177,8 @@ gfx::Rect TilingData::TileBounds(int i, int j) const { |
| DCHECK_GE(y, 0); |
| DCHECK_GE(width, 0); |
| DCHECK_GE(height, 0); |
| - DCHECK_LE(x, total_size_.width()); |
| - DCHECK_LE(y, total_size_.height()); |
| + DCHECK_LE(x, tiling_rect_.right()); |
| + DCHECK_LE(y, tiling_rect_.bottom()); |
| return gfx::Rect(x, y, width, height); |
| } |
| @@ -171,8 +186,6 @@ gfx::Rect TilingData::TileBoundsWithBorder(int i, int j) const { |
| AssertTile(i, j); |
| int max_texture_size_x = max_texture_size_.width() - 2 * border_texels_; |
| int max_texture_size_y = max_texture_size_.height() - 2 * border_texels_; |
| - int total_size_x = total_size_.width(); |
| - int total_size_y = total_size_.height(); |
| int lo_x = max_texture_size_x * i; |
| int lo_y = max_texture_size_y * j; |
| @@ -180,8 +193,13 @@ gfx::Rect TilingData::TileBoundsWithBorder(int i, int j) const { |
| int hi_x = lo_x + max_texture_size_x + 2 * border_texels_; |
| int hi_y = lo_y + max_texture_size_y + 2 * border_texels_; |
| - hi_x = std::min(hi_x, total_size_x); |
| - hi_y = std::min(hi_y, total_size_y); |
| + lo_x += tiling_rect_.x(); |
|
enne (OOO)
2014/04/11 20:19:51
microoptimization: You could move the offset after
ernstm
2014/04/11 23:43:51
Done.
|
| + hi_x += tiling_rect_.x(); |
| + lo_y += tiling_rect_.y(); |
| + hi_y += tiling_rect_.y(); |
| + |
| + hi_x = std::min(hi_x, tiling_rect_.right()); |
| + hi_y = std::min(hi_y, tiling_rect_.bottom()); |
| int x = lo_x; |
| int y = lo_y; |
| @@ -191,8 +209,8 @@ gfx::Rect TilingData::TileBoundsWithBorder(int i, int j) const { |
| DCHECK_GE(y, 0); |
| DCHECK_GE(width, 0); |
| DCHECK_GE(height, 0); |
| - DCHECK_LE(x, total_size_.width()); |
| - DCHECK_LE(y, total_size_.height()); |
| + DCHECK_LE(x, tiling_rect_.right()); |
| + DCHECK_LE(y, tiling_rect_.bottom()); |
| return gfx::Rect(x, y, width, height); |
| } |
| @@ -204,6 +222,8 @@ int TilingData::TilePositionX(int x_index) const { |
| if (x_index != 0) |
| pos += border_texels_; |
| + pos += tiling_rect_.x(); |
| + |
| return pos; |
| } |
| @@ -215,6 +235,8 @@ int TilingData::TilePositionY(int y_index) const { |
| if (y_index != 0) |
| pos += border_texels_; |
| + pos += tiling_rect_.y(); |
| + |
| return pos; |
| } |
| @@ -223,13 +245,13 @@ int TilingData::TileSizeX(int x_index) const { |
| DCHECK_LT(x_index, num_tiles_x_); |
| if (!x_index && num_tiles_x_ == 1) |
| - return total_size_.width(); |
| + return tiling_rect_.width(); |
| if (!x_index && num_tiles_x_ > 1) |
| return max_texture_size_.width() - border_texels_; |
| if (x_index < num_tiles_x_ - 1) |
| return max_texture_size_.width() - 2 * border_texels_; |
| if (x_index == num_tiles_x_ - 1) |
| - return total_size_.width() - TilePositionX(x_index); |
| + return tiling_rect_.width() - TilePositionX(x_index); |
| NOTREACHED(); |
| return 0; |
| @@ -240,13 +262,13 @@ int TilingData::TileSizeY(int y_index) const { |
| DCHECK_LT(y_index, num_tiles_y_); |
| if (!y_index && num_tiles_y_ == 1) |
| - return total_size_.height(); |
| + return tiling_rect_.height(); |
| if (!y_index && num_tiles_y_ > 1) |
| return max_texture_size_.height() - border_texels_; |
| if (y_index < num_tiles_y_ - 1) |
| return max_texture_size_.height() - 2 * border_texels_; |
| if (y_index == num_tiles_y_ - 1) |
| - return total_size_.height() - TilePositionY(y_index); |
| + return tiling_rect_.height() - TilePositionY(y_index); |
| NOTREACHED(); |
| return 0; |
| @@ -261,9 +283,9 @@ gfx::Vector2d TilingData::TextureOffset(int x_index, int y_index) const { |
| void TilingData::RecomputeNumTiles() { |
| num_tiles_x_ = ComputeNumTiles( |
| - max_texture_size_.width(), total_size_.width(), border_texels_); |
| + max_texture_size_.width(), tiling_rect_.width(), border_texels_); |
| num_tiles_y_ = ComputeNumTiles( |
| - max_texture_size_.height(), total_size_.height(), border_texels_); |
| + max_texture_size_.height(), tiling_rect_.height(), border_texels_); |
| } |
| TilingData::BaseIterator::BaseIterator(const TilingData* tiling_data) |
| @@ -284,7 +306,7 @@ TilingData::Iterator::Iterator(const TilingData* tiling_data, |
| } |
| gfx::Rect rect(tiling_rect); |
| - rect.Intersect(gfx::Rect(tiling_data_->total_size())); |
| + rect.Intersect(tiling_data_->tiling_rect()); |
| gfx::Rect top_left_tile; |
| if (include_borders) { |
| @@ -341,11 +363,10 @@ TilingData::DifferenceIterator::DifferenceIterator( |
| return; |
| } |
| - gfx::Rect bounds(tiling_data_->total_size()); |
| gfx::Rect consider(consider_rect); |
| gfx::Rect ignore(ignore_rect); |
| - consider.Intersect(bounds); |
| - ignore.Intersect(bounds); |
| + consider.Intersect(tiling_data_->tiling_rect()); |
| + ignore.Intersect(tiling_data_->tiling_rect()); |
| if (consider.IsEmpty()) { |
| done(); |
| return; |
| @@ -449,12 +470,11 @@ TilingData::SpiralDifferenceIterator::SpiralDifferenceIterator( |
| return; |
| } |
| - gfx::Rect bounds(tiling_data_->total_size()); |
| gfx::Rect consider(consider_rect); |
| gfx::Rect ignore(ignore_rect); |
| gfx::Rect center(center_rect); |
| - consider.Intersect(bounds); |
| - ignore.Intersect(bounds); |
| + consider.Intersect(tiling_data_->tiling_rect()); |
| + ignore.Intersect(tiling_data_->tiling_rect()); |
| if (consider.IsEmpty()) { |
| done(); |
| return; |
| @@ -493,7 +513,7 @@ TilingData::SpiralDifferenceIterator::SpiralDifferenceIterator( |
| int around_left = 0; |
| if (center.x() < 0 || center.IsEmpty()) |
| around_left = -1; |
| - else if (center.x() > tiling_data->total_size().width()) |
| + else if (center.x() > tiling_data->tiling_rect().right()) |
| around_left = tiling_data->num_tiles_x(); |
| else |
| around_left = tiling_data->FirstBorderTileXIndexFromSrcCoord(center.x()); |
| @@ -502,7 +522,7 @@ TilingData::SpiralDifferenceIterator::SpiralDifferenceIterator( |
| int around_top = 0; |
| if (center.y() < 0 || center.IsEmpty()) |
| around_top = -1; |
| - else if (center.y() > tiling_data->total_size().height()) |
| + else if (center.y() > tiling_data->tiling_rect().bottom()) |
| around_top = tiling_data->num_tiles_y(); |
| else |
| around_top = tiling_data->FirstBorderTileYIndexFromSrcCoord(center.y()); |
| @@ -512,7 +532,7 @@ TilingData::SpiralDifferenceIterator::SpiralDifferenceIterator( |
| int around_right = 0; |
| if (right_src_coord < 0 || center.IsEmpty()) { |
| around_right = -1; |
| - } else if (right_src_coord > tiling_data->total_size().width()) { |
| + } else if (right_src_coord > tiling_data->tiling_rect().right()) { |
| around_right = tiling_data->num_tiles_x(); |
| } else { |
| around_right = |
| @@ -524,7 +544,7 @@ TilingData::SpiralDifferenceIterator::SpiralDifferenceIterator( |
| int around_bottom = 0; |
| if (bottom_src_coord < 0 || center.IsEmpty()) { |
| around_bottom = -1; |
| - } else if (bottom_src_coord > tiling_data->total_size().height()) { |
| + } else if (bottom_src_coord > tiling_data->tiling_rect().bottom()) { |
| around_bottom = tiling_data->num_tiles_y(); |
| } else { |
| around_bottom = |