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

Side by Side Diff: cc/tiling_data.cc

Issue 12221077: Fixing tile grid size used by cc:Picture to make it respect current tile configuration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/tiling_data.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "cc/tiling_data.h" 5 #include "cc/tiling_data.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ui/gfx/rect.h" 9 #include "ui/gfx/rect.h"
10 #include "ui/gfx/vector2d.h" 10 #include "ui/gfx/vector2d.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 61
62 void TilingData::SetBorderTexels(int border_texels) { 62 void TilingData::SetBorderTexels(int border_texels) {
63 border_texels_ = border_texels; 63 border_texels_ = border_texels;
64 RecomputeNumTiles(); 64 RecomputeNumTiles();
65 } 65 }
66 66
67 int TilingData::TileXIndexFromSrcCoord(int src_position) const { 67 int TilingData::TileXIndexFromSrcCoord(int src_position) const {
68 if (num_tiles_x_ <= 1) 68 if (num_tiles_x_ <= 1)
69 return 0; 69 return 0;
70 70
71 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0); 71 DCHECK_GT(inner_tile_size_.width(), 0);
72 int x = (src_position - border_texels_) / 72 int x = (src_position - border_texels_) /
73 (max_texture_size_.width() - 2 * border_texels_); 73 (inner_tile_size_.width());
74 return std::min(std::max(x, 0), num_tiles_x_ - 1); 74 return std::min(std::max(x, 0), num_tiles_x_ - 1);
75 } 75 }
76 76
77 int TilingData::TileYIndexFromSrcCoord(int src_position) const { 77 int TilingData::TileYIndexFromSrcCoord(int src_position) const {
78 if (num_tiles_y_ <= 1) 78 if (num_tiles_y_ <= 1)
79 return 0; 79 return 0;
80 80
81 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0); 81 DCHECK_GT(inner_tile_size_.height(), 0);
82 int y = (src_position - border_texels_) / 82 int y = (src_position - border_texels_) /
83 (max_texture_size_.height() - 2 * border_texels_); 83 (inner_tile_size_.height());
84 return std::min(std::max(y, 0), num_tiles_y_ - 1); 84 return std::min(std::max(y, 0), num_tiles_y_ - 1);
85 } 85 }
86 86
87 int TilingData::FirstBorderTileXIndexFromSrcCoord(int src_position) const { 87 int TilingData::FirstBorderTileXIndexFromSrcCoord(int src_position) const {
88 if (num_tiles_x_ <= 1) 88 if (num_tiles_x_ <= 1)
89 return 0; 89 return 0;
90 90
91 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0); 91 DCHECK_GT(inner_tile_size_.width(), 0);
92 int inner_tile_size = max_texture_size_.width() - 2 * border_texels_; 92 int x = (src_position - 2 * border_texels_) / inner_tile_size_.width();
93 int x = (src_position - 2 * border_texels_) / inner_tile_size;
94 return std::min(std::max(x, 0), num_tiles_x_ - 1); 93 return std::min(std::max(x, 0), num_tiles_x_ - 1);
95 } 94 }
96 95
97 int TilingData::FirstBorderTileYIndexFromSrcCoord(int src_position) const { 96 int TilingData::FirstBorderTileYIndexFromSrcCoord(int src_position) const {
98 if (num_tiles_y_ <= 1) 97 if (num_tiles_y_ <= 1)
99 return 0; 98 return 0;
100 99
101 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0); 100 DCHECK_GT(inner_tile_size_.height(), 0);
102 int inner_tile_size = max_texture_size_.height() - 2 * border_texels_; 101 int y = (src_position - 2 * border_texels_) / inner_tile_size_.height();
103 int y = (src_position - 2 * border_texels_) / inner_tile_size;
104 return std::min(std::max(y, 0), num_tiles_y_ - 1); 102 return std::min(std::max(y, 0), num_tiles_y_ - 1);
105 } 103 }
106 104
107 int TilingData::LastBorderTileXIndexFromSrcCoord(int src_position) const { 105 int TilingData::LastBorderTileXIndexFromSrcCoord(int src_position) const {
108 if (num_tiles_x_ <= 1) 106 if (num_tiles_x_ <= 1)
109 return 0; 107 return 0;
110 108
111 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0); 109 DCHECK_GT(inner_tile_size_.width(), 0);
112 int inner_tile_size = max_texture_size_.width() - 2 * border_texels_; 110 int x = src_position / inner_tile_size_.width();
113 int x = src_position / inner_tile_size;
114 return std::min(std::max(x, 0), num_tiles_x_ - 1); 111 return std::min(std::max(x, 0), num_tiles_x_ - 1);
115 } 112 }
116 113
117 int TilingData::LastBorderTileYIndexFromSrcCoord(int src_position) const { 114 int TilingData::LastBorderTileYIndexFromSrcCoord(int src_position) const {
118 if (num_tiles_y_ <= 1) 115 if (num_tiles_y_ <= 1)
119 return 0; 116 return 0;
120 117
121 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0); 118 DCHECK_GT(inner_tile_size_.height(), 0);
122 int inner_tile_size = max_texture_size_.height() - 2 * border_texels_; 119 int y = src_position / inner_tile_size_.height();
123 int y = src_position / inner_tile_size;
124 return std::min(std::max(y, 0), num_tiles_y_ - 1); 120 return std::min(std::max(y, 0), num_tiles_y_ - 1);
125 } 121 }
126 122
127 gfx::Rect TilingData::TileBounds(int i, int j) const { 123 gfx::Rect TilingData::TileBounds(int i, int j) const {
128 AssertTile(i, j); 124 AssertTile(i, j);
129 int max_texture_size_x = max_texture_size_.width() - 2 * border_texels_; 125 int max_texture_size_x = inner_tile_size_.width();
130 int max_texture_size_y = max_texture_size_.height() - 2 * border_texels_; 126 int max_texture_size_y = inner_tile_size_.height();
131 int total_size_x = total_size_.width(); 127 int total_size_x = total_size_.width();
132 int total_size_y = total_size_.height(); 128 int total_size_y = total_size_.height();
133 129
134 int lo_x = max_texture_size_x * i; 130 int lo_x = max_texture_size_x * i;
135 if (i != 0) 131 if (i != 0)
136 lo_x += border_texels_; 132 lo_x += border_texels_;
137 133
138 int lo_y = max_texture_size_y * j; 134 int lo_y = max_texture_size_y * j;
139 if (j != 0) 135 if (j != 0)
140 lo_y += border_texels_; 136 lo_y += border_texels_;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 bounds = gfx::Rect(x1, y1, x2 - x1, y2 - y1); 181 bounds = gfx::Rect(x1, y1, x2 - x1, y2 - y1);
186 } 182 }
187 183
188 return bounds; 184 return bounds;
189 } 185 }
190 186
191 int TilingData::TilePositionX(int x_index) const { 187 int TilingData::TilePositionX(int x_index) const {
192 DCHECK_GE(x_index, 0); 188 DCHECK_GE(x_index, 0);
193 DCHECK_LT(x_index, num_tiles_x_); 189 DCHECK_LT(x_index, num_tiles_x_);
194 190
195 int pos = (max_texture_size_.width() - 2 * border_texels_) * x_index; 191 int pos = inner_tile_size_.width() * x_index;
196 if (x_index != 0) 192 if (x_index != 0)
197 pos += border_texels_; 193 pos += border_texels_;
198 194
199 return pos; 195 return pos;
200 } 196 }
201 197
202 int TilingData::TilePositionY(int y_index) const { 198 int TilingData::TilePositionY(int y_index) const {
203 DCHECK_GE(y_index, 0); 199 DCHECK_GE(y_index, 0);
204 DCHECK_LT(y_index, num_tiles_y_); 200 DCHECK_LT(y_index, num_tiles_y_);
205 201
206 int pos = (max_texture_size_.height() - 2 * border_texels_) * y_index; 202 int pos = inner_tile_size_.height() * y_index;
207 if (y_index != 0) 203 if (y_index != 0)
208 pos += border_texels_; 204 pos += border_texels_;
209 205
210 return pos; 206 return pos;
211 } 207 }
212 208
213 int TilingData::TileSizeX(int x_index) const { 209 int TilingData::TileSizeX(int x_index) const {
214 DCHECK_GE(x_index, 0); 210 DCHECK_GE(x_index, 0);
215 DCHECK_LT(x_index, num_tiles_x_); 211 DCHECK_LT(x_index, num_tiles_x_);
216 212
217 if (!x_index && num_tiles_x_ == 1) 213 if (!x_index && num_tiles_x_ == 1)
218 return total_size_.width(); 214 return total_size_.width();
219 if (!x_index && num_tiles_x_ > 1) 215 if (!x_index && num_tiles_x_ > 1)
220 return max_texture_size_.width() - border_texels_; 216 return max_texture_size_.width() - border_texels_;
danakj 2013/02/07 20:40:01 I'm not sure about the inner_tile_size concept bec
221 if (x_index < num_tiles_x_ - 1) 217 if (x_index < num_tiles_x_ - 1)
222 return max_texture_size_.width() - 2 * border_texels_; 218 return inner_tile_size_.width();
223 if (x_index == num_tiles_x_ - 1) 219 if (x_index == num_tiles_x_ - 1)
224 return total_size_.width() - TilePositionX(x_index); 220 return total_size_.width() - TilePositionX(x_index);
225 221
226 NOTREACHED(); 222 NOTREACHED();
227 return 0; 223 return 0;
228 } 224 }
229 225
230 int TilingData::TileSizeY(int y_index) const { 226 int TilingData::TileSizeY(int y_index) const {
231 DCHECK_GE(y_index, 0); 227 DCHECK_GE(y_index, 0);
232 DCHECK_LT(y_index, num_tiles_y_); 228 DCHECK_LT(y_index, num_tiles_y_);
233 229
234 if (!y_index && num_tiles_y_ == 1) 230 if (!y_index && num_tiles_y_ == 1)
235 return total_size_.height(); 231 return total_size_.height();
236 if (!y_index && num_tiles_y_ > 1) 232 if (!y_index && num_tiles_y_ > 1)
237 return max_texture_size_.height() - border_texels_; 233 return max_texture_size_.height() - border_texels_;
238 if (y_index < num_tiles_y_ - 1) 234 if (y_index < num_tiles_y_ - 1)
239 return max_texture_size_.height() - 2 * border_texels_; 235 return inner_tile_size_.height();
240 if (y_index == num_tiles_y_ - 1) 236 if (y_index == num_tiles_y_ - 1)
241 return total_size_.height() - TilePositionY(y_index); 237 return total_size_.height() - TilePositionY(y_index);
242 238
243 NOTREACHED(); 239 NOTREACHED();
244 return 0; 240 return 0;
245 } 241 }
246 242
247 gfx::Vector2d TilingData::TextureOffset(int x_index, int y_index) const { 243 gfx::Vector2d TilingData::TextureOffset(int x_index, int y_index) const {
248 int left = (!x_index || num_tiles_x_ == 1) ? 0 : border_texels_; 244 int left = (!x_index || num_tiles_x_ == 1) ? 0 : border_texels_;
249 int top = (!y_index || num_tiles_y_ == 1) ? 0 : border_texels_; 245 int top = (!y_index || num_tiles_y_ == 1) ? 0 : border_texels_;
250 246
251 return gfx::Vector2d(left, top); 247 return gfx::Vector2d(left, top);
252 } 248 }
253 249
254 void TilingData::RecomputeNumTiles() { 250 void TilingData::RecomputeNumTiles() {
251 inner_tile_size_ = max_texture_size_;
252 inner_tile_size_.Enlarge(- 2 * border_texels_, - 2 * border_texels_);
255 num_tiles_x_ = ComputeNumTiles(max_texture_size_.width(), total_size_.width(), border_texels_); 253 num_tiles_x_ = ComputeNumTiles(max_texture_size_.width(), total_size_.width(), border_texels_);
256 num_tiles_y_ = ComputeNumTiles(max_texture_size_.height(), total_size_.height( ), border_texels_); 254 num_tiles_y_ = ComputeNumTiles(max_texture_size_.height(), total_size_.height( ), border_texels_);
257 } 255 }
258 256
259 TilingData::BaseIterator::BaseIterator(const TilingData* tiling_data) 257 TilingData::BaseIterator::BaseIterator(const TilingData* tiling_data)
260 : tiling_data_(tiling_data), 258 : tiling_data_(tiling_data),
261 index_x_(-1), 259 index_x_(-1),
262 index_y_(-1) { 260 index_y_(-1) {
263 } 261 }
264 262
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 } 387 }
390 388
391 if (index_y_ > consider_bottom_) 389 if (index_y_ > consider_bottom_)
392 done(); 390 done();
393 } 391 }
394 392
395 return *this; 393 return *this;
396 } 394 }
397 395
398 } // namespace cc 396 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tiling_data.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698