| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 CombineTransformsBetween(source_id, dest_id, transform); | 154 CombineTransformsBetween(source_id, dest_id, transform); |
| 155 return true; | 155 return true; |
| 156 } | 156 } |
| 157 | 157 |
| 158 return CombineInversesBetween(source_id, dest_id, transform); | 158 return CombineInversesBetween(source_id, dest_id, transform); |
| 159 } | 159 } |
| 160 | 160 |
| 161 bool TransformTree::ComputeTranslation(int source_id, | 161 bool TransformTree::ComputeTranslation(int source_id, |
| 162 int dest_id, | 162 int dest_id, |
| 163 gfx::Transform* transform) const { | 163 gfx::Transform* transform) const { |
| 164 bool success = ComputeTransform(source_id, dest_id, transform); | 164 transform->MakeIdentity(); |
| 165 if (source_id == dest_id) |
| 166 return true; |
| 167 |
| 168 const TransformNode* dest = Node(dest_id); |
| 169 if (!dest->ancestors_are_invertible) |
| 170 return false; |
| 171 if (source_id != kInvalidNodeId) |
| 172 transform->ConcatTransform(ToScreen(source_id)); |
| 173 if (dest_id != kInvalidNodeId) { |
| 174 if (dest->local.IsFlat() && (dest->node_and_ancestors_are_flat || |
| 175 dest->flattens_inherited_transform)) { |
| 176 // In this case, flattenning will not affect the result, so we can use the |
| 177 // FromScreen transform of the dest node. |
| 178 transform->ConcatTransform(FromScreen(dest_id)); |
| 179 } else { |
| 180 // In this case, some node between source and destination flattens |
| 181 // inherited transform. Consider the tree R->A->B->C->D, where D is the |
| 182 // source, A is the destination and C flattens inherited transform. The |
| 183 // expected result is D * C * flattened(B). D's ToScreen will be D * C * |
| 184 // flattened(B * A * R), but as the source to destination transform is |
| 185 // at most translation, C and B cannot be non-flat and so flattened(B * A |
| 186 // * R) = B * flattened(A * R). So, to get the expected result we have to |
| 187 // multiply D's ToScreen transform with flattened(A * R)^{-1}, which is |
| 188 // the inverse of flattened ToScreen of destination. |
| 189 gfx::Transform to_screen = ToScreen(dest_id); |
| 190 to_screen.FlattenTo2d(); |
| 191 gfx::Transform from_screen; |
| 192 bool success = to_screen.GetInverse(&from_screen); |
| 193 if (!success) |
| 194 return false; |
| 195 transform->ConcatTransform(from_screen); |
| 196 } |
| 197 } |
| 198 |
| 165 DCHECK( | 199 DCHECK( |
| 166 transform->IsApproximatelyIdentityOrTranslation(SkDoubleToMScalar(1e-4))); | 200 transform->IsApproximatelyIdentityOrTranslation(SkDoubleToMScalar(1e-4))); |
| 167 return success; | 201 return true; |
| 168 } | 202 } |
| 169 | 203 |
| 170 bool TransformTree::NeedsSourceToParentUpdate(TransformNode* node) { | 204 bool TransformTree::NeedsSourceToParentUpdate(TransformNode* node) { |
| 171 return (source_to_parent_updates_allowed() && | 205 return (source_to_parent_updates_allowed() && |
| 172 node->parent_id != node->source_node_id); | 206 node->parent_id != node->source_node_id); |
| 173 } | 207 } |
| 174 | 208 |
| 175 void TransformTree::ResetChangeTracking() { | 209 void TransformTree::ResetChangeTracking() { |
| 176 for (int id = 1; id < static_cast<int>(size()); ++id) { | 210 for (int id = 1; id < static_cast<int>(size()); ++id) { |
| 177 TransformNode* node = Node(id); | 211 TransformNode* node = Node(id); |
| (...skipping 1873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2051 from_target.ConcatTransform(draw_transforms.from_target); | 2085 from_target.ConcatTransform(draw_transforms.from_target); |
| 2052 from_target.Scale(effect_node->surface_contents_scale.x(), | 2086 from_target.Scale(effect_node->surface_contents_scale.x(), |
| 2053 effect_node->surface_contents_scale.y()); | 2087 effect_node->surface_contents_scale.y()); |
| 2054 DCHECK(from_target.ApproximatelyEqual(*transform) || | 2088 DCHECK(from_target.ApproximatelyEqual(*transform) || |
| 2055 !draw_transforms.invertible); | 2089 !draw_transforms.invertible); |
| 2056 } | 2090 } |
| 2057 return success; | 2091 return success; |
| 2058 } | 2092 } |
| 2059 | 2093 |
| 2060 } // namespace cc | 2094 } // namespace cc |
| OLD | NEW |