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/animation/tween.h" | 9 #include "ui/gfx/animation/tween.h" |
10 #include "ui/gfx/geometry/box_f.h" | 10 #include "ui/gfx/geometry/box_f.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 void TransformOperations::AppendTranslate(SkMScalar x, | 188 void TransformOperations::AppendTranslate(SkMScalar x, |
189 SkMScalar y, | 189 SkMScalar y, |
190 SkMScalar z) { | 190 SkMScalar z) { |
191 TransformOperation to_add; | 191 TransformOperation to_add; |
192 to_add.matrix.Translate3d(x, y, z); | 192 to_add.matrix.Translate3d(x, y, z); |
193 to_add.type = TransformOperation::TRANSFORM_OPERATION_TRANSLATE; | 193 to_add.type = TransformOperation::TRANSFORM_OPERATION_TRANSLATE; |
194 to_add.translate.x = x; | 194 to_add.translate.x = x; |
195 to_add.translate.y = y; | 195 to_add.translate.y = y; |
196 to_add.translate.z = z; | 196 to_add.translate.z = z; |
197 operations_.push_back(to_add); | 197 operations_.push_back(to_add); |
198 decomposed_transform_dirty_ = true; | 198 if (!to_add.IsIdentity()) |
| 199 decomposed_transform_dirty_ = true; |
199 } | 200 } |
200 | 201 |
201 void TransformOperations::AppendRotate(SkMScalar x, | 202 void TransformOperations::AppendRotate(SkMScalar x, |
202 SkMScalar y, | 203 SkMScalar y, |
203 SkMScalar z, | 204 SkMScalar z, |
204 SkMScalar degrees) { | 205 SkMScalar degrees) { |
205 TransformOperation to_add; | 206 TransformOperation to_add; |
206 to_add.matrix.RotateAbout(gfx::Vector3dF(x, y, z), degrees); | 207 to_add.matrix.RotateAbout(gfx::Vector3dF(x, y, z), degrees); |
207 to_add.type = TransformOperation::TRANSFORM_OPERATION_ROTATE; | 208 to_add.type = TransformOperation::TRANSFORM_OPERATION_ROTATE; |
208 to_add.rotate.axis.x = x; | 209 to_add.rotate.axis.x = x; |
209 to_add.rotate.axis.y = y; | 210 to_add.rotate.axis.y = y; |
210 to_add.rotate.axis.z = z; | 211 to_add.rotate.axis.z = z; |
211 to_add.rotate.angle = degrees; | 212 to_add.rotate.angle = degrees; |
212 operations_.push_back(to_add); | 213 operations_.push_back(to_add); |
213 decomposed_transform_dirty_ = true; | 214 if (!to_add.IsIdentity()) |
| 215 decomposed_transform_dirty_ = true; |
214 } | 216 } |
215 | 217 |
216 void TransformOperations::AppendScale(SkMScalar x, SkMScalar y, SkMScalar z) { | 218 void TransformOperations::AppendScale(SkMScalar x, SkMScalar y, SkMScalar z) { |
217 TransformOperation to_add; | 219 TransformOperation to_add; |
218 to_add.matrix.Scale3d(x, y, z); | 220 to_add.matrix.Scale3d(x, y, z); |
219 to_add.type = TransformOperation::TRANSFORM_OPERATION_SCALE; | 221 to_add.type = TransformOperation::TRANSFORM_OPERATION_SCALE; |
220 to_add.scale.x = x; | 222 to_add.scale.x = x; |
221 to_add.scale.y = y; | 223 to_add.scale.y = y; |
222 to_add.scale.z = z; | 224 to_add.scale.z = z; |
223 operations_.push_back(to_add); | 225 operations_.push_back(to_add); |
224 decomposed_transform_dirty_ = true; | 226 if (!to_add.IsIdentity()) |
| 227 decomposed_transform_dirty_ = true; |
225 } | 228 } |
226 | 229 |
227 void TransformOperations::AppendSkew(SkMScalar x, SkMScalar y) { | 230 void TransformOperations::AppendSkew(SkMScalar x, SkMScalar y) { |
228 TransformOperation to_add; | 231 TransformOperation to_add; |
229 to_add.matrix.SkewX(x); | 232 to_add.matrix.SkewX(x); |
230 to_add.matrix.SkewY(y); | 233 to_add.matrix.SkewY(y); |
231 to_add.type = TransformOperation::TRANSFORM_OPERATION_SKEW; | 234 to_add.type = TransformOperation::TRANSFORM_OPERATION_SKEW; |
232 to_add.skew.x = x; | 235 to_add.skew.x = x; |
233 to_add.skew.y = y; | 236 to_add.skew.y = y; |
234 operations_.push_back(to_add); | 237 operations_.push_back(to_add); |
235 decomposed_transform_dirty_ = true; | 238 if (!to_add.IsIdentity()) |
| 239 decomposed_transform_dirty_ = true; |
236 } | 240 } |
237 | 241 |
238 void TransformOperations::AppendPerspective(SkMScalar depth) { | 242 void TransformOperations::AppendPerspective(SkMScalar depth) { |
239 TransformOperation to_add; | 243 TransformOperation to_add; |
240 to_add.matrix.ApplyPerspectiveDepth(depth); | 244 to_add.matrix.ApplyPerspectiveDepth(depth); |
241 to_add.type = TransformOperation::TRANSFORM_OPERATION_PERSPECTIVE; | 245 to_add.type = TransformOperation::TRANSFORM_OPERATION_PERSPECTIVE; |
242 to_add.perspective_depth = depth; | 246 to_add.perspective_depth = depth; |
243 operations_.push_back(to_add); | 247 operations_.push_back(to_add); |
244 decomposed_transform_dirty_ = true; | 248 if (!to_add.IsIdentity()) |
| 249 decomposed_transform_dirty_ = true; |
245 } | 250 } |
246 | 251 |
247 void TransformOperations::AppendMatrix(const gfx::Transform& matrix) { | 252 void TransformOperations::AppendMatrix(const gfx::Transform& matrix) { |
248 TransformOperation to_add; | 253 TransformOperation to_add; |
249 to_add.matrix = matrix; | 254 to_add.matrix = matrix; |
250 to_add.type = TransformOperation::TRANSFORM_OPERATION_MATRIX; | 255 to_add.type = TransformOperation::TRANSFORM_OPERATION_MATRIX; |
251 operations_.push_back(to_add); | 256 operations_.push_back(to_add); |
252 decomposed_transform_dirty_ = true; | 257 if (!to_add.IsIdentity()) |
| 258 decomposed_transform_dirty_ = true; |
253 } | 259 } |
254 | 260 |
255 void TransformOperations::AppendIdentity() { | 261 void TransformOperations::AppendIdentity() { |
256 operations_.push_back(TransformOperation()); | 262 operations_.push_back(TransformOperation()); |
257 } | 263 } |
258 | 264 |
259 bool TransformOperations::IsIdentity() const { | 265 bool TransformOperations::IsIdentity() const { |
260 for (size_t i = 0; i < operations_.size(); ++i) { | 266 for (size_t i = 0; i < operations_.size(); ++i) { |
261 if (!operations_[i].IsIdentity()) | 267 if (!operations_[i].IsIdentity()) |
262 return false; | 268 return false; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 decomposed_transform_.reset(new gfx::DecomposedTransform()); | 315 decomposed_transform_.reset(new gfx::DecomposedTransform()); |
310 gfx::Transform transform = Apply(); | 316 gfx::Transform transform = Apply(); |
311 if (!gfx::DecomposeTransform(decomposed_transform_.get(), transform)) | 317 if (!gfx::DecomposeTransform(decomposed_transform_.get(), transform)) |
312 return false; | 318 return false; |
313 decomposed_transform_dirty_ = false; | 319 decomposed_transform_dirty_ = false; |
314 } | 320 } |
315 return true; | 321 return true; |
316 } | 322 } |
317 | 323 |
318 } // namespace cc | 324 } // namespace cc |
OLD | NEW |