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

Side by Side Diff: webkit/compositor/WebTransformOperationsTest.cpp

Issue 10909020: Enable webkit_compositor_unittests (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 3 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
OLDNEW
(Empty)
1 // Copyright 2012 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.
4
5 #include "config.h"
6
7 #include <public/WebTransformOperations.h>
8
9 #include <public/WebTransformationMatrix.h>
10
11 #include "CCLayerTreeTestCommon.h"
12
13 #include <gtest/gtest.h>
14 #include <wtf/OwnPtr.h>
15 #include <wtf/PassOwnPtr.h>
16 #include <wtf/Vector.h>
17
18 using namespace std;
19 using namespace WebKit;
20
21 TEST(WebTransformOperationTest, transformTypesAreUnique)
22 {
23 Vector<OwnPtr<WebTransformOperations> > transforms;
24
25 WebTransformOperations* toAdd = new WebTransformOperations();
26 toAdd->appendTranslate(1, 0, 0);
27 transforms.append(adoptPtr(toAdd));
28
29 toAdd = new WebTransformOperations();
30 toAdd->appendRotate(0, 0, 1, 2);
31 transforms.append(adoptPtr(toAdd));
32
33 toAdd = new WebTransformOperations();
34 toAdd->appendScale(2, 2, 2);
35 transforms.append(adoptPtr(toAdd));
36
37 toAdd = new WebTransformOperations();
38 toAdd->appendSkew(1, 0);
39 transforms.append(adoptPtr(toAdd));
40
41 toAdd = new WebTransformOperations();
42 toAdd->appendPerspective(800);
43 transforms.append(adoptPtr(toAdd));
44
45 for (size_t i = 0; i < transforms.size(); ++i) {
46 for (size_t j = 0; j < transforms.size(); ++j) {
47 bool matchesType = transforms[i]->matchesTypes(*transforms[j]);
48 EXPECT_TRUE((i == j && matchesType) || !matchesType);
49 }
50 }
51 }
52
53 TEST(WebTransformOperationTest, matchTypesSameLength)
54 {
55 WebTransformOperations translates;
56 translates.appendTranslate(1, 0, 0);
57 translates.appendTranslate(1, 0, 0);
58 translates.appendTranslate(1, 0, 0);
59
60 WebTransformOperations skews;
61 skews.appendSkew(0, 2);
62 skews.appendSkew(0, 2);
63 skews.appendSkew(0, 2);
64
65 WebTransformOperations translates2;
66 translates2.appendTranslate(0, 2, 0);
67 translates2.appendTranslate(0, 2, 0);
68 translates2.appendTranslate(0, 2, 0);
69
70 WebTransformOperations translates3 = translates2;
71
72 EXPECT_FALSE(translates.matchesTypes(skews));
73 EXPECT_TRUE(translates.matchesTypes(translates2));
74 EXPECT_TRUE(translates.matchesTypes(translates3));
75 }
76
77 TEST(WebTransformOperationTest, matchTypesDifferentLength)
78 {
79 WebTransformOperations translates;
80 translates.appendTranslate(1, 0, 0);
81 translates.appendTranslate(1, 0, 0);
82 translates.appendTranslate(1, 0, 0);
83
84 WebTransformOperations skews;
85 skews.appendSkew(2, 0);
86 skews.appendSkew(2, 0);
87
88 WebTransformOperations translates2;
89 translates2.appendTranslate(0, 2, 0);
90 translates2.appendTranslate(0, 2, 0);
91
92 EXPECT_FALSE(translates.matchesTypes(skews));
93 EXPECT_FALSE(translates.matchesTypes(translates2));
94 }
95
96 void getIdentityOperations(Vector<OwnPtr<WebTransformOperations> >* operations)
97 {
98 WebTransformOperations* toAdd = new WebTransformOperations();
99 operations->append(adoptPtr(toAdd));
100
101 toAdd = new WebTransformOperations();
102 toAdd->appendTranslate(0, 0, 0);
103 operations->append(adoptPtr(toAdd));
104
105 toAdd = new WebTransformOperations();
106 toAdd->appendTranslate(0, 0, 0);
107 toAdd->appendTranslate(0, 0, 0);
108 operations->append(adoptPtr(toAdd));
109
110 toAdd = new WebTransformOperations();
111 toAdd->appendScale(1, 1, 1);
112 operations->append(adoptPtr(toAdd));
113
114 toAdd = new WebTransformOperations();
115 toAdd->appendScale(1, 1, 1);
116 toAdd->appendScale(1, 1, 1);
117 operations->append(adoptPtr(toAdd));
118
119 toAdd = new WebTransformOperations();
120 toAdd->appendSkew(0, 0);
121 operations->append(adoptPtr(toAdd));
122
123 toAdd = new WebTransformOperations();
124 toAdd->appendSkew(0, 0);
125 toAdd->appendSkew(0, 0);
126 operations->append(adoptPtr(toAdd));
127
128 toAdd = new WebTransformOperations();
129 toAdd->appendRotate(0, 0, 1, 0);
130 operations->append(adoptPtr(toAdd));
131
132 toAdd = new WebTransformOperations();
133 toAdd->appendRotate(0, 0, 1, 0);
134 toAdd->appendRotate(0, 0, 1, 0);
135 operations->append(adoptPtr(toAdd));
136
137 toAdd = new WebTransformOperations();
138 toAdd->appendMatrix(WebTransformationMatrix());
139 operations->append(adoptPtr(toAdd));
140
141 toAdd = new WebTransformOperations();
142 toAdd->appendMatrix(WebTransformationMatrix());
143 toAdd->appendMatrix(WebTransformationMatrix());
144 operations->append(adoptPtr(toAdd));
145 }
146
147 TEST(WebTransformOperationTest, identityAlwaysMatches)
148 {
149 Vector<OwnPtr<WebTransformOperations> > operations;
150 getIdentityOperations(&operations);
151
152 for (size_t i = 0; i < operations.size(); ++i) {
153 for (size_t j = 0; j < operations.size(); ++j)
154 EXPECT_TRUE(operations[i]->matchesTypes(*operations[j]));
155 }
156 }
157
158 TEST(WebTransformOperationTest, applyTranslate)
159 {
160 double x = 1;
161 double y = 2;
162 double z = 3;
163 WebTransformOperations operations;
164 operations.appendTranslate(x, y, z);
165 WebTransformationMatrix expected;
166 expected.translate3d(x, y, z);
167 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, operations.apply());
168 }
169
170 TEST(WebTransformOperationTest, applyRotate)
171 {
172 double x = 1;
173 double y = 2;
174 double z = 3;
175 double degrees = 80;
176 WebTransformOperations operations;
177 operations.appendRotate(x, y, z, degrees);
178 WebTransformationMatrix expected;
179 expected.rotate3d(x, y, z, degrees);
180 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, operations.apply());
181 }
182
183 TEST(WebTransformOperationTest, applyScale)
184 {
185 double x = 1;
186 double y = 2;
187 double z = 3;
188 WebTransformOperations operations;
189 operations.appendScale(x, y, z);
190 WebTransformationMatrix expected;
191 expected.scale3d(x, y, z);
192 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, operations.apply());
193 }
194
195 TEST(WebTransformOperationTest, applySkew)
196 {
197 double x = 1;
198 double y = 2;
199 WebTransformOperations operations;
200 operations.appendSkew(x, y);
201 WebTransformationMatrix expected;
202 expected.skewX(x);
203 expected.skewY(y);
204 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, operations.apply());
205 }
206
207 TEST(WebTransformOperationTest, applyPerspective)
208 {
209 double depth = 800;
210 WebTransformOperations operations;
211 operations.appendPerspective(depth);
212 WebTransformationMatrix expected;
213 expected.applyPerspective(depth);
214 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, operations.apply());
215 }
216
217 TEST(WebTransformOperationTest, applyMatrix)
218 {
219 double dx = 1;
220 double dy = 2;
221 double dz = 3;
222 WebTransformationMatrix expectedMatrix;
223 expectedMatrix.translate3d(dx, dy, dz);
224 WebTransformOperations matrixTransform;
225 matrixTransform.appendMatrix(expectedMatrix);
226 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedMatrix, matrixTransform.apply());
227 }
228
229 TEST(WebTransformOperationTest, applyOrder)
230 {
231 double sx = 2;
232 double sy = 4;
233 double sz = 8;
234
235 double dx = 1;
236 double dy = 2;
237 double dz = 3;
238
239 WebTransformOperations operations;
240 operations.appendScale(sx, sy, sz);
241 operations.appendTranslate(dx, dy, dz);
242
243 WebTransformationMatrix expectedScaleMatrix;
244 expectedScaleMatrix.scale3d(sx, sy, sz);
245
246 WebTransformationMatrix expectedTranslateMatrix;
247 expectedTranslateMatrix.translate3d(dx, dy, dz);
248
249 WebTransformationMatrix expectedCombinedMatrix = expectedScaleMatrix;
250 expectedCombinedMatrix.multiply(expectedTranslateMatrix);
251
252 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedCombinedMatrix, operations.apply());
253 }
254
255 TEST(WebTransformOperationTest, blendOrder)
256 {
257 double sx1 = 2;
258 double sy1 = 4;
259 double sz1 = 8;
260
261 double dx1 = 1;
262 double dy1 = 2;
263 double dz1 = 3;
264
265 double sx2 = 4;
266 double sy2 = 8;
267 double sz2 = 16;
268
269 double dx2 = 10;
270 double dy2 = 20;
271 double dz2 = 30;
272
273 WebTransformOperations operationsFrom;
274 operationsFrom.appendScale(sx1, sy1, sz1);
275 operationsFrom.appendTranslate(dx1, dy1, dz1);
276
277 WebTransformOperations operationsTo;
278 operationsTo.appendScale(sx2, sy2, sz2);
279 operationsTo.appendTranslate(dx2, dy2, dz2);
280
281 WebTransformationMatrix scaleFrom;
282 scaleFrom.scale3d(sx1, sy1, sz1);
283 WebTransformationMatrix translateFrom;
284 translateFrom.translate3d(dx1, dy1, dz1);
285
286 WebTransformationMatrix scaleTo;
287 scaleTo.scale3d(sx2, sy2, sz2);
288 WebTransformationMatrix translateTo;
289 translateTo.translate3d(dx2, dy2, dz2);
290
291 double progress = 0.25;
292
293 WebTransformationMatrix blendedScale = scaleTo;
294 blendedScale.blend(scaleFrom, progress);
295
296 WebTransformationMatrix blendedTranslate = translateTo;
297 blendedTranslate.blend(translateFrom, progress);
298
299 WebTransformationMatrix expected = blendedScale;
300 expected.multiply(blendedTranslate);
301
302 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, operationsTo.blend(operationsFrom, progress));
303 }
304
305 static void checkProgress(double progress,
306 const WebTransformationMatrix& fromMatrix,
307 const WebTransformationMatrix& toMatrix,
308 const WebTransformOperations& fromTransform,
309 const WebTransformOperations& toTransform)
310 {
311 WebTransformationMatrix expectedMatrix = toMatrix;
312 expectedMatrix.blend(fromMatrix, progress);
313 EXPECT_TRANSFORMATION_MATRIX_EQ(expectedMatrix, toTransform.blend(fromTransf orm, progress));
314 }
315
316 TEST(WebTransformOperationTest, blendProgress)
317 {
318 double sx = 2;
319 double sy = 4;
320 double sz = 8;
321 WebTransformOperations operationsFrom;
322 operationsFrom.appendScale(sx, sy, sz);
323
324 WebTransformationMatrix matrixFrom;
325 matrixFrom.scale3d(sx, sy, sz);
326
327 sx = 4;
328 sy = 8;
329 sz = 16;
330 WebTransformOperations operationsTo;
331 operationsTo.appendScale(sx, sy, sz);
332
333 WebTransformationMatrix matrixTo;
334 matrixTo.scale3d(sx, sy, sz);
335
336 checkProgress(-1, matrixFrom, matrixTo, operationsFrom, operationsTo);
337 checkProgress(0, matrixFrom, matrixTo, operationsFrom, operationsTo);
338 checkProgress(0.25, matrixFrom, matrixTo, operationsFrom, operationsTo);
339 checkProgress(0.5, matrixFrom, matrixTo, operationsFrom, operationsTo);
340 checkProgress(1, matrixFrom, matrixTo, operationsFrom, operationsTo);
341 checkProgress(2, matrixFrom, matrixTo, operationsFrom, operationsTo);
342 }
343
344 TEST(WebTransformOperationTest, blendWhenTypesDoNotMatch)
345 {
346 double sx1 = 2;
347 double sy1 = 4;
348 double sz1 = 8;
349
350 double dx1 = 1;
351 double dy1 = 2;
352 double dz1 = 3;
353
354 double sx2 = 4;
355 double sy2 = 8;
356 double sz2 = 16;
357
358 double dx2 = 10;
359 double dy2 = 20;
360 double dz2 = 30;
361
362 WebTransformOperations operationsFrom;
363 operationsFrom.appendScale(sx1, sy1, sz1);
364 operationsFrom.appendTranslate(dx1, dy1, dz1);
365
366 WebTransformOperations operationsTo;
367 operationsTo.appendTranslate(dx2, dy2, dz2);
368 operationsTo.appendScale(sx2, sy2, sz2);
369
370 WebTransformationMatrix from;
371 from.scale3d(sx1, sy1, sz1);
372 from.translate3d(dx1, dy1, dz1);
373
374 WebTransformationMatrix to;
375 to.translate3d(dx2, dy2, dz2);
376 to.scale3d(sx2, sy2, sz2);
377
378 double progress = 0.25;
379
380 WebTransformationMatrix expected = to;
381 expected.blend(from, progress);
382
383 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, operationsTo.blend(operationsFrom, progress));
384 }
385
386 TEST(WebTransformOperationTest, largeRotationsWithSameAxis)
387 {
388 WebTransformOperations operationsFrom;
389 operationsFrom.appendRotate(0, 0, 1, 0);
390
391 WebTransformOperations operationsTo;
392 operationsTo.appendRotate(0, 0, 2, 360);
393
394 double progress = 0.5;
395
396 WebTransformationMatrix expected;
397 expected.rotate3d(0, 0, 1, 180);
398
399 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, operationsTo.blend(operationsFrom, progress));
400 }
401
402 TEST(WebTransformOperationTest, largeRotationsWithSameAxisInDifferentDirection)
403 {
404 WebTransformOperations operationsFrom;
405 operationsFrom.appendRotate(0, 0, 1, 180);
406
407 WebTransformOperations operationsTo;
408 operationsTo.appendRotate(0, 0, -1, 180);
409
410 double progress = 0.5;
411
412 WebTransformationMatrix expected;
413
414 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, operationsTo.blend(operationsFrom, progress));
415 }
416
417 TEST(WebTransformOperationTest, largeRotationsWithDifferentAxes)
418 {
419 WebTransformOperations operationsFrom;
420 operationsFrom.appendRotate(0, 0, 1, 180);
421
422 WebTransformOperations operationsTo;
423 operationsTo.appendRotate(0, 1, 0, 180);
424
425 double progress = 0.5;
426 WebTransformationMatrix matrixFrom;
427 matrixFrom.rotate3d(0, 0, 1, 180);
428
429 WebTransformationMatrix matrixTo;
430 matrixTo.rotate3d(0, 1, 0, 180);
431
432 WebTransformationMatrix expected = matrixTo;
433 expected.blend(matrixFrom, progress);
434
435 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, operationsTo.blend(operationsFrom, progress));
436 }
437
438 TEST(WebTransformOperationTest, blendRotationFromIdentity)
439 {
440 Vector<OwnPtr<WebTransformOperations> > identityOperations;
441 getIdentityOperations(&identityOperations);
442
443 for (size_t i = 0; i < identityOperations.size(); ++i) {
444 WebTransformOperations operations;
445 operations.appendRotate(0, 0, 1, 360);
446
447 double progress = 0.5;
448
449 WebTransformationMatrix expected;
450 expected.rotate3d(0, 0, 1, 180);
451
452 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, operations.blend(*identityOper ations[i], progress));
453 }
454 }
455
456 TEST(WebTransformOperationTest, blendTranslationFromIdentity)
457 {
458 Vector<OwnPtr<WebTransformOperations> > identityOperations;
459 getIdentityOperations(&identityOperations);
460
461 for (size_t i = 0; i < identityOperations.size(); ++i) {
462 WebTransformOperations operations;
463 operations.appendTranslate(2, 2, 2);
464
465 double progress = 0.5;
466
467 WebTransformationMatrix expected;
468 expected.translate3d(1, 1, 1);
469
470 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, operations.blend(*identityOper ations[i], progress));
471 }
472 }
473
474 TEST(WebTransformOperationTest, blendScaleFromIdentity)
475 {
476 Vector<OwnPtr<WebTransformOperations> > identityOperations;
477 getIdentityOperations(&identityOperations);
478
479 for (size_t i = 0; i < identityOperations.size(); ++i) {
480 WebTransformOperations operations;
481 operations.appendScale(3, 3, 3);
482
483 double progress = 0.5;
484
485 WebTransformationMatrix expected;
486 expected.scale3d(2, 2, 2);
487
488 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, operations.blend(*identityOper ations[i], progress));
489 }
490 }
491
492 TEST(WebTransformOperationTest, blendSkewFromIdentity)
493 {
494 Vector<OwnPtr<WebTransformOperations> > identityOperations;
495 getIdentityOperations(&identityOperations);
496
497 for (size_t i = 0; i < identityOperations.size(); ++i) {
498 WebTransformOperations operations;
499 operations.appendSkew(2, 2);
500
501 double progress = 0.5;
502
503 WebTransformationMatrix expected;
504 expected.skewX(1);
505 expected.skewY(1);
506
507 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, operations.blend(*identityOper ations[i], progress));
508 }
509 }
510
511 TEST(WebTransformOperationTest, blendPerspectiveFromIdentity)
512 {
513 Vector<OwnPtr<WebTransformOperations> > identityOperations;
514 getIdentityOperations(&identityOperations);
515
516 for (size_t i = 0; i < identityOperations.size(); ++i) {
517 WebTransformOperations operations;
518 operations.appendPerspective(1000);
519
520 double progress = 0.5;
521
522 WebTransformationMatrix expected;
523 expected.applyPerspective(500 + 0.5 * numeric_limits<double>::max());
524
525 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, operations.blend(*identityOper ations[i], progress));
526 }
527 }
528
529 TEST(WebTransformOperationTest, blendRotationToIdentity)
530 {
531 Vector<OwnPtr<WebTransformOperations> > identityOperations;
532 getIdentityOperations(&identityOperations);
533
534 for (size_t i = 0; i < identityOperations.size(); ++i) {
535 WebTransformOperations operations;
536 operations.appendRotate(0, 0, 1, 360);
537
538 double progress = 0.5;
539
540 WebTransformationMatrix expected;
541 expected.rotate3d(0, 0, 1, 180);
542
543 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, identityOperations[i]->blend(o perations, progress));
544 }
545 }
546
547 TEST(WebTransformOperationTest, blendTranslationToIdentity)
548 {
549 Vector<OwnPtr<WebTransformOperations> > identityOperations;
550 getIdentityOperations(&identityOperations);
551
552 for (size_t i = 0; i < identityOperations.size(); ++i) {
553 WebTransformOperations operations;
554 operations.appendTranslate(2, 2, 2);
555
556 double progress = 0.5;
557
558 WebTransformationMatrix expected;
559 expected.translate3d(1, 1, 1);
560
561 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, identityOperations[i]->blend(o perations, progress));
562 }
563 }
564
565 TEST(WebTransformOperationTest, blendScaleToIdentity)
566 {
567 Vector<OwnPtr<WebTransformOperations> > identityOperations;
568 getIdentityOperations(&identityOperations);
569
570 for (size_t i = 0; i < identityOperations.size(); ++i) {
571 WebTransformOperations operations;
572 operations.appendScale(3, 3, 3);
573
574 double progress = 0.5;
575
576 WebTransformationMatrix expected;
577 expected.scale3d(2, 2, 2);
578
579 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, identityOperations[i]->blend(o perations, progress));
580 }
581 }
582
583 TEST(WebTransformOperationTest, blendSkewToIdentity)
584 {
585 Vector<OwnPtr<WebTransformOperations> > identityOperations;
586 getIdentityOperations(&identityOperations);
587
588 for (size_t i = 0; i < identityOperations.size(); ++i) {
589 WebTransformOperations operations;
590 operations.appendSkew(2, 2);
591
592 double progress = 0.5;
593
594 WebTransformationMatrix expected;
595 expected.skewX(1);
596 expected.skewY(1);
597
598 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, identityOperations[i]->blend(o perations, progress));
599 }
600 }
601
602 TEST(WebTransformOperationTest, blendPerspectiveToIdentity)
603 {
604 Vector<OwnPtr<WebTransformOperations> > identityOperations;
605 getIdentityOperations(&identityOperations);
606
607 for (size_t i = 0; i < identityOperations.size(); ++i) {
608 WebTransformOperations operations;
609 operations.appendPerspective(1000);
610
611 double progress = 0.5;
612
613 WebTransformationMatrix expected;
614 expected.applyPerspective(500 + 0.5 * numeric_limits<double>::max());
615
616 EXPECT_TRANSFORMATION_MATRIX_EQ(expected, identityOperations[i]->blend(o perations, progress));
617 }
618 }
619
OLDNEW
« no previous file with comments | « webkit/compositor/WebLayerTreeViewTest.cpp ('k') | webkit/compositor/WebTransformationMatrixTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698