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 30 matching lines...) Expand all Loading... |
41 const float kCpuSkewportTargetTimeInFrames = 60.0f; | 41 const float kCpuSkewportTargetTimeInFrames = 60.0f; |
42 | 42 |
43 // Don't pre-rasterize on the GPU (except for kBackflingGuardDistancePixels in | 43 // Don't pre-rasterize on the GPU (except for kBackflingGuardDistancePixels in |
44 // TileManager::BinFromTilePriority). | 44 // TileManager::BinFromTilePriority). |
45 const float kGpuSkewportTargetTimeInFrames = 0.0f; | 45 const float kGpuSkewportTargetTimeInFrames = 0.0f; |
46 | 46 |
47 } // namespace | 47 } // namespace |
48 | 48 |
49 namespace cc { | 49 namespace cc { |
50 | 50 |
51 PictureLayerImpl::Pair::Pair() : active(NULL), pending(NULL) { | 51 PictureLayerImpl::Pair::Pair() : active(nullptr), pending(nullptr) { |
52 } | 52 } |
53 | 53 |
54 PictureLayerImpl::Pair::Pair(PictureLayerImpl* active_layer, | 54 PictureLayerImpl::Pair::Pair(PictureLayerImpl* active_layer, |
55 PictureLayerImpl* pending_layer) | 55 PictureLayerImpl* pending_layer) |
56 : active(active_layer), pending(pending_layer) { | 56 : active(active_layer), pending(pending_layer) { |
57 } | 57 } |
58 | 58 |
59 PictureLayerImpl::Pair::~Pair() { | 59 PictureLayerImpl::Pair::~Pair() { |
60 } | 60 } |
61 | 61 |
62 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, int id) | 62 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, int id) |
63 : LayerImpl(tree_impl, id), | 63 : LayerImpl(tree_impl, id), |
64 twin_layer_(NULL), | 64 twin_layer_(nullptr), |
65 pile_(PicturePileImpl::Create()), | 65 pile_(PicturePileImpl::Create()), |
66 ideal_page_scale_(0.f), | 66 ideal_page_scale_(0.f), |
67 ideal_device_scale_(0.f), | 67 ideal_device_scale_(0.f), |
68 ideal_source_scale_(0.f), | 68 ideal_source_scale_(0.f), |
69 ideal_contents_scale_(0.f), | 69 ideal_contents_scale_(0.f), |
70 raster_page_scale_(0.f), | 70 raster_page_scale_(0.f), |
71 raster_device_scale_(0.f), | 71 raster_device_scale_(0.f), |
72 raster_source_scale_(0.f), | 72 raster_source_scale_(0.f), |
73 raster_contents_scale_(0.f), | 73 raster_contents_scale_(0.f), |
74 low_res_raster_contents_scale_(0.f), | 74 low_res_raster_contents_scale_(0.f), |
(...skipping 29 matching lines...) Expand all Loading... |
104 // with new tiles (due to invalidation). This resets all active priorities on | 104 // with new tiles (due to invalidation). This resets all active priorities on |
105 // the to-be-recycled tiling to ensure replaced tiles don't linger and take | 105 // the to-be-recycled tiling to ensure replaced tiles don't linger and take |
106 // memory (due to a stale 'active' priority). | 106 // memory (due to a stale 'active' priority). |
107 if (layer_impl->tilings_) | 107 if (layer_impl->tilings_) |
108 layer_impl->tilings_->DidBecomeRecycled(); | 108 layer_impl->tilings_->DidBecomeRecycled(); |
109 | 109 |
110 LayerImpl::PushPropertiesTo(base_layer); | 110 LayerImpl::PushPropertiesTo(base_layer); |
111 | 111 |
112 // When the pending tree pushes to the active tree, the pending twin | 112 // When the pending tree pushes to the active tree, the pending twin |
113 // becomes recycled. | 113 // becomes recycled. |
114 layer_impl->twin_layer_ = NULL; | 114 layer_impl->twin_layer_ = nullptr; |
115 twin_layer_ = NULL; | 115 twin_layer_ = nullptr; |
116 | 116 |
117 layer_impl->pile_ = pile_; | 117 layer_impl->pile_ = pile_; |
118 | 118 |
119 DCHECK(!pile_->is_solid_color() || !tilings_->num_tilings()); | 119 DCHECK(!pile_->is_solid_color() || !tilings_->num_tilings()); |
120 // Tilings would be expensive to push, so we swap. | 120 // Tilings would be expensive to push, so we swap. |
121 layer_impl->tilings_.swap(tilings_); | 121 layer_impl->tilings_.swap(tilings_); |
122 layer_impl->tilings_->SetClient(layer_impl); | 122 layer_impl->tilings_->SetClient(layer_impl); |
123 if (tilings_) | 123 if (tilings_) |
124 tilings_->SetClient(this); | 124 tilings_->SetClient(this); |
125 | 125 |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 return pile_.get(); | 616 return pile_.get(); |
617 } | 617 } |
618 | 618 |
619 const Region* PictureLayerImpl::GetInvalidation() { | 619 const Region* PictureLayerImpl::GetInvalidation() { |
620 return &invalidation_; | 620 return &invalidation_; |
621 } | 621 } |
622 | 622 |
623 const PictureLayerTiling* PictureLayerImpl::GetTwinTiling( | 623 const PictureLayerTiling* PictureLayerImpl::GetTwinTiling( |
624 const PictureLayerTiling* tiling) const { | 624 const PictureLayerTiling* tiling) const { |
625 if (!twin_layer_) | 625 if (!twin_layer_) |
626 return NULL; | 626 return nullptr; |
627 return twin_layer_->tilings_->TilingAtScale(tiling->contents_scale()); | 627 return twin_layer_->tilings_->TilingAtScale(tiling->contents_scale()); |
628 } | 628 } |
629 | 629 |
630 PictureLayerTiling* PictureLayerImpl::GetRecycledTwinTiling( | 630 PictureLayerTiling* PictureLayerImpl::GetRecycledTwinTiling( |
631 const PictureLayerTiling* tiling) { | 631 const PictureLayerTiling* tiling) { |
632 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); | 632 PictureLayerImpl* recycled_twin = GetRecycledTwinLayer(); |
633 if (!recycled_twin || !recycled_twin->tilings_) | 633 if (!recycled_twin || !recycled_twin->tilings_) |
634 return NULL; | 634 return nullptr; |
635 return recycled_twin->tilings_->TilingAtScale(tiling->contents_scale()); | 635 return recycled_twin->tilings_->TilingAtScale(tiling->contents_scale()); |
636 } | 636 } |
637 | 637 |
638 size_t PictureLayerImpl::GetMaxTilesForInterestArea() const { | 638 size_t PictureLayerImpl::GetMaxTilesForInterestArea() const { |
639 return layer_tree_impl()->settings().max_tiles_for_interest_area; | 639 return layer_tree_impl()->settings().max_tiles_for_interest_area; |
640 } | 640 } |
641 | 641 |
642 float PictureLayerImpl::GetSkewportTargetTimeInSeconds() const { | 642 float PictureLayerImpl::GetSkewportTargetTimeInSeconds() const { |
643 float skewport_target_time_in_frames = | 643 float skewport_target_time_in_frames = |
644 layer_tree_impl()->use_gpu_rasterization() | 644 layer_tree_impl()->use_gpu_rasterization() |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 float twin_min_acceptable_scale = | 819 float twin_min_acceptable_scale = |
820 std::min(twin->ideal_contents_scale_, twin->raster_contents_scale_); | 820 std::min(twin->ideal_contents_scale_, twin->raster_contents_scale_); |
821 // Ignore 0 scale in case CalculateContentsScale() has never been | 821 // Ignore 0 scale in case CalculateContentsScale() has never been |
822 // called for active twin. | 822 // called for active twin. |
823 if (twin_min_acceptable_scale != 0.0f) { | 823 if (twin_min_acceptable_scale != 0.0f) { |
824 min_acceptable_scale = | 824 min_acceptable_scale = |
825 std::min(min_acceptable_scale, twin_min_acceptable_scale); | 825 std::min(min_acceptable_scale, twin_min_acceptable_scale); |
826 } | 826 } |
827 } | 827 } |
828 | 828 |
829 PictureLayerTiling* high_res = NULL; | 829 PictureLayerTiling* high_res = nullptr; |
830 PictureLayerTiling* low_res = NULL; | 830 PictureLayerTiling* low_res = nullptr; |
831 | 831 |
832 // First pass: ready to draw tiles in acceptable but non-ideal tilings are | 832 // First pass: ready to draw tiles in acceptable but non-ideal tilings are |
833 // marked as required for activation so that their textures are not thrown | 833 // marked as required for activation so that their textures are not thrown |
834 // away; any non-ready tiles are not marked as required. | 834 // away; any non-ready tiles are not marked as required. |
835 Region missing_region = rect; | 835 Region missing_region = rect; |
836 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { | 836 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { |
837 PictureLayerTiling* tiling = tilings_->tiling_at(i); | 837 PictureLayerTiling* tiling = tilings_->tiling_at(i); |
838 DCHECK(tiling->has_ever_been_updated()); | 838 DCHECK(tiling->has_ever_been_updated()); |
839 | 839 |
840 if (tiling->resolution() == LOW_RESOLUTION) { | 840 if (tiling->resolution() == LOW_RESOLUTION) { |
(...skipping 15 matching lines...) Expand all Loading... |
856 missing_region.Subtract(iter.geometry_rect()); | 856 missing_region.Subtract(iter.geometry_rect()); |
857 iter->MarkRequiredForActivation(); | 857 iter->MarkRequiredForActivation(); |
858 } | 858 } |
859 } | 859 } |
860 DCHECK(high_res) << "There must be one high res tiling"; | 860 DCHECK(high_res) << "There must be one high res tiling"; |
861 | 861 |
862 // If these pointers are null (because no twin, no matching tiling, or the | 862 // If these pointers are null (because no twin, no matching tiling, or the |
863 // simpification just below), then high res tiles will be required to fill any | 863 // simpification just below), then high res tiles will be required to fill any |
864 // holes left by the first pass above. If the pointers are valid, then this | 864 // holes left by the first pass above. If the pointers are valid, then this |
865 // layer is allowed to skip any tiles that are not ready on its twin. | 865 // layer is allowed to skip any tiles that are not ready on its twin. |
866 const PictureLayerTiling* twin_high_res = NULL; | 866 const PictureLayerTiling* twin_high_res = nullptr; |
867 const PictureLayerTiling* twin_low_res = NULL; | 867 const PictureLayerTiling* twin_low_res = nullptr; |
868 | 868 |
869 if (twin_layer_) { | 869 if (twin_layer_) { |
870 // As a simplification, only allow activating to skip twin tiles that the | 870 // As a simplification, only allow activating to skip twin tiles that the |
871 // active layer is also missing when both this layer and its twin have | 871 // active layer is also missing when both this layer and its twin have |
872 // "simple" sets of tilings: only 2 tilings (high and low) or only 1 high | 872 // "simple" sets of tilings: only 2 tilings (high and low) or only 1 high |
873 // res tiling. This avoids having to iterate/track coverage of non-ideal | 873 // res tiling. This avoids having to iterate/track coverage of non-ideal |
874 // tilings during the last draw call on the active layer. | 874 // tilings during the last draw call on the active layer. |
875 if (tilings_->num_tilings() <= 2 && | 875 if (tilings_->num_tilings() <= 2 && |
876 twin_layer_->tilings_->num_tilings() <= tilings_->num_tilings()) { | 876 twin_layer_->tilings_->num_tilings() <= tilings_->num_tilings()) { |
877 twin_low_res = low_res ? GetTwinTiling(low_res) : NULL; | 877 twin_low_res = low_res ? GetTwinTiling(low_res) : nullptr; |
878 twin_high_res = high_res ? GetTwinTiling(high_res) : NULL; | 878 twin_high_res = high_res ? GetTwinTiling(high_res) : nullptr; |
879 } | 879 } |
880 | 880 |
881 // If this layer and its twin have different transforms, then don't compare | 881 // If this layer and its twin have different transforms, then don't compare |
882 // them and only allow activating to high res tiles, since tiles on each | 882 // them and only allow activating to high res tiles, since tiles on each |
883 // layer will be in different places on screen. | 883 // layer will be in different places on screen. |
884 if (layer_tree_impl()->RequiresHighResToDraw() || | 884 if (layer_tree_impl()->RequiresHighResToDraw() || |
885 bounds() != twin_layer_->bounds() || | 885 bounds() != twin_layer_->bounds() || |
886 draw_properties().screen_space_transform != | 886 draw_properties().screen_space_transform != |
887 twin_layer_->draw_properties().screen_space_transform) { | 887 twin_layer_->draw_properties().screen_space_transform) { |
888 twin_high_res = NULL; | 888 twin_high_res = nullptr; |
889 twin_low_res = NULL; | 889 twin_low_res = nullptr; |
890 } | 890 } |
891 } | 891 } |
892 | 892 |
893 // As a second pass, mark as required any visible high res tiles not filled in | 893 // As a second pass, mark as required any visible high res tiles not filled in |
894 // by acceptable non-ideal tiles from the first pass. | 894 // by acceptable non-ideal tiles from the first pass. |
895 if (MarkVisibleTilesAsRequired( | 895 if (MarkVisibleTilesAsRequired( |
896 high_res, twin_high_res, rect, missing_region)) { | 896 high_res, twin_high_res, rect, missing_region)) { |
897 // As an optional third pass, if a high res tile was skipped because its | 897 // As an optional third pass, if a high res tile was skipped because its |
898 // twin was also missing, then fall back to mark low res tiles as required | 898 // twin was also missing, then fall back to mark low res tiles as required |
899 // in case the active twin is substituting those for missing high res | 899 // in case the active twin is substituting those for missing high res |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1008 | 1008 |
1009 inline float PositiveRatio(float float1, float float2) { | 1009 inline float PositiveRatio(float float1, float float2) { |
1010 DCHECK_GT(float1, 0); | 1010 DCHECK_GT(float1, 0); |
1011 DCHECK_GT(float2, 0); | 1011 DCHECK_GT(float2, 0); |
1012 return float1 > float2 ? float1 / float2 : float2 / float1; | 1012 return float1 > float2 ? float1 / float2 : float2 / float1; |
1013 } | 1013 } |
1014 | 1014 |
1015 } // namespace | 1015 } // namespace |
1016 | 1016 |
1017 void PictureLayerImpl::AddTilingsForRasterScale() { | 1017 void PictureLayerImpl::AddTilingsForRasterScale() { |
1018 PictureLayerTiling* high_res = NULL; | 1018 PictureLayerTiling* high_res = nullptr; |
1019 PictureLayerTiling* low_res = NULL; | 1019 PictureLayerTiling* low_res = nullptr; |
1020 | 1020 |
1021 PictureLayerTiling* previous_low_res = NULL; | 1021 PictureLayerTiling* previous_low_res = nullptr; |
1022 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { | 1022 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { |
1023 PictureLayerTiling* tiling = tilings_->tiling_at(i); | 1023 PictureLayerTiling* tiling = tilings_->tiling_at(i); |
1024 if (tiling->contents_scale() == raster_contents_scale_) | 1024 if (tiling->contents_scale() == raster_contents_scale_) |
1025 high_res = tiling; | 1025 high_res = tiling; |
1026 if (tiling->contents_scale() == low_res_raster_contents_scale_) | 1026 if (tiling->contents_scale() == low_res_raster_contents_scale_) |
1027 low_res = tiling; | 1027 low_res = tiling; |
1028 if (tiling->resolution() == LOW_RESOLUTION) | 1028 if (tiling->resolution() == LOW_RESOLUTION) |
1029 previous_low_res = tiling; | 1029 previous_low_res = tiling; |
1030 | 1030 |
1031 // Reset all tilings to non-ideal until the end of this function. | 1031 // Reset all tilings to non-ideal until the end of this function. |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1509 | 1509 |
1510 if (tile->required_for_activation() && !tile->IsReadyToDraw()) | 1510 if (tile->required_for_activation() && !tile->IsReadyToDraw()) |
1511 return false; | 1511 return false; |
1512 } | 1512 } |
1513 } | 1513 } |
1514 | 1514 |
1515 return true; | 1515 return true; |
1516 } | 1516 } |
1517 | 1517 |
1518 PictureLayerImpl::LayerRasterTileIterator::LayerRasterTileIterator() | 1518 PictureLayerImpl::LayerRasterTileIterator::LayerRasterTileIterator() |
1519 : layer_(NULL), current_stage_(arraysize(stages_)) { | 1519 : layer_(nullptr), current_stage_(arraysize(stages_)) { |
1520 } | 1520 } |
1521 | 1521 |
1522 PictureLayerImpl::LayerRasterTileIterator::LayerRasterTileIterator( | 1522 PictureLayerImpl::LayerRasterTileIterator::LayerRasterTileIterator( |
1523 PictureLayerImpl* layer, | 1523 PictureLayerImpl* layer, |
1524 bool prioritize_low_res) | 1524 bool prioritize_low_res) |
1525 : layer_(layer), current_stage_(0) { | 1525 : layer_(layer), current_stage_(0) { |
1526 DCHECK(layer_); | 1526 DCHECK(layer_); |
1527 | 1527 |
1528 // Early out if the layer has no tilings. | 1528 // Early out if the layer has no tilings. |
1529 if (!layer_->tilings_ || !layer_->tilings_->num_tilings()) { | 1529 if (!layer_->tilings_ || !layer_->tilings_->num_tilings()) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1630 IteratorType index = stages_[current_stage_].iterator_type; | 1630 IteratorType index = stages_[current_stage_].iterator_type; |
1631 TilePriority::PriorityBin tile_type = stages_[current_stage_].tile_type; | 1631 TilePriority::PriorityBin tile_type = stages_[current_stage_].tile_type; |
1632 | 1632 |
1633 if (iterators_[index] && iterators_[index].get_type() == tile_type) | 1633 if (iterators_[index] && iterators_[index].get_type() == tile_type) |
1634 break; | 1634 break; |
1635 ++current_stage_; | 1635 ++current_stage_; |
1636 } | 1636 } |
1637 } | 1637 } |
1638 | 1638 |
1639 PictureLayerImpl::LayerEvictionTileIterator::LayerEvictionTileIterator() | 1639 PictureLayerImpl::LayerEvictionTileIterator::LayerEvictionTileIterator() |
1640 : layer_(NULL), | 1640 : layer_(nullptr), |
1641 tree_priority_(SAME_PRIORITY_FOR_BOTH_TREES), | 1641 tree_priority_(SAME_PRIORITY_FOR_BOTH_TREES), |
1642 current_category_(PictureLayerTiling::EVENTUALLY), | 1642 current_category_(PictureLayerTiling::EVENTUALLY), |
1643 current_tiling_range_type_(PictureLayerTilingSet::HIGHER_THAN_HIGH_RES), | 1643 current_tiling_range_type_(PictureLayerTilingSet::HIGHER_THAN_HIGH_RES), |
1644 current_tiling_(0u) { | 1644 current_tiling_(0u) { |
1645 } | 1645 } |
1646 | 1646 |
1647 PictureLayerImpl::LayerEvictionTileIterator::LayerEvictionTileIterator( | 1647 PictureLayerImpl::LayerEvictionTileIterator::LayerEvictionTileIterator( |
1648 PictureLayerImpl* layer, | 1648 PictureLayerImpl* layer, |
1649 TreePriority tree_priority) | 1649 TreePriority tree_priority) |
1650 : layer_(layer), | 1650 : layer_(layer), |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1783 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); | 1783 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); |
1784 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; | 1784 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; |
1785 return tiling_range.end - 1 - current_tiling_range_offset; | 1785 return tiling_range.end - 1 - current_tiling_range_offset; |
1786 } | 1786 } |
1787 } | 1787 } |
1788 NOTREACHED(); | 1788 NOTREACHED(); |
1789 return 0; | 1789 return 0; |
1790 } | 1790 } |
1791 | 1791 |
1792 } // namespace cc | 1792 } // namespace cc |
OLD | NEW |