Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Side by Side Diff: cc/trees/draw_property_utils.cc

Issue 2334003003: cc : Compute visible rects dynamically (1) (Closed)
Patch Set: comment Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 296
297 is_clipped = true; 297 is_clipped = true;
298 accumulated_clip = 298 accumulated_clip =
299 gfx::IntersectRects(accumulated_clip, current_clip.clip_rect); 299 gfx::IntersectRects(accumulated_clip, current_clip.clip_rect);
300 } 300 }
301 301
302 return ConditionalClip{ 302 return ConditionalClip{
303 is_clipped, accumulated_clip.IsEmpty() ? gfx::RectF() : accumulated_clip}; 303 is_clipped, accumulated_clip.IsEmpty() ? gfx::RectF() : accumulated_clip};
304 } 304 }
305 305
306 static gfx::RectF ComputeAccumulatedClipInRootSpaceForVisibleRect(
307 const PropertyTrees* property_trees,
308 int local_clip_id) {
309 const int root_effect_id = EffectTree::kContentsRootNodeId;
310 ConditionalClip accumulated_clip =
311 ComputeAccumulatedClip(property_trees, local_clip_id, root_effect_id);
312
313 gfx::RectF accumulated_clip_rect = accumulated_clip.clip_rect;
314 const ClipNode* root_effect_node =
315 property_trees->clip_tree.Node(root_effect_id);
316 if (accumulated_clip.is_clipped) {
317 accumulated_clip_rect.Intersect(root_effect_node->clip_in_target_space);
318 } else {
319 // In this case, we need only the viewport clip as the accumulated clip is
320 // unclipped.
321 accumulated_clip_rect = root_effect_node->clip_in_target_space;
322 }
323 return accumulated_clip_rect;
324 }
325
306 template <typename LayerType> 326 template <typename LayerType>
307 void CalculateClipRects( 327 void CalculateClipRects(
308 const typename LayerType::LayerListType& visible_layer_list, 328 const typename LayerType::LayerListType& visible_layer_list,
309 const PropertyTrees* property_trees, 329 const PropertyTrees* property_trees,
310 bool non_root_surfaces_enabled) { 330 bool non_root_surfaces_enabled) {
311 const ClipTree& clip_tree = property_trees->clip_tree; 331 const ClipTree& clip_tree = property_trees->clip_tree;
312 for (auto& layer : visible_layer_list) { 332 for (auto& layer : visible_layer_list) {
313 const ClipNode* clip_node = clip_tree.Node(layer->clip_tree_index()); 333 const ClipNode* clip_node = clip_tree.Node(layer->clip_tree_index());
314 if (!non_root_surfaces_enabled) { 334 if (!non_root_surfaces_enabled) {
315 layer->set_clip_rect( 335 layer->set_clip_rect(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 layer->set_clip_rect(gfx::ToEnclosingRect(clip_rect_in_target_space)); 373 layer->set_clip_rect(gfx::ToEnclosingRect(clip_rect_in_target_space));
354 } else { 374 } else {
355 layer->set_clip_rect(gfx::Rect()); 375 layer->set_clip_rect(gfx::Rect());
356 } 376 }
357 } 377 }
358 } 378 }
359 } 379 }
360 380
361 void CalculateVisibleRects(const LayerImplList& visible_layer_list, 381 void CalculateVisibleRects(const LayerImplList& visible_layer_list,
362 const PropertyTrees* property_trees, 382 const PropertyTrees* property_trees,
363 bool non_root_surfaces_enabled) { 383 bool non_root_surfaces_enabled,
384 bool verify_visible_rect_calculations) {
364 const EffectTree& effect_tree = property_trees->effect_tree; 385 const EffectTree& effect_tree = property_trees->effect_tree;
365 const TransformTree& transform_tree = property_trees->transform_tree; 386 const TransformTree& transform_tree = property_trees->transform_tree;
366 const ClipTree& clip_tree = property_trees->clip_tree; 387 const ClipTree& clip_tree = property_trees->clip_tree;
367 for (auto& layer : visible_layer_list) { 388 for (auto& layer : visible_layer_list) {
368 gfx::Size layer_bounds = layer->bounds(); 389 gfx::Size layer_bounds = layer->bounds();
369 390
370 int effect_ancestor_with_copy_request = 391 int effect_ancestor_with_copy_request =
371 effect_tree.ClosestAncestorWithCopyRequest(layer->effect_tree_index()); 392 effect_tree.ClosestAncestorWithCopyRequest(layer->effect_tree_index());
372 if (effect_ancestor_with_copy_request > 1) { 393 if (effect_ancestor_with_copy_request > 1) {
373 // Non root copy request. 394 // Non root copy request.
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 } 537 }
517 gfx::Transform target_to_content; 538 gfx::Transform target_to_content;
518 target_to_content.Translate(-layer->offset_to_transform_parent().x(), 539 target_to_content.Translate(-layer->offset_to_transform_parent().x(),
519 -layer->offset_to_transform_parent().y()); 540 -layer->offset_to_transform_parent().y());
520 target_to_content.PreconcatTransform(target_to_layer); 541 target_to_content.PreconcatTransform(target_to_layer);
521 542
522 gfx::Rect visible_rect = gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( 543 gfx::Rect visible_rect = gfx::ToEnclosingRect(MathUtil::ProjectClippedRect(
523 target_to_content, combined_clip_rect_in_target_space)); 544 target_to_content, combined_clip_rect_in_target_space));
524 visible_rect.Intersect(gfx::Rect(layer_bounds)); 545 visible_rect.Intersect(gfx::Rect(layer_bounds));
525 layer->set_visible_layer_rect(visible_rect); 546 layer->set_visible_layer_rect(visible_rect);
547
548 if (verify_visible_rect_calculations) {
549 gfx::Rect visible_rect_dynamic =
550 ComputeLayerVisibleRectDynamic(property_trees, layer);
551 DCHECK(layer->visible_layer_rect() == visible_rect)
552 << " layer: " << layer->id()
553 << " clip id: " << layer->clip_tree_index()
554 << " visible rect cached: " << layer->visible_layer_rect().ToString()
555 << " v.s. "
556 << " visible rect dynamic: " << visible_rect_dynamic.ToString();
557 }
526 } 558 }
527 } 559 }
528 560
529 static bool HasSingularTransform(int transform_tree_index, 561 static bool HasSingularTransform(int transform_tree_index,
530 const TransformTree& tree) { 562 const TransformTree& tree) {
531 const TransformNode* node = tree.Node(transform_tree_index); 563 const TransformNode* node = tree.Node(transform_tree_index);
532 return !node->is_invertible || !node->ancestors_are_invertible; 564 return !node->is_invertible || !node->ancestors_are_invertible;
533 } 565 }
534 566
535 template <typename LayerType> 567 template <typename LayerType>
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 << DrawTransform(layer, property_trees->transform_tree, 1094 << DrawTransform(layer, property_trees->transform_tree,
1063 property_trees->effect_tree) 1095 property_trees->effect_tree)
1064 .ToString() 1096 .ToString()
1065 << " v.s." << draw_transform.ToString(); 1097 << " v.s." << draw_transform.ToString();
1066 } 1098 }
1067 1099
1068 static void ComputeVisibleRectsInternal( 1100 static void ComputeVisibleRectsInternal(
1069 LayerImpl* root_layer, 1101 LayerImpl* root_layer,
1070 PropertyTrees* property_trees, 1102 PropertyTrees* property_trees,
1071 bool can_render_to_separate_surface, 1103 bool can_render_to_separate_surface,
1104 bool verify_visible_rect_calculations,
1072 std::vector<LayerImpl*>* visible_layer_list) { 1105 std::vector<LayerImpl*>* visible_layer_list) {
1073 if (property_trees->non_root_surfaces_enabled != 1106 if (property_trees->non_root_surfaces_enabled !=
1074 can_render_to_separate_surface) { 1107 can_render_to_separate_surface) {
1075 property_trees->non_root_surfaces_enabled = can_render_to_separate_surface; 1108 property_trees->non_root_surfaces_enabled = can_render_to_separate_surface;
1076 property_trees->transform_tree.set_needs_update(true); 1109 property_trees->transform_tree.set_needs_update(true);
1077 } 1110 }
1078 if (property_trees->transform_tree.needs_update()) { 1111 if (property_trees->transform_tree.needs_update()) {
1079 property_trees->clip_tree.set_needs_update(true); 1112 property_trees->clip_tree.set_needs_update(true);
1080 property_trees->effect_tree.set_needs_update(true); 1113 property_trees->effect_tree.set_needs_update(true);
1081 } 1114 }
1082 UpdateRenderTarget(&property_trees->effect_tree, 1115 UpdateRenderTarget(&property_trees->effect_tree,
1083 property_trees->non_root_surfaces_enabled); 1116 property_trees->non_root_surfaces_enabled);
1084 ComputeTransforms(&property_trees->transform_tree); 1117 ComputeTransforms(&property_trees->transform_tree);
1085 // Computation of clips uses surface contents scale which is updated while 1118 // Computation of clips uses surface contents scale which is updated while
1086 // computing effects. So, ComputeEffects should be before ComputeClips. 1119 // computing effects. So, ComputeEffects should be before ComputeClips.
1087 ComputeEffects(&property_trees->effect_tree); 1120 ComputeEffects(&property_trees->effect_tree);
1088 ComputeClips(property_trees, can_render_to_separate_surface); 1121 ComputeClips(property_trees, can_render_to_separate_surface);
1089 1122
1090 FindLayersThatNeedUpdates(root_layer->layer_tree_impl(), 1123 FindLayersThatNeedUpdates(root_layer->layer_tree_impl(),
1091 property_trees->transform_tree, 1124 property_trees->transform_tree,
1092 property_trees->effect_tree, visible_layer_list); 1125 property_trees->effect_tree, visible_layer_list);
1093 CalculateClipRects<LayerImpl>(*visible_layer_list, property_trees, 1126 CalculateClipRects<LayerImpl>(*visible_layer_list, property_trees,
1094 can_render_to_separate_surface); 1127 can_render_to_separate_surface);
1095 CalculateVisibleRects(*visible_layer_list, property_trees, 1128 CalculateVisibleRects(*visible_layer_list, property_trees,
1096 can_render_to_separate_surface); 1129 can_render_to_separate_surface,
1130 verify_visible_rect_calculations);
1097 } 1131 }
1098 1132
1099 void UpdatePropertyTrees(PropertyTrees* property_trees, 1133 void UpdatePropertyTrees(PropertyTrees* property_trees,
1100 bool can_render_to_separate_surface) { 1134 bool can_render_to_separate_surface) {
1101 if (property_trees->non_root_surfaces_enabled != 1135 if (property_trees->non_root_surfaces_enabled !=
1102 can_render_to_separate_surface) { 1136 can_render_to_separate_surface) {
1103 property_trees->non_root_surfaces_enabled = can_render_to_separate_surface; 1137 property_trees->non_root_surfaces_enabled = can_render_to_separate_surface;
1104 property_trees->transform_tree.set_needs_update(true); 1138 property_trees->transform_tree.set_needs_update(true);
1105 } 1139 }
1106 if (property_trees->transform_tree.needs_update()) { 1140 if (property_trees->transform_tree.needs_update()) {
(...skipping 12 matching lines...) Expand all
1119 const LayerImpl* page_scale_layer, 1153 const LayerImpl* page_scale_layer,
1120 const LayerImpl* inner_viewport_scroll_layer, 1154 const LayerImpl* inner_viewport_scroll_layer,
1121 const LayerImpl* outer_viewport_scroll_layer, 1155 const LayerImpl* outer_viewport_scroll_layer,
1122 const LayerImpl* overscroll_elasticity_layer, 1156 const LayerImpl* overscroll_elasticity_layer,
1123 const gfx::Vector2dF& elastic_overscroll, 1157 const gfx::Vector2dF& elastic_overscroll,
1124 float page_scale_factor, 1158 float page_scale_factor,
1125 float device_scale_factor, 1159 float device_scale_factor,
1126 const gfx::Rect& viewport, 1160 const gfx::Rect& viewport,
1127 const gfx::Transform& device_transform, 1161 const gfx::Transform& device_transform,
1128 bool can_render_to_separate_surface, 1162 bool can_render_to_separate_surface,
1163 bool verify_visible_rect_calculations,
1129 PropertyTrees* property_trees, 1164 PropertyTrees* property_trees,
1130 LayerImplList* visible_layer_list) { 1165 LayerImplList* visible_layer_list) {
1131 PropertyTreeBuilder::BuildPropertyTrees( 1166 PropertyTreeBuilder::BuildPropertyTrees(
1132 root_layer, page_scale_layer, inner_viewport_scroll_layer, 1167 root_layer, page_scale_layer, inner_viewport_scroll_layer,
1133 outer_viewport_scroll_layer, overscroll_elasticity_layer, 1168 outer_viewport_scroll_layer, overscroll_elasticity_layer,
1134 elastic_overscroll, page_scale_factor, device_scale_factor, viewport, 1169 elastic_overscroll, page_scale_factor, device_scale_factor, viewport,
1135 device_transform, property_trees); 1170 device_transform, property_trees);
1136 ComputeVisibleRects(root_layer, property_trees, 1171 ComputeVisibleRects(root_layer, property_trees,
1137 can_render_to_separate_surface, visible_layer_list); 1172 can_render_to_separate_surface,
1173 verify_visible_rect_calculations, visible_layer_list);
1138 } 1174 }
1139 1175
1140 void VerifyClipTreeCalculations(const LayerImplList& layer_list, 1176 void VerifyClipTreeCalculations(const LayerImplList& layer_list,
1141 PropertyTrees* property_trees) { 1177 PropertyTrees* property_trees) {
1142 if (property_trees->non_root_surfaces_enabled) { 1178 if (property_trees->non_root_surfaces_enabled) {
1143 ComputeClipsWithEffectTree(property_trees); 1179 ComputeClipsWithEffectTree(property_trees);
1144 } 1180 }
1145 for (auto* layer : layer_list) 1181 for (auto* layer : layer_list)
1146 ComputeLayerClipRect(property_trees, layer); 1182 ComputeLayerClipRect(property_trees, layer);
1147 } 1183 }
1148 1184
1149 void VerifyTransformTreeCalculations(const LayerImplList& layer_list, 1185 void VerifyTransformTreeCalculations(const LayerImplList& layer_list,
1150 PropertyTrees* property_trees) { 1186 PropertyTrees* property_trees) {
1151 for (auto* layer : layer_list) 1187 for (auto* layer : layer_list)
1152 VerifyDrawTransformsMatch(layer, property_trees); 1188 VerifyDrawTransformsMatch(layer, property_trees);
1153 } 1189 }
1154 1190
1155 void ComputeVisibleRects(LayerImpl* root_layer, 1191 void ComputeVisibleRects(LayerImpl* root_layer,
1156 PropertyTrees* property_trees, 1192 PropertyTrees* property_trees,
1157 bool can_render_to_separate_surface, 1193 bool can_render_to_separate_surface,
1194 bool verify_visible_rect_calculations,
1158 LayerImplList* visible_layer_list) { 1195 LayerImplList* visible_layer_list) {
1159 for (auto* layer : *root_layer->layer_tree_impl()) { 1196 for (auto* layer : *root_layer->layer_tree_impl()) {
1160 UpdateRenderSurfaceForLayer(&property_trees->effect_tree, 1197 UpdateRenderSurfaceForLayer(&property_trees->effect_tree,
1161 can_render_to_separate_surface, layer); 1198 can_render_to_separate_surface, layer);
1162 EffectNode* node = 1199 EffectNode* node =
1163 property_trees->effect_tree.Node(layer->effect_tree_index()); 1200 property_trees->effect_tree.Node(layer->effect_tree_index());
1164 if (node->owner_id == layer->id()) 1201 if (node->owner_id == layer->id())
1165 node->render_surface = layer->render_surface(); 1202 node->render_surface = layer->render_surface();
1166 #if DCHECK_IS_ON() 1203 #if DCHECK_IS_ON()
1167 if (can_render_to_separate_surface) 1204 if (can_render_to_separate_surface)
1168 ValidateRenderSurfaceForLayer(layer); 1205 ValidateRenderSurfaceForLayer(layer);
1169 #endif 1206 #endif
1170 } 1207 }
1171 ComputeVisibleRectsInternal(root_layer, property_trees, 1208 ComputeVisibleRectsInternal(
1172 can_render_to_separate_surface, 1209 root_layer, property_trees, can_render_to_separate_surface,
1173 visible_layer_list); 1210 verify_visible_rect_calculations, visible_layer_list);
1211 }
1212
1213 gfx::Rect ComputeLayerVisibleRectDynamic(const PropertyTrees* property_trees,
1214 const LayerImpl* layer) {
1215 gfx::RectF accumulated_clip_in_root_space =
1216 ComputeAccumulatedClipInRootSpaceForVisibleRect(property_trees,
1217 layer->clip_tree_index());
1218
1219 const EffectNode* root_effect_node =
1220 property_trees->effect_tree.Node(EffectTree::kContentsRootNodeId);
1221 ConditionalClip accumulated_clip_in_layer_space =
1222 ComputeTargetRectInLocalSpace(
1223 accumulated_clip_in_root_space, property_trees,
1224 root_effect_node->transform_id, layer->transform_tree_index(),
1225 root_effect_node->id);
1226 gfx::RectF clip_in_layer_space = accumulated_clip_in_layer_space.clip_rect;
1227 clip_in_layer_space.Offset(-layer->offset_to_transform_parent());
1228
1229 gfx::Rect layer_content_rect = gfx::Rect(layer->bounds());
1230 gfx::Rect visible_rect = gfx::ToEnclosingRect(clip_in_layer_space);
1231 visible_rect.Intersect(layer_content_rect);
1232 return visible_rect;
1174 } 1233 }
1175 1234
1176 bool LayerNeedsUpdate(Layer* layer, 1235 bool LayerNeedsUpdate(Layer* layer,
1177 bool layer_is_drawn, 1236 bool layer_is_drawn,
1178 const TransformTree& tree) { 1237 const TransformTree& tree) {
1179 return LayerNeedsUpdateInternal(layer, layer_is_drawn, tree); 1238 return LayerNeedsUpdateInternal(layer, layer_is_drawn, tree);
1180 } 1239 }
1181 1240
1182 bool LayerNeedsUpdate(LayerImpl* layer, 1241 bool LayerNeedsUpdate(LayerImpl* layer,
1183 bool layer_is_drawn, 1242 bool layer_is_drawn,
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
1585 void UpdateElasticOverscroll(PropertyTrees* property_trees, 1644 void UpdateElasticOverscroll(PropertyTrees* property_trees,
1586 const Layer* overscroll_elasticity_layer, 1645 const Layer* overscroll_elasticity_layer,
1587 const gfx::Vector2dF& elastic_overscroll) { 1646 const gfx::Vector2dF& elastic_overscroll) {
1588 UpdateElasticOverscrollInternal(property_trees, overscroll_elasticity_layer, 1647 UpdateElasticOverscrollInternal(property_trees, overscroll_elasticity_layer,
1589 elastic_overscroll); 1648 elastic_overscroll);
1590 } 1649 }
1591 1650
1592 } // namespace draw_property_utils 1651 } // namespace draw_property_utils
1593 1652
1594 } // namespace cc 1653 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698