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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 : source_node_id(-1), | 160 : source_node_id(-1), |
161 sorting_context_id(0), | 161 sorting_context_id(0), |
162 needs_local_transform_update(true), | 162 needs_local_transform_update(true), |
163 node_and_ancestors_are_animated_or_invertible(true), | 163 node_and_ancestors_are_animated_or_invertible(true), |
164 is_invertible(true), | 164 is_invertible(true), |
165 ancestors_are_invertible(true), | 165 ancestors_are_invertible(true), |
166 has_potential_animation(false), | 166 has_potential_animation(false), |
167 is_currently_animating(false), | 167 is_currently_animating(false), |
168 to_screen_is_potentially_animated(false), | 168 to_screen_is_potentially_animated(false), |
169 has_only_translation_animations(true), | 169 has_only_translation_animations(true), |
170 to_screen_has_scale_animation(false), | |
171 flattens_inherited_transform(false), | 170 flattens_inherited_transform(false), |
172 node_and_ancestors_are_flat(true), | 171 node_and_ancestors_are_flat(true), |
173 node_and_ancestors_have_only_integer_translation(true), | 172 node_and_ancestors_have_only_integer_translation(true), |
174 scrolls(false), | 173 scrolls(false), |
175 needs_sublayer_scale(false), | 174 needs_sublayer_scale(false), |
176 affected_by_inner_viewport_bounds_delta_x(false), | 175 affected_by_inner_viewport_bounds_delta_x(false), |
177 affected_by_inner_viewport_bounds_delta_y(false), | 176 affected_by_inner_viewport_bounds_delta_y(false), |
178 affected_by_outer_viewport_bounds_delta_x(false), | 177 affected_by_outer_viewport_bounds_delta_x(false), |
179 affected_by_outer_viewport_bounds_delta_y(false), | 178 affected_by_outer_viewport_bounds_delta_y(false), |
180 in_subtree_of_page_scale_layer(false), | 179 in_subtree_of_page_scale_layer(false), |
181 transform_changed(false), | 180 transform_changed(false), |
182 post_local_scale_factor(1.0f), | 181 post_local_scale_factor(1.0f) {} |
183 local_maximum_animation_target_scale(0.f), | |
184 local_starting_animation_scale(0.f), | |
185 combined_maximum_animation_target_scale(0.f), | |
186 combined_starting_animation_scale(0.f) {} | |
187 | 182 |
188 TransformNodeData::TransformNodeData(const TransformNodeData& other) = default; | 183 TransformNodeData::TransformNodeData(const TransformNodeData& other) = default; |
189 | 184 |
190 TransformNodeData::~TransformNodeData() { | 185 TransformNodeData::~TransformNodeData() { |
191 } | 186 } |
192 | 187 |
193 bool TransformNodeData::operator==(const TransformNodeData& other) const { | 188 bool TransformNodeData::operator==(const TransformNodeData& other) const { |
194 return pre_local == other.pre_local && local == other.local && | 189 return pre_local == other.pre_local && local == other.local && |
195 post_local == other.post_local && to_parent == other.to_parent && | 190 post_local == other.post_local && to_parent == other.to_parent && |
196 source_node_id == other.source_node_id && | 191 source_node_id == other.source_node_id && |
197 sorting_context_id == other.sorting_context_id && | 192 sorting_context_id == other.sorting_context_id && |
198 needs_local_transform_update == other.needs_local_transform_update && | 193 needs_local_transform_update == other.needs_local_transform_update && |
199 node_and_ancestors_are_animated_or_invertible == | 194 node_and_ancestors_are_animated_or_invertible == |
200 other.node_and_ancestors_are_animated_or_invertible && | 195 other.node_and_ancestors_are_animated_or_invertible && |
201 is_invertible == other.is_invertible && | 196 is_invertible == other.is_invertible && |
202 ancestors_are_invertible == other.ancestors_are_invertible && | 197 ancestors_are_invertible == other.ancestors_are_invertible && |
203 has_potential_animation == other.has_potential_animation && | 198 has_potential_animation == other.has_potential_animation && |
204 is_currently_animating == other.is_currently_animating && | 199 is_currently_animating == other.is_currently_animating && |
205 to_screen_is_potentially_animated == | 200 to_screen_is_potentially_animated == |
206 other.to_screen_is_potentially_animated && | 201 other.to_screen_is_potentially_animated && |
207 has_only_translation_animations == | 202 has_only_translation_animations == |
208 other.has_only_translation_animations && | 203 other.has_only_translation_animations && |
209 to_screen_has_scale_animation == other.to_screen_has_scale_animation && | |
210 flattens_inherited_transform == other.flattens_inherited_transform && | 204 flattens_inherited_transform == other.flattens_inherited_transform && |
211 node_and_ancestors_are_flat == other.node_and_ancestors_are_flat && | 205 node_and_ancestors_are_flat == other.node_and_ancestors_are_flat && |
212 node_and_ancestors_have_only_integer_translation == | 206 node_and_ancestors_have_only_integer_translation == |
213 other.node_and_ancestors_have_only_integer_translation && | 207 other.node_and_ancestors_have_only_integer_translation && |
214 scrolls == other.scrolls && | 208 scrolls == other.scrolls && |
215 needs_sublayer_scale == other.needs_sublayer_scale && | 209 needs_sublayer_scale == other.needs_sublayer_scale && |
216 affected_by_inner_viewport_bounds_delta_x == | 210 affected_by_inner_viewport_bounds_delta_x == |
217 other.affected_by_inner_viewport_bounds_delta_x && | 211 other.affected_by_inner_viewport_bounds_delta_x && |
218 affected_by_inner_viewport_bounds_delta_y == | 212 affected_by_inner_viewport_bounds_delta_y == |
219 other.affected_by_inner_viewport_bounds_delta_y && | 213 other.affected_by_inner_viewport_bounds_delta_y && |
220 affected_by_outer_viewport_bounds_delta_x == | 214 affected_by_outer_viewport_bounds_delta_x == |
221 other.affected_by_outer_viewport_bounds_delta_x && | 215 other.affected_by_outer_viewport_bounds_delta_x && |
222 affected_by_outer_viewport_bounds_delta_y == | 216 affected_by_outer_viewport_bounds_delta_y == |
223 other.affected_by_outer_viewport_bounds_delta_y && | 217 other.affected_by_outer_viewport_bounds_delta_y && |
224 in_subtree_of_page_scale_layer == | 218 in_subtree_of_page_scale_layer == |
225 other.in_subtree_of_page_scale_layer && | 219 other.in_subtree_of_page_scale_layer && |
226 transform_changed == other.transform_changed && | 220 transform_changed == other.transform_changed && |
227 post_local_scale_factor == other.post_local_scale_factor && | 221 post_local_scale_factor == other.post_local_scale_factor && |
228 local_maximum_animation_target_scale == | |
229 other.local_maximum_animation_target_scale && | |
230 local_starting_animation_scale == | |
231 other.local_starting_animation_scale && | |
232 combined_maximum_animation_target_scale == | |
233 other.combined_maximum_animation_target_scale && | |
234 combined_starting_animation_scale == | |
235 other.combined_starting_animation_scale && | |
236 sublayer_scale == other.sublayer_scale && | 222 sublayer_scale == other.sublayer_scale && |
237 scroll_offset == other.scroll_offset && | 223 scroll_offset == other.scroll_offset && |
238 scroll_snap == other.scroll_snap && | 224 scroll_snap == other.scroll_snap && |
239 source_offset == other.source_offset && | 225 source_offset == other.source_offset && |
240 source_to_parent == other.source_to_parent; | 226 source_to_parent == other.source_to_parent; |
241 } | 227 } |
242 | 228 |
243 void TransformNodeData::update_pre_local_transform( | 229 void TransformNodeData::update_pre_local_transform( |
244 const gfx::Point3F& transform_origin) { | 230 const gfx::Point3F& transform_origin) { |
245 pre_local.MakeIdentity(); | 231 pre_local.MakeIdentity(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 node_and_ancestors_are_animated_or_invertible); | 263 node_and_ancestors_are_animated_or_invertible); |
278 | 264 |
279 data->set_is_invertible(is_invertible); | 265 data->set_is_invertible(is_invertible); |
280 data->set_ancestors_are_invertible(ancestors_are_invertible); | 266 data->set_ancestors_are_invertible(ancestors_are_invertible); |
281 | 267 |
282 data->set_has_potential_animation(has_potential_animation); | 268 data->set_has_potential_animation(has_potential_animation); |
283 data->set_is_currently_animating(is_currently_animating); | 269 data->set_is_currently_animating(is_currently_animating); |
284 data->set_to_screen_is_potentially_animated( | 270 data->set_to_screen_is_potentially_animated( |
285 to_screen_is_potentially_animated); | 271 to_screen_is_potentially_animated); |
286 data->set_has_only_translation_animations(has_only_translation_animations); | 272 data->set_has_only_translation_animations(has_only_translation_animations); |
287 data->set_to_screen_has_scale_animation(to_screen_has_scale_animation); | |
288 | 273 |
289 data->set_flattens_inherited_transform(flattens_inherited_transform); | 274 data->set_flattens_inherited_transform(flattens_inherited_transform); |
290 data->set_node_and_ancestors_are_flat(node_and_ancestors_are_flat); | 275 data->set_node_and_ancestors_are_flat(node_and_ancestors_are_flat); |
291 | 276 |
292 data->set_node_and_ancestors_have_only_integer_translation( | 277 data->set_node_and_ancestors_have_only_integer_translation( |
293 node_and_ancestors_have_only_integer_translation); | 278 node_and_ancestors_have_only_integer_translation); |
294 data->set_scrolls(scrolls); | 279 data->set_scrolls(scrolls); |
295 data->set_needs_sublayer_scale(needs_sublayer_scale); | 280 data->set_needs_sublayer_scale(needs_sublayer_scale); |
296 | 281 |
297 data->set_affected_by_inner_viewport_bounds_delta_x( | 282 data->set_affected_by_inner_viewport_bounds_delta_x( |
298 affected_by_inner_viewport_bounds_delta_x); | 283 affected_by_inner_viewport_bounds_delta_x); |
299 data->set_affected_by_inner_viewport_bounds_delta_y( | 284 data->set_affected_by_inner_viewport_bounds_delta_y( |
300 affected_by_inner_viewport_bounds_delta_y); | 285 affected_by_inner_viewport_bounds_delta_y); |
301 data->set_affected_by_outer_viewport_bounds_delta_x( | 286 data->set_affected_by_outer_viewport_bounds_delta_x( |
302 affected_by_outer_viewport_bounds_delta_x); | 287 affected_by_outer_viewport_bounds_delta_x); |
303 data->set_affected_by_outer_viewport_bounds_delta_y( | 288 data->set_affected_by_outer_viewport_bounds_delta_y( |
304 affected_by_outer_viewport_bounds_delta_y); | 289 affected_by_outer_viewport_bounds_delta_y); |
305 | 290 |
306 data->set_in_subtree_of_page_scale_layer(in_subtree_of_page_scale_layer); | 291 data->set_in_subtree_of_page_scale_layer(in_subtree_of_page_scale_layer); |
307 data->set_transform_changed(transform_changed); | 292 data->set_transform_changed(transform_changed); |
308 data->set_post_local_scale_factor(post_local_scale_factor); | 293 data->set_post_local_scale_factor(post_local_scale_factor); |
309 data->set_local_maximum_animation_target_scale( | |
310 local_maximum_animation_target_scale); | |
311 data->set_local_starting_animation_scale(local_starting_animation_scale); | |
312 data->set_combined_maximum_animation_target_scale( | |
313 combined_maximum_animation_target_scale); | |
314 data->set_combined_starting_animation_scale( | |
315 combined_starting_animation_scale); | |
316 | 294 |
317 Vector2dFToProto(sublayer_scale, data->mutable_sublayer_scale()); | 295 Vector2dFToProto(sublayer_scale, data->mutable_sublayer_scale()); |
318 ScrollOffsetToProto(scroll_offset, data->mutable_scroll_offset()); | 296 ScrollOffsetToProto(scroll_offset, data->mutable_scroll_offset()); |
319 Vector2dFToProto(scroll_snap, data->mutable_scroll_snap()); | 297 Vector2dFToProto(scroll_snap, data->mutable_scroll_snap()); |
320 Vector2dFToProto(source_offset, data->mutable_source_offset()); | 298 Vector2dFToProto(source_offset, data->mutable_source_offset()); |
321 Vector2dFToProto(source_to_parent, data->mutable_source_to_parent()); | 299 Vector2dFToProto(source_to_parent, data->mutable_source_to_parent()); |
322 } | 300 } |
323 | 301 |
324 void TransformNodeData::FromProtobuf(const proto::TreeNode& proto) { | 302 void TransformNodeData::FromProtobuf(const proto::TreeNode& proto) { |
325 DCHECK(proto.has_transform_node_data()); | 303 DCHECK(proto.has_transform_node_data()); |
(...skipping 13 matching lines...) Expand all Loading... |
339 node_and_ancestors_are_animated_or_invertible = | 317 node_and_ancestors_are_animated_or_invertible = |
340 data.node_and_ancestors_are_animated_or_invertible(); | 318 data.node_and_ancestors_are_animated_or_invertible(); |
341 | 319 |
342 is_invertible = data.is_invertible(); | 320 is_invertible = data.is_invertible(); |
343 ancestors_are_invertible = data.ancestors_are_invertible(); | 321 ancestors_are_invertible = data.ancestors_are_invertible(); |
344 | 322 |
345 has_potential_animation = data.has_potential_animation(); | 323 has_potential_animation = data.has_potential_animation(); |
346 is_currently_animating = data.is_currently_animating(); | 324 is_currently_animating = data.is_currently_animating(); |
347 to_screen_is_potentially_animated = data.to_screen_is_potentially_animated(); | 325 to_screen_is_potentially_animated = data.to_screen_is_potentially_animated(); |
348 has_only_translation_animations = data.has_only_translation_animations(); | 326 has_only_translation_animations = data.has_only_translation_animations(); |
349 to_screen_has_scale_animation = data.to_screen_has_scale_animation(); | |
350 | 327 |
351 flattens_inherited_transform = data.flattens_inherited_transform(); | 328 flattens_inherited_transform = data.flattens_inherited_transform(); |
352 node_and_ancestors_are_flat = data.node_and_ancestors_are_flat(); | 329 node_and_ancestors_are_flat = data.node_and_ancestors_are_flat(); |
353 | 330 |
354 node_and_ancestors_have_only_integer_translation = | 331 node_and_ancestors_have_only_integer_translation = |
355 data.node_and_ancestors_have_only_integer_translation(); | 332 data.node_and_ancestors_have_only_integer_translation(); |
356 scrolls = data.scrolls(); | 333 scrolls = data.scrolls(); |
357 needs_sublayer_scale = data.needs_sublayer_scale(); | 334 needs_sublayer_scale = data.needs_sublayer_scale(); |
358 | 335 |
359 affected_by_inner_viewport_bounds_delta_x = | 336 affected_by_inner_viewport_bounds_delta_x = |
360 data.affected_by_inner_viewport_bounds_delta_x(); | 337 data.affected_by_inner_viewport_bounds_delta_x(); |
361 affected_by_inner_viewport_bounds_delta_y = | 338 affected_by_inner_viewport_bounds_delta_y = |
362 data.affected_by_inner_viewport_bounds_delta_y(); | 339 data.affected_by_inner_viewport_bounds_delta_y(); |
363 affected_by_outer_viewport_bounds_delta_x = | 340 affected_by_outer_viewport_bounds_delta_x = |
364 data.affected_by_outer_viewport_bounds_delta_x(); | 341 data.affected_by_outer_viewport_bounds_delta_x(); |
365 affected_by_outer_viewport_bounds_delta_y = | 342 affected_by_outer_viewport_bounds_delta_y = |
366 data.affected_by_outer_viewport_bounds_delta_y(); | 343 data.affected_by_outer_viewport_bounds_delta_y(); |
367 | 344 |
368 in_subtree_of_page_scale_layer = data.in_subtree_of_page_scale_layer(); | 345 in_subtree_of_page_scale_layer = data.in_subtree_of_page_scale_layer(); |
369 transform_changed = data.transform_changed(); | 346 transform_changed = data.transform_changed(); |
370 post_local_scale_factor = data.post_local_scale_factor(); | 347 post_local_scale_factor = data.post_local_scale_factor(); |
371 local_maximum_animation_target_scale = | |
372 data.local_maximum_animation_target_scale(); | |
373 local_starting_animation_scale = data.local_starting_animation_scale(); | |
374 combined_maximum_animation_target_scale = | |
375 data.combined_maximum_animation_target_scale(); | |
376 combined_starting_animation_scale = data.combined_starting_animation_scale(); | |
377 | 348 |
378 sublayer_scale = ProtoToVector2dF(data.sublayer_scale()); | 349 sublayer_scale = ProtoToVector2dF(data.sublayer_scale()); |
379 scroll_offset = ProtoToScrollOffset(data.scroll_offset()); | 350 scroll_offset = ProtoToScrollOffset(data.scroll_offset()); |
380 scroll_snap = ProtoToVector2dF(data.scroll_snap()); | 351 scroll_snap = ProtoToVector2dF(data.scroll_snap()); |
381 source_offset = ProtoToVector2dF(data.source_offset()); | 352 source_offset = ProtoToVector2dF(data.source_offset()); |
382 source_to_parent = ProtoToVector2dF(data.source_to_parent()); | 353 source_to_parent = ProtoToVector2dF(data.source_to_parent()); |
383 } | 354 } |
384 | 355 |
385 void TransformNodeData::AsValueInto( | 356 void TransformNodeData::AsValueInto( |
386 base::trace_event::TracedValue* value) const { | 357 base::trace_event::TracedValue* value) const { |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 TransformNode* node = Node(id); | 774 TransformNode* node = Node(id); |
804 node->data.transform_changed = false; | 775 node->data.transform_changed = false; |
805 } | 776 } |
806 } | 777 } |
807 | 778 |
808 void TransformTree::UpdateTransforms(int id) { | 779 void TransformTree::UpdateTransforms(int id) { |
809 TransformNode* node = Node(id); | 780 TransformNode* node = Node(id); |
810 TransformNode* parent_node = parent(node); | 781 TransformNode* parent_node = parent(node); |
811 TransformNode* target_node = Node(TargetId(id)); | 782 TransformNode* target_node = Node(TargetId(id)); |
812 TransformNode* source_node = Node(node->data.source_node_id); | 783 TransformNode* source_node = Node(node->data.source_node_id); |
| 784 property_trees()->UpdateCachedNumber(); |
813 if (node->data.needs_local_transform_update || | 785 if (node->data.needs_local_transform_update || |
814 NeedsSourceToParentUpdate(node)) | 786 NeedsSourceToParentUpdate(node)) |
815 UpdateLocalTransform(node); | 787 UpdateLocalTransform(node); |
816 else | 788 else |
817 UndoSnapping(node); | 789 UndoSnapping(node); |
818 UpdateScreenSpaceTransform(node, parent_node, target_node); | 790 UpdateScreenSpaceTransform(node, parent_node, target_node); |
819 UpdateSublayerScale(node); | 791 UpdateSublayerScale(node); |
820 UpdateTargetSpaceTransform(node, target_node); | 792 UpdateTargetSpaceTransform(node, target_node); |
821 UpdateAnimationProperties(node, parent_node); | 793 UpdateAnimationProperties(node, parent_node); |
822 UpdateSnapping(node); | 794 UpdateSnapping(node); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1052 gfx::Transform from_target; | 1024 gfx::Transform from_target; |
1053 if (!target_space_transform.GetInverse(&from_target)) | 1025 if (!target_space_transform.GetInverse(&from_target)) |
1054 node->data.ancestors_are_invertible = false; | 1026 node->data.ancestors_are_invertible = false; |
1055 SetToTarget(node->id, target_space_transform); | 1027 SetToTarget(node->id, target_space_transform); |
1056 SetFromTarget(node->id, from_target); | 1028 SetFromTarget(node->id, from_target); |
1057 } | 1029 } |
1058 | 1030 |
1059 void TransformTree::UpdateAnimationProperties(TransformNode* node, | 1031 void TransformTree::UpdateAnimationProperties(TransformNode* node, |
1060 TransformNode* parent_node) { | 1032 TransformNode* parent_node) { |
1061 bool ancestor_is_animating = false; | 1033 bool ancestor_is_animating = false; |
1062 bool ancestor_is_animating_scale = false; | 1034 if (parent_node) |
1063 float ancestor_maximum_target_scale = 0.f; | |
1064 float ancestor_starting_animation_scale = 0.f; | |
1065 if (parent_node) { | |
1066 ancestor_is_animating = parent_node->data.to_screen_is_potentially_animated; | 1035 ancestor_is_animating = parent_node->data.to_screen_is_potentially_animated; |
1067 ancestor_is_animating_scale = | |
1068 parent_node->data.to_screen_has_scale_animation; | |
1069 ancestor_maximum_target_scale = | |
1070 parent_node->data.combined_maximum_animation_target_scale; | |
1071 ancestor_starting_animation_scale = | |
1072 parent_node->data.combined_starting_animation_scale; | |
1073 } | |
1074 node->data.to_screen_is_potentially_animated = | 1036 node->data.to_screen_is_potentially_animated = |
1075 node->data.has_potential_animation || ancestor_is_animating; | 1037 node->data.has_potential_animation || ancestor_is_animating; |
1076 node->data.to_screen_has_scale_animation = | |
1077 !node->data.has_only_translation_animations || | |
1078 ancestor_is_animating_scale; | |
1079 | |
1080 // Once we've failed to compute a maximum animated scale at an ancestor, we | |
1081 // continue to fail. | |
1082 bool failed_at_ancestor = | |
1083 ancestor_is_animating_scale && ancestor_maximum_target_scale == 0.f; | |
1084 | |
1085 // Computing maximum animated scale in the presence of non-scale/translation | |
1086 // transforms isn't supported. | |
1087 bool failed_for_non_scale_or_translation = | |
1088 !ToTarget(node->id).IsScaleOrTranslation(); | |
1089 | |
1090 // We don't attempt to accumulate animation scale from multiple nodes with | |
1091 // scale animations, because of the risk of significant overestimation. For | |
1092 // example, one node might be increasing scale from 1 to 10 at the same time | |
1093 // as another node is decreasing scale from 10 to 1. Naively combining these | |
1094 // scales would produce a scale of 100. | |
1095 bool failed_for_multiple_scale_animations = | |
1096 ancestor_is_animating_scale && | |
1097 !node->data.has_only_translation_animations; | |
1098 | |
1099 if (failed_at_ancestor || failed_for_non_scale_or_translation || | |
1100 failed_for_multiple_scale_animations) { | |
1101 node->data.combined_maximum_animation_target_scale = 0.f; | |
1102 node->data.combined_starting_animation_scale = 0.f; | |
1103 | |
1104 // This ensures that descendants know we've failed to compute a maximum | |
1105 // animated scale. | |
1106 node->data.to_screen_has_scale_animation = true; | |
1107 return; | |
1108 } | |
1109 | |
1110 if (!node->data.to_screen_has_scale_animation) { | |
1111 node->data.combined_maximum_animation_target_scale = 0.f; | |
1112 node->data.combined_starting_animation_scale = 0.f; | |
1113 return; | |
1114 } | |
1115 | |
1116 // At this point, we know exactly one of this node or an ancestor is animating | |
1117 // scale. | |
1118 if (node->data.has_only_translation_animations) { | |
1119 // An ancestor is animating scale. | |
1120 gfx::Vector2dF local_scales = | |
1121 MathUtil::ComputeTransform2dScaleComponents(node->data.local, 0.f); | |
1122 float max_local_scale = std::max(local_scales.x(), local_scales.y()); | |
1123 node->data.combined_maximum_animation_target_scale = | |
1124 max_local_scale * ancestor_maximum_target_scale; | |
1125 node->data.combined_starting_animation_scale = | |
1126 max_local_scale * ancestor_starting_animation_scale; | |
1127 return; | |
1128 } | |
1129 | |
1130 if (node->data.local_starting_animation_scale == 0.f || | |
1131 node->data.local_maximum_animation_target_scale == 0.f) { | |
1132 node->data.combined_maximum_animation_target_scale = 0.f; | |
1133 node->data.combined_starting_animation_scale = 0.f; | |
1134 return; | |
1135 } | |
1136 | |
1137 gfx::Vector2dF ancestor_scales = | |
1138 parent_node ? MathUtil::ComputeTransform2dScaleComponents( | |
1139 ToTarget(parent_node->id), 0.f) | |
1140 : gfx::Vector2dF(1.f, 1.f); | |
1141 float max_ancestor_scale = std::max(ancestor_scales.x(), ancestor_scales.y()); | |
1142 node->data.combined_maximum_animation_target_scale = | |
1143 max_ancestor_scale * node->data.local_maximum_animation_target_scale; | |
1144 node->data.combined_starting_animation_scale = | |
1145 max_ancestor_scale * node->data.local_starting_animation_scale; | |
1146 } | 1038 } |
1147 | 1039 |
1148 void TransformTree::UndoSnapping(TransformNode* node) { | 1040 void TransformTree::UndoSnapping(TransformNode* node) { |
1149 // to_parent transform has the scroll snap from previous frame baked in. | 1041 // to_parent transform has the scroll snap from previous frame baked in. |
1150 // We need to undo it and use the un-snapped transform to compute current | 1042 // We need to undo it and use the un-snapped transform to compute current |
1151 // target and screen space transforms. | 1043 // target and screen space transforms. |
1152 node->data.to_parent.Translate(-node->data.scroll_snap.x(), | 1044 node->data.to_parent.Translate(-node->data.scroll_snap.x(), |
1153 -node->data.scroll_snap.y()); | 1045 -node->data.scroll_snap.y()); |
1154 } | 1046 } |
1155 | 1047 |
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2142 } | 2034 } |
2143 | 2035 |
2144 gfx::ScrollOffset ScrollTree::ClampScrollOffsetToLimits( | 2036 gfx::ScrollOffset ScrollTree::ClampScrollOffsetToLimits( |
2145 gfx::ScrollOffset offset, | 2037 gfx::ScrollOffset offset, |
2146 ScrollNode* scroll_node) const { | 2038 ScrollNode* scroll_node) const { |
2147 offset.SetToMin(MaxScrollOffset(scroll_node->id)); | 2039 offset.SetToMin(MaxScrollOffset(scroll_node->id)); |
2148 offset.SetToMax(gfx::ScrollOffset()); | 2040 offset.SetToMax(gfx::ScrollOffset()); |
2149 return offset; | 2041 return offset; |
2150 } | 2042 } |
2151 | 2043 |
| 2044 PropertyTreesCachedData::PropertyTreesCachedData() |
| 2045 : property_tree_update_number(0) { |
| 2046 animation_scales.clear(); |
| 2047 } |
| 2048 |
| 2049 PropertyTreesCachedData::~PropertyTreesCachedData() {} |
| 2050 |
2152 PropertyTrees::PropertyTrees() | 2051 PropertyTrees::PropertyTrees() |
2153 : needs_rebuild(true), | 2052 : needs_rebuild(true), |
2154 non_root_surfaces_enabled(true), | 2053 non_root_surfaces_enabled(true), |
2155 changed(false), | 2054 changed(false), |
2156 full_tree_damaged(false), | 2055 full_tree_damaged(false), |
2157 sequence_number(0), | 2056 sequence_number(0), |
2158 is_main_thread(true), | 2057 is_main_thread(true), |
2159 is_active(false) { | 2058 is_active(false) { |
2160 transform_tree.SetPropertyTrees(this); | 2059 transform_tree.SetPropertyTrees(this); |
2161 effect_tree.SetPropertyTrees(this); | 2060 effect_tree.SetPropertyTrees(this); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2204 inner_viewport_container_bounds_delta_ = | 2103 inner_viewport_container_bounds_delta_ = |
2205 from.inner_viewport_container_bounds_delta(); | 2104 from.inner_viewport_container_bounds_delta(); |
2206 outer_viewport_container_bounds_delta_ = | 2105 outer_viewport_container_bounds_delta_ = |
2207 from.outer_viewport_container_bounds_delta(); | 2106 from.outer_viewport_container_bounds_delta(); |
2208 inner_viewport_scroll_bounds_delta_ = | 2107 inner_viewport_scroll_bounds_delta_ = |
2209 from.inner_viewport_scroll_bounds_delta(); | 2108 from.inner_viewport_scroll_bounds_delta(); |
2210 transform_tree.SetPropertyTrees(this); | 2109 transform_tree.SetPropertyTrees(this); |
2211 effect_tree.SetPropertyTrees(this); | 2110 effect_tree.SetPropertyTrees(this); |
2212 clip_tree.SetPropertyTrees(this); | 2111 clip_tree.SetPropertyTrees(this); |
2213 scroll_tree.SetPropertyTrees(this); | 2112 scroll_tree.SetPropertyTrees(this); |
| 2113 ResetCachedData(); |
2214 return *this; | 2114 return *this; |
2215 } | 2115 } |
2216 | 2116 |
2217 void PropertyTrees::ToProtobuf(proto::PropertyTrees* proto) const { | 2117 void PropertyTrees::ToProtobuf(proto::PropertyTrees* proto) const { |
2218 // TODO(khushalsagar): Add support for sending diffs when serializaing | 2118 // TODO(khushalsagar): Add support for sending diffs when serializaing |
2219 // property trees. See crbug/555370. | 2119 // property trees. See crbug/555370. |
2220 transform_tree.ToProtobuf(proto->mutable_transform_tree()); | 2120 transform_tree.ToProtobuf(proto->mutable_transform_tree()); |
2221 effect_tree.ToProtobuf(proto->mutable_effect_tree()); | 2121 effect_tree.ToProtobuf(proto->mutable_effect_tree()); |
2222 clip_tree.ToProtobuf(proto->mutable_clip_tree()); | 2122 clip_tree.ToProtobuf(proto->mutable_clip_tree()); |
2223 scroll_tree.ToProtobuf(proto->mutable_scroll_tree()); | 2123 scroll_tree.ToProtobuf(proto->mutable_scroll_tree()); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2386 clip_tree.AsValueInto(value.get()); | 2286 clip_tree.AsValueInto(value.get()); |
2387 value->EndDictionary(); | 2287 value->EndDictionary(); |
2388 | 2288 |
2389 value->BeginDictionary("scroll_tree"); | 2289 value->BeginDictionary("scroll_tree"); |
2390 scroll_tree.AsValueInto(value.get()); | 2290 scroll_tree.AsValueInto(value.get()); |
2391 value->EndDictionary(); | 2291 value->EndDictionary(); |
2392 | 2292 |
2393 return value; | 2293 return value; |
2394 } | 2294 } |
2395 | 2295 |
| 2296 CombinedAnimationScale PropertyTrees::GetAnimationScales( |
| 2297 int transform_node_id, |
| 2298 LayerTreeImpl* layer_tree_impl) { |
| 2299 if (cached_data_.animation_scales[transform_node_id].update_number != |
| 2300 cached_data_.property_tree_update_number) { |
| 2301 if (!layer_tree_impl->settings() |
| 2302 .layer_transforms_should_scale_layer_contents) { |
| 2303 cached_data_.animation_scales[transform_node_id].update_number = |
| 2304 cached_data_.property_tree_update_number; |
| 2305 cached_data_.animation_scales[transform_node_id] |
| 2306 .combined_maximum_animation_target_scale = 0.f; |
| 2307 cached_data_.animation_scales[transform_node_id] |
| 2308 .combined_starting_animation_scale = 0.f; |
| 2309 return CombinedAnimationScale( |
| 2310 cached_data_.animation_scales[transform_node_id] |
| 2311 .combined_maximum_animation_target_scale, |
| 2312 cached_data_.animation_scales[transform_node_id] |
| 2313 .combined_starting_animation_scale); |
| 2314 } |
| 2315 |
| 2316 TransformNode* node = transform_tree.Node(transform_node_id); |
| 2317 TransformNode* parent_node = transform_tree.parent(node); |
| 2318 bool ancestor_is_animating_scale = false; |
| 2319 float ancestor_maximum_target_scale = 0.f; |
| 2320 float ancestor_starting_animation_scale = 0.f; |
| 2321 if (parent_node) { |
| 2322 CombinedAnimationScale combined_animation_scale = |
| 2323 GetAnimationScales(parent_node->id, layer_tree_impl); |
| 2324 ancestor_maximum_target_scale = |
| 2325 combined_animation_scale.maximum_animation_scale; |
| 2326 ancestor_starting_animation_scale = |
| 2327 combined_animation_scale.starting_animation_scale; |
| 2328 ancestor_is_animating_scale = |
| 2329 cached_data_.animation_scales[parent_node->id] |
| 2330 .to_screen_has_scale_animation; |
| 2331 } |
| 2332 |
| 2333 cached_data_.animation_scales[transform_node_id] |
| 2334 .to_screen_has_scale_animation = |
| 2335 !node->data.has_only_translation_animations || |
| 2336 ancestor_is_animating_scale; |
| 2337 |
| 2338 // Once we've failed to compute a maximum animated scale at an ancestor, we |
| 2339 // continue to fail. |
| 2340 bool failed_at_ancestor = |
| 2341 ancestor_is_animating_scale && ancestor_maximum_target_scale == 0.f; |
| 2342 |
| 2343 // Computing maximum animated scale in the presence of non-scale/translation |
| 2344 // transforms isn't supported. |
| 2345 bool failed_for_non_scale_or_translation = |
| 2346 !transform_tree.ToTarget(transform_node_id).IsScaleOrTranslation(); |
| 2347 |
| 2348 // We don't attempt to accumulate animation scale from multiple nodes with |
| 2349 // scale animations, because of the risk of significant overestimation. For |
| 2350 // example, one node might be increasing scale from 1 to 10 at the same time |
| 2351 // as another node is decreasing scale from 10 to 1. Naively combining these |
| 2352 // scales would produce a scale of 100. |
| 2353 bool failed_for_multiple_scale_animations = |
| 2354 ancestor_is_animating_scale && |
| 2355 !node->data.has_only_translation_animations; |
| 2356 |
| 2357 if (failed_at_ancestor || failed_for_non_scale_or_translation || |
| 2358 failed_for_multiple_scale_animations) { |
| 2359 // This ensures that descendants know we've failed to compute a maximum |
| 2360 // animated scale. |
| 2361 cached_data_.animation_scales[transform_node_id] |
| 2362 .to_screen_has_scale_animation = true; |
| 2363 |
| 2364 cached_data_.animation_scales[transform_node_id] |
| 2365 .combined_maximum_animation_target_scale = 0.f; |
| 2366 cached_data_.animation_scales[transform_node_id] |
| 2367 .combined_starting_animation_scale = 0.f; |
| 2368 } else if (!cached_data_.animation_scales[transform_node_id] |
| 2369 .to_screen_has_scale_animation) { |
| 2370 cached_data_.animation_scales[transform_node_id] |
| 2371 .combined_maximum_animation_target_scale = 0.f; |
| 2372 cached_data_.animation_scales[transform_node_id] |
| 2373 .combined_starting_animation_scale = 0.f; |
| 2374 } else if (node->data.has_only_translation_animations) { |
| 2375 // An ancestor is animating scale. |
| 2376 gfx::Vector2dF local_scales = |
| 2377 MathUtil::ComputeTransform2dScaleComponents(node->data.local, 0.f); |
| 2378 float max_local_scale = std::max(local_scales.x(), local_scales.y()); |
| 2379 cached_data_.animation_scales[transform_node_id] |
| 2380 .combined_maximum_animation_target_scale = |
| 2381 max_local_scale * ancestor_maximum_target_scale; |
| 2382 cached_data_.animation_scales[transform_node_id] |
| 2383 .combined_starting_animation_scale = |
| 2384 max_local_scale * ancestor_starting_animation_scale; |
| 2385 } else { |
| 2386 // TODO(sunxd): make LayerTreeImpl::MaximumTargetScale take layer id as |
| 2387 // parameter. |
| 2388 LayerImpl* layer_impl = layer_tree_impl->LayerById(node->owner_id); |
| 2389 layer_tree_impl->MaximumTargetScale( |
| 2390 layer_impl, &cached_data_.animation_scales[transform_node_id] |
| 2391 .local_maximum_animation_target_scale); |
| 2392 layer_tree_impl->AnimationStartScale( |
| 2393 layer_impl, &cached_data_.animation_scales[transform_node_id] |
| 2394 .local_starting_animation_scale); |
| 2395 gfx::Vector2dF local_scales = |
| 2396 MathUtil::ComputeTransform2dScaleComponents(node->data.local, 0.f); |
| 2397 float max_local_scale = std::max(local_scales.x(), local_scales.y()); |
| 2398 |
| 2399 if (cached_data_.animation_scales[transform_node_id] |
| 2400 .local_starting_animation_scale == 0.f || |
| 2401 cached_data_.animation_scales[transform_node_id] |
| 2402 .local_maximum_animation_target_scale == 0.f) { |
| 2403 cached_data_.animation_scales[transform_node_id] |
| 2404 .combined_maximum_animation_target_scale = |
| 2405 max_local_scale * ancestor_maximum_target_scale; |
| 2406 cached_data_.animation_scales[transform_node_id] |
| 2407 .combined_starting_animation_scale = |
| 2408 max_local_scale * ancestor_starting_animation_scale; |
| 2409 } else { |
| 2410 gfx::Vector2dF ancestor_scales = |
| 2411 parent_node ? MathUtil::ComputeTransform2dScaleComponents( |
| 2412 transform_tree.ToTarget(parent_node->id), 0.f) |
| 2413 : gfx::Vector2dF(1.f, 1.f); |
| 2414 float max_ancestor_scale = |
| 2415 std::max(ancestor_scales.x(), ancestor_scales.y()); |
| 2416 cached_data_.animation_scales[transform_node_id] |
| 2417 .combined_maximum_animation_target_scale = |
| 2418 max_ancestor_scale * |
| 2419 cached_data_.animation_scales[transform_node_id] |
| 2420 .local_maximum_animation_target_scale; |
| 2421 cached_data_.animation_scales[transform_node_id] |
| 2422 .combined_starting_animation_scale = |
| 2423 max_ancestor_scale * |
| 2424 cached_data_.animation_scales[transform_node_id] |
| 2425 .local_starting_animation_scale; |
| 2426 } |
| 2427 } |
| 2428 cached_data_.animation_scales[transform_node_id].update_number = |
| 2429 cached_data_.property_tree_update_number; |
| 2430 } |
| 2431 return CombinedAnimationScale(cached_data_.animation_scales[transform_node_id] |
| 2432 .combined_maximum_animation_target_scale, |
| 2433 cached_data_.animation_scales[transform_node_id] |
| 2434 .combined_starting_animation_scale); |
| 2435 } |
| 2436 |
| 2437 void PropertyTrees::SetAnimationScalesForTesting( |
| 2438 int transform_id, |
| 2439 float maximum_animation_scale, |
| 2440 float starting_animation_scale) { |
| 2441 cached_data_.animation_scales[transform_id] |
| 2442 .combined_maximum_animation_target_scale = maximum_animation_scale; |
| 2443 cached_data_.animation_scales[transform_id] |
| 2444 .combined_starting_animation_scale = starting_animation_scale; |
| 2445 cached_data_.animation_scales[transform_id].update_number = |
| 2446 cached_data_.property_tree_update_number; |
| 2447 } |
| 2448 |
| 2449 void PropertyTrees::ResetCachedData() { |
| 2450 cached_data_.property_tree_update_number = 0; |
| 2451 cached_data_.animation_scales = std::vector<AnimationScaleData>( |
| 2452 transform_tree.nodes().size(), AnimationScaleData()); |
| 2453 } |
| 2454 |
| 2455 void PropertyTrees::UpdateCachedNumber() { |
| 2456 cached_data_.property_tree_update_number++; |
| 2457 } |
| 2458 |
2396 } // namespace cc | 2459 } // namespace cc |
OLD | NEW |