| 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 | 9 |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 11 #include "cc/base/math_util.h" | 11 #include "cc/base/math_util.h" |
| 12 #include "ui/gfx/point_conversions.h" | 12 #include "ui/gfx/point_conversions.h" |
| 13 #include "ui/gfx/rect_conversions.h" | 13 #include "ui/gfx/rect_conversions.h" |
| 14 #include "ui/gfx/safe_integer_conversions.h" | 14 #include "ui/gfx/safe_integer_conversions.h" |
| 15 #include "ui/gfx/size_conversions.h" | 15 #include "ui/gfx/size_conversions.h" |
| 16 | 16 |
| 17 namespace cc { | 17 namespace cc { |
| 18 | 18 |
| 19 scoped_ptr<PictureLayerTiling> PictureLayerTiling::Create( | 19 scoped_ptr<PictureLayerTiling> PictureLayerTiling::Create( |
| 20 float contents_scale) { | 20 float contents_scale, |
| 21 return make_scoped_ptr(new PictureLayerTiling(contents_scale)); | 21 gfx::Size layer_bounds, |
| 22 PictureLayerTilingClient* client) { |
| 23 return make_scoped_ptr(new PictureLayerTiling(contents_scale, |
| 24 layer_bounds, |
| 25 client)); |
| 22 } | 26 } |
| 23 | 27 |
| 24 scoped_ptr<PictureLayerTiling> PictureLayerTiling::Clone() const { | 28 scoped_ptr<PictureLayerTiling> PictureLayerTiling::Clone( |
| 25 return make_scoped_ptr(new PictureLayerTiling(*this)); | 29 gfx::Size layer_bounds, |
| 30 PictureLayerTilingClient* client) const { |
| 31 scoped_ptr<PictureLayerTiling> out = |
| 32 make_scoped_ptr(new PictureLayerTiling(contents_scale_, |
| 33 layer_bounds, |
| 34 client)); |
| 35 out->resolution_ = resolution_; |
| 36 out->last_source_frame_number_ = last_source_frame_number_; |
| 37 out->last_impl_frame_time_ = last_impl_frame_time_; |
| 38 return out.Pass(); |
| 26 } | 39 } |
| 27 | 40 |
| 28 PictureLayerTiling::PictureLayerTiling(float contents_scale) | 41 PictureLayerTiling::PictureLayerTiling(float contents_scale, |
| 29 : client_(NULL), | 42 gfx::Size layer_bounds, |
| 43 PictureLayerTilingClient* client) |
| 44 : client_(client), |
| 30 contents_scale_(contents_scale), | 45 contents_scale_(contents_scale), |
| 31 tiling_data_(gfx::Size(), gfx::Size(), true), | 46 tiling_data_(gfx::Size(), gfx::Size(), true), |
| 32 resolution_(NON_IDEAL_RESOLUTION), | 47 resolution_(NON_IDEAL_RESOLUTION), |
| 33 last_source_frame_number_(0), | 48 last_source_frame_number_(0), |
| 34 last_impl_frame_time_(0) { | 49 last_impl_frame_time_(0.0), |
| 50 layer_bounds_(layer_bounds) { |
| 51 gfx::Size content_bounds = |
| 52 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale)); |
| 53 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); |
| 54 |
| 55 tiling_data_.SetTotalSize(content_bounds); |
| 56 tiling_data_.SetMaxTextureSize(tile_size); |
| 35 } | 57 } |
| 36 | 58 |
| 37 PictureLayerTiling::~PictureLayerTiling() { | 59 PictureLayerTiling::~PictureLayerTiling() { |
| 38 } | 60 } |
| 39 | 61 |
| 40 void PictureLayerTiling::SetClient(PictureLayerTilingClient* client) { | 62 void PictureLayerTiling::SetClient(PictureLayerTilingClient* client) { |
| 41 client_ = client; | 63 client_ = client; |
| 42 } | 64 } |
| 43 | 65 |
| 44 gfx::Rect PictureLayerTiling::ContentRect() const { | 66 gfx::Rect PictureLayerTiling::ContentRect() const { |
| 45 return gfx::Rect(tiling_data_.total_size()); | 67 return gfx::Rect(tiling_data_.total_size()); |
| 46 } | 68 } |
| 47 | 69 |
| 48 gfx::SizeF PictureLayerTiling::ContentSizeF() const { | 70 gfx::SizeF PictureLayerTiling::ContentSizeF() const { |
| 49 return gfx::ScaleSize(layer_bounds_, contents_scale_); | 71 return gfx::ScaleSize(layer_bounds_, contents_scale_); |
| 50 } | 72 } |
| 51 | 73 |
| 52 Tile* PictureLayerTiling::TileAt(int i, int j) const { | 74 Tile* PictureLayerTiling::TileAt(int i, int j) const { |
| 53 TileMap::const_iterator iter = tiles_.find(TileMapKey(i, j)); | 75 TileMap::const_iterator iter = tiles_.find(TileMapKey(i, j)); |
| 54 if (iter == tiles_.end()) | 76 if (iter == tiles_.end()) |
| 55 return NULL; | 77 return NULL; |
| 56 return iter->second.get(); | 78 return iter->second.get(); |
| 57 } | 79 } |
| 58 | 80 |
| 59 void PictureLayerTiling::CreateTile(int i, int j) { | 81 void PictureLayerTiling::CreateTile(int i, int j) { |
| 60 gfx::Rect tile_rect = tiling_data_.TileBoundsWithBorder(i, j); | |
| 61 tile_rect.set_size(tiling_data_.max_texture_size()); | |
| 62 TileMapKey key(i, j); | 82 TileMapKey key(i, j); |
| 63 DCHECK(tiles_.find(key) == tiles_.end()); | 83 DCHECK(tiles_.find(key) == tiles_.end()); |
| 84 |
| 85 gfx::Rect paint_rect = tiling_data_.TileBoundsWithBorder(i, j); |
| 86 gfx::Rect tile_rect = paint_rect; |
| 87 tile_rect.set_size(tiling_data_.max_texture_size()); |
| 88 |
| 89 // Check our twin for a valid tile. |
| 90 const PictureLayerTiling* twin = client_->GetTwinTiling(this); |
| 91 if (twin && tiling_data_.max_texture_size() == |
| 92 twin->tiling_data_.max_texture_size()) { |
| 93 Tile* candidate_tile = twin->TileAt(i, j); |
| 94 if (candidate_tile) { |
| 95 gfx::Rect rect = |
| 96 gfx::ToEnclosingRect(ScaleRect(paint_rect, 1.0f / contents_scale_)); |
| 97 if (!client_->GetInvalidation()->Intersects(rect)) { |
| 98 tiles_[key] = candidate_tile; |
| 99 return; |
| 100 } |
| 101 } |
| 102 } |
| 103 |
| 104 // Create a new tile because our twin didn't have a valid one. |
| 64 scoped_refptr<Tile> tile = client_->CreateTile(this, tile_rect); | 105 scoped_refptr<Tile> tile = client_->CreateTile(this, tile_rect); |
| 65 if (tile) | 106 if (tile) |
| 66 tiles_[key] = tile; | 107 tiles_[key] = tile; |
| 67 } | 108 } |
| 68 | 109 |
| 69 Region PictureLayerTiling::OpaqueRegionInContentRect( | 110 Region PictureLayerTiling::OpaqueRegionInContentRect( |
| 70 const gfx::Rect& content_rect) const { | 111 const gfx::Rect& content_rect) const { |
| 71 Region opaque_region; | 112 Region opaque_region; |
| 72 // TODO(enne): implement me | 113 // TODO(enne): implement me |
| 73 return opaque_region; | 114 return opaque_region; |
| 74 } | 115 } |
| 75 | 116 |
| 76 void PictureLayerTiling::SetLayerBounds(gfx::Size layer_bounds) { | |
| 77 if (layer_bounds_ == layer_bounds) | |
| 78 return; | |
| 79 | |
| 80 gfx::Size old_layer_bounds = layer_bounds_; | |
| 81 layer_bounds_ = layer_bounds; | |
| 82 gfx::Size old_content_bounds = tiling_data_.total_size(); | |
| 83 gfx::Size content_bounds = | |
| 84 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds_, contents_scale_)); | |
| 85 | |
| 86 tiling_data_.SetTotalSize(content_bounds); | |
| 87 if (layer_bounds_.IsEmpty()) { | |
| 88 tiles_.clear(); | |
| 89 return; | |
| 90 } | |
| 91 | |
| 92 gfx::Size tile_size = client_->CalculateTileSize( | |
| 93 tiling_data_.max_texture_size(), | |
| 94 content_bounds); | |
| 95 if (tile_size != tiling_data_.max_texture_size()) { | |
| 96 tiling_data_.SetMaxTextureSize(tile_size); | |
| 97 tiles_.clear(); | |
| 98 CreateTilesFromLayerRect(gfx::Rect(layer_bounds_)); | |
| 99 return; | |
| 100 } | |
| 101 | |
| 102 // Any tiles outside our new bounds are invalid and should be dropped. | |
| 103 if (old_content_bounds.width() > content_bounds.width() || | |
| 104 old_content_bounds.height() > content_bounds.height()) { | |
| 105 int right = | |
| 106 tiling_data_.TileXIndexFromSrcCoord(content_bounds.width() - 1); | |
| 107 int bottom = | |
| 108 tiling_data_.TileYIndexFromSrcCoord(content_bounds.height() - 1); | |
| 109 | |
| 110 std::vector<TileMapKey> invalid_tile_keys; | |
| 111 for (TileMap::const_iterator it = tiles_.begin(); | |
| 112 it != tiles_.end(); ++it) { | |
| 113 if (it->first.first > right || it->first.second > bottom) | |
| 114 invalid_tile_keys.push_back(it->first); | |
| 115 } | |
| 116 for (size_t i = 0; i < invalid_tile_keys.size(); ++i) | |
| 117 tiles_.erase(invalid_tile_keys[i]); | |
| 118 } | |
| 119 | |
| 120 // Create tiles for newly exposed areas. | |
| 121 Region layer_region((gfx::Rect(layer_bounds_))); | |
| 122 layer_region.Subtract(gfx::Rect(old_layer_bounds)); | |
| 123 for (Region::Iterator iter(layer_region); iter.has_rect(); iter.next()) { | |
| 124 Invalidate(iter.rect()); | |
| 125 CreateTilesFromLayerRect(iter.rect()); | |
| 126 } | |
| 127 } | |
| 128 | |
| 129 void PictureLayerTiling::Invalidate(const Region& layer_invalidation) { | |
| 130 std::vector<TileMapKey> new_tiles; | |
| 131 | |
| 132 for (Region::Iterator region_iter(layer_invalidation); | |
| 133 region_iter.has_rect(); | |
| 134 region_iter.next()) { | |
| 135 gfx::Rect layer_invalidation = region_iter.rect(); | |
| 136 layer_invalidation.Intersect(gfx::Rect(layer_bounds_)); | |
| 137 gfx::Rect rect = | |
| 138 gfx::ToEnclosingRect(ScaleRect(layer_invalidation, contents_scale_)); | |
| 139 | |
| 140 for (PictureLayerTiling::Iterator tile_iter(this, contents_scale_, rect); | |
| 141 tile_iter; | |
| 142 ++tile_iter) { | |
| 143 TileMapKey key(tile_iter.tile_i_, tile_iter.tile_j_); | |
| 144 TileMap::iterator found = tiles_.find(key); | |
| 145 if (found == tiles_.end()) | |
| 146 continue; | |
| 147 | |
| 148 tiles_.erase(found); | |
| 149 new_tiles.push_back(key); | |
| 150 } | |
| 151 } | |
| 152 | |
| 153 for (size_t i = 0; i < new_tiles.size(); ++i) | |
| 154 CreateTile(new_tiles[i].first, new_tiles[i].second); | |
| 155 } | |
| 156 | |
| 157 void PictureLayerTiling::CreateTilesFromLayerRect(gfx::Rect layer_rect) { | |
| 158 gfx::Rect content_rect = | |
| 159 gfx::ToEnclosingRect(ScaleRect(layer_rect, contents_scale_)); | |
| 160 CreateTilesFromContentRect(content_rect); | |
| 161 } | |
| 162 | |
| 163 void PictureLayerTiling::CreateTilesFromContentRect(gfx::Rect content_rect) { | |
| 164 for (TilingData::Iterator iter(&tiling_data_, content_rect); iter; ++iter) { | |
| 165 TileMap::iterator found = | |
| 166 tiles_.find(TileMapKey(iter.index_x(), iter.index_y())); | |
| 167 // Ignore any tiles that already exist. | |
| 168 if (found != tiles_.end()) | |
| 169 continue; | |
| 170 CreateTile(iter.index_x(), iter.index_y()); | |
| 171 } | |
| 172 } | |
| 173 | |
| 174 PictureLayerTiling::Iterator::Iterator() | 117 PictureLayerTiling::Iterator::Iterator() |
| 175 : tiling_(NULL), | 118 : tiling_(NULL), |
| 176 current_tile_(NULL), | 119 current_tile_(NULL), |
| 177 tile_i_(0), | 120 tile_i_(0), |
| 178 tile_j_(0), | 121 tile_j_(0), |
| 179 left_(0), | 122 left_(0), |
| 180 top_(0), | 123 top_(0), |
| 181 right_(-1), | 124 right_(-1), |
| 182 bottom_(-1) { | 125 bottom_(-1) { |
| 183 } | 126 } |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 texture_rect.Offset(-tex_origin.OffsetFromOrigin()); | 256 texture_rect.Offset(-tex_origin.OffsetFromOrigin()); |
| 314 texture_rect.Intersect(tiling_->ContentRect()); | 257 texture_rect.Intersect(tiling_->ContentRect()); |
| 315 | 258 |
| 316 return texture_rect; | 259 return texture_rect; |
| 317 } | 260 } |
| 318 | 261 |
| 319 gfx::Size PictureLayerTiling::Iterator::texture_size() const { | 262 gfx::Size PictureLayerTiling::Iterator::texture_size() const { |
| 320 return tiling_->tiling_data_.max_texture_size(); | 263 return tiling_->tiling_data_.max_texture_size(); |
| 321 } | 264 } |
| 322 | 265 |
| 266 void PictureLayerTiling::Reset() { |
| 267 live_tiles_rect_ = gfx::Rect(); |
| 268 tiles_.clear(); |
| 269 } |
| 270 |
| 323 void PictureLayerTiling::UpdateTilePriorities( | 271 void PictureLayerTiling::UpdateTilePriorities( |
| 324 WhichTree tree, | 272 WhichTree tree, |
| 325 gfx::Size device_viewport, | 273 gfx::Size device_viewport, |
| 326 const gfx::RectF& viewport_in_layer_space, | 274 const gfx::RectF& viewport_in_layer_space, |
| 327 gfx::Size last_layer_bounds, | 275 gfx::Size last_layer_bounds, |
| 328 gfx::Size current_layer_bounds, | 276 gfx::Size current_layer_bounds, |
| 329 float last_layer_contents_scale, | 277 float last_layer_contents_scale, |
| 330 float current_layer_contents_scale, | 278 float current_layer_contents_scale, |
| 331 const gfx::Transform& last_screen_transform, | 279 const gfx::Transform& last_screen_transform, |
| 332 const gfx::Transform& current_screen_transform, | 280 const gfx::Transform& current_screen_transform, |
| 333 int current_source_frame_number, | 281 int current_source_frame_number, |
| 334 double current_frame_time, | 282 double current_frame_time, |
| 335 bool store_screen_space_quads_on_tiles, | 283 bool store_screen_space_quads_on_tiles, |
| 336 size_t max_tiles_for_interest_area) { | 284 size_t max_tiles_for_interest_area) { |
| 337 if (ContentRect().IsEmpty()) | 285 if (ContentRect().IsEmpty()) |
| 338 return; | 286 return; |
| 339 | 287 |
| 288 gfx::Rect viewport_in_content_space = |
| 289 gfx::ToEnclosingRect(gfx::ScaleRect(viewport_in_layer_space, |
| 290 contents_scale_)); |
| 291 |
| 292 gfx::Size tile_size = tiling_data_.max_texture_size(); |
| 293 int64 interest_rect_area = |
| 294 max_tiles_for_interest_area * tile_size.width() * tile_size.height(); |
| 295 |
| 296 gfx::Rect interest_rect = ExpandRectEquallyToAreaBoundedBy( |
| 297 viewport_in_content_space, |
| 298 interest_rect_area, |
| 299 ContentRect()); |
| 300 DCHECK(ContentRect().Contains(interest_rect)); |
| 301 |
| 302 SetLiveTilesRect(interest_rect); |
| 303 |
| 340 bool first_update_in_new_source_frame = | 304 bool first_update_in_new_source_frame = |
| 341 current_source_frame_number != last_source_frame_number_; | 305 current_source_frame_number != last_source_frame_number_; |
| 342 | 306 |
| 343 bool first_update_in_new_impl_frame = | 307 bool first_update_in_new_impl_frame = |
| 344 current_frame_time != last_impl_frame_time_; | 308 current_frame_time != last_impl_frame_time_; |
| 345 | 309 |
| 346 // In pending tree, this is always called. We update priorities: | 310 // In pending tree, this is always called. We update priorities: |
| 347 // - Immediately after a commit (first_update_in_new_source_frame). | 311 // - Immediately after a commit (first_update_in_new_source_frame). |
| 348 // - On animation ticks after the first frame in the tree | 312 // - On animation ticks after the first frame in the tree |
| 349 // (first_update_in_new_impl_frame). | 313 // (first_update_in_new_impl_frame). |
| 350 // In active tree, this is only called during draw. We update priorities: | 314 // In active tree, this is only called during draw. We update priorities: |
| 351 // - On draw if properties were not already computed by the pending tree | 315 // - On draw if properties were not already computed by the pending tree |
| 352 // and activated for the frame (first_update_in_new_impl_frame). | 316 // and activated for the frame (first_update_in_new_impl_frame). |
| 353 if (!first_update_in_new_impl_frame && !first_update_in_new_source_frame) | 317 if (!first_update_in_new_impl_frame && !first_update_in_new_source_frame) |
| 354 return; | 318 return; |
| 355 | 319 |
| 356 double time_delta = 0; | 320 double time_delta = 0.0; |
| 357 if (last_impl_frame_time_ != 0 && last_layer_bounds == current_layer_bounds) | 321 if (last_impl_frame_time_ != 0.0 && |
| 322 last_layer_bounds == current_layer_bounds) |
| 358 time_delta = current_frame_time - last_impl_frame_time_; | 323 time_delta = current_frame_time - last_impl_frame_time_; |
| 359 | 324 |
| 360 gfx::Rect viewport_in_content_space = | |
| 361 gfx::ToEnclosingRect(gfx::ScaleRect(viewport_in_layer_space, | |
| 362 contents_scale_)); | |
| 363 | |
| 364 gfx::Size tile_size = tiling_data_.max_texture_size(); | |
| 365 int64 prioritized_rect_area = | |
| 366 max_tiles_for_interest_area * | |
| 367 tile_size.width() * tile_size.height(); | |
| 368 | |
| 369 gfx::Rect prioritized_rect = ExpandRectEquallyToAreaBoundedBy( | |
| 370 viewport_in_content_space, | |
| 371 prioritized_rect_area, | |
| 372 ContentRect()); | |
| 373 DCHECK(ContentRect().Contains(prioritized_rect)); | |
| 374 | |
| 375 // Iterate through all of the tiles that were live last frame but will | |
| 376 // not be live this frame, and mark them as being dead. | |
| 377 for (TilingData::DifferenceIterator iter(&tiling_data_, | |
| 378 last_prioritized_rect_, | |
| 379 prioritized_rect); | |
| 380 iter; | |
| 381 ++iter) { | |
| 382 TileMap::iterator find = tiles_.find(iter.index()); | |
| 383 if (find == tiles_.end()) | |
| 384 continue; | |
| 385 | |
| 386 TilePriority priority; | |
| 387 DCHECK(!priority.is_live); | |
| 388 Tile* tile = find->second.get(); | |
| 389 tile->SetPriority(tree, priority); | |
| 390 } | |
| 391 last_prioritized_rect_ = prioritized_rect; | |
| 392 | |
| 393 gfx::Rect view_rect(device_viewport); | 325 gfx::Rect view_rect(device_viewport); |
| 394 float current_scale = current_layer_contents_scale / contents_scale_; | 326 float current_scale = current_layer_contents_scale / contents_scale_; |
| 395 float last_scale = last_layer_contents_scale / contents_scale_; | 327 float last_scale = last_layer_contents_scale / contents_scale_; |
| 396 | 328 |
| 397 // Fast path tile priority calculation when both transforms are translations. | 329 // Fast path tile priority calculation when both transforms are translations. |
| 398 if (last_screen_transform.IsIdentityOrTranslation() && | 330 if (last_screen_transform.IsIdentityOrTranslation() && |
| 399 current_screen_transform.IsIdentityOrTranslation()) { | 331 current_screen_transform.IsIdentityOrTranslation()) { |
| 400 gfx::Vector2dF current_offset( | 332 gfx::Vector2dF current_offset( |
| 401 current_screen_transform.matrix().get(0, 3), | 333 current_screen_transform.matrix().get(0, 3), |
| 402 current_screen_transform.matrix().get(1, 3)); | 334 current_screen_transform.matrix().get(1, 3)); |
| 403 gfx::Vector2dF last_offset( | 335 gfx::Vector2dF last_offset( |
| 404 last_screen_transform.matrix().get(0, 3), | 336 last_screen_transform.matrix().get(0, 3), |
| 405 last_screen_transform.matrix().get(1, 3)); | 337 last_screen_transform.matrix().get(1, 3)); |
| 406 | 338 |
| 407 for (TilingData::Iterator iter(&tiling_data_, prioritized_rect); | 339 for (TilingData::Iterator iter(&tiling_data_, interest_rect); |
| 408 iter; ++iter) { | 340 iter; ++iter) { |
| 409 TileMap::iterator find = tiles_.find(iter.index()); | 341 TileMap::iterator find = tiles_.find(iter.index()); |
| 410 if (find == tiles_.end()) | 342 if (find == tiles_.end()) |
| 411 continue; | 343 continue; |
| 412 Tile* tile = find->second.get(); | 344 Tile* tile = find->second.get(); |
| 413 | 345 |
| 414 gfx::Rect tile_bounds = | 346 gfx::Rect tile_bounds = |
| 415 tiling_data_.TileBounds(iter.index_x(), iter.index_y()); | 347 tiling_data_.TileBounds(iter.index_x(), iter.index_y()); |
| 416 gfx::RectF current_screen_rect = gfx::ScaleRect( | 348 gfx::RectF current_screen_rect = gfx::ScaleRect( |
| 417 tile_bounds, | 349 tile_bounds, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 430 last_screen_rect, current_screen_rect, time_delta, view_rect); | 362 last_screen_rect, current_screen_rect, time_delta, view_rect); |
| 431 TilePriority priority( | 363 TilePriority priority( |
| 432 resolution_, | 364 resolution_, |
| 433 time_to_visible_in_seconds, | 365 time_to_visible_in_seconds, |
| 434 distance_to_visible_in_pixels); | 366 distance_to_visible_in_pixels); |
| 435 if (store_screen_space_quads_on_tiles) | 367 if (store_screen_space_quads_on_tiles) |
| 436 priority.set_current_screen_quad(gfx::QuadF(current_screen_rect)); | 368 priority.set_current_screen_quad(gfx::QuadF(current_screen_rect)); |
| 437 tile->SetPriority(tree, priority); | 369 tile->SetPriority(tree, priority); |
| 438 } | 370 } |
| 439 } else { | 371 } else { |
| 440 for (TilingData::Iterator iter(&tiling_data_, prioritized_rect); | 372 for (TilingData::Iterator iter(&tiling_data_, interest_rect); |
| 441 iter; ++iter) { | 373 iter; ++iter) { |
| 442 TileMap::iterator find = tiles_.find(iter.index()); | 374 TileMap::iterator find = tiles_.find(iter.index()); |
| 443 if (find == tiles_.end()) | 375 if (find == tiles_.end()) |
| 444 continue; | 376 continue; |
| 445 Tile* tile = find->second.get(); | 377 Tile* tile = find->second.get(); |
| 446 | 378 |
| 447 gfx::Rect tile_bounds = | 379 gfx::Rect tile_bounds = |
| 448 tiling_data_.TileBounds(iter.index_x(), iter.index_y()); | 380 tiling_data_.TileBounds(iter.index_x(), iter.index_y()); |
| 449 gfx::RectF current_layer_content_rect = gfx::ScaleRect( | 381 gfx::RectF current_layer_content_rect = gfx::ScaleRect( |
| 450 tile_bounds, | 382 tile_bounds, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 478 &clipped)); | 410 &clipped)); |
| 479 } | 411 } |
| 480 tile->SetPriority(tree, priority); | 412 tile->SetPriority(tree, priority); |
| 481 } | 413 } |
| 482 } | 414 } |
| 483 | 415 |
| 484 last_source_frame_number_ = current_source_frame_number; | 416 last_source_frame_number_ = current_source_frame_number; |
| 485 last_impl_frame_time_ = current_frame_time; | 417 last_impl_frame_time_ = current_frame_time; |
| 486 } | 418 } |
| 487 | 419 |
| 420 void PictureLayerTiling::SetLiveTilesRect( |
| 421 const gfx::Rect& new_live_tiles_rect) { |
| 422 if (live_tiles_rect_ == new_live_tiles_rect) |
| 423 return; |
| 424 |
| 425 // Iterate to delete all tiles outside of our new live_tiles rect. |
| 426 for (TilingData::DifferenceIterator iter(&tiling_data_, |
| 427 live_tiles_rect_, |
| 428 new_live_tiles_rect); |
| 429 iter; |
| 430 ++iter) { |
| 431 TileMapKey key(iter.index()); |
| 432 TileMap::iterator found = tiles_.find(key); |
| 433 if (found != tiles_.end() && |
| 434 !new_live_tiles_rect.Intersects(found->second->content_rect())) |
| 435 tiles_.erase(found); |
| 436 } |
| 437 |
| 438 // Iterate to allocate new tiles for all regions with newly exposed area. |
| 439 for (TilingData::DifferenceIterator iter(&tiling_data_, |
| 440 new_live_tiles_rect, |
| 441 live_tiles_rect_); |
| 442 iter; |
| 443 ++iter) { |
| 444 TileMapKey key(iter.index()); |
| 445 TileMap::iterator found = tiles_.find(key); |
| 446 CreateTile(key.first, key.second); |
| 447 } |
| 448 |
| 449 live_tiles_rect_ = new_live_tiles_rect; |
| 450 } |
| 451 |
| 488 void PictureLayerTiling::DidBecomeActive() { | 452 void PictureLayerTiling::DidBecomeActive() { |
| 489 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 453 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
| 490 it->second->SetPriority(ACTIVE_TREE, it->second->priority(PENDING_TREE)); | 454 it->second->SetPriority(ACTIVE_TREE, it->second->priority(PENDING_TREE)); |
| 491 it->second->SetPriority(PENDING_TREE, TilePriority()); | 455 it->second->SetPriority(PENDING_TREE, TilePriority()); |
| 492 | 456 |
| 493 // Tile holds a ref onto a picture pile. If the tile never gets invalidated | 457 // Tile holds a ref onto a picture pile. If the tile never gets invalidated |
| 494 // and recreated, then that picture pile ref could exist indefinitely. To | 458 // and recreated, then that picture pile ref could exist indefinitely. To |
| 495 // prevent this, ask the client to update the pile to its own ref. This | 459 // prevent this, ask the client to update the pile to its own ref. This |
| 496 // will cause PicturePileImpls and their clones to get deleted once the | 460 // will cause PicturePileImpls and their clones to get deleted once the |
| 497 // corresponding PictureLayerImpl and any in flight raster jobs go out of | 461 // corresponding PictureLayerImpl and any in flight raster jobs go out of |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 | 567 |
| 604 // If our delta is less then our event distance, we're done. | 568 // If our delta is less then our event distance, we're done. |
| 605 if (delta < event.distance) | 569 if (delta < event.distance) |
| 606 break; | 570 break; |
| 607 } | 571 } |
| 608 | 572 |
| 609 return gfx::Rect(origin_x, origin_y, width, height); | 573 return gfx::Rect(origin_x, origin_y, width, height); |
| 610 } | 574 } |
| 611 | 575 |
| 612 } // namespace cc | 576 } // namespace cc |
| OLD | NEW |