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

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

Issue 2336923002: cc: Include viewport clip in visible rect of clip children (Closed)
Patch Set: comments 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 | « no previous file | cc/trees/layer_tree_host_common_unittest.cc » ('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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 const EffectTree& effect_tree) { 82 const EffectTree& effect_tree) {
83 const EffectNode* effect_node = effect_tree.Node(effect_tree_index); 83 const EffectNode* effect_node = effect_tree.Node(effect_tree_index);
84 return effect_node->render_surface ? effect_node 84 return effect_node->render_surface ? effect_node
85 : effect_tree.Node(effect_node->target_id); 85 : effect_tree.Node(effect_node->target_id);
86 } 86 }
87 87
88 bool ComputeClipRectInTargetSpace(const LayerImpl* layer, 88 bool ComputeClipRectInTargetSpace(const LayerImpl* layer,
89 const ClipNode* clip_node, 89 const ClipNode* clip_node,
90 const PropertyTrees* property_trees, 90 const PropertyTrees* property_trees,
91 int target_node_id, 91 int target_node_id,
92 bool for_visible_rect_calculation,
92 gfx::RectF* clip_rect_in_target_space) { 93 gfx::RectF* clip_rect_in_target_space) {
93 DCHECK(layer->clip_tree_index() == clip_node->id); 94 DCHECK(layer->clip_tree_index() == clip_node->id);
94 DCHECK(clip_node->target_transform_id != target_node_id); 95 DCHECK(clip_node->target_transform_id != target_node_id);
95 96
96 const EffectTree& effect_tree = property_trees->effect_tree; 97 const EffectTree& effect_tree = property_trees->effect_tree;
97 const EffectNode* target_effect_node = 98 const EffectNode* target_effect_node =
98 ContentsTargetEffectNode(layer->effect_tree_index(), effect_tree); 99 ContentsTargetEffectNode(layer->effect_tree_index(), effect_tree);
99 gfx::Transform clip_to_target; 100 gfx::Transform clip_to_target;
101 // We use the local clip for clip rect calculation and combined clip for
102 // visible rect calculation.
103 gfx::RectF clip_from_clip_node =
104 for_visible_rect_calculation ? clip_node->combined_clip_in_target_space
105 : clip_node->clip_in_target_space;
106
100 if (clip_node->target_transform_id > target_node_id) { 107 if (clip_node->target_transform_id > target_node_id) {
101 // In this case, layer has a scroll parent. We need to keep the scale 108 // In this case, layer has a scroll parent. We need to keep the scale
102 // at the layer's target but remove the scale at the scroll parent's 109 // at the layer's target but remove the scale at the scroll parent's
103 // target. 110 // target.
104 if (property_trees->ComputeTransformToTarget(clip_node->target_transform_id, 111 if (property_trees->ComputeTransformToTarget(clip_node->target_transform_id,
105 target_effect_node->id, 112 target_effect_node->id,
106 &clip_to_target)) { 113 &clip_to_target)) {
107 // We don't have to apply surface contents scale when target is root. 114 // We don't have to apply surface contents scale when target is root.
108 if (target_effect_node->id != EffectTree::kContentsRootNodeId) { 115 if (target_effect_node->id != EffectTree::kContentsRootNodeId) {
109 PostConcatSurfaceContentsScale(target_effect_node, &clip_to_target); 116 PostConcatSurfaceContentsScale(target_effect_node, &clip_to_target);
110 #if DCHECK_IS_ON() 117 #if DCHECK_IS_ON()
111 const TransformTree& transform_tree = property_trees->transform_tree; 118 const TransformTree& transform_tree = property_trees->transform_tree;
112 VerifySurfaceContentsScalesMatch(layer->effect_tree_index(), 119 VerifySurfaceContentsScalesMatch(layer->effect_tree_index(),
113 target_node_id, effect_tree, 120 target_node_id, effect_tree,
114 transform_tree); 121 transform_tree);
115 #endif 122 #endif
116 } 123 }
117 124
118 const EffectNode* source_node = 125 const EffectNode* source_node =
119 effect_tree.Node(clip_node->target_effect_id); 126 effect_tree.Node(clip_node->target_effect_id);
120 ConcatInverseSurfaceContentsScale(source_node, &clip_to_target); 127 ConcatInverseSurfaceContentsScale(source_node, &clip_to_target);
121 #if DCHECK_IS_ON() 128 #if DCHECK_IS_ON()
122 const TransformTree& transform_tree = property_trees->transform_tree; 129 const TransformTree& transform_tree = property_trees->transform_tree;
123 VerifySurfaceContentsScalesMatch(clip_node->target_effect_id, 130 VerifySurfaceContentsScalesMatch(clip_node->target_effect_id,
124 clip_node->target_transform_id, 131 clip_node->target_transform_id,
125 effect_tree, transform_tree); 132 effect_tree, transform_tree);
126 #endif 133 #endif
127 *clip_rect_in_target_space = MathUtil::MapClippedRect( 134 *clip_rect_in_target_space =
128 clip_to_target, clip_node->clip_in_target_space); 135 MathUtil::MapClippedRect(clip_to_target, clip_from_clip_node);
129 } else { 136 } else {
130 return false; 137 return false;
131 } 138 }
132 } else { 139 } else {
133 if (property_trees->ComputeTransformFromTarget( 140 if (property_trees->ComputeTransformFromTarget(
134 target_node_id, clip_node->target_effect_id, &clip_to_target)) { 141 target_node_id, clip_node->target_effect_id, &clip_to_target)) {
135 *clip_rect_in_target_space = MathUtil::ProjectClippedRect( 142 *clip_rect_in_target_space =
136 clip_to_target, clip_node->clip_in_target_space); 143 MathUtil::ProjectClippedRect(clip_to_target, clip_from_clip_node);
137 } else { 144 } else {
138 return false; 145 return false;
139 } 146 }
140 } 147 }
141 return true; 148 return true;
142 } 149 }
143 150
144 struct ConditionalClip { 151 struct ConditionalClip {
145 bool is_clipped; 152 bool is_clipped;
146 gfx::RectF clip_rect; 153 gfx::RectF clip_rect;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 // target space. 335 // target space.
329 if (clip_node->target_transform_id != target_node_id) { 336 if (clip_node->target_transform_id != target_node_id) {
330 // In this case, layer has a clip parent or scroll parent (or shares the 337 // In this case, layer has a clip parent or scroll parent (or shares the
331 // target with an ancestor layer that has clip parent) and the clip 338 // target with an ancestor layer that has clip parent) and the clip
332 // parent's target is different from the layer's target. As the layer's 339 // parent's target is different from the layer's target. As the layer's
333 // target has unclippped descendants, it is unclippped. 340 // target has unclippped descendants, it is unclippped.
334 if (!clip_node->layers_are_clipped) 341 if (!clip_node->layers_are_clipped)
335 continue; 342 continue;
336 343
337 // Compute the clip rect in target space and store it. 344 // Compute the clip rect in target space and store it.
338 if (!ComputeClipRectInTargetSpace(layer, clip_node, property_trees, 345 bool for_visible_rect_calculation = false;
339 target_node_id, 346 if (!ComputeClipRectInTargetSpace(
340 &clip_rect_in_target_space)) 347 layer, clip_node, property_trees, target_node_id,
348 for_visible_rect_calculation, &clip_rect_in_target_space))
341 continue; 349 continue;
342 } 350 }
343 351
344 if (!clip_rect_in_target_space.IsEmpty()) { 352 if (!clip_rect_in_target_space.IsEmpty()) {
345 layer->set_clip_rect(gfx::ToEnclosingRect(clip_rect_in_target_space)); 353 layer->set_clip_rect(gfx::ToEnclosingRect(clip_rect_in_target_space));
346 } else { 354 } else {
347 layer->set_clip_rect(gfx::Rect()); 355 layer->set_clip_rect(gfx::Rect());
348 } 356 }
349 } 357 }
350 } 358 }
351 } 359 }
352 360
353 bool GetLayerClipRect(const LayerImpl* layer,
354 const ClipNode* clip_node,
355 const PropertyTrees* property_trees,
356 int target_node_id,
357 gfx::RectF* clip_rect_in_target_space) {
358 // This is equivalent of calling ComputeClipRectInTargetSpace.
359 *clip_rect_in_target_space = gfx::RectF(layer->clip_rect());
360 return property_trees->transform_tree.Node(target_node_id)
361 ->ancestors_are_invertible;
362 }
363
364 void CalculateVisibleRects(const LayerImplList& visible_layer_list, 361 void CalculateVisibleRects(const LayerImplList& visible_layer_list,
365 const PropertyTrees* property_trees, 362 const PropertyTrees* property_trees,
366 bool non_root_surfaces_enabled) { 363 bool non_root_surfaces_enabled) {
367 const EffectTree& effect_tree = property_trees->effect_tree; 364 const EffectTree& effect_tree = property_trees->effect_tree;
368 const TransformTree& transform_tree = property_trees->transform_tree; 365 const TransformTree& transform_tree = property_trees->transform_tree;
369 const ClipTree& clip_tree = property_trees->clip_tree; 366 const ClipTree& clip_tree = property_trees->clip_tree;
370 for (auto& layer : visible_layer_list) { 367 for (auto& layer : visible_layer_list) {
371 gfx::Size layer_bounds = layer->bounds(); 368 gfx::Size layer_bounds = layer->bounds();
372 369
373 int effect_ancestor_with_copy_request = 370 int effect_ancestor_with_copy_request =
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 if (clip_node->target_transform_id != target_node_id) { 446 if (clip_node->target_transform_id != target_node_id) {
450 // In this case, layer has a clip parent or scroll parent (or shares the 447 // In this case, layer has a clip parent or scroll parent (or shares the
451 // target with an ancestor layer that has clip parent) and the clip 448 // target with an ancestor layer that has clip parent) and the clip
452 // parent's target is different from the layer's target. As the layer's 449 // parent's target is different from the layer's target. As the layer's
453 // target has unclippped descendants, it is unclippped. 450 // target has unclippped descendants, it is unclippped.
454 if (!clip_node->layers_are_clipped) { 451 if (!clip_node->layers_are_clipped) {
455 layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); 452 layer->set_visible_layer_rect(gfx::Rect(layer_bounds));
456 continue; 453 continue;
457 } 454 }
458 455
459 // We use the clip node's clip_in_target_space (and not 456 bool for_visible_rect_calculation = true;
460 // combined_clip_in_target_space) here because we want to clip 457 if (!ComputeClipRectInTargetSpace(layer, clip_node, property_trees,
461 // with respect to clip parent's local clip and not its combined clip as 458 target_node_id,
462 // the combined clip has even the clip parent's target's clip baked into 459 for_visible_rect_calculation,
463 // it and as our target is different, we don't want to use it in our 460 &combined_clip_rect_in_target_space)) {
464 // visible rect computation.
465 if (!GetLayerClipRect(layer, clip_node, property_trees, target_node_id,
466 &combined_clip_rect_in_target_space)) {
467 layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); 461 layer->set_visible_layer_rect(gfx::Rect(layer_bounds));
468 continue; 462 continue;
469 } 463 }
470 } else { 464 } else {
471 combined_clip_rect_in_target_space = 465 combined_clip_rect_in_target_space =
472 clip_node->combined_clip_in_target_space; 466 clip_node->combined_clip_in_target_space;
473 } 467 }
474 468
475 // The clip rect should be intersected with layer rect in target space. 469 // The clip rect should be intersected with layer rect in target space.
476 gfx::Transform content_to_target = transform_tree.ToTarget( 470 gfx::Transform content_to_target = transform_tree.ToTarget(
(...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1591 void UpdateElasticOverscroll(PropertyTrees* property_trees, 1585 void UpdateElasticOverscroll(PropertyTrees* property_trees,
1592 const Layer* overscroll_elasticity_layer, 1586 const Layer* overscroll_elasticity_layer,
1593 const gfx::Vector2dF& elastic_overscroll) { 1587 const gfx::Vector2dF& elastic_overscroll) {
1594 UpdateElasticOverscrollInternal(property_trees, overscroll_elasticity_layer, 1588 UpdateElasticOverscrollInternal(property_trees, overscroll_elasticity_layer,
1595 elastic_overscroll); 1589 elastic_overscroll);
1596 } 1590 }
1597 1591
1598 } // namespace draw_property_utils 1592 } // namespace draw_property_utils
1599 1593
1600 } // namespace cc 1594 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/trees/layer_tree_host_common_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698