| 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 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 low_res_raster_contents_scale_(0.f), | 83 low_res_raster_contents_scale_(0.f), |
| 84 raster_source_scale_is_fixed_(false), | 84 raster_source_scale_is_fixed_(false), |
| 85 was_screen_space_transform_animating_(false), | 85 was_screen_space_transform_animating_(false), |
| 86 needs_post_commit_initialization_(true), | 86 needs_post_commit_initialization_(true), |
| 87 should_update_tile_priorities_(false), | 87 should_update_tile_priorities_(false), |
| 88 only_used_low_res_last_append_quads_(false) { | 88 only_used_low_res_last_append_quads_(false) { |
| 89 layer_tree_impl()->RegisterPictureLayerImpl(this); | 89 layer_tree_impl()->RegisterPictureLayerImpl(this); |
| 90 } | 90 } |
| 91 | 91 |
| 92 PictureLayerImpl::~PictureLayerImpl() { | 92 PictureLayerImpl::~PictureLayerImpl() { |
| 93 if (twin_layer_) | |
| 94 twin_layer_->twin_layer_ = nullptr; | |
| 95 layer_tree_impl()->UnregisterPictureLayerImpl(this); | 93 layer_tree_impl()->UnregisterPictureLayerImpl(this); |
| 96 } | 94 } |
| 97 | 95 |
| 98 const char* PictureLayerImpl::LayerTypeAsString() const { | 96 const char* PictureLayerImpl::LayerTypeAsString() const { |
| 99 return "cc::PictureLayerImpl"; | 97 return "cc::PictureLayerImpl"; |
| 100 } | 98 } |
| 101 | 99 |
| 102 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl( | 100 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl( |
| 103 LayerTreeImpl* tree_impl) { | 101 LayerTreeImpl* tree_impl) { |
| 104 return PictureLayerImpl::Create(tree_impl, id()); | 102 return PictureLayerImpl::Create(tree_impl, id()); |
| 105 } | 103 } |
| 106 | 104 |
| 107 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { | 105 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { |
| 108 // It's possible this layer was never drawn or updated (e.g. because it was | 106 // It's possible this layer was never drawn or updated (e.g. because it was |
| 109 // a descendant of an opacity 0 layer). | 107 // a descendant of an opacity 0 layer). |
| 110 DoPostCommitInitializationIfNeeded(); | 108 DoPostCommitInitializationIfNeeded(); |
| 111 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); | 109 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); |
| 112 | 110 |
| 113 LayerImpl::PushPropertiesTo(base_layer); | 111 LayerImpl::PushPropertiesTo(base_layer); |
| 114 | 112 |
| 115 // Twin relationships should never change once established. | 113 // When the pending tree pushes to the active tree, the pending twin |
| 116 DCHECK_IMPLIES(twin_layer_, twin_layer_ == layer_impl); | 114 // becomes recycled. |
| 117 DCHECK_IMPLIES(twin_layer_, layer_impl->twin_layer_ == this); | 115 layer_impl->twin_layer_ = nullptr; |
| 118 // The twin relationship does not need to exist before the first | 116 twin_layer_ = nullptr; |
| 119 // PushPropertiesTo from pending to active layer since before that the active | |
| 120 // layer can not have a pile or tilings, it has only been created and inserted | |
| 121 // into the tree at that point. | |
| 122 twin_layer_ = layer_impl; | |
| 123 layer_impl->twin_layer_ = this; | |
| 124 | 117 |
| 125 layer_impl->pile_ = pile_; | 118 layer_impl->pile_ = pile_; |
| 126 | 119 |
| 127 DCHECK(!pile_->is_solid_color() || !tilings_->num_tilings()); | 120 DCHECK(!pile_->is_solid_color() || !tilings_->num_tilings()); |
| 128 // Tilings would be expensive to push, so we swap. | 121 // Tilings would be expensive to push, so we swap. |
| 129 layer_impl->tilings_.swap(tilings_); | 122 layer_impl->tilings_.swap(tilings_); |
| 130 layer_impl->tilings_->SetClient(layer_impl); | 123 layer_impl->tilings_->SetClient(layer_impl); |
| 131 if (tilings_) | 124 if (tilings_) |
| 132 tilings_->SetClient(this); | 125 tilings_->SetClient(this); |
| 133 | 126 |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 if (screen_space_transform().GetInverse(&view_to_layer)) { | 554 if (screen_space_transform().GetInverse(&view_to_layer)) { |
| 562 // Transform from view space to content space. | 555 // Transform from view space to content space. |
| 563 visible_rect_in_content_space = | 556 visible_rect_in_content_space = |
| 564 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( | 557 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( |
| 565 view_to_layer, viewport_rect_for_tile_priority)); | 558 view_to_layer, viewport_rect_for_tile_priority)); |
| 566 } | 559 } |
| 567 } | 560 } |
| 568 return visible_rect_in_content_space; | 561 return visible_rect_in_content_space; |
| 569 } | 562 } |
| 570 | 563 |
| 571 PictureLayerImpl* PictureLayerImpl::GetPendingOrActiveTwinLayer() const { | 564 PictureLayerImpl* PictureLayerImpl::GetRecycledTwinLayer() { |
| 572 if (!twin_layer_ || !twin_layer_->IsOnActiveOrPendingTree()) | 565 // TODO(vmpstr): Maintain recycled twin as a member. crbug.com/407418 |
| 573 return nullptr; | 566 return static_cast<PictureLayerImpl*>( |
| 574 return twin_layer_; | 567 layer_tree_impl()->FindRecycleTreeLayerById(id())); |
| 575 } | |
| 576 | |
| 577 PictureLayerImpl* PictureLayerImpl::GetRecycledTwinLayer() const { | |
| 578 if (!twin_layer_ || twin_layer_->IsOnActiveOrPendingTree()) | |
| 579 return nullptr; | |
| 580 return twin_layer_; | |
| 581 } | 568 } |
| 582 | 569 |
| 583 void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) { | 570 void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) { |
| 584 if (layer_tree_impl()->IsActiveTree()) { | 571 if (layer_tree_impl()->IsActiveTree()) { |
| 585 gfx::RectF layer_damage_rect = | 572 gfx::RectF layer_damage_rect = |
| 586 gfx::ScaleRect(tile->content_rect(), 1.f / tile->contents_scale()); | 573 gfx::ScaleRect(tile->content_rect(), 1.f / tile->contents_scale()); |
| 587 AddDamageRect(layer_damage_rect); | 574 AddDamageRect(layer_damage_rect); |
| 588 } | 575 } |
| 589 } | 576 } |
| 590 | 577 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 tiling->contents_scale(), | 625 tiling->contents_scale(), |
| 639 id(), | 626 id(), |
| 640 layer_tree_impl()->source_frame_number(), | 627 layer_tree_impl()->source_frame_number(), |
| 641 flags); | 628 flags); |
| 642 } | 629 } |
| 643 | 630 |
| 644 PicturePileImpl* PictureLayerImpl::GetPile() { | 631 PicturePileImpl* PictureLayerImpl::GetPile() { |
| 645 return pile_.get(); | 632 return pile_.get(); |
| 646 } | 633 } |
| 647 | 634 |
| 648 const Region* PictureLayerImpl::GetPendingInvalidation() { | 635 const Region* PictureLayerImpl::GetInvalidation() { |
| 649 if (layer_tree_impl()->IsPendingTree()) | 636 return &invalidation_; |
| 650 return &invalidation_; | |
| 651 DCHECK(layer_tree_impl()->IsActiveTree()); | |
| 652 if (PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer()) | |
| 653 return &twin_layer->invalidation_; | |
| 654 return nullptr; | |
| 655 } | 637 } |
| 656 | 638 |
| 657 const PictureLayerTiling* PictureLayerImpl::GetPendingOrActiveTwinTiling( | 639 const PictureLayerTiling* PictureLayerImpl::GetTwinTiling( |
| 658 const PictureLayerTiling* tiling) const { | 640 const PictureLayerTiling* tiling) const { |
| 659 PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer(); | 641 if (!twin_layer_) |
| 660 if (!twin_layer) | |
| 661 return nullptr; | 642 return nullptr; |
| 662 return twin_layer->tilings_->TilingAtScale(tiling->contents_scale()); | 643 return twin_layer_->tilings_->TilingAtScale(tiling->contents_scale()); |
| 663 } | 644 } |
| 664 | 645 |
| 665 PictureLayerTiling* PictureLayerImpl::GetRecycledTwinTiling( | 646 PictureLayerTiling* PictureLayerImpl::GetRecycledTwinTiling( |
| 666 const PictureLayerTiling* tiling) { | 647 const PictureLayerTiling* tiling) { |
| 667 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); | 648 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); |
| 668 if (!recycled_twin || !recycled_twin->tilings_) | 649 if (!recycled_twin || !recycled_twin->tilings_) |
| 669 return nullptr; | 650 return nullptr; |
| 670 return recycled_twin->tilings_->TilingAtScale(tiling->contents_scale()); | 651 return recycled_twin->tilings_->TilingAtScale(tiling->contents_scale()); |
| 671 } | 652 } |
| 672 | 653 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 *resource_size = iter.texture_size(); | 838 *resource_size = iter.texture_size(); |
| 858 } | 839 } |
| 859 | 840 |
| 860 void PictureLayerImpl::DoPostCommitInitialization() { | 841 void PictureLayerImpl::DoPostCommitInitialization() { |
| 861 DCHECK(needs_post_commit_initialization_); | 842 DCHECK(needs_post_commit_initialization_); |
| 862 DCHECK(layer_tree_impl()->IsPendingTree()); | 843 DCHECK(layer_tree_impl()->IsPendingTree()); |
| 863 | 844 |
| 864 if (!tilings_) | 845 if (!tilings_) |
| 865 tilings_ = make_scoped_ptr(new PictureLayerTilingSet(this)); | 846 tilings_ = make_scoped_ptr(new PictureLayerTilingSet(this)); |
| 866 | 847 |
| 867 PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer(); | 848 DCHECK(!twin_layer_); |
| 868 if (twin_layer) { | 849 twin_layer_ = static_cast<PictureLayerImpl*>( |
| 850 layer_tree_impl()->FindActiveTreeLayerById(id())); |
| 851 if (twin_layer_) { |
| 852 DCHECK(!twin_layer_->twin_layer_); |
| 853 twin_layer_->twin_layer_ = this; |
| 869 // If the twin has never been pushed to, do not sync from it. | 854 // If the twin has never been pushed to, do not sync from it. |
| 870 // This can happen if this function is called during activation. | 855 // This can happen if this function is called during activation. |
| 871 if (!twin_layer->needs_post_commit_initialization_) | 856 if (!twin_layer_->needs_post_commit_initialization_) |
| 872 SyncFromActiveLayer(twin_layer); | 857 SyncFromActiveLayer(twin_layer_); |
| 873 } | 858 } |
| 874 | 859 |
| 875 needs_post_commit_initialization_ = false; | 860 needs_post_commit_initialization_ = false; |
| 876 } | 861 } |
| 877 | 862 |
| 878 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { | 863 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { |
| 879 DCHECK(CanHaveTilingWithScale(contents_scale)) << | 864 DCHECK(CanHaveTilingWithScale(contents_scale)) << |
| 880 "contents_scale: " << contents_scale; | 865 "contents_scale: " << contents_scale; |
| 881 | 866 |
| 882 PictureLayerTiling* tiling = tilings_->AddTiling(contents_scale, bounds()); | 867 PictureLayerTiling* tiling = tilings_->AddTiling(contents_scale, bounds()); |
| 883 | 868 |
| 884 DCHECK(pile_->HasRecordings()); | 869 DCHECK(pile_->HasRecordings()); |
| 885 | 870 |
| 886 if (PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer()) | 871 if (twin_layer_) |
| 887 twin_layer->SyncTiling(tiling); | 872 twin_layer_->SyncTiling(tiling); |
| 888 | 873 |
| 889 return tiling; | 874 return tiling; |
| 890 } | 875 } |
| 891 | 876 |
| 892 void PictureLayerImpl::RemoveTiling(float contents_scale) { | 877 void PictureLayerImpl::RemoveTiling(float contents_scale) { |
| 893 if (!tilings_ || tilings_->num_tilings() == 0) | 878 if (!tilings_ || tilings_->num_tilings() == 0) |
| 894 return; | 879 return; |
| 895 | 880 |
| 896 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { | 881 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { |
| 897 PictureLayerTiling* tiling = tilings_->tiling_at(i); | 882 PictureLayerTiling* tiling = tilings_->tiling_at(i); |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 DCHECK(layer_tree_impl()->IsActiveTree()); | 1106 DCHECK(layer_tree_impl()->IsActiveTree()); |
| 1122 if (tilings_->num_tilings() == 0) | 1107 if (tilings_->num_tilings() == 0) |
| 1123 return; | 1108 return; |
| 1124 | 1109 |
| 1125 float min_acceptable_high_res_scale = std::min( | 1110 float min_acceptable_high_res_scale = std::min( |
| 1126 raster_contents_scale_, ideal_contents_scale_); | 1111 raster_contents_scale_, ideal_contents_scale_); |
| 1127 float max_acceptable_high_res_scale = std::max( | 1112 float max_acceptable_high_res_scale = std::max( |
| 1128 raster_contents_scale_, ideal_contents_scale_); | 1113 raster_contents_scale_, ideal_contents_scale_); |
| 1129 float twin_low_res_scale = 0.f; | 1114 float twin_low_res_scale = 0.f; |
| 1130 | 1115 |
| 1131 PictureLayerImpl* twin = GetPendingOrActiveTwinLayer(); | 1116 PictureLayerImpl* twin = twin_layer_; |
| 1132 if (twin && twin->CanHaveTilings()) { | 1117 if (twin && twin->CanHaveTilings()) { |
| 1133 min_acceptable_high_res_scale = std::min( | 1118 min_acceptable_high_res_scale = std::min( |
| 1134 min_acceptable_high_res_scale, | 1119 min_acceptable_high_res_scale, |
| 1135 std::min(twin->raster_contents_scale_, twin->ideal_contents_scale_)); | 1120 std::min(twin->raster_contents_scale_, twin->ideal_contents_scale_)); |
| 1136 max_acceptable_high_res_scale = std::max( | 1121 max_acceptable_high_res_scale = std::max( |
| 1137 max_acceptable_high_res_scale, | 1122 max_acceptable_high_res_scale, |
| 1138 std::max(twin->raster_contents_scale_, twin->ideal_contents_scale_)); | 1123 std::max(twin->raster_contents_scale_, twin->ideal_contents_scale_)); |
| 1139 | 1124 |
| 1140 for (size_t i = 0; i < twin->tilings_->num_tilings(); ++i) { | 1125 for (size_t i = 0; i < twin->tilings_->num_tilings(); ++i) { |
| 1141 PictureLayerTiling* tiling = twin->tilings_->tiling_at(i); | 1126 PictureLayerTiling* tiling = twin->tilings_->tiling_at(i); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1168 | 1153 |
| 1169 to_remove.push_back(tiling); | 1154 to_remove.push_back(tiling); |
| 1170 } | 1155 } |
| 1171 | 1156 |
| 1172 if (to_remove.empty()) | 1157 if (to_remove.empty()) |
| 1173 return; | 1158 return; |
| 1174 | 1159 |
| 1175 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); | 1160 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); |
| 1176 // Remove tilings on this tree and the twin tree. | 1161 // Remove tilings on this tree and the twin tree. |
| 1177 for (size_t i = 0; i < to_remove.size(); ++i) { | 1162 for (size_t i = 0; i < to_remove.size(); ++i) { |
| 1178 const PictureLayerTiling* twin_tiling = | 1163 const PictureLayerTiling* twin_tiling = GetTwinTiling(to_remove[i]); |
| 1179 GetPendingOrActiveTwinTiling(to_remove[i]); | |
| 1180 // Only remove tilings from the twin layer if they have | 1164 // Only remove tilings from the twin layer if they have |
| 1181 // NON_IDEAL_RESOLUTION. | 1165 // NON_IDEAL_RESOLUTION. |
| 1182 if (twin_tiling && twin_tiling->resolution() == NON_IDEAL_RESOLUTION) | 1166 if (twin_tiling && twin_tiling->resolution() == NON_IDEAL_RESOLUTION) |
| 1183 twin->RemoveTiling(to_remove[i]->contents_scale()); | 1167 twin->RemoveTiling(to_remove[i]->contents_scale()); |
| 1184 // Remove the tiling from the recycle tree. Note that we ignore resolution, | 1168 // Remove the tiling from the recycle tree. Note that we ignore resolution, |
| 1185 // since we don't need to maintain high/low res on the recycle tree. | 1169 // since we don't need to maintain high/low res on the recycle tree. |
| 1186 if (recycled_twin) | 1170 if (recycled_twin) |
| 1187 recycled_twin->RemoveTiling(to_remove[i]->contents_scale()); | 1171 recycled_twin->RemoveTiling(to_remove[i]->contents_scale()); |
| 1188 // TODO(enne): temporary sanity CHECK for http://crbug.com/358350 | 1172 // TODO(enne): temporary sanity CHECK for http://crbug.com/358350 |
| 1189 CHECK_NE(HIGH_RESOLUTION, to_remove[i]->resolution()); | 1173 CHECK_NE(HIGH_RESOLUTION, to_remove[i]->resolution()); |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1692 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); | 1676 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); |
| 1693 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; | 1677 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; |
| 1694 return tiling_range.end - 1 - current_tiling_range_offset; | 1678 return tiling_range.end - 1 - current_tiling_range_offset; |
| 1695 } | 1679 } |
| 1696 } | 1680 } |
| 1697 NOTREACHED(); | 1681 NOTREACHED(); |
| 1698 return 0; | 1682 return 0; |
| 1699 } | 1683 } |
| 1700 | 1684 |
| 1701 } // namespace cc | 1685 } // namespace cc |
| OLD | NEW |