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

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
« no previous file with comments | « cc/trees/draw_property_utils.h ('k') | cc/trees/layer_tree_host_common.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 } 553 }
533 gfx::Transform target_to_content; 554 gfx::Transform target_to_content;
534 target_to_content.Translate(-layer->offset_to_transform_parent().x(), 555 target_to_content.Translate(-layer->offset_to_transform_parent().x(),
535 -layer->offset_to_transform_parent().y()); 556 -layer->offset_to_transform_parent().y());
536 target_to_content.PreconcatTransform(target_to_layer); 557 target_to_content.PreconcatTransform(target_to_layer);
537 558
538 gfx::Rect visible_rect = gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( 559 gfx::Rect visible_rect = gfx::ToEnclosingRect(MathUtil::ProjectClippedRect(
539 target_to_content, combined_clip_rect_in_target_space)); 560 target_to_content, combined_clip_rect_in_target_space));
540 visible_rect.Intersect(gfx::Rect(layer_bounds)); 561 visible_rect.Intersect(gfx::Rect(layer_bounds));
541 layer->set_visible_layer_rect(visible_rect); 562 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 }
542 } 574 }
543 } 575 }
544 576
545 static bool HasSingularTransform(int transform_tree_index, 577 static bool HasSingularTransform(int transform_tree_index,
546 const TransformTree& tree) { 578 const TransformTree& tree) {
547 const TransformNode* node = tree.Node(transform_tree_index); 579 const TransformNode* node = tree.Node(transform_tree_index);
548 return !node->is_invertible || !node->ancestors_are_invertible; 580 return !node->is_invertible || !node->ancestors_are_invertible;
549 } 581 }
550 582
551 template <typename LayerType> 583 template <typename LayerType>
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 << DrawTransform(layer, property_trees->transform_tree, 1110 << DrawTransform(layer, property_trees->transform_tree,
1079 property_trees->effect_tree) 1111 property_trees->effect_tree)
1080 .ToString() 1112 .ToString()
1081 << " v.s." << draw_transform.ToString(); 1113 << " v.s." << draw_transform.ToString();
1082 } 1114 }
1083 1115
1084 static void ComputeVisibleRectsInternal( 1116 static void ComputeVisibleRectsInternal(
1085 LayerImpl* root_layer, 1117 LayerImpl* root_layer,
1086 PropertyTrees* property_trees, 1118 PropertyTrees* property_trees,
1087 bool can_render_to_separate_surface, 1119 bool can_render_to_separate_surface,
1120 bool verify_visible_rect_calculations,
1088 std::vector<LayerImpl*>* visible_layer_list) { 1121 std::vector<LayerImpl*>* visible_layer_list) {
1089 if (property_trees->non_root_surfaces_enabled != 1122 if (property_trees->non_root_surfaces_enabled !=
1090 can_render_to_separate_surface) { 1123 can_render_to_separate_surface) {
1091 property_trees->non_root_surfaces_enabled = can_render_to_separate_surface; 1124 property_trees->non_root_surfaces_enabled = can_render_to_separate_surface;
1092 property_trees->transform_tree.set_needs_update(true); 1125 property_trees->transform_tree.set_needs_update(true);
1093 } 1126 }
1094 if (property_trees->transform_tree.needs_update()) { 1127 if (property_trees->transform_tree.needs_update()) {
1095 property_trees->clip_tree.set_needs_update(true); 1128 property_trees->clip_tree.set_needs_update(true);
1096 property_trees->effect_tree.set_needs_update(true); 1129 property_trees->effect_tree.set_needs_update(true);
1097 } 1130 }
1098 UpdateRenderTarget(&property_trees->effect_tree, 1131 UpdateRenderTarget(&property_trees->effect_tree,
1099 property_trees->non_root_surfaces_enabled); 1132 property_trees->non_root_surfaces_enabled);
1100 ComputeTransforms(&property_trees->transform_tree); 1133 ComputeTransforms(&property_trees->transform_tree);
1101 // Computation of clips uses surface contents scale which is updated while 1134 // Computation of clips uses surface contents scale which is updated while
1102 // computing effects. So, ComputeEffects should be before ComputeClips. 1135 // computing effects. So, ComputeEffects should be before ComputeClips.
1103 ComputeEffects(&property_trees->effect_tree); 1136 ComputeEffects(&property_trees->effect_tree);
1104 ComputeClips(property_trees, can_render_to_separate_surface); 1137 ComputeClips(property_trees, can_render_to_separate_surface);
1105 1138
1106 FindLayersThatNeedUpdates(root_layer->layer_tree_impl(), 1139 FindLayersThatNeedUpdates(root_layer->layer_tree_impl(),
1107 property_trees->transform_tree, 1140 property_trees->transform_tree,
1108 property_trees->effect_tree, visible_layer_list); 1141 property_trees->effect_tree, visible_layer_list);
1109 CalculateClipRects<LayerImpl>(*visible_layer_list, property_trees, 1142 CalculateClipRects<LayerImpl>(*visible_layer_list, property_trees,
1110 can_render_to_separate_surface); 1143 can_render_to_separate_surface);
1111 CalculateVisibleRects(*visible_layer_list, property_trees, 1144 CalculateVisibleRects(*visible_layer_list, property_trees,
1112 can_render_to_separate_surface); 1145 can_render_to_separate_surface,
1146 verify_visible_rect_calculations);
1113 } 1147 }
1114 1148
1115 void UpdatePropertyTrees(PropertyTrees* property_trees, 1149 void UpdatePropertyTrees(PropertyTrees* property_trees,
1116 bool can_render_to_separate_surface) { 1150 bool can_render_to_separate_surface) {
1117 if (property_trees->non_root_surfaces_enabled != 1151 if (property_trees->non_root_surfaces_enabled !=
1118 can_render_to_separate_surface) { 1152 can_render_to_separate_surface) {
1119 property_trees->non_root_surfaces_enabled = can_render_to_separate_surface; 1153 property_trees->non_root_surfaces_enabled = can_render_to_separate_surface;
1120 property_trees->transform_tree.set_needs_update(true); 1154 property_trees->transform_tree.set_needs_update(true);
1121 } 1155 }
1122 if (property_trees->transform_tree.needs_update()) { 1156 if (property_trees->transform_tree.needs_update()) {
(...skipping 12 matching lines...) Expand all
1135 const LayerImpl* page_scale_layer, 1169 const LayerImpl* page_scale_layer,
1136 const LayerImpl* inner_viewport_scroll_layer, 1170 const LayerImpl* inner_viewport_scroll_layer,
1137 const LayerImpl* outer_viewport_scroll_layer, 1171 const LayerImpl* outer_viewport_scroll_layer,
1138 const LayerImpl* overscroll_elasticity_layer, 1172 const LayerImpl* overscroll_elasticity_layer,
1139 const gfx::Vector2dF& elastic_overscroll, 1173 const gfx::Vector2dF& elastic_overscroll,
1140 float page_scale_factor, 1174 float page_scale_factor,
1141 float device_scale_factor, 1175 float device_scale_factor,
1142 const gfx::Rect& viewport, 1176 const gfx::Rect& viewport,
1143 const gfx::Transform& device_transform, 1177 const gfx::Transform& device_transform,
1144 bool can_render_to_separate_surface, 1178 bool can_render_to_separate_surface,
1179 bool verify_visible_rect_calculations,
1145 PropertyTrees* property_trees, 1180 PropertyTrees* property_trees,
1146 LayerImplList* visible_layer_list) { 1181 LayerImplList* visible_layer_list) {
1147 PropertyTreeBuilder::BuildPropertyTrees( 1182 PropertyTreeBuilder::BuildPropertyTrees(
1148 root_layer, page_scale_layer, inner_viewport_scroll_layer, 1183 root_layer, page_scale_layer, inner_viewport_scroll_layer,
1149 outer_viewport_scroll_layer, overscroll_elasticity_layer, 1184 outer_viewport_scroll_layer, overscroll_elasticity_layer,
1150 elastic_overscroll, page_scale_factor, device_scale_factor, viewport, 1185 elastic_overscroll, page_scale_factor, device_scale_factor, viewport,
1151 device_transform, property_trees); 1186 device_transform, property_trees);
1152 ComputeVisibleRects(root_layer, property_trees, 1187 ComputeVisibleRects(root_layer, property_trees,
1153 can_render_to_separate_surface, visible_layer_list); 1188 can_render_to_separate_surface,
1189 verify_visible_rect_calculations, visible_layer_list);
1154 } 1190 }
1155 1191
1156 void VerifyClipTreeCalculations(const LayerImplList& layer_list, 1192 void VerifyClipTreeCalculations(const LayerImplList& layer_list,
1157 PropertyTrees* property_trees) { 1193 PropertyTrees* property_trees) {
1158 if (property_trees->non_root_surfaces_enabled) { 1194 if (property_trees->non_root_surfaces_enabled) {
1159 ComputeClipsWithEffectTree(property_trees); 1195 ComputeClipsWithEffectTree(property_trees);
1160 } 1196 }
1161 for (auto* layer : layer_list) 1197 for (auto* layer : layer_list)
1162 ComputeLayerClipRect(property_trees, layer); 1198 ComputeLayerClipRect(property_trees, layer);
1163 } 1199 }
1164 1200
1165 void VerifyTransformTreeCalculations(const LayerImplList& layer_list, 1201 void VerifyTransformTreeCalculations(const LayerImplList& layer_list,
1166 PropertyTrees* property_trees) { 1202 PropertyTrees* property_trees) {
1167 for (auto* layer : layer_list) 1203 for (auto* layer : layer_list)
1168 VerifyDrawTransformsMatch(layer, property_trees); 1204 VerifyDrawTransformsMatch(layer, property_trees);
1169 } 1205 }
1170 1206
1171 void ComputeVisibleRects(LayerImpl* root_layer, 1207 void ComputeVisibleRects(LayerImpl* root_layer,
1172 PropertyTrees* property_trees, 1208 PropertyTrees* property_trees,
1173 bool can_render_to_separate_surface, 1209 bool can_render_to_separate_surface,
1210 bool verify_visible_rect_calculations,
1174 LayerImplList* visible_layer_list) { 1211 LayerImplList* visible_layer_list) {
1175 for (auto* layer : *root_layer->layer_tree_impl()) { 1212 for (auto* layer : *root_layer->layer_tree_impl()) {
1176 UpdateRenderSurfaceForLayer(&property_trees->effect_tree, 1213 UpdateRenderSurfaceForLayer(&property_trees->effect_tree,
1177 can_render_to_separate_surface, layer); 1214 can_render_to_separate_surface, layer);
1178 EffectNode* node = 1215 EffectNode* node =
1179 property_trees->effect_tree.Node(layer->effect_tree_index()); 1216 property_trees->effect_tree.Node(layer->effect_tree_index());
1180 if (node->owner_id == layer->id()) 1217 if (node->owner_id == layer->id())
1181 node->render_surface = layer->render_surface(); 1218 node->render_surface = layer->render_surface();
1182 #if DCHECK_IS_ON() 1219 #if DCHECK_IS_ON()
1183 if (can_render_to_separate_surface) 1220 if (can_render_to_separate_surface)
1184 ValidateRenderSurfaceForLayer(layer); 1221 ValidateRenderSurfaceForLayer(layer);
1185 #endif 1222 #endif
1186 } 1223 }
1187 ComputeVisibleRectsInternal(root_layer, property_trees, 1224 ComputeVisibleRectsInternal(
1188 can_render_to_separate_surface, 1225 root_layer, property_trees, can_render_to_separate_surface,
1189 visible_layer_list); 1226 verify_visible_rect_calculations, visible_layer_list);
1227 }
1228
1229 gfx::Rect ComputeLayerVisibleRectDynamic(const PropertyTrees* property_trees,
1230 const LayerImpl* layer) {
1231 gfx::RectF accumulated_clip_in_root_space =
1232 ComputeAccumulatedClipInRootSpaceForVisibleRect(property_trees,
1233 layer->clip_tree_index());
1234
1235 const EffectNode* root_effect_node =
1236 property_trees->effect_tree.Node(EffectTree::kContentsRootNodeId);
1237 ConditionalClip accumulated_clip_in_layer_space =
1238 ComputeTargetRectInLocalSpace(
1239 accumulated_clip_in_root_space, property_trees,
1240 root_effect_node->transform_id, layer->transform_tree_index(),
1241 root_effect_node->id);
1242 gfx::RectF clip_in_layer_space = accumulated_clip_in_layer_space.clip_rect;
1243 clip_in_layer_space.Offset(-layer->offset_to_transform_parent());
1244
1245 gfx::Rect layer_content_rect = gfx::Rect(layer->bounds());
1246 gfx::Rect visible_rect = gfx::ToEnclosingRect(clip_in_layer_space);
1247 visible_rect.Intersect(layer_content_rect);
1248 return visible_rect;
1190 } 1249 }
1191 1250
1192 bool LayerNeedsUpdate(Layer* layer, 1251 bool LayerNeedsUpdate(Layer* layer,
1193 bool layer_is_drawn, 1252 bool layer_is_drawn,
1194 const TransformTree& tree) { 1253 const TransformTree& tree) {
1195 return LayerNeedsUpdateInternal(layer, layer_is_drawn, tree); 1254 return LayerNeedsUpdateInternal(layer, layer_is_drawn, tree);
1196 } 1255 }
1197 1256
1198 bool LayerNeedsUpdate(LayerImpl* layer, 1257 bool LayerNeedsUpdate(LayerImpl* layer,
1199 bool layer_is_drawn, 1258 bool layer_is_drawn,
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
1601 void UpdateElasticOverscroll(PropertyTrees* property_trees, 1660 void UpdateElasticOverscroll(PropertyTrees* property_trees,
1602 const Layer* overscroll_elasticity_layer, 1661 const Layer* overscroll_elasticity_layer,
1603 const gfx::Vector2dF& elastic_overscroll) { 1662 const gfx::Vector2dF& elastic_overscroll) {
1604 UpdateElasticOverscrollInternal(property_trees, overscroll_elasticity_layer, 1663 UpdateElasticOverscrollInternal(property_trees, overscroll_elasticity_layer,
1605 elastic_overscroll); 1664 elastic_overscroll);
1606 } 1665 }
1607 1666
1608 } // namespace draw_property_utils 1667 } // namespace draw_property_utils
1609 1668
1610 } // namespace cc 1669 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/draw_property_utils.h ('k') | cc/trees/layer_tree_host_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698