OLD | NEW |
1 // Copyright 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_BASE_TILING_DATA_H_ | 5 #ifndef CC_BASE_TILING_DATA_H_ |
6 #define CC_BASE_TILING_DATA_H_ | 6 #define CC_BASE_TILING_DATA_H_ |
7 | 7 |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "cc/base/cc_export.h" | 11 #include "cc/base/cc_export.h" |
| 12 #include "cc/base/index_rect.h" |
12 #include "ui/gfx/geometry/rect.h" | 13 #include "ui/gfx/geometry/rect.h" |
13 #include "ui/gfx/geometry/size.h" | 14 #include "ui/gfx/geometry/size.h" |
14 | 15 |
15 namespace gfx { | 16 namespace gfx { |
16 class Vector2d; | 17 class Vector2d; |
17 } | 18 } |
18 | 19 |
19 namespace cc { | 20 namespace cc { |
20 | 21 |
21 class CC_EXPORT TilingData { | 22 class CC_EXPORT TilingData { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 // Iterate through tiles whose bounds + optional border intersect with |rect|. | 89 // Iterate through tiles whose bounds + optional border intersect with |rect|. |
89 class CC_EXPORT Iterator : public BaseIterator { | 90 class CC_EXPORT Iterator : public BaseIterator { |
90 public: | 91 public: |
91 Iterator(); | 92 Iterator(); |
92 Iterator(const TilingData* tiling_data, | 93 Iterator(const TilingData* tiling_data, |
93 const gfx::Rect& consider_rect, | 94 const gfx::Rect& consider_rect, |
94 bool include_borders); | 95 bool include_borders); |
95 Iterator& operator++(); | 96 Iterator& operator++(); |
96 | 97 |
97 private: | 98 private: |
98 int left_; | 99 IndexRect index_rect_; |
99 int right_; | |
100 int bottom_; | |
101 }; | 100 }; |
102 | 101 |
103 class CC_EXPORT BaseDifferenceIterator : public BaseIterator { | 102 class CC_EXPORT BaseDifferenceIterator : public BaseIterator { |
104 protected: | 103 protected: |
105 BaseDifferenceIterator(); | 104 BaseDifferenceIterator(); |
106 BaseDifferenceIterator(const TilingData* tiling_data, | 105 BaseDifferenceIterator(const TilingData* tiling_data, |
107 const gfx::Rect& consider_rect, | 106 const gfx::Rect& consider_rect, |
108 const gfx::Rect& ignore_rect); | 107 const gfx::Rect& ignore_rect); |
109 | 108 |
110 bool HasConsiderRect() const; | 109 bool HasConsiderRect() const; |
111 bool in_consider_rect() const { | |
112 return index_x_ >= consider_left_ && index_x_ <= consider_right_ && | |
113 index_y_ >= consider_top_ && index_y_ <= consider_bottom_; | |
114 } | |
115 bool in_ignore_rect() const { | |
116 return index_x_ >= ignore_left_ && index_x_ <= ignore_right_ && | |
117 index_y_ >= ignore_top_ && index_y_ <= ignore_bottom_; | |
118 } | |
119 | 110 |
120 int consider_left_; | 111 IndexRect consider_index_rect_; |
121 int consider_top_; | 112 IndexRect ignore_index_rect_; |
122 int consider_right_; | |
123 int consider_bottom_; | |
124 int ignore_left_; | |
125 int ignore_top_; | |
126 int ignore_right_; | |
127 int ignore_bottom_; | |
128 }; | 113 }; |
129 | 114 |
130 // Iterate through all indices whose bounds (not including borders) intersect | 115 // Iterate through all indices whose bounds (not including borders) intersect |
131 // with |consider| but which also do not intersect with |ignore|. | 116 // with |consider| but which also do not intersect with |ignore|. |
132 class CC_EXPORT DifferenceIterator : public BaseDifferenceIterator { | 117 class CC_EXPORT DifferenceIterator : public BaseDifferenceIterator { |
133 public: | 118 public: |
134 DifferenceIterator(); | 119 DifferenceIterator(); |
135 DifferenceIterator(const TilingData* tiling_data, | 120 DifferenceIterator(const TilingData* tiling_data, |
136 const gfx::Rect& consider_rect, | 121 const gfx::Rect& consider_rect, |
137 const gfx::Rect& ignore_rect); | 122 const gfx::Rect& ignore_rect); |
138 DifferenceIterator& operator++(); | 123 DifferenceIterator& operator++(); |
139 }; | 124 }; |
140 | 125 |
141 // Iterate through all indices whose bounds + border intersect with | 126 // Iterate through all indices whose bounds + border intersect with |
142 // |consider| but which also do not intersect with |ignore|. The iterator | 127 // |consider| but which also do not intersect with |ignore|. The iterator |
143 // order is a counterclockwise spiral around the given center. | 128 // order is a counterclockwise spiral around the given center. |
144 class CC_EXPORT SpiralDifferenceIterator : public BaseDifferenceIterator { | 129 class CC_EXPORT SpiralDifferenceIterator : public BaseDifferenceIterator { |
145 public: | 130 public: |
146 SpiralDifferenceIterator(); | 131 SpiralDifferenceIterator(); |
147 SpiralDifferenceIterator(const TilingData* tiling_data, | 132 SpiralDifferenceIterator(const TilingData* tiling_data, |
148 const gfx::Rect& consider_rect, | 133 const gfx::Rect& consider_rect, |
149 const gfx::Rect& ignore_rect, | 134 const gfx::Rect& ignore_rect, |
150 const gfx::Rect& center_rect); | 135 const gfx::Rect& center_rect); |
151 SpiralDifferenceIterator& operator++(); | 136 SpiralDifferenceIterator& operator++(); |
152 | 137 |
153 private: | 138 private: |
154 bool valid_column() const { | |
155 return index_x_ >= consider_left_ && index_x_ <= consider_right_; | |
156 } | |
157 bool valid_row() const { | |
158 return index_y_ >= consider_top_ && index_y_ <= consider_bottom_; | |
159 } | |
160 | |
161 int current_step_count() const { | 139 int current_step_count() const { |
162 return (direction_ == UP || direction_ == DOWN) ? vertical_step_count_ | 140 return (direction_ == UP || direction_ == DOWN) ? vertical_step_count_ |
163 : horizontal_step_count_; | 141 : horizontal_step_count_; |
164 } | 142 } |
165 | 143 |
166 bool needs_direction_switch() const; | 144 bool needs_direction_switch() const; |
167 void switch_direction(); | 145 void switch_direction(); |
168 | 146 |
169 enum Direction { UP, LEFT, DOWN, RIGHT }; | 147 enum Direction { UP, LEFT, DOWN, RIGHT }; |
170 | 148 |
171 Direction direction_; | 149 Direction direction_; |
172 int delta_x_; | 150 int delta_x_; |
173 int delta_y_; | 151 int delta_y_; |
174 int current_step_; | 152 int current_step_; |
175 int horizontal_step_count_; | 153 int horizontal_step_count_; |
176 int vertical_step_count_; | 154 int vertical_step_count_; |
177 }; | 155 }; |
178 | 156 |
179 class CC_EXPORT ReverseSpiralDifferenceIterator | 157 class CC_EXPORT ReverseSpiralDifferenceIterator |
180 : public BaseDifferenceIterator { | 158 : public BaseDifferenceIterator { |
181 public: | 159 public: |
182 ReverseSpiralDifferenceIterator(); | 160 ReverseSpiralDifferenceIterator(); |
183 ReverseSpiralDifferenceIterator(const TilingData* tiling_data, | 161 ReverseSpiralDifferenceIterator(const TilingData* tiling_data, |
184 const gfx::Rect& consider_rect, | 162 const gfx::Rect& consider_rect, |
185 const gfx::Rect& ignore_rect, | 163 const gfx::Rect& ignore_rect, |
186 const gfx::Rect& center_rect); | 164 const gfx::Rect& center_rect); |
187 ReverseSpiralDifferenceIterator& operator++(); | 165 ReverseSpiralDifferenceIterator& operator++(); |
188 | 166 |
189 private: | 167 private: |
190 bool in_around_rect() const { | |
191 return index_x_ >= around_left_ && index_x_ <= around_right_ && | |
192 index_y_ >= around_top_ && index_y_ <= around_bottom_; | |
193 } | |
194 bool valid_column() const { | |
195 return index_x_ >= consider_left_ && index_x_ <= consider_right_; | |
196 } | |
197 bool valid_row() const { | |
198 return index_y_ >= consider_top_ && index_y_ <= consider_bottom_; | |
199 } | |
200 | |
201 int current_step_count() const { | 168 int current_step_count() const { |
202 return (direction_ == UP || direction_ == DOWN) ? vertical_step_count_ | 169 return (direction_ == UP || direction_ == DOWN) ? vertical_step_count_ |
203 : horizontal_step_count_; | 170 : horizontal_step_count_; |
204 } | 171 } |
205 | 172 |
206 bool needs_direction_switch() const; | 173 bool needs_direction_switch() const; |
207 void switch_direction(); | 174 void switch_direction(); |
208 | 175 |
209 int around_left_; | 176 IndexRect around_index_rect_; |
210 int around_top_; | |
211 int around_right_; | |
212 int around_bottom_; | |
213 | 177 |
214 enum Direction { LEFT, UP, RIGHT, DOWN }; | 178 enum Direction { LEFT, UP, RIGHT, DOWN }; |
215 | 179 |
216 Direction direction_; | 180 Direction direction_; |
217 int delta_x_; | 181 int delta_x_; |
218 int delta_y_; | 182 int delta_y_; |
219 int current_step_; | 183 int current_step_; |
220 int horizontal_step_count_; | 184 int horizontal_step_count_; |
221 int vertical_step_count_; | 185 int vertical_step_count_; |
222 }; | 186 }; |
(...skipping 13 matching lines...) Expand all Loading... |
236 int border_texels_; | 200 int border_texels_; |
237 | 201 |
238 // These are computed values. | 202 // These are computed values. |
239 int num_tiles_x_; | 203 int num_tiles_x_; |
240 int num_tiles_y_; | 204 int num_tiles_y_; |
241 }; | 205 }; |
242 | 206 |
243 } // namespace cc | 207 } // namespace cc |
244 | 208 |
245 #endif // CC_BASE_TILING_DATA_H_ | 209 #endif // CC_BASE_TILING_DATA_H_ |
OLD | NEW |