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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 148 |
149 // We always need to push properties. | 149 // We always need to push properties. |
150 // See http://crbug.com/303943 | 150 // See http://crbug.com/303943 |
151 needs_push_properties_ = true; | 151 needs_push_properties_ = true; |
152 } | 152 } |
153 | 153 |
154 void PictureLayerImpl::AppendQuads(RenderPass* render_pass, | 154 void PictureLayerImpl::AppendQuads(RenderPass* render_pass, |
155 const Occlusion& occlusion_in_content_space, | 155 const Occlusion& occlusion_in_content_space, |
156 AppendQuadsData* append_quads_data) { | 156 AppendQuadsData* append_quads_data) { |
157 DCHECK(!needs_post_commit_initialization_); | 157 DCHECK(!needs_post_commit_initialization_); |
| 158 // The bounds and the pile size may differ if the pile wasn't updated (ie. |
| 159 // PictureLayer::Update didn't happen). But that should never be the case if |
| 160 // the layer is part of the visible frame, which is why we're appending quads |
| 161 // in the first place |
| 162 DCHECK_EQ(bounds().ToString(), pile_->tiling_size().ToString()); |
158 | 163 |
159 SharedQuadState* shared_quad_state = | 164 SharedQuadState* shared_quad_state = |
160 render_pass->CreateAndAppendSharedQuadState(); | 165 render_pass->CreateAndAppendSharedQuadState(); |
161 | 166 |
162 if (pile_->is_solid_color()) { | 167 if (pile_->is_solid_color()) { |
163 PopulateSharedQuadState(shared_quad_state); | 168 PopulateSharedQuadState(shared_quad_state); |
164 | 169 |
165 AppendDebugBorderQuad( | 170 AppendDebugBorderQuad( |
166 render_pass, content_bounds(), shared_quad_state, append_quads_data); | 171 render_pass, bounds(), shared_quad_state, append_quads_data); |
167 | 172 |
168 SolidColorLayerImpl::AppendSolidQuads(render_pass, | 173 SolidColorLayerImpl::AppendSolidQuads(render_pass, |
169 occlusion_in_content_space, | 174 occlusion_in_content_space, |
170 shared_quad_state, | 175 shared_quad_state, |
171 visible_content_rect(), | 176 visible_content_rect(), |
172 pile_->solid_color(), | 177 pile_->solid_color(), |
173 append_quads_data); | 178 append_quads_data); |
174 return; | 179 return; |
175 } | 180 } |
176 | 181 |
177 float max_contents_scale = MaximumTilingContentsScale(); | 182 float max_contents_scale = MaximumTilingContentsScale(); |
178 gfx::Transform scaled_draw_transform = draw_transform(); | 183 gfx::Transform scaled_draw_transform = draw_transform(); |
179 scaled_draw_transform.Scale(SK_MScalar1 / max_contents_scale, | 184 scaled_draw_transform.Scale(SK_MScalar1 / max_contents_scale, |
180 SK_MScalar1 / max_contents_scale); | 185 SK_MScalar1 / max_contents_scale); |
181 gfx::Size scaled_content_bounds = | 186 gfx::Size scaled_content_bounds = |
182 gfx::ToCeiledSize(gfx::ScaleSize(content_bounds(), max_contents_scale)); | 187 gfx::ToCeiledSize(gfx::ScaleSize(bounds(), max_contents_scale)); |
183 gfx::Rect scaled_visible_content_rect = | 188 gfx::Rect scaled_visible_content_rect = |
184 gfx::ScaleToEnclosingRect(visible_content_rect(), max_contents_scale); | 189 gfx::ScaleToEnclosingRect(visible_content_rect(), max_contents_scale); |
185 scaled_visible_content_rect.Intersect(gfx::Rect(scaled_content_bounds)); | 190 scaled_visible_content_rect.Intersect(gfx::Rect(scaled_content_bounds)); |
186 Occlusion scaled_occlusion = | 191 Occlusion scaled_occlusion = |
187 occlusion_in_content_space.GetOcclusionWithGivenDrawTransform( | 192 occlusion_in_content_space.GetOcclusionWithGivenDrawTransform( |
188 scaled_draw_transform); | 193 scaled_draw_transform); |
189 | 194 |
190 shared_quad_state->SetAll(scaled_draw_transform, | 195 shared_quad_state->SetAll(scaled_draw_transform, |
191 scaled_content_bounds, | 196 scaled_content_bounds, |
192 scaled_visible_content_rect, | 197 scaled_visible_content_rect, |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 } | 768 } |
764 | 769 |
765 raster_page_scale_ = other->raster_page_scale_; | 770 raster_page_scale_ = other->raster_page_scale_; |
766 raster_device_scale_ = other->raster_device_scale_; | 771 raster_device_scale_ = other->raster_device_scale_; |
767 raster_source_scale_ = other->raster_source_scale_; | 772 raster_source_scale_ = other->raster_source_scale_; |
768 raster_contents_scale_ = other->raster_contents_scale_; | 773 raster_contents_scale_ = other->raster_contents_scale_; |
769 low_res_raster_contents_scale_ = other->low_res_raster_contents_scale_; | 774 low_res_raster_contents_scale_ = other->low_res_raster_contents_scale_; |
770 | 775 |
771 bool synced_high_res_tiling = false; | 776 bool synced_high_res_tiling = false; |
772 if (CanHaveTilings()) { | 777 if (CanHaveTilings()) { |
773 synced_high_res_tiling = tilings_->SyncTilings( | 778 synced_high_res_tiling = tilings_->SyncTilings(*other->tilings_, |
774 *other->tilings_, bounds(), invalidation_, MinimumContentsScale()); | 779 pile_->tiling_size(), |
| 780 invalidation_, |
| 781 MinimumContentsScale()); |
775 } else { | 782 } else { |
776 RemoveAllTilings(); | 783 RemoveAllTilings(); |
777 } | 784 } |
778 | 785 |
779 // If our MinimumContentsScale has changed to prevent the twin's high res | 786 // If our MinimumContentsScale has changed to prevent the twin's high res |
780 // tiling from being synced, we should reset the raster scale and let it be | 787 // tiling from being synced, we should reset the raster scale and let it be |
781 // recalculated (1) again. This can happen if our bounds shrink to the point | 788 // recalculated (1) again. This can happen if our bounds shrink to the point |
782 // where min contents scale grows. | 789 // where min contents scale grows. |
783 // (1) - TODO(vmpstr) Instead of hoping that this will be recalculated, we | 790 // (1) - TODO(vmpstr) Instead of hoping that this will be recalculated, we |
784 // should refactor this code a little bit and actually recalculate this. | 791 // should refactor this code a little bit and actually recalculate this. |
785 // However, this is a larger undertaking, so this will work for now. | 792 // However, this is a larger undertaking, so this will work for now. |
786 if (!synced_high_res_tiling) | 793 if (!synced_high_res_tiling) |
787 ResetRasterScale(); | 794 ResetRasterScale(); |
788 else | 795 else |
789 SanityCheckTilingState(); | 796 SanityCheckTilingState(); |
790 } | 797 } |
791 | 798 |
792 void PictureLayerImpl::SyncTiling( | 799 void PictureLayerImpl::SyncTiling( |
793 const PictureLayerTiling* tiling) { | 800 const PictureLayerTiling* tiling) { |
794 if (!CanHaveTilingWithScale(tiling->contents_scale())) | 801 if (!CanHaveTilingWithScale(tiling->contents_scale())) |
795 return; | 802 return; |
796 tilings_->AddTiling(tiling->contents_scale(), bounds()); | 803 tilings_->AddTiling(tiling->contents_scale(), pile_->tiling_size()); |
797 | 804 |
798 // If this tree needs update draw properties, then the tiling will | 805 // If this tree needs update draw properties, then the tiling will |
799 // get updated prior to drawing or activation. If this tree does not | 806 // get updated prior to drawing or activation. If this tree does not |
800 // need update draw properties, then its transforms are up to date and | 807 // need update draw properties, then its transforms are up to date and |
801 // we can create tiles for this tiling immediately. | 808 // we can create tiles for this tiling immediately. |
802 if (!layer_tree_impl()->needs_update_draw_properties() && | 809 if (!layer_tree_impl()->needs_update_draw_properties() && |
803 should_update_tile_priorities_) { | 810 should_update_tile_priorities_) { |
804 // TODO(danakj): Add a DCHECK() that we are not using occlusion tracking | 811 // TODO(danakj): Add a DCHECK() that we are not using occlusion tracking |
805 // when we stop using the pending tree in the browser compositor. If we want | 812 // when we stop using the pending tree in the browser compositor. If we want |
806 // to support occlusion tracking here, we need to dirty the draw properties | 813 // to support occlusion tracking here, we need to dirty the draw properties |
807 // or save occlusion as a draw property. | 814 // or save occlusion as a draw property. |
808 UpdateTilePriorities(Occlusion()); | 815 UpdateTilePriorities(Occlusion()); |
809 } | 816 } |
810 } | 817 } |
811 | 818 |
812 void PictureLayerImpl::GetContentsResourceId( | 819 void PictureLayerImpl::GetContentsResourceId( |
813 ResourceProvider::ResourceId* resource_id, | 820 ResourceProvider::ResourceId* resource_id, |
814 gfx::Size* resource_size) const { | 821 gfx::Size* resource_size) const { |
| 822 DCHECK_EQ(bounds().ToString(), pile_->tiling_size().ToString()); |
815 gfx::Rect content_rect(bounds()); | 823 gfx::Rect content_rect(bounds()); |
816 PictureLayerTilingSet::CoverageIterator iter( | 824 PictureLayerTilingSet::CoverageIterator iter( |
817 tilings_.get(), 1.f, content_rect, ideal_contents_scale_); | 825 tilings_.get(), 1.f, content_rect, ideal_contents_scale_); |
818 | 826 |
819 // Mask resource not ready yet. | 827 // Mask resource not ready yet. |
820 if (!iter || !*iter) { | 828 if (!iter || !*iter) { |
821 *resource_id = 0; | 829 *resource_id = 0; |
822 return; | 830 return; |
823 } | 831 } |
824 | 832 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 SyncFromActiveLayer(twin_layer_); | 865 SyncFromActiveLayer(twin_layer_); |
858 } | 866 } |
859 | 867 |
860 needs_post_commit_initialization_ = false; | 868 needs_post_commit_initialization_ = false; |
861 } | 869 } |
862 | 870 |
863 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { | 871 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { |
864 DCHECK(CanHaveTilingWithScale(contents_scale)) << | 872 DCHECK(CanHaveTilingWithScale(contents_scale)) << |
865 "contents_scale: " << contents_scale; | 873 "contents_scale: " << contents_scale; |
866 | 874 |
867 PictureLayerTiling* tiling = tilings_->AddTiling(contents_scale, bounds()); | 875 PictureLayerTiling* tiling = |
| 876 tilings_->AddTiling(contents_scale, pile_->tiling_size()); |
868 | 877 |
869 DCHECK(pile_->HasRecordings()); | 878 DCHECK(pile_->HasRecordings()); |
870 | 879 |
871 if (twin_layer_) | 880 if (twin_layer_) |
872 twin_layer_->SyncTiling(tiling); | 881 twin_layer_->SyncTiling(tiling); |
873 | 882 |
874 return tiling; | 883 return tiling; |
875 } | 884 } |
876 | 885 |
877 void PictureLayerImpl::RemoveTiling(float contents_scale) { | 886 void PictureLayerImpl::RemoveTiling(float contents_scale) { |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1060 if (draw_properties().screen_space_transform_is_animating && | 1069 if (draw_properties().screen_space_transform_is_animating && |
1061 !ShouldAdjustRasterScaleDuringScaleAnimations()) { | 1070 !ShouldAdjustRasterScaleDuringScaleAnimations()) { |
1062 bool can_raster_at_maximum_scale = false; | 1071 bool can_raster_at_maximum_scale = false; |
1063 // TODO(ajuma): If we need to deal with scale-down animations starting right | 1072 // TODO(ajuma): If we need to deal with scale-down animations starting right |
1064 // as a layer gets promoted, then we'd want to have the | 1073 // as a layer gets promoted, then we'd want to have the |
1065 // |starting_animation_contents_scale| passed in here as a separate draw | 1074 // |starting_animation_contents_scale| passed in here as a separate draw |
1066 // property so we could try use that when the max is too large. | 1075 // property so we could try use that when the max is too large. |
1067 // See crbug.com/422341. | 1076 // See crbug.com/422341. |
1068 float maximum_scale = draw_properties().maximum_animation_contents_scale; | 1077 float maximum_scale = draw_properties().maximum_animation_contents_scale; |
1069 if (maximum_scale) { | 1078 if (maximum_scale) { |
1070 gfx::Size bounds_at_maximum_scale = | 1079 gfx::Size bounds_at_maximum_scale = gfx::ToCeiledSize( |
1071 gfx::ToCeiledSize(gfx::ScaleSize(bounds(), maximum_scale)); | 1080 gfx::ScaleSize(pile_->tiling_size(), maximum_scale)); |
1072 if (bounds_at_maximum_scale.GetArea() <= | 1081 if (bounds_at_maximum_scale.GetArea() <= |
1073 layer_tree_impl()->device_viewport_size().GetArea()) | 1082 layer_tree_impl()->device_viewport_size().GetArea()) |
1074 can_raster_at_maximum_scale = true; | 1083 can_raster_at_maximum_scale = true; |
1075 } | 1084 } |
1076 // Use the computed scales for the raster scale directly, do not try to use | 1085 // Use the computed scales for the raster scale directly, do not try to use |
1077 // the ideal scale here. The current ideal scale may be way too large in the | 1086 // the ideal scale here. The current ideal scale may be way too large in the |
1078 // case of an animation with scale, and will be constantly changing. | 1087 // case of an animation with scale, and will be constantly changing. |
1079 if (can_raster_at_maximum_scale) | 1088 if (can_raster_at_maximum_scale) |
1080 raster_contents_scale_ = maximum_scale; | 1089 raster_contents_scale_ = maximum_scale; |
1081 else | 1090 else |
1082 raster_contents_scale_ = 1.f * ideal_page_scale_ * ideal_device_scale_; | 1091 raster_contents_scale_ = 1.f * ideal_page_scale_ * ideal_device_scale_; |
1083 } | 1092 } |
1084 | 1093 |
1085 // If this layer would create zero or one tiles at this content scale, | 1094 // If this layer would create zero or one tiles at this content scale, |
1086 // don't create a low res tiling. | 1095 // don't create a low res tiling. |
1087 gfx::Size content_bounds = | 1096 gfx::Size raster_bounds = gfx::ToCeiledSize( |
1088 gfx::ToCeiledSize(gfx::ScaleSize(bounds(), raster_contents_scale_)); | 1097 gfx::ScaleSize(pile_->tiling_size(), raster_contents_scale_)); |
1089 gfx::Size tile_size = CalculateTileSize(content_bounds); | 1098 gfx::Size tile_size = CalculateTileSize(raster_bounds); |
1090 bool tile_covers_bounds = tile_size.width() >= content_bounds.width() && | 1099 bool tile_covers_bounds = tile_size.width() >= raster_bounds.width() && |
1091 tile_size.height() >= content_bounds.height(); | 1100 tile_size.height() >= raster_bounds.height(); |
1092 if (tile_size.IsEmpty() || tile_covers_bounds) { | 1101 if (tile_size.IsEmpty() || tile_covers_bounds) { |
1093 low_res_raster_contents_scale_ = raster_contents_scale_; | 1102 low_res_raster_contents_scale_ = raster_contents_scale_; |
1094 return; | 1103 return; |
1095 } | 1104 } |
1096 | 1105 |
1097 float low_res_factor = | 1106 float low_res_factor = |
1098 layer_tree_impl()->settings().low_res_contents_scale_factor; | 1107 layer_tree_impl()->settings().low_res_contents_scale_factor; |
1099 low_res_raster_contents_scale_ = std::max( | 1108 low_res_raster_contents_scale_ = std::max( |
1100 raster_contents_scale_ * low_res_factor, | 1109 raster_contents_scale_ * low_res_factor, |
1101 MinimumContentsScale()); | 1110 MinimumContentsScale()); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1178 SanityCheckTilingState(); | 1187 SanityCheckTilingState(); |
1179 } | 1188 } |
1180 | 1189 |
1181 float PictureLayerImpl::MinimumContentsScale() const { | 1190 float PictureLayerImpl::MinimumContentsScale() const { |
1182 float setting_min = layer_tree_impl()->settings().minimum_contents_scale; | 1191 float setting_min = layer_tree_impl()->settings().minimum_contents_scale; |
1183 | 1192 |
1184 // If the contents scale is less than 1 / width (also for height), | 1193 // If the contents scale is less than 1 / width (also for height), |
1185 // then it will end up having less than one pixel of content in that | 1194 // then it will end up having less than one pixel of content in that |
1186 // dimension. Bump the minimum contents scale up in this case to prevent | 1195 // dimension. Bump the minimum contents scale up in this case to prevent |
1187 // this from happening. | 1196 // this from happening. |
1188 int min_dimension = std::min(bounds().width(), bounds().height()); | 1197 int min_dimension = |
| 1198 std::min(pile_->tiling_size().width(), pile_->tiling_size().height()); |
1189 if (!min_dimension) | 1199 if (!min_dimension) |
1190 return setting_min; | 1200 return setting_min; |
1191 | 1201 |
1192 return std::max(1.f / min_dimension, setting_min); | 1202 return std::max(1.f / min_dimension, setting_min); |
1193 } | 1203 } |
1194 | 1204 |
1195 void PictureLayerImpl::ResetRasterScale() { | 1205 void PictureLayerImpl::ResetRasterScale() { |
1196 raster_page_scale_ = 0.f; | 1206 raster_page_scale_ = 0.f; |
1197 raster_device_scale_ = 0.f; | 1207 raster_device_scale_ = 0.f; |
1198 raster_source_scale_ = 0.f; | 1208 raster_source_scale_ = 0.f; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1311 | 1321 |
1312 state->BeginArray("pictures"); | 1322 state->BeginArray("pictures"); |
1313 pile_->AsValueInto(state); | 1323 pile_->AsValueInto(state); |
1314 state->EndArray(); | 1324 state->EndArray(); |
1315 | 1325 |
1316 state->BeginArray("invalidation"); | 1326 state->BeginArray("invalidation"); |
1317 invalidation_.AsValueInto(state); | 1327 invalidation_.AsValueInto(state); |
1318 state->EndArray(); | 1328 state->EndArray(); |
1319 | 1329 |
1320 state->BeginArray("coverage_tiles"); | 1330 state->BeginArray("coverage_tiles"); |
1321 for (PictureLayerTilingSet::CoverageIterator iter(tilings_.get(), | 1331 for (PictureLayerTilingSet::CoverageIterator iter( |
1322 1.f, | 1332 tilings_.get(), |
1323 gfx::Rect(content_bounds()), | 1333 1.f, |
1324 ideal_contents_scale_); | 1334 gfx::Rect(pile_->tiling_size()), |
| 1335 ideal_contents_scale_); |
1325 iter; | 1336 iter; |
1326 ++iter) { | 1337 ++iter) { |
1327 state->BeginDictionary(); | 1338 state->BeginDictionary(); |
1328 | 1339 |
1329 state->BeginArray("geometry_rect"); | 1340 state->BeginArray("geometry_rect"); |
1330 MathUtil::AddToTracedValue(iter.geometry_rect(), state); | 1341 MathUtil::AddToTracedValue(iter.geometry_rect(), state); |
1331 state->EndArray(); | 1342 state->EndArray(); |
1332 | 1343 |
1333 if (*iter) | 1344 if (*iter) |
1334 TracedValue::SetIDRef(*iter, state, "tile"); | 1345 TracedValue::SetIDRef(*iter, state, "tile"); |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1676 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); | 1687 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); |
1677 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; | 1688 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; |
1678 return tiling_range.end - 1 - current_tiling_range_offset; | 1689 return tiling_range.end - 1 - current_tiling_range_offset; |
1679 } | 1690 } |
1680 } | 1691 } |
1681 NOTREACHED(); | 1692 NOTREACHED(); |
1682 return 0; | 1693 return 0; |
1683 } | 1694 } |
1684 | 1695 |
1685 } // namespace cc | 1696 } // namespace cc |
OLD | NEW |