forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delegated_renderer_layer_impl_unittest.cc
1541 lines (1288 loc) · 59.6 KB
/
delegated_renderer_layer_impl_unittest.cc
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 2012 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 "cc/layers/delegated_renderer_layer_impl.h"
#include "cc/base/scoped_ptr_vector.h"
#include "cc/layers/solid_color_layer_impl.h"
#include "cc/quads/render_pass_draw_quad.h"
#include "cc/quads/solid_color_draw_quad.h"
#include "cc/test/fake_delegated_renderer_layer_impl.h"
#include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/fake_layer_tree_host_impl_client.h"
#include "cc/test/fake_output_surface.h"
#include "cc/test/fake_proxy.h"
#include "cc/test/fake_rendering_stats_instrumentation.h"
#include "cc/test/geometry_test_utils.h"
#include "cc/test/layer_test_common.h"
#include "cc/test/render_pass_test_common.h"
#include "cc/test/render_pass_test_utils.h"
#include "cc/test/test_shared_bitmap_manager.h"
#include "cc/test/test_web_graphics_context_3d.h"
#include "cc/trees/layer_tree_host_impl.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/single_thread_proxy.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/frame_time.h"
#include "ui/gfx/transform.h"
namespace cc {
namespace {
class DelegatedRendererLayerImplTest : public testing::Test {
public:
DelegatedRendererLayerImplTest()
: proxy_(),
always_impl_thread_and_main_thread_blocked_(&proxy_) {
LayerTreeSettings settings;
settings.minimum_occlusion_tracking_size = gfx::Size();
host_impl_.reset(
new FakeLayerTreeHostImpl(settings, &proxy_, &shared_bitmap_manager_));
host_impl_->InitializeRenderer(
FakeOutputSurface::Create3d().PassAs<OutputSurface>());
host_impl_->SetViewportSize(gfx::Size(10, 10));
}
protected:
FakeProxy proxy_;
DebugScopedSetImplThreadAndMainThreadBlocked
always_impl_thread_and_main_thread_blocked_;
TestSharedBitmapManager shared_bitmap_manager_;
scoped_ptr<LayerTreeHostImpl> host_impl_;
};
class DelegatedRendererLayerImplTestSimple
: public DelegatedRendererLayerImplTest {
public:
DelegatedRendererLayerImplTestSimple()
: DelegatedRendererLayerImplTest() {
scoped_ptr<LayerImpl> root_layer = SolidColorLayerImpl::Create(
host_impl_->active_tree(), 1).PassAs<LayerImpl>();
scoped_ptr<LayerImpl> layer_before = SolidColorLayerImpl::Create(
host_impl_->active_tree(), 2).PassAs<LayerImpl>();
scoped_ptr<LayerImpl> layer_after = SolidColorLayerImpl::Create(
host_impl_->active_tree(), 3).PassAs<LayerImpl>();
scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer =
FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 4);
host_impl_->SetViewportSize(gfx::Size(100, 100));
root_layer->SetBounds(gfx::Size(100, 100));
layer_before->SetPosition(gfx::Point(20, 20));
layer_before->SetBounds(gfx::Size(14, 14));
layer_before->SetContentBounds(gfx::Size(14, 14));
layer_before->SetDrawsContent(true);
layer_before->SetForceRenderSurface(true);
layer_after->SetPosition(gfx::Point(5, 5));
layer_after->SetBounds(gfx::Size(15, 15));
layer_after->SetContentBounds(gfx::Size(15, 15));
layer_after->SetDrawsContent(true);
layer_after->SetForceRenderSurface(true);
delegated_renderer_layer->SetPosition(gfx::Point(3, 3));
delegated_renderer_layer->SetBounds(gfx::Size(10, 10));
delegated_renderer_layer->SetContentBounds(gfx::Size(10, 10));
delegated_renderer_layer->SetDrawsContent(true);
gfx::Transform transform;
transform.Translate(1.0, 1.0);
delegated_renderer_layer->SetTransform(transform);
RenderPassList delegated_render_passes;
TestRenderPass* pass1 = AddRenderPass(&delegated_render_passes,
RenderPass::Id(9, 6),
gfx::Rect(6, 6, 6, 6),
gfx::Transform(1, 0, 0, 1, 5, 6));
AddQuad(pass1, gfx::Rect(0, 0, 6, 6), 33u);
TestRenderPass* pass2 = AddRenderPass(&delegated_render_passes,
RenderPass::Id(9, 7),
gfx::Rect(7, 7, 7, 7),
gfx::Transform(1, 0, 0, 1, 7, 8));
AddQuad(pass2, gfx::Rect(0, 0, 7, 7), 22u);
AddRenderPassQuad(pass2, pass1);
TestRenderPass* pass3 = AddRenderPass(&delegated_render_passes,
RenderPass::Id(9, 8),
gfx::Rect(0, 0, 8, 8),
gfx::Transform(1, 0, 0, 1, 9, 10));
AddRenderPassQuad(pass3, pass2);
delegated_renderer_layer->SetFrameDataForRenderPasses(
1.f, &delegated_render_passes);
// The RenderPasses should be taken by the layer.
EXPECT_EQ(0u, delegated_render_passes.size());
root_layer_ = root_layer.get();
layer_before_ = layer_before.get();
layer_after_ = layer_after.get();
delegated_renderer_layer_ = delegated_renderer_layer.get();
// Force the delegated RenderPasses to come before the RenderPass from
// layer_after.
layer_after->AddChild(delegated_renderer_layer.PassAs<LayerImpl>());
root_layer->AddChild(layer_after.Pass());
// Get the RenderPass generated by layer_before to come before the delegated
// RenderPasses.
root_layer->AddChild(layer_before.Pass());
host_impl_->active_tree()->SetRootLayer(root_layer.Pass());
}
protected:
LayerImpl* root_layer_;
LayerImpl* layer_before_;
LayerImpl* layer_after_;
DelegatedRendererLayerImpl* delegated_renderer_layer_;
};
TEST_F(DelegatedRendererLayerImplTestSimple, AddsContributingRenderPasses) {
LayerTreeHostImpl::FrameData frame;
EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// Each non-DelegatedRendererLayer added one RenderPass. The
// DelegatedRendererLayer added two contributing passes.
ASSERT_EQ(5u, frame.render_passes.size());
// The DelegatedRendererLayer should have added its contributing RenderPasses
// to the frame.
EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
EXPECT_EQ(1, frame.render_passes[1]->id.index);
EXPECT_EQ(4, frame.render_passes[2]->id.layer_id);
EXPECT_EQ(2, frame.render_passes[2]->id.index);
// And all other RenderPasses should be non-delegated.
EXPECT_NE(4, frame.render_passes[0]->id.layer_id);
EXPECT_EQ(0, frame.render_passes[0]->id.index);
EXPECT_NE(4, frame.render_passes[3]->id.layer_id);
EXPECT_EQ(0, frame.render_passes[3]->id.index);
EXPECT_NE(4, frame.render_passes[4]->id.layer_id);
EXPECT_EQ(0, frame.render_passes[4]->id.index);
// The DelegatedRendererLayer should have added its RenderPasses to the frame
// in order.
EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
frame.render_passes[1]->output_rect.ToString());
EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
frame.render_passes[2]->output_rect.ToString());
host_impl_->DrawLayers(&frame);
host_impl_->DidDrawAllLayers(frame);
}
TEST_F(DelegatedRendererLayerImplTestSimple,
AddsQuadsToContributingRenderPasses) {
LayerTreeHostImpl::FrameData frame;
EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// Each non-DelegatedRendererLayer added one RenderPass. The
// DelegatedRendererLayer added two contributing passes.
ASSERT_EQ(5u, frame.render_passes.size());
// The DelegatedRendererLayer should have added its contributing RenderPasses
// to the frame.
EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
EXPECT_EQ(1, frame.render_passes[1]->id.index);
EXPECT_EQ(4, frame.render_passes[2]->id.layer_id);
EXPECT_EQ(2, frame.render_passes[2]->id.index);
// The DelegatedRendererLayer should have added copies of its quads to
// contributing RenderPasses.
ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
frame.render_passes[1]->quad_list[0]->rect.ToString());
// Verify it added the right quads.
ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
EXPECT_EQ(gfx::Rect(0, 0, 7, 7).ToString(),
frame.render_passes[2]->quad_list[0]->rect.ToString());
EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
frame.render_passes[2]->quad_list[1]->rect.ToString());
ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
frame.render_passes[1]->quad_list[0]->rect.ToString());
host_impl_->DrawLayers(&frame);
host_impl_->DidDrawAllLayers(frame);
}
TEST_F(DelegatedRendererLayerImplTestSimple, AddsQuadsToTargetRenderPass) {
LayerTreeHostImpl::FrameData frame;
EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// Each non-DelegatedRendererLayer added one RenderPass. The
// DelegatedRendererLayer added two contributing passes.
ASSERT_EQ(5u, frame.render_passes.size());
// The layer's target is the RenderPass from layer_after_.
EXPECT_EQ(RenderPass::Id(3, 0), frame.render_passes[3]->id);
// The DelegatedRendererLayer should have added copies of quads in its root
// RenderPass to its target RenderPass. The layer_after_ also adds one quad.
ASSERT_EQ(2u, frame.render_passes[3]->quad_list.size());
// Verify it added the right quads.
EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
frame.render_passes[3]->quad_list[0]->rect.ToString());
// Its target layer should have a quad as well.
EXPECT_EQ(gfx::Rect(0, 0, 15, 15).ToString(),
frame.render_passes[3]->quad_list[1]->rect.ToString());
host_impl_->DrawLayers(&frame);
host_impl_->DidDrawAllLayers(frame);
}
TEST_F(DelegatedRendererLayerImplTestSimple,
QuadsFromRootRenderPassAreModifiedForTheTarget) {
LayerTreeHostImpl::FrameData frame;
EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// Each non-DelegatedRendererLayer added one RenderPass. The
// DelegatedRendererLayer added two contributing passes.
ASSERT_EQ(5u, frame.render_passes.size());
// The DelegatedRendererLayer is at position 3,3 compared to its target, and
// has a translation transform of 1,1. So its root RenderPass' quads should
// all be transformed by that combined amount.
gfx::Transform transform;
transform.Translate(4.0, 4.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(
transform, frame.render_passes[3]->quad_list[0]->quadTransform());
// Quads from non-root RenderPasses should not be shifted though.
ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
EXPECT_TRANSFORMATION_MATRIX_EQ(
gfx::Transform(), frame.render_passes[2]->quad_list[0]->quadTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
gfx::Transform(), frame.render_passes[2]->quad_list[1]->quadTransform());
ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
EXPECT_TRANSFORMATION_MATRIX_EQ(
gfx::Transform(), frame.render_passes[1]->quad_list[0]->quadTransform());
host_impl_->DrawLayers(&frame);
host_impl_->DidDrawAllLayers(frame);
}
TEST_F(DelegatedRendererLayerImplTestSimple, RenderPassTransformIsModified) {
LayerTreeHostImpl::FrameData frame;
EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// The delegated layer has a surface between it and the root.
EXPECT_TRUE(delegated_renderer_layer_->render_target()->parent());
// Each non-DelegatedRendererLayer added one RenderPass. The
// DelegatedRendererLayer added two contributing passes.
ASSERT_EQ(5u, frame.render_passes.size());
// The DelegatedRendererLayer is at position 9,9 compared to the root, so all
// render pass' transforms to the root should be shifted by this amount.
gfx::Transform transform;
transform.Translate(9.0, 9.0);
// The first contributing surface has a translation of 5, 6.
gfx::Transform five_six(1, 0, 0, 1, 5, 6);
// The second contributing surface has a translation of 7, 8.
gfx::Transform seven_eight(1, 0, 0, 1, 7, 8);
EXPECT_TRANSFORMATION_MATRIX_EQ(
transform * five_six, frame.render_passes[1]->transform_to_root_target);
EXPECT_TRANSFORMATION_MATRIX_EQ(
transform * seven_eight,
frame.render_passes[2]->transform_to_root_target);
host_impl_->DrawLayers(&frame);
host_impl_->DidDrawAllLayers(frame);
}
TEST_F(DelegatedRendererLayerImplTestSimple, DoesNotOwnARenderSurface) {
LayerTreeHostImpl::FrameData frame;
EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// If the DelegatedRendererLayer is axis aligned and has opacity 1, then it
// has no need to be a RenderSurface for the quads it carries.
EXPECT_FALSE(delegated_renderer_layer_->render_surface());
host_impl_->DrawLayers(&frame);
host_impl_->DidDrawAllLayers(frame);
}
TEST_F(DelegatedRendererLayerImplTestSimple, DoesOwnARenderSurfaceForOpacity) {
delegated_renderer_layer_->SetOpacity(0.5f);
LayerTreeHostImpl::FrameData frame;
EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// This test case has quads from multiple layers in the delegated renderer, so
// if the DelegatedRendererLayer has opacity < 1, it should end up with a
// render surface.
EXPECT_TRUE(delegated_renderer_layer_->render_surface());
host_impl_->DrawLayers(&frame);
host_impl_->DidDrawAllLayers(frame);
}
TEST_F(DelegatedRendererLayerImplTestSimple,
DoesOwnARenderSurfaceForTransform) {
gfx::Transform rotation;
rotation.RotateAboutZAxis(30.0);
delegated_renderer_layer_->SetTransform(rotation);
LayerTreeHostImpl::FrameData frame;
EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// This test case has quads from multiple layers in the delegated renderer, so
// if the DelegatedRendererLayer has opacity < 1, it should end up with a
// render surface.
EXPECT_TRUE(delegated_renderer_layer_->render_surface());
host_impl_->DrawLayers(&frame);
host_impl_->DidDrawAllLayers(frame);
}
class DelegatedRendererLayerImplTestOwnSurface
: public DelegatedRendererLayerImplTestSimple {
public:
DelegatedRendererLayerImplTestOwnSurface()
: DelegatedRendererLayerImplTestSimple() {
delegated_renderer_layer_->SetForceRenderSurface(true);
}
};
TEST_F(DelegatedRendererLayerImplTestOwnSurface, AddsRenderPasses) {
LayerTreeHostImpl::FrameData frame;
EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// Each non-DelegatedRendererLayer added one RenderPass. The
// DelegatedRendererLayer added two contributing passes and its owned surface
// added one pass.
ASSERT_EQ(6u, frame.render_passes.size());
// The DelegatedRendererLayer should have added its contributing RenderPasses
// to the frame.
EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
EXPECT_EQ(1, frame.render_passes[1]->id.index);
EXPECT_EQ(4, frame.render_passes[2]->id.layer_id);
EXPECT_EQ(2, frame.render_passes[2]->id.index);
// The DelegatedRendererLayer should have added a RenderPass for its surface
// to the frame.
EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
EXPECT_EQ(0, frame.render_passes[3]->id.index);
// And all other RenderPasses should be non-delegated.
EXPECT_NE(4, frame.render_passes[0]->id.layer_id);
EXPECT_EQ(0, frame.render_passes[0]->id.index);
EXPECT_NE(4, frame.render_passes[4]->id.layer_id);
EXPECT_EQ(0, frame.render_passes[4]->id.index);
EXPECT_NE(4, frame.render_passes[5]->id.layer_id);
EXPECT_EQ(0, frame.render_passes[5]->id.index);
// The DelegatedRendererLayer should have added its RenderPasses to the frame
// in order.
EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
frame.render_passes[1]->output_rect.ToString());
EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
frame.render_passes[2]->output_rect.ToString());
host_impl_->DrawLayers(&frame);
host_impl_->DidDrawAllLayers(frame);
}
TEST_F(DelegatedRendererLayerImplTestOwnSurface,
AddsQuadsToContributingRenderPasses) {
LayerTreeHostImpl::FrameData frame;
EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// Each non-DelegatedRendererLayer added one RenderPass. The
// DelegatedRendererLayer added two contributing passes and its owned surface
// added one pass.
ASSERT_EQ(6u, frame.render_passes.size());
// The DelegatedRendererLayer should have added its contributing RenderPasses
// to the frame.
EXPECT_EQ(4, frame.render_passes[1]->id.layer_id);
EXPECT_EQ(1, frame.render_passes[1]->id.index);
EXPECT_EQ(4, frame.render_passes[2]->id.layer_id);
EXPECT_EQ(2, frame.render_passes[2]->id.index);
// The DelegatedRendererLayer should have added copies of its quads to
// contributing RenderPasses.
ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
frame.render_passes[1]->quad_list[0]->rect.ToString());
// Verify it added the right quads.
ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
EXPECT_EQ(gfx::Rect(0, 0, 7, 7).ToString(),
frame.render_passes[2]->quad_list[0]->rect.ToString());
EXPECT_EQ(gfx::Rect(6, 6, 6, 6).ToString(),
frame.render_passes[2]->quad_list[1]->rect.ToString());
ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
EXPECT_EQ(gfx::Rect(0, 0, 6, 6).ToString(),
frame.render_passes[1]->quad_list[0]->rect.ToString());
host_impl_->DrawLayers(&frame);
host_impl_->DidDrawAllLayers(frame);
}
TEST_F(DelegatedRendererLayerImplTestOwnSurface, AddsQuadsToTargetRenderPass) {
LayerTreeHostImpl::FrameData frame;
EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// Each non-DelegatedRendererLayer added one RenderPass. The
// DelegatedRendererLayer added two contributing passes and its owned surface
// added one pass.
ASSERT_EQ(6u, frame.render_passes.size());
// The layer's target is the RenderPass owned by itself.
EXPECT_EQ(RenderPass::Id(4, 0), frame.render_passes[3]->id);
// The DelegatedRendererLayer should have added copies of quads in its root
// RenderPass to its target RenderPass.
// The layer_after also adds one quad.
ASSERT_EQ(1u, frame.render_passes[3]->quad_list.size());
// Verify it added the right quads.
EXPECT_EQ(gfx::Rect(7, 7, 7, 7).ToString(),
frame.render_passes[3]->quad_list[0]->rect.ToString());
host_impl_->DrawLayers(&frame);
host_impl_->DidDrawAllLayers(frame);
}
TEST_F(DelegatedRendererLayerImplTestOwnSurface,
QuadsFromRootRenderPassAreNotModifiedForTheTarget) {
LayerTreeHostImpl::FrameData frame;
EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
// Each non-DelegatedRendererLayer added one RenderPass. The
// DelegatedRendererLayer added two contributing passes and its owned surface
// added one pass.
ASSERT_EQ(6u, frame.render_passes.size());
// Because the DelegatedRendererLayer owns a RenderSurfaceImpl, its root
// RenderPass' quads do not need to be translated at all.
EXPECT_TRANSFORMATION_MATRIX_EQ(
gfx::Transform(), frame.render_passes[3]->quad_list[0]->quadTransform());
// Quads from non-root RenderPasses should not be shifted either.
ASSERT_EQ(2u, frame.render_passes[2]->quad_list.size());
EXPECT_TRANSFORMATION_MATRIX_EQ(
gfx::Transform(), frame.render_passes[2]->quad_list[0]->quadTransform());
EXPECT_TRANSFORMATION_MATRIX_EQ(
gfx::Transform(), frame.render_passes[2]->quad_list[1]->quadTransform());
ASSERT_EQ(1u, frame.render_passes[1]->quad_list.size());
EXPECT_TRANSFORMATION_MATRIX_EQ(
gfx::Transform(), frame.render_passes[1]->quad_list[0]->quadTransform());
host_impl_->DrawLayers(&frame);
host_impl_->DidDrawAllLayers(frame);
}
class DelegatedRendererLayerImplTestTransform
: public DelegatedRendererLayerImplTest {
public:
DelegatedRendererLayerImplTestTransform()
: root_delegated_render_pass_is_clipped_(false),
delegated_device_scale_factor_(2.f) {}
void SetUpTest() {
host_impl_->SetDeviceScaleFactor(2.f);
scoped_ptr<LayerImpl> root_layer = LayerImpl::Create(
host_impl_->active_tree(), 1);
scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer =
FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 2);
host_impl_->SetViewportSize(gfx::Size(200, 200));
root_layer->SetBounds(gfx::Size(100, 100));
delegated_renderer_layer->SetPosition(gfx::Point(20, 20));
delegated_renderer_layer->SetBounds(gfx::Size(75, 75));
delegated_renderer_layer->SetContentBounds(gfx::Size(75, 75));
delegated_renderer_layer->SetDrawsContent(true);
gfx::Transform transform;
transform.Scale(2.0, 2.0);
transform.Translate(8.0, 8.0);
delegated_renderer_layer->SetTransform(transform);
RenderPassList delegated_render_passes;
gfx::Size child_pass_content_bounds(7, 7);
gfx::Rect child_pass_rect(20, 20, 7, 7);
gfx::Transform child_pass_transform;
child_pass_transform.Scale(0.8f, 0.8f);
child_pass_transform.Translate(9.0, 9.0);
gfx::Rect child_pass_clip_rect(21, 21, 3, 3);
bool child_pass_clipped = false;
{
TestRenderPass* pass = AddRenderPass(
&delegated_render_passes,
RenderPass::Id(10, 7),
child_pass_rect,
gfx::Transform());
SharedQuadState* shared_quad_state =
pass->CreateAndAppendSharedQuadState();
shared_quad_state->SetAll(child_pass_transform,
child_pass_content_bounds,
child_pass_rect,
child_pass_clip_rect,
child_pass_clipped,
1.f,
SkXfermode::kSrcOver_Mode,
0);
SolidColorDrawQuad* color_quad;
color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
color_quad->SetNew(shared_quad_state,
gfx::Rect(20, 20, 3, 7),
gfx::Rect(20, 20, 3, 7),
1u,
false);
color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
color_quad->SetNew(shared_quad_state,
gfx::Rect(23, 20, 4, 7),
gfx::Rect(23, 20, 4, 7),
1u,
false);
}
gfx::Size root_pass_content_bounds(100, 100);
gfx::Rect root_pass_rect(0, 0, 100, 100);
gfx::Transform root_pass_transform;
root_pass_transform.Scale(1.5, 1.5);
root_pass_transform.Translate(7.0, 7.0);
gfx::Rect root_pass_clip_rect(10, 10, 35, 35);
bool root_pass_clipped = root_delegated_render_pass_is_clipped_;
TestRenderPass* pass = AddRenderPass(
&delegated_render_passes,
RenderPass::Id(9, 6),
root_pass_rect,
gfx::Transform());
SharedQuadState* shared_quad_state = pass->CreateAndAppendSharedQuadState();
shared_quad_state->SetAll(root_pass_transform,
root_pass_content_bounds,
root_pass_rect,
root_pass_clip_rect,
root_pass_clipped,
1.f,
SkXfermode::kSrcOver_Mode,
0);
RenderPassDrawQuad* render_pass_quad =
pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
render_pass_quad->SetNew(
shared_quad_state,
gfx::Rect(5, 5, 7, 7), // quad_rect
gfx::Rect(5, 5, 7, 7), // visible_rect
RenderPass::Id(10, 7), // render_pass_id
false, // is_replica
0, // mask_resource_id
child_pass_rect, // contents_changed_since_last_frame
gfx::RectF(), // mask_uv_rect
FilterOperations(), // filters
FilterOperations()); // background_filters
SolidColorDrawQuad* color_quad;
color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
color_quad->SetNew(shared_quad_state,
gfx::Rect(0, 0, 10, 10),
gfx::Rect(0, 0, 10, 10),
1u,
false);
color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
color_quad->SetNew(shared_quad_state,
gfx::Rect(0, 10, 10, 10),
gfx::Rect(0, 10, 10, 10),
2u,
false);
color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
color_quad->SetNew(shared_quad_state,
gfx::Rect(10, 0, 10, 10),
gfx::Rect(10, 0, 10, 10),
3u,
false);
color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
color_quad->SetNew(shared_quad_state,
gfx::Rect(10, 10, 10, 10),
gfx::Rect(10, 10, 10, 10),
4u,
false);
delegated_renderer_layer->SetFrameDataForRenderPasses(
delegated_device_scale_factor_, &delegated_render_passes);
// The RenderPasses should be taken by the layer.
EXPECT_EQ(0u, delegated_render_passes.size());
root_layer_ = root_layer.get();
delegated_renderer_layer_ = delegated_renderer_layer.get();
root_layer->AddChild(delegated_renderer_layer.PassAs<LayerImpl>());
host_impl_->active_tree()->SetRootLayer(root_layer.Pass());
}
void VerifyRenderPasses(
const LayerTreeHostImpl::FrameData& frame,
size_t num_render_passes,
const SharedQuadState** root_delegated_shared_quad_state,
const SharedQuadState** contrib_delegated_shared_quad_state) {
ASSERT_EQ(num_render_passes, frame.render_passes.size());
// The contributing render pass in the DelegatedRendererLayer.
EXPECT_EQ(2, frame.render_passes[0]->id.layer_id);
EXPECT_EQ(1, frame.render_passes[0]->id.index);
// The root render pass.
EXPECT_EQ(1, frame.render_passes.back()->id.layer_id);
EXPECT_EQ(0, frame.render_passes.back()->id.index);
const QuadList& contrib_delegated_quad_list =
frame.render_passes[0]->quad_list;
ASSERT_EQ(2u, contrib_delegated_quad_list.size());
const QuadList& root_delegated_quad_list =
frame.render_passes[1]->quad_list;
ASSERT_EQ(5u, root_delegated_quad_list.size());
// All quads in a render pass should share the same state.
*contrib_delegated_shared_quad_state =
contrib_delegated_quad_list[0]->shared_quad_state;
EXPECT_EQ(*contrib_delegated_shared_quad_state,
contrib_delegated_quad_list[1]->shared_quad_state);
*root_delegated_shared_quad_state =
root_delegated_quad_list[0]->shared_quad_state;
EXPECT_EQ(*root_delegated_shared_quad_state,
root_delegated_quad_list[1]->shared_quad_state);
EXPECT_EQ(*root_delegated_shared_quad_state,
root_delegated_quad_list[2]->shared_quad_state);
EXPECT_EQ(*root_delegated_shared_quad_state,
root_delegated_quad_list[3]->shared_quad_state);
EXPECT_EQ(*root_delegated_shared_quad_state,
root_delegated_quad_list[4]->shared_quad_state);
EXPECT_NE(*contrib_delegated_shared_quad_state,
*root_delegated_shared_quad_state);
}
protected:
LayerImpl* root_layer_;
DelegatedRendererLayerImpl* delegated_renderer_layer_;
bool root_delegated_render_pass_is_clipped_;
float delegated_device_scale_factor_;
};
TEST_F(DelegatedRendererLayerImplTestTransform, QuadsUnclipped_NoSurface) {
root_delegated_render_pass_is_clipped_ = false;
SetUpTest();
LayerTreeHostImpl::FrameData frame;
EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
const SharedQuadState* root_delegated_shared_quad_state = NULL;
const SharedQuadState* contrib_delegated_shared_quad_state = NULL;
VerifyRenderPasses(
frame,
2,
&root_delegated_shared_quad_state,
&contrib_delegated_shared_quad_state);
// When the quads don't have a clip of their own, the clip rect is set to
// the drawable_content_rect of the delegated renderer layer.
EXPECT_EQ(delegated_renderer_layer_->drawable_content_rect().ToString(),
root_delegated_shared_quad_state->clip_rect.ToString());
// Even though the quads in the root pass have no clip of their own, they
// inherit the clip rect from the delegated renderer layer if it does not
// own a surface.
EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
gfx::Transform expected;
// Device scale factor.
expected.Scale(2.0, 2.0);
// This is the transform from the layer's space to its target.
expected.Translate(20, 20);
expected.Scale(2.0, 2.0);
expected.Translate(8.0, 8.0);
// This is the transform within the source frame.
// Inverse device scale factor to go from physical space to layer space.
expected.Scale(0.5, 0.5);
expected.Scale(1.5, 1.5);
expected.Translate(7.0, 7.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected, root_delegated_shared_quad_state->content_to_target_transform);
// The contributing render pass should not be transformed from its input.
EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
contrib_delegated_shared_quad_state->clip_rect.ToString());
EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
expected.MakeIdentity();
expected.Scale(0.8f, 0.8f);
expected.Translate(9.0, 9.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected,
contrib_delegated_shared_quad_state->content_to_target_transform);
host_impl_->DrawLayers(&frame);
host_impl_->DidDrawAllLayers(frame);
}
TEST_F(DelegatedRendererLayerImplTestTransform, QuadsClipped_NoSurface) {
root_delegated_render_pass_is_clipped_ = true;
SetUpTest();
LayerTreeHostImpl::FrameData frame;
EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
const SharedQuadState* root_delegated_shared_quad_state = NULL;
const SharedQuadState* contrib_delegated_shared_quad_state = NULL;
VerifyRenderPasses(
frame,
2,
&root_delegated_shared_quad_state,
&contrib_delegated_shared_quad_state);
// Since the quads have a clip_rect it should be modified by delegated
// renderer layer's draw_transform.
// The position of the resulting clip_rect is:
// (clip rect position (10) * inverse dsf (1/2) + translate (8)) *
// layer scale (2) + layer position (20) = 46
// The device scale is 2, so everything gets doubled, giving 92.
//
// The size is 35x35 scaled by the device scale.
EXPECT_EQ(gfx::Rect(92, 92, 70, 70).ToString(),
root_delegated_shared_quad_state->clip_rect.ToString());
// The quads had a clip and it should be preserved.
EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
gfx::Transform expected;
// Device scale factor.
expected.Scale(2.0, 2.0);
// This is the transform from the layer's space to its target.
expected.Translate(20, 20);
expected.Scale(2.0, 2.0);
expected.Translate(8.0, 8.0);
// This is the transform within the source frame.
// Inverse device scale factor to go from physical space to layer space.
expected.Scale(0.5, 0.5);
expected.Scale(1.5, 1.5);
expected.Translate(7.0, 7.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected, root_delegated_shared_quad_state->content_to_target_transform);
// The contributing render pass should not be transformed from its input.
EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
contrib_delegated_shared_quad_state->clip_rect.ToString());
EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
expected.MakeIdentity();
expected.Scale(0.8f, 0.8f);
expected.Translate(9.0, 9.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected,
contrib_delegated_shared_quad_state->content_to_target_transform);
host_impl_->DrawLayers(&frame);
host_impl_->DidDrawAllLayers(frame);
}
TEST_F(DelegatedRendererLayerImplTestTransform, QuadsUnclipped_Surface) {
root_delegated_render_pass_is_clipped_ = false;
SetUpTest();
delegated_renderer_layer_->SetForceRenderSurface(true);
LayerTreeHostImpl::FrameData frame;
EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
const SharedQuadState* root_delegated_shared_quad_state = NULL;
const SharedQuadState* contrib_delegated_shared_quad_state = NULL;
VerifyRenderPasses(
frame,
3,
&root_delegated_shared_quad_state,
&contrib_delegated_shared_quad_state);
// When the layer owns a surface, then its position and translation are not
// a part of its draw transform.
EXPECT_EQ(gfx::Rect(10, 10, 35, 35).ToString(),
root_delegated_shared_quad_state->clip_rect.ToString());
// Since the layer owns a surface it doesn't need to clip its quads, so
// unclipped quads remain unclipped.
EXPECT_FALSE(root_delegated_shared_quad_state->is_clipped);
gfx::Transform expected;
// This is the transform within the source frame.
expected.Scale(1.5, 1.5);
expected.Translate(7.0, 7.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected, root_delegated_shared_quad_state->content_to_target_transform);
// The contributing render pass should not be transformed from its input.
EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
contrib_delegated_shared_quad_state->clip_rect.ToString());
EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
expected.MakeIdentity();
expected.Scale(0.8f, 0.8f);
expected.Translate(9.0, 9.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected,
contrib_delegated_shared_quad_state->content_to_target_transform);
host_impl_->DrawLayers(&frame);
host_impl_->DidDrawAllLayers(frame);
}
TEST_F(DelegatedRendererLayerImplTestTransform, QuadsClipped_Surface) {
root_delegated_render_pass_is_clipped_ = true;
SetUpTest();
delegated_renderer_layer_->SetForceRenderSurface(true);
LayerTreeHostImpl::FrameData frame;
EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
const SharedQuadState* root_delegated_shared_quad_state = NULL;
const SharedQuadState* contrib_delegated_shared_quad_state = NULL;
VerifyRenderPasses(
frame,
3,
&root_delegated_shared_quad_state,
&contrib_delegated_shared_quad_state);
// When the layer owns a surface, then its position and translation are not
// a part of its draw transform. The clip_rect should be preserved.
EXPECT_EQ(gfx::Rect(10, 10, 35, 35).ToString(),
root_delegated_shared_quad_state->clip_rect.ToString());
// The quads had a clip and it should be preserved.
EXPECT_TRUE(root_delegated_shared_quad_state->is_clipped);
gfx::Transform expected;
// This is the transform within the source frame.
expected.Scale(1.5, 1.5);
expected.Translate(7.0, 7.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected, root_delegated_shared_quad_state->content_to_target_transform);
// The contributing render pass should not be transformed from its input.
EXPECT_EQ(gfx::Rect(21, 21, 3, 3).ToString(),
contrib_delegated_shared_quad_state->clip_rect.ToString());
EXPECT_FALSE(contrib_delegated_shared_quad_state->is_clipped);
expected.MakeIdentity();
expected.Scale(0.8f, 0.8f);
expected.Translate(9.0, 9.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected,
contrib_delegated_shared_quad_state->content_to_target_transform);
host_impl_->DrawLayers(&frame);
host_impl_->DidDrawAllLayers(frame);
}
TEST_F(DelegatedRendererLayerImplTestTransform, MismatchedDeviceScaleFactor) {
root_delegated_render_pass_is_clipped_ = true;
delegated_device_scale_factor_ = 1.3f;
SetUpTest();
LayerTreeHostImpl::FrameData frame;
EXPECT_EQ(DRAW_SUCCESS, host_impl_->PrepareToDraw(&frame));
const SharedQuadState* root_delegated_shared_quad_state = NULL;
const SharedQuadState* contrib_delegated_shared_quad_state = NULL;
VerifyRenderPasses(frame,
2,
&root_delegated_shared_quad_state,
&contrib_delegated_shared_quad_state);
// The parent tree's device scale factor is 2.0, but the child has submitted a
// frame with a device scale factor of 1.3. Absent any better option, the
// only thing we can do is scale from 1.3 -> 2.0.
gfx::Transform expected;
// Device scale factor (from parent).
expected.Scale(2.0, 2.0);
// This is the transform from the layer's space to its target.
expected.Translate(20, 20);
expected.Scale(2.0, 2.0);
expected.Translate(8.0, 8.0);
// This is the transform within the source frame.
// Inverse device scale factor (from child).
expected.Scale(1.0f / 1.3f, 1.0f / 1.3f);
expected.Scale(1.5, 1.5);
expected.Translate(7.0, 7.0);
EXPECT_TRANSFORMATION_MATRIX_EQ(
expected, root_delegated_shared_quad_state->content_to_target_transform);
host_impl_->DrawLayers(&frame);
host_impl_->DidDrawAllLayers(frame);
}
class DelegatedRendererLayerImplTestClip
: public DelegatedRendererLayerImplTest {
public:
void SetUpTest() {
scoped_ptr<LayerImpl> root_layer =
LayerImpl::Create(host_impl_->active_tree(), 1);
scoped_ptr<FakeDelegatedRendererLayerImpl> delegated_renderer_layer =
FakeDelegatedRendererLayerImpl::Create(host_impl_->active_tree(), 2);
scoped_ptr<LayerImpl> clip_layer =
LayerImpl::Create(host_impl_->active_tree(), 3);
scoped_ptr<LayerImpl> origin_layer =
LayerImpl::Create(host_impl_->active_tree(), 4);
host_impl_->SetViewportSize(gfx::Size(100, 100));
root_layer->SetBounds(gfx::Size(100, 100));
delegated_renderer_layer->SetPosition(gfx::Point(20, 20));
delegated_renderer_layer->SetBounds(gfx::Size(50, 50));
delegated_renderer_layer->SetContentBounds(gfx::Size(50, 50));
delegated_renderer_layer->SetDrawsContent(true);
RenderPassList delegated_render_passes;
gfx::Size child_pass_content_bounds(7, 7);
gfx::Rect child_pass_rect(20, 20, 7, 7);
gfx::Transform child_pass_transform;
gfx::Rect child_pass_clip_rect(21, 21, 3, 3);
bool child_pass_clipped = false;
{
TestRenderPass* pass = AddRenderPass(
&delegated_render_passes,
RenderPass::Id(10, 7),
child_pass_rect,
gfx::Transform());
SharedQuadState* shared_quad_state =
pass->CreateAndAppendSharedQuadState();
shared_quad_state->SetAll(child_pass_transform,
child_pass_content_bounds,
child_pass_rect,
child_pass_clip_rect,
child_pass_clipped,
1.f,
SkXfermode::kSrcOver_Mode,
0);
SolidColorDrawQuad* color_quad;
color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
color_quad->SetNew(shared_quad_state,
gfx::Rect(20, 20, 3, 7),
gfx::Rect(20, 20, 3, 7),
1u,
false);
color_quad = pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
color_quad->SetNew(shared_quad_state,
gfx::Rect(23, 20, 4, 7),
gfx::Rect(23, 20, 4, 7),
1u,
false);
}
gfx::Size root_pass_content_bounds(50, 50);
gfx::Rect root_pass_rect(0, 0, 50, 50);
gfx::Transform root_pass_transform;
gfx::Rect root_pass_clip_rect(5, 5, 40, 40);
bool root_pass_clipped = root_delegated_render_pass_is_clipped_;
TestRenderPass* pass = AddRenderPass(
&delegated_render_passes,
RenderPass::Id(9, 6),
root_pass_rect,
gfx::Transform());
SharedQuadState* shared_quad_state = pass->CreateAndAppendSharedQuadState();