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

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: . Created 6 years, 2 months 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 twin_layer_ = layer_impl;
vmpstr 2014/10/24 16:47:05 Can you make a comment here explaining why we don'
danakj 2014/10/24 16:53:30 Ya, before this the only thing we do is create the
119 layer_impl->twin_layer_ = this;
117 120
118 layer_impl->pile_ = pile_; 121 layer_impl->pile_ = pile_;
119 122
120 DCHECK(!pile_->is_solid_color() || !tilings_->num_tilings()); 123 DCHECK(!pile_->is_solid_color() || !tilings_->num_tilings());
121 // Tilings would be expensive to push, so we swap. 124 // Tilings would be expensive to push, so we swap.
122 layer_impl->tilings_.swap(tilings_); 125 layer_impl->tilings_.swap(tilings_);
123 layer_impl->tilings_->SetClient(layer_impl); 126 layer_impl->tilings_->SetClient(layer_impl);
124 if (tilings_) 127 if (tilings_)
125 tilings_->SetClient(this); 128 tilings_->SetClient(this);
126 129
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 if (screen_space_transform().GetInverse(&view_to_layer)) { 557 if (screen_space_transform().GetInverse(&view_to_layer)) {
555 // Transform from view space to content space. 558 // Transform from view space to content space.
556 visible_rect_in_content_space = 559 visible_rect_in_content_space =
557 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( 560 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect(
558 view_to_layer, viewport_rect_for_tile_priority)); 561 view_to_layer, viewport_rect_for_tile_priority));
559 } 562 }
560 } 563 }
561 return visible_rect_in_content_space; 564 return visible_rect_in_content_space;
562 } 565 }
563 566
564 PictureLayerImpl* PictureLayerImpl::GetRecycledTwinLayer() { 567 PictureLayerImpl* PictureLayerImpl::GetPendingOrActiveTwinLayer() const {
565 // TODO(vmpstr): Maintain recycled twin as a member. crbug.com/407418 568 if (!twin_layer_ || !twin_layer_->IsOnActiveOrPendingTree())
566 return static_cast<PictureLayerImpl*>( 569 return nullptr;
567 layer_tree_impl()->FindRecycleTreeLayerById(id())); 570 return twin_layer_;
571 }
572
573 PictureLayerImpl* PictureLayerImpl::GetRecycledTwinLayer() const {
574 if (!twin_layer_ || twin_layer_->IsOnActiveOrPendingTree())
575 return nullptr;
576 return twin_layer_;
568 } 577 }
569 578
570 void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) { 579 void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) {
571 if (layer_tree_impl()->IsActiveTree()) { 580 if (layer_tree_impl()->IsActiveTree()) {
572 gfx::RectF layer_damage_rect = 581 gfx::RectF layer_damage_rect =
573 gfx::ScaleRect(tile->content_rect(), 1.f / tile->contents_scale()); 582 gfx::ScaleRect(tile->content_rect(), 1.f / tile->contents_scale());
574 AddDamageRect(layer_damage_rect); 583 AddDamageRect(layer_damage_rect);
575 } 584 }
576 } 585 }
577 586
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 } 638 }
630 639
631 PicturePileImpl* PictureLayerImpl::GetPile() { 640 PicturePileImpl* PictureLayerImpl::GetPile() {
632 return pile_.get(); 641 return pile_.get();
633 } 642 }
634 643
635 const Region* PictureLayerImpl::GetInvalidation() { 644 const Region* PictureLayerImpl::GetInvalidation() {
636 return &invalidation_; 645 return &invalidation_;
637 } 646 }
638 647
639 const PictureLayerTiling* PictureLayerImpl::GetTwinTiling( 648 const PictureLayerTiling* PictureLayerImpl::GetTwinTiling(
vmpstr 2014/10/24 16:47:05 nit: This potentially should be GetActiveOrPending
danakj 2014/10/24 16:53:30 Hm, it's part of the PLTClient API. I can change i
640 const PictureLayerTiling* tiling) const { 649 const PictureLayerTiling* tiling) const {
641 if (!twin_layer_) 650 PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer();
651 if (!twin_layer)
642 return nullptr; 652 return nullptr;
643 return twin_layer_->tilings_->TilingAtScale(tiling->contents_scale()); 653 return twin_layer->tilings_->TilingAtScale(tiling->contents_scale());
644 } 654 }
645 655
646 PictureLayerTiling* PictureLayerImpl::GetRecycledTwinTiling( 656 PictureLayerTiling* PictureLayerImpl::GetRecycledTwinTiling(
647 const PictureLayerTiling* tiling) { 657 const PictureLayerTiling* tiling) {
648 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); 658 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer();
649 if (!recycled_twin || !recycled_twin->tilings_) 659 if (!recycled_twin || !recycled_twin->tilings_)
650 return nullptr; 660 return nullptr;
651 return recycled_twin->tilings_->TilingAtScale(tiling->contents_scale()); 661 return recycled_twin->tilings_->TilingAtScale(tiling->contents_scale());
652 } 662 }
653 663
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 *resource_size = iter.texture_size(); 848 *resource_size = iter.texture_size();
839 } 849 }
840 850
841 void PictureLayerImpl::DoPostCommitInitialization() { 851 void PictureLayerImpl::DoPostCommitInitialization() {
842 DCHECK(needs_post_commit_initialization_); 852 DCHECK(needs_post_commit_initialization_);
843 DCHECK(layer_tree_impl()->IsPendingTree()); 853 DCHECK(layer_tree_impl()->IsPendingTree());
844 854
845 if (!tilings_) 855 if (!tilings_)
846 tilings_.reset(new PictureLayerTilingSet(this, bounds())); 856 tilings_.reset(new PictureLayerTilingSet(this, bounds()));
847 857
848 DCHECK(!twin_layer_); 858 PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer();
849 twin_layer_ = static_cast<PictureLayerImpl*>( 859 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. 860 // If the twin has never been pushed to, do not sync from it.
855 // This can happen if this function is called during activation. 861 // This can happen if this function is called during activation.
856 if (!twin_layer_->needs_post_commit_initialization_) 862 if (!twin_layer->needs_post_commit_initialization_)
857 SyncFromActiveLayer(twin_layer_); 863 SyncFromActiveLayer(twin_layer);
858 } 864 }
859 865
860 needs_post_commit_initialization_ = false; 866 needs_post_commit_initialization_ = false;
861 } 867 }
862 868
863 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { 869 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) {
864 DCHECK(CanHaveTilingWithScale(contents_scale)) << 870 DCHECK(CanHaveTilingWithScale(contents_scale)) <<
865 "contents_scale: " << contents_scale; 871 "contents_scale: " << contents_scale;
866 872
867 PictureLayerTiling* tiling = tilings_->AddTiling(contents_scale); 873 PictureLayerTiling* tiling = tilings_->AddTiling(contents_scale);
868 874
869 DCHECK(pile_->HasRecordings()); 875 DCHECK(pile_->HasRecordings());
870 876
871 if (twin_layer_) 877 if (PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer())
872 twin_layer_->SyncTiling(tiling); 878 twin_layer->SyncTiling(tiling);
873 879
874 return tiling; 880 return tiling;
875 } 881 }
876 882
877 void PictureLayerImpl::RemoveTiling(float contents_scale) { 883 void PictureLayerImpl::RemoveTiling(float contents_scale) {
878 if (!tilings_ || tilings_->num_tilings() == 0) 884 if (!tilings_ || tilings_->num_tilings() == 0)
879 return; 885 return;
880 886
881 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { 887 for (size_t i = 0; i < tilings_->num_tilings(); ++i) {
882 PictureLayerTiling* tiling = tilings_->tiling_at(i); 888 PictureLayerTiling* tiling = tilings_->tiling_at(i);
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1106 DCHECK(layer_tree_impl()->IsActiveTree()); 1112 DCHECK(layer_tree_impl()->IsActiveTree());
1107 if (tilings_->num_tilings() == 0) 1113 if (tilings_->num_tilings() == 0)
1108 return; 1114 return;
1109 1115
1110 float min_acceptable_high_res_scale = std::min( 1116 float min_acceptable_high_res_scale = std::min(
1111 raster_contents_scale_, ideal_contents_scale_); 1117 raster_contents_scale_, ideal_contents_scale_);
1112 float max_acceptable_high_res_scale = std::max( 1118 float max_acceptable_high_res_scale = std::max(
1113 raster_contents_scale_, ideal_contents_scale_); 1119 raster_contents_scale_, ideal_contents_scale_);
1114 float twin_low_res_scale = 0.f; 1120 float twin_low_res_scale = 0.f;
1115 1121
1116 PictureLayerImpl* twin = twin_layer_; 1122 PictureLayerImpl* twin = GetPendingOrActiveTwinLayer();
1117 if (twin && twin->CanHaveTilings()) { 1123 if (twin && twin->CanHaveTilings()) {
1118 min_acceptable_high_res_scale = std::min( 1124 min_acceptable_high_res_scale = std::min(
1119 min_acceptable_high_res_scale, 1125 min_acceptable_high_res_scale,
1120 std::min(twin->raster_contents_scale_, twin->ideal_contents_scale_)); 1126 std::min(twin->raster_contents_scale_, twin->ideal_contents_scale_));
1121 max_acceptable_high_res_scale = std::max( 1127 max_acceptable_high_res_scale = std::max(
1122 max_acceptable_high_res_scale, 1128 max_acceptable_high_res_scale,
1123 std::max(twin->raster_contents_scale_, twin->ideal_contents_scale_)); 1129 std::max(twin->raster_contents_scale_, twin->ideal_contents_scale_));
1124 1130
1125 for (size_t i = 0; i < twin->tilings_->num_tilings(); ++i) { 1131 for (size_t i = 0; i < twin->tilings_->num_tilings(); ++i) {
1126 PictureLayerTiling* tiling = twin->tilings_->tiling_at(i); 1132 PictureLayerTiling* tiling = twin->tilings_->tiling_at(i);
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
1676 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); 1682 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange();
1677 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; 1683 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start;
1678 return tiling_range.end - 1 - current_tiling_range_offset; 1684 return tiling_range.end - 1 - current_tiling_range_offset;
1679 } 1685 }
1680 } 1686 }
1681 NOTREACHED(); 1687 NOTREACHED();
1682 return 0; 1688 return 0;
1683 } 1689 }
1684 1690
1685 } // namespace cc 1691 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698