| 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 1090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 void TransformTree::UndoSnapping(TransformNode* node) { | 1101 void TransformTree::UndoSnapping(TransformNode* node) { |
| 1102 // to_parent transform has the scroll snap from previous frame baked in. | 1102 // to_parent transform has the scroll snap from previous frame baked in. |
| 1103 // We need to undo it and use the un-snapped transform to compute current | 1103 // We need to undo it and use the un-snapped transform to compute current |
| 1104 // target and screen space transforms. | 1104 // target and screen space transforms. |
| 1105 node->data.to_parent.Translate(-node->data.scroll_snap.x(), | 1105 node->data.to_parent.Translate(-node->data.scroll_snap.x(), |
| 1106 -node->data.scroll_snap.y()); | 1106 -node->data.scroll_snap.y()); |
| 1107 } | 1107 } |
| 1108 | 1108 |
| 1109 void TransformTree::UpdateSnapping(TransformNode* node) { | 1109 void TransformTree::UpdateSnapping(TransformNode* node) { |
| 1110 if (!node->data.scrolls || node->data.to_screen_is_potentially_animated || | 1110 if (!node->data.scrolls || node->data.to_screen_is_potentially_animated || |
| 1111 !node->data.to_target.IsScaleOrTranslation() || | 1111 !node->data.to_screen.IsScaleOrTranslation() || |
| 1112 !node->data.ancestors_are_invertible) { | 1112 !node->data.ancestors_are_invertible) { |
| 1113 return; | 1113 return; |
| 1114 } | 1114 } |
| 1115 | 1115 |
| 1116 // Scroll snapping must be done in target space (the pixels we care about). | 1116 // Scroll snapping must be done in screen space (the pixels we care about). |
| 1117 // This means we effectively snap the target space transform. If TT is the | 1117 // This means we effectively snap the screen space transform. If ST is the |
| 1118 // target space transform and TT' is TT with its translation components | 1118 // screen space transform and ST' is ST with its translation components |
| 1119 // rounded, then what we're after is the scroll delta X, where TT * X = TT'. | 1119 // rounded, then what we're after is the scroll delta X, where ST * X = ST'. |
| 1120 // I.e., we want a transform that will realize our scroll snap. It follows | 1120 // I.e., we want a transform that will realize our scroll snap. It follows |
| 1121 // that X = TT^-1 * TT'. We cache TT and TT^-1 to make this more efficient. | 1121 // that X = ST^-1 * ST'. We cache ST and ST^-1 to make this more efficient. |
| 1122 gfx::Transform rounded = node->data.to_target; | 1122 gfx::Transform rounded = node->data.to_screen; |
| 1123 rounded.RoundTranslationComponents(); | 1123 rounded.RoundTranslationComponents(); |
| 1124 gfx::Transform delta = node->data.from_target; | 1124 gfx::Transform delta = node->data.from_screen; |
| 1125 delta *= rounded; | 1125 delta *= rounded; |
| 1126 | 1126 |
| 1127 DCHECK(delta.IsApproximatelyIdentityOrTranslation(SkDoubleToMScalar(1e-4))) | 1127 DCHECK(delta.IsApproximatelyIdentityOrTranslation(SkDoubleToMScalar(1e-4))) |
| 1128 << delta.ToString(); | 1128 << delta.ToString(); |
| 1129 | 1129 |
| 1130 gfx::Vector2dF translation = delta.To2dTranslation(); | 1130 gfx::Vector2dF translation = delta.To2dTranslation(); |
| 1131 | 1131 |
| 1132 // Now that we have our scroll delta, we must apply it to each of our | 1132 // Now that we have our scroll delta, we must apply it to each of our |
| 1133 // combined, to/from matrices. | 1133 // combined, to/from matrices. |
| 1134 node->data.to_target = rounded; | 1134 node->data.to_screen = rounded; |
| 1135 node->data.to_parent.Translate(translation.x(), translation.y()); | 1135 node->data.to_parent.Translate(translation.x(), translation.y()); |
| 1136 node->data.from_screen.matrix().postTranslate(-translation.x(), |
| 1137 -translation.y(), 0); |
| 1138 node->data.to_target.Translate(translation.x(), translation.y()); |
| 1136 node->data.from_target.matrix().postTranslate(-translation.x(), | 1139 node->data.from_target.matrix().postTranslate(-translation.x(), |
| 1137 -translation.y(), 0); | 1140 -translation.y(), 0); |
| 1138 node->data.to_screen.Translate(translation.x(), translation.y()); | |
| 1139 node->data.from_screen.matrix().postTranslate(-translation.x(), | |
| 1140 -translation.y(), 0); | |
| 1141 | 1141 |
| 1142 node->data.scroll_snap = translation; | 1142 node->data.scroll_snap = translation; |
| 1143 } | 1143 } |
| 1144 | 1144 |
| 1145 void TransformTree::UpdateTransformChanged(TransformNode* node, | 1145 void TransformTree::UpdateTransformChanged(TransformNode* node, |
| 1146 TransformNode* parent_node, | 1146 TransformNode* parent_node, |
| 1147 TransformNode* source_node) { | 1147 TransformNode* source_node) { |
| 1148 if (parent_node && parent_node->data.transform_changed) { | 1148 if (parent_node && parent_node->data.transform_changed) { |
| 1149 node->data.transform_changed = true; | 1149 node->data.transform_changed = true; |
| 1150 return; | 1150 return; |
| (...skipping 947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2098 value->EndDictionary(); | 2098 value->EndDictionary(); |
| 2099 | 2099 |
| 2100 value->BeginDictionary("scroll_tree"); | 2100 value->BeginDictionary("scroll_tree"); |
| 2101 scroll_tree.AsValueInto(value.get()); | 2101 scroll_tree.AsValueInto(value.get()); |
| 2102 value->EndDictionary(); | 2102 value->EndDictionary(); |
| 2103 | 2103 |
| 2104 return value; | 2104 return value; |
| 2105 } | 2105 } |
| 2106 | 2106 |
| 2107 } // namespace cc | 2107 } // namespace cc |
| OLD | NEW |