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; |
93 layer_tree_impl()->UnregisterPictureLayerImpl(this); | 95 layer_tree_impl()->UnregisterPictureLayerImpl(this); |
94 } | 96 } |
95 | 97 |
96 const char* PictureLayerImpl::LayerTypeAsString() const { | 98 const char* PictureLayerImpl::LayerTypeAsString() const { |
97 return "cc::PictureLayerImpl"; | 99 return "cc::PictureLayerImpl"; |
98 } | 100 } |
99 | 101 |
100 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl( | 102 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl( |
101 LayerTreeImpl* tree_impl) { | 103 LayerTreeImpl* tree_impl) { |
102 return PictureLayerImpl::Create(tree_impl, id()); | 104 return PictureLayerImpl::Create(tree_impl, id()); |
103 } | 105 } |
104 | 106 |
105 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { | 107 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { |
106 // It's possible this layer was never drawn or updated (e.g. because it was | 108 // It's possible this layer was never drawn or updated (e.g. because it was |
107 // a descendant of an opacity 0 layer). | 109 // a descendant of an opacity 0 layer). |
108 DoPostCommitInitializationIfNeeded(); | 110 DoPostCommitInitializationIfNeeded(); |
109 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); | 111 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); |
110 | 112 |
111 LayerImpl::PushPropertiesTo(base_layer); | 113 LayerImpl::PushPropertiesTo(base_layer); |
112 | 114 |
113 // When the pending tree pushes to the active tree, the pending twin | 115 // Twin relationships should never change once established. |
114 // becomes recycled. | 116 DCHECK_IMPLIES(twin_layer_, twin_layer_ == layer_impl); |
115 layer_impl->twin_layer_ = nullptr; | 117 DCHECK_IMPLIES(twin_layer_, layer_impl->twin_layer_ == this); |
116 twin_layer_ = nullptr; | 118 // The twin relationship does not need to exist before the first |
| 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; |
117 | 124 |
118 layer_impl->pile_ = pile_; | 125 layer_impl->pile_ = pile_; |
119 | 126 |
120 DCHECK(!pile_->is_solid_color() || !tilings_->num_tilings()); | 127 DCHECK(!pile_->is_solid_color() || !tilings_->num_tilings()); |
121 // Tilings would be expensive to push, so we swap. | 128 // Tilings would be expensive to push, so we swap. |
122 layer_impl->tilings_.swap(tilings_); | 129 layer_impl->tilings_.swap(tilings_); |
123 layer_impl->tilings_->SetClient(layer_impl); | 130 layer_impl->tilings_->SetClient(layer_impl); |
124 if (tilings_) | 131 if (tilings_) |
125 tilings_->SetClient(this); | 132 tilings_->SetClient(this); |
126 | 133 |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 if (screen_space_transform().GetInverse(&view_to_layer)) { | 566 if (screen_space_transform().GetInverse(&view_to_layer)) { |
560 // Transform from view space to content space. | 567 // Transform from view space to content space. |
561 visible_rect_in_content_space = | 568 visible_rect_in_content_space = |
562 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( | 569 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( |
563 view_to_layer, viewport_rect_for_tile_priority)); | 570 view_to_layer, viewport_rect_for_tile_priority)); |
564 } | 571 } |
565 } | 572 } |
566 return visible_rect_in_content_space; | 573 return visible_rect_in_content_space; |
567 } | 574 } |
568 | 575 |
569 PictureLayerImpl* PictureLayerImpl::GetRecycledTwinLayer() { | 576 PictureLayerImpl* PictureLayerImpl::GetPendingOrActiveTwinLayer() const { |
570 // TODO(vmpstr): Maintain recycled twin as a member. crbug.com/407418 | 577 if (!twin_layer_ || !twin_layer_->IsOnActiveOrPendingTree()) |
571 return static_cast<PictureLayerImpl*>( | 578 return nullptr; |
572 layer_tree_impl()->FindRecycleTreeLayerById(id())); | 579 return twin_layer_; |
| 580 } |
| 581 |
| 582 PictureLayerImpl* PictureLayerImpl::GetRecycledTwinLayer() const { |
| 583 if (!twin_layer_ || twin_layer_->IsOnActiveOrPendingTree()) |
| 584 return nullptr; |
| 585 return twin_layer_; |
573 } | 586 } |
574 | 587 |
575 void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) { | 588 void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) { |
576 if (layer_tree_impl()->IsActiveTree()) { | 589 if (layer_tree_impl()->IsActiveTree()) { |
577 gfx::RectF layer_damage_rect = | 590 gfx::RectF layer_damage_rect = |
578 gfx::ScaleRect(tile->content_rect(), 1.f / tile->contents_scale()); | 591 gfx::ScaleRect(tile->content_rect(), 1.f / tile->contents_scale()); |
579 AddDamageRect(layer_damage_rect); | 592 AddDamageRect(layer_damage_rect); |
580 } | 593 } |
581 } | 594 } |
582 | 595 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 } | 647 } |
635 | 648 |
636 PicturePileImpl* PictureLayerImpl::GetPile() { | 649 PicturePileImpl* PictureLayerImpl::GetPile() { |
637 return pile_.get(); | 650 return pile_.get(); |
638 } | 651 } |
639 | 652 |
640 const Region* PictureLayerImpl::GetPendingInvalidation() { | 653 const Region* PictureLayerImpl::GetPendingInvalidation() { |
641 if (layer_tree_impl()->IsPendingTree()) | 654 if (layer_tree_impl()->IsPendingTree()) |
642 return &invalidation_; | 655 return &invalidation_; |
643 DCHECK(layer_tree_impl()->IsActiveTree()); | 656 DCHECK(layer_tree_impl()->IsActiveTree()); |
644 if (PictureLayerImpl* twin_layer = GetTwinLayer()) | 657 if (PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer()) |
645 return &twin_layer->invalidation_; | 658 return &twin_layer->invalidation_; |
646 return nullptr; | 659 return nullptr; |
647 } | 660 } |
648 | 661 |
649 const PictureLayerTiling* PictureLayerImpl::GetTwinTiling( | 662 const PictureLayerTiling* PictureLayerImpl::GetPendingOrActiveTwinTiling( |
650 const PictureLayerTiling* tiling) const { | 663 const PictureLayerTiling* tiling) const { |
651 if (!twin_layer_) | 664 PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer(); |
| 665 if (!twin_layer) |
652 return nullptr; | 666 return nullptr; |
653 return twin_layer_->tilings_->TilingAtScale(tiling->contents_scale()); | 667 // TODO(danakj): Remove this when no longer swapping tilings. |
| 668 if (!twin_layer->tilings_) |
| 669 return nullptr; |
| 670 return twin_layer->tilings_->TilingAtScale(tiling->contents_scale()); |
654 } | 671 } |
655 | 672 |
656 PictureLayerTiling* PictureLayerImpl::GetRecycledTwinTiling( | 673 PictureLayerTiling* PictureLayerImpl::GetRecycledTwinTiling( |
657 const PictureLayerTiling* tiling) { | 674 const PictureLayerTiling* tiling) { |
658 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); | 675 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); |
659 if (!recycled_twin || !recycled_twin->tilings_) | 676 if (!recycled_twin || !recycled_twin->tilings_) |
660 return nullptr; | 677 return nullptr; |
661 return recycled_twin->tilings_->TilingAtScale(tiling->contents_scale()); | 678 return recycled_twin->tilings_->TilingAtScale(tiling->contents_scale()); |
662 } | 679 } |
663 | 680 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 // should refactor this code a little bit and actually recalculate this. | 813 // should refactor this code a little bit and actually recalculate this. |
797 // However, this is a larger undertaking, so this will work for now. | 814 // However, this is a larger undertaking, so this will work for now. |
798 if (!synced_high_res_tiling) | 815 if (!synced_high_res_tiling) |
799 ResetRasterScale(); | 816 ResetRasterScale(); |
800 else | 817 else |
801 SanityCheckTilingState(); | 818 SanityCheckTilingState(); |
802 } | 819 } |
803 | 820 |
804 void PictureLayerImpl::SyncTiling( | 821 void PictureLayerImpl::SyncTiling( |
805 const PictureLayerTiling* tiling) { | 822 const PictureLayerTiling* tiling) { |
| 823 if (!tilings_) |
| 824 return; |
806 if (!CanHaveTilingWithScale(tiling->contents_scale())) | 825 if (!CanHaveTilingWithScale(tiling->contents_scale())) |
807 return; | 826 return; |
808 tilings_->AddTiling(tiling->contents_scale(), pile_->tiling_size()); | 827 tilings_->AddTiling(tiling->contents_scale(), pile_->tiling_size()); |
809 | 828 |
810 // If this tree needs update draw properties, then the tiling will | 829 // If this tree needs update draw properties, then the tiling will |
811 // get updated prior to drawing or activation. If this tree does not | 830 // get updated prior to drawing or activation. If this tree does not |
812 // need update draw properties, then its transforms are up to date and | 831 // need update draw properties, then its transforms are up to date and |
813 // we can create tiles for this tiling immediately. | 832 // we can create tiles for this tiling immediately. |
814 if (!layer_tree_impl()->needs_update_draw_properties() && | 833 if (!layer_tree_impl()->needs_update_draw_properties() && |
815 should_update_tile_priorities_) { | 834 should_update_tile_priorities_) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 *resource_size = iter.texture_size(); | 870 *resource_size = iter.texture_size(); |
852 } | 871 } |
853 | 872 |
854 void PictureLayerImpl::DoPostCommitInitialization() { | 873 void PictureLayerImpl::DoPostCommitInitialization() { |
855 DCHECK(needs_post_commit_initialization_); | 874 DCHECK(needs_post_commit_initialization_); |
856 DCHECK(layer_tree_impl()->IsPendingTree()); | 875 DCHECK(layer_tree_impl()->IsPendingTree()); |
857 | 876 |
858 if (!tilings_) | 877 if (!tilings_) |
859 tilings_ = make_scoped_ptr(new PictureLayerTilingSet(this)); | 878 tilings_ = make_scoped_ptr(new PictureLayerTilingSet(this)); |
860 | 879 |
861 DCHECK(!twin_layer_); | 880 PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer(); |
862 twin_layer_ = static_cast<PictureLayerImpl*>( | 881 if (twin_layer) { |
863 layer_tree_impl()->FindActiveTreeLayerById(id())); | |
864 if (twin_layer_) { | |
865 DCHECK(!twin_layer_->twin_layer_); | |
866 twin_layer_->twin_layer_ = this; | |
867 // If the twin has never been pushed to, do not sync from it. | 882 // If the twin has never been pushed to, do not sync from it. |
868 // This can happen if this function is called during activation. | 883 // This can happen if this function is called during activation. |
869 if (!twin_layer_->needs_post_commit_initialization_) | 884 if (!twin_layer->needs_post_commit_initialization_) |
870 SyncFromActiveLayer(twin_layer_); | 885 SyncFromActiveLayer(twin_layer); |
871 } | 886 } |
872 | 887 |
873 needs_post_commit_initialization_ = false; | 888 needs_post_commit_initialization_ = false; |
874 } | 889 } |
875 | 890 |
876 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { | 891 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { |
877 DCHECK(CanHaveTilingWithScale(contents_scale)) << | 892 DCHECK(CanHaveTilingWithScale(contents_scale)) << |
878 "contents_scale: " << contents_scale; | 893 "contents_scale: " << contents_scale; |
879 | 894 |
880 PictureLayerTiling* tiling = | 895 PictureLayerTiling* tiling = |
881 tilings_->AddTiling(contents_scale, pile_->tiling_size()); | 896 tilings_->AddTiling(contents_scale, pile_->tiling_size()); |
882 | 897 |
883 DCHECK(pile_->HasRecordings()); | 898 DCHECK(pile_->HasRecordings()); |
884 | 899 |
885 if (twin_layer_) | 900 if (PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer()) |
886 twin_layer_->SyncTiling(tiling); | 901 twin_layer->SyncTiling(tiling); |
887 | 902 |
888 return tiling; | 903 return tiling; |
889 } | 904 } |
890 | 905 |
891 void PictureLayerImpl::RemoveTiling(float contents_scale) { | 906 void PictureLayerImpl::RemoveTiling(float contents_scale) { |
892 if (!tilings_ || tilings_->num_tilings() == 0) | 907 if (!tilings_ || tilings_->num_tilings() == 0) |
893 return; | 908 return; |
894 | 909 |
895 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { | 910 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { |
896 PictureLayerTiling* tiling = tilings_->tiling_at(i); | 911 PictureLayerTiling* tiling = tilings_->tiling_at(i); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1120 DCHECK(layer_tree_impl()->IsActiveTree()); | 1135 DCHECK(layer_tree_impl()->IsActiveTree()); |
1121 if (tilings_->num_tilings() == 0) | 1136 if (tilings_->num_tilings() == 0) |
1122 return; | 1137 return; |
1123 | 1138 |
1124 float min_acceptable_high_res_scale = std::min( | 1139 float min_acceptable_high_res_scale = std::min( |
1125 raster_contents_scale_, ideal_contents_scale_); | 1140 raster_contents_scale_, ideal_contents_scale_); |
1126 float max_acceptable_high_res_scale = std::max( | 1141 float max_acceptable_high_res_scale = std::max( |
1127 raster_contents_scale_, ideal_contents_scale_); | 1142 raster_contents_scale_, ideal_contents_scale_); |
1128 float twin_low_res_scale = 0.f; | 1143 float twin_low_res_scale = 0.f; |
1129 | 1144 |
1130 PictureLayerImpl* twin = twin_layer_; | 1145 PictureLayerImpl* twin = GetPendingOrActiveTwinLayer(); |
1131 if (twin && twin->CanHaveTilings()) { | 1146 if (twin && twin->CanHaveTilings()) { |
1132 min_acceptable_high_res_scale = std::min( | 1147 min_acceptable_high_res_scale = std::min( |
1133 min_acceptable_high_res_scale, | 1148 min_acceptable_high_res_scale, |
1134 std::min(twin->raster_contents_scale_, twin->ideal_contents_scale_)); | 1149 std::min(twin->raster_contents_scale_, twin->ideal_contents_scale_)); |
1135 max_acceptable_high_res_scale = std::max( | 1150 max_acceptable_high_res_scale = std::max( |
1136 max_acceptable_high_res_scale, | 1151 max_acceptable_high_res_scale, |
1137 std::max(twin->raster_contents_scale_, twin->ideal_contents_scale_)); | 1152 std::max(twin->raster_contents_scale_, twin->ideal_contents_scale_)); |
1138 | 1153 |
1139 for (size_t i = 0; i < twin->tilings_->num_tilings(); ++i) { | 1154 // TODO(danakj): Remove the tilings_ check when we create them in the |
1140 PictureLayerTiling* tiling = twin->tilings_->tiling_at(i); | 1155 // constructor. |
1141 if (tiling->resolution() == LOW_RESOLUTION) | 1156 if (twin->tilings_) { |
1142 twin_low_res_scale = tiling->contents_scale(); | 1157 for (size_t i = 0; i < twin->tilings_->num_tilings(); ++i) { |
| 1158 PictureLayerTiling* tiling = twin->tilings_->tiling_at(i); |
| 1159 if (tiling->resolution() == LOW_RESOLUTION) |
| 1160 twin_low_res_scale = tiling->contents_scale(); |
| 1161 } |
1143 } | 1162 } |
1144 } | 1163 } |
1145 | 1164 |
1146 std::vector<PictureLayerTiling*> to_remove; | 1165 std::vector<PictureLayerTiling*> to_remove; |
1147 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { | 1166 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { |
1148 PictureLayerTiling* tiling = tilings_->tiling_at(i); | 1167 PictureLayerTiling* tiling = tilings_->tiling_at(i); |
1149 | 1168 |
1150 // Keep multiple high resolution tilings even if not used to help | 1169 // Keep multiple high resolution tilings even if not used to help |
1151 // activate earlier at non-ideal resolutions. | 1170 // activate earlier at non-ideal resolutions. |
1152 if (tiling->contents_scale() >= min_acceptable_high_res_scale && | 1171 if (tiling->contents_scale() >= min_acceptable_high_res_scale && |
(...skipping 14 matching lines...) Expand all Loading... |
1167 | 1186 |
1168 to_remove.push_back(tiling); | 1187 to_remove.push_back(tiling); |
1169 } | 1188 } |
1170 | 1189 |
1171 if (to_remove.empty()) | 1190 if (to_remove.empty()) |
1172 return; | 1191 return; |
1173 | 1192 |
1174 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); | 1193 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); |
1175 // Remove tilings on this tree and the twin tree. | 1194 // Remove tilings on this tree and the twin tree. |
1176 for (size_t i = 0; i < to_remove.size(); ++i) { | 1195 for (size_t i = 0; i < to_remove.size(); ++i) { |
1177 const PictureLayerTiling* twin_tiling = GetTwinTiling(to_remove[i]); | 1196 const PictureLayerTiling* twin_tiling = |
| 1197 GetPendingOrActiveTwinTiling(to_remove[i]); |
1178 // Only remove tilings from the twin layer if they have | 1198 // Only remove tilings from the twin layer if they have |
1179 // NON_IDEAL_RESOLUTION. | 1199 // NON_IDEAL_RESOLUTION. |
1180 if (twin_tiling && twin_tiling->resolution() == NON_IDEAL_RESOLUTION) | 1200 if (twin_tiling && twin_tiling->resolution() == NON_IDEAL_RESOLUTION) |
1181 twin->RemoveTiling(to_remove[i]->contents_scale()); | 1201 twin->RemoveTiling(to_remove[i]->contents_scale()); |
1182 // Remove the tiling from the recycle tree. Note that we ignore resolution, | 1202 // Remove the tiling from the recycle tree. Note that we ignore resolution, |
1183 // since we don't need to maintain high/low res on the recycle tree. | 1203 // since we don't need to maintain high/low res on the recycle tree. |
1184 if (recycled_twin) | 1204 if (recycled_twin) |
1185 recycled_twin->RemoveTiling(to_remove[i]->contents_scale()); | 1205 recycled_twin->RemoveTiling(to_remove[i]->contents_scale()); |
1186 // TODO(enne): temporary sanity CHECK for http://crbug.com/358350 | 1206 // TODO(enne): temporary sanity CHECK for http://crbug.com/358350 |
1187 CHECK_NE(HIGH_RESOLUTION, to_remove[i]->resolution()); | 1207 CHECK_NE(HIGH_RESOLUTION, to_remove[i]->resolution()); |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1692 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); | 1712 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); |
1693 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; | 1713 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; |
1694 return tiling_range.end - 1 - current_tiling_range_offset; | 1714 return tiling_range.end - 1 - current_tiling_range_offset; |
1695 } | 1715 } |
1696 } | 1716 } |
1697 NOTREACHED(); | 1717 NOTREACHED(); |
1698 return 0; | 1718 return 0; |
1699 } | 1719 } |
1700 | 1720 |
1701 } // namespace cc | 1721 } // namespace cc |
OLD | NEW |