1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415
|
/*
* Copyright (C) 2010, 2013 Apple Inc. All rights reserved.
* Copyright (C) 2019 Google 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 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 ENABLE(WEBGL)
#include "GraphicsContextGLANGLE.h"
#include "ANGLEHeaders.h"
#include "ANGLEUtilities.h"
#include "ByteArrayPixelBuffer.h"
#include "ImageBuffer.h"
#include "IntRect.h"
#include "IntSize.h"
#include "Logging.h"
#include "NotImplemented.h"
#include <algorithm>
#include <cstring>
#include <wtf/MallocSpan.h>
#include <wtf/RuntimeApplicationChecks.h>
#include <wtf/Seconds.h>
#include <wtf/StdLibExtras.h>
#include <wtf/text/CString.h>
#include <wtf/text/StringBuilder.h>
#if ENABLE(VIDEO) && USE(AVFOUNDATION)
#include "GraphicsContextGLCVCocoa.h"
#endif
// This one definition short-circuits the need for gl2ext.h, which
// would need more work to be included from WebCore.
#define GL_MAX_SAMPLES_EXT 0x8D57
namespace WebCore {
// List of displays ever instantiated from EGL. When terminating all EGL resources, we need to
// terminate all displays. However, we cannot ask EGL all the displays it has created.
// We must know all the displays via this set.
static UncheckedKeyHashSet<GCGLDisplay>& usedDisplays()
{
static NeverDestroyed<UncheckedKeyHashSet<GCGLDisplay>> s_usedDisplays;
return s_usedDisplays;
}
#if PLATFORM(MAC) || PLATFORM(IOS_FAMILY)
static void wipeAlphaChannelFromPixels(std::span<uint8_t> pixels)
{
for (size_t i = 0; i < pixels.size(); i += 4)
pixels[i + 3] = 255;
}
#endif
static inline const Vector<const void*> asPointers(std::span<const GCGLsizei> offsets)
{
// Must cast offsets from int to void* before passing down to ANGLE.
return WTF::map(offsets, [](const GCGLsizei offset) {
return reinterpret_cast<const void*>(offset);
});
}
GraphicsContextGLANGLE::GraphicsContextGLANGLE(GraphicsContextGLAttributes attributes)
: GraphicsContextGL(attributes)
{
}
bool GraphicsContextGLANGLE::initialize()
{
if (contextAttributes().failContextCreationForTesting == GraphicsContextGLAttributes::SimulatedCreationFailure::FailPlatformContextCreation)
return false;
if (!platformInitializeContext())
return false;
String extensionsString = String::fromLatin1(byteCast<char>(GL_GetString(GL_EXTENSIONS)));
for (auto& extension : extensionsString.split(' '))
m_availableExtensions.add(extension);
extensionsString = String::fromLatin1(byteCast<char>(GL_GetString(GL_REQUESTABLE_EXTENSIONS_ANGLE)));
for (auto& extension : extensionsString.split(' '))
m_requestableExtensions.add(extension);
validateAttributes();
auto attributes = contextAttributes(); // They may have changed during validation.
if (m_isForWebGL2) {
if (!enableExtension("GL_EXT_occlusion_query_boolean"_s))
return false;
if (!enableExtension("GL_ANGLE_framebuffer_multisample"_s))
return false;
}
if (!platformInitializeExtensions())
return false;
if (m_isForWebGL2)
GL_Enable(GraphicsContextGL::PRIMITIVE_RESTART_FIXED_INDEX);
// Create the texture that will be used for the framebuffer.
GLenum textureTarget = drawingBufferTextureTarget();
GL_GenTextures(1, &m_texture);
GL_BindTexture(textureTarget, m_texture);
GL_TexParameteri(textureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
GL_TexParameteri(textureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
GL_TexParameteri(textureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
GL_TexParameteri(textureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
GL_BindTexture(textureTarget, 0);
GL_GenFramebuffers(1, &m_fbo);
GL_BindFramebuffer(GL_FRAMEBUFFER, m_fbo);
m_state.boundDrawFBO = m_state.boundReadFBO = m_fbo;
if (!attributes.antialias && (attributes.stencil || attributes.depth))
GL_GenRenderbuffers(1, &m_depthStencilBuffer);
// If necessary, create another framebuffer for the multisample results.
if (attributes.antialias) {
GL_GenFramebuffers(1, &m_multisampleFBO);
GL_BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO);
m_state.boundDrawFBO = m_state.boundReadFBO = m_multisampleFBO;
GL_GenRenderbuffers(1, &m_multisampleColorBuffer);
if (attributes.stencil || attributes.depth)
GL_GenRenderbuffers(1, &m_multisampleDepthStencilBuffer);
} else if (attributes.preserveDrawingBuffer) {
// If necessary, create another texture to handle preserveDrawingBuffer:true without
// antialiasing.
GL_GenTextures(1, &m_preserveDrawingBufferTexture);
GL_BindTexture(GL_TEXTURE_2D, m_preserveDrawingBufferTexture);
GL_TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
GL_TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
GL_TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
GL_TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
GL_BindTexture(GL_TEXTURE_2D, 0);
// Create an FBO with which to perform BlitFramebuffer from one texture to the other.
GL_GenFramebuffers(1, &m_preserveDrawingBufferFBO);
}
GL_ClearColor(0, 0, 0, 0);
if (!platformInitialize())
return false;
// EGL resources are only ever released if we run in process mode where EGL is used on host app threads, e.g. WK1
// mode.
static bool tracksUsedDisplays = !(isInWebProcess() || isInGPUProcess());
if (tracksUsedDisplays) {
// TODO: Move to ~GraphicsContextGLANGLE() when the function is moved to this file.
ASSERT(m_displayObj);
usedDisplays().add(m_displayObj);
}
if (supportsExtension("GL_KHR_debug"_s)) {
ensureExtensionEnabled("GL_KHR_debug"_s);
GL_Enable(DEBUG_OUTPUT);
GL_Enable(DEBUG_OUTPUT_SYNCHRONOUS);
GL_DebugMessageControlKHR(DONT_CARE, DONT_CARE, DONT_CARE, 0, nullptr, 0);
GL_DebugMessageControlKHR(DEBUG_SOURCE_API, DONT_CARE, DONT_CARE, 0, nullptr, 1);
auto debugMessageCallback = [](GCGLenum, GCGLenum type, GCGLenum id, GCGLenum severity, GCGLsizei length, const GCGLchar* message, const void* context) {
auto* gl = reinterpret_cast<const GraphicsContextGLANGLE*>(context);
if (gl->m_client)
gl->m_client->addDebugMessage(type, id, severity, String { unsafeMakeSpan(message, length) });
};
GL_DebugMessageCallbackKHR(debugMessageCallback, this);
}
ASSERT(GL_GetError() == NO_ERROR);
return true;
}
bool GraphicsContextGLANGLE::platformInitializeExtensions()
{
return true;
}
bool GraphicsContextGLANGLE::platformInitialize()
{
return true;
}
GCGLenum GraphicsContextGLANGLE::drawingBufferTextureTarget()
{
auto [textureTarget, _] = externalImageTextureBindingPoint();
UNUSED_VARIABLE(_);
return textureTarget;
}
std::tuple<GCGLenum, GCGLenum> GraphicsContextGLANGLE::drawingBufferTextureBindingPoint()
{
return externalImageTextureBindingPoint();
}
GCGLint GraphicsContextGLANGLE::EGLDrawingBufferTextureTargetForDrawingTarget(GCGLenum drawingTarget)
{
switch (drawingTarget) {
case TEXTURE_2D:
return EGL_TEXTURE_2D;
case TEXTURE_RECTANGLE_ARB:
return EGL_TEXTURE_RECTANGLE_ANGLE;
}
ASSERT_WITH_MESSAGE(false, "Invalid drawing target");
return 0;
}
bool GraphicsContextGLANGLE::releaseThreadResources(ReleaseThreadResourceBehavior releaseBehavior)
{
platformReleaseThreadResources();
if (!platformIsANGLEAvailable())
return false;
// Unset the EGL current context, since the next access might be from another thread, and the
// context cannot be current on multiple threads.
if (releaseBehavior == ReleaseThreadResourceBehavior::ReleaseCurrentContext) {
EGLDisplay display = EGL_GetCurrentDisplay();
if (display == EGL_NO_DISPLAY)
return true;
// At the time of writing, ANGLE does not flush on MakeCurrent. Since we are
// potentially switching threads, we should flush.
// Note: Here we assume also that ANGLE has only one platform context -- otherwise
// we would need to flush each EGL context that has been used.
GL_Flush();
return EGL_MakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
}
if (releaseBehavior == ReleaseThreadResourceBehavior::TerminateAndReleaseThreadResources) {
EGLDisplay currentDisplay = EGL_GetCurrentDisplay();
if (currentDisplay != EGL_NO_DISPLAY) {
ASSERT_NOT_REACHED(); // All resources must have been destroyed.
EGL_MakeCurrent(currentDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
}
for (auto display : usedDisplays())
EGL_Terminate(display);
usedDisplays().clear();
}
// Called when we do not know if we will ever see another call from this thread again.
// Unset the EGL current context by releasing whole EGL thread state.
return EGL_ReleaseThread();
}
RefPtr<PixelBuffer> GraphicsContextGLANGLE::readPixelsForPaintResults()
{
PixelBufferFormat format { AlphaPremultiplication::Unpremultiplied, PixelFormat::RGBA8, DestinationColorSpace::SRGB() };
auto pixelBuffer = ByteArrayPixelBuffer::tryCreate(format, getInternalFramebufferSize());
if (!pixelBuffer)
return nullptr;
ScopedBufferBinding scopedPixelPackBufferReset(GL_PIXEL_PACK_BUFFER, 0, m_isForWebGL2);
setPackParameters(1, 0, false);
GL_ReadnPixelsRobustANGLE(0, 0, pixelBuffer->size().width(), pixelBuffer->size().height(), GL_RGBA, GL_UNSIGNED_BYTE, pixelBuffer->bytes().size(), nullptr, nullptr, nullptr, pixelBuffer->bytes().data());
// FIXME: Rendering to GL_RGB textures with a IOSurface bound to the texture image leaves
// the alpha in the IOSurface in incorrect state. Also ANGLE GL_ReadPixels will in some
// cases expose the non-255 values.
// https://bugs.webkit.org/show_bug.cgi?id=215804
#if PLATFORM(MAC) || PLATFORM(IOS_FAMILY)
if (!contextAttributes().alpha)
wipeAlphaChannelFromPixels(pixelBuffer->bytes());
#endif
return pixelBuffer;
}
void GraphicsContextGLANGLE::validateAttributes()
{
m_internalColorFormat = contextAttributes().alpha ? GL_RGBA8 : GL_RGB8;
validateDepthStencil("GL_OES_packed_depth_stencil"_s);
}
bool GraphicsContextGLANGLE::reshapeFBOs(const IntSize& size)
{
auto attrs = contextAttributes();
const int width = size.width();
const int height = size.height();
GLuint colorFormat = attrs.alpha ? GL_RGBA : GL_RGB;
// Resize multisample FBO.
if (attrs.antialias) {
GLint maxSampleCount;
GL_GetIntegerv(GL_MAX_SAMPLES_ANGLE, &maxSampleCount);
// Using more than 4 samples is slow on some hardware and is unlikely to
// produce a significantly better result.
GLint sampleCount = std::min(4, maxSampleCount);
GL_BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO);
GL_BindRenderbuffer(GL_RENDERBUFFER, m_multisampleColorBuffer);
GL_RenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, sampleCount, m_internalColorFormat, width, height);
GL_FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, m_multisampleColorBuffer);
if (attrs.stencil || attrs.depth) {
ASSERT(m_internalDepthStencilFormat);
ASSERT(!attrs.stencil || m_internalDepthStencilFormat == GL_STENCIL_INDEX8 || m_internalDepthStencilFormat == GL_DEPTH24_STENCIL8_OES);
ASSERT(!attrs.depth || m_internalDepthStencilFormat != GL_STENCIL_INDEX8);
GL_BindRenderbuffer(GL_RENDERBUFFER, m_multisampleDepthStencilBuffer);
GL_RenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, sampleCount, m_internalDepthStencilFormat, width, height);
// WebGL 1.0's rules state that combined depth/stencil renderbuffers
// have to be attached to the synthetic DEPTH_STENCIL_ATTACHMENT point.
if (attrs.stencil && attrs.depth)
GL_FramebufferRenderbuffer(GL_FRAMEBUFFER, DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_multisampleDepthStencilBuffer);
else if (attrs.stencil)
GL_FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_multisampleDepthStencilBuffer);
else
GL_FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_multisampleDepthStencilBuffer);
}
GL_BindRenderbuffer(GL_RENDERBUFFER, 0);
if (GL_CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
// FIXME: cleanup.
notImplemented();
}
}
// resize regular FBO
GL_BindFramebuffer(GL_FRAMEBUFFER, m_fbo);
if (!reshapeDrawingBuffer()) {
RELEASE_LOG(WebGL, "Fatal: Unable to allocate backing store of size %d x %d", width, height);
forceContextLost();
return true;
}
if (m_preserveDrawingBufferTexture) {
// The context requires the use of an intermediate texture in order to implement
// preserveDrawingBuffer:true without antialiasing.
GLint texture2DBinding = 0;
GL_GetIntegerv(GL_TEXTURE_BINDING_2D, &texture2DBinding);
GL_BindTexture(GL_TEXTURE_2D, m_preserveDrawingBufferTexture);
// Note that any pixel unpack buffer was unbound earlier, in reshape().
GL_TexImage2D(GL_TEXTURE_2D, 0, colorFormat, width, height, 0, colorFormat, GL_UNSIGNED_BYTE, 0);
// m_fbo is bound at this point.
GL_FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_preserveDrawingBufferTexture, 0);
GL_BindTexture(GL_TEXTURE_2D, texture2DBinding);
// Attach m_texture to m_preserveDrawingBufferFBO for later blitting.
GL_BindFramebuffer(GL_FRAMEBUFFER, m_preserveDrawingBufferFBO);
GL_FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, drawingBufferTextureTarget(), m_texture, 0);
GL_BindFramebuffer(GL_FRAMEBUFFER, m_fbo);
} else
GL_FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, drawingBufferTextureTarget(), m_texture, 0);
attachDepthAndStencilBufferIfNeeded(m_internalDepthStencilFormat, width, height);
bool mustRestoreFBO = true;
if (attrs.antialias) {
GL_BindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO);
if (m_state.boundDrawFBO == m_multisampleFBO && m_state.boundReadFBO == m_multisampleFBO)
mustRestoreFBO = false;
} else {
if (m_state.boundDrawFBO == m_fbo && m_state.boundReadFBO == m_fbo)
mustRestoreFBO = false;
}
return mustRestoreFBO;
}
void GraphicsContextGLANGLE::attachDepthAndStencilBufferIfNeeded(GLuint internalDepthStencilFormat, int width, int height)
{
auto attrs = contextAttributes();
if (!attrs.antialias && (attrs.stencil || attrs.depth)) {
ASSERT(internalDepthStencilFormat);
ASSERT(!attrs.stencil || m_internalDepthStencilFormat == GL_STENCIL_INDEX8 || m_internalDepthStencilFormat == GL_DEPTH24_STENCIL8_OES);
ASSERT(!attrs.depth || internalDepthStencilFormat != GL_STENCIL_INDEX8);
GL_BindRenderbuffer(GL_RENDERBUFFER, m_depthStencilBuffer);
GL_RenderbufferStorage(GL_RENDERBUFFER, internalDepthStencilFormat, width, height);
// WebGL 1.0's rules state that combined depth/stencil renderbuffers
// have to be attached to the synthetic DEPTH_STENCIL_ATTACHMENT point.
if (attrs.stencil && attrs.depth)
GL_FramebufferRenderbuffer(GL_FRAMEBUFFER, DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_depthStencilBuffer);
else if (attrs.stencil)
GL_FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_depthStencilBuffer);
else
GL_FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_depthStencilBuffer);
GL_BindRenderbuffer(GL_RENDERBUFFER, 0);
}
if (GL_CheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
// FIXME: cleanup
notImplemented();
}
}
void GraphicsContextGLANGLE::resolveMultisamplingIfNecessary(const IntRect& rect)
{
prepareForDrawingBufferWrite();
ScopedGLCapability scopedScissor(GL_SCISSOR_TEST, GL_FALSE);
ScopedGLCapability scopedDither(GL_DITHER, GL_FALSE);
GLint boundFrameBuffer = 0;
GLint boundReadFrameBuffer = 0;
if (m_isForWebGL2) {
GL_GetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &boundFrameBuffer);
GL_GetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &boundReadFrameBuffer);
} else
GL_GetIntegerv(GL_FRAMEBUFFER_BINDING, &boundFrameBuffer);
GL_BindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_multisampleFBO);
GL_BindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo);
// FIXME: figure out more efficient solution for iOS.
if (m_isForWebGL2) {
// ES 3.0 has BlitFramebuffer.
IntRect resolveRect = rect.isEmpty() ? IntRect { 0, 0, m_currentWidth, m_currentHeight } : rect;
GL_BlitFramebuffer(resolveRect.x(), resolveRect.y(), resolveRect.maxX(), resolveRect.maxY(), resolveRect.x(), resolveRect.y(), resolveRect.maxX(), resolveRect.maxY(), GL_COLOR_BUFFER_BIT, GL_NEAREST);
} else {
// ES 2.0 has BlitFramebufferANGLE only.
GL_BlitFramebufferANGLE(0, 0, m_currentWidth, m_currentHeight, 0, 0, m_currentWidth, m_currentHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
}
if (m_isForWebGL2) {
GL_BindFramebuffer(GL_DRAW_FRAMEBUFFER, boundFrameBuffer);
GL_BindFramebuffer(GL_READ_FRAMEBUFFER, boundReadFrameBuffer);
} else
GL_BindFramebuffer(GL_FRAMEBUFFER, boundFrameBuffer);
}
void GraphicsContextGLANGLE::renderbufferStorage(GCGLenum target, GCGLenum internalformat, GCGLsizei width, GCGLsizei height)
{
if (!makeContextCurrent())
return;
GL_RenderbufferStorage(target, internalformat, width, height);
}
void GraphicsContextGLANGLE::getIntegerv(GCGLenum pname, std::span<GCGLint> value)
{
if (!makeContextCurrent())
return;
GL_GetIntegervRobustANGLE(pname, value.size(), nullptr, value.data());
}
void GraphicsContextGLANGLE::getIntegeri_v(GCGLenum pname, GCGLuint index, std::span<GCGLint, 4> value) // NOLINT
{
if (!makeContextCurrent())
return;
GL_GetIntegeri_vRobustANGLE(pname, index, value.size(), nullptr, value.data());
}
void GraphicsContextGLANGLE::getShaderPrecisionFormat(GCGLenum shaderType, GCGLenum precisionType, std::span<GCGLint, 2> range, GCGLint* precision)
{
if (!makeContextCurrent())
return;
GL_GetShaderPrecisionFormat(shaderType, precisionType, range.data(), precision);
}
void GraphicsContextGLANGLE::texImage2D(GCGLenum target, GCGLint level, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, GCGLint border, GCGLenum format, GCGLenum type, std::span<const uint8_t> pixels)
{
if (!m_isForWebGL2)
internalformat = adjustWebGL1TextureInternalFormat(internalformat, format, type);
if (!makeContextCurrent())
return;
GL_TexImage2DRobustANGLE(target, level, internalformat, width, height, border, format, type, pixels.size(), pixels.data());
invalidateKnownTextureContent(m_state.currentBoundTexture());
}
void GraphicsContextGLANGLE::texImage2D(GCGLenum target, GCGLint level, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, GCGLint border, GCGLenum format, GCGLenum type, GCGLintptr offset)
{
if (!m_isForWebGL2)
internalformat = adjustWebGL1TextureInternalFormat(internalformat, format, type);
if (!makeContextCurrent())
return;
GL_TexImage2DRobustANGLE(target, level, internalformat, width, height, border, format, type, 0, reinterpret_cast<GLvoid*>(offset));
invalidateKnownTextureContent(m_state.currentBoundTexture());
}
void GraphicsContextGLANGLE::texSubImage2D(GCGLenum target, GCGLint level, GCGLint xoff, GCGLint yoff, GCGLsizei width, GCGLsizei height, GCGLenum format, GCGLenum type, std::span<const uint8_t> pixels)
{
if (!makeContextCurrent())
return;
// FIXME: we will need to deal with PixelStore params when dealing with image buffers that differ from the subimage size.
GL_TexSubImage2DRobustANGLE(target, level, xoff, yoff, width, height, format, type, pixels.size(), pixels.data());
invalidateKnownTextureContent(m_state.currentBoundTexture());
}
void GraphicsContextGLANGLE::texSubImage2D(GCGLenum target, GCGLint level, GCGLint xoff, GCGLint yoff, GCGLsizei width, GCGLsizei height, GCGLenum format, GCGLenum type, GCGLintptr offset)
{
if (!makeContextCurrent())
return;
// FIXME: we will need to deal with PixelStore params when dealing with image buffers that differ from the subimage size.
GL_TexSubImage2DRobustANGLE(target, level, xoff, yoff, width, height, format, type, 0, reinterpret_cast<GLvoid*>(offset));
invalidateKnownTextureContent(m_state.currentBoundTexture());
}
void GraphicsContextGLANGLE::compressedTexImage2D(GCGLenum target, int level, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, int border, GCGLsizei imageSize, std::span<const uint8_t> data)
{
if (!makeContextCurrent())
return;
GL_CompressedTexImage2DRobustANGLE(target, level, internalformat, width, height, border, imageSize, data.size(), data.data());
invalidateKnownTextureContent(m_state.currentBoundTexture());
}
void GraphicsContextGLANGLE::compressedTexImage2D(GCGLenum target, int level, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, int border, GCGLsizei imageSize, GCGLintptr offset)
{
if (!makeContextCurrent())
return;
GL_CompressedTexImage2DRobustANGLE(target, level, internalformat, width, height, border, imageSize, 0, reinterpret_cast<GLvoid*>(offset));
invalidateKnownTextureContent(m_state.currentBoundTexture());
}
void GraphicsContextGLANGLE::compressedTexSubImage2D(GCGLenum target, int level, int xoffset, int yoffset, GCGLsizei width, GCGLsizei height, GCGLenum format, GCGLsizei imageSize, std::span<const uint8_t> data)
{
if (!makeContextCurrent())
return;
GL_CompressedTexSubImage2DRobustANGLE(target, level, xoffset, yoffset, width, height, format, imageSize, data.size(), data.data());
invalidateKnownTextureContent(m_state.currentBoundTexture());
}
void GraphicsContextGLANGLE::compressedTexSubImage2D(GCGLenum target, int level, int xoffset, int yoffset, GCGLsizei width, GCGLsizei height, GCGLenum format, GCGLsizei imageSize, GCGLintptr offset)
{
if (!makeContextCurrent())
return;
GL_CompressedTexSubImage2DRobustANGLE(target, level, xoffset, yoffset, width, height, format, imageSize, 0, reinterpret_cast<GLvoid*>(offset));
invalidateKnownTextureContent(m_state.currentBoundTexture());
}
void GraphicsContextGLANGLE::depthRange(GCGLclampf zNear, GCGLclampf zFar)
{
if (!makeContextCurrent())
return;
GL_DepthRangef(static_cast<float>(zNear), static_cast<float>(zFar));
}
void GraphicsContextGLANGLE::clearDepth(GCGLclampf depth)
{
if (!makeContextCurrent())
return;
GL_ClearDepthf(static_cast<float>(depth));
}
void GraphicsContextGLANGLE::readPixels(IntRect rect, GCGLenum format, GCGLenum type, std::span<uint8_t> data, GCGLint alignment, GCGLint rowLength, GCGLboolean reverseRowOrder)
{
if (!makeContextCurrent())
return;
ScopedBufferBinding scopedPixelPackBufferReset(GL_PIXEL_PACK_BUFFER, 0, m_isForWebGL2);
setPackParameters(alignment, rowLength, reverseRowOrder);
readPixelsImpl(rect, format, type, data);
}
std::optional<IntSize> GraphicsContextGLANGLE::readPixelsWithStatus(IntRect rect, GCGLenum format, GCGLenum type, GCGLboolean reverseRowOrder, std::span<uint8_t> data)
{
if (!makeContextCurrent())
return std::nullopt;
ScopedBufferBinding scopedPixelPackBufferReset(GL_PIXEL_PACK_BUFFER, 0, m_isForWebGL2);
setPackParameters(1, 0, reverseRowOrder); // Used for tight packing read only.
return readPixelsImpl(rect, format, type, data);
}
void GraphicsContextGLANGLE::readPixelsBufferObject(IntRect rect, GCGLenum format, GCGLenum type, GCGLintptr offset, GCGLint alignment, GCGLint rowLength)
{
if (!makeContextCurrent())
return;
setPackParameters(alignment, rowLength, false);
std::span<uint8_t> data(reinterpret_cast<uint8_t*>(offset), 0);
readPixelsImpl(rect, format, type, data);
}
std::optional<IntSize> GraphicsContextGLANGLE::readPixelsImpl(IntRect rect, GCGLenum format, GCGLenum type, std::span<uint8_t> data)
{
// FIXME: remove the two glFlush calls when the driver bug is fixed, i.e.,
// all previous rendering calls should be done before reading pixels.
GL_Flush();
auto attrs = contextAttributes();
GCGLenum framebufferTarget = m_isForWebGL2 ? GraphicsContextGL::READ_FRAMEBUFFER : GraphicsContextGL::FRAMEBUFFER;
if (attrs.antialias && m_state.boundReadFBO == m_multisampleFBO) {
resolveMultisamplingIfNecessary(rect);
GL_BindFramebuffer(framebufferTarget, m_fbo);
GL_Flush();
}
updateErrors();
GLsizei rows = 0;
GLsizei columns = 0;
GL_ReadnPixelsRobustANGLE(rect.x(), rect.y(), rect.width(), rect.height(), format, type, data.size(), nullptr, &rows, &columns, data.data());
if (attrs.antialias && m_state.boundReadFBO == m_multisampleFBO)
GL_BindFramebuffer(framebufferTarget, m_multisampleFBO);
if (updateErrors()) {
// ANGLE detected a failure during the ReadnPixelsRobustANGLE operation. Skip the alpha channel fixup below.
return std::nullopt;
}
#if PLATFORM(MAC) || PLATFORM(IOS_FAMILY)
if (!data.empty() && !attrs.alpha && (format == GraphicsContextGL::RGBA || format == GraphicsContextGL::BGRA) && (type == GraphicsContextGL::UNSIGNED_BYTE) && (m_state.boundReadFBO == m_fbo || (attrs.antialias && m_state.boundReadFBO == m_multisampleFBO)))
wipeAlphaChannelFromPixels(data);
#endif
return IntSize { rows, columns };
}
// The contents of GraphicsContextGLANGLECommon follow, ported to use ANGLE.
void GraphicsContextGLANGLE::validateDepthStencil(ASCIILiteral packedDepthStencilExtension)
{
auto attrs = contextAttributes();
if (attrs.stencil && attrs.depth) {
ASSERT(packedDepthStencilExtension == "GL_OES_packed_depth_stencil"_s);
String packedDepthStencilExtensionString { packedDepthStencilExtension };
if (supportsExtension(packedDepthStencilExtensionString)) {
// This extension is always enabled when supported
m_internalDepthStencilFormat = GL_DEPTH24_STENCIL8_OES;
} else {
// Combined buffer not supported, prefer depth when both requested.
// This extension is always enabled when supported
if (supportsExtension("GL_OES_depth24"_s))
m_internalDepthStencilFormat = GL_DEPTH_COMPONENT24_OES;
else
m_internalDepthStencilFormat = GL_DEPTH_COMPONENT16;
attrs.stencil = false;
setContextAttributes(attrs);
}
} else if (attrs.stencil)
m_internalDepthStencilFormat = GL_STENCIL_INDEX8;
else if (attrs.depth) {
// This extension is always enabled when supported
if (supportsExtension("GL_OES_depth24"_s))
m_internalDepthStencilFormat = GL_DEPTH_COMPONENT24_OES;
else
m_internalDepthStencilFormat = GL_DEPTH_COMPONENT16;
}
if (attrs.antialias) {
// FIXME: must adjust this when upgrading to WebGL 2.0 / OpenGL ES 3.0 support.
if (!supportsExtension("GL_ANGLE_framebuffer_multisample"_s) || !supportsExtension("GL_ANGLE_framebuffer_blit"_s) || !supportsExtension("GL_OES_rgb8_rgba8"_s)) {
attrs.antialias = false;
setContextAttributes(attrs);
} else {
ensureExtensionEnabled("GL_ANGLE_framebuffer_multisample"_s);
ensureExtensionEnabled("GL_ANGLE_framebuffer_blit"_s);
ensureExtensionEnabled("GL_OES_rgb8_rgba8"_s);
}
} else if (attrs.preserveDrawingBuffer) {
// Needed for preserveDrawingBuffer:true support without antialiasing.
ensureExtensionEnabled("GL_ANGLE_framebuffer_blit"_s);
}
}
void GraphicsContextGLANGLE::prepareTexture()
{
if (contextAttributes().antialias)
resolveMultisamplingIfNecessary();
if (m_preserveDrawingBufferTexture) {
prepareForDrawingBufferWrite();
// Blit m_preserveDrawingBufferTexture into m_texture.
ScopedGLCapability scopedScissor(GL_SCISSOR_TEST, GL_FALSE);
ScopedGLCapability scopedDither(GL_DITHER, GL_FALSE);
GL_BindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_preserveDrawingBufferFBO);
GL_BindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_fbo);
GL_BlitFramebufferANGLE(0, 0, m_currentWidth, m_currentHeight, 0, 0, m_currentWidth, m_currentHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
if (m_isForWebGL2) {
GL_BindFramebuffer(GL_DRAW_FRAMEBUFFER, m_state.boundDrawFBO);
GL_BindFramebuffer(GL_READ_FRAMEBUFFER, m_state.boundReadFBO);
} else
GL_BindFramebuffer(GL_FRAMEBUFFER, m_state.boundDrawFBO);
}
}
RefPtr<PixelBuffer> GraphicsContextGLANGLE::readRenderingResults()
{
ScopedRestoreReadFramebufferBinding fboBinding(m_isForWebGL2, m_state.boundReadFBO);
if (contextAttributes().antialias) {
resolveMultisamplingIfNecessary();
fboBinding.markBindingChanged();
}
fboBinding.bindFramebuffer(m_fbo);
return readPixelsForPaintResults();
}
void GraphicsContextGLANGLE::reshape(int width, int height)
{
if (width == m_currentWidth && height == m_currentHeight)
return;
ASSERT(width >= 0 && height >= 0);
if (width < 0 || height < 0)
return;
if (!makeContextCurrent())
return;
// FIXME: these may call makeContextCurrent again, we need to do this before changing the size.
updateErrors();
validateAttributes();
m_currentWidth = width;
m_currentHeight = height;
ScopedGLCapability scopedScissor(GL_SCISSOR_TEST, GL_FALSE);
ScopedGLCapability scopedDither(GL_DITHER, GL_FALSE);
ScopedBufferBinding scopedPixelUnpackBufferReset(GL_PIXEL_UNPACK_BUFFER, 0, m_isForWebGL2);
bool mustRestoreFBO = reshapeFBOs(IntSize(width, height));
auto attrs = contextAttributes();
// Initialize renderbuffers to 0.
std::array<GLfloat, 4> clearColor { 0, 0, 0, 0 };
GLfloat clearDepth = 0;
GLint clearStencil = 0;
std::array<GLboolean, 4> colorMask { GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE };
GLboolean depthMask = GL_TRUE;
GLuint stencilMask = 0xffffffff, stencilMaskBack = 0xffffffff;
GLbitfield clearMask = GL_COLOR_BUFFER_BIT;
GL_GetFloatv(GL_COLOR_CLEAR_VALUE, clearColor.data());
GL_ClearColor(0, 0, 0, 0);
GL_GetBooleanv(GL_COLOR_WRITEMASK, colorMask.data());
GL_ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
if (attrs.depth) {
GL_GetFloatv(GL_DEPTH_CLEAR_VALUE, &clearDepth);
GL_ClearDepthf(1.0f);
GL_GetBooleanv(GL_DEPTH_WRITEMASK, &depthMask);
GL_DepthMask(GL_TRUE);
clearMask |= GL_DEPTH_BUFFER_BIT;
}
if (attrs.stencil) {
GL_GetIntegerv(GL_STENCIL_CLEAR_VALUE, &clearStencil);
GL_ClearStencil(0);
GL_GetIntegerv(GL_STENCIL_WRITEMASK, reinterpret_cast<GLint*>(&stencilMask));
GL_GetIntegerv(GL_STENCIL_BACK_WRITEMASK, reinterpret_cast<GLint*>(&stencilMaskBack));
GL_StencilMaskSeparate(GL_FRONT, 0xffffffff);
GL_StencilMaskSeparate(GL_BACK, 0xffffffff);
clearMask |= GL_STENCIL_BUFFER_BIT;
}
GL_Clear(clearMask);
GL_ClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
GL_ColorMask(colorMask[0], colorMask[1], colorMask[2], colorMask[3]);
if (attrs.depth) {
GL_ClearDepthf(clearDepth);
GL_DepthMask(depthMask);
}
if (attrs.stencil) {
GL_ClearStencil(clearStencil);
GL_StencilMaskSeparate(GL_FRONT, stencilMask);
GL_StencilMaskSeparate(GL_BACK, stencilMaskBack);
}
if (mustRestoreFBO) {
GL_BindFramebuffer(GraphicsContextGL::FRAMEBUFFER, m_state.boundDrawFBO);
if (m_isForWebGL2 && m_state.boundDrawFBO != m_state.boundReadFBO)
GL_BindFramebuffer(GraphicsContextGL::READ_FRAMEBUFFER, m_state.boundReadFBO);
}
auto error = GL_GetError();
if (error != GL_NO_ERROR) {
RELEASE_LOG(WebGL, "Fatal: OpenGL error during GraphicsContextGL buffer initialization (%d).", error);
forceContextLost();
return;
}
GL_Flush();
}
void GraphicsContextGLANGLE::activeTexture(GCGLenum texture)
{
if (!makeContextCurrent())
return;
m_state.activeTextureUnit = texture;
GL_ActiveTexture(texture);
}
void GraphicsContextGLANGLE::attachShader(PlatformGLObject program, PlatformGLObject shader)
{
ASSERT(program);
ASSERT(shader);
if (!makeContextCurrent())
return;
GL_AttachShader(program, shader);
}
void GraphicsContextGLANGLE::bindAttribLocation(PlatformGLObject program, GCGLuint index, const String& name)
{
ASSERT(program);
if (!makeContextCurrent())
return;
GL_BindAttribLocation(program, index, name.utf8().data());
}
void GraphicsContextGLANGLE::bindBuffer(GCGLenum target, PlatformGLObject buffer)
{
if (!makeContextCurrent())
return;
GL_BindBuffer(target, buffer);
}
void GraphicsContextGLANGLE::bindFramebuffer(GCGLenum target, PlatformGLObject buffer)
{
if (!makeContextCurrent())
return;
GLuint fbo;
if (buffer)
fbo = buffer;
else
fbo = (contextAttributes().antialias ? m_multisampleFBO : m_fbo);
GL_BindFramebuffer(target, fbo);
if (target == GL_FRAMEBUFFER) {
m_state.boundReadFBO = m_state.boundDrawFBO = fbo;
} else if (target == GL_READ_FRAMEBUFFER) {
m_state.boundReadFBO = fbo;
} else if (target == GL_DRAW_FRAMEBUFFER) {
m_state.boundDrawFBO = fbo;
}
}
void GraphicsContextGLANGLE::bindRenderbuffer(GCGLenum target, PlatformGLObject renderbuffer)
{
if (!makeContextCurrent())
return;
GL_BindRenderbuffer(target, renderbuffer);
}
void GraphicsContextGLANGLE::bindTexture(GCGLenum target, PlatformGLObject texture)
{
if (!makeContextCurrent())
return;
m_state.setBoundTexture(m_state.activeTextureUnit, texture, target);
GL_BindTexture(target, texture);
}
void GraphicsContextGLANGLE::blendColor(GCGLclampf red, GCGLclampf green, GCGLclampf blue, GCGLclampf alpha)
{
if (!makeContextCurrent())
return;
GL_BlendColor(red, green, blue, alpha);
}
void GraphicsContextGLANGLE::blendEquation(GCGLenum mode)
{
if (!makeContextCurrent())
return;
GL_BlendEquation(mode);
}
void GraphicsContextGLANGLE::blendEquationSeparate(GCGLenum modeRGB, GCGLenum modeAlpha)
{
if (!makeContextCurrent())
return;
GL_BlendEquationSeparate(modeRGB, modeAlpha);
}
void GraphicsContextGLANGLE::blendFunc(GCGLenum sfactor, GCGLenum dfactor)
{
if (!makeContextCurrent())
return;
GL_BlendFunc(sfactor, dfactor);
}
void GraphicsContextGLANGLE::blendFuncSeparate(GCGLenum srcRGB, GCGLenum dstRGB, GCGLenum srcAlpha, GCGLenum dstAlpha)
{
if (!makeContextCurrent())
return;
GL_BlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
}
void GraphicsContextGLANGLE::bufferData(GCGLenum target, GCGLsizeiptr size, GCGLenum usage)
{
if (!makeContextCurrent())
return;
GL_BufferData(target, size, 0, usage);
}
void GraphicsContextGLANGLE::bufferData(GCGLenum target, std::span<const uint8_t> data, GCGLenum usage)
{
if (!makeContextCurrent())
return;
GL_BufferData(target, data.size(), data.data(), usage);
}
void GraphicsContextGLANGLE::bufferSubData(GCGLenum target, GCGLintptr offset, std::span<const uint8_t> data)
{
if (!makeContextCurrent())
return;
GL_BufferSubData(target, offset, data.size(), data.data());
}
bool GraphicsContextGLANGLE::getBufferSubDataImpl(GCGLenum target, GCGLintptr offset, std::span<uint8_t> data)
{
void* ptr = GL_MapBufferRange(target, offset, data.size(), GraphicsContextGL::MAP_READ_BIT);
if (!ptr)
return false;
WTF_ALLOW_UNSAFE_BUFFER_USAGE_BEGIN
memcpy(data.data(), ptr, data.size());
WTF_ALLOW_UNSAFE_BUFFER_USAGE_END
if (!GL_UnmapBuffer(target))
addError(GCGLErrorCode::InvalidOperation);
return true;
}
void GraphicsContextGLANGLE::getBufferSubData(GCGLenum target, GCGLintptr offset, std::span<uint8_t> data)
{
if (!makeContextCurrent())
return;
getBufferSubDataImpl(target, offset, data);
}
bool GraphicsContextGLANGLE::getBufferSubDataWithStatus(GCGLenum target, GCGLintptr offset, std::span<uint8_t> data)
{
if (!makeContextCurrent())
return false;
return getBufferSubDataImpl(target, offset, data);
}
void GraphicsContextGLANGLE::copyBufferSubData(GCGLenum readTarget, GCGLenum writeTarget, GCGLintptr readOffset, GCGLintptr writeOffset, GCGLsizeiptr size)
{
if (!makeContextCurrent())
return;
GL_CopyBufferSubData(readTarget, writeTarget, readOffset, writeOffset, size);
}
void GraphicsContextGLANGLE::getInternalformativ(GCGLenum target, GCGLenum internalformat, GCGLenum pname, std::span<GCGLint> data)
{
if (!makeContextCurrent())
return;
GL_GetInternalformativRobustANGLE(target, internalformat, pname, data.size(), nullptr, data.data());
}
void GraphicsContextGLANGLE::renderbufferStorageMultisample(GCGLenum target, GCGLsizei samples, GCGLenum internalformat, GCGLsizei width, GCGLsizei height)
{
if (!makeContextCurrent())
return;
GL_RenderbufferStorageMultisample(target, samples, internalformat, width, height);
}
void GraphicsContextGLANGLE::renderbufferStorageMultisampleANGLE(GCGLenum target, GCGLsizei samples, GCGLenum internalformat, GCGLsizei width, GCGLsizei height)
{
if (!makeContextCurrent())
return;
GL_RenderbufferStorageMultisampleANGLE(target, samples, internalformat, width, height);
}
void GraphicsContextGLANGLE::texStorage2D(GCGLenum target, GCGLsizei levels, GCGLenum internalformat, GCGLsizei width, GCGLsizei height)
{
if (!makeContextCurrent())
return;
GL_TexStorage2D(target, levels, internalformat, width, height);
invalidateKnownTextureContent(m_state.currentBoundTexture());
}
void GraphicsContextGLANGLE::texStorage3D(GCGLenum target, GCGLsizei levels, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, GCGLsizei depth)
{
if (!makeContextCurrent())
return;
GL_TexStorage3D(target, levels, internalformat, width, height, depth);
invalidateKnownTextureContent(m_state.currentBoundTexture());
}
void GraphicsContextGLANGLE::texImage3D(GCGLenum target, int level, int internalformat, GCGLsizei width, GCGLsizei height, GCGLsizei depth, int border, GCGLenum format, GCGLenum type, std::span<const uint8_t> pixels)
{
if (!makeContextCurrent())
return;
GL_TexImage3DRobustANGLE(target, level, internalformat, width, height, depth, border, format, type, pixels.size(), pixels.data());
}
void GraphicsContextGLANGLE::texImage3D(GCGLenum target, int level, int internalformat, GCGLsizei width, GCGLsizei height, GCGLsizei depth, int border, GCGLenum format, GCGLenum type, GCGLintptr offset)
{
if (!makeContextCurrent())
return;
GL_TexImage3DRobustANGLE(target, level, internalformat, width, height, depth, border, format, type, 0, reinterpret_cast<GLvoid*>(offset));
}
void GraphicsContextGLANGLE::texSubImage3D(GCGLenum target, int level, int xoffset, int yoffset, int zoffset, GCGLsizei width, GCGLsizei height, GCGLsizei depth, GCGLenum format, GCGLenum type, std::span<const uint8_t> pixels)
{
if (!makeContextCurrent())
return;
GL_TexSubImage3DRobustANGLE(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels.size(), pixels.data());
}
void GraphicsContextGLANGLE::texSubImage3D(GCGLenum target, int level, int xoffset, int yoffset, int zoffset, GCGLsizei width, GCGLsizei height, GCGLsizei depth, GCGLenum format, GCGLenum type, GCGLintptr offset)
{
if (!makeContextCurrent())
return;
GL_TexSubImage3DRobustANGLE(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, 0, reinterpret_cast<GLvoid*>(offset));
}
void GraphicsContextGLANGLE::compressedTexImage3D(GCGLenum target, int level, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, GCGLsizei depth, int border, GCGLsizei imageSize, std::span<const uint8_t> data)
{
if (!makeContextCurrent())
return;
GL_CompressedTexImage3DRobustANGLE(target, level, internalformat, width, height, depth, border, imageSize, data.size(), data.data());
}
void GraphicsContextGLANGLE::compressedTexImage3D(GCGLenum target, int level, GCGLenum internalformat, GCGLsizei width, GCGLsizei height, GCGLsizei depth, int border, GCGLsizei imageSize, GCGLintptr offset)
{
if (!makeContextCurrent())
return;
GL_CompressedTexImage3DRobustANGLE(target, level, internalformat, width, height, depth, border, imageSize, 0, reinterpret_cast<GLvoid*>(offset));
}
void GraphicsContextGLANGLE::compressedTexSubImage3D(GCGLenum target, int level, int xoffset, int yoffset, int zoffset, GCGLsizei width, GCGLsizei height, GCGLsizei depth, GCGLenum format, GCGLsizei imageSize, std::span<const uint8_t> data)
{
if (!makeContextCurrent())
return;
GL_CompressedTexSubImage3DRobustANGLE(target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, data.size(), data.data());
}
void GraphicsContextGLANGLE::compressedTexSubImage3D(GCGLenum target, int level, int xoffset, int yoffset, int zoffset, GCGLsizei width, GCGLsizei height, GCGLsizei depth, GCGLenum format, GCGLsizei imageSize, GCGLintptr offset)
{
if (!makeContextCurrent())
return;
GL_CompressedTexSubImage3DRobustANGLE(target, level, xoffset, yoffset, zoffset, width, height, depth, format, imageSize, 0, reinterpret_cast<GLvoid*>(offset));
}
Vector<GCGLint> GraphicsContextGLANGLE::getActiveUniforms(PlatformGLObject program, const Vector<GCGLuint>& uniformIndices, GCGLenum pname)
{
Vector<GCGLint> result(uniformIndices.size(), 0);
ASSERT(program);
if (!makeContextCurrent())
return result;
GL_GetActiveUniformsiv(program, uniformIndices.size(), uniformIndices.data(), pname, result.data());
return result;
}
GCGLenum GraphicsContextGLANGLE::checkFramebufferStatus(GCGLenum target)
{
if (!makeContextCurrent())
return GL_INVALID_OPERATION;
return GL_CheckFramebufferStatus(target);
}
void GraphicsContextGLANGLE::clearColor(GCGLclampf r, GCGLclampf g, GCGLclampf b, GCGLclampf a)
{
if (!makeContextCurrent())
return;
GL_ClearColor(r, g, b, a);
}
void GraphicsContextGLANGLE::clear(GCGLbitfield mask)
{
if (!makeContextCurrent())
return;
if (mask & COLOR_BUFFER_BIT)
prepareForDrawingBufferWriteIfBound();
GL_Clear(mask);
checkGPUStatus();
}
void GraphicsContextGLANGLE::clearStencil(GCGLint s)
{
if (!makeContextCurrent())
return;
GL_ClearStencil(s);
}
void GraphicsContextGLANGLE::colorMask(GCGLboolean red, GCGLboolean green, GCGLboolean blue, GCGLboolean alpha)
{
if (!makeContextCurrent())
return;
GL_ColorMask(red, green, blue, alpha);
}
void GraphicsContextGLANGLE::compileShader(PlatformGLObject shader)
{
ASSERT(shader);
if (!makeContextCurrent())
return;
#if !PLATFORM(WIN)
// We need the ANGLE_texture_rectangle extension to support IOSurface
// backbuffers, but we don't want it exposed to WebGL user shaders.
// Temporarily disable it during shader compilation.
GL_Disable(GL_TEXTURE_RECTANGLE_ANGLE);
#endif
GL_CompileShader(shader);
#if !PLATFORM(WIN)
GL_Enable(GL_TEXTURE_RECTANGLE_ANGLE);
#endif
}
void GraphicsContextGLANGLE::copyTexImage2D(GCGLenum target, GCGLint level, GCGLenum internalformat, GCGLint x, GCGLint y, GCGLsizei width, GCGLsizei height, GCGLint border)
{
if (!makeContextCurrent())
return;
auto attrs = contextAttributes();
GCGLenum framebufferTarget = m_isForWebGL2 ? GraphicsContextGL::READ_FRAMEBUFFER : GraphicsContextGL::FRAMEBUFFER;
if (attrs.antialias && m_state.boundReadFBO == m_multisampleFBO) {
resolveMultisamplingIfNecessary(IntRect(x, y, width, height));
GL_BindFramebuffer(framebufferTarget, m_fbo);
}
GL_CopyTexImage2D(target, level, internalformat, x, y, width, height, border);
if (attrs.antialias && m_state.boundReadFBO == m_multisampleFBO)
GL_BindFramebuffer(framebufferTarget, m_multisampleFBO);
}
void GraphicsContextGLANGLE::copyTexSubImage2D(GCGLenum target, GCGLint level, GCGLint xoffset, GCGLint yoffset, GCGLint x, GCGLint y, GCGLsizei width, GCGLsizei height)
{
if (!makeContextCurrent())
return;
auto attrs = contextAttributes();
GCGLenum framebufferTarget = m_isForWebGL2 ? GraphicsContextGL::READ_FRAMEBUFFER : GraphicsContextGL::FRAMEBUFFER;
if (attrs.antialias && m_state.boundReadFBO == m_multisampleFBO) {
resolveMultisamplingIfNecessary(IntRect(x, y, width, height));
GL_BindFramebuffer(framebufferTarget, m_fbo);
}
GL_CopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
if (attrs.antialias && m_state.boundReadFBO == m_multisampleFBO)
GL_BindFramebuffer(framebufferTarget, m_multisampleFBO);
}
void GraphicsContextGLANGLE::cullFace(GCGLenum mode)
{
if (!makeContextCurrent())
return;
GL_CullFace(mode);
}
void GraphicsContextGLANGLE::depthFunc(GCGLenum func)
{
if (!makeContextCurrent())
return;
GL_DepthFunc(func);
}
void GraphicsContextGLANGLE::depthMask(GCGLboolean flag)
{
if (!makeContextCurrent())
return;
GL_DepthMask(flag);
}
void GraphicsContextGLANGLE::detachShader(PlatformGLObject program, PlatformGLObject shader)
{
ASSERT(program);
ASSERT(shader);
if (!makeContextCurrent())
return;
GL_DetachShader(program, shader);
}
void GraphicsContextGLANGLE::disable(GCGLenum cap)
{
if (!makeContextCurrent())
return;
if (cap == PRIMITIVE_RESTART_FIXED_INDEX) {
if (m_isForWebGL2)
addError(GCGLErrorCode::InvalidOperation);
return;
}
GL_Disable(cap);
}
void GraphicsContextGLANGLE::disableVertexAttribArray(GCGLuint index)
{
if (!makeContextCurrent())
return;
GL_DisableVertexAttribArray(index);
}
void GraphicsContextGLANGLE::drawArrays(GCGLenum mode, GCGLint first, GCGLsizei count)
{
if (!makeContextCurrent())
return;
prepareForDrawingBufferWriteIfBound();
GL_DrawArrays(mode, first, count);
checkGPUStatus();
}
void GraphicsContextGLANGLE::drawElements(GCGLenum mode, GCGLsizei count, GCGLenum type, GCGLintptr offset)
{
if (!makeContextCurrent())
return;
prepareForDrawingBufferWriteIfBound();
GL_DrawElements(mode, count, type, reinterpret_cast<GLvoid*>(static_cast<intptr_t>(offset)));
checkGPUStatus();
}
void GraphicsContextGLANGLE::enable(GCGLenum cap)
{
if (!makeContextCurrent())
return;
if (cap == PRIMITIVE_RESTART_FIXED_INDEX) {
if (!m_isForWebGL2)
addError(GCGLErrorCode::InvalidOperation);
return;
}
GL_Enable(cap);
}
void GraphicsContextGLANGLE::enableVertexAttribArray(GCGLuint index)
{
if (!makeContextCurrent())
return;
GL_EnableVertexAttribArray(index);
}
void GraphicsContextGLANGLE::finish()
{
if (!makeContextCurrent())
return;
GL_Finish();
}
void GraphicsContextGLANGLE::flush()
{
if (!makeContextCurrent())
return;
GL_Flush();
}
void GraphicsContextGLANGLE::framebufferRenderbuffer(GCGLenum target, GCGLenum attachment, GCGLenum renderbuffertarget, PlatformGLObject buffer)
{
if (!makeContextCurrent())
return;
GL_FramebufferRenderbuffer(target, attachment, renderbuffertarget, buffer);
}
void GraphicsContextGLANGLE::framebufferTexture2D(GCGLenum target, GCGLenum attachment, GCGLenum textarget, PlatformGLObject texture, GCGLint level)
{
if (!makeContextCurrent())
return;
GL_FramebufferTexture2D(target, attachment, textarget, texture, level);
invalidateKnownTextureContent(m_state.currentBoundTexture());
}
void GraphicsContextGLANGLE::frontFace(GCGLenum mode)
{
if (!makeContextCurrent())
return;
GL_FrontFace(mode);
}
void GraphicsContextGLANGLE::generateMipmap(GCGLenum target)
{
if (!makeContextCurrent())
return;
GL_GenerateMipmap(target);
}
bool GraphicsContextGLANGLE::getActiveAttribImpl(PlatformGLObject program, GCGLuint index, GraphicsContextGLActiveInfo& info)
{
if (!program) {
addError(GCGLErrorCode::InvalidValue);
return false;
}
if (!makeContextCurrent())
return false;
GLint maxAttributeSize = 0;
GL_GetProgramiv(program, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &maxAttributeSize);
Vector<GLchar> name(maxAttributeSize); // GL_ACTIVE_ATTRIBUTE_MAX_LENGTH includes null termination.
GLsizei nameLength = 0;
GLint size = 0;
GLenum type = 0;
GL_GetActiveAttrib(program, index, maxAttributeSize, &nameLength, &size, &type, name.data());
if (!nameLength)
return false;
info.name = name.subspan(0, nameLength);
info.type = type;
info.size = size;
return true;
}
bool GraphicsContextGLANGLE::getActiveAttrib(PlatformGLObject program, GCGLuint index, GraphicsContextGLActiveInfo& info)
{
return getActiveAttribImpl(program, index, info);
}
bool GraphicsContextGLANGLE::getActiveUniformImpl(PlatformGLObject program, GCGLuint index, GraphicsContextGLActiveInfo& info)
{
if (!program) {
addError(GCGLErrorCode::InvalidValue);
return false;
}
if (!makeContextCurrent())
return false;
GLint maxUniformSize = 0;
GL_GetProgramiv(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxUniformSize);
Vector<GLchar> name(maxUniformSize); // GL_ACTIVE_UNIFORM_MAX_LENGTH includes null termination.
GLsizei nameLength = 0;
GLint size = 0;
GLenum type = 0;
GL_GetActiveUniform(program, index, maxUniformSize, &nameLength, &size, &type, name.data());
if (!nameLength)
return false;
info.name = name.subspan(0, nameLength);
info.type = type;
info.size = size;
return true;
}
bool GraphicsContextGLANGLE::getActiveUniform(PlatformGLObject program, GCGLuint index, GraphicsContextGLActiveInfo& info)
{
return getActiveUniformImpl(program, index, info);
}
void GraphicsContextGLANGLE::getAttachedShaders(PlatformGLObject program, GCGLsizei maxCount, GCGLsizei* count, PlatformGLObject* shaders)
{
if (!program) {
addError(GCGLErrorCode::InvalidValue);
return;
}
if (!makeContextCurrent())
return;
GL_GetAttachedShaders(program, maxCount, count, shaders);
}
int GraphicsContextGLANGLE::getAttribLocation(PlatformGLObject program, const String& name)
{
if (!program)
return -1;
if (!makeContextCurrent())
return -1;
return GL_GetAttribLocation(program, name.utf8().data());
}
bool GraphicsContextGLANGLE::updateErrors()
{
if (!makeContextCurrent())
return false;
bool movedAnError = false;
// Set an arbitrary limit of 100 here to avoid creating a hang if
// a problem driver has a bug that causes it to never clear the error.
// Otherwise, we would just loop until we got NO_ERROR.
for (unsigned i = 0; i < 100; ++i) {
GCGLenum error = GL_GetError();
if (error == NO_ERROR)
break;
addError(enumToErrorCode(error));
movedAnError = true;
}
return movedAnError;
}
GCGLErrorCodeSet GraphicsContextGLANGLE::getErrors()
{
if (!makeContextCurrent())
return GCGLErrorCode::InvalidOperation;
updateErrors();
return std::exchange(m_errors, { });
}
String GraphicsContextGLANGLE::getString(GCGLenum name)
{
if (!makeContextCurrent())
return String();
return String::fromLatin1(byteCast<char>(GL_GetString(name)));
}
void GraphicsContextGLANGLE::hint(GCGLenum target, GCGLenum mode)
{
if (!makeContextCurrent())
return;
GL_Hint(target, mode);
}
GCGLboolean GraphicsContextGLANGLE::isBuffer(PlatformGLObject buffer)
{
if (!buffer)
return GL_FALSE;
if (!makeContextCurrent())
return GL_FALSE;
return GL_IsBuffer(buffer);
}
GCGLboolean GraphicsContextGLANGLE::isEnabled(GCGLenum cap)
{
if (!makeContextCurrent())
return GL_FALSE;
return GL_IsEnabled(cap);
}
GCGLboolean GraphicsContextGLANGLE::isFramebuffer(PlatformGLObject framebuffer)
{
if (!framebuffer)
return GL_FALSE;
if (!makeContextCurrent())
return GL_FALSE;
return GL_IsFramebuffer(framebuffer);
}
GCGLboolean GraphicsContextGLANGLE::isProgram(PlatformGLObject program)
{
if (!program)
return GL_FALSE;
if (!makeContextCurrent())
return GL_FALSE;
return GL_IsProgram(program);
}
GCGLboolean GraphicsContextGLANGLE::isRenderbuffer(PlatformGLObject renderbuffer)
{
if (!renderbuffer)
return GL_FALSE;
if (!makeContextCurrent())
return GL_FALSE;
return GL_IsRenderbuffer(renderbuffer);
}
GCGLboolean GraphicsContextGLANGLE::isShader(PlatformGLObject shader)
{
if (!shader)
return GL_FALSE;
if (!makeContextCurrent())
return GL_FALSE;
return GL_IsShader(shader);
}
GCGLboolean GraphicsContextGLANGLE::isTexture(PlatformGLObject texture)
{
if (!texture)
return GL_FALSE;
if (!makeContextCurrent())
return GL_FALSE;
return GL_IsTexture(texture);
}
void GraphicsContextGLANGLE::lineWidth(GCGLfloat width)
{
if (!makeContextCurrent())
return;
GL_LineWidth(width);
}
void GraphicsContextGLANGLE::linkProgram(PlatformGLObject program)
{
ASSERT(program);
if (!makeContextCurrent())
return;
GL_LinkProgram(program);
}
void GraphicsContextGLANGLE::pixelStorei(GCGLenum pname, GCGLint param)
{
if (!makeContextCurrent())
return;
GL_PixelStorei(pname, param);
}
void GraphicsContextGLANGLE::polygonOffset(GCGLfloat factor, GCGLfloat units)
{
if (!makeContextCurrent())
return;
GL_PolygonOffset(factor, units);
}
void GraphicsContextGLANGLE::sampleCoverage(GCGLclampf value, GCGLboolean invert)
{
if (!makeContextCurrent())
return;
GL_SampleCoverage(value, invert);
}
void GraphicsContextGLANGLE::scissor(GCGLint x, GCGLint y, GCGLsizei width, GCGLsizei height)
{
if (!makeContextCurrent())
return;
GL_Scissor(x, y, width, height);
}
void GraphicsContextGLANGLE::shaderSource(PlatformGLObject shader, const String& string)
{
ASSERT(shader);
if (!makeContextCurrent())
return;
const CString& shaderSourceCString = string.utf8();
const char* shaderSourcePtr = shaderSourceCString.data();
int shaderSourceLength = shaderSourceCString.length();
GL_ShaderSource(shader, 1, &shaderSourcePtr, &shaderSourceLength);
}
void GraphicsContextGLANGLE::stencilFunc(GCGLenum func, GCGLint ref, GCGLuint mask)
{
if (!makeContextCurrent())
return;
GL_StencilFunc(func, ref, mask);
}
void GraphicsContextGLANGLE::stencilFuncSeparate(GCGLenum face, GCGLenum func, GCGLint ref, GCGLuint mask)
{
if (!makeContextCurrent())
return;
GL_StencilFuncSeparate(face, func, ref, mask);
}
void GraphicsContextGLANGLE::stencilMask(GCGLuint mask)
{
if (!makeContextCurrent())
return;
GL_StencilMask(mask);
}
void GraphicsContextGLANGLE::stencilMaskSeparate(GCGLenum face, GCGLuint mask)
{
if (!makeContextCurrent())
return;
GL_StencilMaskSeparate(face, mask);
}
void GraphicsContextGLANGLE::stencilOp(GCGLenum fail, GCGLenum zfail, GCGLenum zpass)
{
if (!makeContextCurrent())
return;
GL_StencilOp(fail, zfail, zpass);
}
void GraphicsContextGLANGLE::stencilOpSeparate(GCGLenum face, GCGLenum fail, GCGLenum zfail, GCGLenum zpass)
{
if (!makeContextCurrent())
return;
GL_StencilOpSeparate(face, fail, zfail, zpass);
}
void GraphicsContextGLANGLE::texParameterf(GCGLenum target, GCGLenum pname, GCGLfloat value)
{
if (!makeContextCurrent())
return;
GL_TexParameterf(target, pname, value);
}
void GraphicsContextGLANGLE::texParameteri(GCGLenum target, GCGLenum pname, GCGLint value)
{
if (!makeContextCurrent())
return;
GL_TexParameteri(target, pname, value);
}
void GraphicsContextGLANGLE::uniform1f(GCGLint location, GCGLfloat v0)
{
if (!makeContextCurrent())
return;
GL_Uniform1f(location, v0);
}
void GraphicsContextGLANGLE::uniform1fv(GCGLint location, std::span<const GCGLfloat> array)
{
if (!makeContextCurrent())
return;
GL_Uniform1fv(location, array.size(), array.data());
}
void GraphicsContextGLANGLE::uniform2f(GCGLint location, GCGLfloat v0, GCGLfloat v1)
{
if (!makeContextCurrent())
return;
GL_Uniform2f(location, v0, v1);
}
void GraphicsContextGLANGLE::uniform2fv(GCGLint location, std::span<const GCGLfloat> array)
{
ASSERT(!(array.size() % 2));
if (!makeContextCurrent())
return;
GL_Uniform2fv(location, array.size() / 2, array.data());
}
void GraphicsContextGLANGLE::uniform3f(GCGLint location, GCGLfloat v0, GCGLfloat v1, GCGLfloat v2)
{
if (!makeContextCurrent())
return;
GL_Uniform3f(location, v0, v1, v2);
}
void GraphicsContextGLANGLE::uniform3fv(GCGLint location, std::span<const GCGLfloat> array)
{
ASSERT(!(array.size() % 3));
if (!makeContextCurrent())
return;
GL_Uniform3fv(location, array.size() / 3, array.data());
}
void GraphicsContextGLANGLE::uniform4f(GCGLint location, GCGLfloat v0, GCGLfloat v1, GCGLfloat v2, GCGLfloat v3)
{
if (!makeContextCurrent())
return;
GL_Uniform4f(location, v0, v1, v2, v3);
}
void GraphicsContextGLANGLE::uniform4fv(GCGLint location, std::span<const GCGLfloat> array)
{
ASSERT(!(array.size() % 4));
if (!makeContextCurrent())
return;
GL_Uniform4fv(location, array.size() / 4, array.data());
}
void GraphicsContextGLANGLE::uniform1i(GCGLint location, GCGLint v0)
{
if (!makeContextCurrent())
return;
GL_Uniform1i(location, v0);
}
void GraphicsContextGLANGLE::uniform1iv(GCGLint location, std::span<const GCGLint> array)
{
if (!makeContextCurrent())
return;
GL_Uniform1iv(location, array.size(), array.data());
}
void GraphicsContextGLANGLE::uniform2i(GCGLint location, GCGLint v0, GCGLint v1)
{
if (!makeContextCurrent())
return;
GL_Uniform2i(location, v0, v1);
}
void GraphicsContextGLANGLE::uniform2iv(GCGLint location, std::span<const GCGLint> array)
{
ASSERT(!(array.size() % 2));
if (!makeContextCurrent())
return;
GL_Uniform2iv(location, array.size() / 2, array.data());
}
void GraphicsContextGLANGLE::uniform3i(GCGLint location, GCGLint v0, GCGLint v1, GCGLint v2)
{
if (!makeContextCurrent())
return;
GL_Uniform3i(location, v0, v1, v2);
}
void GraphicsContextGLANGLE::uniform3iv(GCGLint location, std::span<const GCGLint> array)
{
ASSERT(!(array.size() % 3));
if (!makeContextCurrent())
return;
GL_Uniform3iv(location, array.size() / 3, array.data());
}
void GraphicsContextGLANGLE::uniform4i(GCGLint location, GCGLint v0, GCGLint v1, GCGLint v2, GCGLint v3)
{
if (!makeContextCurrent())
return;
GL_Uniform4i(location, v0, v1, v2, v3);
}
void GraphicsContextGLANGLE::uniform4iv(GCGLint location, std::span<const GCGLint> array)
{
ASSERT(!(array.size() % 4));
if (!makeContextCurrent())
return;
GL_Uniform4iv(location, array.size() / 4, array.data());
}
void GraphicsContextGLANGLE::uniformMatrix2fv(GCGLint location, GCGLboolean transpose, std::span<const GCGLfloat> array)
{
if (!makeContextCurrent())
return;
GL_UniformMatrix2fv(location, array.size() / 4, transpose, array.data());
}
void GraphicsContextGLANGLE::uniformMatrix3fv(GCGLint location, GCGLboolean transpose, std::span<const GCGLfloat> array)
{
ASSERT(!(array.size() % 9));
if (!makeContextCurrent())
return;
GL_UniformMatrix3fv(location, array.size() / 9, transpose, array.data());
}
void GraphicsContextGLANGLE::uniformMatrix4fv(GCGLint location, GCGLboolean transpose, std::span<const GCGLfloat> array)
{
ASSERT(!(array.size() % 16));
if (!makeContextCurrent())
return;
GL_UniformMatrix4fv(location, array.size() / 16, transpose, array.data());
}
void GraphicsContextGLANGLE::useProgram(PlatformGLObject program)
{
if (!makeContextCurrent())
return;
GL_UseProgram(program);
}
void GraphicsContextGLANGLE::validateProgram(PlatformGLObject program)
{
ASSERT(program);
if (!makeContextCurrent())
return;
GL_ValidateProgram(program);
}
void GraphicsContextGLANGLE::vertexAttrib1f(GCGLuint index, GCGLfloat v0)
{
if (!makeContextCurrent())
return;
GL_VertexAttrib1f(index, v0);
}
void GraphicsContextGLANGLE::vertexAttrib1fv(GCGLuint index, std::span<const GCGLfloat, 1> array)
{
if (!makeContextCurrent())
return;
GL_VertexAttrib1fv(index, array.data());
}
void GraphicsContextGLANGLE::vertexAttrib2f(GCGLuint index, GCGLfloat v0, GCGLfloat v1)
{
if (!makeContextCurrent())
return;
GL_VertexAttrib2f(index, v0, v1);
}
void GraphicsContextGLANGLE::vertexAttrib2fv(GCGLuint index, std::span<const GCGLfloat, 2> array)
{
if (!makeContextCurrent())
return;
GL_VertexAttrib2fv(index, array.data());
}
void GraphicsContextGLANGLE::vertexAttrib3f(GCGLuint index, GCGLfloat v0, GCGLfloat v1, GCGLfloat v2)
{
if (!makeContextCurrent())
return;
GL_VertexAttrib3f(index, v0, v1, v2);
}
void GraphicsContextGLANGLE::vertexAttrib3fv(GCGLuint index, std::span<const GCGLfloat, 3> array)
{
if (!makeContextCurrent())
return;
GL_VertexAttrib3fv(index, array.data());
}
void GraphicsContextGLANGLE::vertexAttrib4f(GCGLuint index, GCGLfloat v0, GCGLfloat v1, GCGLfloat v2, GCGLfloat v3)
{
if (!makeContextCurrent())
return;
GL_VertexAttrib4f(index, v0, v1, v2, v3);
}
void GraphicsContextGLANGLE::vertexAttrib4fv(GCGLuint index, std::span<const GCGLfloat, 4> array)
{
if (!makeContextCurrent())
return;
GL_VertexAttrib4fv(index, array.data());
}
void GraphicsContextGLANGLE::vertexAttribPointer(GCGLuint index, GCGLint size, GCGLenum type, GCGLboolean normalized, GCGLsizei stride, GCGLintptr offset)
{
if (!makeContextCurrent())
return;
GL_VertexAttribPointer(index, size, type, normalized, stride, reinterpret_cast<GLvoid*>(static_cast<intptr_t>(offset)));
}
void GraphicsContextGLANGLE::vertexAttribIPointer(GCGLuint index, GCGLint size, GCGLenum type, GCGLsizei stride, GCGLintptr offset)
{
if (!makeContextCurrent())
return;
GL_VertexAttribIPointer(index, size, type, stride, reinterpret_cast<GLvoid*>(static_cast<intptr_t>(offset)));
}
void GraphicsContextGLANGLE::viewport(GCGLint x, GCGLint y, GCGLsizei width, GCGLsizei height)
{
if (!makeContextCurrent())
return;
GL_Viewport(x, y, width, height);
}
PlatformGLObject GraphicsContextGLANGLE::createVertexArray()
{
if (!makeContextCurrent())
return 0;
GLuint array = 0;
if (m_isForWebGL2)
GL_GenVertexArrays(1, &array);
else
GL_GenVertexArraysOES(1, &array);
return array;
}
void GraphicsContextGLANGLE::deleteVertexArray(PlatformGLObject array)
{
if (!array)
return;
if (!makeContextCurrent())
return;
if (m_isForWebGL2)
GL_DeleteVertexArrays(1, &array);
else
GL_DeleteVertexArraysOES(1, &array);
}
GCGLboolean GraphicsContextGLANGLE::isVertexArray(PlatformGLObject array)
{
if (!array)
return GL_FALSE;
if (!makeContextCurrent())
return GL_FALSE;
if (m_isForWebGL2)
return GL_IsVertexArray(array);
return GL_IsVertexArrayOES(array);
}
void GraphicsContextGLANGLE::bindVertexArray(PlatformGLObject array)
{
if (!makeContextCurrent())
return;
if (m_isForWebGL2)
GL_BindVertexArray(array);
else
GL_BindVertexArrayOES(array);
}
void GraphicsContextGLANGLE::getBooleanv(GCGLenum pname, std::span<GCGLboolean> value)
{
if (!makeContextCurrent())
return;
GL_GetBooleanvRobustANGLE(pname, value.size(), nullptr, value.data());
}
GCGLint GraphicsContextGLANGLE::getBufferParameteri(GCGLenum target, GCGLenum pname)
{
GCGLint value = 0;
if (!makeContextCurrent())
return value;
GL_GetBufferParameterivRobustANGLE(target, pname, 1, nullptr, &value);
return value;
}
void GraphicsContextGLANGLE::getFloatv(GCGLenum pname, std::span<GCGLfloat> value)
{
if (!makeContextCurrent())
return;
GL_GetFloatvRobustANGLE(pname, value.size(), nullptr, value.data());
}
GCGLint64 GraphicsContextGLANGLE::getInteger64(GCGLenum pname)
{
GCGLint64 value = 0;
if (!makeContextCurrent())
return value;
GL_GetInteger64vRobustANGLE(pname, 1, nullptr, &value);
return value;
}
GCGLint64 GraphicsContextGLANGLE::getInteger64i(GCGLenum pname, GCGLuint index)
{
GCGLint64 value = 0;
if (!makeContextCurrent())
return value;
GL_GetInteger64i_vRobustANGLE(pname, index, 1, nullptr, &value);
return value;
}
GCGLint GraphicsContextGLANGLE::getFramebufferAttachmentParameteri(GCGLenum target, GCGLenum attachment, GCGLenum pname)
{
GCGLint value = 0;
if (!makeContextCurrent())
return value;
if (attachment == DEPTH_STENCIL_ATTACHMENT)
attachment = DEPTH_ATTACHMENT; // Or STENCIL_ATTACHMENT, either works.
GL_GetFramebufferAttachmentParameterivRobustANGLE(target, attachment, pname, 1, nullptr, &value);
return value;
}
GCGLint GraphicsContextGLANGLE::getProgrami(PlatformGLObject program, GCGLenum pname)
{
GCGLint value = 0;
if (!makeContextCurrent())
return value;
GL_GetProgramivRobustANGLE(program, pname, 1, nullptr, &value);
return value;
}
String GraphicsContextGLANGLE::getProgramInfoLog(PlatformGLObject program)
{
ASSERT(program);
if (!makeContextCurrent())
return String();
GLint length = 0;
GL_GetProgramiv(program, GL_INFO_LOG_LENGTH, &length);
if (!length)
return String();
GLsizei size = 0;
Vector<GLchar> info(length);
GL_GetProgramInfoLog(program, length, &size, info.data());
return info.subspan(0, static_cast<unsigned>(size));
}
GCGLint GraphicsContextGLANGLE::getRenderbufferParameteri(GCGLenum target, GCGLenum pname)
{
GCGLint value = 0;
if (!makeContextCurrent())
return value;
GL_GetRenderbufferParameterivRobustANGLE(target, pname, 1, nullptr, &value);
return value;
}
GCGLint GraphicsContextGLANGLE::getShaderi(PlatformGLObject shader, GCGLenum pname)
{
ASSERT(shader);
GCGLint value = 0;
if (!makeContextCurrent())
return value;
GL_GetShaderivRobustANGLE(shader, pname, 1, nullptr, &value);
return value;
}
String GraphicsContextGLANGLE::getShaderInfoLog(PlatformGLObject shader)
{
ASSERT(shader);
if (!makeContextCurrent())
return String();
GLint length = 0;
GL_GetShaderiv(shader, GL_INFO_LOG_LENGTH, &length);
if (!length)
return String();
GLsizei size = 0;
Vector<GLchar> info(length);
GL_GetShaderInfoLog(shader, length, &size, info.data());
return info.subspan(0, static_cast<unsigned>(size));
}
String GraphicsContextGLANGLE::getShaderSource(PlatformGLObject)
{
return emptyString();
}
GCGLfloat GraphicsContextGLANGLE::getTexParameterf(GCGLenum target, GCGLenum pname)
{
GCGLfloat value = 0.f;
if (!makeContextCurrent())
return value;
GL_GetTexParameterfvRobustANGLE(target, pname, 1, nullptr, &value);
return value;
}
GCGLint GraphicsContextGLANGLE::getTexParameteri(GCGLenum target, GCGLenum pname)
{
GCGLint value = 0;
if (!makeContextCurrent())
return value;
GL_GetTexParameterivRobustANGLE(target, pname, 1, nullptr, &value);
return value;
}
void GraphicsContextGLANGLE::getUniformfv(PlatformGLObject program, GCGLint location, std::span<GCGLfloat> value)
{
if (!makeContextCurrent())
return;
// FIXME: Bug in ANGLE bufSize validation for uniforms. See https://bugs.webkit.org/show_bug.cgi?id=219069.
auto bufSize = value.size() * sizeof(value[0]);
GL_GetUniformfvRobustANGLE(program, location, bufSize, nullptr, value.data());
}
void GraphicsContextGLANGLE::getUniformiv(PlatformGLObject program, GCGLint location, std::span<GCGLint> value)
{
if (!makeContextCurrent())
return;
// FIXME: Bug in ANGLE bufSize validation for uniforms. See https://bugs.webkit.org/show_bug.cgi?id=219069.
auto bufSize = value.size() * sizeof(value[0]);
GL_GetUniformivRobustANGLE(program, location, bufSize, nullptr, value.data());
}
void GraphicsContextGLANGLE::getUniformuiv(PlatformGLObject program, GCGLint location, std::span<GCGLuint> value)
{
if (!makeContextCurrent())
return;
// FIXME: Bug in ANGLE bufSize validation for uniforms. See https://bugs.webkit.org/show_bug.cgi?id=219069.
auto bufSize = value.size() * sizeof(value[0]);
GL_GetUniformuivRobustANGLE(program, location, bufSize, nullptr, value.data());
}
GCGLint GraphicsContextGLANGLE::getUniformLocation(PlatformGLObject program, const String& name)
{
ASSERT(program);
if (!makeContextCurrent())
return -1;
return GL_GetUniformLocation(program, name.utf8().data());
}
GCGLsizeiptr GraphicsContextGLANGLE::getVertexAttribOffset(GCGLuint index, GCGLenum pname)
{
if (!makeContextCurrent())
return 0;
GLvoid* pointer = 0;
GL_GetVertexAttribPointervRobustANGLE(index, pname, 1, nullptr, &pointer);
return static_cast<GCGLsizeiptr>(reinterpret_cast<intptr_t>(pointer));
}
PlatformGLObject GraphicsContextGLANGLE::createBuffer()
{
if (!makeContextCurrent())
return 0;
GLuint o = 0;
GL_GenBuffers(1, &o);
return o;
}
PlatformGLObject GraphicsContextGLANGLE::createFramebuffer()
{
if (!makeContextCurrent())
return 0;
GLuint o = 0;
GL_GenFramebuffers(1, &o);
return o;
}
PlatformGLObject GraphicsContextGLANGLE::createProgram()
{
if (!makeContextCurrent())
return 0;
return GL_CreateProgram();
}
PlatformGLObject GraphicsContextGLANGLE::createRenderbuffer()
{
if (!makeContextCurrent())
return 0;
GLuint o = 0;
GL_GenRenderbuffers(1, &o);
return o;
}
PlatformGLObject GraphicsContextGLANGLE::createShader(GCGLenum type)
{
if (!makeContextCurrent())
return 0;
return GL_CreateShader((type == FRAGMENT_SHADER) ? GL_FRAGMENT_SHADER : GL_VERTEX_SHADER);
}
PlatformGLObject GraphicsContextGLANGLE::createTexture()
{
if (!makeContextCurrent())
return 0;
GLuint o = 0;
GL_GenTextures(1, &o);
invalidateKnownTextureContent(o);
return o;
}
void GraphicsContextGLANGLE::deleteBuffer(PlatformGLObject buffer)
{
if (!makeContextCurrent())
return;
GL_DeleteBuffers(1, &buffer);
}
void GraphicsContextGLANGLE::deleteFramebuffer(PlatformGLObject framebuffer)
{
if (!makeContextCurrent())
return;
// Make sure the framebuffer is not going to be used for drawing
// operations after it gets deleted.
if (m_isForWebGL2) {
if (framebuffer == m_state.boundDrawFBO)
bindFramebuffer(DRAW_FRAMEBUFFER, 0);
if (framebuffer == m_state.boundReadFBO)
bindFramebuffer(READ_FRAMEBUFFER, 0);
} else if (framebuffer == m_state.boundDrawFBO)
bindFramebuffer(FRAMEBUFFER, 0);
GL_DeleteFramebuffers(1, &framebuffer);
}
void GraphicsContextGLANGLE::deleteProgram(PlatformGLObject program)
{
if (!makeContextCurrent())
return;
GL_DeleteProgram(program);
}
void GraphicsContextGLANGLE::deleteRenderbuffer(PlatformGLObject renderbuffer)
{
if (!makeContextCurrent())
return;
GL_DeleteRenderbuffers(1, &renderbuffer);
}
void GraphicsContextGLANGLE::deleteShader(PlatformGLObject shader)
{
if (!makeContextCurrent())
return;
GL_DeleteShader(shader);
}
void GraphicsContextGLANGLE::deleteTexture(PlatformGLObject texture)
{
if (!makeContextCurrent())
return;
m_state.boundTextureMap.removeIf([texture] (auto& keyValue) {
return keyValue.value.first == texture;
});
GL_DeleteTextures(1, &texture);
invalidateKnownTextureContent(texture);
}
void GraphicsContextGLANGLE::drawArraysInstanced(GCGLenum mode, GCGLint first, GCGLsizei count, GCGLsizei primcount)
{
if (!makeContextCurrent())
return;
prepareForDrawingBufferWriteIfBound();
if (m_isForWebGL2)
GL_DrawArraysInstanced(mode, first, count, primcount);
else
GL_DrawArraysInstancedANGLE(mode, first, count, primcount);
checkGPUStatus();
}
void GraphicsContextGLANGLE::drawElementsInstanced(GCGLenum mode, GCGLsizei count, GCGLenum type, GCGLintptr offset, GCGLsizei primcount)
{
if (!makeContextCurrent())
return;
prepareForDrawingBufferWriteIfBound();
if (m_isForWebGL2)
GL_DrawElementsInstanced(mode, count, type, reinterpret_cast<void*>(offset), primcount);
else
GL_DrawElementsInstancedANGLE(mode, count, type, reinterpret_cast<void*>(offset), primcount);
checkGPUStatus();
}
void GraphicsContextGLANGLE::vertexAttribDivisor(GCGLuint index, GCGLuint divisor)
{
if (!makeContextCurrent())
return;
if (m_isForWebGL2)
GL_VertexAttribDivisor(index, divisor);
else
GL_VertexAttribDivisorANGLE(index, divisor);
}
GCGLuint GraphicsContextGLANGLE::getUniformBlockIndex(PlatformGLObject program, const String& uniformBlockName)
{
ASSERT(program);
if (!makeContextCurrent())
return GL_INVALID_INDEX;
return GL_GetUniformBlockIndex(program, uniformBlockName.utf8().data());
}
String GraphicsContextGLANGLE::getActiveUniformBlockName(PlatformGLObject program, GCGLuint uniformBlockIndex)
{
ASSERT(program);
if (!makeContextCurrent())
return String();
GLint maxLength = 0;
GL_GetProgramiv(program, GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH, &maxLength);
if (maxLength <= 0) {
addError(GCGLErrorCode::InvalidValue);
return String();
}
Vector<GLchar> buffer(maxLength);
GLsizei length = 0;
GL_GetActiveUniformBlockName(program, uniformBlockIndex, buffer.size(), &length, buffer.data());
if (!length)
return String();
return buffer.subspan(0, length);
}
void GraphicsContextGLANGLE::uniformBlockBinding(PlatformGLObject program, GCGLuint uniformBlockIndex, GCGLuint uniformBlockBinding)
{
ASSERT(program);
if (!makeContextCurrent())
return;
GL_UniformBlockBinding(program, uniformBlockIndex, uniformBlockBinding);
}
// Query Functions
PlatformGLObject GraphicsContextGLANGLE::createQuery()
{
if (!makeContextCurrent())
return 0;
GLuint name = 0;
GL_GenQueries(1, &name);
return name;
}
void GraphicsContextGLANGLE::beginQuery(GCGLenum target, PlatformGLObject query)
{
if (!makeContextCurrent())
return;
GL_BeginQuery(target, query);
}
void GraphicsContextGLANGLE::endQuery(GCGLenum target)
{
if (!makeContextCurrent())
return;
GL_EndQuery(target);
}
GCGLuint GraphicsContextGLANGLE::getQueryObjectui(GCGLuint id, GCGLenum pname)
{
GCGLuint value = 0;
if (!makeContextCurrent())
return value;
GL_GetQueryObjectuivRobustANGLE(id, pname, 1, nullptr, &value);
return value;
}
// Transform Feedback Functions
PlatformGLObject GraphicsContextGLANGLE::createTransformFeedback()
{
if (!makeContextCurrent())
return 0;
GLuint name = 0;
GL_GenTransformFeedbacks(1, &name);
return name;
}
void GraphicsContextGLANGLE::deleteTransformFeedback(PlatformGLObject transformFeedback)
{
if (!makeContextCurrent())
return;
GL_DeleteTransformFeedbacks(1, &transformFeedback);
}
GCGLboolean GraphicsContextGLANGLE::isTransformFeedback(PlatformGLObject transformFeedback)
{
if (!makeContextCurrent())
return GL_FALSE;
return GL_IsTransformFeedback(transformFeedback);
}
void GraphicsContextGLANGLE::bindTransformFeedback(GCGLenum target, PlatformGLObject transformFeedback)
{
if (!makeContextCurrent())
return;
GL_BindTransformFeedback(target, transformFeedback);
}
void GraphicsContextGLANGLE::beginTransformFeedback(GCGLenum primitiveMode)
{
if (!makeContextCurrent())
return;
GL_BeginTransformFeedback(primitiveMode);
}
void GraphicsContextGLANGLE::endTransformFeedback()
{
if (!makeContextCurrent())
return;
GL_EndTransformFeedback();
}
void GraphicsContextGLANGLE::transformFeedbackVaryings(PlatformGLObject program, const Vector<String>& varyings, GCGLenum bufferMode)
{
if (!makeContextCurrent())
return;
Vector<CString> convertedVaryings = varyings.map([](const String& varying) {
return varying.utf8();
});
Vector<const char*> pointersToVaryings = convertedVaryings.map([](const CString& varying) {
return varying.data();
});
GL_TransformFeedbackVaryings(program, pointersToVaryings.size(), pointersToVaryings.data(), bufferMode);
}
void GraphicsContextGLANGLE::getTransformFeedbackVarying(PlatformGLObject program, GCGLuint index, GraphicsContextGLActiveInfo& info)
{
if (!makeContextCurrent())
return;
GCGLsizei bufSize = 0;
GL_GetProgramiv(program, GraphicsContextGLANGLE::TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH, &bufSize);
if (!bufSize)
return;
GCGLsizei length = 0;
GCGLsizei size = 0;
GCGLenum type = 0;
Vector<GCGLchar> name(bufSize);
GL_GetTransformFeedbackVarying(program, index, bufSize, &length, &size, &type, name.data());
info.name = name.subspan(0, length);
info.size = size;
info.type = type;
}
void GraphicsContextGLANGLE::bindBufferBase(GCGLenum target, GCGLuint index, PlatformGLObject buffer)
{
if (!makeContextCurrent())
return;
GL_BindBufferBase(target, index, buffer);
}
void GraphicsContextGLANGLE::blitFramebuffer(GCGLint srcX0, GCGLint srcY0, GCGLint srcX1, GCGLint srcY1, GCGLint dstX0, GCGLint dstY0, GCGLint dstX1, GCGLint dstY1, GCGLbitfield mask, GCGLenum filter)
{
if (!makeContextCurrent())
return;
prepareForDrawingBufferWriteIfBound();
GL_BlitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
checkGPUStatus();
}
void GraphicsContextGLANGLE::framebufferTextureLayer(GCGLenum target, GCGLenum attachment, PlatformGLObject texture, GCGLint level, GCGLint layer)
{
if (!makeContextCurrent())
return;
GL_FramebufferTextureLayer(target, attachment, texture, level, layer);
}
void GraphicsContextGLANGLE::invalidateFramebuffer(GCGLenum target, std::span<const GCGLenum> attachments)
{
if (!makeContextCurrent())
return;
prepareForDrawingBufferWriteIfBound();
GL_InvalidateFramebuffer(target, attachments.size(), attachments.data());
}
void GraphicsContextGLANGLE::invalidateSubFramebuffer(GCGLenum target, std::span<const GCGLenum> attachments, GCGLint x, GCGLint y, GCGLsizei width, GCGLsizei height)
{
if (!makeContextCurrent())
return;
prepareForDrawingBufferWriteIfBound();
GL_InvalidateSubFramebuffer(target, attachments.size(), attachments.data(), x, y, width, height);
}
void GraphicsContextGLANGLE::readBuffer(GCGLenum src)
{
if (!makeContextCurrent())
return;
GL_ReadBuffer(src);
}
void GraphicsContextGLANGLE::copyTexSubImage3D(GCGLenum target, GCGLint level, GCGLint xoffset, GCGLint yoffset, GCGLint zoffset, GCGLint x, GCGLint y, GCGLsizei width, GCGLsizei height)
{
if (!makeContextCurrent())
return;
auto attrs = contextAttributes();
GCGLenum framebufferTarget = m_isForWebGL2 ? GraphicsContextGL::READ_FRAMEBUFFER : GraphicsContextGL::FRAMEBUFFER;
if (attrs.antialias && m_state.boundReadFBO == m_multisampleFBO) {
resolveMultisamplingIfNecessary(IntRect(x, y, width, height));
GL_BindFramebuffer(framebufferTarget, m_fbo);
}
GL_CopyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width, height);
if (attrs.antialias && m_state.boundReadFBO == m_multisampleFBO)
GL_BindFramebuffer(framebufferTarget, m_multisampleFBO);
}
GCGLint GraphicsContextGLANGLE::getFragDataLocation(PlatformGLObject program, const String& name)
{
if (!makeContextCurrent())
return -1;
return GL_GetFragDataLocation(program, name.utf8().data());
}
void GraphicsContextGLANGLE::uniform1ui(GCGLint location, GCGLuint v0)
{
if (!makeContextCurrent())
return;
GL_Uniform1ui(location, v0);
}
void GraphicsContextGLANGLE::uniform2ui(GCGLint location, GCGLuint v0, GCGLuint v1)
{
if (!makeContextCurrent())
return;
GL_Uniform2ui(location, v0, v1);
}
void GraphicsContextGLANGLE::uniform3ui(GCGLint location, GCGLuint v0, GCGLuint v1, GCGLuint v2)
{
if (!makeContextCurrent())
return;
GL_Uniform3ui(location, v0, v1, v2);
}
void GraphicsContextGLANGLE::uniform4ui(GCGLint location, GCGLuint v0, GCGLuint v1, GCGLuint v2, GCGLuint v3)
{
if (!makeContextCurrent())
return;
GL_Uniform4ui(location, v0, v1, v2, v3);
}
void GraphicsContextGLANGLE::uniform1uiv(GCGLint location, std::span<const GCGLuint> data)
{
if (!makeContextCurrent())
return;
GL_Uniform1uiv(location, data.size(), data.data());
}
void GraphicsContextGLANGLE::uniform2uiv(GCGLint location, std::span<const GCGLuint> data)
{
ASSERT(!(data.size() % 2));
if (!makeContextCurrent())
return;
GL_Uniform2uiv(location, data.size() / 2, data.data());
}
void GraphicsContextGLANGLE::uniform3uiv(GCGLint location, std::span<const GCGLuint> data)
{
ASSERT(!(data.size() % 3));
if (!makeContextCurrent())
return;
GL_Uniform3uiv(location, data.size() / 3, data.data());
}
void GraphicsContextGLANGLE::uniform4uiv(GCGLint location, std::span<const GCGLuint> data)
{
ASSERT(!(data.size() % 4));
if (!makeContextCurrent())
return;
GL_Uniform4uiv(location, data.size() / 4, data.data());
}
void GraphicsContextGLANGLE::uniformMatrix2x3fv(GCGLint location, GCGLboolean transpose, std::span<const GCGLfloat> data)
{
ASSERT(!(data.size() % 6));
if (!makeContextCurrent())
return;
GL_UniformMatrix2x3fv(location, data.size() / 6, transpose, data.data());
}
void GraphicsContextGLANGLE::uniformMatrix3x2fv(GCGLint location, GCGLboolean transpose, std::span<const GCGLfloat> data)
{
ASSERT(!(data.size() % 6));
if (!makeContextCurrent())
return;
GL_UniformMatrix3x2fv(location, data.size() / 6, transpose, data.data());
}
void GraphicsContextGLANGLE::uniformMatrix2x4fv(GCGLint location, GCGLboolean transpose, std::span<const GCGLfloat> data)
{
ASSERT(!(data.size() % 8));
if (!makeContextCurrent())
return;
GL_UniformMatrix2x4fv(location, data.size() / 8, transpose, data.data());
}
void GraphicsContextGLANGLE::uniformMatrix4x2fv(GCGLint location, GCGLboolean transpose, std::span<const GCGLfloat> data)
{
ASSERT(!(data.size() % 8));
if (!makeContextCurrent())
return;
GL_UniformMatrix4x2fv(location, data.size() / 8, transpose, data.data());
}
void GraphicsContextGLANGLE::uniformMatrix3x4fv(GCGLint location, GCGLboolean transpose, std::span<const GCGLfloat> data)
{
ASSERT(!(data.size() % 12));
if (!makeContextCurrent())
return;
GL_UniformMatrix3x4fv(location, data.size() / 12, transpose, data.data());
}
void GraphicsContextGLANGLE::uniformMatrix4x3fv(GCGLint location, GCGLboolean transpose, std::span<const GCGLfloat> data)
{
ASSERT(!(data.size() % 12));
if (!makeContextCurrent())
return;
GL_UniformMatrix4x3fv(location, data.size() / 12, transpose, data.data());
}
void GraphicsContextGLANGLE::vertexAttribI4i(GCGLuint index, GCGLint x, GCGLint y, GCGLint z, GCGLint w)
{
if (!makeContextCurrent())
return;
GL_VertexAttribI4i(index, x, y, z, w);
}
void GraphicsContextGLANGLE::vertexAttribI4iv(GCGLuint index, std::span<const GCGLint, 4> values)
{
if (!makeContextCurrent())
return;
GL_VertexAttribI4iv(index, values.data());
}
void GraphicsContextGLANGLE::vertexAttribI4ui(GCGLuint index, GCGLuint x, GCGLuint y, GCGLuint z, GCGLuint w)
{
if (!makeContextCurrent())
return;
GL_VertexAttribI4ui(index, x, y, z, w);
}
void GraphicsContextGLANGLE::vertexAttribI4uiv(GCGLuint index, std::span<const GCGLuint, 4> values)
{
if (!makeContextCurrent())
return;
GL_VertexAttribI4uiv(index, values.data());
}
void GraphicsContextGLANGLE::drawRangeElements(GCGLenum mode, GCGLuint start, GCGLuint end, GCGLsizei count, GCGLenum type, GCGLintptr offset)
{
if (!makeContextCurrent())
return;
prepareForDrawingBufferWriteIfBound();
GL_DrawRangeElements(mode, start, end, count, type, reinterpret_cast<void*>(offset));
checkGPUStatus();
}
void GraphicsContextGLANGLE::drawBuffers(std::span<const GCGLenum> bufs)
{
if (!makeContextCurrent())
return;
GL_DrawBuffers(bufs.size(), bufs.data());
}
void GraphicsContextGLANGLE::clearBufferiv(GCGLenum buffer, GCGLint drawbuffer, std::span<const GCGLint> values)
{
if (!makeContextCurrent())
return;
if (!validateClearBufferv(buffer, values.size()))
return;
prepareForDrawingBufferWriteIfBound();
GL_ClearBufferiv(buffer, drawbuffer, values.data());
checkGPUStatus();
}
void GraphicsContextGLANGLE::clearBufferuiv(GCGLenum buffer, GCGLint drawbuffer, std::span<const GCGLuint> values)
{
if (!makeContextCurrent())
return;
if (!validateClearBufferv(buffer, values.size()))
return;
prepareForDrawingBufferWriteIfBound();
GL_ClearBufferuiv(buffer, drawbuffer, values.data());
checkGPUStatus();
}
void GraphicsContextGLANGLE::clearBufferfv(GCGLenum buffer, GCGLint drawbuffer, std::span<const GCGLfloat> values)
{
if (!makeContextCurrent())
return;
if (!validateClearBufferv(buffer, values.size()))
return;
prepareForDrawingBufferWriteIfBound();
GL_ClearBufferfv(buffer, drawbuffer, values.data());
checkGPUStatus();
}
void GraphicsContextGLANGLE::clearBufferfi(GCGLenum buffer, GCGLint drawbuffer, GCGLfloat depth, GCGLint stencil)
{
if (!makeContextCurrent())
return;
GL_ClearBufferfi(buffer, drawbuffer, depth, stencil);
checkGPUStatus();
}
void GraphicsContextGLANGLE::deleteQuery(PlatformGLObject query)
{
if (!makeContextCurrent())
return;
GL_DeleteQueries(1, &query);
}
GCGLboolean GraphicsContextGLANGLE::isQuery(PlatformGLObject query)
{
if (!makeContextCurrent())
return GL_FALSE;
return GL_IsQuery(query);
}
GCGLint GraphicsContextGLANGLE::getQuery(GCGLenum target, GCGLenum pname)
{
if (!makeContextCurrent())
return 0;
GLint value = 0;
GL_GetQueryiv(target, pname, &value);
return value;
}
PlatformGLObject GraphicsContextGLANGLE::createSampler()
{
if (!makeContextCurrent())
return 0;
GLuint name = 0;
GL_GenSamplers(1, &name);
return name;
}
void GraphicsContextGLANGLE::deleteSampler(PlatformGLObject sampler)
{
if (!makeContextCurrent())
return;
GL_DeleteSamplers(1, &sampler);
}
GCGLboolean GraphicsContextGLANGLE::isSampler(PlatformGLObject sampler)
{
if (!makeContextCurrent())
return GL_FALSE;
return GL_IsSampler(sampler);
}
void GraphicsContextGLANGLE::bindSampler(GCGLuint unit, PlatformGLObject sampler)
{
if (!makeContextCurrent())
return;
GL_BindSampler(unit, sampler);
}
void GraphicsContextGLANGLE::samplerParameteri(PlatformGLObject sampler, GCGLenum pname, GCGLint param)
{
if (!makeContextCurrent())
return;
GL_SamplerParameteri(sampler, pname, param);
}
void GraphicsContextGLANGLE::samplerParameterf(PlatformGLObject sampler, GCGLenum pname, GCGLfloat param)
{
if (!makeContextCurrent())
return;
GL_SamplerParameterf(sampler, pname, param);
}
GCGLfloat GraphicsContextGLANGLE::getSamplerParameterf(PlatformGLObject sampler, GCGLenum pname)
{
GCGLfloat value = 0.f;
if (!makeContextCurrent())
return value;
GL_GetSamplerParameterfvRobustANGLE(sampler, pname, 1, nullptr, &value);
return value;
}
GCGLint GraphicsContextGLANGLE::getSamplerParameteri(PlatformGLObject sampler, GCGLenum pname)
{
GCGLint value = 0;
if (!makeContextCurrent())
return value;
GL_GetSamplerParameterivRobustANGLE(sampler, pname, 1, nullptr, &value);
return value;
}
GCGLsync GraphicsContextGLANGLE::fenceSync(GCGLenum condition, GCGLbitfield flags)
{
if (!makeContextCurrent())
return 0;
return GL_FenceSync(condition, flags);
}
GCGLboolean GraphicsContextGLANGLE::isSync(GCGLsync sync)
{
if (!makeContextCurrent())
return GL_FALSE;
return GL_IsSync(static_cast<GLsync>(sync));
}
void GraphicsContextGLANGLE::deleteSync(GCGLsync sync)
{
if (!makeContextCurrent())
return;
GL_DeleteSync(static_cast<GLsync>(sync));
}
GCGLenum GraphicsContextGLANGLE::clientWaitSync(GCGLsync sync, GCGLbitfield flags, GCGLuint64 timeout)
{
if (!makeContextCurrent())
return GL_WAIT_FAILED;
return GL_ClientWaitSync(static_cast<GLsync>(sync), flags, timeout);
}
void GraphicsContextGLANGLE::waitSync(GCGLsync sync, GCGLbitfield flags, GCGLint64 timeout)
{
if (!makeContextCurrent())
return;
GL_WaitSync(static_cast<GLsync>(sync), flags, timeout);
}
GCGLint GraphicsContextGLANGLE::getSynci(GCGLsync sync, GCGLenum pname)
{
GCGLint value = 0;
if (!makeContextCurrent())
return value;
GL_GetSynciv(static_cast<GLsync>(sync), pname, 1, nullptr, &value);
return value;
}
void GraphicsContextGLANGLE::pauseTransformFeedback()
{
if (!makeContextCurrent())
return;
GL_PauseTransformFeedback();
}
void GraphicsContextGLANGLE::resumeTransformFeedback()
{
if (!makeContextCurrent())
return;
GL_ResumeTransformFeedback();
}
void GraphicsContextGLANGLE::bindBufferRange(GCGLenum target, GCGLuint index, PlatformGLObject buffer, GCGLintptr offset, GCGLsizeiptr size)
{
if (!makeContextCurrent())
return;
GL_BindBufferRange(target, index, buffer, offset, size);
}
Vector<GCGLuint> GraphicsContextGLANGLE::getUniformIndices(PlatformGLObject program, const Vector<String>& uniformNames)
{
ASSERT(program);
if (!makeContextCurrent())
return { };
Vector<CString> utf8 = uniformNames.map([](auto& x) { return x.utf8(); });
Vector<const char*> cstr = utf8.map([](auto& x) { return x.data(); });
Vector<GCGLuint> result(cstr.size(), 0);
GL_GetUniformIndices(program, cstr.size(), cstr.data(), result.data());
return result;
}
void GraphicsContextGLANGLE::getActiveUniformBlockiv(PlatformGLObject program, GCGLuint uniformBlockIndex, GCGLenum pname, std::span<GCGLint> params)
{
if (!makeContextCurrent())
return;
GL_GetActiveUniformBlockivRobustANGLE(program, uniformBlockIndex, pname, params.size(), nullptr, params.data());
}
#if ENABLE(WEBXR)
GCGLExternalImage GraphicsContextGLANGLE::createExternalImage(ExternalImageSource&&, GCGLenum, GCGLint)
{
notImplemented();
return { };
}
void GraphicsContextGLANGLE::bindExternalImage(GCGLenum, GCGLExternalImage)
{
notImplemented();
}
void GraphicsContextGLANGLE::deleteExternalImage(GCGLExternalImage image)
{
if (UNLIKELY(!image))
return;
auto eglImage = m_eglImages.take(image);
if (UNLIKELY(!eglImage)) {
addError(GCGLErrorCode::InvalidOperation);
return;
}
bool result = EGL_DestroyImageKHR(platformDisplay(), eglImage);
ASSERT(result);
if (UNLIKELY(!result))
addError(GCGLErrorCode::InvalidOperation);
}
GCGLExternalSync GraphicsContextGLANGLE::createExternalSync(ExternalSyncSource&&)
{
notImplemented();
return { };
}
#endif
void GraphicsContextGLANGLE::deleteExternalSync(GCGLExternalSync sync)
{
if (UNLIKELY(!sync))
return;
EGLSync eglSync = m_eglSyncs.take(sync);
if (UNLIKELY(!eglSync)) {
addError(GCGLErrorCode::InvalidOperation);
return;
}
bool result = EGL_DestroySync(platformDisplay(), eglSync);
ASSERT(result);
if (UNLIKELY(!result))
addError(GCGLErrorCode::InvalidOperation);
}
void GraphicsContextGLANGLE::multiDrawArraysANGLE(GCGLenum mode, GCGLSpanTuple<const GCGLint, const GCGLsizei> firstsAndCounts)
{
if (!makeContextCurrent())
return;
prepareForDrawingBufferWriteIfBound();
GL_MultiDrawArraysANGLE(mode, firstsAndCounts.data<0>(), firstsAndCounts.data<1>(), firstsAndCounts.bufSize);
checkGPUStatus();
}
void GraphicsContextGLANGLE::multiDrawArraysInstancedANGLE(GCGLenum mode, GCGLSpanTuple<const GCGLint, const GCGLsizei, const GCGLsizei> firstsCountsAndInstanceCounts)
{
if (!makeContextCurrent())
return;
prepareForDrawingBufferWriteIfBound();
GL_MultiDrawArraysInstancedANGLE(mode, firstsCountsAndInstanceCounts.data<0>(), firstsCountsAndInstanceCounts.data<1>(), firstsCountsAndInstanceCounts.data<2>(), firstsCountsAndInstanceCounts.bufSize);
checkGPUStatus();
}
void GraphicsContextGLANGLE::multiDrawElementsANGLE(GCGLenum mode, GCGLSpanTuple<const GCGLsizei, const GCGLsizei> countsAndOffsets, GCGLenum type)
{
if (!makeContextCurrent())
return;
prepareForDrawingBufferWriteIfBound();
GL_MultiDrawElementsANGLE(mode, countsAndOffsets.data<0>(), type, asPointers(countsAndOffsets.span<1>()).data(), countsAndOffsets.bufSize);
checkGPUStatus();
}
void GraphicsContextGLANGLE::multiDrawElementsInstancedANGLE(GCGLenum mode, GCGLSpanTuple<const GCGLsizei, const GCGLsizei, const GCGLsizei> countsOffsetsAndInstanceCounts, GCGLenum type)
{
if (!makeContextCurrent())
return;
prepareForDrawingBufferWriteIfBound();
GL_MultiDrawElementsInstancedANGLE(mode, countsOffsetsAndInstanceCounts.data<0>(), type, asPointers(countsOffsetsAndInstanceCounts.span<1>()).data(), countsOffsetsAndInstanceCounts.data<2>(), countsOffsetsAndInstanceCounts.bufSize);
checkGPUStatus();
}
bool GraphicsContextGLANGLE::supportsExtension(const String& name)
{
return m_availableExtensions.contains(name) || m_requestableExtensions.contains(name);
}
void GraphicsContextGLANGLE::ensureExtensionEnabled(const String& name)
{
// Enable support in ANGLE (if not enabled already).
if (m_requestableExtensions.contains(name) && !m_enabledExtensions.contains(name)) {
if (!makeContextCurrent())
return;
requestExtension(name);
}
}
bool GraphicsContextGLANGLE::isExtensionEnabled(const String& name)
{
return m_availableExtensions.contains(name) || m_enabledExtensions.contains(name);
}
String GraphicsContextGLANGLE::getTranslatedShaderSourceANGLE(PlatformGLObject shader)
{
if (!makeContextCurrent())
return String();
int sourceLength = getShaderi(shader, GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE);
if (!sourceLength)
return emptyString();
Vector<GLchar> name(sourceLength); // GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE includes null termination.
GCGLint returnedLength = 0;
GL_GetTranslatedShaderSourceANGLE(shader, sourceLength, &returnedLength, name.data());
if (!returnedLength)
return emptyString();
// returnedLength does not include the null terminator.
ASSERT(returnedLength == sourceLength - 1);
return name.subspan(0, returnedLength);
}
void GraphicsContextGLANGLE::drawBuffersEXT(std::span<const GCGLenum> bufs)
{
if (!makeContextCurrent())
return;
GL_DrawBuffersEXT(bufs.size(), bufs.data());
}
PlatformGLObject GraphicsContextGLANGLE::createQueryEXT()
{
if (!makeContextCurrent())
return 0;
GLuint name = 0;
GL_GenQueriesEXT(1, &name);
return name;
}
void GraphicsContextGLANGLE::deleteQueryEXT(PlatformGLObject query)
{
if (!makeContextCurrent())
return;
GL_DeleteQueriesEXT(1, &query);
}
GCGLboolean GraphicsContextGLANGLE::isQueryEXT(PlatformGLObject query)
{
if (!makeContextCurrent())
return GL_FALSE;
return GL_IsQueryEXT(query);
}
void GraphicsContextGLANGLE::beginQueryEXT(GCGLenum target, PlatformGLObject query)
{
if (!makeContextCurrent())
return;
GL_BeginQueryEXT(target, query);
}
void GraphicsContextGLANGLE::endQueryEXT(GCGLenum target)
{
if (!makeContextCurrent())
return;
GL_EndQueryEXT(target);
}
void GraphicsContextGLANGLE::queryCounterEXT(PlatformGLObject query, GCGLenum target)
{
if (!makeContextCurrent())
return;
GL_QueryCounterEXT(query, target);
}
GCGLint GraphicsContextGLANGLE::getQueryiEXT(GCGLenum target, GCGLenum pname)
{
if (!makeContextCurrent())
return 0;
GLint value = 0;
GL_GetQueryivRobustANGLE(target, pname, 1, nullptr, &value);
return value;
}
GCGLint GraphicsContextGLANGLE::getQueryObjectiEXT(PlatformGLObject query, GCGLenum pname)
{
if (!makeContextCurrent())
return 0;
GLint value = 0;
GL_GetQueryObjectivRobustANGLE(query, pname, 1, nullptr, &value);
return value;
}
GCGLuint64 GraphicsContextGLANGLE::getQueryObjectui64EXT(PlatformGLObject query, GCGLenum pname)
{
if (!makeContextCurrent())
return 0;
GLuint64 value = 0;
GL_GetQueryObjectui64vRobustANGLE(query, pname, 1, nullptr, &value);
return value;
}
GCGLint64 GraphicsContextGLANGLE::getInteger64EXT(GCGLenum pname)
{
if (!makeContextCurrent())
return 0;
GCGLint64 value = 0;
GL_GetInteger64vRobustANGLE(pname, 1, nullptr, &value);
return value;
}
void GraphicsContextGLANGLE::enableiOES(GCGLenum target, GCGLuint index)
{
if (!makeContextCurrent())
return;
GL_EnableiOES(target, index);
}
void GraphicsContextGLANGLE::disableiOES(GCGLenum target, GCGLuint index)
{
if (!makeContextCurrent())
return;
GL_DisableiOES(target, index);
}
void GraphicsContextGLANGLE::blendEquationiOES(GCGLuint buf, GCGLenum mode)
{
if (!makeContextCurrent())
return;
GL_BlendEquationiOES(buf, mode);
}
void GraphicsContextGLANGLE::blendEquationSeparateiOES(GCGLuint buf, GCGLenum modeRGB, GCGLenum modeAlpha)
{
if (!makeContextCurrent())
return;
GL_BlendEquationSeparateiOES(buf, modeRGB, modeAlpha);
}
void GraphicsContextGLANGLE::blendFunciOES(GCGLuint buf, GCGLenum src, GCGLenum dst)
{
if (!makeContextCurrent())
return;
GL_BlendFunciOES(buf, src, dst);
}
void GraphicsContextGLANGLE::blendFuncSeparateiOES(GCGLuint buf, GCGLenum srcRGB, GCGLenum dstRGB, GCGLenum srcAlpha, GCGLenum dstAlpha)
{
if (!makeContextCurrent())
return;
GL_BlendFuncSeparateiOES(buf, srcRGB, dstRGB, srcAlpha, dstAlpha);
}
void GraphicsContextGLANGLE::colorMaskiOES(GCGLuint buf, GCGLboolean red, GCGLboolean green, GCGLboolean blue, GCGLboolean alpha)
{
if (!makeContextCurrent())
return;
GL_ColorMaskiOES(buf, red, green, blue, alpha);
}
void GraphicsContextGLANGLE::drawArraysInstancedBaseInstanceANGLE(GCGLenum mode, GCGLint first, GCGLsizei count, GCGLsizei instanceCount, GCGLuint baseInstance)
{
if (!makeContextCurrent())
return;
prepareForDrawingBufferWriteIfBound();
GL_DrawArraysInstancedBaseInstanceANGLE(mode, first, count, instanceCount, baseInstance);
checkGPUStatus();
}
void GraphicsContextGLANGLE::drawElementsInstancedBaseVertexBaseInstanceANGLE(GCGLenum mode, GCGLsizei count, GCGLenum type, GCGLintptr offset, GCGLsizei instanceCount, GCGLint baseVertex, GCGLuint baseInstance)
{
if (!makeContextCurrent())
return;
prepareForDrawingBufferWriteIfBound();
GL_DrawElementsInstancedBaseVertexBaseInstanceANGLE(mode, count, type, reinterpret_cast<void*>(offset), instanceCount, baseVertex, baseInstance);
checkGPUStatus();
}
void GraphicsContextGLANGLE::multiDrawArraysInstancedBaseInstanceANGLE(GCGLenum mode, GCGLSpanTuple<const GCGLint, const GCGLsizei, const GCGLsizei, const GCGLuint> firstsCountsInstanceCountsAndBaseInstances)
{
if (!makeContextCurrent())
return;
prepareForDrawingBufferWriteIfBound();
GL_MultiDrawArraysInstancedBaseInstanceANGLE(mode, firstsCountsInstanceCountsAndBaseInstances.data<0>(), firstsCountsInstanceCountsAndBaseInstances.data<1>(), firstsCountsInstanceCountsAndBaseInstances.data<2>(), firstsCountsInstanceCountsAndBaseInstances.data<3>(), firstsCountsInstanceCountsAndBaseInstances.bufSize);
checkGPUStatus();
}
void GraphicsContextGLANGLE::multiDrawElementsInstancedBaseVertexBaseInstanceANGLE(GCGLenum mode, GCGLSpanTuple<const GCGLsizei, const GCGLsizei, const GCGLsizei, const GCGLint, const GCGLuint> countsOffsetsInstanceCountsBaseVerticesAndBaseInstances, GCGLenum type)
{
if (!makeContextCurrent())
return;
prepareForDrawingBufferWriteIfBound();
GL_MultiDrawElementsInstancedBaseVertexBaseInstanceANGLE(mode, countsOffsetsInstanceCountsBaseVerticesAndBaseInstances.data<0>(), type, asPointers(countsOffsetsInstanceCountsBaseVerticesAndBaseInstances.span<1>()).data(), countsOffsetsInstanceCountsBaseVerticesAndBaseInstances.data<2>(), countsOffsetsInstanceCountsBaseVerticesAndBaseInstances.data<3>(), countsOffsetsInstanceCountsBaseVerticesAndBaseInstances.data<4>(), countsOffsetsInstanceCountsBaseVerticesAndBaseInstances.bufSize);
checkGPUStatus();
}
void GraphicsContextGLANGLE::clipControlEXT(GCGLenum origin, GCGLenum depth)
{
if (!makeContextCurrent())
return;
GL_ClipControlEXT(origin, depth);
}
void GraphicsContextGLANGLE::provokingVertexANGLE(GCGLenum provokeMode)
{
if (!makeContextCurrent())
return;
GL_ProvokingVertexANGLE(provokeMode);
}
void GraphicsContextGLANGLE::polygonModeANGLE(GCGLenum face, GCGLenum mode)
{
if (!makeContextCurrent())
return;
GL_PolygonModeANGLE(face, mode);
}
void GraphicsContextGLANGLE::polygonOffsetClampEXT(GCGLfloat factor, GCGLfloat units, GCGLfloat clamp)
{
if (!makeContextCurrent())
return;
GL_PolygonOffsetClampEXT(factor, units, clamp);
}
void GraphicsContextGLANGLE::simulateEventForTesting(SimulatedEventForTesting event)
{
if (event == SimulatedEventForTesting::GPUStatusFailure || event == SimulatedEventForTesting::DisplayBufferAllocationFailure) {
m_failNextStatusCheck = true;
return;
}
}
void GraphicsContextGLANGLE::drawSurfaceBufferToImageBuffer(SurfaceBuffer buffer, ImageBuffer& imageBuffer)
{
if (RefPtr image = bufferAsNativeImage(buffer))
paintToCanvas(*image, imageBuffer.backendSize(), imageBuffer.context());
}
RefPtr<NativeImage> GraphicsContextGLANGLE::bufferAsNativeImage(SurfaceBuffer source)
{
if (!makeContextCurrent())
return nullptr;
if (getInternalFramebufferSize().isEmpty())
return nullptr;
RefPtr<PixelBuffer> pixelBuffer;
if (source == SurfaceBuffer::DrawingBuffer)
pixelBuffer = readRenderingResults();
else
pixelBuffer = readCompositedResults();
if (!pixelBuffer)
return nullptr;
return createNativeImageFromPixelBuffer(contextAttributes(), pixelBuffer.releaseNonNull());
}
RefPtr<PixelBuffer> GraphicsContextGLANGLE::drawingBufferToPixelBuffer(FlipY flipY)
{
// Reading premultiplied alpha would involve unpremultiplying, which is lossy.
if (contextAttributes().premultipliedAlpha)
return nullptr;
auto results = readRenderingResultsForPainting();
if (flipY == FlipY::Yes && results && !results->size().isEmpty()) {
ASSERT(results->format().pixelFormat == PixelFormat::RGBA8 || results->format().pixelFormat == PixelFormat::BGRA8);
// FIXME: Make PixelBufferConversions support negative rowBytes and in-place conversions.
size_t rowStride = results->size().width() * 4;
auto rowBuffer = MallocSpan<uint8_t>::malloc(rowStride);
for (auto bytes = results->bytes(); bytes.size() >= rowStride * 2; bytes = bytes.subspan(rowStride, bytes.size() - 2 * rowStride)) {
auto top = bytes.first(rowStride);
auto bottom = bytes.last(rowStride);
memcpySpan(rowBuffer.mutableSpan(), bottom);
memcpySpan(bottom, top);
memcpySpan(top, rowBuffer.span());
}
}
return results;
}
RefPtr<PixelBuffer> GraphicsContextGLANGLE::readRenderingResultsForPainting()
{
if (!makeContextCurrent())
return nullptr;
if (getInternalFramebufferSize().isEmpty())
return nullptr;
return readRenderingResults();
}
void GraphicsContextGLANGLE::addError(GCGLErrorCode errorCode)
{
m_errors.add(errorCode);
}
void GraphicsContextGLANGLE::invalidateKnownTextureContent(GCGLuint)
{
}
GCGLenum GraphicsContextGLANGLE::adjustWebGL1TextureInternalFormat(GCGLenum internalformat, GCGLenum format, GCGLenum type)
{
// The implementation of WEBGL_color_buffer_float for WebGL 1.0 / ES 2.0 requires a sized
// internal format. Adjust it if necessary at this lowest level.
if (type == GL_FLOAT) {
if (m_webglColorBufferFloatRGBA && format == GL_RGBA && internalformat == GL_RGBA)
return GL_RGBA32F;
if (m_webglColorBufferFloatRGB && format == GL_RGB && internalformat == GL_RGB)
return GL_RGB32F;
}
return internalformat;
}
void GraphicsContextGLANGLE::setPackParameters(GCGLint alignment, GCGLint rowLength, GCGLboolean reverseRowOrder)
{
if (m_packAlignment != alignment) {
GL_PixelStorei(GL_PACK_ALIGNMENT, alignment);
m_packAlignment = alignment;
}
if (m_packRowLength != rowLength) {
GL_PixelStorei(GL_PACK_ROW_LENGTH, rowLength);
m_packRowLength = rowLength;
}
if (m_packReverseRowOrder != reverseRowOrder) {
GL_PixelStorei(GL_PACK_REVERSE_ROW_ORDER_ANGLE, reverseRowOrder);
m_packReverseRowOrder = reverseRowOrder;
}
}
bool GraphicsContextGLANGLE::enableExtension(const String& name)
{
if (m_availableExtensions.contains(name) || m_enabledExtensions.contains(name))
return true;
if (!m_requestableExtensions.contains(name))
return false;
requestExtension(name);
return true;
}
void GraphicsContextGLANGLE::requestExtension(const String& name)
{
GL_RequestExtensionANGLE(name.ascii().data());
m_enabledExtensions.add(name);
if (name == "GL_CHROMIUM_color_buffer_float_rgba"_s)
m_webglColorBufferFloatRGBA = true;
else if (name == "GL_CHROMIUM_color_buffer_float_rgb"_s)
m_webglColorBufferFloatRGB = true;
}
bool GraphicsContextGLANGLE::validateClearBufferv(GCGLenum buffer, size_t valuesSize)
{
// ClearBuffersfv, iv, uiv are missing ANGLE Robust* entry-point. Make the call act similar way as other
// calls that validate buffer sizes by validating it here.
switch (buffer) {
case GraphicsContextGL::COLOR:
if (valuesSize == 4)
return true;
break;
case GraphicsContextGL::DEPTH:
case GraphicsContextGL::STENCIL:
if (valuesSize == 1)
return true;
break;
default:
break;
}
addError(GCGLErrorCode::InvalidOperation);
return false;
}
void GraphicsContextGLANGLE::prepareForDrawingBufferWriteIfBound()
{
if (m_state.boundDrawFBO != m_fbo)
return;
prepareForDrawingBufferWrite();
}
void GraphicsContextGLANGLE::prepareForDrawingBufferWrite()
{
}
}
#endif // ENABLE(WEBGL)
|