Flip Win32k lockdown to enabled by default.
[chromium-blink-merge.git] / cc / base / tiling_data.h
blob45b763e9ef0ba5c906a69c4eb29176bc9aed9f88
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_
8 #include <utility>
10 #include "base/basictypes.h"
11 #include "base/logging.h"
12 #include "cc/base/cc_export.h"
13 #include "ui/gfx/geometry/rect.h"
14 #include "ui/gfx/geometry/size.h"
16 namespace gfx {
17 class Vector2d;
20 namespace cc {
22 class CC_EXPORT TilingData {
23 public:
24 TilingData();
25 TilingData(const gfx::Size& max_texture_size,
26 const gfx::Size& tiling_size,
27 bool has_border_texels);
28 TilingData(const gfx::Size& max_texture_size,
29 const gfx::Size& tiling_size,
30 int border_texels);
32 gfx::Size tiling_size() const { return tiling_size_; }
33 void SetTilingSize(const gfx::Size& tiling_size);
35 gfx::Size max_texture_size() const { return max_texture_size_; }
36 void SetMaxTextureSize(const gfx::Size& max_texture_size);
38 int border_texels() const { return border_texels_; }
39 void SetHasBorderTexels(bool has_border_texels);
40 void SetBorderTexels(int border_texels);
42 bool has_empty_bounds() const { return !num_tiles_x_ || !num_tiles_y_; }
43 int num_tiles_x() const { return num_tiles_x_; }
44 int num_tiles_y() const { return num_tiles_y_; }
45 // Return the tile index whose non-border texels include src_position.
46 int TileXIndexFromSrcCoord(int src_position) const;
47 int TileYIndexFromSrcCoord(int src_position) const;
48 // Return the lowest tile index whose border texels include src_position.
49 int FirstBorderTileXIndexFromSrcCoord(int src_position) const;
50 int FirstBorderTileYIndexFromSrcCoord(int src_position) const;
51 // Return the highest tile index whose border texels include src_position.
52 int LastBorderTileXIndexFromSrcCoord(int src_position) const;
53 int LastBorderTileYIndexFromSrcCoord(int src_position) const;
55 gfx::Rect ExpandRectIgnoringBordersToTileBounds(const gfx::Rect& rect) const;
56 gfx::Rect ExpandRectToTileBounds(const gfx::Rect& rect) const;
58 gfx::Rect TileBounds(int i, int j) const;
59 gfx::Rect TileBoundsWithBorder(int i, int j) const;
60 int TilePositionX(int x_index) const;
61 int TilePositionY(int y_index) const;
62 int TileSizeX(int x_index) const;
63 int TileSizeY(int y_index) const;
65 // Difference between TileBound's and TileBoundWithBorder's origin().
66 gfx::Vector2d TextureOffset(int x_index, int y_index) const;
68 class CC_EXPORT BaseIterator {
69 public:
70 operator bool() const { return index_x_ != -1 && index_y_ != -1; }
72 int index_x() const { return index_x_; }
73 int index_y() const { return index_y_; }
74 std::pair<int, int> index() const {
75 return std::make_pair(index_x_, index_y_);
78 protected:
79 BaseIterator();
80 void done() {
81 index_x_ = -1;
82 index_y_ = -1;
85 int index_x_;
86 int index_y_;
89 // Iterate through tiles whose bounds + optional border intersect with |rect|.
90 class CC_EXPORT Iterator : public BaseIterator {
91 public:
92 Iterator();
93 Iterator(const TilingData* tiling_data,
94 const gfx::Rect& consider_rect,
95 bool include_borders);
96 Iterator& operator++();
98 private:
99 int left_;
100 int right_;
101 int bottom_;
104 // Iterate through all indices whose bounds (not including borders) intersect
105 // with |consider| but which also do not intersect with |ignore|.
106 class CC_EXPORT DifferenceIterator : public BaseIterator {
107 public:
108 DifferenceIterator(const TilingData* tiling_data,
109 const gfx::Rect& consider_rect,
110 const gfx::Rect& ignore_rect);
111 DifferenceIterator& operator++();
113 private:
114 bool in_ignore_rect() const {
115 return index_x_ >= ignore_left_ && index_x_ <= ignore_right_ &&
116 index_y_ >= ignore_top_ && index_y_ <= ignore_bottom_;
119 int consider_left_;
120 int consider_top_;
121 int consider_right_;
122 int consider_bottom_;
123 int ignore_left_;
124 int ignore_top_;
125 int ignore_right_;
126 int ignore_bottom_;
129 // Iterate through all indices whose bounds + border intersect with
130 // |consider| but which also do not intersect with |ignore|. The iterator
131 // order is a counterclockwise spiral around the given center.
132 class CC_EXPORT SpiralDifferenceIterator : public BaseIterator {
133 public:
134 SpiralDifferenceIterator();
135 SpiralDifferenceIterator(const TilingData* tiling_data,
136 const gfx::Rect& consider_rect,
137 const gfx::Rect& ignore_rect,
138 const gfx::Rect& center_rect);
139 SpiralDifferenceIterator& operator++();
141 private:
142 bool in_consider_rect() const {
143 return index_x_ >= consider_left_ && index_x_ <= consider_right_ &&
144 index_y_ >= consider_top_ && index_y_ <= consider_bottom_;
146 bool in_ignore_rect() const {
147 return index_x_ >= ignore_left_ && index_x_ <= ignore_right_ &&
148 index_y_ >= ignore_top_ && index_y_ <= ignore_bottom_;
150 bool valid_column() const {
151 return index_x_ >= consider_left_ && index_x_ <= consider_right_;
153 bool valid_row() const {
154 return index_y_ >= consider_top_ && index_y_ <= consider_bottom_;
157 int current_step_count() const {
158 return (direction_ == UP || direction_ == DOWN) ? vertical_step_count_
159 : horizontal_step_count_;
162 bool needs_direction_switch() const;
163 void switch_direction();
165 int consider_left_;
166 int consider_top_;
167 int consider_right_;
168 int consider_bottom_;
169 int ignore_left_;
170 int ignore_top_;
171 int ignore_right_;
172 int ignore_bottom_;
174 enum Direction { UP, LEFT, DOWN, RIGHT };
176 Direction direction_;
177 int delta_x_;
178 int delta_y_;
179 int current_step_;
180 int horizontal_step_count_;
181 int vertical_step_count_;
184 class CC_EXPORT ReverseSpiralDifferenceIterator : public BaseIterator {
185 public:
186 ReverseSpiralDifferenceIterator();
187 ReverseSpiralDifferenceIterator(const TilingData* tiling_data,
188 const gfx::Rect& consider_rect,
189 const gfx::Rect& ignore_rect,
190 const gfx::Rect& center_rect);
191 ReverseSpiralDifferenceIterator& operator++();
193 private:
194 bool in_consider_rect() const {
195 return index_x_ >= consider_left_ && index_x_ <= consider_right_ &&
196 index_y_ >= consider_top_ && index_y_ <= consider_bottom_;
198 bool in_around_rect() const {
199 return index_x_ >= around_left_ && index_x_ <= around_right_ &&
200 index_y_ >= around_top_ && index_y_ <= around_bottom_;
202 bool in_ignore_rect() const {
203 return index_x_ >= ignore_left_ && index_x_ <= ignore_right_ &&
204 index_y_ >= ignore_top_ && index_y_ <= ignore_bottom_;
206 bool valid_column() const {
207 return index_x_ >= consider_left_ && index_x_ <= consider_right_;
209 bool valid_row() const {
210 return index_y_ >= consider_top_ && index_y_ <= consider_bottom_;
213 int current_step_count() const {
214 return (direction_ == UP || direction_ == DOWN) ? vertical_step_count_
215 : horizontal_step_count_;
218 bool needs_direction_switch() const;
219 void switch_direction();
221 int consider_left_;
222 int consider_top_;
223 int consider_right_;
224 int consider_bottom_;
225 int around_left_;
226 int around_top_;
227 int around_right_;
228 int around_bottom_;
229 int ignore_left_;
230 int ignore_top_;
231 int ignore_right_;
232 int ignore_bottom_;
234 enum Direction { LEFT, UP, RIGHT, DOWN };
236 Direction direction_;
237 int delta_x_;
238 int delta_y_;
239 int current_step_;
240 int horizontal_step_count_;
241 int vertical_step_count_;
244 private:
245 void AssertTile(int i, int j) const {
246 DCHECK_GE(i, 0);
247 DCHECK_LT(i, num_tiles_x_);
248 DCHECK_GE(j, 0);
249 DCHECK_LT(j, num_tiles_y_);
252 void RecomputeNumTiles();
254 gfx::Size max_texture_size_;
255 gfx::Size tiling_size_;
256 int border_texels_;
258 // These are computed values.
259 int num_tiles_x_;
260 int num_tiles_y_;
263 } // namespace cc
265 #endif // CC_BASE_TILING_DATA_H_