OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/trees/draw_property_utils.h" | 5 #include "cc/trees/draw_property_utils.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 layer->set_clip_rect(gfx::ToEnclosingRect(clip_rect_in_target_space)); | 373 layer->set_clip_rect(gfx::ToEnclosingRect(clip_rect_in_target_space)); |
374 } else { | 374 } else { |
375 layer->set_clip_rect(gfx::Rect()); | 375 layer->set_clip_rect(gfx::Rect()); |
376 } | 376 } |
377 } | 377 } |
378 } | 378 } |
379 } | 379 } |
380 | 380 |
381 void CalculateVisibleRects(const LayerImplList& visible_layer_list, | 381 void CalculateVisibleRects(const LayerImplList& visible_layer_list, |
382 const PropertyTrees* property_trees, | 382 const PropertyTrees* property_trees, |
383 bool non_root_surfaces_enabled, | 383 bool non_root_surfaces_enabled) { |
384 bool verify_visible_rect_calculations) { | |
385 const EffectTree& effect_tree = property_trees->effect_tree; | 384 const EffectTree& effect_tree = property_trees->effect_tree; |
386 const TransformTree& transform_tree = property_trees->transform_tree; | 385 const TransformTree& transform_tree = property_trees->transform_tree; |
387 const ClipTree& clip_tree = property_trees->clip_tree; | 386 const ClipTree& clip_tree = property_trees->clip_tree; |
388 for (auto& layer : visible_layer_list) { | 387 for (auto& layer : visible_layer_list) { |
389 gfx::Size layer_bounds = layer->bounds(); | 388 gfx::Size layer_bounds = layer->bounds(); |
390 | 389 |
391 int effect_ancestor_with_copy_request = | 390 int effect_ancestor_with_copy_request = |
392 effect_tree.ClosestAncestorWithCopyRequest(layer->effect_tree_index()); | 391 effect_tree.ClosestAncestorWithCopyRequest(layer->effect_tree_index()); |
393 if (effect_ancestor_with_copy_request > 1) { | 392 if (effect_ancestor_with_copy_request > 1) { |
394 // Non root copy request. | 393 // Non root copy request. |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 } | 552 } |
554 gfx::Transform target_to_content; | 553 gfx::Transform target_to_content; |
555 target_to_content.Translate(-layer->offset_to_transform_parent().x(), | 554 target_to_content.Translate(-layer->offset_to_transform_parent().x(), |
556 -layer->offset_to_transform_parent().y()); | 555 -layer->offset_to_transform_parent().y()); |
557 target_to_content.PreconcatTransform(target_to_layer); | 556 target_to_content.PreconcatTransform(target_to_layer); |
558 | 557 |
559 gfx::Rect visible_rect = gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( | 558 gfx::Rect visible_rect = gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( |
560 target_to_content, combined_clip_rect_in_target_space)); | 559 target_to_content, combined_clip_rect_in_target_space)); |
561 visible_rect.Intersect(gfx::Rect(layer_bounds)); | 560 visible_rect.Intersect(gfx::Rect(layer_bounds)); |
562 layer->set_visible_layer_rect(visible_rect); | 561 layer->set_visible_layer_rect(visible_rect); |
563 | |
564 if (verify_visible_rect_calculations) { | |
565 gfx::Rect visible_rect_dynamic = | |
566 ComputeLayerVisibleRectDynamic(property_trees, layer); | |
567 DCHECK(layer->visible_layer_rect() == visible_rect_dynamic) | |
568 << " layer: " << layer->id() | |
569 << " clip id: " << layer->clip_tree_index() | |
570 << " visible rect cached: " << layer->visible_layer_rect().ToString() | |
571 << " v.s. " | |
572 << " visible rect dynamic: " << visible_rect_dynamic.ToString(); | |
573 } | |
574 } | 562 } |
575 } | 563 } |
576 | 564 |
577 static bool HasSingularTransform(int transform_tree_index, | 565 static bool HasSingularTransform(int transform_tree_index, |
578 const TransformTree& tree) { | 566 const TransformTree& tree) { |
579 const TransformNode* node = tree.Node(transform_tree_index); | 567 const TransformNode* node = tree.Node(transform_tree_index); |
580 return !node->is_invertible || !node->ancestors_are_invertible; | 568 return !node->is_invertible || !node->ancestors_are_invertible; |
581 } | 569 } |
582 | 570 |
583 template <typename LayerType> | 571 template <typename LayerType> |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1110 << DrawTransform(layer, property_trees->transform_tree, | 1098 << DrawTransform(layer, property_trees->transform_tree, |
1111 property_trees->effect_tree) | 1099 property_trees->effect_tree) |
1112 .ToString() | 1100 .ToString() |
1113 << " v.s." << draw_transform.ToString(); | 1101 << " v.s." << draw_transform.ToString(); |
1114 } | 1102 } |
1115 | 1103 |
1116 static void ComputeVisibleRectsInternal( | 1104 static void ComputeVisibleRectsInternal( |
1117 LayerImpl* root_layer, | 1105 LayerImpl* root_layer, |
1118 PropertyTrees* property_trees, | 1106 PropertyTrees* property_trees, |
1119 bool can_render_to_separate_surface, | 1107 bool can_render_to_separate_surface, |
1120 bool verify_visible_rect_calculations, | |
1121 std::vector<LayerImpl*>* visible_layer_list) { | 1108 std::vector<LayerImpl*>* visible_layer_list) { |
1122 if (property_trees->non_root_surfaces_enabled != | 1109 if (property_trees->non_root_surfaces_enabled != |
1123 can_render_to_separate_surface) { | 1110 can_render_to_separate_surface) { |
1124 property_trees->non_root_surfaces_enabled = can_render_to_separate_surface; | 1111 property_trees->non_root_surfaces_enabled = can_render_to_separate_surface; |
1125 property_trees->transform_tree.set_needs_update(true); | 1112 property_trees->transform_tree.set_needs_update(true); |
1126 } | 1113 } |
1127 if (property_trees->transform_tree.needs_update()) { | 1114 if (property_trees->transform_tree.needs_update()) { |
1128 property_trees->clip_tree.set_needs_update(true); | 1115 property_trees->clip_tree.set_needs_update(true); |
1129 property_trees->effect_tree.set_needs_update(true); | 1116 property_trees->effect_tree.set_needs_update(true); |
1130 } | 1117 } |
1131 UpdateRenderTarget(&property_trees->effect_tree, | 1118 UpdateRenderTarget(&property_trees->effect_tree, |
1132 property_trees->non_root_surfaces_enabled); | 1119 property_trees->non_root_surfaces_enabled); |
1133 ComputeTransforms(&property_trees->transform_tree); | 1120 ComputeTransforms(&property_trees->transform_tree); |
1134 // Computation of clips uses surface contents scale which is updated while | 1121 // Computation of clips uses surface contents scale which is updated while |
1135 // computing effects. So, ComputeEffects should be before ComputeClips. | 1122 // computing effects. So, ComputeEffects should be before ComputeClips. |
1136 ComputeEffects(&property_trees->effect_tree); | 1123 ComputeEffects(&property_trees->effect_tree); |
1137 ComputeClips(property_trees, can_render_to_separate_surface); | 1124 ComputeClips(property_trees, can_render_to_separate_surface); |
1138 | 1125 |
1139 FindLayersThatNeedUpdates(root_layer->layer_tree_impl(), | 1126 FindLayersThatNeedUpdates(root_layer->layer_tree_impl(), |
1140 property_trees->transform_tree, | 1127 property_trees->transform_tree, |
1141 property_trees->effect_tree, visible_layer_list); | 1128 property_trees->effect_tree, visible_layer_list); |
1142 CalculateClipRects<LayerImpl>(*visible_layer_list, property_trees, | 1129 CalculateClipRects<LayerImpl>(*visible_layer_list, property_trees, |
1143 can_render_to_separate_surface); | 1130 can_render_to_separate_surface); |
1144 CalculateVisibleRects(*visible_layer_list, property_trees, | 1131 CalculateVisibleRects(*visible_layer_list, property_trees, |
1145 can_render_to_separate_surface, | 1132 can_render_to_separate_surface); |
1146 verify_visible_rect_calculations); | |
1147 } | 1133 } |
1148 | 1134 |
1149 void UpdatePropertyTrees(PropertyTrees* property_trees, | 1135 void UpdatePropertyTrees(PropertyTrees* property_trees, |
1150 bool can_render_to_separate_surface) { | 1136 bool can_render_to_separate_surface) { |
1151 if (property_trees->non_root_surfaces_enabled != | 1137 if (property_trees->non_root_surfaces_enabled != |
1152 can_render_to_separate_surface) { | 1138 can_render_to_separate_surface) { |
1153 property_trees->non_root_surfaces_enabled = can_render_to_separate_surface; | 1139 property_trees->non_root_surfaces_enabled = can_render_to_separate_surface; |
1154 property_trees->transform_tree.set_needs_update(true); | 1140 property_trees->transform_tree.set_needs_update(true); |
1155 } | 1141 } |
1156 if (property_trees->transform_tree.needs_update()) { | 1142 if (property_trees->transform_tree.needs_update()) { |
(...skipping 12 matching lines...) Expand all Loading... |
1169 const LayerImpl* page_scale_layer, | 1155 const LayerImpl* page_scale_layer, |
1170 const LayerImpl* inner_viewport_scroll_layer, | 1156 const LayerImpl* inner_viewport_scroll_layer, |
1171 const LayerImpl* outer_viewport_scroll_layer, | 1157 const LayerImpl* outer_viewport_scroll_layer, |
1172 const LayerImpl* overscroll_elasticity_layer, | 1158 const LayerImpl* overscroll_elasticity_layer, |
1173 const gfx::Vector2dF& elastic_overscroll, | 1159 const gfx::Vector2dF& elastic_overscroll, |
1174 float page_scale_factor, | 1160 float page_scale_factor, |
1175 float device_scale_factor, | 1161 float device_scale_factor, |
1176 const gfx::Rect& viewport, | 1162 const gfx::Rect& viewport, |
1177 const gfx::Transform& device_transform, | 1163 const gfx::Transform& device_transform, |
1178 bool can_render_to_separate_surface, | 1164 bool can_render_to_separate_surface, |
1179 bool verify_visible_rect_calculations, | |
1180 PropertyTrees* property_trees, | 1165 PropertyTrees* property_trees, |
1181 LayerImplList* visible_layer_list) { | 1166 LayerImplList* visible_layer_list) { |
1182 PropertyTreeBuilder::BuildPropertyTrees( | 1167 PropertyTreeBuilder::BuildPropertyTrees( |
1183 root_layer, page_scale_layer, inner_viewport_scroll_layer, | 1168 root_layer, page_scale_layer, inner_viewport_scroll_layer, |
1184 outer_viewport_scroll_layer, overscroll_elasticity_layer, | 1169 outer_viewport_scroll_layer, overscroll_elasticity_layer, |
1185 elastic_overscroll, page_scale_factor, device_scale_factor, viewport, | 1170 elastic_overscroll, page_scale_factor, device_scale_factor, viewport, |
1186 device_transform, property_trees); | 1171 device_transform, property_trees); |
1187 ComputeVisibleRects(root_layer, property_trees, | 1172 ComputeVisibleRects(root_layer, property_trees, |
1188 can_render_to_separate_surface, | 1173 can_render_to_separate_surface, visible_layer_list); |
1189 verify_visible_rect_calculations, visible_layer_list); | |
1190 } | 1174 } |
1191 | 1175 |
1192 void VerifyClipTreeCalculations(const LayerImplList& layer_list, | 1176 void VerifyClipTreeCalculations(const LayerImplList& layer_list, |
1193 PropertyTrees* property_trees) { | 1177 PropertyTrees* property_trees) { |
1194 if (property_trees->non_root_surfaces_enabled) { | 1178 if (property_trees->non_root_surfaces_enabled) { |
1195 ComputeClipsWithEffectTree(property_trees); | 1179 ComputeClipsWithEffectTree(property_trees); |
1196 } | 1180 } |
1197 for (auto* layer : layer_list) | 1181 for (auto* layer : layer_list) |
1198 ComputeLayerClipRect(property_trees, layer); | 1182 ComputeLayerClipRect(property_trees, layer); |
1199 } | 1183 } |
1200 | 1184 |
1201 void VerifyTransformTreeCalculations(const LayerImplList& layer_list, | 1185 void VerifyTransformTreeCalculations(const LayerImplList& layer_list, |
1202 PropertyTrees* property_trees) { | 1186 PropertyTrees* property_trees) { |
1203 for (auto* layer : layer_list) | 1187 for (auto* layer : layer_list) |
1204 VerifyDrawTransformsMatch(layer, property_trees); | 1188 VerifyDrawTransformsMatch(layer, property_trees); |
1205 } | 1189 } |
1206 | 1190 |
1207 void ComputeVisibleRects(LayerImpl* root_layer, | 1191 void ComputeVisibleRects(LayerImpl* root_layer, |
1208 PropertyTrees* property_trees, | 1192 PropertyTrees* property_trees, |
1209 bool can_render_to_separate_surface, | 1193 bool can_render_to_separate_surface, |
1210 bool verify_visible_rect_calculations, | |
1211 LayerImplList* visible_layer_list) { | 1194 LayerImplList* visible_layer_list) { |
1212 for (auto* layer : *root_layer->layer_tree_impl()) { | 1195 for (auto* layer : *root_layer->layer_tree_impl()) { |
1213 UpdateRenderSurfaceForLayer(&property_trees->effect_tree, | 1196 UpdateRenderSurfaceForLayer(&property_trees->effect_tree, |
1214 can_render_to_separate_surface, layer); | 1197 can_render_to_separate_surface, layer); |
1215 EffectNode* node = | 1198 EffectNode* node = |
1216 property_trees->effect_tree.Node(layer->effect_tree_index()); | 1199 property_trees->effect_tree.Node(layer->effect_tree_index()); |
1217 if (node->owner_id == layer->id()) | 1200 if (node->owner_id == layer->id()) |
1218 node->render_surface = layer->render_surface(); | 1201 node->render_surface = layer->render_surface(); |
1219 #if DCHECK_IS_ON() | 1202 #if DCHECK_IS_ON() |
1220 if (can_render_to_separate_surface) | 1203 if (can_render_to_separate_surface) |
1221 ValidateRenderSurfaceForLayer(layer); | 1204 ValidateRenderSurfaceForLayer(layer); |
1222 #endif | 1205 #endif |
1223 } | 1206 } |
1224 ComputeVisibleRectsInternal( | 1207 ComputeVisibleRectsInternal(root_layer, property_trees, |
1225 root_layer, property_trees, can_render_to_separate_surface, | 1208 can_render_to_separate_surface, |
1226 verify_visible_rect_calculations, visible_layer_list); | 1209 visible_layer_list); |
1227 } | 1210 } |
1228 | 1211 |
1229 gfx::Rect ComputeLayerVisibleRectDynamic(const PropertyTrees* property_trees, | 1212 gfx::Rect ComputeLayerVisibleRectDynamic(const PropertyTrees* property_trees, |
1230 const LayerImpl* layer) { | 1213 const LayerImpl* layer) { |
1231 gfx::RectF accumulated_clip_in_root_space = | 1214 int effect_ancestor_with_copy_request = |
1232 ComputeAccumulatedClipInRootSpaceForVisibleRect(property_trees, | 1215 property_trees->effect_tree.ClosestAncestorWithCopyRequest( |
1233 layer->clip_tree_index()); | 1216 layer->effect_tree_index()); |
| 1217 bool non_root_copy_request = |
| 1218 effect_ancestor_with_copy_request > EffectTree::kContentsRootNodeId; |
| 1219 gfx::Rect layer_content_rect = gfx::Rect(layer->bounds()); |
| 1220 gfx::RectF accumulated_clip_in_root_space; |
| 1221 if (non_root_copy_request) { |
| 1222 ConditionalClip accumulated_clip = |
| 1223 ComputeAccumulatedClip(property_trees, layer->clip_tree_index(), |
| 1224 effect_ancestor_with_copy_request); |
| 1225 if (!accumulated_clip.is_clipped) |
| 1226 return layer_content_rect; |
| 1227 accumulated_clip_in_root_space = accumulated_clip.clip_rect; |
| 1228 } else { |
| 1229 accumulated_clip_in_root_space = |
| 1230 ComputeAccumulatedClipInRootSpaceForVisibleRect( |
| 1231 property_trees, layer->clip_tree_index()); |
| 1232 } |
1234 | 1233 |
1235 const EffectNode* root_effect_node = | 1234 const EffectNode* root_effect_node = |
1236 property_trees->effect_tree.Node(EffectTree::kContentsRootNodeId); | 1235 non_root_copy_request |
| 1236 ? property_trees->effect_tree.Node(effect_ancestor_with_copy_request) |
| 1237 : property_trees->effect_tree.Node(EffectTree::kContentsRootNodeId); |
1237 ConditionalClip accumulated_clip_in_layer_space = | 1238 ConditionalClip accumulated_clip_in_layer_space = |
1238 ComputeTargetRectInLocalSpace( | 1239 ComputeTargetRectInLocalSpace( |
1239 accumulated_clip_in_root_space, property_trees, | 1240 accumulated_clip_in_root_space, property_trees, |
1240 root_effect_node->transform_id, layer->transform_tree_index(), | 1241 root_effect_node->transform_id, layer->transform_tree_index(), |
1241 root_effect_node->id); | 1242 root_effect_node->id); |
| 1243 if (!accumulated_clip_in_layer_space.is_clipped) |
| 1244 return layer_content_rect; |
1242 gfx::RectF clip_in_layer_space = accumulated_clip_in_layer_space.clip_rect; | 1245 gfx::RectF clip_in_layer_space = accumulated_clip_in_layer_space.clip_rect; |
1243 clip_in_layer_space.Offset(-layer->offset_to_transform_parent()); | 1246 clip_in_layer_space.Offset(-layer->offset_to_transform_parent()); |
1244 | 1247 |
1245 gfx::Rect layer_content_rect = gfx::Rect(layer->bounds()); | |
1246 gfx::Rect visible_rect = gfx::ToEnclosingRect(clip_in_layer_space); | 1248 gfx::Rect visible_rect = gfx::ToEnclosingRect(clip_in_layer_space); |
1247 visible_rect.Intersect(layer_content_rect); | 1249 visible_rect.Intersect(layer_content_rect); |
1248 return visible_rect; | 1250 return visible_rect; |
1249 } | 1251 } |
1250 | 1252 |
| 1253 void VerifyVisibleRectsCalculations(const LayerImplList& layer_list, |
| 1254 const PropertyTrees* property_trees) { |
| 1255 for (auto layer : layer_list) { |
| 1256 gfx::Rect visible_rect_dynamic = |
| 1257 ComputeLayerVisibleRectDynamic(property_trees, layer); |
| 1258 DCHECK(layer->visible_layer_rect() == visible_rect_dynamic) |
| 1259 << " layer: " << layer->id() << " clip id: " << layer->clip_tree_index() |
| 1260 << " visible rect cached: " << layer->visible_layer_rect().ToString() |
| 1261 << " v.s. " |
| 1262 << " visible rect dynamic: " << visible_rect_dynamic.ToString(); |
| 1263 } |
| 1264 } |
| 1265 |
1251 bool LayerNeedsUpdate(Layer* layer, | 1266 bool LayerNeedsUpdate(Layer* layer, |
1252 bool layer_is_drawn, | 1267 bool layer_is_drawn, |
1253 const TransformTree& tree) { | 1268 const TransformTree& tree) { |
1254 return LayerNeedsUpdateInternal(layer, layer_is_drawn, tree); | 1269 return LayerNeedsUpdateInternal(layer, layer_is_drawn, tree); |
1255 } | 1270 } |
1256 | 1271 |
1257 bool LayerNeedsUpdate(LayerImpl* layer, | 1272 bool LayerNeedsUpdate(LayerImpl* layer, |
1258 bool layer_is_drawn, | 1273 bool layer_is_drawn, |
1259 const TransformTree& tree) { | 1274 const TransformTree& tree) { |
1260 return LayerNeedsUpdateInternal(layer, layer_is_drawn, tree); | 1275 return LayerNeedsUpdateInternal(layer, layer_is_drawn, tree); |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1660 void UpdateElasticOverscroll(PropertyTrees* property_trees, | 1675 void UpdateElasticOverscroll(PropertyTrees* property_trees, |
1661 const Layer* overscroll_elasticity_layer, | 1676 const Layer* overscroll_elasticity_layer, |
1662 const gfx::Vector2dF& elastic_overscroll) { | 1677 const gfx::Vector2dF& elastic_overscroll) { |
1663 UpdateElasticOverscrollInternal(property_trees, overscroll_elasticity_layer, | 1678 UpdateElasticOverscrollInternal(property_trees, overscroll_elasticity_layer, |
1664 elastic_overscroll); | 1679 elastic_overscroll); |
1665 } | 1680 } |
1666 | 1681 |
1667 } // namespace draw_property_utils | 1682 } // namespace draw_property_utils |
1668 | 1683 |
1669 } // namespace cc | 1684 } // namespace cc |
OLD | NEW |