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

Unified Diff: cc/base/tiling_data.cc

Issue 2061103002: cc: Move computing borderless max texture size to function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed build break. Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/base/tiling_data.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/base/tiling_data.cc
diff --git a/cc/base/tiling_data.cc b/cc/base/tiling_data.cc
index cf2bb57f64c623a09329ee9eecc257358b3bdd7f..9e34f2c098d760c2bcc5043dd653231c6c9d9d32 100644
--- a/cc/base/tiling_data.cc
+++ b/cc/base/tiling_data.cc
@@ -10,10 +10,9 @@
#include "ui/gfx/geometry/vector2d.h"
namespace cc {
+namespace {
-static int ComputeNumTiles(int max_texture_size,
- int total_size,
- int border_texels) {
+int ComputeNumTiles(int max_texture_size, int total_size, int border_texels) {
if (max_texture_size - 2 * border_texels <= 0)
return total_size > 0 && max_texture_size >= total_size ? 1 : 0;
@@ -23,6 +22,8 @@ static int ComputeNumTiles(int max_texture_size,
return total_size > 0 ? num_tiles : 0;
}
+} // namespace
+
TilingData::TilingData()
: border_texels_(0) {
RecomputeNumTiles();
@@ -46,6 +47,10 @@ TilingData::TilingData(const gfx::Size& max_texture_size,
RecomputeNumTiles();
}
+TilingData::TilingData(const TilingData& other) = default;
+
+TilingData::~TilingData() = default;
+
void TilingData::SetTilingSize(const gfx::Size& tiling_size) {
tiling_size_ = tiling_size;
RecomputeNumTiles();
@@ -70,9 +75,8 @@ int TilingData::TileXIndexFromSrcCoord(int src_position) const {
if (num_tiles_x_ <= 1)
return 0;
- DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0);
- int x = (src_position - border_texels_) /
- (max_texture_size_.width() - 2 * border_texels_);
+ int x =
+ (src_position - border_texels_) / borderless_max_texture_size_.width();
return std::min(std::max(x, 0), num_tiles_x_ - 1);
}
@@ -80,9 +84,8 @@ int TilingData::TileYIndexFromSrcCoord(int src_position) const {
if (num_tiles_y_ <= 1)
return 0;
- DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0);
- int y = (src_position - border_texels_) /
- (max_texture_size_.height() - 2 * border_texels_);
+ int y =
+ (src_position - border_texels_) / borderless_max_texture_size_.height();
return std::min(std::max(y, 0), num_tiles_y_ - 1);
}
@@ -90,9 +93,8 @@ int TilingData::FirstBorderTileXIndexFromSrcCoord(int src_position) const {
if (num_tiles_x_ <= 1)
return 0;
- 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;
+ int x = (src_position - 2 * border_texels_) /
+ borderless_max_texture_size_.width();
return std::min(std::max(x, 0), num_tiles_x_ - 1);
}
@@ -100,9 +102,8 @@ int TilingData::FirstBorderTileYIndexFromSrcCoord(int src_position) const {
if (num_tiles_y_ <= 1)
return 0;
- 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;
+ int y = (src_position - 2 * border_texels_) /
+ borderless_max_texture_size_.height();
return std::min(std::max(y, 0), num_tiles_y_ - 1);
}
@@ -110,9 +111,7 @@ int TilingData::LastBorderTileXIndexFromSrcCoord(int src_position) const {
if (num_tiles_x_ <= 1)
return 0;
- 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;
+ int x = src_position / borderless_max_texture_size_.width();
return std::min(std::max(x, 0), num_tiles_x_ - 1);
}
@@ -120,9 +119,7 @@ int TilingData::LastBorderTileYIndexFromSrcCoord(int src_position) const {
if (num_tiles_y_ <= 1)
return 0;
- 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;
+ int y = src_position / borderless_max_texture_size_.height();
return std::min(std::max(y, 0), num_tiles_y_ - 1);
}
@@ -161,22 +158,20 @@ gfx::Rect TilingData::ExpandRectToTileBounds(const gfx::Rect& rect) const {
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 lo_x = max_texture_size_x * i;
+ int lo_x = borderless_max_texture_size_.width() * i;
if (i != 0)
lo_x += border_texels_;
- int lo_y = max_texture_size_y * j;
+ int lo_y = borderless_max_texture_size_.height() * j;
if (j != 0)
lo_y += border_texels_;
- int hi_x = max_texture_size_x * (i + 1) + border_texels_;
+ int hi_x = borderless_max_texture_size_.width() * (i + 1) + border_texels_;
if (i + 1 == num_tiles_x_)
hi_x += border_texels_;
- int hi_y = max_texture_size_y * (j + 1) + border_texels_;
+ int hi_y = borderless_max_texture_size_.height() * (j + 1) + border_texels_;
if (j + 1 == num_tiles_y_)
hi_y += border_texels_;
@@ -198,14 +193,12 @@ gfx::Rect TilingData::TileBounds(int i, int j) const {
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 lo_x = max_texture_size_x * i;
- int lo_y = max_texture_size_y * j;
+ int lo_x = borderless_max_texture_size_.width() * i;
+ int lo_y = borderless_max_texture_size_.height() * j;
- int hi_x = lo_x + max_texture_size_x + 2 * border_texels_;
- int hi_y = lo_y + max_texture_size_y + 2 * border_texels_;
+ int hi_x = lo_x + borderless_max_texture_size_.width() + 2 * border_texels_;
+ int hi_y = lo_y + borderless_max_texture_size_.height() + 2 * border_texels_;
hi_x = std::min(hi_x, tiling_size_.width());
hi_y = std::min(hi_y, tiling_size_.height());
@@ -227,7 +220,7 @@ int TilingData::TilePositionX(int x_index) const {
DCHECK_GE(x_index, 0);
DCHECK_LT(x_index, num_tiles_x_);
- int pos = (max_texture_size_.width() - 2 * border_texels_) * x_index;
+ int pos = (borderless_max_texture_size_.width()) * x_index;
if (x_index != 0)
pos += border_texels_;
@@ -238,7 +231,7 @@ int TilingData::TilePositionY(int y_index) const {
DCHECK_GE(y_index, 0);
DCHECK_LT(y_index, num_tiles_y_);
- int pos = (max_texture_size_.height() - 2 * border_texels_) * y_index;
+ int pos = (borderless_max_texture_size_.height()) * y_index;
if (y_index != 0)
pos += border_texels_;
@@ -254,7 +247,7 @@ int TilingData::TileSizeX(int x_index) const {
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_;
+ return borderless_max_texture_size_.width();
if (x_index == num_tiles_x_ - 1)
return tiling_size_.width() - TilePositionX(x_index);
@@ -271,7 +264,7 @@ int TilingData::TileSizeY(int y_index) const {
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_;
+ return borderless_max_texture_size_.height();
if (y_index == num_tiles_y_ - 1)
return tiling_size_.height() - TilePositionY(y_index);
@@ -291,6 +284,13 @@ void TilingData::RecomputeNumTiles() {
max_texture_size_.width(), tiling_size_.width(), border_texels_);
num_tiles_y_ = ComputeNumTiles(
max_texture_size_.height(), tiling_size_.height(), border_texels_);
+
+ borderless_max_texture_size_.set_width(max_texture_size_.width() -
+ 2 * border_texels_);
+ borderless_max_texture_size_.set_height(max_texture_size_.height() -
+ 2 * border_texels_);
+ DCHECK_GE(borderless_max_texture_size_.width(), 0);
+ DCHECK_GE(borderless_max_texture_size_.height(), 0);
}
TilingData::BaseIterator::BaseIterator() : index_x_(-1), index_y_(-1) {
« no previous file with comments | « cc/base/tiling_data.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698