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
|
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <drm_fourcc.h>
#include <overlay-prioritizer-client-protocol.h>
#include <cstdint>
#include <memory>
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/test/mock_callback.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/geometry/rounded_corners_f.h"
#include "ui/gfx/geometry/rrect_f.h"
#include "ui/gfx/gpu_fence_handle.h"
#include "ui/gfx/linux/drm_util_linux.h"
#include "ui/gfx/overlay_priority_hint.h"
#include "ui/gfx/presentation_feedback.h"
#include "ui/ozone/platform/wayland/common/wayland_overlay_config.h"
#include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.h"
#include "ui/ozone/platform/wayland/gpu/wayland_surface_gpu.h"
#include "ui/ozone/platform/wayland/host/wayland_buffer_factory.h"
#include "ui/ozone/platform/wayland/host/wayland_buffer_manager_host.h"
#include "ui/ozone/platform/wayland/host/wayland_connection.h"
#include "ui/ozone/platform/wayland/host/wayland_frame_manager.h"
#include "ui/ozone/platform/wayland/host/wayland_subsurface.h"
#include "ui/ozone/platform/wayland/host/wayland_zwp_linux_dmabuf.h"
#include "ui/ozone/platform/wayland/test/mock_surface.h"
#include "ui/ozone/platform/wayland/test/mock_zwp_linux_dmabuf.h"
#include "ui/ozone/platform/wayland/test/test_overlay_prioritized_surface.h"
#include "ui/ozone/platform/wayland/test/test_zwp_linux_buffer_params.h"
#include "ui/ozone/platform/wayland/test/wayland_test.h"
#include "ui/platform_window/platform_window_init_properties.h"
using testing::_;
using testing::Truly;
using testing::Values;
namespace ui {
namespace {
using MockTerminateGpuCallback =
base::MockCallback<base::OnceCallback<void(std::string)>>;
constexpr gfx::Size kDefaultSize(1024, 768);
// TODO(msisov): add a test to exercise buffer management with non-default scale
// once all the patches land.
constexpr float kDefaultScale = 1.f;
struct InputData {
bool has_file = false;
gfx::Size size;
uint32_t planes_count = 0;
std::vector<uint32_t> strides;
std::vector<uint32_t> offsets;
std::vector<uint64_t> modifiers;
uint32_t format = 0;
uint32_t buffer_id = 0;
};
class MockSurfaceGpu : public WaylandSurfaceGpu {
public:
MockSurfaceGpu(WaylandBufferManagerGpu* buffer_manager,
gfx::AcceleratedWidget widget)
: buffer_manager_(buffer_manager), widget_(widget) {
buffer_manager_->RegisterSurface(widget_, this);
}
MockSurfaceGpu(const MockSurfaceGpu&) = delete;
MockSurfaceGpu& operator=(const MockSurfaceGpu&) = delete;
~MockSurfaceGpu() override { buffer_manager_->UnregisterSurface(widget_); }
MOCK_METHOD3(OnSubmission,
void(uint32_t buffer_id,
const gfx::SwapResult& swap_result,
gfx::GpuFenceHandle release_fence));
MOCK_METHOD2(OnPresentation,
void(uint32_t buffer_id,
const gfx::PresentationFeedback& feedback));
private:
const raw_ptr<WaylandBufferManagerGpu> buffer_manager_;
const gfx::AcceleratedWidget widget_;
};
} // namespace
class WaylandBufferManagerTest : public WaylandTest {
public:
WaylandBufferManagerTest() = default;
WaylandBufferManagerTest(const WaylandBufferManagerTest&) = delete;
WaylandBufferManagerTest& operator=(const WaylandBufferManagerTest&) = delete;
~WaylandBufferManagerTest() override = default;
void SetUp() override {
// Viewport surface scaling is only checked once on surface creation and
// persisted, so we must make sure the configuration is done before we
// create the surface.
connection_->set_supports_viewporter_surface_scaling(
GetParam().supports_viewporter_surface_scaling);
WaylandTest::SetUp();
manager_host_ = connection_->buffer_manager_host();
EXPECT_TRUE(manager_host_);
// Use the helper methods below, which automatically set the termination
// callback and bind the interface again if the manager failed.
manager_host_->SetTerminateGpuCallback(callback_.Get());
auto interface_ptr = manager_host_->BindInterface();
buffer_manager_gpu_->Initialize(std::move(interface_ptr), {},
/*supports_dma_buf=*/false,
/*supports_viewporter=*/true,
/*supports_acquire_fence=*/false,
/*supports_overlays=*/true,
/*supports_single_pixel_buffer=*/true);
surface_id_ = window_->root_surface()->get_surface_id();
}
void TearDown() override {
// MockGpuSurface will unregister itself from the WaylandBuffermanagerGpu,
// which will remove objects associated with this surface on another thread.
// This run loop gives it a chance to do that.
base::RunLoop().RunUntilIdle();
WaylandTest::TearDown();
}
protected:
void SendFrameCallbackForSurface(uint32_t surface_id) {
PostToServerAndWait([surface_id](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(surface_id);
ASSERT_TRUE(mock_surface);
mock_surface->SendFrameCallback();
});
}
// Might be null. Make sure to not manipulate the returned resource on the
// client thread. Though, if the client does that, the server is able to catch
// calls for libwayland-server on a wrong thread.
wl_resource* GetSurfaceAttachedBuffer(uint32_t surface_id) {
wl_resource* wl_buffer = nullptr;
PostToServerAndWait(
[&wl_buffer, surface_id](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(surface_id);
ASSERT_TRUE(mock_surface);
wl_buffer = mock_surface->attached_buffer();
});
return wl_buffer;
}
base::ScopedFD MakeFD() {
base::FilePath temp_path;
EXPECT_TRUE(base::CreateTemporaryFile(&temp_path));
auto file =
base::File(temp_path, base::File::FLAG_READ | base::File::FLAG_WRITE |
base::File::FLAG_CREATE_ALWAYS);
return base::ScopedFD(file.TakePlatformFile());
}
// Sets the terminate gpu callback expectation, calls OnChannelDestroyed,
// sets the same callback again and re-establishes mojo connection again
// for convenience.
void SetTerminateCallbackExpectationAndDestroyChannel(
MockTerminateGpuCallback* callback,
bool fail) {
channel_destroyed_error_message_.clear();
if (!fail) {
// To avoid warning messages as "Expected to be never called, but has 0
// WillOnce()s", split the expecations based on the expected call times.
EXPECT_CALL(*callback, Run(_)).Times(0);
} else {
EXPECT_CALL(*callback, Run(_))
.Times(1)
.WillRepeatedly(
::testing::Invoke([this, callback](std::string error_string) {
channel_destroyed_error_message_ = error_string;
manager_host_->OnChannelDestroyed();
manager_host_->SetTerminateGpuCallback(callback->Get());
auto interface_ptr = manager_host_->BindInterface();
// Recreate the gpu side manager (the production code does the
// same).
buffer_manager_gpu_ =
std::make_unique<WaylandBufferManagerGpu>();
buffer_manager_gpu_->Initialize(
std::move(interface_ptr), {},
/*supports_dma_buf=*/false,
/*supports_viewporter=*/true,
/*supports_acquire_fence=*/false,
/*supports_overlays=*/true,
/*supports_single_pixel_buffer=*/true);
}));
}
}
void CreateDmabufBasedBufferAndSetTerminateExpectation(
bool fail,
uint32_t buffer_id,
base::ScopedFD fd = base::ScopedFD(),
const gfx::Size& size = kDefaultSize,
const std::vector<uint32_t>& strides = {1},
const std::vector<uint32_t>& offsets = {2},
const std::vector<uint64_t>& modifiers = {3},
uint32_t format = DRM_FORMAT_R8,
uint32_t planes_count = 1) {
if (!fd.is_valid())
fd = MakeFD();
SetTerminateCallbackExpectationAndDestroyChannel(&callback_, fail);
buffer_manager_gpu_->CreateDmabufBasedBuffer(
std::move(fd), kDefaultSize, strides, offsets, modifiers, format,
planes_count, buffer_id);
base::RunLoop().RunUntilIdle();
}
void CreateShmBasedBufferAndSetTerminateExpecation(
bool fail,
uint32_t buffer_id,
const gfx::Size& size = kDefaultSize,
size_t length = 0) {
SetTerminateCallbackExpectationAndDestroyChannel(&callback_, fail);
if (!length)
length = size.width() * size.height() * 4;
buffer_manager_gpu_->CreateShmBasedBuffer(MakeFD(), length, size,
buffer_id);
base::RunLoop().RunUntilIdle();
}
void DestroyBufferAndSetTerminateExpectation(uint32_t buffer_id, bool fail) {
SetTerminateCallbackExpectationAndDestroyChannel(&callback_, fail);
buffer_manager_gpu_->DestroyBuffer(buffer_id);
base::RunLoop().RunUntilIdle();
}
void ProcessCreatedBufferResourcesWithExpectation(size_t expected_size,
bool fail) {
PostToServerAndWait(
[expected_size, fail](wl::TestWaylandServerThread* server) {
auto params_vector = server->zwp_linux_dmabuf_v1()->buffer_params();
// To ensure, no other buffers are created, test the size of the
// vector.
EXPECT_EQ(params_vector.size(), expected_size);
for (wl::TestZwpLinuxBufferParamsV1* mock_params : params_vector) {
if (!fail) {
zwp_linux_buffer_params_v1_send_created(
mock_params->resource(), mock_params->buffer_resource());
} else {
zwp_linux_buffer_params_v1_send_failed(mock_params->resource());
}
}
});
}
std::unique_ptr<WaylandWindow> CreateWindow(
PlatformWindowType type = PlatformWindowType::kWindow,
gfx::AcceleratedWidget parent_widget = gfx::kNullAcceleratedWidget) {
testing::Mock::VerifyAndClearExpectations(&delegate_);
PlatformWindowInitProperties properties;
properties.bounds = gfx::Rect(0, 0, 800, 600);
properties.type = type;
properties.parent_widget = parent_widget;
auto new_window =
delegate_.CreateWaylandWindow(connection_.get(), std::move(properties));
EXPECT_TRUE(new_window);
WaylandTestBase::SyncDisplay();
EXPECT_NE(new_window->GetWidget(), gfx::kNullAcceleratedWidget);
return new_window;
}
wl::WaylandOverlayConfig CreateBasicWaylandOverlayConfig(
int z_order,
uint32_t buffer_id,
const gfx::Rect& bounds_rect) {
return CreateBasicWaylandOverlayConfig(z_order, buffer_id,
gfx::RectF(bounds_rect));
}
wl::WaylandOverlayConfig CreateBasicWaylandOverlayConfig(
int z_order,
uint32_t buffer_id,
const gfx::RectF& bounds_rect) {
wl::WaylandOverlayConfig config;
config.z_order = z_order;
config.buffer_id = buffer_id;
config.bounds_rect = bounds_rect;
config.damage_region = gfx::ToEnclosedRect(bounds_rect);
return config;
}
void CommitBuffer(gfx::AcceleratedWidget widget,
uint32_t frame_id,
uint32_t buffer_id,
gfx::FrameData data,
const gfx::Rect& bounds_rect,
const gfx::RoundedCornersF& corners,
float surface_scale_factor,
const gfx::Rect& damage_region) {
buffer_manager_gpu_->CommitBuffer(
widget, frame_id, buffer_id, data, bounds_rect, /*enable_blend=*/false,
corners, surface_scale_factor, damage_region);
// Let the mojo message to be processed.
base::RunLoop().RunUntilIdle();
}
MockTerminateGpuCallback callback_;
raw_ptr<WaylandBufferManagerHost> manager_host_;
// Error message that is received when the manager_host destroys the channel.
std::string channel_destroyed_error_message_;
uint32_t surface_id_ = 0u;
};
TEST_P(WaylandBufferManagerTest, CreateDmabufBasedBuffers) {
constexpr uint32_t kDmabufBufferId = 1;
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/,
kDmabufBufferId);
DestroyBufferAndSetTerminateExpectation(kDmabufBufferId, false /*fail*/);
}
TEST_P(WaylandBufferManagerTest, VerifyModifiers) {
constexpr uint32_t kDmabufBufferId = 1;
constexpr uint32_t kFourccFormatR8 = DRM_FORMAT_R8;
constexpr uint64_t kFormatModiferLinear = DRM_FORMAT_MOD_LINEAR;
const std::vector<uint64_t> kFormatModifiers{DRM_FORMAT_MOD_INVALID,
kFormatModiferLinear};
// Tests that fourcc format is added, but invalid modifier is ignored first.
// Then, when valid modifier comes, it is stored.
for (const auto& modifier : kFormatModifiers) {
PostToServerAndWait([modifier](wl::TestWaylandServerThread* server) {
uint32_t modifier_hi = modifier >> 32;
uint32_t modifier_lo = modifier & UINT32_MAX;
zwp_linux_dmabuf_v1_send_modifier(
server->zwp_linux_dmabuf_v1()->resource(), kFourccFormatR8,
modifier_hi, modifier_lo);
});
auto buffer_formats =
connection_->buffer_factory()->GetSupportedBufferFormats();
ASSERT_EQ(buffer_formats.size(), 1u);
ASSERT_EQ(buffer_formats.begin()->first,
GetBufferFormatFromFourCCFormat(kFourccFormatR8));
auto modifiers = buffer_formats.begin()->second;
if (modifier == DRM_FORMAT_MOD_INVALID) {
ASSERT_EQ(modifiers.size(), 0u);
} else {
ASSERT_EQ(modifiers.size(), 1u);
ASSERT_EQ(modifiers[0], modifier);
}
}
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(
false /*fail*/, kDmabufBufferId, base::ScopedFD(), kDefaultSize, {1}, {2},
{kFormatModiferLinear}, kFourccFormatR8, 1);
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
auto params_vector = server->zwp_linux_dmabuf_v1()->buffer_params();
EXPECT_EQ(params_vector.size(), 1u);
EXPECT_EQ(params_vector[0]->modifier_hi_, kFormatModiferLinear >> 32);
EXPECT_EQ(params_vector[0]->modifier_lo_,
kFormatModiferLinear & UINT32_MAX);
});
// Clean up.
DestroyBufferAndSetTerminateExpectation(kDmabufBufferId, false /*fail*/);
}
TEST_P(WaylandBufferManagerTest, CreateShmBasedBuffers) {
constexpr uint32_t kShmBufferId = 1;
CreateShmBasedBufferAndSetTerminateExpecation(false /*fail*/, kShmBufferId);
DestroyBufferAndSetTerminateExpectation(kShmBufferId, false /*fail*/);
}
TEST_P(WaylandBufferManagerTest, ValidateDataFromGpu) {
const InputData kBadInputs[] = {
// All zeros.
{},
// Valid file but zeros everywhereelse.
{true},
// Valid file, invalid size, zeros elsewhere.
{true, {kDefaultSize.width(), 0}},
{true, {0, kDefaultSize.height()}},
// Valid file and size but zeros in other fields.
{true, kDefaultSize},
// Vectors have different lengths.
{true, kDefaultSize, 1, {1}, {2, 3}, {4, 5, 6}},
// Vectors have same lengths but strides have a zero.
{true, kDefaultSize, 1, {0}, {2}, {6}},
// Vectors are valid but buffer format is not.
{true, kDefaultSize, 1, {1}, {2}, {6}},
// Everything is correct but the buffer ID is zero.
{true, kDefaultSize, 1, {1}, {2}, {6}, DRM_FORMAT_R8},
};
for (const auto& bad : kBadInputs) {
EXPECT_CALL(*server_.zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(0);
base::ScopedFD dummy;
CreateDmabufBasedBufferAndSetTerminateExpectation(
true /*fail*/, bad.buffer_id,
bad.has_file ? MakeFD() : std::move(dummy), bad.size, bad.strides,
bad.offsets, bad.modifiers, bad.format, bad.planes_count);
}
}
TEST_P(WaylandBufferManagerTest, CreateAndDestroyBuffer) {
const uint32_t kBufferId1 = 1;
const uint32_t kBufferId2 = 2;
const gfx::AcceleratedWidget widget = window_->GetWidget();
// This section tests that it is impossible to create buffers with the same
// id if they haven't been assigned to any surfaces yet.
{
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _))
.Times(2);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/,
kBufferId1);
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/,
kBufferId2);
// Can't create buffer with existing id.
CreateDmabufBasedBufferAndSetTerminateExpectation(true /*fail*/,
kBufferId2);
}
// ... impossible to create buffers with the same id if one of them
// has already been attached to a surface.
{
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _))
.Times(1);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/,
kBufferId1);
CommitBuffer(widget, kBufferId1, kBufferId1,
gfx::FrameData(delegate_.viz_seq()),
window_->GetBoundsInPixels(), gfx::RoundedCornersF(),
kDefaultScale, gfx::Rect(window_->applied_state().size_px));
CreateDmabufBasedBufferAndSetTerminateExpectation(true /*fail*/,
kBufferId1);
}
// ... impossible to destroy non-existing buffer.
{
// Either it is attached...
DestroyBufferAndSetTerminateExpectation(kBufferId1, true /*fail*/);
// Or not attached.
DestroyBufferAndSetTerminateExpectation(kBufferId1, true /*fail*/);
}
// Can destroy the buffer without specifying the widget.
{
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _))
.Times(1);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/,
kBufferId1);
CommitBuffer(widget, kBufferId1, kBufferId1,
gfx::FrameData(delegate_.viz_seq()),
window_->GetBoundsInPixels(), gfx::RoundedCornersF(),
kDefaultScale, gfx::Rect(window_->applied_state().size_px));
DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/);
}
// Still can destroy the buffer even if it has not been attached to any
// widgets.
{
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _))
.Times(1);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/,
kBufferId1);
DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/);
}
// ... impossible to destroy buffers twice.
{
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _))
.Times(3);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/,
kBufferId1);
// Attach to a surface.
CommitBuffer(widget, kBufferId1, kBufferId1,
gfx::FrameData(delegate_.viz_seq()),
window_->GetBoundsInPixels(), gfx::RoundedCornersF(),
kDefaultScale, gfx::Rect(window_->applied_state().size_px));
// Created non-attached buffer as well.
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/,
kBufferId2);
DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/);
// Can't destroy the buffer with non-existing id (the manager cleared the
// state after the previous failure).
DestroyBufferAndSetTerminateExpectation(kBufferId1, true /*fail*/);
// Non-attached buffer must have been also destroyed (we can't destroy it
// twice) if there was a failure.
DestroyBufferAndSetTerminateExpectation(kBufferId2, true /*fail*/);
// Create and destroy non-attached buffer twice.
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/,
kBufferId2);
DestroyBufferAndSetTerminateExpectation(kBufferId2, false /*fail*/);
DestroyBufferAndSetTerminateExpectation(kBufferId2, true /*fail*/);
}
}
TEST_P(WaylandBufferManagerTest, CommitBufferNonExistingBufferId) {
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, 1u);
ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */,
false /* fail */);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
// Can't commit for non-existing buffer id.
constexpr uint32_t kNumberOfCommits = 0;
EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(kNumberOfCommits);
EXPECT_CALL(*mock_surface, Frame(_)).Times(kNumberOfCommits);
EXPECT_CALL(*mock_surface, Commit()).Times(kNumberOfCommits);
});
CommitBuffer(window_->GetWidget(), 1u, 5u,
gfx::FrameData(delegate_.viz_seq()),
window_->GetBoundsInPixels(), gfx::RoundedCornersF(),
kDefaultScale, gfx::Rect(window_->applied_state().size_px));
// Let the mojo call to go through.
base::RunLoop().RunUntilIdle();
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
testing::Mock::VerifyAndClearExpectations(
server->GetObject<wl::MockSurface>(id));
});
}
TEST_P(WaylandBufferManagerTest, CommitOverlaysNonExistingBufferId) {
EXPECT_CALL(*server_.zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1);
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, 1u);
ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */,
false /* fail */);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
// Can't commit for non-existing buffer id.
constexpr uint32_t kNumberOfCommits = 0;
EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(kNumberOfCommits);
EXPECT_CALL(*mock_surface, Frame(_)).Times(kNumberOfCommits);
EXPECT_CALL(*mock_surface, Commit()).Times(kNumberOfCommits);
});
std::vector<wl::WaylandOverlayConfig> overlay_configs;
if (connection_->ShouldUseOverlayDelegation()) {
overlay_configs.emplace_back(CreateBasicWaylandOverlayConfig(
INT32_MIN, 1u, window_->GetBoundsInPixels()));
}
// Non-existing buffer id
overlay_configs.emplace_back(
CreateBasicWaylandOverlayConfig(0, 2u, window_->GetBoundsInPixels()));
buffer_manager_gpu_->CommitOverlays(window_->GetWidget(), 1u,
gfx::FrameData(delegate_.viz_seq()),
std::move(overlay_configs));
// Let the mojo call to go through.
base::RunLoop().RunUntilIdle();
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
testing::Mock::VerifyAndClearExpectations(
server->GetObject<wl::MockSurface>(id));
});
}
TEST_P(WaylandBufferManagerTest, CommitOverlaysWithSameBufferId) {
if (!connection_->ShouldUseOverlayDelegation()) {
GTEST_SKIP();
}
const size_t expected_number_of_buffers =
connection_->linux_explicit_synchronization_v1() ? 1 : 2;
PostToServerAndWait(
[expected_number_of_buffers](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _))
.Times(expected_number_of_buffers);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, 1u);
// Re-using the same buffer id across multiple surfaces is allowed.
SetTerminateCallbackExpectationAndDestroyChannel(&callback_, false /*fail*/);
std::vector<wl::WaylandOverlayConfig> overlay_configs;
overlay_configs.emplace_back(
CreateBasicWaylandOverlayConfig(0, 1u, window_->GetBoundsInPixels()));
overlay_configs.emplace_back(
CreateBasicWaylandOverlayConfig(1, 1u, window_->GetBoundsInPixels()));
buffer_manager_gpu_->CommitOverlays(window_->GetWidget(), 1u,
gfx::FrameData(delegate_.viz_seq()),
std::move(overlay_configs));
// Let the mojo call to go through.
base::RunLoop().RunUntilIdle();
ProcessCreatedBufferResourcesWithExpectation(
expected_number_of_buffers /* expected size */, false /* fail */);
}
TEST_P(WaylandBufferManagerTest, CommitBufferNullWidget) {
constexpr uint32_t kBufferId = 1;
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId);
// Can't commit for non-existing widget.
SetTerminateCallbackExpectationAndDestroyChannel(&callback_, true /*fail*/);
CommitBuffer(gfx::kNullAcceleratedWidget, 1u, kBufferId,
gfx::FrameData(delegate_.viz_seq()),
window_->GetBoundsInPixels(), gfx::RoundedCornersF(),
kDefaultScale, gfx::Rect(window_->applied_state().size_px));
// Let the mojo call to go through.
base::RunLoop().RunUntilIdle();
}
// Tests that committing overlays with bounds_rect containing NaN or infinity
// values is illegal - the host terminates the gpu process.
TEST_P(WaylandBufferManagerTest, CommitOverlaysNonsensicalBoundsRect) {
if (!connection_->ShouldUseOverlayDelegation()) {
GTEST_SKIP();
}
const std::vector<gfx::RectF> bounds_rect_test_data = {
gfx::RectF(std::nanf(""), window_->GetBoundsInPixels().y(), std::nanf(""),
window_->GetBoundsInPixels().height()),
gfx::RectF(window_->GetBoundsInPixels().x(),
std::numeric_limits<float>::infinity(),
window_->GetBoundsInPixels().width(),
std::numeric_limits<float>::infinity())};
constexpr bool config[2] = {/*root_has_nan_bounds=*/true,
/*non_root_overlay_has_nan_bounds=*/false};
constexpr uint32_t kBufferId1 = 1;
constexpr uint32_t kBufferId2 = 2;
constexpr uint32_t kBufferId3 = 3;
for (bool should_root_have_nan_bounds : config) {
for (const auto& faulty_bounds_rect : bounds_rect_test_data) {
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/,
kBufferId1);
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/,
kBufferId2);
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/,
kBufferId3);
ProcessCreatedBufferResourcesWithExpectation(3u /* expected size */,
false /* fail */);
// Can't commit for bounds rect containing NaN
SetTerminateCallbackExpectationAndDestroyChannel(&callback_,
true /*fail*/);
size_t z_order = 0;
std::vector<wl::WaylandOverlayConfig> overlay_configs;
if (should_root_have_nan_bounds) {
// The root surface has nan bounds.
overlay_configs.emplace_back(CreateBasicWaylandOverlayConfig(
INT32_MIN, kBufferId1, faulty_bounds_rect));
overlay_configs.emplace_back(CreateBasicWaylandOverlayConfig(
z_order++, kBufferId2, window_->GetBoundsInPixels()));
overlay_configs.emplace_back(CreateBasicWaylandOverlayConfig(
z_order++, kBufferId3, window_->GetBoundsInPixels()));
} else {
// Overlays have nan bounds. Given playback starts with the biggest
// z-order number, add two more overlays around the faulty overlay
// config so that the test ensures no further playback happens and it
// doesn't crash.
overlay_configs.emplace_back(CreateBasicWaylandOverlayConfig(
INT32_MIN, kBufferId1, window_->GetBoundsInPixels()));
overlay_configs.emplace_back(CreateBasicWaylandOverlayConfig(
z_order++, kBufferId2, window_->GetBoundsInPixels()));
overlay_configs.emplace_back(CreateBasicWaylandOverlayConfig(
z_order++, kBufferId3, faulty_bounds_rect));
overlay_configs.emplace_back(CreateBasicWaylandOverlayConfig(
z_order++, kBufferId2, window_->GetBoundsInPixels()));
}
buffer_manager_gpu_->CommitOverlays(window_->GetWidget(), 1u,
gfx::FrameData(delegate_.viz_seq()),
std::move(overlay_configs));
base::RunLoop().RunUntilIdle();
if (!should_root_have_nan_bounds &&
!connection_->linux_explicit_synchronization_v1()) {
// This case submits kBufferId2 twice. So, a second handle is requested
// during a frame playback if explicit sync is unavailable.
ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */,
false /* fail */);
}
EXPECT_EQ("Overlay bounds_rect is invalid (NaN or infinity).",
channel_destroyed_error_message_);
std::vector<uint32_t> ids_of_subsurfaces;
ids_of_subsurfaces.reserve(window_->wayland_subsurfaces_.size());
for (auto& subsurface : window_->wayland_subsurfaces_) {
ids_of_subsurfaces.emplace_back(
subsurface->wayland_surface()->get_surface_id());
}
PostToServerAndWait([id = surface_id_, ids_of_subsurfaces](
wl::TestWaylandServerThread* server) {
// Clear all the possible frame and release callbacks.
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
for (auto subsurface_id : ids_of_subsurfaces) {
auto* mock_surface_of_subsurface =
server->GetObject<wl::MockSurface>(subsurface_id);
EXPECT_TRUE(mock_surface_of_subsurface);
mock_surface_of_subsurface->SendFrameCallback();
mock_surface_of_subsurface->ClearBufferReleases();
}
mock_surface->SendFrameCallback();
mock_surface->ClearBufferReleases();
});
}
}
}
// A similar test to the above with the only difference that a background
// dummy buffer is not used as delegation is disabled.
TEST_P(WaylandBufferManagerTest,
CommitOverlaysNonsensicalBoundsRectSingleOverlay) {
if (connection_->ShouldUseOverlayDelegation()) {
GTEST_SKIP();
}
const std::vector<gfx::RectF> bounds_rect_test_data = {
gfx::RectF(std::nanf(""), window_->GetBoundsInPixels().y(), std::nanf(""),
window_->GetBoundsInPixels().height()),
gfx::RectF(window_->GetBoundsInPixels().x(),
std::numeric_limits<float>::infinity(),
window_->GetBoundsInPixels().width(),
std::numeric_limits<float>::infinity())};
for (const auto& faulty_bounds_rect : bounds_rect_test_data) {
constexpr uint32_t kBufferId1 = 1;
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/,
kBufferId1);
ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */,
false /* fail */);
// Can't commit for bounds rect containing NaN
SetTerminateCallbackExpectationAndDestroyChannel(&callback_, true /*fail*/);
size_t z_order = 0;
std::vector<wl::WaylandOverlayConfig> overlay_configs;
overlay_configs.emplace_back(CreateBasicWaylandOverlayConfig(
z_order, kBufferId1, faulty_bounds_rect));
buffer_manager_gpu_->CommitOverlays(window_->GetWidget(), 1u,
gfx::FrameData(delegate_.viz_seq()),
std::move(overlay_configs));
base::RunLoop().RunUntilIdle();
EXPECT_EQ("Overlay bounds_rect is invalid (NaN or infinity).",
channel_destroyed_error_message_);
}
}
TEST_P(WaylandBufferManagerTest, EnsureCorrectOrderOfCallbacks) {
constexpr uint32_t kBufferId1 = 1;
constexpr uint32_t kBufferId2 = 2;
const gfx::AcceleratedWidget widget = window_->GetWidget();
const gfx::Rect bounds = gfx::Rect({0, 0}, kDefaultSize);
window_->SetBoundsInDIP(bounds);
MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), widget_);
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(2);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1);
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2);
ProcessCreatedBufferResourcesWithExpectation(2u /* expected size */,
false /* fail */);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
constexpr uint32_t kNumberOfCommits = 3;
EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(kNumberOfCommits);
EXPECT_CALL(*mock_surface, Frame(_)).Times(kNumberOfCommits);
EXPECT_CALL(*mock_surface, Commit()).Times(kNumberOfCommits);
});
// All the other expectations must come in order.
::testing::InSequence sequence;
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _))
.Times(1);
// wp_presentation must not exist now. This means that the buffer
// manager must send synthetized presentation feedbacks.
ASSERT_TRUE(!connection_->presentation());
EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId1, _)).Times(1);
CommitBuffer(widget, kBufferId1, kBufferId1,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
base::RunLoop().RunUntilIdle();
// As long as there hasn't any previous buffer attached (nothing to release
// yet), it must be enough to just send a frame callback back.
SendFrameCallbackForSurface(surface_id_);
// Commit second buffer now.
CommitBuffer(widget, kBufferId2, kBufferId2,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
base::RunLoop().RunUntilIdle();
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId2, gfx::SwapResult::SWAP_ACK, _))
.Times(1);
EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId2, _)).Times(1);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
mock_surface->ReleaseBuffer(mock_surface->prev_attached_buffer());
mock_surface->SendFrameCallback();
});
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
// wp_presentation is available now.
auto* mock_wp_presentation = server->EnsureAndGetWpPresentation();
ASSERT_TRUE(mock_wp_presentation);
EXPECT_CALL(*mock_wp_presentation,
Feedback(_, _, mock_surface->resource(), _))
.Times(1);
});
// Now, the wp_presentation object exists and there must be a real feedback
// sent. Ensure the order now.
ASSERT_TRUE(connection_->presentation());
// Commit second buffer now.
CommitBuffer(widget, kBufferId1, kBufferId1,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
base::RunLoop().RunUntilIdle();
// Even though, the server send the presentation feedback, the host manager
// must make sure the order of the submission and presentation callbacks is
// correct. Thus, no callbacks must be received by the MockSurfaceGpu.
EXPECT_CALL(mock_surface_gpu, OnSubmission(_, _, _)).Times(0);
EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0);
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
server->EnsureAndGetWpPresentation()->SendPresentationCallback();
});
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _))
.Times(1);
EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId1, _)).Times(1);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
// Now, send the release callback. The host manager must send the submission
// and presentation callbacks in correct order.
mock_surface->ReleaseBuffer(mock_surface->prev_attached_buffer());
});
DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/);
DestroyBufferAndSetTerminateExpectation(kBufferId2, false /*fail*/);
}
TEST_P(WaylandBufferManagerTest,
DestroyedBuffersGeneratePresentationFeedbackFailure) {
constexpr uint32_t kBufferId1 = 1;
constexpr uint32_t kBufferId2 = 2;
constexpr uint32_t kBufferId3 = 3;
const gfx::AcceleratedWidget widget = window_->GetWidget();
const gfx::Rect bounds = gfx::Rect({0, 0}, kDefaultSize);
window_->SetBoundsInDIP(bounds);
MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), widget_);
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(3);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1);
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2);
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId3);
ProcessCreatedBufferResourcesWithExpectation(3u /* expected size */,
false /* fail */);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
ASSERT_TRUE(mock_surface);
auto* mock_wp_presentation = server->EnsureAndGetWpPresentation();
ASSERT_TRUE(mock_wp_presentation);
constexpr uint32_t kNumberOfCommits = 3;
EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(kNumberOfCommits);
EXPECT_CALL(*mock_surface, Frame(_)).Times(kNumberOfCommits);
EXPECT_CALL(*mock_surface, Commit()).Times(kNumberOfCommits);
EXPECT_CALL(*mock_wp_presentation,
Feedback(_, _, mock_surface->resource(), _))
.Times(3);
});
::testing::InSequence s;
// wp_presentation_feedback should work now.
ASSERT_TRUE(connection_->presentation());
// Commit the first buffer and expect OnSubmission immediately.
EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0);
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _))
.Times(1);
CommitBuffer(widget, kBufferId1, kBufferId1,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
SendFrameCallbackForSurface(surface_id_);
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
// Deliberately drop the presentation feedback for the first buffer,
// since we will destroy it.
auto* mock_wp_presentation = server->EnsureAndGetWpPresentation();
EXPECT_EQ(1u, mock_wp_presentation->num_of_presentation_callbacks());
mock_wp_presentation->DropPresentationCallback();
});
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
// Commit second buffer now.
CommitBuffer(widget, kBufferId2, kBufferId2,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
SendFrameCallbackForSurface(surface_id_);
// Destroy the first buffer, which should trigger submission for the second
// buffer.
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId2, gfx::SwapResult::SWAP_ACK, _))
.Times(1);
DestroyBufferAndSetTerminateExpectation(kBufferId1, /*fail=*/false);
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
mock_surface->DestroyPrevAttachedBuffer();
mock_surface->SendFrameCallback();
});
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
// Deliberately drop the presentation feedback for the second buffer,
// since we will destroy it.
auto* mock_wp_presentation = server->EnsureAndGetWpPresentation();
EXPECT_EQ(1u, mock_wp_presentation->num_of_presentation_callbacks());
mock_wp_presentation->DropPresentationCallback();
});
// Commit buffer 3 then send the presentation callback for it. This should
// not call OnPresentation as OnSubmission hasn't been called yet. Though,
// the previously submitted buffers will have their presentation feedback
// discarded and sent to the |mock_surface_gpu| as those buffers have already
// been acked.
EXPECT_CALL(mock_surface_gpu, OnSubmission(_, _, _)).Times(0);
EXPECT_CALL(
mock_surface_gpu,
OnPresentation(
kBufferId1,
::testing::Field(
&gfx::PresentationFeedback::flags,
::testing::Eq(gfx::PresentationFeedback::Flags::kFailure))))
.Times(1);
EXPECT_CALL(
mock_surface_gpu,
OnPresentation(
kBufferId2,
::testing::Field(
&gfx::PresentationFeedback::flags,
::testing::Eq(gfx::PresentationFeedback::Flags::kFailure))))
.Times(1);
EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0);
CommitBuffer(widget, kBufferId3, kBufferId3,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
server->GetObject<wl::MockSurface>(id)->SendFrameCallback();
server->EnsureAndGetWpPresentation()->SendPresentationCallback();
});
// Ensure that presentation feedback is flushed.
task_environment_.FastForwardBy(
WaylandFrameManager::GetPresentationFlushTimerDurationForTesting());
// Verify our expecations.
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
// Destroy buffer 2, which should trigger OnSubmission for buffer 3, and
// finally OnPresentation for buffer 3.
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId3, gfx::SwapResult::SWAP_ACK, _))
.Times(1);
EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId3, _)).Times(1);
DestroyBufferAndSetTerminateExpectation(kBufferId2, /*fail=*/false);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
mock_surface->DestroyPrevAttachedBuffer();
mock_surface->SendFrameCallback();
server->EnsureAndGetWpPresentation()->SendPresentationCallback();
});
// Let the mojo messages to be processed.
// No need to fast forward to ensure the presentation flush timer is fired,
// because in this case the OnSubmission should piggyback the feedback.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
DestroyBufferAndSetTerminateExpectation(kBufferId3, false /*fail*/);
}
// This test ensures that a discarded presentation feedback sent prior receiving
// results for the previous presentation feedback does not make them
// automatically failed.
TEST_P(WaylandBufferManagerTest,
EnsureDiscardedPresentationDoesNotMakePreviousFeedbacksFailed) {
constexpr uint32_t kBufferId1 = 1;
constexpr uint32_t kBufferId2 = 2;
constexpr uint32_t kBufferId3 = 3;
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
// Enable wp_presentation support.
auto* mock_wp_presentation = server->EnsureAndGetWpPresentation();
ASSERT_TRUE(mock_wp_presentation);
});
const gfx::AcceleratedWidget widget = window_->GetWidget();
const gfx::Rect bounds = gfx::Rect({0, 0}, kDefaultSize);
window_->SetBoundsInDIP(bounds);
MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), widget_);
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(3);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1);
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2);
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId3);
ProcessCreatedBufferResourcesWithExpectation(3u /* expected size */,
false /* fail */);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
constexpr uint32_t kNumberOfCommits = 3;
EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(kNumberOfCommits);
EXPECT_CALL(*mock_surface, Frame(_)).Times(kNumberOfCommits);
EXPECT_CALL(*mock_surface, Commit()).Times(kNumberOfCommits);
});
// All the other expectations must come in order.
::testing::InSequence sequence;
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _))
.Times(1);
EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0);
// Commit first buffer
CommitBuffer(widget, kBufferId1, kBufferId1,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
// Let the mojo message for OnSubmission go back.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
// Verify we have a presentation callback now. This will be sent later.
EXPECT_EQ(
1u,
server->EnsureAndGetWpPresentation()->num_of_presentation_callbacks());
server->GetObject<wl::MockSurface>(id)->SendFrameCallback();
});
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId2, gfx::SwapResult::SWAP_ACK, _))
.Times(1);
EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0);
// Commit second buffer
CommitBuffer(widget, kBufferId2, kBufferId2,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
// Verify we have a presentation callback now. This will be sent later.
EXPECT_EQ(
2u,
server->EnsureAndGetWpPresentation()->num_of_presentation_callbacks());
// Release previous buffer and commit third buffer.
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
mock_surface->ReleaseBuffer(mock_surface->prev_attached_buffer());
mock_surface->SendFrameCallback();
});
// Let the mojo message for OnSubmission go back.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId3, gfx::SwapResult::SWAP_ACK, _))
.Times(1);
EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0);
// Commit third buffer
CommitBuffer(widget, kBufferId3, kBufferId3,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
mock_surface->ReleaseBuffer(mock_surface->prev_attached_buffer());
});
// Let the mojo messages to be processed.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
// Even though WaylandBufferManagerHost stores the previous stores
// presentation feedbacks and waits for their value, the current last one
// mustn't result in the previous marked as failed. Thus, no feedback must be
// actually sent to the MockSurfaceGpu as it's required to send feedbacks in
// order.
EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0);
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
auto* mock_wp_presentation = server->EnsureAndGetWpPresentation();
EXPECT_EQ(3u, mock_wp_presentation->num_of_presentation_callbacks());
mock_wp_presentation->SendPresentationCallbackDiscarded(/*last=*/true);
});
// Let the mojo messages to be processed if any to ensure there are no pending
// messages.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
// Now, start to send all the previous callbacks.
EXPECT_CALL(mock_surface_gpu,
OnPresentation(
kBufferId1,
::testing::Field(
&gfx::PresentationFeedback::flags,
::testing::Eq(gfx::PresentationFeedback::Flags::kVSync))))
.Times(1);
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
auto* mock_wp_presentation = server->EnsureAndGetWpPresentation();
EXPECT_EQ(2u, mock_wp_presentation->num_of_presentation_callbacks());
mock_wp_presentation->SendPresentationCallback();
});
// Ensure that presentation feedback is flushed.
task_environment_.FastForwardBy(
WaylandFrameManager::GetPresentationFlushTimerDurationForTesting());
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
// Now, send the second presentation feedback. It will send both second and
// third feedback that was discarded.
EXPECT_CALL(mock_surface_gpu,
OnPresentation(
kBufferId2,
::testing::Field(
&gfx::PresentationFeedback::flags,
::testing::Eq(gfx::PresentationFeedback::Flags::kVSync))))
.Times(1);
EXPECT_CALL(
mock_surface_gpu,
OnPresentation(
kBufferId3,
::testing::Field(
&gfx::PresentationFeedback::flags,
::testing::Eq(gfx::PresentationFeedback::Flags::kFailure))))
.Times(1);
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
auto* mock_wp_presentation = server->EnsureAndGetWpPresentation();
EXPECT_EQ(1u, mock_wp_presentation->num_of_presentation_callbacks());
mock_wp_presentation->SendPresentationCallback();
});
// Ensure that presentation feedback is flushed.
task_environment_.FastForwardBy(
WaylandFrameManager::GetPresentationFlushTimerDurationForTesting());
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/);
DestroyBufferAndSetTerminateExpectation(kBufferId2, false /*fail*/);
DestroyBufferAndSetTerminateExpectation(kBufferId3, false /*fail*/);
}
TEST_P(WaylandBufferManagerTest, TestCommitBufferConditions) {
constexpr uint32_t kDmabufBufferId = 1;
constexpr uint32_t kDmabufBufferId2 = 2;
const gfx::AcceleratedWidget widget = window_->GetWidget();
MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), widget_);
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/,
kDmabufBufferId);
// Part 1: the surface mustn't have a buffer attached until
// zwp_linux_buffer_params_v1_send_created is called. Instead, the buffer must
// be set as pending buffer.
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(0);
EXPECT_CALL(*mock_surface, Frame(_)).Times(0);
EXPECT_CALL(*mock_surface, Commit()).Times(0);
});
CommitBuffer(widget, kDmabufBufferId, kDmabufBufferId,
gfx::FrameData(delegate_.viz_seq()),
window_->GetBoundsInPixels(), gfx::RoundedCornersF(),
kDefaultScale, gfx::Rect(window_->applied_state().size_px));
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(1);
EXPECT_CALL(*mock_surface, Frame(_)).Times(1);
EXPECT_CALL(*mock_surface, Commit()).Times(1);
});
ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */,
false /* fail */);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* linux_dmabuf = server->zwp_linux_dmabuf_v1();
// Once the client receives a "...send_created" call, it must destroy the
// params resource.
EXPECT_TRUE(linux_dmabuf->buffer_params().empty());
// Part 2: the surface mustn't have a buffer attached until frame callback
// is sent by the server.
EXPECT_CALL(*linux_dmabuf, CreateParams(_, _, _)).Times(1);
testing::Mock::VerifyAndClearExpectations(
server->GetObject<wl::MockSurface>(id));
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/,
kDmabufBufferId2);
ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */,
false /* fail */);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(0);
EXPECT_CALL(*mock_surface, Frame(_)).Times(0);
EXPECT_CALL(*mock_surface, Commit()).Times(0);
});
CommitBuffer(widget, kDmabufBufferId2, kDmabufBufferId2,
gfx::FrameData(delegate_.viz_seq()),
window_->GetBoundsInPixels(), gfx::RoundedCornersF(),
kDefaultScale, gfx::Rect(window_->applied_state().size_px));
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
testing::Mock::VerifyAndClearExpectations(mock_surface);
// After the frame callback is sent, the pending buffer will be committed.
EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(1);
EXPECT_CALL(*mock_surface, Frame(_)).Times(1);
EXPECT_CALL(*mock_surface, Commit()).Times(1);
mock_surface->SendFrameCallback();
});
DestroyBufferAndSetTerminateExpectation(kDmabufBufferId, false /*fail*/);
DestroyBufferAndSetTerminateExpectation(kDmabufBufferId2, false /*fail*/);
}
// Tests the surface does not have buffers attached until it's configured at
// least once.
TEST_P(WaylandBufferManagerTest, TestCommitBufferConditionsAckConfigured) {
constexpr uint32_t kDmabufBufferId = 1;
// Exercise two window types that create different windows - toplevel, menu.
// subsurface windows do not create xdg_surfaces so no need to configure them.
std::vector<PlatformWindowType> window_types{PlatformWindowType::kWindow,
PlatformWindowType::kTooltip};
for (const auto& type : window_types) {
// If the type is not kWindow, provide default created window as parent of
// the newly created window.
auto temp_window = CreateWindow(type, type != PlatformWindowType::kWindow
? widget_
: gfx::kNullAcceleratedWidget);
auto widget = temp_window->GetWidget();
temp_window->Show(false);
const uint32_t temp_window_surface_id =
temp_window->root_surface()->get_surface_id();
MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), widget);
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _))
.Times(1);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/,
kDmabufBufferId);
PostToServerAndWait(
[temp_window_surface_id](wl::TestWaylandServerThread* server) {
auto* mock_surface =
server->GetObject<wl::MockSurface>(temp_window_surface_id);
auto* xdg_surface = mock_surface->xdg_surface();
ASSERT_TRUE(xdg_surface);
});
ASSERT_FALSE(temp_window->IsSurfaceConfigured());
ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */,
false /* fail */);
// Buffer commits before surface configure are expected to be
// discarded.
PostToServerAndWait(
[temp_window_surface_id](wl::TestWaylandServerThread* server) {
auto* mock_surface =
server->GetObject<wl::MockSurface>(temp_window_surface_id);
auto* xdg_surface = mock_surface->xdg_surface();
EXPECT_CALL(*xdg_surface, SetWindowGeometry(_)).Times(0);
EXPECT_CALL(*xdg_surface, AckConfigure(_)).Times(0);
EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(0);
EXPECT_CALL(*mock_surface, Frame(_)).Times(0);
EXPECT_CALL(*mock_surface, Commit()).Times(0);
});
CommitBuffer(widget, kDmabufBufferId, kDmabufBufferId,
gfx::FrameData(delegate_.viz_seq()),
temp_window->GetBoundsInPixels(), gfx::RoundedCornersF(),
kDefaultScale, temp_window->GetBoundsInPixels());
PostToServerAndWait(
[temp_window_surface_id](wl::TestWaylandServerThread* server) {
auto* mock_surface =
server->GetObject<wl::MockSurface>(temp_window_surface_id);
auto* xdg_surface = mock_surface->xdg_surface();
testing::Mock::VerifyAndClearExpectations(mock_surface);
EXPECT_CALL(*xdg_surface, SetWindowGeometry(_));
EXPECT_CALL(*xdg_surface, AckConfigure(10U));
EXPECT_CALL(*mock_surface, Attach(_, _, _));
EXPECT_CALL(*mock_surface, Frame(_));
EXPECT_CALL(*mock_surface, Commit());
});
ActivateSurface(delegate_, 10U);
CommitBuffer(widget, kDmabufBufferId, kDmabufBufferId,
gfx::FrameData(delegate_.viz_seq()),
temp_window->GetBoundsInPixels(), gfx::RoundedCornersF(),
kDefaultScale, temp_window->GetBoundsInPixels());
PostToServerAndWait([id = temp_window_surface_id](
wl::TestWaylandServerThread* server) {
wl::MockSurface* mock_surface = server->GetObject<wl::MockSurface>(id);
testing::Mock::VerifyAndClearExpectations(mock_surface);
testing::Mock::VerifyAndClearExpectations(mock_surface->xdg_surface());
});
testing::Mock::VerifyAndClearExpectations(&delegate_);
SetPointerFocusedWindow(nullptr);
temp_window.reset();
DestroyBufferAndSetTerminateExpectation(kDmabufBufferId, false /*fail*/);
}
}
// Verifies toplevel surfaces do not have buffers attached until configured,
// even when the initial configure sequence is not acked in response to
// xdg_surface.configure event, i.e: done asynchronously when OnSequencePoint()
// is called by they FrameManager).
//
// Regression test for https://crbug.com/1313023.
TEST_P(WaylandBufferManagerTest,
CommitBufferConditionsWithDeferredAckConfigure) {
constexpr gfx::Rect kNormalBounds{800, 800};
constexpr gfx::Rect kRestoredBounds{500, 500};
constexpr uint32_t kDmabufBufferId = 1;
testing::Mock::VerifyAndClearExpectations(&delegate_);
PlatformWindowInitProperties properties(kNormalBounds);
auto window =
delegate_.CreateWaylandWindow(connection_.get(), std::move(properties));
ASSERT_TRUE(window);
ASSERT_NE(window->GetWidget(), gfx::kNullAcceleratedWidget);
widget_ = window->GetWidget();
// Set restored bounds to a value different from the initial window bounds in
// order to force WaylandWindow::ProcessPendingConfigureState() to defer the
// very first configure ack to be done in the subsequent OnSequencePoint()
// call.
window->SetRestoredBoundsInDIP(kRestoredBounds);
WaylandTestBase::SyncDisplay();
window->Show(false);
const uint32_t surface_id = window->root_surface()->get_surface_id();
MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), widget_);
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/,
kDmabufBufferId);
PostToServerAndWait([surface_id](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(surface_id);
auto* xdg_surface = mock_surface->xdg_surface();
ASSERT_TRUE(xdg_surface);
});
ASSERT_FALSE(window->IsSurfaceConfigured());
ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */,
false /* fail */);
// Emulate the following steps:
//
// 1. A CommitBuffer request coming from the GPU service, with frame
// bounds that do not match the one stored in |pending_configures_| at Host
// side (filled when processing 0x0 initial configure sequence sent by the
// Wayland compositor.
// 2. The initial configure sequence (i.e: with 0x0 size which means the
// client must suggest the initial geometry of the surface.
// 3. And then a CommitBuffer with the expected bounds (ie: suggested to the
// Wayland compositor through a set_geometry/ack_configure sequence when
// processing (2).
//
// And ensures the xdg and wl_surface objects received the correct requests
// amount. I.e: No buffer attaches before setting geometry + acking initial
// configure sequence, etc.
constexpr uint32_t kActivateSerial = 1u;
PostToServerAndWait([surface_id, bounds = kRestoredBounds](
wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(surface_id);
auto* xdg_surface = mock_surface->xdg_surface();
EXPECT_CALL(*xdg_surface, SetWindowGeometry(bounds)).Times(1);
EXPECT_CALL(*xdg_surface, AckConfigure(kActivateSerial)).Times(1);
EXPECT_CALL(*mock_surface, Attach(_, 0, 0)).Times(1);
EXPECT_CALL(*mock_surface, Frame(_)).Times(1);
EXPECT_CALL(*mock_surface, Commit()).Times(1);
});
CommitBuffer(widget_, kDmabufBufferId, kDmabufBufferId,
gfx::FrameData(delegate_.viz_seq() - 1), gfx::Rect{55, 55},
gfx::RoundedCornersF(), kDefaultScale, gfx::Rect{55, 55});
EXPECT_CALL(delegate_, CalculateInsetsInDIP(PlatformWindowState::kNormal))
.WillRepeatedly(testing::Return(gfx::Insets()));
ActivateSurface(delegate_, kActivateSerial);
CommitBuffer(widget_, kDmabufBufferId, kDmabufBufferId,
gfx::FrameData(delegate_.viz_seq()), kRestoredBounds,
gfx::RoundedCornersF(), kDefaultScale, kRestoredBounds);
SetPointerFocusedWindow(nullptr);
window.reset();
DestroyBufferAndSetTerminateExpectation(kDmabufBufferId, false /*fail*/);
}
// The buffer that is not originally attached to any of the surfaces,
// must be attached when a commit request comes. Also, it must setup a buffer
// release listener and OnSubmission must be called for that buffer if it is
// released.
TEST_P(WaylandBufferManagerTest, AnonymousBufferAttachedAndReleased) {
constexpr uint32_t kBufferId1 = 1;
constexpr uint32_t kBufferId2 = 2;
constexpr uint32_t kBufferId3 = 3;
const gfx::AcceleratedWidget widget = window_->GetWidget();
const gfx::Rect bounds = gfx::Rect({0, 0}, kDefaultSize);
window_->SetBoundsInDIP(bounds);
MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), widget_);
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1);
ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */,
false /* fail */);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
constexpr uint32_t kNumberOfCommits = 3;
EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(kNumberOfCommits);
EXPECT_CALL(*mock_surface, Frame(_)).Times(kNumberOfCommits);
EXPECT_CALL(*mock_surface, Commit()).Times(kNumberOfCommits);
});
// All the other expectations must come in order.
::testing::InSequence sequence;
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _))
.Times(1);
EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId1, _)).Times(1);
// Commit second buffer now.
CommitBuffer(widget, kBufferId1, kBufferId1,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
SendFrameCallbackForSurface(surface_id_);
// Let mojo messages to be processed.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
// Now synchronously create a second buffer and commit it. The release
// callback must be setup and OnSubmission must be called.
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2);
ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */,
false /* fail */);
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId2, gfx::SwapResult::SWAP_ACK, _))
.Times(1);
EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId2, _)).Times(1);
// Commit second buffer now.
CommitBuffer(widget, kBufferId2, kBufferId2,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
mock_surface->ReleaseBuffer(mock_surface->prev_attached_buffer());
});
SendFrameCallbackForSurface(surface_id_);
// Let mojo messages to be processed.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
// Now asynchronously create another buffer so that a commit request
// comes earlier than it is created by the Wayland compositor, but it can
// released once the buffer is committed and processed (that is, it must be
// able to setup a buffer release callback).
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId3);
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId3, gfx::SwapResult::SWAP_ACK, _))
.Times(0);
EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId3, _)).Times(0);
CommitBuffer(widget, kBufferId3, kBufferId3,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
// Let mojo messages to be processed from host to gpu (if any).
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId3, gfx::SwapResult::SWAP_ACK, _))
.Times(1);
EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId3, _)).Times(1);
// Now, create the buffer from the Wayland compositor side and let the buffer
// manager complete the commit request.
ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */,
false /* fail */);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
mock_surface->ReleaseBuffer(mock_surface->prev_attached_buffer());
});
// Let mojo messages to be processed.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/);
DestroyBufferAndSetTerminateExpectation(kBufferId2, false /*fail*/);
DestroyBufferAndSetTerminateExpectation(kBufferId3, false /*fail*/);
}
TEST_P(WaylandBufferManagerTest, DestroyBufferForDestroyedWindow) {
constexpr uint32_t kBufferId = 1;
auto temp_window = CreateWindow();
auto widget = temp_window->GetWidget();
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId);
CommitBuffer(widget, kBufferId, kBufferId,
gfx::FrameData(delegate_.viz_seq()),
temp_window->GetBoundsInPixels(), gfx::RoundedCornersF(),
kDefaultScale, temp_window->GetBoundsInPixels());
temp_window.reset();
DestroyBufferAndSetTerminateExpectation(kBufferId, false /*fail*/);
}
TEST_P(WaylandBufferManagerTest, DestroyedWindowNoSubmissionSingleBuffer) {
constexpr uint32_t kBufferId = 1;
auto temp_window = CreateWindow();
auto widget = temp_window->GetWidget();
auto bounds = temp_window->GetBoundsInPixels();
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId);
ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */,
false /* fail */);
MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), widget);
// All the other expectations must come in order.
::testing::InSequence sequence;
EXPECT_CALL(mock_surface_gpu, OnSubmission(_, _, _)).Times(0);
EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0);
temp_window.reset();
CommitBuffer(widget, kBufferId, kBufferId,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
DestroyBufferAndSetTerminateExpectation(kBufferId, false /*fail*/);
}
TEST_P(WaylandBufferManagerTest, DestroyedWindowNoSubmissionMultipleBuffers) {
constexpr uint32_t kBufferId1 = 1;
constexpr uint32_t kBufferId2 = 2;
auto temp_window = CreateWindow();
temp_window->Show(false);
auto widget = temp_window->GetWidget();
auto bounds = temp_window->GetBoundsInPixels();
const uint32_t temp_window_surface_id =
temp_window->root_surface()->get_surface_id();
PostToServerAndWait(
[temp_window_surface_id](wl::TestWaylandServerThread* server) {
ASSERT_TRUE(server->GetObject<wl::MockSurface>(temp_window_surface_id));
});
ActivateSurface(delegate_);
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1);
ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */,
false /* fail */);
MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), widget);
// All the other expectations must come in order.
::testing::InSequence sequence;
EXPECT_CALL(mock_surface_gpu, OnSubmission(_, _, _)).Times(1);
EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(1);
CommitBuffer(widget, kBufferId1, kBufferId1,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
// Let mojo messages to be processed back to the gpu.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
PostToServerAndWait([temp_window_surface_id](
wl::TestWaylandServerThread* server) {
server->GetObject<wl::MockSurface>(temp_window_surface_id)
->SendFrameCallback();
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2);
ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */,
false /* fail */);
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId2, gfx::SwapResult::SWAP_ACK, _))
.Times(1);
EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId2, _)).Times(1);
CommitBuffer(widget, kBufferId2, kBufferId2,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
PostToServerAndWait(
[temp_window_surface_id](wl::TestWaylandServerThread* server) {
auto* mock_surface =
server->GetObject<wl::MockSurface>(temp_window_surface_id);
mock_surface->ReleaseBuffer(mock_surface->prev_attached_buffer());
});
// Let mojo messages to be processed back to the gpu.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
EXPECT_CALL(mock_surface_gpu, OnSubmission(_, _, _)).Times(0);
EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0);
temp_window.reset();
CommitBuffer(widget, kBufferId1, kBufferId1,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
// Let mojo messages to be processed back to the gpu.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/);
DestroyBufferAndSetTerminateExpectation(kBufferId2, false /*fail*/);
}
// Tests that OnSubmission and OnPresentation are properly triggered if a buffer
// is committed twice in a row and those buffers are destroyed.
TEST_P(WaylandBufferManagerTest, DestroyBufferCommittedTwiceInARow) {
constexpr uint32_t kBufferId1 = 1;
constexpr uint32_t kBufferId2 = 2;
const gfx::AcceleratedWidget widget = window_->GetWidget();
const gfx::Rect bounds = window_->GetBoundsInPixels();
MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), widget);
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(2);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1);
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2);
ProcessCreatedBufferResourcesWithExpectation(2u /* expected size */,
false /* fail */);
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _))
.Times(1);
EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId1, _)).Times(1);
CommitBuffer(widget, kBufferId1, kBufferId1,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
SendFrameCallbackForSurface(surface_id_);
// Let mojo messages to be processed back to the gpu.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
// Can't call OnSubmission until there is a release.
EXPECT_CALL(mock_surface_gpu, OnSubmission(_, _, _)).Times(0);
EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0);
CommitBuffer(widget, kBufferId2, kBufferId2,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
SendFrameCallbackForSurface(surface_id_);
CommitBuffer(widget, kBufferId2, kBufferId2,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
SendFrameCallbackForSurface(surface_id_);
// Destroying buffer2 should do nothing yet.
DestroyBufferAndSetTerminateExpectation(kBufferId2, false /*fail*/);
// Let mojo messages to be processed back to the gpu.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
// Destroying buffer1 should give us two acks for buffer2.
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId2, gfx::SwapResult::SWAP_ACK, _))
.Times(2);
EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId2, _)).Times(2);
DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/);
// Let mojo messages to be processed back to the gpu.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
}
// Tests that OnSubmission and OnPresentation are properly triggered if a buffer
// is committed twice in a row and then released.
TEST_P(WaylandBufferManagerTest, ReleaseBufferCommittedTwiceInARow) {
constexpr uint32_t kBufferId1 = 1;
constexpr uint32_t kBufferId2 = 2;
const gfx::AcceleratedWidget widget = window_->GetWidget();
const gfx::Rect bounds = window_->GetBoundsInPixels();
MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), widget);
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(2);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1);
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2);
ProcessCreatedBufferResourcesWithExpectation(2u /* expected size */,
false /* fail */);
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _))
.Times(1);
EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId1, _)).Times(1);
CommitBuffer(widget, kBufferId1, kBufferId1,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
SendFrameCallbackForSurface(surface_id_);
// Let mojo messages to be processed back to the gpu.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
// Even though, this is stored on the client thread, but must only be used on
// the server thread.
wl_resource* wl_buffer1 = GetSurfaceAttachedBuffer(surface_id_);
ASSERT_TRUE(wl_buffer1);
// Can't call OnSubmission until there is a release.
EXPECT_CALL(mock_surface_gpu, OnSubmission(_, _, _)).Times(0);
EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0);
CommitBuffer(widget, kBufferId2, kBufferId2,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
SendFrameCallbackForSurface(surface_id_);
CommitBuffer(widget, kBufferId2, kBufferId2,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
// Let mojo messages to be processed back to the gpu.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
// Releasing buffer1 should trigger two acks for buffer2.
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId2, gfx::SwapResult::SWAP_ACK, _))
.Times(2);
EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId2, _)).Times(2);
PostToServerAndWait(
[wl_buffer1, id = surface_id_](wl::TestWaylandServerThread* server) {
server->GetObject<wl::MockSurface>(id)->ReleaseBuffer(wl_buffer1);
});
// Let mojo messages to be processed back to the gpu.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/);
DestroyBufferAndSetTerminateExpectation(kBufferId2, false /*fail*/);
}
// Tests that OnSubmission and OnPresentation callbacks are properly called
// even if buffers are not released in the same order they were committed.
TEST_P(WaylandBufferManagerTest, ReleaseOrderDifferentToCommitOrder) {
constexpr uint32_t kBufferId1 = 1;
constexpr uint32_t kBufferId2 = 2;
constexpr uint32_t kBufferId3 = 3;
const gfx::AcceleratedWidget widget = window_->GetWidget();
const gfx::Rect bounds = window_->GetBoundsInPixels();
MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), widget);
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(3);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1);
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2);
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId3);
ProcessCreatedBufferResourcesWithExpectation(3u /* expected size */,
false /* fail */);
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _))
.Times(1);
EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId1, _)).Times(1);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->GetObject<wl::MockSurface>(id), Attach(_, _, _))
.Times(1);
});
CommitBuffer(widget, kBufferId1, kBufferId1,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
SendFrameCallbackForSurface(surface_id_);
// Let mojo messages to be processed and passed from host to gpu.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
// Even though, this is stored on the client thread, but must only be used on
// the server thread.
wl_resource* wl_buffer1 = GetSurfaceAttachedBuffer(surface_id_);
ASSERT_TRUE(wl_buffer1);
// Can't call OnSubmission until there is a release.
EXPECT_CALL(mock_surface_gpu, OnSubmission(_, _, _)).Times(0);
EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->GetObject<wl::MockSurface>(id), Attach(_, _, _))
.Times(2);
});
CommitBuffer(widget, kBufferId2, kBufferId2,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
SendFrameCallbackForSurface(surface_id_);
// Even though, this is stored on the client thread, but must only be used on
// the server thread.
wl_resource* wl_buffer2 = GetSurfaceAttachedBuffer(surface_id_);
ASSERT_TRUE(wl_buffer2);
CommitBuffer(widget, kBufferId3, kBufferId3,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
SendFrameCallbackForSurface(surface_id_);
// Let mojo messages to be processed and passed from host to gpu.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
// Releasing buffer2 can't trigger OnSubmission for buffer3, because
// OnSubmission for buffer2 has not been sent yet.
EXPECT_CALL(mock_surface_gpu, OnSubmission(_, _, _)).Times(0);
EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0);
PostToServerAndWait(
[wl_buffer2, id = surface_id_](wl::TestWaylandServerThread* server) {
server->GetObject<wl::MockSurface>(id)->ReleaseBuffer(wl_buffer2);
});
// Let mojo messages to be processed and passed from host to gpu.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
// Releasing buffer1 should trigger acks for both.
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId2, gfx::SwapResult::SWAP_ACK, _))
.Times(1);
EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId2, _)).Times(1);
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId3, gfx::SwapResult::SWAP_ACK, _))
.Times(1);
EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId3, _)).Times(1);
PostToServerAndWait(
[wl_buffer1, id = surface_id_](wl::TestWaylandServerThread* server) {
server->GetObject<wl::MockSurface>(id)->ReleaseBuffer(wl_buffer1);
});
// Let mojo messages to be processed and passed from host to gpu.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/);
DestroyBufferAndSetTerminateExpectation(kBufferId2, false /*fail*/);
DestroyBufferAndSetTerminateExpectation(kBufferId3, false /*fail*/);
}
// This test verifies that submitting the buffer more than once results in
// OnSubmission callback as Wayland compositor is not supposed to release the
// buffer committed twice.
TEST_P(WaylandBufferManagerTest,
OnSubmissionCalledForBufferCommitedTwiceInARow) {
constexpr uint32_t kBufferId1 = 1;
constexpr uint32_t kBufferId2 = 2;
const gfx::AcceleratedWidget widget = window_->GetWidget();
const gfx::Rect bounds = window_->GetBoundsInPixels();
MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), widget);
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(2);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1);
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2);
ProcessCreatedBufferResourcesWithExpectation(2u /* expected size */,
false /* fail */);
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _))
.Times(1);
ASSERT_TRUE(!connection_->presentation());
EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId1, _)).Times(1);
PostToServerAndWait(
[id = surface_id_, bounds](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(1);
EXPECT_CALL(*mock_surface, Frame(_)).Times(1);
EXPECT_CALL(*mock_surface,
Damage(0, 0, bounds.width(), bounds.height()))
.Times(1);
EXPECT_CALL(*mock_surface, Commit()).Times(1);
});
CommitBuffer(widget, kBufferId1, kBufferId1,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
// Let mojo messages to be passed from host to gpu.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
EXPECT_CALL(mock_surface_gpu, OnSubmission(_, _, _)).Times(0);
EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0);
PostToServerAndWait(
[id = surface_id_, bounds](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
testing::Mock::VerifyAndClearExpectations(mock_surface);
mock_surface->SendFrameCallback();
EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(1);
EXPECT_CALL(*mock_surface, Frame(_)).Times(1);
EXPECT_CALL(*mock_surface,
Damage(0, 0, bounds.width(), bounds.height()))
.Times(1);
EXPECT_CALL(*mock_surface, Commit()).Times(1);
});
// Commit second buffer now.
CommitBuffer(widget, kBufferId2, kBufferId2,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
// Let mojo messages to be passed from host to gpu.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId2, gfx::SwapResult::SWAP_ACK, _))
.Times(1);
EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId2, _)).Times(1);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
testing::Mock::VerifyAndClearExpectations(mock_surface);
EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(0);
EXPECT_CALL(*mock_surface, Frame(_)).Times(0);
EXPECT_CALL(*mock_surface, Damage(_, _, _, _)).Times(0);
EXPECT_CALL(*mock_surface, Commit()).Times(0);
mock_surface->ReleaseBuffer(mock_surface->prev_attached_buffer());
mock_surface->SendFrameCallback();
});
// Let mojo messages to be passed from host to gpu.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
// Now, commit the buffer with the |kBufferId2| again. The manager does not
// sends the submission callback, the compositor is not going to release a
// buffer as it was the same buffer submitted more than once.
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId2, gfx::SwapResult::SWAP_ACK, _))
.Times(1);
EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId2, _)).Times(1);
PostToServerAndWait(
[id = surface_id_, bounds](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
testing::Mock::VerifyAndClearExpectations(mock_surface);
EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(0);
EXPECT_CALL(*mock_surface, Frame(_)).Times(0);
EXPECT_CALL(*mock_surface,
Damage(0, 0, bounds.width(), bounds.height()))
.Times(1);
EXPECT_CALL(*mock_surface, Commit()).Times(1);
});
// Commit second buffer now.
CommitBuffer(widget, kBufferId2, kBufferId2,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
// Let mojo messages to be passed from host to gpu.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
EXPECT_CALL(mock_surface_gpu, OnSubmission(_, _, _)).Times(0);
EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
testing::Mock::VerifyAndClearExpectations(mock_surface);
EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(0);
EXPECT_CALL(*mock_surface, Frame(_)).Times(0);
EXPECT_CALL(*mock_surface, Damage(_, _, _, _)).Times(0);
EXPECT_CALL(*mock_surface, Commit()).Times(0);
mock_surface->SendFrameCallback();
});
// Let mojo messages to be passed from host to gpu.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
// If we commit another buffer now, the manager host must not automatically
// trigger OnSubmission and OnPresentation callbacks.
EXPECT_CALL(mock_surface_gpu, OnSubmission(_, _, _)).Times(0);
EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0);
PostToServerAndWait(
[id = surface_id_, bounds](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
testing::Mock::VerifyAndClearExpectations(mock_surface);
EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(1);
EXPECT_CALL(*mock_surface, Frame(_)).Times(1);
EXPECT_CALL(*mock_surface,
Damage(0, 0, bounds.width(), bounds.height()))
.Times(1);
EXPECT_CALL(*mock_surface, Commit()).Times(1);
});
CommitBuffer(widget, kBufferId1, kBufferId1,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
// Let mojo messages to be passed from host to gpu.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
// Now, they must be triggered once the buffer is released.
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _))
.Times(1);
EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId1, _)).Times(1);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
testing::Mock::VerifyAndClearExpectations(mock_surface);
mock_surface->ReleaseBuffer(mock_surface->prev_attached_buffer());
mock_surface->SendFrameCallback();
});
// Let mojo messages to be passed from host to gpu.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/);
DestroyBufferAndSetTerminateExpectation(kBufferId2, false /*fail*/);
}
// Tests that submitting a single buffer only receives an OnSubmission. This is
// required behaviour to make sure that submitting buffers in a quiescent state
// will be immediately acked.
TEST_P(WaylandBufferManagerTest, OnSubmissionCalledForSingleBuffer) {
constexpr uint32_t kBufferId1 = 1;
const gfx::AcceleratedWidget widget = window_->GetWidget();
const gfx::Rect bounds = window_->GetBoundsInPixels();
MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), widget);
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1);
ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */,
false /* fail */);
EXPECT_CALL(mock_surface_gpu,
OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _))
.Times(1);
EXPECT_CALL(mock_surface_gpu, OnPresentation(kBufferId1, _)).Times(1);
CommitBuffer(widget, kBufferId1, kBufferId1,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
// Let mojo messages to be passed from host to gpu.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/);
}
// Tests that when CommitOverlays(), root_surface can only be committed once all
// overlays in the frame are committed.
TEST_P(WaylandBufferManagerTest, RootSurfaceIsCommittedLast) {
if (!connection_->ShouldUseOverlayDelegation()) {
GTEST_SKIP();
}
constexpr uint32_t kBufferId1 = 1;
constexpr uint32_t kBufferId2 = 2;
constexpr uint32_t kBufferId3 = 3;
const gfx::AcceleratedWidget widget = window_->GetWidget();
const gfx::Rect bounds = window_->GetBoundsInPixels();
MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), widget);
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(3);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1);
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2);
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId3);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* linux_dmabuf = server->zwp_linux_dmabuf_v1();
// Ack creation for only the first 2 wl_buffers.
zwp_linux_buffer_params_v1_send_created(
linux_dmabuf->buffer_params()[0]->resource(),
linux_dmabuf->buffer_params()[0]->buffer_resource());
zwp_linux_buffer_params_v1_send_created(
linux_dmabuf->buffer_params()[1]->resource(),
linux_dmabuf->buffer_params()[1]->buffer_resource());
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
// root_surface shall not be committed as one of its subsurface is not
// committed yet due to pending wl_buffer creation.
EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(0);
EXPECT_CALL(*mock_surface, Frame(_)).Times(0);
EXPECT_CALL(*mock_surface, Commit()).Times(0);
});
std::vector<wl::WaylandOverlayConfig> overlay_configs;
overlay_configs.emplace_back(
CreateBasicWaylandOverlayConfig(INT32_MIN, kBufferId1, bounds));
overlay_configs.emplace_back(
CreateBasicWaylandOverlayConfig(0, kBufferId2, bounds));
overlay_configs.emplace_back(
CreateBasicWaylandOverlayConfig(1, kBufferId3, bounds));
buffer_manager_gpu_->CommitOverlays(window_->GetWidget(), 1u,
gfx::FrameData(delegate_.viz_seq()),
std::move(overlay_configs));
// Let mojo messages from gpu to host to go through.
base::RunLoop().RunUntilIdle();
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
testing::Mock::VerifyAndClearExpectations(mock_surface);
auto* linux_dmabuf = server->zwp_linux_dmabuf_v1();
// Once wl_buffer is created, all subsurfaces are committed, hence
// root_surface can be committed.
zwp_linux_buffer_params_v1_send_created(
linux_dmabuf->buffer_params()[0]->resource(),
linux_dmabuf->buffer_params()[0]->buffer_resource());
EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(1);
EXPECT_CALL(*mock_surface, Frame(_)).Times(1);
EXPECT_CALL(*mock_surface, Commit()).Times(1);
});
}
// TODO(crbug.com/367623923) Decouple this test from the older explicit sync
// protocol and/or add coverage for the new linux-drm-syncobj protocol.
TEST_P(WaylandBufferManagerTest, FencedRelease) {
if (!connection_->linux_explicit_synchronization_v1())
GTEST_SKIP();
constexpr uint32_t kBufferId1 = 1;
constexpr uint32_t kBufferId2 = 2;
constexpr uint32_t kBufferId3 = 3;
const gfx::AcceleratedWidget widget = window_->GetWidget();
const gfx::Rect bounds = gfx::Rect({0, 0}, kDefaultSize);
window_->SetBoundsInDIP(bounds);
MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), widget_);
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(3);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1);
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2);
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId3);
ProcessCreatedBufferResourcesWithExpectation(3u /* expected size */,
false /* fail */);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
constexpr uint32_t kNumberOfCommits = 3;
EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(kNumberOfCommits);
EXPECT_CALL(*mock_surface, Frame(_)).Times(kNumberOfCommits);
EXPECT_CALL(*mock_surface, Commit()).Times(kNumberOfCommits);
});
::testing::InSequence s;
// Commit the first buffer and expect the OnSubmission immediately.
EXPECT_CALL(
mock_surface_gpu,
OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK,
Truly([](const auto& fence) { return fence.is_null(); })))
.Times(1);
CommitBuffer(widget, kBufferId1, kBufferId1,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
// Let mojo messages from gpu to host to go through.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
SendFrameCallbackForSurface(surface_id_);
// Commit the second buffer now.
CommitBuffer(widget, kBufferId2, kBufferId2,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
SendFrameCallbackForSurface(surface_id_);
EXPECT_CALL(
mock_surface_gpu,
OnSubmission(kBufferId2, gfx::SwapResult::SWAP_ACK,
Truly([](const auto& fence) { return !fence.is_null(); })))
.Times(1);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
// Release the first buffer via fenced release. This should trigger
// OnSubmission for the second buffer with a non-null fence.
gfx::GpuFenceHandle handle;
const int32_t kFenceFD = dup(1);
handle.Adopt(base::ScopedFD(kFenceFD));
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
mock_surface->ReleaseBufferFenced(mock_surface->prev_attached_buffer(),
std::move(handle));
mock_surface->SendFrameCallback();
});
// Let mojo messages from gpu to host to go through.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
// Commit the third buffer now.
CommitBuffer(widget, kBufferId3, kBufferId3,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
SendFrameCallbackForSurface(surface_id_);
// Release the second buffer via immediate explicit release. This should
// trigger OnSubmission for the second buffer with a null fence.
EXPECT_CALL(
mock_surface_gpu,
OnSubmission(kBufferId3, gfx::SwapResult::SWAP_ACK,
Truly([](const auto& fence) { return fence.is_null(); })))
.Times(1);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
mock_surface->ReleaseBufferFenced(mock_surface->prev_attached_buffer(),
gfx::GpuFenceHandle());
mock_surface->SendFrameCallback();
});
// Let mojo messages from gpu to host to go through.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/);
DestroyBufferAndSetTerminateExpectation(kBufferId2, false /*fail*/);
DestroyBufferAndSetTerminateExpectation(kBufferId3, false /*fail*/);
}
// Tests that destroying a channel doesn't result in resetting surface state
// and buffers can be attached after the channel has been reinitialized.
TEST_P(WaylandBufferManagerTest,
CanSubmitBufferAfterChannelDestroyedAndInitialized) {
constexpr uint32_t kBufferId1 = 1;
const gfx::AcceleratedWidget widget = window_->GetWidget();
const gfx::Rect bounds = window_->GetBoundsInPixels();
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(1);
EXPECT_CALL(*mock_surface, Frame(_)).Times(1);
EXPECT_CALL(*mock_surface, Commit()).Times(1);
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1);
});
auto mock_surface_gpu =
std::make_unique<MockSurfaceGpu>(buffer_manager_gpu_.get(), widget);
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1);
ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */,
false /* fail */);
EXPECT_CALL(*mock_surface_gpu.get(),
OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _))
.Times(1);
EXPECT_CALL(*mock_surface_gpu.get(), OnPresentation(kBufferId1, _)).Times(1);
CommitBuffer(widget, kBufferId1, kBufferId1,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
// Let mojo messages from host to gpu to go through.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
// The root surface shouldn't get null buffer attached.
EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(0);
EXPECT_CALL(*mock_surface, Commit()).Times(1);
mock_surface->SendFrameCallback();
});
// After the channel has been destroyed and surface state has been reset, the
// interface should bind again and it still should be possible to attach
// buffers as WaylandBufferManagerHost::Surface::ResetSurfaceContents mustn't
// reset the state of |configured|.
manager_host_->OnChannelDestroyed();
manager_host_ = connection_->buffer_manager_host();
// Let mojo messages from host to gpu go through.
base::RunLoop().RunUntilIdle();
// The surface must has the buffer detached and all the buffers are destroyed.
// Release the fence as there is no further need to hold that as the client
// no longer expects that. Moreover, its next attach may result in a DCHECK,
// as the next buffer resource can be allocated on the same memory address
// resulting in a DCHECK when set_linux_buffer_release is called. The reason
// is that wl_resource_create calls internally calls malloc, which may reuse
// that memory.
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
server->GetObject<wl::MockSurface>(id)->ClearBufferReleases();
});
auto interface_ptr = manager_host_->BindInterface();
buffer_manager_gpu_->Initialize(std::move(interface_ptr), {},
/*supports_dma_buf=*/false,
/*supports_viewporter=*/true,
/*supports_acquire_fence=*/false,
/*supports_overlays=*/true,
/*supports_single_pixel_buffer=*/true);
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1);
ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */,
false /* fail */);
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
// The buffer must be attached.
EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(1);
EXPECT_CALL(*mock_surface, Frame(_)).Times(1);
EXPECT_CALL(*mock_surface, Commit()).Times(1);
});
EXPECT_CALL(*mock_surface_gpu.get(),
OnSubmission(kBufferId1, gfx::SwapResult::SWAP_ACK, _))
.Times(1);
EXPECT_CALL(*mock_surface_gpu.get(), OnPresentation(kBufferId1, _)).Times(1);
CommitBuffer(widget, kBufferId1, kBufferId1,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
// Let mojo messages from host to gpu to go through.
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/);
}
// Tests that destroying a channel results in attaching null buffers to the root
// surface, and hiding primary subsurface and overlay surfaces. This is required
// to make it possible for a GPU service to switch from hw acceleration to sw
// compositing. Otherwise, there will be frozen graphics represented by a
// primary subsurface as sw compositing uses the root surface to draw new
// frames. Verifies the fix for https://crbug.com/1201314
TEST_P(WaylandBufferManagerTest, HidesSubsurfacesOnChannelDestroyed) {
if (!connection_->ShouldUseOverlayDelegation()) {
GTEST_SKIP();
}
constexpr uint32_t kBufferId1 = 1;
constexpr uint32_t kBufferId2 = 2;
constexpr uint32_t kBufferId3 = 3;
const gfx::Rect bounds = window_->GetBoundsInPixels();
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(3);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1);
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2);
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId3);
ProcessCreatedBufferResourcesWithExpectation(3u /* expected size */,
false /* fail */);
// Prepare a frame with one background buffer, one primary plane and one
// additional overlay plane. This will simulate hw accelerated compositing.
std::vector<wl::WaylandOverlayConfig> overlay_configs;
overlay_configs.emplace_back(
CreateBasicWaylandOverlayConfig(INT32_MIN, kBufferId1, bounds));
overlay_configs.emplace_back(
CreateBasicWaylandOverlayConfig(0, kBufferId2, bounds));
overlay_configs.emplace_back(
CreateBasicWaylandOverlayConfig(1, kBufferId3, bounds));
buffer_manager_gpu_->CommitOverlays(window_->GetWidget(), 1u,
gfx::FrameData(delegate_.viz_seq()),
std::move(overlay_configs));
// Let mojo messages from gpu to host to go through.
base::RunLoop().RunUntilIdle();
// 3 surfaces must exist - root surface, the primary subsurface and one
// additional overlay surface. All of them must have buffers attached.
EXPECT_EQ(1u, window_->wayland_subsurfaces().size());
PostToServerAndWait(
[id = surface_id_,
primary_subsurface_id =
window_->primary_subsurface()->wayland_surface()->get_surface_id(),
overlay_surface_id =
window_->wayland_subsurfaces()
.begin()
->get()
->wayland_surface()
->get_surface_id()](wl::TestWaylandServerThread* server) {
EXPECT_TRUE(server->GetObject<wl::MockSurface>(id)->attached_buffer());
EXPECT_TRUE(server->GetObject<wl::MockSurface>(primary_subsurface_id)
->attached_buffer());
EXPECT_TRUE(server->GetObject<wl::MockSurface>(overlay_surface_id)
->attached_buffer());
});
// Pretend that the channel gets destroyed because of some internal reason.
manager_host_->OnChannelDestroyed();
manager_host_ = connection_->buffer_manager_host();
// Let mojo messages from host to gpu go through.
base::RunLoop().RunUntilIdle();
// The root surface should still have the buffer attached....
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
EXPECT_TRUE(server->GetObject<wl::MockSurface>(id)->attached_buffer());
});
// ... and the primary and secondary subsurfaces must be hidden.
EXPECT_FALSE(window_->primary_subsurface()->IsVisible());
EXPECT_EQ(1u, window_->wayland_subsurfaces().size());
EXPECT_FALSE(window_->wayland_subsurfaces().begin()->get()->IsVisible());
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* root_surface = server->GetObject<wl::MockSurface>(id);
root_surface->ClearBufferReleases();
root_surface->SendFrameCallback();
});
auto interface_ptr = manager_host_->BindInterface();
buffer_manager_gpu_->Initialize(std::move(interface_ptr), {},
/*supports_dma_buf=*/false,
/*supports_viewporter=*/true,
/*supports_acquire_fence=*/false,
/*supports_overlays=*/true,
/*supports_single_pixel_buffer=*/true);
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
// Now, create only one buffer and attach that to the root surface. The
// primary subsurface and secondary subsurface must remain invisible.
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(1);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1);
ProcessCreatedBufferResourcesWithExpectation(1u /* expected size */,
false /* fail */);
std::vector<wl::WaylandOverlayConfig> overlay_configs2;
overlay_configs2.push_back(
CreateBasicWaylandOverlayConfig(INT32_MIN, kBufferId1, bounds));
buffer_manager_gpu_->CommitOverlays(window_->GetWidget(), 2u,
gfx::FrameData(delegate_.viz_seq()),
std::move(overlay_configs2));
base::RunLoop().RunUntilIdle();
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
// The root surface should have the buffer detached.
EXPECT_TRUE(server->GetObject<wl::MockSurface>(id)->attached_buffer());
});
// The primary and secondary subsurfaces must remain hidden.
EXPECT_FALSE(window_->primary_subsurface()->IsVisible());
EXPECT_EQ(1u, window_->wayland_subsurfaces().size());
EXPECT_FALSE(window_->wayland_subsurfaces().begin()->get()->IsVisible());
}
TEST_P(WaylandBufferManagerTest, AttachNullBufferAndCommitOnHide) {
EXPECT_TRUE(window_->IsVisible());
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
EXPECT_CALL(*mock_surface, Attach(nullptr, 0, 0)).Times(1);
EXPECT_CALL(*mock_surface, Commit()).Times(1);
});
window_->Hide();
}
TEST_P(WaylandBufferManagerTest, HasOverlayPrioritizer) {
EXPECT_TRUE(connection_->overlay_prioritizer());
}
TEST_P(WaylandBufferManagerTest, CanSubmitOverlayPriority) {
if (!connection_->ShouldUseOverlayDelegation()) {
GTEST_SKIP();
}
std::vector<uint32_t> kBufferIds = {1, 2, 3};
MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(),
window_->GetWidget());
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(3);
});
for (auto id : kBufferIds)
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, id);
PostToServerAndWait(
[size = kBufferIds.size()](wl::TestWaylandServerThread* server) {
auto* linux_dmabuf = server->zwp_linux_dmabuf_v1();
for (size_t i = 0; i < size; i++) {
zwp_linux_buffer_params_v1_send_created(
linux_dmabuf->buffer_params()[i]->resource(),
linux_dmabuf->buffer_params()[i]->buffer_resource());
}
});
std::vector<std::pair<gfx::OverlayPriorityHint, uint32_t>> priorities = {
{gfx::OverlayPriorityHint::kNone,
OVERLAY_PRIORITIZED_SURFACE_OVERLAY_PRIORITY_NONE},
{gfx::OverlayPriorityHint::kRegular,
OVERLAY_PRIORITIZED_SURFACE_OVERLAY_PRIORITY_REGULAR},
{gfx::OverlayPriorityHint::kVideo,
OVERLAY_PRIORITIZED_SURFACE_OVERLAY_PRIORITY_REGULAR},
{gfx::OverlayPriorityHint::kLowLatencyCanvas,
OVERLAY_PRIORITIZED_SURFACE_OVERLAY_PRIORITY_PREFERRED_LOW_LATENCY_CANVAS},
{gfx::OverlayPriorityHint::kHardwareProtection,
OVERLAY_PRIORITIZED_SURFACE_OVERLAY_PRIORITY_REQUIRED_HARDWARE_PROTECTION}};
uint32_t frame_id = 0u;
for (const auto& priority : priorities) {
std::vector<wl::WaylandOverlayConfig> overlay_configs;
for (auto id : kBufferIds) {
overlay_configs.emplace_back(CreateBasicWaylandOverlayConfig(
id == 1 ? INT32_MIN : id, id, window_->GetBoundsInPixels()));
overlay_configs.back().priority_hint = priority.first;
}
buffer_manager_gpu_->CommitOverlays(window_->GetWidget(), ++frame_id,
gfx::FrameData(delegate_.viz_seq()),
std::move(overlay_configs));
base::RunLoop().RunUntilIdle();
for (auto& subsurface : window_->wayland_subsurfaces_) {
PostToServerAndWait(
[subsurface_id = subsurface->wayland_surface()->get_surface_id(),
&priority](wl::TestWaylandServerThread* server) {
auto* mock_surface_of_subsurface =
server->GetObject<wl::MockSurface>(subsurface_id);
EXPECT_TRUE(mock_surface_of_subsurface);
EXPECT_EQ(mock_surface_of_subsurface->prioritized_surface()
->overlay_priority(),
priority.second);
mock_surface_of_subsurface->SendFrameCallback();
});
}
SendFrameCallbackForSurface(surface_id_);
}
}
// Verifies that there are no more than certain number of submitted frames that
// wait presentation feedbacks. If the number of pending frames hit the
// threshold, the feedbacks are marked as failed and discarded. See the comments
// below in the test.
TEST_P(WaylandBufferManagerTest, FeedbacksAreDiscardedIfClientMisbehaves) {
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
ASSERT_TRUE(server->EnsureAndGetWpPresentation());
});
// 2 buffers are enough.
constexpr uint32_t kBufferId1 = 1;
constexpr uint32_t kBufferId2 = 2;
const gfx::AcceleratedWidget widget = window_->GetWidget();
const gfx::Rect bounds = gfx::Rect({0, 0}, kDefaultSize);
window_->SetBoundsInDIP(bounds);
MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(), widget_);
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
EXPECT_CALL(*server->zwp_linux_dmabuf_v1(), CreateParams(_, _, _)).Times(2);
});
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId1);
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/, kBufferId2);
ProcessCreatedBufferResourcesWithExpectation(2u /* expected size */,
false /* fail */);
// There will be 235 frames/commits.
constexpr uint32_t kNumberOfCommits = 235u;
PostToServerAndWait([id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
EXPECT_CALL(*mock_surface, Attach(_, _, _)).Times(kNumberOfCommits);
EXPECT_CALL(*mock_surface, Frame(_)).Times(kNumberOfCommits);
EXPECT_CALL(*server->EnsureAndGetWpPresentation(), Feedback(_, _, _, _))
.Times(kNumberOfCommits);
EXPECT_CALL(*mock_surface, Commit()).Times(kNumberOfCommits);
});
// The presentation feedbacks should fail after first 20 commits (that's the
// threshold that WaylandFrameManager maintains). Next, the presentation
// feedbacks will fail every consequent 17 commits as 3 frames out of 20
// previous frames that WaylandFrameManager stores are always preserved in
// case if the client restores the behavior (which is very unlikely).
uint32_t expect_presentation_failure_on_commit_seq = 20u;
// Chooses the next buffer id that should be committed.
uint32_t next_buffer_id_commit = 0;
// Specifies the expected number of failing feedbacks if the client
// misbehaves.
constexpr uint32_t kExpectedFailedFeedbacks = 17u;
for (auto commit_seq = 1u; commit_seq <= kNumberOfCommits; commit_seq++) {
// All the other expectations must come in order.
if (next_buffer_id_commit == kBufferId1)
next_buffer_id_commit = kBufferId2;
else
next_buffer_id_commit = kBufferId1;
EXPECT_CALL(mock_surface_gpu, OnSubmission(next_buffer_id_commit,
gfx::SwapResult::SWAP_ACK, _))
.Times(1);
if (commit_seq % expect_presentation_failure_on_commit_seq == 0) {
EXPECT_CALL(mock_surface_gpu,
OnPresentation(_, gfx::PresentationFeedback::Failure()))
.Times(kExpectedFailedFeedbacks);
// See comment near |expect_presentation_failure_on_commit_seq|.
expect_presentation_failure_on_commit_seq += kExpectedFailedFeedbacks;
} else {
// The client misbehaves and doesn't send presentation feedbacks. The
// frame manager doesn't mark the feedbacks as failed until the threshold
// is hit.
EXPECT_CALL(mock_surface_gpu, OnPresentation(_, _)).Times(0);
}
CommitBuffer(widget, next_buffer_id_commit, next_buffer_id_commit,
gfx::FrameData(delegate_.viz_seq()), bounds,
gfx::RoundedCornersF(), kDefaultScale, bounds);
PostToServerAndWait(
[id = surface_id_](wl::TestWaylandServerThread* server) {
auto* mock_surface = server->GetObject<wl::MockSurface>(id);
if (auto* buffer = mock_surface->prev_attached_buffer())
mock_surface->ReleaseBuffer(buffer);
server->EnsureAndGetWpPresentation()->DropPresentationCallback(
/*last=*/true);
mock_surface->SendFrameCallback();
});
base::RunLoop().RunUntilIdle();
testing::Mock::VerifyAndClearExpectations(&mock_surface_gpu);
}
DestroyBufferAndSetTerminateExpectation(kBufferId1, false /*fail*/);
DestroyBufferAndSetTerminateExpectation(kBufferId2, false /*fail*/);
}
TEST_P(WaylandBufferManagerTest, ExecutesTasksAfterInitialization) {
// Unbind the pipe.
manager_host_->OnChannelDestroyed();
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(buffer_manager_gpu_->remote_host_);
EXPECT_TRUE(buffer_manager_gpu_->pending_tasks_.empty());
constexpr uint32_t kDmabufBufferId = 1;
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/,
kDmabufBufferId);
CommitBuffer(window_->GetWidget(), kDmabufBufferId, kDmabufBufferId,
gfx::FrameData(delegate_.viz_seq()),
window_->GetBoundsInPixels(), gfx::RoundedCornersF(),
kDefaultScale, window_->GetBoundsInPixels());
DestroyBufferAndSetTerminateExpectation(kDmabufBufferId, false /*fail*/);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(3u, buffer_manager_gpu_->pending_tasks_.size());
auto interface_ptr = manager_host_->BindInterface();
buffer_manager_gpu_->Initialize(std::move(interface_ptr), {},
/*supports_dma_buf=*/false,
/*supports_viewporter=*/true,
/*supports_acquire_fence=*/false,
/*supports_overlays=*/true,
/*supports_single_pixel_buffer=*/true);
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(buffer_manager_gpu_->pending_tasks_.empty());
}
class WaylandBufferManagerViewportTest : public WaylandBufferManagerTest {
public:
WaylandBufferManagerViewportTest() = default;
~WaylandBufferManagerViewportTest() override = default;
protected:
void ViewportDestinationTestHelper(const gfx::RectF& bounds_rect,
const gfx::RectF& expected_bounds_rect) {
auto temp_window = CreateWindow();
temp_window->Show(false);
const uint32_t surface_id = temp_window->root_surface()->get_surface_id();
PostToServerAndWait([surface_id](wl::TestWaylandServerThread* server) {
ASSERT_TRUE(server->GetObject<wl::MockSurface>(surface_id));
});
ActivateSurface(delegate_);
constexpr uint32_t kBufferId1 = 1;
constexpr uint32_t kBufferId2 = 2;
MockSurfaceGpu mock_surface_gpu(buffer_manager_gpu_.get(),
temp_window->GetWidget());
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/,
kBufferId1);
CreateDmabufBasedBufferAndSetTerminateExpectation(false /*fail*/,
kBufferId2);
ProcessCreatedBufferResourcesWithExpectation(2u /* expected size */,
false /* fail */);
std::vector<wl::WaylandOverlayConfig> overlay_configs;
auto bounds = temp_window->GetBoundsInPixels();
overlay_configs.emplace_back(
CreateBasicWaylandOverlayConfig(INT32_MIN, kBufferId1, bounds));
overlay_configs.emplace_back(
CreateBasicWaylandOverlayConfig(0, kBufferId1, bounds));
overlay_configs.emplace_back(
CreateBasicWaylandOverlayConfig(1, kBufferId1, bounds_rect));
buffer_manager_gpu_->CommitOverlays(temp_window->GetWidget(), 1u,
gfx::FrameData(delegate_.viz_seq()),
std::move(overlay_configs));
base::RunLoop().RunUntilIdle();
PostToServerAndWait([](wl::TestWaylandServerThread* server) {
// Creates a handle for a subsurface.
const std::vector<raw_ptr<wl::TestZwpLinuxBufferParamsV1,
VectorExperimental>>& params_vector =
server->zwp_linux_dmabuf_v1()->buffer_params();
for (wl::TestZwpLinuxBufferParamsV1* mock_params : params_vector) {
zwp_linux_buffer_params_v1_send_created(mock_params->resource(),
mock_params->buffer_resource());
}
});
EXPECT_EQ(temp_window->wayland_subsurfaces_.size(), 1u);
WaylandSubsurface* subsurface =
temp_window->wayland_subsurfaces_.begin()->get();
ASSERT_TRUE(subsurface);
const uint32_t subsurface_id =
subsurface->wayland_surface()->get_surface_id();
PostToServerAndWait([subsurface_id](wl::TestWaylandServerThread* server) {
ASSERT_TRUE(server->GetObject<wl::MockSurface>(subsurface_id));
});
// The conversion from double to fixed and back is necessary because it
// happens during the roundtrip, and it creates significant error.
gfx::SizeF expected_size(wl_fixed_to_double(wl_fixed_from_double(
expected_bounds_rect.size().width())),
wl_fixed_to_double(wl_fixed_from_double(
expected_bounds_rect.size().height())));
PostToServerAndWait([surface_id, subsurface_id,
&expected_size](wl::TestWaylandServerThread* server) {
auto* mock_surface_of_subsurface =
server->GetObject<wl::MockSurface>(subsurface_id);
auto* test_vp = mock_surface_of_subsurface->viewport();
EXPECT_EQ(expected_size, test_vp->destination_size());
mock_surface_of_subsurface->SendFrameCallback();
server->GetObject<wl::MockSurface>(surface_id)->SendFrameCallback();
});
DestroyBufferAndSetTerminateExpectation(kBufferId1, false);
DestroyBufferAndSetTerminateExpectation(kBufferId2, false);
}
};
// Tests viewport destination is set correctly.
TEST_P(WaylandBufferManagerViewportTest, ViewportDestinationNonInteger) {
if (!connection_->ShouldUseOverlayDelegation()) {
GTEST_SKIP();
}
constexpr std::array<std::array<gfx::RectF, 2>, 2> test_data = {
{{gfx::RectF({21, 18}, {7, 11}), gfx::RectF({21, 18}, {7, 11})},
{gfx::RectF({7, 8}, {43, 63}), gfx::RectF({7, 8}, {43, 63})}}};
for (const auto& data : test_data) {
ViewportDestinationTestHelper(data[0] /* display_rect */,
data[1] /* expected_rect */);
}
}
TEST_P(WaylandBufferManagerViewportTest, ViewportDestinationInteger) {
if (!connection_->ShouldUseOverlayDelegation()) {
GTEST_SKIP();
}
constexpr std::array<std::array<gfx::RectF, 2>, 2> test_data = {
{{gfx::RectF({21, 18}, {7.423, 11.854}), gfx::RectF({21, 18}, {7, 12})},
{gfx::RectF({7, 8}, {43.562, 63.76}), gfx::RectF({7, 8}, {44, 64})}}};
for (const auto& data : test_data) {
ViewportDestinationTestHelper(data[0] /* display_rect */,
data[1] /* expected_rect */);
}
}
INSTANTIATE_TEST_SUITE_P(XdgVersionStableTest,
WaylandBufferManagerTest,
Values(wl::ServerConfig{}));
INSTANTIATE_TEST_SUITE_P(XdgVersionStableTest,
WaylandBufferManagerViewportTest,
Values(wl::ServerConfig{}));
INSTANTIATE_TEST_SUITE_P(
XdgVersionStableTestWithoutExplicitSync,
WaylandBufferManagerTest,
Values(wl::ServerConfig{
.use_explicit_synchronization =
wl::ShouldUseExplicitSynchronizationProtocol::kNone}));
INSTANTIATE_TEST_SUITE_P(
XdgVersionStableTestWithExplicitSync,
WaylandBufferManagerTest,
Values(wl::ServerConfig{
.use_explicit_synchronization =
wl::ShouldUseExplicitSynchronizationProtocol::kUse}));
INSTANTIATE_TEST_SUITE_P(
XdgVersionStableTestWithViewporterSurfaceScalingDisabled,
WaylandBufferManagerTest,
Values(wl::ServerConfig{.supports_viewporter_surface_scaling = false}));
INSTANTIATE_TEST_SUITE_P(
XdgVersionStableTestWithViewporterSurfaceScalingEnabled,
WaylandBufferManagerTest,
Values(wl::ServerConfig{.supports_viewporter_surface_scaling = true}));
} // namespace ui
|