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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
cc / trees / layer_tree_host_unittest.cc [blame]
// Copyright 2011 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif
#include "cc/trees/layer_tree_host.h"
#include <stddef.h>
#include <stdint.h>
#include <algorithm>
#include <memory>
#include "base/auto_reset.h"
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/synchronization/lock.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/time/time.h"
#include "base/unguessable_token.h"
#include "build/build_config.h"
#include "cc/animation/animation_host.h"
#include "cc/input/scroll_elasticity_helper.h"
#include "cc/layers/content_layer_client.h"
#include "cc/layers/heads_up_display_layer.h"
#include "cc/layers/layer_impl.h"
#include "cc/layers/painted_scrollbar_layer.h"
#include "cc/layers/picture_layer.h"
#include "cc/layers/solid_color_layer.h"
#include "cc/layers/video_layer.h"
#include "cc/layers/view_transition_content_layer.h"
#include "cc/metrics/begin_main_frame_metrics.h"
#include "cc/metrics/events_metrics_manager.h"
#include "cc/metrics/ukm_smoothness_data.h"
#include "cc/paint/image_animation_count.h"
#include "cc/resources/ui_resource_manager.h"
#include "cc/test/fake_content_layer_client.h"
#include "cc/test/fake_frame_info.h"
#include "cc/test/fake_layer_tree_host_client.h"
#include "cc/test/fake_paint_image_generator.h"
#include "cc/test/fake_picture_layer.h"
#include "cc/test/fake_picture_layer_impl.h"
#include "cc/test/fake_proxy.h"
#include "cc/test/fake_recording_source.h"
#include "cc/test/fake_scoped_ui_resource.h"
#include "cc/test/fake_scrollbar_layer.h"
#include "cc/test/fake_video_frame_provider.h"
#include "cc/test/layer_test_common.h"
#include "cc/test/layer_tree_test.h"
#include "cc/test/mock_latency_info_swap_promise_monitor.h"
#include "cc/test/push_properties_counting_layer.h"
#include "cc/test/push_properties_counting_layer_impl.h"
#include "cc/test/render_pass_test_utils.h"
#include "cc/test/skia_common.h"
#include "cc/test/stub_input_handler_client.h"
#include "cc/test/test_layer_tree_frame_sink.h"
#include "cc/trees/clip_node.h"
#include "cc/trees/compositor_commit_data.h"
#include "cc/trees/effect_node.h"
#include "cc/trees/layer_tree_host_impl.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/paint_holding_reason.h"
#include "cc/trees/scroll_node.h"
#include "cc/trees/single_thread_proxy.h"
#include "cc/trees/swap_promise.h"
#include "cc/trees/swap_promise_manager.h"
#include "cc/trees/transform_node.h"
#include "cc/view_transition/view_transition_request.h"
#include "components/ukm/test_ukm_recorder.h"
#include "components/viz/common/features.h"
#include "components/viz/common/frame_sinks/begin_frame_args.h"
#include "components/viz/common/frame_sinks/copy_output_request.h"
#include "components/viz/common/frame_sinks/copy_output_result.h"
#include "components/viz/common/quads/compositor_frame_transition_directive.h"
#include "components/viz/common/quads/compositor_render_pass_draw_quad.h"
#include "components/viz/common/quads/draw_quad.h"
#include "components/viz/common/quads/tile_draw_quad.h"
#include "components/viz/service/display/output_surface.h"
#include "components/viz/service/display/skia_output_surface.h"
#include "components/viz/test/begin_frame_args_test.h"
#include "components/viz/test/fake_output_surface.h"
#include "components/viz/test/test_raster_interface.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkPicture.h"
#include "third_party/skia/include/gpu/ganesh/GrDirectContext.h"
#include "ui/gfx/animation/keyframe/timing_function.h"
#include "ui/gfx/geometry/point_conversions.h"
#include "ui/gfx/geometry/size_conversions.h"
#include "ui/gfx/geometry/test/geometry_util.h"
#include "ui/gfx/geometry/vector2d_conversions.h"
#define EXPECT_SCOPED(statements) \
{ \
SCOPED_TRACE(""); \
statements; \
}
using testing::_;
using testing::AnyNumber;
using testing::AtLeast;
using testing::Mock;
using testing::StrictMock;
namespace cc {
namespace {
bool LayerSubtreeHasCopyRequest(Layer* layer) {
const LayerTreeHost* host = layer->layer_tree_host();
int index = layer->effect_tree_index();
const auto* node = host->property_trees()->effect_tree().Node(index);
return node->subtree_has_copy_request;
}
FrameInfo CreateFakeImplDroppedFrameInfo() {
auto info = CreateFakeFrameInfo(FrameInfo::FrameFinalState::kDropped);
info.main_thread_response = FrameInfo::MainThreadResponse::kMissing;
return info;
}
using LayerTreeHostTest = LayerTreeTest;
class LayerTreeHostTestHasImplThreadTest : public LayerTreeHostTest {
public:
LayerTreeHostTestHasImplThreadTest() : single_threaded_(false) {}
void RunTest(CompositorMode mode) override {
single_threaded_ = mode == CompositorMode::SINGLE_THREADED;
LayerTreeHostTest::RunTest(mode);
}
void BeginTest() override {
EXPECT_EQ(single_threaded_, !HasImplThread());
EndTest();
}
void AfterTest() override { EXPECT_EQ(single_threaded_, !HasImplThread()); }
private:
bool single_threaded_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestHasImplThreadTest);
class LayerTreeHostTestSetNeedsCommitInsideLayout : public LayerTreeHostTest {
protected:
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void UpdateLayerTreeHost() override {
// This shouldn't cause a second commit to happen.
layer_tree_host()->SetNeedsCommit();
}
void DidCommit() override {
EXPECT_EQ(1, layer_tree_host()->SourceFrameNumber());
EndTest();
}
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommitInsideLayout);
class LayerTreeHostTestFrameOrdering : public LayerTreeHostTest {
protected:
enum MainOrder : int {
MAIN_START = 1,
MAIN_LAYOUT,
MAIN_DID_BEGIN_FRAME,
MAIN_COMMIT_COMPLETE,
MAIN_END,
};
enum ImplOrder : int {
IMPL_START = 1,
IMPL_READY_TO_COMMIT,
IMPL_COMMIT,
IMPL_COMMIT_COMPLETE,
IMPL_ACTIVATE,
IMPL_DRAW,
IMPL_END,
};
template <typename T>
bool CheckStep(T next, T* var) {
int expected = next - 1;
EXPECT_EQ(expected, *var);
bool correct = expected == *var;
*var = next;
return correct;
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void UpdateLayerTreeHost() override {
EXPECT_TRUE(CheckStep(MAIN_LAYOUT, &main_));
}
void DidCommit() override {
EXPECT_TRUE(CheckStep(MAIN_COMMIT_COMPLETE, &main_));
}
void DidBeginMainFrame() override {
EXPECT_TRUE(CheckStep(MAIN_DID_BEGIN_FRAME, &main_));
}
void ReadyToCommitOnThread(LayerTreeHostImpl* impl) override {
EXPECT_TRUE(CheckStep(IMPL_READY_TO_COMMIT, &impl_));
}
void BeginCommitOnThread(LayerTreeHostImpl* impl) override {
EXPECT_TRUE(CheckStep(IMPL_COMMIT, &impl_));
}
void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
EXPECT_TRUE(CheckStep(IMPL_COMMIT_COMPLETE, &impl_));
}
void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override {
EXPECT_TRUE(CheckStep(IMPL_ACTIVATE, &impl_));
}
void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
EXPECT_TRUE(CheckStep(IMPL_DRAW, &impl_));
EndTest();
}
void AfterTest() override {
EXPECT_TRUE(CheckStep(MAIN_END, &main_));
EXPECT_TRUE(CheckStep(IMPL_END, &impl_));
}
MainOrder main_ = MAIN_START;
ImplOrder impl_ = IMPL_START;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestFrameOrdering);
// This tests that the frame ordering is the same for an update-layers-only
// frame as for a fully committed frame.
class LayerTreeHostTestUpdateLayersFrameOrdering
: public LayerTreeHostTestFrameOrdering {
void DidCommit() override {
EXPECT_TRUE(CheckStep(MAIN_COMMIT_COMPLETE, &main_));
if (main_iteration_++ == 0) {
main_ = MAIN_START;
} else {
EndTest();
}
}
void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
EXPECT_TRUE(CheckStep(IMPL_DRAW, &impl_));
impl_ = IMPL_START;
if (impl_iteration_++ == 0) {
PostSetNeedsUpdateLayersToMainThread();
}
}
void AfterTest() override { EXPECT_TRUE(CheckStep(MAIN_END, &main_)); }
private:
int main_iteration_ = 0;
int impl_iteration_ = 0;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestUpdateLayersFrameOrdering);
class LayerTreeHostTestRequestedMainFrame : public LayerTreeHostTest {
public:
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void WillBeginMainFrame() override {
// Post NextStep() so it happens after the MainFrame completes.
MainThreadTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(&LayerTreeHostTestRequestedMainFrame::NextStep,
base::Unretained(this)));
}
void NextStep() {
// The MainFrame request is cleared once a MainFrame happens.
EXPECT_FALSE(layer_tree_host()->RequestedMainFramePending());
switch (layer_tree_host()->SourceFrameNumber()) {
case 0:
ADD_FAILURE()
<< "Case 0 is the initial commit used to send the test here";
[[fallthrough]];
case 1:
layer_tree_host()->SetNeedsAnimate();
break;
case 2:
layer_tree_host()->SetNeedsUpdateLayers();
break;
case 3:
layer_tree_host()->SetNeedsCommit();
break;
case 4:
EndTest();
return;
}
// SetNeeds{Animate,UpdateLayers,Commit}() will mean a MainFrame is pending.
EXPECT_TRUE(layer_tree_host()->RequestedMainFramePending());
}
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestRequestedMainFrame);
class LayerTreeHostTestSchedulingClient : public LayerTreeHostTest {
public:
void BeginTest() override {
PostSetNeedsCommitToMainThread();
EXPECT_EQ(0, main_frame_run_count_);
}
void DidRunBeginMainFrame() override { main_frame_run_count_++; }
void DidBeginMainFrame() override {
EXPECT_EQ(1, main_frame_run_count_);
EndTest();
}
void AfterTest() override {}
private:
int main_frame_run_count_ = 0;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestSchedulingClient);
class LayerTreeHostTestSetNeedsUpdateInsideLayout : public LayerTreeHostTest {
protected:
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void UpdateLayerTreeHost() override {
// This shouldn't cause a second commit to happen.
layer_tree_host()->SetNeedsUpdateLayers();
}
void DidCommit() override {
EXPECT_EQ(1, layer_tree_host()->SourceFrameNumber());
EndTest();
}
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsUpdateInsideLayout);
// Test if the LTHI receives ReadyToActivate notifications from the TileManager
// when no raster tasks get scheduled.
class LayerTreeHostTestReadyToActivateEmpty : public LayerTreeHostTest {
public:
LayerTreeHostTestReadyToActivateEmpty()
: did_notify_ready_to_activate_(false),
all_tiles_required_for_activation_are_ready_to_draw_(false),
required_for_activation_count_(0) {}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
const std::vector<raw_ptr<PictureLayerImpl, VectorExperimental>>& layers =
impl->sync_tree()->picture_layers();
required_for_activation_count_ = 0;
for (PictureLayerImpl* layer : layers) {
FakePictureLayerImpl* fake_layer =
static_cast<FakePictureLayerImpl*>(layer);
required_for_activation_count_ +=
fake_layer->CountTilesRequiredForActivation();
}
}
void NotifyReadyToActivateOnThread(LayerTreeHostImpl* impl) override {
did_notify_ready_to_activate_ = true;
all_tiles_required_for_activation_are_ready_to_draw_ =
impl->tile_manager()->IsReadyToActivate();
EndTest();
}
void AfterTest() override {
EXPECT_TRUE(did_notify_ready_to_activate_);
EXPECT_TRUE(all_tiles_required_for_activation_are_ready_to_draw_);
EXPECT_EQ(size_t(0), required_for_activation_count_);
}
protected:
bool did_notify_ready_to_activate_;
bool all_tiles_required_for_activation_are_ready_to_draw_;
size_t required_for_activation_count_;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestReadyToActivateEmpty);
// Test if the LTHI receives ReadyToActivate notifications from the TileManager
// when some raster tasks flagged as REQUIRED_FOR_ACTIVATION got scheduled.
class LayerTreeHostTestReadyToActivateNonEmpty
: public LayerTreeHostTestReadyToActivateEmpty {
public:
void SetupTree() override {
client_.set_fill_with_nonsolid_color(true);
scoped_refptr<FakePictureLayer> root_layer =
FakePictureLayer::Create(&client_);
root_layer->SetBounds(gfx::Size(1024, 1024));
root_layer->SetIsDrawable(true);
layer_tree_host()->SetRootLayer(root_layer);
LayerTreeHostTest::SetupTree();
client_.set_bounds(root_layer->bounds());
}
void AfterTest() override {
EXPECT_TRUE(did_notify_ready_to_activate_);
EXPECT_TRUE(all_tiles_required_for_activation_are_ready_to_draw_);
EXPECT_LE(size_t(1), required_for_activation_count_);
}
private:
FakeContentLayerClient client_;
};
// No single thread test because the commit goes directly to the active tree in
// single thread mode, so notify ready to activate is skipped.
// Flaky: https://crbug.com/947673
// MULTI_THREAD_TEST_F(LayerTreeHostTestReadyToActivateNonEmpty);
// Test if the LTHI receives ReadyToDraw notifications from the TileManager when
// no raster tasks get scheduled.
class LayerTreeHostTestReadyToDrawEmpty : public LayerTreeHostTest {
public:
LayerTreeHostTestReadyToDrawEmpty()
: did_notify_ready_to_draw_(false),
all_tiles_required_for_draw_are_ready_to_draw_(false),
required_for_draw_count_(0) {}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void NotifyReadyToDrawOnThread(LayerTreeHostImpl* impl) override {
did_notify_ready_to_draw_ = true;
const std::vector<raw_ptr<PictureLayerImpl, VectorExperimental>>& layers =
impl->active_tree()->picture_layers();
all_tiles_required_for_draw_are_ready_to_draw_ =
impl->tile_manager()->IsReadyToDraw();
for (PictureLayerImpl* layer : layers) {
FakePictureLayerImpl* fake_layer =
static_cast<FakePictureLayerImpl*>(layer);
required_for_draw_count_ += fake_layer->CountTilesRequiredForDraw();
}
EndTest();
}
void AfterTest() override {
EXPECT_TRUE(did_notify_ready_to_draw_);
EXPECT_TRUE(all_tiles_required_for_draw_are_ready_to_draw_);
EXPECT_EQ(size_t(0), required_for_draw_count_);
}
protected:
bool did_notify_ready_to_draw_;
bool all_tiles_required_for_draw_are_ready_to_draw_;
size_t required_for_draw_count_;
};
SINGLE_THREAD_TEST_F(LayerTreeHostTestReadyToDrawEmpty);
// Test if the LTHI receives ReadyToDraw notifications from the TileManager when
// some raster tasks flagged as REQUIRED_FOR_DRAW got scheduled.
class LayerTreeHostTestReadyToDrawNonEmpty
: public LayerTreeHostTestReadyToDrawEmpty {
public:
void SetupTree() override {
client_.set_fill_with_nonsolid_color(true);
scoped_refptr<FakePictureLayer> root_layer =
FakePictureLayer::Create(&client_);
root_layer->SetBounds(gfx::Size(1024, 1024));
root_layer->SetIsDrawable(true);
layer_tree_host()->SetRootLayer(root_layer);
LayerTreeHostTest::SetupTree();
client_.set_bounds(root_layer->bounds());
}
void AfterTest() override {
EXPECT_TRUE(did_notify_ready_to_draw_);
EXPECT_TRUE(all_tiles_required_for_draw_are_ready_to_draw_);
EXPECT_LE(size_t(1), required_for_draw_count_);
}
private:
FakeContentLayerClient client_;
};
// Note: With this test setup, we only get tiles flagged as REQUIRED_FOR_DRAW in
// single threaded mode.
SINGLE_THREAD_TEST_F(LayerTreeHostTestReadyToDrawNonEmpty);
// This tests if we get the READY_TO_DRAW signal and draw if we become invisible
// and then become visible again.
class LayerTreeHostTestReadyToDrawVisibility : public LayerTreeHostTest {
public:
LayerTreeHostTestReadyToDrawVisibility()
: LayerTreeHostTest(),
toggled_visibility_(false),
did_notify_ready_to_draw_(false),
did_draw_(false) {}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void SetupTree() override {
client_.set_fill_with_nonsolid_color(true);
scoped_refptr<FakePictureLayer> root_layer =
FakePictureLayer::Create(&client_);
root_layer->SetBounds(gfx::Size(1024, 1024));
client_.set_bounds(root_layer->bounds());
root_layer->SetIsDrawable(true);
layer_tree_host()->SetRootLayer(root_layer);
LayerTreeHostTest::SetupTree();
}
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
if (!toggled_visibility_) {
{
DebugScopedSetMainThread main(task_runner_provider());
layer_tree_host()->SetVisible(false);
}
toggled_visibility_ = true;
EXPECT_FALSE(host_impl->visible());
}
}
void NotifyReadyToDrawOnThread(LayerTreeHostImpl* host_impl) override {
// Sometimes the worker thread posts NotifyReadyToDraw in the extremely
// short duration of time between PrepareTiles and SetVisible(false) so we
// might get two NotifyReadyToDraw signals for this test.
did_notify_ready_to_draw_ = true;
}
void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
EXPECT_FALSE(did_draw_);
did_draw_ = true;
EndTest();
}
void DidFinishImplFrameOnThread(LayerTreeHostImpl* host_impl) override {
if (!host_impl->visible()) {
// DidFinishImplFrameOnThread is called from Scheduler::FinishImplFrame()
// with inside_scheduled_action_ being true, so if SetVisible is called
// directly here without PostTask, ProcessScheduledActions() triggered by
// SetVisible() is ignored, so no more action will be executed.
// Therefore, this TC will be succeed only if there is another events like
// - RasterTaskImpl's OnTaskCompleted : this is flaky depending on tile
// task threads when SetVisible(false) is called.
// - NotifyReadytoActivate : this is not called in single threaded
// To remove flaky, PostTask is required here.
ImplThreadTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(&LayerTreeHostTestReadyToDrawVisibility::SetVisible,
base::Unretained(this), host_impl));
}
}
void SetVisible(LayerTreeHostImpl* host_impl) {
DebugScopedSetMainThread main(task_runner_provider());
layer_tree_host()->SetVisible(true);
EXPECT_TRUE(host_impl->visible());
}
void AfterTest() override {
EXPECT_TRUE(did_notify_ready_to_draw_);
EXPECT_TRUE(did_draw_);
}
private:
FakeContentLayerClient client_;
bool toggled_visibility_;
bool did_notify_ready_to_draw_;
bool did_draw_;
};
// Note: With this test setup, we only get tiles flagged as REQUIRED_FOR_DRAW in
// single threaded mode.
SINGLE_THREAD_TEST_F(LayerTreeHostTestReadyToDrawVisibility);
class LayerTreeHostContextCacheTest : public LayerTreeHostTest {
public:
std::unique_ptr<TestLayerTreeFrameSink> CreateLayerTreeFrameSink(
const viz::RendererSettings& renderer_settings,
double refresh_rate,
scoped_refptr<viz::RasterContextProvider> compositor_context_provider,
scoped_refptr<viz::RasterContextProvider> worker_context_provider)
override {
// Create the main viz::RasterContextProvider with a MockContextSupport.
auto main_support = std::make_unique<MockContextSupport>();
mock_main_context_support_ = main_support.get();
auto test_main_context_provider =
viz::TestContextProvider::CreateRaster(std::move(main_support));
// Create the main viz::RasterContextProvider with a MockContextSupport.
auto worker_support = std::make_unique<MockContextSupport>();
mock_worker_context_support_ = worker_support.get();
auto test_worker_context_provider =
viz::TestContextProvider::CreateWorker(std::move(worker_support));
// At init, visibility is set to true, so SetAggressivelyFreeResources will
// be disabled.
EXPECT_CALL(*mock_main_context_support_,
SetAggressivelyFreeResources(false));
EXPECT_CALL(*mock_worker_context_support_,
SetAggressivelyFreeResources(false));
return LayerTreeHostTest::CreateLayerTreeFrameSink(
renderer_settings, refresh_rate, std::move(test_main_context_provider),
std::move(test_worker_context_provider));
}
void BeginTest() override {}
protected:
class MockContextSupport : public viz::TestContextSupport {
public:
MockContextSupport() = default;
MOCK_METHOD1(SetAggressivelyFreeResources,
void(bool aggressively_free_resources));
};
raw_ptr<MockContextSupport, AcrossTasksDanglingUntriaged>
mock_main_context_support_;
raw_ptr<MockContextSupport, AcrossTasksDanglingUntriaged>
mock_worker_context_support_;
};
// Test if the LTH successfully frees resources on the main/worker
// ContextSupport when visibility is set to false.
class LayerTreeHostFreesContextResourcesOnInvisible
: public LayerTreeHostContextCacheTest {
public:
void InitializedRendererOnThread(LayerTreeHostImpl* host_impl,
bool success) override {
// Ensure that our initialization expectations have completed.
Mock::VerifyAndClearExpectations(mock_main_context_support_);
Mock::VerifyAndClearExpectations(mock_worker_context_support_);
// Update visibility and make sure resources are freed.
EXPECT_CALL(*mock_main_context_support_,
SetAggressivelyFreeResources(true));
EXPECT_CALL(*mock_worker_context_support_,
SetAggressivelyFreeResources(true))
.WillOnce(testing::Invoke([this](bool is_visible) { EndTest(); }));
PostSetVisibleToMainThread(false);
}
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostFreesContextResourcesOnInvisible);
// Test if the LTH successfully frees worker context resources when the hard
// memory limit is set to zero.
class LayerTreeHostFreesWorkerContextResourcesOnZeroMemoryLimit
: public LayerTreeHostContextCacheTest {
public:
void InitializedRendererOnThread(LayerTreeHostImpl* host_impl,
bool success) override {
// Ensure that our initialization expectations have completed.
Mock::VerifyAndClearExpectations(mock_main_context_support_);
Mock::VerifyAndClearExpectations(mock_worker_context_support_);
// Main and worker context support should start freeing resources when hard
// memory limit is zeroed.
EXPECT_CALL(*mock_main_context_support_,
SetAggressivelyFreeResources(true));
EXPECT_CALL(*mock_worker_context_support_,
SetAggressivelyFreeResources(true))
.WillOnce(testing::Invoke([this](bool is_visible) {
// End test after verifying both.
EndTest();
}));
ManagedMemoryPolicy zero_policy(
0, gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING, 0);
host_impl->SetMemoryPolicy(zero_policy);
}
};
SINGLE_AND_MULTI_THREAD_TEST_F(
LayerTreeHostFreesWorkerContextResourcesOnZeroMemoryLimit);
// Test if the LTH successfully frees worker context resources when hard memory
// limit is set to zero while using a synchronous compositor (Android WebView).
class LayerTreeHostFreesWorkerContextResourcesOnZeroMemoryLimitSynchronous
: public LayerTreeHostFreesWorkerContextResourcesOnZeroMemoryLimit {
public:
void InitializeSettings(LayerTreeSettings* settings) override {
LayerTreeHostContextCacheTest::InitializeSettings(settings);
settings->using_synchronous_renderer_compositor = true;
}
};
// Android Webview only runs in multi-threaded compositing mode.
MULTI_THREAD_TEST_F(
LayerTreeHostFreesWorkerContextResourcesOnZeroMemoryLimitSynchronous);
// Test if the LTH successfully frees main and worker resources when the
// OutputSurface is destroyed.
class LayerTreeHostFreeContextResourcesOnDestroy
: public LayerTreeHostContextCacheTest {
public:
void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl,
const viz::BeginFrameArgs& args,
bool has_damage) override {
if (!first_will_begin_impl_frame_)
return;
first_will_begin_impl_frame_ = false;
// Ensure that our initialization expectations have completed.
Mock::VerifyAndClearExpectations(mock_main_context_support_);
Mock::VerifyAndClearExpectations(mock_worker_context_support_);
// We leave the LTHI visible, so it start freeing resources on destruction.
EXPECT_CALL(*mock_worker_context_support_,
SetAggressivelyFreeResources(true));
EXPECT_CALL(*mock_main_context_support_,
SetAggressivelyFreeResources(true));
EndTest();
}
private:
bool first_will_begin_impl_frame_ = true;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostFreeContextResourcesOnDestroy);
// Test if the LTH successfully frees and stops freeing context resources
// when the LayerTreeFrameSink is lost and recreated.
class LayerTreeHostCacheBehaviorOnLayerTreeFrameSinkRecreated
: public LayerTreeHostContextCacheTest {
public:
void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl,
const viz::BeginFrameArgs& args,
bool has_damage) override {
// This code is run once, to trigger recreation of our LayerTreeFrameSink.
if (test_state_ != TestState::INIT)
return;
// Ensure that our initialization expectations have completed.
Mock::VerifyAndClearExpectations(mock_main_context_support_);
Mock::VerifyAndClearExpectations(mock_worker_context_support_);
// LayerTreeFrameSink lost expectations.
EXPECT_CALL(*mock_worker_context_support_,
SetAggressivelyFreeResources(true));
EXPECT_CALL(*mock_main_context_support_,
SetAggressivelyFreeResources(true));
host_impl->DidLoseLayerTreeFrameSink();
test_state_ = TestState::RECREATED;
}
void InitializedRendererOnThread(LayerTreeHostImpl* host_impl,
bool success) override {
// This is run after we have recreated our LayerTreeFrameSink.
if (test_state_ != TestState::RECREATED)
return;
// Ensure that our expectations have completed.
Mock::VerifyAndClearExpectations(mock_main_context_support_);
Mock::VerifyAndClearExpectations(mock_worker_context_support_);
// Destruction exptectations.
EXPECT_CALL(*mock_worker_context_support_,
SetAggressivelyFreeResources(true));
EXPECT_CALL(*mock_main_context_support_,
SetAggressivelyFreeResources(true));
EndTest();
test_state_ = TestState::DONE;
}
private:
enum class TestState { INIT, RECREATED, DONE };
TestState test_state_ = TestState::INIT;
};
SINGLE_AND_MULTI_THREAD_TEST_F(
LayerTreeHostCacheBehaviorOnLayerTreeFrameSinkRecreated);
// Two setNeedsCommits in a row should lead to at least 1 commit and at least 1
// draw with frame 0.
class LayerTreeHostTestSetNeedsCommit1 : public LayerTreeHostTest {
public:
LayerTreeHostTestSetNeedsCommit1() : num_commits_(0), num_draws_(0) {}
void BeginTest() override {
PostSetNeedsCommitToMainThread();
PostSetNeedsCommitToMainThread();
}
void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
num_draws_++;
if (!impl->active_tree()->source_frame_number())
EndTest();
}
void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
num_commits_++;
}
void AfterTest() override {
EXPECT_LE(1, num_commits_);
EXPECT_LE(1, num_draws_);
}
private:
int num_commits_;
int num_draws_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommit1);
// A SetNeedsCommit should lead to 1 commit. Issuing a second commit after that
// first committed frame draws should lead to another commit.
class LayerTreeHostTestSetNeedsCommit2 : public LayerTreeHostTest {
public:
LayerTreeHostTestSetNeedsCommit2() : num_commits_(0), num_draws_(0) {}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DrawLayersOnThread(LayerTreeHostImpl* impl) override { ++num_draws_; }
void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
++num_commits_;
switch (num_commits_) {
case 1:
PostSetNeedsCommitToMainThread();
break;
case 2:
EndTest();
break;
default:
NOTREACHED();
}
}
void AfterTest() override {
EXPECT_EQ(2, num_commits_);
EXPECT_LE(1, num_draws_);
}
private:
int num_commits_;
int num_draws_;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsCommit2);
// Verify that we pass property values in PushPropertiesTo.
class LayerTreeHostTestPushPropertiesTo : public LayerTreeHostTest {
protected:
void SetupTree() override {
SetInitialRootBounds(gfx::Size(10, 10));
LayerTreeHostTest::SetupTree();
}
enum Properties {
STARTUP,
BOUNDS,
HIDE_LAYER_AND_SUBTREE,
DRAWS_CONTENT,
DONE,
};
void BeginTest() override {
index_ = STARTUP;
PostSetNeedsCommitToMainThread();
}
void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
VerifyAfterValues(impl->active_tree()->root_layer());
}
void DidCommitAndDrawFrame() override {
SetBeforeValues(layer_tree_host()->root_layer());
VerifyBeforeValues(layer_tree_host()->root_layer());
++index_;
if (index_ == DONE) {
EndTest();
return;
}
SetAfterValues(layer_tree_host()->root_layer());
}
void VerifyBeforeValues(Layer* layer) {
EXPECT_EQ(gfx::Size(10, 10).ToString(), layer->bounds().ToString());
EXPECT_FALSE(layer->hide_layer_and_subtree());
EXPECT_FALSE(layer->draws_content());
}
void SetBeforeValues(Layer* layer) {
layer->SetBounds(gfx::Size(10, 10));
layer->SetHideLayerAndSubtree(false);
layer->SetIsDrawable(false);
}
void VerifyAfterValues(LayerImpl* layer) {
const EffectTree& tree =
layer->layer_tree_impl()->property_trees()->effect_tree();
const EffectNode* node = tree.Node(layer->effect_tree_index());
switch (static_cast<Properties>(index_)) {
case STARTUP:
case DONE:
break;
case BOUNDS:
EXPECT_EQ(gfx::Size(20, 20).ToString(), layer->bounds().ToString());
break;
case HIDE_LAYER_AND_SUBTREE:
EXPECT_EQ(tree.EffectiveOpacity(node), 0.f);
break;
case DRAWS_CONTENT:
EXPECT_TRUE(layer->draws_content());
break;
}
}
void SetAfterValues(Layer* layer) {
switch (static_cast<Properties>(index_)) {
case STARTUP:
case DONE:
break;
case BOUNDS:
layer->SetBounds(gfx::Size(20, 20));
break;
case HIDE_LAYER_AND_SUBTREE:
layer->SetHideLayerAndSubtree(true);
break;
case DRAWS_CONTENT:
layer->SetIsDrawable(true);
break;
}
}
int index_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPushPropertiesTo);
// Verify that invisible render passes are excluded in CompositorFrame.
class LayerTreeHostTestInvisibleLayersSkipRenderPass
: public LayerTreeHostTest {
protected:
enum Step {
kAllInvisible,
kOneVisible,
kAllVisible,
kAllInvisibleAgain,
kDone,
};
void SetupTree() override {
SetInitialRootBounds(gfx::Size(10, 10));
LayerTreeHostTest::SetupTree();
auto* root = layer_tree_host()->root_layer();
child1_ = CreateChild(root);
child2_ = CreateChild(root);
}
scoped_refptr<Layer> CreateChild(scoped_refptr<Layer> root) {
auto child = Layer::Create();
// Initially hidden.
child->SetHideLayerAndSubtree(true);
AddBackgroundBlurFilter(child.get());
root->AddChild(child.get());
return child;
}
void AddBackgroundBlurFilter(Layer* layer) {
FilterOperations filters;
filters.Append(FilterOperation::CreateBlurFilter(30, SkTileMode::kClamp));
layer->SetBackdropFilters(filters);
}
void BeginTest() override {
index_ = kAllInvisible;
PostSetNeedsCommitToMainThread();
}
void DidCommitAndDrawFrame() override {
++index_;
switch (index_) {
case kAllInvisible:
NOTREACHED();
case kOneVisible:
child1_->SetHideLayerAndSubtree(false);
break;
case kAllVisible:
child2_->SetHideLayerAndSubtree(false);
break;
case kAllInvisibleAgain:
child1_->SetHideLayerAndSubtree(true);
child2_->SetHideLayerAndSubtree(true);
break;
case kDone:
EndTest();
break;
}
}
void DisplayReceivedCompositorFrameOnThread(
const viz::CompositorFrame& frame) override {
size_t num_render_passes = frame.render_pass_list.size();
switch (index_) {
case kAllInvisible:
// There is only a root render pass.
EXPECT_EQ(1u, num_render_passes);
break;
case kOneVisible:
EXPECT_EQ(2u, num_render_passes);
break;
case kAllVisible:
EXPECT_EQ(3u, num_render_passes);
break;
case kAllInvisibleAgain:
EXPECT_EQ(1u, num_render_passes);
break;
case kDone:
EndTest();
break;
}
}
int index_ = kAllInvisible;
scoped_refptr<Layer> child1_;
scoped_refptr<Layer> child2_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestInvisibleLayersSkipRenderPass);
class LayerTreeHostTestPushNodeOwnerToNodeIdMap : public LayerTreeHostTest {
protected:
void SetupTree() override {
root_ = Layer::Create();
child_ = Layer::Create();
root_->AddChild(child_);
layer_tree_host()->SetRootLayer(root_);
LayerTreeHostTest::SetupTree();
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void WillCommit(const CommitState&) override {
root_transform_index_ = root_->transform_tree_index();
child_transform_index_ = child_->transform_tree_index();
root_effect_index_ = root_->effect_tree_index();
child_effect_index_ = child_->effect_tree_index();
root_clip_index_ = root_->clip_tree_index();
child_clip_index_ = child_->clip_tree_index();
root_scroll_index_ = root_->scroll_tree_index();
child_scroll_index_ = child_->scroll_tree_index();
}
void DidCommit() override {
switch (layer_tree_host()->SourceFrameNumber()) {
case 1:
// child_ should create transform, effect node.
child_->SetForceRenderSurfaceForTesting(true);
break;
case 2:
// child_ should create a scroll node.
child_->SetScrollable(gfx::Size(1, 1));
break;
case 3:
// child_ should create a clip node.
child_->SetMasksToBounds(true);
break;
case 4:
// child_ should only create the scroll-related nodes.
child_->SetMasksToBounds(false);
child_->SetForceRenderSurfaceForTesting(false);
// Should have no effect because empty bounds do not prevent scrolling.
child_->SetScrollable(gfx::Size(0, 0));
}
}
void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
PropertyTrees* property_trees = impl->sync_tree()->property_trees();
const TransformNode* root_transform_node =
property_trees->transform_tree().Node(root_transform_index_);
const TransformNode* child_transform_node =
property_trees->transform_tree().Node(child_transform_index_);
const EffectNode* root_effect_node =
property_trees->effect_tree().Node(root_effect_index_);
const EffectNode* child_effect_node =
property_trees->effect_tree().Node(child_effect_index_);
const ClipNode* root_clip_node =
property_trees->clip_tree().Node(root_clip_index_);
const ClipNode* child_clip_node =
property_trees->clip_tree().Node(child_clip_index_);
const ScrollNode* root_scroll_node =
property_trees->scroll_tree().Node(root_scroll_index_);
const ScrollNode* child_scroll_node =
property_trees->scroll_tree().Node(child_scroll_index_);
switch (impl->sync_tree()->source_frame_number()) {
case 0:
// root_ should create transform, scroll and effect tree nodes but not
// a clip node.
EXPECT_NE(nullptr, root_transform_node);
EXPECT_NE(nullptr, root_effect_node);
EXPECT_NE(nullptr, root_scroll_node);
EXPECT_NE(nullptr, root_clip_node);
EXPECT_EQ(root_transform_node, child_transform_node);
EXPECT_EQ(child_effect_node, root_effect_node);
EXPECT_EQ(root_clip_node, child_clip_node);
EXPECT_EQ(root_scroll_node, child_scroll_node);
break;
case 1:
// child_ should create a transfrom, effect nodes but not a scroll, clip
// node.
EXPECT_NE(root_transform_node, child_transform_node);
EXPECT_NE(child_effect_node, root_effect_node);
EXPECT_EQ(root_clip_node, child_clip_node);
EXPECT_EQ(root_scroll_node, child_scroll_node);
break;
case 2:
// child_ should create a scroll node.
EXPECT_NE(root_scroll_node, child_scroll_node);
break;
case 3:
// child_ should create a clip node.
EXPECT_NE(root_clip_node, child_clip_node);
break;
case 4:
// child_ should only create the scroll-related nodes.
EXPECT_EQ(child_transform_node->id, child_scroll_node->transform_id);
EXPECT_EQ(child_effect_node, root_effect_node);
EXPECT_EQ(root_clip_node, child_clip_node);
EXPECT_NE(root_scroll_node, child_scroll_node);
EndTest();
break;
}
}
private:
scoped_refptr<Layer> root_;
scoped_refptr<Layer> child_;
int root_transform_index_ = kInvalidPropertyNodeId;
int child_transform_index_ = kInvalidPropertyNodeId;
int root_effect_index_ = kInvalidPropertyNodeId;
int child_effect_index_ = kInvalidPropertyNodeId;
int root_clip_index_ = kInvalidPropertyNodeId;
int child_clip_index_ = kInvalidPropertyNodeId;
int root_scroll_index_ = kInvalidPropertyNodeId;
int child_scroll_index_ = kInvalidPropertyNodeId;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPushNodeOwnerToNodeIdMap);
class LayerTreeHostTestPushElementIdToNodeIdMap : public LayerTreeHostTest {
protected:
void SetupTree() override {
root_ = Layer::Create();
child_ = Layer::Create();
root_->AddChild(child_);
layer_tree_host()->SetRootLayer(root_);
LayerTreeHostTest::SetupTree();
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void WillCommit(const CommitState&) override {
child_element_id_ = child_->element_id();
}
void DidCommit() override {
switch (layer_tree_host()->SourceFrameNumber()) {
case 1:
child_->SetForceRenderSurfaceForTesting(true);
child_->SetScrollable(gfx::Size(100, 100));
break;
case 2:
child_->RemoveFromParent();
child_ = Layer::Create();
root_->AddChild(child_);
break;
}
}
void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
PropertyTrees* property_trees = impl->sync_tree()->property_trees();
LayerImpl* child_impl_ = impl->sync_tree()->LayerById(child_->id());
switch (impl->sync_tree()->source_frame_number()) {
case 0:
EXPECT_EQ(2U, child_impl_->layer_tree_impl()
->property_trees()
->transform_tree()
.size());
EXPECT_EQ(2U, child_impl_->layer_tree_impl()
->property_trees()
->effect_tree()
.size());
EXPECT_EQ(2U, child_impl_->layer_tree_impl()
->property_trees()
->scroll_tree()
.size());
EXPECT_EQ(property_trees->scroll_tree().FindNodeFromElementId(
child_element_id_),
nullptr);
EXPECT_EQ(property_trees->effect_tree().FindNodeFromElementId(
child_element_id_),
nullptr);
EXPECT_EQ(property_trees->scroll_tree().FindNodeFromElementId(
child_element_id_),
nullptr);
break;
case 1:
EXPECT_EQ(3U, child_impl_->layer_tree_impl()
->property_trees()
->transform_tree()
.size());
EXPECT_EQ(3U, child_impl_->layer_tree_impl()
->property_trees()
->effect_tree()
.size());
EXPECT_EQ(3U, child_impl_->layer_tree_impl()
->property_trees()
->scroll_tree()
.size());
EXPECT_EQ(2, property_trees->transform_tree()
.FindNodeFromElementId(child_element_id_)
->id);
EXPECT_EQ(2, property_trees->effect_tree()
.FindNodeFromElementId(child_element_id_)
->id);
EXPECT_EQ(2, property_trees->scroll_tree()
.FindNodeFromElementId(child_element_id_)
->id);
break;
case 2:
EXPECT_EQ(2U, child_impl_->layer_tree_impl()
->property_trees()
->transform_tree()
.size());
EXPECT_EQ(2U, child_impl_->layer_tree_impl()
->property_trees()
->effect_tree()
.size());
EXPECT_EQ(property_trees->transform_tree().FindNodeFromElementId(
child_element_id_),
nullptr);
EXPECT_EQ(property_trees->effect_tree().FindNodeFromElementId(
child_element_id_),
nullptr);
EXPECT_EQ(property_trees->scroll_tree().FindNodeFromElementId(
child_element_id_),
nullptr);
break;
}
EndTest();
}
private:
scoped_refptr<Layer> root_;
scoped_refptr<Layer> child_;
ElementId child_element_id_;
};
// Validates that, for a layer with a compositor element id set on it, mappings
// from compositor element id to transform/effect node indexes are created as
// part of building a layer's property tree and are present on the impl thread.
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPushElementIdToNodeIdMap);
class LayerTreeHostTestSurfaceDamage : public LayerTreeHostTest {
protected:
void SetupTree() override {
root_ = Layer::Create();
child_ = Layer::Create();
grand_child_ = Layer::Create();
layer_tree_host()->SetRootLayer(root_);
root_->AddChild(child_);
child_->AddChild(grand_child_);
root_->SetBounds(gfx::Size(50, 50));
root_->SetMasksToBounds(true);
child_->SetForceRenderSurfaceForTesting(true);
LayerTreeHostTest::SetupTree();
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DidCommit() override {
switch (layer_tree_host()->SourceFrameNumber()) {
case 1:
grand_child_->SetOpacity(0.9f);
break;
case 2:
root_->SetBounds(gfx::Size(20, 20));
break;
case 3:
child_->SetOpacity(0.8f);
break;
}
}
DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* impl,
LayerTreeHostImpl::FrameData* frame_data,
DrawResult draw_result) override {
LayerImpl* root_impl = impl->active_tree()->LayerById(root_->id());
LayerImpl* child_impl = impl->active_tree()->LayerById(child_->id());
switch (impl->active_tree()->source_frame_number()) {
case 0:
EXPECT_TRUE(GetRenderSurface(root_impl)->AncestorPropertyChanged());
EXPECT_TRUE(GetRenderSurface(child_impl)->AncestorPropertyChanged());
PostSetNeedsCommitToMainThread();
break;
case 1:
EXPECT_FALSE(GetRenderSurface(root_impl)->AncestorPropertyChanged());
EXPECT_FALSE(GetRenderSurface(child_impl)->AncestorPropertyChanged());
PostSetNeedsCommitToMainThread();
break;
case 2:
EXPECT_TRUE(GetRenderSurface(root_impl)->AncestorPropertyChanged());
EXPECT_TRUE(GetRenderSurface(child_impl)->AncestorPropertyChanged());
PostSetNeedsCommitToMainThread();
break;
case 3:
EXPECT_FALSE(GetRenderSurface(root_impl)->AncestorPropertyChanged());
EXPECT_TRUE(GetRenderSurface(child_impl)->AncestorPropertyChanged());
PostSetNeedsCommitToMainThread();
break;
case 4:
EXPECT_FALSE(GetRenderSurface(root_impl)->AncestorPropertyChanged());
EXPECT_FALSE(GetRenderSurface(child_impl)->AncestorPropertyChanged());
EndTest();
break;
}
return draw_result;
}
private:
scoped_refptr<Layer> root_;
scoped_refptr<Layer> child_;
scoped_refptr<Layer> grand_child_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSurfaceDamage);
class LayerTreeHostTestLayerListSurfaceDamage : public LayerTreeHostTest {
protected:
LayerTreeHostTestLayerListSurfaceDamage() { SetUseLayerLists(); }
void SetupTree() override {
SetInitialRootBounds(gfx::Size(50, 50));
LayerTreeHostTest::SetupTree();
root_ = layer_tree_host()->root_layer();
child_a_ = Layer::Create();
child_a_->SetBounds(gfx::Size(10, 20));
child_a_->SetIsDrawable(true);
CopyProperties(root_, child_a_.get());
auto& effect_a = CreateEffectNode(child_a_.get());
effect_a.render_surface_reason = RenderSurfaceReason::kTest;
root_->AddChild(child_a_);
child_b_ = Layer::Create();
child_b_->SetBounds(gfx::Size(20, 10));
child_b_->SetIsDrawable(true);
CopyProperties(root_, child_b_.get());
auto& effect_b = CreateEffectNode(child_b_.get());
effect_b.render_surface_reason = RenderSurfaceReason::kTest;
root_->AddChild(child_b_);
child_c_ = Layer::Create();
child_c_->SetBounds(gfx::Size(15, 15));
child_c_->SetIsDrawable(true);
CopyProperties(root_, child_c_.get());
auto& effect_c = CreateEffectNode(child_c_.get());
effect_c.render_surface_reason = RenderSurfaceReason::kTest;
root_->AddChild(child_c_);
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DidCommit() override {
switch (layer_tree_host()->SourceFrameNumber()) {
case 1:
// Push an unchanged list. This should cause no damage.
{
LayerList same_list = root_->children();
root_->SetChildLayerList(same_list);
}
break;
case 2:
// Reverse the last two layers so the order becomes: [a, c, b]. This
// should only damage the 'b' layer.
{
LayerList last_two_reversed;
last_two_reversed.push_back(child_a_);
last_two_reversed.push_back(child_c_);
last_two_reversed.push_back(child_b_);
root_->SetChildLayerList(last_two_reversed);
}
break;
case 3:
// Reverse the first two layers so the order becomes: [c, a, b]. This
// should damage the last two layers, 'a' and 'b'.
{
LayerList last_pair_reversed;
last_pair_reversed.push_back(child_c_);
last_pair_reversed.push_back(child_a_);
last_pair_reversed.push_back(child_b_);
root_->SetChildLayerList(last_pair_reversed);
}
break;
case 4:
// Remove the first layer, 'c', so the order becomes: ['a', 'b']. This
// should not damage 'a' or 'b'.
{
LayerList first_removed = root_->children();
first_removed.erase(first_removed.begin());
root_->SetChildLayerList(first_removed);
}
break;
case 5:
// Add a new layer, 'c', so the order becomes: ['a', 'b', 'c']. This
// should only damage 'c'.
{
LayerList existing_plus_new_child = root_->children();
existing_plus_new_child.push_back(child_c_);
root_->SetChildLayerList(existing_plus_new_child);
}
break;
}
}
DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* impl,
LayerTreeHostImpl::FrameData* frame_data,
DrawResult draw_result) override {
LayerImpl* child_a_impl = impl->active_tree()->LayerById(child_a_->id());
LayerImpl* child_b_impl = impl->active_tree()->LayerById(child_b_->id());
LayerImpl* child_c_impl = impl->active_tree()->LayerById(child_c_->id());
switch (impl->active_tree()->source_frame_number()) {
case 0:
// Full damage on first frame.
EXPECT_EQ(GetRenderSurface(child_a_impl)->GetDamageRect(),
gfx::Rect(0, 0, 10, 20));
EXPECT_EQ(GetRenderSurface(child_b_impl)->GetDamageRect(),
gfx::Rect(0, 0, 20, 10));
EXPECT_EQ(GetRenderSurface(child_c_impl)->GetDamageRect(),
gfx::Rect(0, 0, 15, 15));
PostSetNeedsCommitToMainThread();
break;
case 1:
// No damage after pushing the same list.
EXPECT_TRUE(GetRenderSurface(child_a_impl)->GetDamageRect().IsEmpty());
EXPECT_TRUE(GetRenderSurface(child_b_impl)->GetDamageRect().IsEmpty());
EXPECT_TRUE(GetRenderSurface(child_c_impl)->GetDamageRect().IsEmpty());
PostSetNeedsCommitToMainThread();
break;
case 2:
// Only 'b' damaged after reversing the last two layers.
EXPECT_TRUE(GetRenderSurface(child_a_impl)->GetDamageRect().IsEmpty());
EXPECT_EQ(GetRenderSurface(child_b_impl)->GetDamageRect(),
gfx::Rect(0, 0, 20, 10));
EXPECT_TRUE(GetRenderSurface(child_c_impl)->GetDamageRect().IsEmpty());
PostSetNeedsCommitToMainThread();
break;
case 3:
// 'a' and 'b' damaged after reversing the first two layers.
EXPECT_EQ(GetRenderSurface(child_a_impl)->GetDamageRect(),
gfx::Rect(0, 0, 10, 20));
EXPECT_EQ(GetRenderSurface(child_b_impl)->GetDamageRect(),
gfx::Rect(0, 0, 20, 10));
EXPECT_TRUE(GetRenderSurface(child_c_impl)->GetDamageRect().IsEmpty());
PostSetNeedsCommitToMainThread();
break;
case 4:
// When the first layer, 'c', is removed, 'a' and 'b' should not be
// damaged.
EXPECT_TRUE(GetRenderSurface(child_a_impl)->GetDamageRect().IsEmpty());
EXPECT_TRUE(GetRenderSurface(child_b_impl)->GetDamageRect().IsEmpty());
PostSetNeedsCommitToMainThread();
break;
case 5:
// When 'c' is added, 'a' and 'b' should not be damaged.
EXPECT_TRUE(GetRenderSurface(child_a_impl)->GetDamageRect().IsEmpty());
EXPECT_TRUE(GetRenderSurface(child_b_impl)->GetDamageRect().IsEmpty());
EXPECT_EQ(GetRenderSurface(child_c_impl)->GetDamageRect(),
gfx::Rect(0, 0, 15, 15));
EndTest();
break;
}
return draw_result;
}
private:
raw_ptr<Layer, DanglingUntriaged> root_;
scoped_refptr<Layer> child_a_;
scoped_refptr<Layer> child_b_;
scoped_refptr<Layer> child_c_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLayerListSurfaceDamage);
// When settings->enable_early_damage_check is true, verify that invalidate is
// not called when changes to a layer don't cause visible damage.
class LayerTreeHostTestNoDamageCausesNoInvalidate : public LayerTreeHostTest {
void InitializeSettings(LayerTreeSettings* settings) override {
settings->using_synchronous_renderer_compositor = true;
settings->enable_early_damage_check = true;
}
protected:
void SetupTree() override {
scoped_refptr<Layer> root = Layer::Create();
layer_ = Layer::Create();
root->AddChild(layer_);
layer_tree_host()->SetViewportRectAndScale(gfx::Rect(10, 10), 1.f,
viz::LocalSurfaceId());
layer_tree_host()->SetRootLayer(root);
// Translate the root layer past the viewport.
gfx::Transform translation;
translation.Translate(100, 100);
layer_->SetTransform(translation);
root->SetBounds(gfx::Size(50, 50));
layer_->SetBounds(gfx::Size(50, 50));
LayerTreeHostTest::SetupTree();
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DidCommit() override {
// This does not damage the frame because the root layer is outside the
// viewport.
if (layer_tree_host()->SourceFrameNumber() == 2)
layer_->SetOpacity(0.9f);
}
DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* impl,
LayerTreeHostImpl::FrameData* frame_data,
DrawResult draw_result) override {
PostSetNeedsCommitToMainThread();
return draw_result;
}
void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
switch (impl->active_tree()->source_frame_number()) {
// This gives us some assurance that invalidates happen before this call,
// so invalidating on frame 2 will cause a failure before the test ends.
case 0:
EXPECT_TRUE(first_frame_invalidate_before_commit_);
break;
case 2:
EndTest();
break;
}
}
void DidInvalidateLayerTreeFrameSink(LayerTreeHostImpl* impl) override {
int source_frame_number = impl->active_tree()->source_frame_number();
if (source_frame_number == 0) {
// Be sure that invalidates happen before commits, so the below failure
// works.
first_frame_invalidate_before_commit_ = true;
} else if (source_frame_number > 0) {
// The first frame (frame number 0) has damage because it's the first
// frame. All subsequent frames in this test are set up to have no damage.
// The early damage check will prevent further invalidates without damage
// after 2 consecutive invalidates without damage. So check there is no
// more than 2.
invalidate_without_damage_count_++;
EXPECT_LT(invalidate_without_damage_count_, 2);
}
}
private:
scoped_refptr<Layer> layer_;
bool first_frame_invalidate_before_commit_ = false;
int invalidate_without_damage_count_ = 0;
};
// This behavior is specific to Android WebView, which only uses
// multi-threaded compositor.
// TODO(crbug.com/40853271): Flaky.
// MULTI_THREAD_TEST_F(LayerTreeHostTestNoDamageCausesNoInvalidate);
// When settings->enable_early_damage_check is true, verify that the early
// damage check is turned off after |settings->damaged_frame_limit| frames
// have consecutive damage.
// The test verifies that frames come in as follows:
// 0: visible damage as the root appears; invalidated
// 1: no visible damage; invalidate because all previous frames had damage
// 2: no visible damage; check early since frame 1 had no damage; no invalidate
// 3: visible damage
// ... (visible damage)
// 3 + damaged_frame_limit - 1: visible damage
// 3 + damaged_frame_limit: no visible damage, but invalidate because all of
// the last |damaged_frame_limit| frames had damage.
class LayerTreeHostTestEarlyDamageCheckStops : public LayerTreeHostTest {
void InitializeSettings(LayerTreeSettings* settings) override {
settings->using_synchronous_renderer_compositor = true;
settings->enable_early_damage_check = true;
damaged_frame_limit_ = settings->damaged_frame_limit;
}
protected:
void SetupTree() override {
root_ = Layer::Create();
child_ = Layer::Create();
root_->AddChild(child_);
layer_tree_host()->SetViewportRectAndScale(gfx::Rect(100, 100), 1.f,
viz::LocalSurfaceId());
layer_tree_host()->SetRootLayer(root_);
root_->SetBounds(gfx::Size(50, 50));
child_->SetBounds(gfx::Size(50, 50));
// Translate the child layer past the viewport.
gfx::Transform translation;
translation.Translate(200, 200);
child_->SetTransform(translation);
LayerTreeHostTest::SetupTree();
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void WillBeginMainFrame() override {
int frame = layer_tree_host()->SourceFrameNumber();
// Change the child layer each frame. Since the child layer is translated
// past the viewport, it should not cause damage, but webview will still
// invalidate if the frame doesn't check for damage early.
child_->SetOpacity(1.0f / (frame + 1));
// For |damaged_frame_limit| consecutive frames, cause actual damage.
if (frame >= 3 && frame < (damaged_frame_limit_ + 3)) {
root_->SetOpacity(1.0f / frame);
}
}
void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
PostSetNeedsCommitToMainThread();
}
void DidInvalidateLayerTreeFrameSink(LayerTreeHostImpl* impl) override {
int frame_number = impl->active_tree()->source_frame_number();
// Frames 0 and 1 invalidate because the early damage check is not enabled
// during this setup. But frames 1 and 2 are not damaged, so the early
// check should prevent frame 2 from invalidating.
if (frame_number == 2) {
ADD_FAILURE();
} else if (frame_number > 2) {
invalidate_count_++;
}
// Frame number |damaged_frame_limit_ + 3| was not damaged, but it should
// invalidate since the previous |damaged_frame_limit_| frames had damage
// and should have turned off the early damage check.
if (frame_number == damaged_frame_limit_ + 3) {
EndTest();
return;
}
}
void AfterTest() override {
// We should invalidate |damaged_frame_limit_| frames that had actual damage
// and one additional frame after, since the early check is disabled.
EXPECT_EQ(invalidate_count_, damaged_frame_limit_ + 1);
}
private:
scoped_refptr<Layer> root_;
scoped_refptr<Layer> child_;
int invalidate_count_ = 0;
int damaged_frame_limit_;
};
// This behavior is specific to Android WebView, which only uses
// multi-threaded compositor.
// TODO(crbug.com/40669342): Disabled because test is flaky on Mac10.13.
// MULTI_THREAD_TEST_F(LayerTreeHostTestEarlyDamageCheckStops);
// When settings->enable_early_damage_check is true, verifies that PrepareTiles
// need not cause a draw when there is no visible damage. Here, a child layer is
// translated outside of the viewport. After two draws, the early damage check
// should prevent further draws, but preventing further draws should not prevent
// PrepareTiles.
class LayerTreeHostTestPrepareTilesWithoutDraw : public LayerTreeHostTest {
void InitializeSettings(LayerTreeSettings* settings) override {
settings->using_synchronous_renderer_compositor = true;
settings->enable_early_damage_check = true;
}
protected:
void SetupTree() override {
LayerTreeHostTest::SetupTree();
child_layer_ = Layer::Create();
layer_tree_host()->root_layer()->AddChild(child_layer_);
layer_tree_host()->SetViewportRectAndScale(gfx::Rect(10, 10), 1.f,
viz::LocalSurfaceId());
layer_tree_host()->root_layer()->SetBounds(gfx::Size(50, 50));
child_layer_->SetBounds(gfx::Size(50, 50));
// Translate the child layer past the viewport.
gfx::Transform translation;
translation.Translate(100, 100);
child_layer_->SetTransform(translation);
child_layer_->SetBounds(gfx::Size(50, 50));
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DidCommit() override {
int frame_number = layer_tree_host()->SourceFrameNumber();
if (frame_number > 3) {
EndTest();
return;
}
// Modify the child layer each frame.
float new_opacity = 0.9f / (frame_number + 1);
child_layer_->SetOpacity(new_opacity);
PostSetNeedsCommitToMainThread();
}
void WillPrepareTilesOnThread(LayerTreeHostImpl* impl) override {
if (impl->active_tree()->source_frame_number() >= 0)
prepare_tiles_count_++;
switch (impl->active_tree()->source_frame_number()) {
case 0:
EXPECT_EQ(1, prepare_tiles_count_);
break;
case 1:
EXPECT_EQ(2, prepare_tiles_count_);
break;
case 2:
EXPECT_EQ(3, prepare_tiles_count_);
break;
}
}
void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
draw_count_++;
switch (impl->active_tree()->source_frame_number()) {
case 0:
// There is actual damage as the layers are set up.
EXPECT_EQ(1, draw_count_);
break;
case 1:
// There is no damage, but draw because the early damage check
// didn't occur.
EXPECT_EQ(2, draw_count_);
break;
default:
// After the first two draws, the early damage check should kick
// in and prevent further draws.
ADD_FAILURE();
}
}
void AfterTest() override { EXPECT_EQ(2, draw_count_); }
private:
scoped_refptr<Layer> child_layer_;
int prepare_tiles_count_ = 0;
int draw_count_ = 0;
};
// This behavior is specific to Android WebView, which only uses
// multi-threaded compositor.
// Flaky: https://crbug.com/947673
// MULTI_THREAD_TEST_F(LayerTreeHostTestPrepareTilesWithoutDraw);
// Verify CanDraw() is false until first commit.
class LayerTreeHostTestCantDrawBeforeCommit : public LayerTreeHostTest {
protected:
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void ReadyToCommitOnThread(LayerTreeHostImpl* host_impl) override {
EXPECT_FALSE(host_impl->CanDraw());
}
void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
EXPECT_TRUE(host_impl->CanDraw());
EndTest();
}
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestCantDrawBeforeCommit);
// Verify CanDraw() is false until first commit+activate.
class LayerTreeHostTestCantDrawBeforeCommitActivate : public LayerTreeHostTest {
protected:
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
EXPECT_FALSE(host_impl->CanDraw());
}
void WillActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
EXPECT_FALSE(host_impl->CanDraw());
}
void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
EXPECT_TRUE(host_impl->CanDraw());
EndTest();
}
};
// Single thread mode commits directly to the active tree, so CanDraw()
// is true by the time WillActivateTreeOnThread is called.
MULTI_THREAD_TEST_F(LayerTreeHostTestCantDrawBeforeCommitActivate);
// Verify damage status of property trees is preserved after commit.
class LayerTreeHostTestPropertyTreesChangedSync : public LayerTreeHostTest {
protected:
void SetupTree() override {
root_ = Layer::Create();
child_ = Layer::Create();
// This is to force the child to create a transform and effect node.
child_->SetForceRenderSurfaceForTesting(true);
root_->AddChild(child_);
layer_tree_host()->SetRootLayer(root_);
LayerTreeHostTest::SetupTree();
}
enum Animations {
OPACITY,
TRANSFORM,
FILTER,
END,
};
void BeginTest() override {
index_ = OPACITY;
PostSetNeedsCommitToMainThread();
}
void DidCommit() override {
switch (layer_tree_host()->SourceFrameNumber()) {
case 2:
// We rebuild property trees for this case to test the code path of
// damage status synchronization when property trees are different.
layer_tree_host()->property_trees()->set_needs_rebuild(true);
break;
default:
EXPECT_FALSE(layer_tree_host()->property_trees()->needs_rebuild());
}
}
void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
gfx::Transform transform;
FilterOperations filters;
LayerImpl* root = impl->active_tree()->root_layer();
switch (static_cast<Animations>(index_)) {
case OPACITY:
index_++;
impl->active_tree()->ResetAllChangeTracking();
impl->active_tree()->SetOpacityMutated(root->element_id(), 0.5f);
PostSetNeedsCommitToMainThread();
break;
case TRANSFORM:
index_++;
EXPECT_TRUE(impl->active_tree()
->LayerById(root_->id())
->LayerPropertyChanged());
impl->active_tree()->ResetAllChangeTracking();
EXPECT_FALSE(impl->active_tree()
->LayerById(root_->id())
->LayerPropertyChanged());
EXPECT_FALSE(impl->active_tree()
->LayerById(child_->id())
->LayerPropertyChanged());
transform.Translate(10, 10);
impl->active_tree()->SetTransformMutated(root->element_id(), transform);
PostSetNeedsCommitToMainThread();
break;
case FILTER:
index_++;
EXPECT_TRUE(root->LayerPropertyChanged());
EXPECT_TRUE(impl->active_tree()
->LayerById(child_->id())
->LayerPropertyChanged());
impl->active_tree()->ResetAllChangeTracking();
EXPECT_FALSE(root->LayerPropertyChanged());
EXPECT_FALSE(impl->active_tree()
->LayerById(child_->id())
->LayerPropertyChanged());
filters.Append(FilterOperation::CreateOpacityFilter(0.5f));
impl->active_tree()->SetFilterMutated(root->element_id(), filters);
PostSetNeedsCommitToMainThread();
break;
case END:
EXPECT_TRUE(root->LayerPropertyChanged());
EndTest();
break;
}
}
private:
int index_;
scoped_refptr<Layer> root_;
scoped_refptr<Layer> child_;
};
SINGLE_THREAD_TEST_F(LayerTreeHostTestPropertyTreesChangedSync);
class LayerTreeHostTestAnimationOpacityMutatedNotUsingLayerLists
: public LayerTreeHostTest {
protected:
void BeginTest() override {
Layer* root = layer_tree_host()->root_layer();
EXPECT_EQ(1.0f, root->opacity());
layer_tree_host()->SetElementOpacityMutated(root->element_id(),
ElementListType::ACTIVE, 0.3f);
// When not using layer lists, opacity is stored on the layer.
EXPECT_EQ(0.3f, root->opacity());
EndTest();
}
};
SINGLE_THREAD_TEST_F(
LayerTreeHostTestAnimationOpacityMutatedNotUsingLayerLists);
class LayerTreeHostTestAnimationOpacityMutatedUsingLayerLists
: public LayerTreeHostTest {
public:
LayerTreeHostTestAnimationOpacityMutatedUsingLayerLists() {
SetUseLayerLists();
}
protected:
void BeginTest() override {
Layer* root = layer_tree_host()->root_layer();
EXPECT_EQ(1.0f, layer_tree_host()
->property_trees()
->effect_tree()
.FindNodeFromElementId(root->element_id())
->opacity);
layer_tree_host()->SetElementOpacityMutated(root->element_id(),
ElementListType::ACTIVE, 0.3f);
// The opacity should have been set directly on the effect node instead.
EXPECT_EQ(0.3f, layer_tree_host()
->property_trees()
->effect_tree()
.FindNodeFromElementId(root->element_id())
->opacity);
EndTest();
}
};
SINGLE_THREAD_TEST_F(LayerTreeHostTestAnimationOpacityMutatedUsingLayerLists);
class LayerTreeHostTestAnimationTransformMutatedNotUsingLayerLists
: public LayerTreeHostTest {
protected:
void SetupTree() override {
root_ = Layer::Create();
child_ = Layer::Create();
root_->AddChild(child_);
layer_tree_host()->SetRootLayer(root_);
LayerTreeHostTest::SetupTree();
}
void BeginTest() override {
EXPECT_EQ(gfx::Transform(), child_->transform());
gfx::Transform expected_transform;
expected_transform.Translate(42, 42);
layer_tree_host()->SetElementTransformMutated(
child_->element_id(), ElementListType::ACTIVE, expected_transform);
// When not using layer lists, transform is stored on the layer.
EXPECT_EQ(expected_transform, child_->transform());
EndTest();
}
private:
scoped_refptr<Layer> root_;
scoped_refptr<Layer> child_;
};
SINGLE_THREAD_TEST_F(
LayerTreeHostTestAnimationTransformMutatedNotUsingLayerLists);
class LayerTreeHostTestAnimationTransformMutatedUsingLayerLists
: public LayerTreeHostTest {
public:
LayerTreeHostTestAnimationTransformMutatedUsingLayerLists() {
SetUseLayerLists();
}
protected:
void BeginTest() override {
Layer* root = layer_tree_host()->root_layer();
EXPECT_EQ(gfx::Transform(), layer_tree_host()
->property_trees()
->transform_tree()
.FindNodeFromElementId(root->element_id())
->local);
gfx::Transform expected_transform;
expected_transform.Translate(42, 42);
layer_tree_host()->SetElementTransformMutated(
root->element_id(), ElementListType::ACTIVE, expected_transform);
// The transform should have been set directly on the transform node
// instead.
EXPECT_EQ(expected_transform, layer_tree_host()
->property_trees()
->transform_tree()
.FindNodeFromElementId(root->element_id())
->local);
EndTest();
}
};
SINGLE_THREAD_TEST_F(LayerTreeHostTestAnimationTransformMutatedUsingLayerLists);
class LayerTreeHostTestAnimationFilterMutatedNotUsingLayerLists
: public LayerTreeHostTest {
protected:
void BeginTest() override {
Layer* root = layer_tree_host()->root_layer();
FilterOperations filters;
EXPECT_EQ(FilterOperations(), root->filters());
filters.Append(FilterOperation::CreateOpacityFilter(0.5f));
layer_tree_host()->SetElementFilterMutated(
root->element_id(), ElementListType::ACTIVE, filters);
// When not using layer lists, filters are just stored directly on the
// layer.
EXPECT_EQ(filters, root->filters());
EndTest();
}
};
SINGLE_THREAD_TEST_F(LayerTreeHostTestAnimationFilterMutatedNotUsingLayerLists);
class LayerTreeHostTestAnimationFilterMutatedUsingLayerLists
: public LayerTreeHostTest {
public:
LayerTreeHostTestAnimationFilterMutatedUsingLayerLists() {
SetUseLayerLists();
}
protected:
void BeginTest() override {
Layer* root = layer_tree_host()->root_layer();
EXPECT_EQ(FilterOperations(), layer_tree_host()
->property_trees()
->effect_tree()
.FindNodeFromElementId(root->element_id())
->filters);
FilterOperations filters;
filters.Append(FilterOperation::CreateOpacityFilter(0.5f));
layer_tree_host()->SetElementFilterMutated(
root->element_id(), ElementListType::ACTIVE, filters);
// The filter should have been set directly on the effect node instead.
EXPECT_EQ(filters, layer_tree_host()
->property_trees()
->effect_tree()
.FindNodeFromElementId(root->element_id())
->filters);
EndTest();
}
};
SINGLE_THREAD_TEST_F(LayerTreeHostTestAnimationFilterMutatedUsingLayerLists);
class LayerTreeHostTestEffectTreeSync : public LayerTreeHostTest {
protected:
void SetupTree() override {
root_ = Layer::Create();
layer_tree_host()->SetRootLayer(root_);
blur_filter_.Append(FilterOperation::CreateBlurFilter(0.5f));
brightness_filter_.Append(FilterOperation::CreateBrightnessFilter(0.25f));
sepia_filter_.Append(FilterOperation::CreateSepiaFilter(0.75f));
LayerTreeHostTest::SetupTree();
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void WillCommit(const CommitState&) override {
root_effect_tree_index_ =
const_cast<const LayerTreeHost*>(layer_tree_host())
->root_layer()
->effect_tree_index();
}
void DidCommit() override {
EffectTree& effect_tree =
layer_tree_host()->property_trees()->effect_tree_mutable();
EffectNode* node = effect_tree.Node(root_effect_tree_index_);
switch (layer_tree_host()->SourceFrameNumber()) {
case 1:
node->opacity = 0.5f;
node->is_currently_animating_opacity = true;
break;
case 2:
node->is_currently_animating_opacity = true;
break;
case 3:
node->is_currently_animating_opacity = false;
break;
case 4:
node->opacity = 0.25f;
node->is_currently_animating_opacity = true;
break;
case 5:
node->filters = blur_filter_;
node->is_currently_animating_filter = true;
break;
case 6:
node->is_currently_animating_filter = true;
break;
case 7:
node->is_currently_animating_filter = false;
break;
case 8:
node->filters = sepia_filter_;
node->is_currently_animating_filter = true;
break;
}
}
void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
EffectTree& effect_tree =
impl->sync_tree()->property_trees()->effect_tree_mutable();
LayerImpl* root = impl->sync_tree()->root_layer();
EffectNode* node = effect_tree.Node(root_effect_tree_index_);
switch (impl->sync_tree()->source_frame_number()) {
case 0:
impl->sync_tree()->SetOpacityMutated(root->element_id(), 0.75f);
PostSetNeedsCommitToMainThread();
break;
case 1:
impl->sync_tree()->SetOpacityMutated(root->element_id(), 0.75f);
EXPECT_EQ(node->opacity, 0.75f);
PostSetNeedsCommitToMainThread();
break;
case 2:
impl->sync_tree()->SetOpacityMutated(root->element_id(), 0.75f);
EXPECT_EQ(node->opacity, 0.75f);
impl->sync_tree()->SetOpacityMutated(root->element_id(), 0.75f);
PostSetNeedsCommitToMainThread();
break;
case 3:
EXPECT_EQ(node->opacity, 0.5f);
PostSetNeedsCommitToMainThread();
break;
case 4:
EXPECT_EQ(node->opacity, 0.25f);
impl->sync_tree()->SetFilterMutated(root->element_id(),
brightness_filter_);
PostSetNeedsCommitToMainThread();
break;
case 5:
impl->sync_tree()->SetFilterMutated(root->element_id(),
brightness_filter_);
EXPECT_EQ(node->filters, brightness_filter_);
PostSetNeedsCommitToMainThread();
break;
case 6:
impl->sync_tree()->SetFilterMutated(root->element_id(),
brightness_filter_);
EXPECT_EQ(node->filters, brightness_filter_);
PostSetNeedsCommitToMainThread();
break;
case 7:
EXPECT_EQ(node->filters, blur_filter_);
PostSetNeedsCommitToMainThread();
break;
case 8:
EXPECT_EQ(node->filters, sepia_filter_);
EndTest();
break;
}
}
private:
scoped_refptr<Layer> root_;
int root_effect_tree_index_ = kInvalidPropertyNodeId;
FilterOperations blur_filter_;
FilterOperations brightness_filter_;
FilterOperations sepia_filter_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestEffectTreeSync);
class LayerTreeHostTestTransformTreeSync : public LayerTreeHostTest {
protected:
void SetupTree() override {
scoped_refptr<Layer> root = Layer::Create();
layer_ = Layer::Create();
// Force a transform node for the layer.
gfx::Transform rotate5;
rotate5.Rotate(5.f);
layer_->SetTransform(rotate5);
root->AddChild(layer_);
layer_tree_host()->SetRootLayer(root);
LayerTreeHostTest::SetupTree();
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void WillCommit(const CommitState&) override {
transform_tree_index_ = layer_->transform_tree_index();
}
void DidCommit() override {
TransformTree& transform_tree =
layer_tree_host()->property_trees()->transform_tree_mutable();
TransformNode* node = transform_tree.Node(transform_tree_index_);
gfx::Transform rotate10;
rotate10.Rotate(10.f);
switch (layer_tree_host()->SourceFrameNumber()) {
case 1:
node->local = rotate10;
node->is_currently_animating = true;
break;
case 2:
node->is_currently_animating = true;
break;
case 3:
node->is_currently_animating = false;
break;
case 4:
node->local = gfx::Transform();
node->is_currently_animating = true;
break;
}
}
void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
TransformTree& transform_tree =
impl->sync_tree()->property_trees()->transform_tree_mutable();
const LayerImpl* layer = impl->sync_tree()->LayerById(layer_->id());
const TransformNode* node =
transform_tree.Node(layer->transform_tree_index());
gfx::Transform rotate10;
rotate10.Rotate(10.f);
gfx::Transform rotate20;
rotate20.Rotate(20.f);
switch (impl->sync_tree()->source_frame_number()) {
case 0:
impl->sync_tree()->SetTransformMutated(layer->element_id(), rotate20);
PostSetNeedsCommitToMainThread();
break;
case 1:
impl->sync_tree()->SetTransformMutated(layer->element_id(), rotate20);
EXPECT_EQ(node->local, rotate20);
PostSetNeedsCommitToMainThread();
break;
case 2:
impl->sync_tree()->SetTransformMutated(layer->element_id(), rotate20);
EXPECT_EQ(node->local, rotate20);
PostSetNeedsCommitToMainThread();
break;
case 3:
EXPECT_EQ(node->local, rotate10);
PostSetNeedsCommitToMainThread();
break;
case 4:
EXPECT_EQ(node->local, gfx::Transform());
EndTest();
}
}
private:
scoped_refptr<Layer> layer_;
int transform_tree_index_ = kInvalidPropertyNodeId;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestTransformTreeSync);
// Verify damage status is updated even when the transform tree doesn't need
// to be updated at draw time.
class LayerTreeHostTestTransformTreeDamageIsUpdated : public LayerTreeHostTest {
protected:
void SetupTree() override {
root_ = Layer::Create();
child_ = Layer::Create();
grand_child_ = Layer::Create();
root_->SetBounds(gfx::Size(50, 50));
// Make sure child and grand_child have transform nodes.
gfx::Transform rotation;
rotation.RotateAboutZAxis(45.0);
child_->SetTransform(rotation);
grand_child_->SetTransform(rotation);
root_->AddChild(child_);
child_->AddChild(grand_child_);
layer_tree_host()->SetRootLayer(root_);
LayerTreeHostTest::SetupTree();
child_element_id_ = child_->element_id();
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DidCommit() override {
if (layer_tree_host()->SourceFrameNumber() == 1) {
gfx::Transform scale;
scale.Scale(2.0, 2.0);
layer_tree_host()->SetElementTransformMutated(
child_element_id_, ElementListType::ACTIVE, scale);
}
}
void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
if (impl->sync_tree()->source_frame_number() == 0)
PostSetNeedsCommitToMainThread();
}
DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* impl,
LayerTreeHostImpl::FrameData* frame_data,
DrawResult draw_result) override {
if (impl->active_tree()->source_frame_number() == 1) {
EXPECT_FALSE(
impl->active_tree()->LayerById(root_->id())->LayerPropertyChanged());
EXPECT_TRUE(
impl->active_tree()->LayerById(child_->id())->LayerPropertyChanged());
EXPECT_TRUE(impl->active_tree()
->LayerById(grand_child_->id())
->LayerPropertyChanged());
EndTest();
}
return draw_result;
}
void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
if (impl->active_tree()->source_frame_number() == 0) {
gfx::Transform scale;
scale.Scale(2.0, 2.0);
impl->active_tree()->SetTransformMutated(child_element_id_, scale);
}
}
private:
scoped_refptr<Layer> root_;
scoped_refptr<Layer> child_;
scoped_refptr<Layer> grand_child_;
ElementId child_element_id_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestTransformTreeDamageIsUpdated);
class UpdateCountingLayer : public PictureLayer {
public:
explicit UpdateCountingLayer(ContentLayerClient* client)
: PictureLayer(client) {}
bool Update() override {
update_count_++;
return false;
}
int update_count() const { return update_count_; }
private:
~UpdateCountingLayer() override = default;
int update_count_ = 0;
};
// Test that when mask layers switches layers, this gets pushed onto impl.
// Also test that mask layer is in the layer update list even if its owning
// layer isn't.
class LayerTreeHostTestSwitchMaskLayer : public LayerTreeHostTest {
protected:
void SetupTree() override {
scoped_refptr<Layer> root = Layer::Create();
root->SetBounds(gfx::Size(10, 10));
// child_layer_ is not drawable.
child_layer_ = base::MakeRefCounted<UpdateCountingLayer>(&client_);
child_layer_->SetBounds(gfx::Size(10, 10));
mask_layer_ = base::MakeRefCounted<UpdateCountingLayer>(&client_);
mask_layer_->SetBounds(gfx::Size(10, 10));
mask_layer_->SetIsDrawable(true);
child_layer_->SetMaskLayer(mask_layer_);
root->AddChild(child_layer_);
layer_tree_host()->SetRootLayer(root);
LayerTreeHostTest::SetupTree();
}
void BeginTest() override {
index_ = 0;
PostSetNeedsCommitToMainThread();
}
void DidCommit() override {
switch (layer_tree_host()->SourceFrameNumber()) {
case 1:
// Root and mask layer should have the same source frame number as they
// will be in the layer update list but the child is not as it doesn't
// draw content.
EXPECT_EQ(mask_layer_->update_count(), 1);
EXPECT_EQ(child_layer_->update_count(), 0);
layer_tree_host()->root_layer()->RemoveAllChildren();
layer_tree_host()->root_layer()->SetMaskLayer(mask_layer_);
break;
}
}
void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
auto* mask_surface =
GetRenderSurface(impl->sync_tree()->LayerById(mask_layer_->id()));
auto* root_surface = GetRenderSurface(impl->sync_tree()->root_layer());
ASSERT_TRUE(mask_surface);
switch (index_) {
case 0: {
index_++;
auto* child_surface =
GetRenderSurface(impl->sync_tree()->LayerById(child_layer_->id()));
EXPECT_EQ(child_surface, mask_surface->render_target());
EXPECT_NE(child_surface, root_surface);
break;
}
case 1:
EXPECT_EQ(mask_surface->render_target(), root_surface);
EndTest();
break;
}
}
FakeContentLayerClient client_;
scoped_refptr<UpdateCountingLayer> mask_layer_;
scoped_refptr<UpdateCountingLayer> child_layer_;
int index_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSwitchMaskLayer);
// 1 setNeedsRedraw after the first commit has completed should lead to 1
// additional draw.
class LayerTreeHostTestSetNeedsRedraw : public LayerTreeHostTest {
public:
LayerTreeHostTestSetNeedsRedraw() : num_commits_(0), num_draws_(0) {}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
EXPECT_EQ(0, impl->active_tree()->source_frame_number());
if (!num_draws_) {
// Redraw again to verify that the second redraw doesn't commit.
PostSetNeedsRedrawToMainThread();
} else {
EndTest();
}
num_draws_++;
}
void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
EXPECT_EQ(0, num_draws_);
num_commits_++;
}
void AfterTest() override {
EXPECT_GE(2, num_draws_);
EXPECT_EQ(1, num_commits_);
}
private:
int num_commits_;
int num_draws_;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedraw);
// After setNeedsRedrawRect(invalid_rect) the final damage_rect
// must contain invalid_rect.
class LayerTreeHostTestSetNeedsRedrawRect : public LayerTreeHostTest {
public:
LayerTreeHostTestSetNeedsRedrawRect()
: num_draws_(0), bounds_(50, 50), invalid_rect_(10, 10, 20, 20) {}
void BeginTest() override {
root_layer_ = FakePictureLayer::Create(&client_);
root_layer_->SetIsDrawable(true);
root_layer_->SetBounds(bounds_);
layer_tree_host()->SetRootLayer(root_layer_);
layer_tree_host()->SetViewportRectAndScale(gfx::Rect(bounds_), 1.f,
viz::LocalSurfaceId());
PostSetNeedsCommitToMainThread();
client_.set_bounds(root_layer_->bounds());
}
DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
LayerTreeHostImpl::FrameData* frame_data,
DrawResult draw_result) override {
EXPECT_EQ(DrawResult::kSuccess, draw_result);
gfx::Rect root_damage_rect;
if (!frame_data->render_passes.empty())
root_damage_rect = frame_data->render_passes.back()->damage_rect;
if (!num_draws_) {
// If this is the first frame, expect full frame damage.
EXPECT_EQ(root_damage_rect, gfx::Rect(bounds_));
} else {
// Check that invalid_rect_ is indeed repainted.
EXPECT_TRUE(root_damage_rect.Contains(invalid_rect_));
}
return draw_result;
}
void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
if (!num_draws_) {
PostSetNeedsRedrawRectToMainThread(invalid_rect_);
} else {
EndTest();
}
num_draws_++;
}
void AfterTest() override { EXPECT_EQ(2, num_draws_); }
private:
int num_draws_;
const gfx::Size bounds_;
const gfx::Rect invalid_rect_;
FakeContentLayerClient client_;
scoped_refptr<FakePictureLayer> root_layer_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetNeedsRedrawRect);
// Ensure the texture size of the pending and active trees are identical when a
// layer is not in the viewport and a resize happens on the viewport
class LayerTreeHostTestGpuRasterDeviceSizeChanged : public LayerTreeHostTest {
public:
LayerTreeHostTestGpuRasterDeviceSizeChanged()
: num_draws_(0), bounds_(500, 64), invalid_rect_(10, 10, 20, 20) {}
void BeginTest() override {
client_.set_fill_with_nonsolid_color(true);
scoped_refptr<Layer> root = Layer::Create();
layer_ = FakePictureLayer::Create(&client_);
root->AddChild(layer_);
layer_->SetIsDrawable(true);
gfx::Transform transform;
// Translate the layer out of the viewport to force it to not update its
// tile size via PushProperties.
transform.Translate(10000.0, 10000.0);
layer_->SetTransform(transform);
root->SetBounds(bounds_);
layer_->SetBounds(bounds_);
layer_tree_host()->SetRootLayer(root);
layer_tree_host()->SetViewportRectAndScale(gfx::Rect(bounds_), 1.f,
GetCurrentLocalSurfaceId());
PostSetNeedsCommitToMainThread();
client_.set_bounds(layer_->bounds());
}
void SetUpUnboundContextProviders(
viz::TestContextProvider* context_provider,
viz::TestContextProvider* worker_provider) override {
context_provider->UnboundTestRasterInterface()->set_gpu_rasterization(true);
worker_provider->UnboundTestRasterInterface()->set_gpu_rasterization(true);
}
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
if (num_draws_ == 2) {
auto* pending_tree = host_impl->pending_tree();
auto* pending_layer_impl = static_cast<FakePictureLayerImpl*>(
pending_tree->LayerById(layer_->id()));
EXPECT_NE(pending_layer_impl, nullptr);
auto* active_tree = host_impl->pending_tree();
auto* active_layer_impl = static_cast<FakePictureLayerImpl*>(
active_tree->LayerById(layer_->id()));
EXPECT_NE(pending_layer_impl, nullptr);
auto* active_tiling_set = active_layer_impl->picture_layer_tiling_set();
auto* active_tiling = active_tiling_set->tiling_at(0);
auto* pending_tiling_set = pending_layer_impl->picture_layer_tiling_set();
auto* pending_tiling = pending_tiling_set->tiling_at(0);
EXPECT_EQ(
pending_tiling->TilingDataForTesting().max_texture_size().width(),
active_tiling->TilingDataForTesting().max_texture_size().width());
}
}
void DidCommitAndDrawFrame() override {
// On the second commit, resize the viewport.
if (num_draws_ == 1) {
GenerateNewLocalSurfaceId();
layer_tree_host()->SetViewportRectAndScale(gfx::Rect(400, 64), 1.f,
GetCurrentLocalSurfaceId());
}
if (num_draws_ < 2) {
layer_tree_host()->SetNeedsRedrawRect(invalid_rect_);
layer_tree_host()->SetNeedsCommit();
num_draws_++;
} else {
EndTest();
}
}
private:
int num_draws_;
const gfx::Size bounds_;
const gfx::Rect invalid_rect_;
FakeContentLayerClient client_;
scoped_refptr<FakePictureLayer> layer_;
};
// As there's no pending tree in single-threaded case, this test should run
// only for multi-threaded case.
MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterDeviceSizeChanged);
class LayerTreeHostTestNoExtraCommitFromInvalidate : public LayerTreeHostTest {
public:
void SetupTree() override {
root_layer_ = Layer::Create();
root_layer_->SetBounds(gfx::Size(10, 20));
scaled_layer_ = FakePictureLayer::Create(&client_);
scaled_layer_->SetBounds(gfx::Size(1, 1));
root_layer_->AddChild(scaled_layer_);
layer_tree_host()->SetRootLayer(root_layer_);
LayerTreeHostTest::SetupTree();
client_.set_bounds(root_layer_->bounds());
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
if (host_impl->active_tree()->source_frame_number() == 1)
EndTest();
}
void DidCommit() override {
switch (layer_tree_host()->SourceFrameNumber()) {
case 1:
// SetBounds grows the layer and exposes new content.
scaled_layer_->SetBounds(gfx::Size(4, 4));
break;
default:
// No extra commits.
EXPECT_EQ(2, layer_tree_host()->SourceFrameNumber());
}
}
void AfterTest() override {
EXPECT_EQ(gfx::Size(4, 4).ToString(), scaled_layer_->bounds().ToString());
}
private:
FakeContentLayerClient client_;
scoped_refptr<Layer> root_layer_;
scoped_refptr<Layer> scaled_layer_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoExtraCommitFromInvalidate);
class LayerTreeHostTestNoExtraCommitFromScrollbarInvalidate
: public LayerTreeHostTest {
public:
void SetupTree() override {
root_layer_ = Layer::Create();
root_layer_->SetBounds(gfx::Size(10, 20));
auto scrollbar = FakePaintedScrollbarLayer::CreateScrollbar();
scrollbar->set_should_paint(true);
scrollbar->set_has_thumb(false);
scrollbar_ = base::MakeRefCounted<FakePaintedScrollbarLayer>(
root_layer_->element_id());
scrollbar_->SetPosition(gfx::PointF(0.f, 10.f));
scrollbar_->SetBounds(gfx::Size(10, 10));
root_layer_->AddChild(scrollbar_);
layer_tree_host()->SetRootLayer(root_layer_);
LayerTreeHostTest::SetupTree();
client_.set_bounds(root_layer_->bounds());
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
if (host_impl->active_tree()->source_frame_number() == 1)
EndTest();
}
void DidCommit() override {
switch (layer_tree_host()->SourceFrameNumber()) {
case 1:
// Changing the device scale factor causes a commit. It also changes
// the content bounds of |scrollbar_|, which should not generate
// a second commit as a result.
layer_tree_host()->SetViewportRectAndScale(
layer_tree_host()->device_viewport_rect(), 4.f,
layer_tree_host()->local_surface_id_from_parent());
break;
default:
// No extra commits.
EXPECT_EQ(2, layer_tree_host()->SourceFrameNumber());
break;
}
}
private:
FakeContentLayerClient client_;
scoped_refptr<Layer> root_layer_;
scoped_refptr<FakePaintedScrollbarLayer> scrollbar_;
};
// TODO(crbug.com/40819189): Flaky failures.
// SINGLE_AND_MULTI_THREAD_TEST_F(
// LayerTreeHostTestNoExtraCommitFromScrollbarInvalidate);
class LayerTreeHostTestDeviceScaleFactorChange : public LayerTreeHostTest {
public:
void SetupTree() override {
root_layer_ = Layer::Create();
root_layer_->SetBounds(gfx::Size(10, 20));
child_layer_ = FakePictureLayer::Create(&client_);
child_layer_->SetBounds(gfx::Size(10, 10));
root_layer_->AddChild(child_layer_);
layer_tree_host()->SetRootLayer(root_layer_);
LayerTreeHostTest::SetupTree();
client_.set_bounds(root_layer_->bounds());
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DidCommit() override {
if (layer_tree_host()->SourceFrameNumber() == 1) {
layer_tree_host()->SetViewportRectAndScale(
layer_tree_host()->device_viewport_rect(), 4.f,
layer_tree_host()->local_surface_id_from_parent());
}
}
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
if (host_impl->sync_tree()->source_frame_number() == 1) {
EXPECT_EQ(4.f, host_impl->sync_tree()->device_scale_factor());
if (host_impl->pending_tree()) {
// The active tree's device scale factor shouldn't change until
// activation.
EXPECT_EQ(1.f, host_impl->active_tree()->device_scale_factor());
}
}
}
DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
LayerTreeHostImpl::FrameData* frame_data,
DrawResult draw_result) override {
if (host_impl->active_tree()->source_frame_number() == 0) {
EXPECT_EQ(1.f, host_impl->active_tree()->device_scale_factor());
} else {
gfx::Rect root_damage_rect =
frame_data->render_passes.back()->damage_rect;
EXPECT_EQ(gfx::Rect(host_impl->active_tree()->root_layer()->bounds()),
root_damage_rect);
EXPECT_EQ(4.f, host_impl->active_tree()->device_scale_factor());
EndTest();
}
return draw_result;
}
private:
FakeContentLayerClient client_;
scoped_refptr<Layer> root_layer_;
scoped_refptr<Layer> child_layer_;
};
// TODO(crbug.com/40820956): Flaky on ChromeOS and Linux.
// SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDeviceScaleFactorChange);
class LayerTreeHostTestRasterColorSpaceChange : public LayerTreeHostTest {
public:
void SetupTree() override {
space1_ = gfx::DisplayColorSpaces(gfx::ColorSpace::CreateXYZD50());
space2_ = gfx::DisplayColorSpaces(gfx::ColorSpace::CreateSRGB());
space2_with_hdr_ = space2_;
space2_with_hdr_.SetHDRMaxLuminanceRelative(2.f);
root_layer_ = Layer::Create();
root_layer_->SetBounds(gfx::Size(10, 20));
child_layer_ = FakePictureLayer::Create(&client_);
child_layer_->SetBounds(gfx::Size(10, 10));
root_layer_->AddChild(child_layer_);
layer_tree_host()->SetRootLayer(root_layer_);
layer_tree_host()->SetDisplayColorSpaces(space1_);
LayerTreeHostTest::SetupTree();
client_.set_bounds(root_layer_->bounds());
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
LayerTreeHostImpl::FrameData* frame_data,
DrawResult draw_result) override {
EXPECT_EQ(DrawResult::kSuccess, draw_result);
int source_frame = host_impl->active_tree()->source_frame_number();
gfx::Rect expected_root_damage_rect;
switch (source_frame) {
case 0:
// The first frame will have full damage, and should be in the initial
// color space.
EXPECT_FALSE(frame_data->has_no_damage);
EXPECT_TRUE(space1_ ==
host_impl->active_tree()->display_color_spaces());
expected_root_damage_rect =
gfx::Rect(host_impl->active_tree()->root_layer()->bounds());
break;
case 1:
// Empty commit.
EXPECT_TRUE(frame_data->has_no_damage);
EXPECT_TRUE(space1_ ==
host_impl->active_tree()->display_color_spaces());
break;
case 2:
// The change from space1 to space2 should cause full damage.
EXPECT_FALSE(frame_data->has_no_damage);
EXPECT_TRUE(space2_ ==
host_impl->active_tree()->display_color_spaces());
expected_root_damage_rect =
gfx::Rect(host_impl->active_tree()->root_layer()->bounds());
break;
case 3:
// Empty commit with the color space set to space2 redundantly.
EXPECT_TRUE(frame_data->has_no_damage);
EXPECT_TRUE(space2_ ==
host_impl->active_tree()->display_color_spaces());
break;
case 4:
// The change from space2 to space2_with_hdr should cause full damage.
EXPECT_FALSE(frame_data->has_no_damage);
EXPECT_TRUE(space2_with_hdr_ ==
host_impl->active_tree()->display_color_spaces());
expected_root_damage_rect = gfx::Rect(0, 0, 10, 10);
break;
case 5:
// Empty commit.
EXPECT_TRUE(frame_data->has_no_damage);
EXPECT_TRUE(space2_with_hdr_ ==
host_impl->active_tree()->display_color_spaces());
EndTest();
break;
default:
NOTREACHED();
}
if (!frame_data->has_no_damage) {
gfx::Rect root_damage_rect =
frame_data->render_passes.back()->damage_rect;
EXPECT_EQ(expected_root_damage_rect, root_damage_rect);
}
return draw_result;
}
void DidCommit() override {
switch (layer_tree_host()->SourceFrameNumber()) {
case 1:
PostSetNeedsCommitToMainThread();
break;
case 2:
EXPECT_TRUE(child_layer_->update_rect().IsEmpty());
layer_tree_host()->SetDisplayColorSpaces(space2_);
EXPECT_FALSE(child_layer_->update_rect().IsEmpty());
break;
case 3:
// The redundant SetRasterColorSpace should cause no commit and no
// damage. Force a commit for the test to continue.
layer_tree_host()->SetDisplayColorSpaces(space2_);
PostSetNeedsCommitToMainThread();
EXPECT_TRUE(child_layer_->update_rect().IsEmpty());
break;
case 4:
EXPECT_TRUE(child_layer_->update_rect().IsEmpty());
// Setting to space2_with_hdr_ should be a no-op, because there is
// no HDR content.
layer_tree_host()->SetDisplayColorSpaces(space2_with_hdr_);
EXPECT_TRUE(child_layer_->update_rect().IsEmpty());
// Same with setting back to space2_.
layer_tree_host()->SetDisplayColorSpaces(space2_);
EXPECT_TRUE(child_layer_->update_rect().IsEmpty());
// Now set the content to be HDR, and set to space2_with_hdr. This
// should trigger a commit.
child_layer_->set_reraster_on_hdr_change(true);
layer_tree_host()->SetDisplayColorSpaces(space2_with_hdr_);
EXPECT_FALSE(child_layer_->update_rect().IsEmpty());
break;
case 5:
EXPECT_TRUE(child_layer_->update_rect().IsEmpty());
PostSetNeedsCommitToMainThread();
break;
case 6:
break;
default:
NOTREACHED();
}
}
private:
gfx::DisplayColorSpaces space1_;
gfx::DisplayColorSpaces space2_;
gfx::DisplayColorSpaces space2_with_hdr_;
FakeContentLayerClient client_;
scoped_refptr<Layer> root_layer_;
scoped_refptr<FakePictureLayer> child_layer_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestRasterColorSpaceChange);
class LayerTreeHostTestSetNeedsCommitWithForcedRedraw
: public LayerTreeHostTest {
public:
LayerTreeHostTestSetNeedsCommitWithForcedRedraw()
: num_draws_(0), bounds_(50, 50), invalid_rect_(10, 10, 20, 20) {}
void BeginTest() override {
root_layer_ = FakePictureLayer::Create(&client_);
root_layer_->SetIsDrawable(true);
root_layer_->SetBounds(bounds_);
layer_tree_host()->SetRootLayer(root_layer_);
layer_tree_host()->SetViewportRectAndScale(gfx::Rect(bounds_), 1.f,
viz::LocalSurfaceId());
PostSetNeedsCommitToMainThread();
client_.set_bounds(root_layer_->bounds());
}
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
if (num_draws_ == 3) {
host_impl->SetViewportDamage(invalid_rect_);
host_impl->SetNeedsRedraw();
}
}
DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
LayerTreeHostImpl::FrameData* frame_data,
DrawResult draw_result) override {
EXPECT_EQ(DrawResult::kSuccess, draw_result);
gfx::Rect root_damage_rect;
if (!frame_data->render_passes.empty())
root_damage_rect = frame_data->render_passes.back()->damage_rect;
switch (num_draws_) {
case 0:
EXPECT_EQ(gfx::Rect(bounds_), root_damage_rect);
break;
case 1:
case 2:
EXPECT_EQ(gfx::Rect(), root_damage_rect);
break;
case 3:
EXPECT_EQ(invalid_rect_, root_damage_rect);
break;
case 4:
EXPECT_EQ(gfx::Rect(bounds_), root_damage_rect);
break;
default:
NOTREACHED();
}
return draw_result;
}
void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
switch (num_draws_) {
case 0:
case 1:
// Cycle through a couple of empty commits to ensure we're observing the
// right behavior
PostSetNeedsCommitToMainThread();
break;
case 2:
// Should force full frame damage on the next commit
PostSetNeedsCommitWithForcedRedrawToMainThread();
host_impl->BlockNotifyReadyToActivateForTesting(true);
break;
case 3:
host_impl->BlockNotifyReadyToActivateForTesting(false);
break;
default:
EndTest();
break;
}
num_draws_++;
}
void AfterTest() override { EXPECT_EQ(5, num_draws_); }
private:
int num_draws_;
const gfx::Size bounds_;
const gfx::Rect invalid_rect_;
FakeContentLayerClient client_;
scoped_refptr<FakePictureLayer> root_layer_;
};
// This test blocks activation which is not supported for single thread mode.
MULTI_THREAD_BLOCKNOTIFY_TEST_F(
LayerTreeHostTestSetNeedsCommitWithForcedRedraw);
// Tests that if a layer is not drawn because of some reason in the parent then
// its damage is preserved until the next time it is drawn.
class LayerTreeHostTestUndrawnLayersDamageLater : public LayerTreeHostTest {
public:
void SetupTree() override {
root_layer_bounds_ = gfx::Size(50, 50);
child_layer_bounds_ = gfx::Size(25, 25);
root_layer_ = FakePictureLayer::Create(&client_);
root_layer_->SetIsDrawable(true);
root_layer_->SetBounds(root_layer_bounds_);
layer_tree_host()->SetRootLayer(root_layer_);
// The initially transparent layer has a larger child layer, which is
// not initially drawn because of the this (parent) layer.
parent_layer_ = FakePictureLayer::Create(&client_);
parent_layer_->SetBounds(gfx::Size(15, 15));
parent_layer_->SetOpacity(0.0f);
root_layer_->AddChild(parent_layer_);
child_layer_ = FakePictureLayer::Create(&client_);
child_layer_->SetBounds(child_layer_bounds_);
parent_layer_->AddChild(child_layer_);
client_.set_bounds(root_layer_->bounds());
LayerTreeHostTest::SetupTree();
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
LayerTreeHostImpl::FrameData* frame_data,
DrawResult draw_result) override {
EXPECT_EQ(DrawResult::kSuccess, draw_result);
gfx::Rect root_damage_rect;
if (!frame_data->render_passes.empty())
root_damage_rect = frame_data->render_passes.back()->damage_rect;
// The first time, the whole view needs be drawn.
// Afterwards, just the opacity of surface_layer1 is changed a few times,
// and each damage should be the bounding box of it and its child. If this
// was working improperly, the damage might not include its childs bounding
// box.
switch (host_impl->active_tree()->source_frame_number()) {
case 0:
EXPECT_EQ(gfx::Rect(root_layer_bounds_), root_damage_rect);
break;
case 1:
case 2:
case 3:
EXPECT_EQ(gfx::Rect(child_layer_bounds_), root_damage_rect);
break;
default:
NOTREACHED();
}
return draw_result;
}
void DidCommitAndDrawFrame() override {
switch (layer_tree_host()->SourceFrameNumber()) {
case 1:
// Test not owning the surface.
parent_layer_->SetOpacity(1.0f);
break;
case 2:
parent_layer_->SetOpacity(0.0f);
break;
case 3:
// Test owning the surface.
parent_layer_->SetOpacity(0.5f);
parent_layer_->SetForceRenderSurfaceForTesting(true);
break;
case 4:
EndTest();
break;
default:
NOTREACHED();
}
}
private:
FakeContentLayerClient client_;
scoped_refptr<FakePictureLayer> root_layer_;
scoped_refptr<FakePictureLayer> parent_layer_;
scoped_refptr<FakePictureLayer> child_layer_;
gfx::Size root_layer_bounds_;
gfx::Size child_layer_bounds_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestUndrawnLayersDamageLater);
// Tests that if a layer is not drawn because of some reason in the parent then
// its damage is preserved until the next time it is drawn.
class LayerTreeHostTestDamageWithScale : public LayerTreeHostTest {
public:
LayerTreeHostTestDamageWithScale() = default;
void SetupTree() override {
client_.set_fill_with_nonsolid_color(true);
root_layer_bounds_ = gfx::Size(50, 50);
child_layer_bounds_ = gfx::Size(25, 25);
root_layer_ = FakePictureLayer::Create(&client_);
root_layer_->SetBounds(root_layer_bounds_);
child_layer_ = FakePictureLayer::Create(&client_);
child_layer_->SetBounds(child_layer_bounds_);
child_layer_->SetIsDrawable(true);
child_layer_->SetContentsOpaque(true);
root_layer_->AddChild(child_layer_);
layer_tree_host()->SetRootLayer(root_layer_);
LayerTreeHostTest::SetupTree();
client_.set_bounds(root_layer_->bounds());
}
void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
// Force the layer to have a tiling at 1.3f scale. Note that if we simply
// add tiling, it will be gone by the time we draw because of aggressive
// cleanup. AddTilingUntilNextDraw ensures that it remains there during
// damage calculation.
FakePictureLayerImpl* child_layer_impl = static_cast<FakePictureLayerImpl*>(
host_impl->active_tree()->LayerById(child_layer_->id()));
child_layer_impl->AddTilingUntilNextDraw(1.3f);
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
LayerTreeHostImpl::FrameData* frame_data,
DrawResult draw_result) override {
EXPECT_EQ(DrawResult::kSuccess, draw_result);
gfx::Rect root_damage_rect;
if (!frame_data->render_passes.empty())
root_damage_rect = frame_data->render_passes.back()->damage_rect;
// The first time, the whole view needs be drawn.
// Afterwards, just the opacity of surface_layer1 is changed a few times,
// and each damage should be the bounding box of it and its child. If this
// was working improperly, the damage might not include its childs bounding
// box.
switch (host_impl->active_tree()->source_frame_number()) {
case 0:
EXPECT_EQ(gfx::Rect(root_layer_bounds_), root_damage_rect);
break;
case 1: {
FakePictureLayerImpl* child_layer_impl =
static_cast<FakePictureLayerImpl*>(
host_impl->active_tree()->LayerById(child_layer_->id()));
// We remove tilings pretty aggressively if they are not ideal. Add this
// back in so that we can compare
// child_layer_impl->GetEnclosingVisibleRectInTargetSpace to the damage.
child_layer_impl->AddTilingUntilNextDraw(1.3f);
EXPECT_EQ(gfx::Rect(26, 26), root_damage_rect);
EXPECT_EQ(child_layer_impl->GetEnclosingVisibleRectInTargetSpace(),
root_damage_rect);
EXPECT_TRUE(
child_layer_impl->GetEnclosingVisibleRectInTargetSpace().Contains(
gfx::Rect(child_layer_bounds_)));
break;
}
default:
NOTREACHED();
}
return draw_result;
}
void DidCommitAndDrawFrame() override {
switch (layer_tree_host()->SourceFrameNumber()) {
case 1: {
// Test not owning the surface.
child_layer_->SetOpacity(0.5f);
break;
}
case 2:
EndTest();
break;
default:
NOTREACHED();
}
}
private:
FakeContentLayerClient client_;
scoped_refptr<Layer> root_layer_;
scoped_refptr<Layer> child_layer_;
gfx::Size root_layer_bounds_;
gfx::Size child_layer_bounds_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDamageWithScale);
// This test verifies that properties on the layer tree host are commited
// to the impl side.
class LayerTreeHostTestCommit : public LayerTreeHostTest {
public:
LayerTreeHostTestCommit() = default;
void BeginTest() override {
layer_tree_host()->SetViewportRectAndScale(gfx::Rect(20, 20), 1.f,
viz::LocalSurfaceId());
layer_tree_host()->set_background_color(SkColors::kGray);
layer_tree_host()->SetEventListenerProperties(
EventListenerClass::kMouseWheel, EventListenerProperties::kPassive);
layer_tree_host()->SetEventListenerProperties(
EventListenerClass::kTouchStartOrMove,
EventListenerProperties::kBlocking);
layer_tree_host()->SetEventListenerProperties(
EventListenerClass::kTouchEndOrCancel,
EventListenerProperties::kBlockingAndPassive);
layer_tree_host()->SetHaveScrollEventHandlers(true);
PostSetNeedsCommitToMainThread();
}
void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
EXPECT_EQ(gfx::Rect(20, 20), impl->active_tree()->GetDeviceViewport());
EXPECT_EQ(SkColors::kGray, impl->active_tree()->background_color());
EXPECT_EQ(EventListenerProperties::kPassive,
impl->active_tree()->event_listener_properties(
EventListenerClass::kMouseWheel));
EXPECT_EQ(EventListenerProperties::kBlocking,
impl->active_tree()->event_listener_properties(
EventListenerClass::kTouchStartOrMove));
EXPECT_EQ(EventListenerProperties::kBlockingAndPassive,
impl->active_tree()->event_listener_properties(
EventListenerClass::kTouchEndOrCancel));
EXPECT_TRUE(impl->active_tree()->have_scroll_event_handlers());
EndTest();
}
};
MULTI_THREAD_TEST_F(LayerTreeHostTestCommit);
// This test verifies that LayerTreeHostImpl's current frame time gets
// updated in consecutive frames when it doesn't draw due to tree
// activation failure.
class LayerTreeHostTestFrameTimeUpdatesAfterActivationFails
: public LayerTreeHostTest {
public:
LayerTreeHostTestFrameTimeUpdatesAfterActivationFails()
: frame_count_with_pending_tree_(0) {}
void BeginTest() override {
layer_tree_host()->SetViewportRectAndScale(gfx::Rect(20, 20), 1.f,
viz::LocalSurfaceId());
layer_tree_host()->set_background_color(SkColors::kGray);
PostSetNeedsCommitToMainThread();
}
void BeginCommitOnThread(LayerTreeHostImpl* impl) override {
EXPECT_EQ(frame_count_with_pending_tree_, 0);
impl->BlockNotifyReadyToActivateForTesting(true);
}
void WillBeginImplFrameOnThread(LayerTreeHostImpl* impl,
const viz::BeginFrameArgs& args,
bool has_damage) override {
if (impl->pending_tree())
frame_count_with_pending_tree_++;
if (frame_count_with_pending_tree_ == 1) {
EXPECT_EQ(base::TimeTicks(), first_frame_time_);
first_frame_time_ = impl->CurrentBeginFrameArgs().frame_time;
} else if (frame_count_with_pending_tree_ == 2) {
impl->BlockNotifyReadyToActivateForTesting(false);
}
}
void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
EXPECT_GT(frame_count_with_pending_tree_, 1);
EXPECT_NE(base::TimeTicks(), first_frame_time_);
EXPECT_NE(first_frame_time_, impl->CurrentBeginFrameArgs().frame_time);
EndTest();
}
void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
EXPECT_GT(frame_count_with_pending_tree_, 1);
}
private:
int frame_count_with_pending_tree_;
base::TimeTicks first_frame_time_;
};
// This test blocks activation which is not supported for single thread mode.
MULTI_THREAD_BLOCKNOTIFY_TEST_F(
LayerTreeHostTestFrameTimeUpdatesAfterActivationFails);
// This test verifies that LayerTreeHostImpl's current frame time gets
// updated in consecutive frames when it draws in each frame.
class LayerTreeHostTestFrameTimeUpdatesAfterDraw : public LayerTreeHostTest {
public:
LayerTreeHostTestFrameTimeUpdatesAfterDraw() : frame_(0) {}
void BeginTest() override {
layer_tree_host()->SetViewportRectAndScale(gfx::Rect(20, 20), 1.f,
viz::LocalSurfaceId());
layer_tree_host()->set_background_color(SkColors::kGray);
PostSetNeedsCommitToMainThread();
}
void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
frame_++;
if (frame_ == 1) {
first_frame_time_ = impl->CurrentBeginFrameArgs().frame_time;
impl->SetNeedsRedraw();
// Since we might use a low-resolution clock on Windows, we need to
// make sure that the clock has incremented past first_frame_time_.
while (first_frame_time_ == base::TimeTicks::Now()) {
}
return;
}
EXPECT_NE(first_frame_time_, impl->CurrentBeginFrameArgs().frame_time);
EndTest();
}
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
// Ensure there isn't a commit between the two draws, to ensure that a
// commit isn't required for updating the current frame time. We can
// only check for this in the multi-threaded case, since in the single-
// threaded case there will always be a commit between consecutive draws.
if (HasImplThread())
EXPECT_EQ(0, frame_);
}
private:
int frame_;
base::TimeTicks first_frame_time_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestFrameTimeUpdatesAfterDraw);
// Verifies that StartPageScaleAnimation events propagate correctly
// from LayerTreeHost to LayerTreeHostImpl in the MT compositor.
class LayerTreeHostTestStartPageScaleAnimation : public LayerTreeHostTest {
public:
LayerTreeHostTestStartPageScaleAnimation() { SetUseLayerLists(); }
void SetupTree() override {
LayerTreeHostTest::SetupTree();
Layer* root_layer = layer_tree_host()->root_layer();
scroll_layer_ = FakePictureLayer::Create(&client_);
scroll_layer_->set_always_update_resources(true);
scroll_layer_->SetBounds(gfx::Size(2 * root_layer->bounds().width(),
2 * root_layer->bounds().height()));
SetupViewport(root_layer, scroll_layer_, root_layer->bounds());
layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.5f, 2.f);
client_.set_bounds(root_layer->bounds());
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void ApplyViewportChanges(const ApplyViewportChangesArgs& args) override {
gfx::PointF offset = CurrentScrollOffset(scroll_layer_.get());
SetScrollOffset(scroll_layer_.get(), offset + args.inner_delta);
layer_tree_host()->SetPageScaleFactorAndLimits(args.page_scale_delta, 0.5f,
2.f);
}
void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
// We get one commit before the first draw, and the animation doesn't happen
// until the second draw.
switch (impl->active_tree()->source_frame_number()) {
case 0:
EXPECT_EQ(1.f, impl->active_tree()->current_page_scale_factor());
// We'll start an animation when we get back to the main thread.
break;
case 1:
EXPECT_EQ(1.f, impl->active_tree()->current_page_scale_factor());
// Once the animation starts, an ImplFrame will be requested. However,
// main frames may be happening in the mean-time due to high-latency
// mode. If one happens before the next impl frame, then the source
// frame number may increment twice instead of just once.
break;
case 2:
case 3:
EXPECT_EQ(1.25f, impl->active_tree()->current_page_scale_factor());
EndTest();
break;
}
}
void DidCommitAndDrawFrame() override {
switch (layer_tree_host()->SourceFrameNumber()) {
case 1:
layer_tree_host()->StartPageScaleAnimation(gfx::Point(), false, 1.25f,
base::TimeDelta());
break;
}
}
FakeContentLayerClient client_;
scoped_refptr<FakePictureLayer> scroll_layer_;
};
// Single thread proxy does not support impl-side page scale changes.
MULTI_THREAD_TEST_F(LayerTreeHostTestStartPageScaleAnimation);
class ViewportDeltasAppliedDuringPinch : public LayerTreeHostTest,
public ScrollCallbacks {
protected:
ViewportDeltasAppliedDuringPinch() : sent_gesture_(false) {
SetUseLayerLists();
}
void SetupTree() override {
SetInitialRootBounds(gfx::Size(200, 200));
LayerTreeHostTest::SetupTree();
Layer* root = layer_tree_host()->root_layer();
SetupViewport(root, gfx::Size(500, 500), gfx::Size(500, 500));
layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 1.f, 4.f);
layer_tree_host()
->property_trees()
->scroll_tree_mutable()
.SetScrollCallbacks(weak_ptr_factory_.GetWeakPtr());
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
if (!sent_gesture_) {
host_impl->GetInputHandler().PinchGestureBegin(
gfx::Point(100, 100), ui::ScrollInputType::kWheel);
host_impl->GetInputHandler().PinchGestureUpdate(2, gfx::Point(100, 100));
host_impl->GetInputHandler().PinchGestureEnd(gfx::Point(100, 100));
sent_gesture_ = true;
}
}
void ApplyViewportChanges(const ApplyViewportChangesArgs& args) override {
EXPECT_TRUE(sent_gesture_);
EXPECT_EQ(gfx::Vector2dF(50, 50), args.inner_delta);
EXPECT_EQ(2, args.page_scale_delta);
auto* scroll_layer =
layer_tree_host()->InnerViewportScrollLayerForTesting();
EXPECT_EQ(scroll_layer->element_id(), last_scrolled_element_id_);
EXPECT_EQ(gfx::PointF(50, 50), last_scrolled_offset_);
// The scroll offset in the scroll tree is typically updated from blink
// which doesn't exist in this test. Because we preemptively apply the
// scroll offset in LayerTreeHost::UpdateScrollOffsetFromImpl, the current
// scroll offset will still be updated.
EXPECT_EQ(gfx::PointF(50, 50), CurrentScrollOffset(scroll_layer));
EndTest();
}
void AfterTest() override { EXPECT_TRUE(sent_gesture_); }
// ScrollCallbacks
void DidCompositorScroll(
ElementId element_id,
const gfx::PointF& scroll_offset,
const std::optional<TargetSnapAreaElementIds>& snap_target_ids) override {
last_scrolled_element_id_ = element_id;
last_scrolled_offset_ = scroll_offset;
}
void DidChangeScrollbarsHidden(ElementId, bool) override {}
private:
bool sent_gesture_;
ElementId last_scrolled_element_id_;
gfx::PointF last_scrolled_offset_;
base::WeakPtrFactory<ViewportDeltasAppliedDuringPinch> weak_ptr_factory_{
this};
};
MULTI_THREAD_TEST_F(ViewportDeltasAppliedDuringPinch);
class LayerTreeHostTestSetVisible : public LayerTreeHostTest {
public:
LayerTreeHostTestSetVisible() : num_draws_(0) {}
void BeginTest() override {
PostSetNeedsCommitToMainThread();
}
void WillCommit(const CommitState&) override {
PostSetVisibleToMainThread(false);
// This is suppressed while we're invisible.
PostSetNeedsRedrawToMainThread();
// Triggers the redraw.
PostSetVisibleToMainThread(true);
}
void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
EXPECT_TRUE(impl->visible());
++num_draws_;
EndTest();
}
void AfterTest() override { EXPECT_EQ(1, num_draws_); }
private:
int num_draws_;
};
// TODO(crbug.com/40823253): Test is flaky.
// MULTI_THREAD_TEST_F(LayerTreeHostTestSetVisible);
class LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers
: public LayerTreeHostTest {
public:
LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers() = default;
void BeginTest() override {
client_.set_fill_with_nonsolid_color(true);
root_layer_ = FakePictureLayer::Create(&client_);
child_layer_ = FakePictureLayer::Create(&client_);
layer_tree_host()->SetViewportRectAndScale(gfx::Rect(60, 60), 1.5f,
viz::LocalSurfaceId());
EXPECT_EQ(gfx::Size(60, 60),
layer_tree_host()->device_viewport_rect().size());
root_layer_->AddChild(child_layer_);
root_layer_->SetIsDrawable(true);
root_layer_->SetBounds(gfx::Size(30, 30));
child_layer_->SetIsDrawable(true);
child_layer_->SetPosition(gfx::PointF(2.f, 2.f));
child_layer_->SetBounds(gfx::Size(10, 10));
client_.set_bounds(gfx::Size(10, 10));
layer_tree_host()->SetRootLayer(root_layer_);
PostSetNeedsCommitToMainThread();
client_.set_bounds(root_layer_->bounds());
}
void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
// Should only do one commit.
EXPECT_EQ(0, impl->active_tree()->source_frame_number());
// Device scale factor should come over to impl.
EXPECT_NEAR(impl->active_tree()->device_scale_factor(), 1.5f, 0.00001f);
// Device viewport is scaled.
EXPECT_EQ(gfx::Rect(60, 60), impl->active_tree()->GetDeviceViewport());
FakePictureLayerImpl* root =
static_cast<FakePictureLayerImpl*>(impl->active_tree()->root_layer());
FakePictureLayerImpl* child = static_cast<FakePictureLayerImpl*>(
impl->active_tree()->LayerById(child_layer_->id()));
// Compute all the layer transforms for the frame.
LayerTreeHostImpl::FrameData frame_data;
impl->PrepareToDraw(&frame_data);
impl->DidDrawAllLayers(frame_data);
const RenderSurfaceList& render_surface_list =
*frame_data.render_surface_list;
// Both layers should be drawing into the root render surface.
ASSERT_EQ(1u, render_surface_list.size());
ASSERT_EQ(GetRenderSurface(root), render_surface_list[0]);
ASSERT_EQ(2, GetRenderSurface(root)->num_contributors());
// The root render surface is the size of the viewport.
EXPECT_EQ(gfx::Rect(0, 0, 60, 60), GetRenderSurface(root)->content_rect());
// The max tiling scale of the child should be scaled.
EXPECT_FLOAT_EQ(1.5f, child->MaximumTilingContentsScale());
gfx::Transform scale_transform;
scale_transform.Scale(impl->active_tree()->device_scale_factor(),
impl->active_tree()->device_scale_factor());
// The root layer is scaled by 2x.
gfx::Transform root_screen_space_transform = scale_transform;
gfx::Transform root_draw_transform = scale_transform;
EXPECT_EQ(root_draw_transform, root->DrawTransform());
EXPECT_EQ(root_screen_space_transform, root->ScreenSpaceTransform());
// The child is at position 2,2, which is transformed to 3,3 after the scale
gfx::Transform child_transform;
child_transform.Translate(3.f, 3.f);
child_transform.Scale(child->MaximumTilingContentsScale(),
child->MaximumTilingContentsScale());
EXPECT_TRANSFORM_EQ(child_transform, child->DrawTransform());
EXPECT_TRANSFORM_EQ(child_transform, child->ScreenSpaceTransform());
EndTest();
}
private:
FakeContentLayerClient client_;
scoped_refptr<FakePictureLayer> root_layer_;
scoped_refptr<FakePictureLayer> child_layer_;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestDeviceScaleFactorScalesViewportAndLayers);
class LayerTreeHostTestContinuousInvalidate : public LayerTreeHostTest {
public:
LayerTreeHostTestContinuousInvalidate()
: num_commit_complete_(0), num_draw_layers_(0) {}
void BeginTest() override {
layer_tree_host()->SetViewportRectAndScale(gfx::Rect(10, 10), 1.f,
viz::LocalSurfaceId());
layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10));
layer_ = FakePictureLayer::Create(&client_);
layer_->SetBounds(gfx::Size(10, 10));
layer_->SetPosition(gfx::PointF(0.f, 0.f));
layer_->SetIsDrawable(true);
layer_tree_host()->root_layer()->AddChild(layer_);
PostSetNeedsCommitToMainThread();
client_.set_bounds(layer_->bounds());
}
void DidCommitAndDrawFrame() override {
if (num_draw_layers_ == 2)
return;
layer_->SetNeedsDisplay();
}
void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
if (num_draw_layers_ == 1)
num_commit_complete_++;
}
void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
num_draw_layers_++;
if (num_draw_layers_ == 2)
EndTest();
}
void AfterTest() override {
// Check that we didn't commit twice between first and second draw.
EXPECT_EQ(1, num_commit_complete_);
}
private:
FakeContentLayerClient client_;
scoped_refptr<Layer> layer_;
int num_commit_complete_;
int num_draw_layers_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousInvalidate);
class LayerTreeHostTestDeferMainFrameUpdate : public LayerTreeHostTest {
public:
LayerTreeHostTestDeferMainFrameUpdate() = default;
void BeginTest() override {
// Start with commits deferred.
PostGetDeferMainFrameUpdateToMainThread(&scoped_defer_main_frame_update_);
PostSetNeedsCommitToMainThread();
}
void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl,
const viz::BeginFrameArgs& args,
bool has_damage) override {
// Impl frames happen while commits are deferred.
num_will_begin_impl_frame_++;
switch (num_will_begin_impl_frame_) {
case 1:
case 2:
case 3:
case 4:
// Post a number of frames to increase the chance that, if there exist
// bugs, an unexpected BeginMainFrame will be issued.
PostSetNeedsCommitToMainThread();
PostSetNeedsRedrawToMainThread();
break;
case 5:
MainThreadTaskRunner()->PostTask(
FROM_HERE,
// Unretained because the test should not end before allowing
// commits via this running.
base::BindOnce(&LayerTreeHostTestDeferMainFrameUpdate::AllowCommits,
base::Unretained(this)));
break;
default:
// Sometimes |num_will_begin_impl_frame_| will be greater than 5 if the
// main thread is slow to respond.
break;
}
}
void WillBeginMainFrame() override {
EXPECT_FALSE(scoped_defer_main_frame_update_);
EXPECT_TRUE(IsCommitAllowed());
num_send_begin_main_frame_++;
EndTest();
}
void AfterTest() override {
EXPECT_GE(num_will_begin_impl_frame_, 5);
EXPECT_EQ(1, num_send_begin_main_frame_);
}
virtual void AllowCommits() {
allow_commits_ = true;
scoped_defer_main_frame_update_.reset();
}
virtual bool IsCommitAllowed() const { return allow_commits_; }
private:
std::unique_ptr<ScopedDeferMainFrameUpdate> scoped_defer_main_frame_update_;
bool allow_commits_ = false;
int num_will_begin_impl_frame_ = 0;
int num_send_begin_main_frame_ = 0;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDeferMainFrameUpdate);
// This verifies that changing the size of a LayerTreeHost without providing a
// LocalSurfaceId defers commits.
class LayerTreeHostInvalidLocalSurfaceIdDefersCommit
: public LayerTreeHostTestDeferMainFrameUpdate {
public:
LayerTreeHostInvalidLocalSurfaceIdDefersCommit() {
SkipAllocateInitialLocalSurfaceId();
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void AllowCommits() override {
GenerateNewLocalSurfaceId();
PostSetLocalSurfaceIdToMainThread(GetCurrentLocalSurfaceId());
}
bool IsCommitAllowed() const override {
return GetCurrentLocalSurfaceId().is_valid();
}
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostInvalidLocalSurfaceIdDefersCommit);
// This verifies that we can abort a commit inside the main frame, and
// we don't leave any weird states around if we never allow the commit
// to happen.
class LayerTreeHostTestDeferMainFrameUpdateInsideBeginMainFrame
: public LayerTreeHostTest {
public:
LayerTreeHostTestDeferMainFrameUpdateInsideBeginMainFrame() = default;
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void WillBeginMainFrame() override {
++begin_main_frame_count_;
// This should prevent the commit from happening.
scoped_defer_main_frame_update_ = layer_tree_host()->DeferMainFrameUpdate();
// Wait to see if the commit happens. It's possible the deferred
// commit happens when it shouldn't but takes long enough that
// this passes. But it won't fail when it shouldn't.
MainThreadTaskRunner()->PostDelayedTask(
FROM_HERE,
// Unretained because the test doesn't end before this runs.
base::BindOnce(&LayerTreeTest::EndTest, base::Unretained(this)),
base::Milliseconds(100));
}
void DidCommit() override { ++commit_count_; }
void AfterTest() override {
EXPECT_EQ(0, commit_count_);
EXPECT_EQ(1, begin_main_frame_count_);
}
private:
std::unique_ptr<ScopedDeferMainFrameUpdate> scoped_defer_main_frame_update_;
int commit_count_ = 0;
int begin_main_frame_count_ = 0;
};
SINGLE_AND_MULTI_THREAD_TEST_F(
LayerTreeHostTestDeferMainFrameUpdateInsideBeginMainFrame);
// This verifies that we can abort a commit inside the main frame, and
// we will finish the commit once it is allowed.
class LayerTreeHostTestDeferInsideBeginMainFrameWithCommitAfter
: public LayerTreeHostTest {
public:
LayerTreeHostTestDeferInsideBeginMainFrameWithCommitAfter() = default;
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void WillBeginMainFrame() override {
++begin_main_frame_count_;
if (allow_commits_)
return;
// This should prevent the commit from happening.
scoped_defer_main_frame_update_ = layer_tree_host()->DeferMainFrameUpdate();
// Wait to see if the commit happens. It's possible the deferred
// commit happens when it shouldn't but takes long enough that
// this passes. But it won't fail when it shouldn't.
MainThreadTaskRunner()->PostDelayedTask(
FROM_HERE,
// Unretained because the test doesn't end before this runs.
base::BindOnce(
&LayerTreeHostTestDeferInsideBeginMainFrameWithCommitAfter::
AllowCommits,
base::Unretained(this)),
base::Milliseconds(100));
}
void AllowCommits() {
// Once we've waited and seen that commit did not happen, we
// allow commits and should see this one go through.
allow_commits_ = true;
scoped_defer_main_frame_update_.reset();
}
void DidCommit() override {
++commit_count_;
EXPECT_TRUE(allow_commits_);
EndTest();
}
void AfterTest() override {
EXPECT_EQ(1, commit_count_);
EXPECT_EQ(2, begin_main_frame_count_);
// The commit should not have been aborted.
EXPECT_EQ(1, ready_to_commit_count_);
}
void ReadyToCommitOnThread(LayerTreeHostImpl* host_impl) override {
++ready_to_commit_count_;
}
private:
std::unique_ptr<ScopedDeferMainFrameUpdate> scoped_defer_main_frame_update_;
bool allow_commits_ = false;
int commit_count_ = 0;
int begin_main_frame_count_ = 0;
int ready_to_commit_count_ = 0;
};
SINGLE_AND_MULTI_THREAD_TEST_F(
LayerTreeHostTestDeferInsideBeginMainFrameWithCommitAfter);
// This verifies that animate_only BeginFrames only run animation/layout
// updates, i.e. abort commits after the paint stage and only request layer
// tree updates for layout.
//
// The tests sends five Begin(Main)Frames in sequence: four animate_only
// Begin(Main)Frames followed by a normal Begin(Main)Frame. The first frame
// has animate_only force to false by CompositorFrameSinkSupport, since it
// needs a complete frame to assure surface activation. Frames 2-4 should
// result in aborted commits, whereas the last one should complete the
// previously aborted commits.
//
// Between BeginMainFrames 3 and 4, the client also requests a new commit
// (SetNeedsCommit), but not between BeginMainFrames 1-3. In multi-threaded
// mode, ProxyMain will run the animate pipeline stage only for BeginMainFrames
// 2 and 4, as no new commit was requested between 2 and 3.
//
// The test uses the full-pipeline mode to ensure that each BeginFrame also
// incurs a BeginMainFrame.
class LayerTreeHostTestAnimateOnlyBeginFrames
: public LayerTreeHostTest,
public viz::ExternalBeginFrameSourceClient {
public:
LayerTreeHostTestAnimateOnlyBeginFrames()
: external_begin_frame_source_(this) {
UseBeginFrameSource(&external_begin_frame_source_);
}
void IssueBeginFrame(bool animate_only) {
++begin_frame_count_;
last_begin_frame_time_ += viz::BeginFrameArgs::DefaultInterval();
uint64_t sequence_number = next_begin_frame_sequence_number_++;
auto args = viz::BeginFrameArgs::Create(
BEGINFRAME_FROM_HERE, viz::BeginFrameArgs::kManualSourceId,
sequence_number, last_begin_frame_time_,
last_begin_frame_time_ + viz::BeginFrameArgs::DefaultInterval(),
viz::BeginFrameArgs::DefaultInterval(), viz::BeginFrameArgs::NORMAL);
args.animate_only = animate_only;
external_begin_frame_source_.OnBeginFrame(args);
}
void PostIssueBeginFrame(bool animate_only) {
// Post a new task so that BeginFrame is not issued within same callstack.
ImplThreadTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(
&LayerTreeHostTestAnimateOnlyBeginFrames::IssueBeginFrame,
base::Unretained(this), animate_only));
}
// viz::ExternalBeginFrameSourceClient implementation:
void OnNeedsBeginFrames(bool needs_begin_frames) override {
if (needs_begin_frames) {
EXPECT_EQ(0, begin_frame_count_);
// Send a first animation_only BeginFrame.
PostIssueBeginFrame(true);
}
}
// LayerTreeHostTest implementation:
void BeginTest() override {
PostSetNeedsCommitToMainThread();
// OnNeedsBeginFrames(true) will be called during tree initialization.
}
void WillBeginMainFrame() override {
++will_begin_main_frame_count_;
EXPECT_GE(begin_frame_count_, will_begin_main_frame_count_);
}
void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl,
const viz::BeginFrameArgs& args,
bool has_damage) override {
EXPECT_EQ(args.animate_only,
(begin_frame_count_ >= 2 && begin_frame_count_ <= 4));
}
void DidFinishImplFrameOnThread(LayerTreeHostImpl* host_impl) override {
EXPECT_LE(will_begin_main_frame_count_, begin_frame_count_);
if (begin_frame_count_ < 3) {
// Send another animation_only BeginFrame.
PostIssueBeginFrame(true);
} else if (begin_frame_count_ == 3) {
MainThreadTaskRunner()->PostTaskAndReply(
FROM_HERE,
base::BindOnce(&LayerTreeHostTestAnimateOnlyBeginFrames::
SetNeedsCommitOnMainThread,
base::Unretained(this)),
base::BindOnce(
&LayerTreeHostTestAnimateOnlyBeginFrames::PostIssueBeginFrame,
base::Unretained(this), true));
} else if (begin_frame_count_ == 4) {
PostIssueBeginFrame(false);
}
}
void SetNeedsCommitOnMainThread() { layer_tree_host()->SetNeedsCommit(); }
void UpdateLayerTreeHost() override { ++update_layer_tree_host_count_; }
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
if (begin_frame_count_ == 1)
host_impl->NotifyReadyToDraw();
++commit_count_;
// First commit is due to first frame having animate_only forced to false
// in ordser to create the surface.
if (commit_count_ == 1)
return;
// Fourth BeginMainFrame should lead to commit.
EXPECT_EQ(5, begin_frame_count_);
EXPECT_EQ(3, will_begin_main_frame_count_);
EndTest();
}
void ReadyToCommitOnThread(LayerTreeHostImpl* host_impl) override {
++ready_to_commit_count_;
}
void AfterTest() override {
EXPECT_EQ(2, commit_count_);
EXPECT_EQ(5, begin_frame_count_);
EXPECT_EQ(3, will_begin_main_frame_count_);
EXPECT_EQ(3, update_layer_tree_host_count_);
// The final commit should not have been aborted.
EXPECT_EQ(2, ready_to_commit_count_);
}
protected:
void InitializeSettings(LayerTreeSettings* settings) override {
// Use full-pipeline mode to make BeginFrame handling deterministic.
EXPECT_FALSE(settings->wait_for_all_pipeline_stages_before_draw);
settings->wait_for_all_pipeline_stages_before_draw = true;
}
private:
viz::ExternalBeginFrameSource external_begin_frame_source_;
base::TimeTicks last_begin_frame_time_ = base::TimeTicks::Now();
uint64_t next_begin_frame_sequence_number_ =
viz::BeginFrameArgs::kStartingFrameNumber;
int commit_count_ = 0;
int begin_frame_count_ = 0;
int will_begin_main_frame_count_ = 0;
int update_layer_tree_host_count_ = 0;
int ready_to_commit_count_ = 0;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestAnimateOnlyBeginFrames);
class LayerTreeHostTestCompositeImmediatelyStateTransitions
: public LayerTreeHostTest {
public:
enum {
kInvalid,
kStartedTest,
kStartedImplFrame,
kStartedMainFrame,
kStartedCommit,
kCompletedCommit,
kCompletedMainFrame,
kCompletedImplFrame,
};
LayerTreeHostTestCompositeImmediatelyStateTransitions()
: current_state_(kInvalid), current_begin_frame_args_() {}
void InitializeSettings(LayerTreeSettings* settings) override {
settings->single_thread_proxy_scheduler = false;
settings->use_zero_copy = true;
}
void BeginTest() override {
current_state_ = kStartedTest;
PostCompositeImmediatelyToMainThread();
}
void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl,
const viz::BeginFrameArgs& args,
bool has_damage) override {
EXPECT_EQ(current_state_, kStartedTest);
current_state_ = kStartedImplFrame;
EXPECT_FALSE(current_begin_frame_args_.IsValid());
EXPECT_TRUE(args.IsValid());
current_begin_frame_args_ = args;
}
void WillBeginMainFrame() override {
EXPECT_EQ(current_state_, kStartedImplFrame);
current_state_ = kStartedMainFrame;
}
void BeginMainFrame(const viz::BeginFrameArgs& args) override {
EXPECT_EQ(current_state_, kStartedMainFrame);
EXPECT_EQ(args.frame_time, current_begin_frame_args_.frame_time);
}
void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override {
EXPECT_EQ(current_state_, kStartedMainFrame);
current_state_ = kStartedCommit;
}
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
EXPECT_EQ(current_state_, kStartedCommit);
current_state_ = kCompletedCommit;
}
void DidBeginMainFrame() override {
EXPECT_EQ(current_state_, kCompletedCommit);
current_state_ = kCompletedMainFrame;
}
void DidFinishImplFrameOnThread(LayerTreeHostImpl* host_impl) override {
EXPECT_EQ(current_state_, kCompletedMainFrame);
current_state_ = kCompletedImplFrame;
EndTest();
}
void AfterTest() override { EXPECT_EQ(current_state_, kCompletedImplFrame); }
private:
int current_state_;
viz::BeginFrameArgs current_begin_frame_args_;
};
SINGLE_THREAD_TEST_F(LayerTreeHostTestCompositeImmediatelyStateTransitions);
class LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled
: public LayerTreeHostTest {
public:
void InitializeSettings(LayerTreeSettings* settings) override {
settings->using_synchronous_renderer_compositor = true;
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
// The BeginFrame notification is turned off now but will get enabled
// once we return. End test while it's enabled.
ImplThreadTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(&LayerTreeHostTest::EndTest, base::Unretained(this)));
}
};
MULTI_THREAD_TEST_F(
LayerTreeHostTestBeginFrameNotificationShutdownWhileEnabled);
class LayerTreeHostTestAbortedCommitDoesntStall : public LayerTreeHostTest {
protected:
LayerTreeHostTestAbortedCommitDoesntStall()
: commit_count_(0), commit_abort_count_(0), commit_complete_count_(0) {}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DidCommit() override {
commit_count_++;
if (commit_count_ == 4) {
// After two aborted commits, request a real commit now to make sure a
// real commit following an aborted commit will still complete and
// end the test even when the Impl thread is idle.
layer_tree_host()->SetNeedsCommit();
}
}
void BeginMainFrameAbortedOnThread(
LayerTreeHostImpl* host_impl,
CommitEarlyOutReason reason,
bool /* did_sync_scroll_and_viewport */) override {
commit_abort_count_++;
// Initiate another abortable commit.
host_impl->SetNeedsCommit();
}
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
commit_complete_count_++;
if (commit_complete_count_ == 1) {
// Initiate an abortable commit after the first commit.
host_impl->SetNeedsCommit();
} else {
EndTest();
}
}
void AfterTest() override {
EXPECT_EQ(commit_count_, 5);
EXPECT_EQ(commit_abort_count_, 3);
EXPECT_EQ(commit_complete_count_, 2);
}
int commit_count_;
int commit_abort_count_;
int commit_complete_count_;
};
class OnDrawLayerTreeFrameSink : public TestLayerTreeFrameSink {
public:
OnDrawLayerTreeFrameSink(
scoped_refptr<viz::RasterContextProvider> compositor_context_provider,
scoped_refptr<viz::RasterContextProvider> worker_context_provider,
gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager,
const viz::RendererSettings& renderer_settings,
const viz::DebugRendererSettings* const debug_settings,
TaskRunnerProvider* task_runner_provider,
bool synchronous_composite,
double refresh_rate,
base::RepeatingClosure invalidate_callback)
: TestLayerTreeFrameSink(std::move(compositor_context_provider),
std::move(worker_context_provider),
gpu_memory_buffer_manager,
renderer_settings,
debug_settings,
task_runner_provider,
synchronous_composite,
false /* disable_display_vsync */,
refresh_rate),
invalidate_callback_(std::move(invalidate_callback)) {}
// TestLayerTreeFrameSink overrides.
void Invalidate(bool needs_draw) override { invalidate_callback_.Run(); }
void OnDraw(bool resourceless_software_draw) {
gfx::Transform identity;
gfx::Rect empty_rect;
client_->OnDraw(identity, empty_rect, resourceless_software_draw, false);
}
private:
const base::RepeatingClosure invalidate_callback_;
};
class LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor
: public LayerTreeHostTestAbortedCommitDoesntStall {
protected:
void InitializeSettings(LayerTreeSettings* settings) override {
LayerTreeHostTestAbortedCommitDoesntStall::InitializeSettings(settings);
settings->using_synchronous_renderer_compositor = true;
}
std::unique_ptr<TestLayerTreeFrameSink> CreateLayerTreeFrameSink(
const viz::RendererSettings& renderer_settings,
double refresh_rate,
scoped_refptr<viz::RasterContextProvider> compositor_context_provider,
scoped_refptr<viz::RasterContextProvider> worker_context_provider)
override {
auto on_draw_callback = base::BindRepeating(
&LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor::
CallOnDraw,
base::Unretained(this));
auto frame_sink = std::make_unique<OnDrawLayerTreeFrameSink>(
compositor_context_provider, std::move(worker_context_provider),
gpu_memory_buffer_manager(), renderer_settings, &debug_settings_,
task_runner_provider(), false /* synchronous_composite */, refresh_rate,
std::move(on_draw_callback));
layer_tree_frame_sink_ = frame_sink.get();
return std::move(frame_sink);
}
void CallOnDraw() {
if (!TestEnded()) {
// Synchronous compositor does not draw unless told to do so by the output
// surface. But it needs to be done on a new stack frame.
bool resourceless_software_draw = false;
ImplThreadTaskRunner()->PostTask(
FROM_HERE, base::BindOnce(&OnDrawLayerTreeFrameSink::OnDraw,
base::Unretained(layer_tree_frame_sink_),
resourceless_software_draw));
}
}
raw_ptr<OnDrawLayerTreeFrameSink> layer_tree_frame_sink_ = nullptr;
};
// TODO(crbug.com/40146306): Test is flaky.
// MULTI_THREAD_TEST_F(
// LayerTreeHostTestAbortedCommitDoesntStallSynchronousCompositor);
class LayerTreeHostTestSynchronousCompositorActivateWithoutDraw
: public LayerTreeHostTest {
protected:
void InitializeSettings(LayerTreeSettings* settings) override {
settings->using_synchronous_renderer_compositor = true;
}
std::unique_ptr<TestLayerTreeFrameSink> CreateLayerTreeFrameSink(
const viz::RendererSettings& renderer_settings,
double refresh_rate,
scoped_refptr<viz::RasterContextProvider> compositor_context_provider,
scoped_refptr<viz::RasterContextProvider> worker_context_provider)
override {
// Make |invalidate_callback| do nothing so there is no draw.
auto frame_sink = std::make_unique<OnDrawLayerTreeFrameSink>(
compositor_context_provider, std::move(worker_context_provider),
gpu_memory_buffer_manager(), renderer_settings, &debug_settings_,
task_runner_provider(),
/*synchronous_composite=*/false, refresh_rate,
/*invalidate_callback=*/base::DoNothing());
return std::move(frame_sink);
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DidCommit() override { commit_count_++; }
void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
activate_count_++;
if (activate_count_ == 1) {
PostSetNeedsCommitToMainThread();
} else if (activate_count_ == 2) {
EndTest();
} else {
NOTREACHED();
}
}
void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
// This test specifically tests that two commit-activate cycles without
// draw in between them.
ADD_FAILURE();
}
void AfterTest() override {
// There should be two commits and activations without any draw.
EXPECT_EQ(commit_count_, 2);
EXPECT_EQ(activate_count_, 2);
}
private:
int commit_count_ = 0;
int activate_count_ = 0;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestSynchronousCompositorActivateWithoutDraw);
class LayerTreeHostTestUninvertibleTransformDoesNotBlockActivation
: public LayerTreeHostTest {
protected:
void SetupTree() override {
LayerTreeHostTest::SetupTree();
scoped_refptr<Layer> layer = PictureLayer::Create(&client_);
layer->SetTransform(gfx::Transform::MakeScale(0, 0));
layer->SetBounds(gfx::Size(10, 10));
layer_tree_host()->root_layer()->AddChild(layer);
client_.set_bounds(layer->bounds());
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
EndTest();
}
FakeContentLayerClient client_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(
LayerTreeHostTestUninvertibleTransformDoesNotBlockActivation);
// Test for UI Resource management.
class LayerTreeHostTestUIResource : public LayerTreeHostTest {
public:
LayerTreeHostTestUIResource() : num_ui_resources_(0) {}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DidCommit() override {
int frame = layer_tree_host()->SourceFrameNumber();
switch (frame) {
case 1:
CreateResource();
CreateResource();
PostSetNeedsCommitToMainThread();
break;
case 2:
// Usually ScopedUIResource are deleted from the manager in their
// destructor. Here we just want to test that a direct call to
// DeleteUIResource works.
layer_tree_host()->GetUIResourceManager()->DeleteUIResource(
ui_resources_[0]->id());
PostSetNeedsCommitToMainThread();
break;
case 3:
// DeleteUIResource can be called with an invalid id.
layer_tree_host()->GetUIResourceManager()->DeleteUIResource(
ui_resources_[0]->id());
PostSetNeedsCommitToMainThread();
break;
case 4:
CreateResource();
CreateResource();
PostSetNeedsCommitToMainThread();
break;
case 5:
ClearResources();
EndTest();
break;
}
}
void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
auto* sii = static_cast<viz::TestContextProvider*>(
impl->layer_tree_frame_sink()->context_provider())
->SharedImageInterface();
int frame = impl->active_tree()->source_frame_number();
switch (frame) {
case 0:
ASSERT_EQ(0u, sii->shared_image_count());
break;
case 1:
// Created two textures.
ASSERT_EQ(2u, sii->shared_image_count());
break;
case 2:
// One texture left after one deletion.
ASSERT_EQ(1u, sii->shared_image_count());
break;
case 3:
// Resource manager state should not change when delete is called on an
// invalid id.
ASSERT_EQ(1u, sii->shared_image_count());
break;
case 4:
// Creation after deletion: two more creates should total up to
// three textures.
ASSERT_EQ(3u, sii->shared_image_count());
break;
}
}
private:
// Must clear all resources before exiting.
void ClearResources() {
for (int i = 0; i < num_ui_resources_; i++)
ui_resources_[i] = nullptr;
}
void CreateResource() {
ui_resources_[num_ui_resources_++] =
FakeScopedUIResource::Create(layer_tree_host()->GetUIResourceManager());
}
std::unique_ptr<FakeScopedUIResource> ui_resources_[5];
int num_ui_resources_;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestUIResource);
class LayerTreeHostTestLayersPushProperties : public LayerTreeHostTest {
protected:
void BeginTest() override {
num_commits_ = 0;
expected_push_properties_root_ = 0;
expected_push_properties_child_ = 0;
expected_push_properties_grandchild_ = 0;
expected_push_properties_child2_ = 0;
expected_push_properties_other_root_ = 0;
expected_push_properties_leaf_layer_ = 0;
PostSetNeedsCommitToMainThread();
}
void SetupTree() override {
root_ = PushPropertiesCountingLayer::Create();
child_ = PushPropertiesCountingLayer::Create();
child2_ = PushPropertiesCountingLayer::Create();
grandchild_ = PushPropertiesCountingLayer::Create();
leaf_always_pushing_layer_ = PushPropertiesCountingLayer::Create();
root_->AddChild(child_);
root_->AddChild(child2_);
child_->AddChild(grandchild_);
child2_->AddChild(leaf_always_pushing_layer_);
other_root_ = PushPropertiesCountingLayer::Create();
// Don't set the root layer here.
LayerTreeHostTest::SetupTree();
client_.set_bounds(root_->bounds());
}
void DidCommitAndDrawFrame() override {
EXPECT_EQ(expected_push_properties_root_, root_->push_properties_count())
<< "num_commits: " << num_commits_;
EXPECT_EQ(expected_push_properties_child_, child_->push_properties_count())
<< "num_commits: " << num_commits_;
EXPECT_EQ(expected_push_properties_grandchild_,
grandchild_->push_properties_count())
<< "num_commits: " << num_commits_;
EXPECT_EQ(expected_push_properties_child2_,
child2_->push_properties_count())
<< "num_commits: " << num_commits_;
EXPECT_EQ(expected_push_properties_other_root_,
other_root_->push_properties_count())
<< "num_commits: " << num_commits_;
EXPECT_EQ(expected_push_properties_leaf_layer_,
leaf_always_pushing_layer_->push_properties_count())
<< "num_commits: " << num_commits_;
++num_commits_;
// The scrollbar layer always needs to be pushed.
if (root_->layer_tree_host()) {
EXPECT_FALSE(base::Contains(
static_cast<const LayerTreeHost*>(root_->layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
}
if (child2_->layer_tree_host()) {
EXPECT_FALSE(base::Contains(
static_cast<const LayerTreeHost*>(child2_->layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child2_.get()));
}
if (leaf_always_pushing_layer_->layer_tree_host()) {
leaf_always_pushing_layer_->SetNeedsPushProperties();
EXPECT_TRUE(
base::Contains(static_cast<const LayerTreeHost*>(
leaf_always_pushing_layer_->layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
leaf_always_pushing_layer_.get()));
}
// child_ and grandchild_ don't persist their need to push properties.
if (child_->layer_tree_host()) {
EXPECT_FALSE(base::Contains(
static_cast<const LayerTreeHost*>(child_->layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
}
if (grandchild_->layer_tree_host()) {
EXPECT_FALSE(base::Contains(
static_cast<const LayerTreeHost*>(grandchild_->layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild_.get()));
}
if (other_root_->layer_tree_host()) {
EXPECT_FALSE(base::Contains(
static_cast<const LayerTreeHost*>(other_root_->layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
other_root_.get()));
}
switch (num_commits_) {
case 1:
layer_tree_host()->SetRootLayer(root_);
// Layers added to the tree get committed.
++expected_push_properties_root_;
++expected_push_properties_child_;
++expected_push_properties_grandchild_;
++expected_push_properties_child2_;
break;
case 2:
layer_tree_host()->SetNeedsCommit();
// No layers need commit.
break;
case 3:
layer_tree_host()->SetRootLayer(other_root_);
// Layers added to the tree get committed.
++expected_push_properties_other_root_;
break;
case 4:
layer_tree_host()->SetRootLayer(root_);
// Layers added to the tree get committed.
++expected_push_properties_root_;
++expected_push_properties_child_;
++expected_push_properties_grandchild_;
++expected_push_properties_child2_;
break;
case 5:
layer_tree_host()->SetNeedsCommit();
// No layers need commit.
break;
case 6:
child_->RemoveFromParent();
// No layers need commit.
break;
case 7:
root_->AddChild(child_);
// Layers added to the tree get committed.
++expected_push_properties_child_;
++expected_push_properties_grandchild_;
break;
case 8:
grandchild_->RemoveFromParent();
// No layers need commit.
break;
case 9:
child_->AddChild(grandchild_);
// Layers added to the tree get committed.
++expected_push_properties_grandchild_;
break;
case 10:
GenerateNewLocalSurfaceId();
layer_tree_host()->SetViewportRectAndScale(gfx::Rect(20, 20), 1.f,
GetCurrentLocalSurfaceId());
// No layers need commit.
break;
case 11:
layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.8f, 1.1f);
// No layers need commit.
break;
case 12:
child_->MakePushProperties();
// The modified layer needs commit
++expected_push_properties_child_;
++expected_push_properties_grandchild_;
break;
case 13:
child2_->MakePushProperties();
// The modified layer needs commit
++expected_push_properties_child2_;
break;
case 14:
child_->RemoveFromParent();
root_->AddChild(child_);
// Layers added to the tree get committed.
++expected_push_properties_child_;
++expected_push_properties_grandchild_;
break;
case 15:
grandchild_->MakePushProperties();
// The modified layer needs commit
++expected_push_properties_grandchild_;
break;
case 16:
// SetNeedsDisplay does not always set needs commit (so call it
// explicitly), but is a property change.
child_->SetNeedsDisplay();
++expected_push_properties_child_;
layer_tree_host()->SetNeedsCommit();
break;
case 17:
EndTest();
break;
}
// The leaf layer always pushes.
if (leaf_always_pushing_layer_->layer_tree_host())
++expected_push_properties_leaf_layer_;
}
int num_commits_;
FakeContentLayerClient client_;
scoped_refptr<PushPropertiesCountingLayer> root_;
scoped_refptr<PushPropertiesCountingLayer> child_;
scoped_refptr<PushPropertiesCountingLayer> child2_;
scoped_refptr<PushPropertiesCountingLayer> grandchild_;
scoped_refptr<PushPropertiesCountingLayer> other_root_;
scoped_refptr<PushPropertiesCountingLayer> leaf_always_pushing_layer_;
size_t expected_push_properties_root_;
size_t expected_push_properties_child_;
size_t expected_push_properties_child2_;
size_t expected_push_properties_grandchild_;
size_t expected_push_properties_other_root_;
size_t expected_push_properties_leaf_layer_;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestLayersPushProperties);
class LayerTreeHostTestImplLayersPushProperties
: public LayerTreeHostTestLayersPushProperties {
protected:
void BeginTest() override {
expected_push_properties_root_impl_ = 0;
expected_push_properties_child_impl_ = 0;
expected_push_properties_grandchild_impl_ = 0;
expected_push_properties_child2_impl_ = 0;
expected_push_properties_grandchild2_impl_ = 0;
LayerTreeHostTestLayersPushProperties::BeginTest();
}
void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
// These commits are in response to the changes made in
// LayerTreeHostTestLayersPushProperties::DidCommitAndDrawFrame()
switch (num_commits_) {
case 0:
// Tree hasn't been setup yet don't bother to check anything.
return;
case 1:
// Root gets set up, Everyone is initialized.
++expected_push_properties_root_impl_;
++expected_push_properties_child_impl_;
++expected_push_properties_grandchild_impl_;
++expected_push_properties_child2_impl_;
++expected_push_properties_grandchild2_impl_;
break;
case 2:
// Tree doesn't change but the one leaf that always pushes is pushed.
++expected_push_properties_grandchild2_impl_;
break;
case 3:
// Root is swapped here.
// Clear the expected push properties the tree will be rebuilt.
expected_push_properties_root_impl_ = 0;
expected_push_properties_child_impl_ = 0;
expected_push_properties_grandchild_impl_ = 0;
expected_push_properties_child2_impl_ = 0;
expected_push_properties_grandchild2_impl_ = 0;
// Make sure the new root is pushed.
EXPECT_EQ(1u, static_cast<PushPropertiesCountingLayerImpl*>(
host_impl->active_tree()->root_layer())
->push_properties_count());
return;
case 4:
// Root is swapped back all of the layers in the tree get pushed.
++expected_push_properties_root_impl_;
++expected_push_properties_child_impl_;
++expected_push_properties_grandchild_impl_;
++expected_push_properties_child2_impl_;
++expected_push_properties_grandchild2_impl_;
break;
case 5:
// Tree doesn't change but the one leaf that always pushes is pushed.
++expected_push_properties_grandchild2_impl_;
break;
case 6:
// First child is removed. Structure of the tree changes.
expected_push_properties_child_impl_ = 0;
expected_push_properties_grandchild_impl_ = 0;
// The leaf that always pushes is pushed.
++expected_push_properties_grandchild2_impl_;
break;
case 7:
// The leaf that always pushes is pushed.
++expected_push_properties_grandchild2_impl_;
// Child is added back. New layers are initialized.
++expected_push_properties_grandchild_impl_;
++expected_push_properties_child_impl_;
break;
case 8:
// Leaf is removed.
expected_push_properties_grandchild_impl_ = 0;
// Always pushing.
++expected_push_properties_grandchild2_impl_;
break;
case 9:
// Leaf is added back
++expected_push_properties_grandchild_impl_;
// The leaf that always pushes is pushed.
++expected_push_properties_grandchild2_impl_;
break;
case 10:
// The leaf that always pushes is pushed.
++expected_push_properties_grandchild2_impl_;
break;
case 11:
// The leaf that always pushes is pushed.
++expected_push_properties_grandchild2_impl_;
break;
case 12:
// The leaf that always pushes is pushed.
++expected_push_properties_grandchild2_impl_;
// This child position was changed. So the subtree needs to push
// properties.
++expected_push_properties_child_impl_;
++expected_push_properties_grandchild_impl_;
break;
case 13:
// The position of this child was changed.
++expected_push_properties_child2_impl_;
// The leaf that always pushes is pushed.
++expected_push_properties_grandchild2_impl_;
break;
case 14:
// Second child is removed from tree. Don't discard counts because
// they are added back before commit.
// The leaf that always pushes is pushed.
++expected_push_properties_grandchild2_impl_;
// Second child added back.
++expected_push_properties_child_impl_;
++expected_push_properties_grandchild_impl_;
break;
case 15:
// The position of this child was changed.
++expected_push_properties_grandchild_impl_;
// The leaf that always pushes is pushed.
++expected_push_properties_grandchild2_impl_;
break;
case 16:
// Second child is invalidated with SetNeedsDisplay
++expected_push_properties_child_impl_;
// The leaf that always pushed is pushed.
++expected_push_properties_grandchild2_impl_;
break;
}
PushPropertiesCountingLayerImpl* root_impl_ = nullptr;
PushPropertiesCountingLayerImpl* child_impl_ = nullptr;
PushPropertiesCountingLayerImpl* child2_impl_ = nullptr;
PushPropertiesCountingLayerImpl* grandchild_impl_ = nullptr;
PushPropertiesCountingLayerImpl* leaf_always_pushing_layer_impl_ = nullptr;
// Pull the layers that we need from the tree assuming the same structure
// as LayerTreeHostTestLayersPushProperties
root_impl_ = static_cast<PushPropertiesCountingLayerImpl*>(
host_impl->active_tree()->root_layer());
LayerTreeImpl* impl = root_impl_->layer_tree_impl();
if (impl->LayerById(child_->id())) {
child_impl_ = static_cast<PushPropertiesCountingLayerImpl*>(
impl->LayerById(child_->id()));
if (impl->LayerById(grandchild_->id()))
grandchild_impl_ = static_cast<PushPropertiesCountingLayerImpl*>(
impl->LayerById(grandchild_->id()));
}
if (impl->LayerById(child2_->id())) {
child2_impl_ = static_cast<PushPropertiesCountingLayerImpl*>(
impl->LayerById(child2_->id()));
if (impl->LayerById(leaf_always_pushing_layer_->id()))
leaf_always_pushing_layer_impl_ =
static_cast<PushPropertiesCountingLayerImpl*>(
impl->LayerById(leaf_always_pushing_layer_->id()));
}
if (root_impl_)
EXPECT_EQ(expected_push_properties_root_impl_,
root_impl_->push_properties_count());
if (child_impl_)
EXPECT_EQ(expected_push_properties_child_impl_,
child_impl_->push_properties_count());
if (grandchild_impl_)
EXPECT_EQ(expected_push_properties_grandchild_impl_,
grandchild_impl_->push_properties_count());
if (child2_impl_)
EXPECT_EQ(expected_push_properties_child2_impl_,
child2_impl_->push_properties_count());
if (leaf_always_pushing_layer_impl_)
EXPECT_EQ(expected_push_properties_grandchild2_impl_,
leaf_always_pushing_layer_impl_->push_properties_count());
}
size_t expected_push_properties_root_impl_;
size_t expected_push_properties_child_impl_;
size_t expected_push_properties_child2_impl_;
size_t expected_push_properties_grandchild_impl_;
size_t expected_push_properties_grandchild2_impl_;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestImplLayersPushProperties);
class LayerTreeHostTestPropertyChangesDuringUpdateArePushed
: public LayerTreeHostTest {
protected:
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void SetupTree() override {
root_ = Layer::Create();
root_->SetBounds(gfx::Size(30, 30));
auto scrollbar = FakePaintedScrollbarLayer::CreateScrollbar();
scrollbar->set_should_paint(true);
scrollbar->set_has_thumb(false);
scrollbar_layer_ =
base::MakeRefCounted<FakePaintedScrollbarLayer>(root_->element_id());
scrollbar_layer_->SetBounds(gfx::Size(23, 100));
root_->AddChild(scrollbar_layer_);
layer_tree_host()->SetRootLayer(root_);
LayerTreeHostTest::SetupTree();
}
void DidCommitAndDrawFrame() override {
switch (layer_tree_host()->SourceFrameNumber()) {
case 0:
break;
case 1: {
// During update, the ignore_set_needs_commit_ bit is set to true to
// avoid causing a second commit to be scheduled. If a property change
// is made during this, however, it needs to be pushed in the upcoming
// commit.
auto ignore = scrollbar_layer_->IgnoreSetNeedsCommitForTest();
scrollbar_layer_->SetBounds(gfx::Size(30, 30));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
scrollbar_layer_.get()));
layer_tree_host()->SetNeedsCommit();
scrollbar_layer_->reset_push_properties_count();
EXPECT_EQ(0u, scrollbar_layer_->push_properties_count());
break;
}
case 2:
EXPECT_EQ(1u, scrollbar_layer_->push_properties_count());
EndTest();
break;
}
}
scoped_refptr<Layer> root_;
scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer_;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestPropertyChangesDuringUpdateArePushed);
class LayerTreeHostTestSetDrawableCausesCommit : public LayerTreeHostTest {
protected:
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void SetupTree() override {
root_ = PushPropertiesCountingLayer::Create();
child_ = PushPropertiesCountingLayer::Create();
root_->AddChild(child_);
layer_tree_host()->SetRootLayer(root_);
LayerTreeHostTest::SetupTree();
}
void DidCommitAndDrawFrame() override {
switch (layer_tree_host()->SourceFrameNumber()) {
case 0:
break;
case 1: {
// During update, the ignore_set_needs_commit_ bit is set to true to
// avoid causing a second commit to be scheduled. If a property change
// is made during this, however, it needs to be pushed in the upcoming
// commit.
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
EXPECT_EQ(0, root_->NumDescendantsThatDrawContent());
root_->reset_push_properties_count();
child_->reset_push_properties_count();
child_->SetIsDrawable(true);
EXPECT_EQ(1, root_->NumDescendantsThatDrawContent());
EXPECT_EQ(0u, root_->push_properties_count());
EXPECT_EQ(0u, child_->push_properties_count());
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
break;
}
case 2:
EXPECT_EQ(1u, root_->push_properties_count());
EXPECT_EQ(1u, child_->push_properties_count());
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
EndTest();
break;
}
}
scoped_refptr<PushPropertiesCountingLayer> root_;
scoped_refptr<PushPropertiesCountingLayer> child_;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestSetDrawableCausesCommit);
class LayerTreeHostTestCasePushPropertiesThreeGrandChildren
: public LayerTreeHostTest {
protected:
void BeginTest() override {
expected_push_properties_root_ = 0;
expected_push_properties_child_ = 0;
expected_push_properties_grandchild1_ = 0;
expected_push_properties_grandchild2_ = 0;
expected_push_properties_grandchild3_ = 0;
PostSetNeedsCommitToMainThread();
}
void SetupTree() override {
root_ = PushPropertiesCountingLayer::Create();
child_ = PushPropertiesCountingLayer::Create();
grandchild1_ = PushPropertiesCountingLayer::Create();
grandchild2_ = PushPropertiesCountingLayer::Create();
grandchild3_ = PushPropertiesCountingLayer::Create();
root_->AddChild(child_);
child_->AddChild(grandchild1_);
child_->AddChild(grandchild2_);
child_->AddChild(grandchild3_);
// Don't set the root layer here.
LayerTreeHostTest::SetupTree();
client_.set_bounds(root_->bounds());
}
FakeContentLayerClient client_;
scoped_refptr<PushPropertiesCountingLayer> root_;
scoped_refptr<PushPropertiesCountingLayer> child_;
scoped_refptr<PushPropertiesCountingLayer> grandchild1_;
scoped_refptr<PushPropertiesCountingLayer> grandchild2_;
scoped_refptr<PushPropertiesCountingLayer> grandchild3_;
size_t expected_push_properties_root_;
size_t expected_push_properties_child_;
size_t expected_push_properties_grandchild1_;
size_t expected_push_properties_grandchild2_;
size_t expected_push_properties_grandchild3_;
};
class LayerTreeHostTestPushPropertiesAddingToTreeRequiresPush
: public LayerTreeHostTestCasePushPropertiesThreeGrandChildren {
protected:
void DidCommitAndDrawFrame() override {
int last_source_frame_number = layer_tree_host()->SourceFrameNumber() - 1;
switch (last_source_frame_number) {
case 0:
// All layers will need push properties as we set their layer tree host
layer_tree_host()->SetRootLayer(root_);
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild1_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild2_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild3_.get()));
break;
case 1:
EndTest();
break;
}
}
};
MULTI_THREAD_TEST_F(LayerTreeHostTestPushPropertiesAddingToTreeRequiresPush);
class LayerTreeHostTestPushPropertiesRemovingChildStopsRecursion
: public LayerTreeHostTestCasePushPropertiesThreeGrandChildren {
protected:
void DidCommitAndDrawFrame() override {
int last_source_frame_number = layer_tree_host()->SourceFrameNumber() - 1;
switch (last_source_frame_number) {
case 0:
layer_tree_host()->SetRootLayer(root_);
break;
case 1:
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild1_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild2_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild3_.get()));
grandchild1_->RemoveFromParent();
grandchild1_->SetPosition(gfx::PointF(1.f, 1.f));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild2_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild3_.get()));
child_->AddChild(grandchild1_);
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild1_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild2_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild3_.get()));
grandchild2_->SetPosition(gfx::PointF(1.f, 1.f));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild1_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild2_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild3_.get()));
// grandchild2_ will still need a push properties.
grandchild1_->RemoveFromParent();
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
// grandchild3_ does not need a push properties, so recursing should
// no longer be needed.
grandchild2_->RemoveFromParent();
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
EndTest();
break;
}
}
};
MULTI_THREAD_TEST_F(LayerTreeHostTestPushPropertiesRemovingChildStopsRecursion);
class LayerTreeHostTestPushPropertiesRemovingChildStopsRecursionWithPersistence
: public LayerTreeHostTestCasePushPropertiesThreeGrandChildren {
protected:
void DidCommitAndDrawFrame() override {
// The grand children are set to need push properties, to verify the impact
// on their ancestors.
grandchild1_->SetNeedsPushProperties();
grandchild2_->SetNeedsPushProperties();
int last_source_frame_number = layer_tree_host()->SourceFrameNumber() - 1;
switch (last_source_frame_number) {
case 0:
layer_tree_host()->SetRootLayer(root_);
break;
case 1:
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild1_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild2_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild3_.get()));
// grandchild2_ will still need a push properties.
grandchild1_->RemoveFromParent();
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
// grandchild3_ does not need a push properties, so recursing should
// no longer be needed.
grandchild2_->RemoveFromParent();
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
EndTest();
break;
}
}
};
MULTI_THREAD_TEST_F(
LayerTreeHostTestPushPropertiesRemovingChildStopsRecursionWithPersistence);
class LayerTreeHostTestPushPropertiesSetPropertiesWhileOutsideTree
: public LayerTreeHostTestCasePushPropertiesThreeGrandChildren {
protected:
void DidCommitAndDrawFrame() override {
int last_source_frame_number = layer_tree_host()->SourceFrameNumber() - 1;
switch (last_source_frame_number) {
case 0:
layer_tree_host()->SetRootLayer(root_);
break;
case 1:
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild1_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild2_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild3_.get()));
// Change grandchildren while their parent is not in the tree.
child_->RemoveFromParent();
grandchild1_->SetPosition(gfx::PointF(1.f, 1.f));
grandchild2_->SetPosition(gfx::PointF(1.f, 1.f));
root_->AddChild(child_);
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild1_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild2_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild3_.get()));
grandchild1_->RemoveFromParent();
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
grandchild2_->RemoveFromParent();
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
grandchild3_->RemoveFromParent();
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
EndTest();
break;
}
}
};
MULTI_THREAD_TEST_F(
LayerTreeHostTestPushPropertiesSetPropertiesWhileOutsideTree);
class LayerTreeHostTestPushPropertiesSetPropertyInParentThenChild
: public LayerTreeHostTestCasePushPropertiesThreeGrandChildren {
protected:
void DidCommitAndDrawFrame() override {
int last_source_frame_number = layer_tree_host()->SourceFrameNumber() - 1;
switch (last_source_frame_number) {
case 0:
layer_tree_host()->SetRootLayer(root_);
break;
case 1:
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild1_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild2_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild3_.get()));
child_->SetPosition(gfx::PointF(1.f, 1.f));
grandchild1_->SetPosition(gfx::PointF(1.f, 1.f));
grandchild2_->SetPosition(gfx::PointF(1.f, 1.f));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild1_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild2_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild3_.get()));
grandchild1_->RemoveFromParent();
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
grandchild2_->RemoveFromParent();
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
child_->RemoveFromParent();
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EndTest();
break;
}
}
};
MULTI_THREAD_TEST_F(
LayerTreeHostTestPushPropertiesSetPropertyInParentThenChild);
class LayerTreeHostTestPushPropertiesSetPropertyInChildThenParent
: public LayerTreeHostTestCasePushPropertiesThreeGrandChildren {
protected:
void DidCommitAndDrawFrame() override {
int last_source_frame_number = layer_tree_host()->SourceFrameNumber() - 1;
switch (last_source_frame_number) {
case 0:
layer_tree_host()->SetRootLayer(root_);
break;
case 1:
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild1_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild2_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild3_.get()));
grandchild1_->SetPosition(gfx::PointF(1.f, 1.f));
grandchild2_->SetPosition(gfx::PointF(1.f, 1.f));
child_->SetPosition(gfx::PointF(1.f, 1.f));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild1_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild2_.get()));
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
grandchild3_.get()));
grandchild1_->RemoveFromParent();
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
grandchild2_->RemoveFromParent();
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EXPECT_TRUE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_.get()));
child_->RemoveFromParent();
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
root_.get()));
EndTest();
break;
}
}
};
MULTI_THREAD_TEST_F(
LayerTreeHostTestPushPropertiesSetPropertyInChildThenParent);
// This test verifies that the tree activation callback is invoked correctly.
class LayerTreeHostTestTreeActivationCallback : public LayerTreeHostTest {
public:
LayerTreeHostTestTreeActivationCallback()
: num_commits_(0), callback_count_(0) {}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
LayerTreeHostImpl::FrameData* frame_data,
DrawResult draw_result) override {
++num_commits_;
switch (num_commits_) {
case 1:
EXPECT_EQ(0, callback_count_);
callback_count_ = 0;
SetCallback(host_impl, true);
PostSetNeedsCommitToMainThread();
break;
case 2:
EXPECT_EQ(1, callback_count_);
callback_count_ = 0;
SetCallback(host_impl, false);
PostSetNeedsCommitToMainThread();
break;
case 3:
EXPECT_EQ(0, callback_count_);
callback_count_ = 0;
EndTest();
break;
default:
ADD_FAILURE() << num_commits_;
EndTest();
break;
}
return LayerTreeHostTest::PrepareToDrawOnThread(host_impl, frame_data,
draw_result);
}
void AfterTest() override { EXPECT_EQ(3, num_commits_); }
void SetCallback(LayerTreeHostImpl* host_impl, bool enable) {
host_impl->SetTreeActivationCallback(
enable
? base::BindRepeating(
&LayerTreeHostTestTreeActivationCallback::ActivationCallback,
base::Unretained(this))
: base::RepeatingClosure());
}
void ActivationCallback() { ++callback_count_; }
int num_commits_;
int callback_count_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestTreeActivationCallback);
class LayerInvalidateCausesDraw : public LayerTreeHostTest {
public:
LayerInvalidateCausesDraw() : num_commits_(0), num_draws_(0) {}
void BeginTest() override {
ASSERT_TRUE(invalidate_layer_)
<< "Derived tests must set this in SetupTree";
// One initial commit.
PostSetNeedsCommitToMainThread();
}
void DidCommitAndDrawFrame() override {
// After commit, invalidate the layer. This should cause a commit.
if (layer_tree_host()->SourceFrameNumber() == 1)
invalidate_layer_->SetNeedsDisplay();
}
void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
num_draws_++;
if (impl->active_tree()->source_frame_number() == 1)
EndTest();
}
void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
num_commits_++;
}
void AfterTest() override {
EXPECT_GE(2, num_commits_);
EXPECT_GE(2, num_draws_);
}
protected:
scoped_refptr<Layer> invalidate_layer_;
private:
int num_commits_;
int num_draws_;
};
// VideoLayer must support being invalidated and then passing that along
// to the compositor thread, even though no resources are updated in
// response to that invalidation.
class LayerTreeHostTestVideoLayerInvalidate : public LayerInvalidateCausesDraw {
public:
void SetupTree() override {
LayerTreeHostTest::SetupTree();
scoped_refptr<VideoLayer> video_layer =
VideoLayer::Create(&provider_, media::VIDEO_ROTATION_0);
video_layer->SetBounds(gfx::Size(10, 10));
video_layer->SetIsDrawable(true);
layer_tree_host()->root_layer()->AddChild(video_layer);
invalidate_layer_ = video_layer;
}
private:
FakeVideoFrameProvider provider_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestVideoLayerInvalidate);
class LayerTreeHostTestPushHiddenLayer : public LayerTreeHostTest {
protected:
void SetupTree() override {
root_layer_ = Layer::Create();
root_layer_->SetPosition(gfx::PointF());
root_layer_->SetBounds(gfx::Size(10, 10));
parent_layer_ = SolidColorLayer::Create();
parent_layer_->SetPosition(gfx::PointF());
parent_layer_->SetBounds(gfx::Size(10, 10));
parent_layer_->SetIsDrawable(true);
root_layer_->AddChild(parent_layer_);
child_layer_ = SolidColorLayer::Create();
child_layer_->SetPosition(gfx::PointF());
child_layer_->SetBounds(gfx::Size(10, 10));
child_layer_->SetIsDrawable(true);
parent_layer_->AddChild(child_layer_);
layer_tree_host()->SetRootLayer(root_layer_);
LayerTreeHostTest::SetupTree();
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DidCommitAndDrawFrame() override {
switch (layer_tree_host()->SourceFrameNumber()) {
case 1:
// The layer type used does not need to push properties every frame.
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_layer_.get()));
// Change the bounds of the child layer, but make it skipped
// by CalculateDrawProperties.
parent_layer_->SetOpacity(0.f);
child_layer_->SetBounds(gfx::Size(5, 5));
break;
case 2:
// The bounds of the child layer were pushed to the impl side.
EXPECT_FALSE(
base::Contains(const_cast<const LayerTreeHost*>(layer_tree_host())
->pending_commit_state()
->layers_that_should_push_properties,
child_layer_.get()));
EndTest();
break;
}
}
void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
LayerImpl* child = impl->active_tree()->LayerById(child_layer_->id());
switch (impl->active_tree()->source_frame_number()) {
case 1:
EXPECT_EQ(gfx::Size(5, 5).ToString(), child->bounds().ToString());
break;
}
}
scoped_refptr<Layer> root_layer_;
scoped_refptr<SolidColorLayer> parent_layer_;
scoped_refptr<SolidColorLayer> child_layer_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPushHiddenLayer);
class LayerTreeHostTestUpdateLayerInEmptyViewport : public LayerTreeHostTest {
protected:
void SetupTree() override {
root_layer_ = FakePictureLayer::Create(&client_);
root_layer_->SetBounds(gfx::Size(10, 10));
layer_tree_host()->SetRootLayer(root_layer_);
LayerTreeHostTest::SetupTree();
client_.set_bounds(root_layer_->bounds());
}
void BeginTest() override {
// The viewport is empty, but we still need to update layers on the main
// thread.
layer_tree_host()->SetViewportRectAndScale(gfx::Rect(0, 0), 1.f,
viz::LocalSurfaceId());
PostSetNeedsCommitToMainThread();
}
void DidCommit() override {
// The layer should be updated even though the viewport is empty, so we
// are capable of drawing it on the impl tree.
EXPECT_GT(root_layer_->update_count(), 0);
EndTest();
}
FakeContentLayerClient client_;
scoped_refptr<FakePictureLayer> root_layer_;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestUpdateLayerInEmptyViewport);
class LayerTreeHostTestElasticOverscroll : public LayerTreeHostTest {
public:
LayerTreeHostTestElasticOverscroll()
: scroll_elasticity_helper_(nullptr), num_draws_(0) {
SetUseLayerLists();
}
void InitializeSettings(LayerTreeSettings* settings) override {
settings->enable_elastic_overscroll = true;
}
void SetupTree() override {
SetInitialRootBounds(gfx::Size(100, 100));
LayerTreeHostTest::SetupTree();
root_layer_ = layer_tree_host()->root_layer();
SetupViewport(root_layer_, root_layer_->bounds(), root_layer_->bounds());
scoped_refptr<Layer> content_layer = FakePictureLayer::Create(&client_);
content_layer_id_ = content_layer->id();
content_layer->SetBounds(gfx::Size(100, 100));
CopyProperties(layer_tree_host()->OuterViewportScrollLayerForTesting(),
content_layer.get());
root_layer_->AddChild(content_layer);
client_.set_bounds(content_layer->bounds());
client_.set_fill_with_nonsolid_color(true);
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
if (host_impl->sync_tree()->source_frame_number() == 0) {
scroll_elasticity_helper_ =
host_impl->GetInputHandler().CreateScrollElasticityHelper();
}
}
void VerifyOverscroll(const gfx::Vector2dF& stretch_amount,
const gfx::Transform& transform) {
#if BUILDFLAG(IS_ANDROID)
gfx::Vector2dF scale = transform.To2dScale();
// On android, overscroll stretches the content. We don't assert the amount
// of stretch but there should be some stretch for overscroll and no stretch
// without it.
if (stretch_amount.x() == 0.f)
EXPECT_EQ(1.f, scale.x());
else
EXPECT_GT(scale.x(), 1.f);
if (stretch_amount.y() == 0.f)
EXPECT_EQ(1.f, scale.y());
else
EXPECT_GT(scale.y(), 1.f);
#else // BUILDFLAG(IS_ANDROID)
gfx::Transform expected_draw_transform;
expected_draw_transform.Translate(-stretch_amount);
EXPECT_EQ(expected_draw_transform, transform);
#endif // BUILDFLAG(IS_ANDROID)
}
void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
num_draws_++;
FakePictureLayerImpl* content_layer_impl =
static_cast<FakePictureLayerImpl*>(
host_impl->active_tree()->LayerById(content_layer_id_));
#if BUILDFLAG(IS_ANDROID)
// Elastic overscroll should not cause tilings with new scale to be created.
EXPECT_EQ(1u, content_layer_impl->tilings()->num_tilings())
<< "num_draws:" << num_draws_;
EXPECT_EQ(1.f, content_layer_impl->tilings()->GetMaximumContentsScale())
<< "num_draws_:" << num_draws_;
#endif // BUILDFLAG(IS_ANDROID)
switch (num_draws_) {
case 1:
// Initially, there's no overscroll.
VerifyOverscroll(gfx::Vector2dF(), content_layer_impl->DrawTransform());
// Begin overscrolling. This should be reflected in the draw transform
// the next time we draw.
scroll_elasticity_helper_->SetStretchAmount(gfx::Vector2dF(5.f, 6.f));
break;
case 2:
// We should have some overscroll.
VerifyOverscroll(gfx::Vector2dF(5.f, 6.f),
content_layer_impl->DrawTransform());
scroll_elasticity_helper_->SetStretchAmount(gfx::Vector2dF(3.f, 2.f));
break;
case 3:
VerifyOverscroll(gfx::Vector2dF(3.f, 2.f),
content_layer_impl->DrawTransform());
scroll_elasticity_helper_->SetStretchAmount(gfx::Vector2dF());
break;
case 4:
// In the final frame there is no more overscroll.
VerifyOverscroll(gfx::Vector2dF(), content_layer_impl->DrawTransform());
EndTest();
break;
default:
NOTREACHED();
}
}
private:
FakeContentLayerClient client_;
raw_ptr<Layer, DanglingUntriaged> root_layer_;
raw_ptr<ScrollElasticityHelper, AcrossTasksDanglingUntriaged>
scroll_elasticity_helper_;
int content_layer_id_;
int num_draws_;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestElasticOverscroll);
struct TestSwapPromiseResult {
TestSwapPromiseResult()
: did_activate_called(false),
did_swap_called(false),
did_not_swap_called(false),
dtor_called(false),
reason(SwapPromise::COMMIT_FAILS) {}
bool did_activate_called;
bool did_swap_called;
bool did_not_swap_called;
bool dtor_called;
SwapPromise::DidNotSwapReason reason;
base::Lock lock;
};
class TestSwapPromise : public SwapPromise {
public:
explicit TestSwapPromise(TestSwapPromiseResult* result) : result_(result) {}
~TestSwapPromise() override {
base::AutoLock lock(result_->lock);
result_->dtor_called = true;
}
void DidActivate() override {
base::AutoLock lock(result_->lock);
EXPECT_FALSE(result_->did_activate_called);
EXPECT_FALSE(result_->did_swap_called);
EXPECT_TRUE(!result_->did_not_swap_called ||
action_ == SwapPromise::DidNotSwapAction::KEEP_ACTIVE);
result_->did_activate_called = true;
}
void WillSwap(viz::CompositorFrameMetadata* metadata) override {
base::AutoLock lock(result_->lock);
EXPECT_FALSE(result_->did_swap_called);
EXPECT_TRUE(!result_->did_not_swap_called ||
action_ == SwapPromise::DidNotSwapAction::KEEP_ACTIVE);
result_->did_swap_called = true;
}
void DidSwap() override {}
DidNotSwapAction DidNotSwap(DidNotSwapReason reason,
base::TimeTicks ts) override {
base::AutoLock lock(result_->lock);
EXPECT_FALSE(result_->did_swap_called);
EXPECT_FALSE(result_->did_not_swap_called);
EXPECT_FALSE(result_->did_activate_called &&
reason != DidNotSwapReason::SWAP_FAILS);
result_->did_not_swap_called = true;
result_->reason = reason;
return action_;
}
void set_action(DidNotSwapAction action) { action_ = action; }
int64_t GetTraceId() const override { return 0; }
private:
// Not owned.
raw_ptr<TestSwapPromiseResult> result_;
DidNotSwapAction action_ = DidNotSwapAction::BREAK_PROMISE;
};
class PinnedLayerTreeSwapPromise : public LayerTreeHostTest {
protected:
void BeginTest() override {
layer_tree_host()->SetNeedsCommitWithForcedRedraw();
}
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
int frame = host_impl->active_tree()->source_frame_number();
if (frame == -1) {
host_impl->active_tree()->QueuePinnedSwapPromise(
std::make_unique<TestSwapPromise>(
&pinned_active_swap_promise_result_));
host_impl->pending_tree()->QueueSwapPromise(
std::make_unique<TestSwapPromise>(&pending_swap_promise_result_));
host_impl->active_tree()->QueueSwapPromise(
std::make_unique<TestSwapPromise>(&active_swap_promise_result_));
}
}
void DisplayDidDrawAndSwapOnThread() override { EndTest(); }
void AfterTest() override {
// The pending swap promise should activate and swap.
EXPECT_TRUE(pending_swap_promise_result_.did_activate_called);
EXPECT_TRUE(pending_swap_promise_result_.did_swap_called);
// The active swap promise should fail to swap (it is cancelled by
// the activation of a new frame).
EXPECT_FALSE(active_swap_promise_result_.did_activate_called);
EXPECT_FALSE(active_swap_promise_result_.did_swap_called);
EXPECT_TRUE(active_swap_promise_result_.did_not_swap_called);
EXPECT_EQ(active_swap_promise_result_.reason, SwapPromise::SWAP_FAILS);
// The pinned active swap promise should not activate, but should swap.
EXPECT_FALSE(pinned_active_swap_promise_result_.did_activate_called);
EXPECT_TRUE(pinned_active_swap_promise_result_.did_swap_called);
}
TestSwapPromiseResult pending_swap_promise_result_;
TestSwapPromiseResult active_swap_promise_result_;
TestSwapPromiseResult pinned_active_swap_promise_result_;
};
MULTI_THREAD_TEST_F(PinnedLayerTreeSwapPromise);
class LayerTreeHostTestBreakSwapPromise : public LayerTreeHostTest {
protected:
LayerTreeHostTestBreakSwapPromise()
: commit_count_(0), commit_complete_count_(0) {}
void WillBeginMainFrame() override {
ASSERT_LE(commit_count_, 2);
std::unique_ptr<SwapPromise> swap_promise(
new TestSwapPromise(&swap_promise_result_[commit_count_]));
layer_tree_host()->GetSwapPromiseManager()->QueueSwapPromise(
std::move(swap_promise));
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DidCommit() override {
commit_count_++;
if (commit_count_ == 2) {
// This commit will finish.
layer_tree_host()->SetNeedsCommit();
}
}
void WillActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
if (host_impl->pending_tree()) {
int frame = host_impl->pending_tree()->source_frame_number();
base::AutoLock lock(swap_promise_result_[frame].lock);
EXPECT_FALSE(swap_promise_result_[frame].did_activate_called);
EXPECT_FALSE(swap_promise_result_[frame].did_swap_called);
}
}
void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
int frame = host_impl->active_tree()->source_frame_number();
base::AutoLock lock(swap_promise_result_[frame].lock);
EXPECT_TRUE(swap_promise_result_[frame].did_activate_called);
EXPECT_FALSE(swap_promise_result_[frame].did_swap_called);
}
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
commit_complete_count_++;
if (commit_complete_count_ == 1) {
// This commit will be aborted because no actual update.
PostSetNeedsUpdateLayersToMainThread();
}
}
void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
int frame_num = host_impl->active_tree()->source_frame_number();
if (frame_num == 2) {
EndTest();
}
}
void AfterTest() override {
// 3 commits are scheduled. 2 completes. 1 is aborted.
EXPECT_EQ(commit_count_, 3);
EXPECT_EQ(commit_complete_count_, 2);
{
// The first commit completes and causes swap buffer which finishes
// the promise.
base::AutoLock lock(swap_promise_result_[0].lock);
EXPECT_TRUE(swap_promise_result_[0].did_swap_called);
EXPECT_FALSE(swap_promise_result_[0].did_not_swap_called);
EXPECT_TRUE(swap_promise_result_[0].dtor_called);
}
{
// The second commit is aborted since it contains no updates.
base::AutoLock lock(swap_promise_result_[1].lock);
EXPECT_FALSE(swap_promise_result_[1].did_activate_called);
EXPECT_FALSE(swap_promise_result_[1].did_swap_called);
EXPECT_TRUE(swap_promise_result_[1].did_not_swap_called);
EXPECT_EQ(SwapPromise::COMMIT_NO_UPDATE, swap_promise_result_[1].reason);
EXPECT_TRUE(swap_promise_result_[1].dtor_called);
}
{
// The last commit completes but it does not cause swap buffer because
// there is no damage in the frame data.
base::AutoLock lock(swap_promise_result_[2].lock);
EXPECT_TRUE(swap_promise_result_[2].did_activate_called);
EXPECT_FALSE(swap_promise_result_[2].did_swap_called);
EXPECT_TRUE(swap_promise_result_[2].did_not_swap_called);
EXPECT_EQ(SwapPromise::SWAP_FAILS, swap_promise_result_[2].reason);
EXPECT_TRUE(swap_promise_result_[2].dtor_called);
}
}
int commit_count_;
int commit_complete_count_;
TestSwapPromiseResult swap_promise_result_[3];
};
MULTI_THREAD_TEST_F(LayerTreeHostTestBreakSwapPromise);
class LayerTreeHostTestKeepSwapPromise : public LayerTreeHostTest {
public:
LayerTreeHostTestKeepSwapPromise() = default;
void BeginTest() override {
layer_ = SolidColorLayer::Create();
layer_->SetIsDrawable(true);
layer_->SetBounds(gfx::Size(10, 10));
layer_tree_host()->SetRootLayer(layer_);
gfx::Size bounds(100, 100);
layer_tree_host()->SetViewportRectAndScale(gfx::Rect(bounds), 1.f,
viz::LocalSurfaceId());
PostSetNeedsCommitToMainThread();
}
void DidCommit() override {
MainThreadTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(&LayerTreeHostTestKeepSwapPromise::ChangeFrame,
base::Unretained(this)));
}
void ChangeFrame() {
switch (layer_tree_host()->SourceFrameNumber()) {
case 1:
layer_->SetBounds(gfx::Size(10, 11));
layer_tree_host()->GetSwapPromiseManager()->QueueSwapPromise(
std::make_unique<TestSwapPromise>(&swap_promise_result_));
break;
case 2:
break;
default:
NOTREACHED();
}
}
void WillActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
if (host_impl->pending_tree()) {
if (host_impl->pending_tree()->source_frame_number() == 1) {
base::AutoLock lock(swap_promise_result_.lock);
EXPECT_FALSE(swap_promise_result_.did_activate_called);
EXPECT_FALSE(swap_promise_result_.did_swap_called);
SetCallback(host_impl, true);
} else {
SetCallback(host_impl, false);
}
}
}
void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
if (host_impl->active_tree()->source_frame_number() == 1) {
base::AutoLock lock(swap_promise_result_.lock);
EXPECT_TRUE(swap_promise_result_.did_activate_called);
EXPECT_FALSE(swap_promise_result_.did_swap_called);
}
}
void ActivationCallback() {
// DidActivate needs to happen before the tree activation callback.
base::AutoLock lock(swap_promise_result_.lock);
EXPECT_TRUE(swap_promise_result_.did_activate_called);
}
void SetCallback(LayerTreeHostImpl* host_impl, bool enable) {
host_impl->SetTreeActivationCallback(
enable ? base::BindRepeating(
&LayerTreeHostTestKeepSwapPromise::ActivationCallback,
base::Unretained(this))
: base::RepeatingClosure());
}
void DisplayDidDrawAndSwapOnThread() override {
if (num_swaps_++ >= 1) {
// The commit changes layers so it should cause a swap.
base::AutoLock lock(swap_promise_result_.lock);
EXPECT_TRUE(swap_promise_result_.did_swap_called);
EXPECT_FALSE(swap_promise_result_.did_not_swap_called);
EXPECT_TRUE(swap_promise_result_.dtor_called);
EndTest();
}
}
private:
int num_swaps_ = 0;
scoped_refptr<Layer> layer_;
TestSwapPromiseResult swap_promise_result_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestKeepSwapPromise);
class LayerTreeHostTestKeepSwapPromiseMFBA : public LayerTreeHostTest {
public:
LayerTreeHostTestKeepSwapPromiseMFBA() = default;
void InitializeSettings(LayerTreeSettings* settings) override {
settings->main_frame_before_activation_enabled = true;
}
void BeginTest() override {
layer_ = SolidColorLayer::Create();
layer_->SetIsDrawable(true);
layer_->SetBounds(gfx::Size(10, 10));
layer_tree_host()->SetRootLayer(layer_);
gfx::Size bounds(100, 100);
layer_tree_host()->SetViewportRectAndScale(gfx::Rect(bounds), 1.f,
viz::LocalSurfaceId());
PostSetNeedsCommitToMainThread();
}
void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override {
if (host_impl->sync_tree()->source_frame_number() == 0) {
host_impl->BlockNotifyReadyToActivateForTesting(true);
} else {
NOTREACHED();
}
}
void DidCommit() override {
MainThreadTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(&LayerTreeHostTestKeepSwapPromiseMFBA::ChangeFrame,
base::Unretained(this)));
}
void BeginMainFrameAbortedOnThread(
LayerTreeHostImpl* host_impl,
CommitEarlyOutReason reason,
bool /* did_sync_scroll_and_viewport */) override {
base::AutoLock lock(swap_promise_result_.lock);
EXPECT_FALSE(swap_promise_result_.did_not_swap_called);
EXPECT_FALSE(swap_promise_result_.did_activate_called);
EXPECT_FALSE(swap_promise_result_.did_swap_called);
host_impl->BlockNotifyReadyToActivateForTesting(false);
}
void ChangeFrame() {
switch (layer_tree_host()->SourceFrameNumber()) {
case 1:
// Make no changes so that we abort the next commit caused by queuing
// the swap promise.
layer_tree_host()->GetSwapPromiseManager()->QueueSwapPromise(
std::make_unique<TestSwapPromise>(&swap_promise_result_));
layer_tree_host()->SetNeedsUpdateLayers();
break;
case 2:
break;
default:
NOTREACHED();
}
}
void WillActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
if (host_impl->pending_tree()) {
if (host_impl->pending_tree()->source_frame_number() == 1) {
base::AutoLock lock(swap_promise_result_.lock);
EXPECT_FALSE(swap_promise_result_.did_activate_called);
EXPECT_FALSE(swap_promise_result_.did_swap_called);
SetCallback(host_impl, true);
} else {
SetCallback(host_impl, false);
}
}
}
void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
if (host_impl->active_tree()->source_frame_number() == 1) {
base::AutoLock lock(swap_promise_result_.lock);
EXPECT_TRUE(swap_promise_result_.did_activate_called);
EXPECT_FALSE(swap_promise_result_.did_swap_called);
}
}
void ActivationCallback() {
// DidActivate needs to happen before the tree activation callback.
base::AutoLock lock(swap_promise_result_.lock);
EXPECT_TRUE(swap_promise_result_.did_activate_called);
}
void SetCallback(LayerTreeHostImpl* host_impl, bool enable) {
host_impl->SetTreeActivationCallback(
enable ? base::BindRepeating(
&LayerTreeHostTestKeepSwapPromiseMFBA::ActivationCallback,
base::Unretained(this))
: base::RepeatingClosure());
}
void DisplayDidDrawAndSwapOnThread() override {
num_swaps_++;
base::AutoLock lock(swap_promise_result_.lock);
EXPECT_TRUE(swap_promise_result_.did_swap_called);
EXPECT_FALSE(swap_promise_result_.did_not_swap_called);
EXPECT_TRUE(swap_promise_result_.dtor_called);
EndTest();
}
void AfterTest() override { EXPECT_EQ(1, num_swaps_); }
private:
int num_swaps_ = 0;
scoped_refptr<Layer> layer_;
TestSwapPromiseResult swap_promise_result_;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestKeepSwapPromiseMFBA);
class LayerTreeHostTestDeferSwapPromiseForVisibility
: public LayerTreeHostTest {
protected:
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void SetVisibleFalseAndQueueSwapPromise() {
layer_tree_host()->SetVisible(false);
auto swap_promise =
std::make_unique<TestSwapPromise>(&swap_promise_result_);
swap_promise->set_action(SwapPromise::DidNotSwapAction::KEEP_ACTIVE);
layer_tree_host()->GetSwapPromiseManager()->QueueSwapPromise(
std::move(swap_promise));
}
void WillBeginImplFrameOnThread(LayerTreeHostImpl* impl,
const viz::BeginFrameArgs& args,
bool has_damage) override {
if (!sent_queue_request_) {
sent_queue_request_ = true;
MainThreadTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(&LayerTreeHostTestDeferSwapPromiseForVisibility::
SetVisibleFalseAndQueueSwapPromise,
base::Unretained(this)));
}
}
void BeginMainFrameAbortedOnThread(
LayerTreeHostImpl* host_impl,
CommitEarlyOutReason reason,
bool /* did_sync_scroll_and_viewport */) override {
MainThreadTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(&LayerTreeHostTestDeferSwapPromiseForVisibility::
CheckSwapPromiseNotCalled,
base::Unretained(this)));
}
void CheckSwapPromiseNotCalled() {
{
base::AutoLock lock(swap_promise_result_.lock);
EXPECT_FALSE(swap_promise_result_.did_activate_called);
EXPECT_FALSE(swap_promise_result_.did_swap_called);
EXPECT_TRUE(swap_promise_result_.did_not_swap_called);
EXPECT_EQ(SwapPromise::COMMIT_FAILS, swap_promise_result_.reason);
EXPECT_FALSE(swap_promise_result_.dtor_called);
}
layer_tree_host()->SetVisible(true);
}
void DidCommitAndDrawFrame() override {
{
base::AutoLock lock(swap_promise_result_.lock);
EXPECT_TRUE(swap_promise_result_.did_activate_called);
EXPECT_TRUE(swap_promise_result_.did_swap_called);
EXPECT_TRUE(swap_promise_result_.dtor_called);
}
EndTest();
}
TestSwapPromiseResult swap_promise_result_;
bool sent_queue_request_ = false;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDeferSwapPromiseForVisibility);
class LayerTreeHostTestSwapPromiseDuringCommit : public LayerTreeHostTest {
protected:
LayerTreeHostTestSwapPromiseDuringCommit() = default;
void WillBeginMainFrame() override {
if (TestEnded())
return;
std::unique_ptr<SwapPromise> swap_promise =
std::make_unique<TestSwapPromise>(&swap_promise_result_[0]);
{
StrictMock<MockLatencyInfoSwapPromiseMonitor> monitor(
layer_tree_host()->GetSwapPromiseManager());
// Queueing a swap promise from WillBeginMainFrame should not cause
// another commit to be scheduled.
EXPECT_CALL(monitor, OnSetNeedsCommitOnMain()).Times(0);
EXPECT_CALL(monitor, OnSetNeedsRedrawOnImpl()).Times(0);
layer_tree_host()->QueueSwapPromise(std::move(swap_promise));
}
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DidBeginMainFrame() override {
if (TestEnded())
return;
std::unique_ptr<SwapPromise> swap_promise =
std::make_unique<TestSwapPromise>(&swap_promise_result_[1]);
{
StrictMock<MockLatencyInfoSwapPromiseMonitor> monitor(
layer_tree_host()->GetSwapPromiseManager());
// Queueing a swap promise from DidBeginMainFrame should not cause a
// subsequent main frame to be scheduled.
EXPECT_CALL(monitor, OnSetNeedsCommitOnMain()).Times(0);
EXPECT_CALL(monitor, OnSetNeedsRedrawOnImpl()).Times(0);
layer_tree_host()->QueueSwapPromise(std::move(swap_promise));
}
EndTest();
}
TestSwapPromiseResult swap_promise_result_[2];
};
MULTI_THREAD_TEST_F(LayerTreeHostTestSwapPromiseDuringCommit);
class LayerTreeHostTestLatencyInfoSwapPromiseMonitor
: public LayerTreeHostTest {
public:
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void WillBeginMainFrame() override {
if (TestEnded())
return;
{
StrictMock<MockLatencyInfoSwapPromiseMonitor> monitor(
layer_tree_host()->GetSwapPromiseManager());
EXPECT_CALL(monitor, OnSetNeedsCommitOnMain()).Times(1);
EXPECT_CALL(monitor, OnSetNeedsRedrawOnImpl()).Times(0);
layer_tree_host()->SetNeedsCommit();
}
{
StrictMock<MockLatencyInfoSwapPromiseMonitor> monitor(
layer_tree_host()->GetSwapPromiseManager());
EXPECT_CALL(monitor, OnSetNeedsCommitOnMain()).Times(1);
EXPECT_CALL(monitor, OnSetNeedsRedrawOnImpl()).Times(0);
layer_tree_host()->SetNeedsUpdateLayers();
}
{
StrictMock<MockLatencyInfoSwapPromiseMonitor> monitor(
layer_tree_host()->GetSwapPromiseManager());
EXPECT_CALL(monitor, OnSetNeedsCommitOnMain()).Times(1);
EXPECT_CALL(monitor, OnSetNeedsRedrawOnImpl()).Times(0);
layer_tree_host()->SetNeedsAnimate();
}
EndTest();
}
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLatencyInfoSwapPromiseMonitor);
class LayerTreeHostTestHighResRequiredAfterEvictingUIResources
: public LayerTreeHostTest {
protected:
void SetupTree() override {
LayerTreeHostTest::SetupTree();
ui_resource_ =
FakeScopedUIResource::Create(layer_tree_host()->GetUIResourceManager());
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
if (TestEnded())
return;
host_impl->EvictAllUIResources();
// Existence of evicted UI resources will trigger NEW_CONTENT_TAKES_PRIORITY
// mode. Active tree should require high-res to draw after entering this
// mode to ensure that high-res tiles are also required for a pending tree
// to be activated.
EXPECT_TRUE(host_impl->RequiresHighResToDraw());
MainThreadTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(
&LayerTreeHostTestHighResRequiredAfterEvictingUIResources::
DeleteResourceAndEndTest,
base::Unretained(this)));
}
void DeleteResourceAndEndTest() {
// This must be destroyed before the test ends and tears down the
// LayerTreeHost. It causes another commit+activation though, which
// may run before the test exits.
ui_resource_ = nullptr;
EndTest();
}
std::unique_ptr<FakeScopedUIResource> ui_resource_;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestHighResRequiredAfterEvictingUIResources);
class LayerTreeHostTestGpuRasterizationDisabled : public LayerTreeHostTest {
protected:
void SetUpUnboundContextProviders(
viz::TestContextProvider* context_provider,
viz::TestContextProvider* worker_provider) override {
// The test contexts have gpu raster disabled by default.
gpu::Capabilities worker_caps =
worker_provider->UnboundTestRasterInterface()->capabilities();
EXPECT_FALSE(worker_caps.gpu_rasterization);
}
void SetupTree() override {
LayerTreeHostTest::SetupTree();
scoped_refptr<FakePictureLayer> layer =
FakePictureLayer::Create(&layer_client_);
layer_ = layer.get();
layer->SetBounds(gfx::Size(10, 10));
layer->SetIsDrawable(true);
layer_tree_host()->root_layer()->AddChild(layer);
layer_client_.set_bounds(layer_->bounds());
}
void BeginTest() override {
PostSetNeedsCommitToMainThread();
}
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
EXPECT_FALSE(host_impl->pending_tree()->use_gpu_rasterization());
EXPECT_FALSE(host_impl->use_gpu_rasterization());
}
void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
EXPECT_FALSE(host_impl->active_tree()->use_gpu_rasterization());
EXPECT_FALSE(host_impl->use_gpu_rasterization());
EndTest();
}
FakeContentLayerClient layer_client_;
raw_ptr<FakePictureLayer, DanglingUntriaged> layer_;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterizationDisabled);
class LayerTreeHostTestGpuRasterizationSupportedButDisabled
: public LayerTreeTest {
protected:
void SetUpUnboundContextProviders(
viz::TestContextProvider* context_provider,
viz::TestContextProvider* worker_provider) override {
context_provider->UnboundTestRasterInterface()->set_gpu_rasterization(true);
worker_provider->UnboundTestRasterInterface()->set_gpu_rasterization(true);
}
void InitializeSettings(LayerTreeSettings* settings) override {
settings->gpu_rasterization_disabled = true;
}
void SetupTree() override {
LayerTreeHostTest::SetupTree();
scoped_refptr<FakePictureLayer> layer =
FakePictureLayer::Create(&layer_client_);
layer_ = layer.get();
layer->SetBounds(gfx::Size(10, 10));
layer->SetIsDrawable(true);
layer_tree_host()->root_layer()->AddChild(layer);
layer_client_.set_bounds(layer_->bounds());
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
EXPECT_FALSE(host_impl->sync_tree()->use_gpu_rasterization());
EXPECT_FALSE(host_impl->use_gpu_rasterization());
}
void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
EXPECT_FALSE(host_impl->active_tree()->use_gpu_rasterization());
EXPECT_FALSE(host_impl->use_gpu_rasterization());
EndTest();
}
FakeContentLayerClient layer_client_;
raw_ptr<FakePictureLayer, DanglingUntriaged> layer_;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterizationSupportedButDisabled);
class LayerTreeHostTestGpuRasterizationEnabled : public LayerTreeHostTest {
protected:
void SetUpUnboundContextProviders(
viz::TestContextProvider* context_provider,
viz::TestContextProvider* worker_provider) override {
context_provider->UnboundTestRasterInterface()->set_gpu_rasterization(true);
worker_provider->UnboundTestRasterInterface()->set_gpu_rasterization(true);
}
void SetupTree() override {
LayerTreeHostTest::SetupTree();
scoped_refptr<FakePictureLayer> layer =
FakePictureLayer::Create(&layer_client_);
layer_ = layer.get();
layer->SetBounds(gfx::Size(10, 10));
layer->SetIsDrawable(true);
layer_tree_host()->root_layer()->AddChild(layer);
layer_client_.set_bounds(layer_->bounds());
}
void BeginTest() override {
PostSetNeedsCommitToMainThread();
}
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
EXPECT_TRUE(host_impl->sync_tree()->use_gpu_rasterization());
EXPECT_TRUE(host_impl->use_gpu_rasterization());
}
void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
EXPECT_TRUE(host_impl->active_tree()->use_gpu_rasterization());
EXPECT_TRUE(host_impl->use_gpu_rasterization());
EndTest();
}
FakeContentLayerClient layer_client_;
raw_ptr<FakePictureLayer, DanglingUntriaged> layer_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterizationEnabled);
class LayerTreeHostTestGpuRasterizationEnabledWithMSAA : public LayerTreeTest {
protected:
void SetUpUnboundContextProviders(
viz::TestContextProvider* context_provider,
viz::TestContextProvider* worker_provider) override {
auto* compositor = context_provider->UnboundTestRasterInterface();
compositor->set_gpu_rasterization(true);
auto* worker = worker_provider->UnboundTestRasterInterface();
worker->set_gpu_rasterization(true);
}
void InitializeSettings(LayerTreeSettings* settings) override {
// GetMSAASampleCountForRaster() will return this value if there are too
// many slow paths.
settings->gpu_rasterization_msaa_sample_count = 4;
}
void SetupTree() override {
LayerTreeHostTest::SetupTree();
scoped_refptr<FakePictureLayer> layer =
FakePictureLayer::Create(&layer_client_);
layer_ = layer.get();
layer->SetBounds(gfx::Size(10, 10));
layer->SetIsDrawable(true);
layer_tree_host()->root_layer()->AddChild(layer);
layer_client_.set_bounds(layer_->bounds());
}
void BeginTest() override {
// Content-based MSAA trigger.
layer_client_.set_contains_slow_paths(true);
// MSAA trigger will take effect when layers are updated.
// The results will be verified after commit is completed below.
// Since we are manually marking the source as containing slow paths,
// make sure that the layer gets a chance to update.
layer_->SetNeedsDisplay();
PostSetNeedsCommitToMainThread();
}
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
auto* raster_source = static_cast<PictureLayerImpl*>(
host_impl->sync_tree()->LayerById(layer_->id()))
->GetRasterSource();
EXPECT_GT(host_impl->GetMSAASampleCountForRaster(
*raster_source->GetDisplayItemList()),
0);
EXPECT_TRUE(host_impl->pending_tree()->use_gpu_rasterization());
EXPECT_TRUE(host_impl->use_gpu_rasterization());
EndTest();
}
FakeContentLayerClient layer_client_;
raw_ptr<FakePictureLayer, DanglingUntriaged> layer_;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestGpuRasterizationEnabledWithMSAA);
class LayerTreeHostTestWillBeginImplFrameHasDidFinishImplFrame
: public LayerTreeHostTest {
public:
enum { kExpectedNumImplFrames = 10 };
LayerTreeHostTestWillBeginImplFrameHasDidFinishImplFrame()
: will_begin_impl_frame_count_(0), did_finish_impl_frame_count_(0) {}
void BeginTest() override {
PostSetNeedsCommitToMainThread();
}
void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl,
const viz::BeginFrameArgs& args,
bool has_damage) override {
EXPECT_EQ(will_begin_impl_frame_count_, did_finish_impl_frame_count_);
EXPECT_FALSE(TestEnded());
will_begin_impl_frame_count_++;
}
void DidFinishImplFrameOnThread(LayerTreeHostImpl* host_impl) override {
did_finish_impl_frame_count_++;
EXPECT_EQ(will_begin_impl_frame_count_, did_finish_impl_frame_count_);
// Trigger a new impl frame until we are done testing.
if (did_finish_impl_frame_count_ < kExpectedNumImplFrames)
PostSetNeedsRedrawToMainThread();
else
EndTest();
}
void AfterTest() override {
EXPECT_GT(will_begin_impl_frame_count_, 0);
EXPECT_GT(did_finish_impl_frame_count_, 0);
EXPECT_EQ(will_begin_impl_frame_count_, did_finish_impl_frame_count_);
EXPECT_EQ(will_begin_impl_frame_count_, kExpectedNumImplFrames);
EXPECT_EQ(did_finish_impl_frame_count_, kExpectedNumImplFrames);
}
private:
int will_begin_impl_frame_count_;
int did_finish_impl_frame_count_;
};
// TODO(crbug.com/41388437): Disabled as flaky.
// SINGLE_AND_MULTI_THREAD_TEST_F(
// LayerTreeHostTestWillBeginImplFrameHasDidFinishImplFrame);
::testing::AssertionResult AssertFrameTimeContained(
const char* haystack_expr,
const char* needle_expr,
const std::vector<viz::BeginFrameArgs> haystack,
const viz::BeginFrameArgs needle) {
auto failure = ::testing::AssertionFailure()
<< needle.frame_time << " (" << needle_expr
<< ") not found in " << haystack_expr;
if (haystack.size() == 0) {
failure << " which is empty.";
} else {
failure << " which contains:\n";
for (size_t i = 0; i < haystack.size(); i++) {
if (haystack[i].frame_time == needle.frame_time)
return ::testing::AssertionSuccess();
failure << " [" << i << "]: " << haystack[i].frame_time << "\n";
}
}
return failure;
}
class LayerTreeHostTestBeginMainFrameTimeIsAlsoImplTime
: public LayerTreeHostTest {
public:
LayerTreeHostTestBeginMainFrameTimeIsAlsoImplTime()
: impl_frame_args_(), will_begin_impl_frame_count_(0) {}
void BeginTest() override {
// Test terminates when a main frame is no longer expected so request that
// this message is actually sent.
layer_tree_host()->RequestBeginMainFrameNotExpected(true);
// Kick off the test with a commit.
PostSetNeedsCommitToMainThread();
}
void WillBeginImplFrameOnThread(LayerTreeHostImpl* impl,
const viz::BeginFrameArgs& args,
bool has_damage) override {
impl_frame_args_.push_back(args);
will_begin_impl_frame_count_++;
if (will_begin_impl_frame_count_ < 10)
PostSetNeedsCommitToMainThread();
}
void BeginMainFrame(const viz::BeginFrameArgs& args) override {
ASSERT_GT(impl_frame_args_.size(), 0U)
<< "BeginMainFrame called before BeginImplFrame called!";
EXPECT_PRED_FORMAT2(AssertFrameTimeContained, impl_frame_args_, args);
}
void BeginMainFrameNotExpectedSoon() override { EndTest(); }
void AfterTest() override {
EXPECT_GT(impl_frame_args_.size(), 0U);
EXPECT_GE(will_begin_impl_frame_count_, 10);
}
private:
std::vector<viz::BeginFrameArgs> impl_frame_args_;
int will_begin_impl_frame_count_;
};
// TODO(mithro): Re-enable the multi-threaded version of this test
// http://crbug.com/537621
// SINGLE_AND_MULTI_THREAD_TEST_F(
// LayerTreeHostTestBeginMainFrameTimeIsAlsoImplTime);
SINGLE_THREAD_TEST_F(LayerTreeHostTestBeginMainFrameTimeIsAlsoImplTime);
class LayerTreeHostTestActivateOnInvisible : public LayerTreeHostTest {
public:
LayerTreeHostTestActivateOnInvisible()
: activation_count_(0), visible_(true) {}
void BeginTest() override {
// Kick off the test with a commit.
PostSetNeedsCommitToMainThread();
}
void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override {
// Make sure we don't activate using the notify signal from tile manager.
host_impl->BlockNotifyReadyToActivateForTesting(true);
}
void DidCommit() override { layer_tree_host()->SetVisible(false); }
void DidSetVisibleOnImplTree(LayerTreeHostImpl* host_impl,
bool visible) override {
visible_ = visible;
// Once invisible, we can go visible again.
if (!visible) {
PostSetVisibleToMainThread(true);
} else if (activation_count_) {
EXPECT_TRUE(host_impl->RequiresHighResToDraw());
EndTest();
}
}
void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
++activation_count_;
EXPECT_FALSE(visible_);
}
void AfterTest() override {
// Ensure we activated even though the signal was blocked.
EXPECT_EQ(1, activation_count_);
EXPECT_TRUE(visible_);
}
private:
int activation_count_;
bool visible_;
};
// TODO(vmpstr): Enable with single thread impl-side painting.
// This test blocks activation which is not supported for single thread mode.
MULTI_THREAD_BLOCKNOTIFY_TEST_F(LayerTreeHostTestActivateOnInvisible);
class LayerTreeHostTestRenderSurfaceEffectTreeIndex : public LayerTreeHostTest {
public:
LayerTreeHostTestRenderSurfaceEffectTreeIndex() = default;
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void SetupTree() override {
root_ = Layer::Create();
child_ = Layer::Create();
grand_child_ = Layer::Create();
layer_tree_host()->SetRootLayer(root_);
root_->AddChild(child_);
child_->AddChild(grand_child_);
root_->SetBounds(gfx::Size(50, 50));
child_->SetBounds(gfx::Size(50, 50));
grand_child_->SetBounds(gfx::Size(50, 50));
child_->SetForceRenderSurfaceForTesting(true);
grand_child_->SetForceRenderSurfaceForTesting(true);
LayerTreeHostTest::SetupTree();
}
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
if (host_impl->sync_tree()->source_frame_number() >= 1) {
LayerImpl* grand_child_impl =
host_impl->sync_tree()->LayerById(grand_child_->id());
EXPECT_EQ(grand_child_impl->effect_tree_index(),
GetRenderSurface(grand_child_impl)->EffectTreeIndex());
}
}
void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
LayerImpl* grand_child_impl =
host_impl->active_tree()->LayerById(grand_child_->id());
switch (host_impl->active_tree()->source_frame_number()) {
case 0:
PostSetNeedsCommitToMainThread();
break;
case 1:
case 2:
EXPECT_EQ(grand_child_impl->effect_tree_index(),
GetRenderSurface(grand_child_impl)->EffectTreeIndex());
PostSetNeedsCommitToMainThread();
break;
case 3:
EXPECT_EQ(grand_child_impl->effect_tree_index(),
GetRenderSurface(grand_child_impl)->EffectTreeIndex());
EndTest();
}
}
void DidCommit() override {
switch (layer_tree_host()->SourceFrameNumber()) {
case 2:
// Setting an empty viewport causes draws to get skipped, so the active
// tree won't update draw properties.
layer_tree_host()->SetViewportRectAndScale(gfx::Rect(), 1.f,
GetCurrentLocalSurfaceId());
child_->SetForceRenderSurfaceForTesting(false);
break;
case 3:
layer_tree_host()->SetViewportRectAndScale(
gfx::Rect(root_->bounds()), 1.f, GetCurrentLocalSurfaceId());
}
}
private:
scoped_refptr<Layer> root_;
scoped_refptr<Layer> child_;
scoped_refptr<Layer> grand_child_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestRenderSurfaceEffectTreeIndex);
// Do a synchronous composite and assert that the swap promise succeeds.
class LayerTreeHostTestSynchronousCompositeSwapPromise
: public LayerTreeHostTest {
public:
LayerTreeHostTestSynchronousCompositeSwapPromise() = default;
void InitializeSettings(LayerTreeSettings* settings) override {
settings->single_thread_proxy_scheduler = false;
settings->use_zero_copy = true;
}
std::unique_ptr<TestLayerTreeFrameSink> CreateLayerTreeFrameSink(
const viz::RendererSettings& renderer_settings,
double refresh_rate,
scoped_refptr<viz::RasterContextProvider> compositor_context_provider,
scoped_refptr<viz::RasterContextProvider> worker_context_provider)
override {
constexpr bool disable_display_vsync = false;
bool synchronous_composite =
!HasImplThread() &&
!layer_tree_host()->GetSettings().single_thread_proxy_scheduler;
return std::make_unique<TestLayerTreeFrameSink>(
compositor_context_provider, std::move(worker_context_provider),
gpu_memory_buffer_manager(), renderer_settings, &debug_settings_,
task_runner_provider(), synchronous_composite, disable_display_vsync,
refresh_rate);
}
void BeginTest() override {
// Successful composite.
const bool raster = true;
std::unique_ptr<SwapPromise> swap_promise0(
new TestSwapPromise(&swap_promise_result_[0]));
layer_tree_host()->GetSwapPromiseManager()->QueueSwapPromise(
std::move(swap_promise0));
layer_tree_host()->CompositeForTest(base::TimeTicks::Now(), raster,
base::OnceClosure());
// Fail to swap (no damage) if not reclaiming resources from the Display.
std::unique_ptr<SwapPromise> swap_promise1(
new TestSwapPromise(&swap_promise_result_[1]));
layer_tree_host()->GetSwapPromiseManager()->QueueSwapPromise(
std::move(swap_promise1));
layer_tree_host()->SetNeedsCommit();
layer_tree_host()->CompositeForTest(base::TimeTicks::Now(), raster,
base::OnceClosure());
// Fail to draw (not visible).
std::unique_ptr<SwapPromise> swap_promise2(
new TestSwapPromise(&swap_promise_result_[2]));
layer_tree_host()->GetSwapPromiseManager()->QueueSwapPromise(
std::move(swap_promise2));
layer_tree_host()->SetNeedsDisplayOnAllLayers();
layer_tree_host()->SetVisible(false);
layer_tree_host()->CompositeForTest(base::TimeTicks::Now(), raster,
base::OnceClosure());
EndTest();
}
void DidCommit() override {
commit_count_++;
ASSERT_LE(commit_count_, 3);
}
void AfterTest() override {
EXPECT_EQ(3, commit_count_);
// Initial swap promise should have succeded.
{
base::AutoLock lock(swap_promise_result_[0].lock);
EXPECT_TRUE(swap_promise_result_[0].did_swap_called);
EXPECT_FALSE(swap_promise_result_[0].did_not_swap_called);
EXPECT_TRUE(swap_promise_result_[0].dtor_called);
}
// Second swap promise fails to swap.
{
base::AutoLock lock(swap_promise_result_[1].lock);
EXPECT_TRUE(swap_promise_result_[1].did_activate_called);
EXPECT_FALSE(swap_promise_result_[1].did_swap_called);
EXPECT_TRUE(swap_promise_result_[1].did_not_swap_called);
EXPECT_EQ(SwapPromise::SWAP_FAILS, swap_promise_result_[1].reason);
EXPECT_TRUE(swap_promise_result_[1].dtor_called);
}
// Third swap promises also fails to swap (and draw).
{
base::AutoLock lock(swap_promise_result_[2].lock);
EXPECT_TRUE(swap_promise_result_[2].did_activate_called);
EXPECT_FALSE(swap_promise_result_[2].did_swap_called);
EXPECT_TRUE(swap_promise_result_[2].did_not_swap_called);
EXPECT_EQ(SwapPromise::SWAP_FAILS, swap_promise_result_[2].reason);
EXPECT_TRUE(swap_promise_result_[2].dtor_called);
}
}
int commit_count_ = 0;
TestSwapPromiseResult swap_promise_result_[3];
};
// Synchronous composite is a single-threaded only feature.
SINGLE_THREAD_TEST_F(LayerTreeHostTestSynchronousCompositeSwapPromise);
// Make sure page scale and top control deltas are applied to the client even
// when the LayerTreeHost doesn't have a root layer.
class LayerTreeHostAcceptsDeltasFromImplWithoutRootLayer
: public LayerTreeHostTest {
public:
LayerTreeHostAcceptsDeltasFromImplWithoutRootLayer()
: deltas_sent_to_client_(false) {}
void BeginTest() override {
layer_tree_host()->SetRootLayer(nullptr);
commit_data_.page_scale_delta = 3.14f;
commit_data_.top_controls_delta = 2.73f;
PostSetNeedsCommitToMainThread();
}
void BeginMainFrame(const viz::BeginFrameArgs& args) override {
EXPECT_EQ(nullptr, layer_tree_host()->root_layer());
layer_tree_host()->ApplyCompositorChanges(&commit_data_);
EndTest();
}
void ApplyViewportChanges(const ApplyViewportChangesArgs& args) override {
EXPECT_EQ(commit_data_.page_scale_delta, args.page_scale_delta);
EXPECT_EQ(commit_data_.top_controls_delta, args.top_controls_delta);
EXPECT_EQ(commit_data_.browser_controls_constraint,
args.browser_controls_constraint);
deltas_sent_to_client_ = true;
}
void AfterTest() override { EXPECT_TRUE(deltas_sent_to_client_); }
CompositorCommitData commit_data_;
bool deltas_sent_to_client_;
};
MULTI_THREAD_TEST_F(LayerTreeHostAcceptsDeltasFromImplWithoutRootLayer);
// Make sure we don't block waiting for commit to finish if there are no
// compositor changes to apply.
class NoOpApplyCompositorChangesDoesNotBlock : public LayerTreeHostTest {
public:
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void WillApplyCompositorChanges() override {
num_blocking_calls_ = NumCallsToWaitForProtectedSequenceCompletion();
}
void BeginMainFrame(const viz::BeginFrameArgs& args) override {
EXPECT_EQ(num_blocking_calls_,
NumCallsToWaitForProtectedSequenceCompletion());
EndTest();
}
size_t num_blocking_calls_ = 0u;
};
MULTI_THREAD_TEST_F(NoOpApplyCompositorChangesDoesNotBlock);
class LayerTreeHostTestCrispUpAfterPinchEnds : public LayerTreeHostTest {
protected:
LayerTreeHostTestCrispUpAfterPinchEnds()
: playback_allowed_event_(base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::SIGNALED) {
SetUseLayerLists();
}
void SetupTree() override {
frame_ = 1;
posted_ = false;
client_.set_fill_with_nonsolid_color(true);
SetInitialRootBounds(gfx::Size(500, 500));
LayerTreeHostTest::SetupTree();
Layer* root = layer_tree_host()->root_layer();
SetupViewport(root, root->bounds(), root->bounds());
scoped_refptr<FakePictureLayer> layer = FakePictureLayer::Create(&client_);
layer->set_playback_allowed_event(&playback_allowed_event_);
layer->SetBounds(gfx::Size(500, 500));
layer->SetContentsOpaque(true);
// Avoid LCD text on the layer so we don't cause extra commits when we
// pinch.
CopyProperties(layer_tree_host()->InnerViewportScrollLayerForTesting(),
layer.get());
root->AddChild(layer);
layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 1.f, 4.f);
client_.set_bounds(root->bounds());
}
// Returns the delta scale of all quads in the frame's root pass from their
// ideal, or 0 if they are not all the same.
float FrameQuadScaleDeltaFromIdeal(LayerTreeHostImpl::FrameData* frame_data) {
if (frame_data->has_no_damage)
return 0.f;
float frame_scale = 0.f;
viz::CompositorRenderPass* root_pass =
frame_data->render_passes.back().get();
for (auto* draw_quad : root_pass->quad_list) {
// Checkerboards mean an incomplete frame.
if (draw_quad->material != viz::DrawQuad::Material::kTiledContent)
return 0.f;
const viz::TileDrawQuad* quad =
viz::TileDrawQuad::MaterialCast(draw_quad);
float quad_scale =
quad->tex_coord_rect.width() / static_cast<float>(quad->rect.width());
float transform_scale = SkScalarToFloat(
quad->shared_quad_state->quad_to_target_transform.rc(0, 0));
float scale = quad_scale / transform_scale;
if (frame_scale != 0.f && frame_scale != scale)
return 0.f;
frame_scale = scale;
}
return frame_scale;
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
LayerTreeHostImpl::FrameData* frame_data,
DrawResult draw_result) override {
float quad_scale_delta = FrameQuadScaleDeltaFromIdeal(frame_data);
switch (frame_) {
case 1:
// Drew at page scale 1 before any pinching.
EXPECT_EQ(1.f, host_impl->active_tree()->current_page_scale_factor());
EXPECT_EQ(1.f, quad_scale_delta);
PostNextAfterDraw(host_impl);
break;
case 2:
if (quad_scale_delta != 1.f)
break;
// Drew at page scale 1.5 after pinching in.
EXPECT_EQ(1.5f, host_impl->active_tree()->current_page_scale_factor());
EXPECT_EQ(1.f, quad_scale_delta);
PostNextAfterDraw(host_impl);
break;
case 3:
// By pinching out, we will create a new tiling and raster it. This may
// cause some additional draws, though we should still be drawing with
// the old 1.5 tiling.
if (frame_data->has_no_damage)
break;
// Drew at page scale 1 with the 1.5 tiling while pinching out.
EXPECT_EQ(1.f, host_impl->active_tree()->current_page_scale_factor());
EXPECT_EQ(1.5f, quad_scale_delta);
// We don't PostNextAfterDraw here, instead we wait for the new tiling
// to finish rastering so we don't get any noise in further steps.
break;
case 4:
// Drew at page scale 1 with the 1.5 tiling after pinching out completed
// while waiting for texture uploads to complete.
EXPECT_EQ(1.f, host_impl->active_tree()->current_page_scale_factor());
// This frame will not have any damage, since it's actually the same as
// the last frame, and should contain no incomplete tiles. We just want
// to make sure we drew here at least once after the pinch ended to be
// sure that drawing after pinch doesn't leave us at the wrong scale
EXPECT_TRUE(frame_data->has_no_damage);
PostNextAfterDraw(host_impl);
break;
case 5:
if (quad_scale_delta != 1.f)
break;
// Drew at scale 1 after texture uploads are done.
EXPECT_EQ(1.f, host_impl->active_tree()->current_page_scale_factor());
EXPECT_EQ(1.f, quad_scale_delta);
EndTest();
break;
}
return draw_result;
}
void PostNextAfterDraw(LayerTreeHostImpl* host_impl) {
if (posted_)
return;
posted_ = true;
ImplThreadTaskRunner()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&LayerTreeHostTestCrispUpAfterPinchEnds::Next,
base::Unretained(this), host_impl),
// Use a delay to allow raster/upload to happen in between frames. This
// should cause flakiness if we fail to block raster/upload when
// desired.
base::Milliseconds(16 * 4));
}
void Next(LayerTreeHostImpl* host_impl) {
++frame_;
posted_ = false;
switch (frame_) {
case 2:
// Pinch zoom in.
host_impl->GetInputHandler().PinchGestureBegin(
gfx::Point(100, 100), ui::ScrollInputType::kWheel);
host_impl->GetInputHandler().PinchGestureUpdate(1.5f,
gfx::Point(100, 100));
host_impl->GetInputHandler().PinchGestureEnd(gfx::Point(100, 100));
break;
case 3:
// Pinch zoom back to 1.f but don't end it.
host_impl->GetInputHandler().PinchGestureBegin(
gfx::Point(100, 100), ui::ScrollInputType::kWheel);
host_impl->GetInputHandler().PinchGestureUpdate(1.f / 1.5f,
gfx::Point(100, 100));
break;
case 4:
// End the pinch, but delay tile production.
playback_allowed_event_.Reset();
host_impl->GetInputHandler().PinchGestureEnd(gfx::Point(100, 100));
break;
case 5:
// Let tiles complete.
playback_allowed_event_.Signal();
break;
}
}
void NotifyTileStateChangedOnThread(LayerTreeHostImpl* host_impl,
const Tile* tile) override {
if (frame_ == 3) {
// On frame 3, we will have a lower res tile complete for the pinch-out
// gesture even though it's not displayed. We wait for it here to prevent
// flakiness.
EXPECT_EQ(gfx::AxisTransform2d(0.75f, gfx::Vector2dF()),
tile->raster_transform());
PostNextAfterDraw(host_impl);
}
// On frame_ == 4, we are preventing texture uploads from completing,
// so this verifies they are not completing before frame_ == 5.
// Flaky failures here indicate we're failing to prevent uploads from
// completing.
EXPECT_NE(4, frame_) << tile->contents_scale_key();
}
FakeContentLayerClient client_;
int frame_;
bool posted_;
base::WaitableEvent playback_allowed_event_;
};
// This test does pinching on the impl side which is not supported in single
// thread.
MULTI_THREAD_TEST_F(LayerTreeHostTestCrispUpAfterPinchEnds);
class RasterizeWithGpuRasterizationCreatesResources : public LayerTreeHostTest {
protected:
void SetUpUnboundContextProviders(
viz::TestContextProvider* context_provider,
viz::TestContextProvider* worker_provider) override {
context_provider->UnboundTestRasterInterface()->set_gpu_rasterization(true);
worker_provider->UnboundTestRasterInterface()->set_gpu_rasterization(true);
}
void SetupTree() override {
client_.set_fill_with_nonsolid_color(true);
scoped_refptr<Layer> root = Layer::Create();
root->SetBounds(gfx::Size(500, 500));
client_.set_bounds(root->bounds());
scoped_refptr<FakePictureLayer> layer = FakePictureLayer::Create(&client_);
layer->SetBounds(gfx::Size(500, 500));
layer->SetContentsOpaque(true);
root->AddChild(layer);
layer_tree_host()->SetRootLayer(root);
LayerTreeHostTest::SetupTree();
client_.set_bounds(root->bounds());
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
LayerTreeHostImpl::FrameData* frame_data,
DrawResult draw_result) override {
EXPECT_NE(0u, host_impl->resource_pool()->resource_count());
EndTest();
return draw_result;
}
FakeContentLayerClient client_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(RasterizeWithGpuRasterizationCreatesResources);
class GpuRasterizationRasterizesBorderTiles : public LayerTreeHostTest {
protected:
GpuRasterizationRasterizesBorderTiles() : viewport_size_(1024, 2048) {}
void SetUpUnboundContextProviders(
viz::TestContextProvider* context_provider,
viz::TestContextProvider* worker_provider) override {
context_provider->UnboundTestRasterInterface()->set_gpu_rasterization(true);
worker_provider->UnboundTestRasterInterface()->set_gpu_rasterization(true);
}
void SetupTree() override {
client_.set_fill_with_nonsolid_color(true);
scoped_refptr<FakePictureLayer> root = FakePictureLayer::Create(&client_);
root->SetBounds(gfx::Size(10000, 10000));
client_.set_bounds(root->bounds());
root->SetContentsOpaque(true);
layer_tree_host()->SetRootLayer(root);
LayerTreeHostTest::SetupTree();
layer_tree_host()->SetViewportRectAndScale(gfx::Rect(viewport_size_), 1.f,
viz::LocalSurfaceId());
client_.set_bounds(root->bounds());
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
LayerTreeHostImpl::FrameData* frame_data,
DrawResult draw_result) override {
EXPECT_EQ(15u, host_impl->resource_pool()->resource_count());
EndTest();
return draw_result;
}
private:
FakeContentLayerClient client_;
gfx::Size viewport_size_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(GpuRasterizationRasterizesBorderTiles);
class LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles
: public LayerTreeHostTest {
protected:
LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles()
: playback_allowed_event_(base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::SIGNALED) {
SetUseLayerLists();
}
void SetupTree() override {
step_ = 1;
continuous_draws_ = 0;
client_.set_fill_with_nonsolid_color(true);
SetInitialRootBounds(gfx::Size(500, 500));
LayerTreeHostTest::SetupTree();
Layer* root = layer_tree_host()->root_layer();
SetupViewport(root, root->bounds(), root->bounds());
scoped_refptr<FakePictureLayer> layer = FakePictureLayer::Create(&client_);
layer->set_playback_allowed_event(&playback_allowed_event_);
layer->SetBounds(gfx::Size(500, 500));
layer->SetContentsOpaque(true);
CopyProperties(layer_tree_host()->InnerViewportScrollLayerForTesting(),
layer.get());
root->AddChild(layer);
layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 1.f, 4.f);
client_.set_bounds(root->bounds());
}
// Returns the delta scale of all quads in the frame's root pass from their
// ideal, or 0 if they are not all the same.
float FrameQuadScaleDeltaFromIdeal(LayerTreeHostImpl::FrameData* frame_data) {
if (frame_data->has_no_damage)
return 0.f;
float frame_scale = 0.f;
viz::CompositorRenderPass* root_pass =
frame_data->render_passes.back().get();
for (auto* draw_quad : root_pass->quad_list) {
const viz::TileDrawQuad* quad =
viz::TileDrawQuad::MaterialCast(draw_quad);
float quad_scale =
quad->tex_coord_rect.width() / static_cast<float>(quad->rect.width());
float transform_scale = SkScalarToFloat(
quad->shared_quad_state->quad_to_target_transform.rc(0, 0));
float scale = quad_scale / transform_scale;
if (frame_scale != 0.f && frame_scale != scale)
return 0.f;
frame_scale = scale;
}
return frame_scale;
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
LayerTreeHostImpl::FrameData* frame_data,
DrawResult draw_result) override {
float quad_scale_delta = FrameQuadScaleDeltaFromIdeal(frame_data);
switch (step_) {
case 1:
// Drew at scale 1 before any pinching.
EXPECT_EQ(1.f, host_impl->active_tree()->current_page_scale_factor());
EXPECT_EQ(1.f, quad_scale_delta);
break;
case 2:
if (quad_scale_delta != 1.f / 1.5f)
break;
// Drew at scale 1 still though the ideal is 1.5.
EXPECT_EQ(1.5f, host_impl->active_tree()->current_page_scale_factor());
EXPECT_EQ(1.f / 1.5f, quad_scale_delta);
break;
case 3:
// Continuous draws are attempted.
EXPECT_EQ(1.5f, host_impl->active_tree()->current_page_scale_factor());
if (!frame_data->has_no_damage)
EXPECT_EQ(1.f / 1.5f, quad_scale_delta);
break;
case 4:
if (quad_scale_delta != 1.f)
break;
// Drew at scale 1.5 when all the tiles completed.
EXPECT_EQ(1.5f, host_impl->active_tree()->current_page_scale_factor());
EXPECT_EQ(1.f, quad_scale_delta);
break;
case 5:
// TODO(danakj): We get more draws before the NotifyReadyToDraw
// because it is asynchronous from the previous draw and happens late.
break;
case 6:
// NotifyReadyToDraw happened. If we were already inside a frame, we may
// try to draw once more.
break;
case 7:
NOTREACHED() << "No draws should happen once we have a complete frame.";
}
return draw_result;
}
void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
switch (step_) {
case 1:
// Delay tile production.
playback_allowed_event_.Reset();
// Pinch zoom in to cause new tiles to be required.
host_impl->GetInputHandler().PinchGestureBegin(
gfx::Point(100, 100), ui::ScrollInputType::kWheel);
host_impl->GetInputHandler().PinchGestureUpdate(1.5f,
gfx::Point(100, 100));
host_impl->GetInputHandler().PinchGestureEnd(gfx::Point(100, 100));
++step_;
break;
case 2:
++step_;
break;
case 3:
// We should continue to try draw while there are incomplete visible
// tiles.
if (++continuous_draws_ > 5) {
// Allow the tiles to complete.
playback_allowed_event_.Signal();
++step_;
}
break;
case 4:
// NotifyReadyToDrawOnThread() is not called in multi threaded mode
EndTest();
break;
}
}
void NotifyTileStateChangedOnThread(LayerTreeHostImpl* host_impl,
const Tile* tile) override {
// On step_ == 2, we are preventing texture uploads from completing,
// so this verifies they are not completing before step_ == 3.
// Flaky failures here indicate we're failing to prevent uploads from
// completing.
EXPECT_NE(2, step_);
}
void AfterTest() override { EXPECT_GT(continuous_draws_, 5); }
FakeContentLayerClient client_;
int step_;
int continuous_draws_;
base::WaitableEvent playback_allowed_event_;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestContinuousDrawWhenCreatingVisibleTiles);
class LayerTreeHostTestOneActivatePerPrepareTiles : public LayerTreeHostTest {
public:
LayerTreeHostTestOneActivatePerPrepareTiles()
: notify_ready_to_activate_count_(0u),
scheduled_prepare_tiles_count_(0) {}
void SetupTree() override {
client_.set_fill_with_nonsolid_color(true);
scoped_refptr<FakePictureLayer> root_layer =
FakePictureLayer::Create(&client_);
root_layer->SetBounds(gfx::Size(1500, 1500));
root_layer->SetIsDrawable(true);
layer_tree_host()->SetRootLayer(root_layer);
LayerTreeHostTest::SetupTree();
client_.set_bounds(root_layer->bounds());
}
void BeginTest() override {
layer_tree_host()->SetViewportRectAndScale(gfx::Rect(16, 16), 1.f,
viz::LocalSurfaceId());
PostSetNeedsCommitToMainThread();
}
void InitializedRendererOnThread(LayerTreeHostImpl* host_impl,
bool success) override {
ASSERT_TRUE(success);
host_impl->tile_manager()->SetScheduledRasterTaskLimitForTesting(1);
}
void NotifyReadyToActivateOnThread(LayerTreeHostImpl* impl) override {
++notify_ready_to_activate_count_;
EndTestAfterDelayMs(100);
}
void WillPrepareTilesOnThread(LayerTreeHostImpl* impl) override {
++scheduled_prepare_tiles_count_;
}
void AfterTest() override {
// Expect at most a notification for each scheduled prepare tiles, plus one
// for the initial commit (which doesn't go through scheduled actions).
// The reason this is not an equality is because depending on timing, we
// might get a prepare tiles but not yet get a notification that we're
// ready to activate. The intent of a test is to ensure that we don't
// get more than one notification per prepare tiles, so this is OK.
EXPECT_LE(notify_ready_to_activate_count_,
1u + scheduled_prepare_tiles_count_);
}
protected:
FakeContentLayerClient client_;
size_t notify_ready_to_activate_count_;
size_t scheduled_prepare_tiles_count_;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestOneActivatePerPrepareTiles);
class LayerTreeHostTestActivationCausesPrepareTiles : public LayerTreeHostTest {
public:
LayerTreeHostTestActivationCausesPrepareTiles()
: scheduled_prepare_tiles_count_(0) {}
void SetupTree() override {
client_.set_fill_with_nonsolid_color(true);
scoped_refptr<FakePictureLayer> root_layer =
FakePictureLayer::Create(&client_);
root_layer->SetBounds(gfx::Size(150, 150));
root_layer->SetIsDrawable(true);
layer_tree_host()->SetRootLayer(root_layer);
LayerTreeHostTest::SetupTree();
client_.set_bounds(root_layer->bounds());
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void NotifyReadyToActivateOnThread(LayerTreeHostImpl* impl) override {
// Ensure we've already activated.
EXPECT_FALSE(impl->pending_tree());
// After activating, we either need to prepare tiles, or we've already
// called a scheduled prepare tiles. This is done because activation might
// cause us to have to memory available (old active tree is gone), so we
// need to ensure we will get a PrepareTiles call.
if (!impl->prepare_tiles_needed())
EXPECT_GE(scheduled_prepare_tiles_count_, 1);
EndTest();
}
void WillPrepareTilesOnThread(LayerTreeHostImpl* impl) override {
++scheduled_prepare_tiles_count_;
}
protected:
FakeContentLayerClient client_;
int scheduled_prepare_tiles_count_;
};
// This test is testing activation from a pending tree and doesn't make sense
// with single thread commit-to-active.
MULTI_THREAD_TEST_F(LayerTreeHostTestActivationCausesPrepareTiles);
// This tests an assertion that DidCommit and WillCommit happen in the same
// stack frame with no tasks that run between them. Various embedders of
// cc depend on this logic. ui::Compositor holds a compositor lock between
// these events and the inspector timeline wants begin/end CompositeLayers
// to be properly nested with other begin/end events.
class LayerTreeHostTestNoTasksBetweenWillAndDidCommit
: public LayerTreeHostTest {
public:
LayerTreeHostTestNoTasksBetweenWillAndDidCommit() : did_commit_(false) {}
void BeginTest() override {
// The entire purpose of Non-Blocking Commit is to allow the main thread to
// continue doing work while commit is running on the impl thread, making
// this test obsolete.
if (layer_tree_host()->IsThreaded()) {
DidCommit();
EndTest();
} else {
PostSetNeedsCommitToMainThread();
}
}
void WillCommit(const CommitState&) override {
MainThreadTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(&LayerTreeHostTestNoTasksBetweenWillAndDidCommit::
EndTestShouldRunAfterDidCommit,
base::Unretained(this)));
}
void EndTestShouldRunAfterDidCommit() {
EXPECT_TRUE(did_commit_);
EndTest();
}
void DidCommit() override {
EXPECT_FALSE(did_commit_);
did_commit_ = true;
}
void AfterTest() override { EXPECT_TRUE(did_commit_); }
private:
bool did_commit_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoTasksBetweenWillAndDidCommit);
class LayerTreeHostTestUpdateCopyRequests : public LayerTreeHostTest {
protected:
void SetupTree() override {
root = Layer::Create();
child = Layer::Create();
root->AddChild(child);
layer_tree_host()->SetRootLayer(root);
LayerTreeHostTest::SetupTree();
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void WillCommit(const CommitState& commit_state) override {
switch (commit_state.source_frame_number) {
case 1:
EXPECT_TRUE(LayerSubtreeHasCopyRequest(root.get()));
break;
}
}
void DidCommit() override {
gfx::Transform transform;
switch (layer_tree_host()->SourceFrameNumber()) {
case 1:
child->RequestCopyOfOutput(
viz::CopyOutputRequest::CreateStubForTesting());
transform.Scale(2.0, 2.0);
child->SetTransform(transform);
break;
case 2:
// By changing the scale of a layer which already owns a transform node,
// a commit will be triggered but a property tree rebuild will not, this
// is used to test sure that clearing copy requestts does trigger a
// rebuild whenever next commit happens.
transform.Scale(1.5, 1.5);
child->SetTransform(transform);
break;
case 3:
EXPECT_FALSE(LayerSubtreeHasCopyRequest(root.get()));
EndTest();
break;
}
}
private:
scoped_refptr<Layer> root;
scoped_refptr<Layer> child;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestUpdateCopyRequests);
class LayerTreeTestPageScaleFlags : public LayerTreeTest {
public:
LayerTreeTestPageScaleFlags() { SetUseLayerLists(); }
protected:
void SetupTree() override {
// -root
// -pre page scale
// -viewport layers
// -post page scale
LayerTreeTest::SetupTree();
Layer* root = layer_tree_host()->root_layer();
scoped_refptr<Layer> pre_page_scale = Layer::Create();
CopyProperties(root, pre_page_scale.get());
root->AddChild(pre_page_scale);
SetupViewport(root, root->bounds(), root->bounds());
scoped_refptr<Layer> post_page_scale = Layer::Create();
CopyProperties(root, post_page_scale.get());
root->AddChild(post_page_scale);
affected_by_page_scale_.push_back(
layer_tree_host()->InnerViewportScrollLayerForTesting()->id());
affected_by_page_scale_.push_back(
layer_tree_host()->OuterViewportScrollLayerForTesting()->id());
not_affected_by_page_scale_.push_back(root->id());
not_affected_by_page_scale_.push_back(pre_page_scale->id());
not_affected_by_page_scale_.push_back(post_page_scale->id());
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
for (auto* layer : *host_impl->sync_tree()) {
const std::vector<int>& list = layer->IsAffectedByPageScale()
? this->affected_by_page_scale_
: this->not_affected_by_page_scale_;
EXPECT_TRUE(base::Contains(list, layer->id()));
}
EndTest();
}
std::vector<int> affected_by_page_scale_;
std::vector<int> not_affected_by_page_scale_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeTestPageScaleFlags);
class LayerTreeHostTestDestroyWhileInitializingOutputSurface
: public LayerTreeHostTest {
protected:
void BeginTest() override {
// By ending the test immediately we start initialization of an output
// surface but destroy the LTH before it completes. This test verifies
// that this works correctly and the output surface is destroyed on
// the correct thread.
EndTest();
}
};
MULTI_THREAD_TEST_F(LayerTreeHostTestDestroyWhileInitializingOutputSurface);
// Makes sure that painted_device_scale_factor is propagated to the
// frame's metadata.
class LayerTreeHostTestPaintedDeviceScaleFactor : public LayerTreeHostTest {
protected:
void InitializeSettings(LayerTreeSettings* settings) override {
settings->use_painted_device_scale_factor = true;
LayerTreeHostTest::InitializeSettings(settings);
}
void SetupTree() override {
SetInitialDeviceScaleFactor(2.f);
LayerTreeHostTest::SetupTree();
}
void BeginTest() override {
EXPECT_EQ(1.0f, layer_tree_host()->device_scale_factor());
PostSetNeedsCommitToMainThread();
}
DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
LayerTreeHostImpl::FrameData* frame_data,
DrawResult draw_result) override {
EXPECT_EQ(DrawResult::kSuccess, draw_result);
EXPECT_EQ(2.0f, host_impl->active_tree()->painted_device_scale_factor());
EXPECT_EQ(1.0f, host_impl->active_tree()->device_scale_factor());
return draw_result;
}
void DisplayReceivedCompositorFrameOnThread(
const viz::CompositorFrame& frame) override {
EXPECT_EQ(2.0f, frame.metadata.device_scale_factor);
EndTest();
}
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPaintedDeviceScaleFactor);
// Tests that a presentation-timestamps are received for a frame.
class LayerTreeHostTestPresentationTime : public LayerTreeHostTest {
protected:
void BeginTest() override {
PostSetNeedsCommitToMainThread();
}
void DisplayReceivedCompositorFrameOnThread(
const viz::CompositorFrame& frame) override {
frame_token_ = frame.metadata.frame_token;
}
void DidReceivePresentationTimeOnThread(
LayerTreeHostImpl* host_impl,
uint32_t frame_token,
const gfx::PresentationFeedback& feedback) override {
EXPECT_EQ(frame_token_, frame_token);
EndTest();
}
void AfterTest() override { ASSERT_GT(frame_token_, 0u); }
private:
uint32_t frame_token_ = 0;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPresentationTime);
// Makes sure that viz::LocalSurfaceId is propagated to the LayerTreeFrameSink.
class LayerTreeHostTestLocalSurfaceId : public LayerTreeHostTest {
protected:
void BeginTest() override {}
DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
LayerTreeHostImpl::FrameData* frame_data,
DrawResult draw_result) override {
EXPECT_EQ(DrawResult::kSuccess, draw_result);
EXPECT_EQ(GetCurrentLocalSurfaceId(),
host_impl->active_tree()->local_surface_id_from_parent());
return draw_result;
}
void DisplayReceivedLocalSurfaceIdOnThread(
const viz::LocalSurfaceId& local_surface_id) override {
EXPECT_EQ(GetCurrentLocalSurfaceId(), local_surface_id);
EndTest();
}
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLocalSurfaceId);
// Makes sure that LayerTreeHost does not pick up changes to
// viz::LocalSurfaceIds that only involve the child sequence number.
class LayerTreeHostTestLocalSurfaceIdSkipChildNum : public LayerTreeHostTest {
protected:
void BeginTest() override {
EXPECT_TRUE(child_allocator_.UpdateFromParent(GetCurrentLocalSurfaceId()));
}
DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
LayerTreeHostImpl::FrameData* frame_data,
DrawResult draw_result) override {
EXPECT_EQ(DrawResult::kSuccess, draw_result);
// We should not be picking up the newer |child_local_surface_id_|.
EXPECT_EQ(GetCurrentLocalSurfaceId(),
host_impl->active_tree()->local_surface_id_from_parent());
// This initial test setup triggers a commit and subsequent draw. Upon the
// first draw, enqueue the second portion of the test. The newly pushed id,
// with an advanced child sequence number, but no change in parent sequence,
// should not trigger a commit. If it does, then PrepareToDrawOnThread will
// be called a second time, and the expectation upon viz::LocalSurfaceId
// will fail. We do not assert on frame number, as that interferes with
// returning from this method. We do not just have an expectation either,
// as then we would continuously increment that child sequence until the
// test times out.
if (!host_impl->active_tree()->source_frame_number()) {
child_allocator_.GenerateId();
child_local_surface_id_ = child_allocator_.GetCurrentLocalSurfaceId();
EXPECT_NE(GetCurrentLocalSurfaceId(), child_local_surface_id_);
PostSetLocalSurfaceIdToMainThread(child_local_surface_id_);
}
return draw_result;
}
void DisplayReceivedLocalSurfaceIdOnThread(
const viz::LocalSurfaceId& local_surface_id) override {
EXPECT_EQ(GetCurrentLocalSurfaceId(), local_surface_id);
EndTest();
}
viz::LocalSurfaceId child_local_surface_id_;
viz::ChildLocalSurfaceIdAllocator child_allocator_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLocalSurfaceIdSkipChildNum);
// Makes sure that viz::LocalSurfaceId allocation requests propagate all the way
// to LayerTreeFrameSink.
class LayerTreeHostTestRequestNewLocalSurfaceId : public LayerTreeHostTest {
protected:
void BeginTest() override {
PostRequestNewLocalSurfaceIdToMainThread();
}
DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
LayerTreeHostImpl::FrameData* frame_data,
DrawResult draw_result) override {
EXPECT_EQ(DrawResult::kSuccess, draw_result);
EXPECT_EQ(GetCurrentLocalSurfaceId(),
host_impl->active_tree()->local_surface_id_from_parent());
return draw_result;
}
void DisplayReceivedLocalSurfaceIdOnThread(
const viz::LocalSurfaceId& local_surface_id) override {
const viz::LocalSurfaceId& expected_parent_local_surface_id =
GetCurrentLocalSurfaceId();
viz::LocalSurfaceId child_local_surface_id(
expected_parent_local_surface_id.parent_sequence_number(),
expected_parent_local_surface_id.child_sequence_number() + 1,
expected_parent_local_surface_id.embed_token());
EXPECT_NE(expected_parent_local_surface_id, local_surface_id);
EXPECT_EQ(child_local_surface_id, local_surface_id);
}
// This gets called after DispllayReceivedLocalSurfaceIdOnThread.
void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
// Verify that the request bit doesn't stick after we submit a frame.
EXPECT_FALSE(
host_impl->active_tree()->new_local_surface_id_request_for_testing());
EndTest();
}
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestRequestNewLocalSurfaceId);
// The GPU image decode controller hands images off to Skia for rasterization.
// When used with large images, the images in question could be deleted before
// Skia was done with them, causing a crash. This test performs an end-to-end
// check of large image rasterization to ensure we do not hit this crash.
// Note that this code path won't always hit the crash, even when incorrect
// behavior occurs, so this is more of a sanity check.
// TODO(ericrk): We should improve this so that we can reliably detect the
// crash.
class GpuRasterizationSucceedsWithLargeImage : public LayerTreeHostTest {
protected:
GpuRasterizationSucceedsWithLargeImage()
: viewport_size_(1024, 2048), large_image_size_(20000, 10) {}
void SetUpUnboundContextProviders(
viz::TestContextProvider* context_provider,
viz::TestContextProvider* worker_provider) override {
context_provider->UnboundTestRasterInterface()->set_gpu_rasterization(true);
worker_provider->UnboundTestRasterInterface()->set_gpu_rasterization(true);
}
void InitializeSettings(LayerTreeSettings* settings) override {
// Set to 0 to force at-raster GPU image decode.
settings->decoded_image_working_set_budget_bytes = 0;
}
void SetupTree() override {
client_.set_fill_with_nonsolid_color(true);
client_.add_draw_image(CreateDiscardablePaintImage(large_image_size_),
gfx::Point(0, 0));
scoped_refptr<FakePictureLayer> root = FakePictureLayer::Create(&client_);
root->SetBounds(gfx::Size(10000, 10000));
client_.set_bounds(root->bounds());
root->SetContentsOpaque(true);
layer_tree_host()->SetRootLayer(root);
LayerTreeHostTest::SetupTree();
layer_tree_host()->SetViewportRectAndScale(gfx::Rect(viewport_size_), 1.f,
viz::LocalSurfaceId());
client_.set_bounds(root->bounds());
}
void InitializedRendererOnThread(LayerTreeHostImpl* host_impl,
bool success) override {
// Check that our large_image_size_ is greater than max texture size. We do
// this here to ensure that our otuput surface exists.
// Retrieve max texture size from Skia.
viz::RasterContextProvider* context_provider =
host_impl->layer_tree_frame_sink()->context_provider();
ASSERT_TRUE(context_provider);
const uint32_t max_texture_size =
context_provider->ContextCapabilities().max_texture_size;
ASSERT_GT(static_cast<uint32_t>(large_image_size_.width()),
max_texture_size);
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DidCommit() override { EndTest(); }
private:
FakeContentLayerClient client_;
const gfx::Size viewport_size_;
const gfx::Size large_image_size_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(GpuRasterizationSucceedsWithLargeImage);
class LayerTreeHostTestSubmitFrameMetadata : public LayerTreeHostTest {
protected:
void BeginTest() override {
layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 0.5f, 4.f);
PostSetNeedsCommitToMainThread();
}
DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
LayerTreeHostImpl::FrameData* frame_data,
DrawResult draw_result) override {
EXPECT_EQ(DrawResult::kSuccess, draw_result);
EXPECT_EQ(0, num_swaps_);
drawn_viewport_ = host_impl->active_tree()->GetDeviceViewport();
return draw_result;
}
void DisplayReceivedCompositorFrameOnThread(
const viz::CompositorFrame& frame) override {
EXPECT_EQ(1, ++num_swaps_);
EXPECT_EQ(drawn_viewport_, frame.render_pass_list.back()->output_rect);
EXPECT_EQ(0.5f, frame.metadata.min_page_scale_factor);
EXPECT_EQ(0u, frame.resource_list.size());
EXPECT_EQ(1u, frame.render_pass_list.size());
EndTest();
}
int num_swaps_ = 0;
gfx::Rect drawn_viewport_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSubmitFrameMetadata);
class LayerTreeHostTestSubmitFrameResources : public LayerTreeHostTest {
protected:
std::unique_ptr<TestLayerTreeFrameSink> CreateLayerTreeFrameSink(
const viz::RendererSettings& renderer_settings,
double refresh_rate,
scoped_refptr<viz::RasterContextProvider> compositor_context_provider,
scoped_refptr<viz::RasterContextProvider> worker_context_provider)
override {
return LayerTreeTest::CreateLayerTreeFrameSink(
renderer_settings, refresh_rate, std::move(compositor_context_provider),
std::move(worker_context_provider));
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
LayerTreeHostImpl::FrameData* frame,
DrawResult draw_result) override {
frame->render_passes.clear();
viz::CompositorRenderPass* child_pass = AddRenderPass(
&frame->render_passes, viz::CompositorRenderPassId{2},
gfx::Rect(3, 3, 100, 100), gfx::Transform(), FilterOperations());
std::vector<viz::ResourceId> child_resources =
AddOneOfEveryQuadType(child_pass, host_impl->resource_provider(),
viz::CompositorRenderPassId{0});
viz::CompositorRenderPass* pass = AddRenderPass(
&frame->render_passes, viz::CompositorRenderPassId{1},
gfx::Rect(3, 3, 100, 100), gfx::Transform(), FilterOperations());
std::vector<viz::ResourceId> root_resources = AddOneOfEveryQuadType(
pass, host_impl->resource_provider(), child_pass->id);
auto append = [](std::vector<viz::ResourceId>* to,
std::vector<viz::ResourceId> from) {
to->insert(to->end(), from.begin(), from.end());
};
append(&resources_, child_resources);
append(&resources_, root_resources);
return draw_result;
}
void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
// The resources have been submitted to the display compositor by now, we
// can remove them from cc now, so that they are not leaked.
for (viz::ResourceId id : resources_)
host_impl->resource_provider()->RemoveImportedResource(id);
}
void DisplayReceivedCompositorFrameOnThread(
const viz::CompositorFrame& frame) override {
EXPECT_EQ(2u, frame.render_pass_list.size());
// Each render pass has 6 resources in it. And the root render pass has a
// mask resource used when drawing the child render pass. The number 6 may
// change if AppendOneOfEveryQuadType() is updated, and the value here
// should be updated accordingly.
EXPECT_EQ(13u, frame.resource_list.size());
EndTest();
}
std::vector<viz::ResourceId> resources_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSubmitFrameResources);
class LayerTreeHostTestBeginFrameAcks : public LayerTreeHostTest {
protected:
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void WillBeginImplFrameOnThread(LayerTreeHostImpl* impl,
const viz::BeginFrameArgs& args,
bool has_damage) override {
EXPECT_TRUE(args.IsValid());
current_begin_frame_args_ = args;
}
DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* impl,
LayerTreeHostImpl::FrameData* frame_data,
DrawResult draw_result) override {
frame_data_ = frame_data;
return draw_result;
}
void DisplayReceivedCompositorFrameOnThread(
const viz::CompositorFrame& frame) override {
if (compositor_frame_submitted_)
return;
compositor_frame_submitted_ = true;
EXPECT_EQ(viz::BeginFrameAck(current_begin_frame_args_, true),
frame.metadata.begin_frame_ack);
}
void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
if (layers_drawn_)
return;
layers_drawn_ = true;
EXPECT_TRUE(frame_data_);
EXPECT_TRUE(compositor_frame_submitted_);
EXPECT_EQ(viz::BeginFrameAck(current_begin_frame_args_, true),
frame_data_->begin_frame_ack);
EndTest();
}
void AfterTest() override { EXPECT_TRUE(layers_drawn_); }
private:
bool compositor_frame_submitted_ = false;
bool layers_drawn_ = false;
viz::BeginFrameArgs current_begin_frame_args_;
raw_ptr<LayerTreeHostImpl::FrameData> frame_data_;
};
MULTI_THREAD_BLOCKNOTIFY_TEST_F(LayerTreeHostTestBeginFrameAcks);
class LayerTreeHostTestQueueImageDecode : public LayerTreeHostTest {
protected:
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void InitializeSettings(LayerTreeSettings* settings) override {
settings->enable_checker_imaging = true;
settings->min_image_bytes_to_checker = 512 * 1024;
}
void WillBeginMainFrame() override {
if (!first_)
return;
first_ = false;
image_ =
DrawImage(CreateDiscardablePaintImage(gfx::Size(400, 400)), false,
SkIRect::MakeWH(400, 400), PaintFlags::FilterQuality::kNone,
SkM44(), PaintImage::kDefaultFrameIndex, TargetColorParams());
auto callback = base::BindRepeating(
&LayerTreeHostTestQueueImageDecode::ImageDecodeFinished,
base::Unretained(this));
// Schedule the decode twice for the same image.
layer_tree_host()->QueueImageDecode(image_.paint_image(), callback);
layer_tree_host()->QueueImageDecode(image_.paint_image(), callback);
}
void ReadyToCommitOnThread(LayerTreeHostImpl* impl) override {
if (one_commit_done_)
return;
EXPECT_FALSE(
impl->tile_manager()->checker_image_tracker().ShouldCheckerImage(
image_, WhichTree::PENDING_TREE));
}
void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
one_commit_done_ = true;
EXPECT_FALSE(
impl->tile_manager()->checker_image_tracker().ShouldCheckerImage(
image_, WhichTree::PENDING_TREE));
}
void ImageDecodeFinished(bool decode_succeeded) {
EXPECT_TRUE(decode_succeeded);
++finished_decode_count_;
EXPECT_LE(finished_decode_count_, 2);
if (finished_decode_count_ == 2)
EndTest();
}
private:
bool first_ = true;
bool one_commit_done_ = false;
int finished_decode_count_ = 0;
DrawImage image_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestQueueImageDecode);
class LayerTreeHostTestQueueImageDecodeNonLazy : public LayerTreeHostTest {
protected:
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void WillBeginMainFrame() override {
if (!first_)
return;
first_ = false;
bitmap_.allocN32Pixels(10, 10);
PaintImage image = PaintImageBuilder::WithDefault()
.set_id(PaintImage::GetNextId())
.set_image(SkImages::RasterFromBitmap(bitmap_),
PaintImage::GetNextContentId())
.TakePaintImage();
auto callback = base::BindOnce(
&LayerTreeHostTestQueueImageDecodeNonLazy::ImageDecodeFinished,
base::Unretained(this));
layer_tree_host()->QueueImageDecode(image, std::move(callback));
}
void ImageDecodeFinished(bool decode_succeeded) {
EXPECT_TRUE(decode_succeeded);
EndTest();
}
private:
bool first_ = true;
SkBitmap bitmap_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestQueueImageDecodeNonLazy);
class LayerTreeHostTestHudLayerWithLayerLists : public LayerTreeHostTest {
public:
LayerTreeHostTestHudLayerWithLayerLists() { SetUseLayerLists(); }
void InitializeSettings(LayerTreeSettings* settings) override {
settings->initial_debug_state.show_paint_rects = true;
}
void BeginTest() override {
// The HUD layer should not have been setup.
DCHECK_EQ(layer_tree_host()->hud_layer(), nullptr);
PostSetNeedsCommitToMainThread();
}
void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { EndTest(); }
void DidCommit() override {
auto* hud = layer_tree_host()->hud_layer();
DCHECK(hud);
auto* root_layer = layer_tree_host()->root_layer();
DCHECK_EQ(hud->transform_tree_index(), root_layer->transform_tree_index());
DCHECK_EQ(hud->clip_tree_index(), root_layer->clip_tree_index());
DCHECK_EQ(hud->effect_tree_index(), root_layer->effect_tree_index());
DCHECK_EQ(hud->scroll_tree_index(), root_layer->scroll_tree_index());
}
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestHudLayerWithLayerLists);
class LayerTreeHostTestImageAnimation : public LayerTreeHostTest {
public:
explicit LayerTreeHostTestImageAnimation(
viz::RendererType type = kDefaultRendererType)
: LayerTreeHostTest(type) {}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
virtual void AddImageOp(const PaintImage& image) = 0;
void SetupTree() override {
gfx::Size layer_size(1000, 500);
content_layer_client_.set_bounds(layer_size);
content_layer_client_.set_fill_with_nonsolid_color(true);
std::vector<FrameMetadata> frames = {FrameMetadata(true, base::Seconds(1)),
FrameMetadata(true, base::Seconds(1)),
FrameMetadata(true, base::Seconds(1))};
generator_ = sk_make_sp<FakePaintImageGenerator>(
SkImageInfo::MakeN32Premul(500, 500, SkColorSpace::MakeSRGB()), frames);
PaintImage image =
PaintImageBuilder::WithDefault()
.set_id(PaintImage::GetNextId())
.set_paint_image_generator(generator_)
.set_animation_type(PaintImage::AnimationType::kAnimated)
.set_repetition_count(kAnimationLoopOnce)
.TakePaintImage();
AddImageOp(image);
layer_tree_host()->SetRootLayer(
FakePictureLayer::Create(&content_layer_client_));
layer_tree_host()->root_layer()->SetBounds(layer_size);
LayerTreeTest::SetupTree();
}
void WillPrepareToDrawOnThread(LayerTreeHostImpl* host_impl) override {
gfx::Rect image_rect(-1, -1, 502, 502);
auto* layer =
static_cast<PictureLayerImpl*>(host_impl->active_tree()->root_layer());
switch (++draw_count_) {
case 1:
// First draw, everything is invalid. layer->update_rect() doesn't
// matter because a new layer always causes surface damage.
EXPECT_EQ(layer->InvalidationForTesting().bounds(),
gfx::Rect(layer->bounds()));
EXPECT_EQ(generator_->frames_decoded().size(), 1u);
EXPECT_EQ(generator_->frames_decoded().count(0u), 1u);
break;
case 2:
// Every frame after the first one should invalidate only the image.
EXPECT_EQ(layer->InvalidationForTesting().bounds(), image_rect);
EXPECT_EQ(layer->update_rect(), image_rect);
EXPECT_EQ(generator_->frames_decoded().size(), 2u);
EXPECT_EQ(generator_->frames_decoded().count(1u), 1u);
EXPECT_EQ(layer->GetDamageReasons(),
DamageReasonSet{DamageReason::kAnimatedImage});
break;
case 3:
EXPECT_EQ(layer->InvalidationForTesting().bounds(), image_rect);
EXPECT_EQ(layer->update_rect(), image_rect);
EXPECT_EQ(generator_->frames_decoded().size(), 3u);
EXPECT_EQ(generator_->frames_decoded().count(2u), 1u);
EXPECT_EQ(layer->GetDamageReasons(),
DamageReasonSet{DamageReason::kAnimatedImage});
break;
default:
// Only 3 draws should happen for 3 frames of the animate image.
NOTREACHED();
}
if (draw_count_ == 3)
EndTest();
}
void WillSubmitCompositorFrame(LayerTreeHostImpl* host_impl,
const viz::CompositorFrame& frame) override {
const viz::FrameIntervalInputs& inputs =
frame.metadata.frame_interval_inputs;
// `draw_count_` matches `WillPrepareToDrawOnThread`
switch (draw_count_) {
case 1:
// Very first frame is set directly, without calling
// PictureLayerImpl::InvalidateRegionForImages.
EXPECT_FALSE(inputs.has_only_content_frame_interval_updates);
break;
case 2:
// Second frame contains damage from animating image only.
ASSERT_EQ(inputs.content_interval_info.size(), 1u);
EXPECT_EQ(inputs.content_interval_info[0].type,
viz::ContentFrameIntervalType::kAnimatingImage);
EXPECT_EQ(inputs.content_interval_info[0].frame_interval,
base::Seconds(1));
EXPECT_TRUE(inputs.has_only_content_frame_interval_updates);
break;
case 3:
// Because the image isn't repeating, it's no longer considered
// animating at the very last frame.
EXPECT_FALSE(inputs.has_only_content_frame_interval_updates);
break;
default:
NOTREACHED();
}
}
void AfterTest() override {
EXPECT_EQ(generator_->frames_decoded().size(), 3u);
}
protected:
FakeContentLayerClient content_layer_client_;
sk_sp<FakePaintImageGenerator> generator_;
int draw_count_ = 0;
};
class LayerTreeHostTestImageAnimationDrawImage
: public LayerTreeHostTestImageAnimation {
public:
explicit LayerTreeHostTestImageAnimationDrawImage(
viz::RendererType type = kDefaultRendererType)
: LayerTreeHostTestImageAnimation(type) {}
private:
void AddImageOp(const PaintImage& image) override {
content_layer_client_.add_draw_image(image, gfx::Point(0, 0));
}
};
MULTI_THREAD_TEST_F(LayerTreeHostTestImageAnimationDrawImage);
class LayerTreeHostTestImageAnimationDrawImageShader
: public LayerTreeHostTestImageAnimation {
void AddImageOp(const PaintImage& image) override {
PaintFlags flags;
flags.setShader(PaintShader::MakeImage(image, SkTileMode::kRepeat,
SkTileMode::kRepeat, nullptr));
content_layer_client_.add_draw_rect(gfx::Rect(500, 500), flags);
}
};
MULTI_THREAD_TEST_F(LayerTreeHostTestImageAnimationDrawImageShader);
class LayerTreeHostTestImageAnimationDrawRecordShader
: public LayerTreeHostTestImageAnimation {
void AddImageOp(const PaintImage& image) override {
PaintOpBuffer buffer;
buffer.push<DrawImageOp>(image, 0.f, 0.f);
PaintFlags flags;
flags.setShader(PaintShader::MakePaintRecord(
buffer.ReleaseAsRecord(), SkRect::MakeWH(500, 500), SkTileMode::kClamp,
SkTileMode::kClamp, nullptr));
content_layer_client_.add_draw_rect(gfx::Rect(500, 500), flags);
}
};
MULTI_THREAD_TEST_F(LayerTreeHostTestImageAnimationDrawRecordShader);
class LayerTreeHostTestImageAnimationPaintFilter
: public LayerTreeHostTestImageAnimation {
void AddImageOp(const PaintImage& image) override {
PaintOpBuffer buffer;
buffer.push<DrawImageOp>(image, 0.f, 0.f);
PaintFlags flags;
flags.setImageFilter(sk_make_sp<RecordPaintFilter>(
buffer.ReleaseAsRecord(), SkRect::MakeWH(500, 500)));
content_layer_client_.add_draw_rect(gfx::Rect(500, 500), flags);
}
};
MULTI_THREAD_TEST_F(LayerTreeHostTestImageAnimationPaintFilter);
class LayerTreeHostTestImageAnimationSynchronousScheduling
: public LayerTreeHostTestImageAnimationDrawImage {
public:
explicit LayerTreeHostTestImageAnimationSynchronousScheduling(
viz::RendererType type = kDefaultRendererType)
: LayerTreeHostTestImageAnimationDrawImage(type) {}
void InitializeSettings(LayerTreeSettings* settings) override {
LayerTreeHostTestImageAnimation::InitializeSettings(settings);
settings->using_synchronous_renderer_compositor = true;
}
};
MULTI_THREAD_TEST_F(LayerTreeHostTestImageAnimationSynchronousScheduling);
class LayerTreeHostTestImageAnimationSynchronousSchedulingSoftwareDraw
: public LayerTreeHostTestImageAnimationSynchronousScheduling {
public:
LayerTreeHostTestImageAnimationSynchronousSchedulingSoftwareDraw()
: LayerTreeHostTestImageAnimationSynchronousScheduling(
viz::RendererType::kSoftware) {}
void AfterTest() override {
LayerTreeHostTestImageAnimationSynchronousScheduling::AfterTest();
// 3 frames decoded twice, once during tile raster and once during raster
// for PictureDrawQuad.
for (size_t i = 0u; i < 3u; ++i) {
EXPECT_EQ(generator_->frames_decoded().find(i)->second, 2);
}
}
};
// TODO(crbug.com/40698130): Flaky on TSan bot.
// MULTI_THREAD_TEST_F(
// LayerTreeHostTestImageAnimationSynchronousSchedulingSoftwareDraw);
class LayerTreeHostTestImageDecodingHints : public LayerTreeHostTest {
public:
void InitializeSettings(LayerTreeSettings* settings) override {
LayerTreeHostTest::InitializeSettings(settings);
settings->enable_checker_imaging = true;
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void SetupTree() override {
gfx::Size layer_size(100, 100);
content_layer_client_.set_bounds(layer_size);
content_layer_client_.set_fill_with_nonsolid_color(true);
PaintImage async_image =
PaintImageBuilder::WithCopy(
CreateDiscardablePaintImage(gfx::Size(10, 10)))
.set_id(1)
.set_decoding_mode(PaintImage::DecodingMode::kAsync)
.TakePaintImage();
PaintImage sync_image =
PaintImageBuilder::WithCopy(
CreateDiscardablePaintImage(gfx::Size(10, 10)))
.set_id(2)
.set_decoding_mode(PaintImage::DecodingMode::kSync)
.TakePaintImage();
PaintImage unspecified_image =
PaintImageBuilder::WithCopy(
CreateDiscardablePaintImage(gfx::Size(10, 10)))
.set_id(3)
.set_decoding_mode(PaintImage::DecodingMode::kUnspecified)
.TakePaintImage();
content_layer_client_.add_draw_image(async_image, gfx::Point(0, 0));
content_layer_client_.add_draw_image(sync_image, gfx::Point(1, 2));
content_layer_client_.add_draw_image(unspecified_image, gfx::Point(3, 4));
layer_tree_host()->SetRootLayer(
FakePictureLayer::Create(&content_layer_client_));
layer_tree_host()->root_layer()->SetBounds(layer_size);
LayerTreeTest::SetupTree();
}
void WillPrepareToDrawOnThread(LayerTreeHostImpl* host_impl) override {
auto& tracker = host_impl->tile_manager()->checker_image_tracker();
EXPECT_EQ(tracker.get_decoding_mode_hint_for_testing(1),
PaintImage::DecodingMode::kAsync);
EXPECT_EQ(tracker.get_decoding_mode_hint_for_testing(2),
PaintImage::DecodingMode::kSync);
EXPECT_EQ(tracker.get_decoding_mode_hint_for_testing(3),
PaintImage::DecodingMode::kUnspecified);
EndTest();
}
private:
FakeContentLayerClient content_layer_client_;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestImageDecodingHints);
class DontUpdateLayersWithEmptyBounds : public LayerTreeTest {
protected:
void SetupTree() override {
auto root = FakePictureLayer::Create(&root_client_);
child_ = FakePictureLayer::Create(&child_client_);
mask_ = FakePictureLayer::Create(&mask_client_);
// Add a lot of draw ops, to make sure the recording source
// hits the early out and avoids being detected as solid color even
// though it is empty. This ensures we hit later code paths that would
// early out if solid color in CanHaveTilings().
PaintFlags flags;
flags.setColor(SK_ColorRED);
for (int i = 0; i < 100; ++i) {
child_client_.add_draw_rect(gfx::Rect(3, 3), flags);
mask_client_.add_draw_rect(gfx::Rect(2, 2), flags);
}
root_client_.set_bounds(gfx::Size(10, 10));
root->SetBounds(gfx::Size(10, 10));
child_client_.set_bounds(gfx::Size(9, 9));
child_->SetBounds(gfx::Size(9, 9));
mask_client_.set_bounds(gfx::Size(9, 9));
mask_->SetBounds(gfx::Size(9, 9));
child_->SetMaskLayer(mask_);
root->AddChild(child_);
layer_tree_host()->SetRootLayer(std::move(root));
LayerTreeTest::SetupTree();
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DidCommit() override {
switch (layer_tree_host()->SourceFrameNumber()) {
case 1:
// The child and mask are updated when they have non-empty bounds.
EXPECT_EQ(1, child_->update_count());
EXPECT_EQ(1, mask_->update_count());
// The child and mask become empty bounds.
child_client_.set_bounds(gfx::Size());
child_->SetBounds(gfx::Size());
mask_client_.set_bounds(gfx::Size());
mask_->SetBounds(gfx::Size());
break;
case 2: {
scoped_refptr<RasterSource> child_raster =
child_->GetRecordingSourceForTesting().CreateRasterSource();
EXPECT_FALSE(child_raster->IsSolidColor());
scoped_refptr<RasterSource> mask_raster =
mask_->GetRecordingSourceForTesting().CreateRasterSource();
EXPECT_FALSE(mask_raster->IsSolidColor());
}
// The child and mask are not updated when they have empty bounds.
EXPECT_EQ(1, child_->update_count());
EXPECT_EQ(1, mask_->update_count());
EndTest();
break;
default:
ADD_FAILURE() << layer_tree_host()->SourceFrameNumber();
}
}
scoped_refptr<FakePictureLayer> child_;
scoped_refptr<FakePictureLayer> mask_;
FakeContentLayerClient root_client_;
FakeContentLayerClient child_client_;
FakeContentLayerClient mask_client_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(DontUpdateLayersWithEmptyBounds);
// Verifies that if we have a new LocalSurfaceId we submit a CompositorFrame
// even if there is no damage.
class LayerTreeHostTestNewLocalSurfaceIdForcesDraw : public LayerTreeHostTest {
public:
LayerTreeHostTestNewLocalSurfaceIdForcesDraw() {}
void BeginTest() override {
layer_tree_host()->SetViewportRectAndScale(gfx::Rect(10, 10), 1.f,
viz::LocalSurfaceId());
layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10));
}
void WillSubmitCompositorFrame(LayerTreeHostImpl* host_impl,
const viz::CompositorFrame& frame) override {
switch (frame.metadata.frame_token) {
case 1:
GenerateNewLocalSurfaceId();
PostSetLocalSurfaceIdToMainThread(GetCurrentLocalSurfaceId());
break;
case 2:
EndTest();
break;
default:
NOTREACHED();
}
}
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNewLocalSurfaceIdForcesDraw);
// Confirms that requests to force send RFM are forwarded once (and exactly
// once) to the RFM observer. Does this by drawing 3 frames and requesting
// force send from only the second then validating the request.
class LayerTreeHostTestRequestForceSendMetadata
: public LayerTreeHostTest,
public RenderFrameMetadataObserver {
public:
// Provides a wrapper which can be passed to LayerTreeHost, but just forwards
// to the test class.
class ForwardingRenderFrameMetadataObserver
: public RenderFrameMetadataObserver {
public:
explicit ForwardingRenderFrameMetadataObserver(
RenderFrameMetadataObserver* target)
: target_(target) {}
// RenderFrameMetadataObserver implementation.
void BindToCurrentSequence() override { target_->BindToCurrentSequence(); }
void OnRenderFrameSubmission(
const RenderFrameMetadata& render_frame_metadata,
viz::CompositorFrameMetadata* compositor_frame_metadata,
bool force_send) override {
target_->OnRenderFrameSubmission(render_frame_metadata,
compositor_frame_metadata, force_send);
}
#if BUILDFLAG(IS_ANDROID)
void DidEndScroll() override { target_->DidEndScroll(); }
#endif
private:
raw_ptr<RenderFrameMetadataObserver> target_ = nullptr;
};
LayerTreeHostTestRequestForceSendMetadata() = default;
void BeginTest() override {
// Just set up a basic frame which can be repeatedly re-drawn.
layer_tree_host()->SetRenderFrameObserver(
std::make_unique<ForwardingRenderFrameMetadataObserver>(this));
layer_tree_host()->SetViewportRectAndScale(gfx::Rect(10, 10), 1.f,
viz::LocalSurfaceId());
layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10));
layer_ = FakePictureLayer::Create(&client_);
layer_->SetBounds(gfx::Size(10, 10));
layer_->SetPosition(gfx::PointF(0.f, 0.f));
layer_->SetIsDrawable(true);
layer_tree_host()->root_layer()->AddChild(layer_);
PostSetNeedsCommitToMainThread();
client_.set_bounds(layer_->bounds());
}
void DidCommitAndDrawFrame() override {
// Draw three frames, sending a request to force send metadata on the
// middle (second) frame.
if (num_draw_layers_ == 3)
return;
if (num_draw_layers_ == 2)
layer_tree_host()->RequestForceSendMetadata();
layer_->SetNeedsDisplay();
}
void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
num_draw_layers_++;
if (num_draw_layers_ == 3)
EndTest();
}
void AfterTest() override { EXPECT_EQ(1, num_force_sends_); }
// RenderFrameMetadataObserver implementation. Called on thread.
void BindToCurrentSequence() override {}
void OnRenderFrameSubmission(
const RenderFrameMetadata& render_frame_metadata,
viz::CompositorFrameMetadata* compositor_frame_metadata,
bool force_send) override {
if (force_send)
num_force_sends_++;
}
#if BUILDFLAG(IS_ANDROID)
void DidEndScroll() override {}
#endif
private:
FakeContentLayerClient client_;
scoped_refptr<Layer> layer_;
int num_draw_layers_ = 0;
int num_force_sends_ = 0;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestRequestForceSendMetadata);
class LayerTreeHostTestPartialTileDamage : public LayerTreeHostTest {
public:
LayerTreeHostTestPartialTileDamage()
: partial_damage_(20, 20, 45, 60), layer_size_(512, 512) {}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void InitializeSettings(LayerTreeSettings* settings) override {
settings->default_tile_size = gfx::Size(256, 256);
}
void SetupTree() override {
content_layer_client_.set_bounds(layer_size_);
content_layer_client_.set_fill_with_nonsolid_color(true);
layer_tree_host()->SetRootLayer(
FakePictureLayer::Create(&content_layer_client_));
layer_tree_host()->root_layer()->SetBounds(layer_size_);
LayerTreeTest::SetupTree();
}
void DoPartialTileInvalidation() {
layer_tree_host()->root_layer()->SetNeedsDisplayRect(partial_damage_);
}
void DisplayReceivedCompositorFrameOnThread(
const viz::CompositorFrame& frame) override {
frame_count_on_impl_thread_++;
gfx::Rect frame_damage = frame.render_pass_list.back()->damage_rect;
switch (frame_count_on_impl_thread_) {
case 1:
// We have the first frame, which should damage everything. Schedule
// another which partially damages one of tiles.
MainThreadTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(
&LayerTreeHostTestPartialTileDamage::DoPartialTileInvalidation,
base::Unretained(this)));
EXPECT_EQ(frame_damage, gfx::Rect(layer_size_));
break;
case 2:
EXPECT_EQ(frame_damage, partial_damage_);
EndTest();
}
}
protected:
const gfx::Rect partial_damage_;
const gfx::Size layer_size_;
// Main thread.
FakeContentLayerClient content_layer_client_;
// Impl thread.
int frame_count_on_impl_thread_ = 0;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestPartialTileDamage);
// Make sure that a change in top controls shown ratio causes an update to the
// pending tree's viewports.
class LayerTreeHostTopControlsDeltaTriggersViewportUpdate
: public LayerTreeHostTest {
public:
LayerTreeHostTopControlsDeltaTriggersViewportUpdate() { SetUseLayerLists(); }
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void SetupTree() override {
LayerTreeHostTest::SetupTree();
Layer* root_layer = layer_tree_host()->root_layer();
// Set up scrollable root.
root_layer->SetBounds(gfx::Size(100, 100));
SetupViewport(root_layer, gfx::Size(50, 50), root_layer->bounds());
layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 1.f, 1.f);
// Set browser controls to be partially shown.
layer_tree_host()->SetBrowserControlsParams(
{kTopControlsHeight, 0, kBottomControlsHeight, 0, false /* animate */,
true /* shrink */});
layer_tree_host()->SetBrowserControlsShownRatio(kTopControlsShownRatio,
kBottomControlsShownRatio);
}
void BeginCommitOnThread(LayerTreeHostImpl* impl) override {
// Before commit the inner_viewport_container_bounds_delta() value should
// not reflect the partially shown top controls.
float bounds_delta = impl->pending_tree()
->property_trees()
->inner_viewport_container_bounds_delta()
.y();
EXPECT_EQ(bounds_delta, 0.0f);
}
void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
// After commit the inner_viewport_container_bounds_delta() value should
// reflect the partially shown top controls.
float bounds_delta = impl->pending_tree()
->property_trees()
->inner_viewport_container_bounds_delta()
.y();
EXPECT_EQ(bounds_delta,
kTopControlsHeight - kTopControlsHeight * kTopControlsShownRatio);
EndTest();
}
static constexpr float kTopControlsHeight = 10.0f;
static constexpr float kTopControlsShownRatio = 0.3f;
static constexpr float kBottomControlsHeight = 10.0f;
static constexpr float kBottomControlsShownRatio = 1.f;
};
MULTI_THREAD_TEST_F(LayerTreeHostTopControlsDeltaTriggersViewportUpdate);
#if BUILDFLAG(IS_CHROMEOS)
// Tests that custom sequence metrics tracking result is reported to
// LayerTreeHostClient.
constexpr MutatorHost::TrackedAnimationSequenceId kSequenceId = 1u;
class LayerTreeHostCustomMetricsTrackerTest : public LayerTreeHostTest {
public:
// Custom sequences are only supported for ChromeOS UI, which is
// Single-Threaded.
void InitializeSettings(LayerTreeSettings* settings) override {
settings->is_layer_tree_for_ui = true;
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DidCommit() override {
// FrameSequenceTracker typically sees the following sequence:
// e(2,2)b(3)B(0,3)E(3)s(3)S(3)e(3,3)P(3)b(4)B(3,4)E(4)s(4)S(4)e(4,4)P(4)
switch (layer_tree_host()->SourceFrameNumber()) {
case 1:
animation_host()->StartCompositorMetricsTracking(kSequenceId);
break;
case 3:
animation_host()->StopCompositorMetricsTracking(kSequenceId);
break;
default:
break;
}
if (!TestEnded())
PostSetNeedsCommitWithForcedRedrawToMainThread();
}
void NotifyCompositorMetricsTrackerResults(
CustomTrackerResults results) override {
// Check that data for kSequenceId is captured. Ideally, we should get
// 2 frame_expected and 2 frame_produced. But on slow bots, it is difficult
// to infer the correct numbers. Both frame_expected and frame_produced
// could drop to 1 (or even below). So no sanity check on data itself.
ASSERT_TRUE(base::Contains(results, kSequenceId));
EndTest();
}
// FrameSorter only tracks for BeginMainFrame which have provided metrics.
std::unique_ptr<BeginMainFrameMetrics> GetBeginMainFrameMetrics() override {
std::unique_ptr<BeginMainFrameMetrics> metrics =
std::make_unique<BeginMainFrameMetrics>();
metrics->should_measure_smoothness = true;
return metrics;
}
};
SINGLE_THREAD_TEST_F(LayerTreeHostCustomMetricsTrackerTest);
#endif // BUILDFLAG(IS_CHROMEOS)
class LayerTreeHostTestDelegatedInkMetadataBase
: public LayerTreeHostTest,
public RenderFrameMetadataObserver {
public:
// Provides a wrapper which can be passed to LayerTreeHost, but just forwards
// to the test class.
class ForwardingRenderFrameMetadataObserver
: public RenderFrameMetadataObserver {
public:
explicit ForwardingRenderFrameMetadataObserver(
RenderFrameMetadataObserver* target)
: target_(target) {}
// RenderFrameMetadataObserver implementation.
void BindToCurrentSequence() override { target_->BindToCurrentSequence(); }
void OnRenderFrameSubmission(
const RenderFrameMetadata& render_frame_metadata,
viz::CompositorFrameMetadata* compositor_frame_metadata,
bool force_send) override {
target_->OnRenderFrameSubmission(render_frame_metadata,
compositor_frame_metadata, force_send);
}
#if BUILDFLAG(IS_ANDROID)
void DidEndScroll() override { target_->DidEndScroll(); }
#endif
private:
raw_ptr<RenderFrameMetadataObserver> target_ = nullptr;
};
// LayerTreeHostTest implementation:
void BeginTest() override {
// Set up a basic render frame observer for the LTH/LTHI to forward to.
layer_tree_host()->SetRenderFrameObserver(
std::make_unique<ForwardingRenderFrameMetadataObserver>(this));
// Setting up a basic frame that can be redrawn.
layer_tree_host()->SetViewportRectAndScale(gfx::Rect(10, 10), 1.f,
viz::LocalSurfaceId());
layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10));
layer_ = FakePictureLayer::Create(&client_);
layer_tree_host()->root_layer()->AddChild(layer_);
client_.set_bounds(layer_->bounds());
// Create DelegatedInkMetadata. Values chosen arbitrarily.
SkColor color = SK_ColorDKGRAY;
double diameter = 1.000002;
gfx::PointF point = gfx::PointF(135, 45);
gfx::RectF area = gfx::RectF(173, 438);
base::TimeTicks timestamp = base::TimeTicks::Now();
bool is_hovering = true;
expected_metadata_ = gfx::DelegatedInkMetadata(
point, diameter, color, timestamp, area, is_hovering);
// Send the initial delegated ink metadata so it can be passed to
// CompositorFrameMetadata.
layer_tree_host()->SetDelegatedInkMetadata(
std::make_unique<gfx::DelegatedInkMetadata>(
expected_metadata_.value()));
}
// Check DelegatedInkMetadata on the CompositorFrameMetadata when the
// compositor frame is submitted.
void ExpectMetadata(
std::optional<DelegatedInkBrowserMetadata> browser_delegated_ink_metadata,
gfx::DelegatedInkMetadata* actual_metadata) {
if (expected_metadata_.has_value()) {
EXPECT_TRUE(browser_delegated_ink_metadata.has_value());
EXPECT_TRUE(actual_metadata);
EXPECT_TRUE(
browser_delegated_ink_metadata.value().delegated_ink_is_hovering);
EXPECT_EQ(expected_metadata_->point(), actual_metadata->point());
EXPECT_EQ(expected_metadata_->color(), actual_metadata->color());
EXPECT_EQ(expected_metadata_->diameter(), actual_metadata->diameter());
EXPECT_EQ(expected_metadata_->presentation_area(),
actual_metadata->presentation_area());
EXPECT_EQ(expected_metadata_->timestamp(), actual_metadata->timestamp());
EXPECT_EQ(expected_metadata_->is_hovering(),
actual_metadata->is_hovering());
// Record the frame time from the metadata so we can confirm that it
// matches the LayerTreeHostImpl's frame time in DrawLayersOnThread.
EXPECT_GT(actual_metadata->frame_time(), base::TimeTicks::Min());
metadata_frame_time_ = actual_metadata->frame_time();
} else {
EXPECT_FALSE(browser_delegated_ink_metadata.has_value());
EXPECT_FALSE(actual_metadata);
EndTest();
}
}
// RenderFrameMetadataObserver implementation.
void BindToCurrentSequence() override {}
void OnRenderFrameSubmission(
const RenderFrameMetadata& render_frame_metadata,
viz::CompositorFrameMetadata* compositor_frame_metadata,
bool force_send) override {
ExpectMetadata(render_frame_metadata.delegated_ink_metadata,
compositor_frame_metadata->delegated_ink_metadata.get());
}
#if BUILDFLAG(IS_ANDROID)
void DidEndScroll() override {}
#endif
protected:
std::optional<gfx::DelegatedInkMetadata> expected_metadata_;
base::TimeTicks metadata_frame_time_;
FakeContentLayerClient client_;
scoped_refptr<Layer> layer_;
};
// Confirm that DelegatedInkMetadata set on the LTH propagates to the
// CompositorFrameMetadata and RenderFrameMetadata, and then both are correctly
// reset when another frame is drawn without DelegatedInkMetadata.
class LayerTreeHostTestDelegatedInkMetadataOnAndOff
: public LayerTreeHostTestDelegatedInkMetadataBase {
public:
void DidCommitAndDrawFrame() override {
// Cause a redraw to occur.
if (set_needs_display_) {
layer_->SetNeedsDisplay();
set_needs_display_ = false;
}
}
void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
if (expected_metadata_.has_value()) {
EXPECT_EQ(metadata_frame_time_, impl->CurrentBeginFrameArgs().frame_time);
// Now try again with no metadata to confirm everything is cleared out.
expected_metadata_.reset();
}
}
private:
bool set_needs_display_ = true;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDelegatedInkMetadataOnAndOff);
// Confirm that DelegatedInkMetadata set on the LTH propagates to the
// CompositorFrameMetadata and RenderFrameMetadata. Also confirm that the
// DelegatedInkMetadata persists on the active tree and is present in the
// CompositorFrameMetadata until a new main frame is complete with no
// DelegatedInkMetadata present in commit data.
// This test does the following:
//
// 1) Set DelegatedInkMetadata on LayerTreeHost (BeginTest() in
// LayerTreeHostTestDelegatedInkMetadataBase)
// 3) Confirm it gets passed down to CompositorFrameMetadata in first frame
// 4) Issue some animation-only BeginFrames so that compositor-only frames are
// generated.
// 5) Commit+Activate without new DelegatedInkMetadata and confirm that the
// metadata is erased from all relevant data structures.
class LayerTreeHostTestDelegatedInkMetadataCompositorOnlyFrame
: public viz::ExternalBeginFrameSourceClient,
public LayerTreeHostTestDelegatedInkMetadataBase {
public:
LayerTreeHostTestDelegatedInkMetadataCompositorOnlyFrame()
: external_begin_frame_source_(this) {
UseBeginFrameSource(&external_begin_frame_source_);
}
// Once the first Impl frame is finished, send some more that are animation
// only so that there is no main frame. Once each compositor-only frame
// is generated and sent, the DelegatedInkMetadata is assessed on the
// frame's associated CompositorFrameMetadata.
// Once the frame count has reached 3 (arbitrarily chosen), SetNeedsCommit
// so that the DelegatedInkMetadata can be reset.
void DidFinishImplFrameOnThread(LayerTreeHostImpl* host_impl) override {
if (begin_frame_count_ < 3) {
// Send another animation_only BeginFrame.
PostIssueBeginFrame(true);
} else if (begin_frame_count_ == 3) {
// Trigger second commit.
MainThreadTaskRunner()->PostTaskAndReply(
FROM_HERE,
base::BindOnce(
&LayerTreeHostTestDelegatedInkMetadataCompositorOnlyFrame::
SetNeedsCommitOnMainThread,
base::Unretained(this)),
base::BindOnce(
&LayerTreeHostTestDelegatedInkMetadataCompositorOnlyFrame::
IssueBeginFrame,
base::Unretained(this), true));
} else if (begin_frame_count_ == 4) {
PostIssueBeginFrame(false);
}
host_impl->SetNeedsRedraw();
host_impl->SetViewportDamage(gfx::Rect(1, 1));
}
void SetNeedsCommitOnMainThread() { layer_tree_host()->SetNeedsCommit(); }
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
++commit_count_;
// First commit is due to first frame having `animate_only` forced to false
// in order to create the surface.
if (commit_count_ == 1)
return;
// Reset the expected metadata on the second commit complete as a signal
// for ExpectMetadata to know that there should be no actual metadata
// received.
expected_metadata_.reset();
}
void AfterTest() override {
EXPECT_EQ(2, commit_count_);
EXPECT_EQ(5, begin_frame_count_);
}
// The following code is necessary to issue BeginFrames.
// Initialize BeginFrameArgs.
void IssueBeginFrame(bool animate_only) {
++begin_frame_count_;
last_begin_frame_time_ += viz::BeginFrameArgs::DefaultInterval();
uint64_t sequence_number = next_begin_frame_sequence_number_++;
auto args = viz::BeginFrameArgs::Create(
BEGINFRAME_FROM_HERE, viz::BeginFrameArgs::kManualSourceId,
sequence_number, last_begin_frame_time_,
last_begin_frame_time_ + viz::BeginFrameArgs::DefaultInterval(),
viz::BeginFrameArgs::DefaultInterval(), viz::BeginFrameArgs::NORMAL);
args.animate_only = animate_only;
external_begin_frame_source_.OnBeginFrame(args);
}
void PostIssueBeginFrame(bool animate_only) {
// Post a new task so that BeginFrame is not issued within same callstack.
ImplThreadTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(
&LayerTreeHostTestDelegatedInkMetadataCompositorOnlyFrame::
IssueBeginFrame,
base::Unretained(this), animate_only));
}
// viz::ExternalBeginFrameSourceClient implementation:
void OnNeedsBeginFrames(bool needs_begin_frames) override {
if (needs_begin_frames) {
EXPECT_EQ(0, begin_frame_count_);
// Send a first animation_only BeginFrame.
PostIssueBeginFrame(true);
}
}
private:
viz::ExternalBeginFrameSource external_begin_frame_source_;
base::TimeTicks last_begin_frame_time_ = base::TimeTicks::Now();
uint64_t next_begin_frame_sequence_number_ =
viz::BeginFrameArgs::kStartingFrameNumber;
int commit_count_ = 0;
int begin_frame_count_ = 0;
scoped_refptr<Layer> layer_;
FakeContentLayerClient client_;
};
// TODO(crbug.com/40265182): flaky on win-asan.
#if !(BUILDFLAG(IS_WIN) && defined(ADDRESS_SANITIZER))
SINGLE_AND_MULTI_THREAD_TEST_F(
LayerTreeHostTestDelegatedInkMetadataCompositorOnlyFrame);
#endif
// Base class for EventMetrics-related tests.
class LayerTreeHostTestEventsMetrics : public LayerTreeHostTest {
protected:
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
// Simulate an event being handled on the main thread.
void PostSimulateEvent() {
MainThreadTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(&LayerTreeHostTestEventsMetrics::SimulateEventOnMain,
base::Unretained(this)));
}
// Verifies the number of saved events metrics on the main thread.
void PostVerifyMainSavedEventsMetricsCount(size_t count) const {
MainThreadTaskRunner()->PostTask(
FROM_HERE, base::BindOnce(&LayerTreeHostTestEventsMetrics::
VerifyMainSavedEventsMetricsCountOnMain,
base::Unretained(this), count));
}
// Verifies the number of events metrics copied from the main thread to the
// impl thread.
void VerifyImplEventsMetricsFromMainCount(LayerTreeHostImpl* impl,
size_t count) const {
EXPECT_EQ(count, impl->active_tree()
->events_metrics_from_main_thread_count_for_testing());
}
private:
void SimulateEventOnMain() {
base::SimpleTestTickClock tick_clock;
tick_clock.Advance(base::Microseconds(10));
base::TimeTicks event_time = tick_clock.NowTicks();
tick_clock.Advance(base::Microseconds(10));
base::TimeTicks arrived_in_browser_main_timestamp = tick_clock.NowTicks();
tick_clock.Advance(base::Microseconds(10));
std::unique_ptr<EventMetrics> metrics =
ScrollUpdateEventMetrics::CreateForTesting(
ui::EventType::kGestureScrollUpdate, ui::ScrollInputType::kWheel,
/*is_inertial=*/false,
ScrollUpdateEventMetrics::ScrollUpdateType::kContinued,
/*delta=*/10.0f, event_time, arrived_in_browser_main_timestamp,
&tick_clock, std::nullopt);
DCHECK_NE(metrics, nullptr);
{
tick_clock.Advance(base::Microseconds(10));
metrics->SetDispatchStageTimestamp(
EventMetrics::DispatchStage::kRendererCompositorStarted);
auto done_callback = base::BindOnce(
[](std::unique_ptr<EventMetrics> metrics,
base::SimpleTestTickClock* tick_clock, bool handled) {
tick_clock->Advance(base::Microseconds(10));
metrics->SetDispatchStageTimestamp(
EventMetrics::DispatchStage::kRendererCompositorFinished);
std::unique_ptr<EventMetrics> result =
handled ? std::move(metrics) : nullptr;
return result;
},
std::move(metrics), &tick_clock);
auto scoped_event_monitor =
layer_tree_host()->GetScopedEventMetricsMonitor(
std::move(done_callback));
layer_tree_host()->SetNeedsAnimate();
}
EXPECT_SCOPED(VerifyMainSavedEventsMetricsCountOnMain(1));
}
void VerifyMainSavedEventsMetricsCountOnMain(size_t count) const {
EXPECT_EQ(count,
layer_tree_host()->saved_events_metrics_count_for_testing());
}
};
// Verifies that if the commit is aborted (deferred) due to LayerTreeHost being
// hidden, events metrics are discarded to prevent reporting arbitrarily large
// latencies when the frame becomes visible again.
class LayerTreeHostTestKeepEventsMetricsForVisibility
: public LayerTreeHostTestEventsMetrics {
protected:
void WillBeginImplFrameOnThread(LayerTreeHostImpl* impl,
const viz::BeginFrameArgs& args,
bool has_damage) override {
// Skip if we have already received a begin-impl-frame and acted on it.
if (received_will_begin_impl_frame_)
return;
received_will_begin_impl_frame_ = true;
EXPECT_SCOPED(VerifyImplEventsMetricsFromMainCount(impl, 0));
// Simulate an event being handled on the main thread. Since the main frame
// is not yet scheduled, we will have events metrics when the main frame is
// processed.
PostSimulateEvent();
// Hide layer tree host. Since the main frame is not yet scheduled, layer
// tree host will be hidden when the main frame is processed, causing it to
// abort.
PostSetLayerTreeHostVisible(false);
}
void BeginMainFrameAbortedOnThread(
LayerTreeHostImpl* impl,
CommitEarlyOutReason reason,
bool /* did_sync_scroll_and_viewport */) override {
EXPECT_EQ(reason, CommitEarlyOutReason::kAbortedNotVisible);
// Since the main frame is aborted due to invisibility, events metrics
// should be discarded.
PostVerifyMainSavedEventsMetricsCount(0);
// Make layer tree host visible so that the deferred commit is completed.
// Note that there is no events metrics to be passed to the impl thread.
PostSetLayerTreeHostVisible(true);
}
void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
// Now a commit is completed and activated, but events metrics from main are
// already discarded, so there is no events metrics to be moved to the impl
// thread.
PostVerifyMainSavedEventsMetricsCount(0);
EXPECT_SCOPED(VerifyImplEventsMetricsFromMainCount(impl, 0));
EndTest();
}
private:
void SetLayerTreeHostVisibleOnMain(bool visible) {
layer_tree_host()->SetVisible(visible);
}
void PostSetLayerTreeHostVisible(bool visible) {
MainThreadTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(&LayerTreeHostTestKeepEventsMetricsForVisibility::
SetLayerTreeHostVisibleOnMain,
base::Unretained(this), visible));
}
bool received_will_begin_impl_frame_ = false;
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestKeepEventsMetricsForVisibility);
// Verifies that if the commit is aborted due to main frame update being
// deferred, events metrics are not thrown away to be used when the actual
// commit happens.
class LayerTreeHostTestKeepEventsMetricsForDeferredMainFrameUpdate
: public LayerTreeHostTestEventsMetrics {
protected:
void WillBeginImplFrameOnThread(LayerTreeHostImpl* impl,
const viz::BeginFrameArgs& args,
bool has_damage) override {
// Skip if we have already received a begin-impl-frame and acted on it.
if (received_will_begin_impl_frame_)
return;
received_will_begin_impl_frame_ = true;
EXPECT_SCOPED(VerifyImplEventsMetricsFromMainCount(impl, 0));
// Simulate an event being handled on the main thread. Since the main frame
// is not yet scheduled, we will have events metrics when the main frame is
// processed.
PostSimulateEvent();
// Defer main frame updates. Since the main frame is not yet scheduled, main
// frame updates will be deferred when the main frame is processed, causing
// it to abort.
PostDeferMainFrameUpdate();
}
void BeginMainFrameAbortedOnThread(
LayerTreeHostImpl* impl,
CommitEarlyOutReason reason,
bool /* did_sync_scroll_and_viewport */) override {
EXPECT_EQ(reason, CommitEarlyOutReason::kAbortedDeferredMainFrameUpdate);
// Since the main frame is aborted due to deferred main frame updates,
// events metrics should not have been thrown away.
PostVerifyMainSavedEventsMetricsCount(1);
// Stop deferring main frame updates so that the deferred commit is
// completed, causing events metrics being passed to the impl thread.
PostStopDeferringMainFrameUpdate();
}
void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
// Now that a commit is completed and activated, events metrics from main
// thread should have been moved to the impl thread.
PostVerifyMainSavedEventsMetricsCount(0);
EXPECT_SCOPED(VerifyImplEventsMetricsFromMainCount(impl, 1));
EndTest();
}
private:
void DeferMainFrameUpdateOnMain() {
scoped_defer_main_frame_update_ = layer_tree_host()->DeferMainFrameUpdate();
}
void PostDeferMainFrameUpdate() {
MainThreadTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(
&LayerTreeHostTestKeepEventsMetricsForDeferredMainFrameUpdate::
DeferMainFrameUpdateOnMain,
base::Unretained(this)));
}
void StopDeferringMainFrameUpdateOnMain() {
scoped_defer_main_frame_update_.reset();
}
void PostStopDeferringMainFrameUpdate() {
MainThreadTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(
&LayerTreeHostTestKeepEventsMetricsForDeferredMainFrameUpdate::
StopDeferringMainFrameUpdateOnMain,
base::Unretained(this)));
}
bool received_will_begin_impl_frame_ = false;
std::unique_ptr<ScopedDeferMainFrameUpdate> scoped_defer_main_frame_update_;
};
SINGLE_AND_MULTI_THREAD_TEST_F(
LayerTreeHostTestKeepEventsMetricsForDeferredMainFrameUpdate);
// Verifies that if the commit is aborted (deferred), events metrics are not
// thrown away to be used when the actual commit happens.
class LayerTreeHostTestKeepEventsMetricsForDeferredCommit
: public LayerTreeHostTestEventsMetrics {
protected:
void WillBeginImplFrameOnThread(LayerTreeHostImpl* impl,
const viz::BeginFrameArgs& args,
bool has_damage) override {
// Skip if we have already received a begin-impl-frame and acted on it.
if (received_will_begin_impl_frame_)
return;
received_will_begin_impl_frame_ = true;
EXPECT_SCOPED(VerifyImplEventsMetricsFromMainCount(impl, 0));
// Simulate an event being handled on the main thread. Since the main frame
// is not yet scheduled, we will have events metrics when the main frame is
// processed.
PostSimulateEvent();
// Defer commits. Since the main frame is not yet scheduled, commits will be
// deferred when the main frame is processed, causing it to abort.
PostDeferCommit();
}
void BeginMainFrameAbortedOnThread(
LayerTreeHostImpl* impl,
CommitEarlyOutReason reason,
bool /* did_sync_scroll_and_viewport */) override {
EXPECT_EQ(reason, CommitEarlyOutReason::kAbortedDeferredCommit);
// Since the main frame is aborted due to deferred commits, events metrics
// should not have been thrown away.
PostVerifyMainSavedEventsMetricsCount(1);
// Stop deferring commits so that the deferred commit is completed, causing
// events metrics being passed to the impl thread.
PostStopDeferringCommit();
}
void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
// Now that a commit is completed and activated, events metrics from main
// thread should have been moved to the impl thread.
PostVerifyMainSavedEventsMetricsCount(0);
EXPECT_SCOPED(VerifyImplEventsMetricsFromMainCount(impl, 1));
EndTest();
}
private:
void DeferCommitOnMain() {
layer_tree_host()->StartDeferringCommits(
base::Days(1), PaintHoldingReason::kFirstContentfulPaint);
}
void PostDeferCommit() {
MainThreadTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(&LayerTreeHostTestKeepEventsMetricsForDeferredCommit::
DeferCommitOnMain,
base::Unretained(this)));
}
void StopDeferringCommitOnMain() {
layer_tree_host()->StopDeferringCommits(
PaintHoldingCommitTrigger::kFirstContentfulPaint);
}
void PostStopDeferringCommit() {
MainThreadTaskRunner()->PostTask(
FROM_HERE,
base::BindOnce(&LayerTreeHostTestKeepEventsMetricsForDeferredCommit::
StopDeferringCommitOnMain,
base::Unretained(this)));
}
bool received_will_begin_impl_frame_ = false;
};
SINGLE_AND_MULTI_THREAD_TEST_F(
LayerTreeHostTestKeepEventsMetricsForDeferredCommit);
// Verifies that if the commit is aborted due to no damage, events metrics are
// thrown away, so there is nothing to report in the next commit.
class LayerTreeHostTestIgnoreEventsMetricsForNoUpdate
: public LayerTreeHostTestEventsMetrics {
protected:
void WillBeginImplFrameOnThread(LayerTreeHostImpl* impl,
const viz::BeginFrameArgs& args,
bool has_damage) override {
// Continue only if we are waiting for the second frame's being-impl-frame.
// The first frame will end up in a commit which is not what we want.
if (state_ != State::kWaitingForSecondFrameBeginImpl)
return;
state_ = State::kReceivedSecondFrameBeginImpl;
EXPECT_SCOPED(VerifyImplEventsMetricsFromMainCount(impl, 0));
// Simulate an event being handled on the main thread. Since the main frame
// is not yet scheduled, we will have events metrics when the main frame is
// processed.
PostSimulateEvent();
}
void BeginMainFrameAbortedOnThread(
LayerTreeHostImpl* impl,
CommitEarlyOutReason reason,
bool /* did_sync_scroll_and_viewport */) override {
EXPECT_EQ(reason, CommitEarlyOutReason::kFinishedNoUpdates);
// We should reach here only for the second frame.
EXPECT_EQ(state_, State::kReceivedSecondFrameBeginImpl);
state_ = State::kWaitingForThirdFrameActivation;
// Since the main frame is aborted due to no updates, events metrics should
// have been thrown away.
PostVerifyMainSavedEventsMetricsCount(0);
// Request another commit to make sure no events metrics is passed to the
// impl thread when it is complete.
PostSetNeedsCommitToMainThread();
}
void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
switch (state_) {
case State::kWaitingForFirstFrameActivation:
// Now that the first frame's commit is completed and activated, request
// another begin-main-frame without requesting a full commit so that it
// aborts with no updates.
state_ = State::kWaitingForSecondFrameBeginImpl;
EXPECT_SCOPED(VerifyImplEventsMetricsFromMainCount(impl, 0));
PostSetNeedsUpdateLayersToMainThread();
break;
case State::kWaitingForThirdFrameActivation:
// Now that the third frame's commit is completed and activated there
// should be no events metrics on the main or impl thread as the events
// metrics were thrown away after second frame was aborted with no
// updates.
EXPECT_SCOPED(VerifyImplEventsMetricsFromMainCount(impl, 0));
PostVerifyMainSavedEventsMetricsCount(0);
EndTest();
break;
default:
NOTREACHED();
}
}
private:
enum class State {
kWaitingForFirstFrameActivation,
kWaitingForSecondFrameBeginImpl,
kReceivedSecondFrameBeginImpl,
kWaitingForThirdFrameActivation,
};
State state_ = State::kWaitingForFirstFrameActivation;
};
// TODO(crbug.com/40756887): Disabled because test is flaky on Linux and CrOS.
// MULTI_THREAD_TEST_F(LayerTreeHostTestIgnoreEventsMetricsForNoUpdate);
class LayerTreeHostUkmSmoothnessMetric : public LayerTreeTest {
public:
LayerTreeHostUkmSmoothnessMetric() = default;
~LayerTreeHostUkmSmoothnessMetric() override = default;
void InitializeSettings(LayerTreeSettings* settings) override {
settings->commit_to_active_tree = false;
}
void SetupTree() override {
LayerTreeTest::SetupTree();
shmem_region_ = layer_tree_host()->CreateSharedMemoryForSmoothnessUkm();
}
void BeginTest() override {
// Start with requesting main-frames.
PostSetNeedsCommitToMainThread();
}
void AfterTest() override {
ASSERT_TRUE(shmem_region_.IsValid());
auto mapping = shmem_region_.Map();
auto* smoothness = mapping.GetMemoryAs<UkmSmoothnessDataShared>();
ASSERT_TRUE(smoothness);
// It is not always possible to guarantee an exact number of dropped frames.
// So validate that there are non-zero dropped frames.
EXPECT_GT(smoothness->data.avg_smoothness, 0);
}
void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl,
const viz::BeginFrameArgs& args,
bool has_damage) override {
last_args_ = args;
if (!fcp_sent_) {
host_impl->dropped_frame_counter()->OnFirstContentfulPaintReceived();
fcp_sent_ = true;
}
}
void DidFinishImplFrameOnThread(LayerTreeHostImpl* host_impl) override {
if (TestEnded())
return;
if (frames_counter_ == 0) {
EndTest();
return;
}
// Mark every frame as a dropped frame affecting smoothness.
host_impl->dropped_frame_counter()->OnEndFrame(
last_args_, CreateFakeImplDroppedFrameInfo());
host_impl->SetNeedsRedraw();
--frames_counter_;
}
private:
const uint32_t kTotalFramesForTest = 5;
uint32_t frames_counter_ = kTotalFramesForTest;
bool fcp_sent_ = false;
viz::BeginFrameArgs last_args_;
base::ReadOnlySharedMemoryRegion shmem_region_;
};
MULTI_THREAD_TEST_F(LayerTreeHostUkmSmoothnessMetric);
class LayerTreeHostUkmSmoothnessMemoryOwnership : public LayerTreeTest {
public:
LayerTreeHostUkmSmoothnessMemoryOwnership() = default;
~LayerTreeHostUkmSmoothnessMemoryOwnership() override = default;
void InitializeSettings(LayerTreeSettings* settings) override {
settings->commit_to_active_tree = false;
}
void BeginTest() override {
// Start with requesting main-frames.
PostSetNeedsCommitToMainThread();
}
void AfterTest() override {
}
void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl,
const viz::BeginFrameArgs& args,
bool has_damage) override {
last_args_ = args;
if (!fcp_sent_) {
host_impl->dropped_frame_counter()->OnFirstContentfulPaintReceived();
fcp_sent_ = true;
}
host_impl->SetNeedsCommit();
}
void DidFinishImplFrameOnThread(LayerTreeHostImpl* host_impl) override {
if (TestEnded())
return;
if (frames_counter_ == 0) {
EndTest();
return;
}
// Mark every frame as a dropped frame affecting smoothness. This happens
// entirely on the compositor thread, so mark it as not including
// main-thread update.
host_impl->dropped_frame_counter()->OnEndFrame(
last_args_, CreateFakeImplDroppedFrameInfo());
host_impl->SetNeedsRedraw();
--frames_counter_;
}
void DidBeginMainFrame() override {
// Re-request the shared memory region in each frame.
shmem_region_ = layer_tree_host()->CreateSharedMemoryForSmoothnessUkm();
}
private:
const uint32_t kTotalFramesForTest = 50;
uint32_t frames_counter_ = kTotalFramesForTest;
bool fcp_sent_ = false;
viz::BeginFrameArgs last_args_;
base::ReadOnlySharedMemoryRegion shmem_region_;
};
MULTI_THREAD_TEST_F(LayerTreeHostUkmSmoothnessMemoryOwnership);
class LayerTreeHostTestViewTransitionsPropagatedToMetadata
: public LayerTreeHostTest {
protected:
void SetupTree() override {
SetInitialRootBounds(gfx::Size(10, 10));
LayerTreeHostTest::SetupTree();
}
void BeginTest() override {
layer_tree_host()->AddViewTransitionRequest(
ViewTransitionRequest::CreateCapture(
blink::ViewTransitionToken(), /*maybe_cross_frame_sink=*/false, {},
base::BindLambdaForTesting(
[this](const viz::ViewTransitionElementResourceRects&) {
CommitLambdaCalled();
})));
}
void CommitLambdaCalled() { ++num_lambda_calls_; }
void DisplayReceivedCompositorFrameOnThread(
const viz::CompositorFrame& frame) override {
ASSERT_EQ(1u, frame.metadata.transition_directives.size());
const auto& save = frame.metadata.transition_directives[0];
submitted_sequence_id_ = save.sequence_id();
EXPECT_EQ(save.type(),
viz::CompositorFrameTransitionDirective::Type::kSave);
}
void DidPresentCompositorFrame(
uint32_t frame_token,
const viz::FrameTimingDetails& frame_timing_details) override {
layer_tree_host()->NotifyTransitionRequestsFinished(submitted_sequence_id_,
{});
EndTest();
}
void AfterTest() override { EXPECT_EQ(1, num_lambda_calls_); }
uint32_t submitted_sequence_id_;
int num_lambda_calls_ = 0;
};
SINGLE_AND_MULTI_THREAD_TEST_F(
LayerTreeHostTestViewTransitionsPropagatedToMetadata);
class LayerTreeHostTestDebugStateDowngrade : public LayerTreeHostTest {
void InitializeSettings(LayerTreeSettings* settings) override {
settings->initial_debug_state.show_fps_counter = true;
}
void BeginTest() override {
LayerTreeHost* host = layer_tree_host();
LayerTreeDebugState state = host->GetDebugState();
EXPECT_TRUE(state.show_fps_counter);
state.show_fps_counter = false;
host->SetDebugState(state);
EXPECT_FALSE(host->GetDebugState().show_fps_counter);
EndTest();
}
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestDebugStateDowngrade);
class LayerTreeHostTestClearCaches : public LayerTreeHostTest {
protected:
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void WillCommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
if (host_impl->sync_tree()->source_frame_number() == 1) {
EXPECT_TRUE(host_impl->image_animation_controller()->did_navigate());
EXPECT_EQ(1u, host_impl->CommitDurationSampleCountForTesting());
}
}
void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
EXPECT_FALSE(host_impl->image_animation_controller()->did_navigate());
}
void DidCommit() override {
switch (layer_tree_host()->SourceFrameNumber()) {
case 1:
layer_tree_host()->SetNeedsCommit();
layer_tree_host()->SetSourceURL(123, GURL("https://example.com"));
break;
case 2:
EndTest();
break;
}
}
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestClearCaches);
class LayerTreeHostTestWithHelper : public LayerTreeHostTest {
public:
scoped_refptr<FakePictureLayer> CreateAndAddFakePictureLayer(
const gfx::Size& size,
Layer* parent = nullptr) {
if (!parent)
parent = layer_tree_host()->root_layer();
client_.set_fill_with_nonsolid_color(true);
client_.set_has_draw_text_op();
auto picture_layer = FakePictureLayer::Create(&client_);
picture_layer->SetBounds(size);
picture_layer->SetIsDrawable(true);
parent->AddChild(picture_layer);
client_.set_bounds(size);
return picture_layer;
}
protected:
FakeContentLayerClient client_;
};
class LayerTreeHostTestHideLayerAndSubtree
: public LayerTreeHostTestWithHelper {
public:
void InitializeSettings(LayerTreeSettings* settings) override {
settings->release_tile_resources_for_hidden_layers = true;
}
void BeginTest() override {
layer_tree_host()->SetViewportRectAndScale(gfx::Rect(10, 10), 1.f,
viz::LocalSurfaceId());
layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10));
picture_layer_ = CreateAndAddFakePictureLayer(gfx::Size(10, 10));
PostSetNeedsCommitToMainThread();
}
void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
++num_commits_;
FakePictureLayerImpl* picture_layer_impl =
static_cast<FakePictureLayerImpl*>(
impl->sync_tree()->LayerById(picture_layer_->id()));
switch (num_commits_) {
case 1:
ASSERT_EQ(1u, picture_layer_impl->num_tilings());
break;
case 2:
ASSERT_EQ(0u, picture_layer_impl->num_tilings());
EndTest();
break;
default:
NOTREACHED();
}
}
void DidCommit() override { picture_layer_->SetHideLayerAndSubtree(true); }
private:
scoped_refptr<FakePictureLayer> picture_layer_;
int num_commits_ = 0;
};
SINGLE_THREAD_TEST_F(LayerTreeHostTestHideLayerAndSubtree);
class LayerTreeHostTestHideLayerAndSubtreeOnParent
: public LayerTreeHostTestWithHelper {
public:
void InitializeSettings(LayerTreeSettings* settings) override {
settings->release_tile_resources_for_hidden_layers = true;
}
void BeginTest() override {
layer_tree_host()->SetViewportRectAndScale(gfx::Rect(10, 10), 1.f,
viz::LocalSurfaceId());
layer_tree_host()->root_layer()->SetBounds(gfx::Size(10, 10));
parent_layer_ = Layer::Create();
parent_layer_->SetBounds(gfx::Size(10, 10));
parent_layer_->SetPosition(gfx::PointF(0.f, 0.f));
parent_layer_->SetIsDrawable(true);
layer_tree_host()->root_layer()->AddChild(parent_layer_);
picture_layer_ =
CreateAndAddFakePictureLayer(gfx::Size(10, 10), parent_layer_.get());
PostSetNeedsCommitToMainThread();
}
void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
++num_commits_;
FakePictureLayerImpl* picture_layer_impl =
static_cast<FakePictureLayerImpl*>(
impl->sync_tree()->LayerById(picture_layer_->id()));
switch (num_commits_) {
case 1:
ASSERT_EQ(1u, picture_layer_impl->num_tilings());
break;
case 2:
ASSERT_EQ(0u, picture_layer_impl->num_tilings());
EndTest();
break;
default:
NOTREACHED();
}
}
void DidCommit() override { parent_layer_->SetHideLayerAndSubtree(true); }
private:
scoped_refptr<FakePictureLayer> picture_layer_;
scoped_refptr<Layer> parent_layer_;
int num_commits_ = 0;
};
SINGLE_THREAD_TEST_F(LayerTreeHostTestHideLayerAndSubtreeOnParent);
class LayerTreeHostTestOccludedTileReleased
: public LayerTreeHostTestWithHelper {
public:
void InitializeSettings(LayerTreeSettings* settings) override {
settings->memory_policy.priority_cutoff_when_visible =
gpu::MemoryAllocation::CUTOFF_ALLOW_REQUIRED_ONLY;
settings->use_occlusion_for_tile_prioritization = true;
settings->minimum_occlusion_tracking_size = gfx::Size(60, 60);
}
void BeginTest() override {
layer_tree_host()->SetViewportRectAndScale(gfx::Rect(100, 100), 1.f,
viz::LocalSurfaceId());
layer_tree_host()->root_layer()->SetBounds(gfx::Size(100, 100));
picture_layer_ = CreateAndAddFakePictureLayer(gfx::Size(100, 100));
PostSetNeedsCommitToMainThread();
}
void AfterTest() override {
EXPECT_TRUE(got_commit_after_added_obscuring_layer_);
}
void CommitCompleteOnThread(LayerTreeHostImpl* impl) override {
if (added_obscuring_layer_ && !got_commit_after_added_obscuring_layer_) {
got_commit_after_added_obscuring_layer_ = true;
FakePictureLayerImpl* picture_layer_impl =
static_cast<FakePictureLayerImpl*>(
impl->sync_tree()->LayerById(picture_layer_->id()));
EXPECT_EQ(0u, picture_layer_impl->GetNumberOfTilesWithResources());
EndTest();
}
}
void NotifyTileStateChangedOnThread(LayerTreeHostImpl* host_impl,
const Tile* tile) override {
FakePictureLayerImpl* picture_layer_impl =
static_cast<FakePictureLayerImpl*>(
host_impl->sync_tree()->LayerById(picture_layer_->id()));
EXPECT_EQ(1u, picture_layer_impl->GetNumberOfTilesWithResources());
MainThreadTaskRunner()->PostTask(
FROM_HERE, base::BindOnce(&LayerTreeHostTestOccludedTileReleased::
AddLayerThatObscuresPictureLayer,
base::Unretained(this)));
}
protected:
void AddLayerThatObscuresPictureLayer() {
auto covering_layer = SolidColorLayer::Create();
covering_layer->SetBounds(gfx::Size(100, 100));
covering_layer->SetBackgroundColor(SkColors::kRed);
covering_layer->SetIsDrawable(true);
layer_tree_host()->root_layer()->AddChild(covering_layer);
added_obscuring_layer_ = true;
}
private:
scoped_refptr<FakePictureLayer> picture_layer_;
bool added_obscuring_layer_ = false;
bool got_commit_after_added_obscuring_layer_ = false;
};
SINGLE_THREAD_TEST_F(LayerTreeHostTestOccludedTileReleased);
class LayerTreeHostTestNoCommitDeadlock : public LayerTreeHostTest {
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void WillCommit(const CommitState& commit_state) override {
// Test passes if this doesn't deadlock.
layer_tree_host()->root_layer()->update_rect();
}
void DidCommit() override { EndTest(); }
};
SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoCommitDeadlock);
// In real site, problem happened like this
// 1. commit
// 2. tiling is delayed, so NotifyReadyToActivate is not triggered
// 3. Draw is called and NotifyReadyToActivate is triggered
// during PrepareDraw() by TileManager's CheckForCompletedTask().
// 4. pending_tree()::UpdateDrawProperties() is called after PrepareDraw(),
// and tiling is recreated if transform is changed
// 5. Activation happen right after the Draw
// So tiling with empty tiles will be activated to active tree.
class LayerTreeHostTestDelayRecreateTiling
: public LayerTreeHostTestWithHelper {
public:
LayerTreeHostTestDelayRecreateTiling() {}
void SetupTree() override {
client_.set_fill_with_nonsolid_color(true);
scoped_refptr<FakePictureLayer> root_layer =
FakePictureLayer::Create(&client_);
root_layer->SetBounds(gfx::Size(150, 150));
root_layer->SetIsDrawable(true);
layer_on_main_ =
CreateAndAddFakePictureLayer(gfx::Size(30, 30), root_layer.get());
// initial transform to force transform node
gfx::Transform transform;
transform.Scale(2.0f, 1.0f);
layer_on_main_->SetTransform(transform);
layer_tree_host()->SetRootLayer(root_layer);
LayerTreeHostTest::SetupTree();
client_.set_bounds(root_layer->bounds());
layer_id_ = layer_on_main_->id();
}
void WillCommit(const CommitState&) override {
TransformTree& transform_tree =
layer_tree_host()->property_trees()->transform_tree_mutable();
TransformNode* node =
transform_tree.Node(layer_on_main_->transform_tree_index());
gfx::Transform transform;
transform.Scale(2.0f, 1.0f);
transform.Translate(0.0f, 0.8f);
switch (layer_tree_host()->SourceFrameNumber()) {
case 1:
// in frame1, translation changed and animation start
transform_tree.OnTransformAnimated(layer_on_main_->element_id(),
transform);
node->has_potential_animation = true;
break;
}
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
FakePictureLayerImpl* layer_impl = static_cast<FakePictureLayerImpl*>(
host_impl->pending_tree()->LayerById(layer_id_));
TransformTree& transform_tree =
host_impl->pending_tree()->property_trees()->transform_tree_mutable();
TransformNode* node =
transform_tree.Node(layer_impl->transform_tree_index());
if (host_impl->pending_tree()->source_frame_number() == 2) {
// delay Activation for this pending tree
host_impl->BlockNotifyReadyToActivateForTesting(true);
// to reproduce problem, conditions to recreate tiling should be changed
// after commitcomplete
// e.g., transform change, animation status change
// commitcomplete -> beginimpl -> draw (pending's updatedrawproperties)
// in beginimpl, scroll can be handled, so transform can be changed
// in draw, UpdateAnimationState can change animation status
node->has_potential_animation = false;
transform_tree.set_needs_update(true);
host_impl->pending_tree()->set_needs_update_draw_properties();
// to make sure Draw happen
host_impl->SetNeedsRedraw();
}
}
DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
LayerTreeHostImpl::FrameData* frame_data,
DrawResult draw_result) override {
if (host_impl->pending_tree() &&
host_impl->pending_tree()->source_frame_number() == 2) {
host_impl->BlockNotifyReadyToActivateForTesting(false, false);
// BlockNotifyReadyToActivateForTesting(false) call NotifyReadyToActivate,
// but NotifyReadyToActivate should be called directly instead of PostTask
// because it should called inside PrepareToDraw()
host_impl->NotifyReadyToActivate();
}
return draw_result;
}
void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
FakePictureLayerImpl* layer_impl = static_cast<FakePictureLayerImpl*>(
host_impl->active_tree()->LayerById(layer_id_));
gfx::AxisTransform2d tiling_transform =
layer_impl->HighResTiling()->raster_transform();
switch (host_impl->active_tree()->source_frame_number()) {
case 0:
PostSetNeedsCommitToMainThread();
break;
case 1:
PostSetNeedsCommitToMainThread();
break;
case 2:
if (should_delay_recreating_tiling_) {
// translation is changed in frame2, but recreating tiling should not
// happen because ReadyToActivate is true
ASSERT_EQ(tiling_transform.scale(), gfx::Vector2dF(2.0f, 1.0f));
ASSERT_EQ(tiling_transform.translation(), gfx::Vector2dF(0, 0));
should_delay_recreating_tiling_ = false;
} else {
// Invalidating implside will trigger recreating tiling without next
// commit
ASSERT_EQ(tiling_transform.scale(), gfx::Vector2dF(2.0f, 1.0f));
ASSERT_EQ(tiling_transform.translation(), gfx::Vector2dF(0, 0.8f));
EndTest();
}
break;
case 3:
NOTREACHED() << "We shouldn't see another commit in this test";
}
}
protected:
FakeContentLayerClient client_;
// to access layer information in main and impl
int layer_id_;
// to access layer information in main's WillCommit()
scoped_refptr<FakePictureLayer> layer_on_main_;
bool should_delay_recreating_tiling_ = true;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestDelayRecreateTiling);
// This test validate that recreating tiling is delayed by veto conditions and
// the delayed tiling is created again when the veto conditions are reset.
class LayerTreeHostTestInvalidateImplSideForRerasterTiling
: public LayerTreeHostTestWithHelper {
public:
void SetupTree() override {
client_.set_fill_with_nonsolid_color(true);
scoped_refptr<FakePictureLayer> root_layer =
FakePictureLayer::Create(&client_);
root_layer->SetBounds(gfx::Size(150, 150));
root_layer->SetIsDrawable(true);
layer_on_main_ =
CreateAndAddFakePictureLayer(gfx::Size(30, 30), root_layer.get());
// initial transform to force transform node
gfx::Transform transform;
transform.Scale(2.0f, 1.0f);
layer_on_main_->SetTransform(transform);
layer_tree_host()->SetRootLayer(root_layer);
LayerTreeHostTest::SetupTree();
client_.set_bounds(root_layer->bounds());
layer_id_ = layer_on_main_->id();
}
void WillCommit(const CommitState&) override {
TransformTree& transform_tree =
layer_tree_host()->property_trees()->transform_tree_mutable();
TransformNode* node =
transform_tree.Node(layer_on_main_->transform_tree_index());
gfx::Transform transform;
transform.Scale(2.0f, 1.0f);
transform.Translate(0.0f, 0.8f);
switch (layer_tree_host()->SourceFrameNumber()) {
case 1:
// in frame1, translation changed and animation start
transform_tree.OnTransformAnimated(layer_on_main_->element_id(),
transform);
node->has_potential_animation = true;
break;
}
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void ClearAnimationForLayer(LayerTreeImpl* tree_impl,
FakePictureLayerImpl* layer_impl) {
if (!tree_impl)
return;
TransformTree& transform_tree =
tree_impl->property_trees()->transform_tree_mutable();
TransformNode* node =
transform_tree.Node(layer_impl->transform_tree_index());
node->has_potential_animation = false;
transform_tree.set_needs_update(true);
tree_impl->set_needs_update_draw_properties();
}
TransformNode* TransformNodeForLayer(LayerTreeImpl* tree_impl,
FakePictureLayerImpl* layer_impl) {
TransformTree& transform_tree =
tree_impl->property_trees()->transform_tree_mutable();
TransformNode* node =
transform_tree.Node(layer_impl->transform_tree_index());
return node;
}
void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
if (host_impl->active_tree()->source_frame_number() == 2) {
FakePictureLayerImpl* target_layer = static_cast<FakePictureLayerImpl*>(
host_impl->active_tree()->LayerById(layer_id_));
gfx::AxisTransform2d tiling_transform =
target_layer->HighResTiling()->raster_transform();
TransformNode* node =
TransformNodeForLayer(host_impl->active_tree(), target_layer);
if (node->has_potential_animation) {
// in frame 2, active tree still have old tiling because animation is
// still active.
EXPECT_EQ(tiling_transform.scale(), gfx::Vector2dF(2.0f, 1.0f));
EXPECT_EQ(tiling_transform.translation(), gfx::Vector2dF(0, 0));
// now clear animation and trigger a new draw to check if invalidation
// implside will be requested for rerastering tiling.
ClearAnimationForLayer(host_impl->active_tree(), target_layer);
ClearAnimationForLayer(host_impl->recycle_tree(), target_layer);
host_impl->SetNeedsRedraw();
}
}
}
void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
FakePictureLayerImpl* target_layer = static_cast<FakePictureLayerImpl*>(
host_impl->active_tree()->LayerById(layer_id_));
gfx::AxisTransform2d tiling_transform =
target_layer->HighResTiling()->raster_transform();
TransformNode* node =
TransformNodeForLayer(host_impl->active_tree(), target_layer);
switch (host_impl->active_tree()->source_frame_number()) {
case 0:
PostSetNeedsCommitToMainThread();
break;
case 1:
PostSetNeedsCommitToMainThread();
break;
case 2:
if (node->has_potential_animation) {
// translation is changed in frame2, but recreating tiling should not
// happen because animation is still active.
EXPECT_EQ(tiling_transform.scale(), gfx::Vector2dF(2.0f, 1.0f));
EXPECT_EQ(tiling_transform.translation(), gfx::Vector2dF(0, 0));
// trigger draw to check if invalidating implside is not triggered
// if animation is still active.
host_impl->SetNeedsRedraw();
} else {
// check if invalidation implside was requested successfully.
// new tiling should be created.
EXPECT_EQ(tiling_transform.scale(), gfx::Vector2dF(2.0f, 1.0f));
EXPECT_EQ(tiling_transform.translation(), gfx::Vector2dF(0, 0.8f));
EndTest();
}
break;
}
}
protected:
FakeContentLayerClient client_;
// to access layer information in main and impl
int layer_id_;
// to access layer information in main's WillCommit()
scoped_refptr<FakePictureLayer> layer_on_main_;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestInvalidateImplSideForRerasterTiling);
class LayerTreeHostTestNeedsNotifyReadyToDrawAndActivate
: public LayerTreeHostTest {
public:
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DidCommitAndDrawFrame() override { EndTest(); }
void NotifyReadyToDrawOnThread(LayerTreeHostImpl* host_impl) override {
// called if needs_notify_ready_to_draw_ is true
EXPECT_TRUE(needs_notify_ready_to_draw_);
}
void NotifyReadyToActivateOnThread(LayerTreeHostImpl* host_impl) override {
// called if needs_notify_ready_to_activate_ is true
EXPECT_TRUE(needs_notify_ready_to_activate_);
}
protected:
bool needs_notify_ready_to_draw_ = true;
bool needs_notify_ready_to_activate_ = true;
};
class LayerTreeHostTestNeedsNotifyReadyToDrawOnly
: public LayerTreeHostTestNeedsNotifyReadyToDrawAndActivate {
public:
LayerTreeHostTestNeedsNotifyReadyToDrawOnly() {
// expectation for Single Threaded LayerTreeHost
needs_notify_ready_to_draw_ = true;
needs_notify_ready_to_activate_ = false;
}
};
SINGLE_THREAD_TEST_F(LayerTreeHostTestNeedsNotifyReadyToDrawOnly);
class LayerTreeHostTestNeedsNotifyReadyToActivateOnly
: public LayerTreeHostTestNeedsNotifyReadyToDrawAndActivate {
public:
LayerTreeHostTestNeedsNotifyReadyToActivateOnly() {
// expectation for threaded LayerTreeHost
needs_notify_ready_to_draw_ = false;
needs_notify_ready_to_activate_ = true;
}
};
MULTI_THREAD_TEST_F(LayerTreeHostTestNeedsNotifyReadyToActivateOnly);
class LayerTreeHostTestDidCommitAndDrawFrame : public LayerTreeHostTest {
public:
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DidCommitAndDrawFrame() override { EXPECT_EQ(0, num_draws_); }
void DidReceivePresentationTimeOnThread(
LayerTreeHostImpl* host_impl,
uint32_t frame_token,
const gfx::PresentationFeedback& feedback) override {
++num_draws_;
if (num_draws_ == 2) {
EndTest();
} else {
host_impl->SetViewportDamage(gfx::Rect(1, 1));
host_impl->RequestImplSideInvalidationForRerasterTiling();
}
}
void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
EXPECT_EQ(0, host_impl->active_tree()->source_frame_number());
}
protected:
int num_draws_ = 0;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestDidCommitAndDrawFrame);
class LayerTreeHostTestBeginFramePausedChanged : public LayerTreeHostTest {
protected:
void SetupTree() override {
scoped_refptr<Layer> root = Layer::Create();
root->SetBounds(gfx::Size(10, 10));
layer_tree_host()->SetRootLayer(std::move(root));
LayerTreeHostTest::SetupTree();
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void ReadyToCommitOnThread(LayerTreeHostImpl* host_impl) override {
switch (host_impl->active_tree()->source_frame_number()) {
// frame 1 is ready in main thread and main thread is waiting until
// commit complete in impl thread
case 0:
// this should trigger OnBeginFramePausedChanged(true) callback, so that
// scheduler can abort the pending commit job
layer_tree_frame_sink_->UnregisterBeginFrameSource();
break;
}
}
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
switch (host_impl->pending_tree()->source_frame_number()) {
case 1:
// Scheduler abort the pending commit job successfully
EndTest();
break;
}
}
void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
switch (host_impl->active_tree()->source_frame_number()) {
case 0:
// Block activation of pedning tree which is created by implside
// invalidation. This is for making ShouldCommit() return false.
host_impl->BlockNotifyReadyToActivateForTesting(true);
// next commit can start only if pending tree was created by implside
// invalidation.
host_impl->RequestImplSideInvalidationForRerasterTiling();
break;
}
}
void DidInvalidateContentOnImplSide(LayerTreeHostImpl* host_impl) override {
switch (host_impl->active_tree()->source_frame_number()) {
case 0:
// has_pending_tree_ is true now, so we can request next frame which
// will be stuck in main thread because has_pending_tree_ == true block
// commit process.
PostSetNeedsCommitToMainThread();
break;
}
}
std::unique_ptr<TestLayerTreeFrameSink> CreateLayerTreeFrameSink(
const viz::RendererSettings& renderer_settings,
double refresh_rate,
scoped_refptr<viz::RasterContextProvider> compositor_context_provider,
scoped_refptr<viz::RasterContextProvider> worker_context_provider)
override {
std::unique_ptr<TestLayerTreeFrameSink> frame_sink =
LayerTreeHostTest::CreateLayerTreeFrameSink(
renderer_settings, refresh_rate,
std::move(compositor_context_provider),
std::move(worker_context_provider));
layer_tree_frame_sink_ = frame_sink.get();
return frame_sink;
}
private:
raw_ptr<TestLayerTreeFrameSink, DanglingUntriaged> layer_tree_frame_sink_;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestBeginFramePausedChanged);
class LayerTreeHostUpdateViewportContainerSize : public LayerTreeHostTest {
public:
LayerTreeHostUpdateViewportContainerSize() { SetUseLayerLists(); }
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void SetupTree() override {
LayerTreeHostTest::SetupTree();
Layer* root_layer = layer_tree_host()->root_layer();
// Set up scrollable root.
root_layer->SetBounds(gfx::Size(100, 100));
SetupViewport(root_layer, gfx::Size(50, 50), root_layer->bounds());
layer_tree_host()->SetPageScaleFactorAndLimits(1.f, 1.f, 1.f);
layer_tree_host()->SetBrowserControlsParams(
{kTopControlsHeight, 0, kBottomControlsHeight, 0, false /* animate */,
true /* shrink */});
top_shown_ratio_ = 1.f;
bottom_shown_ratio_ = 1.f;
layer_tree_host()->SetBrowserControlsShownRatio(top_shown_ratio_,
bottom_shown_ratio_);
}
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
// The propertytree in main does not compute the bounds_delta, so main
// always copy 0 to bounds_delta. Let's check if bounds_delta is computed
// correctly in pending by UpdateViewportContainerSize().
gfx::Vector2dF pending_bounds_delta =
host_impl->pending_tree()
->property_trees()
->inner_viewport_container_bounds_delta();
gfx::Vector2dF active_bounds_delta =
host_impl->active_tree()
->property_trees()
->inner_viewport_container_bounds_delta();
switch (host_impl->pending_tree()->source_frame_number()) {
case 1:
case 2:
case 3:
case 4:
EXPECT_EQ(pending_bounds_delta, active_bounds_delta);
if (host_impl->pending_tree()->source_frame_number() == 4)
EndTest();
break;
}
}
void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
// change the shownratio in active and check if it's applied to pending
switch (host_impl->active_tree()->source_frame_number()) {
case 0:
host_impl->SetCurrentBrowserControlsShownRatio(0.5f, 0.5f);
break;
case 1:
host_impl->SetCurrentBrowserControlsShownRatio(0.f, 0.f);
break;
case 2:
host_impl->SetCurrentBrowserControlsShownRatio(0.3f, 0.3f);
break;
case 3:
host_impl->SetCurrentBrowserControlsShownRatio(1.f, 1.f);
break;
}
PostSetNeedsCommitToMainThread();
}
void ApplyViewportChanges(const ApplyViewportChangesArgs& args) override {
top_shown_ratio_ += args.top_controls_delta;
bottom_shown_ratio_ += args.bottom_controls_delta;
layer_tree_host()->SetBrowserControlsShownRatio(top_shown_ratio_,
bottom_shown_ratio_);
}
static constexpr float kTopControlsHeight = 10.0f;
static constexpr float kBottomControlsHeight = 10.0f;
float top_shown_ratio_;
float bottom_shown_ratio_;
};
MULTI_THREAD_TEST_F(LayerTreeHostUpdateViewportContainerSize);
// Ensures that a change in LCD text status forces tilings to be recreated on
// the pending tree even during accelerated gestures (scrolling and pinch zoom)
// and animations.
class LayerTreeHostTestForceRecreateTilingForLCDText
: public LayerTreeHostTestWithHelper {
public:
LayerTreeHostTestForceRecreateTilingForLCDText() {}
void SetupTree() override {
client_.set_fill_with_nonsolid_color(true);
client_.set_has_draw_text_op();
scoped_refptr<FakePictureLayer> root_layer =
FakePictureLayer::Create(&client_);
root_layer->SetBounds(gfx::Size(150, 150));
root_layer->SetIsDrawable(true);
layer_on_main_ =
CreateAndAddFakePictureLayer(gfx::Size(30, 30), root_layer.get());
layer_tree_host()->SetRootLayer(root_layer);
LayerTreeHostTest::SetupTree();
client_.set_bounds(root_layer->bounds());
layer_id_ = layer_on_main_->id();
}
void OnCommitRequested() override {
switch (layer_tree_host()->SourceFrameNumber()) {
case 0:
// First frame enables LCD text by marking the layer opaque.
layer_on_main_->SetContentsOpaque(true);
layer_on_main_->SetBackgroundColor(SkColor4f::FromColor(SK_ColorBLACK));
break;
case 1:
// Now mark the layer non-opaque to disable LCD text.
layer_on_main_->SetContentsOpaque(false);
break;
case 2:
// Back to LCD text.
layer_on_main_->SetContentsOpaque(true);
break;
case 3:
// Disable LCD text from non-opaque background.
layer_on_main_->SetContentsOpaque(false);
layer_on_main_->SetBackgroundColor(
SkColor4f::FromColor(SK_ColorTRANSPARENT));
break;
}
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
FakePictureLayerImpl* layer_impl = static_cast<FakePictureLayerImpl*>(
host_impl->pending_tree()->LayerById(layer_id_));
switch (host_impl->pending_tree()->source_frame_number()) {
case 0:
ASSERT_FALSE(host_impl->IsPinchGestureActive());
EXPECT_TRUE(layer_impl->can_use_lcd_text());
EXPECT_TRUE(layer_impl->HighResTiling()->can_use_lcd_text());
host_impl->GetInputHandler().PinchGestureBegin(
gfx::Point(1, 1), ui::ScrollInputType::kWheel);
PostSetNeedsCommitToMainThread();
break;
case 1:
ASSERT_TRUE(host_impl->IsPinchGestureActive());
EXPECT_FALSE(layer_impl->can_use_lcd_text());
EXPECT_EQ(layer_impl->lcd_text_disallowed_reason(),
LCDTextDisallowedReason::kContentsNotOpaque);
EXPECT_FALSE(layer_impl->HighResTiling()->can_use_lcd_text());
host_impl->GetInputHandler().PinchGestureEnd(gfx::Point(1, 1));
PostSetNeedsCommitToMainThread();
break;
case 2:
ASSERT_FALSE(host_impl->IsPinchGestureActive());
EXPECT_TRUE(layer_impl->can_use_lcd_text());
EXPECT_TRUE(layer_impl->HighResTiling()->can_use_lcd_text());
host_impl->GetInputHandler().PinchGestureBegin(
gfx::Point(1, 1), ui::ScrollInputType::kWheel);
PostSetNeedsCommitToMainThread();
break;
case 3:
ASSERT_TRUE(host_impl->IsPinchGestureActive());
EXPECT_FALSE(layer_impl->can_use_lcd_text());
EXPECT_EQ(layer_impl->lcd_text_disallowed_reason(),
LCDTextDisallowedReason::kBackgroundColorNotOpaque);
EXPECT_FALSE(layer_impl->HighResTiling()->can_use_lcd_text());
EndTest();
break;
}
}
protected:
// main and impl thread.
int layer_id_;
// main thread only
FakeContentLayerClient client_;
scoped_refptr<FakePictureLayer> layer_on_main_;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestForceRecreateTilingForLCDText);
class LayerTreeHostTestDamagePropagatesFromViewTransitionSurface
: public LayerTreeHostTest {
public:
LayerTreeHostTestDamagePropagatesFromViewTransitionSurface() {
SetUseLayerLists();
}
void BeginMainFrame(const viz::BeginFrameArgs& args) override {
switch (layer_tree_host()->SourceFrameNumber()) {
case 0:
break;
case 1:
// Damage unrelated layer and ensure that no other content is damaged.
unrelated_layer_->SetNeedsDisplayRect(gfx::Rect(0, 0, 5, 5));
break;
case 2:
// Damage view transition layer, ensure that the contributing VT pass
// is not redrawn.
view_transition_layer_->SetNeedsDisplayRect(gfx::Rect(0, 0, 5, 5));
break;
case 3:
// Damage layer which generates VT content. Ensure it propagates to VT
// layer's target.
layer_with_view_transition_content_->SetNeedsDisplayRect(
gfx::Rect(0, 0, 5, 5));
}
}
void SetupTree() override {
SetInitialRootBounds(root_rect_.size());
LayerTreeHostTest::SetupTree();
auto* root = layer_tree_host()->root_layer();
layer_with_view_transition_content_ = SolidColorLayer::Create();
CopyProperties(root, layer_with_view_transition_content_.get());
layer_with_view_transition_content_->SetIsDrawable(true);
layer_with_view_transition_content_->SetBackgroundColor(
SkColor4f::FromColor(SK_ColorBLUE));
layer_with_view_transition_content_->SetBounds(
layer_with_view_transition_content_rect_.size());
layer_with_view_transition_content_->SetOffsetToTransformParent(
layer_with_view_transition_content_rect_.OffsetFromOrigin());
root->AddChild(layer_with_view_transition_content_);
blink::ViewTransitionToken transition_token;
resource_id_ = viz::ViewTransitionElementResourceId(transition_token, 1);
view_transition_layer_ = ViewTransitionContentLayer::Create(
resource_id_, /*is_live_content_layer=*/true);
CopyProperties(root, view_transition_layer_.get());
view_transition_layer_->SetIsDrawable(true);
view_transition_layer_->SetBounds(view_transition_layer_rect_.size());
view_transition_layer_->SetOffsetToTransformParent(
view_transition_layer_rect_.OffsetFromOrigin());
root->AddChild(view_transition_layer_);
unrelated_layer_ = SolidColorLayer::Create();
CopyProperties(root, unrelated_layer_.get());
unrelated_layer_->SetIsDrawable(true);
unrelated_layer_->SetBounds(unrelated_layer_rect_.size());
unrelated_layer_->SetOffsetToTransformParent(
unrelated_layer_rect_.OffsetFromOrigin());
unrelated_layer_->SetBackgroundColor(SkColor4f::FromColor(SK_ColorRED));
root->AddChild(unrelated_layer_);
auto& layer_with_view_transition_content_node = CreateEffectNode(
layer_with_view_transition_content_.get(), kContentsRootPropertyNodeId);
layer_with_view_transition_content_->SetEffectTreeIndex(
layer_with_view_transition_content_node.id);
layer_with_view_transition_content_node
.view_transition_element_resource_id = resource_id_;
layer_with_view_transition_content_node.render_surface_reason =
RenderSurfaceReason::kViewTransitionParticipant;
auto& view_transition_layer_node = CreateEffectNode(
view_transition_layer_.get(), kContentsRootPropertyNodeId);
view_transition_layer_->SetEffectTreeIndex(view_transition_layer_node.id);
view_transition_layer_node.render_surface_reason =
RenderSurfaceReason::kBlendMode;
}
void BeginTest() override { layer_tree_host()->SetNeedsCommit(); }
void WillSubmitCompositorFrame(LayerTreeHostImpl* host_impl,
const viz::CompositorFrame& frame) override {
switch (host_impl->active_tree()->source_frame_number()) {
case 0: {
// First frame draws the entire tree with full damage.
ASSERT_EQ(frame.render_pass_list.size(), 3u);
const auto& vt_content_pass = frame.render_pass_list.at(0);
EXPECT_EQ(vt_content_pass->view_transition_element_resource_id,
resource_id_);
EXPECT_EQ(vt_content_pass->output_rect,
layer_with_view_transition_content_rect_);
EXPECT_TRUE(vt_content_pass->has_damage_from_contributing_content);
const auto& vt_layer_pass = frame.render_pass_list.at(1);
EXPECT_FALSE(
vt_layer_pass->view_transition_element_resource_id.IsValid());
EXPECT_EQ(vt_layer_pass->output_rect, view_transition_layer_rect_);
EXPECT_TRUE(vt_layer_pass->has_damage_from_contributing_content);
const auto& root_pass = frame.render_pass_list.back();
EXPECT_EQ(root_pass->damage_rect, root_rect_);
PostSetNeedsCommitToMainThread();
break;
}
case 1: {
// Second frame only damages unrelated layer.
ASSERT_EQ(frame.render_pass_list.size(), 3u);
const auto& vt_content_pass = frame.render_pass_list.at(0);
EXPECT_EQ(vt_content_pass->view_transition_element_resource_id,
resource_id_);
EXPECT_EQ(vt_content_pass->output_rect,
layer_with_view_transition_content_rect_);
EXPECT_FALSE(vt_content_pass->has_damage_from_contributing_content);
const auto& vt_layer_pass = frame.render_pass_list.at(1);
EXPECT_EQ(vt_layer_pass->output_rect, view_transition_layer_rect_);
EXPECT_FALSE(vt_layer_pass->has_damage_from_contributing_content);
const auto& root_pass = frame.render_pass_list.back();
EXPECT_EQ(root_pass->damage_rect,
gfx::Rect(unrelated_layer_rect_.origin(), gfx::Size(5, 5)));
PostSetNeedsCommitToMainThread();
break;
}
case 2: {
// Third frame only damages the VT layer.
ASSERT_EQ(frame.render_pass_list.size(), 3u);
const auto& vt_content_pass = frame.render_pass_list.at(0);
EXPECT_EQ(vt_content_pass->view_transition_element_resource_id,
resource_id_);
EXPECT_EQ(vt_content_pass->output_rect,
layer_with_view_transition_content_rect_);
EXPECT_FALSE(vt_content_pass->has_damage_from_contributing_content);
const auto& vt_layer_pass = frame.render_pass_list.at(1);
EXPECT_EQ(vt_layer_pass->output_rect, view_transition_layer_rect_);
EXPECT_TRUE(vt_layer_pass->has_damage_from_contributing_content);
const auto& root_pass = frame.render_pass_list.back();
EXPECT_EQ(
root_pass->damage_rect,
gfx::Rect(view_transition_layer_rect_.origin(), gfx::Size(5, 5)));
PostSetNeedsCommitToMainThread();
break;
}
case 3: {
// Last frame damages the layer contributing to VT.
ASSERT_EQ(frame.render_pass_list.size(), 3u);
const auto& vt_content_pass = frame.render_pass_list.at(0);
EXPECT_EQ(vt_content_pass->view_transition_element_resource_id,
resource_id_);
EXPECT_EQ(vt_content_pass->output_rect,
layer_with_view_transition_content_rect_);
EXPECT_TRUE(vt_content_pass->has_damage_from_contributing_content);
const auto& vt_layer_pass = frame.render_pass_list.at(1);
EXPECT_EQ(vt_layer_pass->output_rect, view_transition_layer_rect_);
EXPECT_TRUE(vt_layer_pass->has_damage_from_contributing_content);
const auto& root_pass = frame.render_pass_list.back();
// TODO(khushalsagar): We shouldn't be damaging the area where
// layer_with_view_transition_content_ draws since the content is
// is instead drawn by view_transition_layer_.
gfx::Rect total_damage(
layer_with_view_transition_content_rect_.origin(), gfx::Size(5, 5));
total_damage.Union(
gfx::Rect(view_transition_layer_rect_.origin(), gfx::Size(5, 5)));
EXPECT_EQ(root_pass->damage_rect, total_damage);
EndTest();
break;
}
default:
break;
}
}
private:
scoped_refptr<SolidColorLayer> unrelated_layer_;
viz::ViewTransitionElementResourceId resource_id_;
scoped_refptr<ViewTransitionContentLayer> view_transition_layer_;
scoped_refptr<SolidColorLayer> layer_with_view_transition_content_;
// All rects are in the root coordinate space.
const gfx::Rect root_rect_ = gfx::Rect(0, 0, 50, 50);
const gfx::Rect layer_with_view_transition_content_rect_ =
gfx::Rect(0, 0, 10, 10);
const gfx::Rect view_transition_layer_rect_ = gfx::Rect(20, 20, 10, 10);
const gfx::Rect unrelated_layer_rect_ = gfx::Rect(40, 40, 10, 10);
};
MULTI_THREAD_TEST_F(LayerTreeHostTestDamagePropagatesFromViewTransitionSurface);
class LayerTreeHostTestBlockOnCommitAfterInputEvent : public LayerTreeHostTest {
protected:
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void WillBeginMainFrame() override { ++main_frame_num_; }
void DidBeginMainFrame() override {
EXPECT_EQ(main_frame_num_ % 2 != 0,
layer_tree_host()->MustWaitForCommitForTesting());
}
void DidCommit() override {
if (main_frame_num_ < 5) {
layer_tree_host()->SetNeedsCommit();
if (main_frame_num_ % 2) {
layer_tree_host()->proxy()->SetInputResponsePending();
}
} else {
EndTest();
}
}
private:
uint32_t main_frame_num_ = 0u;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestBlockOnCommitAfterInputEvent);
class LayerTreeHostTestDetachInputDelegateAndRenderFrameObserver
: public LayerTreeTest,
StubInputHandlerClient {
public:
void BeginTest() override {
impl_task_runner_ =
layer_tree_host()->GetTaskRunnerProvider()->ImplThreadTaskRunner();
layer_tree_host()->SetRenderFrameObserver(
std::make_unique<FakeRenderFrameMetadataObserver>(this));
CompletionEvent event;
impl_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
&LayerTreeHostTestDetachInputDelegateAndRenderFrameObserver::
SetUpInputHandlerOnImpl,
base::Unretained(this), base::Unretained(&event),
layer_tree_host()->GetDelegateForInput()));
event.Wait();
PostSetNeedsCommitToMainThread();
}
void DidCommit() override {
layer_tree_host()->DetachInputDelegateAndRenderFrameObserver();
CompletionEvent event;
impl_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
&LayerTreeHostTestDetachInputDelegateAndRenderFrameObserver::
AssertDestroyedOnImpl,
base::Unretained(this), base::Unretained(&event)));
event.Wait();
EndTest();
}
private:
class FakeRenderFrameMetadataObserver : public RenderFrameMetadataObserver {
public:
FakeRenderFrameMetadataObserver(
LayerTreeHostTestDetachInputDelegateAndRenderFrameObserver* test)
: test_(test) {}
~FakeRenderFrameMetadataObserver() override {
CHECK(is_bound_);
CHECK(!test_->did_shutdown_render_frame_observer_);
test_->did_shutdown_render_frame_observer_ = true;
}
void BindToCurrentSequence() override {
CHECK(!is_bound_);
is_bound_ = true;
}
void OnRenderFrameSubmission(
const RenderFrameMetadata& render_frame_metadata,
viz::CompositorFrameMetadata* compositor_frame_metadata,
bool force_send) override {}
#if BUILDFLAG(IS_ANDROID)
void DidEndScroll() override {}
#endif
private:
raw_ptr<LayerTreeHostTestDetachInputDelegateAndRenderFrameObserver> test_;
bool is_bound_ = false;
};
// InputHandlerClient implementation, invoked on impl thread.
void WillShutdown() override {
CHECK(impl_task_runner_->BelongsToCurrentThread());
EXPECT_FALSE(did_shutdown_input_handler_);
did_shutdown_input_handler_ = true;
}
void SetUpInputHandlerOnImpl(
CompletionEvent* event,
base::WeakPtr<CompositorDelegateForInput> compositor_delegate) {
CHECK(compositor_delegate);
base::WeakPtr<InputHandler> input_handler =
InputHandler::Create(*compositor_delegate);
CHECK(input_handler);
input_handler->BindToClient(this);
event->Signal();
}
void AssertDestroyedOnImpl(CompletionEvent* event) {
EXPECT_TRUE(did_shutdown_input_handler_);
EXPECT_TRUE(did_shutdown_render_frame_observer_);
event->Signal();
}
// Can be accessed on both threads.
scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner_;
// Accessed only on the impl thread.
bool did_shutdown_input_handler_ = false;
bool did_shutdown_render_frame_observer_ = false;
};
MULTI_THREAD_TEST_F(LayerTreeHostTestDetachInputDelegateAndRenderFrameObserver);
class LayerTreeHostTestSetMaxSafeAreaInsets : public LayerTreeHostTest {
public:
LayerTreeHostTestSetMaxSafeAreaInsets() : LayerTreeHostTest() {}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void SetupTree() override {
LayerTreeHostTest::SetupTree();
gfx::InsetsF insets(10);
insets.set_bottom(20);
layer_tree_host()->SetMaxSafeAreaInsets(insets);
}
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
EXPECT_EQ(20, host_impl->pending_tree()->max_safe_area_inset_bottom());
host_impl->pending_tree()->PushPropertiesTo(host_impl->active_tree());
EXPECT_EQ(20, host_impl->active_tree()->max_safe_area_inset_bottom());
EndTest();
}
};
MULTI_THREAD_TEST_F(LayerTreeHostTestSetMaxSafeAreaInsets);
} // namespace
} // namespace cc