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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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, int id) |
74 : LayerImpl(tree_impl, id), | 74 : LayerImpl(tree_impl, id), |
75 twin_layer_(nullptr), | 75 twin_layer_(nullptr), |
| 76 tilings_(PictureLayerTilingSet::Create(this)), |
| 77 // TODO(danakj): Can this be null to start? |
76 raster_source_(PicturePileImpl::Create()), | 78 raster_source_(PicturePileImpl::Create()), |
77 ideal_page_scale_(0.f), | 79 ideal_page_scale_(0.f), |
78 ideal_device_scale_(0.f), | 80 ideal_device_scale_(0.f), |
79 ideal_source_scale_(0.f), | 81 ideal_source_scale_(0.f), |
80 ideal_contents_scale_(0.f), | 82 ideal_contents_scale_(0.f), |
81 raster_page_scale_(0.f), | 83 raster_page_scale_(0.f), |
82 raster_device_scale_(0.f), | 84 raster_device_scale_(0.f), |
83 raster_source_scale_(0.f), | 85 raster_source_scale_(0.f), |
84 raster_contents_scale_(0.f), | 86 raster_contents_scale_(0.f), |
85 low_res_raster_contents_scale_(0.f), | 87 low_res_raster_contents_scale_(0.f), |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 // Twin relationships should never change once established. | 128 // Twin relationships should never change once established. |
127 DCHECK_IMPLIES(twin_layer_, twin_layer_ == layer_impl); | 129 DCHECK_IMPLIES(twin_layer_, twin_layer_ == layer_impl); |
128 DCHECK_IMPLIES(twin_layer_, layer_impl->twin_layer_ == this); | 130 DCHECK_IMPLIES(twin_layer_, layer_impl->twin_layer_ == this); |
129 // The twin relationship does not need to exist before the first | 131 // The twin relationship does not need to exist before the first |
130 // PushPropertiesTo from pending to active layer since before that the active | 132 // PushPropertiesTo from pending to active layer since before that the active |
131 // layer can not have a pile or tilings, it has only been created and inserted | 133 // layer can not have a pile or tilings, it has only been created and inserted |
132 // into the tree at that point. | 134 // into the tree at that point. |
133 twin_layer_ = layer_impl; | 135 twin_layer_ = layer_impl; |
134 layer_impl->twin_layer_ = this; | 136 layer_impl->twin_layer_ = this; |
135 | 137 |
136 layer_impl->set_is_mask(is_mask_); | 138 // Solid color layers have no tilings. |
137 layer_impl->UpdateRasterSource(raster_source_); | 139 DCHECK_IMPLIES(raster_source_->IsSolidColor(), tilings_->num_tilings() == 0); |
| 140 // The pending tree should only have a high res (and possibly low res) tiling. |
| 141 DCHECK_LE(tilings_->num_tilings(), |
| 142 layer_tree_impl()->create_low_res_tiling() ? 2u : 1u); |
138 | 143 |
139 DCHECK_IMPLIES(raster_source_->IsSolidColor(), tilings_->num_tilings() == 0); | 144 layer_impl->UpdateRasterSource(raster_source_, &invalidation_, is_mask_, |
140 // Tilings would be expensive to push, so we swap. | 145 tilings_.get()); |
141 layer_impl->tilings_.swap(tilings_); | 146 DCHECK(invalidation_.IsEmpty()); |
142 layer_impl->tilings_->SetClient(layer_impl); | |
143 if (tilings_) | |
144 tilings_->SetClient(this); | |
145 | 147 |
146 // Ensure that the recycle tree doesn't have any unshared tiles. | 148 // After syncing a solid color layer, the active layer has no tilings. |
147 if (tilings_ && raster_source_->IsSolidColor()) | 149 DCHECK_IMPLIES(raster_source_->IsSolidColor(), |
148 tilings_->RemoveAllTilings(); | 150 !layer_impl->tilings_->num_tilings()); |
149 | |
150 // Remove invalidated tiles from what will become a recycle tree. | |
151 if (tilings_) | |
152 tilings_->RemoveTilesInRegion(invalidation_); | |
153 | 151 |
154 layer_impl->raster_page_scale_ = raster_page_scale_; | 152 layer_impl->raster_page_scale_ = raster_page_scale_; |
155 layer_impl->raster_device_scale_ = raster_device_scale_; | 153 layer_impl->raster_device_scale_ = raster_device_scale_; |
156 layer_impl->raster_source_scale_ = raster_source_scale_; | 154 layer_impl->raster_source_scale_ = raster_source_scale_; |
157 layer_impl->raster_contents_scale_ = raster_contents_scale_; | 155 layer_impl->raster_contents_scale_ = raster_contents_scale_; |
158 layer_impl->low_res_raster_contents_scale_ = low_res_raster_contents_scale_; | 156 layer_impl->low_res_raster_contents_scale_ = low_res_raster_contents_scale_; |
| 157 |
| 158 layer_impl->SanityCheckTilingState(); |
| 159 |
159 layer_impl->needs_post_commit_initialization_ = false; | 160 layer_impl->needs_post_commit_initialization_ = false; |
160 | |
161 // The invalidation on this soon-to-be-recycled layer must be cleared to | |
162 // mirror clearing the invalidation in PictureLayer's version of this function | |
163 // in case push properties is skipped. | |
164 layer_impl->invalidation_.Swap(&invalidation_); | |
165 invalidation_.Clear(); | |
166 needs_post_commit_initialization_ = true; | 161 needs_post_commit_initialization_ = true; |
167 | 162 |
168 // We always need to push properties. | 163 // We always need to push properties. |
169 // See http://crbug.com/303943 | 164 // See http://crbug.com/303943 |
| 165 // TODO(danakj): Stop always pushing properties since we don't swap tilings. |
170 needs_push_properties_ = true; | 166 needs_push_properties_ = true; |
171 } | 167 } |
172 | 168 |
173 void PictureLayerImpl::UpdateRasterSource( | |
174 scoped_refptr<RasterSource> raster_source) { | |
175 bool could_have_tilings = CanHaveTilings(); | |
176 raster_source_.swap(raster_source); | |
177 | |
178 // Need to call UpdateTiles again if CanHaveTilings changed. | |
179 if (could_have_tilings != CanHaveTilings()) { | |
180 layer_tree_impl()->set_needs_update_draw_properties(); | |
181 } | |
182 } | |
183 | |
184 void PictureLayerImpl::AppendQuads(RenderPass* render_pass, | 169 void PictureLayerImpl::AppendQuads(RenderPass* render_pass, |
185 const Occlusion& occlusion_in_content_space, | 170 const Occlusion& occlusion_in_content_space, |
186 AppendQuadsData* append_quads_data) { | 171 AppendQuadsData* append_quads_data) { |
187 DCHECK(!needs_post_commit_initialization_); | 172 DCHECK(!needs_post_commit_initialization_); |
188 // The bounds and the pile size may differ if the pile wasn't updated (ie. | 173 // The bounds and the pile size may differ if the pile wasn't updated (ie. |
189 // PictureLayer::Update didn't happen). In that case the pile will be empty. | 174 // PictureLayer::Update didn't happen). In that case the pile will be empty. |
190 DCHECK_IMPLIES(!raster_source_->GetSize().IsEmpty(), | 175 DCHECK_IMPLIES(!raster_source_->GetSize().IsEmpty(), |
191 bounds() == raster_source_->GetSize()) | 176 bounds() == raster_source_->GetSize()) |
192 << " bounds " << bounds().ToString() << " pile " | 177 << " bounds " << bounds().ToString() << " pile " |
193 << raster_source_->GetSize().ToString(); | 178 << raster_source_->GetSize().ToString(); |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 ideal_page_scale_ = 0.f; | 462 ideal_page_scale_ = 0.f; |
478 ideal_device_scale_ = 0.f; | 463 ideal_device_scale_ = 0.f; |
479 ideal_contents_scale_ = 0.f; | 464 ideal_contents_scale_ = 0.f; |
480 ideal_source_scale_ = 0.f; | 465 ideal_source_scale_ = 0.f; |
481 SanityCheckTilingState(); | 466 SanityCheckTilingState(); |
482 return; | 467 return; |
483 } | 468 } |
484 | 469 |
485 UpdateIdealScales(); | 470 UpdateIdealScales(); |
486 | 471 |
487 DCHECK_IMPLIES(tilings_->num_tilings() == 0, raster_contents_scale_ == 0.f) | |
488 << "A layer with no tilings shouldn't have valid raster scales"; | |
489 if (!raster_contents_scale_ || ShouldAdjustRasterScale()) { | 472 if (!raster_contents_scale_ || ShouldAdjustRasterScale()) { |
490 RecalculateRasterScales(); | 473 RecalculateRasterScales(); |
491 AddTilingsForRasterScale(); | 474 AddTilingsForRasterScale(); |
492 } | 475 } |
493 | 476 |
494 DCHECK(raster_page_scale_); | 477 DCHECK(raster_page_scale_); |
495 DCHECK(raster_device_scale_); | 478 DCHECK(raster_device_scale_); |
496 DCHECK(raster_source_scale_); | 479 DCHECK(raster_source_scale_); |
497 DCHECK(raster_contents_scale_); | 480 DCHECK(raster_contents_scale_); |
498 DCHECK(low_res_raster_contents_scale_); | 481 DCHECK(low_res_raster_contents_scale_); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 return nullptr; | 556 return nullptr; |
574 return twin_layer_; | 557 return twin_layer_; |
575 } | 558 } |
576 | 559 |
577 PictureLayerImpl* PictureLayerImpl::GetRecycledTwinLayer() const { | 560 PictureLayerImpl* PictureLayerImpl::GetRecycledTwinLayer() const { |
578 if (!twin_layer_ || twin_layer_->IsOnActiveOrPendingTree()) | 561 if (!twin_layer_ || twin_layer_->IsOnActiveOrPendingTree()) |
579 return nullptr; | 562 return nullptr; |
580 return twin_layer_; | 563 return twin_layer_; |
581 } | 564 } |
582 | 565 |
| 566 void PictureLayerImpl::UpdateRasterSource( |
| 567 scoped_refptr<RasterSource> raster_source, |
| 568 Region* new_invalidation, |
| 569 bool is_mask, |
| 570 const PictureLayerTilingSet* pending_set) { |
| 571 // The bounds and the pile size may differ if the pile wasn't updated (ie. |
| 572 // PictureLayer::Update didn't happen). In that case the pile will be empty. |
| 573 DCHECK_IMPLIES(!raster_source->GetSize().IsEmpty(), |
| 574 bounds() == raster_source->GetSize()) |
| 575 << " bounds " << bounds().ToString() << " pile " |
| 576 << raster_source->GetSize().ToString(); |
| 577 |
| 578 bool could_have_tilings = CanHaveTilings(); |
| 579 raster_source_.swap(raster_source); |
| 580 |
| 581 // The |new_invalidation| must be cleared before updating tilings since they |
| 582 // access the invalidation through the PictureLayerTilingClient interface. |
| 583 invalidation_.Clear(); |
| 584 invalidation_.Swap(new_invalidation); |
| 585 |
| 586 is_mask_ = is_mask; |
| 587 |
| 588 bool can_have_tilings = CanHaveTilings(); |
| 589 |
| 590 // Need to call UpdateTiles again if CanHaveTilings changed. |
| 591 if (could_have_tilings != can_have_tilings) |
| 592 layer_tree_impl()->set_needs_update_draw_properties(); |
| 593 |
| 594 if (!can_have_tilings) { |
| 595 RemoveAllTilings(); |
| 596 return; |
| 597 } |
| 598 |
| 599 // We could do this after doing UpdateTiles, which would avoid doing this for |
| 600 // tilings that are going to disappear on the pending tree (if scale changed). |
| 601 // But that would also be more complicated, so we just do it here for now. |
| 602 // TODO(danakj): Just pass along the pile to this function instead of using |
| 603 // the client API? |
| 604 // TODO(danakj): What I mean here is IsSyncTree, for the commit to active |
| 605 // case. |
| 606 if (layer_tree_impl()->IsPendingTree()) { |
| 607 tilings_->UpdateTilingsToCurrentRasterSource( |
| 608 raster_source_.get(), raster_source_->GetSize(), invalidation_, |
| 609 MinimumContentsScale()); |
| 610 } else { |
| 611 tilings_->UpdateTilingsFromPending(raster_source_.get(), *pending_set, |
| 612 raster_source_->GetSize(), invalidation_, |
| 613 MinimumContentsScale()); |
| 614 } |
| 615 } |
| 616 |
583 void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) { | 617 void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) { |
584 if (layer_tree_impl()->IsActiveTree()) { | 618 if (layer_tree_impl()->IsActiveTree()) { |
585 gfx::RectF layer_damage_rect = | 619 gfx::RectF layer_damage_rect = |
586 gfx::ScaleRect(tile->content_rect(), 1.f / tile->contents_scale()); | 620 gfx::ScaleRect(tile->content_rect(), 1.f / tile->contents_scale()); |
587 AddDamageRect(layer_damage_rect); | 621 AddDamageRect(layer_damage_rect); |
588 } | 622 } |
589 } | 623 } |
590 | 624 |
591 void PictureLayerImpl::DidBecomeActive() { | 625 void PictureLayerImpl::DidBecomeActive() { |
592 LayerImpl::DidBecomeActive(); | 626 LayerImpl::DidBecomeActive(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 if (PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer()) | 678 if (PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer()) |
645 return &twin_layer->invalidation_; | 679 return &twin_layer->invalidation_; |
646 return nullptr; | 680 return nullptr; |
647 } | 681 } |
648 | 682 |
649 const PictureLayerTiling* PictureLayerImpl::GetPendingOrActiveTwinTiling( | 683 const PictureLayerTiling* PictureLayerImpl::GetPendingOrActiveTwinTiling( |
650 const PictureLayerTiling* tiling) const { | 684 const PictureLayerTiling* tiling) const { |
651 PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer(); | 685 PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer(); |
652 if (!twin_layer) | 686 if (!twin_layer) |
653 return nullptr; | 687 return nullptr; |
654 // TODO(danakj): Remove this when no longer swapping tilings. | |
655 if (!twin_layer->tilings_) | |
656 return nullptr; | |
657 return twin_layer->tilings_->FindTilingWithScale(tiling->contents_scale()); | 688 return twin_layer->tilings_->FindTilingWithScale(tiling->contents_scale()); |
658 } | 689 } |
659 | 690 |
660 PictureLayerTiling* PictureLayerImpl::GetRecycledTwinTiling( | 691 PictureLayerTiling* PictureLayerImpl::GetRecycledTwinTiling( |
661 const PictureLayerTiling* tiling) { | 692 const PictureLayerTiling* tiling) { |
662 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); | 693 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); |
663 if (!recycled_twin || !recycled_twin->tilings_) | 694 if (!recycled_twin || !recycled_twin->tilings_) |
664 return nullptr; | 695 return nullptr; |
665 return recycled_twin->tilings_->FindTilingWithScale(tiling->contents_scale()); | 696 return recycled_twin->tilings_->FindTilingWithScale(tiling->contents_scale()); |
666 } | 697 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 tile_height = RoundUp(tile_height, kTileRoundUp); | 796 tile_height = RoundUp(tile_height, kTileRoundUp); |
766 tile_height = std::min(tile_height, default_tile_height); | 797 tile_height = std::min(tile_height, default_tile_height); |
767 } | 798 } |
768 | 799 |
769 // Under no circumstance should we be larger than the max texture size. | 800 // Under no circumstance should we be larger than the max texture size. |
770 tile_width = std::min(tile_width, max_texture_size); | 801 tile_width = std::min(tile_width, max_texture_size); |
771 tile_height = std::min(tile_height, max_texture_size); | 802 tile_height = std::min(tile_height, max_texture_size); |
772 return gfx::Size(tile_width, tile_height); | 803 return gfx::Size(tile_width, tile_height); |
773 } | 804 } |
774 | 805 |
775 void PictureLayerImpl::SyncFromActiveLayer(const PictureLayerImpl* other) { | |
776 DCHECK(!other->needs_post_commit_initialization_); | |
777 DCHECK(other->tilings_); | |
778 | |
779 if (!DrawsContent()) { | |
780 RemoveAllTilings(); | |
781 return; | |
782 } | |
783 | |
784 raster_page_scale_ = other->raster_page_scale_; | |
785 raster_device_scale_ = other->raster_device_scale_; | |
786 raster_source_scale_ = other->raster_source_scale_; | |
787 raster_contents_scale_ = other->raster_contents_scale_; | |
788 low_res_raster_contents_scale_ = other->low_res_raster_contents_scale_; | |
789 | |
790 bool synced_high_res_tiling = false; | |
791 if (CanHaveTilings()) { | |
792 synced_high_res_tiling = tilings_->SyncTilings( | |
793 *other->tilings_, raster_source_->GetSize(), invalidation_, | |
794 MinimumContentsScale(), raster_source_.get()); | |
795 } else { | |
796 RemoveAllTilings(); | |
797 } | |
798 | |
799 // If our MinimumContentsScale has changed to prevent the twin's high res | |
800 // tiling from being synced, we should reset the raster scale and let it be | |
801 // recalculated (1) again. This can happen if our bounds shrink to the point | |
802 // where min contents scale grows. | |
803 // (1) - TODO(vmpstr) Instead of hoping that this will be recalculated, we | |
804 // should refactor this code a little bit and actually recalculate this. | |
805 // However, this is a larger undertaking, so this will work for now. | |
806 if (!synced_high_res_tiling) | |
807 ResetRasterScale(); | |
808 else | |
809 SanityCheckTilingState(); | |
810 } | |
811 | |
812 void PictureLayerImpl::SyncTiling( | |
813 const PictureLayerTiling* tiling) { | |
814 if (!tilings_) | |
815 return; | |
816 if (!CanHaveTilingWithScale(tiling->contents_scale())) | |
817 return; | |
818 tilings_->AddTiling(tiling->contents_scale(), raster_source_->GetSize()); | |
819 | |
820 // If this tree needs update draw properties, then the tiling will | |
821 // get updated prior to drawing or activation. If this tree does not | |
822 // need update draw properties, then its transforms are up to date and | |
823 // we can create tiles for this tiling immediately. | |
824 if (!layer_tree_impl()->needs_update_draw_properties() && | |
825 should_update_tile_priorities_) { | |
826 // TODO(danakj): Add a DCHECK() that we are not using occlusion tracking | |
827 // when we stop using the pending tree in the browser compositor. If we want | |
828 // to support occlusion tracking here, we need to dirty the draw properties | |
829 // or save occlusion as a draw property. | |
830 UpdateTilePriorities(Occlusion()); | |
831 } | |
832 } | |
833 | |
834 void PictureLayerImpl::GetContentsResourceId( | 806 void PictureLayerImpl::GetContentsResourceId( |
835 ResourceProvider::ResourceId* resource_id, | 807 ResourceProvider::ResourceId* resource_id, |
836 gfx::Size* resource_size) const { | 808 gfx::Size* resource_size) const { |
837 DCHECK_EQ(bounds().ToString(), raster_source_->GetSize().ToString()); | 809 // The bounds and the pile size may differ if the pile wasn't updated (ie. |
| 810 // PictureLayer::Update didn't happen). In that case the pile will be empty. |
| 811 DCHECK_IMPLIES(!raster_source_->GetSize().IsEmpty(), |
| 812 bounds() == raster_source_->GetSize()) |
| 813 << " bounds " << bounds().ToString() << " pile " |
| 814 << raster_source_->GetSize().ToString(); |
838 gfx::Rect content_rect(bounds()); | 815 gfx::Rect content_rect(bounds()); |
839 PictureLayerTilingSet::CoverageIterator iter( | 816 PictureLayerTilingSet::CoverageIterator iter( |
840 tilings_.get(), 1.f, content_rect, ideal_contents_scale_); | 817 tilings_.get(), 1.f, content_rect, ideal_contents_scale_); |
841 | 818 |
842 // Mask resource not ready yet. | 819 // Mask resource not ready yet. |
843 if (!iter || !*iter) { | 820 if (!iter || !*iter) { |
844 *resource_id = 0; | 821 *resource_id = 0; |
845 return; | 822 return; |
846 } | 823 } |
847 | 824 |
848 // Masks only supported if they fit on exactly one tile. | 825 // Masks only supported if they fit on exactly one tile. |
849 DCHECK(iter.geometry_rect() == content_rect) | 826 DCHECK(iter.geometry_rect() == content_rect) |
850 << "iter rect " << iter.geometry_rect().ToString() << " content rect " | 827 << "iter rect " << iter.geometry_rect().ToString() << " content rect " |
851 << content_rect.ToString(); | 828 << content_rect.ToString(); |
852 | 829 |
853 const ManagedTileState::DrawInfo& draw_info = iter->draw_info(); | 830 const ManagedTileState::DrawInfo& draw_info = iter->draw_info(); |
854 if (!draw_info.IsReadyToDraw() || | 831 if (!draw_info.IsReadyToDraw() || |
855 draw_info.mode() != ManagedTileState::DrawInfo::RESOURCE_MODE) { | 832 draw_info.mode() != ManagedTileState::DrawInfo::RESOURCE_MODE) { |
856 *resource_id = 0; | 833 *resource_id = 0; |
857 return; | 834 return; |
858 } | 835 } |
859 | 836 |
860 *resource_id = draw_info.get_resource_id(); | 837 *resource_id = draw_info.get_resource_id(); |
861 *resource_size = iter.texture_size(); | 838 *resource_size = iter.texture_size(); |
862 } | 839 } |
863 | 840 |
864 void PictureLayerImpl::DoPostCommitInitialization() { | 841 void PictureLayerImpl::DoPostCommitInitialization() { |
| 842 // TODO(danakj): Remove this. |
865 DCHECK(needs_post_commit_initialization_); | 843 DCHECK(needs_post_commit_initialization_); |
866 DCHECK(layer_tree_impl()->IsPendingTree()); | 844 DCHECK(layer_tree_impl()->IsPendingTree()); |
867 | |
868 if (!tilings_) | |
869 tilings_ = PictureLayerTilingSet::Create(this); | |
870 | |
871 PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer(); | |
872 if (twin_layer) { | |
873 // If the twin has never been pushed to, do not sync from it. | |
874 // This can happen if this function is called during activation. | |
875 if (!twin_layer->needs_post_commit_initialization_) | |
876 SyncFromActiveLayer(twin_layer); | |
877 } | |
878 | |
879 needs_post_commit_initialization_ = false; | 845 needs_post_commit_initialization_ = false; |
880 } | 846 } |
881 | 847 |
882 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { | 848 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { |
883 DCHECK(CanHaveTilingWithScale(contents_scale)) << | 849 DCHECK(CanHaveTilingWithScale(contents_scale)) << |
884 "contents_scale: " << contents_scale; | 850 "contents_scale: " << contents_scale; |
885 | 851 |
886 PictureLayerTiling* tiling = | 852 PictureLayerTiling* tiling = |
887 tilings_->AddTiling(contents_scale, raster_source_->GetSize()); | 853 tilings_->AddTiling(contents_scale, raster_source_->GetSize()); |
888 | 854 |
889 DCHECK(raster_source_->HasRecordings()); | 855 DCHECK(raster_source_->HasRecordings()); |
890 | 856 |
891 if (PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer()) | |
892 twin_layer->SyncTiling(tiling); | |
893 | |
894 return tiling; | 857 return tiling; |
895 } | 858 } |
896 | 859 |
897 void PictureLayerImpl::RemoveAllTilings() { | 860 void PictureLayerImpl::RemoveAllTilings() { |
898 if (tilings_) | 861 if (tilings_) |
899 tilings_->RemoveAllTilings(); | 862 tilings_->RemoveAllTilings(); |
900 // If there are no tilings, then raster scales are no longer meaningful. | 863 // If there are no tilings, then raster scales are no longer meaningful. |
901 ResetRasterScale(); | 864 ResetRasterScale(); |
902 } | 865 } |
903 | 866 |
(...skipping 25 matching lines...) Expand all Loading... |
929 if (can_have_low_res && needs_low_res && !is_pinching && !is_animating) | 892 if (can_have_low_res && needs_low_res && !is_pinching && !is_animating) |
930 low_res = AddTiling(low_res_raster_contents_scale_); | 893 low_res = AddTiling(low_res_raster_contents_scale_); |
931 | 894 |
932 // Set low-res if we have one. | 895 // Set low-res if we have one. |
933 if (low_res && low_res != high_res) | 896 if (low_res && low_res != high_res) |
934 low_res->set_resolution(LOW_RESOLUTION); | 897 low_res->set_resolution(LOW_RESOLUTION); |
935 | 898 |
936 // Make sure we always have one high-res (even if high == low). | 899 // Make sure we always have one high-res (even if high == low). |
937 high_res->set_resolution(HIGH_RESOLUTION); | 900 high_res->set_resolution(HIGH_RESOLUTION); |
938 | 901 |
| 902 if (layer_tree_impl()->IsPendingTree()) { |
| 903 // On the pending tree, drop any tilings that are non-ideal since we don't |
| 904 // need them to activate anyway. |
| 905 tilings_->RemoveNonIdealTilings(); |
| 906 } |
| 907 |
939 SanityCheckTilingState(); | 908 SanityCheckTilingState(); |
940 } | 909 } |
941 | 910 |
942 bool PictureLayerImpl::ShouldAdjustRasterScale() const { | 911 bool PictureLayerImpl::ShouldAdjustRasterScale() const { |
943 if (was_screen_space_transform_animating_ != | 912 if (was_screen_space_transform_animating_ != |
944 draw_properties().screen_space_transform_is_animating) | 913 draw_properties().screen_space_transform_is_animating) |
945 return true; | 914 return true; |
946 | 915 |
947 if (draw_properties().screen_space_transform_is_animating && | 916 if (draw_properties().screen_space_transform_is_animating && |
948 raster_contents_scale_ != ideal_contents_scale_ && | 917 raster_contents_scale_ != ideal_contents_scale_ && |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 PictureLayerTilingSet* twin_set = twin ? twin->tilings_.get() : nullptr; | 1082 PictureLayerTilingSet* twin_set = twin ? twin->tilings_.get() : nullptr; |
1114 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); | 1083 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); |
1115 PictureLayerTilingSet* recycled_twin_set = | 1084 PictureLayerTilingSet* recycled_twin_set = |
1116 recycled_twin ? recycled_twin->tilings_.get() : nullptr; | 1085 recycled_twin ? recycled_twin->tilings_.get() : nullptr; |
1117 | 1086 |
1118 tilings_->CleanUpTilings(min_acceptable_high_res_scale, | 1087 tilings_->CleanUpTilings(min_acceptable_high_res_scale, |
1119 max_acceptable_high_res_scale, used_tilings, | 1088 max_acceptable_high_res_scale, used_tilings, |
1120 layer_tree_impl()->create_low_res_tiling(), twin_set, | 1089 layer_tree_impl()->create_low_res_tiling(), twin_set, |
1121 recycled_twin_set); | 1090 recycled_twin_set); |
1122 | 1091 |
1123 if (twin_set && twin_set->num_tilings() == 0) | |
1124 twin->ResetRasterScale(); | |
1125 | |
1126 if (recycled_twin_set && recycled_twin_set->num_tilings() == 0) | 1092 if (recycled_twin_set && recycled_twin_set->num_tilings() == 0) |
1127 recycled_twin->ResetRasterScale(); | 1093 recycled_twin->ResetRasterScale(); |
1128 | 1094 |
1129 DCHECK_GT(tilings_->num_tilings(), 0u); | 1095 DCHECK_GT(tilings_->num_tilings(), 0u); |
1130 SanityCheckTilingState(); | 1096 SanityCheckTilingState(); |
1131 } | 1097 } |
1132 | 1098 |
1133 float PictureLayerImpl::MinimumContentsScale() const { | 1099 float PictureLayerImpl::MinimumContentsScale() const { |
1134 float setting_min = layer_tree_impl()->settings().minimum_contents_scale; | 1100 float setting_min = layer_tree_impl()->settings().minimum_contents_scale; |
1135 | 1101 |
(...skipping 22 matching lines...) Expand all Loading... |
1158 should_update_tile_priorities_ = false; | 1124 should_update_tile_priorities_ = false; |
1159 } | 1125 } |
1160 | 1126 |
1161 bool PictureLayerImpl::CanHaveTilings() const { | 1127 bool PictureLayerImpl::CanHaveTilings() const { |
1162 if (raster_source_->IsSolidColor()) | 1128 if (raster_source_->IsSolidColor()) |
1163 return false; | 1129 return false; |
1164 if (!DrawsContent()) | 1130 if (!DrawsContent()) |
1165 return false; | 1131 return false; |
1166 if (!raster_source_->HasRecordings()) | 1132 if (!raster_source_->HasRecordings()) |
1167 return false; | 1133 return false; |
| 1134 // If the |raster_source_| has a recording it should have non-empty bounds. |
| 1135 DCHECK(!raster_source_->GetSize().IsEmpty()); |
1168 return true; | 1136 return true; |
1169 } | 1137 } |
1170 | 1138 |
1171 bool PictureLayerImpl::CanHaveTilingWithScale(float contents_scale) const { | 1139 bool PictureLayerImpl::CanHaveTilingWithScale(float contents_scale) const { |
1172 if (!CanHaveTilings()) | 1140 if (!CanHaveTilings()) |
1173 return false; | 1141 return false; |
1174 if (contents_scale < MinimumContentsScale()) | 1142 if (contents_scale < MinimumContentsScale()) |
1175 return false; | 1143 return false; |
1176 return true; | 1144 return true; |
1177 } | 1145 } |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1481 IteratorType index = stages_[current_stage_].iterator_type; | 1449 IteratorType index = stages_[current_stage_].iterator_type; |
1482 TilePriority::PriorityBin tile_type = stages_[current_stage_].tile_type; | 1450 TilePriority::PriorityBin tile_type = stages_[current_stage_].tile_type; |
1483 | 1451 |
1484 if (iterators_[index] && iterators_[index].get_type() == tile_type) | 1452 if (iterators_[index] && iterators_[index].get_type() == tile_type) |
1485 break; | 1453 break; |
1486 ++current_stage_; | 1454 ++current_stage_; |
1487 } | 1455 } |
1488 } | 1456 } |
1489 | 1457 |
1490 } // namespace cc | 1458 } // namespace cc |
OLD | NEW |