summaryrefslogtreecommitdiffstats
path: root/cc
diff options
context:
space:
mode:
authordanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-02 15:37:41 +0000
committerdanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-02 15:37:41 +0000
commit8a03518ab1cf9d715056674230bdb4e4662b4c90 (patch)
tree4e8cec7db90927d65c83f826b62c03b140f3fbb2 /cc
parente5d477340a27793e23258c2a2ed08e3682d37205 (diff)
downloadchromium_src-8a03518ab1cf9d715056674230bdb4e4662b4c90.zip
chromium_src-8a03518ab1cf9d715056674230bdb4e4662b4c90.tar.gz
chromium_src-8a03518ab1cf9d715056674230bdb4e4662b4c90.tar.bz2
Create cc::TilingData based on WebCore::TilingData.
This is a direct port of the TilingData class from the WebKit repo, found in: Source/WebCore/platform/graphics/gpu/TilingData.h|cpp Previous commits from non-google folks have been: - ossy replacing the non-copyable macro (which is not present here). - hyatt replacing right()/bottom() with maxX()/maxY() (we use right()/bottom() again here, with gfx::Rect instead of IntRect). - mitz using ASSERT_UNUSED instead of ASSERT guarded on NDEBUG (we use DCHECK instead here). Covered by existing tests; this replaces the use of WebCore::TilingData with the new cc::TilingData. R=enne BUG=147395 Review URL: https://codereview.chromium.org/11359030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165681 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r--cc/cc.gyp4
-rw-r--r--cc/layer_tiling_data.cc24
-rw-r--r--cc/layer_tiling_data.h18
-rw-r--r--cc/stubs/TilingData.h6
-rw-r--r--cc/stubs/tiling_data.h18
-rw-r--r--cc/tiling_data.cc174
-rw-r--r--cc/tiling_data.h71
7 files changed, 265 insertions, 50 deletions
diff --git a/cc/cc.gyp b/cc/cc.gyp
index 3929a4f..24973eb 100644
--- a/cc/cc.gyp
+++ b/cc/cc.gyp
@@ -213,6 +213,8 @@
'tiled_layer.h',
'tiled_layer_impl.cc',
'tiled_layer_impl.h',
+ 'tiling_data.cc',
+ 'tiling_data.h',
'time_source.h',
'timing_function.cc',
'timing_function.h',
@@ -263,7 +265,6 @@
'stubs/IntSize.h',
'stubs/Region.h',
'stubs/SkiaUtils.h',
- 'stubs/TilingData.h',
'stubs/UnitBezier.h',
'stubs/config.h',
@@ -275,7 +276,6 @@
'stubs/int_rect.h',
'stubs/int_size.h',
'stubs/skia_utils.h',
- 'stubs/tiling_data.h',
'stubs/unit_bezier.h',
],
},
diff --git a/cc/layer_tiling_data.cc b/cc/layer_tiling_data.cc
index 10086da..ccfa205 100644
--- a/cc/layer_tiling_data.cc
+++ b/cc/layer_tiling_data.cc
@@ -7,8 +7,6 @@
#include "cc/layer_tiling_data.h"
-#include "IntRect.h"
-#include "IntSize.h"
#include "base/logging.h"
using namespace std;
@@ -21,7 +19,7 @@ scoped_ptr<LayerTilingData> LayerTilingData::create(const gfx::Size& tileSize, B
}
LayerTilingData::LayerTilingData(const gfx::Size& tileSize, BorderTexelOption border)
- : m_tilingData(cc::IntSize(tileSize), cc::IntSize(), border == HasBorderTexels)
+ : m_tilingData(tileSize, gfx::Size(), border == HasBorderTexels)
{
setTileSize(tileSize);
}
@@ -37,12 +35,12 @@ void LayerTilingData::setTileSize(const gfx::Size& size)
reset();
- m_tilingData.setMaxTextureSize(cc::IntSize(size));
+ m_tilingData.SetMaxTextureSize(size);
}
gfx::Size LayerTilingData::tileSize() const
{
- return cc::IntSize(m_tilingData.maxTextureSize());
+ return m_tilingData.max_texture_size();
}
void LayerTilingData::setBorderTexelOption(BorderTexelOption borderTexelOption)
@@ -52,7 +50,7 @@ void LayerTilingData::setBorderTexelOption(BorderTexelOption borderTexelOption)
return;
reset();
- m_tilingData.setHasBorderTexels(borderTexels);
+ m_tilingData.SetHasBorderTexels(borderTexels);
}
const LayerTilingData& LayerTilingData::operator=(const LayerTilingData& tiler)
@@ -91,15 +89,15 @@ void LayerTilingData::contentRectToTileIndices(const gfx::Rect& contentRect, int
// since the normal use of this function is to enumerate some tiles.
DCHECK(!contentRect.IsEmpty());
- left = m_tilingData.tileXIndexFromSrcCoord(contentRect.x());
- top = m_tilingData.tileYIndexFromSrcCoord(contentRect.y());
- right = m_tilingData.tileXIndexFromSrcCoord(contentRect.right() - 1);
- bottom = m_tilingData.tileYIndexFromSrcCoord(contentRect.bottom() - 1);
+ left = m_tilingData.TileXIndexFromSrcCoord(contentRect.x());
+ top = m_tilingData.TileYIndexFromSrcCoord(contentRect.y());
+ right = m_tilingData.TileXIndexFromSrcCoord(contentRect.right() - 1);
+ bottom = m_tilingData.TileYIndexFromSrcCoord(contentRect.bottom() - 1);
}
gfx::Rect LayerTilingData::tileRect(const Tile* tile) const
{
- gfx::Rect tileRect = cc::IntRect(m_tilingData.tileBoundsWithBorder(tile->i(), tile->j()));
+ gfx::Rect tileRect = m_tilingData.TileBoundsWithBorder(tile->i(), tile->j());
tileRect.set_size(tileSize());
return tileRect;
}
@@ -127,7 +125,7 @@ Region LayerTilingData::opaqueRegionInContentRect(const gfx::Rect& contentRect)
void LayerTilingData::setBounds(const gfx::Size& size)
{
- m_tilingData.setTotalSize(cc::IntSize(size));
+ m_tilingData.SetTotalSize(size);
if (size.IsEmpty()) {
m_tiles.clear();
return;
@@ -147,7 +145,7 @@ void LayerTilingData::setBounds(const gfx::Size& size)
gfx::Size LayerTilingData::bounds() const
{
- return cc::IntSize(m_tilingData.totalSize());
+ return m_tilingData.total_size();
}
} // namespace cc
diff --git a/cc/layer_tiling_data.h b/cc/layer_tiling_data.h
index a464556..5f2e5ea 100644
--- a/cc/layer_tiling_data.h
+++ b/cc/layer_tiling_data.h
@@ -10,12 +10,11 @@
#include "base/memory/scoped_ptr.h"
#include "cc/hash_pair.h"
#include "cc/scoped_ptr_hash_map.h"
+#include "cc/tiling_data.h"
#include "ui/gfx/rect.h"
#include "Region.h"
-#include "TilingData.h"
namespace cc {
-class IntRect;
class LayerTilingData {
public:
@@ -25,21 +24,18 @@ public:
static scoped_ptr<LayerTilingData> create(const gfx::Size& tileSize, BorderTexelOption);
- bool hasEmptyBounds() const { return m_tilingData.hasEmptyBounds(); }
- int numTilesX() const { return m_tilingData.numTilesX(); }
- int numTilesY() const { return m_tilingData.numTilesY(); }
- gfx::Rect tileBounds(int i, int j) const { return cc::IntRect(m_tilingData.tileBounds(i, j)); }
- gfx::Vector2d textureOffset(int xIndex, int yIndex) const {
- cc::IntPoint p(m_tilingData.textureOffset(xIndex, yIndex));
- return gfx::Vector2d(p.x(), p.y());
- }
+ bool hasEmptyBounds() const { return m_tilingData.has_empty_bounds(); }
+ int numTilesX() const { return m_tilingData.num_tiles_x(); }
+ int numTilesY() const { return m_tilingData.num_tiles_y(); }
+ gfx::Rect tileBounds(int i, int j) const { return m_tilingData.TileBounds(i, j); }
+ gfx::Vector2d textureOffset(int xIndex, int yIndex) const { return m_tilingData.TextureOffset(xIndex, yIndex); }
// Change the tile size. This may invalidate all the existing tiles.
void setTileSize(const gfx::Size&);
gfx::Size tileSize() const;
// Change the border texel setting. This may invalidate all existing tiles.
void setBorderTexelOption(BorderTexelOption);
- bool hasBorderTexels() const { return m_tilingData.borderTexels(); }
+ bool hasBorderTexels() const { return m_tilingData.border_texels(); }
bool isEmpty() const { return hasEmptyBounds() || !tiles().size(); }
diff --git a/cc/stubs/TilingData.h b/cc/stubs/TilingData.h
deleted file mode 100644
index e6507e3..0000000
--- a/cc/stubs/TilingData.h
+++ /dev/null
@@ -1,6 +0,0 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Temporary forwarding header
-#include "cc/stubs/tiling_data.h"
diff --git a/cc/stubs/tiling_data.h b/cc/stubs/tiling_data.h
deleted file mode 100644
index 0221500..0000000
--- a/cc/stubs/tiling_data.h
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CC_STUBS_TILINGDATA_H_
-#define CC_STUBS_TILINGDATA_H_
-
-#if INSIDE_WEBKIT_BUILD
-#include "Source/WebCore/platform/graphics/gpu/TilingData.h"
-#else
-#include "third_party/WebKit/Source/WebCore/platform/graphics/gpu/TilingData.h"
-#endif
-
-namespace cc {
- typedef WebCore::TilingData TilingData;
-}
-
-#endif // CC_STUBS_TILINGDATA_H_
diff --git a/cc/tiling_data.cc b/cc/tiling_data.cc
new file mode 100644
index 0000000..022c40f
--- /dev/null
+++ b/cc/tiling_data.cc
@@ -0,0 +1,174 @@
+// Copyright 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+
+#include "cc/tiling_data.h"
+
+#include <algorithm>
+
+#include "ui/gfx/rect.h"
+#include "ui/gfx/vector2d.h"
+
+namespace cc {
+
+static 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;
+
+ int num_tiles = std::max(1, 1 + (total_size - 1 - 2 * border_texels) / (max_texture_size - 2 * border_texels));
+ return total_size > 0 ? num_tiles : 0;
+}
+
+TilingData::TilingData(gfx::Size max_texture_size, gfx::Size total_size, bool hasBorderTexels)
+ : max_texture_size_(max_texture_size),
+ total_size_(total_size),
+ border_texels_(hasBorderTexels ? 1 : 0) {
+ RecomputeNumTiles();
+}
+
+TilingData::~TilingData() {
+}
+
+void TilingData::SetTotalSize(gfx::Size total_size) {
+ total_size_ = total_size;
+ RecomputeNumTiles();
+}
+
+void TilingData::SetMaxTextureSize(gfx::Size max_texture_size) {
+ max_texture_size_ = max_texture_size;
+ RecomputeNumTiles();
+}
+
+void TilingData::SetHasBorderTexels(bool has_border_texels) {
+ border_texels_ = has_border_texels ? 1 : 0;
+ RecomputeNumTiles();
+}
+
+int TilingData::TileXIndexFromSrcCoord(int src_position) const {
+ if (num_tiles_x_ <= 1)
+ return 0;
+
+ DCHECK(max_texture_size_.width() - 2 * border_texels_);
+ int x = (src_position - border_texels_) / (max_texture_size_.width() - 2 * border_texels_);
+ return std::min(std::max(x, 0), num_tiles_x_ - 1);
+}
+
+int TilingData::TileYIndexFromSrcCoord(int src_position) const {
+ if (num_tiles_y_ <= 1)
+ return 0;
+
+ DCHECK(max_texture_size_.height() - 2 * border_texels_);
+ int y = (src_position - border_texels_) / (max_texture_size_.height() - 2 * border_texels_);
+ return std::min(std::max(y, 0), num_tiles_y_ - 1);
+}
+
+gfx::Rect TilingData::TileBounds(int i, int j) const {
+ AssertTile(i, j);
+ int x = TilePositionX(i);
+ int y = TilePositionY(j);
+ int width = TileSizeX(i);
+ int height = TileSizeY(j);
+ DCHECK_GE(x, 0);
+ DCHECK_GE(y, 0);
+ DCHECK_GE(width, 0);
+ DCHECK_GE(height, 0);
+ DCHECK_LE(x, total_size_.width());
+ DCHECK_LE(y, total_size_.height());
+ return gfx::Rect(x, y, width, height);
+}
+
+gfx::Rect TilingData::TileBoundsWithBorder(int i, int j) const {
+ gfx::Rect bounds = TileBounds(i, j);
+
+ if (border_texels_) {
+ int x1 = bounds.x();
+ int x2 = bounds.right();
+ int y1 = bounds.y();
+ int y2 = bounds.bottom();
+
+ if (i > 0)
+ x1--;
+ if (i < (num_tiles_x_ - 1))
+ x2++;
+ if (j > 0)
+ y1--;
+ if (j < (num_tiles_y_ - 1))
+ y2++;
+
+ bounds = gfx::Rect(x1, y1, x2 - x1, y2 - y1);
+ }
+
+ return bounds;
+}
+
+int TilingData::TilePositionX(int x_index) const {
+ DCHECK_GE(x_index, 0);
+ DCHECK_LT(x_index, num_tiles_x_);
+
+ int pos = 0;
+ for (int i = 0; i < x_index; i++)
+ pos += TileSizeX(i);
+
+ return pos;
+}
+
+int TilingData::TilePositionY(int y_index) const {
+ DCHECK_GE(y_index, 0);
+ DCHECK_LT(y_index, num_tiles_y_);
+
+ int pos = 0;
+ for (int i = 0; i < y_index; i++)
+ pos += TileSizeY(i);
+
+ return pos;
+}
+
+int TilingData::TileSizeX(int x_index) const {
+ DCHECK_GE(x_index, 0);
+ DCHECK_LT(x_index, num_tiles_x_);
+
+ if (!x_index && num_tiles_x_ == 1)
+ return total_size_.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);
+
+ NOTREACHED();
+ return 0;
+}
+
+int TilingData::TileSizeY(int y_index) const {
+ DCHECK_GE(y_index, 0);
+ DCHECK_LT(y_index, num_tiles_y_);
+
+ if (!y_index && num_tiles_y_ == 1)
+ return total_size_.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);
+
+ NOTREACHED();
+ return 0;
+}
+
+gfx::Vector2d TilingData::TextureOffset(int x_index, int y_index) const {
+ int left = (!x_index || num_tiles_x_ == 1) ? 0 : border_texels_;
+ int top = (!y_index || num_tiles_y_ == 1) ? 0 : border_texels_;
+
+ return gfx::Vector2d(left, top);
+}
+
+void TilingData::RecomputeNumTiles() {
+ num_tiles_x_ = ComputeNumTiles(max_texture_size_.width(), total_size_.width(), border_texels_);
+ num_tiles_y_ = ComputeNumTiles(max_texture_size_.height(), total_size_.height(), border_texels_);
+}
+
+} // namespace cc
diff --git a/cc/tiling_data.h b/cc/tiling_data.h
new file mode 100644
index 0000000..6d052c0
--- /dev/null
+++ b/cc/tiling_data.h
@@ -0,0 +1,71 @@
+// Copyright 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CC_TILING_DATA_H_
+#define CC_TILING_DATA_H_
+
+#include "base/basictypes.h"
+#include "base/logging.h"
+#include "ui/gfx/size.h"
+
+namespace gfx {
+class Rect;
+class Vector2d;
+}
+
+namespace cc {
+
+class TilingData {
+ public:
+ TilingData(gfx::Size max_texture_size, gfx::Size total_size, bool has_border_texels);
+ ~TilingData();
+
+ gfx::Size total_size() const { return total_size_; }
+ void SetTotalSize(const gfx::Size total_size);
+
+ gfx::Size max_texture_size() const { return max_texture_size_; }
+ void SetMaxTextureSize(gfx::Size max_texture_size);
+
+ int border_texels() const { return border_texels_; }
+ void SetHasBorderTexels(bool has_border_texels);
+
+ bool has_empty_bounds() const { return !num_tiles_x_ || !num_tiles_y_; }
+ int num_tiles_x() const { return num_tiles_x_; }
+ int num_tiles_y() const { return num_tiles_y_; }
+ int TileXIndexFromSrcCoord(int src_position) const;
+ int TileYIndexFromSrcCoord(int src_position) const;
+
+ gfx::Rect TileBounds(int i, int j) const;
+ gfx::Rect TileBoundsWithBorder(int i, int j) const;
+ int TilePositionX(int x_index) const;
+ int TilePositionY(int y_index) const;
+ int TileSizeX(int x_index) const;
+ int TileSizeY(int y_index) const;
+
+ // Difference between TileBound's and TileBoundWithBorder's origin().
+ gfx::Vector2d TextureOffset(int x_index, int y_index) const;
+
+ private:
+ void AssertTile(int i, int j) const {
+ DCHECK_GE(i, 0);
+ DCHECK_LT(i, num_tiles_x_);
+ DCHECK_GE(j, 0);
+ DCHECK_LT(j, num_tiles_y_);
+ }
+
+ void RecomputeNumTiles();
+
+ gfx::Size max_texture_size_;
+ gfx::Size total_size_;
+ // This value is always 0 or 1.
+ int border_texels_;
+
+ // These are computed values.
+ int num_tiles_x_;
+ int num_tiles_y_;
+};
+
+} // namespace cc
+
+#endif // CC_TILING_DATA_H_