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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
63 } | 63 } |
64 | 64 |
65 PictureLayerImpl::Pair::Pair(PictureLayerImpl* active_layer, | 65 PictureLayerImpl::Pair::Pair(PictureLayerImpl* active_layer, |
66 PictureLayerImpl* pending_layer) | 66 PictureLayerImpl* pending_layer) |
67 : active(active_layer), pending(pending_layer) { | 67 : active(active_layer), pending(pending_layer) { |
68 } | 68 } |
69 | 69 |
70 PictureLayerImpl::Pair::~Pair() { | 70 PictureLayerImpl::Pair::~Pair() { |
71 } | 71 } |
72 | 72 |
73 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, int id) | 73 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, |
74 int id, | |
75 bool is_mask) | |
74 : LayerImpl(tree_impl, id), | 76 : LayerImpl(tree_impl, id), |
75 twin_layer_(nullptr), | 77 twin_layer_(nullptr), |
78 tilings_(PictureLayerTilingSet::Create(this)), | |
79 // TODO(danakj): Can this be null to start? | |
76 raster_source_(PicturePileImpl::Create()), | 80 raster_source_(PicturePileImpl::Create()), |
77 ideal_page_scale_(0.f), | 81 ideal_page_scale_(0.f), |
78 ideal_device_scale_(0.f), | 82 ideal_device_scale_(0.f), |
79 ideal_source_scale_(0.f), | 83 ideal_source_scale_(0.f), |
80 ideal_contents_scale_(0.f), | 84 ideal_contents_scale_(0.f), |
81 raster_page_scale_(0.f), | 85 raster_page_scale_(0.f), |
82 raster_device_scale_(0.f), | 86 raster_device_scale_(0.f), |
83 raster_source_scale_(0.f), | 87 raster_source_scale_(0.f), |
84 raster_contents_scale_(0.f), | 88 raster_contents_scale_(0.f), |
85 low_res_raster_contents_scale_(0.f), | 89 low_res_raster_contents_scale_(0.f), |
86 raster_source_scale_is_fixed_(false), | 90 raster_source_scale_is_fixed_(false), |
87 was_screen_space_transform_animating_(false), | 91 was_screen_space_transform_animating_(false), |
88 needs_post_commit_initialization_(true), | 92 needs_post_commit_initialization_(true), |
89 should_update_tile_priorities_(false), | 93 should_update_tile_priorities_(false), |
90 only_used_low_res_last_append_quads_(false), | 94 only_used_low_res_last_append_quads_(false), |
91 is_mask_(false) { | 95 is_mask_(is_mask) { |
92 layer_tree_impl()->RegisterPictureLayerImpl(this); | 96 layer_tree_impl()->RegisterPictureLayerImpl(this); |
93 } | 97 } |
94 | 98 |
95 PictureLayerImpl::~PictureLayerImpl() { | 99 PictureLayerImpl::~PictureLayerImpl() { |
96 if (twin_layer_) | 100 if (twin_layer_) |
97 twin_layer_->twin_layer_ = nullptr; | 101 twin_layer_->twin_layer_ = nullptr; |
98 layer_tree_impl()->UnregisterPictureLayerImpl(this); | 102 layer_tree_impl()->UnregisterPictureLayerImpl(this); |
99 } | 103 } |
100 | 104 |
101 scoped_ptr<TilingSetEvictionQueue> PictureLayerImpl::CreateEvictionQueue( | 105 scoped_ptr<TilingSetEvictionQueue> PictureLayerImpl::CreateEvictionQueue( |
(...skipping 11 matching lines...) Expand all Loading... | |
113 return make_scoped_ptr( | 117 return make_scoped_ptr( |
114 new TilingSetRasterQueue(tilings_.get(), prioritize_low_res)); | 118 new TilingSetRasterQueue(tilings_.get(), prioritize_low_res)); |
115 } | 119 } |
116 | 120 |
117 const char* PictureLayerImpl::LayerTypeAsString() const { | 121 const char* PictureLayerImpl::LayerTypeAsString() const { |
118 return "cc::PictureLayerImpl"; | 122 return "cc::PictureLayerImpl"; |
119 } | 123 } |
120 | 124 |
121 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl( | 125 scoped_ptr<LayerImpl> PictureLayerImpl::CreateLayerImpl( |
122 LayerTreeImpl* tree_impl) { | 126 LayerTreeImpl* tree_impl) { |
123 return PictureLayerImpl::Create(tree_impl, id()); | 127 return PictureLayerImpl::Create(tree_impl, id(), is_mask_); |
124 } | 128 } |
125 | 129 |
126 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { | 130 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { |
127 // It's possible this layer was never drawn or updated (e.g. because it was | 131 // It's possible this layer was never drawn or updated (e.g. because it was |
128 // a descendant of an opacity 0 layer). | 132 // a descendant of an opacity 0 layer). |
129 DoPostCommitInitializationIfNeeded(); | 133 DoPostCommitInitializationIfNeeded(); |
130 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); | 134 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); |
135 DCHECK_EQ(layer_impl->is_mask_, is_mask_); | |
131 | 136 |
132 LayerImpl::PushPropertiesTo(base_layer); | 137 LayerImpl::PushPropertiesTo(base_layer); |
133 | 138 |
134 // Twin relationships should never change once established. | 139 // Twin relationships should never change once established. |
135 DCHECK_IMPLIES(twin_layer_, twin_layer_ == layer_impl); | 140 DCHECK_IMPLIES(twin_layer_, twin_layer_ == layer_impl); |
136 DCHECK_IMPLIES(twin_layer_, layer_impl->twin_layer_ == this); | 141 DCHECK_IMPLIES(twin_layer_, layer_impl->twin_layer_ == this); |
137 // The twin relationship does not need to exist before the first | 142 // The twin relationship does not need to exist before the first |
138 // PushPropertiesTo from pending to active layer since before that the active | 143 // PushPropertiesTo from pending to active layer since before that the active |
139 // layer can not have a pile or tilings, it has only been created and inserted | 144 // layer can not have a pile or tilings, it has only been created and inserted |
140 // into the tree at that point. | 145 // into the tree at that point. |
141 twin_layer_ = layer_impl; | 146 twin_layer_ = layer_impl; |
142 layer_impl->twin_layer_ = this; | 147 layer_impl->twin_layer_ = this; |
143 | 148 |
144 layer_impl->set_is_mask(is_mask_); | 149 // Solid color layers have no tilings. |
145 layer_impl->UpdateRasterSource(raster_source_); | 150 DCHECK_IMPLIES(raster_source_->IsSolidColor(), tilings_->num_tilings() == 0); |
151 // The pending tree should only have a high res (and possibly low res) tiling. | |
152 DCHECK_LE(tilings_->num_tilings(), | |
153 layer_tree_impl()->create_low_res_tiling() ? 2u : 1u); | |
146 | 154 |
147 DCHECK_IMPLIES(raster_source_->IsSolidColor(), tilings_->num_tilings() == 0); | 155 layer_impl->UpdateRasterSource(raster_source_, &invalidation_, |
148 // Tilings would be expensive to push, so we swap. | 156 tilings_.get()); |
149 layer_impl->tilings_.swap(tilings_); | 157 DCHECK(invalidation_.IsEmpty()); |
150 layer_impl->tilings_->SetClient(layer_impl); | |
151 if (tilings_) | |
152 tilings_->SetClient(this); | |
153 | 158 |
154 // Ensure that the recycle tree doesn't have any unshared tiles. | 159 // After syncing a solid color layer, the active layer has no tilings. |
155 if (tilings_ && raster_source_->IsSolidColor()) | 160 DCHECK_IMPLIES(raster_source_->IsSolidColor(), |
156 tilings_->RemoveAllTilings(); | 161 !layer_impl->tilings_->num_tilings()); |
vmpstr
2014/12/09 00:10:19
nit: Above you do blah == 0, and here you do !blah
| |
157 | |
158 // Remove invalidated tiles from what will become a recycle tree. | |
159 if (tilings_) | |
160 tilings_->RemoveTilesInRegion(invalidation_); | |
161 | 162 |
162 layer_impl->raster_page_scale_ = raster_page_scale_; | 163 layer_impl->raster_page_scale_ = raster_page_scale_; |
163 layer_impl->raster_device_scale_ = raster_device_scale_; | 164 layer_impl->raster_device_scale_ = raster_device_scale_; |
164 layer_impl->raster_source_scale_ = raster_source_scale_; | 165 layer_impl->raster_source_scale_ = raster_source_scale_; |
165 layer_impl->raster_contents_scale_ = raster_contents_scale_; | 166 layer_impl->raster_contents_scale_ = raster_contents_scale_; |
166 layer_impl->low_res_raster_contents_scale_ = low_res_raster_contents_scale_; | 167 layer_impl->low_res_raster_contents_scale_ = low_res_raster_contents_scale_; |
168 | |
169 layer_impl->SanityCheckTilingState(); | |
170 | |
167 layer_impl->needs_post_commit_initialization_ = false; | 171 layer_impl->needs_post_commit_initialization_ = false; |
168 | |
169 // The invalidation on this soon-to-be-recycled layer must be cleared to | |
170 // mirror clearing the invalidation in PictureLayer's version of this function | |
171 // in case push properties is skipped. | |
172 layer_impl->invalidation_.Swap(&invalidation_); | |
173 invalidation_.Clear(); | |
174 needs_post_commit_initialization_ = true; | 172 needs_post_commit_initialization_ = true; |
175 | 173 |
176 // We always need to push properties. | 174 // We always need to push properties. |
177 // See http://crbug.com/303943 | 175 // See http://crbug.com/303943 |
176 // TODO(danakj): Stop always pushing properties since we don't swap tilings. | |
178 needs_push_properties_ = true; | 177 needs_push_properties_ = true; |
179 } | 178 } |
180 | 179 |
181 void PictureLayerImpl::UpdateRasterSource( | |
182 scoped_refptr<RasterSource> raster_source) { | |
183 bool could_have_tilings = CanHaveTilings(); | |
184 raster_source_.swap(raster_source); | |
185 | |
186 // Need to call UpdateTiles again if CanHaveTilings changed. | |
187 if (could_have_tilings != CanHaveTilings()) { | |
188 layer_tree_impl()->set_needs_update_draw_properties(); | |
189 } | |
190 } | |
191 | |
192 void PictureLayerImpl::AppendQuads(RenderPass* render_pass, | 180 void PictureLayerImpl::AppendQuads(RenderPass* render_pass, |
193 const Occlusion& occlusion_in_content_space, | 181 const Occlusion& occlusion_in_content_space, |
194 AppendQuadsData* append_quads_data) { | 182 AppendQuadsData* append_quads_data) { |
195 DCHECK(!needs_post_commit_initialization_); | 183 DCHECK(!needs_post_commit_initialization_); |
196 // The bounds and the pile size may differ if the pile wasn't updated (ie. | 184 // The bounds and the pile size may differ if the pile wasn't updated (ie. |
197 // PictureLayer::Update didn't happen). In that case the pile will be empty. | 185 // PictureLayer::Update didn't happen). In that case the pile will be empty. |
198 DCHECK_IMPLIES(!raster_source_->GetSize().IsEmpty(), | 186 DCHECK_IMPLIES(!raster_source_->GetSize().IsEmpty(), |
199 bounds() == raster_source_->GetSize()) | 187 bounds() == raster_source_->GetSize()) |
200 << " bounds " << bounds().ToString() << " pile " | 188 << " bounds " << bounds().ToString() << " pile " |
201 << raster_source_->GetSize().ToString(); | 189 << raster_source_->GetSize().ToString(); |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
485 ideal_page_scale_ = 0.f; | 473 ideal_page_scale_ = 0.f; |
486 ideal_device_scale_ = 0.f; | 474 ideal_device_scale_ = 0.f; |
487 ideal_contents_scale_ = 0.f; | 475 ideal_contents_scale_ = 0.f; |
488 ideal_source_scale_ = 0.f; | 476 ideal_source_scale_ = 0.f; |
489 SanityCheckTilingState(); | 477 SanityCheckTilingState(); |
490 return; | 478 return; |
491 } | 479 } |
492 | 480 |
493 UpdateIdealScales(); | 481 UpdateIdealScales(); |
494 | 482 |
495 DCHECK_IMPLIES(tilings_->num_tilings() == 0, raster_contents_scale_ == 0.f) | |
496 << "A layer with no tilings shouldn't have valid raster scales"; | |
497 if (!raster_contents_scale_ || ShouldAdjustRasterScale()) { | 483 if (!raster_contents_scale_ || ShouldAdjustRasterScale()) { |
498 RecalculateRasterScales(); | 484 RecalculateRasterScales(); |
499 AddTilingsForRasterScale(); | 485 AddTilingsForRasterScale(); |
500 } | 486 } |
501 | 487 |
502 DCHECK(raster_page_scale_); | 488 DCHECK(raster_page_scale_); |
503 DCHECK(raster_device_scale_); | 489 DCHECK(raster_device_scale_); |
504 DCHECK(raster_source_scale_); | 490 DCHECK(raster_source_scale_); |
505 DCHECK(raster_contents_scale_); | 491 DCHECK(raster_contents_scale_); |
506 DCHECK(low_res_raster_contents_scale_); | 492 DCHECK(low_res_raster_contents_scale_); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
581 return nullptr; | 567 return nullptr; |
582 return twin_layer_; | 568 return twin_layer_; |
583 } | 569 } |
584 | 570 |
585 PictureLayerImpl* PictureLayerImpl::GetRecycledTwinLayer() const { | 571 PictureLayerImpl* PictureLayerImpl::GetRecycledTwinLayer() const { |
586 if (!twin_layer_ || twin_layer_->IsOnActiveOrPendingTree()) | 572 if (!twin_layer_ || twin_layer_->IsOnActiveOrPendingTree()) |
587 return nullptr; | 573 return nullptr; |
588 return twin_layer_; | 574 return twin_layer_; |
589 } | 575 } |
590 | 576 |
577 void PictureLayerImpl::UpdateRasterSource( | |
578 scoped_refptr<RasterSource> raster_source, | |
579 Region* new_invalidation, | |
580 const PictureLayerTilingSet* pending_set) { | |
581 // The bounds and the pile size may differ if the pile wasn't updated (ie. | |
582 // PictureLayer::Update didn't happen). In that case the pile will be empty. | |
583 DCHECK_IMPLIES(!raster_source->GetSize().IsEmpty(), | |
584 bounds() == raster_source->GetSize()) | |
585 << " bounds " << bounds().ToString() << " pile " | |
586 << raster_source->GetSize().ToString(); | |
587 | |
588 bool could_have_tilings = CanHaveTilings(); | |
589 raster_source_.swap(raster_source); | |
590 | |
591 // The |new_invalidation| must be cleared before updating tilings since they | |
592 // access the invalidation through the PictureLayerTilingClient interface. | |
593 invalidation_.Clear(); | |
594 invalidation_.Swap(new_invalidation); | |
595 | |
596 bool can_have_tilings = CanHaveTilings(); | |
597 | |
598 // Need to call UpdateTiles again if CanHaveTilings changed. | |
599 if (could_have_tilings != can_have_tilings) | |
600 layer_tree_impl()->set_needs_update_draw_properties(); | |
601 | |
602 if (!can_have_tilings) { | |
603 RemoveAllTilings(); | |
604 return; | |
605 } | |
606 | |
607 // We could do this after doing UpdateTiles, which would avoid doing this for | |
608 // tilings that are going to disappear on the pending tree (if scale changed). | |
609 // But that would also be more complicated, so we just do it here for now. | |
610 tilings_->UpdateTilingsToCurrentRasterSource( | |
611 raster_source_.get(), pending_set, raster_source_->GetSize(), | |
612 invalidation_, MinimumContentsScale()); | |
613 } | |
614 | |
591 void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) { | 615 void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) { |
592 if (layer_tree_impl()->IsActiveTree()) { | 616 if (layer_tree_impl()->IsActiveTree()) { |
593 gfx::RectF layer_damage_rect = | 617 gfx::RectF layer_damage_rect = |
594 gfx::ScaleRect(tile->content_rect(), 1.f / tile->contents_scale()); | 618 gfx::ScaleRect(tile->content_rect(), 1.f / tile->contents_scale()); |
595 AddDamageRect(layer_damage_rect); | 619 AddDamageRect(layer_damage_rect); |
596 } | 620 } |
597 } | 621 } |
598 | 622 |
599 void PictureLayerImpl::DidBecomeActive() { | 623 void PictureLayerImpl::DidBecomeActive() { |
600 LayerImpl::DidBecomeActive(); | 624 LayerImpl::DidBecomeActive(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
652 if (PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer()) | 676 if (PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer()) |
653 return &twin_layer->invalidation_; | 677 return &twin_layer->invalidation_; |
654 return nullptr; | 678 return nullptr; |
655 } | 679 } |
656 | 680 |
657 const PictureLayerTiling* PictureLayerImpl::GetPendingOrActiveTwinTiling( | 681 const PictureLayerTiling* PictureLayerImpl::GetPendingOrActiveTwinTiling( |
658 const PictureLayerTiling* tiling) const { | 682 const PictureLayerTiling* tiling) const { |
659 PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer(); | 683 PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer(); |
660 if (!twin_layer) | 684 if (!twin_layer) |
661 return nullptr; | 685 return nullptr; |
662 // TODO(danakj): Remove this when no longer swapping tilings. | |
663 if (!twin_layer->tilings_) | |
664 return nullptr; | |
665 return twin_layer->tilings_->FindTilingWithScale(tiling->contents_scale()); | 686 return twin_layer->tilings_->FindTilingWithScale(tiling->contents_scale()); |
666 } | 687 } |
667 | 688 |
668 PictureLayerTiling* PictureLayerImpl::GetRecycledTwinTiling( | 689 PictureLayerTiling* PictureLayerImpl::GetRecycledTwinTiling( |
669 const PictureLayerTiling* tiling) { | 690 const PictureLayerTiling* tiling) { |
670 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); | 691 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); |
671 if (!recycled_twin || !recycled_twin->tilings_) | 692 if (!recycled_twin || !recycled_twin->tilings_) |
672 return nullptr; | 693 return nullptr; |
673 return recycled_twin->tilings_->FindTilingWithScale(tiling->contents_scale()); | 694 return recycled_twin->tilings_->FindTilingWithScale(tiling->contents_scale()); |
674 } | 695 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
773 tile_height = RoundUp(tile_height, kTileRoundUp); | 794 tile_height = RoundUp(tile_height, kTileRoundUp); |
774 tile_height = std::min(tile_height, default_tile_height); | 795 tile_height = std::min(tile_height, default_tile_height); |
775 } | 796 } |
776 | 797 |
777 // Under no circumstance should we be larger than the max texture size. | 798 // Under no circumstance should we be larger than the max texture size. |
778 tile_width = std::min(tile_width, max_texture_size); | 799 tile_width = std::min(tile_width, max_texture_size); |
779 tile_height = std::min(tile_height, max_texture_size); | 800 tile_height = std::min(tile_height, max_texture_size); |
780 return gfx::Size(tile_width, tile_height); | 801 return gfx::Size(tile_width, tile_height); |
781 } | 802 } |
782 | 803 |
783 void PictureLayerImpl::SyncFromActiveLayer(const PictureLayerImpl* other) { | |
784 DCHECK(!other->needs_post_commit_initialization_); | |
785 DCHECK(other->tilings_); | |
786 | |
787 if (!DrawsContent()) { | |
788 RemoveAllTilings(); | |
789 return; | |
790 } | |
791 | |
792 raster_page_scale_ = other->raster_page_scale_; | |
793 raster_device_scale_ = other->raster_device_scale_; | |
794 raster_source_scale_ = other->raster_source_scale_; | |
795 raster_contents_scale_ = other->raster_contents_scale_; | |
796 low_res_raster_contents_scale_ = other->low_res_raster_contents_scale_; | |
797 | |
798 bool synced_high_res_tiling = false; | |
799 if (CanHaveTilings()) { | |
800 synced_high_res_tiling = tilings_->SyncTilings( | |
801 *other->tilings_, raster_source_->GetSize(), invalidation_, | |
802 MinimumContentsScale(), raster_source_.get()); | |
803 } else { | |
804 RemoveAllTilings(); | |
805 } | |
806 | |
807 // If our MinimumContentsScale has changed to prevent the twin's high res | |
808 // tiling from being synced, we should reset the raster scale and let it be | |
809 // recalculated (1) again. This can happen if our bounds shrink to the point | |
810 // where min contents scale grows. | |
811 // (1) - TODO(vmpstr) Instead of hoping that this will be recalculated, we | |
812 // should refactor this code a little bit and actually recalculate this. | |
813 // However, this is a larger undertaking, so this will work for now. | |
814 if (!synced_high_res_tiling) | |
815 ResetRasterScale(); | |
816 else | |
817 SanityCheckTilingState(); | |
818 } | |
819 | |
820 void PictureLayerImpl::SyncTiling( | |
821 const PictureLayerTiling* tiling) { | |
822 if (!tilings_) | |
823 return; | |
824 if (!CanHaveTilingWithScale(tiling->contents_scale())) | |
825 return; | |
826 tilings_->AddTiling(tiling->contents_scale(), raster_source_->GetSize()); | |
827 | |
828 // If this tree needs update draw properties, then the tiling will | |
829 // get updated prior to drawing or activation. If this tree does not | |
830 // need update draw properties, then its transforms are up to date and | |
831 // we can create tiles for this tiling immediately. | |
832 if (!layer_tree_impl()->needs_update_draw_properties() && | |
833 should_update_tile_priorities_) { | |
834 // TODO(danakj): Add a DCHECK() that we are not using occlusion tracking | |
835 // when we stop using the pending tree in the browser compositor. If we want | |
836 // to support occlusion tracking here, we need to dirty the draw properties | |
837 // or save occlusion as a draw property. | |
838 UpdateTilePriorities(Occlusion()); | |
839 } | |
840 } | |
841 | |
842 void PictureLayerImpl::GetContentsResourceId( | 804 void PictureLayerImpl::GetContentsResourceId( |
843 ResourceProvider::ResourceId* resource_id, | 805 ResourceProvider::ResourceId* resource_id, |
844 gfx::Size* resource_size) const { | 806 gfx::Size* resource_size) const { |
845 DCHECK_EQ(bounds().ToString(), raster_source_->GetSize().ToString()); | 807 // The bounds and the pile size may differ if the pile wasn't updated (ie. |
808 // PictureLayer::Update didn't happen). In that case the pile will be empty. | |
809 DCHECK_IMPLIES(!raster_source_->GetSize().IsEmpty(), | |
810 bounds() == raster_source_->GetSize()) | |
811 << " bounds " << bounds().ToString() << " pile " | |
812 << raster_source_->GetSize().ToString(); | |
846 gfx::Rect content_rect(bounds()); | 813 gfx::Rect content_rect(bounds()); |
847 PictureLayerTilingSet::CoverageIterator iter( | 814 PictureLayerTilingSet::CoverageIterator iter( |
848 tilings_.get(), 1.f, content_rect, ideal_contents_scale_); | 815 tilings_.get(), 1.f, content_rect, ideal_contents_scale_); |
849 | 816 |
850 // Mask resource not ready yet. | 817 // Mask resource not ready yet. |
851 if (!iter || !*iter) { | 818 if (!iter || !*iter) { |
852 *resource_id = 0; | 819 *resource_id = 0; |
853 return; | 820 return; |
854 } | 821 } |
855 | 822 |
856 // Masks only supported if they fit on exactly one tile. | 823 // Masks only supported if they fit on exactly one tile. |
857 DCHECK(iter.geometry_rect() == content_rect) | 824 DCHECK(iter.geometry_rect() == content_rect) |
858 << "iter rect " << iter.geometry_rect().ToString() << " content rect " | 825 << "iter rect " << iter.geometry_rect().ToString() << " content rect " |
859 << content_rect.ToString(); | 826 << content_rect.ToString(); |
860 | 827 |
861 const ManagedTileState::DrawInfo& draw_info = iter->draw_info(); | 828 const ManagedTileState::DrawInfo& draw_info = iter->draw_info(); |
862 if (!draw_info.IsReadyToDraw() || | 829 if (!draw_info.IsReadyToDraw() || |
863 draw_info.mode() != ManagedTileState::DrawInfo::RESOURCE_MODE) { | 830 draw_info.mode() != ManagedTileState::DrawInfo::RESOURCE_MODE) { |
864 *resource_id = 0; | 831 *resource_id = 0; |
865 return; | 832 return; |
866 } | 833 } |
867 | 834 |
868 *resource_id = draw_info.get_resource_id(); | 835 *resource_id = draw_info.get_resource_id(); |
869 *resource_size = iter.texture_size(); | 836 *resource_size = iter.texture_size(); |
870 } | 837 } |
871 | 838 |
872 void PictureLayerImpl::DoPostCommitInitialization() { | 839 void PictureLayerImpl::DoPostCommitInitialization() { |
840 // TODO(danakj): Remove this. | |
873 DCHECK(needs_post_commit_initialization_); | 841 DCHECK(needs_post_commit_initialization_); |
874 DCHECK(layer_tree_impl()->IsPendingTree()); | 842 DCHECK(layer_tree_impl()->IsPendingTree()); |
875 | |
876 if (!tilings_) | |
877 tilings_ = PictureLayerTilingSet::Create(this); | |
878 | |
879 PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer(); | |
880 if (twin_layer) { | |
881 // If the twin has never been pushed to, do not sync from it. | |
882 // This can happen if this function is called during activation. | |
883 if (!twin_layer->needs_post_commit_initialization_) | |
884 SyncFromActiveLayer(twin_layer); | |
885 } | |
886 | |
887 needs_post_commit_initialization_ = false; | 843 needs_post_commit_initialization_ = false; |
888 } | 844 } |
889 | 845 |
890 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { | 846 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { |
891 DCHECK(CanHaveTilingWithScale(contents_scale)) << | 847 DCHECK(CanHaveTilingWithScale(contents_scale)) << |
892 "contents_scale: " << contents_scale; | 848 "contents_scale: " << contents_scale; |
893 | 849 |
894 PictureLayerTiling* tiling = | 850 PictureLayerTiling* tiling = |
895 tilings_->AddTiling(contents_scale, raster_source_->GetSize()); | 851 tilings_->AddTiling(contents_scale, raster_source_->GetSize()); |
896 | 852 |
897 DCHECK(raster_source_->HasRecordings()); | 853 DCHECK(raster_source_->HasRecordings()); |
898 | 854 |
899 if (PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer()) | |
900 twin_layer->SyncTiling(tiling); | |
901 | |
902 return tiling; | 855 return tiling; |
903 } | 856 } |
904 | 857 |
905 void PictureLayerImpl::RemoveAllTilings() { | 858 void PictureLayerImpl::RemoveAllTilings() { |
906 if (tilings_) | 859 if (tilings_) |
907 tilings_->RemoveAllTilings(); | 860 tilings_->RemoveAllTilings(); |
908 // If there are no tilings, then raster scales are no longer meaningful. | 861 // If there are no tilings, then raster scales are no longer meaningful. |
909 ResetRasterScale(); | 862 ResetRasterScale(); |
910 } | 863 } |
911 | 864 |
(...skipping 25 matching lines...) Expand all Loading... | |
937 if (can_have_low_res && needs_low_res && !is_pinching && !is_animating) | 890 if (can_have_low_res && needs_low_res && !is_pinching && !is_animating) |
938 low_res = AddTiling(low_res_raster_contents_scale_); | 891 low_res = AddTiling(low_res_raster_contents_scale_); |
939 | 892 |
940 // Set low-res if we have one. | 893 // Set low-res if we have one. |
941 if (low_res && low_res != high_res) | 894 if (low_res && low_res != high_res) |
942 low_res->set_resolution(LOW_RESOLUTION); | 895 low_res->set_resolution(LOW_RESOLUTION); |
943 | 896 |
944 // Make sure we always have one high-res (even if high == low). | 897 // Make sure we always have one high-res (even if high == low). |
945 high_res->set_resolution(HIGH_RESOLUTION); | 898 high_res->set_resolution(HIGH_RESOLUTION); |
946 | 899 |
900 if (layer_tree_impl()->IsPendingTree()) { | |
901 // On the pending tree, drop any tilings that are non-ideal since we don't | |
902 // need them to activate anyway. | |
903 tilings_->RemoveNonIdealTilings(); | |
904 } | |
905 | |
947 SanityCheckTilingState(); | 906 SanityCheckTilingState(); |
948 } | 907 } |
949 | 908 |
950 bool PictureLayerImpl::ShouldAdjustRasterScale() const { | 909 bool PictureLayerImpl::ShouldAdjustRasterScale() const { |
951 if (was_screen_space_transform_animating_ != | 910 if (was_screen_space_transform_animating_ != |
952 draw_properties().screen_space_transform_is_animating) | 911 draw_properties().screen_space_transform_is_animating) |
953 return true; | 912 return true; |
954 | 913 |
955 if (draw_properties().screen_space_transform_is_animating && | 914 if (draw_properties().screen_space_transform_is_animating && |
956 raster_contents_scale_ != ideal_contents_scale_ && | 915 raster_contents_scale_ != ideal_contents_scale_ && |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1121 PictureLayerTilingSet* twin_set = twin ? twin->tilings_.get() : nullptr; | 1080 PictureLayerTilingSet* twin_set = twin ? twin->tilings_.get() : nullptr; |
1122 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); | 1081 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); |
1123 PictureLayerTilingSet* recycled_twin_set = | 1082 PictureLayerTilingSet* recycled_twin_set = |
1124 recycled_twin ? recycled_twin->tilings_.get() : nullptr; | 1083 recycled_twin ? recycled_twin->tilings_.get() : nullptr; |
1125 | 1084 |
1126 tilings_->CleanUpTilings(min_acceptable_high_res_scale, | 1085 tilings_->CleanUpTilings(min_acceptable_high_res_scale, |
1127 max_acceptable_high_res_scale, used_tilings, | 1086 max_acceptable_high_res_scale, used_tilings, |
1128 layer_tree_impl()->create_low_res_tiling(), twin_set, | 1087 layer_tree_impl()->create_low_res_tiling(), twin_set, |
1129 recycled_twin_set); | 1088 recycled_twin_set); |
1130 | 1089 |
1131 if (twin_set && twin_set->num_tilings() == 0) | |
1132 twin->ResetRasterScale(); | |
1133 | |
1134 if (recycled_twin_set && recycled_twin_set->num_tilings() == 0) | 1090 if (recycled_twin_set && recycled_twin_set->num_tilings() == 0) |
1135 recycled_twin->ResetRasterScale(); | 1091 recycled_twin->ResetRasterScale(); |
1136 | 1092 |
1137 DCHECK_GT(tilings_->num_tilings(), 0u); | 1093 DCHECK_GT(tilings_->num_tilings(), 0u); |
1138 SanityCheckTilingState(); | 1094 SanityCheckTilingState(); |
1139 } | 1095 } |
1140 | 1096 |
1141 float PictureLayerImpl::MinimumContentsScale() const { | 1097 float PictureLayerImpl::MinimumContentsScale() const { |
1142 float setting_min = layer_tree_impl()->settings().minimum_contents_scale; | 1098 float setting_min = layer_tree_impl()->settings().minimum_contents_scale; |
1143 | 1099 |
(...skipping 22 matching lines...) Expand all Loading... | |
1166 should_update_tile_priorities_ = false; | 1122 should_update_tile_priorities_ = false; |
1167 } | 1123 } |
1168 | 1124 |
1169 bool PictureLayerImpl::CanHaveTilings() const { | 1125 bool PictureLayerImpl::CanHaveTilings() const { |
1170 if (raster_source_->IsSolidColor()) | 1126 if (raster_source_->IsSolidColor()) |
1171 return false; | 1127 return false; |
1172 if (!DrawsContent()) | 1128 if (!DrawsContent()) |
1173 return false; | 1129 return false; |
1174 if (!raster_source_->HasRecordings()) | 1130 if (!raster_source_->HasRecordings()) |
1175 return false; | 1131 return false; |
1132 // If the |raster_source_| has a recording it should have non-empty bounds. | |
1133 DCHECK(!raster_source_->GetSize().IsEmpty()); | |
1176 return true; | 1134 return true; |
1177 } | 1135 } |
1178 | 1136 |
1179 bool PictureLayerImpl::CanHaveTilingWithScale(float contents_scale) const { | 1137 bool PictureLayerImpl::CanHaveTilingWithScale(float contents_scale) const { |
1180 if (!CanHaveTilings()) | 1138 if (!CanHaveTilings()) |
1181 return false; | 1139 return false; |
1182 if (contents_scale < MinimumContentsScale()) | 1140 if (contents_scale < MinimumContentsScale()) |
1183 return false; | 1141 return false; |
1184 return true; | 1142 return true; |
1185 } | 1143 } |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1370 | 1328 |
1371 bool PictureLayerImpl::AllTilesRequiredForDrawAreReadyToDraw() const { | 1329 bool PictureLayerImpl::AllTilesRequiredForDrawAreReadyToDraw() const { |
1372 if (!layer_tree_impl()->IsActiveTree()) | 1330 if (!layer_tree_impl()->IsActiveTree()) |
1373 return true; | 1331 return true; |
1374 | 1332 |
1375 return AllTilesRequiredAreReadyToDraw( | 1333 return AllTilesRequiredAreReadyToDraw( |
1376 &PictureLayerTiling::IsTileRequiredForDrawIfVisible); | 1334 &PictureLayerTiling::IsTileRequiredForDrawIfVisible); |
1377 } | 1335 } |
1378 | 1336 |
1379 } // namespace cc | 1337 } // namespace cc |
OLD | NEW |