| 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/layers/picture_layer_impl.h" | 5 #include "cc/layers/picture_layer_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 // tiling's scale if the desired scale is within this ratio. | 33 // tiling's scale if the desired scale is within this ratio. |
| 34 const float kSnapToExistingTilingRatio = 0.2f; | 34 const float kSnapToExistingTilingRatio = 0.2f; |
| 35 } | 35 } |
| 36 | 36 |
| 37 namespace cc { | 37 namespace cc { |
| 38 | 38 |
| 39 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, int id) | 39 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, int id) |
| 40 : LayerImpl(tree_impl, id), | 40 : LayerImpl(tree_impl, id), |
| 41 twin_layer_(NULL), | 41 twin_layer_(NULL), |
| 42 pile_(PicturePileImpl::Create()), | 42 pile_(PicturePileImpl::Create()), |
| 43 last_content_scale_(0), | |
| 44 is_mask_(false), | 43 is_mask_(false), |
| 45 ideal_page_scale_(0.f), | 44 ideal_page_scale_(0.f), |
| 46 ideal_device_scale_(0.f), | 45 ideal_device_scale_(0.f), |
| 47 ideal_source_scale_(0.f), | 46 ideal_source_scale_(0.f), |
| 48 ideal_contents_scale_(0.f), | 47 ideal_contents_scale_(0.f), |
| 49 raster_page_scale_(0.f), | 48 raster_page_scale_(0.f), |
| 50 raster_device_scale_(0.f), | 49 raster_device_scale_(0.f), |
| 51 raster_source_scale_(0.f), | 50 raster_source_scale_(0.f), |
| 52 raster_contents_scale_(0.f), | 51 raster_contents_scale_(0.f), |
| 53 low_res_raster_contents_scale_(0.f), | 52 low_res_raster_contents_scale_(0.f), |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 current_frame_time_in_seconds)) { | 326 current_frame_time_in_seconds)) { |
| 328 tiling_needs_update = true; | 327 tiling_needs_update = true; |
| 329 break; | 328 break; |
| 330 } | 329 } |
| 331 } | 330 } |
| 332 if (!tiling_needs_update) | 331 if (!tiling_needs_update) |
| 333 return; | 332 return; |
| 334 | 333 |
| 335 UpdateLCDTextStatus(can_use_lcd_text()); | 334 UpdateLCDTextStatus(can_use_lcd_text()); |
| 336 | 335 |
| 337 gfx::Transform current_screen_space_transform = screen_space_transform(); | 336 gfx::Size viewport_size = layer_tree_impl()->DrawViewportSize(); |
| 338 | 337 |
| 339 gfx::Size viewport_size = layer_tree_impl()->DrawViewportSize(); | 338 // Use visible_content_rect, unless it's empty. If it's empty, then |
| 340 gfx::Rect viewport_in_content_space; | 339 // try to inverse project the viewport into layer space and use that. |
| 341 gfx::Transform screen_to_layer(gfx::Transform::kSkipInitialization); | 340 gfx::Rect visible_rect_in_content_space = visible_content_rect(); |
| 342 if (screen_space_transform().GetInverse(&screen_to_layer)) { | 341 if (visible_rect_in_content_space.IsEmpty()) { |
| 343 viewport_in_content_space = | 342 gfx::Transform screen_to_layer(gfx::Transform::kSkipInitialization); |
| 344 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( | 343 if (screen_space_transform().GetInverse(&screen_to_layer)) { |
| 345 screen_to_layer, gfx::Rect(viewport_size))); | 344 visible_rect_in_content_space = |
| 345 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( |
| 346 screen_to_layer, gfx::Rect(viewport_size))); |
| 347 } |
| 346 } | 348 } |
| 347 | 349 |
| 348 WhichTree tree = | 350 WhichTree tree = |
| 349 layer_tree_impl()->IsActiveTree() ? ACTIVE_TREE : PENDING_TREE; | 351 layer_tree_impl()->IsActiveTree() ? ACTIVE_TREE : PENDING_TREE; |
| 350 size_t max_tiles_for_interest_area = | 352 |
| 351 layer_tree_impl()->settings().max_tiles_for_interest_area; | |
| 352 tilings_->UpdateTilePriorities( | 353 tilings_->UpdateTilePriorities( |
| 353 tree, | 354 tree, |
| 354 viewport_size, | 355 visible_rect_in_content_space, |
| 355 viewport_in_content_space, | |
| 356 visible_content_rect(), | |
| 357 last_bounds_, | |
| 358 bounds(), | |
| 359 last_content_scale_, | |
| 360 contents_scale_x(), | 356 contents_scale_x(), |
| 361 last_screen_space_transform_, | 357 current_frame_time_in_seconds); |
| 362 current_screen_space_transform, | |
| 363 current_frame_time_in_seconds, | |
| 364 max_tiles_for_interest_area); | |
| 365 | 358 |
| 366 if (layer_tree_impl()->IsPendingTree()) | 359 if (layer_tree_impl()->IsPendingTree()) |
| 367 MarkVisibleResourcesAsRequired(); | 360 MarkVisibleResourcesAsRequired(); |
| 368 | 361 |
| 369 last_screen_space_transform_ = current_screen_space_transform; | |
| 370 last_bounds_ = bounds(); | |
| 371 last_content_scale_ = contents_scale_x(); | |
| 372 | |
| 373 // Tile priorities were modified. | 362 // Tile priorities were modified. |
| 374 layer_tree_impl()->DidModifyTilePriorities(); | 363 layer_tree_impl()->DidModifyTilePriorities(); |
| 375 } | 364 } |
| 376 | 365 |
| 377 void PictureLayerImpl::DidBecomeActive() { | 366 void PictureLayerImpl::DidBecomeActive() { |
| 378 LayerImpl::DidBecomeActive(); | 367 LayerImpl::DidBecomeActive(); |
| 379 tilings_->DidBecomeActive(); | 368 tilings_->DidBecomeActive(); |
| 380 layer_tree_impl()->DidModifyTilePriorities(); | 369 layer_tree_impl()->DidModifyTilePriorities(); |
| 381 } | 370 } |
| 382 | 371 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 if (!twin_layer_ || twin_layer_->should_use_gpu_rasterization() != | 495 if (!twin_layer_ || twin_layer_->should_use_gpu_rasterization() != |
| 507 should_use_gpu_rasterization()) | 496 should_use_gpu_rasterization()) |
| 508 return NULL; | 497 return NULL; |
| 509 for (size_t i = 0; i < twin_layer_->tilings_->num_tilings(); ++i) | 498 for (size_t i = 0; i < twin_layer_->tilings_->num_tilings(); ++i) |
| 510 if (twin_layer_->tilings_->tiling_at(i)->contents_scale() == | 499 if (twin_layer_->tilings_->tiling_at(i)->contents_scale() == |
| 511 tiling->contents_scale()) | 500 tiling->contents_scale()) |
| 512 return twin_layer_->tilings_->tiling_at(i); | 501 return twin_layer_->tilings_->tiling_at(i); |
| 513 return NULL; | 502 return NULL; |
| 514 } | 503 } |
| 515 | 504 |
| 505 size_t PictureLayerImpl::GetMaxTilesForInterestArea() const { |
| 506 return layer_tree_impl()->settings().max_tiles_for_interest_area; |
| 507 } |
| 508 |
| 509 float PictureLayerImpl::GetSkewportTargetTimeInSeconds() const { |
| 510 return layer_tree_impl()->settings().skewport_target_time_in_seconds; |
| 511 } |
| 512 |
| 516 gfx::Size PictureLayerImpl::CalculateTileSize( | 513 gfx::Size PictureLayerImpl::CalculateTileSize( |
| 517 const gfx::Size& content_bounds) const { | 514 const gfx::Size& content_bounds) const { |
| 518 if (is_mask_) { | 515 if (is_mask_) { |
| 519 int max_size = layer_tree_impl()->MaxTextureSize(); | 516 int max_size = layer_tree_impl()->MaxTextureSize(); |
| 520 return gfx::Size( | 517 return gfx::Size( |
| 521 std::min(max_size, content_bounds.width()), | 518 std::min(max_size, content_bounds.width()), |
| 522 std::min(max_size, content_bounds.height())); | 519 std::min(max_size, content_bounds.height())); |
| 523 } | 520 } |
| 524 | 521 |
| 525 int max_texture_size = | 522 int max_texture_size = |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 continue; | 713 continue; |
| 717 } | 714 } |
| 718 for (PictureLayerTiling::CoverageIterator iter(tiling, | 715 for (PictureLayerTiling::CoverageIterator iter(tiling, |
| 719 contents_scale_x(), | 716 contents_scale_x(), |
| 720 rect); | 717 rect); |
| 721 iter; | 718 iter; |
| 722 ++iter) { | 719 ++iter) { |
| 723 if (!*iter || !iter->IsReadyToDraw()) | 720 if (!*iter || !iter->IsReadyToDraw()) |
| 724 continue; | 721 continue; |
| 725 | 722 |
| 726 // This iteration is over the visible content rect which is potentially | |
| 727 // less conservative than projecting the viewport into the layer. | |
| 728 // Ignore tiles that are know to be outside the viewport. | |
| 729 if (iter->priority(PENDING_TREE).distance_to_visible_in_pixels != 0) | |
| 730 continue; | |
| 731 | |
| 732 missing_region.Subtract(iter.geometry_rect()); | 723 missing_region.Subtract(iter.geometry_rect()); |
| 733 iter->MarkRequiredForActivation(); | 724 iter->MarkRequiredForActivation(); |
| 734 } | 725 } |
| 735 } | 726 } |
| 736 DCHECK(high_res) << "There must be one high res tiling"; | 727 DCHECK(high_res) << "There must be one high res tiling"; |
| 737 | 728 |
| 738 // If these pointers are null (because no twin, no matching tiling, or the | 729 // If these pointers are null (because no twin, no matching tiling, or the |
| 739 // simpification just below), then high res tiles will be required to fill any | 730 // simpification just below), then high res tiles will be required to fill any |
| 740 // holes left by the first pass above. If the pointers are valid, then this | 731 // holes left by the first pass above. If the pointers are valid, then this |
| 741 // layer is allowed to skip any tiles that are not ready on its twin. | 732 // layer is allowed to skip any tiles that are not ready on its twin. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 for (PictureLayerTiling::CoverageIterator iter(tiling, | 776 for (PictureLayerTiling::CoverageIterator iter(tiling, |
| 786 contents_scale, | 777 contents_scale, |
| 787 rect); | 778 rect); |
| 788 iter; | 779 iter; |
| 789 ++iter) { | 780 ++iter) { |
| 790 Tile* tile = *iter; | 781 Tile* tile = *iter; |
| 791 // A null tile (i.e. missing recording) can just be skipped. | 782 // A null tile (i.e. missing recording) can just be skipped. |
| 792 if (!tile) | 783 if (!tile) |
| 793 continue; | 784 continue; |
| 794 | 785 |
| 795 // This iteration is over the visible content rect which is potentially | |
| 796 // less conservative than projecting the viewport into the layer. | |
| 797 // Ignore tiles that are know to be outside the viewport. | |
| 798 if (tile->priority(PENDING_TREE).distance_to_visible_in_pixels != 0) | |
| 799 continue; | |
| 800 | |
| 801 // If the missing region doesn't cover it, this tile is fully | 786 // If the missing region doesn't cover it, this tile is fully |
| 802 // covered by acceptable tiles at other scales. | 787 // covered by acceptable tiles at other scales. |
| 803 if (!missing_region.Intersects(iter.geometry_rect())) | 788 if (!missing_region.Intersects(iter.geometry_rect())) |
| 804 continue; | 789 continue; |
| 805 | 790 |
| 806 // If the twin tile doesn't exist (i.e. missing recording or so far away | 791 // If the twin tile doesn't exist (i.e. missing recording or so far away |
| 807 // that it is outside the visible tile rect) or this tile is shared between | 792 // that it is outside the visible tile rect) or this tile is shared between |
| 808 // with the twin, then this tile isn't required to prevent flashing. | 793 // with the twin, then this tile isn't required to prevent flashing. |
| 809 if (optional_twin_tiling) { | 794 if (optional_twin_tiling) { |
| 810 Tile* twin_tile = optional_twin_tiling->TileAt(iter.i(), iter.j()); | 795 Tile* twin_tile = optional_twin_tiling->TileAt(iter.i(), iter.j()); |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1231 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const { | 1216 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const { |
| 1232 const_cast<PictureLayerImpl*>(this)->DoPostCommitInitializationIfNeeded(); | 1217 const_cast<PictureLayerImpl*>(this)->DoPostCommitInitializationIfNeeded(); |
| 1233 return tilings_->GPUMemoryUsageInBytes(); | 1218 return tilings_->GPUMemoryUsageInBytes(); |
| 1234 } | 1219 } |
| 1235 | 1220 |
| 1236 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { | 1221 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { |
| 1237 benchmark->RunOnLayer(this); | 1222 benchmark->RunOnLayer(this); |
| 1238 } | 1223 } |
| 1239 | 1224 |
| 1240 } // namespace cc | 1225 } // namespace cc |
| OLD | NEW |