OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/resources/picture_layer_tiling.h" | 5 #include "cc/resources/picture_layer_tiling.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <limits> | 9 #include <limits> |
10 #include <set> | 10 #include <set> |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 | 98 |
99 tiling_data_.SetTilingSize(content_bounds); | 99 tiling_data_.SetTilingSize(content_bounds); |
100 tiling_data_.SetMaxTextureSize(tile_size); | 100 tiling_data_.SetMaxTextureSize(tile_size); |
101 } | 101 } |
102 | 102 |
103 PictureLayerTiling::~PictureLayerTiling() { | 103 PictureLayerTiling::~PictureLayerTiling() { |
104 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) | 104 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) |
105 it->second->set_shared(false); | 105 it->second->set_shared(false); |
106 } | 106 } |
107 | 107 |
108 void PictureLayerTiling::SetClient(PictureLayerTilingClient* client) { | |
109 client_ = client; | |
110 } | |
111 | |
112 Tile* PictureLayerTiling::CreateTile(int i, | 108 Tile* PictureLayerTiling::CreateTile(int i, |
113 int j, | 109 int j, |
114 const PictureLayerTiling* twin_tiling) { | 110 const PictureLayerTiling* twin_tiling) { |
115 TileMapKey key(i, j); | 111 TileMapKey key(i, j); |
116 DCHECK(tiles_.find(key) == tiles_.end()); | 112 DCHECK(tiles_.find(key) == tiles_.end()); |
117 | 113 |
118 gfx::Rect paint_rect = tiling_data_.TileBoundsWithBorder(i, j); | 114 gfx::Rect paint_rect = tiling_data_.TileBoundsWithBorder(i, j); |
119 gfx::Rect tile_rect = paint_rect; | 115 gfx::Rect tile_rect = paint_rect; |
120 tile_rect.set_size(tiling_data_.max_texture_size()); | 116 tile_rect.set_size(tiling_data_.max_texture_size()); |
121 | 117 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 TileMapKey key = iter.index(); | 156 TileMapKey key = iter.index(); |
161 TileMap::iterator find = tiles_.find(key); | 157 TileMap::iterator find = tiles_.find(key); |
162 if (find != tiles_.end()) | 158 if (find != tiles_.end()) |
163 continue; | 159 continue; |
164 CreateTile(key.first, key.second, twin_tiling); | 160 CreateTile(key.first, key.second, twin_tiling); |
165 } | 161 } |
166 | 162 |
167 VerifyLiveTilesRect(); | 163 VerifyLiveTilesRect(); |
168 } | 164 } |
169 | 165 |
| 166 void PictureLayerTiling::CreateSharedTilesFromPending( |
| 167 const PictureLayerTiling& other) { |
| 168 DCHECK_EQ(&other, client_->GetPendingOrActiveTwinTiling(this)); |
| 169 SetLiveTilesRect(other.live_tiles_rect()); |
| 170 DCHECK_EQ(other.tiles_.size(), tiles_.size()); |
| 171 } |
| 172 |
170 void PictureLayerTiling::UpdateTilesToCurrentRasterSource( | 173 void PictureLayerTiling::UpdateTilesToCurrentRasterSource( |
171 RasterSource* raster_source, | 174 RasterSource* raster_source, |
172 const Region& layer_invalidation, | 175 const Region& layer_invalidation, |
173 const gfx::Size& new_layer_bounds) { | 176 const gfx::Size& new_layer_bounds) { |
174 DCHECK(!new_layer_bounds.IsEmpty()); | 177 DCHECK(!new_layer_bounds.IsEmpty()); |
175 | 178 |
176 gfx::Size content_bounds = | 179 gfx::Size content_bounds = |
177 gfx::ToCeiledSize(gfx::ScaleSize(new_layer_bounds, contents_scale_)); | 180 gfx::ToCeiledSize(gfx::ScaleSize(new_layer_bounds, contents_scale_)); |
178 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); | 181 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); |
179 | 182 |
(...skipping 23 matching lines...) Expand all Loading... |
203 | 206 |
204 int after_right = -1; | 207 int after_right = -1; |
205 int after_bottom = -1; | 208 int after_bottom = -1; |
206 if (!live_tiles_rect_.IsEmpty()) { | 209 if (!live_tiles_rect_.IsEmpty()) { |
207 after_right = | 210 after_right = |
208 tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.right() - 1); | 211 tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.right() - 1); |
209 after_bottom = | 212 after_bottom = |
210 tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.bottom() - 1); | 213 tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.bottom() - 1); |
211 } | 214 } |
212 | 215 |
213 // There is no recycled twin since this is run on the pending tiling. | 216 // There is no recycled twin since this is run on the pending tiling |
| 217 // during commit, and on the active tree during activate. |
214 PictureLayerTiling* recycled_twin = NULL; | 218 PictureLayerTiling* recycled_twin = NULL; |
215 DCHECK_EQ(recycled_twin, client_->GetRecycledTwinTiling(this)); | 219 DCHECK_EQ(recycled_twin, client_->GetRecycledTwinTiling(this)); |
216 DCHECK_EQ(PENDING_TREE, client_->GetTree()); | |
217 | 220 |
218 // Drop tiles outside the new layer bounds if the layer shrank. | 221 // Drop tiles outside the new layer bounds if the layer shrank. |
219 for (int i = after_right + 1; i <= before_right; ++i) { | 222 for (int i = after_right + 1; i <= before_right; ++i) { |
220 for (int j = before_top; j <= before_bottom; ++j) | 223 for (int j = before_top; j <= before_bottom; ++j) |
221 RemoveTileAt(i, j, recycled_twin); | 224 RemoveTileAt(i, j, recycled_twin); |
222 } | 225 } |
223 for (int i = before_left; i <= after_right; ++i) { | 226 for (int i = before_left; i <= after_right; ++i) { |
224 for (int j = after_bottom + 1; j <= before_bottom; ++j) | 227 for (int j = after_bottom + 1; j <= before_bottom; ++j) |
225 RemoveTileAt(i, j, recycled_twin); | 228 RemoveTileAt(i, j, recycled_twin); |
226 } | 229 } |
(...skipping 16 matching lines...) Expand all Loading... |
243 | 246 |
244 if (tile_size != tiling_data_.max_texture_size()) { | 247 if (tile_size != tiling_data_.max_texture_size()) { |
245 tiling_data_.SetMaxTextureSize(tile_size); | 248 tiling_data_.SetMaxTextureSize(tile_size); |
246 // When the tile size changes, the TilingData positions no longer work | 249 // When the tile size changes, the TilingData positions no longer work |
247 // as valid keys to the TileMap, so just drop all tiles. | 250 // as valid keys to the TileMap, so just drop all tiles. |
248 Reset(); | 251 Reset(); |
249 } else { | 252 } else { |
250 Invalidate(layer_invalidation); | 253 Invalidate(layer_invalidation); |
251 } | 254 } |
252 | 255 |
253 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) | 256 // Shared (ie. non-invalidated) tiles on the pending tree are updated to use |
254 it->second->set_raster_source(raster_source); | 257 // the new raster source. When this raster source is activated, the raster |
| 258 // source will remain valid for shared tiles in the active tree. |
| 259 // TODO(danakj): Clean this up, pass it in or make it a separate function call |
| 260 // or something. |
| 261 // TODO(danakj): This breaks if we commit to active tree! We really need to do |
| 262 // this for the sync tree. |
| 263 bool set_tiles_to_raster_source = client_->GetTree() == PENDING_TREE; |
| 264 if (set_tiles_to_raster_source) { |
| 265 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) |
| 266 it->second->set_raster_source(raster_source); |
| 267 } |
255 VerifyLiveTilesRect(); | 268 VerifyLiveTilesRect(); |
256 } | 269 } |
257 | 270 |
258 void PictureLayerTiling::RemoveTilesInRegion(const Region& layer_region) { | |
259 bool recreate_invalidated_tiles = false; | |
260 DoInvalidate(layer_region, recreate_invalidated_tiles); | |
261 } | |
262 | |
263 void PictureLayerTiling::Invalidate(const Region& layer_region) { | 271 void PictureLayerTiling::Invalidate(const Region& layer_region) { |
264 bool recreate_invalidated_tiles = true; | |
265 DoInvalidate(layer_region, recreate_invalidated_tiles); | |
266 } | |
267 | |
268 void PictureLayerTiling::DoInvalidate(const Region& layer_region, | |
269 bool recreate_invalidated_tiles) { | |
270 std::vector<TileMapKey> new_tile_keys; | 272 std::vector<TileMapKey> new_tile_keys; |
271 gfx::Rect expanded_live_tiles_rect = | 273 gfx::Rect expanded_live_tiles_rect = |
272 tiling_data_.ExpandRectIgnoringBordersToTileBounds(live_tiles_rect_); | 274 tiling_data_.ExpandRectIgnoringBordersToTileBounds(live_tiles_rect_); |
273 for (Region::Iterator iter(layer_region); iter.has_rect(); iter.next()) { | 275 for (Region::Iterator iter(layer_region); iter.has_rect(); iter.next()) { |
274 gfx::Rect layer_rect = iter.rect(); | 276 gfx::Rect layer_rect = iter.rect(); |
275 gfx::Rect content_rect = | 277 gfx::Rect content_rect = |
276 gfx::ScaleToEnclosingRect(layer_rect, contents_scale_); | 278 gfx::ScaleToEnclosingRect(layer_rect, contents_scale_); |
277 // Consider tiles inside the live tiles rect even if only their border | 279 // Consider tiles inside the live tiles rect even if only their border |
278 // pixels intersect the invalidation. But don't consider tiles outside | 280 // pixels intersect the invalidation. But don't consider tiles outside |
279 // the live tiles rect with the same conditions, as they won't exist. | 281 // the live tiles rect with the same conditions, as they won't exist. |
280 int border_pixels = tiling_data_.border_texels(); | 282 int border_pixels = tiling_data_.border_texels(); |
281 content_rect.Inset(-border_pixels, -border_pixels); | 283 content_rect.Inset(-border_pixels, -border_pixels); |
282 // Avoid needless work by not bothering to invalidate where there aren't | 284 // Avoid needless work by not bothering to invalidate where there aren't |
283 // tiles. | 285 // tiles. |
284 content_rect.Intersect(expanded_live_tiles_rect); | 286 content_rect.Intersect(expanded_live_tiles_rect); |
285 if (content_rect.IsEmpty()) | 287 if (content_rect.IsEmpty()) |
286 continue; | 288 continue; |
287 // Since the content_rect includes border pixels already, don't include | 289 // Since the content_rect includes border pixels already, don't include |
288 // borders when iterating to avoid double counting them. | 290 // borders when iterating to avoid double counting them. |
289 bool include_borders = false; | 291 bool include_borders = false; |
290 for (TilingData::Iterator iter( | 292 for (TilingData::Iterator iter( |
291 &tiling_data_, content_rect, include_borders); | 293 &tiling_data_, content_rect, include_borders); |
292 iter; | 294 iter; |
293 ++iter) { | 295 ++iter) { |
294 // There is no recycled twin since this is run on the pending tiling. | 296 // There is no recycled twin for the peding tree during commit, or for the |
| 297 // active tree during activation. |
295 PictureLayerTiling* recycled_twin = NULL; | 298 PictureLayerTiling* recycled_twin = NULL; |
296 DCHECK_EQ(recycled_twin, client_->GetRecycledTwinTiling(this)); | 299 DCHECK_EQ(recycled_twin, client_->GetRecycledTwinTiling(this)); |
297 DCHECK_EQ(PENDING_TREE, client_->GetTree()); | |
298 if (RemoveTileAt(iter.index_x(), iter.index_y(), recycled_twin)) | 300 if (RemoveTileAt(iter.index_x(), iter.index_y(), recycled_twin)) |
299 new_tile_keys.push_back(iter.index()); | 301 new_tile_keys.push_back(iter.index()); |
300 } | 302 } |
301 } | 303 } |
302 | 304 |
303 if (recreate_invalidated_tiles && !new_tile_keys.empty()) { | 305 if (!new_tile_keys.empty()) { |
| 306 // During commit to the pending tree, invalidations can never be shared with |
| 307 // the active tree since the active tree has different content there. |
| 308 // However, during activation, invalidations on the active tree can be |
| 309 // shared with the pending tree always. |
| 310 const PictureLayerTiling* twin_tiling = nullptr; |
| 311 if (client_->GetTree() == ACTIVE_TREE) |
| 312 twin_tiling = client_->GetPendingOrActiveTwinTiling(this); |
304 for (size_t i = 0; i < new_tile_keys.size(); ++i) { | 313 for (size_t i = 0; i < new_tile_keys.size(); ++i) { |
305 // Don't try to share a tile with the twin layer, it's been invalidated so | |
306 // we have to make our own tile here. | |
307 const PictureLayerTiling* twin_tiling = NULL; | |
308 CreateTile(new_tile_keys[i].first, new_tile_keys[i].second, twin_tiling); | 314 CreateTile(new_tile_keys[i].first, new_tile_keys[i].second, twin_tiling); |
309 } | 315 } |
310 } | 316 } |
311 } | 317 } |
312 | 318 |
313 PictureLayerTiling::CoverageIterator::CoverageIterator() | 319 PictureLayerTiling::CoverageIterator::CoverageIterator() |
314 : tiling_(NULL), | 320 : tiling_(NULL), |
315 current_tile_(NULL), | 321 current_tile_(NULL), |
316 tile_i_(0), | 322 tile_i_(0), |
317 tile_j_(0), | 323 tile_j_(0), |
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1210 } | 1216 } |
1211 current_tile_ = tiling_->TileAt(next_index.first, next_index.second); | 1217 current_tile_ = tiling_->TileAt(next_index.first, next_index.second); |
1212 } | 1218 } |
1213 | 1219 |
1214 if (current_tile_) | 1220 if (current_tile_) |
1215 tiling_->UpdateTileAndTwinPriority(current_tile_); | 1221 tiling_->UpdateTileAndTwinPriority(current_tile_); |
1216 return *this; | 1222 return *this; |
1217 } | 1223 } |
1218 | 1224 |
1219 } // namespace cc | 1225 } // namespace cc |
OLD | NEW |