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 | 9 |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 LayerTreeImpl* tree_impl) { | 79 LayerTreeImpl* tree_impl) { |
80 return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); | 80 return PictureLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>(); |
81 } | 81 } |
82 | 82 |
83 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { | 83 void PictureLayerImpl::PushPropertiesTo(LayerImpl* base_layer) { |
84 // It's possible this layer was never drawn or updated (e.g. because it was | 84 // It's possible this layer was never drawn or updated (e.g. because it was |
85 // a descendant of an opacity 0 layer). | 85 // a descendant of an opacity 0 layer). |
86 DoPostCommitInitializationIfNeeded(); | 86 DoPostCommitInitializationIfNeeded(); |
87 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); | 87 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); |
88 | 88 |
89 // We have already synced the important bits from the the active layer, and | |
90 // we will soon swap out its tilings and use them for recycling. However, | |
91 // there are now tiles in this layer's tilings that were unref'd and replaced | |
92 // with new tiles (due to invalidation). This resets all active priorities on | |
93 // the to-be-recycled tiling to ensure replaced tiles don't linger and take | |
94 // memory (due to a stale 'active' priority). | |
95 if (layer_impl->tilings_) | |
96 layer_impl->tilings_->DidBecomeRecycled(); | |
vmpstr
2014/07/02 23:51:29
This is no longer needed, as we can't access tiles
enne (OOO)
2014/07/07 19:41:59
\o/
| |
97 | |
98 LayerImpl::PushPropertiesTo(base_layer); | 89 LayerImpl::PushPropertiesTo(base_layer); |
99 | 90 |
100 // When the pending tree pushes to the active tree, the pending twin | 91 // When the pending tree pushes to the active tree, the pending twin |
101 // disappears. | 92 // disappears. |
102 layer_impl->twin_layer_ = NULL; | 93 layer_impl->twin_layer_ = NULL; |
103 twin_layer_ = NULL; | 94 twin_layer_ = NULL; |
104 | 95 |
105 layer_impl->SetIsMask(is_mask_); | 96 layer_impl->SetIsMask(is_mask_); |
106 layer_impl->pile_ = pile_; | 97 layer_impl->pile_ = pile_; |
107 | 98 |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
434 DCHECK(raster_source_scale_); | 425 DCHECK(raster_source_scale_); |
435 DCHECK(raster_contents_scale_); | 426 DCHECK(raster_contents_scale_); |
436 DCHECK(low_res_raster_contents_scale_); | 427 DCHECK(low_res_raster_contents_scale_); |
437 | 428 |
438 was_screen_space_transform_animating_ = | 429 was_screen_space_transform_animating_ = |
439 draw_properties().screen_space_transform_is_animating; | 430 draw_properties().screen_space_transform_is_animating; |
440 | 431 |
441 should_update_tile_priorities_ = true; | 432 should_update_tile_priorities_ = true; |
442 | 433 |
443 UpdateTilePriorities(occlusion_tracker); | 434 UpdateTilePriorities(occlusion_tracker); |
444 | |
445 if (layer_tree_impl()->IsPendingTree()) | |
446 MarkVisibleResourcesAsRequired(); | |
447 } | 435 } |
448 | 436 |
449 void PictureLayerImpl::UpdateTilePriorities( | 437 void PictureLayerImpl::UpdateTilePriorities( |
450 const OcclusionTracker<LayerImpl>* occlusion_tracker) { | 438 const OcclusionTracker<LayerImpl>* occlusion_tracker) { |
451 TRACE_EVENT0("cc", "PictureLayerImpl::UpdateTilePriorities"); | 439 TRACE_EVENT0("cc", "PictureLayerImpl::UpdateTilePriorities"); |
452 | 440 |
453 double current_frame_time_in_seconds = | 441 double current_frame_time_in_seconds = |
454 (layer_tree_impl()->CurrentFrameTimeTicks() - | 442 (layer_tree_impl()->CurrentFrameTimeTicks() - |
455 base::TimeTicks()).InSecondsF(); | 443 base::TimeTicks()).InSecondsF(); |
456 | 444 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
599 layer_tree_impl()->begin_impl_frame_interval().InSecondsF() * | 587 layer_tree_impl()->begin_impl_frame_interval().InSecondsF() * |
600 layer_tree_impl()->settings().skewport_target_time_multiplier; | 588 layer_tree_impl()->settings().skewport_target_time_multiplier; |
601 } | 589 } |
602 | 590 |
603 int PictureLayerImpl::GetSkewportExtrapolationLimitInContentPixels() const { | 591 int PictureLayerImpl::GetSkewportExtrapolationLimitInContentPixels() const { |
604 return layer_tree_impl() | 592 return layer_tree_impl() |
605 ->settings() | 593 ->settings() |
606 .skewport_extrapolation_limit_in_content_pixels; | 594 .skewport_extrapolation_limit_in_content_pixels; |
607 } | 595 } |
608 | 596 |
597 bool PictureLayerImpl::RequiresHighResToDraw() const { | |
598 const PictureLayerImpl* layer = this; | |
599 if (GetTree() == PENDING_TREE) | |
600 layer = twin_layer_; | |
601 | |
602 if (layer) | |
603 return layer->layer_tree_impl()->RequiresHighResToDraw(); | |
604 return false; | |
605 } | |
606 | |
609 gfx::Size PictureLayerImpl::CalculateTileSize( | 607 gfx::Size PictureLayerImpl::CalculateTileSize( |
610 const gfx::Size& content_bounds) const { | 608 const gfx::Size& content_bounds) const { |
611 if (is_mask_) { | 609 if (is_mask_) { |
612 int max_size = layer_tree_impl()->MaxTextureSize(); | 610 int max_size = layer_tree_impl()->MaxTextureSize(); |
613 return gfx::Size( | 611 return gfx::Size( |
614 std::min(max_size, content_bounds.width()), | 612 std::min(max_size, content_bounds.width()), |
615 std::min(max_size, content_bounds.height())); | 613 std::min(max_size, content_bounds.height())); |
616 } | 614 } |
617 | 615 |
618 int max_texture_size = | 616 int max_texture_size = |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
753 | 751 |
754 const ManagedTileState::TileVersion& tile_version = | 752 const ManagedTileState::TileVersion& tile_version = |
755 iter->GetTileVersionForDrawing(); | 753 iter->GetTileVersionForDrawing(); |
756 if (!tile_version.IsReadyToDraw() || | 754 if (!tile_version.IsReadyToDraw() || |
757 tile_version.mode() != ManagedTileState::TileVersion::RESOURCE_MODE) | 755 tile_version.mode() != ManagedTileState::TileVersion::RESOURCE_MODE) |
758 return 0; | 756 return 0; |
759 | 757 |
760 return tile_version.get_resource_id(); | 758 return tile_version.get_resource_id(); |
761 } | 759 } |
762 | 760 |
763 void PictureLayerImpl::MarkVisibleResourcesAsRequired() const { | |
enne (OOO)
2014/07/07 19:41:59
\o/
| |
764 DCHECK(layer_tree_impl()->IsPendingTree()); | |
765 DCHECK(ideal_contents_scale_); | |
766 DCHECK_GT(tilings_->num_tilings(), 0u); | |
767 | |
768 // The goal of this function is to find the minimum set of tiles that need to | |
769 // be ready to draw in order to activate without flashing content from a | |
770 // higher res on the active tree to a lower res on the pending tree. | |
771 | |
772 // First, early out for layers with no visible content. | |
773 if (visible_content_rect().IsEmpty()) | |
774 return; | |
775 | |
776 gfx::Rect rect(visible_content_rect()); | |
777 | |
778 float min_acceptable_scale = | |
779 std::min(raster_contents_scale_, ideal_contents_scale_); | |
780 | |
781 if (PictureLayerImpl* twin = twin_layer_) { | |
782 float twin_min_acceptable_scale = | |
783 std::min(twin->ideal_contents_scale_, twin->raster_contents_scale_); | |
784 // Ignore 0 scale in case CalculateContentsScale() has never been | |
785 // called for active twin. | |
786 if (twin_min_acceptable_scale != 0.0f) { | |
787 min_acceptable_scale = | |
788 std::min(min_acceptable_scale, twin_min_acceptable_scale); | |
789 } | |
790 } | |
791 | |
792 PictureLayerTiling* high_res = NULL; | |
793 PictureLayerTiling* low_res = NULL; | |
794 | |
795 // First pass: ready to draw tiles in acceptable but non-ideal tilings are | |
796 // marked as required for activation so that their textures are not thrown | |
797 // away; any non-ready tiles are not marked as required. | |
798 Region missing_region = rect; | |
799 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { | |
800 PictureLayerTiling* tiling = tilings_->tiling_at(i); | |
801 DCHECK(tiling->has_ever_been_updated()); | |
802 | |
803 if (tiling->resolution() == LOW_RESOLUTION) { | |
804 DCHECK(!low_res) << "There can only be one low res tiling"; | |
805 low_res = tiling; | |
806 } | |
807 if (tiling->contents_scale() < min_acceptable_scale) | |
808 continue; | |
809 if (tiling->resolution() == HIGH_RESOLUTION) { | |
810 DCHECK(!high_res) << "There can only be one high res tiling"; | |
811 high_res = tiling; | |
812 continue; | |
813 } | |
814 for (PictureLayerTiling::CoverageIterator iter(tiling, | |
815 contents_scale_x(), | |
816 rect); | |
817 iter; | |
818 ++iter) { | |
819 if (!*iter || !iter->IsReadyToDraw()) | |
820 continue; | |
821 | |
822 missing_region.Subtract(iter.geometry_rect()); | |
823 iter->MarkRequiredForActivation(); | |
824 } | |
825 } | |
826 DCHECK(high_res) << "There must be one high res tiling"; | |
827 | |
828 // If these pointers are null (because no twin, no matching tiling, or the | |
829 // simpification just below), then high res tiles will be required to fill any | |
830 // holes left by the first pass above. If the pointers are valid, then this | |
831 // layer is allowed to skip any tiles that are not ready on its twin. | |
832 const PictureLayerTiling* twin_high_res = NULL; | |
833 const PictureLayerTiling* twin_low_res = NULL; | |
834 | |
835 if (twin_layer_) { | |
836 // As a simplification, only allow activating to skip twin tiles that the | |
837 // active layer is also missing when both this layer and its twin have | |
838 // "simple" sets of tilings: only 2 tilings (high and low) or only 1 high | |
839 // res tiling. This avoids having to iterate/track coverage of non-ideal | |
840 // tilings during the last draw call on the active layer. | |
841 if (tilings_->num_tilings() <= 2 && | |
842 twin_layer_->tilings_->num_tilings() <= tilings_->num_tilings()) { | |
843 twin_low_res = low_res ? GetTwinTiling(low_res) : NULL; | |
844 twin_high_res = high_res ? GetTwinTiling(high_res) : NULL; | |
845 } | |
846 | |
847 // If this layer and its twin have different transforms, then don't compare | |
848 // them and only allow activating to high res tiles, since tiles on each | |
849 // layer will be in different places on screen. | |
850 if (twin_layer_->layer_tree_impl()->RequiresHighResToDraw() || | |
851 bounds() != twin_layer_->bounds() || | |
852 draw_properties().screen_space_transform != | |
853 twin_layer_->draw_properties().screen_space_transform) { | |
854 twin_high_res = NULL; | |
855 twin_low_res = NULL; | |
856 } | |
857 } | |
858 | |
859 // As a second pass, mark as required any visible high res tiles not filled in | |
860 // by acceptable non-ideal tiles from the first pass. | |
861 if (MarkVisibleTilesAsRequired( | |
862 high_res, twin_high_res, contents_scale_x(), rect, missing_region)) { | |
863 // As an optional third pass, if a high res tile was skipped because its | |
864 // twin was also missing, then fall back to mark low res tiles as required | |
865 // in case the active twin is substituting those for missing high res | |
866 // content. Only suitable, when low res is enabled. | |
867 if (low_res) { | |
868 MarkVisibleTilesAsRequired( | |
869 low_res, twin_low_res, contents_scale_x(), rect, missing_region); | |
870 } | |
871 } | |
872 } | |
873 | |
874 bool PictureLayerImpl::MarkVisibleTilesAsRequired( | |
875 PictureLayerTiling* tiling, | |
876 const PictureLayerTiling* optional_twin_tiling, | |
877 float contents_scale, | |
878 const gfx::Rect& rect, | |
879 const Region& missing_region) const { | |
880 bool twin_had_missing_tile = false; | |
881 for (PictureLayerTiling::CoverageIterator iter(tiling, | |
882 contents_scale, | |
883 rect); | |
884 iter; | |
885 ++iter) { | |
886 Tile* tile = *iter; | |
887 // A null tile (i.e. missing recording) can just be skipped. | |
888 if (!tile) | |
889 continue; | |
890 | |
891 // If the tile is occluded, don't mark it as required for activation. | |
892 if (tile->is_occluded()) | |
893 continue; | |
894 | |
895 // If the missing region doesn't cover it, this tile is fully | |
896 // covered by acceptable tiles at other scales. | |
897 if (!missing_region.Intersects(iter.geometry_rect())) | |
898 continue; | |
899 | |
900 // If the twin tile doesn't exist (i.e. missing recording or so far away | |
901 // that it is outside the visible tile rect) or this tile is shared between | |
902 // with the twin, then this tile isn't required to prevent flashing. | |
903 if (optional_twin_tiling) { | |
904 Tile* twin_tile = optional_twin_tiling->TileAt(iter.i(), iter.j()); | |
905 if (!twin_tile || twin_tile == tile) { | |
906 twin_had_missing_tile = true; | |
907 continue; | |
908 } | |
909 } | |
910 | |
911 tile->MarkRequiredForActivation(); | |
912 } | |
913 return twin_had_missing_tile; | |
914 } | |
915 | |
916 void PictureLayerImpl::DoPostCommitInitialization() { | 761 void PictureLayerImpl::DoPostCommitInitialization() { |
917 DCHECK(needs_post_commit_initialization_); | 762 DCHECK(needs_post_commit_initialization_); |
918 DCHECK(layer_tree_impl()->IsPendingTree()); | 763 DCHECK(layer_tree_impl()->IsPendingTree()); |
919 | 764 |
920 if (!tilings_) | 765 if (!tilings_) |
921 tilings_.reset(new PictureLayerTilingSet(this, bounds())); | 766 tilings_.reset(new PictureLayerTilingSet(this, bounds())); |
922 | 767 |
923 DCHECK(!twin_layer_); | 768 DCHECK(!twin_layer_); |
924 twin_layer_ = static_cast<PictureLayerImpl*>( | 769 twin_layer_ = static_cast<PictureLayerImpl*>( |
925 layer_tree_impl()->FindActiveTreeLayerById(id())); | 770 layer_tree_impl()->FindActiveTreeLayerById(id())); |
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1640 return iterator_index_ < iterators_.size(); | 1485 return iterator_index_ < iterators_.size(); |
1641 } | 1486 } |
1642 | 1487 |
1643 bool PictureLayerImpl::LayerEvictionTileIterator::IsCorrectType( | 1488 bool PictureLayerImpl::LayerEvictionTileIterator::IsCorrectType( |
1644 PictureLayerTiling::TilingEvictionTileIterator* it) const { | 1489 PictureLayerTiling::TilingEvictionTileIterator* it) const { |
1645 return it->get_type() == iteration_stage_ && | 1490 return it->get_type() == iteration_stage_ && |
1646 (**it)->required_for_activation() == required_for_activation_; | 1491 (**it)->required_for_activation() == required_for_activation_; |
1647 } | 1492 } |
1648 | 1493 |
1649 } // namespace cc | 1494 } // namespace cc |
OLD | NEW |