1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322
|
/*
* Copyright (C) 2009, 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#if USE(ACCELERATED_COMPOSITING)
#include "RenderLayerCompositor.h"
#include "AnimationController.h"
#include "CanvasRenderingContext.h"
#include "CSSPropertyNames.h"
#include "Chrome.h"
#include "ChromeClient.h"
#include "Frame.h"
#include "FrameView.h"
#include "GraphicsLayer.h"
#include "HTMLCanvasElement.h"
#include "HTMLIFrameElement.h"
#include "HTMLNames.h"
#include "HitTestResult.h"
#include "InspectorInstrumentation.h"
#include "Logging.h"
#include "NodeList.h"
#include "Page.h"
#include "RenderApplet.h"
#include "RenderEmbeddedObject.h"
#include "RenderFullScreen.h"
#include "RenderGeometryMap.h"
#include "RenderIFrame.h"
#include "RenderLayerBacking.h"
#include "RenderReplica.h"
#include "RenderVideo.h"
#include "RenderView.h"
#include "ScrollbarTheme.h"
#include "ScrollingConstraints.h"
#include "ScrollingCoordinator.h"
#include "Settings.h"
#include "TiledBacking.h"
#include "TransformState.h"
#include <wtf/CurrentTime.h>
#include <wtf/TemporaryChange.h>
#include <wtf/text/CString.h>
#include <wtf/text/StringBuilder.h>
#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
#include "HTMLAudioElement.h"
#include "HTMLMediaElement.h"
#endif
#ifndef NDEBUG
#include "RenderTreeAsText.h"
#endif
#if ENABLE(3D_RENDERING)
// This symbol is used to determine from a script whether 3D rendering is enabled (via 'nm').
bool WebCoreHas3DRendering = true;
#endif
#if !PLATFORM(MAC) && !PLATFORM(IOS)
#define WTF_USE_COMPOSITING_FOR_SMALL_CANVASES 1
#endif
namespace WebCore {
static const int canvasAreaThresholdRequiringCompositing = 50 * 100;
static const int largeAreaThresholdForCompositing = 8192 * 8192;
// During page loading delay layer flushes up to this many seconds to allow them coalesce, reducing workload.
static const double throttledLayerFlushDelay = .5;
using namespace HTMLNames;
class RenderLayerCompositor::OverlapMap {
WTF_MAKE_NONCOPYABLE(OverlapMap);
public:
OverlapMap()
: m_geometryMap(UseTransforms)
{
// Begin assuming the root layer will be composited so that there is
// something on the stack. The root layer should also never get an
// popCompositingContainer call.
pushCompositingContainer();
}
void add(const RenderLayer* layer, const IntRect& bounds)
{
// Layers do not contribute to overlap immediately--instead, they will
// contribute to overlap as soon as their composited ancestor has been
// recursively processed and popped off the stack.
ASSERT(m_overlapStack.size() >= 2);
m_overlapStack[m_overlapStack.size() - 2].append(bounds);
m_layers.add(layer);
}
bool contains(const RenderLayer* layer)
{
return m_layers.contains(layer);
}
bool overlapsLayers(const IntRect& bounds) const
{
return m_overlapStack.last().intersects(bounds);
}
bool isEmpty()
{
return m_layers.isEmpty();
}
void pushCompositingContainer()
{
m_overlapStack.append(RectList());
}
void popCompositingContainer()
{
m_overlapStack[m_overlapStack.size() - 2].append(m_overlapStack.last());
m_overlapStack.removeLast();
}
RenderGeometryMap& geometryMap() { return m_geometryMap; }
private:
struct RectList {
Vector<IntRect> rects;
IntRect boundingRect;
void append(const IntRect& rect)
{
rects.append(rect);
boundingRect.unite(rect);
}
void append(const RectList& rectList)
{
rects.appendVector(rectList.rects);
boundingRect.unite(rectList.boundingRect);
}
bool intersects(const IntRect& rect) const
{
if (!rects.size() || !boundingRect.intersects(rect))
return false;
for (unsigned i = 0; i < rects.size(); i++) {
if (rects[i].intersects(rect))
return true;
}
return false;
}
};
Vector<RectList> m_overlapStack;
HashSet<const RenderLayer*> m_layers;
RenderGeometryMap m_geometryMap;
};
struct CompositingState {
CompositingState(RenderLayer* compAncestor, bool testOverlap = true)
: m_compositingAncestor(compAncestor)
, m_subtreeIsCompositing(false)
, m_testingOverlap(testOverlap)
#ifndef NDEBUG
, m_depth(0)
#endif
{
}
CompositingState(const CompositingState& other)
: m_compositingAncestor(other.m_compositingAncestor)
, m_subtreeIsCompositing(other.m_subtreeIsCompositing)
, m_testingOverlap(other.m_testingOverlap)
#ifndef NDEBUG
, m_depth(other.m_depth + 1)
#endif
{
}
RenderLayer* m_compositingAncestor;
bool m_subtreeIsCompositing;
bool m_testingOverlap;
#ifndef NDEBUG
int m_depth;
#endif
};
static inline bool compositingLogEnabled()
{
#if !LOG_DISABLED
return LogCompositing.state == WTFLogChannelOn;
#else
return false;
#endif
}
RenderLayerCompositor::RenderLayerCompositor(RenderView* renderView)
: m_renderView(renderView)
, m_updateCompositingLayersTimer(this, &RenderLayerCompositor::updateCompositingLayersTimerFired)
, m_hasAcceleratedCompositing(true)
, m_compositingTriggers(static_cast<ChromeClient::CompositingTriggerFlags>(ChromeClient::AllTriggers))
, m_compositedLayerCount(0)
, m_showDebugBorders(false)
, m_showRepaintCounter(false)
, m_acceleratedDrawingEnabled(false)
, m_reevaluateCompositingAfterLayout(false)
, m_compositing(false)
, m_compositingLayersNeedRebuild(false)
, m_flushingLayers(false)
, m_shouldFlushOnReattach(false)
, m_forceCompositingMode(false)
, m_inPostLayoutUpdate(false)
, m_isTrackingRepaints(false)
, m_layersWithTiledBackingCount(0)
, m_rootLayerAttachment(RootLayerUnattached)
, m_layerFlushTimer(this, &RenderLayerCompositor::layerFlushTimerFired)
, m_layerFlushThrottlingEnabled(false)
, m_layerFlushThrottlingTemporarilyDisabledForInteraction(false)
, m_hasPendingLayerFlush(false)
, m_paintRelatedMilestonesTimer(this, &RenderLayerCompositor::paintRelatedMilestonesTimerFired)
#if !LOG_DISABLED
, m_rootLayerUpdateCount(0)
, m_obligateCompositedLayerCount(0)
, m_secondaryCompositedLayerCount(0)
, m_obligatoryBackingStoreBytes(0)
, m_secondaryBackingStoreBytes(0)
#endif
{
}
RenderLayerCompositor::~RenderLayerCompositor()
{
// Take care that the owned GraphicsLayers are deleted first as their destructors may call back here.
m_clipLayer = nullptr;
m_scrollLayer = nullptr;
ASSERT(m_rootLayerAttachment == RootLayerUnattached);
}
void RenderLayerCompositor::enableCompositingMode(bool enable /* = true */)
{
if (enable != m_compositing) {
m_compositing = enable;
if (m_compositing) {
ensureRootLayer();
notifyIFramesOfCompositingChange();
} else
destroyRootLayer();
}
}
void RenderLayerCompositor::cacheAcceleratedCompositingFlags()
{
bool hasAcceleratedCompositing = false;
bool showDebugBorders = false;
bool showRepaintCounter = false;
bool forceCompositingMode = false;
bool acceleratedDrawingEnabled = false;
if (Settings* settings = m_renderView->document()->settings()) {
hasAcceleratedCompositing = settings->acceleratedCompositingEnabled();
// We allow the chrome to override the settings, in case the page is rendered
// on a chrome that doesn't allow accelerated compositing.
if (hasAcceleratedCompositing) {
if (Page* page = this->page()) {
ChromeClient* chromeClient = page->chrome().client();
m_compositingTriggers = chromeClient->allowedCompositingTriggers();
hasAcceleratedCompositing = m_compositingTriggers;
}
}
showDebugBorders = settings->showDebugBorders();
showRepaintCounter = settings->showRepaintCounter();
forceCompositingMode = settings->forceCompositingMode() && hasAcceleratedCompositing;
if (forceCompositingMode && m_renderView->document()->ownerElement())
forceCompositingMode = requiresCompositingForScrollableFrame();
acceleratedDrawingEnabled = settings->acceleratedDrawingEnabled();
}
if (hasAcceleratedCompositing != m_hasAcceleratedCompositing || showDebugBorders != m_showDebugBorders || showRepaintCounter != m_showRepaintCounter || forceCompositingMode != m_forceCompositingMode)
setCompositingLayersNeedRebuild();
bool debugBordersChanged = m_showDebugBorders != showDebugBorders;
m_hasAcceleratedCompositing = hasAcceleratedCompositing;
m_showDebugBorders = showDebugBorders;
m_showRepaintCounter = showRepaintCounter;
m_forceCompositingMode = forceCompositingMode;
m_acceleratedDrawingEnabled = acceleratedDrawingEnabled;
if (debugBordersChanged) {
if (m_layerForHorizontalScrollbar)
m_layerForHorizontalScrollbar->setShowDebugBorder(m_showDebugBorders);
if (m_layerForVerticalScrollbar)
m_layerForVerticalScrollbar->setShowDebugBorder(m_showDebugBorders);
if (m_layerForScrollCorner)
m_layerForScrollCorner->setShowDebugBorder(m_showDebugBorders);
}
}
bool RenderLayerCompositor::canRender3DTransforms() const
{
#if !ENABLE(3D_RENDERING)
return false;
#elif PLATFORM(QT)
return true;
#else
return hasAcceleratedCompositing() && (m_compositingTriggers & ChromeClient::ThreeDTransformTrigger);
#endif
}
void RenderLayerCompositor::setCompositingLayersNeedRebuild(bool needRebuild)
{
if (inCompositingMode())
m_compositingLayersNeedRebuild = needRebuild;
}
void RenderLayerCompositor::customPositionForVisibleRectComputation(const GraphicsLayer* graphicsLayer, FloatPoint& position) const
{
if (graphicsLayer != m_scrollLayer.get())
return;
FrameView* frameView = m_renderView ? m_renderView->frameView() : 0;
if (!frameView)
return;
FloatPoint scrollPosition = -position;
scrollPosition = frameView->constrainScrollPositionForOverhang(roundedIntPoint(scrollPosition));
position = -scrollPosition;
}
void RenderLayerCompositor::notifyFlushRequired(const GraphicsLayer* layer)
{
scheduleLayerFlush(layer->canThrottleLayerFlush());
}
void RenderLayerCompositor::scheduleLayerFlushNow()
{
m_hasPendingLayerFlush = false;
if (Page* page = this->page())
page->chrome().client()->scheduleCompositingLayerFlush();
}
void RenderLayerCompositor::scheduleLayerFlush(bool canThrottle)
{
if (canThrottle && isThrottlingLayerFlushes()) {
m_hasPendingLayerFlush = true;
return;
}
scheduleLayerFlushNow();
}
void RenderLayerCompositor::flushPendingLayerChanges(bool isFlushRoot)
{
// FrameView::flushCompositingStateIncludingSubframes() flushes each subframe,
// but GraphicsLayer::flushCompositingState() will cross frame boundaries
// if the GraphicsLayers are connected (the RootLayerAttachedViaEnclosingFrame case).
// As long as we're not the root of the flush, we can bail.
if (!isFlushRoot && rootLayerAttachment() == RootLayerAttachedViaEnclosingFrame)
return;
if (rootLayerAttachment() == RootLayerUnattached) {
m_shouldFlushOnReattach = true;
return;
}
AnimationUpdateBlock animationUpdateBlock(m_renderView->frameView()->frame()->animation());
ASSERT(!m_flushingLayers);
m_flushingLayers = true;
FrameView* frameView = m_renderView ? m_renderView->frameView() : 0;
if (GraphicsLayer* rootLayer = rootGraphicsLayer()) {
if (frameView) {
// Having a m_clipLayer indicates that we're doing scrolling via GraphicsLayers.
IntRect visibleRect = m_clipLayer ? IntRect(IntPoint(), frameView->contentsSize()) : frameView->visibleContentRect();
rootLayer->flushCompositingState(visibleRect);
}
}
ASSERT(m_flushingLayers);
m_flushingLayers = false;
if (!m_viewportConstrainedLayersNeedingUpdate.isEmpty()) {
HashSet<RenderLayer*>::const_iterator end = m_viewportConstrainedLayersNeedingUpdate.end();
for (HashSet<RenderLayer*>::const_iterator it = m_viewportConstrainedLayersNeedingUpdate.begin(); it != end; ++it)
registerOrUpdateViewportConstrainedLayer(*it);
m_viewportConstrainedLayersNeedingUpdate.clear();
}
startLayerFlushTimerIfNeeded();
}
void RenderLayerCompositor::didFlushChangesForLayer(RenderLayer* layer, const GraphicsLayer* graphicsLayer)
{
if (m_viewportConstrainedLayers.contains(layer))
m_viewportConstrainedLayersNeedingUpdate.add(layer);
RenderLayerBacking* backing = layer->backing();
if (backing->backgroundLayerPaintsFixedRootBackground() && graphicsLayer == backing->backgroundLayer())
fixedRootBackgroundLayerChanged();
}
void RenderLayerCompositor::didPaintBacking(RenderLayerBacking*)
{
FrameView* frameView = m_renderView->frameView();
frameView->setLastPaintTime(currentTime());
if (frameView->milestonesPendingPaint() && !m_paintRelatedMilestonesTimer.isActive())
m_paintRelatedMilestonesTimer.startOneShot(0);
}
void RenderLayerCompositor::didChangeVisibleRect()
{
GraphicsLayer* rootLayer = rootGraphicsLayer();
if (!rootLayer)
return;
FrameView* frameView = m_renderView ? m_renderView->frameView() : 0;
if (!frameView)
return;
IntRect visibleRect = m_clipLayer ? IntRect(IntPoint(), frameView->contentsSize()) : frameView->visibleContentRect();
if (!rootLayer->visibleRectChangeRequiresFlush(visibleRect))
return;
scheduleLayerFlushNow();
}
void RenderLayerCompositor::notifyFlushBeforeDisplayRefresh(const GraphicsLayer*)
{
if (!m_layerUpdater) {
PlatformDisplayID displayID = 0;
if (Page* page = this->page())
displayID = page->chrome().displayID();
m_layerUpdater = adoptPtr(new GraphicsLayerUpdater(this, displayID));
}
m_layerUpdater->scheduleUpdate();
}
void RenderLayerCompositor::flushLayers(GraphicsLayerUpdater*)
{
flushPendingLayerChanges(true); // FIXME: deal with iframes
}
void RenderLayerCompositor::layerTiledBackingUsageChanged(const GraphicsLayer*, bool usingTiledBacking)
{
if (usingTiledBacking)
++m_layersWithTiledBackingCount;
else {
ASSERT(m_layersWithTiledBackingCount > 0);
--m_layersWithTiledBackingCount;
}
}
RenderLayerCompositor* RenderLayerCompositor::enclosingCompositorFlushingLayers() const
{
if (!m_renderView->frameView())
return 0;
for (Frame* frame = m_renderView->frameView()->frame(); frame; frame = frame->tree()->parent()) {
RenderLayerCompositor* compositor = frame->contentRenderer() ? frame->contentRenderer()->compositor() : 0;
if (compositor->isFlushingLayers())
return compositor;
}
return 0;
}
void RenderLayerCompositor::scheduleCompositingLayerUpdate()
{
if (!m_updateCompositingLayersTimer.isActive())
m_updateCompositingLayersTimer.startOneShot(0);
}
void RenderLayerCompositor::updateCompositingLayersTimerFired(Timer<RenderLayerCompositor>*)
{
updateCompositingLayers(CompositingUpdateAfterLayout);
}
bool RenderLayerCompositor::hasAnyAdditionalCompositedLayers(const RenderLayer* rootLayer) const
{
return m_compositedLayerCount > (rootLayer->isComposited() ? 1 : 0);
}
void RenderLayerCompositor::updateCompositingLayers(CompositingUpdateType updateType, RenderLayer* updateRoot)
{
m_updateCompositingLayersTimer.stop();
// Compositing layers will be updated in Document::implicitClose() if suppressed here.
if (!m_renderView->document()->visualUpdatesAllowed())
return;
// Avoid updating the layers with old values. Compositing layers will be updated after the layout is finished.
if (m_renderView->needsLayout())
return;
if (m_forceCompositingMode && !m_compositing)
enableCompositingMode(true);
if (!m_reevaluateCompositingAfterLayout && !m_compositing)
return;
AnimationUpdateBlock animationUpdateBlock(m_renderView->frameView()->frame()->animation());
TemporaryChange<bool> postLayoutChange(m_inPostLayoutUpdate, true);
bool checkForHierarchyUpdate = m_reevaluateCompositingAfterLayout;
bool needGeometryUpdate = false;
switch (updateType) {
case CompositingUpdateAfterStyleChange:
case CompositingUpdateAfterLayout:
case CompositingUpdateOnHitTest:
checkForHierarchyUpdate = true;
break;
case CompositingUpdateOnScroll:
checkForHierarchyUpdate = true; // Overlap can change with scrolling, so need to check for hierarchy updates.
needGeometryUpdate = true;
break;
case CompositingUpdateOnCompositedScroll:
needGeometryUpdate = true;
break;
}
if (!checkForHierarchyUpdate && !needGeometryUpdate)
return;
bool needHierarchyUpdate = m_compositingLayersNeedRebuild;
bool isFullUpdate = !updateRoot;
// Only clear the flag if we're updating the entire hierarchy.
m_compositingLayersNeedRebuild = false;
updateRoot = rootRenderLayer();
if (isFullUpdate && updateType == CompositingUpdateAfterLayout)
m_reevaluateCompositingAfterLayout = false;
#if !LOG_DISABLED
double startTime = 0;
if (compositingLogEnabled()) {
++m_rootLayerUpdateCount;
startTime = currentTime();
}
#endif
if (checkForHierarchyUpdate) {
// Go through the layers in presentation order, so that we can compute which RenderLayers need compositing layers.
// FIXME: we could maybe do this and the hierarchy udpate in one pass, but the parenting logic would be more complex.
CompositingState compState(updateRoot);
bool layersChanged = false;
bool saw3DTransform = false;
OverlapMap overlapTestRequestMap;
computeCompositingRequirements(0, updateRoot, &overlapTestRequestMap, compState, layersChanged, saw3DTransform);
needHierarchyUpdate |= layersChanged;
}
#if !LOG_DISABLED
if (compositingLogEnabled() && isFullUpdate && (needHierarchyUpdate || needGeometryUpdate)) {
m_obligateCompositedLayerCount = 0;
m_secondaryCompositedLayerCount = 0;
m_obligatoryBackingStoreBytes = 0;
m_secondaryBackingStoreBytes = 0;
Frame* frame = m_renderView->frameView()->frame();
bool isMainFrame = !m_renderView->document()->ownerElement();
LOG(Compositing, "\nUpdate %d of %s.\n", m_rootLayerUpdateCount, isMainFrame ? "main frame" : frame->tree()->uniqueName().string().utf8().data());
}
#endif
if (needHierarchyUpdate) {
// Update the hierarchy of the compositing layers.
Vector<GraphicsLayer*> childList;
rebuildCompositingLayerTree(updateRoot, childList, 0);
// Host the document layer in the RenderView's root layer.
if (isFullUpdate) {
// Even when childList is empty, don't drop out of compositing mode if there are
// composited layers that we didn't hit in our traversal (e.g. because of visibility:hidden).
if (childList.isEmpty() && !hasAnyAdditionalCompositedLayers(updateRoot))
destroyRootLayer();
else
m_rootContentLayer->setChildren(childList);
}
} else if (needGeometryUpdate) {
// We just need to do a geometry update. This is only used for position:fixed scrolling;
// most of the time, geometry is updated via RenderLayer::styleChanged().
updateLayerTreeGeometry(updateRoot, 0);
}
#if !LOG_DISABLED
if (compositingLogEnabled() && isFullUpdate && (needHierarchyUpdate || needGeometryUpdate)) {
double endTime = currentTime();
LOG(Compositing, "Total layers primary secondary obligatory backing (KB) secondary backing(KB) total backing (KB) update time (ms)\n");
LOG(Compositing, "%8d %11d %9d %20.2f %22.2f %22.2f %18.2f\n",
m_obligateCompositedLayerCount + m_secondaryCompositedLayerCount, m_obligateCompositedLayerCount,
m_secondaryCompositedLayerCount, m_obligatoryBackingStoreBytes / 1024, m_secondaryBackingStoreBytes / 1024, (m_obligatoryBackingStoreBytes + m_secondaryBackingStoreBytes) / 1024, 1000.0 * (endTime - startTime));
}
#endif
ASSERT(updateRoot || !m_compositingLayersNeedRebuild);
if (!hasAcceleratedCompositing())
enableCompositingMode(false);
// Inform the inspector that the layer tree has changed.
InspectorInstrumentation::layerTreeDidChange(page());
}
void RenderLayerCompositor::layerBecameNonComposited(const RenderLayer* renderLayer)
{
// Inform the inspector that the given RenderLayer was destroyed.
InspectorInstrumentation::renderLayerDestroyed(page(), renderLayer);
ASSERT(m_compositedLayerCount > 0);
--m_compositedLayerCount;
}
#if !LOG_DISABLED
void RenderLayerCompositor::logLayerInfo(const RenderLayer* layer, int depth)
{
if (!compositingLogEnabled())
return;
RenderLayerBacking* backing = layer->backing();
if (requiresCompositingLayer(layer) || layer->isRootLayer()) {
++m_obligateCompositedLayerCount;
m_obligatoryBackingStoreBytes += backing->backingStoreMemoryEstimate();
} else {
++m_secondaryCompositedLayerCount;
m_secondaryBackingStoreBytes += backing->backingStoreMemoryEstimate();
}
StringBuilder logString;
logString.append(String::format("%*p %dx%d %.2fKB", 12 + depth * 2, layer,
backing->compositedBounds().width().round(), backing->compositedBounds().height().round(),
backing->backingStoreMemoryEstimate() / 1024));
logString.append(" (");
logString.append(logReasonsForCompositing(layer));
logString.append(") ");
if (backing->graphicsLayer()->contentsOpaque() || backing->paintsIntoCompositedAncestor()) {
logString.append('[');
if (backing->graphicsLayer()->contentsOpaque())
logString.append("opaque");
if (backing->paintsIntoCompositedAncestor())
logString.append("paints into ancestor");
logString.append("] ");
}
logString.append(layer->name());
LOG(Compositing, "%s", logString.toString().utf8().data());
}
#endif
bool RenderLayerCompositor::updateBacking(RenderLayer* layer, CompositingChangeRepaint shouldRepaint)
{
bool layerChanged = false;
RenderLayer::ViewportConstrainedNotCompositedReason viewportConstrainedNotCompositedReason = RenderLayer::NoNotCompositedReason;
if (needsToBeComposited(layer, &viewportConstrainedNotCompositedReason)) {
enableCompositingMode();
if (!layer->backing()) {
// If we need to repaint, do so before making backing
if (shouldRepaint == CompositingChangeRepaintNow)
repaintOnCompositingChange(layer);
layer->ensureBacking();
// At this time, the ScrollingCooridnator only supports the top-level frame.
if (layer->isRootLayer() && !m_renderView->document()->ownerElement()) {
layer->backing()->attachToScrollingCoordinatorWithParent(0);
if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
scrollingCoordinator->frameViewRootLayerDidChange(m_renderView->frameView());
#if ENABLE(RUBBER_BANDING)
if (Page* page = this->page()) {
updateLayerForHeader(page->headerHeight());
updateLayerForFooter(page->footerHeight());
}
#endif
}
// This layer and all of its descendants have cached repaints rects that are relative to
// the repaint container, so change when compositing changes; we need to update them here.
if (layer->parent())
layer->computeRepaintRectsIncludingDescendants();
layerChanged = true;
}
} else {
if (layer->backing()) {
// If we're removing backing on a reflection, clear the source GraphicsLayer's pointer to
// its replica GraphicsLayer. In practice this should never happen because reflectee and reflection
// are both either composited, or not composited.
if (layer->isReflection()) {
RenderLayer* sourceLayer = toRenderLayerModelObject(layer->renderer()->parent())->layer();
if (RenderLayerBacking* backing = sourceLayer->backing()) {
ASSERT(backing->graphicsLayer()->replicaLayer() == layer->backing()->graphicsLayer());
backing->graphicsLayer()->setReplicatedByLayer(0);
}
}
removeViewportConstrainedLayer(layer);
layer->clearBacking();
layerChanged = true;
// This layer and all of its descendants have cached repaints rects that are relative to
// the repaint container, so change when compositing changes; we need to update them here.
layer->computeRepaintRectsIncludingDescendants();
// If we need to repaint, do so now that we've removed the backing
if (shouldRepaint == CompositingChangeRepaintNow)
repaintOnCompositingChange(layer);
}
}
#if ENABLE(VIDEO)
if (layerChanged && layer->renderer()->isVideo()) {
// If it's a video, give the media player a chance to hook up to the layer.
RenderVideo* video = toRenderVideo(layer->renderer());
video->acceleratedRenderingStateChanged();
}
#endif
if (layerChanged && layer->renderer()->isRenderPart()) {
RenderLayerCompositor* innerCompositor = frameContentsCompositor(toRenderPart(layer->renderer()));
if (innerCompositor && innerCompositor->inCompositingMode())
innerCompositor->updateRootLayerAttachment();
}
if (layerChanged)
layer->clearClipRectsIncludingDescendants(PaintingClipRects);
// If a fixed position layer gained/lost a backing or the reason not compositing it changed,
// the scrolling coordinator needs to recalculate whether it can do fast scrolling.
if (layer->renderer()->style()->position() == FixedPosition) {
if (layer->viewportConstrainedNotCompositedReason() != viewportConstrainedNotCompositedReason) {
layer->setViewportConstrainedNotCompositedReason(viewportConstrainedNotCompositedReason);
layerChanged = true;
}
if (layerChanged) {
if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
scrollingCoordinator->frameViewFixedObjectsDidChange(m_renderView->frameView());
}
} else
layer->setViewportConstrainedNotCompositedReason(RenderLayer::NoNotCompositedReason);
if (layer->backing())
layer->backing()->updateDebugIndicators(m_showDebugBorders, m_showRepaintCounter);
return layerChanged;
}
bool RenderLayerCompositor::updateLayerCompositingState(RenderLayer* layer, CompositingChangeRepaint shouldRepaint)
{
bool layerChanged = updateBacking(layer, shouldRepaint);
// See if we need content or clipping layers. Methods called here should assume
// that the compositing state of descendant layers has not been updated yet.
if (layer->backing() && layer->backing()->updateGraphicsLayerConfiguration())
layerChanged = true;
return layerChanged;
}
void RenderLayerCompositor::repaintOnCompositingChange(RenderLayer* layer)
{
// If the renderer is not attached yet, no need to repaint.
if (layer->renderer() != m_renderView && !layer->renderer()->parent())
return;
RenderLayerModelObject* repaintContainer = layer->renderer()->containerForRepaint();
if (!repaintContainer)
repaintContainer = m_renderView;
layer->repaintIncludingNonCompositingDescendants(repaintContainer);
if (repaintContainer == m_renderView) {
// The contents of this layer may be moving between the window
// and a GraphicsLayer, so we need to make sure the window system
// synchronizes those changes on the screen.
m_renderView->frameView()->setNeedsOneShotDrawingSynchronization();
}
}
// This method assumes that layout is up-to-date, unlike repaintOnCompositingChange().
void RenderLayerCompositor::repaintInCompositedAncestor(RenderLayer* layer, const LayoutRect& rect)
{
RenderLayer* compositedAncestor = layer->enclosingCompositingLayerForRepaint(ExcludeSelf);
if (compositedAncestor) {
ASSERT(compositedAncestor->backing());
LayoutPoint offset;
layer->convertToLayerCoords(compositedAncestor, offset);
LayoutRect repaintRect = rect;
repaintRect.moveBy(offset);
compositedAncestor->setBackingNeedsRepaintInRect(repaintRect);
}
// The contents of this layer may be moving from a GraphicsLayer to the window,
// so we need to make sure the window system synchronizes those changes on the screen.
if (compositedAncestor == m_renderView->layer())
m_renderView->frameView()->setNeedsOneShotDrawingSynchronization();
}
// The bounds of the GraphicsLayer created for a compositing layer is the union of the bounds of all the descendant
// RenderLayers that are rendered by the composited RenderLayer.
LayoutRect RenderLayerCompositor::calculateCompositedBounds(const RenderLayer* layer, const RenderLayer* ancestorLayer) const
{
if (!canBeComposited(layer))
return LayoutRect();
return layer->calculateLayerBounds(ancestorLayer, 0, RenderLayer::DefaultCalculateLayerBoundsFlags | RenderLayer::ExcludeHiddenDescendants | RenderLayer::DontConstrainForMask);
}
void RenderLayerCompositor::layerWasAdded(RenderLayer* /*parent*/, RenderLayer* /*child*/)
{
setCompositingLayersNeedRebuild();
}
void RenderLayerCompositor::layerWillBeRemoved(RenderLayer* parent, RenderLayer* child)
{
if (!child->isComposited() || parent->renderer()->documentBeingDestroyed())
return;
removeViewportConstrainedLayer(child);
repaintInCompositedAncestor(child, child->backing()->compositedBounds());
setCompositingParent(child, 0);
setCompositingLayersNeedRebuild();
}
RenderLayer* RenderLayerCompositor::enclosingNonStackingClippingLayer(const RenderLayer* layer) const
{
for (RenderLayer* curr = layer->parent(); curr != 0; curr = curr->parent()) {
if (curr->isStackingContainer())
return 0;
if (curr->renderer()->hasClipOrOverflowClip())
return curr;
}
return 0;
}
void RenderLayerCompositor::addToOverlapMap(OverlapMap& overlapMap, RenderLayer* layer, IntRect& layerBounds, bool& boundsComputed)
{
if (layer->isRootLayer())
return;
if (!boundsComputed) {
// FIXME: If this layer's overlap bounds include its children, we don't need to add its
// children's bounds to the overlap map.
layerBounds = enclosingIntRect(overlapMap.geometryMap().absoluteRect(layer->overlapBounds()));
// Empty rects never intersect, but we need them to for the purposes of overlap testing.
if (layerBounds.isEmpty())
layerBounds.setSize(IntSize(1, 1));
boundsComputed = true;
}
IntRect clipRect = pixelSnappedIntRect(layer->backgroundClipRect(RenderLayer::ClipRectsContext(rootRenderLayer(), 0, AbsoluteClipRects)).rect()); // FIXME: Incorrect for CSS regions.
if (Settings* settings = m_renderView->document()->settings())
if (!settings->applyPageScaleFactorInCompositor())
clipRect.scale(pageScaleFactor());
clipRect.intersect(layerBounds);
overlapMap.add(layer, clipRect);
}
void RenderLayerCompositor::addToOverlapMapRecursive(OverlapMap& overlapMap, RenderLayer* layer, RenderLayer* ancestorLayer)
{
if (!canBeComposited(layer) || overlapMap.contains(layer))
return;
// A null ancestorLayer is an indication that 'layer' has already been pushed.
if (ancestorLayer)
overlapMap.geometryMap().pushMappingsToAncestor(layer, ancestorLayer);
IntRect bounds;
bool haveComputedBounds = false;
addToOverlapMap(overlapMap, layer, bounds, haveComputedBounds);
#if !ASSERT_DISABLED
LayerListMutationDetector mutationChecker(layer);
#endif
if (layer->isStackingContainer()) {
if (Vector<RenderLayer*>* negZOrderList = layer->negZOrderList()) {
size_t listSize = negZOrderList->size();
for (size_t i = 0; i < listSize; ++i) {
RenderLayer* curLayer = negZOrderList->at(i);
addToOverlapMapRecursive(overlapMap, curLayer, layer);
}
}
}
if (Vector<RenderLayer*>* normalFlowList = layer->normalFlowList()) {
size_t listSize = normalFlowList->size();
for (size_t i = 0; i < listSize; ++i) {
RenderLayer* curLayer = normalFlowList->at(i);
addToOverlapMapRecursive(overlapMap, curLayer, layer);
}
}
if (layer->isStackingContainer()) {
if (Vector<RenderLayer*>* posZOrderList = layer->posZOrderList()) {
size_t listSize = posZOrderList->size();
for (size_t i = 0; i < listSize; ++i) {
RenderLayer* curLayer = posZOrderList->at(i);
addToOverlapMapRecursive(overlapMap, curLayer, layer);
}
}
}
if (ancestorLayer)
overlapMap.geometryMap().popMappingsToAncestor(ancestorLayer);
}
// Recurse through the layers in z-index and overflow order (which is equivalent to painting order)
// For the z-order children of a compositing layer:
// If a child layers has a compositing layer, then all subsequent layers must
// be compositing in order to render above that layer.
//
// If a child in the negative z-order list is compositing, then the layer itself
// must be compositing so that its contents render over that child.
// This implies that its positive z-index children must also be compositing.
//
void RenderLayerCompositor::computeCompositingRequirements(RenderLayer* ancestorLayer, RenderLayer* layer, OverlapMap* overlapMap, CompositingState& compositingState, bool& layersChanged, bool& descendantHas3DTransform)
{
layer->updateLayerListsIfNeeded();
if (layer->isOutOfFlowRenderFlowThread())
return;
if (overlapMap)
overlapMap->geometryMap().pushMappingsToAncestor(layer, ancestorLayer);
// Clear the flag
layer->setHasCompositingDescendant(false);
RenderLayer::IndirectCompositingReason compositingReason = compositingState.m_subtreeIsCompositing ? RenderLayer::IndirectCompositingForStacking : RenderLayer::NoIndirectCompositingReason;
bool haveComputedBounds = false;
IntRect absBounds;
if (overlapMap && !overlapMap->isEmpty() && compositingState.m_testingOverlap) {
// If we're testing for overlap, we only need to composite if we overlap something that is already composited.
absBounds = enclosingIntRect(overlapMap->geometryMap().absoluteRect(layer->overlapBounds()));
// Empty rects never intersect, but we need them to for the purposes of overlap testing.
if (absBounds.isEmpty())
absBounds.setSize(IntSize(1, 1));
haveComputedBounds = true;
compositingReason = overlapMap->overlapsLayers(absBounds) ? RenderLayer::IndirectCompositingForOverlap : RenderLayer::NoIndirectCompositingReason;
}
#if ENABLE(VIDEO)
// Video is special. It's the only RenderLayer type that can both have
// RenderLayer children and whose children can't use its backing to render
// into. These children (the controls) always need to be promoted into their
// own layers to draw on top of the accelerated video.
if (compositingState.m_compositingAncestor && compositingState.m_compositingAncestor->renderer()->isVideo())
compositingReason = RenderLayer::IndirectCompositingForOverlap;
#endif
layer->setIndirectCompositingReason(compositingReason);
// The children of this layer don't need to composite, unless there is
// a compositing layer among them, so start by inheriting the compositing
// ancestor with m_subtreeIsCompositing set to false.
CompositingState childState(compositingState);
childState.m_subtreeIsCompositing = false;
bool willBeComposited = needsToBeComposited(layer);
if (willBeComposited) {
// Tell the parent it has compositing descendants.
compositingState.m_subtreeIsCompositing = true;
// This layer now acts as the ancestor for kids.
childState.m_compositingAncestor = layer;
if (overlapMap)
overlapMap->pushCompositingContainer();
// This layer is going to be composited, so children can safely ignore the fact that there's an
// animation running behind this layer, meaning they can rely on the overlap map testing again.
childState.m_testingOverlap = true;
}
#if !ASSERT_DISABLED
LayerListMutationDetector mutationChecker(layer);
#endif
bool anyDescendantHas3DTransform = false;
if (layer->isStackingContainer()) {
if (Vector<RenderLayer*>* negZOrderList = layer->negZOrderList()) {
size_t listSize = negZOrderList->size();
for (size_t i = 0; i < listSize; ++i) {
RenderLayer* curLayer = negZOrderList->at(i);
computeCompositingRequirements(layer, curLayer, overlapMap, childState, layersChanged, anyDescendantHas3DTransform);
// If we have to make a layer for this child, make one now so we can have a contents layer
// (since we need to ensure that the -ve z-order child renders underneath our contents).
if (!willBeComposited && childState.m_subtreeIsCompositing) {
// make layer compositing
layer->setIndirectCompositingReason(RenderLayer::IndirectCompositingForBackgroundLayer);
childState.m_compositingAncestor = layer;
if (overlapMap)
overlapMap->pushCompositingContainer();
// This layer is going to be composited, so children can safely ignore the fact that there's an
// animation running behind this layer, meaning they can rely on the overlap map testing again
childState.m_testingOverlap = true;
willBeComposited = true;
}
}
}
}
if (Vector<RenderLayer*>* normalFlowList = layer->normalFlowList()) {
size_t listSize = normalFlowList->size();
for (size_t i = 0; i < listSize; ++i) {
RenderLayer* curLayer = normalFlowList->at(i);
computeCompositingRequirements(layer, curLayer, overlapMap, childState, layersChanged, anyDescendantHas3DTransform);
}
}
if (layer->isStackingContainer()) {
if (Vector<RenderLayer*>* posZOrderList = layer->posZOrderList()) {
size_t listSize = posZOrderList->size();
for (size_t i = 0; i < listSize; ++i) {
RenderLayer* curLayer = posZOrderList->at(i);
computeCompositingRequirements(layer, curLayer, overlapMap, childState, layersChanged, anyDescendantHas3DTransform);
}
}
}
// If we just entered compositing mode, the root will have become composited (as long as accelerated compositing is enabled).
if (layer->isRootLayer()) {
if (inCompositingMode() && m_hasAcceleratedCompositing)
willBeComposited = true;
}
ASSERT(willBeComposited == needsToBeComposited(layer));
// All layers (even ones that aren't being composited) need to get added to
// the overlap map. Layers that do not composite will draw into their
// compositing ancestor's backing, and so are still considered for overlap.
if (overlapMap && childState.m_compositingAncestor && !childState.m_compositingAncestor->isRootLayer())
addToOverlapMap(*overlapMap, layer, absBounds, haveComputedBounds);
// Now check for reasons to become composited that depend on the state of descendant layers.
RenderLayer::IndirectCompositingReason indirectCompositingReason;
if (!willBeComposited && canBeComposited(layer)
&& requiresCompositingForIndirectReason(layer->renderer(), childState.m_subtreeIsCompositing, anyDescendantHas3DTransform, indirectCompositingReason)) {
layer->setIndirectCompositingReason(indirectCompositingReason);
childState.m_compositingAncestor = layer;
if (overlapMap) {
overlapMap->pushCompositingContainer();
addToOverlapMapRecursive(*overlapMap, layer);
}
willBeComposited = true;
}
ASSERT(willBeComposited == needsToBeComposited(layer));
if (layer->reflectionLayer()) {
// FIXME: Shouldn't we call computeCompositingRequirements to handle a reflection overlapping with another renderer?
layer->reflectionLayer()->setIndirectCompositingReason(willBeComposited ? RenderLayer::IndirectCompositingForStacking : RenderLayer::NoIndirectCompositingReason);
}
// Subsequent layers in the parent stacking context also need to composite.
if (childState.m_subtreeIsCompositing)
compositingState.m_subtreeIsCompositing = true;
// Set the flag to say that this SC has compositing children.
layer->setHasCompositingDescendant(childState.m_subtreeIsCompositing);
// setHasCompositingDescendant() may have changed the answer to needsToBeComposited() when clipping,
// so test that again.
bool isCompositedClippingLayer = canBeComposited(layer) && clipsCompositingDescendants(layer);
// Turn overlap testing off for later layers if it's already off, or if we have an animating transform.
// Note that if the layer clips its descendants, there's no reason to propagate the child animation to the parent layers. That's because
// we know for sure the animation is contained inside the clipping rectangle, which is already added to the overlap map.
if ((!childState.m_testingOverlap && !isCompositedClippingLayer) || isRunningAcceleratedTransformAnimation(layer->renderer()))
compositingState.m_testingOverlap = false;
if (isCompositedClippingLayer) {
if (!willBeComposited) {
childState.m_compositingAncestor = layer;
if (overlapMap) {
overlapMap->pushCompositingContainer();
addToOverlapMapRecursive(*overlapMap, layer);
}
willBeComposited = true;
}
}
if (overlapMap && childState.m_compositingAncestor == layer && !layer->isRootLayer())
overlapMap->popCompositingContainer();
// If we're back at the root, and no other layers need to be composited, and the root layer itself doesn't need
// to be composited, then we can drop out of compositing mode altogether. However, don't drop out of compositing mode
// if there are composited layers that we didn't hit in our traversal (e.g. because of visibility:hidden).
if (layer->isRootLayer() && !childState.m_subtreeIsCompositing && !requiresCompositingLayer(layer) && !m_forceCompositingMode && !hasAnyAdditionalCompositedLayers(layer)) {
enableCompositingMode(false);
willBeComposited = false;
}
// If the layer is going into compositing mode, repaint its old location.
ASSERT(willBeComposited == needsToBeComposited(layer));
if (!layer->isComposited() && willBeComposited)
repaintOnCompositingChange(layer);
// Update backing now, so that we can use isComposited() reliably during tree traversal in rebuildCompositingLayerTree().
if (updateBacking(layer, CompositingChangeRepaintNow))
layersChanged = true;
if (layer->reflectionLayer() && updateLayerCompositingState(layer->reflectionLayer(), CompositingChangeRepaintNow))
layersChanged = true;
descendantHas3DTransform |= anyDescendantHas3DTransform || layer->has3DTransform();
if (overlapMap)
overlapMap->geometryMap().popMappingsToAncestor(ancestorLayer);
}
void RenderLayerCompositor::setCompositingParent(RenderLayer* childLayer, RenderLayer* parentLayer)
{
ASSERT(!parentLayer || childLayer->ancestorCompositingLayer() == parentLayer);
ASSERT(childLayer->isComposited());
// It's possible to be called with a parent that isn't yet composited when we're doing
// partial updates as required by painting or hit testing. Just bail in that case;
// we'll do a full layer update soon.
if (!parentLayer || !parentLayer->isComposited())
return;
if (parentLayer) {
GraphicsLayer* hostingLayer = parentLayer->backing()->parentForSublayers();
GraphicsLayer* hostedLayer = childLayer->backing()->childForSuperlayers();
hostingLayer->addChild(hostedLayer);
} else
childLayer->backing()->childForSuperlayers()->removeFromParent();
}
void RenderLayerCompositor::removeCompositedChildren(RenderLayer* layer)
{
ASSERT(layer->isComposited());
GraphicsLayer* hostingLayer = layer->backing()->parentForSublayers();
hostingLayer->removeAllChildren();
}
#if ENABLE(VIDEO)
bool RenderLayerCompositor::canAccelerateVideoRendering(RenderVideo* o) const
{
if (!m_hasAcceleratedCompositing)
return false;
return o->supportsAcceleratedRendering();
}
#endif
void RenderLayerCompositor::rebuildCompositingLayerTree(RenderLayer* layer, Vector<GraphicsLayer*>& childLayersOfEnclosingLayer, int depth)
{
// Make the layer compositing if necessary, and set up clipping and content layers.
// Note that we can only do work here that is independent of whether the descendant layers
// have been processed. computeCompositingRequirements() will already have done the repaint if necessary.
if (layer->isOutOfFlowRenderFlowThread())
return;
RenderLayerBacking* layerBacking = layer->backing();
if (layerBacking) {
// The compositing state of all our children has been updated already, so now
// we can compute and cache the composited bounds for this layer.
layerBacking->updateCompositedBounds();
if (RenderLayer* reflection = layer->reflectionLayer()) {
if (reflection->backing())
reflection->backing()->updateCompositedBounds();
}
if (layerBacking->updateGraphicsLayerConfiguration())
layerBacking->updateDebugIndicators(m_showDebugBorders, m_showRepaintCounter);
layerBacking->updateGraphicsLayerGeometry();
if (!layer->parent())
updateRootLayerPosition();
#if !LOG_DISABLED
logLayerInfo(layer, depth);
#else
UNUSED_PARAM(depth);
#endif
if (layerBacking->hasUnpositionedOverflowControlsLayers())
layer->positionNewlyCreatedOverflowControls();
}
// If this layer has backing, then we are collecting its children, otherwise appending
// to the compositing child list of an enclosing layer.
Vector<GraphicsLayer*> layerChildren;
Vector<GraphicsLayer*>& childList = layerBacking ? layerChildren : childLayersOfEnclosingLayer;
#if !ASSERT_DISABLED
LayerListMutationDetector mutationChecker(layer);
#endif
if (layer->isStackingContainer()) {
if (Vector<RenderLayer*>* negZOrderList = layer->negZOrderList()) {
size_t listSize = negZOrderList->size();
for (size_t i = 0; i < listSize; ++i) {
RenderLayer* curLayer = negZOrderList->at(i);
rebuildCompositingLayerTree(curLayer, childList, depth + 1);
}
}
// If a negative z-order child is compositing, we get a foreground layer which needs to get parented.
if (layerBacking && layerBacking->foregroundLayer())
childList.append(layerBacking->foregroundLayer());
}
if (Vector<RenderLayer*>* normalFlowList = layer->normalFlowList()) {
size_t listSize = normalFlowList->size();
for (size_t i = 0; i < listSize; ++i) {
RenderLayer* curLayer = normalFlowList->at(i);
rebuildCompositingLayerTree(curLayer, childList, depth + 1);
}
}
if (layer->isStackingContainer()) {
if (Vector<RenderLayer*>* posZOrderList = layer->posZOrderList()) {
size_t listSize = posZOrderList->size();
for (size_t i = 0; i < listSize; ++i) {
RenderLayer* curLayer = posZOrderList->at(i);
rebuildCompositingLayerTree(curLayer, childList, depth + 1);
}
}
}
if (layerBacking) {
bool parented = false;
if (layer->renderer()->isRenderPart())
parented = parentFrameContentLayers(toRenderPart(layer->renderer()));
if (!parented)
layerBacking->parentForSublayers()->setChildren(layerChildren);
// If the layer has a clipping layer the overflow controls layers will be siblings of the clipping layer.
// Otherwise, the overflow control layers are normal children.
if (!layerBacking->hasClippingLayer() && !layerBacking->hasScrollingLayer()) {
if (GraphicsLayer* overflowControlLayer = layerBacking->layerForHorizontalScrollbar()) {
overflowControlLayer->removeFromParent();
layerBacking->parentForSublayers()->addChild(overflowControlLayer);
}
if (GraphicsLayer* overflowControlLayer = layerBacking->layerForVerticalScrollbar()) {
overflowControlLayer->removeFromParent();
layerBacking->parentForSublayers()->addChild(overflowControlLayer);
}
if (GraphicsLayer* overflowControlLayer = layerBacking->layerForScrollCorner()) {
overflowControlLayer->removeFromParent();
layerBacking->parentForSublayers()->addChild(overflowControlLayer);
}
}
childLayersOfEnclosingLayer.append(layerBacking->childForSuperlayers());
}
}
void RenderLayerCompositor::frameViewDidChangeLocation(const IntPoint& contentsOffset)
{
if (m_overflowControlsHostLayer)
m_overflowControlsHostLayer->setPosition(contentsOffset);
}
void RenderLayerCompositor::frameViewDidChangeSize()
{
if (m_clipLayer) {
FrameView* frameView = m_renderView->frameView();
m_clipLayer->setSize(frameView->unscaledVisibleContentSize());
frameViewDidScroll();
updateOverflowControlsLayers();
#if ENABLE(RUBBER_BANDING)
if (m_layerForOverhangAreas)
m_layerForOverhangAreas->setSize(frameView->frameRect().size());
#endif
}
}
bool RenderLayerCompositor::hasCoordinatedScrolling() const
{
ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator();
return scrollingCoordinator && scrollingCoordinator->coordinatesScrollingForFrameView(m_renderView->frameView());
}
void RenderLayerCompositor::frameViewDidScroll()
{
FrameView* frameView = m_renderView->frameView();
IntPoint scrollPosition = frameView->scrollPosition();
if (!m_scrollLayer)
return;
// If there's a scrolling coordinator that manages scrolling for this frame view,
// it will also manage updating the scroll layer position.
if (hasCoordinatedScrolling())
return;
if (Settings* settings = m_renderView->document()->settings()) {
if (settings->compositedScrollingForFramesEnabled()) {
if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
scrollingCoordinator->scrollableAreaScrollLayerDidChange(frameView);
}
}
m_scrollLayer->setPosition(FloatPoint(-scrollPosition.x(), -scrollPosition.y()));
if (GraphicsLayer* fixedBackgroundLayer = fixedRootBackgroundLayer())
fixedBackgroundLayer->setPosition(IntPoint(frameView->scrollOffsetForFixedPosition()));
}
void RenderLayerCompositor::frameViewDidLayout()
{
RenderLayerBacking* renderViewBacking = m_renderView->layer()->backing();
if (renderViewBacking)
renderViewBacking->adjustTiledBackingCoverage();
}
void RenderLayerCompositor::rootFixedBackgroundsChanged()
{
RenderLayerBacking* renderViewBacking = m_renderView->layer()->backing();
if (renderViewBacking && renderViewBacking->usingTiledBacking())
setCompositingLayersNeedRebuild();
}
void RenderLayerCompositor::scrollingLayerDidChange(RenderLayer* layer)
{
if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
scrollingCoordinator->scrollableAreaScrollLayerDidChange(layer);
}
void RenderLayerCompositor::fixedRootBackgroundLayerChanged()
{
if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator()) {
RenderLayerBacking* renderViewBacking = m_renderView->layer()->backing();
if (!renderViewBacking)
return;
scrollingCoordinator->updateScrollingNode(renderViewBacking->scrollLayerID(), scrollLayer(), fixedRootBackgroundLayer());
}
}
String RenderLayerCompositor::layerTreeAsText(LayerTreeFlags flags)
{
updateCompositingLayers(CompositingUpdateAfterLayout);
if (!m_rootContentLayer)
return String();
flushPendingLayerChanges(true);
LayerTreeAsTextBehavior layerTreeBehavior = LayerTreeAsTextBehaviorNormal;
if (flags & LayerTreeFlagsIncludeDebugInfo)
layerTreeBehavior |= LayerTreeAsTextDebug;
if (flags & LayerTreeFlagsIncludeVisibleRects)
layerTreeBehavior |= LayerTreeAsTextIncludeVisibleRects;
if (flags & LayerTreeFlagsIncludeTileCaches)
layerTreeBehavior |= LayerTreeAsTextIncludeTileCaches;
if (flags & LayerTreeFlagsIncludeRepaintRects)
layerTreeBehavior |= LayerTreeAsTextIncludeRepaintRects;
if (flags & LayerTreeFlagsIncludePaintingPhases)
layerTreeBehavior |= LayerTreeAsTextIncludePaintingPhases;
// We skip dumping the scroll and clip layers to keep layerTreeAsText output
// similar between platforms.
String layerTreeText = m_rootContentLayer->layerTreeAsText(layerTreeBehavior);
// The true root layer is not included in the dump, so if we want to report
// its repaint rects, they must be included here.
if (flags & LayerTreeFlagsIncludeRepaintRects) {
String layerTreeTextWithRootRepaintRects = m_renderView->frameView()->trackedRepaintRectsAsText();
layerTreeTextWithRootRepaintRects.append(layerTreeText);
return layerTreeTextWithRootRepaintRects;
}
return layerTreeText;
}
RenderLayerCompositor* RenderLayerCompositor::frameContentsCompositor(RenderPart* renderer)
{
if (!renderer->node()->isFrameOwnerElement())
return 0;
HTMLFrameOwnerElement* element = toFrameOwnerElement(renderer->node());
if (Document* contentDocument = element->contentDocument()) {
if (RenderView* view = contentDocument->renderView())
return view->compositor();
}
return 0;
}
bool RenderLayerCompositor::parentFrameContentLayers(RenderPart* renderer)
{
RenderLayerCompositor* innerCompositor = frameContentsCompositor(renderer);
if (!innerCompositor || !innerCompositor->inCompositingMode() || innerCompositor->rootLayerAttachment() != RootLayerAttachedViaEnclosingFrame)
return false;
RenderLayer* layer = renderer->layer();
if (!layer->isComposited())
return false;
RenderLayerBacking* backing = layer->backing();
GraphicsLayer* hostingLayer = backing->parentForSublayers();
GraphicsLayer* rootLayer = innerCompositor->rootGraphicsLayer();
if (hostingLayer->children().size() != 1 || hostingLayer->children()[0] != rootLayer) {
hostingLayer->removeAllChildren();
hostingLayer->addChild(rootLayer);
}
return true;
}
// This just updates layer geometry without changing the hierarchy.
void RenderLayerCompositor::updateLayerTreeGeometry(RenderLayer* layer, int depth)
{
if (RenderLayerBacking* layerBacking = layer->backing()) {
// The compositing state of all our children has been updated already, so now
// we can compute and cache the composited bounds for this layer.
layerBacking->updateCompositedBounds();
if (RenderLayer* reflection = layer->reflectionLayer()) {
if (reflection->backing())
reflection->backing()->updateCompositedBounds();
}
layerBacking->updateGraphicsLayerConfiguration();
layerBacking->updateGraphicsLayerGeometry();
if (!layer->parent())
updateRootLayerPosition();
#if !LOG_DISABLED
logLayerInfo(layer, depth);
#else
UNUSED_PARAM(depth);
#endif
}
#if !ASSERT_DISABLED
LayerListMutationDetector mutationChecker(layer);
#endif
if (layer->isStackingContainer()) {
if (Vector<RenderLayer*>* negZOrderList = layer->negZOrderList()) {
size_t listSize = negZOrderList->size();
for (size_t i = 0; i < listSize; ++i)
updateLayerTreeGeometry(negZOrderList->at(i), depth + 1);
}
}
if (Vector<RenderLayer*>* normalFlowList = layer->normalFlowList()) {
size_t listSize = normalFlowList->size();
for (size_t i = 0; i < listSize; ++i)
updateLayerTreeGeometry(normalFlowList->at(i), depth + 1);
}
if (layer->isStackingContainer()) {
if (Vector<RenderLayer*>* posZOrderList = layer->posZOrderList()) {
size_t listSize = posZOrderList->size();
for (size_t i = 0; i < listSize; ++i)
updateLayerTreeGeometry(posZOrderList->at(i), depth + 1);
}
}
}
// Recurs down the RenderLayer tree until its finds the compositing descendants of compositingAncestor and updates their geometry.
void RenderLayerCompositor::updateCompositingDescendantGeometry(RenderLayer* compositingAncestor, RenderLayer* layer, bool compositedChildrenOnly)
{
if (layer != compositingAncestor) {
if (RenderLayerBacking* layerBacking = layer->backing()) {
layerBacking->updateCompositedBounds();
if (RenderLayer* reflection = layer->reflectionLayer()) {
if (reflection->backing())
reflection->backing()->updateCompositedBounds();
}
layerBacking->updateGraphicsLayerGeometry();
if (compositedChildrenOnly)
return;
}
}
if (layer->reflectionLayer())
updateCompositingDescendantGeometry(compositingAncestor, layer->reflectionLayer(), compositedChildrenOnly);
if (!layer->hasCompositingDescendant())
return;
#if !ASSERT_DISABLED
LayerListMutationDetector mutationChecker(layer);
#endif
if (layer->isStackingContainer()) {
if (Vector<RenderLayer*>* negZOrderList = layer->negZOrderList()) {
size_t listSize = negZOrderList->size();
for (size_t i = 0; i < listSize; ++i)
updateCompositingDescendantGeometry(compositingAncestor, negZOrderList->at(i), compositedChildrenOnly);
}
}
if (Vector<RenderLayer*>* normalFlowList = layer->normalFlowList()) {
size_t listSize = normalFlowList->size();
for (size_t i = 0; i < listSize; ++i)
updateCompositingDescendantGeometry(compositingAncestor, normalFlowList->at(i), compositedChildrenOnly);
}
if (layer->isStackingContainer()) {
if (Vector<RenderLayer*>* posZOrderList = layer->posZOrderList()) {
size_t listSize = posZOrderList->size();
for (size_t i = 0; i < listSize; ++i)
updateCompositingDescendantGeometry(compositingAncestor, posZOrderList->at(i), compositedChildrenOnly);
}
}
}
void RenderLayerCompositor::repaintCompositedLayers(const IntRect* absRect)
{
recursiveRepaintLayer(rootRenderLayer(), absRect);
}
void RenderLayerCompositor::recursiveRepaintLayer(RenderLayer* layer, const IntRect* rect)
{
// FIXME: This method does not work correctly with transforms.
if (layer->isComposited() && !layer->backing()->paintsIntoCompositedAncestor()) {
if (rect)
layer->setBackingNeedsRepaintInRect(*rect);
else
layer->setBackingNeedsRepaint();
}
#if !ASSERT_DISABLED
LayerListMutationDetector mutationChecker(layer);
#endif
if (layer->hasCompositingDescendant()) {
if (Vector<RenderLayer*>* negZOrderList = layer->negZOrderList()) {
size_t listSize = negZOrderList->size();
for (size_t i = 0; i < listSize; ++i) {
RenderLayer* curLayer = negZOrderList->at(i);
if (rect) {
IntRect childRect(*rect);
curLayer->convertToPixelSnappedLayerCoords(layer, childRect);
recursiveRepaintLayer(curLayer, &childRect);
} else
recursiveRepaintLayer(curLayer);
}
}
if (Vector<RenderLayer*>* posZOrderList = layer->posZOrderList()) {
size_t listSize = posZOrderList->size();
for (size_t i = 0; i < listSize; ++i) {
RenderLayer* curLayer = posZOrderList->at(i);
if (rect) {
IntRect childRect(*rect);
curLayer->convertToPixelSnappedLayerCoords(layer, childRect);
recursiveRepaintLayer(curLayer, &childRect);
} else
recursiveRepaintLayer(curLayer);
}
}
}
if (Vector<RenderLayer*>* normalFlowList = layer->normalFlowList()) {
size_t listSize = normalFlowList->size();
for (size_t i = 0; i < listSize; ++i) {
RenderLayer* curLayer = normalFlowList->at(i);
if (rect) {
IntRect childRect(*rect);
curLayer->convertToPixelSnappedLayerCoords(layer, childRect);
recursiveRepaintLayer(curLayer, &childRect);
} else
recursiveRepaintLayer(curLayer);
}
}
}
RenderLayer* RenderLayerCompositor::rootRenderLayer() const
{
return m_renderView->layer();
}
GraphicsLayer* RenderLayerCompositor::rootGraphicsLayer() const
{
if (m_overflowControlsHostLayer)
return m_overflowControlsHostLayer.get();
return m_rootContentLayer.get();
}
GraphicsLayer* RenderLayerCompositor::scrollLayer() const
{
return m_scrollLayer.get();
}
#if ENABLE(RUBBER_BANDING)
GraphicsLayer* RenderLayerCompositor::headerLayer() const
{
return m_layerForHeader.get();
}
GraphicsLayer* RenderLayerCompositor::footerLayer() const
{
return m_layerForFooter.get();
}
#endif
TiledBacking* RenderLayerCompositor::pageTiledBacking() const
{
RenderLayerBacking* renderViewBacking = m_renderView->layer()->backing();
return renderViewBacking ? renderViewBacking->tiledBacking() : 0;
}
void RenderLayerCompositor::setIsInWindow(bool isInWindow)
{
if (TiledBacking* tiledBacking = pageTiledBacking())
tiledBacking->setIsInWindow(isInWindow);
if (!inCompositingMode())
return;
if (isInWindow) {
if (m_rootLayerAttachment != RootLayerUnattached)
return;
RootLayerAttachment attachment = shouldPropagateCompositingToEnclosingFrame() ? RootLayerAttachedViaEnclosingFrame : RootLayerAttachedViaChromeClient;
attachRootLayer(attachment);
} else {
if (m_rootLayerAttachment == RootLayerUnattached)
return;
detachRootLayer();
}
}
void RenderLayerCompositor::clearBackingForLayerIncludingDescendants(RenderLayer* layer)
{
if (!layer)
return;
if (layer->isComposited()) {
removeViewportConstrainedLayer(layer);
layer->clearBacking();
}
for (RenderLayer* currLayer = layer->firstChild(); currLayer; currLayer = currLayer->nextSibling())
clearBackingForLayerIncludingDescendants(currLayer);
}
void RenderLayerCompositor::clearBackingForAllLayers()
{
clearBackingForLayerIncludingDescendants(m_renderView->layer());
}
void RenderLayerCompositor::updateRootLayerPosition()
{
if (m_rootContentLayer) {
const IntRect& documentRect = m_renderView->documentRect();
m_rootContentLayer->setSize(documentRect.size());
m_rootContentLayer->setPosition(FloatPoint(documentRect.x(), documentRect.y() + m_renderView->frameView()->headerHeight()));
}
if (m_clipLayer) {
FrameView* frameView = m_renderView->frameView();
m_clipLayer->setSize(frameView->unscaledVisibleContentSize());
}
#if ENABLE(RUBBER_BANDING)
if (m_contentShadowLayer) {
m_contentShadowLayer->setPosition(m_rootContentLayer->position());
FloatSize rootContentLayerSize = m_rootContentLayer->size();
if (m_contentShadowLayer->size() != rootContentLayerSize) {
m_contentShadowLayer->setSize(rootContentLayerSize);
ScrollbarTheme::theme()->setUpContentShadowLayer(m_contentShadowLayer.get());
}
}
updateLayerForTopOverhangArea(m_layerForTopOverhangArea);
updateLayerForBottomOverhangArea(m_layerForBottomOverhangArea);
updateLayerForHeader(m_layerForHeader);
updateLayerForFooter(m_layerForFooter);
#endif
}
bool RenderLayerCompositor::has3DContent() const
{
return layerHas3DContent(rootRenderLayer());
}
bool RenderLayerCompositor::allowsIndependentlyCompositedFrames(const FrameView* view)
{
#if PLATFORM(MAC)
// frames are only independently composited in Mac pre-WebKit2.
return view->platformWidget();
#else
UNUSED_PARAM(view);
#endif
return false;
}
bool RenderLayerCompositor::shouldPropagateCompositingToEnclosingFrame() const
{
// Parent document content needs to be able to render on top of a composited frame, so correct behavior
// is to have the parent document become composited too. However, this can cause problems on platforms that
// use native views for frames (like Mac), so disable that behavior on those platforms for now.
HTMLFrameOwnerElement* ownerElement = m_renderView->document()->ownerElement();
RenderObject* renderer = ownerElement ? ownerElement->renderer() : 0;
// If we are the top-level frame, don't propagate.
if (!ownerElement)
return false;
if (!allowsIndependentlyCompositedFrames(m_renderView->frameView()))
return true;
if (!renderer || !renderer->isRenderPart())
return false;
// On Mac, only propagate compositing if the frame is overlapped in the parent
// document, or the parent is already compositing, or the main frame is scaled.
Page* page = this->page();
if (page && page->pageScaleFactor() != 1)
return true;
RenderPart* frameRenderer = toRenderPart(renderer);
if (frameRenderer->widget()) {
ASSERT(frameRenderer->widget()->isFrameView());
FrameView* view = toFrameView(frameRenderer->widget());
if (view->isOverlappedIncludingAncestors() || view->hasCompositingAncestor())
return true;
}
return false;
}
bool RenderLayerCompositor::needsToBeComposited(const RenderLayer* layer, RenderLayer::ViewportConstrainedNotCompositedReason* viewportConstrainedNotCompositedReason) const
{
if (!canBeComposited(layer))
return false;
return requiresCompositingLayer(layer, viewportConstrainedNotCompositedReason) || layer->mustCompositeForIndirectReasons() || (inCompositingMode() && layer->isRootLayer());
}
// Note: this specifies whether the RL needs a compositing layer for intrinsic reasons.
// Use needsToBeComposited() to determine if a RL actually needs a compositing layer.
// static
bool RenderLayerCompositor::requiresCompositingLayer(const RenderLayer* layer, RenderLayer::ViewportConstrainedNotCompositedReason* viewportConstrainedNotCompositedReason) const
{
RenderObject* renderer = layer->renderer();
// The compositing state of a reflection should match that of its reflected layer.
if (layer->isReflection()) {
renderer = renderer->parent(); // The RenderReplica's parent is the object being reflected.
layer = toRenderLayerModelObject(renderer)->layer();
}
// The root layer always has a compositing layer, but it may not have backing.
return requiresCompositingForTransform(renderer)
|| requiresCompositingForVideo(renderer)
|| requiresCompositingForCanvas(renderer)
|| requiresCompositingForPlugin(renderer)
|| requiresCompositingForFrame(renderer)
|| (canRender3DTransforms() && renderer->style()->backfaceVisibility() == BackfaceVisibilityHidden)
|| clipsCompositingDescendants(layer)
|| requiresCompositingForAnimation(renderer)
|| requiresCompositingForFilters(renderer)
|| requiresCompositingForPosition(renderer, layer, viewportConstrainedNotCompositedReason)
|| requiresCompositingForOverflowScrolling(layer)
|| requiresCompositingForBlending(renderer);
}
bool RenderLayerCompositor::canBeComposited(const RenderLayer* layer) const
{
if (!(m_compositingTriggers & ChromeClient::LargeAreaTrigger) && layer->size().area() > largeAreaThresholdForCompositing)
return false;
// FIXME: We disable accelerated compositing for elements in a RenderFlowThread as it doesn't work properly.
// See http://webkit.org/b/84900 to re-enable it.
return m_hasAcceleratedCompositing && layer->isSelfPaintingLayer() && layer->renderer()->flowThreadState() == RenderObject::NotInsideFlowThread;
}
bool RenderLayerCompositor::requiresOwnBackingStore(const RenderLayer* layer, const RenderLayer* compositingAncestorLayer, const IntRect& layerCompositedBoundsInAncestor, const IntRect& ancestorCompositedBounds) const
{
RenderObject* renderer = layer->renderer();
if (compositingAncestorLayer
&& !(compositingAncestorLayer->backing()->graphicsLayer()->drawsContent()
|| compositingAncestorLayer->backing()->paintsIntoWindow()
|| compositingAncestorLayer->backing()->paintsIntoCompositedAncestor()))
return true;
if (layer->isRootLayer()
|| layer->transform() // note: excludes perspective and transformStyle3D.
|| requiresCompositingForVideo(renderer)
|| requiresCompositingForCanvas(renderer)
|| requiresCompositingForPlugin(renderer)
|| requiresCompositingForFrame(renderer)
|| (canRender3DTransforms() && renderer->style()->backfaceVisibility() == BackfaceVisibilityHidden)
|| requiresCompositingForAnimation(renderer)
|| requiresCompositingForFilters(renderer)
|| requiresCompositingForBlending(renderer)
|| requiresCompositingForPosition(renderer, layer)
|| requiresCompositingForOverflowScrolling(layer)
|| renderer->isTransparent()
|| renderer->hasMask()
|| renderer->hasReflection()
|| renderer->hasFilter())
return true;
if (layer->mustCompositeForIndirectReasons()) {
RenderLayer::IndirectCompositingReason reason = layer->indirectCompositingReason();
return reason == RenderLayer::IndirectCompositingForOverlap
|| reason == RenderLayer::IndirectCompositingForStacking
|| reason == RenderLayer::IndirectCompositingForBackgroundLayer
|| reason == RenderLayer::IndirectCompositingForGraphicalEffect
|| reason == RenderLayer::IndirectCompositingForPreserve3D; // preserve-3d has to create backing store to ensure that 3d-transformed elements intersect.
}
if (!ancestorCompositedBounds.contains(layerCompositedBoundsInAncestor))
return true;
return false;
}
CompositingReasons RenderLayerCompositor::reasonsForCompositing(const RenderLayer* layer) const
{
CompositingReasons reasons = CompositingReasonNone;
if (!layer || !layer->isComposited())
return reasons;
RenderObject* renderer = layer->renderer();
if (layer->isReflection()) {
renderer = renderer->parent();
layer = toRenderLayerModelObject(renderer)->layer();
}
if (requiresCompositingForTransform(renderer))
reasons |= CompositingReason3DTransform;
if (requiresCompositingForVideo(renderer))
reasons |= CompositingReasonVideo;
else if (requiresCompositingForCanvas(renderer))
reasons |= CompositingReasonCanvas;
else if (requiresCompositingForPlugin(renderer))
reasons |= CompositingReasonPlugin;
else if (requiresCompositingForFrame(renderer))
reasons |= CompositingReasonIFrame;
if ((canRender3DTransforms() && renderer->style()->backfaceVisibility() == BackfaceVisibilityHidden))
reasons |= CompositingReasonBackfaceVisibilityHidden;
if (clipsCompositingDescendants(layer))
reasons |= CompositingReasonClipsCompositingDescendants;
if (requiresCompositingForAnimation(renderer))
reasons |= CompositingReasonAnimation;
if (requiresCompositingForFilters(renderer))
reasons |= CompositingReasonFilters;
if (requiresCompositingForPosition(renderer, layer))
reasons |= renderer->style()->position() == FixedPosition ? CompositingReasonPositionFixed : CompositingReasonPositionSticky;
if (requiresCompositingForOverflowScrolling(layer))
reasons |= CompositingReasonOverflowScrollingTouch;
if (layer->indirectCompositingReason() == RenderLayer::IndirectCompositingForStacking)
reasons |= CompositingReasonStacking;
else if (layer->indirectCompositingReason() == RenderLayer::IndirectCompositingForOverlap)
reasons |= CompositingReasonOverlap;
else if (layer->indirectCompositingReason() == RenderLayer::IndirectCompositingForBackgroundLayer)
reasons |= CompositingReasonNegativeZIndexChildren;
else if (layer->indirectCompositingReason() == RenderLayer::IndirectCompositingForGraphicalEffect) {
if (layer->transform())
reasons |= CompositingReasonTransformWithCompositedDescendants;
if (renderer->isTransparent())
reasons |= CompositingReasonOpacityWithCompositedDescendants;
if (renderer->hasMask())
reasons |= CompositingReasonMaskWithCompositedDescendants;
if (renderer->hasReflection())
reasons |= CompositingReasonReflectionWithCompositedDescendants;
if (renderer->hasFilter())
reasons |= CompositingReasonFilterWithCompositedDescendants;
if (renderer->hasBlendMode())
reasons |= CompositingReasonBlendingWithCompositedDescendants;
} else if (layer->indirectCompositingReason() == RenderLayer::IndirectCompositingForPerspective)
reasons |= CompositingReasonPerspective;
else if (layer->indirectCompositingReason() == RenderLayer::IndirectCompositingForPreserve3D)
reasons |= CompositingReasonPreserve3D;
if (inCompositingMode() && layer->isRootLayer())
reasons |= CompositingReasonRoot;
return reasons;
}
#if !LOG_DISABLED
const char* RenderLayerCompositor::logReasonsForCompositing(const RenderLayer* layer)
{
CompositingReasons reasons = reasonsForCompositing(layer);
if (reasons & CompositingReason3DTransform)
return "3D transform";
if (reasons & CompositingReasonVideo)
return "video";
else if (reasons & CompositingReasonCanvas)
return "canvas";
else if (reasons & CompositingReasonPlugin)
return "plugin";
else if (reasons & CompositingReasonIFrame)
return "iframe";
if (reasons & CompositingReasonBackfaceVisibilityHidden)
return "backface-visibility: hidden";
if (reasons & CompositingReasonClipsCompositingDescendants)
return "clips compositing descendants";
if (reasons & CompositingReasonAnimation)
return "animation";
if (reasons & CompositingReasonFilters)
return "filters";
if (reasons & CompositingReasonPositionFixed)
return "position: fixed";
if (reasons & CompositingReasonPositionSticky)
return "position: sticky";
if (reasons & CompositingReasonOverflowScrollingTouch)
return "-webkit-overflow-scrolling: touch";
if (reasons & CompositingReasonStacking)
return "stacking";
if (reasons & CompositingReasonOverlap)
return "overlap";
if (reasons & CompositingReasonNegativeZIndexChildren)
return "negative z-index children";
if (reasons & CompositingReasonTransformWithCompositedDescendants)
return "transform with composited descendants";
if (reasons & CompositingReasonOpacityWithCompositedDescendants)
return "opacity with composited descendants";
if (reasons & CompositingReasonMaskWithCompositedDescendants)
return "mask with composited descendants";
if (reasons & CompositingReasonReflectionWithCompositedDescendants)
return "reflection with composited descendants";
if (reasons & CompositingReasonFilterWithCompositedDescendants)
return "filter with composited descendants";
if (reasons & CompositingReasonBlendingWithCompositedDescendants)
return "blending with composited descendants";
if (reasons & CompositingReasonPerspective)
return "perspective";
if (reasons & CompositingReasonPreserve3D)
return "preserve-3d";
if (reasons & CompositingReasonRoot)
return "root";
return "";
}
#endif
// Return true if the given layer has some ancestor in the RenderLayer hierarchy that clips,
// up to the enclosing compositing ancestor. This is required because compositing layers are parented
// according to the z-order hierarchy, yet clipping goes down the renderer hierarchy.
// Thus, a RenderLayer can be clipped by a RenderLayer that is an ancestor in the renderer hierarchy,
// but a sibling in the z-order hierarchy.
bool RenderLayerCompositor::clippedByAncestor(RenderLayer* layer) const
{
if (!layer->isComposited() || !layer->parent())
return false;
RenderLayer* compositingAncestor = layer->ancestorCompositingLayer();
if (!compositingAncestor)
return false;
// If the compositingAncestor clips, that will be taken care of by clipsCompositingDescendants(),
// so we only care about clipping between its first child that is our ancestor (the computeClipRoot),
// and layer.
RenderLayer* computeClipRoot = 0;
RenderLayer* curr = layer;
while (curr) {
RenderLayer* next = curr->parent();
if (next == compositingAncestor) {
computeClipRoot = curr;
break;
}
curr = next;
}
if (!computeClipRoot || computeClipRoot == layer)
return false;
return layer->backgroundClipRect(RenderLayer::ClipRectsContext(computeClipRoot, 0, TemporaryClipRects)).rect() != PaintInfo::infiniteRect(); // FIXME: Incorrect for CSS regions.
}
// Return true if the given layer is a stacking context and has compositing child
// layers that it needs to clip. In this case we insert a clipping GraphicsLayer
// into the hierarchy between this layer and its children in the z-order hierarchy.
bool RenderLayerCompositor::clipsCompositingDescendants(const RenderLayer* layer) const
{
return layer->hasCompositingDescendant() && layer->renderer()->hasClipOrOverflowClip();
}
bool RenderLayerCompositor::requiresCompositingForScrollableFrame() const
{
// Need this done first to determine overflow.
ASSERT(!m_renderView->needsLayout());
HTMLFrameOwnerElement* ownerElement = m_renderView->document()->ownerElement();
if (!ownerElement)
return false;
if (!(m_compositingTriggers & ChromeClient::ScrollableInnerFrameTrigger))
return false;
FrameView* frameView = m_renderView->frameView();
return frameView->isScrollable();
}
bool RenderLayerCompositor::requiresCompositingForTransform(RenderObject* renderer) const
{
if (!(m_compositingTriggers & ChromeClient::ThreeDTransformTrigger))
return false;
RenderStyle* style = renderer->style();
// Note that we ask the renderer if it has a transform, because the style may have transforms,
// but the renderer may be an inline that doesn't suppport them.
return renderer->hasTransform() && style->transform().has3DOperation();
}
bool RenderLayerCompositor::requiresCompositingForVideo(RenderObject* renderer) const
{
if (!(m_compositingTriggers & ChromeClient::VideoTrigger))
return false;
#if ENABLE(VIDEO)
if (renderer->isVideo()) {
RenderVideo* video = toRenderVideo(renderer);
return video->shouldDisplayVideo() && canAccelerateVideoRendering(video);
}
#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
else if (renderer->isRenderPart()) {
if (!m_hasAcceleratedCompositing)
return false;
Node* node = renderer->node();
if (!node || (!node->hasTagName(HTMLNames::videoTag) && !isHTMLAudioElement(node)))
return false;
HTMLMediaElement* mediaElement = toHTMLMediaElement(node);
return mediaElement->player() ? mediaElement->player()->supportsAcceleratedRendering() : false;
}
#endif // ENABLE(PLUGIN_PROXY_FOR_VIDEO)
#else
UNUSED_PARAM(renderer);
#endif
return false;
}
bool RenderLayerCompositor::requiresCompositingForCanvas(RenderObject* renderer) const
{
if (!(m_compositingTriggers & ChromeClient::CanvasTrigger))
return false;
if (renderer->isCanvas()) {
HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(renderer->node());
#if USE(COMPOSITING_FOR_SMALL_CANVASES)
bool isCanvasLargeEnoughToForceCompositing = true;
#else
bool isCanvasLargeEnoughToForceCompositing = canvas->size().area() >= canvasAreaThresholdRequiringCompositing;
#endif
return canvas->renderingContext() && canvas->renderingContext()->isAccelerated() && (canvas->renderingContext()->is3d() || isCanvasLargeEnoughToForceCompositing);
}
return false;
}
bool RenderLayerCompositor::requiresCompositingForPlugin(RenderObject* renderer) const
{
if (!(m_compositingTriggers & ChromeClient::PluginTrigger))
return false;
bool composite = renderer->isEmbeddedObject() && toRenderEmbeddedObject(renderer)->allowsAcceleratedCompositing();
if (!composite)
return false;
m_reevaluateCompositingAfterLayout = true;
RenderWidget* pluginRenderer = toRenderWidget(renderer);
// If we can't reliably know the size of the plugin yet, don't change compositing state.
if (pluginRenderer->needsLayout())
return pluginRenderer->hasLayer() && pluginRenderer->layer()->isComposited();
// Don't go into compositing mode if height or width are zero, or size is 1x1.
IntRect contentBox = pixelSnappedIntRect(pluginRenderer->contentBoxRect());
return contentBox.height() * contentBox.width() > 1;
}
bool RenderLayerCompositor::requiresCompositingForFrame(RenderObject* renderer) const
{
if (!renderer->isRenderPart())
return false;
RenderPart* frameRenderer = toRenderPart(renderer);
if (!frameRenderer->requiresAcceleratedCompositing())
return false;
m_reevaluateCompositingAfterLayout = true;
RenderLayerCompositor* innerCompositor = frameContentsCompositor(frameRenderer);
if (!innerCompositor || !innerCompositor->shouldPropagateCompositingToEnclosingFrame())
return false;
// If we can't reliably know the size of the iframe yet, don't change compositing state.
if (!renderer->parent() || renderer->needsLayout())
return frameRenderer->hasLayer() && frameRenderer->layer()->isComposited();
// Don't go into compositing mode if height or width are zero.
IntRect contentBox = pixelSnappedIntRect(frameRenderer->contentBoxRect());
return contentBox.height() * contentBox.width() > 0;
}
bool RenderLayerCompositor::requiresCompositingForAnimation(RenderObject* renderer) const
{
if (!(m_compositingTriggers & ChromeClient::AnimationTrigger))
return false;
if (AnimationController* animController = renderer->animation()) {
return (animController->isRunningAnimationOnRenderer(renderer, CSSPropertyOpacity)
&& (inCompositingMode() || (m_compositingTriggers & ChromeClient::AnimatedOpacityTrigger)))
#if ENABLE(CSS_FILTERS)
#if !PLATFORM(MAC) || (!PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080)
// <rdar://problem/10907251> - WebKit2 doesn't support CA animations of CI filters on Lion and below
|| animController->isRunningAnimationOnRenderer(renderer, CSSPropertyWebkitFilter)
#endif // !PLATFORM(MAC) || (!PLATFORM(IOS) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080)
#endif // CSS_FILTERS
|| animController->isRunningAnimationOnRenderer(renderer, CSSPropertyWebkitTransform);
}
return false;
}
bool RenderLayerCompositor::requiresCompositingForIndirectReason(RenderObject* renderer, bool hasCompositedDescendants, bool has3DTransformedDescendants, RenderLayer::IndirectCompositingReason& reason) const
{
RenderLayer* layer = toRenderBoxModelObject(renderer)->layer();
// When a layer has composited descendants, some effects, like 2d transforms, filters, masks etc must be implemented
// via compositing so that they also apply to those composited descdendants.
if (hasCompositedDescendants && (layer->transform() || renderer->createsGroup() || renderer->hasReflection())) {
reason = RenderLayer::IndirectCompositingForGraphicalEffect;
return true;
}
// A layer with preserve-3d or perspective only needs to be composited if there are descendant layers that
// will be affected by the preserve-3d or perspective.
if (has3DTransformedDescendants) {
if (renderer->style()->transformStyle3D() == TransformStyle3DPreserve3D) {
reason = RenderLayer::IndirectCompositingForPreserve3D;
return true;
}
if (renderer->style()->hasPerspective()) {
reason = RenderLayer::IndirectCompositingForPerspective;
return true;
}
}
reason = RenderLayer::NoIndirectCompositingReason;
return false;
}
bool RenderLayerCompositor::requiresCompositingForFilters(RenderObject* renderer) const
{
#if ENABLE(CSS_FILTERS)
if (!(m_compositingTriggers & ChromeClient::FilterTrigger))
return false;
return renderer->hasFilter();
#else
UNUSED_PARAM(renderer);
return false;
#endif
}
bool RenderLayerCompositor::requiresCompositingForBlending(RenderObject* renderer) const
{
#if ENABLE(CSS_COMPOSITING)
return renderer->hasBlendMode();
#else
UNUSED_PARAM(renderer);
return false;
#endif
}
static bool isViewportConstrainedFixedOrStickyLayer(const RenderLayer* layer)
{
if (layer->renderer()->isStickyPositioned())
return !layer->enclosingOverflowClipLayer(ExcludeSelf);
if (layer->renderer()->style()->position() != FixedPosition)
return false;
for (RenderLayer* stackingContainer = layer->stackingContainer(); stackingContainer; stackingContainer = stackingContainer->stackingContainer()) {
if (stackingContainer->isComposited() && stackingContainer->renderer()->style()->position() == FixedPosition)
return false;
}
return true;
}
bool RenderLayerCompositor::requiresCompositingForPosition(RenderObject* renderer, const RenderLayer* layer, RenderLayer::ViewportConstrainedNotCompositedReason* viewportConstrainedNotCompositedReason) const
{
// position:fixed elements that create their own stacking context (e.g. have an explicit z-index,
// opacity, transform) can get their own composited layer. A stacking context is required otherwise
// z-index and clipping will be broken.
if (!renderer->isPositioned())
return false;
EPosition position = renderer->style()->position();
bool isFixed = renderer->isOutOfFlowPositioned() && position == FixedPosition;
if (isFixed && !layer->isStackingContainer())
return false;
bool isSticky = renderer->isInFlowPositioned() && position == StickyPosition;
if (!isFixed && !isSticky)
return false;
// FIXME: acceleratedCompositingForFixedPositionEnabled should probably be renamed acceleratedCompositingForViewportConstrainedPositionEnabled().
if (Settings* settings = m_renderView->document()->settings()) {
if (!settings->acceleratedCompositingForFixedPositionEnabled())
return false;
}
if (isSticky)
return hasCoordinatedScrolling() && isViewportConstrainedFixedOrStickyLayer(layer);
RenderObject* container = renderer->container();
// If the renderer is not hooked up yet then we have to wait until it is.
if (!container) {
m_reevaluateCompositingAfterLayout = true;
return false;
}
// Don't promote fixed position elements that are descendants of a non-view container, e.g. transformed elements.
// They will stay fixed wrt the container rather than the enclosing frame.
if (container != m_renderView) {
if (viewportConstrainedNotCompositedReason)
*viewportConstrainedNotCompositedReason = RenderLayer::NotCompositedForNonViewContainer;
return false;
}
// Subsequent tests depend on layout. If we can't tell now, just keep things the way they are until layout is done.
if (!m_inPostLayoutUpdate) {
m_reevaluateCompositingAfterLayout = true;
return layer->isComposited();
}
bool paintsContent = layer->isVisuallyNonEmpty() || layer->hasVisibleDescendant();
if (!paintsContent) {
if (viewportConstrainedNotCompositedReason)
*viewportConstrainedNotCompositedReason = RenderLayer::NotCompositedForNoVisibleContent;
return false;
}
// Fixed position elements that are invisible in the current view don't get their own layer.
if (FrameView* frameView = m_renderView->frameView()) {
LayoutRect viewBounds = frameView->viewportConstrainedVisibleContentRect();
LayoutRect layerBounds = layer->calculateLayerBounds(rootRenderLayer(), 0, RenderLayer::DefaultCalculateLayerBoundsFlags
| RenderLayer::ExcludeHiddenDescendants | RenderLayer::DontConstrainForMask | RenderLayer::IncludeCompositedDescendants);
if (!viewBounds.intersects(enclosingIntRect(layerBounds))) {
if (viewportConstrainedNotCompositedReason)
*viewportConstrainedNotCompositedReason = RenderLayer::NotCompositedForBoundsOutOfView;
return false;
}
}
return true;
}
bool RenderLayerCompositor::requiresCompositingForOverflowScrolling(const RenderLayer* layer) const
{
return layer->needsCompositedScrolling();
}
bool RenderLayerCompositor::isRunningAcceleratedTransformAnimation(RenderObject* renderer) const
{
if (!(m_compositingTriggers & ChromeClient::AnimationTrigger))
return false;
if (AnimationController* animController = renderer->animation())
return animController->isRunningAnimationOnRenderer(renderer, CSSPropertyWebkitTransform);
return false;
}
// If an element has negative z-index children, those children render in front of the
// layer background, so we need an extra 'contents' layer for the foreground of the layer
// object.
bool RenderLayerCompositor::needsContentsCompositingLayer(const RenderLayer* layer) const
{
return layer->hasNegativeZOrderList();
}
bool RenderLayerCompositor::requiresScrollLayer(RootLayerAttachment attachment) const
{
// This applies when the application UI handles scrolling, in which case RenderLayerCompositor doesn't need to manage it.
if (m_renderView->frameView()->delegatesScrolling())
return false;
// We need to handle our own scrolling if we're:
return !m_renderView->frameView()->platformWidget() // viewless (i.e. non-Mac, or Mac in WebKit2)
|| attachment == RootLayerAttachedViaEnclosingFrame; // a composited frame on Mac
}
static void paintScrollbar(Scrollbar* scrollbar, GraphicsContext& context, const IntRect& clip)
{
if (!scrollbar)
return;
context.save();
const IntRect& scrollbarRect = scrollbar->frameRect();
context.translate(-scrollbarRect.x(), -scrollbarRect.y());
IntRect transformedClip = clip;
transformedClip.moveBy(scrollbarRect.location());
scrollbar->paint(&context, transformedClip);
context.restore();
}
void RenderLayerCompositor::paintContents(const GraphicsLayer* graphicsLayer, GraphicsContext& context, GraphicsLayerPaintingPhase, const IntRect& clip)
{
if (graphicsLayer == layerForHorizontalScrollbar())
paintScrollbar(m_renderView->frameView()->horizontalScrollbar(), context, clip);
else if (graphicsLayer == layerForVerticalScrollbar())
paintScrollbar(m_renderView->frameView()->verticalScrollbar(), context, clip);
else if (graphicsLayer == layerForScrollCorner()) {
const IntRect& scrollCorner = m_renderView->frameView()->scrollCornerRect();
context.save();
context.translate(-scrollCorner.x(), -scrollCorner.y());
IntRect transformedClip = clip;
transformedClip.moveBy(scrollCorner.location());
m_renderView->frameView()->paintScrollCorner(&context, transformedClip);
context.restore();
}
}
bool RenderLayerCompositor::supportsFixedRootBackgroundCompositing() const
{
RenderLayerBacking* renderViewBacking = m_renderView->layer()->backing();
return renderViewBacking && renderViewBacking->usingTiledBacking();
}
bool RenderLayerCompositor::needsFixedRootBackgroundLayer(const RenderLayer* layer) const
{
if (layer != m_renderView->layer())
return false;
return supportsFixedRootBackgroundCompositing() && m_renderView->rootBackgroundIsEntirelyFixed();
}
GraphicsLayer* RenderLayerCompositor::fixedRootBackgroundLayer() const
{
// Get the fixed root background from the RenderView layer's backing.
RenderLayer* viewLayer = m_renderView->layer();
if (!viewLayer)
return 0;
if (viewLayer->isComposited() && viewLayer->backing()->backgroundLayerPaintsFixedRootBackground())
return viewLayer->backing()->backgroundLayer();
return 0;
}
static void resetTrackedRepaintRectsRecursive(GraphicsLayer* graphicsLayer)
{
if (!graphicsLayer)
return;
graphicsLayer->resetTrackedRepaints();
for (size_t i = 0; i < graphicsLayer->children().size(); ++i)
resetTrackedRepaintRectsRecursive(graphicsLayer->children()[i]);
if (GraphicsLayer* replicaLayer = graphicsLayer->replicaLayer())
resetTrackedRepaintRectsRecursive(replicaLayer);
if (GraphicsLayer* maskLayer = graphicsLayer->maskLayer())
resetTrackedRepaintRectsRecursive(maskLayer);
}
void RenderLayerCompositor::resetTrackedRepaintRects()
{
if (GraphicsLayer* rootLayer = rootGraphicsLayer())
resetTrackedRepaintRectsRecursive(rootLayer);
}
void RenderLayerCompositor::setTracksRepaints(bool tracksRepaints)
{
m_isTrackingRepaints = tracksRepaints;
}
bool RenderLayerCompositor::isTrackingRepaints() const
{
return m_isTrackingRepaints;
}
float RenderLayerCompositor::deviceScaleFactor() const
{
Page* page = this->page();
return page ? page->deviceScaleFactor() : 1;
}
float RenderLayerCompositor::pageScaleFactor() const
{
Page* page = this->page();
return page ? page->pageScaleFactor() : 1;
}
void RenderLayerCompositor::didCommitChangesForLayer(const GraphicsLayer*) const
{
// Nothing to do here yet.
}
bool RenderLayerCompositor::keepLayersPixelAligned() const
{
// When scaling, attempt to align compositing layers to pixel boundaries.
return true;
}
bool RenderLayerCompositor::shouldCompositeOverflowControls() const
{
FrameView* view = m_renderView->frameView();
if (view->platformWidget())
return false;
if (hasCoordinatedScrolling())
return true;
if (!view->hasOverlayScrollbars())
return false;
return true;
}
bool RenderLayerCompositor::requiresHorizontalScrollbarLayer() const
{
FrameView* view = m_renderView->frameView();
return shouldCompositeOverflowControls() && view->horizontalScrollbar();
}
bool RenderLayerCompositor::requiresVerticalScrollbarLayer() const
{
FrameView* view = m_renderView->frameView();
return shouldCompositeOverflowControls() && view->verticalScrollbar();
}
bool RenderLayerCompositor::requiresScrollCornerLayer() const
{
FrameView* view = m_renderView->frameView();
return shouldCompositeOverflowControls() && view->isScrollCornerVisible();
}
#if ENABLE(RUBBER_BANDING)
bool RenderLayerCompositor::requiresOverhangAreasLayer() const
{
// We don't want a layer if this is a subframe.
if (m_renderView->document()->ownerElement())
return false;
// We do want a layer if we have a scrolling coordinator and can scroll.
if (scrollingCoordinator() && m_renderView->frameView()->hasOpaqueBackground() && !m_renderView->frameView()->prohibitsScrolling())
return true;
return false;
}
bool RenderLayerCompositor::requiresContentShadowLayer() const
{
// We don't want a layer if this is a subframe.
if (m_renderView->document()->ownerElement())
return false;
#if PLATFORM(MAC)
if (viewHasTransparentBackground())
return false;
// On Mac, we want a content shadow layer if we have a scrolling coordinator and can scroll.
if (scrollingCoordinator() && !m_renderView->frameView()->prohibitsScrolling())
return true;
#endif
return false;
}
GraphicsLayer* RenderLayerCompositor::updateLayerForTopOverhangArea(bool wantsLayer)
{
if (m_renderView->document()->ownerElement())
return 0;
if (!wantsLayer) {
if (m_layerForTopOverhangArea) {
m_layerForTopOverhangArea->removeFromParent();
m_layerForTopOverhangArea = nullptr;
}
return 0;
}
if (!m_layerForTopOverhangArea) {
m_layerForTopOverhangArea = GraphicsLayer::create(graphicsLayerFactory(), this);
#ifndef NDEBUG
m_layerForTopOverhangArea->setName("top overhang area");
#endif
m_scrollLayer->addChildBelow(m_layerForTopOverhangArea.get(), m_rootContentLayer.get());
}
return m_layerForTopOverhangArea.get();
}
GraphicsLayer* RenderLayerCompositor::updateLayerForBottomOverhangArea(bool wantsLayer)
{
if (m_renderView->document()->ownerElement())
return 0;
if (!wantsLayer) {
if (m_layerForBottomOverhangArea) {
m_layerForBottomOverhangArea->removeFromParent();
m_layerForBottomOverhangArea = nullptr;
}
return 0;
}
if (!m_layerForBottomOverhangArea) {
m_layerForBottomOverhangArea = GraphicsLayer::create(graphicsLayerFactory(), this);
#ifndef NDEBUG
m_layerForBottomOverhangArea->setName("bottom overhang area");
#endif
m_scrollLayer->addChildBelow(m_layerForBottomOverhangArea.get(), m_rootContentLayer.get());
}
m_layerForBottomOverhangArea->setPosition(FloatPoint(0, m_rootContentLayer->size().height() + m_renderView->frameView()->headerHeight() + m_renderView->frameView()->footerHeight()));
return m_layerForBottomOverhangArea.get();
}
GraphicsLayer* RenderLayerCompositor::updateLayerForHeader(bool wantsLayer)
{
if (m_renderView->document()->ownerElement())
return 0;
if (!wantsLayer) {
if (m_layerForHeader) {
m_layerForHeader->removeFromParent();
m_layerForHeader = nullptr;
// The ScrollingTree knows about the header layer, and the position of the root layer is affected
// by the header layer, so if we remove the header, we need to tell the scrolling tree.
if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
scrollingCoordinator->frameViewRootLayerDidChange(m_renderView->frameView());
}
return 0;
}
if (!m_layerForHeader) {
m_layerForHeader = GraphicsLayer::create(graphicsLayerFactory(), this);
#ifndef NDEBUG
m_layerForHeader->setName("header");
#endif
m_scrollLayer->addChildBelow(m_layerForHeader.get(), m_rootContentLayer.get());
m_renderView->frameView()->addPaintPendingMilestones(DidFirstFlushForHeaderLayer);
}
m_layerForHeader->setPosition(FloatPoint());
m_layerForHeader->setAnchorPoint(FloatPoint3D());
m_layerForHeader->setSize(FloatSize(m_renderView->frameView()->visibleWidth(), m_renderView->frameView()->headerHeight()));
if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
scrollingCoordinator->frameViewRootLayerDidChange(m_renderView->frameView());
if (Page* page = this->page())
page->chrome().client()->didAddHeaderLayer(m_layerForHeader.get());
return m_layerForHeader.get();
}
GraphicsLayer* RenderLayerCompositor::updateLayerForFooter(bool wantsLayer)
{
if (m_renderView->document()->ownerElement())
return 0;
if (!wantsLayer) {
if (m_layerForFooter) {
m_layerForFooter->removeFromParent();
m_layerForFooter = nullptr;
// The ScrollingTree knows about the footer layer, and the total scrollable size is affected
// by the footer layer, so if we remove the footer, we need to tell the scrolling tree.
if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
scrollingCoordinator->frameViewRootLayerDidChange(m_renderView->frameView());
}
return 0;
}
if (!m_layerForFooter) {
m_layerForFooter = GraphicsLayer::create(graphicsLayerFactory(), this);
#ifndef NDEBUG
m_layerForFooter->setName("footer");
#endif
m_scrollLayer->addChildBelow(m_layerForFooter.get(), m_rootContentLayer.get());
}
m_layerForFooter->setPosition(FloatPoint(0, m_rootContentLayer->size().height() + m_renderView->frameView()->headerHeight()));
m_layerForFooter->setAnchorPoint(FloatPoint3D());
m_layerForFooter->setSize(FloatSize(m_renderView->frameView()->visibleWidth(), m_renderView->frameView()->footerHeight()));
if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
scrollingCoordinator->frameViewRootLayerDidChange(m_renderView->frameView());
if (Page* page = this->page())
page->chrome().client()->didAddFooterLayer(m_layerForFooter.get());
return m_layerForFooter.get();
}
#endif
bool RenderLayerCompositor::viewHasTransparentBackground(Color* backgroundColor) const
{
FrameView* frameView = m_renderView->frameView();
if (frameView->isTransparent()) {
if (backgroundColor)
*backgroundColor = Color(); // Return an invalid color.
return true;
}
Color documentBackgroundColor = frameView->documentBackgroundColor();
if (!documentBackgroundColor.isValid())
documentBackgroundColor = Color::white;
if (backgroundColor)
*backgroundColor = documentBackgroundColor;
return documentBackgroundColor.hasAlpha();
}
void RenderLayerCompositor::updateOverflowControlsLayers()
{
#if ENABLE(RUBBER_BANDING)
if (requiresOverhangAreasLayer()) {
if (!m_layerForOverhangAreas) {
m_layerForOverhangAreas = GraphicsLayer::create(graphicsLayerFactory(), this);
#ifndef NDEBUG
m_layerForOverhangAreas->setName("overhang areas");
#endif
m_layerForOverhangAreas->setDrawsContent(false);
m_layerForOverhangAreas->setSize(m_renderView->frameView()->frameRect().size());
ScrollbarTheme::theme()->setUpOverhangAreasLayerContents(m_layerForOverhangAreas.get(), this->page()->chrome().client()->underlayColor());
// We want the overhang areas layer to be positioned below the frame contents,
// so insert it below the clip layer.
m_overflowControlsHostLayer->addChildBelow(m_layerForOverhangAreas.get(), m_clipLayer.get());
}
} else if (m_layerForOverhangAreas) {
m_layerForOverhangAreas->removeFromParent();
m_layerForOverhangAreas = nullptr;
}
if (requiresContentShadowLayer()) {
if (!m_contentShadowLayer) {
m_contentShadowLayer = GraphicsLayer::create(graphicsLayerFactory(), this);
#ifndef NDEBUG
m_contentShadowLayer->setName("content shadow");
#endif
m_contentShadowLayer->setSize(m_rootContentLayer->size());
m_contentShadowLayer->setPosition(m_rootContentLayer->position());
ScrollbarTheme::theme()->setUpContentShadowLayer(m_contentShadowLayer.get());
m_scrollLayer->addChildBelow(m_contentShadowLayer.get(), m_rootContentLayer.get());
}
} else if (m_contentShadowLayer) {
m_contentShadowLayer->removeFromParent();
m_contentShadowLayer = nullptr;
}
#endif
if (requiresHorizontalScrollbarLayer()) {
if (!m_layerForHorizontalScrollbar) {
m_layerForHorizontalScrollbar = GraphicsLayer::create(graphicsLayerFactory(), this);
m_layerForHorizontalScrollbar->setShowDebugBorder(m_showDebugBorders);
#ifndef NDEBUG
m_layerForHorizontalScrollbar->setName("horizontal scrollbar");
#endif
#if PLATFORM(MAC) && USE(CA)
m_layerForHorizontalScrollbar->setAcceleratesDrawing(acceleratedDrawingEnabled());
#endif
m_overflowControlsHostLayer->addChild(m_layerForHorizontalScrollbar.get());
if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
scrollingCoordinator->scrollableAreaScrollbarLayerDidChange(m_renderView->frameView(), HorizontalScrollbar);
}
} else if (m_layerForHorizontalScrollbar) {
m_layerForHorizontalScrollbar->removeFromParent();
m_layerForHorizontalScrollbar = nullptr;
if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
scrollingCoordinator->scrollableAreaScrollbarLayerDidChange(m_renderView->frameView(), HorizontalScrollbar);
}
if (requiresVerticalScrollbarLayer()) {
if (!m_layerForVerticalScrollbar) {
m_layerForVerticalScrollbar = GraphicsLayer::create(graphicsLayerFactory(), this);
m_layerForVerticalScrollbar->setShowDebugBorder(m_showDebugBorders);
#ifndef NDEBUG
m_layerForVerticalScrollbar->setName("vertical scrollbar");
#endif
#if PLATFORM(MAC) && USE(CA)
m_layerForVerticalScrollbar->setAcceleratesDrawing(acceleratedDrawingEnabled());
#endif
m_overflowControlsHostLayer->addChild(m_layerForVerticalScrollbar.get());
if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
scrollingCoordinator->scrollableAreaScrollbarLayerDidChange(m_renderView->frameView(), VerticalScrollbar);
}
} else if (m_layerForVerticalScrollbar) {
m_layerForVerticalScrollbar->removeFromParent();
m_layerForVerticalScrollbar = nullptr;
if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
scrollingCoordinator->scrollableAreaScrollbarLayerDidChange(m_renderView->frameView(), VerticalScrollbar);
}
if (requiresScrollCornerLayer()) {
if (!m_layerForScrollCorner) {
m_layerForScrollCorner = GraphicsLayer::create(graphicsLayerFactory(), this);
m_layerForScrollCorner->setShowDebugBorder(m_showDebugBorders);
#ifndef NDEBUG
m_layerForScrollCorner->setName("scroll corner");
#endif
#if PLATFORM(MAC) && USE(CA)
m_layerForScrollCorner->setAcceleratesDrawing(acceleratedDrawingEnabled());
#endif
m_overflowControlsHostLayer->addChild(m_layerForScrollCorner.get());
}
} else if (m_layerForScrollCorner) {
m_layerForScrollCorner->removeFromParent();
m_layerForScrollCorner = nullptr;
}
m_renderView->frameView()->positionScrollbarLayers();
}
void RenderLayerCompositor::ensureRootLayer()
{
RootLayerAttachment expectedAttachment = shouldPropagateCompositingToEnclosingFrame() ? RootLayerAttachedViaEnclosingFrame : RootLayerAttachedViaChromeClient;
if (expectedAttachment == m_rootLayerAttachment)
return;
if (!m_rootContentLayer) {
m_rootContentLayer = GraphicsLayer::create(graphicsLayerFactory(), this);
#ifndef NDEBUG
m_rootContentLayer->setName("content root");
#endif
IntRect overflowRect = m_renderView->pixelSnappedLayoutOverflowRect();
m_rootContentLayer->setSize(FloatSize(overflowRect.maxX(), overflowRect.maxY()));
m_rootContentLayer->setPosition(FloatPoint());
// Need to clip to prevent transformed content showing outside this frame
m_rootContentLayer->setMasksToBounds(true);
}
if (requiresScrollLayer(expectedAttachment)) {
if (!m_overflowControlsHostLayer) {
ASSERT(!m_scrollLayer);
ASSERT(!m_clipLayer);
// Create a layer to host the clipping layer and the overflow controls layers.
m_overflowControlsHostLayer = GraphicsLayer::create(graphicsLayerFactory(), this);
#ifndef NDEBUG
m_overflowControlsHostLayer->setName("overflow controls host");
#endif
// Create a clipping layer if this is an iframe
m_clipLayer = GraphicsLayer::create(graphicsLayerFactory(), this);
#ifndef NDEBUG
m_clipLayer->setName("frame clipping");
#endif
m_clipLayer->setMasksToBounds(true);
m_scrollLayer = GraphicsLayer::create(graphicsLayerFactory(), this);
#ifndef NDEBUG
m_scrollLayer->setName("frame scrolling");
#endif
if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
scrollingCoordinator->setLayerIsContainerForFixedPositionLayers(m_scrollLayer.get(), true);
// Hook them up
m_overflowControlsHostLayer->addChild(m_clipLayer.get());
m_clipLayer->addChild(m_scrollLayer.get());
m_scrollLayer->addChild(m_rootContentLayer.get());
frameViewDidChangeSize();
frameViewDidScroll();
}
} else {
if (m_overflowControlsHostLayer) {
m_overflowControlsHostLayer = nullptr;
m_clipLayer = nullptr;
m_scrollLayer = nullptr;
}
}
// Check to see if we have to change the attachment
if (m_rootLayerAttachment != RootLayerUnattached)
detachRootLayer();
attachRootLayer(expectedAttachment);
}
void RenderLayerCompositor::destroyRootLayer()
{
if (!m_rootContentLayer)
return;
detachRootLayer();
#if ENABLE(RUBBER_BANDING)
if (m_layerForOverhangAreas) {
m_layerForOverhangAreas->removeFromParent();
m_layerForOverhangAreas = nullptr;
}
#endif
if (m_layerForHorizontalScrollbar) {
m_layerForHorizontalScrollbar->removeFromParent();
m_layerForHorizontalScrollbar = nullptr;
if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
scrollingCoordinator->scrollableAreaScrollbarLayerDidChange(m_renderView->frameView(), HorizontalScrollbar);
if (Scrollbar* horizontalScrollbar = m_renderView->frameView()->verticalScrollbar())
m_renderView->frameView()->invalidateScrollbar(horizontalScrollbar, IntRect(IntPoint(0, 0), horizontalScrollbar->frameRect().size()));
}
if (m_layerForVerticalScrollbar) {
m_layerForVerticalScrollbar->removeFromParent();
m_layerForVerticalScrollbar = nullptr;
if (ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator())
scrollingCoordinator->scrollableAreaScrollbarLayerDidChange(m_renderView->frameView(), VerticalScrollbar);
if (Scrollbar* verticalScrollbar = m_renderView->frameView()->verticalScrollbar())
m_renderView->frameView()->invalidateScrollbar(verticalScrollbar, IntRect(IntPoint(0, 0), verticalScrollbar->frameRect().size()));
}
if (m_layerForScrollCorner) {
m_layerForScrollCorner = nullptr;
m_renderView->frameView()->invalidateScrollCorner(m_renderView->frameView()->scrollCornerRect());
}
if (m_overflowControlsHostLayer) {
m_overflowControlsHostLayer = nullptr;
m_clipLayer = nullptr;
m_scrollLayer = nullptr;
}
ASSERT(!m_scrollLayer);
m_rootContentLayer = nullptr;
m_layerUpdater = nullptr;
}
void RenderLayerCompositor::attachRootLayer(RootLayerAttachment attachment)
{
if (!m_rootContentLayer)
return;
switch (attachment) {
case RootLayerUnattached:
ASSERT_NOT_REACHED();
break;
case RootLayerAttachedViaChromeClient: {
Frame* frame = m_renderView->frameView()->frame();
Page* page = frame ? frame->page() : 0;
if (!page)
return;
page->chrome().client()->attachRootGraphicsLayer(frame, rootGraphicsLayer());
break;
}
case RootLayerAttachedViaEnclosingFrame: {
// The layer will get hooked up via RenderLayerBacking::updateGraphicsLayerConfiguration()
// for the frame's renderer in the parent document.
m_renderView->document()->ownerElement()->scheduleSetNeedsStyleRecalc(SyntheticStyleChange);
break;
}
}
m_rootLayerAttachment = attachment;
rootLayerAttachmentChanged();
if (m_shouldFlushOnReattach) {
flushPendingLayerChanges(true);
m_shouldFlushOnReattach = false;
}
}
void RenderLayerCompositor::detachRootLayer()
{
if (!m_rootContentLayer || m_rootLayerAttachment == RootLayerUnattached)
return;
switch (m_rootLayerAttachment) {
case RootLayerAttachedViaEnclosingFrame: {
// The layer will get unhooked up via RenderLayerBacking::updateGraphicsLayerConfiguration()
// for the frame's renderer in the parent document.
if (m_overflowControlsHostLayer)
m_overflowControlsHostLayer->removeFromParent();
else
m_rootContentLayer->removeFromParent();
if (HTMLFrameOwnerElement* ownerElement = m_renderView->document()->ownerElement())
ownerElement->scheduleSetNeedsStyleRecalc(SyntheticStyleChange);
break;
}
case RootLayerAttachedViaChromeClient: {
Frame* frame = m_renderView->frameView()->frame();
Page* page = frame ? frame->page() : 0;
if (!page)
return;
page->chrome().client()->attachRootGraphicsLayer(frame, 0);
}
break;
case RootLayerUnattached:
break;
}
m_rootLayerAttachment = RootLayerUnattached;
rootLayerAttachmentChanged();
}
void RenderLayerCompositor::updateRootLayerAttachment()
{
ensureRootLayer();
}
void RenderLayerCompositor::rootLayerAttachmentChanged()
{
// The attachment can affect whether the RenderView layer's paintsIntoWindow() behavior,
// so call updateGraphicsLayerGeometry() to udpate that.
RenderLayer* layer = m_renderView->layer();
if (RenderLayerBacking* backing = layer ? layer->backing() : 0)
backing->updateDrawsContent();
}
// IFrames are special, because we hook compositing layers together across iframe boundaries
// when both parent and iframe content are composited. So when this frame becomes composited, we have
// to use a synthetic style change to get the iframes into RenderLayers in order to allow them to composite.
void RenderLayerCompositor::notifyIFramesOfCompositingChange()
{
Frame* frame = m_renderView->frameView() ? m_renderView->frameView()->frame() : 0;
if (!frame)
return;
for (Frame* child = frame->tree()->firstChild(); child; child = child->tree()->traverseNext(frame)) {
if (child->document() && child->document()->ownerElement())
child->document()->ownerElement()->scheduleSetNeedsStyleRecalc(SyntheticStyleChange);
}
// Compositing also affects the answer to RenderIFrame::requiresAcceleratedCompositing(), so
// we need to schedule a style recalc in our parent document.
if (HTMLFrameOwnerElement* ownerElement = m_renderView->document()->ownerElement())
ownerElement->scheduleSetNeedsStyleRecalc(SyntheticStyleChange);
}
bool RenderLayerCompositor::layerHas3DContent(const RenderLayer* layer) const
{
const RenderStyle* style = layer->renderer()->style();
if (style &&
(style->transformStyle3D() == TransformStyle3DPreserve3D ||
style->hasPerspective() ||
style->transform().has3DOperation()))
return true;
const_cast<RenderLayer*>(layer)->updateLayerListsIfNeeded();
#if !ASSERT_DISABLED
LayerListMutationDetector mutationChecker(const_cast<RenderLayer*>(layer));
#endif
if (layer->isStackingContainer()) {
if (Vector<RenderLayer*>* negZOrderList = layer->negZOrderList()) {
size_t listSize = negZOrderList->size();
for (size_t i = 0; i < listSize; ++i) {
RenderLayer* curLayer = negZOrderList->at(i);
if (layerHas3DContent(curLayer))
return true;
}
}
if (Vector<RenderLayer*>* posZOrderList = layer->posZOrderList()) {
size_t listSize = posZOrderList->size();
for (size_t i = 0; i < listSize; ++i) {
RenderLayer* curLayer = posZOrderList->at(i);
if (layerHas3DContent(curLayer))
return true;
}
}
}
if (Vector<RenderLayer*>* normalFlowList = layer->normalFlowList()) {
size_t listSize = normalFlowList->size();
for (size_t i = 0; i < listSize; ++i) {
RenderLayer* curLayer = normalFlowList->at(i);
if (layerHas3DContent(curLayer))
return true;
}
}
return false;
}
void RenderLayerCompositor::deviceOrPageScaleFactorChanged()
{
// Start at the RenderView's layer, since that's where the scale is applied.
RenderLayer* viewLayer = m_renderView->layer();
if (!viewLayer->isComposited())
return;
if (GraphicsLayer* rootLayer = viewLayer->backing()->childForSuperlayers())
rootLayer->noteDeviceOrPageScaleFactorChangedIncludingDescendants();
}
void RenderLayerCompositor::updateViewportConstraintStatus(RenderLayer* layer)
{
if (isViewportConstrainedFixedOrStickyLayer(layer))
addViewportConstrainedLayer(layer);
else
removeViewportConstrainedLayer(layer);
}
void RenderLayerCompositor::addViewportConstrainedLayer(RenderLayer* layer)
{
m_viewportConstrainedLayers.add(layer);
registerOrUpdateViewportConstrainedLayer(layer);
}
void RenderLayerCompositor::removeViewportConstrainedLayer(RenderLayer* layer)
{
if (!m_viewportConstrainedLayers.contains(layer))
return;
unregisterViewportConstrainedLayer(layer);
m_viewportConstrainedLayers.remove(layer);
m_viewportConstrainedLayersNeedingUpdate.remove(layer);
}
FixedPositionViewportConstraints RenderLayerCompositor::computeFixedViewportConstraints(RenderLayer* layer) const
{
ASSERT(layer->isComposited());
FrameView* frameView = m_renderView->frameView();
LayoutRect viewportRect = frameView->viewportConstrainedVisibleContentRect();
FixedPositionViewportConstraints constraints;
GraphicsLayer* graphicsLayer = layer->backing()->graphicsLayer();
constraints.setLayerPositionAtLastLayout(graphicsLayer->position());
constraints.setViewportRectAtLastLayout(viewportRect);
RenderStyle* style = layer->renderer()->style();
if (!style->left().isAuto())
constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeLeft);
if (!style->right().isAuto())
constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeRight);
if (!style->top().isAuto())
constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeTop);
if (!style->bottom().isAuto())
constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeBottom);
// If left and right are auto, use left.
if (style->left().isAuto() && style->right().isAuto())
constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeLeft);
// If top and bottom are auto, use top.
if (style->top().isAuto() && style->bottom().isAuto())
constraints.addAnchorEdge(ViewportConstraints::AnchorEdgeTop);
return constraints;
}
StickyPositionViewportConstraints RenderLayerCompositor::computeStickyViewportConstraints(RenderLayer* layer) const
{
ASSERT(layer->isComposited());
// We should never get here for stickies constrained by an enclosing clipping layer.
ASSERT(!layer->enclosingOverflowClipLayer(ExcludeSelf));
FrameView* frameView = m_renderView->frameView();
LayoutRect viewportRect = frameView->viewportConstrainedVisibleContentRect();
RenderBoxModelObject* renderer = toRenderBoxModelObject(layer->renderer());
StickyPositionViewportConstraints constraints;
renderer->computeStickyPositionConstraints(constraints, viewportRect);
GraphicsLayer* graphicsLayer = layer->backing()->graphicsLayer();
constraints.setLayerPositionAtLastLayout(graphicsLayer->position());
constraints.setStickyOffsetAtLastLayout(renderer->stickyPositionOffset());
return constraints;
}
static RenderLayerBacking* nearestScrollingCoordinatorAncestor(RenderLayer* layer)
{
RenderLayer* ancestor = layer->parent();
while (ancestor) {
if (RenderLayerBacking* backing = ancestor->backing()) {
if (backing->scrollLayerID() && !ancestor->scrollsOverflow())
return backing;
}
ancestor = ancestor->parent();
}
return 0;
}
void RenderLayerCompositor::registerOrUpdateViewportConstrainedLayer(RenderLayer* layer)
{
// FIXME: We should support sticky position here! And we should eventuall support fixed/sticky elements
// that are inside non-main frames once we get non-main frames scrolling with the ScrollingCoordinator.
if (m_renderView->document()->ownerElement())
return;
ScrollingCoordinator* scrollingCoordinator = this->scrollingCoordinator();
if (!scrollingCoordinator)
return;
// FIXME: rename to supportsViewportConstrainedPositionLayers()?
if (!scrollingCoordinator->supportsFixedPositionLayers() || !layer->parent())
return;
ASSERT(m_viewportConstrainedLayers.contains(layer));
ASSERT(layer->isComposited());
RenderLayerBacking* backing = layer->backing();
if (!backing)
return;
ScrollingNodeID nodeID = backing->scrollLayerID();
RenderLayerBacking* parent = nearestScrollingCoordinatorAncestor(layer);
if (!parent)
return;
// Always call this even if the backing is already attached because the parent may have changed.
backing->attachToScrollingCoordinatorWithParent(parent);
nodeID = backing->scrollLayerID();
if (layer->renderer()->isStickyPositioned())
scrollingCoordinator->updateViewportConstrainedNode(nodeID, computeStickyViewportConstraints(layer), backing->graphicsLayer());
else
scrollingCoordinator->updateViewportConstrainedNode(nodeID, computeFixedViewportConstraints(layer), backing->graphicsLayer());
}
void RenderLayerCompositor::unregisterViewportConstrainedLayer(RenderLayer* layer)
{
ASSERT(m_viewportConstrainedLayers.contains(layer));
if (RenderLayerBacking* backing = layer->backing())
backing->detachFromScrollingCoordinator();
}
void RenderLayerCompositor::windowScreenDidChange(PlatformDisplayID displayID)
{
if (m_layerUpdater)
m_layerUpdater->screenDidChange(displayID);
}
ScrollingCoordinator* RenderLayerCompositor::scrollingCoordinator() const
{
if (Page* page = this->page())
return page->scrollingCoordinator();
return 0;
}
GraphicsLayerFactory* RenderLayerCompositor::graphicsLayerFactory() const
{
if (Page* page = this->page())
return page->chrome().client()->graphicsLayerFactory();
return 0;
}
Page* RenderLayerCompositor::page() const
{
if (Frame* frame = m_renderView->frameView()->frame())
return frame->page();
return 0;
}
void RenderLayerCompositor::setLayerFlushThrottlingEnabled(bool enabled)
{
m_layerFlushThrottlingEnabled = enabled;
if (m_layerFlushThrottlingEnabled)
return;
m_layerFlushTimer.stop();
if (!m_hasPendingLayerFlush)
return;
scheduleLayerFlushNow();
}
void RenderLayerCompositor::disableLayerFlushThrottlingTemporarilyForInteraction()
{
if (m_layerFlushThrottlingTemporarilyDisabledForInteraction)
return;
m_layerFlushThrottlingTemporarilyDisabledForInteraction = true;
}
bool RenderLayerCompositor::isThrottlingLayerFlushes() const
{
if (!m_layerFlushThrottlingEnabled)
return false;
if (!m_layerFlushTimer.isActive())
return false;
if (m_layerFlushThrottlingTemporarilyDisabledForInteraction)
return false;
return true;
}
void RenderLayerCompositor::startLayerFlushTimerIfNeeded()
{
m_layerFlushThrottlingTemporarilyDisabledForInteraction = false;
m_layerFlushTimer.stop();
if (!m_layerFlushThrottlingEnabled)
return;
m_layerFlushTimer.startOneShot(throttledLayerFlushDelay);
}
void RenderLayerCompositor::layerFlushTimerFired(Timer<RenderLayerCompositor>*)
{
if (!m_hasPendingLayerFlush)
return;
scheduleLayerFlushNow();
}
void RenderLayerCompositor::paintRelatedMilestonesTimerFired(Timer<RenderLayerCompositor>*)
{
FrameView* frameView = m_renderView ? m_renderView->frameView() : 0;
if (!frameView)
return;
Frame* frame = frameView->frame();
Page* page = frame ? frame->page() : 0;
if (!page)
return;
// If the layer tree is frozen, we'll paint when it's unfrozen and schedule the timer again.
if (page->chrome().client()->layerTreeStateIsFrozen())
return;
frameView->firePaintRelatedMilestones();
}
} // namespace WebCore
#endif // USE(ACCELERATED_COMPOSITING)
|