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
3 // found in the LICENSE file.
5 #ifndef CC_BASE_TILING_DATA_H_
6 #define CC_BASE_TILING_DATA_H_
10 #include "base/basictypes.h"
11 #include "base/logging.h"
12 #include "cc/base/cc_export.h"
13 #include "ui/gfx/rect.h"
14 #include "ui/gfx/size.h"
22 class CC_EXPORT TilingData {
26 gfx::Size max_texture_size,
28 bool has_border_texels);
30 gfx::Size max_texture_size,
34 gfx::Size total_size() const { return total_size_; }
35 void SetTotalSize(const gfx::Size total_size);
37 gfx::Size max_texture_size() const { return max_texture_size_; }
38 void SetMaxTextureSize(gfx::Size max_texture_size);
40 int border_texels() const { return border_texels_; }
41 void SetHasBorderTexels(bool has_border_texels);
42 void SetBorderTexels(int border_texels);
44 bool has_empty_bounds() const { return !num_tiles_x_ || !num_tiles_y_; }
45 int num_tiles_x() const { return num_tiles_x_; }
46 int num_tiles_y() const { return num_tiles_y_; }
47 // Return the tile index whose non-border texels include src_position.
48 int TileXIndexFromSrcCoord(int src_position) const;
49 int TileYIndexFromSrcCoord(int src_position) const;
50 // Return the lowest tile index whose border texels include src_position.
51 int FirstBorderTileXIndexFromSrcCoord(int src_position) const;
52 int FirstBorderTileYIndexFromSrcCoord(int src_position) const;
53 // Return the highest tile index whose border texels include src_position.
54 int LastBorderTileXIndexFromSrcCoord(int src_position) const;
55 int LastBorderTileYIndexFromSrcCoord(int src_position) const;
57 gfx::Rect TileBounds(int i, int j) const;
58 gfx::Rect TileBoundsWithBorder(int i, int j) const;
59 int TilePositionX(int x_index) const;
60 int TilePositionY(int y_index) const;
61 int TileSizeX(int x_index) const;
62 int TileSizeY(int y_index) const;
64 // Difference between TileBound's and TileBoundWithBorder's origin().
65 gfx::Vector2d TextureOffset(int x_index, int y_index) const;
67 class CC_EXPORT BaseIterator {
69 operator bool() const { return index_x_ != -1 && index_y_ != -1; }
71 int index_x() const { return index_x_; }
72 int index_y() const { return index_y_; }
73 std::pair<int, int> index() const {
74 return std::make_pair(index_x_, index_y_);
78 explicit BaseIterator(const TilingData* tiling_data);
84 const TilingData* tiling_data_;
89 // Iterate through all indices whose bounds + border intersect with |rect|.
90 class CC_EXPORT Iterator : public BaseIterator {
92 Iterator(const TilingData* tiling_data, const gfx::Rect& tiling_rect);
93 Iterator& operator++();
101 // Iterate through all indices whose bounds + border intersect with
102 // |consider| but which also do not intersect with |ignore|.
103 class CC_EXPORT DifferenceIterator : public BaseIterator {
106 const TilingData* tiling_data,
107 const gfx::Rect& consider_rect,
108 const gfx::Rect& ignore_rect);
109 DifferenceIterator& operator++();
112 bool in_ignore_rect() const {
113 return index_x_ >= ignore_left_ && index_x_ <= ignore_right_ &&
114 index_y_ >= ignore_top_ && index_y_ <= ignore_bottom_;
120 int consider_bottom_;
128 void AssertTile(int i, int j) const {
130 DCHECK_LT(i, num_tiles_x_);
132 DCHECK_LT(j, num_tiles_y_);
135 void RecomputeNumTiles();
137 gfx::Size max_texture_size_;
138 gfx::Size total_size_;
141 // These are computed values.
148 #endif // CC_BASE_TILING_DATA_H_