Implements RLZTrackerDelegate on iOS.
[chromium-blink-merge.git] / cc / animation / transform_operations.h
blob65f8511d5110a60e50ec4f9c22b236399da4dab4
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_
8 #include <vector>
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"
15 namespace gfx {
16 class BoxF;
17 struct DecomposedTransform;
20 namespace cc {
22 // Transform operations are a decomposed transformation matrix. It can be
23 // applied to obtain a gfx::Transform at any time, and can be blended
24 // intelligently with other transform operations, so long as they represent the
25 // same decomposition. For example, if we have a transform that is made up of
26 // a rotation followed by skew, it can be blended intelligently with another
27 // transform made up of a rotation followed by a skew. Blending is possible if
28 // we have two dissimilar sets of transform operations, but the effect may not
29 // be what was intended. For more information, see the comments for the blend
30 // function below.
31 class CC_EXPORT TransformOperations {
32 public:
33 TransformOperations();
34 TransformOperations(const TransformOperations& other);
35 ~TransformOperations();
37 // Returns a transformation matrix representing these transform operations.
38 gfx::Transform Apply() const;
40 // Given another set of transform operations and a progress in the range
41 // [0, 1], returns a transformation matrix representing the intermediate
42 // value. If this->MatchesTypes(from), then each of the operations are
43 // blended separately and then combined. Otherwise, the two sets of
44 // transforms are baked to matrices (using apply), and the matrices are
45 // then decomposed and interpolated. For more information, see
46 // http://www.w3.org/TR/2011/WD-css3-2d-transforms-20111215/#matrix-decomposition.
47 gfx::Transform Blend(const TransformOperations& from,
48 SkMScalar progress) const;
50 // Sets |bounds| be the bounding box for the region within which |box| will
51 // exist when it is transformed by the result of calling Blend on |from| and
52 // with progress in the range [min_progress, max_progress]. If this region
53 // cannot be computed, returns false.
54 bool BlendedBoundsForBox(const gfx::BoxF& box,
55 const TransformOperations& from,
56 SkMScalar min_progress,
57 SkMScalar max_progress,
58 gfx::BoxF* bounds) const;
60 // Returns true if these operations affect scale.
61 bool AffectsScale() const;
63 // Returns true if these operations are only translations.
64 bool IsTranslation() const;
66 // Returns false if the operations affect 2d axis alignment.
67 bool PreservesAxisAlignment() const;
69 // Returns true if this operation and its descendants have the same types
70 // as other and its descendants.
71 bool MatchesTypes(const TransformOperations& other) const;
73 // Returns true if these operations can be blended. It will only return
74 // false if we must resort to matrix interpolation, and matrix interpolation
75 // fails (this can happen if either matrix cannot be decomposed).
76 bool CanBlendWith(const TransformOperations& other) const;
78 // If these operations have no more than one scale operation, and if the only
79 // other operations are translations, sets |scale| to the scale component
80 // of these operations. Otherwise, returns false.
81 bool ScaleComponent(gfx::Vector3dF* scale) const;
83 void AppendTranslate(SkMScalar x, SkMScalar y, SkMScalar z);
84 void AppendRotate(SkMScalar x, SkMScalar y, SkMScalar z, SkMScalar degrees);
85 void AppendScale(SkMScalar x, SkMScalar y, SkMScalar z);
86 void AppendSkew(SkMScalar x, SkMScalar y);
87 void AppendPerspective(SkMScalar depth);
88 void AppendMatrix(const gfx::Transform& matrix);
89 void AppendIdentity();
90 bool IsIdentity() const;
92 private:
93 bool BlendInternal(const TransformOperations& from,
94 SkMScalar progress,
95 gfx::Transform* result) const;
97 std::vector<TransformOperation> operations_;
99 bool ComputeDecomposedTransform() const;
101 // For efficiency, we cache the decomposed transform.
102 mutable scoped_ptr<gfx::DecomposedTransform> decomposed_transform_;
103 mutable bool decomposed_transform_dirty_;
105 DISALLOW_ASSIGN(TransformOperations);
108 } // namespace cc
110 #endif // CC_ANIMATION_TRANSFORM_OPERATIONS_H_