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(); | |
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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 float width; | 200 float width; |
210 if (*iter && iter->IsReadyToDraw()) { | 201 if (*iter && iter->IsReadyToDraw()) { |
211 ManagedTileState::TileVersion::Mode mode = | 202 ManagedTileState::TileVersion::Mode mode = |
212 iter->GetTileVersionForDrawing().mode(); | 203 iter->GetTileVersionForDrawing().mode(); |
213 if (mode == ManagedTileState::TileVersion::SOLID_COLOR_MODE) { | 204 if (mode == ManagedTileState::TileVersion::SOLID_COLOR_MODE) { |
214 color = DebugColors::SolidColorTileBorderColor(); | 205 color = DebugColors::SolidColorTileBorderColor(); |
215 width = DebugColors::SolidColorTileBorderWidth(layer_tree_impl()); | 206 width = DebugColors::SolidColorTileBorderWidth(layer_tree_impl()); |
216 } else if (mode == ManagedTileState::TileVersion::PICTURE_PILE_MODE) { | 207 } else if (mode == ManagedTileState::TileVersion::PICTURE_PILE_MODE) { |
217 color = DebugColors::PictureTileBorderColor(); | 208 color = DebugColors::PictureTileBorderColor(); |
218 width = DebugColors::PictureTileBorderWidth(layer_tree_impl()); | 209 width = DebugColors::PictureTileBorderWidth(layer_tree_impl()); |
219 } else if (iter->priority(ACTIVE_TREE).resolution == HIGH_RESOLUTION) { | 210 } else if (iter.resolution() == HIGH_RESOLUTION) { |
220 color = DebugColors::HighResTileBorderColor(); | 211 color = DebugColors::HighResTileBorderColor(); |
221 width = DebugColors::HighResTileBorderWidth(layer_tree_impl()); | 212 width = DebugColors::HighResTileBorderWidth(layer_tree_impl()); |
222 } else if (iter->priority(ACTIVE_TREE).resolution == LOW_RESOLUTION) { | 213 } else if (iter.resolution() == LOW_RESOLUTION) { |
223 color = DebugColors::LowResTileBorderColor(); | 214 color = DebugColors::LowResTileBorderColor(); |
224 width = DebugColors::LowResTileBorderWidth(layer_tree_impl()); | 215 width = DebugColors::LowResTileBorderWidth(layer_tree_impl()); |
225 } else if (iter->contents_scale() > max_contents_scale) { | 216 } else if (iter->contents_scale() > max_contents_scale) { |
226 color = DebugColors::ExtraHighResTileBorderColor(); | 217 color = DebugColors::ExtraHighResTileBorderColor(); |
227 width = DebugColors::ExtraHighResTileBorderWidth(layer_tree_impl()); | 218 width = DebugColors::ExtraHighResTileBorderWidth(layer_tree_impl()); |
228 } else { | 219 } else { |
229 color = DebugColors::ExtraLowResTileBorderColor(); | 220 color = DebugColors::ExtraLowResTileBorderColor(); |
230 width = DebugColors::ExtraLowResTileBorderWidth(layer_tree_impl()); | 221 width = DebugColors::ExtraLowResTileBorderWidth(layer_tree_impl()); |
231 } | 222 } |
232 } else { | 223 } else { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 false); | 341 false); |
351 } | 342 } |
352 | 343 |
353 append_quads_data->num_missing_tiles++; | 344 append_quads_data->num_missing_tiles++; |
354 append_quads_data->approximated_visible_content_area += | 345 append_quads_data->approximated_visible_content_area += |
355 visible_geometry_rect.width() * visible_geometry_rect.height(); | 346 visible_geometry_rect.width() * visible_geometry_rect.height(); |
356 ++missing_tile_count; | 347 ++missing_tile_count; |
357 continue; | 348 continue; |
358 } | 349 } |
359 | 350 |
360 if (iter->priority(ACTIVE_TREE).resolution != HIGH_RESOLUTION) { | 351 if (iter.resolution() != HIGH_RESOLUTION) { |
361 append_quads_data->approximated_visible_content_area += | 352 append_quads_data->approximated_visible_content_area += |
362 visible_geometry_rect.width() * visible_geometry_rect.height(); | 353 visible_geometry_rect.width() * visible_geometry_rect.height(); |
363 } | 354 } |
364 | 355 |
365 if (seen_tilings.empty() || seen_tilings.back() != iter.CurrentTiling()) | 356 if (seen_tilings.empty() || seen_tilings.back() != iter.CurrentTiling()) |
366 seen_tilings.push_back(iter.CurrentTiling()); | 357 seen_tilings.push_back(iter.CurrentTiling()); |
367 } | 358 } |
368 | 359 |
369 if (missing_tile_count) { | 360 if (missing_tile_count) { |
370 TRACE_EVENT_INSTANT2("cc", | 361 TRACE_EVENT_INSTANT2("cc", |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 DCHECK(raster_source_scale_); | 417 DCHECK(raster_source_scale_); |
427 DCHECK(raster_contents_scale_); | 418 DCHECK(raster_contents_scale_); |
428 DCHECK(low_res_raster_contents_scale_); | 419 DCHECK(low_res_raster_contents_scale_); |
429 | 420 |
430 was_screen_space_transform_animating_ = | 421 was_screen_space_transform_animating_ = |
431 draw_properties().screen_space_transform_is_animating; | 422 draw_properties().screen_space_transform_is_animating; |
432 | 423 |
433 should_update_tile_priorities_ = true; | 424 should_update_tile_priorities_ = true; |
434 | 425 |
435 UpdateTilePriorities(occlusion_tracker); | 426 UpdateTilePriorities(occlusion_tracker); |
436 | |
437 if (layer_tree_impl()->IsPendingTree()) | |
438 MarkVisibleResourcesAsRequired(); | |
439 } | 427 } |
440 | 428 |
441 void PictureLayerImpl::UpdateTilePriorities( | 429 void PictureLayerImpl::UpdateTilePriorities( |
442 const OcclusionTracker<LayerImpl>* occlusion_tracker) { | 430 const OcclusionTracker<LayerImpl>* occlusion_tracker) { |
443 TRACE_EVENT0("cc", "PictureLayerImpl::UpdateTilePriorities"); | 431 TRACE_EVENT0("cc", "PictureLayerImpl::UpdateTilePriorities"); |
444 | 432 |
445 double current_frame_time_in_seconds = | 433 double current_frame_time_in_seconds = |
446 (layer_tree_impl()->CurrentFrameTimeTicks() - | 434 (layer_tree_impl()->CurrentFrameTimeTicks() - |
447 base::TimeTicks()).InSecondsF(); | 435 base::TimeTicks()).InSecondsF(); |
448 | 436 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 layer_tree_impl()->begin_impl_frame_interval().InSecondsF() * | 579 layer_tree_impl()->begin_impl_frame_interval().InSecondsF() * |
592 layer_tree_impl()->settings().skewport_target_time_multiplier; | 580 layer_tree_impl()->settings().skewport_target_time_multiplier; |
593 } | 581 } |
594 | 582 |
595 int PictureLayerImpl::GetSkewportExtrapolationLimitInContentPixels() const { | 583 int PictureLayerImpl::GetSkewportExtrapolationLimitInContentPixels() const { |
596 return layer_tree_impl() | 584 return layer_tree_impl() |
597 ->settings() | 585 ->settings() |
598 .skewport_extrapolation_limit_in_content_pixels; | 586 .skewport_extrapolation_limit_in_content_pixels; |
599 } | 587 } |
600 | 588 |
| 589 bool PictureLayerImpl::RequiresHighResToDraw() const { |
| 590 const PictureLayerImpl* layer = this; |
| 591 if (GetTree() == PENDING_TREE) |
| 592 layer = twin_layer_; |
| 593 |
| 594 if (layer) |
| 595 return layer->layer_tree_impl()->RequiresHighResToDraw(); |
| 596 return false; |
| 597 } |
| 598 |
601 gfx::Size PictureLayerImpl::CalculateTileSize( | 599 gfx::Size PictureLayerImpl::CalculateTileSize( |
602 const gfx::Size& content_bounds) const { | 600 const gfx::Size& content_bounds) const { |
603 if (is_mask_) { | 601 if (is_mask_) { |
604 int max_size = layer_tree_impl()->MaxTextureSize(); | 602 int max_size = layer_tree_impl()->MaxTextureSize(); |
605 return gfx::Size( | 603 return gfx::Size( |
606 std::min(max_size, content_bounds.width()), | 604 std::min(max_size, content_bounds.width()), |
607 std::min(max_size, content_bounds.height())); | 605 std::min(max_size, content_bounds.height())); |
608 } | 606 } |
609 | 607 |
610 int max_texture_size = | 608 int max_texture_size = |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 | 743 |
746 const ManagedTileState::TileVersion& tile_version = | 744 const ManagedTileState::TileVersion& tile_version = |
747 iter->GetTileVersionForDrawing(); | 745 iter->GetTileVersionForDrawing(); |
748 if (!tile_version.IsReadyToDraw() || | 746 if (!tile_version.IsReadyToDraw() || |
749 tile_version.mode() != ManagedTileState::TileVersion::RESOURCE_MODE) | 747 tile_version.mode() != ManagedTileState::TileVersion::RESOURCE_MODE) |
750 return 0; | 748 return 0; |
751 | 749 |
752 return tile_version.get_resource_id(); | 750 return tile_version.get_resource_id(); |
753 } | 751 } |
754 | 752 |
755 void PictureLayerImpl::MarkVisibleResourcesAsRequired() const { | |
756 DCHECK(layer_tree_impl()->IsPendingTree()); | |
757 DCHECK(ideal_contents_scale_); | |
758 DCHECK_GT(tilings_->num_tilings(), 0u); | |
759 | |
760 // The goal of this function is to find the minimum set of tiles that need to | |
761 // be ready to draw in order to activate without flashing content from a | |
762 // higher res on the active tree to a lower res on the pending tree. | |
763 | |
764 // First, early out for layers with no visible content. | |
765 if (visible_content_rect().IsEmpty()) | |
766 return; | |
767 | |
768 gfx::Rect rect(visible_content_rect()); | |
769 | |
770 float min_acceptable_scale = | |
771 std::min(raster_contents_scale_, ideal_contents_scale_); | |
772 | |
773 if (PictureLayerImpl* twin = twin_layer_) { | |
774 float twin_min_acceptable_scale = | |
775 std::min(twin->ideal_contents_scale_, twin->raster_contents_scale_); | |
776 // Ignore 0 scale in case CalculateContentsScale() has never been | |
777 // called for active twin. | |
778 if (twin_min_acceptable_scale != 0.0f) { | |
779 min_acceptable_scale = | |
780 std::min(min_acceptable_scale, twin_min_acceptable_scale); | |
781 } | |
782 } | |
783 | |
784 PictureLayerTiling* high_res = NULL; | |
785 PictureLayerTiling* low_res = NULL; | |
786 | |
787 // First pass: ready to draw tiles in acceptable but non-ideal tilings are | |
788 // marked as required for activation so that their textures are not thrown | |
789 // away; any non-ready tiles are not marked as required. | |
790 Region missing_region = rect; | |
791 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { | |
792 PictureLayerTiling* tiling = tilings_->tiling_at(i); | |
793 DCHECK(tiling->has_ever_been_updated()); | |
794 | |
795 if (tiling->resolution() == LOW_RESOLUTION) { | |
796 DCHECK(!low_res) << "There can only be one low res tiling"; | |
797 low_res = tiling; | |
798 } | |
799 if (tiling->contents_scale() < min_acceptable_scale) | |
800 continue; | |
801 if (tiling->resolution() == HIGH_RESOLUTION) { | |
802 DCHECK(!high_res) << "There can only be one high res tiling"; | |
803 high_res = tiling; | |
804 continue; | |
805 } | |
806 for (PictureLayerTiling::CoverageIterator iter(tiling, | |
807 contents_scale_x(), | |
808 rect); | |
809 iter; | |
810 ++iter) { | |
811 if (!*iter || !iter->IsReadyToDraw()) | |
812 continue; | |
813 | |
814 missing_region.Subtract(iter.geometry_rect()); | |
815 iter->MarkRequiredForActivation(); | |
816 } | |
817 } | |
818 DCHECK(high_res) << "There must be one high res tiling"; | |
819 | |
820 // If these pointers are null (because no twin, no matching tiling, or the | |
821 // simpification just below), then high res tiles will be required to fill any | |
822 // holes left by the first pass above. If the pointers are valid, then this | |
823 // layer is allowed to skip any tiles that are not ready on its twin. | |
824 const PictureLayerTiling* twin_high_res = NULL; | |
825 const PictureLayerTiling* twin_low_res = NULL; | |
826 | |
827 if (twin_layer_) { | |
828 // As a simplification, only allow activating to skip twin tiles that the | |
829 // active layer is also missing when both this layer and its twin have | |
830 // "simple" sets of tilings: only 2 tilings (high and low) or only 1 high | |
831 // res tiling. This avoids having to iterate/track coverage of non-ideal | |
832 // tilings during the last draw call on the active layer. | |
833 if (tilings_->num_tilings() <= 2 && | |
834 twin_layer_->tilings_->num_tilings() <= tilings_->num_tilings()) { | |
835 twin_low_res = low_res ? GetTwinTiling(low_res) : NULL; | |
836 twin_high_res = high_res ? GetTwinTiling(high_res) : NULL; | |
837 } | |
838 | |
839 // If this layer and its twin have different transforms, then don't compare | |
840 // them and only allow activating to high res tiles, since tiles on each | |
841 // layer will be in different places on screen. | |
842 if (twin_layer_->layer_tree_impl()->RequiresHighResToDraw() || | |
843 bounds() != twin_layer_->bounds() || | |
844 draw_properties().screen_space_transform != | |
845 twin_layer_->draw_properties().screen_space_transform) { | |
846 twin_high_res = NULL; | |
847 twin_low_res = NULL; | |
848 } | |
849 } | |
850 | |
851 // As a second pass, mark as required any visible high res tiles not filled in | |
852 // by acceptable non-ideal tiles from the first pass. | |
853 if (MarkVisibleTilesAsRequired( | |
854 high_res, twin_high_res, contents_scale_x(), rect, missing_region)) { | |
855 // As an optional third pass, if a high res tile was skipped because its | |
856 // twin was also missing, then fall back to mark low res tiles as required | |
857 // in case the active twin is substituting those for missing high res | |
858 // content. Only suitable, when low res is enabled. | |
859 if (low_res) { | |
860 MarkVisibleTilesAsRequired( | |
861 low_res, twin_low_res, contents_scale_x(), rect, missing_region); | |
862 } | |
863 } | |
864 } | |
865 | |
866 bool PictureLayerImpl::MarkVisibleTilesAsRequired( | |
867 PictureLayerTiling* tiling, | |
868 const PictureLayerTiling* optional_twin_tiling, | |
869 float contents_scale, | |
870 const gfx::Rect& rect, | |
871 const Region& missing_region) const { | |
872 bool twin_had_missing_tile = false; | |
873 for (PictureLayerTiling::CoverageIterator iter(tiling, | |
874 contents_scale, | |
875 rect); | |
876 iter; | |
877 ++iter) { | |
878 Tile* tile = *iter; | |
879 // A null tile (i.e. missing recording) can just be skipped. | |
880 if (!tile) | |
881 continue; | |
882 | |
883 // If the tile is occluded, don't mark it as required for activation. | |
884 if (tile->is_occluded(PENDING_TREE)) | |
885 continue; | |
886 | |
887 // If the missing region doesn't cover it, this tile is fully | |
888 // covered by acceptable tiles at other scales. | |
889 if (!missing_region.Intersects(iter.geometry_rect())) | |
890 continue; | |
891 | |
892 // If the twin tile doesn't exist (i.e. missing recording or so far away | |
893 // that it is outside the visible tile rect) or this tile is shared between | |
894 // with the twin, then this tile isn't required to prevent flashing. | |
895 if (optional_twin_tiling) { | |
896 Tile* twin_tile = optional_twin_tiling->TileAt(iter.i(), iter.j()); | |
897 if (!twin_tile || twin_tile == tile) { | |
898 twin_had_missing_tile = true; | |
899 continue; | |
900 } | |
901 } | |
902 | |
903 tile->MarkRequiredForActivation(); | |
904 } | |
905 return twin_had_missing_tile; | |
906 } | |
907 | |
908 void PictureLayerImpl::DoPostCommitInitialization() { | 753 void PictureLayerImpl::DoPostCommitInitialization() { |
909 DCHECK(needs_post_commit_initialization_); | 754 DCHECK(needs_post_commit_initialization_); |
910 DCHECK(layer_tree_impl()->IsPendingTree()); | 755 DCHECK(layer_tree_impl()->IsPendingTree()); |
911 | 756 |
912 if (!tilings_) | 757 if (!tilings_) |
913 tilings_.reset(new PictureLayerTilingSet(this, bounds())); | 758 tilings_.reset(new PictureLayerTilingSet(this, bounds())); |
914 | 759 |
915 DCHECK(!twin_layer_); | 760 DCHECK(!twin_layer_); |
916 twin_layer_ = static_cast<PictureLayerImpl*>( | 761 twin_layer_ = static_cast<PictureLayerImpl*>( |
917 layer_tree_impl()->FindActiveTreeLayerById(id())); | 762 layer_tree_impl()->FindActiveTreeLayerById(id())); |
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1635 return iterator_index_ < iterators_.size(); | 1480 return iterator_index_ < iterators_.size(); |
1636 } | 1481 } |
1637 | 1482 |
1638 bool PictureLayerImpl::LayerEvictionTileIterator::IsCorrectType( | 1483 bool PictureLayerImpl::LayerEvictionTileIterator::IsCorrectType( |
1639 PictureLayerTiling::TilingEvictionTileIterator* it) const { | 1484 PictureLayerTiling::TilingEvictionTileIterator* it) const { |
1640 return it->get_type() == iteration_stage_ && | 1485 return it->get_type() == iteration_stage_ && |
1641 (**it)->required_for_activation() == required_for_activation_; | 1486 (**it)->required_for_activation() == required_for_activation_; |
1642 } | 1487 } |
1643 | 1488 |
1644 } // namespace cc | 1489 } // namespace cc |
OLD | NEW |