Wayland support Based on the original port to Wayland by: Joel Teichroeb, Benjamin Franzke, Scott Moreau, et al. Additional changes in this commit, done by me: * Wayland uses the common EGL framework * EGL can now create a desktop OpenGL context * testgl2 loads GL functions dynamically, no need to link to libGL anymore * Assorted fixes to the Wayland backend Tested on the Weston Compositor (v1.0.5) that ships with Ubuntu 13.10, running Weston under X. Tests ran: testrendercopyex (all backends), testgl2, testgles2,testintersections
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
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7455ab8..fb90299 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -218,6 +218,7 @@ set_option(RPATH "Use an rpath when linking SDL" ${UNIX_SYS})
set_option(CLOCK_GETTIME "Use clock_gettime() instead of gettimeofday()" OFF)
set_option(INPUT_TSLIB "Use the Touchscreen library for input" ${UNIX_SYS})
set_option(VIDEO_X11 "Use X11 video driver" ${UNIX_SYS})
+set_option(VIDEO_WAYLAND "Use Wayland video driver" ${UNIX_SYS})
dep_option(X11_SHARED "Dynamically load X11 support" ON "VIDEO_X11" OFF)
set(SDL_X11_OPTIONS Xcursor Xinerama XInput Xrandr Xscrnsaver XShape Xvm)
foreach(_SUB ${SDL_X11_OPTIONS})
@@ -641,6 +642,7 @@ if(UNIX AND NOT APPLE)
CheckDirectFB()
CheckOpenGLX11()
CheckOpenGLESX11()
+ CheckWayland()
endif(SDL_VIDEO)
if(LINUX)
diff --git a/WhatsNew.txt b/WhatsNew.txt
index e7cec5b..db2ad8f 100644
--- a/WhatsNew.txt
+++ b/WhatsNew.txt
@@ -7,7 +7,10 @@ This is a list of major changes in SDL's version history.
General:
* Added an API to load a database of Game Controller mappings from a file:
SDL_GameControllerAddMappingsFromFile
-
+* EGL can now create/manage OpenGL and OpenGL ES 1.x/2.x contexts, and share
+ them using SDL_GL_SHARE_WITH_CURRENT_CONTEXT
+* Added testgles2. testgl2 does not need to link with libGL anymore.
+
Windows:
* Support for OpenGL ES 2.x contexts using either WGL or EGL (natively via
the driver or emulated through ANGLE)
@@ -20,7 +23,7 @@ Android:
Linux:
* Fixed fullscreen and focused behavior when receiving NotifyGrab events
-
+* Wayland support
---------------------------------------------------------------------------
2.0.1:
diff --git a/cmake/sdlchecks.cmake b/cmake/sdlchecks.cmake
index 86366e4..c2286b8 100644
--- a/cmake/sdlchecks.cmake
+++ b/cmake/sdlchecks.cmake
@@ -506,6 +506,29 @@ macro(CheckX11)
endmacro(CheckX11)
# Requires:
+# - EGL
+macro(CheckWayland)
+ if(VIDEO_WAYLAND)
+ pkg_check_modules(WAYLAND wayland-client wayland-cursor wayland-egl egl xkbcommon)
+ if(WAYLAND_FOUND)
+ link_directories(
+ ${WAYLAND_LIBRARY_DIRS}
+ )
+ include_directories(
+ ${WAYLAND_INCLUDE_DIRS}
+ )
+ set(EXTRA_LIBS ${WAYLAND_LIBRARIES} ${EXTRA_LIBS})
+ set(HAVE_VIDEO_WAYLAND TRUE)
+ set(HAVE_SDL_VIDEO TRUE)
+
+ file(GLOB WAYLAND_SOURCES ${SDL2_SOURCE_DIR}/src/video/wayland/*.c)
+ set(SOURCE_FILES ${SOURCE_FILES} ${WAYLAND_SOURCES})
+ set(SDL_VIDEO_DRIVER_WAYLAND 1)
+ endif(WAYLAND_FOUND)
+ endif(VIDEO_WAYLAND)
+endmacro(CheckWayland)
+
+# Requires:
# - n/a
#
macro(CheckCOCOA)
diff --git a/configure b/configure
index bd2c5d2..0cc698a 100755
--- a/configure
+++ b/configure
@@ -817,6 +817,7 @@ enable_sndio
enable_sndio_shared
enable_diskaudio
enable_dummyaudio
+enable_video_wayland
enable_video_x11
with_x
enable_x11_shared
@@ -1532,6 +1533,7 @@ Optional Features:
--enable-sndio-shared dynamically load sndio audio support [[default=yes]]
--enable-diskaudio support the disk writer audio driver [[default=yes]]
--enable-dummyaudio support the dummy audio driver [[default=yes]]
+ --enable-video-wayland use Wayland video driver [[default=yes]]
--enable-video-x11 use X11 video driver [[default=yes]]
--enable-x11-shared dynamically load X11 support [[default=maybe]]
--enable-video-x11-xcursor
@@ -18633,6 +18635,82 @@ $as_echo "$need_gcc_Wno_multichar" >&6; }
fi
}
+CheckWayland()
+{
+ # Check whether --enable-video-wayland was given.
+if test "${enable_video_wayland+set}" = set; then :
+ enableval=$enable_video_wayland;
+else
+ enable_video_wayland=yes
+fi
+
+
+ if test x$enable_video = xyes -a x$enable_video_wayland = xyes; then
+ # Extract the first word of "pkg-config", so it can be a program name with args.
+set dummy pkg-config; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_PKG_CONFIG+:} false; then :
+ $as_echo_n "(cached) " >&6
+else
+ case $PKG_CONFIG in
+ [\\/]* | ?:[\\/]*)
+ ac_cv_path_PKG_CONFIG="$PKG_CONFIG" # Let the user override the test with a path.
+ ;;
+ *)
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
+ $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+ done
+IFS=$as_save_IFS
+
+ test -z "$ac_cv_path_PKG_CONFIG" && ac_cv_path_PKG_CONFIG="no"
+ ;;
+esac
+fi
+PKG_CONFIG=$ac_cv_path_PKG_CONFIG
+if test -n "$PKG_CONFIG"; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PKG_CONFIG" >&5
+$as_echo "$PKG_CONFIG" >&6; }
+else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Wayland support" >&5
+$as_echo_n "checking for Wayland support... " >&6; }
+ video_wayland=no
+ if test x$PKG_CONFIG != xno; then
+ if $PKG_CONFIG --exists wayland-client wayland-egl wayland-cursor egl xkbcommon ; then
+ WAYLAND_CFLAGS=`$PKG_CONFIG --cflags wayland-client wayland-egl wayland-cursor egl xkbcommon`
+ WAYLAND_LIBS=`$PKG_CONFIG --libs wayland-client wayland-egl wayland-cursor egl xkbcommon`
+ video_wayland=yes
+ fi
+ fi
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $video_wayland" >&5
+$as_echo "$video_wayland" >&6; }
+
+ if test x$video_wayland = xyes; then
+
+$as_echo "#define SDL_VIDEO_DRIVER_WAYLAND 1" >>confdefs.h
+
+ SOURCES="$SOURCES $srcdir/src/video/wayland/*.c"
+ EXTRA_CFLAGS="$EXTRA_CFLAGS $WAYLAND_CFLAGS"
+ EXTRA_LDFLAGS="$EXTRA_LDFLAGS $WAYLAND_LIBS"
+ have_video=yes
+ fi
+ fi
+}
CheckX11()
{
@@ -22220,6 +22298,7 @@ case "$host" in
CheckNAS
CheckSNDIO
CheckX11
+ CheckWayland
CheckDirectFB
CheckFusionSound
CheckOpenGLX11
diff --git a/configure.in b/configure.in
index 7c3a1b1..941a255 100644
--- a/configure.in
+++ b/configure.in
@@ -1115,6 +1115,36 @@ CheckWarnAll()
fi
}
+dnl Check for Wayland
+CheckWayland()
+{
+ AC_ARG_ENABLE(video-wayland,
+AC_HELP_STRING([--enable-video-wayland], [use Wayland video driver [[default=yes]]]),
+ ,enable_video_wayland=yes)
+
+ if test x$enable_video = xyes -a x$enable_video_wayland = xyes; then
+ AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
+ AC_MSG_CHECKING(for Wayland support)
+ video_wayland=no
+ if test x$PKG_CONFIG != xno; then
+ if $PKG_CONFIG --exists wayland-client wayland-egl wayland-cursor egl xkbcommon ; then
+ WAYLAND_CFLAGS=`$PKG_CONFIG --cflags wayland-client wayland-egl wayland-cursor egl xkbcommon`
+ WAYLAND_LIBS=`$PKG_CONFIG --libs wayland-client wayland-egl wayland-cursor egl xkbcommon`
+ video_wayland=yes
+ fi
+ fi
+ AC_MSG_RESULT($video_wayland)
+
+ if test x$video_wayland = xyes; then
+ AC_DEFINE(SDL_VIDEO_DRIVER_WAYLAND, 1, [ ])
+ SOURCES="$SOURCES $srcdir/src/video/wayland/*.c"
+ EXTRA_CFLAGS="$EXTRA_CFLAGS $WAYLAND_CFLAGS"
+ dnl FIXME do dynamic loading code here.
+ EXTRA_LDFLAGS="$EXTRA_LDFLAGS $WAYLAND_LIBS"
+ have_video=yes
+ fi
+ fi
+}
dnl Find the X11 include and library directories
CheckX11()
@@ -2449,6 +2479,7 @@ case "$host" in
CheckNAS
CheckSNDIO
CheckX11
+ CheckWayland
CheckDirectFB
CheckFusionSound
CheckOpenGLX11
diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake
index 08237a8..66a530b 100644
--- a/include/SDL_config.h.cmake
+++ b/include/SDL_config.h.cmake
@@ -259,6 +259,7 @@
#cmakedefine SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC @SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC@
#cmakedefine SDL_VIDEO_DRIVER_DUMMY @SDL_VIDEO_DRIVER_DUMMY@
#cmakedefine SDL_VIDEO_DRIVER_WINDOWS @SDL_VIDEO_DRIVER_WINDOWS@
+#cmakedefine SDL_VIDEO_DRIVER_WAYLAND @SDL_VIDEO_DRIVER_WAYLAND@
#cmakedefine SDL_VIDEO_DRIVER_X11 @SDL_VIDEO_DRIVER_X11@
#cmakedefine SDL_VIDEO_DRIVER_X11_DYNAMIC @SDL_VIDEO_DRIVER_X11_DYNAMIC@
#cmakedefine SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT @SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT@
diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in
index 536b297..14ce791 100644
--- a/include/SDL_config.h.in
+++ b/include/SDL_config.h.in
@@ -260,6 +260,7 @@
#undef SDL_VIDEO_DRIVER_DIRECTFB_DYNAMIC
#undef SDL_VIDEO_DRIVER_DUMMY
#undef SDL_VIDEO_DRIVER_WINDOWS
+#undef SDL_VIDEO_DRIVER_WAYLAND
#undef SDL_VIDEO_DRIVER_X11
#undef SDL_VIDEO_DRIVER_RPI
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC
diff --git a/include/SDL_syswm.h b/include/SDL_syswm.h
index 5e4454f..c43a78d 100644
--- a/include/SDL_syswm.h
+++ b/include/SDL_syswm.h
@@ -101,6 +101,7 @@ typedef enum
SDL_SYSWM_UNKNOWN,
SDL_SYSWM_WINDOWS,
SDL_SYSWM_X11,
+ SDL_SYSWM_WAYLAND,
SDL_SYSWM_DIRECTFB,
SDL_SYSWM_COCOA,
SDL_SYSWM_UIKIT,
@@ -175,6 +176,14 @@ struct SDL_SysWMinfo
Window window; /**< The X11 window */
} x11;
#endif
+#if defined(SDL_VIDEO_DRIVER_WAYLAND)
+ struct
+ {
+ struct wl_display *display; /**< Wayland display */
+ struct wl_surface *surface; /**< Wayland surface */
+ struct wl_shell_surface *shell_surface; /**< Wayland shell_surface (window manager handle) */
+ } wl;
+#endif
#if defined(SDL_VIDEO_DRIVER_DIRECTFB)
struct
{
diff --git a/src/render/opengl/SDL_glfuncs.h b/src/render/opengl/SDL_glfuncs.h
index 7544929..c7e577b 100644
--- a/src/render/opengl/SDL_glfuncs.h
+++ b/src/render/opengl/SDL_glfuncs.h
@@ -30,7 +30,7 @@ SDL_PROC_UNUSED(void, glColor3bv, (const GLbyte *))
SDL_PROC_UNUSED(void, glColor3d, (GLdouble, GLdouble, GLdouble))
SDL_PROC_UNUSED(void, glColor3dv, (const GLdouble *))
SDL_PROC_UNUSED(void, glColor3f, (GLfloat, GLfloat, GLfloat))
-SDL_PROC_UNUSED(void, glColor3fv, (const GLfloat *))
+SDL_PROC(void, glColor3fv, (const GLfloat *))
SDL_PROC_UNUSED(void, glColor3i, (GLint, GLint, GLint))
SDL_PROC_UNUSED(void, glColor3iv, (const GLint *))
SDL_PROC_UNUSED(void, glColor3s, (GLshort, GLshort, GLshort))
@@ -85,7 +85,7 @@ SDL_PROC_UNUSED(void, glCopyTexSubImage2D,
SDL_PROC_UNUSED(void, glCullFace, (GLenum mode))
SDL_PROC_UNUSED(void, glDeleteLists, (GLuint list, GLsizei range))
SDL_PROC(void, glDeleteTextures, (GLsizei n, const GLuint * textures))
-SDL_PROC_UNUSED(void, glDepthFunc, (GLenum func))
+SDL_PROC(void, glDepthFunc, (GLenum func))
SDL_PROC_UNUSED(void, glDepthMask, (GLboolean flag))
SDL_PROC_UNUSED(void, glDepthRange, (GLclampd zNear, GLclampd zFar))
SDL_PROC(void, glDisable, (GLenum cap))
@@ -334,13 +334,13 @@ SDL_PROC_UNUSED(void, glRectsv, (const GLshort * v1, const GLshort * v2))
SDL_PROC_UNUSED(GLint, glRenderMode, (GLenum mode))
SDL_PROC(void, glRotated,
(GLdouble angle, GLdouble x, GLdouble y, GLdouble z))
-SDL_PROC_UNUSED(void, glRotatef,
+SDL_PROC(void, glRotatef,
(GLfloat angle, GLfloat x, GLfloat y, GLfloat z))
SDL_PROC_UNUSED(void, glScaled, (GLdouble x, GLdouble y, GLdouble z))
SDL_PROC_UNUSED(void, glScalef, (GLfloat x, GLfloat y, GLfloat z))
SDL_PROC(void, glScissor, (GLint x, GLint y, GLsizei width, GLsizei height))
SDL_PROC_UNUSED(void, glSelectBuffer, (GLsizei size, GLuint * buffer))
-SDL_PROC_UNUSED(void, glShadeModel, (GLenum mode))
+SDL_PROC(void, glShadeModel, (GLenum mode))
SDL_PROC_UNUSED(void, glStencilFunc, (GLenum func, GLint ref, GLuint mask))
SDL_PROC_UNUSED(void, glStencilMask, (GLuint mask))
SDL_PROC_UNUSED(void, glStencilOp, (GLenum fail, GLenum zfail, GLenum zpass))
@@ -432,7 +432,7 @@ SDL_PROC_UNUSED(void, glVertex2sv, (const GLshort * v))
SDL_PROC_UNUSED(void, glVertex3d, (GLdouble x, GLdouble y, GLdouble z))
SDL_PROC_UNUSED(void, glVertex3dv, (const GLdouble * v))
SDL_PROC_UNUSED(void, glVertex3f, (GLfloat x, GLfloat y, GLfloat z))
-SDL_PROC_UNUSED(void, glVertex3fv, (const GLfloat * v))
+SDL_PROC(void, glVertex3fv, (const GLfloat * v))
SDL_PROC_UNUSED(void, glVertex3i, (GLint x, GLint y, GLint z))
SDL_PROC_UNUSED(void, glVertex3iv, (const GLint * v))
SDL_PROC_UNUSED(void, glVertex3s, (GLshort x, GLshort y, GLshort z))
diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c
index c081a5d..3ef24b0 100644
--- a/src/video/SDL_egl.c
+++ b/src/video/SDL_egl.c
@@ -50,6 +50,7 @@
#else
/* Desktop Linux */
+#define DEFAULT_OGL "libGL.so.1"
#define DEFAULT_EGL "libEGL.so.1"
#define DEFAULT_OGL_ES2 "libGLESv2.so.2"
#define DEFAULT_OGL_ES_PVR "libGLES_CM.so.1"
@@ -149,23 +150,31 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
}
if (egl_dll_handle == NULL) {
- if (_this->gl_config.major_version > 1) {
- path = DEFAULT_OGL_ES2;
- egl_dll_handle = SDL_LoadObject(path);
+ if(_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
+ if (_this->gl_config.major_version > 1) {
+ path = DEFAULT_OGL_ES2;
+ egl_dll_handle = SDL_LoadObject(path);
+ }
+ else {
+ path = DEFAULT_OGL_ES;
+ egl_dll_handle = SDL_LoadObject(path);
+ if (egl_dll_handle == NULL) {
+ path = DEFAULT_OGL_ES_PVR;
+ egl_dll_handle = SDL_LoadObject(path);
+ }
+ }
}
+#ifdef DEFAULT_OGL
else {
- path = DEFAULT_OGL_ES;
+ path = DEFAULT_OGL;
egl_dll_handle = SDL_LoadObject(path);
- if (egl_dll_handle == NULL) {
- path = DEFAULT_OGL_ES_PVR;
- egl_dll_handle = SDL_LoadObject(path);
- }
}
+#endif
}
_this->egl_data->egl_dll_handle = egl_dll_handle;
if (egl_dll_handle == NULL) {
- return SDL_SetError("Could not initialize OpenGL ES library");
+ return SDL_SetError("Could not initialize OpenGL / GLES library");
}
/* Loading libGL* in the previous step took care of loading libEGL.so, but we future proof by double checking */
@@ -205,6 +214,7 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
LOAD_FUNC(eglSwapInterval);
LOAD_FUNC(eglWaitNative);
LOAD_FUNC(eglWaitGL);
+ LOAD_FUNC(eglBindAPI);
_this->egl_data->egl_display = _this->egl_data->eglGetDisplay(native_display);
if (!_this->egl_data->egl_display) {
@@ -281,14 +291,21 @@ SDL_EGL_ChooseConfig(_THIS)
}
attribs[i++] = EGL_RENDERABLE_TYPE;
- if (_this->gl_config.major_version == 2) {
- attribs[i++] = EGL_OPENGL_ES2_BIT;
- } else {
- attribs[i++] = EGL_OPENGL_ES_BIT;
+ if(_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
+ if (_this->gl_config.major_version == 2) {
+ attribs[i++] = EGL_OPENGL_ES2_BIT;
+ } else {
+ attribs[i++] = EGL_OPENGL_ES_BIT;
+ }
+ _this->egl_data->eglBindAPI(EGL_OPENGL_ES_API);
+ }
+ else {
+ attribs[i++] = EGL_OPENGL_BIT;
+ _this->egl_data->eglBindAPI(EGL_OPENGL_API);
}
attribs[i++] = EGL_NONE;
-
+
if (_this->egl_data->eglChooseConfig(_this->egl_data->egl_display,
attribs,
configs, SDL_arraysize(configs),
@@ -347,18 +364,27 @@ SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface)
return NULL;
}
- if (_this->gl_config.major_version) {
- context_attrib_list[1] = _this->gl_config.major_version;
- }
-
if (_this->gl_config.share_with_current_context) {
share_context = (EGLContext)SDL_GL_GetCurrentContext();
}
+
+ /* Bind the API */
+ if(_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
+ _this->egl_data->eglBindAPI(EGL_OPENGL_ES_API);
+ if (_this->gl_config.major_version) {
+ context_attrib_list[1] = _this->gl_config.major_version;
+ }
- egl_context =
- _this->egl_data->eglCreateContext(_this->egl_data->egl_display,
- _this->egl_data->egl_config,
- share_context, context_attrib_list);
+ egl_context = _this->egl_data->eglCreateContext(_this->egl_data->egl_display,
+ _this->egl_data->egl_config,
+ share_context, context_attrib_list);
+ }
+ else {
+ _this->egl_data->eglBindAPI(EGL_OPENGL_API);
+ egl_context = _this->egl_data->eglCreateContext(_this->egl_data->egl_display,
+ _this->egl_data->egl_config,
+ share_context, NULL);
+ }
if (egl_context == EGL_NO_CONTEXT) {
SDL_SetError("Could not create EGL context");
diff --git a/src/video/SDL_egl_c.h b/src/video/SDL_egl_c.h
index 3f0cd06..30d2b2d 100644
--- a/src/video/SDL_egl_c.h
+++ b/src/video/SDL_egl_c.h
@@ -76,6 +76,9 @@ typedef struct SDL_EGL_VideoData
EGLBoolean(EGLAPIENTRY *eglWaitNative) (EGLint engine);
EGLBoolean(EGLAPIENTRY *eglWaitGL)(void);
+
+ EGLBoolean(EGLAPIENTRY *eglBindAPI)(EGLenum);
+
} SDL_EGL_VideoData;
/* OpenGLES functions */
diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h
index 18cf5f3..49f8363 100644
--- a/src/video/SDL_sysvideo.h
+++ b/src/video/SDL_sysvideo.h
@@ -369,6 +369,9 @@ extern VideoBootStrap RPI_bootstrap;
#if SDL_VIDEO_DRIVER_DUMMY
extern VideoBootStrap DUMMY_bootstrap;
#endif
+#if SDL_VIDEO_DRIVER_WAYLAND
+extern VideoBootStrap Wayland_bootstrap;
+#endif
extern SDL_VideoDevice *SDL_GetVideoDevice(void);
extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 7741729..5aacac8 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -86,6 +86,9 @@ static VideoBootStrap *bootstrap[] = {
#if SDL_VIDEO_DRIVER_DUMMY
&DUMMY_bootstrap,
#endif
+#if SDL_VIDEO_DRIVER_WAYLAND
+ &Wayland_bootstrap,
+#endif
NULL
};
diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c
new file mode 100644
index 0000000..b002a05
--- /dev/null
+++ b/src/video/wayland/SDL_waylandevents.c
@@ -0,0 +1,381 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "SDL_config.h"
+
+#include "SDL_stdinc.h"
+#include "SDL_assert.h"
+
+#include "../../events/SDL_sysevents.h"
+#include "../../events/SDL_events_c.h"
+#include "../../events/scancodes_xfree86.h"
+
+#include "SDL_waylandvideo.h"
+#include "SDL_waylandevents_c.h"
+#include "SDL_waylandwindow.h"
+
+#include <linux/input.h>
+#include <sys/select.h>
+#include <sys/mman.h>
+#include <poll.h>
+#include <errno.h>
+#include <unistd.h>
+#include <xkbcommon/xkbcommon.h>
+
+struct SDL_WaylandInput {
+ SDL_VideoData *display;
+ struct wl_seat *seat;
+ struct wl_pointer *pointer;
+ struct wl_keyboard *keyboard;
+ SDL_WindowData *pointer_focus;
+ SDL_WindowData *keyboard_focus;
+
+ struct {
+ struct xkb_keymap *keymap;
+ struct xkb_state *state;
+ } xkb;
+};
+
+void
+Wayland_PumpEvents(_THIS)
+{
+ SDL_VideoData *d = _this->driverdata;
+ struct pollfd pfd[1];
+
+ pfd[0].fd = wl_display_get_fd(d->display);
+ pfd[0].events = POLLIN;
+ poll(pfd, 1, 0);
+
+ if (pfd[0].revents & POLLIN)
+ wl_display_dispatch(d->display);
+ else
+ wl_display_dispatch_pending(d->display);
+}
+
+static void
+pointer_handle_enter(void *data, struct wl_pointer *pointer,
+ uint32_t serial, struct wl_surface *surface,
+ wl_fixed_t sx_w, wl_fixed_t sy_w)
+{
+ struct SDL_WaylandInput *input = data;
+ SDL_WindowData *window;
+
+ if (!surface) {
+ /* enter event for a window we've just destroyed */
+ return;
+ }
+
+ input->pointer_focus = wl_surface_get_user_data(surface);
+ window = input->pointer_focus;
+ SDL_SetMouseFocus(window->sdlwindow);
+}
+
+static void
+pointer_handle_leave(void *data, struct wl_pointer *pointer,
+ uint32_t serial, struct wl_surface *surface)
+{
+ struct SDL_WaylandInput *input = data;
+
+ SDL_SetMouseFocus(NULL);
+ input->pointer_focus = NULL;
+}
+
+static void
+pointer_handle_motion(void *data, struct wl_pointer *pointer,
+ uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w)
+{
+ struct SDL_WaylandInput *input = data;
+ SDL_WindowData *window = input->pointer_focus;
+ int sx = wl_fixed_to_int(sx_w);
+ int sy = wl_fixed_to_int(sy_w);
+
+ SDL_SendMouseMotion(window->sdlwindow, 0, 0, sx, sy);
+}
+
+static void
+pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial,
+ uint32_t time, uint32_t button, uint32_t state_w)
+{
+ struct SDL_WaylandInput *input = data;
+ SDL_WindowData *window = input->pointer_focus;
+ enum wl_pointer_button_state state = state_w;
+ uint32_t sdl_button;
+
+ switch (button) {
+ case BTN_LEFT:
+ sdl_button = SDL_BUTTON_LEFT;
+ break;
+ case BTN_MIDDLE:
+ sdl_button = SDL_BUTTON_MIDDLE;
+ break;
+ case BTN_RIGHT:
+ sdl_button = SDL_BUTTON_RIGHT;
+ break;
+ case BTN_SIDE:
+ sdl_button = SDL_BUTTON_X1;
+ break;
+ case BTN_EXTRA:
+ sdl_button = SDL_BUTTON_X2;
+ break;
+ default:
+ return;
+ }
+
+ SDL_SendMouseButton(window->sdlwindow, 0,
+ state ? SDL_PRESSED : SDL_RELEASED, sdl_button);
+}
+
+static void
+pointer_handle_axis(void *data, struct wl_pointer *pointer,
+ uint32_t time, uint32_t axis, wl_fixed_t value)
+{
+ struct SDL_WaylandInput *input = data;
+ SDL_WindowData *window = input->pointer_focus;
+ enum wl_pointer_axis a = axis;
+ int x, y;
+
+ switch (a) {
+ case WL_POINTER_AXIS_VERTICAL_SCROLL:
+ x = 0;
+ y = wl_fixed_to_int(value);
+ break;
+ case WL_POINTER_AXIS_HORIZONTAL_SCROLL:
+ x = wl_fixed_to_int(value);
+ y = 0;
+ break;
+ default:
+ return;
+ }
+
+ SDL_SendMouseWheel(window->sdlwindow, 0, x, y);
+}
+
+static const struct wl_pointer_listener pointer_listener = {
+ pointer_handle_enter,
+ pointer_handle_leave,
+ pointer_handle_motion,
+ pointer_handle_button,
+ pointer_handle_axis,
+};
+
+static void
+keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
+ uint32_t format, int fd, uint32_t size)
+{
+ struct SDL_WaylandInput *input = data;
+ char *map_str;
+
+ if (!data) {
+ close(fd);
+ return;
+ }
+
+ if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
+ close(fd);
+ return;
+ }
+
+ map_str = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
+ if (map_str == MAP_FAILED) {
+ close(fd);
+ return;
+ }
+
+ input->xkb.keymap = xkb_map_new_from_string(input->display->xkb_context,
+ map_str,
+ XKB_KEYMAP_FORMAT_TEXT_V1,
+ 0);
+ munmap(map_str, size);
+ close(fd);
+
+ if (!input->xkb.keymap) {
+ fprintf(stderr, "failed to compile keymap\n");
+ return;
+ }
+
+ input->xkb.state = xkb_state_new(input->xkb.keymap);
+ if (!input->xkb.state) {
+ fprintf(stderr, "failed to create XKB state\n");
+ xkb_map_unref(input->xkb.keymap);
+ input->xkb.keymap = NULL;
+ return;
+ }
+}
+
+static void
+keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
+ uint32_t serial, struct wl_surface *surface,
+ struct wl_array *keys)
+{
+ struct SDL_WaylandInput *input = data;
+ SDL_WindowData *window = wl_surface_get_user_data(surface);
+
+ input->keyboard_focus = window;
+ window->keyboard_device = input;
+ SDL_SetKeyboardFocus(window->sdlwindow);
+}
+
+static void
+keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
+ uint32_t serial, struct wl_surface *surface)
+{
+ SDL_SetKeyboardFocus(NULL);
+}
+
+static void
+keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
+ uint32_t serial, uint32_t time, uint32_t key,
+ uint32_t state_w)
+{
+ struct SDL_WaylandInput *input = data;
+ SDL_WindowData *window = input->keyboard_focus;
+ enum wl_keyboard_key_state state = state_w;
+ const xkb_keysym_t *syms;
+ uint32_t scancode;
+ char text[8];
+ int size;
+
+ if (key < SDL_arraysize(xfree86_scancode_table2)) {
+ scancode = xfree86_scancode_table2[key];
+
+ // TODO when do we get WL_KEYBOARD_KEY_STATE_REPEAT?
+ if (scancode != SDL_SCANCODE_UNKNOWN)
+ SDL_SendKeyboardKey(state == WL_KEYBOARD_KEY_STATE_PRESSED ?
+ SDL_PRESSED : SDL_RELEASED, scancode);
+ }
+
+ if (!window || window->keyboard_device != input || !input->xkb.state)
+ return;
+
+ // TODO can this happen?
+ if (xkb_key_get_syms(input->xkb.state, key + 8, &syms) != 1)
+ return;
+
+ if (state) {
+ size = xkb_keysym_to_utf8(syms[0], text, sizeof text);
+
+ if (size > 0) {
+ text[size] = 0;
+ SDL_SendKeyboardText(text);
+ }
+ }
+}
+
+static void
+keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard,
+ uint32_t serial, uint32_t mods_depressed,
+ uint32_t mods_latched, uint32_t mods_locked,
+ uint32_t group)
+{
+ struct SDL_WaylandInput *input = data;
+
+ xkb_state_update_mask(input->xkb.state, mods_depressed, mods_latched,
+ mods_locked, 0, 0, group);
+}
+
+static const struct wl_keyboard_listener keyboard_listener = {
+ keyboard_handle_keymap,
+ keyboard_handle_enter,
+ keyboard_handle_leave,
+ keyboard_handle_key,
+ keyboard_handle_modifiers,
+};
+
+static void
+seat_handle_capabilities(void *data, struct wl_seat *seat,
+ enum wl_seat_capability caps)
+{
+ struct SDL_WaylandInput *input = data;
+
+ if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->pointer) {
+ input->pointer = wl_seat_get_pointer(seat);
+ input->display->pointer = input->pointer;
+ wl_pointer_set_user_data(input->pointer, input);
+ wl_pointer_add_listener(input->pointer, &pointer_listener,
+ input);
+ } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->pointer) {
+ wl_pointer_destroy(input->pointer);
+ input->pointer = NULL;
+ }
+
+ if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !input->keyboard) {
+ input->keyboard = wl_seat_get_keyboard(seat);
+ wl_keyboard_set_user_data(input->keyboard, input);
+ wl_keyboard_add_listener(input->keyboard, &keyboard_listener,
+ input);
+ } else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && input->keyboard) {
+ wl_keyboard_destroy(input->keyboard);
+ input->keyboard = NULL;
+ }
+}
+
+static const struct wl_seat_listener seat_listener = {
+ seat_handle_capabilities,
+};
+
+void
+Wayland_display_add_input(SDL_VideoData *d, uint32_t id)
+{
+ struct SDL_WaylandInput *input;
+
+ input = malloc(sizeof *input);
+ if (input == NULL)
+ return;
+
+ memset(input, 0, sizeof *input);
+ input->display = d;
+ input->seat = wl_registry_bind(d->registry, id, &wl_seat_interface, 1);
+
+ d->input = input;
+
+ wl_seat_add_listener(input->seat, &seat_listener, input);
+ wl_seat_set_user_data(input->seat, input);
+
+ wayland_schedule_write(d);
+}
+
+void Wayland_display_destroy_input(SDL_VideoData *d)
+{
+ struct SDL_WaylandInput *input = d->input;
+
+ if (!input)
+ return;
+
+ if (input->keyboard)
+ wl_keyboard_destroy(input->keyboard);
+
+ if (input->pointer)
+ wl_pointer_destroy(input->pointer);
+
+ if (input->seat)
+ wl_seat_destroy(input->seat);
+
+ if (input->xkb.state)
+ xkb_state_unref(input->xkb.state);
+
+ if (input->xkb.keymap)
+ xkb_map_unref(input->xkb.keymap);
+
+ free(input);
+ d->input = NULL;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/wayland/SDL_waylandevents_c.h b/src/video/wayland/SDL_waylandevents_c.h
new file mode 100644
index 0000000..ed5ff7c
--- /dev/null
+++ b/src/video/wayland/SDL_waylandevents_c.h
@@ -0,0 +1,37 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "SDL_config.h"
+
+#ifndef _SDL_waylandevents_h
+#define _SDL_waylandevents_h
+
+#include "SDL_waylandvideo.h"
+#include "SDL_waylandwindow.h"
+
+extern void Wayland_PumpEvents(_THIS);
+
+extern void Wayland_display_add_input(SDL_VideoData *d, uint32_t id);
+extern void Wayland_display_destroy_input(SDL_VideoData *d);
+
+#endif /* _SDL_waylandevents_h */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/wayland/SDL_waylandmouse.c b/src/video/wayland/SDL_waylandmouse.c
new file mode 100644
index 0000000..62c65e9
--- /dev/null
+++ b/src/video/wayland/SDL_waylandmouse.c
@@ -0,0 +1,407 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include "../SDL_sysvideo.h"
+
+#include "SDL_config.h"
+#include "SDL_mouse.h"
+#include "../../events/SDL_mouse_c.h"
+#include "SDL_waylandvideo.h"
+#include "SDL_waylandevents_c.h"
+
+#include "SDL_assert.h"
+
+#if SDL_VIDEO_DRIVER_WAYLAND
+
+typedef struct {
+ struct wl_buffer *buffer;
+ struct wl_surface *surface;
+
+ int hot_x, hot_y;
+
+ /* Either a preloaded cursor, or one we created ourselves */
+ struct wl_cursor *cursor;
+ void *shm_data;
+} Wayland_CursorData;
+
+static int
+wayland_create_tmp_file(off_t size)
+{
+ static const char template[] = "/sdl-shared-XXXXXX";
+ char *xdg_path;
+ char tmp_path[PATH_MAX];
+ int fd;
+
+ xdg_path = SDL_getenv("XDG_RUNTIME_DIR");
+ if (!xdg_path) {
+ errno = ENOENT;
+ return -1;
+ }
+
+ SDL_strlcpy(tmp_path, xdg_path, PATH_MAX);
+ SDL_strlcat(tmp_path, template, PATH_MAX);
+
+ fd = mkostemp(tmp_path, O_CLOEXEC);
+ if (fd < 0)
+ return -1;
+
+ if (ftruncate(fd, size) < 0) {
+ close(fd);
+ return -1;
+ }
+
+ return fd;
+}
+
+static void
+mouse_buffer_release(void *data, struct wl_buffer *buffer)
+{
+}
+
+static const struct wl_buffer_listener mouse_buffer_listener = {
+ mouse_buffer_release
+};
+
+static int
+create_buffer_from_shm(Wayland_CursorData *d,
+ int width,
+ int height,
+ uint32_t format)
+{
+ SDL_VideoDevice *vd = SDL_GetVideoDevice();
+ SDL_VideoData *data = (SDL_VideoData *) vd->driverdata;
+
+ int stride = width * 4;
+ int size = stride * height;
+
+ int shm_fd;
+
+ shm_fd = wayland_create_tmp_file(size);
+ if (shm_fd < 0)
+ {
+ fprintf(stderr, "creating mouse cursor buffer failed!\n");
+ return -1;
+ }
+
+ d->shm_data = mmap(NULL,
+ size,
+ PROT_READ | PROT_WRITE,
+ MAP_SHARED,
+ shm_fd,
+ 0);
+ if (data == MAP_FAILED) {
+ d->shm_data = NULL;
+ fprintf (stderr, "mmap () failed\n");
+ close (shm_fd);
+ }
+
+ struct wl_shm_pool *shm_pool = wl_shm_create_pool(data->shm,
+ shm_fd,
+ size);
+ d->buffer = wl_shm_pool_create_buffer(shm_pool,
+ 0,
+ width,
+ height,
+ stride,
+ format);
+ wl_buffer_add_listener(d->buffer,
+ &mouse_buffer_listener,
+ d);
+
+ wl_shm_pool_destroy (shm_pool);
+ close (shm_fd);
+
+ return 0;
+}
+
+static SDL_Cursor *
+Wayland_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y)
+{
+ SDL_Cursor *cursor;
+
+ cursor = calloc(1, sizeof (*cursor));
+ if (cursor) {
+ SDL_VideoDevice *vd = SDL_GetVideoDevice ();
+ SDL_VideoData *wd = (SDL_VideoData *) vd->driverdata;
+ Wayland_CursorData *data = calloc (1, sizeof (Wayland_CursorData));
+ cursor->driverdata = (void *) data;
+
+ /* Assume ARGB8888 */
+ SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
+ SDL_assert(surface->pitch == surface->w * 4);
+
+ /* Allocate shared memory buffer for this cursor */
+ if (create_buffer_from_shm (data,
+ surface->w,
+ surface->h,
+ WL_SHM_FORMAT_XRGB8888) < 0)
+ {
+ free (cursor->driverdata);
+ free (cursor);
+ return NULL;
+ }
+
+ SDL_memcpy(data->shm_data,
+ surface->pixels,
+ surface->h * surface->pitch);
+
+ data->surface = wl_compositor_create_surface(wd->compositor);
+ wl_surface_attach(data->surface,
+ data->buffer,
+ 0,
+ 0);
+ wl_surface_damage(data->surface,
+ 0,
+ 0,
+ surface->w,
+ surface->h);
+ wl_surface_commit(data->surface);
+
+ data->hot_x = hot_x;
+ data->hot_y = hot_y;
+ }
+
+ return cursor;
+}
+
+static SDL_Cursor *
+CreateCursorFromWlCursor(SDL_VideoData *d, struct wl_cursor *wlcursor)
+{
+ SDL_Cursor *cursor;
+
+ cursor = calloc(1, sizeof (*cursor));
+ if (cursor) {
+ Wayland_CursorData *data = calloc (1, sizeof (Wayland_CursorData));
+ cursor->driverdata = (void *) data;
+
+ /* The wl_buffer here will be destroyed from wl_cursor_theme_destroy
+ * if we are fetching this from a wl_cursor_theme, so don't store a
+ * reference to it here */
+ data->buffer = NULL;
+ data->surface = wl_compositor_create_surface(d->compositor);
+ wl_surface_attach(data->surface,
+ wl_cursor_image_get_buffer(wlcursor->images[0]),
+ 0,
+ 0);
+ wl_surface_damage(data->surface,
+ 0,
+ 0,
+ wlcursor->images[0]->width,
+ wlcursor->images[0]->height);
+ wl_surface_commit(data->surface);
+ data->hot_x = wlcursor->images[0]->hotspot_x;
+ data->hot_y = wlcursor->images[0]->hotspot_y;
+ data->cursor= wlcursor;
+ } else {
+ SDL_OutOfMemory ();
+ }
+
+ return cursor;
+}
+
+static SDL_Cursor *
+Wayland_CreateDefaultCursor()
+{
+ SDL_VideoDevice *device = SDL_GetVideoDevice();
+ SDL_VideoData *data = device->driverdata;
+
+ return CreateCursorFromWlCursor (data,
+ wl_cursor_theme_get_cursor(data->cursor_theme,
+ "left_ptr"));
+}
+
+static SDL_Cursor *
+Wayland_CreateSystemCursor(SDL_SystemCursor id)
+{
+ SDL_VideoDevice *vd = SDL_GetVideoDevice();
+ SDL_VideoData *d = vd->driverdata;
+
+ struct wl_cursor *cursor = NULL;
+
+ switch(id)
+ {
+ default:
+ SDL_assert(0);
+ return NULL;
+ case SDL_SYSTEM_CURSOR_ARROW:
+ cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "left_ptr");
+ break;
+ case SDL_SYSTEM_CURSOR_IBEAM:
+ cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "xterm");
+ break;
+ case SDL_SYSTEM_CURSOR_WAIT:
+ cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "wait");
+ break;
+ case SDL_SYSTEM_CURSOR_CROSSHAIR:
+ cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
+ break;
+ case SDL_SYSTEM_CURSOR_WAITARROW:
+ cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "wait");
+ break;
+ case SDL_SYSTEM_CURSOR_SIZENWSE:
+ cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
+ break;
+ case SDL_SYSTEM_CURSOR_SIZENESW:
+ cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
+ break;
+ case SDL_SYSTEM_CURSOR_SIZEWE:
+ cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
+ break;
+ case SDL_SYSTEM_CURSOR_SIZENS:
+ cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
+ break;
+ case SDL_SYSTEM_CURSOR_SIZEALL:
+ cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
+ break;
+ case SDL_SYSTEM_CURSOR_NO:
+ cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "xterm");
+ break;
+ case SDL_SYSTEM_CURSOR_HAND:
+ cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "hand1");
+ break;
+ }
+
+ SDL_Cursor *sdl_cursor = CreateCursorFromWlCursor (d, cursor);
+
+ return sdl_cursor;
+}
+
+static void
+Wayland_FreeCursor(SDL_Cursor *cursor)
+{
+ if (!cursor)
+ return;
+
+ Wayland_CursorData *d = cursor->driverdata;
+
+ /* Probably not a cursor we own */
+ if (!d)
+ return;
+
+ if (d->buffer)
+ wl_buffer_destroy(d->buffer);
+
+ if (d->surface)
+ wl_surface_destroy(d->surface);
+
+ /* Not sure what's meant to happen to shm_data */
+ free (cursor->driverdata);
+ SDL_free(cursor);
+}
+
+static int
+Wayland_ShowCursor(SDL_Cursor *cursor)
+{
+ SDL_VideoDevice *vd = SDL_GetVideoDevice();
+ SDL_VideoData *d = vd->driverdata;
+
+ struct wl_pointer *pointer = d->pointer;
+
+ if (!pointer)
+ return -1;
+
+ if (cursor)
+ {
+ Wayland_CursorData *data = cursor->driverdata;
+
+ wl_pointer_set_cursor (pointer, 0,
+ data->surface,
+ data->hot_x,
+ data->hot_y);
+ }
+ else
+ {
+ wl_pointer_set_cursor (pointer, 0,
+ NULL,
+ 0,
+ 0);
+ }
+
+ return 0;
+}
+
+static void
+Wayland_WarpMouse(SDL_Window *window, int x, int y)
+{
+ SDL_Unsupported();
+ return;
+}
+
+static int
+Wayland_SetRelativeMouseMode(SDL_bool enabled)
+{
+ SDL_Unsupported();
+ return -1;
+}
+
+void
+Wayland_InitMouse(void)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ mouse->CreateCursor = Wayland_CreateCursor;
+ mouse->CreateSystemCursor = Wayland_CreateSystemCursor;
+ mouse->ShowCursor = Wayland_ShowCursor;
+ mouse->FreeCursor = Wayland_FreeCursor;
+ mouse->WarpMouse = Wayland_WarpMouse;
+ mouse->SetRelativeMouseMode = Wayland_SetRelativeMouseMode;
+
+ SDL_SetDefaultCursor(Wayland_CreateDefaultCursor());
+}
+
+void
+Wayland_FiniMouse(void)
+{
+ /* This effectively assumes that nobody else
+ * touches SDL_Mouse which is effectively
+ * a singleton */
+
+ SDL_Mouse *mouse = SDL_GetMouse();
+
+ /* Free the current cursor if not the same pointer as
+ * the default cursor */
+ if (mouse->def_cursor != mouse->cur_cursor)
+ Wayland_FreeCursor (mouse->cur_cursor);
+
+ Wayland_FreeCursor (mouse->def_cursor);
+ mouse->def_cursor = NULL;
+ mouse->cur_cursor = NULL;
+
+ mouse->CreateCursor = NULL;
+ mouse->CreateSystemCursor = NULL;
+ mouse->ShowCursor = NULL;
+ mouse->FreeCursor = NULL;
+ mouse->WarpMouse = NULL;
+ mouse->SetRelativeMouseMode = NULL;
+}
+#endif
diff --git a/src/video/wayland/SDL_waylandmouse.h b/src/video/wayland/SDL_waylandmouse.h
new file mode 100644
index 0000000..f434b9d
--- /dev/null
+++ b/src/video/wayland/SDL_waylandmouse.h
@@ -0,0 +1,31 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "SDL_config.h"
+#include "SDL_mouse.h"
+#include "SDL_waylandvideo.h"
+
+#if SDL_VIDEO_DRIVER_WAYLAND
+
+extern void Wayland_InitMouse(void);
+extern void Wayland_FiniMouse(void);
+
+#endif
diff --git a/src/video/wayland/SDL_waylandopengles.c b/src/video/wayland/SDL_waylandopengles.c
new file mode 100644
index 0000000..7a13839
--- /dev/null
+++ b/src/video/wayland/SDL_waylandopengles.c
@@ -0,0 +1,90 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL_config.h"
+
+#if SDL_VIDEO_DRIVER_WAYLAND && SDL_VIDEO_OPENGL_EGL
+
+#include "SDL_waylandvideo.h"
+#include "SDL_waylandopengles.h"
+#include "SDL_waylandwindow.h"
+#include "SDL_waylandevents_c.h"
+
+/* EGL implementation of SDL OpenGL ES support */
+
+int
+Wayland_GLES_LoadLibrary(_THIS, const char *path) {
+ int ret;
+ SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+
+ ret = SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType) data->display);
+
+ Wayland_PumpEvents(_this);
+ wayland_schedule_write(data);
+
+ return ret;
+}
+
+
+SDL_GLContext
+Wayland_GLES_CreateContext(_THIS, SDL_Window * window)
+{
+ SDL_GLContext context;
+ context = SDL_EGL_CreateContext(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
+ wayland_schedule_write(_this->driverdata);
+
+ return context;
+}
+
+void
+Wayland_GLES_SwapWindow(_THIS, SDL_Window *window)
+{
+ SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
+ wayland_schedule_write(_this->driverdata);
+}
+
+
+int
+Wayland_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
+{
+ int ret;
+
+ if (window && context) {
+ ret = SDL_EGL_MakeCurrent(_this, ((SDL_WindowData *) window->driverdata)->egl_surface, context);
+ }
+ else {
+ ret = SDL_EGL_MakeCurrent(_this, NULL, NULL);
+ }
+
+ wayland_schedule_write(_this->driverdata);
+
+ return ret;
+}
+
+void
+Wayland_GLES_DeleteContext(_THIS, SDL_GLContext context)
+{
+ SDL_EGL_DeleteContext(_this, context);
+ wayland_schedule_write(_this->driverdata);
+}
+
+#endif /* SDL_VIDEO_DRIVER_WAYLAND && SDL_VIDEO_OPENGL_EGL */
+
+/* vi: set ts=4 sw=4 expandtab: */
\ No newline at end of file
diff --git a/src/video/wayland/SDL_waylandopengles.h b/src/video/wayland/SDL_waylandopengles.h
new file mode 100644
index 0000000..2deed0c
--- /dev/null
+++ b/src/video/wayland/SDL_waylandopengles.h
@@ -0,0 +1,46 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include "SDL_config.h"
+
+#ifndef _SDL_waylandopengles_h
+#define _SDL_waylandopengles_h
+
+#include "../SDL_sysvideo.h"
+#include "../SDL_egl_c.h"
+
+typedef struct SDL_PrivateGLESData
+{
+} SDL_PrivateGLESData;
+
+/* OpenGLES functions */
+#define Wayland_GLES_GetAttribute SDL_EGL_GetAttribute
+#define Wayland_GLES_GetProcAddress SDL_EGL_GetProcAddress
+#define Wayland_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
+#define Wayland_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
+#define Wayland_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
+
+extern int Wayland_GLES_LoadLibrary(_THIS, const char *path);
+extern SDL_GLContext Wayland_GLES_CreateContext(_THIS, SDL_Window * window);
+extern void Wayland_GLES_SwapWindow(_THIS, SDL_Window * window);
+extern int Wayland_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
+extern void Wayland_GLES_DeleteContext(_THIS, SDL_GLContext context);
+
+#endif /* _SDL_waylandopengles_h */
diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c
new file mode 100644
index 0000000..e75bea1
--- /dev/null
+++ b/src/video/wayland/SDL_waylandvideo.c
@@ -0,0 +1,365 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "SDL_config.h"
+
+#include "SDL_video.h"
+#include "SDL_mouse.h"
+#include "../../events/SDL_events_c.h"
+
+#include "SDL_waylandvideo.h"
+#include "SDL_waylandevents_c.h"
+#include "SDL_waylandwindow.h"
+#include "SDL_waylandopengles.h"
+#include "SDL_waylandmouse.h"
+
+#include <fcntl.h>
+#include <xkbcommon/xkbcommon.h>
+
+#define WAYLANDVID_DRIVER_NAME "wayland"
+
+struct wayland_mode {
+ SDL_DisplayMode mode;
+ struct wl_list link;
+};
+
+/* Initialization/Query functions */
+static int
+Wayland_VideoInit(_THIS);
+
+static void
+Wayland_GetDisplayModes(_THIS, SDL_VideoDisplay *sdl_display);
+static int
+Wayland_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode);
+
+static void
+Wayland_VideoQuit(_THIS);
+
+/* Wayland driver bootstrap functions */
+static int
+Wayland_Available(void)
+{
+ struct wl_display *display = NULL;
+
+ display = wl_display_connect(NULL);
+ if (display != NULL) {
+ wl_display_disconnect(display);
+ }
+
+ return (display != NULL);
+}
+
+static void
+Wayland_DeleteDevice(SDL_VideoDevice *device)
+{
+ SDL_free(device);
+}
+
+static SDL_VideoDevice *
+Wayland_CreateDevice(int devindex)
+{
+ SDL_VideoDevice *device;
+
+ /* Initialize all variables that we clean on shutdown */
+ device = SDL_calloc(1, sizeof(SDL_VideoDevice));
+ if (!device) {
+ SDL_OutOfMemory();
+ return NULL;
+ }
+
+ /* Set the function pointers */
+ device->VideoInit = Wayland_VideoInit;
+ device->VideoQuit = Wayland_VideoQuit;
+ device->SetDisplayMode = Wayland_SetDisplayMode;
+ device->GetDisplayModes = Wayland_GetDisplayModes;
+ device->GetWindowWMInfo = Wayland_GetWindowWMInfo;
+
+ device->PumpEvents = Wayland_PumpEvents;
+
+ device->GL_SwapWindow = Wayland_GLES_SwapWindow;
+ device->GL_GetSwapInterval = Wayland_GLES_GetSwapInterval;
+ device->GL_SetSwapInterval = Wayland_GLES_SetSwapInterval;
+ device->GL_MakeCurrent = Wayland_GLES_MakeCurrent;
+ device->GL_CreateContext = Wayland_GLES_CreateContext;
+ device->GL_LoadLibrary = Wayland_GLES_LoadLibrary;
+ device->GL_UnloadLibrary = Wayland_GLES_UnloadLibrary;
+ device->GL_GetProcAddress = Wayland_GLES_GetProcAddress;
+ device->GL_DeleteContext = Wayland_GLES_DeleteContext;
+
+ device->CreateWindow = Wayland_CreateWindow;
+ device->ShowWindow = Wayland_ShowWindow;
+ device->SetWindowFullscreen = Wayland_SetWindowFullscreen;
+ device->SetWindowSize = Wayland_SetWindowSize;
+ device->DestroyWindow = Wayland_DestroyWindow;
+
+ device->free = Wayland_DeleteDevice;
+
+ return device;
+}
+
+VideoBootStrap Wayland_bootstrap = {
+ WAYLANDVID_DRIVER_NAME, "SDL Wayland video driver",
+ Wayland_Available, Wayland_CreateDevice
+};
+
+static void
+wayland_add_mode(SDL_VideoData *d, SDL_DisplayMode m)
+{
+ struct wayland_mode *mode;
+
+ /* Check for duplicate mode */
+ wl_list_for_each(mode, &d->modes_list, link)
+ if (mode->mode.w == m.w && mode->mode.h == m.h &&
+ mode->mode.refresh_rate == m.refresh_rate)
+ return;
+
+ /* Add new mode to the list */
+ mode = SDL_calloc(1, sizeof *mode);
+
+ if (!mode)
+ return;
+
+ mode->mode = m;
+ wl_list_insert(&d->modes_list, &mode->link);
+}
+
+static void
+display_handle_geometry(void *data,
+ struct wl_output *output,
+ int x, int y,
+ int physical_width,
+ int physical_height,
+ int subpixel,
+ const char *make,
+ const char *model,
+ int transform)
+
+{
+ SDL_VideoData *d = data;
+
+ d->screen_allocation.x = x;
+ d->screen_allocation.y = y;
+}
+
+static void
+display_handle_mode(void *data,
+ struct wl_output *wl_output,
+ uint32_t flags,
+ int width,
+ int height,
+ int refresh)
+{
+ SDL_VideoData *d = data;
+ SDL_DisplayMode mode;
+
+ SDL_zero(mode);
+ mode.w = width;
+ mode.h = height;
+ mode.refresh_rate = refresh / 1000;
+
+ wayland_add_mode(d, mode);
+
+ if (flags & WL_OUTPUT_MODE_CURRENT) {
+ d->screen_allocation.width = width;
+ d->screen_allocation.height = height;
+ }
+}
+
+static const struct wl_output_listener output_listener = {
+ display_handle_geometry,
+ display_handle_mode
+};
+
+static void
+shm_handle_format(void *data,
+ struct wl_shm *shm,
+ uint32_t format)
+{
+ SDL_VideoData *d = data;
+
+ d->shm_formats |= (1 << format);
+}
+
+static const struct wl_shm_listener shm_listener = {
+ shm_handle_format
+};
+
+static void
+display_handle_global(void *data, struct wl_registry *registry, uint32_t id,
+ const char *interface, uint32_t version)
+{
+ SDL_VideoData *d = data;
+
+ if (strcmp(interface, "wl_compositor") == 0) {
+ d->compositor = wl_registry_bind(d->registry, id, &wl_compositor_interface, 1);
+ } else if (strcmp(interface, "wl_output") == 0) {
+ d->output = wl_registry_bind(d->registry, id, &wl_output_interface, 1);
+ wl_output_add_listener(d->output, &output_listener, d);
+ } else if (strcmp(interface, "wl_seat") == 0) {
+ Wayland_display_add_input(d, id);
+ } else if (strcmp(interface, "wl_shell") == 0) {
+ d->shell = wl_registry_bind(d->registry, id, &wl_shell_interface, 1);
+ } else if (strcmp(interface, "wl_shm") == 0) {
+ d->shm = wl_registry_bind(registry, id, &wl_shm_interface, 1);
+ d->cursor_theme = wl_cursor_theme_load(NULL, 32, d->shm);
+ d->default_cursor = wl_cursor_theme_get_cursor(d->cursor_theme, "left_ptr");
+ wl_shm_add_listener(d->shm, &shm_listener, d);
+ }
+}
+
+static const struct wl_registry_listener registry_listener = {
+ display_handle_global
+};
+
+int
+Wayland_VideoInit(_THIS)
+{
+ SDL_VideoData *data;
+
+ data = malloc(sizeof *data);
+ if (data == NULL)
+ return 0;
+ memset(data, 0, sizeof *data);
+
+ _this->driverdata = data;
+
+ wl_list_init(&data->modes_list);
+
+ data->display = wl_display_connect(NULL);
+ if (data->display == NULL) {
+ SDL_SetError("Failed to connect to a Wayland display");
+ return 0;
+ }
+
+ data->registry = wl_display_get_registry(data->display);
+ wl_registry_add_listener(data->registry, ®istry_listener, data);
+
+ while (data->screen_allocation.width == 0)
+ wl_display_dispatch(data->display);
+
+ data->xkb_context = xkb_context_new(0);
+ if (!data->xkb_context) {
+ SDL_SetError("Failed to create XKB context");
+ return 0;
+ }
+
+ SDL_VideoDisplay display;
+ SDL_DisplayMode mode;
+
+ /* Use a fake 32-bpp desktop mode */
+ mode.format = SDL_PIXELFORMAT_RGB888;
+ mode.w = data->screen_allocation.width;
+ mode.h = data->screen_allocation.height;
+ mode.refresh_rate = 0;
+ mode.driverdata = NULL;
+ wayland_add_mode(data, mode);
+ SDL_zero(display);
+ display.desktop_mode = mode;
+ display.current_mode = mode;
+ display.driverdata = NULL;
+ SDL_AddVideoDisplay(&display);
+
+ Wayland_InitMouse ();
+
+ wayland_schedule_write(data);
+
+ return 0;
+}
+
+static void
+Wayland_GetDisplayModes(_THIS, SDL_VideoDisplay *sdl_display)
+{
+ SDL_VideoData *data = _this->driverdata;
+ SDL_DisplayMode mode;
+ struct wayland_mode *m;
+
+ Wayland_PumpEvents(_this);
+
+ wl_list_for_each(m, &data->modes_list, link) {
+ m->mode.format = SDL_PIXELFORMAT_RGB888;
+ SDL_AddDisplayMode(sdl_display, &m->mode);
+ m->mode.format = SDL_PIXELFORMAT_RGBA8888;
+ SDL_AddDisplayMode(sdl_display, &m->mode);
+ }
+
+ mode.w = data->screen_allocation.width;
+ mode.h = data->screen_allocation.height;
+ mode.refresh_rate = 0;
+ mode.driverdata = NULL;
+
+ mode.format = SDL_PIXELFORMAT_RGB888;
+ SDL_AddDisplayMode(sdl_display, &mode);
+ mode.format = SDL_PIXELFORMAT_RGBA8888;
+ SDL_AddDisplayMode(sdl_display, &mode);
+}
+
+static int
+Wayland_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
+{
+ return 0;
+}
+
+void
+Wayland_VideoQuit(_THIS)
+{
+ SDL_VideoData *data = _this->driverdata;
+ struct wayland_mode *t, *m;
+
+ Wayland_FiniMouse ();
+
+ if (data->output)
+ wl_output_destroy(data->output);
+
+ Wayland_display_destroy_input(data);
+
+ if (data->xkb_context) {
+ xkb_context_unref(data->xkb_context);
+ data->xkb_context = NULL;
+ }
+
+ if (data->shm)
+ wl_shm_destroy(data->shm);
+
+ if (data->cursor_theme)
+ wl_cursor_theme_destroy(data->cursor_theme);
+
+ if (data->shell)
+ wl_shell_destroy(data->shell);
+
+ if (data->compositor)
+ wl_compositor_destroy(data->compositor);
+
+ if (data->display) {
+ wl_display_flush(data->display);
+ wl_display_disconnect(data->display);
+ }
+
+ wl_list_for_each_safe(m, t, &data->modes_list, link) {
+ wl_list_remove(&m->link);
+ free(m);
+ }
+
+
+ free(data);
+ _this->driverdata = NULL;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/wayland/SDL_waylandvideo.h b/src/video/wayland/SDL_waylandvideo.h
new file mode 100644
index 0000000..ca1b66f
--- /dev/null
+++ b/src/video/wayland/SDL_waylandvideo.h
@@ -0,0 +1,71 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "SDL_config.h"
+
+#ifndef _SDL_waylandvideo_h
+#define _SDL_waylandvideo_h
+
+#include <wayland-client.h>
+#include <wayland-cursor.h>
+#include <wayland-egl.h>
+
+#include <EGL/egl.h>
+
+struct xkb_context;
+struct SDL_WaylandInput;
+
+typedef struct {
+ struct wl_display *display;
+ struct wl_registry *registry;
+ struct wl_compositor *compositor;
+ struct wl_output *output;
+ struct wl_shm *shm;
+ struct wl_cursor_theme *cursor_theme;
+ struct wl_cursor *default_cursor;
+ struct wl_pointer *pointer;
+ struct wl_shell *shell;
+
+ struct {
+ int32_t x, y, width, height;
+ } screen_allocation;
+
+ struct wl_list modes_list;
+
+ EGLDisplay edpy;
+ EGLContext context;
+ EGLConfig econf;
+
+ struct xkb_context *xkb_context;
+ struct SDL_WaylandInput *input;
+
+ uint32_t shm_formats;
+} SDL_VideoData;
+
+static inline void
+wayland_schedule_write(SDL_VideoData *data)
+{
+ wl_display_flush(data->display);
+}
+
+#endif /* _SDL_nullvideo_h */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c
new file mode 100644
index 0000000..e530f5b
--- /dev/null
+++ b/src/video/wayland/SDL_waylandwindow.c
@@ -0,0 +1,192 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "SDL_config.h"
+
+#include "../SDL_sysvideo.h"
+#include "../../events/SDL_windowevents_c.h"
+#include "../SDL_egl_c.h"
+#include "SDL_waylandwindow.h"
+#include "SDL_waylandvideo.h"
+
+static void
+handle_ping(void *data, struct wl_shell_surface *shell_surface,
+ uint32_t serial)
+{
+ wl_shell_surface_pong(shell_surface, serial);
+}
+
+static void
+handle_configure(void *data, struct wl_shell_surface *shell_surface,
+ uint32_t edges, int32_t width, int32_t height)
+{
+}
+
+static void
+handle_popup_done(void *data, struct wl_shell_surface *shell_surface)
+{
+}
+
+static const struct wl_shell_surface_listener shell_surface_listener = {
+ handle_ping,
+ handle_configure,
+ handle_popup_done
+};
+
+SDL_bool
+Wayland_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
+{
+ SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
+
+ info->info.wl.display = data->waylandData->display;
+ info->info.wl.surface = data->surface;
+ info->info.wl.shell_surface = data->shell_surface;
+ info->subsystem = SDL_SYSWM_WAYLAND;
+
+ return SDL_TRUE;
+}
+
+void Wayland_ShowWindow(_THIS, SDL_Window *window)
+{
+ SDL_WindowData *wind = window->driverdata;
+
+ if (window->flags & SDL_WINDOW_FULLSCREEN)
+ wl_shell_surface_set_fullscreen(wind->shell_surface,
+ WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
+ 0, NULL);
+ else
+ wl_shell_surface_set_toplevel(wind->shell_surface);
+
+ wayland_schedule_write(_this->driverdata);
+}
+
+void
+Wayland_SetWindowFullscreen(_THIS, SDL_Window * window,
+ SDL_VideoDisplay * _display, SDL_bool fullscreen)
+{
+ SDL_WindowData *wind = window->driverdata;
+
+ if (fullscreen)
+ wl_shell_surface_set_fullscreen(wind->shell_surface,
+ WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE,
+ 0, NULL);
+ else
+ wl_shell_surface_set_toplevel(wind->shell_surface);
+
+ wayland_schedule_write(_this->driverdata);
+}
+
+int Wayland_CreateWindow(_THIS, SDL_Window *window)
+{
+ SDL_WindowData *data;
+ SDL_VideoData *c;
+ struct wl_region *region;
+
+ data = calloc(1, sizeof *data);
+ if (data == NULL)
+ return 0;
+
+ c = _this->driverdata;
+ window->driverdata = data;
+
+ if (!(window->flags & SDL_WINDOW_OPENGL)) {
+ SDL_GL_LoadLibrary(NULL);
+ window->flags |= SDL_WINDOW_OPENGL;
+ }
+
+ if (window->x == SDL_WINDOWPOS_UNDEFINED) {
+ window->x = 0;
+ }
+ if (window->y == SDL_WINDOWPOS_UNDEFINED) {
+ window->y = 0;
+ }
+
+ data->waylandData = c;
+ data->sdlwindow = window;
+
+ data->surface =
+ wl_compositor_create_surface(c->compositor);
+ wl_surface_set_user_data(data->surface, data);
+ data->shell_surface = wl_shell_get_shell_surface(c->shell,
+ data->surface);
+ data->egl_window = wl_egl_window_create(data->surface,
+ window->w, window->h);
+
+ /* Create the GLES window surface */
+ data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->egl_window);
+
+ if (data->egl_surface == EGL_NO_SURFACE) {
+ SDL_SetError("failed to create a window surface");
+ return -1;
+ }
+
+ if (data->shell_surface) {
+ wl_shell_surface_set_user_data(data->shell_surface, data);
+ wl_shell_surface_add_listener(data->shell_surface,
+ &shell_surface_listener, data);
+ }
+
+ region = wl_compositor_create_region(c->compositor);
+ wl_region_add(region, 0, 0, window->w, window->h);
+ wl_surface_set_opaque_region(data->surface, region);
+ wl_region_destroy(region);
+
+ wayland_schedule_write(c);
+
+ return 0;
+}
+
+void Wayland_SetWindowSize(_THIS, SDL_Window * window)
+{
+ SDL_VideoData *data = _this->driverdata;
+ SDL_WindowData *wind = window->driverdata;
+ struct wl_region *region;
+
+ wl_egl_window_resize(wind->egl_window, window->w, window->h, 0, 0);
+
+ region = wl_compositor_create_region(data->compositor);
+ wl_region_add(region, 0, 0, window->w, window->h);
+ wl_surface_set_opaque_region(wind->surface, region);
+ wl_region_destroy(region);
+}
+
+void Wayland_DestroyWindow(_THIS, SDL_Window *window)
+{
+ SDL_VideoData *data = _this->driverdata;
+ SDL_WindowData *wind = window->driverdata;
+
+ window->driverdata = NULL;
+
+ if (data) {
+ SDL_EGL_DestroySurface(_this, wind->egl_surface);
+ wl_egl_window_destroy(wind->egl_window);
+
+ if (wind->shell_surface)
+ wl_shell_surface_destroy(wind->shell_surface);
+
+ wl_surface_destroy(wind->surface);
+
+ SDL_free(wind);
+ wayland_schedule_write(data);
+ }
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/video/wayland/SDL_waylandwindow.h b/src/video/wayland/SDL_waylandwindow.h
new file mode 100644
index 0000000..f4f1836
--- /dev/null
+++ b/src/video/wayland/SDL_waylandwindow.h
@@ -0,0 +1,58 @@
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "SDL_config.h"
+
+#ifndef _SDL_waylandwindow_h
+#define _SDL_waylandwindow_h
+
+#include "../SDL_sysvideo.h"
+#include "SDL_syswm.h"
+
+#include "SDL_waylandvideo.h"
+
+struct SDL_WaylandInput;
+
+typedef struct {
+ SDL_Window *sdlwindow;
+ SDL_VideoData *waylandData;
+ struct wl_surface *surface;
+ struct wl_shell_surface *shell_surface;
+ struct wl_egl_window *egl_window;
+ struct SDL_WaylandInput *keyboard_device;
+
+ EGLSurface egl_surface;
+} SDL_WindowData;
+
+extern void Wayland_ShowWindow(_THIS, SDL_Window *window);
+extern void Wayland_SetWindowFullscreen(_THIS, SDL_Window * window,
+ SDL_VideoDisplay * _display,
+ SDL_bool fullscreen);
+extern int Wayland_CreateWindow(_THIS, SDL_Window *window);
+extern void Wayland_SetWindowSize(_THIS, SDL_Window * window);
+extern void Wayland_DestroyWindow(_THIS, SDL_Window *window);
+
+extern SDL_bool
+Wayland_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info);
+
+#endif /* _SDL_waylandwindow_h */
+
+/* vi: set ts=4 sw=4 expandtab: */
diff --git a/test/Makefile.in b/test/Makefile.in
index a534250..8a8c2b8 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -128,13 +128,13 @@ testgesture$(EXE): $(srcdir)/testgesture.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
testgl2$(EXE): $(srcdir)/testgl2.c
- $(CC) -o $@ $^ $(CFLAGS) $(LIBS) @GLLIB@ @MATHLIB@
+ $(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
testgles$(EXE): $(srcdir)/testgles.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @GLESLIB@ @MATHLIB@
testgles2$(EXE): $(srcdir)/testgles2.c
- $(CC) -o $@ $^ $(CFLAGS) $(LIBS) @GLES2LIB@ @MATHLIB@
+ $(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
testhaptic$(EXE): $(srcdir)/testhaptic.c
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
diff --git a/test/testgl2.c b/test/testgl2.c
index 19685ea..f51efe9 100644
--- a/test/testgl2.c
+++ b/test/testgl2.c
@@ -24,11 +24,48 @@
#include "SDL_opengl.h"
+typedef struct GL_Context
+{
+#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
+#include "../src/render/opengl/SDL_glfuncs.h"
+#undef SDL_PROC
+} GL_Context;
+
+
/* Undefine this if you want a flat cube instead of a rainbow cube */
#define SHADED_CUBE
static SDLTest_CommonState *state;
static SDL_GLContext context;
+static GL_Context ctx;
+
+static int LoadContext(GL_Context * data)
+{
+#if SDL_VIDEO_DRIVER_UIKIT
+#define __SDL_NOGETPROCADDR__
+#elif SDL_VIDEO_DRIVER_ANDROID
+#define __SDL_NOGETPROCADDR__
+#elif SDL_VIDEO_DRIVER_PANDORA
+#define __SDL_NOGETPROCADDR__
+#endif
+
+#if defined __SDL_NOGETPROCADDR__
+#define SDL_PROC(ret,func,params) data->func=func;
+#else
+#define SDL_PROC(ret,func,params) \
+ do { \
+ data->func = SDL_GL_GetProcAddress(#func); \
+ if ( ! data->func ) { \
+ return SDL_SetError("Couldn't load GL function %s: %s\n", #func, SDL_GetError()); \
+ } \
+ } while ( 0 );
+#endif /* _SDL_NOGETPROCADDR_ */
+
+#include "../src/render/opengl/SDL_glfuncs.h"
+#undef SDL_PROC
+ return 0;
+}
+
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
@@ -67,107 +104,107 @@ Render()
};
/* Do our drawing, too. */
- glClearColor(0.0, 0.0, 0.0, 1.0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ ctx.glClearColor(0.0, 0.0, 0.0, 1.0);
+ ctx.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glBegin(GL_QUADS);
+ ctx.glBegin(GL_QUADS);
#ifdef SHADED_CUBE
- glColor3fv(color[0]);
- glVertex3fv(cube[0]);
- glColor3fv(color[1]);
- glVertex3fv(cube[1]);
- glColor3fv(color[2]);
- glVertex3fv(cube[2]);
- glColor3fv(color[3]);
- glVertex3fv(cube[3]);
-
- glColor3fv(color[3]);
- glVertex3fv(cube[3]);
- glColor3fv(color[4]);
- glVertex3fv(cube[4]);
- glColor3fv(color[7]);
- glVertex3fv(cube[7]);
- glColor3fv(color[2]);
- glVertex3fv(cube[2]);
-
- glColor3fv(color[0]);
- glVertex3fv(cube[0]);
- glColor3fv(color[5]);
- glVertex3fv(cube[5]);
- glColor3fv(color[6]);
- glVertex3fv(cube[6]);
- glColor3fv(color[1]);
- glVertex3fv(cube[1]);
-
- glColor3fv(color[5]);
- glVertex3fv(cube[5]);
- glColor3fv(color[4]);
- glVertex3fv(cube[4]);
- glColor3fv(color[7]);
- glVertex3fv(cube[7]);
- glColor3fv(color[6]);
- glVertex3fv(cube[6]);
-
- glColor3fv(color[5]);
- glVertex3fv(cube[5]);
- glColor3fv(color[0]);
- glVertex3fv(cube[0]);
- glColor3fv(color[3]);
- glVertex3fv(cube[3]);
- glColor3fv(color[4]);
- glVertex3fv(cube[4]);
-
- glColor3fv(color[6]);
- glVertex3fv(cube[6]);
- glColor3fv(color[1]);
- glVertex3fv(cube[1]);
- glColor3fv(color[2]);
- glVertex3fv(cube[2]);
- glColor3fv(color[7]);
- glVertex3fv(cube[7]);
+ ctx.glColor3fv(color[0]);
+ ctx.glVertex3fv(cube[0]);
+ ctx.glColor3fv(color[1]);
+ ctx.glVertex3fv(cube[1]);
+ ctx.glColor3fv(color[2]);
+ ctx.glVertex3fv(cube[2]);
+ ctx.glColor3fv(color[3]);
+ ctx.glVertex3fv(cube[3]);
+
+ ctx.glColor3fv(color[3]);
+ ctx.glVertex3fv(cube[3]);
+ ctx.glColor3fv(color[4]);
+ ctx.glVertex3fv(cube[4]);
+ ctx.glColor3fv(color[7]);
+ ctx.glVertex3fv(cube[7]);
+ ctx.glColor3fv(color[2]);
+ ctx.glVertex3fv(cube[2]);
+
+ ctx.glColor3fv(color[0]);
+ ctx.glVertex3fv(cube[0]);
+ ctx.glColor3fv(color[5]);
+ ctx.glVertex3fv(cube[5]);
+ ctx.glColor3fv(color[6]);
+ ctx.glVertex3fv(cube[6]);
+ ctx.glColor3fv(color[1]);
+ ctx.glVertex3fv(cube[1]);
+
+ ctx.glColor3fv(color[5]);
+ ctx.glVertex3fv(cube[5]);
+ ctx.glColor3fv(color[4]);
+ ctx.glVertex3fv(cube[4]);
+ ctx.glColor3fv(color[7]);
+ ctx.glVertex3fv(cube[7]);
+ ctx.glColor3fv(color[6]);
+ ctx.glVertex3fv(cube[6]);
+
+ ctx.glColor3fv(color[5]);
+ ctx.glVertex3fv(cube[5]);
+ ctx.glColor3fv(color[0]);
+ ctx.glVertex3fv(cube[0]);
+ ctx.glColor3fv(color[3]);
+ ctx.glVertex3fv(cube[3]);
+ ctx.glColor3fv(color[4]);
+ ctx.glVertex3fv(cube[4]);
+
+ ctx.glColor3fv(color[6]);
+ ctx.glVertex3fv(cube[6]);
+ ctx.glColor3fv(color[1]);
+ ctx.glVertex3fv(cube[1]);
+ ctx.glColor3fv(color[2]);
+ ctx.glVertex3fv(cube[2]);
+ ctx.glColor3fv(color[7]);
+ ctx.glVertex3fv(cube[7]);
#else /* flat cube */
- glColor3f(1.0, 0.0, 0.0);
- glVertex3fv(cube[0]);
- glVertex3fv(cube[1]);
- glVertex3fv(cube[2]);
- glVertex3fv(cube[3]);
-
- glColor3f(0.0, 1.0, 0.0);
- glVertex3fv(cube[3]);
- glVertex3fv(cube[4]);
- glVertex3fv(cube[7]);
- glVertex3fv(cube[2]);
-
- glColor3f(0.0, 0.0, 1.0);
- glVertex3fv(cube[0]);
- glVertex3fv(cube[5]);
- glVertex3fv(cube[6]);
- glVertex3fv(cube[1]);
-
- glColor3f(0.0, 1.0, 1.0);
- glVertex3fv(cube[5]);
- glVertex3fv(cube[4]);
- glVertex3fv(cube[7]);
- glVertex3fv(cube[6]);
-
- glColor3f(1.0, 1.0, 0.0);
- glVertex3fv(cube[5]);
- glVertex3fv(cube[0]);
- glVertex3fv(cube[3]);
- glVertex3fv(cube[4]);
-
- glColor3f(1.0, 0.0, 1.0);
- glVertex3fv(cube[6]);
- glVertex3fv(cube[1]);
- glVertex3fv(cube[2]);
- glVertex3fv(cube[7]);
+ ctx.glColor3f(1.0, 0.0, 0.0);
+ ctx.glVertex3fv(cube[0]);
+ ctx.glVertex3fv(cube[1]);
+ ctx.glVertex3fv(cube[2]);
+ ctx.glVertex3fv(cube[3]);
+
+ ctx.glColor3f(0.0, 1.0, 0.0);
+ ctx.glVertex3fv(cube[3]);
+ ctx.glVertex3fv(cube[4]);
+ ctx.glVertex3fv(cube[7]);
+ ctx.glVertex3fv(cube[2]);
+
+ ctx.glColor3f(0.0, 0.0, 1.0);
+ ctx.glVertex3fv(cube[0]);
+ ctx.glVertex3fv(cube[5]);
+ ctx.glVertex3fv(cube[6]);
+ ctx.glVertex3fv(cube[1]);
+
+ ctx.glColor3f(0.0, 1.0, 1.0);
+ ctx.glVertex3fv(cube[5]);
+ ctx.glVertex3fv(cube[4]);
+ ctx.glVertex3fv(cube[7]);
+ ctx.glVertex3fv(cube[6]);
+
+ ctx.glColor3f(1.0, 1.0, 0.0);
+ ctx.glVertex3fv(cube[5]);
+ ctx.glVertex3fv(cube[0]);
+ ctx.glVertex3fv(cube[3]);
+ ctx.glVertex3fv(cube[4]);
+
+ ctx.glColor3f(1.0, 0.0, 1.0);
+ ctx.glVertex3fv(cube[6]);
+ ctx.glVertex3fv(cube[1]);
+ ctx.glVertex3fv(cube[2]);
+ ctx.glVertex3fv(cube[7]);
#endif /* SHADED_CUBE */
- glEnd();
+ ctx.glEnd();
- glMatrixMode(GL_MODELVIEW);
- glRotatef(5.0, 1.0, 1.0, 1.0);
+ ctx.glMatrixMode(GL_MODELVIEW);
+ ctx.glRotatef(5.0, 1.0, 1.0, 1.0);
}
int
@@ -242,6 +279,13 @@ main(int argc, char *argv[])
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
quit(2);
}
+
+ /* Important: call this *after* creating the context */
+ if (LoadContext(&ctx) < 0) {
+ SDL_Log("Could not load GL functions\n");
+ quit(2);
+ return 0;
+ }
if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
/* try late-swap-tearing first. If not supported, try normal vsync. */
@@ -260,10 +304,10 @@ main(int argc, char *argv[])
SDL_GL_GetDrawableSize(state->windows[0], &dw, &dh);
SDL_Log("Draw Size : %d,%d\n", dw, dh);
SDL_Log("\n");
- SDL_Log("Vendor : %s\n", glGetString(GL_VENDOR));
- SDL_Log("Renderer : %s\n", glGetString(GL_RENDERER));
- SDL_Log("Version : %s\n", glGetString(GL_VERSION));
- SDL_Log("Extensions : %s\n", glGetString(GL_EXTENSIONS));
+ SDL_Log("Vendor : %s\n", ctx.glGetString(GL_VENDOR));
+ SDL_Log("Renderer : %s\n", ctx.glGetString(GL_RENDERER));
+ SDL_Log("Version : %s\n", ctx.glGetString(GL_VERSION));
+ SDL_Log("Extensions : %s\n", ctx.glGetString(GL_EXTENSIONS));
SDL_Log("\n");
status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
@@ -319,14 +363,14 @@ main(int argc, char *argv[])
}
/* Set rendering settings */
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glEnable(GL_DEPTH_TEST);
- glDepthFunc(GL_LESS);
- glShadeModel(GL_SMOOTH);
+ ctx.glMatrixMode(GL_PROJECTION);
+ ctx.glLoadIdentity();
+ ctx.glOrtho(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0);
+ ctx.glMatrixMode(GL_MODELVIEW);
+ ctx.glLoadIdentity();
+ ctx.glEnable(GL_DEPTH_TEST);
+ ctx.glDepthFunc(GL_LESS);
+ ctx.glShadeModel(GL_SMOOTH);
/* Main render loop */
frames = 0;
@@ -344,7 +388,7 @@ main(int argc, char *argv[])
continue;
SDL_GL_MakeCurrent(state->windows[i], context);
SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
- glViewport(0, 0, w, h);
+ ctx.glViewport(0, 0, w, h);
Render();
SDL_GL_SwapWindow(state->windows[i]);
}