forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCCLayerTreeHostCommonTest.cpp
3586 lines (2951 loc) · 197 KB
/
CCLayerTreeHostCommonTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
#include "CCLayerTreeHostCommon.h"
#include "CCAnimationTestCommon.h"
#include "CCGeometryTestUtils.h"
#include "CCLayerAnimationController.h"
#include "CCLayerImpl.h"
#include "CCLayerSorter.h"
#include "CCMathUtil.h"
#include "CCProxy.h"
#include "CCSingleThreadProxy.h"
#include "CCThread.h"
#include "ContentLayerChromium.h"
#include "ContentLayerChromiumClient.h"
#include "LayerChromium.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include <public/WebTransformationMatrix.h>
using namespace cc;
using namespace WebKitTests;
using WebKit::WebTransformationMatrix;
namespace {
template<typename LayerType>
void setLayerPropertiesForTesting(LayerType* layer, const WebTransformationMatrix& transform, const WebTransformationMatrix& sublayerTransform, const FloatPoint& anchor, const FloatPoint& position, const IntSize& bounds, bool preserves3D)
{
layer->setTransform(transform);
layer->setSublayerTransform(sublayerTransform);
layer->setAnchorPoint(anchor);
layer->setPosition(position);
layer->setBounds(bounds);
layer->setPreserves3D(preserves3D);
}
void setLayerPropertiesForTesting(LayerChromium* layer, const WebTransformationMatrix& transform, const WebTransformationMatrix& sublayerTransform, const FloatPoint& anchor, const FloatPoint& position, const IntSize& bounds, bool preserves3D)
{
setLayerPropertiesForTesting<LayerChromium>(layer, transform, sublayerTransform, anchor, position, bounds, preserves3D);
}
void setLayerPropertiesForTesting(CCLayerImpl* layer, const WebTransformationMatrix& transform, const WebTransformationMatrix& sublayerTransform, const FloatPoint& anchor, const FloatPoint& position, const IntSize& bounds, bool preserves3D)
{
setLayerPropertiesForTesting<CCLayerImpl>(layer, transform, sublayerTransform, anchor, position, bounds, preserves3D);
layer->setContentBounds(bounds);
}
void executeCalculateDrawTransformsAndVisibility(LayerChromium* rootLayer, float deviceScaleFactor = 1)
{
WebTransformationMatrix identityMatrix;
std::vector<scoped_refptr<LayerChromium> > dummyRenderSurfaceLayerList;
int dummyMaxTextureSize = 512;
IntSize deviceViewportSize = IntSize(rootLayer->bounds().width() * deviceScaleFactor, rootLayer->bounds().height() * deviceScaleFactor);
// We are probably not testing what is intended if the rootLayer bounds are empty.
ASSERT(!rootLayer->bounds().isEmpty());
CCLayerTreeHostCommon::calculateDrawTransforms(rootLayer, deviceViewportSize, deviceScaleFactor, dummyMaxTextureSize, dummyRenderSurfaceLayerList);
}
void executeCalculateDrawTransformsAndVisibility(CCLayerImpl* rootLayer, float deviceScaleFactor = 1)
{
// Note: this version skips layer sorting.
WebTransformationMatrix identityMatrix;
std::vector<CCLayerImpl*> dummyRenderSurfaceLayerList;
int dummyMaxTextureSize = 512;
IntSize deviceViewportSize = IntSize(rootLayer->bounds().width() * deviceScaleFactor, rootLayer->bounds().height() * deviceScaleFactor);
// We are probably not testing what is intended if the rootLayer bounds are empty.
ASSERT(!rootLayer->bounds().isEmpty());
CCLayerTreeHostCommon::calculateDrawTransforms(rootLayer, deviceViewportSize, deviceScaleFactor, 0, dummyMaxTextureSize, dummyRenderSurfaceLayerList);
}
WebTransformationMatrix remove3DComponentOfMatrix(const WebTransformationMatrix& mat)
{
WebTransformationMatrix ret = mat;
ret.setM13(0);
ret.setM23(0);
ret.setM31(0);
ret.setM32(0);
ret.setM33(1);
ret.setM34(0);
ret.setM43(0);
return ret;
}
PassOwnPtr<CCLayerImpl> createTreeForFixedPositionTests()
{
OwnPtr<CCLayerImpl> root = CCLayerImpl::create(1);
OwnPtr<CCLayerImpl> child = CCLayerImpl::create(2);
OwnPtr<CCLayerImpl> grandChild = CCLayerImpl::create(3);
OwnPtr<CCLayerImpl> greatGrandChild = CCLayerImpl::create(4);
WebTransformationMatrix IdentityMatrix;
FloatPoint anchor(0, 0);
FloatPoint position(0, 0);
IntSize bounds(100, 100);
setLayerPropertiesForTesting(root.get(), IdentityMatrix, IdentityMatrix, anchor, position, bounds, false);
setLayerPropertiesForTesting(child.get(), IdentityMatrix, IdentityMatrix, anchor, position, bounds, false);
setLayerPropertiesForTesting(grandChild.get(), IdentityMatrix, IdentityMatrix, anchor, position, bounds, false);
setLayerPropertiesForTesting(greatGrandChild.get(), IdentityMatrix, IdentityMatrix, anchor, position, bounds, false);
grandChild->addChild(greatGrandChild.release());
child->addChild(grandChild.release());
root->addChild(child.release());
return root.release();
}
class LayerChromiumWithForcedDrawsContent : public LayerChromium {
public:
LayerChromiumWithForcedDrawsContent()
: LayerChromium()
{
}
virtual bool drawsContent() const OVERRIDE { return true; }
private:
virtual ~LayerChromiumWithForcedDrawsContent()
{
}
};
class MockContentLayerChromiumClient : public ContentLayerChromiumClient {
public:
MockContentLayerChromiumClient() { }
virtual ~MockContentLayerChromiumClient() { }
virtual void paintContents(SkCanvas*, const IntRect& clip, FloatRect& opaque) OVERRIDE { }
};
scoped_refptr<ContentLayerChromium> createDrawableContentLayerChromium(ContentLayerChromiumClient* delegate)
{
scoped_refptr<ContentLayerChromium> toReturn = ContentLayerChromium::create(delegate);
toReturn->setIsDrawable(true);
return toReturn;
}
TEST(CCLayerTreeHostCommonTest, verifyTransformsForNoOpLayer)
{
// Sanity check: For layers positioned at zero, with zero size,
// and with identity transforms, then the drawTransform,
// screenSpaceTransform, and the hierarchy passed on to children
// layers should also be identity transforms.
scoped_refptr<LayerChromium> parent = LayerChromium::create();
scoped_refptr<LayerChromium> child = LayerChromium::create();
scoped_refptr<LayerChromium> grandChild = LayerChromium::create();
parent->addChild(child);
child->addChild(grandChild);
WebTransformationMatrix identityMatrix;
setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(0, 0), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(0, 0), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->screenSpaceTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyTransformsForSingleLayer)
{
WebTransformationMatrix identityMatrix;
scoped_refptr<LayerChromium> layer = LayerChromium::create();
// Case 1: setting the sublayer transform should not affect this layer's draw transform or screen-space transform.
WebTransformationMatrix arbitraryTranslation;
arbitraryTranslation.translate(10, 20);
setLayerPropertiesForTesting(layer.get(), identityMatrix, arbitraryTranslation, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
executeCalculateDrawTransformsAndVisibility(layer.get());
WebTransformationMatrix expectedDrawTransform = identityMatrix;
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedDrawTransform, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform());
// Case 2: Setting the bounds of the layer should not affect either the draw transform or the screenspace transform.
WebTransformationMatrix translationToCenter;
translationToCenter.translate(5, 6);
setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 12), false);
executeCalculateDrawTransformsAndVisibility(layer.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform());
// Case 3: The anchor point by itself (without a layer transform) should have no effect on the transforms.
setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false);
executeCalculateDrawTransformsAndVisibility(layer.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, layer->screenSpaceTransform());
// Case 4: A change in actual position affects both the draw transform and screen space transform.
WebTransformationMatrix positionTransform;
positionTransform.translate(0, 1.2);
setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 1.2f), IntSize(10, 12), false);
executeCalculateDrawTransformsAndVisibility(layer.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(positionTransform, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(positionTransform, layer->screenSpaceTransform());
// Case 5: In the correct sequence of transforms, the layer transform should pre-multiply the translationToCenter. This is easily tested by
// using a scale transform, because scale and translation are not commutative.
WebTransformationMatrix layerTransform;
layerTransform.scale3d(2, 2, 1);
setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(10, 12), false);
executeCalculateDrawTransformsAndVisibility(layer.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(layerTransform, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(layerTransform, layer->screenSpaceTransform());
// Case 6: The layer transform should occur with respect to the anchor point.
WebTransformationMatrix translationToAnchor;
translationToAnchor.translate(5, 0);
WebTransformationMatrix expectedResult = translationToAnchor * layerTransform * translationToAnchor.inverse();
setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, FloatPoint(0.5, 0), FloatPoint(0, 0), IntSize(10, 12), false);
executeCalculateDrawTransformsAndVisibility(layer.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->screenSpaceTransform());
// Case 7: Verify that position pre-multiplies the layer transform.
// The current implementation of calculateDrawTransforms does this implicitly, but it is
// still worth testing to detect accidental regressions.
expectedResult = positionTransform * translationToAnchor * layerTransform * translationToAnchor.inverse();
setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, FloatPoint(0.5, 0), FloatPoint(0, 1.2f), IntSize(10, 12), false);
executeCalculateDrawTransformsAndVisibility(layer.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedResult, layer->screenSpaceTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyTransformsForSimpleHierarchy)
{
WebTransformationMatrix identityMatrix;
scoped_refptr<LayerChromium> parent = LayerChromium::create();
scoped_refptr<LayerChromium> child = LayerChromium::create();
scoped_refptr<LayerChromium> grandChild = LayerChromium::create();
parent->addChild(child);
child->addChild(grandChild);
// Case 1: parent's anchorPoint should not affect child or grandChild.
setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->screenSpaceTransform());
// Case 2: parent's position affects child and grandChild.
WebTransformationMatrix parentPositionTransform;
parentPositionTransform.translate(0, 1.2);
setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 1.2f), IntSize(10, 12), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, child->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentPositionTransform, grandChild->screenSpaceTransform());
// Case 3: parent's local transform affects child and grandchild
WebTransformationMatrix parentLayerTransform;
parentLayerTransform.scale3d(2, 2, 1);
WebTransformationMatrix parentTranslationToAnchor;
parentTranslationToAnchor.translate(2.5, 3);
WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse();
setLayerPropertiesForTesting(parent.get(), parentLayerTransform, identityMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->screenSpaceTransform());
// Case 4: parent's sublayerMatrix affects child and grandchild
// scaling is used here again so that the correct sequence of transforms is properly tested.
// Note that preserves3D is false, but the sublayer matrix should retain its 3D properties when given to child.
// But then, the child also does not preserve3D. When it gives its hierarchy to the grandChild, it should be flattened to 2D.
WebTransformationMatrix parentSublayerMatrix;
parentSublayerMatrix.scale3d(10, 10, 3.3);
WebTransformationMatrix parentTranslationToCenter;
parentTranslationToCenter.translate(5, 6);
// Sublayer matrix is applied to the center of the parent layer.
parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse()
* parentTranslationToCenter * parentSublayerMatrix * parentTranslationToCenter.inverse();
WebTransformationMatrix flattenedCompositeTransform = remove3DComponentOfMatrix(parentCompositeTransform);
setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSublayerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(flattenedCompositeTransform, grandChild->screenSpaceTransform());
// Case 5: same as Case 4, except that child does preserve 3D, so the grandChild should receive the non-flattened composite transform.
//
setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSublayerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), true);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(76, 78), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, grandChild->screenSpaceTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyTransformsForSingleRenderSurface)
{
scoped_refptr<LayerChromium> parent = LayerChromium::create();
scoped_refptr<LayerChromium> child = LayerChromium::create();
scoped_refptr<LayerChromiumWithForcedDrawsContent> grandChild = make_scoped_refptr(new LayerChromiumWithForcedDrawsContent());
parent->addChild(child);
child->addChild(grandChild);
// Child is set up so that a new render surface should be created.
child->setOpacity(0.5);
WebTransformationMatrix identityMatrix;
WebTransformationMatrix parentLayerTransform;
parentLayerTransform.scale3d(1, 0.9, 1);
WebTransformationMatrix parentTranslationToAnchor;
parentTranslationToAnchor.translate(25, 30);
WebTransformationMatrix parentSublayerMatrix;
parentSublayerMatrix.scale3d(0.9, 1, 3.3);
WebTransformationMatrix parentTranslationToCenter;
parentTranslationToCenter.translate(50, 60);
WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse()
* parentTranslationToCenter * parentSublayerMatrix * parentTranslationToCenter.inverse();
// Child's render surface should not exist yet.
ASSERT_FALSE(child->renderSurface());
setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSublayerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(100, 120), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(8, 10), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
// Render surface should have been created now.
ASSERT_TRUE(child->renderSurface());
ASSERT_EQ(child, child->renderTarget());
// The child layer's draw transform should refer to its new render surface.
// The screen-space transform, however, should still refer to the root.
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->screenSpaceTransform());
// Because the grandChild is the only drawable content, the child's renderSurface will tighten its bounds to the grandChild.
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->renderTarget()->renderSurface()->drawTransform());
// The screen space is the same as the target since the child surface draws into the root.
EXPECT_TRANSFORMATION_MATRIX_EQ(parentCompositeTransform, child->renderTarget()->renderSurface()->screenSpaceTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyTransformsForReplica)
{
scoped_refptr<LayerChromium> parent = LayerChromium::create();
scoped_refptr<LayerChromium> child = LayerChromium::create();
scoped_refptr<LayerChromium> childReplica = LayerChromium::create();
scoped_refptr<LayerChromiumWithForcedDrawsContent> grandChild = make_scoped_refptr(new LayerChromiumWithForcedDrawsContent());
parent->addChild(child);
child->addChild(grandChild);
child->setReplicaLayer(childReplica.get());
// Child is set up so that a new render surface should be created.
child->setOpacity(0.5);
WebTransformationMatrix identityMatrix;
WebTransformationMatrix parentLayerTransform;
parentLayerTransform.scale3d(2, 2, 1);
WebTransformationMatrix parentTranslationToAnchor;
parentTranslationToAnchor.translate(2.5, 3);
WebTransformationMatrix parentSublayerMatrix;
parentSublayerMatrix.scale3d(10, 10, 3.3);
WebTransformationMatrix parentTranslationToCenter;
parentTranslationToCenter.translate(5, 6);
WebTransformationMatrix parentCompositeTransform = parentTranslationToAnchor * parentLayerTransform * parentTranslationToAnchor.inverse()
* parentTranslationToCenter * parentSublayerMatrix * parentTranslationToCenter.inverse();
WebTransformationMatrix childTranslationToCenter;
childTranslationToCenter.translate(8, 9);
WebTransformationMatrix replicaLayerTransform;
replicaLayerTransform.scale3d(3, 3, 1);
WebTransformationMatrix replicaCompositeTransform = parentCompositeTransform * replicaLayerTransform;
// Child's render surface should not exist yet.
ASSERT_FALSE(child->renderSurface());
setLayerPropertiesForTesting(parent.get(), parentLayerTransform, parentSublayerMatrix, FloatPoint(0.25, 0.25), FloatPoint(0, 0), IntSize(10, 12), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(16, 18), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(-0.5, -0.5), IntSize(1, 1), false);
setLayerPropertiesForTesting(childReplica.get(), replicaLayerTransform, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(0, 0), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
// Render surface should have been created now.
ASSERT_TRUE(child->renderSurface());
ASSERT_EQ(child, child->renderTarget());
EXPECT_TRANSFORMATION_MATRIX_EQ(replicaCompositeTransform, child->renderTarget()->renderSurface()->replicaDrawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(replicaCompositeTransform, child->renderTarget()->renderSurface()->replicaScreenSpaceTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyTransformsForRenderSurfaceHierarchy)
{
// This test creates a more complex tree and verifies it all at once. This covers the following cases:
// - layers that are described w.r.t. a render surface: should have draw transforms described w.r.t. that surface
// - A render surface described w.r.t. an ancestor render surface: should have a draw transform described w.r.t. that ancestor surface
// - Replicas of a render surface are described w.r.t. the replica's transform around its anchor, along with the surface itself.
// - Sanity check on recursion: verify transforms of layers described w.r.t. a render surface that is described w.r.t. an ancestor render surface.
// - verifying that each layer has a reference to the correct renderSurface and renderTarget values.
scoped_refptr<LayerChromium> parent = LayerChromium::create();
scoped_refptr<LayerChromium> renderSurface1 = LayerChromium::create();
scoped_refptr<LayerChromium> renderSurface2 = LayerChromium::create();
scoped_refptr<LayerChromium> childOfRoot = LayerChromium::create();
scoped_refptr<LayerChromium> childOfRS1 = LayerChromium::create();
scoped_refptr<LayerChromium> childOfRS2 = LayerChromium::create();
scoped_refptr<LayerChromium> replicaOfRS1 = LayerChromium::create();
scoped_refptr<LayerChromium> replicaOfRS2 = LayerChromium::create();
scoped_refptr<LayerChromium> grandChildOfRoot = LayerChromium::create();
scoped_refptr<LayerChromiumWithForcedDrawsContent> grandChildOfRS1 = make_scoped_refptr(new LayerChromiumWithForcedDrawsContent());
scoped_refptr<LayerChromiumWithForcedDrawsContent> grandChildOfRS2 = make_scoped_refptr(new LayerChromiumWithForcedDrawsContent());
parent->addChild(renderSurface1);
parent->addChild(childOfRoot);
renderSurface1->addChild(childOfRS1);
renderSurface1->addChild(renderSurface2);
renderSurface2->addChild(childOfRS2);
childOfRoot->addChild(grandChildOfRoot);
childOfRS1->addChild(grandChildOfRS1);
childOfRS2->addChild(grandChildOfRS2);
renderSurface1->setReplicaLayer(replicaOfRS1.get());
renderSurface2->setReplicaLayer(replicaOfRS2.get());
// In combination with descendantDrawsContent, opacity != 1 forces the layer to have a new renderSurface.
renderSurface1->setOpacity(0.5);
renderSurface2->setOpacity(0.33f);
// All layers in the tree are initialized with an anchor at .25 and a size of (10,10).
// matrix "A" is the composite layer transform used in all layers, centered about the anchor point
// matrix "B" is the sublayer transform used in all layers, centered about the center position of the layer.
// matrix "R" is the composite replica transform used in all replica layers.
//
// x component tests that layerTransform and sublayerTransform are done in the right order (translation and scale are noncommutative).
// y component has a translation by 1 for every ancestor, which indicates the "depth" of the layer in the hierarchy.
WebTransformationMatrix translationToAnchor;
translationToAnchor.translate(2.5, 0);
WebTransformationMatrix translationToCenter;
translationToCenter.translate(5, 5);
WebTransformationMatrix layerTransform;
layerTransform.translate(1, 1);
WebTransformationMatrix sublayerTransform;
sublayerTransform.scale3d(10, 1, 1);
WebTransformationMatrix replicaLayerTransform;
replicaLayerTransform.scale3d(-2, 5, 1);
WebTransformationMatrix A = translationToAnchor * layerTransform * translationToAnchor.inverse();
WebTransformationMatrix B = translationToCenter * sublayerTransform * translationToCenter.inverse();
WebTransformationMatrix R = A * translationToAnchor * replicaLayerTransform * translationToAnchor.inverse();
WebTransformationMatrix identityMatrix;
setLayerPropertiesForTesting(parent.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(renderSurface1.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(renderSurface2.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(childOfRoot.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(childOfRS1.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(childOfRS2.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(grandChildOfRoot.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(grandChildOfRS1.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(grandChildOfRS2.get(), layerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(10, 10), false);
setLayerPropertiesForTesting(replicaOfRS1.get(), replicaLayerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(), false);
setLayerPropertiesForTesting(replicaOfRS2.get(), replicaLayerTransform, sublayerTransform, FloatPoint(0.25, 0), FloatPoint(0, 0), IntSize(), false);
executeCalculateDrawTransformsAndVisibility(parent.get());
// Only layers that are associated with render surfaces should have an actual renderSurface() value.
//
ASSERT_TRUE(parent->renderSurface());
ASSERT_FALSE(childOfRoot->renderSurface());
ASSERT_FALSE(grandChildOfRoot->renderSurface());
ASSERT_TRUE(renderSurface1->renderSurface());
ASSERT_FALSE(childOfRS1->renderSurface());
ASSERT_FALSE(grandChildOfRS1->renderSurface());
ASSERT_TRUE(renderSurface2->renderSurface());
ASSERT_FALSE(childOfRS2->renderSurface());
ASSERT_FALSE(grandChildOfRS2->renderSurface());
// Verify all renderTarget accessors
//
EXPECT_EQ(parent, parent->renderTarget());
EXPECT_EQ(parent, childOfRoot->renderTarget());
EXPECT_EQ(parent, grandChildOfRoot->renderTarget());
EXPECT_EQ(renderSurface1, renderSurface1->renderTarget());
EXPECT_EQ(renderSurface1, childOfRS1->renderTarget());
EXPECT_EQ(renderSurface1, grandChildOfRS1->renderTarget());
EXPECT_EQ(renderSurface2, renderSurface2->renderTarget());
EXPECT_EQ(renderSurface2, childOfRS2->renderTarget());
EXPECT_EQ(renderSurface2, grandChildOfRS2->renderTarget());
// Verify layer draw transforms
// note that draw transforms are described with respect to the nearest ancestor render surface
// but screen space transforms are described with respect to the root.
//
EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A, childOfRoot->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A, grandChildOfRoot->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, renderSurface1->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(B * A, childOfRS1->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(B * A * B * A, grandChildOfRS1->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, renderSurface2->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(B * A, childOfRS2->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(B * A * B * A, grandChildOfRS2->drawTransform());
// Verify layer screen-space transforms
//
EXPECT_TRANSFORMATION_MATRIX_EQ(A, parent->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A, childOfRoot->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A, grandChildOfRoot->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A, renderSurface1->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A, childOfRS1->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A * B * A, grandChildOfRS1->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A, renderSurface2->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A * B * A, childOfRS2->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A * B * A * B * A, grandChildOfRS2->screenSpaceTransform());
// Verify render surface transforms.
//
// Draw transform of render surface 1 is described with respect to root.
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A, renderSurface1->renderSurface()->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * R, renderSurface1->renderSurface()->replicaDrawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A, renderSurface1->renderSurface()->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * R, renderSurface1->renderSurface()->replicaScreenSpaceTransform());
// Draw transform of render surface 2 is described with respect to render surface 2.
EXPECT_TRANSFORMATION_MATRIX_EQ(B * A, renderSurface2->renderSurface()->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(B * R, renderSurface2->renderSurface()->replicaDrawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * A, renderSurface2->renderSurface()->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(A * B * A * B * R, renderSurface2->renderSurface()->replicaScreenSpaceTransform());
// Sanity check. If these fail there is probably a bug in the test itself.
// It is expected that we correctly set up transforms so that the y-component of the screen-space transform
// encodes the "depth" of the layer in the tree.
EXPECT_FLOAT_EQ(1, parent->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(2, childOfRoot->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(3, grandChildOfRoot->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(2, renderSurface1->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(3, childOfRS1->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(4, grandChildOfRS1->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(3, renderSurface2->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(4, childOfRS2->screenSpaceTransform().m42());
EXPECT_FLOAT_EQ(5, grandChildOfRS2->screenSpaceTransform().m42());
}
TEST(CCLayerTreeHostCommonTest, verifyTransformsForFlatteningLayer)
{
// For layers that flatten their subtree, there should be an orthographic projection
// (for x and y values) in the middle of the transform sequence. Note that the way the
// code is currently implemented, it is not expected to use a canonical orthographic
// projection.
scoped_refptr<LayerChromium> root = LayerChromium::create();
scoped_refptr<LayerChromium> child = LayerChromium::create();
scoped_refptr<LayerChromiumWithForcedDrawsContent> grandChild = make_scoped_refptr(new LayerChromiumWithForcedDrawsContent());
WebTransformationMatrix rotationAboutYAxis;
rotationAboutYAxis.rotate3d(0, 30, 0);
const WebTransformationMatrix identityMatrix;
setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(100, 100), false);
setLayerPropertiesForTesting(child.get(), rotationAboutYAxis, identityMatrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false);
setLayerPropertiesForTesting(grandChild.get(), rotationAboutYAxis, identityMatrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false);
root->addChild(child);
child->addChild(grandChild);
child->setForceRenderSurface(true);
// No layers in this test should preserve 3d.
ASSERT_FALSE(root->preserves3D());
ASSERT_FALSE(child->preserves3D());
ASSERT_FALSE(grandChild->preserves3D());
WebTransformationMatrix expectedChildDrawTransform = rotationAboutYAxis;
WebTransformationMatrix expectedChildScreenSpaceTransform = rotationAboutYAxis;
WebTransformationMatrix expectedGrandChildDrawTransform = rotationAboutYAxis; // draws onto child's renderSurface
WebTransformationMatrix expectedGrandChildScreenSpaceTransform = rotationAboutYAxis.to2dTransform() * rotationAboutYAxis;
executeCalculateDrawTransformsAndVisibility(root.get());
// The child's drawTransform should have been taken by its surface.
ASSERT_TRUE(child->renderSurface());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildDrawTransform, child->renderSurface()->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildScreenSpaceTransform, child->renderSurface()->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildScreenSpaceTransform, child->screenSpaceTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildDrawTransform, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildScreenSpaceTransform, grandChild->screenSpaceTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyTransformsForDegenerateIntermediateLayer)
{
// A layer that is empty in one axis, but not the other, was accidentally skipping a necessary translation.
// Without that translation, the coordinate space of the layer's drawTransform is incorrect.
//
// Normally this isn't a problem, because the layer wouldn't be drawn anyway, but if that layer becomes a renderSurface, then
// its drawTransform is implicitly inherited by the rest of the subtree, which then is positioned incorrectly as a result.
scoped_refptr<LayerChromium> root = LayerChromium::create();
scoped_refptr<LayerChromium> child = LayerChromium::create();
scoped_refptr<LayerChromiumWithForcedDrawsContent> grandChild = make_scoped_refptr(new LayerChromiumWithForcedDrawsContent());
// The child height is zero, but has non-zero width that should be accounted for while computing drawTransforms.
const WebTransformationMatrix identityMatrix;
setLayerPropertiesForTesting(root.get(), identityMatrix, identityMatrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(100, 100), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 0), false);
setLayerPropertiesForTesting(grandChild.get(), identityMatrix, identityMatrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false);
root->addChild(child);
child->addChild(grandChild);
child->setForceRenderSurface(true);
executeCalculateDrawTransformsAndVisibility(root.get());
ASSERT_TRUE(child->renderSurface());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->renderSurface()->drawTransform()); // This is the real test, the rest are sanity checks.
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(identityMatrix, grandChild->drawTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyRenderSurfaceListForRenderSurfaceWithClippedLayer)
{
scoped_refptr<LayerChromium> parent = LayerChromium::create();
scoped_refptr<LayerChromium> renderSurface1 = LayerChromium::create();
scoped_refptr<LayerChromiumWithForcedDrawsContent> child = make_scoped_refptr(new LayerChromiumWithForcedDrawsContent());
const WebTransformationMatrix identityMatrix;
setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false);
setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityMatrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint::zero(), FloatPoint(30, 30), IntSize(10, 10), false);
parent->addChild(renderSurface1);
parent->setMasksToBounds(true);
renderSurface1->addChild(child);
renderSurface1->setForceRenderSurface(true);
std::vector<scoped_refptr<LayerChromium> > renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
// The child layer's content is entirely outside the parent's clip rect, so the intermediate
// render surface should not be listed here, even if it was forced to be created. Render surfaces without children or visible
// content are unexpected at draw time (e.g. we might try to create a content texture of size 0).
ASSERT_TRUE(parent->renderSurface());
ASSERT_FALSE(renderSurface1->renderSurface());
EXPECT_EQ(1U, renderSurfaceLayerList.size());
}
TEST(CCLayerTreeHostCommonTest, verifyRenderSurfaceListForTransparentChild)
{
scoped_refptr<LayerChromium> parent = LayerChromium::create();
scoped_refptr<LayerChromium> renderSurface1 = LayerChromium::create();
scoped_refptr<LayerChromiumWithForcedDrawsContent> child = make_scoped_refptr(new LayerChromiumWithForcedDrawsContent());
const WebTransformationMatrix identityMatrix;
setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityMatrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false);
parent->addChild(renderSurface1);
renderSurface1->addChild(child);
renderSurface1->setForceRenderSurface(true);
renderSurface1->setOpacity(0);
std::vector<scoped_refptr<LayerChromium> > renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
// Since the layer is transparent, renderSurface1->renderSurface() should not have gotten added anywhere.
// Also, the drawable content rect should not have been extended by the children.
ASSERT_TRUE(parent->renderSurface());
EXPECT_EQ(0U, parent->renderSurface()->layerList().size());
EXPECT_EQ(1U, renderSurfaceLayerList.size());
EXPECT_EQ(parent->id(), renderSurfaceLayerList[0]->id());
EXPECT_EQ(IntRect(), parent->drawableContentRect());
}
TEST(CCLayerTreeHostCommonTest, verifyForceRenderSurface)
{
scoped_refptr<LayerChromium> parent = LayerChromium::create();
scoped_refptr<LayerChromium> renderSurface1 = LayerChromium::create();
scoped_refptr<LayerChromiumWithForcedDrawsContent> child = make_scoped_refptr(new LayerChromiumWithForcedDrawsContent());
renderSurface1->setForceRenderSurface(true);
const WebTransformationMatrix identityMatrix;
setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false);
setLayerPropertiesForTesting(renderSurface1.get(), identityMatrix, identityMatrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false);
setLayerPropertiesForTesting(child.get(), identityMatrix, identityMatrix, FloatPoint::zero(), FloatPoint::zero(), IntSize(10, 10), false);
parent->addChild(renderSurface1);
renderSurface1->addChild(child);
// Sanity check before the actual test
EXPECT_FALSE(parent->renderSurface());
EXPECT_FALSE(renderSurface1->renderSurface());
std::vector<scoped_refptr<LayerChromium> > renderSurfaceLayerList;
int dummyMaxTextureSize = 512;
CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
// The root layer always creates a renderSurface
EXPECT_TRUE(parent->renderSurface());
EXPECT_TRUE(renderSurface1->renderSurface());
EXPECT_EQ(2U, renderSurfaceLayerList.size());
renderSurfaceLayerList.clear();
renderSurface1->setForceRenderSurface(false);
CCLayerTreeHostCommon::calculateDrawTransforms(parent.get(), parent->bounds(), 1, dummyMaxTextureSize, renderSurfaceLayerList);
EXPECT_TRUE(parent->renderSurface());
EXPECT_FALSE(renderSurface1->renderSurface());
EXPECT_EQ(1U, renderSurfaceLayerList.size());
}
TEST(CCLayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithDirectContainer)
{
// This test checks for correct scroll compensation when the fixed-position container
// is the direct parent of the fixed-position layer.
DebugScopedSetImplThread scopedImplThread;
OwnPtr<CCLayerImpl> root = createTreeForFixedPositionTests();
CCLayerImpl* child = root->children()[0];
CCLayerImpl* grandChild = child->children()[0];
child->setIsContainerForFixedPositionLayers(true);
grandChild->setFixedToContainerLayer(true);
// Case 1: scrollDelta of 0, 0
child->setScrollDelta(IntSize(0, 0));
executeCalculateDrawTransformsAndVisibility(root.get());
WebTransformationMatrix expectedChildTransform;
WebTransformationMatrix expectedGrandChildTransform = expectedChildTransform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
// Case 2: scrollDelta of 10, 10
child->setScrollDelta(IntSize(10, 10));
executeCalculateDrawTransformsAndVisibility(root.get());
// Here the child is affected by scrollDelta, but the fixed position grandChild should not be affected.
expectedChildTransform.makeIdentity();
expectedChildTransform.translate(-10, -10);
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithTransformedDirectContainer)
{
// This test checks for correct scroll compensation when the fixed-position container
// is the direct parent of the fixed-position layer, but that container is transformed.
// In this case, the fixed position element inherits the container's transform,
// but the scrollDelta that has to be undone should not be affected by that transform.
//
// Transforms are in general non-commutative; using something like a non-uniform scale
// helps to verify that translations and non-uniform scales are applied in the correct
// order.
DebugScopedSetImplThread scopedImplThread;
OwnPtr<CCLayerImpl> root = createTreeForFixedPositionTests();
CCLayerImpl* child = root->children()[0];
CCLayerImpl* grandChild = child->children()[0];
// This scale will cause child and grandChild to be effectively 200 x 800 with respect to the renderTarget.
WebTransformationMatrix nonUniformScale;
nonUniformScale.scaleNonUniform(2, 8);
child->setTransform(nonUniformScale);
child->setIsContainerForFixedPositionLayers(true);
grandChild->setFixedToContainerLayer(true);
// Case 1: scrollDelta of 0, 0
child->setScrollDelta(IntSize(0, 0));
executeCalculateDrawTransformsAndVisibility(root.get());
WebTransformationMatrix expectedChildTransform;
expectedChildTransform.multiply(nonUniformScale);
WebTransformationMatrix expectedGrandChildTransform = expectedChildTransform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
// Case 2: scrollDelta of 10, 20
child->setScrollDelta(IntSize(10, 20));
executeCalculateDrawTransformsAndVisibility(root.get());
// The child should be affected by scrollDelta, but the fixed position grandChild should not be affected.
expectedChildTransform.makeIdentity();
expectedChildTransform.translate(-10, -20); // scrollDelta
expectedChildTransform.multiply(nonUniformScale);
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithDistantContainer)
{
// This test checks for correct scroll compensation when the fixed-position container
// is NOT the direct parent of the fixed-position layer.
DebugScopedSetImplThread scopedImplThread;
OwnPtr<CCLayerImpl> root = createTreeForFixedPositionTests();
CCLayerImpl* child = root->children()[0];
CCLayerImpl* grandChild = child->children()[0];
CCLayerImpl* greatGrandChild = grandChild->children()[0];
child->setIsContainerForFixedPositionLayers(true);
grandChild->setPosition(FloatPoint(8, 6));
greatGrandChild->setFixedToContainerLayer(true);
// Case 1: scrollDelta of 0, 0
child->setScrollDelta(IntSize(0, 0));
executeCalculateDrawTransformsAndVisibility(root.get());
WebTransformationMatrix expectedChildTransform;
WebTransformationMatrix expectedGrandChildTransform;
expectedGrandChildTransform.translate(8, 6);
WebTransformationMatrix expectedGreatGrandChildTransform = expectedGrandChildTransform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrandChild->drawTransform());
// Case 2: scrollDelta of 10, 10
child->setScrollDelta(IntSize(10, 10));
executeCalculateDrawTransformsAndVisibility(root.get());
// Here the child and grandChild are affected by scrollDelta, but the fixed position greatGrandChild should not be affected.
expectedChildTransform.makeIdentity();
expectedChildTransform.translate(-10, -10);
expectedGrandChildTransform.makeIdentity();
expectedGrandChildTransform.translate(-2, -4);
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrandChild->drawTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithDistantContainerAndTransforms)
{
// This test checks for correct scroll compensation when the fixed-position container
// is NOT the direct parent of the fixed-position layer, and the hierarchy has various
// transforms that have to be processed in the correct order.
DebugScopedSetImplThread scopedImplThread;
OwnPtr<CCLayerImpl> root = createTreeForFixedPositionTests();
CCLayerImpl* child = root->children()[0];
CCLayerImpl* grandChild = child->children()[0];
CCLayerImpl* greatGrandChild = grandChild->children()[0];
WebTransformationMatrix rotationAboutZ;
rotationAboutZ.rotate3d(0, 0, 90);
child->setIsContainerForFixedPositionLayers(true);
child->setTransform(rotationAboutZ);
grandChild->setPosition(FloatPoint(8, 6));
grandChild->setTransform(rotationAboutZ);
greatGrandChild->setFixedToContainerLayer(true); // greatGrandChild is positioned upside-down with respect to the renderTarget.
// Case 1: scrollDelta of 0, 0
child->setScrollDelta(IntSize(0, 0));
executeCalculateDrawTransformsAndVisibility(root.get());
WebTransformationMatrix expectedChildTransform;
expectedChildTransform.multiply(rotationAboutZ);
WebTransformationMatrix expectedGrandChildTransform;
expectedGrandChildTransform.multiply(rotationAboutZ); // child's local transform is inherited
expectedGrandChildTransform.translate(8, 6); // translation because of position occurs before layer's local transform.
expectedGrandChildTransform.multiply(rotationAboutZ); // grandChild's local transform
WebTransformationMatrix expectedGreatGrandChildTransform = expectedGrandChildTransform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrandChild->drawTransform());
// Case 2: scrollDelta of 10, 20
child->setScrollDelta(IntSize(10, 20));
executeCalculateDrawTransformsAndVisibility(root.get());
// Here the child and grandChild are affected by scrollDelta, but the fixed position greatGrandChild should not be affected.
expectedChildTransform.makeIdentity();
expectedChildTransform.translate(-10, -20); // scrollDelta
expectedChildTransform.multiply(rotationAboutZ);
expectedGrandChildTransform.makeIdentity();
expectedGrandChildTransform.translate(-10, -20); // child's scrollDelta is inherited
expectedGrandChildTransform.multiply(rotationAboutZ); // child's local transform is inherited
expectedGrandChildTransform.translate(8, 6); // translation because of position occurs before layer's local transform.
expectedGrandChildTransform.multiply(rotationAboutZ); // grandChild's local transform
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrandChild->drawTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithMultipleScrollDeltas)
{
// This test checks for correct scroll compensation when the fixed-position container
// has multiple ancestors that have nonzero scrollDelta before reaching the space where the layer is fixed.
// In this test, each scrollDelta occurs in a different space because of each layer's local transform.
// This test checks for correct scroll compensation when the fixed-position container
// is NOT the direct parent of the fixed-position layer, and the hierarchy has various
// transforms that have to be processed in the correct order.
DebugScopedSetImplThread scopedImplThread;
OwnPtr<CCLayerImpl> root = createTreeForFixedPositionTests();
CCLayerImpl* child = root->children()[0];
CCLayerImpl* grandChild = child->children()[0];
CCLayerImpl* greatGrandChild = grandChild->children()[0];
WebTransformationMatrix rotationAboutZ;
rotationAboutZ.rotate3d(0, 0, 90);
child->setIsContainerForFixedPositionLayers(true);
child->setTransform(rotationAboutZ);
grandChild->setPosition(FloatPoint(8, 6));
grandChild->setTransform(rotationAboutZ);
greatGrandChild->setFixedToContainerLayer(true); // greatGrandChild is positioned upside-down with respect to the renderTarget.
// Case 1: scrollDelta of 0, 0
child->setScrollDelta(IntSize(0, 0));
executeCalculateDrawTransformsAndVisibility(root.get());
WebTransformationMatrix expectedChildTransform;
expectedChildTransform.multiply(rotationAboutZ);
WebTransformationMatrix expectedGrandChildTransform;
expectedGrandChildTransform.multiply(rotationAboutZ); // child's local transform is inherited
expectedGrandChildTransform.translate(8, 6); // translation because of position occurs before layer's local transform.
expectedGrandChildTransform.multiply(rotationAboutZ); // grandChild's local transform
WebTransformationMatrix expectedGreatGrandChildTransform = expectedGrandChildTransform;
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrandChild->drawTransform());
// Case 2: scrollDelta of 10, 20
child->setScrollDelta(IntSize(10, 0));
grandChild->setScrollDelta(IntSize(5, 0));
executeCalculateDrawTransformsAndVisibility(root.get());
// Here the child and grandChild are affected by scrollDelta, but the fixed position greatGrandChild should not be affected.
expectedChildTransform.makeIdentity();
expectedChildTransform.translate(-10, 0); // scrollDelta
expectedChildTransform.multiply(rotationAboutZ);
expectedGrandChildTransform.makeIdentity();
expectedGrandChildTransform.translate(-10, 0); // child's scrollDelta is inherited
expectedGrandChildTransform.multiply(rotationAboutZ); // child's local transform is inherited
expectedGrandChildTransform.translate(-5, 0); // grandChild's scrollDelta
expectedGrandChildTransform.translate(8, 6); // translation because of position occurs before layer's local transform.
expectedGrandChildTransform.multiply(rotationAboutZ); // grandChild's local transform
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedChildTransform, child->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGrandChildTransform, grandChild->drawTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(expectedGreatGrandChildTransform, greatGrandChild->drawTransform());
}
TEST(CCLayerTreeHostCommonTest, verifyScrollCompensationForFixedPositionLayerWithIntermediateSurfaceAndTransforms)
{
// This test checks for correct scroll compensation when the fixed-position container
// contributes to a different renderSurface than the fixed-position layer. In this
// case, the surface drawTransforms also have to be accounted for when checking the
// scrollDelta.
DebugScopedSetImplThread scopedImplThread;
OwnPtr<CCLayerImpl> root = createTreeForFixedPositionTests();
CCLayerImpl* child = root->children()[0];
CCLayerImpl* grandChild = child->children()[0];
CCLayerImpl* greatGrandChild = grandChild->children()[0];
child->setIsContainerForFixedPositionLayers(true);
grandChild->setPosition(FloatPoint(8, 6));
grandChild->setForceRenderSurface(true);
greatGrandChild->setFixedToContainerLayer(true);