| 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 | 10 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 client)); | 46 client)); |
| 47 } | 47 } |
| 48 | 48 |
| 49 PictureLayerTiling::PictureLayerTiling(float contents_scale, | 49 PictureLayerTiling::PictureLayerTiling(float contents_scale, |
| 50 const gfx::Size& layer_bounds, | 50 const gfx::Size& layer_bounds, |
| 51 PictureLayerTilingClient* client) | 51 PictureLayerTilingClient* client) |
| 52 : contents_scale_(contents_scale), | 52 : contents_scale_(contents_scale), |
| 53 layer_bounds_(layer_bounds), | 53 layer_bounds_(layer_bounds), |
| 54 resolution_(NON_IDEAL_RESOLUTION), | 54 resolution_(NON_IDEAL_RESOLUTION), |
| 55 client_(client), | 55 client_(client), |
| 56 tiling_data_(gfx::Size(), gfx::Size(), true), | 56 tiling_data_(gfx::Size(), gfx::Rect(), true), |
| 57 last_impl_frame_time_in_seconds_(0.0), | 57 last_impl_frame_time_in_seconds_(0.0), |
| 58 eviction_tiles_cache_valid_(false) { | 58 eviction_tiles_cache_valid_(false) { |
| 59 gfx::Size content_bounds = | 59 gfx::Size content_bounds = |
| 60 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale)); | 60 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds, contents_scale)); |
| 61 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); | 61 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); |
| 62 | 62 |
| 63 DCHECK(!gfx::ToFlooredSize( | 63 DCHECK(!gfx::ToFlooredSize( |
| 64 gfx::ScaleSize(layer_bounds, contents_scale)).IsEmpty()) << | 64 gfx::ScaleSize(layer_bounds, contents_scale)).IsEmpty()) << |
| 65 "Tiling created with scale too small as contents become empty." << | 65 "Tiling created with scale too small as contents become empty." << |
| 66 " Layer bounds: " << layer_bounds.ToString() << | 66 " Layer bounds: " << layer_bounds.ToString() << |
| 67 " Contents scale: " << contents_scale; | 67 " Contents scale: " << contents_scale; |
| 68 | 68 |
| 69 tiling_data_.SetTotalSize(content_bounds); | 69 tiling_data_.SetTilingRect(gfx::Rect(content_bounds)); |
| 70 tiling_data_.SetMaxTextureSize(tile_size); | 70 tiling_data_.SetMaxTextureSize(tile_size); |
| 71 } | 71 } |
| 72 | 72 |
| 73 PictureLayerTiling::~PictureLayerTiling() { | 73 PictureLayerTiling::~PictureLayerTiling() { |
| 74 } | 74 } |
| 75 | 75 |
| 76 void PictureLayerTiling::SetClient(PictureLayerTilingClient* client) { | 76 void PictureLayerTiling::SetClient(PictureLayerTilingClient* client) { |
| 77 client_ = client; | 77 client_ = client; |
| 78 } | 78 } |
| 79 | 79 |
| 80 gfx::Rect PictureLayerTiling::ContentRect() const { | 80 gfx::Rect PictureLayerTiling::TilingRect() const { |
| 81 return gfx::Rect(tiling_data_.total_size()); | 81 return tiling_data_.tiling_rect(); |
| 82 } | |
| 83 | |
| 84 gfx::SizeF PictureLayerTiling::ContentSizeF() const { | |
| 85 return gfx::ScaleSize(layer_bounds_, contents_scale_); | |
| 86 } | 82 } |
| 87 | 83 |
| 88 Tile* PictureLayerTiling::CreateTile(int i, | 84 Tile* PictureLayerTiling::CreateTile(int i, |
| 89 int j, | 85 int j, |
| 90 const PictureLayerTiling* twin_tiling) { | 86 const PictureLayerTiling* twin_tiling) { |
| 91 TileMapKey key(i, j); | 87 TileMapKey key(i, j); |
| 92 DCHECK(tiles_.find(key) == tiles_.end()); | 88 DCHECK(tiles_.find(key) == tiles_.end()); |
| 93 | 89 |
| 94 gfx::Rect paint_rect = tiling_data_.TileBoundsWithBorder(i, j); | 90 gfx::Rect paint_rect = tiling_data_.TileBoundsWithBorder(i, j); |
| 95 gfx::Rect tile_rect = paint_rect; | 91 gfx::Rect tile_rect = paint_rect; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 } | 140 } |
| 145 | 141 |
| 146 void PictureLayerTiling::SetLayerBounds(const gfx::Size& layer_bounds) { | 142 void PictureLayerTiling::SetLayerBounds(const gfx::Size& layer_bounds) { |
| 147 if (layer_bounds_ == layer_bounds) | 143 if (layer_bounds_ == layer_bounds) |
| 148 return; | 144 return; |
| 149 | 145 |
| 150 DCHECK(!layer_bounds.IsEmpty()); | 146 DCHECK(!layer_bounds.IsEmpty()); |
| 151 | 147 |
| 152 gfx::Size old_layer_bounds = layer_bounds_; | 148 gfx::Size old_layer_bounds = layer_bounds_; |
| 153 layer_bounds_ = layer_bounds; | 149 layer_bounds_ = layer_bounds; |
| 154 gfx::Size old_content_bounds = tiling_data_.total_size(); | |
| 155 gfx::Size content_bounds = | 150 gfx::Size content_bounds = |
| 156 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds_, contents_scale_)); | 151 gfx::ToCeiledSize(gfx::ScaleSize(layer_bounds_, contents_scale_)); |
| 157 | 152 |
| 158 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); | 153 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); |
| 159 if (tile_size != tiling_data_.max_texture_size()) { | 154 if (tile_size != tiling_data_.max_texture_size()) { |
| 160 tiling_data_.SetTotalSize(content_bounds); | 155 tiling_data_.SetTilingRect(gfx::Rect(content_bounds)); |
| 161 tiling_data_.SetMaxTextureSize(tile_size); | 156 tiling_data_.SetMaxTextureSize(tile_size); |
| 162 Reset(); | 157 Reset(); |
| 163 return; | 158 return; |
| 164 } | 159 } |
| 165 | 160 |
| 166 // Any tiles outside our new bounds are invalid and should be dropped. | 161 // Any tiles outside our new bounds are invalid and should be dropped. |
| 167 gfx::Rect bounded_live_tiles_rect(live_tiles_rect_); | 162 gfx::Rect bounded_live_tiles_rect(live_tiles_rect_); |
| 168 bounded_live_tiles_rect.Intersect(gfx::Rect(content_bounds)); | 163 bounded_live_tiles_rect.Intersect(gfx::Rect(content_bounds)); |
| 169 SetLiveTilesRect(bounded_live_tiles_rect); | 164 SetLiveTilesRect(bounded_live_tiles_rect); |
| 170 tiling_data_.SetTotalSize(content_bounds); | 165 tiling_data_.SetTilingRect(gfx::Rect(content_bounds)); |
| 171 | 166 |
| 172 // Create tiles for newly exposed areas. | 167 // Create tiles for newly exposed areas. |
| 173 Region layer_region((gfx::Rect(layer_bounds_))); | 168 Region layer_region((gfx::Rect(layer_bounds_))); |
| 174 layer_region.Subtract(gfx::Rect(old_layer_bounds)); | 169 layer_region.Subtract(gfx::Rect(old_layer_bounds)); |
| 175 Invalidate(layer_region); | 170 Invalidate(layer_region); |
| 176 } | 171 } |
| 177 | 172 |
| 178 void PictureLayerTiling::Invalidate(const Region& layer_region) { | 173 void PictureLayerTiling::Invalidate(const Region& layer_region) { |
| 179 std::vector<TileMapKey> new_tile_keys; | 174 std::vector<TileMapKey> new_tile_keys; |
| 180 for (Region::Iterator iter(layer_region); iter.has_rect(); iter.next()) { | 175 for (Region::Iterator iter(layer_region); iter.has_rect(); iter.next()) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 tile_j_(0), | 221 tile_j_(0), |
| 227 left_(0), | 222 left_(0), |
| 228 top_(0), | 223 top_(0), |
| 229 right_(-1), | 224 right_(-1), |
| 230 bottom_(-1) { | 225 bottom_(-1) { |
| 231 DCHECK(tiling_); | 226 DCHECK(tiling_); |
| 232 if (dest_rect_.IsEmpty()) | 227 if (dest_rect_.IsEmpty()) |
| 233 return; | 228 return; |
| 234 | 229 |
| 235 dest_to_content_scale_ = tiling_->contents_scale_ / dest_scale; | 230 dest_to_content_scale_ = tiling_->contents_scale_ / dest_scale; |
| 236 // This is the maximum size that the dest rect can be, given the content size. | |
| 237 gfx::Size dest_content_size = gfx::ToCeiledSize(gfx::ScaleSize( | |
| 238 tiling_->ContentRect().size(), | |
| 239 1 / dest_to_content_scale_, | |
| 240 1 / dest_to_content_scale_)); | |
| 241 | 231 |
| 242 gfx::Rect content_rect = | 232 gfx::Rect content_rect = |
| 243 gfx::ScaleToEnclosingRect(dest_rect_, | 233 gfx::ScaleToEnclosingRect(dest_rect_, |
| 244 dest_to_content_scale_, | 234 dest_to_content_scale_, |
| 245 dest_to_content_scale_); | 235 dest_to_content_scale_); |
| 246 // IndexFromSrcCoord clamps to valid tile ranges, so it's necessary to | 236 // IndexFromSrcCoord clamps to valid tile ranges, so it's necessary to |
| 247 // check for non-intersection first. | 237 // check for non-intersection first. |
| 248 content_rect.Intersect(gfx::Rect(tiling_->tiling_data_.total_size())); | 238 content_rect.Intersect(tiling_->TilingRect()); |
| 249 if (content_rect.IsEmpty()) | 239 if (content_rect.IsEmpty()) |
| 250 return; | 240 return; |
| 251 | 241 |
| 252 left_ = tiling_->tiling_data_.TileXIndexFromSrcCoord(content_rect.x()); | 242 left_ = tiling_->tiling_data_.TileXIndexFromSrcCoord(content_rect.x()); |
| 253 top_ = tiling_->tiling_data_.TileYIndexFromSrcCoord(content_rect.y()); | 243 top_ = tiling_->tiling_data_.TileYIndexFromSrcCoord(content_rect.y()); |
| 254 right_ = tiling_->tiling_data_.TileXIndexFromSrcCoord( | 244 right_ = tiling_->tiling_data_.TileXIndexFromSrcCoord( |
| 255 content_rect.right() - 1); | 245 content_rect.right() - 1); |
| 256 bottom_ = tiling_->tiling_data_.TileYIndexFromSrcCoord( | 246 bottom_ = tiling_->tiling_data_.TileYIndexFromSrcCoord( |
| 257 content_rect.bottom() - 1); | 247 content_rect.bottom() - 1); |
| 258 | 248 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 | 330 |
| 341 gfx::RectF PictureLayerTiling::CoverageIterator::texture_rect() const { | 331 gfx::RectF PictureLayerTiling::CoverageIterator::texture_rect() const { |
| 342 gfx::PointF tex_origin = | 332 gfx::PointF tex_origin = |
| 343 tiling_->tiling_data_.TileBoundsWithBorder(tile_i_, tile_j_).origin(); | 333 tiling_->tiling_data_.TileBoundsWithBorder(tile_i_, tile_j_).origin(); |
| 344 | 334 |
| 345 // Convert from dest space => content space => texture space. | 335 // Convert from dest space => content space => texture space. |
| 346 gfx::RectF texture_rect(current_geometry_rect_); | 336 gfx::RectF texture_rect(current_geometry_rect_); |
| 347 texture_rect.Scale(dest_to_content_scale_, | 337 texture_rect.Scale(dest_to_content_scale_, |
| 348 dest_to_content_scale_); | 338 dest_to_content_scale_); |
| 349 texture_rect.Offset(-tex_origin.OffsetFromOrigin()); | 339 texture_rect.Offset(-tex_origin.OffsetFromOrigin()); |
| 350 texture_rect.Intersect(tiling_->ContentRect()); | 340 texture_rect.Intersect(tiling_->TilingRect()); |
| 351 | 341 |
| 352 return texture_rect; | 342 return texture_rect; |
| 353 } | 343 } |
| 354 | 344 |
| 355 gfx::Size PictureLayerTiling::CoverageIterator::texture_size() const { | 345 gfx::Size PictureLayerTiling::CoverageIterator::texture_size() const { |
| 356 return tiling_->tiling_data_.max_texture_size(); | 346 return tiling_->tiling_data_.max_texture_size(); |
| 357 } | 347 } |
| 358 | 348 |
| 359 void PictureLayerTiling::Reset() { | 349 void PictureLayerTiling::Reset() { |
| 360 live_tiles_rect_ = gfx::Rect(); | 350 live_tiles_rect_ = gfx::Rect(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 double current_frame_time_in_seconds) { | 406 double current_frame_time_in_seconds) { |
| 417 if (!NeedsUpdateForFrameAtTime(current_frame_time_in_seconds)) { | 407 if (!NeedsUpdateForFrameAtTime(current_frame_time_in_seconds)) { |
| 418 // This should never be zero for the purposes of has_ever_been_updated(). | 408 // This should never be zero for the purposes of has_ever_been_updated(). |
| 419 DCHECK_NE(current_frame_time_in_seconds, 0.0); | 409 DCHECK_NE(current_frame_time_in_seconds, 0.0); |
| 420 return; | 410 return; |
| 421 } | 411 } |
| 422 | 412 |
| 423 gfx::Rect visible_rect_in_content_space = | 413 gfx::Rect visible_rect_in_content_space = |
| 424 gfx::ScaleToEnclosingRect(visible_layer_rect, contents_scale_); | 414 gfx::ScaleToEnclosingRect(visible_layer_rect, contents_scale_); |
| 425 | 415 |
| 426 if (ContentRect().IsEmpty()) { | 416 if (TilingRect().IsEmpty()) { |
| 427 last_impl_frame_time_in_seconds_ = current_frame_time_in_seconds; | 417 last_impl_frame_time_in_seconds_ = current_frame_time_in_seconds; |
| 428 last_visible_rect_in_content_space_ = visible_rect_in_content_space; | 418 last_visible_rect_in_content_space_ = visible_rect_in_content_space; |
| 429 return; | 419 return; |
| 430 } | 420 } |
| 431 | 421 |
| 432 size_t max_tiles_for_interest_area = client_->GetMaxTilesForInterestArea(); | 422 size_t max_tiles_for_interest_area = client_->GetMaxTilesForInterestArea(); |
| 433 | 423 |
| 434 gfx::Size tile_size = tiling_data_.max_texture_size(); | 424 gfx::Size tile_size = tiling_data_.max_texture_size(); |
| 435 int64 eventually_rect_area = | 425 int64 eventually_rect_area = |
| 436 max_tiles_for_interest_area * tile_size.width() * tile_size.height(); | 426 max_tiles_for_interest_area * tile_size.width() * tile_size.height(); |
| 437 | 427 |
| 438 gfx::Rect skewport = ComputeSkewport(current_frame_time_in_seconds, | 428 gfx::Rect skewport = ComputeSkewport(current_frame_time_in_seconds, |
| 439 visible_rect_in_content_space); | 429 visible_rect_in_content_space); |
| 440 DCHECK(skewport.Contains(visible_rect_in_content_space)); | 430 DCHECK(skewport.Contains(visible_rect_in_content_space)); |
| 441 | 431 |
| 442 gfx::Rect eventually_rect = | 432 gfx::Rect eventually_rect = |
| 443 ExpandRectEquallyToAreaBoundedBy(visible_rect_in_content_space, | 433 ExpandRectEquallyToAreaBoundedBy(visible_rect_in_content_space, |
| 444 eventually_rect_area, | 434 eventually_rect_area, |
| 445 ContentRect(), | 435 TilingRect(), |
| 446 &expansion_cache_); | 436 &expansion_cache_); |
| 447 | 437 |
| 448 DCHECK(eventually_rect.IsEmpty() || ContentRect().Contains(eventually_rect)); | 438 DCHECK(eventually_rect.IsEmpty() || TilingRect().Contains(eventually_rect)); |
| 449 | 439 |
| 450 SetLiveTilesRect(eventually_rect); | 440 SetLiveTilesRect(eventually_rect); |
| 451 | 441 |
| 452 last_impl_frame_time_in_seconds_ = current_frame_time_in_seconds; | 442 last_impl_frame_time_in_seconds_ = current_frame_time_in_seconds; |
| 453 last_visible_rect_in_content_space_ = visible_rect_in_content_space; | 443 last_visible_rect_in_content_space_ = visible_rect_in_content_space; |
| 454 | 444 |
| 455 current_visible_rect_in_content_space_ = visible_rect_in_content_space; | 445 current_visible_rect_in_content_space_ = visible_rect_in_content_space; |
| 456 current_skewport_ = skewport; | 446 current_skewport_ = skewport; |
| 457 current_eventually_rect_ = eventually_rect; | 447 current_eventually_rect_ = eventually_rect; |
| 458 eviction_tiles_cache_valid_ = false; | 448 eviction_tiles_cache_valid_ = false; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 content_to_screen_scale; | 504 content_to_screen_scale; |
| 515 TilePriority priority( | 505 TilePriority priority( |
| 516 resolution_, TilePriority::EVENTUALLY, distance_to_visible); | 506 resolution_, TilePriority::EVENTUALLY, distance_to_visible); |
| 517 tile->SetPriority(tree, priority); | 507 tile->SetPriority(tree, priority); |
| 518 } | 508 } |
| 519 } | 509 } |
| 520 | 510 |
| 521 void PictureLayerTiling::SetLiveTilesRect( | 511 void PictureLayerTiling::SetLiveTilesRect( |
| 522 const gfx::Rect& new_live_tiles_rect) { | 512 const gfx::Rect& new_live_tiles_rect) { |
| 523 DCHECK(new_live_tiles_rect.IsEmpty() || | 513 DCHECK(new_live_tiles_rect.IsEmpty() || |
| 524 ContentRect().Contains(new_live_tiles_rect)); | 514 TilingRect().Contains(new_live_tiles_rect)); |
| 525 if (live_tiles_rect_ == new_live_tiles_rect) | 515 if (live_tiles_rect_ == new_live_tiles_rect) |
| 526 return; | 516 return; |
| 527 | 517 |
| 528 // Iterate to delete all tiles outside of our new live_tiles rect. | 518 // Iterate to delete all tiles outside of our new live_tiles rect. |
| 529 for (TilingData::DifferenceIterator iter(&tiling_data_, | 519 for (TilingData::DifferenceIterator iter(&tiling_data_, |
| 530 live_tiles_rect_, | 520 live_tiles_rect_, |
| 531 new_live_tiles_rect); | 521 new_live_tiles_rect); |
| 532 iter; | 522 iter; |
| 533 ++iter) { | 523 ++iter) { |
| 534 TileMapKey key(iter.index()); | 524 TileMapKey key(iter.index()); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 void PictureLayerTiling::UpdateTilesToCurrentPile() { | 572 void PictureLayerTiling::UpdateTilesToCurrentPile() { |
| 583 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 573 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
| 584 client_->UpdatePile(it->second.get()); | 574 client_->UpdatePile(it->second.get()); |
| 585 } | 575 } |
| 586 } | 576 } |
| 587 | 577 |
| 588 scoped_ptr<base::Value> PictureLayerTiling::AsValue() const { | 578 scoped_ptr<base::Value> PictureLayerTiling::AsValue() const { |
| 589 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 579 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 590 state->SetInteger("num_tiles", tiles_.size()); | 580 state->SetInteger("num_tiles", tiles_.size()); |
| 591 state->SetDouble("content_scale", contents_scale_); | 581 state->SetDouble("content_scale", contents_scale_); |
| 592 state->Set("content_bounds", | 582 state->Set("tiling_rect", |
| 593 MathUtil::AsValue(ContentRect().size()).release()); | 583 MathUtil::AsValue(TilingRect()).release()); |
| 594 return state.PassAs<base::Value>(); | 584 return state.PassAs<base::Value>(); |
| 595 } | 585 } |
| 596 | 586 |
| 597 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const { | 587 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const { |
| 598 size_t amount = 0; | 588 size_t amount = 0; |
| 599 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 589 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
| 600 const Tile* tile = it->second.get(); | 590 const Tile* tile = it->second.get(); |
| 601 amount += tile->GPUMemoryUsageInBytes(); | 591 amount += tile->GPUMemoryUsageInBytes(); |
| 602 } | 592 } |
| 603 return amount; | 593 return amount; |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 tiling_->UpdateEvictionCacheIfNeeded(tree_); | 899 tiling_->UpdateEvictionCacheIfNeeded(tree_); |
| 910 tile_iterator_ = tiling_->eviction_tiles_cache_.begin(); | 900 tile_iterator_ = tiling_->eviction_tiles_cache_.begin(); |
| 911 is_valid_ = true; | 901 is_valid_ = true; |
| 912 if (tile_iterator_ != tiling_->eviction_tiles_cache_.end() && | 902 if (tile_iterator_ != tiling_->eviction_tiles_cache_.end() && |
| 913 !(*tile_iterator_)->HasResources()) { | 903 !(*tile_iterator_)->HasResources()) { |
| 914 ++(*this); | 904 ++(*this); |
| 915 } | 905 } |
| 916 } | 906 } |
| 917 | 907 |
| 918 } // namespace cc | 908 } // namespace cc |
| OLD | NEW |