Chromium Code Reviews| 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 #include "cc/base/tiling_data.h" | 5 #include "cc/base/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 12 matching lines...) Expand all Loading... | |
| 23 return total_size > 0 ? num_tiles : 0; | 23 return total_size > 0 ? num_tiles : 0; |
| 24 } | 24 } |
| 25 | 25 |
| 26 TilingData::TilingData() | 26 TilingData::TilingData() |
| 27 : border_texels_(0) { | 27 : border_texels_(0) { |
| 28 RecomputeNumTiles(); | 28 RecomputeNumTiles(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 TilingData::TilingData( | 31 TilingData::TilingData( |
| 32 const gfx::Size& max_texture_size, | 32 const gfx::Size& max_texture_size, |
| 33 const gfx::Size& total_size, | 33 const gfx::Rect& tiling_rect, |
| 34 bool has_border_texels) | 34 bool has_border_texels) |
| 35 : max_texture_size_(max_texture_size), | 35 : max_texture_size_(max_texture_size), |
| 36 total_size_(total_size), | 36 tiling_rect_(tiling_rect), |
| 37 border_texels_(has_border_texels ? 1 : 0) { | 37 border_texels_(has_border_texels ? 1 : 0) { |
| 38 RecomputeNumTiles(); | 38 RecomputeNumTiles(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 TilingData::TilingData( | 41 TilingData::TilingData( |
| 42 const gfx::Size& max_texture_size, | 42 const gfx::Size& max_texture_size, |
| 43 const gfx::Size& total_size, | 43 const gfx::Rect& tiling_rect, |
| 44 int border_texels) | 44 int border_texels) |
| 45 : max_texture_size_(max_texture_size), | 45 : max_texture_size_(max_texture_size), |
| 46 total_size_(total_size), | 46 tiling_rect_(tiling_rect), |
| 47 border_texels_(border_texels) { | 47 border_texels_(border_texels) { |
| 48 RecomputeNumTiles(); | 48 RecomputeNumTiles(); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void TilingData::SetTotalSize(const gfx::Size& total_size) { | 51 void TilingData::SetTilingRect(const gfx::Rect& tiling_rect) { |
| 52 total_size_ = total_size; | 52 tiling_rect_ = tiling_rect; |
| 53 RecomputeNumTiles(); | 53 RecomputeNumTiles(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void TilingData::SetMaxTextureSize(const gfx::Size& max_texture_size) { | 56 void TilingData::SetMaxTextureSize(const gfx::Size& max_texture_size) { |
| 57 max_texture_size_ = max_texture_size; | 57 max_texture_size_ = max_texture_size; |
| 58 RecomputeNumTiles(); | 58 RecomputeNumTiles(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void TilingData::SetHasBorderTexels(bool has_border_texels) { | 61 void TilingData::SetHasBorderTexels(bool has_border_texels) { |
| 62 border_texels_ = has_border_texels ? 1 : 0; | 62 border_texels_ = has_border_texels ? 1 : 0; |
| 63 RecomputeNumTiles(); | 63 RecomputeNumTiles(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void TilingData::SetBorderTexels(int border_texels) { | 66 void TilingData::SetBorderTexels(int border_texels) { |
| 67 border_texels_ = border_texels; | 67 border_texels_ = border_texels; |
| 68 RecomputeNumTiles(); | 68 RecomputeNumTiles(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 int TilingData::TileXIndexFromSrcCoord(int src_position) const { | 71 int TilingData::TileXIndexFromSrcCoord(int src_position) const { |
| 72 if (num_tiles_x_ <= 1) | 72 if (num_tiles_x_ <= 1) |
| 73 return 0; | 73 return 0; |
| 74 | 74 |
| 75 src_position -= tiling_rect_.x(); | |
| 76 | |
| 75 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0); | 77 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0); |
| 76 int x = (src_position - border_texels_) / | 78 int x = (src_position - border_texels_) / |
| 77 (max_texture_size_.width() - 2 * border_texels_); | 79 (max_texture_size_.width() - 2 * border_texels_); |
| 78 return std::min(std::max(x, 0), num_tiles_x_ - 1); | 80 return std::min(std::max(x, 0), num_tiles_x_ - 1); |
| 79 } | 81 } |
| 80 | 82 |
| 81 int TilingData::TileYIndexFromSrcCoord(int src_position) const { | 83 int TilingData::TileYIndexFromSrcCoord(int src_position) const { |
| 82 if (num_tiles_y_ <= 1) | 84 if (num_tiles_y_ <= 1) |
| 83 return 0; | 85 return 0; |
| 84 | 86 |
| 87 src_position -= tiling_rect_.y(); | |
| 88 | |
| 85 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0); | 89 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0); |
| 86 int y = (src_position - border_texels_) / | 90 int y = (src_position - border_texels_) / |
| 87 (max_texture_size_.height() - 2 * border_texels_); | 91 (max_texture_size_.height() - 2 * border_texels_); |
| 88 return std::min(std::max(y, 0), num_tiles_y_ - 1); | 92 return std::min(std::max(y, 0), num_tiles_y_ - 1); |
| 89 } | 93 } |
| 90 | 94 |
| 91 int TilingData::FirstBorderTileXIndexFromSrcCoord(int src_position) const { | 95 int TilingData::FirstBorderTileXIndexFromSrcCoord(int src_position) const { |
| 92 if (num_tiles_x_ <= 1) | 96 if (num_tiles_x_ <= 1) |
| 93 return 0; | 97 return 0; |
| 94 | 98 |
| 99 src_position -= tiling_rect_.x(); | |
| 100 | |
| 95 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0); | 101 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0); |
| 96 int inner_tile_size = max_texture_size_.width() - 2 * border_texels_; | 102 int inner_tile_size = max_texture_size_.width() - 2 * border_texels_; |
| 97 int x = (src_position - 2 * border_texels_) / inner_tile_size; | 103 int x = (src_position - 2 * border_texels_) / inner_tile_size; |
| 98 return std::min(std::max(x, 0), num_tiles_x_ - 1); | 104 return std::min(std::max(x, 0), num_tiles_x_ - 1); |
| 99 } | 105 } |
| 100 | 106 |
| 101 int TilingData::FirstBorderTileYIndexFromSrcCoord(int src_position) const { | 107 int TilingData::FirstBorderTileYIndexFromSrcCoord(int src_position) const { |
| 102 if (num_tiles_y_ <= 1) | 108 if (num_tiles_y_ <= 1) |
| 103 return 0; | 109 return 0; |
| 104 | 110 |
| 111 src_position -= tiling_rect_.y(); | |
| 112 | |
| 105 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0); | 113 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0); |
| 106 int inner_tile_size = max_texture_size_.height() - 2 * border_texels_; | 114 int inner_tile_size = max_texture_size_.height() - 2 * border_texels_; |
| 107 int y = (src_position - 2 * border_texels_) / inner_tile_size; | 115 int y = (src_position - 2 * border_texels_) / inner_tile_size; |
| 108 return std::min(std::max(y, 0), num_tiles_y_ - 1); | 116 return std::min(std::max(y, 0), num_tiles_y_ - 1); |
| 109 } | 117 } |
| 110 | 118 |
| 111 int TilingData::LastBorderTileXIndexFromSrcCoord(int src_position) const { | 119 int TilingData::LastBorderTileXIndexFromSrcCoord(int src_position) const { |
| 112 if (num_tiles_x_ <= 1) | 120 if (num_tiles_x_ <= 1) |
| 113 return 0; | 121 return 0; |
| 114 | 122 |
| 123 src_position -= tiling_rect_.x(); | |
| 124 | |
| 115 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0); | 125 DCHECK_GT(max_texture_size_.width() - 2 * border_texels_, 0); |
| 116 int inner_tile_size = max_texture_size_.width() - 2 * border_texels_; | 126 int inner_tile_size = max_texture_size_.width() - 2 * border_texels_; |
| 117 int x = src_position / inner_tile_size; | 127 int x = src_position / inner_tile_size; |
| 118 return std::min(std::max(x, 0), num_tiles_x_ - 1); | 128 return std::min(std::max(x, 0), num_tiles_x_ - 1); |
| 119 } | 129 } |
| 120 | 130 |
| 121 int TilingData::LastBorderTileYIndexFromSrcCoord(int src_position) const { | 131 int TilingData::LastBorderTileYIndexFromSrcCoord(int src_position) const { |
| 122 if (num_tiles_y_ <= 1) | 132 if (num_tiles_y_ <= 1) |
| 123 return 0; | 133 return 0; |
| 124 | 134 |
| 135 src_position -= tiling_rect_.y(); | |
| 136 | |
| 125 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0); | 137 DCHECK_GT(max_texture_size_.height() - 2 * border_texels_, 0); |
| 126 int inner_tile_size = max_texture_size_.height() - 2 * border_texels_; | 138 int inner_tile_size = max_texture_size_.height() - 2 * border_texels_; |
| 127 int y = src_position / inner_tile_size; | 139 int y = src_position / inner_tile_size; |
| 128 return std::min(std::max(y, 0), num_tiles_y_ - 1); | 140 return std::min(std::max(y, 0), num_tiles_y_ - 1); |
| 129 } | 141 } |
| 130 | 142 |
| 131 gfx::Rect TilingData::TileBounds(int i, int j) const { | 143 gfx::Rect TilingData::TileBounds(int i, int j) const { |
| 132 AssertTile(i, j); | 144 AssertTile(i, j); |
| 133 int max_texture_size_x = max_texture_size_.width() - 2 * border_texels_; | 145 int max_texture_size_x = max_texture_size_.width() - 2 * border_texels_; |
| 134 int max_texture_size_y = max_texture_size_.height() - 2 * border_texels_; | 146 int max_texture_size_y = max_texture_size_.height() - 2 * border_texels_; |
| 135 int total_size_x = total_size_.width(); | |
| 136 int total_size_y = total_size_.height(); | |
| 137 | 147 |
| 138 int lo_x = max_texture_size_x * i; | 148 int lo_x = max_texture_size_x * i; |
| 139 if (i != 0) | 149 if (i != 0) |
| 140 lo_x += border_texels_; | 150 lo_x += border_texels_; |
| 141 | 151 |
| 142 int lo_y = max_texture_size_y * j; | 152 int lo_y = max_texture_size_y * j; |
| 143 if (j != 0) | 153 if (j != 0) |
| 144 lo_y += border_texels_; | 154 lo_y += border_texels_; |
| 145 | 155 |
| 146 int hi_x = max_texture_size_x * (i + 1) + border_texels_; | 156 int hi_x = max_texture_size_x * (i + 1) + border_texels_; |
| 147 if (i + 1 == num_tiles_x_) | 157 if (i + 1 == num_tiles_x_) |
| 148 hi_x += border_texels_; | 158 hi_x += border_texels_; |
| 149 | 159 |
| 150 int hi_y = max_texture_size_y * (j + 1) + border_texels_; | 160 int hi_y = max_texture_size_y * (j + 1) + border_texels_; |
| 151 if (j + 1 == num_tiles_y_) | 161 if (j + 1 == num_tiles_y_) |
| 152 hi_y += border_texels_; | 162 hi_y += border_texels_; |
| 153 | 163 |
| 154 hi_x = std::min(hi_x, total_size_x); | 164 lo_x += tiling_rect_.x(); |
| 155 hi_y = std::min(hi_y, total_size_y); | 165 hi_x += tiling_rect_.x(); |
| 166 lo_y += tiling_rect_.y(); | |
| 167 hi_y += tiling_rect_.y(); | |
| 168 | |
| 169 hi_x = std::min(hi_x, tiling_rect_.right()); | |
| 170 hi_y = std::min(hi_y, tiling_rect_.bottom()); | |
| 156 | 171 |
| 157 int x = lo_x; | 172 int x = lo_x; |
| 158 int y = lo_y; | 173 int y = lo_y; |
| 159 int width = hi_x - lo_x; | 174 int width = hi_x - lo_x; |
| 160 int height = hi_y - lo_y; | 175 int height = hi_y - lo_y; |
| 161 DCHECK_GE(x, 0); | 176 DCHECK_GE(x, 0); |
| 162 DCHECK_GE(y, 0); | 177 DCHECK_GE(y, 0); |
| 163 DCHECK_GE(width, 0); | 178 DCHECK_GE(width, 0); |
| 164 DCHECK_GE(height, 0); | 179 DCHECK_GE(height, 0); |
| 165 DCHECK_LE(x, total_size_.width()); | 180 DCHECK_LE(x, tiling_rect_.right()); |
| 166 DCHECK_LE(y, total_size_.height()); | 181 DCHECK_LE(y, tiling_rect_.bottom()); |
| 167 return gfx::Rect(x, y, width, height); | 182 return gfx::Rect(x, y, width, height); |
| 168 } | 183 } |
| 169 | 184 |
| 170 gfx::Rect TilingData::TileBoundsWithBorder(int i, int j) const { | 185 gfx::Rect TilingData::TileBoundsWithBorder(int i, int j) const { |
| 171 AssertTile(i, j); | 186 AssertTile(i, j); |
| 172 int max_texture_size_x = max_texture_size_.width() - 2 * border_texels_; | 187 int max_texture_size_x = max_texture_size_.width() - 2 * border_texels_; |
| 173 int max_texture_size_y = max_texture_size_.height() - 2 * border_texels_; | 188 int max_texture_size_y = max_texture_size_.height() - 2 * border_texels_; |
| 174 int total_size_x = total_size_.width(); | |
| 175 int total_size_y = total_size_.height(); | |
| 176 | 189 |
| 177 int lo_x = max_texture_size_x * i; | 190 int lo_x = max_texture_size_x * i; |
| 178 int lo_y = max_texture_size_y * j; | 191 int lo_y = max_texture_size_y * j; |
| 179 | 192 |
| 180 int hi_x = lo_x + max_texture_size_x + 2 * border_texels_; | 193 int hi_x = lo_x + max_texture_size_x + 2 * border_texels_; |
| 181 int hi_y = lo_y + max_texture_size_y + 2 * border_texels_; | 194 int hi_y = lo_y + max_texture_size_y + 2 * border_texels_; |
| 182 | 195 |
| 183 hi_x = std::min(hi_x, total_size_x); | 196 lo_x += tiling_rect_.x(); |
|
enne (OOO)
2014/04/11 20:19:51
microoptimization: You could move the offset after
ernstm
2014/04/11 23:43:51
Done.
| |
| 184 hi_y = std::min(hi_y, total_size_y); | 197 hi_x += tiling_rect_.x(); |
| 198 lo_y += tiling_rect_.y(); | |
| 199 hi_y += tiling_rect_.y(); | |
| 200 | |
| 201 hi_x = std::min(hi_x, tiling_rect_.right()); | |
| 202 hi_y = std::min(hi_y, tiling_rect_.bottom()); | |
| 185 | 203 |
| 186 int x = lo_x; | 204 int x = lo_x; |
| 187 int y = lo_y; | 205 int y = lo_y; |
| 188 int width = hi_x - lo_x; | 206 int width = hi_x - lo_x; |
| 189 int height = hi_y - lo_y; | 207 int height = hi_y - lo_y; |
| 190 DCHECK_GE(x, 0); | 208 DCHECK_GE(x, 0); |
| 191 DCHECK_GE(y, 0); | 209 DCHECK_GE(y, 0); |
| 192 DCHECK_GE(width, 0); | 210 DCHECK_GE(width, 0); |
| 193 DCHECK_GE(height, 0); | 211 DCHECK_GE(height, 0); |
| 194 DCHECK_LE(x, total_size_.width()); | 212 DCHECK_LE(x, tiling_rect_.right()); |
| 195 DCHECK_LE(y, total_size_.height()); | 213 DCHECK_LE(y, tiling_rect_.bottom()); |
| 196 return gfx::Rect(x, y, width, height); | 214 return gfx::Rect(x, y, width, height); |
| 197 } | 215 } |
| 198 | 216 |
| 199 int TilingData::TilePositionX(int x_index) const { | 217 int TilingData::TilePositionX(int x_index) const { |
| 200 DCHECK_GE(x_index, 0); | 218 DCHECK_GE(x_index, 0); |
| 201 DCHECK_LT(x_index, num_tiles_x_); | 219 DCHECK_LT(x_index, num_tiles_x_); |
| 202 | 220 |
| 203 int pos = (max_texture_size_.width() - 2 * border_texels_) * x_index; | 221 int pos = (max_texture_size_.width() - 2 * border_texels_) * x_index; |
| 204 if (x_index != 0) | 222 if (x_index != 0) |
| 205 pos += border_texels_; | 223 pos += border_texels_; |
| 206 | 224 |
| 225 pos += tiling_rect_.x(); | |
| 226 | |
| 207 return pos; | 227 return pos; |
| 208 } | 228 } |
| 209 | 229 |
| 210 int TilingData::TilePositionY(int y_index) const { | 230 int TilingData::TilePositionY(int y_index) const { |
| 211 DCHECK_GE(y_index, 0); | 231 DCHECK_GE(y_index, 0); |
| 212 DCHECK_LT(y_index, num_tiles_y_); | 232 DCHECK_LT(y_index, num_tiles_y_); |
| 213 | 233 |
| 214 int pos = (max_texture_size_.height() - 2 * border_texels_) * y_index; | 234 int pos = (max_texture_size_.height() - 2 * border_texels_) * y_index; |
| 215 if (y_index != 0) | 235 if (y_index != 0) |
| 216 pos += border_texels_; | 236 pos += border_texels_; |
| 217 | 237 |
| 238 pos += tiling_rect_.y(); | |
| 239 | |
| 218 return pos; | 240 return pos; |
| 219 } | 241 } |
| 220 | 242 |
| 221 int TilingData::TileSizeX(int x_index) const { | 243 int TilingData::TileSizeX(int x_index) const { |
| 222 DCHECK_GE(x_index, 0); | 244 DCHECK_GE(x_index, 0); |
| 223 DCHECK_LT(x_index, num_tiles_x_); | 245 DCHECK_LT(x_index, num_tiles_x_); |
| 224 | 246 |
| 225 if (!x_index && num_tiles_x_ == 1) | 247 if (!x_index && num_tiles_x_ == 1) |
| 226 return total_size_.width(); | 248 return tiling_rect_.width(); |
| 227 if (!x_index && num_tiles_x_ > 1) | 249 if (!x_index && num_tiles_x_ > 1) |
| 228 return max_texture_size_.width() - border_texels_; | 250 return max_texture_size_.width() - border_texels_; |
| 229 if (x_index < num_tiles_x_ - 1) | 251 if (x_index < num_tiles_x_ - 1) |
| 230 return max_texture_size_.width() - 2 * border_texels_; | 252 return max_texture_size_.width() - 2 * border_texels_; |
| 231 if (x_index == num_tiles_x_ - 1) | 253 if (x_index == num_tiles_x_ - 1) |
| 232 return total_size_.width() - TilePositionX(x_index); | 254 return tiling_rect_.width() - TilePositionX(x_index); |
| 233 | 255 |
| 234 NOTREACHED(); | 256 NOTREACHED(); |
| 235 return 0; | 257 return 0; |
| 236 } | 258 } |
| 237 | 259 |
| 238 int TilingData::TileSizeY(int y_index) const { | 260 int TilingData::TileSizeY(int y_index) const { |
| 239 DCHECK_GE(y_index, 0); | 261 DCHECK_GE(y_index, 0); |
| 240 DCHECK_LT(y_index, num_tiles_y_); | 262 DCHECK_LT(y_index, num_tiles_y_); |
| 241 | 263 |
| 242 if (!y_index && num_tiles_y_ == 1) | 264 if (!y_index && num_tiles_y_ == 1) |
| 243 return total_size_.height(); | 265 return tiling_rect_.height(); |
| 244 if (!y_index && num_tiles_y_ > 1) | 266 if (!y_index && num_tiles_y_ > 1) |
| 245 return max_texture_size_.height() - border_texels_; | 267 return max_texture_size_.height() - border_texels_; |
| 246 if (y_index < num_tiles_y_ - 1) | 268 if (y_index < num_tiles_y_ - 1) |
| 247 return max_texture_size_.height() - 2 * border_texels_; | 269 return max_texture_size_.height() - 2 * border_texels_; |
| 248 if (y_index == num_tiles_y_ - 1) | 270 if (y_index == num_tiles_y_ - 1) |
| 249 return total_size_.height() - TilePositionY(y_index); | 271 return tiling_rect_.height() - TilePositionY(y_index); |
| 250 | 272 |
| 251 NOTREACHED(); | 273 NOTREACHED(); |
| 252 return 0; | 274 return 0; |
| 253 } | 275 } |
| 254 | 276 |
| 255 gfx::Vector2d TilingData::TextureOffset(int x_index, int y_index) const { | 277 gfx::Vector2d TilingData::TextureOffset(int x_index, int y_index) const { |
| 256 int left = (!x_index || num_tiles_x_ == 1) ? 0 : border_texels_; | 278 int left = (!x_index || num_tiles_x_ == 1) ? 0 : border_texels_; |
| 257 int top = (!y_index || num_tiles_y_ == 1) ? 0 : border_texels_; | 279 int top = (!y_index || num_tiles_y_ == 1) ? 0 : border_texels_; |
| 258 | 280 |
| 259 return gfx::Vector2d(left, top); | 281 return gfx::Vector2d(left, top); |
| 260 } | 282 } |
| 261 | 283 |
| 262 void TilingData::RecomputeNumTiles() { | 284 void TilingData::RecomputeNumTiles() { |
| 263 num_tiles_x_ = ComputeNumTiles( | 285 num_tiles_x_ = ComputeNumTiles( |
| 264 max_texture_size_.width(), total_size_.width(), border_texels_); | 286 max_texture_size_.width(), tiling_rect_.width(), border_texels_); |
| 265 num_tiles_y_ = ComputeNumTiles( | 287 num_tiles_y_ = ComputeNumTiles( |
| 266 max_texture_size_.height(), total_size_.height(), border_texels_); | 288 max_texture_size_.height(), tiling_rect_.height(), border_texels_); |
| 267 } | 289 } |
| 268 | 290 |
| 269 TilingData::BaseIterator::BaseIterator(const TilingData* tiling_data) | 291 TilingData::BaseIterator::BaseIterator(const TilingData* tiling_data) |
| 270 : tiling_data_(tiling_data), | 292 : tiling_data_(tiling_data), |
| 271 index_x_(-1), | 293 index_x_(-1), |
| 272 index_y_(-1) { | 294 index_y_(-1) { |
| 273 } | 295 } |
| 274 | 296 |
| 275 TilingData::Iterator::Iterator() : BaseIterator(NULL) { done(); } | 297 TilingData::Iterator::Iterator() : BaseIterator(NULL) { done(); } |
| 276 | 298 |
| 277 TilingData::Iterator::Iterator(const TilingData* tiling_data, | 299 TilingData::Iterator::Iterator(const TilingData* tiling_data, |
| 278 const gfx::Rect& tiling_rect, | 300 const gfx::Rect& tiling_rect, |
| 279 bool include_borders) | 301 bool include_borders) |
| 280 : BaseIterator(tiling_data), left_(-1), right_(-1), bottom_(-1) { | 302 : BaseIterator(tiling_data), left_(-1), right_(-1), bottom_(-1) { |
| 281 if (tiling_data_->num_tiles_x() <= 0 || tiling_data_->num_tiles_y() <= 0) { | 303 if (tiling_data_->num_tiles_x() <= 0 || tiling_data_->num_tiles_y() <= 0) { |
| 282 done(); | 304 done(); |
| 283 return; | 305 return; |
| 284 } | 306 } |
| 285 | 307 |
| 286 gfx::Rect rect(tiling_rect); | 308 gfx::Rect rect(tiling_rect); |
| 287 rect.Intersect(gfx::Rect(tiling_data_->total_size())); | 309 rect.Intersect(tiling_data_->tiling_rect()); |
| 288 | 310 |
| 289 gfx::Rect top_left_tile; | 311 gfx::Rect top_left_tile; |
| 290 if (include_borders) { | 312 if (include_borders) { |
| 291 index_x_ = tiling_data_->FirstBorderTileXIndexFromSrcCoord(rect.x()); | 313 index_x_ = tiling_data_->FirstBorderTileXIndexFromSrcCoord(rect.x()); |
| 292 index_y_ = tiling_data_->FirstBorderTileYIndexFromSrcCoord(rect.y()); | 314 index_y_ = tiling_data_->FirstBorderTileYIndexFromSrcCoord(rect.y()); |
| 293 right_ = tiling_data_->LastBorderTileXIndexFromSrcCoord(rect.right() - 1); | 315 right_ = tiling_data_->LastBorderTileXIndexFromSrcCoord(rect.right() - 1); |
| 294 bottom_ = tiling_data_->LastBorderTileYIndexFromSrcCoord(rect.bottom() - 1); | 316 bottom_ = tiling_data_->LastBorderTileYIndexFromSrcCoord(rect.bottom() - 1); |
| 295 top_left_tile = tiling_data_->TileBoundsWithBorder(index_x_, index_y_); | 317 top_left_tile = tiling_data_->TileBoundsWithBorder(index_x_, index_y_); |
| 296 } else { | 318 } else { |
| 297 index_x_ = tiling_data_->TileXIndexFromSrcCoord(rect.x()); | 319 index_x_ = tiling_data_->TileXIndexFromSrcCoord(rect.x()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 consider_bottom_(-1), | 356 consider_bottom_(-1), |
| 335 ignore_left_(-1), | 357 ignore_left_(-1), |
| 336 ignore_top_(-1), | 358 ignore_top_(-1), |
| 337 ignore_right_(-1), | 359 ignore_right_(-1), |
| 338 ignore_bottom_(-1) { | 360 ignore_bottom_(-1) { |
| 339 if (tiling_data_->num_tiles_x() <= 0 || tiling_data_->num_tiles_y() <= 0) { | 361 if (tiling_data_->num_tiles_x() <= 0 || tiling_data_->num_tiles_y() <= 0) { |
| 340 done(); | 362 done(); |
| 341 return; | 363 return; |
| 342 } | 364 } |
| 343 | 365 |
| 344 gfx::Rect bounds(tiling_data_->total_size()); | |
| 345 gfx::Rect consider(consider_rect); | 366 gfx::Rect consider(consider_rect); |
| 346 gfx::Rect ignore(ignore_rect); | 367 gfx::Rect ignore(ignore_rect); |
| 347 consider.Intersect(bounds); | 368 consider.Intersect(tiling_data_->tiling_rect()); |
| 348 ignore.Intersect(bounds); | 369 ignore.Intersect(tiling_data_->tiling_rect()); |
| 349 if (consider.IsEmpty()) { | 370 if (consider.IsEmpty()) { |
| 350 done(); | 371 done(); |
| 351 return; | 372 return; |
| 352 } | 373 } |
| 353 | 374 |
| 354 consider_left_ = | 375 consider_left_ = |
| 355 tiling_data_->FirstBorderTileXIndexFromSrcCoord(consider.x()); | 376 tiling_data_->FirstBorderTileXIndexFromSrcCoord(consider.x()); |
| 356 consider_top_ = | 377 consider_top_ = |
| 357 tiling_data_->FirstBorderTileYIndexFromSrcCoord(consider.y()); | 378 tiling_data_->FirstBorderTileYIndexFromSrcCoord(consider.y()); |
| 358 consider_right_ = | 379 consider_right_ = |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 delta_x_(1), | 463 delta_x_(1), |
| 443 delta_y_(0), | 464 delta_y_(0), |
| 444 current_step_(0), | 465 current_step_(0), |
| 445 horizontal_step_count_(0), | 466 horizontal_step_count_(0), |
| 446 vertical_step_count_(0) { | 467 vertical_step_count_(0) { |
| 447 if (tiling_data_->num_tiles_x() <= 0 || tiling_data_->num_tiles_y() <= 0) { | 468 if (tiling_data_->num_tiles_x() <= 0 || tiling_data_->num_tiles_y() <= 0) { |
| 448 done(); | 469 done(); |
| 449 return; | 470 return; |
| 450 } | 471 } |
| 451 | 472 |
| 452 gfx::Rect bounds(tiling_data_->total_size()); | |
| 453 gfx::Rect consider(consider_rect); | 473 gfx::Rect consider(consider_rect); |
| 454 gfx::Rect ignore(ignore_rect); | 474 gfx::Rect ignore(ignore_rect); |
| 455 gfx::Rect center(center_rect); | 475 gfx::Rect center(center_rect); |
| 456 consider.Intersect(bounds); | 476 consider.Intersect(tiling_data_->tiling_rect()); |
| 457 ignore.Intersect(bounds); | 477 ignore.Intersect(tiling_data_->tiling_rect()); |
| 458 if (consider.IsEmpty()) { | 478 if (consider.IsEmpty()) { |
| 459 done(); | 479 done(); |
| 460 return; | 480 return; |
| 461 } | 481 } |
| 462 | 482 |
| 463 consider_left_ = | 483 consider_left_ = |
| 464 tiling_data_->FirstBorderTileXIndexFromSrcCoord(consider.x()); | 484 tiling_data_->FirstBorderTileXIndexFromSrcCoord(consider.x()); |
| 465 consider_top_ = tiling_data_->FirstBorderTileYIndexFromSrcCoord(consider.y()); | 485 consider_top_ = tiling_data_->FirstBorderTileYIndexFromSrcCoord(consider.y()); |
| 466 consider_right_ = | 486 consider_right_ = |
| 467 tiling_data_->LastBorderTileXIndexFromSrcCoord(consider.right() - 1); | 487 tiling_data_->LastBorderTileXIndexFromSrcCoord(consider.right() - 1); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 486 if (ignore_left_ == consider_left_ && ignore_right_ == consider_right_ && | 506 if (ignore_left_ == consider_left_ && ignore_right_ == consider_right_ && |
| 487 ignore_top_ == consider_top_ && ignore_bottom_ == consider_bottom_) { | 507 ignore_top_ == consider_top_ && ignore_bottom_ == consider_bottom_) { |
| 488 done(); | 508 done(); |
| 489 return; | 509 return; |
| 490 } | 510 } |
| 491 | 511 |
| 492 // Determine around left, such that it is between -1 and num_tiles_x. | 512 // Determine around left, such that it is between -1 and num_tiles_x. |
| 493 int around_left = 0; | 513 int around_left = 0; |
| 494 if (center.x() < 0 || center.IsEmpty()) | 514 if (center.x() < 0 || center.IsEmpty()) |
| 495 around_left = -1; | 515 around_left = -1; |
| 496 else if (center.x() > tiling_data->total_size().width()) | 516 else if (center.x() > tiling_data->tiling_rect().right()) |
| 497 around_left = tiling_data->num_tiles_x(); | 517 around_left = tiling_data->num_tiles_x(); |
| 498 else | 518 else |
| 499 around_left = tiling_data->FirstBorderTileXIndexFromSrcCoord(center.x()); | 519 around_left = tiling_data->FirstBorderTileXIndexFromSrcCoord(center.x()); |
| 500 | 520 |
| 501 // Determine around top, such that it is between -1 and num_tiles_y. | 521 // Determine around top, such that it is between -1 and num_tiles_y. |
| 502 int around_top = 0; | 522 int around_top = 0; |
| 503 if (center.y() < 0 || center.IsEmpty()) | 523 if (center.y() < 0 || center.IsEmpty()) |
| 504 around_top = -1; | 524 around_top = -1; |
| 505 else if (center.y() > tiling_data->total_size().height()) | 525 else if (center.y() > tiling_data->tiling_rect().bottom()) |
| 506 around_top = tiling_data->num_tiles_y(); | 526 around_top = tiling_data->num_tiles_y(); |
| 507 else | 527 else |
| 508 around_top = tiling_data->FirstBorderTileYIndexFromSrcCoord(center.y()); | 528 around_top = tiling_data->FirstBorderTileYIndexFromSrcCoord(center.y()); |
| 509 | 529 |
| 510 // Determine around right, such that it is between -1 and num_tiles_x. | 530 // Determine around right, such that it is between -1 and num_tiles_x. |
| 511 int right_src_coord = center.right() - 1; | 531 int right_src_coord = center.right() - 1; |
| 512 int around_right = 0; | 532 int around_right = 0; |
| 513 if (right_src_coord < 0 || center.IsEmpty()) { | 533 if (right_src_coord < 0 || center.IsEmpty()) { |
| 514 around_right = -1; | 534 around_right = -1; |
| 515 } else if (right_src_coord > tiling_data->total_size().width()) { | 535 } else if (right_src_coord > tiling_data->tiling_rect().right()) { |
| 516 around_right = tiling_data->num_tiles_x(); | 536 around_right = tiling_data->num_tiles_x(); |
| 517 } else { | 537 } else { |
| 518 around_right = | 538 around_right = |
| 519 tiling_data->LastBorderTileXIndexFromSrcCoord(right_src_coord); | 539 tiling_data->LastBorderTileXIndexFromSrcCoord(right_src_coord); |
| 520 } | 540 } |
| 521 | 541 |
| 522 // Determine around bottom, such that it is between -1 and num_tiles_y. | 542 // Determine around bottom, such that it is between -1 and num_tiles_y. |
| 523 int bottom_src_coord = center.bottom() - 1; | 543 int bottom_src_coord = center.bottom() - 1; |
| 524 int around_bottom = 0; | 544 int around_bottom = 0; |
| 525 if (bottom_src_coord < 0 || center.IsEmpty()) { | 545 if (bottom_src_coord < 0 || center.IsEmpty()) { |
| 526 around_bottom = -1; | 546 around_bottom = -1; |
| 527 } else if (bottom_src_coord > tiling_data->total_size().height()) { | 547 } else if (bottom_src_coord > tiling_data->tiling_rect().bottom()) { |
| 528 around_bottom = tiling_data->num_tiles_y(); | 548 around_bottom = tiling_data->num_tiles_y(); |
| 529 } else { | 549 } else { |
| 530 around_bottom = | 550 around_bottom = |
| 531 tiling_data->LastBorderTileYIndexFromSrcCoord(bottom_src_coord); | 551 tiling_data->LastBorderTileYIndexFromSrcCoord(bottom_src_coord); |
| 532 } | 552 } |
| 533 | 553 |
| 534 vertical_step_count_ = around_bottom - around_top + 1; | 554 vertical_step_count_ = around_bottom - around_top + 1; |
| 535 horizontal_step_count_ = around_right - around_left + 1; | 555 horizontal_step_count_ = around_right - around_left + 1; |
| 536 current_step_ = horizontal_step_count_ - 1; | 556 current_step_ = horizontal_step_count_ - 1; |
| 537 | 557 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 644 current_step_ = 0; | 664 current_step_ = 0; |
| 645 direction_ = static_cast<Direction>((direction_ + 1) % 4); | 665 direction_ = static_cast<Direction>((direction_ + 1) % 4); |
| 646 | 666 |
| 647 if (direction_ == RIGHT || direction_ == LEFT) { | 667 if (direction_ == RIGHT || direction_ == LEFT) { |
| 648 ++vertical_step_count_; | 668 ++vertical_step_count_; |
| 649 ++horizontal_step_count_; | 669 ++horizontal_step_count_; |
| 650 } | 670 } |
| 651 } | 671 } |
| 652 | 672 |
| 653 } // namespace cc | 673 } // namespace cc |
| OLD | NEW |