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

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

Issue 2715243008: cc : Fix transform calculation bug while calculating clip rects (Closed)
Patch Set: Created 3 years, 9 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 target_effect_node->id, &clip_to_target)) { 90 target_effect_node->id, &clip_to_target)) {
91 const EffectNode* source_node = 91 const EffectNode* source_node =
92 effect_tree.Node(clip_node->target_effect_id); 92 effect_tree.Node(clip_node->target_effect_id);
93 ConcatInverseSurfaceContentsScale(source_node, &clip_to_target); 93 ConcatInverseSurfaceContentsScale(source_node, &clip_to_target);
94 *clip_rect_in_target_space = 94 *clip_rect_in_target_space =
95 MathUtil::MapClippedRect(clip_to_target, clip_from_clip_node); 95 MathUtil::MapClippedRect(clip_to_target, clip_from_clip_node);
96 } else { 96 } else {
97 return false; 97 return false;
98 } 98 }
99 } else { 99 } else {
100 if (property_trees->ComputeTransformFromTarget( 100 if (property_trees->GetFromTarget(
101 target_node_id, clip_node->target_effect_id, &clip_to_target)) { 101 target_node_id, clip_node->target_effect_id, &clip_to_target)) {
102 PostConcatSurfaceContentsScale(target_effect_node, &clip_to_target);
102 *clip_rect_in_target_space = 103 *clip_rect_in_target_space =
103 MathUtil::ProjectClippedRect(clip_to_target, clip_from_clip_node); 104 MathUtil::ProjectClippedRect(clip_to_target, clip_from_clip_node);
104 } else { 105 } else {
105 return false; 106 return false;
106 } 107 }
107 } 108 }
108 return true; 109 return true;
109 } 110 }
110 111
111 struct ConditionalClip { 112 struct ConditionalClip {
112 bool is_clipped; 113 bool is_clipped;
113 gfx::RectF clip_rect; 114 gfx::RectF clip_rect;
114 }; 115 };
115 116
116 static ConditionalClip ComputeTargetRectInLocalSpace( 117 static ConditionalClip ComputeTargetRectInLocalSpace(
117 gfx::RectF rect, 118 gfx::RectF rect,
118 const PropertyTrees* property_trees, 119 const PropertyTrees* property_trees,
119 int target_transform_id, 120 int target_transform_id,
120 int local_transform_id, 121 int local_transform_id,
121 const int target_effect_id) { 122 const int target_effect_id) {
122 const EffectTree& effect_tree = property_trees->effect_tree;
123 gfx::Transform target_to_local; 123 gfx::Transform target_to_local;
124 bool success = property_trees->ComputeTransformFromTarget( 124 bool success = property_trees->GetFromTarget(
125 local_transform_id, target_effect_id, &target_to_local); 125 local_transform_id, target_effect_id, &target_to_local);
126 if (!success) 126 if (!success)
127 // If transform is not invertible, cannot apply clip. 127 // If transform is not invertible, cannot apply clip.
128 return ConditionalClip{false, gfx::RectF()}; 128 return ConditionalClip{false, gfx::RectF()};
129 const EffectNode* target_effect_node = effect_tree.Node(target_effect_id);
130 ConcatInverseSurfaceContentsScale(target_effect_node, &target_to_local);
131 129
132 if (target_transform_id > local_transform_id) 130 if (target_transform_id > local_transform_id)
133 return ConditionalClip{true, // is_clipped. 131 return ConditionalClip{true, // is_clipped.
134 MathUtil::MapClippedRect(target_to_local, rect)}; 132 MathUtil::MapClippedRect(target_to_local, rect)};
135 133
136 return ConditionalClip{true, // is_clipped. 134 return ConditionalClip{true, // is_clipped.
137 MathUtil::ProjectClippedRect(target_to_local, rect)}; 135 MathUtil::ProjectClippedRect(target_to_local, rect)};
138 } 136 }
139 137
140 static ConditionalClip ConvertRectBetweenSurfaceSpaces( 138 static ConditionalClip ConvertRectBetweenSurfaceSpaces(
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 } 554 }
557 555
558 combined_clip_rect_in_target_space.Intersect( 556 combined_clip_rect_in_target_space.Intersect(
559 layer_content_bounds_in_target_space); 557 layer_content_bounds_in_target_space);
560 if (combined_clip_rect_in_target_space.IsEmpty()) { 558 if (combined_clip_rect_in_target_space.IsEmpty()) {
561 layer->set_visible_layer_rect(gfx::Rect()); 559 layer->set_visible_layer_rect(gfx::Rect());
562 continue; 560 continue;
563 } 561 }
564 562
565 gfx::Transform target_to_layer; 563 gfx::Transform target_to_layer;
566 if (transform_node->ancestors_are_invertible) { 564 const EffectNode* target_effect_node =
567 property_trees->GetFromTarget(transform_node->id, 565 ContentsTargetEffectNode(layer->effect_tree_index(), effect_tree);
568 layer->render_target_effect_tree_index(), 566 bool success = property_trees->GetFromTarget(
569 &target_to_layer); 567 transform_node->id, target_effect_node->id, &target_to_layer);
570 } else { 568 if (!success) {
571 const EffectNode* target_effect_node = 569 // An animated singular transform may become non-singular during the
572 ContentsTargetEffectNode(layer->effect_tree_index(), effect_tree); 570 // animation, so we still need to compute a visible rect. In this
573 bool success = property_trees->ComputeTransformFromTarget( 571 // situation, we treat the entire layer as visible.
574 transform_node->id, target_effect_node->id, &target_to_layer); 572 layer->set_visible_layer_rect(gfx::Rect(layer_bounds));
575 if (!success) { 573 continue;
576 // An animated singular transform may become non-singular during the
577 // animation, so we still need to compute a visible rect. In this
578 // situation, we treat the entire layer as visible.
579 layer->set_visible_layer_rect(gfx::Rect(layer_bounds));
580 continue;
581 }
582 ConcatInverseSurfaceContentsScale(target_effect_node, &target_to_layer);
583 } 574 }
584 gfx::Transform target_to_content; 575 gfx::Transform target_to_content;
585 target_to_content.Translate(-layer->offset_to_transform_parent().x(), 576 target_to_content.Translate(-layer->offset_to_transform_parent().x(),
586 -layer->offset_to_transform_parent().y()); 577 -layer->offset_to_transform_parent().y());
587 target_to_content.PreconcatTransform(target_to_layer); 578 target_to_content.PreconcatTransform(target_to_layer);
588 579
589 gfx::Rect visible_rect = gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( 580 gfx::Rect visible_rect = gfx::ToEnclosingRect(MathUtil::ProjectClippedRect(
590 target_to_content, combined_clip_rect_in_target_space)); 581 target_to_content, combined_clip_rect_in_target_space));
591 visible_rect.Intersect(gfx::Rect(layer_bounds)); 582 visible_rect.Intersect(gfx::Rect(layer_bounds));
592 layer->set_visible_layer_rect(visible_rect); 583 layer->set_visible_layer_rect(visible_rect);
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 // must combine clips. For each clip node, we save the clip rects in its 846 // must combine clips. For each clip node, we save the clip rects in its
856 // target space. So, we need to get the ancestor clip rect in the current 847 // target space. So, we need to get the ancestor clip rect in the current
857 // clip node's target space. 848 // clip node's target space.
858 gfx::RectF parent_combined_clip_in_target_space = 849 gfx::RectF parent_combined_clip_in_target_space =
859 parent_clip_node->combined_clip_in_target_space; 850 parent_clip_node->combined_clip_in_target_space;
860 gfx::RectF parent_clip_in_target_space = 851 gfx::RectF parent_clip_in_target_space =
861 parent_clip_node->clip_in_target_space; 852 parent_clip_node->clip_in_target_space;
862 if (parent_target_transform_node && 853 if (parent_target_transform_node &&
863 parent_target_transform_node->id != clip_node->target_transform_id && 854 parent_target_transform_node->id != clip_node->target_transform_id &&
864 non_root_surfaces_enabled) { 855 non_root_surfaces_enabled) {
865 success &= property_trees->ComputeTransformFromTarget( 856 success &= property_trees->GetFromTarget(
866 clip_node->target_transform_id, parent_clip_node->target_effect_id, 857 clip_node->target_transform_id, parent_clip_node->target_effect_id,
867 &parent_to_current); 858 &parent_to_current);
868 const EffectNode* target_effect_node = 859 const EffectNode* target_effect_node =
869 effect_tree.Node(clip_node->target_effect_id); 860 effect_tree.Node(clip_node->target_effect_id);
870 PostConcatSurfaceContentsScale(target_effect_node, &parent_to_current); 861 PostConcatSurfaceContentsScale(target_effect_node, &parent_to_current);
871 const EffectNode* parent_target_effect_node =
872 effect_tree.Node(parent_clip_node->target_effect_id);
873 ConcatInverseSurfaceContentsScale(parent_target_effect_node,
874 &parent_to_current);
875 // If we can't compute a transform, it's because we had to use the inverse 862 // If we can't compute a transform, it's because we had to use the inverse
876 // of a singular transform. We won't draw in this case, so there's no need 863 // of a singular transform. We won't draw in this case, so there's no need
877 // to compute clips. 864 // to compute clips.
878 if (!success) 865 if (!success)
879 continue; 866 continue;
880 parent_combined_clip_in_target_space = MathUtil::ProjectClippedRect( 867 parent_combined_clip_in_target_space = MathUtil::ProjectClippedRect(
881 parent_to_current, parent_clip_node->combined_clip_in_target_space); 868 parent_to_current, parent_clip_node->combined_clip_in_target_space);
882 if (clip_node->clip_type == ClipNode::ClipType::EXPANDS_CLIP) { 869 if (clip_node->clip_type == ClipNode::ClipType::EXPANDS_CLIP) {
883 parent_combined_clip_in_target_space = 870 parent_combined_clip_in_target_space =
884 gfx::RectF(clip_node->clip_expander->MapRectReverse( 871 gfx::RectF(clip_node->clip_expander->MapRectReverse(
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
1560 void UpdateElasticOverscroll(PropertyTrees* property_trees, 1547 void UpdateElasticOverscroll(PropertyTrees* property_trees,
1561 const Layer* overscroll_elasticity_layer, 1548 const Layer* overscroll_elasticity_layer,
1562 const gfx::Vector2dF& elastic_overscroll) { 1549 const gfx::Vector2dF& elastic_overscroll) {
1563 UpdateElasticOverscrollInternal(property_trees, overscroll_elasticity_layer, 1550 UpdateElasticOverscrollInternal(property_trees, overscroll_elasticity_layer,
1564 elastic_overscroll); 1551 elastic_overscroll);
1565 } 1552 }
1566 1553
1567 } // namespace draw_property_utils 1554 } // namespace draw_property_utils
1568 1555
1569 } // namespace cc 1556 } // 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