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
3 // found in the LICENSE file.
5 #ifndef CC_ANIMATION_TRANSFORM_OPERATIONS_H_
6 #define CC_ANIMATION_TRANSFORM_OPERATIONS_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "cc/animation/transform_operation.h"
12 #include "cc/base/cc_export.h"
13 #include "ui/gfx/transform.h"
16 struct DecomposedTransform
;
21 // Transform operations are a decomposed transformation matrix. It can be
22 // applied to obtain a gfx::Transform at any time, and can be blended
23 // intelligently with other transform operations, so long as they represent the
24 // same decomposition. For example, if we have a transform that is made up of
25 // a rotation followed by skew, it can be blended intelligently with another
26 // transform made up of a rotation followed by a skew. Blending is possible if
27 // we have two dissimilar sets of transform operations, but the effect may not
28 // be what was intended. For more information, see the comments for the blend
30 class CC_EXPORT TransformOperations
{
32 TransformOperations();
33 TransformOperations(const TransformOperations
& other
);
34 ~TransformOperations();
36 // Returns a transformation matrix representing these transform operations.
37 gfx::Transform
Apply() const;
39 // Given another set of transform operations and a progress in the range
40 // [0, 1], returns a transformation matrix representing the intermediate
41 // value. If this->MatchesTypes(from), then each of the operations are
42 // blended separately and then combined. Otherwise, the two sets of
43 // transforms are baked to matrices (using apply), and the matrices are
44 // then decomposed and interpolated. For more information, see
45 // http://www.w3.org/TR/2011/WD-css3-2d-transforms-20111215/#matrix-decomposition.
46 gfx::Transform
Blend(const TransformOperations
& from
, double progress
) const;
48 // Returns true if this operation and its descendants have the same types
49 // as other and its descendants.
50 bool MatchesTypes(const TransformOperations
& other
) const;
52 // Returns true if these operations can be blended. It will only return
53 // false if we must resort to matrix interpolation, and matrix interpolation
54 // fails (this can happen if either matrix cannot be decomposed).
55 bool CanBlendWith(const TransformOperations
& other
) const;
57 void AppendTranslate(double x
, double y
, double z
);
58 void AppendRotate(double x
, double y
, double z
, double degrees
);
59 void AppendScale(double x
, double y
, double z
);
60 void AppendSkew(double x
, double y
);
61 void AppendPerspective(double depth
);
62 void AppendMatrix(const gfx::Transform
& matrix
);
63 void AppendIdentity();
64 bool IsIdentity() const;
67 bool BlendInternal(const TransformOperations
& from
, double progress
,
68 gfx::Transform
* result
) const;
70 std::vector
<TransformOperation
> operations_
;
72 bool ComputeDecomposedTransform() const;
74 // For efficiency, we cache the decomposed transform.
75 mutable scoped_ptr
<gfx::DecomposedTransform
> decomposed_transform_
;
76 mutable bool decomposed_transform_dirty_
;
78 DISALLOW_ASSIGN(TransformOperations
);
83 #endif // CC_ANIMATION_TRANSFORM_OPERATIONS_H_