| 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 // Use visible_content_rect, unless it's empty. If it's empty, then |
| 338 | 337 // try to inverse project the viewport into layer space and use that. |
| 339 gfx::Size viewport_size = layer_tree_impl()->DrawViewportSize(); | 338 gfx::Rect visible_rect_in_content_space = visible_content_rect(); |
| 340 gfx::Rect viewport_in_content_space; | 339 if (visible_rect_in_content_space.IsEmpty()) { |
| 341 gfx::Transform screen_to_layer(gfx::Transform::kSkipInitialization); | 340 gfx::Transform screen_to_layer(gfx::Transform::kSkipInitialization); |
| 342 if (screen_space_transform().GetInverse(&screen_to_layer)) { | 341 if (screen_space_transform().GetInverse(&screen_to_layer)) { |
| 343 viewport_in_content_space = | 342 gfx::Size viewport_size = layer_tree_impl()->DrawViewportSize(); |
| 344 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( | 343 visible_rect_in_content_space = |
| 345 screen_to_layer, gfx::Rect(viewport_size))); | 344 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( |
| 345 screen_to_layer, gfx::Rect(viewport_size))); |
| 346 visible_rect_in_content_space.Intersect(gfx::Rect(content_bounds())); |
| 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; | 353 tilings_->UpdateTilePriorities(tree, |
| 352 tilings_->UpdateTilePriorities( | 354 visible_rect_in_content_space, |
| 353 tree, | 355 contents_scale_x(), |
| 354 viewport_size, | 356 current_frame_time_in_seconds); |
| 355 viewport_in_content_space, | |
| 356 visible_content_rect(), | |
| 357 last_bounds_, | |
| 358 bounds(), | |
| 359 last_content_scale_, | |
| 360 contents_scale_x(), | |
| 361 last_screen_space_transform_, | |
| 362 current_screen_space_transform, | |
| 363 current_frame_time_in_seconds, | |
| 364 max_tiles_for_interest_area); | |
| 365 | 357 |
| 366 if (layer_tree_impl()->IsPendingTree()) | 358 if (layer_tree_impl()->IsPendingTree()) |
| 367 MarkVisibleResourcesAsRequired(); | 359 MarkVisibleResourcesAsRequired(); |
| 368 | 360 |
| 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. | 361 // Tile priorities were modified. |
| 374 layer_tree_impl()->DidModifyTilePriorities(); | 362 layer_tree_impl()->DidModifyTilePriorities(); |
| 375 } | 363 } |
| 376 | 364 |
| 377 void PictureLayerImpl::DidBecomeActive() { | 365 void PictureLayerImpl::DidBecomeActive() { |
| 378 LayerImpl::DidBecomeActive(); | 366 LayerImpl::DidBecomeActive(); |
| 379 tilings_->DidBecomeActive(); | 367 tilings_->DidBecomeActive(); |
| 380 layer_tree_impl()->DidModifyTilePriorities(); | 368 layer_tree_impl()->DidModifyTilePriorities(); |
| 381 } | 369 } |
| 382 | 370 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 if (!twin_layer_ || twin_layer_->should_use_gpu_rasterization() != | 494 if (!twin_layer_ || twin_layer_->should_use_gpu_rasterization() != |
| 507 should_use_gpu_rasterization()) | 495 should_use_gpu_rasterization()) |
| 508 return NULL; | 496 return NULL; |
| 509 for (size_t i = 0; i < twin_layer_->tilings_->num_tilings(); ++i) | 497 for (size_t i = 0; i < twin_layer_->tilings_->num_tilings(); ++i) |
| 510 if (twin_layer_->tilings_->tiling_at(i)->contents_scale() == | 498 if (twin_layer_->tilings_->tiling_at(i)->contents_scale() == |
| 511 tiling->contents_scale()) | 499 tiling->contents_scale()) |
| 512 return twin_layer_->tilings_->tiling_at(i); | 500 return twin_layer_->tilings_->tiling_at(i); |
| 513 return NULL; | 501 return NULL; |
| 514 } | 502 } |
| 515 | 503 |
| 504 size_t PictureLayerImpl::GetMaxTilesForInterestArea() const { |
| 505 return layer_tree_impl()->settings().max_tiles_for_interest_area; |
| 506 } |
| 507 |
| 508 float PictureLayerImpl::GetSkewportTargetTimeInSeconds() const { |
| 509 return layer_tree_impl()->settings().skewport_target_time_in_seconds; |
| 510 } |
| 511 |
| 512 int PictureLayerImpl::GetSkewportExtrapolationLimitInContentPixels() const { |
| 513 return layer_tree_impl() |
| 514 ->settings() |
| 515 .skewport_extrapolation_limit_in_content_pixels; |
| 516 } |
| 517 |
| 516 gfx::Size PictureLayerImpl::CalculateTileSize( | 518 gfx::Size PictureLayerImpl::CalculateTileSize( |
| 517 const gfx::Size& content_bounds) const { | 519 const gfx::Size& content_bounds) const { |
| 518 if (is_mask_) { | 520 if (is_mask_) { |
| 519 int max_size = layer_tree_impl()->MaxTextureSize(); | 521 int max_size = layer_tree_impl()->MaxTextureSize(); |
| 520 return gfx::Size( | 522 return gfx::Size( |
| 521 std::min(max_size, content_bounds.width()), | 523 std::min(max_size, content_bounds.width()), |
| 522 std::min(max_size, content_bounds.height())); | 524 std::min(max_size, content_bounds.height())); |
| 523 } | 525 } |
| 524 | 526 |
| 525 int max_texture_size = | 527 int max_texture_size = |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 continue; | 718 continue; |
| 717 } | 719 } |
| 718 for (PictureLayerTiling::CoverageIterator iter(tiling, | 720 for (PictureLayerTiling::CoverageIterator iter(tiling, |
| 719 contents_scale_x(), | 721 contents_scale_x(), |
| 720 rect); | 722 rect); |
| 721 iter; | 723 iter; |
| 722 ++iter) { | 724 ++iter) { |
| 723 if (!*iter || !iter->IsReadyToDraw()) | 725 if (!*iter || !iter->IsReadyToDraw()) |
| 724 continue; | 726 continue; |
| 725 | 727 |
| 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()); | 728 missing_region.Subtract(iter.geometry_rect()); |
| 733 iter->MarkRequiredForActivation(); | 729 iter->MarkRequiredForActivation(); |
| 734 } | 730 } |
| 735 } | 731 } |
| 736 DCHECK(high_res) << "There must be one high res tiling"; | 732 DCHECK(high_res) << "There must be one high res tiling"; |
| 737 | 733 |
| 738 // If these pointers are null (because no twin, no matching tiling, or the | 734 // 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 | 735 // 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 | 736 // 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. | 737 // layer is allowed to skip any tiles that are not ready on its twin. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 for (PictureLayerTiling::CoverageIterator iter(tiling, | 786 for (PictureLayerTiling::CoverageIterator iter(tiling, |
| 791 contents_scale, | 787 contents_scale, |
| 792 rect); | 788 rect); |
| 793 iter; | 789 iter; |
| 794 ++iter) { | 790 ++iter) { |
| 795 Tile* tile = *iter; | 791 Tile* tile = *iter; |
| 796 // A null tile (i.e. missing recording) can just be skipped. | 792 // A null tile (i.e. missing recording) can just be skipped. |
| 797 if (!tile) | 793 if (!tile) |
| 798 continue; | 794 continue; |
| 799 | 795 |
| 800 // This iteration is over the visible content rect which is potentially | |
| 801 // less conservative than projecting the viewport into the layer. | |
| 802 // Ignore tiles that are know to be outside the viewport. | |
| 803 if (tile->priority(PENDING_TREE).distance_to_visible_in_pixels != 0) | |
| 804 continue; | |
| 805 | |
| 806 // If the missing region doesn't cover it, this tile is fully | 796 // If the missing region doesn't cover it, this tile is fully |
| 807 // covered by acceptable tiles at other scales. | 797 // covered by acceptable tiles at other scales. |
| 808 if (!missing_region.Intersects(iter.geometry_rect())) | 798 if (!missing_region.Intersects(iter.geometry_rect())) |
| 809 continue; | 799 continue; |
| 810 | 800 |
| 811 // If the twin tile doesn't exist (i.e. missing recording or so far away | 801 // If the twin tile doesn't exist (i.e. missing recording or so far away |
| 812 // that it is outside the visible tile rect) or this tile is shared between | 802 // that it is outside the visible tile rect) or this tile is shared between |
| 813 // with the twin, then this tile isn't required to prevent flashing. | 803 // with the twin, then this tile isn't required to prevent flashing. |
| 814 if (optional_twin_tiling) { | 804 if (optional_twin_tiling) { |
| 815 Tile* twin_tile = optional_twin_tiling->TileAt(iter.i(), iter.j()); | 805 Tile* twin_tile = optional_twin_tiling->TileAt(iter.i(), iter.j()); |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1236 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const { | 1226 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const { |
| 1237 const_cast<PictureLayerImpl*>(this)->DoPostCommitInitializationIfNeeded(); | 1227 const_cast<PictureLayerImpl*>(this)->DoPostCommitInitializationIfNeeded(); |
| 1238 return tilings_->GPUMemoryUsageInBytes(); | 1228 return tilings_->GPUMemoryUsageInBytes(); |
| 1239 } | 1229 } |
| 1240 | 1230 |
| 1241 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { | 1231 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { |
| 1242 benchmark->RunOnLayer(this); | 1232 benchmark->RunOnLayer(this); |
| 1243 } | 1233 } |
| 1244 | 1234 |
| 1245 } // namespace cc | 1235 } // namespace cc |
| OLD | NEW |