Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: cc/layers/picture_layer_impl.cc

Issue 676953003: cc: Always keep the PictureLayerImpl::twin_layer_ pointer valid. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: twins: add-test-case Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 if (screen_space_transform().GetInverse(&view_to_layer)) { 561 if (screen_space_transform().GetInverse(&view_to_layer)) {
555 // Transform from view space to content space. 562 // Transform from view space to content space.
556 visible_rect_in_content_space = 563 visible_rect_in_content_space =
557 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( 564 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect(
558 view_to_layer, viewport_rect_for_tile_priority)); 565 view_to_layer, viewport_rect_for_tile_priority));
559 } 566 }
560 } 567 }
561 return visible_rect_in_content_space; 568 return visible_rect_in_content_space;
562 } 569 }
563 570
564 PictureLayerImpl* PictureLayerImpl::GetRecycledTwinLayer() { 571 PictureLayerImpl* PictureLayerImpl::GetPendingOrActiveTwinLayer() const {
565 // TODO(vmpstr): Maintain recycled twin as a member. crbug.com/407418 572 if (!twin_layer_ || !twin_layer_->IsOnActiveOrPendingTree())
566 return static_cast<PictureLayerImpl*>( 573 return nullptr;
567 layer_tree_impl()->FindRecycleTreeLayerById(id())); 574 return twin_layer_;
575 }
576
577 PictureLayerImpl* PictureLayerImpl::GetRecycledTwinLayer() const {
578 if (!twin_layer_ || twin_layer_->IsOnActiveOrPendingTree())
579 return nullptr;
580 return twin_layer_;
568 } 581 }
569 582
570 void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) { 583 void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) {
571 if (layer_tree_impl()->IsActiveTree()) { 584 if (layer_tree_impl()->IsActiveTree()) {
572 gfx::RectF layer_damage_rect = 585 gfx::RectF layer_damage_rect =
573 gfx::ScaleRect(tile->content_rect(), 1.f / tile->contents_scale()); 586 gfx::ScaleRect(tile->content_rect(), 1.f / tile->contents_scale());
574 AddDamageRect(layer_damage_rect); 587 AddDamageRect(layer_damage_rect);
575 } 588 }
576 } 589 }
577 590
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 } 642 }
630 643
631 PicturePileImpl* PictureLayerImpl::GetPile() { 644 PicturePileImpl* PictureLayerImpl::GetPile() {
632 return pile_.get(); 645 return pile_.get();
633 } 646 }
634 647
635 const Region* PictureLayerImpl::GetInvalidation() { 648 const Region* PictureLayerImpl::GetInvalidation() {
636 return &invalidation_; 649 return &invalidation_;
637 } 650 }
638 651
639 const PictureLayerTiling* PictureLayerImpl::GetTwinTiling( 652 const PictureLayerTiling* PictureLayerImpl::GetPendingOrActiveTwinTiling(
640 const PictureLayerTiling* tiling) const { 653 const PictureLayerTiling* tiling) const {
641 if (!twin_layer_) 654 PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer();
655 if (!twin_layer)
642 return nullptr; 656 return nullptr;
643 return twin_layer_->tilings_->TilingAtScale(tiling->contents_scale()); 657 return twin_layer->tilings_->TilingAtScale(tiling->contents_scale());
644 } 658 }
645 659
646 PictureLayerTiling* PictureLayerImpl::GetRecycledTwinTiling( 660 PictureLayerTiling* PictureLayerImpl::GetRecycledTwinTiling(
647 const PictureLayerTiling* tiling) { 661 const PictureLayerTiling* tiling) {
648 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); 662 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer();
649 if (!recycled_twin || !recycled_twin->tilings_) 663 if (!recycled_twin || !recycled_twin->tilings_)
650 return nullptr; 664 return nullptr;
651 return recycled_twin->tilings_->TilingAtScale(tiling->contents_scale()); 665 return recycled_twin->tilings_->TilingAtScale(tiling->contents_scale());
652 } 666 }
653 667
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 *resource_size = iter.texture_size(); 852 *resource_size = iter.texture_size();
839 } 853 }
840 854
841 void PictureLayerImpl::DoPostCommitInitialization() { 855 void PictureLayerImpl::DoPostCommitInitialization() {
842 DCHECK(needs_post_commit_initialization_); 856 DCHECK(needs_post_commit_initialization_);
843 DCHECK(layer_tree_impl()->IsPendingTree()); 857 DCHECK(layer_tree_impl()->IsPendingTree());
844 858
845 if (!tilings_) 859 if (!tilings_)
846 tilings_ = make_scoped_ptr(new PictureLayerTilingSet(this)); 860 tilings_ = make_scoped_ptr(new PictureLayerTilingSet(this));
847 861
848 DCHECK(!twin_layer_); 862 PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer();
849 twin_layer_ = static_cast<PictureLayerImpl*>( 863 if (twin_layer) {
850 layer_tree_impl()->FindActiveTreeLayerById(id()));
851 if (twin_layer_) {
852 DCHECK(!twin_layer_->twin_layer_);
853 twin_layer_->twin_layer_ = this;
854 // If the twin has never been pushed to, do not sync from it. 864 // If the twin has never been pushed to, do not sync from it.
855 // This can happen if this function is called during activation. 865 // This can happen if this function is called during activation.
856 if (!twin_layer_->needs_post_commit_initialization_) 866 if (!twin_layer->needs_post_commit_initialization_)
857 SyncFromActiveLayer(twin_layer_); 867 SyncFromActiveLayer(twin_layer);
858 } 868 }
859 869
860 needs_post_commit_initialization_ = false; 870 needs_post_commit_initialization_ = false;
861 } 871 }
862 872
863 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { 873 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) {
864 DCHECK(CanHaveTilingWithScale(contents_scale)) << 874 DCHECK(CanHaveTilingWithScale(contents_scale)) <<
865 "contents_scale: " << contents_scale; 875 "contents_scale: " << contents_scale;
866 876
867 PictureLayerTiling* tiling = tilings_->AddTiling(contents_scale, bounds()); 877 PictureLayerTiling* tiling = tilings_->AddTiling(contents_scale, bounds());
868 878
869 DCHECK(pile_->HasRecordings()); 879 DCHECK(pile_->HasRecordings());
870 880
871 if (twin_layer_) 881 if (PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer())
872 twin_layer_->SyncTiling(tiling); 882 twin_layer->SyncTiling(tiling);
873 883
874 return tiling; 884 return tiling;
875 } 885 }
876 886
877 void PictureLayerImpl::RemoveTiling(float contents_scale) { 887 void PictureLayerImpl::RemoveTiling(float contents_scale) {
878 if (!tilings_ || tilings_->num_tilings() == 0) 888 if (!tilings_ || tilings_->num_tilings() == 0)
879 return; 889 return;
880 890
881 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { 891 for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
882 PictureLayerTiling* tiling = tilings_->tiling_at(i); 892 PictureLayerTiling* tiling = tilings_->tiling_at(i);
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 DCHECK(layer_tree_impl()->IsActiveTree()); 1116 DCHECK(layer_tree_impl()->IsActiveTree());
1107 if (tilings_->num_tilings() == 0) 1117 if (tilings_->num_tilings() == 0)
1108 return; 1118 return;
1109 1119
1110 float min_acceptable_high_res_scale = std::min( 1120 float min_acceptable_high_res_scale = std::min(
1111 raster_contents_scale_, ideal_contents_scale_); 1121 raster_contents_scale_, ideal_contents_scale_);
1112 float max_acceptable_high_res_scale = std::max( 1122 float max_acceptable_high_res_scale = std::max(
1113 raster_contents_scale_, ideal_contents_scale_); 1123 raster_contents_scale_, ideal_contents_scale_);
1114 float twin_low_res_scale = 0.f; 1124 float twin_low_res_scale = 0.f;
1115 1125
1116 PictureLayerImpl* twin = twin_layer_; 1126 PictureLayerImpl* twin = GetPendingOrActiveTwinLayer();
1117 if (twin && twin->CanHaveTilings()) { 1127 if (twin && twin->CanHaveTilings()) {
1118 min_acceptable_high_res_scale = std::min( 1128 min_acceptable_high_res_scale = std::min(
1119 min_acceptable_high_res_scale, 1129 min_acceptable_high_res_scale,
1120 std::min(twin->raster_contents_scale_, twin->ideal_contents_scale_)); 1130 std::min(twin->raster_contents_scale_, twin->ideal_contents_scale_));
1121 max_acceptable_high_res_scale = std::max( 1131 max_acceptable_high_res_scale = std::max(
1122 max_acceptable_high_res_scale, 1132 max_acceptable_high_res_scale,
1123 std::max(twin->raster_contents_scale_, twin->ideal_contents_scale_)); 1133 std::max(twin->raster_contents_scale_, twin->ideal_contents_scale_));
1124 1134
1125 for (size_t i = 0; i < twin->tilings_->num_tilings(); ++i) { 1135 for (size_t i = 0; i < twin->tilings_->num_tilings(); ++i) {
1126 PictureLayerTiling* tiling = twin->tilings_->tiling_at(i); 1136 PictureLayerTiling* tiling = twin->tilings_->tiling_at(i);
(...skipping 26 matching lines...) Expand all
1153 1163
1154 to_remove.push_back(tiling); 1164 to_remove.push_back(tiling);
1155 } 1165 }
1156 1166
1157 if (to_remove.empty()) 1167 if (to_remove.empty())
1158 return; 1168 return;
1159 1169
1160 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); 1170 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer();
1161 // Remove tilings on this tree and the twin tree. 1171 // Remove tilings on this tree and the twin tree.
1162 for (size_t i = 0; i < to_remove.size(); ++i) { 1172 for (size_t i = 0; i < to_remove.size(); ++i) {
1163 const PictureLayerTiling* twin_tiling = GetTwinTiling(to_remove[i]); 1173 const PictureLayerTiling* twin_tiling =
1174 GetPendingOrActiveTwinTiling(to_remove[i]);
1164 // Only remove tilings from the twin layer if they have 1175 // Only remove tilings from the twin layer if they have
1165 // NON_IDEAL_RESOLUTION. 1176 // NON_IDEAL_RESOLUTION.
1166 if (twin_tiling && twin_tiling->resolution() == NON_IDEAL_RESOLUTION) 1177 if (twin_tiling && twin_tiling->resolution() == NON_IDEAL_RESOLUTION)
1167 twin->RemoveTiling(to_remove[i]->contents_scale()); 1178 twin->RemoveTiling(to_remove[i]->contents_scale());
1168 // Remove the tiling from the recycle tree. Note that we ignore resolution, 1179 // Remove the tiling from the recycle tree. Note that we ignore resolution,
1169 // since we don't need to maintain high/low res on the recycle tree. 1180 // since we don't need to maintain high/low res on the recycle tree.
1170 if (recycled_twin) 1181 if (recycled_twin)
1171 recycled_twin->RemoveTiling(to_remove[i]->contents_scale()); 1182 recycled_twin->RemoveTiling(to_remove[i]->contents_scale());
1172 // TODO(enne): temporary sanity CHECK for http://crbug.com/358350 1183 // TODO(enne): temporary sanity CHECK for http://crbug.com/358350
1173 CHECK_NE(HIGH_RESOLUTION, to_remove[i]->resolution()); 1184 CHECK_NE(HIGH_RESOLUTION, to_remove[i]->resolution());
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
1676 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); 1687 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange();
1677 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; 1688 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start;
1678 return tiling_range.end - 1 - current_tiling_range_offset; 1689 return tiling_range.end - 1 - current_tiling_range_offset;
1679 } 1690 }
1680 } 1691 }
1681 NOTREACHED(); 1692 NOTREACHED();
1682 return 0; 1693 return 0;
1683 } 1694 }
1684 1695
1685 } // namespace cc 1696 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698