Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: cc/animation/transform_operations.cc

Issue 2971503002: Transform animations should not collapse by default when interpolating (Closed)
Patch Set: . Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/animation/transform_operations.h ('k') | cc/animation/transform_operations_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Needed on Windows to get |M_PI| from <cmath> 5 // Needed on Windows to get |M_PI| from <cmath>
6 #ifdef _WIN32 6 #ifdef _WIN32
7 #define _USE_MATH_DEFINES 7 #define _USE_MATH_DEFINES
8 #endif 8 #endif
9 9
10 #include "cc/animation/transform_operations.h" 10 #include "cc/animation/transform_operations.h"
(...skipping 19 matching lines...) Expand all
30 decomposed_transform_dirty_ = other.decomposed_transform_dirty_; 30 decomposed_transform_dirty_ = other.decomposed_transform_dirty_;
31 if (!decomposed_transform_dirty_) { 31 if (!decomposed_transform_dirty_) {
32 decomposed_transform_.reset( 32 decomposed_transform_.reset(
33 new gfx::DecomposedTransform(*other.decomposed_transform_.get())); 33 new gfx::DecomposedTransform(*other.decomposed_transform_.get()));
34 } 34 }
35 } 35 }
36 36
37 TransformOperations::~TransformOperations() { 37 TransformOperations::~TransformOperations() {
38 } 38 }
39 39
40 TransformOperations& TransformOperations::operator=(
41 const TransformOperations& other) {
42 operations_ = other.operations_;
43 decomposed_transform_dirty_ = other.decomposed_transform_dirty_;
44 if (!decomposed_transform_dirty_) {
45 decomposed_transform_.reset(
46 new gfx::DecomposedTransform(*other.decomposed_transform_.get()));
47 }
48 return *this;
49 }
50
40 gfx::Transform TransformOperations::Apply() const { 51 gfx::Transform TransformOperations::Apply() const {
41 gfx::Transform to_return; 52 gfx::Transform to_return;
42 for (size_t i = 0; i < operations_.size(); ++i) 53 for (size_t i = 0; i < operations_.size(); ++i)
43 to_return.PreconcatTransform(operations_[i].matrix); 54 to_return.PreconcatTransform(operations_[i].matrix);
44 return to_return; 55 return to_return;
45 } 56 }
46 57
47 gfx::Transform TransformOperations::Blend(const TransformOperations& from, 58 TransformOperations TransformOperations::Blend(const TransformOperations& from,
48 SkMScalar progress) const { 59 SkMScalar progress) const {
49 gfx::Transform to_return; 60 TransformOperations to_return;
50 BlendInternal(from, progress, &to_return); 61 BlendInternal(from, progress, &to_return);
51 return to_return; 62 return to_return;
52 } 63 }
53 64
54 bool TransformOperations::BlendedBoundsForBox(const gfx::BoxF& box, 65 bool TransformOperations::BlendedBoundsForBox(const gfx::BoxF& box,
55 const TransformOperations& from, 66 const TransformOperations& from,
56 SkMScalar min_progress, 67 SkMScalar min_progress,
57 SkMScalar max_progress, 68 SkMScalar max_progress,
58 gfx::BoxF* bounds) const { 69 gfx::BoxF* bounds) const {
59 *bounds = box; 70 *bounds = box;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 for (size_t i = 0; i < operations_.size(); ++i) { 196 for (size_t i = 0; i < operations_.size(); ++i) {
186 if (operations_[i].type != other.operations_[i].type) 197 if (operations_[i].type != other.operations_[i].type)
187 return false; 198 return false;
188 } 199 }
189 200
190 return true; 201 return true;
191 } 202 }
192 203
193 bool TransformOperations::CanBlendWith( 204 bool TransformOperations::CanBlendWith(
194 const TransformOperations& other) const { 205 const TransformOperations& other) const {
195 gfx::Transform dummy; 206 TransformOperations dummy;
196 return BlendInternal(other, 0.5, &dummy); 207 return BlendInternal(other, 0.5, &dummy);
197 } 208 }
198 209
199 void TransformOperations::AppendTranslate(SkMScalar x, 210 void TransformOperations::AppendTranslate(SkMScalar x,
200 SkMScalar y, 211 SkMScalar y,
201 SkMScalar z) { 212 SkMScalar z) {
202 TransformOperation to_add; 213 TransformOperation to_add;
203 to_add.matrix.Translate3d(x, y, z); 214 to_add.matrix.Translate3d(x, y, z);
204 to_add.type = TransformOperation::TRANSFORM_OPERATION_TRANSLATE; 215 to_add.type = TransformOperation::TRANSFORM_OPERATION_TRANSLATE;
205 to_add.translate.x = x; 216 to_add.translate.x = x;
206 to_add.translate.y = y; 217 to_add.translate.y = y;
207 to_add.translate.z = z; 218 to_add.translate.z = z;
208 operations_.push_back(to_add); 219 operations_.push_back(to_add);
209 decomposed_transform_dirty_ = true; 220 decomposed_transform_dirty_ = true;
210 } 221 }
211 222
212 void TransformOperations::AppendRotate(SkMScalar x, 223 void TransformOperations::AppendRotate(SkMScalar x,
213 SkMScalar y, 224 SkMScalar y,
214 SkMScalar z, 225 SkMScalar z,
215 SkMScalar degrees) { 226 SkMScalar degrees) {
216 TransformOperation to_add; 227 TransformOperation to_add;
217 to_add.matrix.RotateAbout(gfx::Vector3dF(x, y, z), degrees);
218 to_add.type = TransformOperation::TRANSFORM_OPERATION_ROTATE; 228 to_add.type = TransformOperation::TRANSFORM_OPERATION_ROTATE;
219 to_add.rotate.axis.x = x; 229 to_add.rotate.axis.x = x;
220 to_add.rotate.axis.y = y; 230 to_add.rotate.axis.y = y;
221 to_add.rotate.axis.z = z; 231 to_add.rotate.axis.z = z;
222 to_add.rotate.angle = degrees; 232 to_add.rotate.angle = degrees;
233 to_add.Bake();
223 operations_.push_back(to_add); 234 operations_.push_back(to_add);
224 decomposed_transform_dirty_ = true; 235 decomposed_transform_dirty_ = true;
225 } 236 }
226 237
227 void TransformOperations::AppendScale(SkMScalar x, SkMScalar y, SkMScalar z) { 238 void TransformOperations::AppendScale(SkMScalar x, SkMScalar y, SkMScalar z) {
228 TransformOperation to_add; 239 TransformOperation to_add;
229 to_add.matrix.Scale3d(x, y, z);
230 to_add.type = TransformOperation::TRANSFORM_OPERATION_SCALE; 240 to_add.type = TransformOperation::TRANSFORM_OPERATION_SCALE;
231 to_add.scale.x = x; 241 to_add.scale.x = x;
232 to_add.scale.y = y; 242 to_add.scale.y = y;
233 to_add.scale.z = z; 243 to_add.scale.z = z;
244 to_add.Bake();
234 operations_.push_back(to_add); 245 operations_.push_back(to_add);
235 decomposed_transform_dirty_ = true; 246 decomposed_transform_dirty_ = true;
236 } 247 }
237 248
238 void TransformOperations::AppendSkew(SkMScalar x, SkMScalar y) { 249 void TransformOperations::AppendSkew(SkMScalar x, SkMScalar y) {
239 TransformOperation to_add; 250 TransformOperation to_add;
240 to_add.matrix.Skew(x, y);
241 to_add.type = TransformOperation::TRANSFORM_OPERATION_SKEW; 251 to_add.type = TransformOperation::TRANSFORM_OPERATION_SKEW;
242 to_add.skew.x = x; 252 to_add.skew.x = x;
243 to_add.skew.y = y; 253 to_add.skew.y = y;
254 to_add.Bake();
244 operations_.push_back(to_add); 255 operations_.push_back(to_add);
245 decomposed_transform_dirty_ = true; 256 decomposed_transform_dirty_ = true;
246 } 257 }
247 258
248 void TransformOperations::AppendPerspective(SkMScalar depth) { 259 void TransformOperations::AppendPerspective(SkMScalar depth) {
249 TransformOperation to_add; 260 TransformOperation to_add;
250 to_add.matrix.ApplyPerspectiveDepth(depth);
251 to_add.type = TransformOperation::TRANSFORM_OPERATION_PERSPECTIVE; 261 to_add.type = TransformOperation::TRANSFORM_OPERATION_PERSPECTIVE;
252 to_add.perspective_depth = depth; 262 to_add.perspective_depth = depth;
263 to_add.Bake();
253 operations_.push_back(to_add); 264 operations_.push_back(to_add);
254 decomposed_transform_dirty_ = true; 265 decomposed_transform_dirty_ = true;
255 } 266 }
256 267
257 void TransformOperations::AppendMatrix(const gfx::Transform& matrix) { 268 void TransformOperations::AppendMatrix(const gfx::Transform& matrix) {
258 TransformOperation to_add; 269 TransformOperation to_add;
259 to_add.matrix = matrix; 270 to_add.matrix = matrix;
260 to_add.type = TransformOperation::TRANSFORM_OPERATION_MATRIX; 271 to_add.type = TransformOperation::TRANSFORM_OPERATION_MATRIX;
261 operations_.push_back(to_add); 272 operations_.push_back(to_add);
262 decomposed_transform_dirty_ = true; 273 decomposed_transform_dirty_ = true;
263 } 274 }
264 275
265 void TransformOperations::AppendIdentity() { 276 void TransformOperations::AppendIdentity() {
266 operations_.push_back(TransformOperation()); 277 operations_.push_back(TransformOperation());
267 } 278 }
268 279
269 bool TransformOperations::IsIdentity() const { 280 bool TransformOperations::IsIdentity() const {
270 for (size_t i = 0; i < operations_.size(); ++i) { 281 for (size_t i = 0; i < operations_.size(); ++i) {
271 if (!operations_[i].IsIdentity()) 282 if (!operations_[i].IsIdentity())
272 return false; 283 return false;
273 } 284 }
274 return true; 285 return true;
275 } 286 }
276 287
288 void TransformOperations::Append(const TransformOperation& operation) {
289 operations_.push_back(operation);
290 }
291
277 bool TransformOperations::BlendInternal(const TransformOperations& from, 292 bool TransformOperations::BlendInternal(const TransformOperations& from,
278 SkMScalar progress, 293 SkMScalar progress,
279 gfx::Transform* result) const { 294 TransformOperations* result) const {
280 bool from_identity = from.IsIdentity(); 295 bool from_identity = from.IsIdentity();
281 bool to_identity = IsIdentity(); 296 bool to_identity = IsIdentity();
282 if (from_identity && to_identity) 297 if (from_identity && to_identity)
283 return true; 298 return true;
284 299
285 if (MatchesTypes(from)) { 300 if (MatchesTypes(from)) {
286 size_t num_operations = 301 size_t num_operations =
287 std::max(from_identity ? 0 : from.operations_.size(), 302 std::max(from_identity ? 0 : from.operations_.size(),
288 to_identity ? 0 : operations_.size()); 303 to_identity ? 0 : operations_.size());
289 for (size_t i = 0; i < num_operations; ++i) { 304 for (size_t i = 0; i < num_operations; ++i) {
290 gfx::Transform blended; 305 TransformOperation blended;
291 if (!TransformOperation::BlendTransformOperations( 306 if (!TransformOperation::BlendTransformOperations(
292 from_identity ? 0 : &from.operations_[i], 307 from_identity ? 0 : &from.operations_[i],
293 to_identity ? 0 : &operations_[i], 308 to_identity ? 0 : &operations_[i], progress, &blended)) {
294 progress, 309 return false;
295 &blended)) 310 }
296 return false; 311 result->Append(blended);
297 result->PreconcatTransform(blended);
298 } 312 }
299 return true; 313 return true;
300 } 314 }
301 315
302 if (!ComputeDecomposedTransform() || !from.ComputeDecomposedTransform()) 316 if (!ComputeDecomposedTransform() || !from.ComputeDecomposedTransform())
303 return false; 317 return false;
304 318
305 gfx::DecomposedTransform to_return; 319 gfx::DecomposedTransform to_return;
306 to_return = gfx::BlendDecomposedTransforms(*decomposed_transform_.get(), 320 to_return = gfx::BlendDecomposedTransforms(*decomposed_transform_.get(),
307 *from.decomposed_transform_.get(), 321 *from.decomposed_transform_.get(),
308 progress); 322 progress);
309 323
310 *result = ComposeTransform(to_return); 324 result->AppendMatrix(ComposeTransform(to_return));
311 return true; 325 return true;
312 } 326 }
313 327
314 bool TransformOperations::ComputeDecomposedTransform() const { 328 bool TransformOperations::ComputeDecomposedTransform() const {
315 if (decomposed_transform_dirty_) { 329 if (decomposed_transform_dirty_) {
316 if (!decomposed_transform_) 330 if (!decomposed_transform_)
317 decomposed_transform_.reset(new gfx::DecomposedTransform()); 331 decomposed_transform_.reset(new gfx::DecomposedTransform());
318 gfx::Transform transform = Apply(); 332 gfx::Transform transform = Apply();
319 if (!gfx::DecomposeTransform(decomposed_transform_.get(), transform)) 333 if (!gfx::DecomposeTransform(decomposed_transform_.get(), transform))
320 return false; 334 return false;
321 decomposed_transform_dirty_ = false; 335 decomposed_transform_dirty_ = false;
322 } 336 }
323 return true; 337 return true;
324 } 338 }
325 339
326 } // namespace cc 340 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/transform_operations.h ('k') | cc/animation/transform_operations_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698