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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 EffectNode* effect_node = | 47 EffectNode* effect_node = |
48 layer->layer_tree_impl()->property_trees()->effect_tree.Node( | 48 layer->layer_tree_impl()->property_trees()->effect_tree.Node( |
49 layer->effect_tree_index()); | 49 layer->effect_tree_index()); |
50 if (effect_node->owner_id != layer->id()) | 50 if (effect_node->owner_id != layer->id()) |
51 return; | 51 return; |
52 DCHECK_EQ(effect_node->mask_layer_id, -1) << "layer: " << layer->id(); | 52 DCHECK_EQ(effect_node->mask_layer_id, -1) << "layer: " << layer->id(); |
53 DCHECK_EQ(effect_node->replica_layer_id, -1) << "layer: " << layer->id(); | 53 DCHECK_EQ(effect_node->replica_layer_id, -1) << "layer: " << layer->id(); |
54 DCHECK(effect_node->background_filters.IsEmpty()); | 54 DCHECK(effect_node->background_filters.IsEmpty()); |
55 } | 55 } |
56 | 56 |
57 void VerifySublayerScalesMatch(const int effect_node_id, | 57 void VerifySublayerScalesMatch(const int target_effect_id, |
58 const int target_transform_id, | 58 const int target_transform_id, |
59 const EffectTree& effect_tree, | 59 const EffectTree& effect_tree, |
60 const TransformTree& transform_tree) { | 60 const TransformTree& transform_tree) { |
61 const TransformNode* target_transform_node = | 61 const TransformNode* target_transform_node = |
62 transform_tree.Node(target_transform_id); | 62 transform_tree.Node(target_transform_id); |
63 const EffectNode* effect_node = effect_tree.Node(effect_node_id); | 63 const EffectNode* target_effect_node = effect_tree.Node(target_effect_id); |
64 const EffectNode* target_effect_node = | 64 DCHECK(target_transform_node->surface_contents_scale == |
65 effect_node->has_render_surface | 65 target_effect_node->surface_contents_scale) |
66 ? effect_node | |
67 : effect_tree.Node(effect_node->target_id); | |
68 DCHECK(target_transform_node->sublayer_scale == | |
69 target_effect_node->sublayer_scale) | |
70 << " sublayer scale from transform tree: " | 66 << " sublayer scale from transform tree: " |
71 << target_transform_node->sublayer_scale.ToString() | 67 << target_transform_node->surface_contents_scale.ToString() |
72 << " sublayer scale from effect tree: " | 68 << " sublayer scale from effect tree: " |
73 << target_effect_node->sublayer_scale.ToString(); | 69 << target_effect_node->surface_contents_scale.ToString(); |
74 } | 70 } |
75 #endif | 71 #endif |
76 | 72 |
| 73 static const EffectNode* ContentsTargetEffectNode( |
| 74 const int effect_tree_index, |
| 75 const EffectTree& effect_tree) { |
| 76 const EffectNode* effect_node = effect_tree.Node(effect_tree_index); |
| 77 return effect_node->has_render_surface |
| 78 ? effect_node |
| 79 : effect_tree.Node(effect_node->target_id); |
| 80 } |
| 81 |
77 template <typename LayerType> | 82 template <typename LayerType> |
78 bool ComputeClipRectInTargetSpace(const LayerType* layer, | 83 bool ComputeClipRectInTargetSpace(const LayerType* layer, |
79 const ClipNode* clip_node, | 84 const ClipNode* clip_node, |
80 const TransformTree& transform_tree, | 85 const TransformTree& transform_tree, |
81 const EffectTree& effect_tree, | 86 const EffectTree& effect_tree, |
82 int target_node_id, | 87 int target_node_id, |
83 gfx::RectF* clip_rect_in_target_space) { | 88 gfx::RectF* clip_rect_in_target_space) { |
84 DCHECK(layer->clip_tree_index() == clip_node->id); | 89 DCHECK(layer->clip_tree_index() == clip_node->id); |
85 DCHECK(clip_node->target_transform_id != target_node_id); | 90 DCHECK(clip_node->target_transform_id != target_node_id); |
86 | 91 |
87 gfx::Transform clip_to_target; | 92 gfx::Transform clip_to_target; |
88 if (clip_node->target_transform_id > target_node_id) { | 93 if (clip_node->target_transform_id > target_node_id) { |
89 // In this case, layer has a scroll parent. We need to keep the scale | 94 // In this case, layer has a scroll parent. We need to keep the scale |
90 // at the layer's target but remove the scale at the scroll parent's | 95 // at the layer's target but remove the scale at the scroll parent's |
91 // target. | 96 // target. |
92 if (transform_tree.ComputeTransform(clip_node->target_transform_id, | 97 if (transform_tree.ComputeTransform(clip_node->target_transform_id, |
93 target_node_id, &clip_to_target)) { | 98 target_node_id, &clip_to_target)) { |
94 // We don't have to apply sublayer scale when target is root. | 99 // We don't have to apply sublayer scale when target is root. |
95 if (target_node_id != 0) { | 100 if (target_node_id != 0) { |
96 PostConcatSublayerScale(layer->effect_tree_index(), effect_tree, | 101 const EffectNode* target_effect_node = |
97 &clip_to_target); | 102 ContentsTargetEffectNode(layer->effect_tree_index(), effect_tree); |
| 103 PostConcatSublayerScale(target_effect_node, &clip_to_target); |
98 #if DCHECK_IS_ON() | 104 #if DCHECK_IS_ON() |
99 VerifySublayerScalesMatch(layer->effect_tree_index(), target_node_id, | 105 VerifySublayerScalesMatch(layer->effect_tree_index(), target_node_id, |
100 effect_tree, transform_tree); | 106 effect_tree, transform_tree); |
101 #endif | 107 #endif |
102 } | 108 } |
103 | 109 |
104 const TransformNode* source_node = | 110 const EffectNode* source_node = |
105 transform_tree.Node(clip_node->target_transform_id); | 111 effect_tree.Node(clip_node->target_effect_id); |
106 if (source_node->sublayer_scale.x() != 0.f && | 112 ConcatInverseSublayerScale(source_node, &clip_to_target); |
107 source_node->sublayer_scale.y() != 0.f) | 113 #if DCHECK_IS_ON() |
108 clip_to_target.Scale(1.0f / source_node->sublayer_scale.x(), | 114 VerifySublayerScalesMatch(clip_node->target_effect_id, |
109 1.0f / source_node->sublayer_scale.y()); | 115 clip_node->target_transform_id, effect_tree, |
| 116 transform_tree); |
| 117 #endif |
110 *clip_rect_in_target_space = MathUtil::MapClippedRect( | 118 *clip_rect_in_target_space = MathUtil::MapClippedRect( |
111 clip_to_target, clip_node->clip_in_target_space); | 119 clip_to_target, clip_node->clip_in_target_space); |
112 } else { | 120 } else { |
113 return false; | 121 return false; |
114 } | 122 } |
115 } else { | 123 } else { |
116 if (transform_tree.ComputeTransform(clip_node->target_transform_id, | 124 if (transform_tree.ComputeTransform(clip_node->target_transform_id, |
117 target_node_id, &clip_to_target)) { | 125 target_node_id, &clip_to_target)) { |
118 *clip_rect_in_target_space = MathUtil::ProjectClippedRect( | 126 *clip_rect_in_target_space = MathUtil::ProjectClippedRect( |
119 clip_to_target, clip_node->clip_in_target_space); | 127 clip_to_target, clip_node->clip_in_target_space); |
120 } else { | 128 } else { |
121 return false; | 129 return false; |
122 } | 130 } |
123 } | 131 } |
124 return true; | 132 return true; |
125 } | 133 } |
126 | 134 |
127 struct ConditionalClip { | 135 struct ConditionalClip { |
128 bool is_clipped; | 136 bool is_clipped; |
129 gfx::RectF clip_rect; | 137 gfx::RectF clip_rect; |
130 }; | 138 }; |
131 | 139 |
132 static ConditionalClip ComputeTargetRectInLocalSpace( | 140 static ConditionalClip ComputeTargetRectInLocalSpace( |
133 gfx::RectF rect, | 141 gfx::RectF rect, |
134 const TransformTree& transform_tree, | 142 const TransformTree& transform_tree, |
| 143 const EffectTree& effect_tree, |
135 int current_transform_id, | 144 int current_transform_id, |
136 int target_transform_id) { | 145 int target_transform_id, |
| 146 const int current_effect_id) { |
137 gfx::Transform current_to_target; | 147 gfx::Transform current_to_target; |
138 if (!transform_tree.ComputeTransformWithSourceSublayerScale( | 148 bool success = transform_tree.ComputeTransform( |
139 current_transform_id, target_transform_id, ¤t_to_target)) | 149 current_transform_id, target_transform_id, ¤t_to_target); |
| 150 if (!success) |
140 // If transform is not invertible, cannot apply clip. | 151 // If transform is not invertible, cannot apply clip. |
141 return ConditionalClip{false, gfx::RectF()}; | 152 return ConditionalClip{false, gfx::RectF()}; |
| 153 const EffectNode* current_effect_node = effect_tree.Node(current_effect_id); |
| 154 ConcatInverseSublayerScale(current_effect_node, ¤t_to_target); |
142 | 155 |
143 if (current_transform_id > target_transform_id) | 156 if (current_transform_id > target_transform_id) |
144 return ConditionalClip{true, // is_clipped. | 157 return ConditionalClip{true, // is_clipped. |
145 MathUtil::MapClippedRect(current_to_target, rect)}; | 158 MathUtil::MapClippedRect(current_to_target, rect)}; |
146 | 159 |
147 return ConditionalClip{true, // is_clipped. | 160 return ConditionalClip{true, // is_clipped. |
148 MathUtil::ProjectClippedRect(current_to_target, rect)}; | 161 MathUtil::ProjectClippedRect(current_to_target, rect)}; |
149 } | 162 } |
150 | 163 |
151 static ConditionalClip ComputeLocalRectInTargetSpace( | 164 static ConditionalClip ComputeLocalRectInTargetSpace( |
152 gfx::RectF rect, | 165 gfx::RectF rect, |
153 const TransformTree& transform_tree, | 166 const TransformTree& transform_tree, |
154 const EffectTree& effect_tree, | 167 const EffectTree& effect_tree, |
155 int current_transform_id, | 168 int current_transform_id, |
156 int target_transform_id, | 169 int target_transform_id, |
157 int target_effect_id) { | 170 int target_effect_id) { |
158 gfx::Transform current_to_target; | 171 gfx::Transform current_to_target; |
159 if (!transform_tree.ComputeTransform(current_transform_id, | 172 if (!transform_tree.ComputeTransform(current_transform_id, |
160 target_transform_id, ¤t_to_target)) | 173 target_transform_id, ¤t_to_target)) |
161 // If transform is not invertible, cannot apply clip. | 174 // If transform is not invertible, cannot apply clip. |
162 return ConditionalClip{false, gfx::RectF()}; | 175 return ConditionalClip{false, gfx::RectF()}; |
163 // We don't have to apply sublayer scale when target is root. | 176 // We don't have to apply sublayer scale when target is root. |
164 if (target_transform_id != 0) { | 177 if (target_transform_id != 0) { |
165 PostConcatSublayerScale(target_effect_id, effect_tree, ¤t_to_target); | 178 const EffectNode* target_effect_node = effect_tree.Node(target_effect_id); |
| 179 PostConcatSublayerScale(target_effect_node, ¤t_to_target); |
166 #if DCHECK_IS_ON() | 180 #if DCHECK_IS_ON() |
167 VerifySublayerScalesMatch(target_effect_id, target_transform_id, | 181 VerifySublayerScalesMatch(target_effect_id, target_transform_id, |
168 effect_tree, transform_tree); | 182 effect_tree, transform_tree); |
169 #endif | 183 #endif |
170 } | 184 } |
171 | 185 |
172 if (current_transform_id > target_transform_id) | 186 if (current_transform_id > target_transform_id) |
173 return ConditionalClip{true, // is_clipped. | 187 return ConditionalClip{true, // is_clipped. |
174 MathUtil::MapClippedRect(current_to_target, rect)}; | 188 MathUtil::MapClippedRect(current_to_target, rect)}; |
175 | 189 |
176 return ConditionalClip{true, // is_clipped. | 190 return ConditionalClip{true, // is_clipped. |
177 MathUtil::ProjectClippedRect(current_to_target, rect)}; | 191 MathUtil::ProjectClippedRect(current_to_target, rect)}; |
178 } | 192 } |
179 | 193 |
180 static ConditionalClip ComputeCurrentClip(const ClipNode* clip_node, | 194 static ConditionalClip ComputeCurrentClip(const ClipNode* clip_node, |
181 const TransformTree& transform_tree, | 195 const TransformTree& transform_tree, |
182 const EffectTree& effect_tree, | 196 const EffectTree& effect_tree, |
183 int target_transform_id, | 197 int target_transform_id, |
184 int target_effect_id) { | 198 int target_effect_id) { |
185 if (clip_node->transform_id != target_transform_id) | 199 if (clip_node->transform_id != target_transform_id) |
186 return ComputeLocalRectInTargetSpace(clip_node->clip, transform_tree, | 200 return ComputeLocalRectInTargetSpace(clip_node->clip, transform_tree, |
187 effect_tree, clip_node->transform_id, | 201 effect_tree, clip_node->transform_id, |
188 target_transform_id, target_effect_id); | 202 target_transform_id, target_effect_id); |
189 | 203 |
190 gfx::RectF current_clip = clip_node->clip; | 204 gfx::RectF current_clip = clip_node->clip; |
191 gfx::Vector2dF sublayer_scale = | 205 gfx::Vector2dF surface_contents_scale = |
192 transform_tree.Node(target_transform_id)->sublayer_scale; | 206 effect_tree.Node(target_effect_id)->surface_contents_scale; |
193 if (sublayer_scale.x() > 0 && sublayer_scale.y() > 0) | 207 if (surface_contents_scale.x() > 0 && surface_contents_scale.y() > 0) |
194 current_clip.Scale(sublayer_scale.x(), sublayer_scale.y()); | 208 current_clip.Scale(surface_contents_scale.x(), surface_contents_scale.y()); |
195 return ConditionalClip{true /* is_clipped */, current_clip}; | 209 return ConditionalClip{true /* is_clipped */, current_clip}; |
196 } | 210 } |
197 | 211 |
198 static ConditionalClip ComputeAccumulatedClip( | 212 static ConditionalClip ComputeAccumulatedClip( |
199 const ClipTree& clip_tree, | 213 const ClipTree& clip_tree, |
200 int local_clip_id, | 214 int local_clip_id, |
201 const EffectTree& effect_tree, | 215 const EffectTree& effect_tree, |
202 int target_id, | 216 int target_id, |
203 const TransformTree& transform_tree) { | 217 const TransformTree& transform_tree) { |
204 const ClipNode* clip_node = clip_tree.Node(local_clip_id); | 218 const ClipNode* clip_node = clip_tree.Node(local_clip_id); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); | 381 layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); |
368 continue; | 382 continue; |
369 } | 383 } |
370 | 384 |
371 gfx::RectF accumulated_clip_in_copy_request_space = | 385 gfx::RectF accumulated_clip_in_copy_request_space = |
372 accumulated_clip_rect.clip_rect; | 386 accumulated_clip_rect.clip_rect; |
373 | 387 |
374 const EffectNode* copy_request_effect_node = | 388 const EffectNode* copy_request_effect_node = |
375 effect_tree.Node(effect_ancestor_with_copy_request); | 389 effect_tree.Node(effect_ancestor_with_copy_request); |
376 ConditionalClip clip_in_layer_space = ComputeTargetRectInLocalSpace( | 390 ConditionalClip clip_in_layer_space = ComputeTargetRectInLocalSpace( |
377 accumulated_clip_in_copy_request_space, transform_tree, | 391 accumulated_clip_in_copy_request_space, transform_tree, effect_tree, |
378 copy_request_effect_node->transform_id, | 392 copy_request_effect_node->transform_id, layer->transform_tree_index(), |
379 layer->transform_tree_index()); | 393 copy_request_effect_node->id); |
380 | 394 |
381 if (clip_in_layer_space.is_clipped) { | 395 if (clip_in_layer_space.is_clipped) { |
382 gfx::RectF clip_rect = clip_in_layer_space.clip_rect; | 396 gfx::RectF clip_rect = clip_in_layer_space.clip_rect; |
383 clip_rect.Offset(-layer->offset_to_transform_parent()); | 397 clip_rect.Offset(-layer->offset_to_transform_parent()); |
384 gfx::Rect visible_rect = gfx::ToEnclosingRect(clip_rect); | 398 gfx::Rect visible_rect = gfx::ToEnclosingRect(clip_rect); |
385 visible_rect.Intersect(gfx::Rect(layer_bounds)); | 399 visible_rect.Intersect(gfx::Rect(layer_bounds)); |
386 layer->set_visible_layer_rect(visible_rect); | 400 layer->set_visible_layer_rect(visible_rect); |
387 } else { | 401 } else { |
388 layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); | 402 layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); |
389 } | 403 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 layer_content_bounds_in_target_space); | 498 layer_content_bounds_in_target_space); |
485 if (combined_clip_rect_in_target_space.IsEmpty()) { | 499 if (combined_clip_rect_in_target_space.IsEmpty()) { |
486 layer->set_visible_layer_rect(gfx::Rect()); | 500 layer->set_visible_layer_rect(gfx::Rect()); |
487 continue; | 501 continue; |
488 } | 502 } |
489 | 503 |
490 gfx::Transform target_to_layer; | 504 gfx::Transform target_to_layer; |
491 if (transform_node->ancestors_are_invertible) { | 505 if (transform_node->ancestors_are_invertible) { |
492 target_to_layer = transform_tree.FromTarget(transform_node->id); | 506 target_to_layer = transform_tree.FromTarget(transform_node->id); |
493 } else { | 507 } else { |
494 if (!transform_tree.ComputeTransformWithSourceSublayerScale( | 508 bool success = transform_tree.ComputeTransform( |
495 target_node_id, transform_node->id, &target_to_layer)) { | 509 target_node_id, transform_node->id, &target_to_layer); |
| 510 if (!success) { |
496 // An animated singular transform may become non-singular during the | 511 // An animated singular transform may become non-singular during the |
497 // animation, so we still need to compute a visible rect. In this | 512 // animation, so we still need to compute a visible rect. In this |
498 // situation, we treat the entire layer as visible. | 513 // situation, we treat the entire layer as visible. |
499 layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); | 514 layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); |
500 continue; | 515 continue; |
501 } | 516 } |
| 517 if (target_node_id != 0) { |
| 518 const EffectNode* target_effect_node = |
| 519 ContentsTargetEffectNode(layer->effect_tree_index(), effect_tree); |
| 520 ConcatInverseSublayerScale(target_effect_node, &target_to_layer); |
| 521 #if DCHECK_IS_ON() |
| 522 VerifySublayerScalesMatch(target_effect_node->id, target_node_id, |
| 523 effect_tree, transform_tree); |
| 524 #endif |
| 525 } |
502 } | 526 } |
503 | |
504 gfx::Transform target_to_content; | 527 gfx::Transform target_to_content; |
505 target_to_content.Translate(-layer->offset_to_transform_parent().x(), | 528 target_to_content.Translate(-layer->offset_to_transform_parent().x(), |
506 -layer->offset_to_transform_parent().y()); | 529 -layer->offset_to_transform_parent().y()); |
507 target_to_content.PreconcatTransform(target_to_layer); | 530 target_to_content.PreconcatTransform(target_to_layer); |
508 | 531 |
509 gfx::Rect visible_rect = gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( | 532 gfx::Rect visible_rect = gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( |
510 target_to_content, combined_clip_rect_in_target_space)); | 533 target_to_content, combined_clip_rect_in_target_space)); |
511 visible_rect.Intersect(gfx::Rect(layer_bounds)); | 534 visible_rect.Intersect(gfx::Rect(layer_bounds)); |
512 layer->set_visible_layer_rect(visible_rect); | 535 layer->set_visible_layer_rect(visible_rect); |
513 } | 536 } |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 } | 716 } |
694 } | 717 } |
695 } | 718 } |
696 | 719 |
697 static void ResetIfHasNanCoordinate(gfx::RectF* rect) { | 720 static void ResetIfHasNanCoordinate(gfx::RectF* rect) { |
698 if (std::isnan(rect->x()) || std::isnan(rect->y()) || | 721 if (std::isnan(rect->x()) || std::isnan(rect->y()) || |
699 std::isnan(rect->right()) || std::isnan(rect->bottom())) | 722 std::isnan(rect->right()) || std::isnan(rect->bottom())) |
700 *rect = gfx::RectF(); | 723 *rect = gfx::RectF(); |
701 } | 724 } |
702 | 725 |
703 void PostConcatSublayerScale(const int effect_node_id, | 726 void PostConcatSublayerScale(const EffectNode* effect_node, |
704 const EffectTree& effect_tree, | |
705 gfx::Transform* transform) { | 727 gfx::Transform* transform) { |
706 // TODO(jaydasika): This function should not compute target effect node id. It | 728 DCHECK(effect_node->has_render_surface); |
707 // should receive it from callers. | 729 transform->matrix().postScale(effect_node->surface_contents_scale.x(), |
708 const EffectNode* effect_node = effect_tree.Node(effect_node_id); | 730 effect_node->surface_contents_scale.y(), 1.f); |
709 const EffectNode* target_effect_node = | |
710 effect_node->has_render_surface | |
711 ? effect_node | |
712 : effect_tree.Node(effect_node->target_id); | |
713 transform->matrix().postScale(target_effect_node->sublayer_scale.x(), | |
714 target_effect_node->sublayer_scale.y(), 1.f); | |
715 } | 731 } |
716 | 732 |
717 void ConcatInverseSublayerScale(const int effect_node_id, | 733 void ConcatInverseSublayerScale(const EffectNode* effect_node, |
718 const EffectTree& effect_tree, | |
719 gfx::Transform* transform) { | 734 gfx::Transform* transform) { |
720 const EffectNode* effect_node = effect_tree.Node(effect_node_id); | 735 DCHECK(effect_node->has_render_surface); |
721 if (effect_node->sublayer_scale.x() != 0.0 && | 736 if (effect_node->surface_contents_scale.x() != 0.0 && |
722 effect_node->sublayer_scale.y() != 0.0) | 737 effect_node->surface_contents_scale.y() != 0.0) |
723 transform->Scale(1.0 / effect_node->sublayer_scale.x(), | 738 transform->Scale(1.0 / effect_node->surface_contents_scale.x(), |
724 1.0 / effect_node->sublayer_scale.y()); | 739 1.0 / effect_node->surface_contents_scale.y()); |
725 } | 740 } |
726 | 741 |
727 void ComputeClips(ClipTree* clip_tree, | 742 void ComputeClips(ClipTree* clip_tree, |
728 const TransformTree& transform_tree, | 743 const TransformTree& transform_tree, |
729 const EffectTree& effect_tree, | 744 const EffectTree& effect_tree, |
730 bool non_root_surfaces_enabled) { | 745 bool non_root_surfaces_enabled) { |
731 if (!clip_tree->needs_update()) | 746 if (!clip_tree->needs_update()) |
732 return; | 747 return; |
733 for (int i = 1; i < static_cast<int>(clip_tree->size()); ++i) { | 748 for (int i = 1; i < static_cast<int>(clip_tree->size()); ++i) { |
734 ClipNode* clip_node = clip_tree->Node(i); | 749 ClipNode* clip_node = clip_tree->Node(i); |
(...skipping 28 matching lines...) Expand all Loading... |
763 gfx::RectF parent_clip_in_target_space = | 778 gfx::RectF parent_clip_in_target_space = |
764 parent_clip_node->clip_in_target_space; | 779 parent_clip_node->clip_in_target_space; |
765 if (parent_target_transform_node && | 780 if (parent_target_transform_node && |
766 parent_target_transform_node->id != clip_node->target_transform_id && | 781 parent_target_transform_node->id != clip_node->target_transform_id && |
767 non_root_surfaces_enabled) { | 782 non_root_surfaces_enabled) { |
768 success &= transform_tree.ComputeTransform( | 783 success &= transform_tree.ComputeTransform( |
769 parent_target_transform_node->id, clip_node->target_transform_id, | 784 parent_target_transform_node->id, clip_node->target_transform_id, |
770 &parent_to_current); | 785 &parent_to_current); |
771 // We don't have to apply sublayer scale when target is root. | 786 // We don't have to apply sublayer scale when target is root. |
772 if (clip_node->target_transform_id != 0) { | 787 if (clip_node->target_transform_id != 0) { |
773 PostConcatSublayerScale(clip_node->target_effect_id, effect_tree, | 788 const EffectNode* target_effect_node = |
774 &parent_to_current); | 789 effect_tree.Node(clip_node->target_effect_id); |
| 790 PostConcatSublayerScale(target_effect_node, &parent_to_current); |
775 #if DCHECK_IS_ON() | 791 #if DCHECK_IS_ON() |
776 VerifySublayerScalesMatch(clip_node->target_effect_id, | 792 VerifySublayerScalesMatch(clip_node->target_effect_id, |
777 clip_node->target_transform_id, effect_tree, | 793 clip_node->target_transform_id, effect_tree, |
778 transform_tree); | 794 transform_tree); |
779 #endif | 795 #endif |
780 } | 796 } |
781 if (parent_target_transform_node->sublayer_scale.x() > 0 && | 797 if (parent_clip_node->target_transform_id != 0) { |
782 parent_target_transform_node->sublayer_scale.y() > 0) | 798 const EffectNode* parent_target_effect_node = |
783 parent_to_current.Scale( | 799 effect_tree.Node(parent_clip_node->target_effect_id); |
784 1.f / parent_target_transform_node->sublayer_scale.x(), | 800 ConcatInverseSublayerScale(parent_target_effect_node, |
785 1.f / parent_target_transform_node->sublayer_scale.y()); | 801 &parent_to_current); |
| 802 #if DCHECK_IS_ON() |
| 803 VerifySublayerScalesMatch(parent_clip_node->target_effect_id, |
| 804 parent_clip_node->target_transform_id, |
| 805 effect_tree, transform_tree); |
| 806 #endif |
| 807 } |
786 // If we can't compute a transform, it's because we had to use the inverse | 808 // If we can't compute a transform, it's because we had to use the inverse |
787 // of a singular transform. We won't draw in this case, so there's no need | 809 // of a singular transform. We won't draw in this case, so there's no need |
788 // to compute clips. | 810 // to compute clips. |
789 if (!success) | 811 if (!success) |
790 continue; | 812 continue; |
791 parent_combined_clip_in_target_space = MathUtil::ProjectClippedRect( | 813 parent_combined_clip_in_target_space = MathUtil::ProjectClippedRect( |
792 parent_to_current, parent_clip_node->combined_clip_in_target_space); | 814 parent_to_current, parent_clip_node->combined_clip_in_target_space); |
793 parent_clip_in_target_space = MathUtil::ProjectClippedRect( | 815 parent_clip_in_target_space = MathUtil::ProjectClippedRect( |
794 parent_to_current, parent_clip_node->clip_in_target_space); | 816 parent_to_current, parent_clip_node->clip_in_target_space); |
795 } | 817 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 source_to_target = transform_tree.ToScreen(clip_node->transform_id); | 859 source_to_target = transform_tree.ToScreen(clip_node->transform_id); |
838 } else if (transform_tree.ContentTargetId(transform_node->id) == | 860 } else if (transform_tree.ContentTargetId(transform_node->id) == |
839 clip_node->target_transform_id) { | 861 clip_node->target_transform_id) { |
840 source_to_target = transform_tree.ToTarget(clip_node->transform_id); | 862 source_to_target = transform_tree.ToTarget(clip_node->transform_id); |
841 } else { | 863 } else { |
842 success = transform_tree.ComputeTransform( | 864 success = transform_tree.ComputeTransform( |
843 transform_node->id, clip_node->target_transform_id, | 865 transform_node->id, clip_node->target_transform_id, |
844 &source_to_target); | 866 &source_to_target); |
845 // We don't have to apply sublayer scale when target is root. | 867 // We don't have to apply sublayer scale when target is root. |
846 if (clip_node->target_transform_id != 0) { | 868 if (clip_node->target_transform_id != 0) { |
847 PostConcatSublayerScale(clip_node->target_effect_id, effect_tree, | 869 const EffectNode* target_effect_node = |
848 &source_to_target); | 870 effect_tree.Node(clip_node->target_effect_id); |
| 871 PostConcatSublayerScale(target_effect_node, &source_to_target); |
849 #if DCHECK_IS_ON() | 872 #if DCHECK_IS_ON() |
850 VerifySublayerScalesMatch(clip_node->target_effect_id, | 873 VerifySublayerScalesMatch(clip_node->target_effect_id, |
851 clip_node->target_transform_id, effect_tree, | 874 clip_node->target_transform_id, effect_tree, |
852 transform_tree); | 875 transform_tree); |
853 #endif | 876 #endif |
854 } | 877 } |
855 // source_to_target computation should be successful as target is an | 878 // source_to_target computation should be successful as target is an |
856 // ancestor of the transform node. | 879 // ancestor of the transform node. |
857 DCHECK(success); | 880 DCHECK(success); |
858 } | 881 } |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
999 static void VerifyDrawTransformsMatch(LayerImpl* layer, | 1022 static void VerifyDrawTransformsMatch(LayerImpl* layer, |
1000 PropertyTrees* property_trees) { | 1023 PropertyTrees* property_trees) { |
1001 const int source_id = layer->transform_tree_index(); | 1024 const int source_id = layer->transform_tree_index(); |
1002 int destination_id = FindTargetTransformTreeIndexFromEffectTree( | 1025 int destination_id = FindTargetTransformTreeIndexFromEffectTree( |
1003 property_trees->effect_tree, layer->effect_tree_index()); | 1026 property_trees->effect_tree, layer->effect_tree_index()); |
1004 gfx::Transform draw_transform; | 1027 gfx::Transform draw_transform; |
1005 property_trees->transform_tree.ComputeTransform(source_id, destination_id, | 1028 property_trees->transform_tree.ComputeTransform(source_id, destination_id, |
1006 &draw_transform); | 1029 &draw_transform); |
1007 // We don't have to apply sublayer scale when target is root. | 1030 // We don't have to apply sublayer scale when target is root. |
1008 if (destination_id != 0) { | 1031 if (destination_id != 0) { |
1009 PostConcatSublayerScale(layer->effect_tree_index(), | 1032 const EffectNode* target_effect_node = ContentsTargetEffectNode( |
1010 property_trees->effect_tree, &draw_transform); | 1033 layer->effect_tree_index(), property_trees->effect_tree); |
| 1034 PostConcatSublayerScale(target_effect_node, &draw_transform); |
1011 #if DCHECK_IS_ON() | 1035 #if DCHECK_IS_ON() |
1012 VerifySublayerScalesMatch(layer->effect_tree_index(), destination_id, | 1036 VerifySublayerScalesMatch(layer->effect_tree_index(), destination_id, |
1013 property_trees->effect_tree, | 1037 property_trees->effect_tree, |
1014 property_trees->transform_tree); | 1038 property_trees->transform_tree); |
1015 #endif | 1039 #endif |
1016 } | 1040 } |
1017 if (layer->should_flatten_transform_from_property_tree()) | 1041 if (layer->should_flatten_transform_from_property_tree()) |
1018 draw_transform.FlattenTo2d(); | 1042 draw_transform.FlattenTo2d(); |
1019 draw_transform.Translate(layer->offset_to_transform_parent().x(), | 1043 draw_transform.Translate(layer->offset_to_transform_parent().x(), |
1020 layer->offset_to_transform_parent().y()); | 1044 layer->offset_to_transform_parent().y()); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1171 if (!owns_non_root_surface) { | 1195 if (!owns_non_root_surface) { |
1172 // If you're not the root, or you don't own a surface, you need to apply | 1196 // If you're not the root, or you don't own a surface, you need to apply |
1173 // your local offset. | 1197 // your local offset. |
1174 xform = tree.ToTarget(layer->transform_tree_index()); | 1198 xform = tree.ToTarget(layer->transform_tree_index()); |
1175 if (layer->should_flatten_transform_from_property_tree()) | 1199 if (layer->should_flatten_transform_from_property_tree()) |
1176 xform.FlattenTo2d(); | 1200 xform.FlattenTo2d(); |
1177 xform.Translate(layer->offset_to_transform_parent().x(), | 1201 xform.Translate(layer->offset_to_transform_parent().x(), |
1178 layer->offset_to_transform_parent().y()); | 1202 layer->offset_to_transform_parent().y()); |
1179 } else { | 1203 } else { |
1180 // Surfaces need to apply their sublayer scale. | 1204 // Surfaces need to apply their sublayer scale. |
1181 xform.Scale(node->sublayer_scale.x(), node->sublayer_scale.y()); | 1205 xform.Scale(node->surface_contents_scale.x(), |
| 1206 node->surface_contents_scale.y()); |
1182 } | 1207 } |
1183 return xform; | 1208 return xform; |
1184 } | 1209 } |
1185 | 1210 |
1186 static void SetSurfaceDrawTransform(const TransformTree& transform_tree, | 1211 static void SetSurfaceDrawTransform(const TransformTree& transform_tree, |
1187 const EffectTree& effect_tree, | 1212 const EffectTree& effect_tree, |
1188 RenderSurfaceImpl* render_surface) { | 1213 RenderSurfaceImpl* render_surface) { |
1189 const TransformNode* transform_node = | 1214 const TransformNode* transform_node = |
1190 transform_tree.Node(render_surface->TransformTreeIndex()); | 1215 transform_tree.Node(render_surface->TransformTreeIndex()); |
1191 const EffectNode* effect_node = | 1216 const EffectNode* effect_node = |
1192 effect_tree.Node(render_surface->EffectTreeIndex()); | 1217 effect_tree.Node(render_surface->EffectTreeIndex()); |
1193 // The draw transform of root render surface is identity tranform. | 1218 // The draw transform of root render surface is identity tranform. |
1194 if (transform_node->id == 1) { | 1219 if (transform_node->id == 1) { |
1195 render_surface->SetDrawTransform(gfx::Transform()); | 1220 render_surface->SetDrawTransform(gfx::Transform()); |
1196 return; | 1221 return; |
1197 } | 1222 } |
1198 | 1223 |
1199 gfx::Transform render_surface_transform; | 1224 gfx::Transform render_surface_transform; |
1200 const TransformNode* target_transform_node = | 1225 const TransformNode* target_transform_node = |
1201 transform_tree.Node(transform_tree.TargetId(transform_node->id)); | 1226 transform_tree.Node(transform_tree.TargetId(transform_node->id)); |
1202 transform_tree.ComputeTransform(transform_node->id, target_transform_node->id, | 1227 transform_tree.ComputeTransform(transform_node->id, target_transform_node->id, |
1203 &render_surface_transform); | 1228 &render_surface_transform); |
1204 // We don't have to apply sublayer scale when target is root. | 1229 // We don't have to apply sublayer scale when target is root. |
1205 if (target_transform_node->id != 0) { | 1230 if (target_transform_node->id != 0) { |
1206 PostConcatSublayerScale(effect_node->target_id, effect_tree, | 1231 const EffectNode* target_effect_node = |
1207 &render_surface_transform); | 1232 effect_tree.Node(effect_node->target_id); |
| 1233 PostConcatSublayerScale(target_effect_node, &render_surface_transform); |
1208 #if DCHECK_IS_ON() | 1234 #if DCHECK_IS_ON() |
1209 VerifySublayerScalesMatch(effect_node->target_id, target_transform_node->id, | 1235 VerifySublayerScalesMatch(effect_node->target_id, target_transform_node->id, |
1210 effect_tree, transform_tree); | 1236 effect_tree, transform_tree); |
1211 #endif | 1237 #endif |
1212 } | 1238 } |
1213 | 1239 |
1214 DCHECK(transform_node->sublayer_scale == effect_node->sublayer_scale); | 1240 ConcatInverseSublayerScale(effect_node, &render_surface_transform); |
1215 if (effect_node->sublayer_scale.x() != 0.0 && | 1241 #if DCHECK_IS_ON() |
1216 effect_node->sublayer_scale.y() != 0.0) | 1242 VerifySublayerScalesMatch(effect_node->id, transform_node->id, effect_tree, |
1217 render_surface_transform.Scale(1.0 / effect_node->sublayer_scale.x(), | 1243 transform_tree); |
1218 1.0 / effect_node->sublayer_scale.y()); | 1244 #endif |
1219 render_surface->SetDrawTransform(render_surface_transform); | 1245 render_surface->SetDrawTransform(render_surface_transform); |
1220 } | 1246 } |
1221 | 1247 |
1222 static void SetSurfaceIsClipped(const ClipNode* clip_node, | 1248 static void SetSurfaceIsClipped(const ClipNode* clip_node, |
1223 RenderSurfaceImpl* render_surface) { | 1249 RenderSurfaceImpl* render_surface) { |
1224 DCHECK(render_surface->OwningLayerId() == clip_node->owner_id) | 1250 DCHECK(render_surface->OwningLayerId() == clip_node->owner_id) |
1225 << "we now create clip node for every render surface"; | 1251 << "we now create clip node for every render surface"; |
1226 | 1252 |
1227 render_surface->SetIsClipped(clip_node->target_is_clipped); | 1253 render_surface->SetIsClipped(clip_node->target_is_clipped); |
1228 } | 1254 } |
(...skipping 25 matching lines...) Expand all Loading... |
1254 transform_tree.TargetId(transform_node->id), | 1280 transform_tree.TargetId(transform_node->id), |
1255 &clip_parent_target_to_target); | 1281 &clip_parent_target_to_target); |
1256 | 1282 |
1257 if (!success) { | 1283 if (!success) { |
1258 render_surface->SetClipRect(gfx::Rect()); | 1284 render_surface->SetClipRect(gfx::Rect()); |
1259 return; | 1285 return; |
1260 } | 1286 } |
1261 | 1287 |
1262 // We don't have to apply sublayer scale when target is root. | 1288 // We don't have to apply sublayer scale when target is root. |
1263 if (transform_tree.TargetId(transform_node->id) != 0) { | 1289 if (transform_tree.TargetId(transform_node->id) != 0) { |
1264 PostConcatSublayerScale(render_surface->EffectTreeIndex(), effect_tree, | 1290 const EffectNode* effect_node = |
1265 &clip_parent_target_to_target); | 1291 effect_tree.Node(render_surface->EffectTreeIndex()); |
| 1292 PostConcatSublayerScale(effect_node, &clip_parent_target_to_target); |
1266 #if DCHECK_IS_ON() | 1293 #if DCHECK_IS_ON() |
1267 VerifySublayerScalesMatch(render_surface->EffectTreeIndex(), | 1294 VerifySublayerScalesMatch(render_surface->EffectTreeIndex(), |
1268 transform_tree.TargetId(transform_node->id), | 1295 transform_tree.TargetId(transform_node->id), |
1269 effect_tree, transform_tree); | 1296 effect_tree, transform_tree); |
1270 #endif | 1297 #endif |
1271 } | 1298 } |
1272 | 1299 |
1273 DCHECK_LT(parent_clip_node->target_transform_id, | 1300 DCHECK_LT(parent_clip_node->target_transform_id, |
1274 transform_tree.TargetId(transform_node->id)); | 1301 transform_tree.TargetId(transform_node->id)); |
1275 render_surface->SetClipRect(gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( | 1302 render_surface->SetClipRect(gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1341 | 1368 |
1342 static gfx::Transform ReplicaToSurfaceTransform( | 1369 static gfx::Transform ReplicaToSurfaceTransform( |
1343 const RenderSurfaceImpl* render_surface, | 1370 const RenderSurfaceImpl* render_surface, |
1344 const TransformTree& tree) { | 1371 const TransformTree& tree) { |
1345 gfx::Transform replica_to_surface; | 1372 gfx::Transform replica_to_surface; |
1346 if (!render_surface->HasReplica()) | 1373 if (!render_surface->HasReplica()) |
1347 return replica_to_surface; | 1374 return replica_to_surface; |
1348 const LayerImpl* replica_layer = render_surface->ReplicaLayer(); | 1375 const LayerImpl* replica_layer = render_surface->ReplicaLayer(); |
1349 const TransformNode* surface_transform_node = | 1376 const TransformNode* surface_transform_node = |
1350 tree.Node(render_surface->TransformTreeIndex()); | 1377 tree.Node(render_surface->TransformTreeIndex()); |
1351 replica_to_surface.Scale(surface_transform_node->sublayer_scale.x(), | 1378 replica_to_surface.Scale(surface_transform_node->surface_contents_scale.x(), |
1352 surface_transform_node->sublayer_scale.y()); | 1379 surface_transform_node->surface_contents_scale.y()); |
1353 replica_to_surface.Translate(replica_layer->offset_to_transform_parent().x(), | 1380 replica_to_surface.Translate(replica_layer->offset_to_transform_parent().x(), |
1354 replica_layer->offset_to_transform_parent().y()); | 1381 replica_layer->offset_to_transform_parent().y()); |
1355 gfx::Transform replica_transform_node_to_surface; | 1382 gfx::Transform replica_transform_node_to_surface; |
1356 tree.ComputeTransform(replica_layer->transform_tree_index(), | 1383 tree.ComputeTransform(replica_layer->transform_tree_index(), |
1357 render_surface->TransformTreeIndex(), | 1384 render_surface->TransformTreeIndex(), |
1358 &replica_transform_node_to_surface); | 1385 &replica_transform_node_to_surface); |
1359 replica_to_surface.PreconcatTransform(replica_transform_node_to_surface); | 1386 replica_to_surface.PreconcatTransform(replica_transform_node_to_surface); |
1360 if (surface_transform_node->sublayer_scale.x() != 0 && | 1387 if (surface_transform_node->surface_contents_scale.x() != 0 && |
1361 surface_transform_node->sublayer_scale.y() != 0) { | 1388 surface_transform_node->surface_contents_scale.y() != 0) { |
1362 replica_to_surface.Scale(1.0 / surface_transform_node->sublayer_scale.x(), | 1389 replica_to_surface.Scale( |
1363 1.0 / surface_transform_node->sublayer_scale.y()); | 1390 1.0 / surface_transform_node->surface_contents_scale.x(), |
| 1391 1.0 / surface_transform_node->surface_contents_scale.y()); |
1364 } | 1392 } |
1365 return replica_to_surface; | 1393 return replica_to_surface; |
1366 } | 1394 } |
1367 | 1395 |
1368 void ComputeLayerDrawProperties(LayerImpl* layer, | 1396 void ComputeLayerDrawProperties(LayerImpl* layer, |
1369 const PropertyTrees* property_trees) { | 1397 const PropertyTrees* property_trees) { |
1370 const TransformNode* transform_node = | 1398 const TransformNode* transform_node = |
1371 property_trees->transform_tree.Node(layer->transform_tree_index()); | 1399 property_trees->transform_tree.Node(layer->transform_tree_index()); |
1372 const ClipNode* clip_node = | 1400 const ClipNode* clip_node = |
1373 property_trees->clip_tree.Node(layer->clip_tree_index()); | 1401 property_trees->clip_tree.Node(layer->clip_tree_index()); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1536 void UpdateElasticOverscroll(PropertyTrees* property_trees, | 1564 void UpdateElasticOverscroll(PropertyTrees* property_trees, |
1537 const Layer* overscroll_elasticity_layer, | 1565 const Layer* overscroll_elasticity_layer, |
1538 const gfx::Vector2dF& elastic_overscroll) { | 1566 const gfx::Vector2dF& elastic_overscroll) { |
1539 UpdateElasticOverscrollInternal(property_trees, overscroll_elasticity_layer, | 1567 UpdateElasticOverscrollInternal(property_trees, overscroll_elasticity_layer, |
1540 elastic_overscroll); | 1568 elastic_overscroll); |
1541 } | 1569 } |
1542 | 1570 |
1543 } // namespace draw_property_utils | 1571 } // namespace draw_property_utils |
1544 | 1572 |
1545 } // namespace cc | 1573 } // namespace cc |
OLD | NEW |