| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/animation/transform_operations.h" | 5 #include "cc/animation/transform_operations.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ui/gfx/box_f.h" | 9 #include "ui/gfx/box_f.h" |
| 10 #include "ui/gfx/transform_util.h" | 10 #include "ui/gfx/transform_util.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 TransformOperations::~TransformOperations() { | 28 TransformOperations::~TransformOperations() { |
| 29 } | 29 } |
| 30 | 30 |
| 31 gfx::Transform TransformOperations::Apply() const { | 31 gfx::Transform TransformOperations::Apply() const { |
| 32 gfx::Transform to_return; | 32 gfx::Transform to_return; |
| 33 for (size_t i = 0; i < operations_.size(); ++i) | 33 for (size_t i = 0; i < operations_.size(); ++i) |
| 34 to_return.PreconcatTransform(operations_[i].matrix); | 34 to_return.PreconcatTransform(operations_[i].matrix); |
| 35 return to_return; | 35 return to_return; |
| 36 } | 36 } |
| 37 | 37 |
| 38 gfx::Transform TransformOperations::Blend( | 38 gfx::Transform TransformOperations::Blend(const TransformOperations& from, |
| 39 const TransformOperations& from, double progress) const { | 39 SkMScalar progress) const { |
| 40 gfx::Transform to_return; | 40 gfx::Transform to_return; |
| 41 BlendInternal(from, progress, &to_return); | 41 BlendInternal(from, progress, &to_return); |
| 42 return to_return; | 42 return to_return; |
| 43 } | 43 } |
| 44 | 44 |
| 45 bool TransformOperations::BlendedBoundsForBox(const gfx::BoxF& box, | 45 bool TransformOperations::BlendedBoundsForBox(const gfx::BoxF& box, |
| 46 const TransformOperations& from, | 46 const TransformOperations& from, |
| 47 double min_progress, | 47 SkMScalar min_progress, |
| 48 double max_progress, | 48 SkMScalar max_progress, |
| 49 gfx::BoxF* bounds) const { | 49 gfx::BoxF* bounds) const { |
| 50 *bounds = box; | 50 *bounds = box; |
| 51 | 51 |
| 52 bool from_identity = from.IsIdentity(); | 52 bool from_identity = from.IsIdentity(); |
| 53 bool to_identity = IsIdentity(); | 53 bool to_identity = IsIdentity(); |
| 54 if (from_identity && to_identity) | 54 if (from_identity && to_identity) |
| 55 return true; | 55 return true; |
| 56 | 56 |
| 57 if (!MatchesTypes(from)) | 57 if (!MatchesTypes(from)) |
| 58 return false; | 58 return false; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 94 |
| 95 return true; | 95 return true; |
| 96 } | 96 } |
| 97 | 97 |
| 98 bool TransformOperations::CanBlendWith( | 98 bool TransformOperations::CanBlendWith( |
| 99 const TransformOperations& other) const { | 99 const TransformOperations& other) const { |
| 100 gfx::Transform dummy; | 100 gfx::Transform dummy; |
| 101 return BlendInternal(other, 0.5, &dummy); | 101 return BlendInternal(other, 0.5, &dummy); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void TransformOperations::AppendTranslate(double x, double y, double z) { | 104 void TransformOperations::AppendTranslate(SkMScalar x, |
| 105 SkMScalar y, |
| 106 SkMScalar z) { |
| 105 TransformOperation to_add; | 107 TransformOperation to_add; |
| 106 to_add.matrix.Translate3d(x, y, z); | 108 to_add.matrix.Translate3d(x, y, z); |
| 107 to_add.type = TransformOperation::TransformOperationTranslate; | 109 to_add.type = TransformOperation::TransformOperationTranslate; |
| 108 to_add.translate.x = x; | 110 to_add.translate.x = x; |
| 109 to_add.translate.y = y; | 111 to_add.translate.y = y; |
| 110 to_add.translate.z = z; | 112 to_add.translate.z = z; |
| 111 operations_.push_back(to_add); | 113 operations_.push_back(to_add); |
| 112 decomposed_transform_dirty_ = true; | 114 decomposed_transform_dirty_ = true; |
| 113 } | 115 } |
| 114 | 116 |
| 115 void TransformOperations::AppendRotate(double x, double y, double z, | 117 void TransformOperations::AppendRotate(SkMScalar x, |
| 116 double degrees) { | 118 SkMScalar y, |
| 119 SkMScalar z, |
| 120 SkMScalar degrees) { |
| 117 TransformOperation to_add; | 121 TransformOperation to_add; |
| 118 to_add.matrix.RotateAbout(gfx::Vector3dF(x, y, z), degrees); | 122 to_add.matrix.RotateAbout(gfx::Vector3dF(x, y, z), degrees); |
| 119 to_add.type = TransformOperation::TransformOperationRotate; | 123 to_add.type = TransformOperation::TransformOperationRotate; |
| 120 to_add.rotate.axis.x = x; | 124 to_add.rotate.axis.x = x; |
| 121 to_add.rotate.axis.y = y; | 125 to_add.rotate.axis.y = y; |
| 122 to_add.rotate.axis.z = z; | 126 to_add.rotate.axis.z = z; |
| 123 to_add.rotate.angle = degrees; | 127 to_add.rotate.angle = degrees; |
| 124 operations_.push_back(to_add); | 128 operations_.push_back(to_add); |
| 125 decomposed_transform_dirty_ = true; | 129 decomposed_transform_dirty_ = true; |
| 126 } | 130 } |
| 127 | 131 |
| 128 void TransformOperations::AppendScale(double x, double y, double z) { | 132 void TransformOperations::AppendScale(SkMScalar x, SkMScalar y, SkMScalar z) { |
| 129 TransformOperation to_add; | 133 TransformOperation to_add; |
| 130 to_add.matrix.Scale3d(x, y, z); | 134 to_add.matrix.Scale3d(x, y, z); |
| 131 to_add.type = TransformOperation::TransformOperationScale; | 135 to_add.type = TransformOperation::TransformOperationScale; |
| 132 to_add.scale.x = x; | 136 to_add.scale.x = x; |
| 133 to_add.scale.y = y; | 137 to_add.scale.y = y; |
| 134 to_add.scale.z = z; | 138 to_add.scale.z = z; |
| 135 operations_.push_back(to_add); | 139 operations_.push_back(to_add); |
| 136 decomposed_transform_dirty_ = true; | 140 decomposed_transform_dirty_ = true; |
| 137 } | 141 } |
| 138 | 142 |
| 139 void TransformOperations::AppendSkew(double x, double y) { | 143 void TransformOperations::AppendSkew(SkMScalar x, SkMScalar y) { |
| 140 TransformOperation to_add; | 144 TransformOperation to_add; |
| 141 to_add.matrix.SkewX(x); | 145 to_add.matrix.SkewX(x); |
| 142 to_add.matrix.SkewY(y); | 146 to_add.matrix.SkewY(y); |
| 143 to_add.type = TransformOperation::TransformOperationSkew; | 147 to_add.type = TransformOperation::TransformOperationSkew; |
| 144 to_add.skew.x = x; | 148 to_add.skew.x = x; |
| 145 to_add.skew.y = y; | 149 to_add.skew.y = y; |
| 146 operations_.push_back(to_add); | 150 operations_.push_back(to_add); |
| 147 decomposed_transform_dirty_ = true; | 151 decomposed_transform_dirty_ = true; |
| 148 } | 152 } |
| 149 | 153 |
| 150 void TransformOperations::AppendPerspective(double depth) { | 154 void TransformOperations::AppendPerspective(SkMScalar depth) { |
| 151 TransformOperation to_add; | 155 TransformOperation to_add; |
| 152 to_add.matrix.ApplyPerspectiveDepth(depth); | 156 to_add.matrix.ApplyPerspectiveDepth(depth); |
| 153 to_add.type = TransformOperation::TransformOperationPerspective; | 157 to_add.type = TransformOperation::TransformOperationPerspective; |
| 154 to_add.perspective_depth = depth; | 158 to_add.perspective_depth = depth; |
| 155 operations_.push_back(to_add); | 159 operations_.push_back(to_add); |
| 156 decomposed_transform_dirty_ = true; | 160 decomposed_transform_dirty_ = true; |
| 157 } | 161 } |
| 158 | 162 |
| 159 void TransformOperations::AppendMatrix(const gfx::Transform& matrix) { | 163 void TransformOperations::AppendMatrix(const gfx::Transform& matrix) { |
| 160 TransformOperation to_add; | 164 TransformOperation to_add; |
| 161 to_add.matrix = matrix; | 165 to_add.matrix = matrix; |
| 162 to_add.type = TransformOperation::TransformOperationMatrix; | 166 to_add.type = TransformOperation::TransformOperationMatrix; |
| 163 operations_.push_back(to_add); | 167 operations_.push_back(to_add); |
| 164 decomposed_transform_dirty_ = true; | 168 decomposed_transform_dirty_ = true; |
| 165 } | 169 } |
| 166 | 170 |
| 167 void TransformOperations::AppendIdentity() { | 171 void TransformOperations::AppendIdentity() { |
| 168 operations_.push_back(TransformOperation()); | 172 operations_.push_back(TransformOperation()); |
| 169 } | 173 } |
| 170 | 174 |
| 171 bool TransformOperations::IsIdentity() const { | 175 bool TransformOperations::IsIdentity() const { |
| 172 for (size_t i = 0; i < operations_.size(); ++i) { | 176 for (size_t i = 0; i < operations_.size(); ++i) { |
| 173 if (!operations_[i].IsIdentity()) | 177 if (!operations_[i].IsIdentity()) |
| 174 return false; | 178 return false; |
| 175 } | 179 } |
| 176 return true; | 180 return true; |
| 177 } | 181 } |
| 178 | 182 |
| 179 bool TransformOperations::BlendInternal(const TransformOperations& from, | 183 bool TransformOperations::BlendInternal(const TransformOperations& from, |
| 180 double progress, | 184 SkMScalar progress, |
| 181 gfx::Transform* result) const { | 185 gfx::Transform* result) const { |
| 182 bool from_identity = from.IsIdentity(); | 186 bool from_identity = from.IsIdentity(); |
| 183 bool to_identity = IsIdentity(); | 187 bool to_identity = IsIdentity(); |
| 184 if (from_identity && to_identity) | 188 if (from_identity && to_identity) |
| 185 return true; | 189 return true; |
| 186 | 190 |
| 187 if (MatchesTypes(from)) { | 191 if (MatchesTypes(from)) { |
| 188 size_t num_operations = | 192 size_t num_operations = |
| 189 std::max(from_identity ? 0 : from.operations_.size(), | 193 std::max(from_identity ? 0 : from.operations_.size(), |
| 190 to_identity ? 0 : operations_.size()); | 194 to_identity ? 0 : operations_.size()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 221 decomposed_transform_.reset(new gfx::DecomposedTransform()); | 225 decomposed_transform_.reset(new gfx::DecomposedTransform()); |
| 222 gfx::Transform transform = Apply(); | 226 gfx::Transform transform = Apply(); |
| 223 if (!gfx::DecomposeTransform(decomposed_transform_.get(), transform)) | 227 if (!gfx::DecomposeTransform(decomposed_transform_.get(), transform)) |
| 224 return false; | 228 return false; |
| 225 decomposed_transform_dirty_ = false; | 229 decomposed_transform_dirty_ = false; |
| 226 } | 230 } |
| 227 return true; | 231 return true; |
| 228 } | 232 } |
| 229 | 233 |
| 230 } // namespace cc | 234 } // namespace cc |
| OLD | NEW |