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/transform_operations.h" | 5 #include "cc/transform_operations.h" |
6 | 6 #include "ui/gfx/vector3d_f.h" |
7 using WebKit::WebTransformationMatrix; | |
8 | 7 |
9 namespace cc { | 8 namespace cc { |
10 | 9 |
11 TransformOperations::TransformOperations() { | 10 TransformOperations::TransformOperations() { |
12 } | 11 } |
13 | 12 |
14 TransformOperations::TransformOperations(const TransformOperations& other) { | 13 TransformOperations::TransformOperations(const TransformOperations& other) { |
15 operations_ = other.operations_; | 14 operations_ = other.operations_; |
16 } | 15 } |
17 | 16 |
18 TransformOperations::~TransformOperations() { | 17 TransformOperations::~TransformOperations() { |
19 } | 18 } |
20 | 19 |
21 WebTransformationMatrix TransformOperations::Apply() const { | 20 gfx::Transform TransformOperations::Apply() const { |
22 WebTransformationMatrix to_return; | 21 gfx::Transform to_return; |
23 for (size_t i = 0; i < operations_.size(); ++i) | 22 for (size_t i = 0; i < operations_.size(); ++i) |
24 to_return.multiply(operations_[i].matrix); | 23 to_return.PreconcatTransform(operations_[i].matrix); |
25 return to_return; | 24 return to_return; |
26 } | 25 } |
27 | 26 |
28 WebTransformationMatrix TransformOperations::Blend( | 27 gfx::Transform TransformOperations::Blend( |
29 const TransformOperations& from, double progress) const { | 28 const TransformOperations& from, double progress) const { |
30 WebTransformationMatrix to_return; | 29 gfx::Transform to_return; |
31 BlendInternal(from, progress, to_return); | 30 BlendInternal(from, progress, to_return); |
32 return to_return; | 31 return to_return; |
33 } | 32 } |
34 | 33 |
35 bool TransformOperations::MatchesTypes(const TransformOperations& other) const { | 34 bool TransformOperations::MatchesTypes(const TransformOperations& other) const { |
36 if (IsIdentity() || other.IsIdentity()) | 35 if (IsIdentity() || other.IsIdentity()) |
37 return true; | 36 return true; |
38 | 37 |
39 if (operations_.size() != other.operations_.size()) | 38 if (operations_.size() != other.operations_.size()) |
40 return false; | 39 return false; |
41 | 40 |
42 for (size_t i = 0; i < operations_.size(); ++i) { | 41 for (size_t i = 0; i < operations_.size(); ++i) { |
43 if (operations_[i].type != other.operations_[i].type | 42 if (operations_[i].type != other.operations_[i].type |
44 && !operations_[i].IsIdentity() | 43 && !operations_[i].IsIdentity() |
45 && !other.operations_[i].IsIdentity()) | 44 && !other.operations_[i].IsIdentity()) |
46 return false; | 45 return false; |
47 } | 46 } |
48 | 47 |
49 return true; | 48 return true; |
50 } | 49 } |
51 | 50 |
52 bool TransformOperations::CanBlendWith( | 51 bool TransformOperations::CanBlendWith( |
53 const TransformOperations& other) const { | 52 const TransformOperations& other) const { |
54 WebTransformationMatrix dummy; | 53 gfx::Transform dummy; |
55 return BlendInternal(other, 0.5, dummy); | 54 return BlendInternal(other, 0.5, dummy); |
56 } | 55 } |
57 | 56 |
58 void TransformOperations::AppendTranslate(double x, double y, double z) { | 57 void TransformOperations::AppendTranslate(double x, double y, double z) { |
59 TransformOperation to_add; | 58 TransformOperation to_add; |
60 to_add.matrix.translate3d(x, y, z); | 59 to_add.matrix.Translate3d(x, y, z); |
61 to_add.type = TransformOperation::TransformOperationTranslate; | 60 to_add.type = TransformOperation::TransformOperationTranslate; |
62 to_add.translate.x = x; | 61 to_add.translate.x = x; |
63 to_add.translate.y = y; | 62 to_add.translate.y = y; |
64 to_add.translate.z = z; | 63 to_add.translate.z = z; |
65 operations_.push_back(to_add); | 64 operations_.push_back(to_add); |
66 } | 65 } |
67 | 66 |
68 void TransformOperations::AppendRotate(double x, double y, double z, | 67 void TransformOperations::AppendRotate(double x, double y, double z, |
69 double degrees) { | 68 double degrees) { |
70 TransformOperation to_add; | 69 TransformOperation to_add; |
71 to_add.matrix.rotate3d(x, y, z, degrees); | 70 to_add.matrix.RotateAbout(gfx::Vector3dF(x, y, z), degrees); |
72 to_add.type = TransformOperation::TransformOperationRotate; | 71 to_add.type = TransformOperation::TransformOperationRotate; |
73 to_add.rotate.axis.x = x; | 72 to_add.rotate.axis.x = x; |
74 to_add.rotate.axis.y = y; | 73 to_add.rotate.axis.y = y; |
75 to_add.rotate.axis.z = z; | 74 to_add.rotate.axis.z = z; |
76 to_add.rotate.angle = degrees; | 75 to_add.rotate.angle = degrees; |
77 operations_.push_back(to_add); | 76 operations_.push_back(to_add); |
78 } | 77 } |
79 | 78 |
80 void TransformOperations::AppendScale(double x, double y, double z) { | 79 void TransformOperations::AppendScale(double x, double y, double z) { |
81 TransformOperation to_add; | 80 TransformOperation to_add; |
82 to_add.matrix.scale3d(x, y, z); | 81 to_add.matrix.Scale3d(x, y, z); |
83 to_add.type = TransformOperation::TransformOperationScale; | 82 to_add.type = TransformOperation::TransformOperationScale; |
84 to_add.scale.x = x; | 83 to_add.scale.x = x; |
85 to_add.scale.y = y; | 84 to_add.scale.y = y; |
86 to_add.scale.z = z; | 85 to_add.scale.z = z; |
87 operations_.push_back(to_add); | 86 operations_.push_back(to_add); |
88 } | 87 } |
89 | 88 |
90 void TransformOperations::AppendSkew(double x, double y) { | 89 void TransformOperations::AppendSkew(double x, double y) { |
91 TransformOperation to_add; | 90 TransformOperation to_add; |
92 to_add.matrix.skewX(x); | 91 to_add.matrix.SkewX(x); |
93 to_add.matrix.skewY(y); | 92 to_add.matrix.SkewY(y); |
94 to_add.type = TransformOperation::TransformOperationSkew; | 93 to_add.type = TransformOperation::TransformOperationSkew; |
95 to_add.skew.x = x; | 94 to_add.skew.x = x; |
96 to_add.skew.y = y; | 95 to_add.skew.y = y; |
97 operations_.push_back(to_add); | 96 operations_.push_back(to_add); |
98 } | 97 } |
99 | 98 |
100 void TransformOperations::AppendPerspective(double depth) { | 99 void TransformOperations::AppendPerspective(double depth) { |
101 TransformOperation to_add; | 100 TransformOperation to_add; |
102 to_add.matrix.applyPerspective(depth); | 101 to_add.matrix.ApplyPerspectiveDepth(depth); |
103 to_add.type = TransformOperation::TransformOperationPerspective; | 102 to_add.type = TransformOperation::TransformOperationPerspective; |
104 to_add.perspective_depth = depth; | 103 to_add.perspective_depth = depth; |
105 operations_.push_back(to_add); | 104 operations_.push_back(to_add); |
106 } | 105 } |
107 | 106 |
108 void TransformOperations::AppendMatrix(const WebTransformationMatrix& matrix) { | 107 void TransformOperations::AppendMatrix(const gfx::Transform& matrix) { |
109 TransformOperation to_add; | 108 TransformOperation to_add; |
110 to_add.matrix = matrix; | 109 to_add.matrix = matrix; |
111 to_add.type = TransformOperation::TransformOperationMatrix; | 110 to_add.type = TransformOperation::TransformOperationMatrix; |
112 operations_.push_back(to_add); | 111 operations_.push_back(to_add); |
113 } | 112 } |
114 | 113 |
115 void TransformOperations::AppendIdentity() { | 114 void TransformOperations::AppendIdentity() { |
116 operations_.push_back(TransformOperation()); | 115 operations_.push_back(TransformOperation()); |
117 } | 116 } |
118 | 117 |
119 bool TransformOperations::IsIdentity() const { | 118 bool TransformOperations::IsIdentity() const { |
120 for (size_t i = 0; i < operations_.size(); ++i) { | 119 for (size_t i = 0; i < operations_.size(); ++i) { |
121 if (!operations_[i].IsIdentity()) | 120 if (!operations_[i].IsIdentity()) |
122 return false; | 121 return false; |
123 } | 122 } |
124 return true; | 123 return true; |
125 } | 124 } |
126 | 125 |
127 bool TransformOperations::BlendInternal(const TransformOperations& from, | 126 bool TransformOperations::BlendInternal(const TransformOperations& from, |
128 double progress, | 127 double progress, |
129 WebTransformationMatrix& result) const { | 128 gfx::Transform& result) const { |
130 bool from_identity = from.IsIdentity(); | 129 bool from_identity = from.IsIdentity(); |
131 bool to_identity = IsIdentity(); | 130 bool to_identity = IsIdentity(); |
132 if (from_identity && to_identity) | 131 if (from_identity && to_identity) |
133 return true; | 132 return true; |
134 | 133 |
135 if (MatchesTypes(from)) { | 134 if (MatchesTypes(from)) { |
136 size_t num_operations = | 135 size_t num_operations = |
137 std::max(from_identity ? 0 : from.operations_.size(), | 136 std::max(from_identity ? 0 : from.operations_.size(), |
138 to_identity ? 0 : operations_.size()); | 137 to_identity ? 0 : operations_.size()); |
139 for (size_t i = 0; i < num_operations; ++i) { | 138 for (size_t i = 0; i < num_operations; ++i) { |
140 WebTransformationMatrix blended; | 139 gfx::Transform blended; |
141 if (!TransformOperation::BlendTransformOperations( | 140 if (!TransformOperation::BlendTransformOperations( |
142 from_identity ? 0 : &from.operations_[i], | 141 from_identity ? 0 : &from.operations_[i], |
143 to_identity ? 0 : &operations_[i], | 142 to_identity ? 0 : &operations_[i], |
144 progress, | 143 progress, |
145 blended)) | 144 blended)) |
146 return false; | 145 return false; |
147 result.multiply(blended); | 146 result.PreconcatTransform(blended); |
148 } | 147 } |
149 return true; | 148 return true; |
150 } | 149 } |
151 | 150 |
152 result = Apply(); | 151 result = Apply(); |
153 WebTransformationMatrix from_transform = from.Apply(); | 152 gfx::Transform from_transform = from.Apply(); |
154 return result.blend(from_transform, progress); | 153 return result.Blend(from_transform, progress); |
155 } | 154 } |
156 | 155 |
157 } // namespace cc | 156 } // namespace cc |
OLD | NEW |