Add myself as a password bubble owner.
[chromium-blink-merge.git] / cc / animation / transform_operations.h
blobf086eb1baac1d7a0405189066569d8878e383f64
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 // Sets |max_scale| to be the maximum scale in any dimension when calling
67 // Blend on |from| with progress in the range [min_progress, max_progress]. If
68 // this maximum scale cannot be computed, returns false.
69 bool MaximumScale(const TransformOperations& from,
70 SkMScalar min_progress,
71 SkMScalar max_progress,
72 float* max_scale) const;
74 // Returns true if this operation and its descendants have the same types
75 // as other and its descendants.
76 bool MatchesTypes(const TransformOperations& other) const;
78 // Returns true if these operations can be blended. It will only return
79 // false if we must resort to matrix interpolation, and matrix interpolation
80 // fails (this can happen if either matrix cannot be decomposed).
81 bool CanBlendWith(const TransformOperations& other) 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 // If these operations have no more than one scale operation, and if the only
102 // other operations are translations, sets |scale| to the scale component
103 // of these operations. Otherwise, returns false.
104 bool ScaleComponent(gfx::Vector3dF* scale) const;
106 // For efficiency, we cache the decomposed transform.
107 mutable scoped_ptr<gfx::DecomposedTransform> decomposed_transform_;
108 mutable bool decomposed_transform_dirty_;
110 DISALLOW_ASSIGN(TransformOperations);
113 } // namespace cc
115 #endif // CC_ANIMATION_TRANSFORM_OPERATIONS_H_