1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509
|
/*
* Clutter.
*
* An OpenGL based 'interactive canvas' library.
*
* Authored By Matthew Allum <mallum@openedhand.com>
*
* Copyright (C) 2006 OpenedHand
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* SECTION:clutter-stage
* @short_description: Top level visual element to which actors are placed.
*
* #ClutterStage is a top level 'window' on which child actors are placed
* and manipulated.
*
* Backends might provide support for multiple stages. The support for this
* feature can be checked at run-time using the clutter_feature_available()
* function and the %CLUTTER_FEATURE_STAGE_MULTIPLE flag. If the backend used
* supports multiple stages, new #ClutterStage instances can be created
* using clutter_stage_new(). These stages must be managed by the developer
* using clutter_actor_destroy(), which will take care of destroying all the
* actors contained inside them.
*
* #ClutterStage is a proxy actor, wrapping the backend-specific
* implementation of the windowing system. It is possible to subclass
* #ClutterStage, as long as every overridden virtual function chains up to
* the parent class corresponding function.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <math.h>
#include <cairo.h>
#define CLUTTER_DISABLE_DEPRECATION_WARNINGS
#define CLUTTER_ENABLE_EXPERIMENTAL_API
#include "clutter-stage.h"
#include "deprecated/clutter-stage.h"
#include "deprecated/clutter-container.h"
#include "clutter-actor-private.h"
#include "clutter-backend-private.h"
#include "clutter-cairo.h"
#include "clutter-color.h"
#include "clutter-container.h"
#include "clutter-debug.h"
#include "clutter-device-manager-private.h"
#include "clutter-enum-types.h"
#include "clutter-event-private.h"
#include "clutter-id-pool.h"
#include "clutter-main.h"
#include "clutter-marshal.h"
#include "clutter-master-clock.h"
#include "clutter-paint-volume-private.h"
#include "clutter-private.h"
#include "clutter-stage-manager-private.h"
#include "clutter-stage-private.h"
#include "clutter-version.h" /* For flavour */
#include "clutter-private.h"
#include "cogl/cogl.h"
/* <private>
* ClutterStageHint:
* @CLUTTER_STAGE_NONE: No hint set
* @CLUTTER_STAGE_NO_CLEAR_ON_PAINT: When this hint is set, the stage
* should not clear the viewport; this flag is useful when painting
* fully opaque actors covering the whole visible area of the stage,
* i.e. when no blending with the stage color happens over the whole
* stage viewport
*
* A series of hints that enable or disable behaviours on the stage
*/
typedef enum { /*< prefix=CLUTTER_STAGE >*/
CLUTTER_STAGE_HINT_NONE = 0,
CLUTTER_STAGE_NO_CLEAR_ON_PAINT = 1 << 0
} ClutterStageHint;
#define STAGE_NO_CLEAR_ON_PAINT(s) ((((ClutterStage *) (s))->priv->stage_hints & CLUTTER_STAGE_NO_CLEAR_ON_PAINT) != 0)
struct _ClutterStageQueueRedrawEntry
{
ClutterActor *actor;
gboolean has_clip;
ClutterPaintVolume clip;
};
struct _ClutterStagePrivate
{
/* the stage implementation */
ClutterStageWindow *impl;
ClutterPerspective perspective;
CoglMatrix projection;
CoglMatrix inverse_projection;
CoglMatrix view;
float viewport[4];
ClutterFog fog;
gchar *title;
ClutterActor *key_focused_actor;
GQueue *event_queue;
ClutterStageHint stage_hints;
GArray *paint_volume_stack;
ClutterPlane current_clip_planes[4];
GList *pending_queue_redraws;
CoglFramebuffer *active_framebuffer;
gint sync_delay;
GTimer *fps_timer;
gint32 timer_n_frames;
ClutterIDPool *pick_id_pool;
#ifdef CLUTTER_ENABLE_DEBUG
gulong redraw_count;
#endif /* CLUTTER_ENABLE_DEBUG */
ClutterStageState current_state;
gpointer paint_data;
GDestroyNotify paint_notify;
guint relayout_pending : 1;
guint redraw_pending : 1;
guint is_fullscreen : 1;
guint is_cursor_visible : 1;
guint is_user_resizable : 1;
guint use_fog : 1;
guint throttle_motion_events : 1;
guint use_alpha : 1;
guint min_size_changed : 1;
guint dirty_viewport : 1;
guint dirty_projection : 1;
guint accept_focus : 1;
guint motion_events_enabled : 1;
guint has_custom_perspective : 1;
};
enum
{
PROP_0,
PROP_COLOR,
PROP_FULLSCREEN_SET,
PROP_OFFSCREEN,
PROP_CURSOR_VISIBLE,
PROP_PERSPECTIVE,
PROP_TITLE,
PROP_USER_RESIZABLE,
PROP_USE_FOG,
PROP_FOG,
PROP_USE_ALPHA,
PROP_KEY_FOCUS,
PROP_NO_CLEAR_HINT,
PROP_ACCEPT_FOCUS
};
enum
{
FULLSCREEN,
UNFULLSCREEN,
ACTIVATE,
DEACTIVATE,
DELETE_EVENT,
AFTER_PAINT,
LAST_SIGNAL
};
static guint stage_signals[LAST_SIGNAL] = { 0, };
static const ClutterColor default_stage_color = { 255, 255, 255, 255 };
static void clutter_stage_maybe_finish_queue_redraws (ClutterStage *stage);
static void free_queue_redraw_entry (ClutterStageQueueRedrawEntry *entry);
static void clutter_container_iface_init (ClutterContainerIface *iface);
G_DEFINE_TYPE_WITH_CODE (ClutterStage, clutter_stage, CLUTTER_TYPE_GROUP,
G_ADD_PRIVATE (ClutterStage)
G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_CONTAINER,
clutter_container_iface_init))
static void
clutter_stage_real_add (ClutterContainer *container,
ClutterActor *child)
{
clutter_actor_add_child (CLUTTER_ACTOR (container), child);
}
static void
clutter_stage_real_remove (ClutterContainer *container,
ClutterActor *child)
{
clutter_actor_remove_child (CLUTTER_ACTOR (container), child);
}
static void
clutter_stage_real_foreach (ClutterContainer *container,
ClutterCallback callback,
gpointer user_data)
{
ClutterActorIter iter;
ClutterActor *child;
clutter_actor_iter_init (&iter, CLUTTER_ACTOR (container));
while (clutter_actor_iter_next (&iter, &child))
callback (child, user_data);
}
static void
clutter_stage_real_raise (ClutterContainer *container,
ClutterActor *child,
ClutterActor *sibling)
{
clutter_actor_set_child_above_sibling (CLUTTER_ACTOR (container),
child,
sibling);
}
static void
clutter_stage_real_lower (ClutterContainer *container,
ClutterActor *child,
ClutterActor *sibling)
{
clutter_actor_set_child_below_sibling (CLUTTER_ACTOR (container),
child,
sibling);
}
static void
clutter_stage_real_sort_depth_order (ClutterContainer *container)
{
}
static void
clutter_container_iface_init (ClutterContainerIface *iface)
{
iface->add = clutter_stage_real_add;
iface->remove = clutter_stage_real_remove;
iface->foreach = clutter_stage_real_foreach;
iface->raise = clutter_stage_real_raise;
iface->lower = clutter_stage_real_lower;
iface->sort_depth_order = clutter_stage_real_sort_depth_order;
}
static void
clutter_stage_get_preferred_width (ClutterActor *self,
gfloat for_height,
gfloat *min_width_p,
gfloat *natural_width_p)
{
ClutterStagePrivate *priv = CLUTTER_STAGE (self)->priv;
cairo_rectangle_int_t geom;
if (priv->impl == NULL)
return;
_clutter_stage_window_get_geometry (priv->impl, &geom);
if (min_width_p)
*min_width_p = geom.width;
if (natural_width_p)
*natural_width_p = geom.width;
}
static void
clutter_stage_get_preferred_height (ClutterActor *self,
gfloat for_width,
gfloat *min_height_p,
gfloat *natural_height_p)
{
ClutterStagePrivate *priv = CLUTTER_STAGE (self)->priv;
cairo_rectangle_int_t geom;
if (priv->impl == NULL)
return;
_clutter_stage_window_get_geometry (priv->impl, &geom);
if (min_height_p)
*min_height_p = geom.height;
if (natural_height_p)
*natural_height_p = geom.height;
}
static inline void
queue_full_redraw (ClutterStage *stage)
{
ClutterStageWindow *stage_window;
if (CLUTTER_ACTOR_IN_DESTRUCTION (stage))
return;
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
/* Just calling clutter_actor_queue_redraw will typically only
* redraw the bounding box of the children parented on the stage but
* in this case we really need to ensure that the full stage is
* redrawn so we add a NULL redraw clip to the stage window. */
stage_window = _clutter_stage_get_window (stage);
if (stage_window == NULL)
return;
_clutter_stage_window_add_redraw_clip (stage_window, NULL);
}
static gboolean
stage_is_default (ClutterStage *stage)
{
ClutterStageManager *stage_manager;
ClutterStageWindow *impl;
stage_manager = clutter_stage_manager_get_default ();
if (stage != clutter_stage_manager_get_default_stage (stage_manager))
return FALSE;
impl = _clutter_stage_get_window (stage);
if (impl != _clutter_stage_get_default_window ())
return FALSE;
return TRUE;
}
static void
clutter_stage_allocate (ClutterActor *self,
const ClutterActorBox *box,
ClutterAllocationFlags flags)
{
ClutterStagePrivate *priv = CLUTTER_STAGE (self)->priv;
ClutterActorBox alloc = CLUTTER_ACTOR_BOX_INIT_ZERO;
float old_width, old_height;
float new_width, new_height;
float width, height;
cairo_rectangle_int_t window_size;
int scale_factor;
if (priv->impl == NULL)
return;
/* our old allocation */
clutter_actor_get_allocation_box (self, &alloc);
clutter_actor_box_get_size (&alloc, &old_width, &old_height);
/* the current allocation */
clutter_actor_box_get_size (box, &width, &height);
/* the current Stage implementation size */
_clutter_stage_window_get_geometry (priv->impl, &window_size);
/* if the stage is fixed size (for instance, it's using a EGL framebuffer)
* then we simply ignore any allocation request and override the
* allocation chain - because we cannot forcibly change the size of the
* stage window.
*/
if (!clutter_feature_available (CLUTTER_FEATURE_STAGE_STATIC))
{
CLUTTER_NOTE (LAYOUT,
"Following allocation to %.2fx%.2f (absolute origin %s)",
width, height,
(flags & CLUTTER_ABSOLUTE_ORIGIN_CHANGED)
? "changed"
: "not changed");
clutter_actor_set_allocation (self, box,
flags | CLUTTER_DELEGATE_LAYOUT);
/* Ensure the window is sized correctly */
if (!priv->is_fullscreen)
{
if (priv->min_size_changed)
{
gfloat min_width, min_height;
gboolean min_width_set, min_height_set;
g_object_get (G_OBJECT (self),
"min-width", &min_width,
"min-width-set", &min_width_set,
"min-height", &min_height,
"min-height-set", &min_height_set,
NULL);
if (!min_width_set)
min_width = 1;
if (!min_height_set)
min_height = 1;
if (width < min_width)
width = min_width;
if (height < min_height)
height = min_height;
priv->min_size_changed = FALSE;
}
if (window_size.width != CLUTTER_NEARBYINT (width) ||
window_size.height != CLUTTER_NEARBYINT (height))
{
_clutter_stage_window_resize (priv->impl,
CLUTTER_NEARBYINT (width),
CLUTTER_NEARBYINT (height));
}
}
}
else
{
ClutterActorBox override = { 0, };
/* override the passed allocation */
override.x1 = 0;
override.y1 = 0;
override.x2 = window_size.width;
override.y2 = window_size.height;
CLUTTER_NOTE (LAYOUT,
"Overriding original allocation of %.2fx%.2f "
"with %.2fx%.2f (absolute origin %s)",
width, height,
override.x2, override.y2,
(flags & CLUTTER_ABSOLUTE_ORIGIN_CHANGED)
? "changed"
: "not changed");
/* and store the overridden allocation */
clutter_actor_set_allocation (self, &override,
flags | CLUTTER_DELEGATE_LAYOUT);
}
/* XXX: Until Cogl becomes fully responsible for backend windows
* Clutter need to manually keep it informed of the current window
* size. We do this after the allocation above so that the stage
* window has a chance to update the window size based on the
* allocation.
*/
_clutter_stage_window_get_geometry (priv->impl, &window_size);
scale_factor = _clutter_stage_window_get_scale_factor (priv->impl);
window_size.width *= scale_factor;
window_size.height *= scale_factor;
cogl_onscreen_clutter_backend_set_size (window_size.width,
window_size.height);
/* reset the viewport if the allocation effectively changed */
clutter_actor_get_allocation_box (self, &alloc);
clutter_actor_box_get_size (&alloc, &new_width, &new_height);
if (CLUTTER_NEARBYINT (old_width) != CLUTTER_NEARBYINT (new_width) ||
CLUTTER_NEARBYINT (old_height) != CLUTTER_NEARBYINT (new_height))
{
int real_width = CLUTTER_NEARBYINT (new_width);
int real_height = CLUTTER_NEARBYINT (new_height);
_clutter_stage_set_viewport (CLUTTER_STAGE (self),
0, 0,
real_width,
real_height);
/* Note: we don't assume that set_viewport will queue a full redraw
* since it may bail-out early if something preemptively set the
* viewport before the stage was really allocated its new size.
*/
queue_full_redraw (CLUTTER_STAGE (self));
}
}
typedef struct _Vector4
{
float x, y, z, w;
} Vector4;
static void
_cogl_util_get_eye_planes_for_screen_poly (float *polygon,
int n_vertices,
float *viewport,
const CoglMatrix *projection,
const CoglMatrix *inverse_project,
ClutterPlane *planes)
{
float Wc;
Vector4 *tmp_poly;
ClutterPlane *plane;
int i;
float b[3];
float c[3];
int count;
tmp_poly = g_alloca (sizeof (Vector4) * n_vertices * 2);
#define DEPTH -50
/* Determine W in clip-space (Wc) for a point (0, 0, DEPTH, 1)
*
* Note: the depth could be anything except 0.
*
* We will transform the polygon into clip coordinates using this
* depth and then into eye coordinates. Our clip planes will be
* defined by triangles that extend between points of the polygon at
* DEPTH and corresponding points of the same polygon at DEPTH * 2.
*
* NB: Wc defines the position of the clip planes in clip
* coordinates. Given a screen aligned cross section through the
* frustum; coordinates range from [-Wc,Wc] left to right on the
* x-axis and [Wc,-Wc] top to bottom on the y-axis.
*/
Wc = DEPTH * projection->wz + projection->ww;
#define CLIP_X(X) ((((float)X - viewport[0]) * (2.0 / viewport[2])) - 1) * Wc
#define CLIP_Y(Y) ((((float)Y - viewport[1]) * (2.0 / viewport[3])) - 1) * -Wc
for (i = 0; i < n_vertices; i++)
{
tmp_poly[i].x = CLIP_X (polygon[i * 2]);
tmp_poly[i].y = CLIP_Y (polygon[i * 2 + 1]);
tmp_poly[i].z = DEPTH;
tmp_poly[i].w = Wc;
}
Wc = DEPTH * 2 * projection->wz + projection->ww;
/* FIXME: technically we don't need to project all of the points
* twice, it would be enough project every other point since
* we can share points in this set to define the plane vectors. */
for (i = 0; i < n_vertices; i++)
{
tmp_poly[n_vertices + i].x = CLIP_X (polygon[i * 2]);
tmp_poly[n_vertices + i].y = CLIP_Y (polygon[i * 2 + 1]);
tmp_poly[n_vertices + i].z = DEPTH * 2;
tmp_poly[n_vertices + i].w = Wc;
}
#undef CLIP_X
#undef CLIP_Y
cogl_matrix_project_points (inverse_project,
4,
sizeof (Vector4),
tmp_poly,
sizeof (Vector4),
tmp_poly,
n_vertices * 2);
/* XXX: It's quite ugly that we end up with these casts between
* Vector4 types and CoglVector3s, it might be better if the
* cogl_vector APIs just took pointers to floats.
*/
count = n_vertices - 1;
for (i = 0; i < count; i++)
{
plane = &planes[i];
memcpy (plane->v0, tmp_poly + i, sizeof (float) * 3);
memcpy (b, tmp_poly + n_vertices + i, sizeof (float) * 3);
memcpy (c, tmp_poly + n_vertices + i + 1, sizeof (float) * 3);
cogl_vector3_subtract (b, b, plane->v0);
cogl_vector3_subtract (c, c, plane->v0);
cogl_vector3_cross_product (plane->n, b, c);
cogl_vector3_normalize (plane->n);
}
plane = &planes[n_vertices - 1];
memcpy (plane->v0, tmp_poly + 0, sizeof (float) * 3);
memcpy (b, tmp_poly + (2 * n_vertices - 1), sizeof (float) * 3);
memcpy (c, tmp_poly + n_vertices, sizeof (float) * 3);
cogl_vector3_subtract (b, b, plane->v0);
cogl_vector3_subtract (c, c, plane->v0);
cogl_vector3_cross_product (plane->n, b, c);
cogl_vector3_normalize (plane->n);
}
static void
_clutter_stage_update_active_framebuffer (ClutterStage *stage)
{
ClutterStagePrivate *priv = stage->priv;
/* We track the CoglFramebuffer that corresponds to the stage itself
* so, for example, we can disable culling when rendering to an
* offscreen framebuffer.
*/
priv->active_framebuffer =
_clutter_stage_window_get_active_framebuffer (priv->impl);
if (!priv->active_framebuffer)
priv->active_framebuffer = cogl_get_draw_framebuffer ();
}
/* This provides a common point of entry for painting the scenegraph
* for picking or painting...
*
* XXX: Instead of having a toplevel 2D clip region, it might be
* better to have a clip volume within the view frustum. This could
* allow us to avoid projecting actors into window coordinates to
* be able to cull them.
*/
void
_clutter_stage_do_paint (ClutterStage *stage,
const cairo_rectangle_int_t *clip)
{
ClutterStagePrivate *priv = stage->priv;
float clip_poly[8];
float viewport[4];
cairo_rectangle_int_t geom;
int window_scale;
if (priv->impl == NULL)
return;
_clutter_stage_window_get_geometry (priv->impl, &geom);
window_scale = _clutter_stage_window_get_scale_factor (priv->impl);
viewport[0] = priv->viewport[0] * window_scale;
viewport[1] = priv->viewport[1] * window_scale;
viewport[2] = priv->viewport[2] * window_scale;
viewport[3] = priv->viewport[3] * window_scale;
if (clip)
{
clip_poly[0] = MAX (clip->x * window_scale, 0);
clip_poly[1] = MAX (clip->y * window_scale, 0);
clip_poly[2] = MIN ((clip->x + clip->width) * window_scale, geom.width * window_scale);
clip_poly[3] = clip_poly[1];
clip_poly[4] = clip_poly[2];
clip_poly[5] = MIN ((clip->y + clip->height) * window_scale, geom.height * window_scale);
clip_poly[6] = clip_poly[0];
clip_poly[7] = clip_poly[5];
}
else
{
clip_poly[0] = 0;
clip_poly[1] = 0;
clip_poly[2] = geom.width * window_scale;
clip_poly[3] = 0;
clip_poly[4] = geom.width * window_scale;
clip_poly[5] = geom.height * window_scale;
clip_poly[6] = 0;
clip_poly[7] = geom.height * window_scale;
}
CLUTTER_NOTE (CLIPPING, "Setting stage clip too: "
"x=%f, y=%f, width=%f, height=%f",
clip_poly[0], clip_poly[1],
clip_poly[2] - clip_poly[0],
clip_poly[5] - clip_poly[1]);
_cogl_util_get_eye_planes_for_screen_poly (clip_poly,
4,
viewport,
&priv->projection,
&priv->inverse_projection,
priv->current_clip_planes);
_clutter_stage_paint_volume_stack_free_all (stage);
_clutter_stage_update_active_framebuffer (stage);
clutter_actor_paint (CLUTTER_ACTOR (stage));
g_signal_emit (stage, stage_signals[AFTER_PAINT], 0);
}
/* If we don't implement this here, we get the paint function
* from the deprecated clutter-group class, which doesn't
* respect the Z order as it uses our empty sort_depth_order.
*/
static void
clutter_stage_paint (ClutterActor *self)
{
ClutterActorIter iter;
ClutterActor *child;
clutter_actor_iter_init (&iter, self);
while (clutter_actor_iter_next (&iter, &child))
clutter_actor_paint (child);
}
static void
clutter_stage_pick (ClutterActor *self,
const ClutterColor *color)
{
ClutterActorIter iter;
ClutterActor *child;
/* Note: we don't chain up to our parent as we don't want any geometry
* emitted for the stage itself. The stage's pick id is effectively handled
* by the call to cogl_clear done in clutter-main.c:_clutter_do_pick_async()
*/
clutter_actor_iter_init (&iter, self);
while (clutter_actor_iter_next (&iter, &child))
clutter_actor_paint (child);
}
static gboolean
clutter_stage_get_paint_volume (ClutterActor *self,
ClutterPaintVolume *volume)
{
/* Returning False effectively means Clutter has to assume it covers
* everything... */
return FALSE;
}
static void
clutter_stage_realize (ClutterActor *self)
{
ClutterStagePrivate *priv = CLUTTER_STAGE (self)->priv;
gboolean is_realized;
/* Make sure the viewport and projection matrix are valid for the
* first paint (which will likely occur before the ConfigureNotify
* is received)
*/
priv->dirty_viewport = TRUE;
priv->dirty_projection = TRUE;
g_assert (priv->impl != NULL);
is_realized = _clutter_stage_window_realize (priv->impl);
/* ensure that the stage is using the context if the
* realization sequence was successful
*/
if (is_realized)
{
ClutterBackend *backend = clutter_get_default_backend ();
/* We want to select the context without calling
clutter_backend_ensure_context so that it doesn't call any
Cogl functions. Otherwise it would create the Cogl context
before we get a chance to check whether the GL version is
valid */
_clutter_backend_ensure_context_internal (backend, CLUTTER_STAGE (self));
}
else
CLUTTER_ACTOR_UNSET_FLAGS (self, CLUTTER_ACTOR_REALIZED);
}
static void
clutter_stage_unrealize (ClutterActor *self)
{
ClutterStagePrivate *priv = CLUTTER_STAGE (self)->priv;
/* and then unrealize the implementation */
g_assert (priv->impl != NULL);
_clutter_stage_window_unrealize (priv->impl);
CLUTTER_ACTOR_UNSET_FLAGS (self, CLUTTER_ACTOR_REALIZED);
clutter_stage_ensure_current (CLUTTER_STAGE (self));
}
static void
clutter_stage_show_all (ClutterActor *self)
{
ClutterActorIter iter;
ClutterActor *child;
/* we don't do a recursive show_all(), to maintain the old
* invariants from ClutterGroup
*/
clutter_actor_iter_init (&iter, self);
while (clutter_actor_iter_next (&iter, &child))
clutter_actor_show (child);
clutter_actor_show (self);
}
static void
clutter_stage_show (ClutterActor *self)
{
ClutterStagePrivate *priv = CLUTTER_STAGE (self)->priv;
CLUTTER_ACTOR_CLASS (clutter_stage_parent_class)->show (self);
/* Possibly do an allocation run so that the stage will have the
right size before we map it */
_clutter_stage_maybe_relayout (self);
g_assert (priv->impl != NULL);
_clutter_stage_window_show (priv->impl, TRUE);
}
static void
clutter_stage_hide_all (ClutterActor *self)
{
ClutterActorIter iter;
ClutterActor *child;
clutter_actor_hide (self);
/* we don't do a recursive hide_all(), to maintain the old invariants
* from ClutterGroup
*/
clutter_actor_iter_init (&iter, self);
while (clutter_actor_iter_next (&iter, &child))
clutter_actor_hide (child);
}
static void
clutter_stage_hide (ClutterActor *self)
{
ClutterStagePrivate *priv = CLUTTER_STAGE (self)->priv;
g_assert (priv->impl != NULL);
_clutter_stage_window_hide (priv->impl);
CLUTTER_ACTOR_CLASS (clutter_stage_parent_class)->hide (self);
}
static void
clutter_stage_emit_key_focus_event (ClutterStage *stage,
gboolean focus_in)
{
ClutterStagePrivate *priv = stage->priv;
if (priv->key_focused_actor == NULL)
return;
if (focus_in)
g_signal_emit_by_name (priv->key_focused_actor, "key-focus-in");
else
g_signal_emit_by_name (priv->key_focused_actor, "key-focus-out");
g_object_notify (G_OBJECT (stage), "key-focus");
}
static void
clutter_stage_real_activate (ClutterStage *stage)
{
clutter_stage_emit_key_focus_event (stage, TRUE);
}
static void
clutter_stage_real_deactivate (ClutterStage *stage)
{
clutter_stage_emit_key_focus_event (stage, FALSE);
}
static void
clutter_stage_real_fullscreen (ClutterStage *stage)
{
ClutterStagePrivate *priv = stage->priv;
cairo_rectangle_int_t geom;
ClutterActorBox box;
/* we need to force an allocation here because the size
* of the stage might have been changed by the backend
*
* this is a really bad solution to the issues caused by
* the fact that fullscreening the stage on the X11 backends
* is really an asynchronous operation
*/
_clutter_stage_window_get_geometry (priv->impl, &geom);
box.x1 = 0;
box.y1 = 0;
box.x2 = geom.width;
box.y2 = geom.height;
/* we need to blow the caching on the Stage size, given that
* we're about to force an allocation, because if anything
* ends up querying the size of the stage during the allocate()
* call, like constraints or signal handlers, we'll get into an
* inconsistent state: the stage will report the old cached size,
* but the allocation will be updated anyway.
*/
clutter_actor_set_size (CLUTTER_ACTOR (stage), -1.0, -1.0);
clutter_actor_allocate (CLUTTER_ACTOR (stage),
&box,
CLUTTER_ALLOCATION_NONE);
}
void
_clutter_stage_queue_event (ClutterStage *stage,
ClutterEvent *event,
gboolean copy_event)
{
ClutterStagePrivate *priv;
gboolean first_event;
ClutterInputDevice *device;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
priv = stage->priv;
first_event = priv->event_queue->length == 0;
if (copy_event)
event = clutter_event_copy (event);
g_queue_push_tail (priv->event_queue, event);
if (first_event)
{
ClutterMasterClock *master_clock = _clutter_master_clock_get_default ();
_clutter_master_clock_start_running (master_clock);
_clutter_stage_schedule_update (stage);
}
/* if needed, update the state of the input device of the event.
* we do it here to avoid calling the same code from every backend
* event processing function
*/
device = clutter_event_get_device (event);
if (device != NULL)
{
ClutterModifierType event_state = clutter_event_get_state (event);
ClutterEventSequence *sequence = clutter_event_get_event_sequence (event);
guint32 event_time = clutter_event_get_time (event);
gfloat event_x, event_y;
clutter_event_get_coords (event, &event_x, &event_y);
_clutter_input_device_set_coords (device, sequence, event_x, event_y, stage);
_clutter_input_device_set_state (device, event_state);
_clutter_input_device_set_time (device, event_time);
}
}
gboolean
_clutter_stage_has_queued_events (ClutterStage *stage)
{
ClutterStagePrivate *priv;
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), FALSE);
priv = stage->priv;
return priv->event_queue->length > 0;
}
void
_clutter_stage_process_queued_events (ClutterStage *stage)
{
ClutterStagePrivate *priv;
GList *events, *l;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
priv = stage->priv;
if (priv->event_queue->length == 0)
return;
/* In case the stage gets destroyed during event processing */
g_object_ref (stage);
/* Steal events before starting processing to avoid reentrancy
* issues */
events = priv->event_queue->head;
priv->event_queue->head = NULL;
priv->event_queue->tail = NULL;
priv->event_queue->length = 0;
for (l = events; l != NULL; l = l->next)
{
ClutterEvent *event;
ClutterEvent *next_event;
ClutterInputDevice *device;
ClutterInputDevice *next_device;
gboolean check_device = FALSE;
event = l->data;
next_event = l->next ? l->next->data : NULL;
device = clutter_event_get_device (event);
if (next_event != NULL)
next_device = clutter_event_get_device (next_event);
else
next_device = NULL;
if (device != NULL && next_device != NULL)
check_device = TRUE;
/* Skip consecutive motion events coming from the same device */
if (priv->throttle_motion_events && next_event != NULL)
{
if (event->type == CLUTTER_MOTION &&
(next_event->type == CLUTTER_MOTION ||
next_event->type == CLUTTER_LEAVE) &&
(!check_device || (device == next_device)))
{
CLUTTER_NOTE (EVENT,
"Omitting motion event at %d, %d",
(int) event->motion.x,
(int) event->motion.y);
goto next_event;
}
else if (event->type == CLUTTER_TOUCH_UPDATE &&
next_event->type == CLUTTER_TOUCH_UPDATE &&
event->touch.sequence == next_event->touch.sequence &&
(!check_device || (device == next_device)))
{
CLUTTER_NOTE (EVENT,
"Omitting touch update event at %d, %d",
(int) event->touch.x,
(int) event->touch.y);
goto next_event;
}
}
_clutter_process_event (event);
next_event:
clutter_event_free (event);
}
g_list_free (events);
g_object_unref (stage);
}
/**
* _clutter_stage_needs_update:
* @stage: A #ClutterStage
*
* Determines if _clutter_stage_do_update() needs to be called.
*
* Return value: %TRUE if the stage need layout or painting
*/
gboolean
_clutter_stage_needs_update (ClutterStage *stage)
{
ClutterStagePrivate *priv;
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), FALSE);
priv = stage->priv;
return priv->relayout_pending || priv->redraw_pending;
}
void
_clutter_stage_maybe_relayout (ClutterActor *actor)
{
ClutterStage *stage = CLUTTER_STAGE (actor);
ClutterStagePrivate *priv = stage->priv;
gfloat natural_width, natural_height;
ClutterActorBox box = { 0, };
if (!priv->relayout_pending)
return;
/* avoid reentrancy */
if (!CLUTTER_ACTOR_IN_RELAYOUT (stage))
{
priv->relayout_pending = FALSE;
CLUTTER_NOTE (ACTOR, "Recomputing layout");
CLUTTER_SET_PRIVATE_FLAGS (stage, CLUTTER_IN_RELAYOUT);
natural_width = natural_height = 0;
clutter_actor_get_preferred_size (CLUTTER_ACTOR (stage),
NULL, NULL,
&natural_width, &natural_height);
box.x1 = 0;
box.y1 = 0;
box.x2 = natural_width;
box.y2 = natural_height;
CLUTTER_NOTE (ACTOR, "Allocating (0, 0 - %d, %d) for the stage",
(int) natural_width,
(int) natural_height);
clutter_actor_allocate (CLUTTER_ACTOR (stage),
&box, CLUTTER_ALLOCATION_NONE);
CLUTTER_UNSET_PRIVATE_FLAGS (stage, CLUTTER_IN_RELAYOUT);
}
}
static void
clutter_stage_do_redraw (ClutterStage *stage)
{
ClutterBackend *backend = clutter_get_default_backend ();
ClutterActor *actor = CLUTTER_ACTOR (stage);
ClutterStagePrivate *priv = stage->priv;
if (CLUTTER_ACTOR_IN_DESTRUCTION (stage))
return;
if (priv->impl == NULL)
return;
CLUTTER_NOTE (PAINT, "Redraw started for stage '%s'[%p]",
_clutter_actor_get_debug_name (actor),
stage);
_clutter_backend_ensure_context (backend, stage);
if (_clutter_context_get_show_fps ())
{
if (priv->fps_timer == NULL)
priv->fps_timer = g_timer_new ();
}
_clutter_stage_maybe_setup_viewport (stage);
_clutter_stage_window_redraw (priv->impl);
if (_clutter_context_get_show_fps ())
{
priv->timer_n_frames += 1;
if (g_timer_elapsed (priv->fps_timer, NULL) >= 1.0)
{
g_print ("*** FPS for %s: %i ***\n",
_clutter_actor_get_debug_name (actor),
priv->timer_n_frames);
priv->timer_n_frames = 0;
g_timer_start (priv->fps_timer);
}
}
CLUTTER_NOTE (PAINT, "Redraw finished for stage '%s'[%p]",
_clutter_actor_get_debug_name (actor),
stage);
}
/**
* _clutter_stage_do_update:
* @stage: A #ClutterStage
*
* Handles per-frame layout and repaint for the stage.
*
* Return value: %TRUE if the stage was updated
*/
gboolean
_clutter_stage_do_update (ClutterStage *stage)
{
ClutterStagePrivate *priv = stage->priv;
/* if the stage is being destroyed, or if the destruction already
* happened and we don't have an StageWindow any more, then we
* should bail out
*/
if (CLUTTER_ACTOR_IN_DESTRUCTION (stage) || priv->impl == NULL)
return FALSE;
if (!CLUTTER_ACTOR_IS_REALIZED (stage))
return FALSE;
/* NB: We need to ensure we have an up to date layout *before* we
* check or clear the pending redraws flag since a relayout may
* queue a redraw.
*/
_clutter_stage_maybe_relayout (CLUTTER_ACTOR (stage));
if (!priv->redraw_pending)
return FALSE;
clutter_stage_maybe_finish_queue_redraws (stage);
clutter_stage_do_redraw (stage);
/* reset the guard, so that new redraws are possible */
priv->redraw_pending = FALSE;
#ifdef CLUTTER_ENABLE_DEBUG
if (priv->redraw_count > 0)
{
CLUTTER_NOTE (SCHEDULER, "Queued %lu redraws during the last cycle",
priv->redraw_count);
priv->redraw_count = 0;
}
#endif /* CLUTTER_ENABLE_DEBUG */
return TRUE;
}
static void
clutter_stage_real_queue_relayout (ClutterActor *self)
{
ClutterStage *stage = CLUTTER_STAGE (self);
ClutterStagePrivate *priv = stage->priv;
ClutterActorClass *parent_class;
if (!priv->relayout_pending)
{
_clutter_stage_schedule_update (stage);
priv->relayout_pending = TRUE;
}
/* chain up */
parent_class = CLUTTER_ACTOR_CLASS (clutter_stage_parent_class);
parent_class->queue_relayout (self);
}
static void
clutter_stage_real_queue_redraw (ClutterActor *actor,
ClutterActor *leaf)
{
ClutterStage *stage = CLUTTER_STAGE (actor);
ClutterStageWindow *stage_window;
ClutterPaintVolume *redraw_clip;
ClutterActorBox bounding_box;
ClutterActorBox intersection_box;
cairo_rectangle_int_t geom, stage_clip;
if (CLUTTER_ACTOR_IN_DESTRUCTION (actor))
return;
/* If the backend can't do anything with redraw clips (e.g. it already knows
* it needs to redraw everything anyway) then don't spend time transforming
* any clip volume into stage coordinates... */
stage_window = _clutter_stage_get_window (stage);
if (stage_window == NULL)
return;
if (_clutter_stage_window_ignoring_redraw_clips (stage_window))
{
_clutter_stage_window_add_redraw_clip (stage_window, NULL);
return;
}
/* Convert the clip volume into stage coordinates and then into an
* axis aligned stage coordinates bounding box...
*/
redraw_clip = _clutter_actor_get_queue_redraw_clip (leaf);
if (redraw_clip == NULL)
{
_clutter_stage_window_add_redraw_clip (stage_window, NULL);
return;
}
if (redraw_clip->is_empty)
return;
_clutter_paint_volume_get_stage_paint_box (redraw_clip,
stage,
&bounding_box);
_clutter_stage_window_get_geometry (stage_window, &geom);
intersection_box.x1 = MAX (bounding_box.x1, 0);
intersection_box.y1 = MAX (bounding_box.y1, 0);
intersection_box.x2 = MIN (bounding_box.x2, geom.width);
intersection_box.y2 = MIN (bounding_box.y2, geom.height);
/* There is no need to track degenerate/empty redraw clips */
if (intersection_box.x2 <= intersection_box.x1 ||
intersection_box.y2 <= intersection_box.y1)
return;
/* when converting to integer coordinates make sure we round the edges of the
* clip rectangle outwards... */
stage_clip.x = intersection_box.x1;
stage_clip.y = intersection_box.y1;
stage_clip.width = intersection_box.x2 - stage_clip.x;
stage_clip.height = intersection_box.y2 - stage_clip.y;
_clutter_stage_window_add_redraw_clip (stage_window, &stage_clip);
}
gboolean
_clutter_stage_has_full_redraw_queued (ClutterStage *stage)
{
ClutterStageWindow *stage_window = _clutter_stage_get_window (stage);
if (CLUTTER_ACTOR_IN_DESTRUCTION (stage) || stage_window == NULL)
return FALSE;
if (stage->priv->redraw_pending &&
!_clutter_stage_window_has_redraw_clips (stage_window))
return TRUE;
else
return FALSE;
}
/**
* clutter_stage_get_redraw_clip_bounds:
* @stage: A #ClutterStage
* @clip: (out caller-allocates): Return location for the clip bounds
*
* Gets the bounds of the current redraw for @stage in stage pixel
* coordinates. E.g., if only a single actor has queued a redraw then
* Clutter may redraw the stage with a clip so that it doesn't have to
* paint every pixel in the stage. This function would then return the
* bounds of that clip. An application can use this information to
* avoid some extra work if it knows that some regions of the stage
* aren't going to be painted. This should only be called while the
* stage is being painted. If there is no current redraw clip then
* this function will set @clip to the full extents of the stage.
*
* Since: 1.8
*/
void
clutter_stage_get_redraw_clip_bounds (ClutterStage *stage,
cairo_rectangle_int_t *clip)
{
ClutterStagePrivate *priv;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
g_return_if_fail (clip != NULL);
priv = stage->priv;
if (!_clutter_stage_window_get_redraw_clip_bounds (priv->impl, clip))
{
/* Set clip to the full extents of the stage */
_clutter_stage_window_get_geometry (priv->impl, clip);
}
}
static void
read_pixels_to_file (char *filename_stem,
int x,
int y,
int width,
int height)
{
guint8 *data;
cairo_surface_t *surface;
static int read_count = 0;
char *filename = g_strdup_printf ("%s-%05d.png",
filename_stem,
read_count);
data = g_malloc (4 * width * height);
cogl_read_pixels (x, y, width, height,
COGL_READ_PIXELS_COLOR_BUFFER,
CLUTTER_CAIRO_FORMAT_ARGB32,
data);
surface = cairo_image_surface_create_for_data (data, CAIRO_FORMAT_RGB24,
width, height,
width * 4);
cairo_surface_write_to_png (surface, filename);
cairo_surface_destroy (surface);
g_free (data);
g_free (filename);
read_count++;
}
ClutterActor *
_clutter_stage_do_pick (ClutterStage *stage,
gint x,
gint y,
ClutterPickMode mode)
{
ClutterActor *actor = CLUTTER_ACTOR (stage);
ClutterStagePrivate *priv = stage->priv;
ClutterMainContext *context;
guchar pixel[4] = { 0xff, 0xff, 0xff, 0xff };
CoglColor stage_pick_id;
gboolean dither_enabled_save;
ClutterActor *retval;
CoglFramebuffer *fb;
gint dirty_x;
gint dirty_y;
gint read_x;
gint read_y;
float stage_width, stage_height;
int window_scale;
priv = stage->priv;
if (CLUTTER_ACTOR_IN_DESTRUCTION (stage))
return actor;
if (G_UNLIKELY (clutter_pick_debug_flags & CLUTTER_DEBUG_NOP_PICKING))
return actor;
if (G_UNLIKELY (priv->impl == NULL))
return actor;
clutter_actor_get_size (CLUTTER_ACTOR (stage), &stage_width, &stage_height);
if (x < 0 || x >= stage_width || y < 0 || y >= stage_height)
return actor;
context = _clutter_context_get_default ();
clutter_stage_ensure_current (stage);
window_scale = _clutter_stage_window_get_scale_factor (priv->impl);
fb = cogl_get_draw_framebuffer ();
_clutter_backend_ensure_context (context->backend, stage);
/* needed for when a context switch happens */
_clutter_stage_maybe_setup_viewport (stage);
_clutter_stage_window_get_dirty_pixel (priv->impl, &dirty_x, &dirty_y);
if (G_LIKELY (!(clutter_pick_debug_flags & CLUTTER_DEBUG_DUMP_PICK_BUFFERS)))
cogl_framebuffer_push_scissor_clip (fb, dirty_x * window_scale, dirty_y * window_scale, 1, 1);
cogl_set_viewport (priv->viewport[0] * window_scale - x * window_scale + dirty_x * window_scale,
priv->viewport[1] * window_scale - y * window_scale + dirty_y * window_scale,
priv->viewport[2] * window_scale,
priv->viewport[3] * window_scale);
read_x = dirty_x * window_scale;
read_y = dirty_y * window_scale;
CLUTTER_NOTE (PICK, "Performing pick at %i,%i", x, y);
cogl_color_init_from_4ub (&stage_pick_id, 255, 255, 255, 255);
cogl_clear (&stage_pick_id, COGL_BUFFER_BIT_COLOR | COGL_BUFFER_BIT_DEPTH);
/* Disable dithering (if any) when doing the painting in pick mode */
dither_enabled_save = cogl_framebuffer_get_dither_enabled (fb);
cogl_framebuffer_set_dither_enabled (fb, FALSE);
/* Render the entire scence in pick mode - just single colored silhouette's
* are drawn offscreen (as we never swap buffers)
*/
context->pick_mode = mode;
_clutter_stage_do_paint (stage, NULL);
context->pick_mode = CLUTTER_PICK_NONE;
/* Read the color of the screen co-ords pixel. RGBA_8888_PRE is used
even though we don't care about the alpha component because under
GLES this is the only format that is guaranteed to work so Cogl
will end up having to do a conversion if any other format is
used. The format is requested as pre-multiplied because Cogl
assumes that all pixels in the framebuffer are premultiplied so
it avoids a conversion. */
cogl_read_pixels (read_x, read_y, 1, 1,
COGL_READ_PIXELS_COLOR_BUFFER,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
pixel);
if (G_UNLIKELY (clutter_pick_debug_flags & CLUTTER_DEBUG_DUMP_PICK_BUFFERS))
{
char *file_name =
g_strconcat ("pick-buffer-",
_clutter_actor_get_debug_name (actor),
NULL);
read_pixels_to_file (file_name, 0, 0, stage_width, stage_height);
g_free (file_name);
}
/* Restore whether GL_DITHER was enabled */
cogl_framebuffer_set_dither_enabled (fb, dither_enabled_save);
if (G_LIKELY (!(clutter_pick_debug_flags & CLUTTER_DEBUG_DUMP_PICK_BUFFERS)))
cogl_framebuffer_pop_clip (fb);
_clutter_stage_dirty_viewport (stage);
if (pixel[0] == 0xff && pixel[1] == 0xff && pixel[2] == 0xff)
retval = actor;
else
{
guint32 id_ = _clutter_pixel_to_id (pixel);
retval = _clutter_stage_get_actor_by_pick_id (stage, id_);
}
return retval;
}
static gboolean
clutter_stage_real_delete_event (ClutterStage *stage,
ClutterEvent *event)
{
if (stage_is_default (stage))
clutter_main_quit ();
else
clutter_actor_destroy (CLUTTER_ACTOR (stage));
return CLUTTER_EVENT_STOP;
}
static void
clutter_stage_real_apply_transform (ClutterActor *stage,
CoglMatrix *matrix)
{
ClutterStagePrivate *priv = CLUTTER_STAGE (stage)->priv;
/* FIXME: we probably shouldn't be explicitly reseting the matrix
* here... */
cogl_matrix_init_identity (matrix);
cogl_matrix_multiply (matrix, matrix, &priv->view);
}
static void
clutter_stage_constructed (GObject *gobject)
{
ClutterStage *self = CLUTTER_STAGE (gobject);
ClutterStageManager *stage_manager;
stage_manager = clutter_stage_manager_get_default ();
/* this will take care to sinking the floating reference */
_clutter_stage_manager_add_stage (stage_manager, self);
/* if this stage has been created on a backend that does not
* support multiple stages then it becomes the default stage
* as well; any other attempt at creating a ClutterStage will
* fail.
*/
if (!clutter_feature_available (CLUTTER_FEATURE_STAGE_MULTIPLE))
{
if (G_UNLIKELY (clutter_stage_manager_get_default_stage (stage_manager) != NULL))
{
g_error ("Unable to create another stage: the backend of "
"type '%s' does not support multiple stages. Use "
"clutter_stage_manager_get_default_stage() instead "
"to access the stage singleton.",
G_OBJECT_TYPE_NAME (clutter_get_default_backend ()));
}
_clutter_stage_manager_set_default_stage (stage_manager, self);
}
G_OBJECT_CLASS (clutter_stage_parent_class)->constructed (gobject);
}
static void
clutter_stage_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
ClutterStage *stage = CLUTTER_STAGE (object);
switch (prop_id)
{
case PROP_COLOR:
clutter_actor_set_background_color (CLUTTER_ACTOR (stage),
clutter_value_get_color (value));
break;
case PROP_OFFSCREEN:
if (g_value_get_boolean (value))
g_warning ("Offscreen stages are currently not supported\n");
break;
case PROP_CURSOR_VISIBLE:
if (g_value_get_boolean (value))
clutter_stage_show_cursor (stage);
else
clutter_stage_hide_cursor (stage);
break;
case PROP_PERSPECTIVE:
clutter_stage_set_perspective (stage, g_value_get_boxed (value));
break;
case PROP_TITLE:
clutter_stage_set_title (stage, g_value_get_string (value));
break;
case PROP_USER_RESIZABLE:
clutter_stage_set_user_resizable (stage, g_value_get_boolean (value));
break;
case PROP_USE_FOG:
clutter_stage_set_use_fog (stage, g_value_get_boolean (value));
break;
case PROP_FOG:
clutter_stage_set_fog (stage, g_value_get_boxed (value));
break;
case PROP_USE_ALPHA:
clutter_stage_set_use_alpha (stage, g_value_get_boolean (value));
break;
case PROP_KEY_FOCUS:
clutter_stage_set_key_focus (stage, g_value_get_object (value));
break;
case PROP_NO_CLEAR_HINT:
clutter_stage_set_no_clear_hint (stage, g_value_get_boolean (value));
break;
case PROP_ACCEPT_FOCUS:
clutter_stage_set_accept_focus (stage, g_value_get_boolean (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
clutter_stage_get_property (GObject *gobject,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
ClutterStagePrivate *priv = CLUTTER_STAGE (gobject)->priv;
switch (prop_id)
{
case PROP_COLOR:
{
ClutterColor bg_color;
clutter_actor_get_background_color (CLUTTER_ACTOR (gobject),
&bg_color);
clutter_value_set_color (value, &bg_color);
}
break;
case PROP_OFFSCREEN:
g_value_set_boolean (value, FALSE);
break;
case PROP_FULLSCREEN_SET:
g_value_set_boolean (value, priv->is_fullscreen);
break;
case PROP_CURSOR_VISIBLE:
g_value_set_boolean (value, priv->is_cursor_visible);
break;
case PROP_PERSPECTIVE:
g_value_set_boxed (value, &priv->perspective);
break;
case PROP_TITLE:
g_value_set_string (value, priv->title);
break;
case PROP_USER_RESIZABLE:
g_value_set_boolean (value, priv->is_user_resizable);
break;
case PROP_USE_FOG:
g_value_set_boolean (value, priv->use_fog);
break;
case PROP_FOG:
g_value_set_boxed (value, &priv->fog);
break;
case PROP_USE_ALPHA:
g_value_set_boolean (value, priv->use_alpha);
break;
case PROP_KEY_FOCUS:
g_value_set_object (value, priv->key_focused_actor);
break;
case PROP_NO_CLEAR_HINT:
{
gboolean hint =
(priv->stage_hints & CLUTTER_STAGE_NO_CLEAR_ON_PAINT) != 0;
g_value_set_boolean (value, hint);
}
break;
case PROP_ACCEPT_FOCUS:
g_value_set_boolean (value, priv->accept_focus);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
break;
}
}
static void
clutter_stage_dispose (GObject *object)
{
ClutterStage *stage = CLUTTER_STAGE (object);
ClutterStagePrivate *priv = stage->priv;
ClutterStageManager *stage_manager;
clutter_actor_hide (CLUTTER_ACTOR (object));
_clutter_clear_events_queue_for_stage (stage);
if (priv->impl != NULL)
{
CLUTTER_NOTE (BACKEND, "Disposing of the stage implementation");
if (CLUTTER_ACTOR_IS_REALIZED (object))
_clutter_stage_window_unrealize (priv->impl);
g_object_unref (priv->impl);
priv->impl = NULL;
}
clutter_actor_destroy_all_children (CLUTTER_ACTOR (object));
g_list_free_full (priv->pending_queue_redraws,
(GDestroyNotify) free_queue_redraw_entry);
priv->pending_queue_redraws = NULL;
/* this will release the reference on the stage */
stage_manager = clutter_stage_manager_get_default ();
_clutter_stage_manager_remove_stage (stage_manager, stage);
G_OBJECT_CLASS (clutter_stage_parent_class)->dispose (object);
}
static void
clutter_stage_finalize (GObject *object)
{
ClutterStage *stage = CLUTTER_STAGE (object);
ClutterStagePrivate *priv = stage->priv;
g_queue_foreach (priv->event_queue, (GFunc) clutter_event_free, NULL);
g_queue_free (priv->event_queue);
g_free (priv->title);
g_array_free (priv->paint_volume_stack, TRUE);
_clutter_id_pool_free (priv->pick_id_pool);
if (priv->fps_timer != NULL)
g_timer_destroy (priv->fps_timer);
if (priv->paint_notify != NULL)
priv->paint_notify (priv->paint_data);
G_OBJECT_CLASS (clutter_stage_parent_class)->finalize (object);
}
static void
clutter_stage_class_init (ClutterStageClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
GParamSpec *pspec;
gobject_class->constructed = clutter_stage_constructed;
gobject_class->set_property = clutter_stage_set_property;
gobject_class->get_property = clutter_stage_get_property;
gobject_class->dispose = clutter_stage_dispose;
gobject_class->finalize = clutter_stage_finalize;
actor_class->allocate = clutter_stage_allocate;
actor_class->get_preferred_width = clutter_stage_get_preferred_width;
actor_class->get_preferred_height = clutter_stage_get_preferred_height;
actor_class->paint = clutter_stage_paint;
actor_class->pick = clutter_stage_pick;
actor_class->get_paint_volume = clutter_stage_get_paint_volume;
actor_class->realize = clutter_stage_realize;
actor_class->unrealize = clutter_stage_unrealize;
actor_class->show = clutter_stage_show;
actor_class->show_all = clutter_stage_show_all;
actor_class->hide = clutter_stage_hide;
actor_class->hide_all = clutter_stage_hide_all;
actor_class->queue_relayout = clutter_stage_real_queue_relayout;
actor_class->queue_redraw = clutter_stage_real_queue_redraw;
actor_class->apply_transform = clutter_stage_real_apply_transform;
/**
* ClutterStage:fullscreen:
*
* Whether the stage should be fullscreen or not.
*
* This property is set by calling clutter_stage_set_fullscreen()
* but since the actual implementation is delegated to the backend
* you should connect to the notify::fullscreen-set signal in order
* to get notification if the fullscreen state has been successfully
* achieved.
*
* Since: 1.0
*/
pspec = g_param_spec_boolean ("fullscreen-set",
P_("Fullscreen Set"),
P_("Whether the main stage is fullscreen"),
FALSE,
CLUTTER_PARAM_READABLE);
g_object_class_install_property (gobject_class,
PROP_FULLSCREEN_SET,
pspec);
/**
* ClutterStage:offscreen:
*
* Whether the stage should be rendered in an offscreen buffer.
*
* Deprecated: 1.10: This property does not do anything.
*/
pspec = g_param_spec_boolean ("offscreen",
P_("Offscreen"),
P_("Whether the main stage should be rendered offscreen"),
FALSE,
CLUTTER_PARAM_READWRITE | G_PARAM_DEPRECATED);
g_object_class_install_property (gobject_class,
PROP_OFFSCREEN,
pspec);
/**
* ClutterStage:cursor-visible:
*
* Whether the mouse pointer should be visible
*/
pspec = g_param_spec_boolean ("cursor-visible",
P_("Cursor Visible"),
P_("Whether the mouse pointer is visible on the main stage"),
TRUE,
CLUTTER_PARAM_READWRITE);
g_object_class_install_property (gobject_class,
PROP_CURSOR_VISIBLE,
pspec);
/**
* ClutterStage:user-resizable:
*
* Whether the stage is resizable via user interaction.
*
* Since: 0.4
*/
pspec = g_param_spec_boolean ("user-resizable",
P_("User Resizable"),
P_("Whether the stage is able to be resized via user interaction"),
FALSE,
CLUTTER_PARAM_READWRITE);
g_object_class_install_property (gobject_class,
PROP_USER_RESIZABLE,
pspec);
/**
* ClutterStage:color:
*
* The background color of the main stage.
*
* Deprecated: 1.10: Use the #ClutterActor:background-color property of
* #ClutterActor instead.
*/
pspec = clutter_param_spec_color ("color",
P_("Color"),
P_("The color of the stage"),
&default_stage_color,
CLUTTER_PARAM_READWRITE |
G_PARAM_DEPRECATED);
g_object_class_install_property (gobject_class, PROP_COLOR, pspec);
/**
* ClutterStage:perspective:
*
* The parameters used for the perspective projection from 3D
* coordinates to 2D
*
* Since: 0.8
*/
pspec = g_param_spec_boxed ("perspective",
P_("Perspective"),
P_("Perspective projection parameters"),
CLUTTER_TYPE_PERSPECTIVE,
CLUTTER_PARAM_READWRITE);
g_object_class_install_property (gobject_class,
PROP_PERSPECTIVE,
pspec);
/**
* ClutterStage:title:
*
* The stage's title - usually displayed in stage windows title decorations.
*
* Since: 0.4
*/
pspec = g_param_spec_string ("title",
P_("Title"),
P_("Stage Title"),
NULL,
CLUTTER_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_TITLE, pspec);
/**
* ClutterStage:use-fog:
*
* Whether the stage should use a linear GL "fog" in creating the
* depth-cueing effect, to enhance the perception of depth by fading
* actors farther from the viewpoint.
*
* Since: 0.6
*
* Deprecated: 1.10: This property does not do anything.
*/
pspec = g_param_spec_boolean ("use-fog",
P_("Use Fog"),
P_("Whether to enable depth cueing"),
FALSE,
CLUTTER_PARAM_READWRITE | G_PARAM_DEPRECATED);
g_object_class_install_property (gobject_class, PROP_USE_FOG, pspec);
/**
* ClutterStage:fog:
*
* The settings for the GL "fog", used only if #ClutterStage:use-fog
* is set to %TRUE
*
* Since: 1.0
*
* Deprecated: 1.10: This property does not do anything.
*/
pspec = g_param_spec_boxed ("fog",
P_("Fog"),
P_("Settings for the depth cueing"),
CLUTTER_TYPE_FOG,
CLUTTER_PARAM_READWRITE | G_PARAM_DEPRECATED);
g_object_class_install_property (gobject_class, PROP_FOG, pspec);
/**
* ClutterStage:use-alpha:
*
* Whether the #ClutterStage should honour the alpha component of the
* #ClutterStage:color property when painting. If Clutter is run under
* a compositing manager this will result in the stage being blended
* with the underlying window(s)
*
* Since: 1.2
*/
pspec = g_param_spec_boolean ("use-alpha",
P_("Use Alpha"),
P_("Whether to honour the alpha component of the stage color"),
FALSE,
CLUTTER_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_USE_ALPHA, pspec);
/**
* ClutterStage:key-focus:
*
* The #ClutterActor that will receive key events from the underlying
* windowing system.
*
* If %NULL, the #ClutterStage will receive the events.
*
* Since: 1.2
*/
pspec = g_param_spec_object ("key-focus",
P_("Key Focus"),
P_("The currently key focused actor"),
CLUTTER_TYPE_ACTOR,
CLUTTER_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_KEY_FOCUS, pspec);
/**
* ClutterStage:no-clear-hint:
*
* Whether or not the #ClutterStage should clear its contents
* before each paint cycle.
*
* See clutter_stage_set_no_clear_hint() for further information.
*
* Since: 1.4
*/
pspec = g_param_spec_boolean ("no-clear-hint",
P_("No Clear Hint"),
P_("Whether the stage should clear its contents"),
FALSE,
CLUTTER_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_NO_CLEAR_HINT, pspec);
/**
* ClutterStage:accept-focus:
*
* Whether the #ClutterStage should accept key focus when shown.
*
* Since: 1.6
*/
pspec = g_param_spec_boolean ("accept-focus",
P_("Accept Focus"),
P_("Whether the stage should accept focus on show"),
TRUE,
CLUTTER_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_ACCEPT_FOCUS, pspec);
/**
* ClutterStage::fullscreen:
* @stage: the stage which was fullscreened
*
* The ::fullscreen signal is emitted when the stage is made fullscreen.
*
* Since: 0.6
*/
stage_signals[FULLSCREEN] =
g_signal_new (I_("fullscreen"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (ClutterStageClass, fullscreen),
NULL, NULL,
_clutter_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* ClutterStage::unfullscreen:
* @stage: the stage which has left a fullscreen state.
*
* The ::unfullscreen signal is emitted when the stage leaves a fullscreen
* state.
*
* Since: 0.6
*/
stage_signals[UNFULLSCREEN] =
g_signal_new (I_("unfullscreen"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (ClutterStageClass, unfullscreen),
NULL, NULL,
_clutter_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* ClutterStage::activate:
* @stage: the stage which was activated
*
* The ::activate signal is emitted when the stage receives key focus
* from the underlying window system.
*
* Since: 0.6
*/
stage_signals[ACTIVATE] =
g_signal_new (I_("activate"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (ClutterStageClass, activate),
NULL, NULL,
_clutter_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* ClutterStage::deactivate:
* @stage: the stage which was deactivated
*
* The ::deactivate signal is emitted when the stage loses key focus
* from the underlying window system.
*
* Since: 0.6
*/
stage_signals[DEACTIVATE] =
g_signal_new (I_("deactivate"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (ClutterStageClass, deactivate),
NULL, NULL,
_clutter_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
* ClutterStage::delete-event:
* @stage: the stage that received the event
* @event: a #ClutterEvent of type %CLUTTER_DELETE
*
* The ::delete-event signal is emitted when the user closes a
* #ClutterStage window using the window controls.
*
* Clutter by default will call clutter_main_quit() if @stage is
* the default stage, and clutter_actor_destroy() for any other
* stage.
*
* It is possible to override the default behaviour by connecting
* a new handler and returning %TRUE there.
*
* This signal is emitted only on Clutter backends that
* embed #ClutterStage in native windows. It is not emitted for
* backends that use a static frame buffer.
*
* Since: 1.2
*/
stage_signals[DELETE_EVENT] =
g_signal_new (I_("delete-event"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (ClutterStageClass, delete_event),
_clutter_boolean_handled_accumulator, NULL,
_clutter_marshal_BOOLEAN__BOXED,
G_TYPE_BOOLEAN, 1,
CLUTTER_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
/**
* ClutterStage::after-paint:
* @stage: the stage that received the event
*
* The ::after-paint signal is emitted after the stage is painted,
* but before the results are displayed on the screen.
*
* Since: 1.20
*/
stage_signals[AFTER_PAINT] =
g_signal_new (I_("after-paint"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_LAST,
0, /* no corresponding vfunc */
NULL, NULL, NULL,
G_TYPE_NONE, 0);
klass->fullscreen = clutter_stage_real_fullscreen;
klass->activate = clutter_stage_real_activate;
klass->deactivate = clutter_stage_real_deactivate;
klass->delete_event = clutter_stage_real_delete_event;
}
static void
clutter_stage_notify_min_size (ClutterStage *self)
{
self->priv->min_size_changed = TRUE;
}
static void
clutter_stage_init (ClutterStage *self)
{
cairo_rectangle_int_t geom = { 0, };
ClutterStagePrivate *priv;
ClutterStageWindow *impl;
ClutterBackend *backend;
int window_scale = 1;
GError *error;
/* a stage is a top-level object */
CLUTTER_SET_PRIVATE_FLAGS (self, CLUTTER_IS_TOPLEVEL);
self->priv = priv = clutter_stage_get_instance_private (self);
CLUTTER_NOTE (BACKEND, "Creating stage from the default backend");
backend = clutter_get_default_backend ();
error = NULL;
impl = _clutter_backend_create_stage (backend, self, &error);
if (G_LIKELY (impl != NULL))
{
_clutter_stage_set_window (self, impl);
_clutter_stage_window_get_geometry (priv->impl, &geom);
window_scale = _clutter_stage_window_get_scale_factor (priv->impl);
}
else
{
if (error != NULL)
{
g_critical ("Unable to create a new stage implementation: %s",
error->message);
g_error_free (error);
}
else
g_critical ("Unable to create a new stage implementation.");
}
priv->event_queue = g_queue_new ();
priv->is_fullscreen = FALSE;
priv->is_user_resizable = FALSE;
priv->is_cursor_visible = TRUE;
priv->use_fog = FALSE;
priv->throttle_motion_events = TRUE;
priv->min_size_changed = FALSE;
priv->sync_delay = -1;
/* XXX - we need to keep the invariant that calling
* clutter_set_motion_event_enabled() before the stage creation
* will cause motion event delivery to be disabled on any newly
* created stage. this can go away when we break API and remove
* deprecated functions.
*/
priv->motion_events_enabled = _clutter_context_get_motion_events_enabled ();
clutter_actor_set_background_color (CLUTTER_ACTOR (self),
&default_stage_color);
priv->perspective.fovy = 60.0; /* 60 Degrees */
priv->perspective.aspect = (float) geom.width / (float) geom.height;
priv->perspective.z_near = 0.1;
priv->perspective.z_far = 100.0;
cogl_matrix_init_identity (&priv->projection);
cogl_matrix_perspective (&priv->projection,
priv->perspective.fovy,
priv->perspective.aspect,
priv->perspective.z_near,
priv->perspective.z_far);
cogl_matrix_get_inverse (&priv->projection,
&priv->inverse_projection);
cogl_matrix_init_identity (&priv->view);
cogl_matrix_view_2d_in_perspective (&priv->view,
priv->perspective.fovy,
priv->perspective.aspect,
priv->perspective.z_near,
50, /* distance to 2d plane */
geom.width * window_scale,
geom.height * window_scale);
/* FIXME - remove for 2.0 */
priv->fog.z_near = 1.0;
priv->fog.z_far = 2.0;
priv->relayout_pending = TRUE;
clutter_actor_set_reactive (CLUTTER_ACTOR (self), TRUE);
clutter_stage_set_title (self, g_get_prgname ());
clutter_stage_set_key_focus (self, NULL);
g_signal_connect (self, "notify::min-width",
G_CALLBACK (clutter_stage_notify_min_size), NULL);
g_signal_connect (self, "notify::min-height",
G_CALLBACK (clutter_stage_notify_min_size), NULL);
_clutter_stage_set_viewport (self,
0, 0,
geom.width,
geom.height);
priv->paint_volume_stack =
g_array_new (FALSE, FALSE, sizeof (ClutterPaintVolume));
priv->pick_id_pool = _clutter_id_pool_new (256);
}
/**
* clutter_stage_get_default:
*
* Retrieves a #ClutterStage singleton.
*
* This function is not as useful as it sounds, and will most likely
* by deprecated in the future. Application code should only create
* a #ClutterStage instance using clutter_stage_new(), and manage the
* lifetime of the stage manually.
*
* The default stage singleton has a platform-specific behaviour: on
* platforms without the %CLUTTER_FEATURE_STAGE_MULTIPLE feature flag
* set, the first #ClutterStage instance will also be set to be the
* default stage instance, and this function will always return a
* pointer to it.
*
* On platforms with the %CLUTTER_FEATURE_STAGE_MULTIPLE feature flag
* set, the default stage will be created by the first call to this
* function, and every following call will return the same pointer to
* it.
*
* Return value: (transfer none) (type Clutter.Stage): the main
* #ClutterStage. You should never destroy or unref the returned
* actor.
*
* Deprecated: 1.10: Use clutter_stage_new() instead.
*/
ClutterActor *
clutter_stage_get_default (void)
{
ClutterStageManager *stage_manager = clutter_stage_manager_get_default ();
ClutterStage *stage;
stage = clutter_stage_manager_get_default_stage (stage_manager);
if (G_UNLIKELY (stage == NULL))
{
/* This will take care of automatically adding the stage to the
* stage manager and setting it as the default. Its floating
* reference will be claimed by the stage manager.
*/
stage = g_object_new (CLUTTER_TYPE_STAGE, NULL);
_clutter_stage_manager_set_default_stage (stage_manager, stage);
/* the default stage is realized by default */
clutter_actor_realize (CLUTTER_ACTOR (stage));
}
return CLUTTER_ACTOR (stage);
}
/**
* clutter_stage_set_color:
* @stage: A #ClutterStage
* @color: A #ClutterColor
*
* Sets the stage color.
*
* Deprecated: 1.10: Use clutter_actor_set_background_color() instead.
*/
void
clutter_stage_set_color (ClutterStage *stage,
const ClutterColor *color)
{
clutter_actor_set_background_color (CLUTTER_ACTOR (stage), color);
g_object_notify (G_OBJECT (stage), "color");
}
/**
* clutter_stage_get_color:
* @stage: A #ClutterStage
* @color: (out caller-allocates): return location for a #ClutterColor
*
* Retrieves the stage color.
*
* Deprecated: 1.10: Use clutter_actor_get_background_color() instead.
*/
void
clutter_stage_get_color (ClutterStage *stage,
ClutterColor *color)
{
clutter_actor_get_background_color (CLUTTER_ACTOR (stage), color);
}
static void
clutter_stage_set_perspective_internal (ClutterStage *stage,
ClutterPerspective *perspective)
{
ClutterStagePrivate *priv = stage->priv;
if (priv->perspective.fovy == perspective->fovy &&
priv->perspective.aspect == perspective->aspect &&
priv->perspective.z_near == perspective->z_near &&
priv->perspective.z_far == perspective->z_far)
return;
priv->perspective = *perspective;
cogl_matrix_init_identity (&priv->projection);
cogl_matrix_perspective (&priv->projection,
priv->perspective.fovy,
priv->perspective.aspect,
priv->perspective.z_near,
priv->perspective.z_far);
cogl_matrix_get_inverse (&priv->projection,
&priv->inverse_projection);
priv->dirty_projection = TRUE;
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
}
/**
* clutter_stage_set_perspective:
* @stage: A #ClutterStage
* @perspective: A #ClutterPerspective
*
* Sets the stage perspective. Using this function is not recommended
* because it will disable Clutter's attempts to generate an
* appropriate perspective based on the size of the stage.
*/
void
clutter_stage_set_perspective (ClutterStage *stage,
ClutterPerspective *perspective)
{
ClutterStagePrivate *priv;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
g_return_if_fail (perspective != NULL);
g_return_if_fail (perspective->z_far - perspective->z_near != 0);
priv = stage->priv;
/* If the application ever calls this function then we'll stop
automatically updating the perspective when the stage changes
size */
priv->has_custom_perspective = TRUE;
clutter_stage_set_perspective_internal (stage, perspective);
}
/**
* clutter_stage_get_perspective:
* @stage: A #ClutterStage
* @perspective: (out caller-allocates) (allow-none): return location for a
* #ClutterPerspective
*
* Retrieves the stage perspective.
*/
void
clutter_stage_get_perspective (ClutterStage *stage,
ClutterPerspective *perspective)
{
g_return_if_fail (CLUTTER_IS_STAGE (stage));
g_return_if_fail (perspective != NULL);
*perspective = stage->priv->perspective;
}
/*
* clutter_stage_get_projection_matrix:
* @stage: A #ClutterStage
* @projection: return location for a #CoglMatrix representing the
* perspective projection applied to actors on the given
* @stage.
*
* Retrieves the @stage's projection matrix. This is derived from the
* current perspective set using clutter_stage_set_perspective().
*
* Since: 1.6
*/
void
_clutter_stage_get_projection_matrix (ClutterStage *stage,
CoglMatrix *projection)
{
g_return_if_fail (CLUTTER_IS_STAGE (stage));
g_return_if_fail (projection != NULL);
*projection = stage->priv->projection;
}
/* This simply provides a simple mechanism for us to ensure that
* the projection matrix gets re-asserted before painting.
*
* This is used when switching between multiple stages */
void
_clutter_stage_dirty_projection (ClutterStage *stage)
{
stage->priv->dirty_projection = TRUE;
}
/*
* clutter_stage_set_viewport:
* @stage: A #ClutterStage
* @x: The X postition to render the stage at, in window coordinates
* @y: The Y position to render the stage at, in window coordinates
* @width: The width to render the stage at, in window coordinates
* @height: The height to render the stage at, in window coordinates
*
* Sets the stage viewport. The viewport defines a final scale and
* translation of your rendered stage and actors. This lets you render
* your stage into a subregion of the stage window or you could use it to
* pan a subregion of the stage if your stage window is smaller then
* the stage. (XXX: currently this isn't possible)
*
* Unlike a scale and translation done using the modelview matrix this
* is done after everything has had perspective projection applied, so
* for example if you were to pan across a subregion of the stage using
* the viewport then you would not see a change in perspective for the
* actors on the stage.
*
* Normally the stage viewport will automatically track the size of the
* stage window with no offset so the stage will fill your window. This
* behaviour can be changed with the "viewport-mimics-window" property
* which will automatically be set to FALSE if you use this API. If
* you want to revert to the original behaviour then you should set
* this property back to %TRUE using
* clutter_stage_set_viewport_mimics_window().
* (XXX: If we were to make this API public then we might want to do
* add that property.)
*
* Note: currently this interface only support integer precision
* offsets and sizes for viewports but the interface takes floats because
* OpenGL 4.0 has introduced floating point viewports which we might
* want to expose via this API eventually.
*
* Since: 1.6
*/
void
_clutter_stage_set_viewport (ClutterStage *stage,
float x,
float y,
float width,
float height)
{
ClutterStagePrivate *priv;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
priv = stage->priv;
if (x == priv->viewport[0] &&
y == priv->viewport[1] &&
width == priv->viewport[2] &&
height == priv->viewport[3])
return;
priv->viewport[0] = x;
priv->viewport[1] = y;
priv->viewport[2] = width;
priv->viewport[3] = height;
priv->dirty_viewport = TRUE;
queue_full_redraw (stage);
}
/* This simply provides a simple mechanism for us to ensure that
* the viewport gets re-asserted before next painting.
*
* This is used when switching between multiple stages */
void
_clutter_stage_dirty_viewport (ClutterStage *stage)
{
stage->priv->dirty_viewport = TRUE;
}
/*
* clutter_stage_get_viewport:
* @stage: A #ClutterStage
* @x: A location for the X position where the stage is rendered,
* in window coordinates.
* @y: A location for the Y position where the stage is rendered,
* in window coordinates.
* @width: A location for the width the stage is rendered at,
* in window coordinates.
* @height: A location for the height the stage is rendered at,
* in window coordinates.
*
* Returns the viewport offset and size set using
* clutter_stage_set_viewport() or if the "viewport-mimics-window" property
* is TRUE then @x and @y will be set to 0 and @width and @height will equal
* the width if the stage window.
*
* Since: 1.6
*/
void
_clutter_stage_get_viewport (ClutterStage *stage,
float *x,
float *y,
float *width,
float *height)
{
ClutterStagePrivate *priv;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
priv = stage->priv;
*x = priv->viewport[0];
*y = priv->viewport[1];
*width = priv->viewport[2];
*height = priv->viewport[3];
}
/**
* clutter_stage_set_fullscreen:
* @stage: a #ClutterStage
* @fullscreen: %TRUE to to set the stage fullscreen
*
* Asks to place the stage window in the fullscreen or unfullscreen
* states.
*
( Note that you shouldn't assume the window is definitely full screen
* afterward, because other entities (e.g. the user or window manager)
* could unfullscreen it again, and not all window managers honor
* requests to fullscreen windows.
*
* If you want to receive notification of the fullscreen state you
* should either use the #ClutterStage::fullscreen and
* #ClutterStage::unfullscreen signals, or use the notify signal
* for the #ClutterStage:fullscreen-set property
*
* Since: 1.0
*/
void
clutter_stage_set_fullscreen (ClutterStage *stage,
gboolean fullscreen)
{
ClutterStagePrivate *priv;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
priv = stage->priv;
if (priv->is_fullscreen != fullscreen)
{
ClutterStageWindow *impl = CLUTTER_STAGE_WINDOW (priv->impl);
ClutterStageWindowIface *iface;
iface = CLUTTER_STAGE_WINDOW_GET_IFACE (impl);
/* Only set if backend implements.
*
* Also see clutter_stage_event() for setting priv->is_fullscreen
* on state change event.
*/
if (iface->set_fullscreen)
iface->set_fullscreen (impl, fullscreen);
}
/* If the backend did fullscreen the stage window then we need to resize
* the stage and update its viewport so we queue a relayout. Note: if the
* fullscreen request is handled asynchronously we can't rely on this
* queue_relayout to update the viewport, but for example the X backend
* will recieve a ConfigureNotify after a successful resize which is how
* we ensure the viewport is updated on X.
*/
clutter_actor_queue_relayout (CLUTTER_ACTOR (stage));
}
/**
* clutter_stage_get_fullscreen:
* @stage: a #ClutterStage
*
* Retrieves whether the stage is full screen or not
*
* Return value: %TRUE if the stage is full screen
*
* Since: 1.0
*/
gboolean
clutter_stage_get_fullscreen (ClutterStage *stage)
{
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), FALSE);
return stage->priv->is_fullscreen;
}
/**
* clutter_stage_set_user_resizable:
* @stage: a #ClutterStage
* @resizable: whether the stage should be user resizable.
*
* Sets if the stage is resizable by user interaction (e.g. via
* window manager controls)
*
* Since: 0.4
*/
void
clutter_stage_set_user_resizable (ClutterStage *stage,
gboolean resizable)
{
ClutterStagePrivate *priv;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
priv = stage->priv;
if (clutter_feature_available (CLUTTER_FEATURE_STAGE_USER_RESIZE)
&& priv->is_user_resizable != resizable)
{
ClutterStageWindow *impl = CLUTTER_STAGE_WINDOW (priv->impl);
ClutterStageWindowIface *iface;
iface = CLUTTER_STAGE_WINDOW_GET_IFACE (impl);
if (iface->set_user_resizable)
{
priv->is_user_resizable = resizable;
iface->set_user_resizable (impl, resizable);
g_object_notify (G_OBJECT (stage), "user-resizable");
}
}
}
/**
* clutter_stage_get_user_resizable:
* @stage: a #ClutterStage
*
* Retrieves the value set with clutter_stage_set_user_resizable().
*
* Return value: %TRUE if the stage is resizable by the user.
*
* Since: 0.4
*/
gboolean
clutter_stage_get_user_resizable (ClutterStage *stage)
{
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), FALSE);
return stage->priv->is_user_resizable;
}
/**
* clutter_stage_show_cursor:
* @stage: a #ClutterStage
*
* Shows the cursor on the stage window
*/
void
clutter_stage_show_cursor (ClutterStage *stage)
{
ClutterStagePrivate *priv;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
priv = stage->priv;
if (!priv->is_cursor_visible)
{
ClutterStageWindow *impl = CLUTTER_STAGE_WINDOW (priv->impl);
ClutterStageWindowIface *iface;
iface = CLUTTER_STAGE_WINDOW_GET_IFACE (impl);
if (iface->set_cursor_visible)
{
priv->is_cursor_visible = TRUE;
iface->set_cursor_visible (impl, TRUE);
g_object_notify (G_OBJECT (stage), "cursor-visible");
}
}
}
/**
* clutter_stage_hide_cursor:
* @stage: a #ClutterStage
*
* Makes the cursor invisible on the stage window
*
* Since: 0.4
*/
void
clutter_stage_hide_cursor (ClutterStage *stage)
{
ClutterStagePrivate *priv;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
priv = stage->priv;
if (priv->is_cursor_visible)
{
ClutterStageWindow *impl = CLUTTER_STAGE_WINDOW (priv->impl);
ClutterStageWindowIface *iface;
iface = CLUTTER_STAGE_WINDOW_GET_IFACE (impl);
if (iface->set_cursor_visible)
{
priv->is_cursor_visible = FALSE;
iface->set_cursor_visible (impl, FALSE);
g_object_notify (G_OBJECT (stage), "cursor-visible");
}
}
}
/**
* clutter_stage_read_pixels:
* @stage: A #ClutterStage
* @x: x coordinate of the first pixel that is read from stage
* @y: y coordinate of the first pixel that is read from stage
* @width: Width dimention of pixels to be read, or -1 for the
* entire stage width
* @height: Height dimention of pixels to be read, or -1 for the
* entire stage height
*
* Makes a screenshot of the stage in RGBA 8bit data, returns a
* linear buffer with @width * 4 as rowstride.
*
* The alpha data contained in the returned buffer is driver-dependent,
* and not guaranteed to hold any sensible value.
*
* Return value: (transfer full) (array): a pointer to newly allocated memory with the buffer
* or %NULL if the read failed. Use g_free() on the returned data
* to release the resources it has allocated.
*/
guchar *
clutter_stage_read_pixels (ClutterStage *stage,
gint x,
gint y,
gint width,
gint height)
{
ClutterActorBox box;
guchar *pixels;
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), NULL);
/* Force a redraw of the stage before reading back pixels */
clutter_stage_ensure_current (stage);
clutter_actor_paint (CLUTTER_ACTOR (stage));
clutter_actor_get_allocation_box (CLUTTER_ACTOR (stage), &box);
if (width < 0)
width = ceilf (box.x2 - box.x1);
if (height < 0)
height = ceilf (box.y2 - box.y1);
pixels = g_malloc (height * width * 4);
cogl_read_pixels (x, y, width, height,
COGL_READ_PIXELS_COLOR_BUFFER,
COGL_PIXEL_FORMAT_RGBA_8888,
pixels);
return pixels;
}
/**
* clutter_stage_get_actor_at_pos:
* @stage: a #ClutterStage
* @pick_mode: how the scene graph should be painted
* @x: X coordinate to check
* @y: Y coordinate to check
*
* Checks the scene at the coordinates @x and @y and returns a pointer
* to the #ClutterActor at those coordinates.
*
* By using @pick_mode it is possible to control which actors will be
* painted and thus available.
*
* Return value: (transfer none): the actor at the specified coordinates,
* if any
*/
ClutterActor *
clutter_stage_get_actor_at_pos (ClutterStage *stage,
ClutterPickMode pick_mode,
gint x,
gint y)
{
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), NULL);
return _clutter_stage_do_pick (stage, x, y, pick_mode);
}
/**
* clutter_stage_event:
* @stage: a #ClutterStage
* @event: a #ClutterEvent
*
* This function is used to emit an event on the main stage.
*
* You should rarely need to use this function, except for
* synthetised events.
*
* Return value: the return value from the signal emission
*
* Since: 0.4
*/
gboolean
clutter_stage_event (ClutterStage *stage,
ClutterEvent *event)
{
ClutterStagePrivate *priv;
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
priv = stage->priv;
if (event->type == CLUTTER_DELETE)
{
gboolean retval = FALSE;
g_signal_emit_by_name (stage, "event", event, &retval);
if (!retval)
g_signal_emit_by_name (stage, "delete-event", event, &retval);
return retval;
}
if (event->type != CLUTTER_STAGE_STATE)
return FALSE;
/* emit raw event */
if (clutter_actor_event (CLUTTER_ACTOR (stage), event, FALSE))
return TRUE;
if (event->stage_state.changed_mask & CLUTTER_STAGE_STATE_FULLSCREEN)
{
if (event->stage_state.new_state & CLUTTER_STAGE_STATE_FULLSCREEN)
{
priv->is_fullscreen = TRUE;
g_signal_emit (stage, stage_signals[FULLSCREEN], 0);
g_object_notify (G_OBJECT (stage), "fullscreen-set");
}
else
{
priv->is_fullscreen = FALSE;
g_signal_emit (stage, stage_signals[UNFULLSCREEN], 0);
g_object_notify (G_OBJECT (stage), "fullscreen-set");
}
}
if (event->stage_state.changed_mask & CLUTTER_STAGE_STATE_ACTIVATED)
{
if (event->stage_state.new_state & CLUTTER_STAGE_STATE_ACTIVATED)
g_signal_emit (stage, stage_signals[ACTIVATE], 0);
else
g_signal_emit (stage, stage_signals[DEACTIVATE], 0);
}
return TRUE;
}
/**
* clutter_stage_set_title:
* @stage: A #ClutterStage
* @title: A utf8 string for the stage windows title.
*
* Sets the stage title.
*
* Since: 0.4
**/
void
clutter_stage_set_title (ClutterStage *stage,
const gchar *title)
{
ClutterStagePrivate *priv;
ClutterStageWindow *impl;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
priv = stage->priv;
g_free (priv->title);
priv->title = g_strdup (title);
impl = CLUTTER_STAGE_WINDOW (priv->impl);
if (CLUTTER_STAGE_WINDOW_GET_IFACE(impl)->set_title != NULL)
CLUTTER_STAGE_WINDOW_GET_IFACE (impl)->set_title (impl, priv->title);
g_object_notify (G_OBJECT (stage), "title");
}
/**
* clutter_stage_get_title:
* @stage: A #ClutterStage
*
* Gets the stage title.
*
* Return value: pointer to the title string for the stage. The
* returned string is owned by the actor and should not
* be modified or freed.
*
* Since: 0.4
**/
const gchar *
clutter_stage_get_title (ClutterStage *stage)
{
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), NULL);
return stage->priv->title;
}
static void
on_key_focus_destroy (ClutterActor *actor,
ClutterStage *stage)
{
/* unset the key focus */
clutter_stage_set_key_focus (stage, NULL);
}
/**
* clutter_stage_set_key_focus:
* @stage: the #ClutterStage
* @actor: (allow-none): the actor to set key focus to, or %NULL
*
* Sets the key focus on @actor. An actor with key focus will receive
* all the key events. If @actor is %NULL, the stage will receive
* focus.
*
* Since: 0.6
*/
void
clutter_stage_set_key_focus (ClutterStage *stage,
ClutterActor *actor)
{
ClutterStagePrivate *priv;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
g_return_if_fail (actor == NULL || CLUTTER_IS_ACTOR (actor));
priv = stage->priv;
/* normalize the key focus. NULL == stage */
if (actor == CLUTTER_ACTOR (stage))
actor = NULL;
/* avoid emitting signals and notifications if we're setting the same
* actor as the key focus
*/
if (priv->key_focused_actor == actor)
return;
if (priv->key_focused_actor != NULL)
{
ClutterActor *old_focused_actor;
old_focused_actor = priv->key_focused_actor;
/* set key_focused_actor to NULL before emitting the signal or someone
* might hide the previously focused actor in the signal handler and we'd
* get re-entrant call and get glib critical from g_object_weak_unref
*/
g_signal_handlers_disconnect_by_func (priv->key_focused_actor,
G_CALLBACK (on_key_focus_destroy),
stage);
priv->key_focused_actor = NULL;
g_signal_emit_by_name (old_focused_actor, "key-focus-out");
}
else
g_signal_emit_by_name (stage, "key-focus-out");
/* Note, if someone changes key focus in focus-out signal handler we'd be
* overriding the latter call below moving the focus where it was originally
* intended. The order of events would be:
* 1st focus-out, 2nd focus-out (on stage), 2nd focus-in, 1st focus-in
*/
if (actor != NULL)
{
priv->key_focused_actor = actor;
g_signal_connect (actor,
"destroy", G_CALLBACK (on_key_focus_destroy),
stage);
g_signal_emit_by_name (priv->key_focused_actor, "key-focus-in");
}
else
g_signal_emit_by_name (stage, "key-focus-in");
g_object_notify (G_OBJECT (stage), "key-focus");
}
/**
* clutter_stage_get_key_focus:
* @stage: the #ClutterStage
*
* Retrieves the actor that is currently under key focus.
*
* Return value: (transfer none): the actor with key focus, or the stage
*
* Since: 0.6
*/
ClutterActor *
clutter_stage_get_key_focus (ClutterStage *stage)
{
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), NULL);
if (stage->priv->key_focused_actor)
return stage->priv->key_focused_actor;
return CLUTTER_ACTOR (stage);
}
/**
* clutter_stage_get_use_fog:
* @stage: the #ClutterStage
*
* Gets whether the depth cueing effect is enabled on @stage.
*
* Return value: %TRUE if the depth cueing effect is enabled
*
* Since: 0.6
*
* Deprecated: 1.10: This function will always return %FALSE
*/
gboolean
clutter_stage_get_use_fog (ClutterStage *stage)
{
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), FALSE);
return stage->priv->use_fog;
}
/**
* clutter_stage_set_use_fog:
* @stage: the #ClutterStage
* @fog: %TRUE for enabling the depth cueing effect
*
* Sets whether the depth cueing effect on the stage should be enabled
* or not.
*
* Depth cueing is a 3D effect that makes actors farther away from the
* viewing point less opaque, by fading them with the stage color.
* The parameters of the GL fog used can be changed using the
* clutter_stage_set_fog() function.
*
* Since: 0.6
*
* Deprecated: 1.10: Calling this function produces no visible effect
*/
void
clutter_stage_set_use_fog (ClutterStage *stage,
gboolean fog)
{
}
/**
* clutter_stage_set_fog:
* @stage: the #ClutterStage
* @fog: a #ClutterFog structure
*
* Sets the fog (also known as "depth cueing") settings for the @stage.
*
* A #ClutterStage will only use a linear fog progression, which
* depends solely on the distance from the viewer. The cogl_set_fog()
* function in COGL exposes more of the underlying implementation,
* and allows changing the for progression function. It can be directly
* used by disabling the #ClutterStage:use-fog property and connecting
* a signal handler to the #ClutterActor::paint signal on the @stage,
* like:
*
* |[
* clutter_stage_set_use_fog (stage, FALSE);
* g_signal_connect (stage, "paint", G_CALLBACK (on_stage_paint), NULL);
* ]|
*
* The paint signal handler will call cogl_set_fog() with the
* desired settings:
*
* |[
* static void
* on_stage_paint (ClutterActor *actor)
* {
* ClutterColor stage_color = { 0, };
* CoglColor fog_color = { 0, };
*
* // set the fog color to the stage background color
* clutter_stage_get_color (CLUTTER_STAGE (actor), &stage_color);
* cogl_color_init_from_4ub (&fog_color,
* stage_color.red,
* stage_color.green,
* stage_color.blue,
* stage_color.alpha);
*
* // enable fog //
* cogl_set_fog (&fog_color,
* COGL_FOG_MODE_EXPONENTIAL, // mode
* 0.5, // density
* 5.0, 30.0); // z_near and z_far
* }
* ]|
*
* The fogging functions only work correctly when the visible actors use
* unmultiplied alpha colors. By default Cogl will premultiply textures and
* cogl_set_source_color() will premultiply colors, so unless you explicitly
* load your textures requesting an unmultiplied internal format and use
* cogl_material_set_color() you can only use fogging with fully opaque actors.
* Support for premultiplied colors will improve in the future when we can
* depend on fragment shaders.
*
* Since: 0.6
*
* Deprecated: 1.10: Fog settings are ignored.
*/
void
clutter_stage_set_fog (ClutterStage *stage,
ClutterFog *fog)
{
}
/**
* clutter_stage_get_fog:
* @stage: the #ClutterStage
* @fog: (out): return location for a #ClutterFog structure
*
* Retrieves the current depth cueing settings from the stage.
*
* Since: 0.6
*
* Deprecated: 1.10: This function will always return the default
* values of #ClutterFog
*/
void
clutter_stage_get_fog (ClutterStage *stage,
ClutterFog *fog)
{
g_return_if_fail (CLUTTER_IS_STAGE (stage));
g_return_if_fail (fog != NULL);
*fog = stage->priv->fog;
}
/*** Perspective boxed type ******/
static gpointer
clutter_perspective_copy (gpointer data)
{
if (G_LIKELY (data))
return g_slice_dup (ClutterPerspective, data);
return NULL;
}
static void
clutter_perspective_free (gpointer data)
{
if (G_LIKELY (data))
g_slice_free (ClutterPerspective, data);
}
G_DEFINE_BOXED_TYPE (ClutterPerspective, clutter_perspective,
clutter_perspective_copy,
clutter_perspective_free);
static gpointer
clutter_fog_copy (gpointer data)
{
if (G_LIKELY (data))
return g_slice_dup (ClutterFog, data);
return NULL;
}
static void
clutter_fog_free (gpointer data)
{
if (G_LIKELY (data))
g_slice_free (ClutterFog, data);
}
G_DEFINE_BOXED_TYPE (ClutterFog, clutter_fog, clutter_fog_copy, clutter_fog_free);
/**
* clutter_stage_new:
*
* Creates a new, non-default stage. A non-default stage is a new
* top-level actor which can be used as another container. It works
* exactly like the default stage, but while clutter_stage_get_default()
* will always return the same instance, you will have to keep a pointer
* to any #ClutterStage returned by clutter_stage_new().
*
* The ability to support multiple stages depends on the current
* backend. Use clutter_feature_available() and
* %CLUTTER_FEATURE_STAGE_MULTIPLE to check at runtime whether a
* backend supports multiple stages.
*
* Return value: a new stage, or %NULL if the default backend does
* not support multiple stages. Use clutter_actor_destroy() to
* programmatically close the returned stage.
*
* Since: 0.8
*/
ClutterActor *
clutter_stage_new (void)
{
return g_object_new (CLUTTER_TYPE_STAGE, NULL);
}
/**
* clutter_stage_ensure_current:
* @stage: the #ClutterStage
*
* This function essentially makes sure the right GL context is
* current for the passed stage. It is not intended to
* be used by applications.
*
* Since: 0.8
*/
void
clutter_stage_ensure_current (ClutterStage *stage)
{
ClutterBackend *backend;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
backend = clutter_get_default_backend ();
_clutter_backend_ensure_context (backend, stage);
}
/**
* clutter_stage_ensure_viewport:
* @stage: a #ClutterStage
*
* Ensures that the GL viewport is updated with the current
* stage window size.
*
* This function will queue a redraw of @stage.
*
* This function should not be called by applications; it is used
* when embedding a #ClutterStage into a toolkit with another
* windowing system, like GTK+.
*
* Since: 1.0
*/
void
clutter_stage_ensure_viewport (ClutterStage *stage)
{
g_return_if_fail (CLUTTER_IS_STAGE (stage));
_clutter_stage_dirty_viewport (stage);
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
}
static void
clutter_stage_apply_scale (ClutterStage *stage)
{
int factor;
factor = _clutter_stage_window_get_scale_factor (stage->priv->impl);
if (factor != 1)
cogl_matrix_scale (&stage->priv->view, factor, factor, 1.f);
}
# define _DEG_TO_RAD(d) ((d) * ((float) G_PI / 180.0f))
/* This calculates a distance into the view frustum to position the
* stage so there is a decent amount of space to position geometry
* between the stage and the near clipping plane.
*
* Some awkward issues with this problem are:
* - It's not possible to have a gap as large as the stage size with
* a fov > 53° which is basically always the case since the default
* fov is 60°.
* - This can be deduced if you consider that this requires a
* triangle as wide as it is deep to fit in the frustum in front
* of the z_near plane. That triangle will always have an angle
* of 53.13° at the point sitting on the z_near plane, but if the
* frustum has a wider fov angle the left/right clipping planes
* can never converge with the two corners of our triangle no
* matter what size the triangle has.
* - With a fov > 53° there is a trade off between maximizing the gap
* size relative to the stage size but not loosing depth precision.
* - Perhaps ideally we wouldn't just consider the fov on the y-axis
* that is usually used to define a perspective, we would consider
* the fov of the axis with the largest stage size so the gap would
* accommodate that size best.
*
* After going around in circles a few times with how to handle these
* issues, we decided in the end to go for the simplest solution to
* start with instead of an elaborate function that handles arbitrary
* fov angles that we currently have no use-case for.
*
* The solution assumes a fovy of 60° and for that case gives a gap
* that's 85% of the stage height. We can consider more elaborate
* functions if necessary later.
*
* One guide we had to steer the gap size we support is the
* interactive test, test-texture-quality which expects to animate an
* actor to +400 on the z axis with a stage size of 640x480. A gap
* that's 85% of the stage height gives a gap of 408 in that case.
*/
static float
calculate_z_translation (float z_near)
{
/* This solution uses fairly basic trigonometry, but is seems worth
* clarifying the particular geometry we are looking at in-case
* anyone wants to develop this further later. Not sure how well an
* ascii diagram is going to work :-)
*
* |--- stage_height ---|
* | stage line |
* ╲━━━━━━━━━━━━━━━━━━━━━╱------------
* ╲. (2) │ .╱ | |
* C ╲ . │ . ╱ gap| |
* =0.5°╲ . a │ . ╱ | |
* b╲(1). D│ . ╱ | |
* ╲ B.│. ╱near plane | |
* A= ╲━━━━━━━━━╱------------- |
* 120° ╲ c │ ╱ | z_2d
* ╲ │ ╱ z_near |
* left ╲ │ ╱ | |
* clip 60°fovy | |
* plane ╳----------------------
* |
* |
* origin line
*
* The area of interest is the triangle labeled (1) at the top left
* marked with the ... line (a) from where the origin line crosses
* the near plane to the top left where the stage line cross the
* left clip plane.
*
* The sides of the triangle are a, b and c and the corresponding
* angles opposite those sides are A, B and C.
*
* The angle of C is what trades off the gap size we have relative
* to the stage size vs the depth precision we have.
*
* As mentioned above we arove at the angle for C is by working
* backwards from how much space we want for test-texture-quality.
* With a stage_height of 480 we want a gap > 400, ideally we also
* wanted a somewhat round number as a percentage of the height for
* documentation purposes. ~87% or a gap of ~416 is the limit
* because that's where we approach a C angle of 0° and effectively
* loose all depth precision.
*
* So for our test app with a stage_height of 480 if we aim for a
* gap of 408 (85% of 480) we can get the angle D as
* atan (stage_height/2/408) = 30.5°.
*
* That gives us the angle for B as 90° - 30.5° = 59.5°
*
* We can already determine that A has an angle of (fovy/2 + 90°) =
* 120°
*
* Therefore C = 180 - A - B = 0.5°
*
* The length of c = z_near * tan (30°)
*
* Now we can use the rule a/SinA = c/SinC to calculate the
* length of a. After some rearranging that gives us:
*
* a c
* ---------- = ----------
* sin (120°) sin (0.5°)
*
* c * sin (120°)
* a = --------------
* sin (0.5°)
*
* And with that we can determine z_2d = cos (D) * a =
* cos (30.5°) * a + z_near:
*
* c * sin (120°) * cos (30.5°)
* z_2d = --------------------------- + z_near
* sin (0.5°)
*/
/* We expect the compiler should boil this down to z_near * CONSTANT
* already, but just in case we use precomputed constants
*/
#if 0
# define A tanf (_DEG_TO_RAD (30.f))
# define B sinf (_DEG_TO_RAD (120.f))
# define C cosf (_DEG_TO_RAD (30.5f))
# define D sinf (_DEG_TO_RAD (.5f))
#else
# define A 0.57735025882720947265625f
# define B 0.866025388240814208984375f
# define C 0.86162912845611572265625f
# define D 0.00872653536498546600341796875f
#endif
return z_near
* A * B * C
/ D
+ z_near;
}
void
_clutter_stage_maybe_setup_viewport (ClutterStage *stage)
{
ClutterStagePrivate *priv = stage->priv;
if (priv->dirty_viewport)
{
ClutterPerspective perspective;
int window_scale;
float z_2d;
CLUTTER_NOTE (PAINT,
"Setting up the viewport { w:%f, h:%f }",
priv->viewport[2],
priv->viewport[3]);
window_scale = _clutter_stage_window_get_scale_factor (priv->impl);
cogl_set_viewport (priv->viewport[0] * window_scale,
priv->viewport[1] * window_scale,
priv->viewport[2] * window_scale,
priv->viewport[3] * window_scale);
perspective = priv->perspective;
/* Ideally we want to regenerate the perspective matrix whenever
* the size changes but if the user has provided a custom matrix
* then we don't want to override it */
if (!priv->has_custom_perspective)
{
perspective.aspect = priv->viewport[2] / priv->viewport[3];
z_2d = calculate_z_translation (perspective.z_near);
/* NB: z_2d is only enough room for 85% of the stage_height between
* the stage and the z_near plane. For behind the stage plane we
* want a more consistent gap of 10 times the stage_height before
* hitting the far plane so we calculate that relative to the final
* height of the stage plane at the z_2d_distance we got... */
perspective.z_far = z_2d +
tanf (_DEG_TO_RAD (perspective.fovy / 2.0f)) * z_2d * 20.0f;
clutter_stage_set_perspective_internal (stage, &perspective);
}
else
z_2d = calculate_z_translation (perspective.z_near);
cogl_matrix_init_identity (&priv->view);
cogl_matrix_view_2d_in_perspective (&priv->view,
perspective.fovy,
perspective.aspect,
perspective.z_near,
z_2d,
priv->viewport[2] * window_scale,
priv->viewport[3] * window_scale);
clutter_stage_apply_scale (stage);
priv->dirty_viewport = FALSE;
}
if (priv->dirty_projection)
{
cogl_set_projection_matrix (&priv->projection);
priv->dirty_projection = FALSE;
}
}
#undef _DEG_TO_RAD
/**
* clutter_stage_ensure_redraw:
* @stage: a #ClutterStage
*
* Ensures that @stage is redrawn
*
* This function should not be called by applications: it is
* used when embedding a #ClutterStage into a toolkit with
* another windowing system, like GTK+.
*
* Since: 1.0
*/
void
clutter_stage_ensure_redraw (ClutterStage *stage)
{
ClutterMasterClock *master_clock;
ClutterStagePrivate *priv;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
priv = stage->priv;
if (!priv->relayout_pending && !priv->redraw_pending)
_clutter_stage_schedule_update (stage);
priv->relayout_pending = TRUE;
priv->redraw_pending = TRUE;
master_clock = _clutter_master_clock_get_default ();
_clutter_master_clock_start_running (master_clock);
}
/**
* clutter_stage_queue_redraw:
* @stage: the #ClutterStage
*
* Queues a redraw for the passed stage.
*
* Applications should call clutter_actor_queue_redraw() and not
* this function.
*
* Since: 0.8
*
* Deprecated: 1.10: Use clutter_actor_queue_redraw() instead.
*/
void
clutter_stage_queue_redraw (ClutterStage *stage)
{
g_return_if_fail (CLUTTER_IS_STAGE (stage));
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
}
/**
* clutter_stage_is_default:
* @stage: a #ClutterStage
*
* Checks if @stage is the default stage, or an instance created using
* clutter_stage_new() but internally using the same implementation.
*
* Return value: %TRUE if the passed stage is the default one
*
* Since: 0.8
*
* Deprecated: 1.10: Track the stage pointer inside your application
* code, or use clutter_actor_get_stage() to retrieve the stage for
* a given actor.
*/
gboolean
clutter_stage_is_default (ClutterStage *stage)
{
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), FALSE);
return stage_is_default (stage);
}
void
_clutter_stage_set_window (ClutterStage *stage,
ClutterStageWindow *stage_window)
{
g_return_if_fail (CLUTTER_IS_STAGE (stage));
g_return_if_fail (CLUTTER_IS_STAGE_WINDOW (stage_window));
if (stage->priv->impl != NULL)
g_object_unref (stage->priv->impl);
stage->priv->impl = stage_window;
}
ClutterStageWindow *
_clutter_stage_get_window (ClutterStage *stage)
{
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), NULL);
return CLUTTER_STAGE_WINDOW (stage->priv->impl);
}
ClutterStageWindow *
_clutter_stage_get_default_window (void)
{
ClutterStageManager *manager = clutter_stage_manager_get_default ();
ClutterStage *stage;
stage = clutter_stage_manager_get_default_stage (manager);
if (stage == NULL)
return NULL;
return _clutter_stage_get_window (stage);
}
/**
* clutter_stage_set_throttle_motion_events:
* @stage: a #ClutterStage
* @throttle: %TRUE to throttle motion events
*
* Sets whether motion events received between redraws should
* be throttled or not. If motion events are throttled, those
* events received by the windowing system between redraws will
* be compressed so that only the last event will be propagated
* to the @stage and its actors.
*
* This function should only be used if you want to have all
* the motion events delivered to your application code.
*
* Since: 1.0
*/
void
clutter_stage_set_throttle_motion_events (ClutterStage *stage,
gboolean throttle)
{
ClutterStagePrivate *priv;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
priv = stage->priv;
if (priv->throttle_motion_events != throttle)
priv->throttle_motion_events = throttle;
}
/**
* clutter_stage_get_throttle_motion_events:
* @stage: a #ClutterStage
*
* Retrieves the value set with clutter_stage_set_throttle_motion_events()
*
* Return value: %TRUE if the motion events are being throttled,
* and %FALSE otherwise
*
* Since: 1.0
*/
gboolean
clutter_stage_get_throttle_motion_events (ClutterStage *stage)
{
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), FALSE);
return stage->priv->throttle_motion_events;
}
/**
* clutter_stage_set_use_alpha:
* @stage: a #ClutterStage
* @use_alpha: whether the stage should honour the opacity or the
* alpha channel of the stage color
*
* Sets whether the @stage should honour the #ClutterActor:opacity and
* the alpha channel of the #ClutterStage:color
*
* Since: 1.2
*/
void
clutter_stage_set_use_alpha (ClutterStage *stage,
gboolean use_alpha)
{
ClutterStagePrivate *priv;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
priv = stage->priv;
if (priv->use_alpha != use_alpha)
{
priv->use_alpha = use_alpha;
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
g_object_notify (G_OBJECT (stage), "use-alpha");
}
}
/**
* clutter_stage_get_use_alpha:
* @stage: a #ClutterStage
*
* Retrieves the value set using clutter_stage_set_use_alpha()
*
* Return value: %TRUE if the stage should honour the opacity and the
* alpha channel of the stage color
*
* Since: 1.2
*/
gboolean
clutter_stage_get_use_alpha (ClutterStage *stage)
{
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), FALSE);
return stage->priv->use_alpha;
}
/**
* clutter_stage_set_minimum_size:
* @stage: a #ClutterStage
* @width: width, in pixels
* @height: height, in pixels
*
* Sets the minimum size for a stage window, if the default backend
* uses #ClutterStage inside a window
*
* This is a convenience function, and it is equivalent to setting the
* #ClutterActor:min-width and #ClutterActor:min-height on @stage
*
* If the current size of @stage is smaller than the minimum size, the
* @stage will be resized to the new @width and @height
*
* This function has no effect if @stage is fullscreen
*
* Since: 1.2
*/
void
clutter_stage_set_minimum_size (ClutterStage *stage,
guint width,
guint height)
{
g_return_if_fail (CLUTTER_IS_STAGE (stage));
g_return_if_fail ((width > 0) && (height > 0));
g_object_set (G_OBJECT (stage),
"min-width", (gfloat) width,
"min-height", (gfloat )height,
NULL);
}
/**
* clutter_stage_get_minimum_size:
* @stage: a #ClutterStage
* @width: (out): return location for the minimum width, in pixels,
* or %NULL
* @height: (out): return location for the minimum height, in pixels,
* or %NULL
*
* Retrieves the minimum size for a stage window as set using
* clutter_stage_set_minimum_size().
*
* The returned size may not correspond to the actual minimum size and
* it is specific to the #ClutterStage implementation inside the
* Clutter backend
*
* Since: 1.2
*/
void
clutter_stage_get_minimum_size (ClutterStage *stage,
guint *width_p,
guint *height_p)
{
gfloat width, height;
gboolean width_set, height_set;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
g_object_get (G_OBJECT (stage),
"min-width", &width,
"min-width-set", &width_set,
"min-height", &height,
"min-height-set", &height_set,
NULL);
/* if not width or height have been set, then the Stage
* minimum size is defined to be 1x1
*/
if (!width_set)
width = 1;
if (!height_set)
height = 1;
if (width_p)
*width_p = (guint) width;
if (height_p)
*height_p = (guint) height;
}
void
_clutter_stage_schedule_update (ClutterStage *stage)
{
ClutterStageWindow *stage_window;
if (CLUTTER_ACTOR_IN_DESTRUCTION (stage))
return;
stage_window = _clutter_stage_get_window (stage);
if (stage_window == NULL)
return;
return _clutter_stage_window_schedule_update (stage_window,
stage->priv->sync_delay);
}
/* Returns the earliest time the stage is ready to update */
gint64
_clutter_stage_get_update_time (ClutterStage *stage)
{
ClutterStageWindow *stage_window;
if (CLUTTER_ACTOR_IN_DESTRUCTION (stage))
return 0;
stage_window = _clutter_stage_get_window (stage);
if (stage_window == NULL)
return 0;
return _clutter_stage_window_get_update_time (stage_window);
}
void
_clutter_stage_clear_update_time (ClutterStage *stage)
{
ClutterStageWindow *stage_window;
stage_window = _clutter_stage_get_window (stage);
if (stage_window)
_clutter_stage_window_clear_update_time (stage_window);
}
/**
* clutter_stage_set_no_clear_hint:
* @stage: a #ClutterStage
* @no_clear: %TRUE if the @stage should not clear itself on every
* repaint cycle
*
* Sets whether the @stage should clear itself at the beginning
* of each paint cycle or not.
*
* Clearing the #ClutterStage can be a costly operation, especially
* if the stage is always covered - for instance, in a full-screen
* video player or in a game with a background texture.
*
* This setting is a hint; Clutter might discard this hint
* depending on its internal state.
*
* If parts of the stage are visible and you disable clearing you
* might end up with visual artifacts while painting the contents of
* the stage.
*
* Since: 1.4
*/
void
clutter_stage_set_no_clear_hint (ClutterStage *stage,
gboolean no_clear)
{
ClutterStagePrivate *priv;
ClutterStageHint new_hints;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
priv = stage->priv;
new_hints = priv->stage_hints;
if (no_clear)
new_hints |= CLUTTER_STAGE_NO_CLEAR_ON_PAINT;
else
new_hints &= ~CLUTTER_STAGE_NO_CLEAR_ON_PAINT;
if (priv->stage_hints == new_hints)
return;
priv->stage_hints = new_hints;
g_object_notify (G_OBJECT (stage), "no-clear-hint");
}
/**
* clutter_stage_get_no_clear_hint:
* @stage: a #ClutterStage
*
* Retrieves the hint set with clutter_stage_set_no_clear_hint()
*
* Return value: %TRUE if the stage should not clear itself on every paint
* cycle, and %FALSE otherwise
*
* Since: 1.4
*/
gboolean
clutter_stage_get_no_clear_hint (ClutterStage *stage)
{
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), FALSE);
return (stage->priv->stage_hints & CLUTTER_STAGE_NO_CLEAR_ON_PAINT) != 0;
}
ClutterPaintVolume *
_clutter_stage_paint_volume_stack_allocate (ClutterStage *stage)
{
GArray *paint_volume_stack = stage->priv->paint_volume_stack;
g_array_set_size (paint_volume_stack,
paint_volume_stack->len+1);
return &g_array_index (paint_volume_stack,
ClutterPaintVolume,
paint_volume_stack->len - 1);
}
void
_clutter_stage_paint_volume_stack_free_all (ClutterStage *stage)
{
GArray *paint_volume_stack = stage->priv->paint_volume_stack;
int i;
for (i = 0; i < paint_volume_stack->len; i++)
{
ClutterPaintVolume *pv =
&g_array_index (paint_volume_stack, ClutterPaintVolume, i);
clutter_paint_volume_free (pv);
}
g_array_set_size (paint_volume_stack, 0);
}
/* The is an out-of-band paramater available while painting that
* can be used to cull actors. */
const ClutterPlane *
_clutter_stage_get_clip (ClutterStage *stage)
{
return stage->priv->current_clip_planes;
}
/* When an actor queues a redraw we add it to a list on the stage that
* gets processed once all updates to the stage have been finished.
*
* This deferred approach to processing queue_redraw requests means
* that we can avoid redundant transformations of clip volumes if
* something later triggers a full stage redraw anyway. It also means
* we can be more sure that all the referenced actors will have valid
* allocations improving the chance that we can determine the actors
* paint volume so we can clip the redraw request even if the user
* didn't explicitly do so.
*/
ClutterStageQueueRedrawEntry *
_clutter_stage_queue_actor_redraw (ClutterStage *stage,
ClutterStageQueueRedrawEntry *entry,
ClutterActor *actor,
ClutterPaintVolume *clip)
{
ClutterStagePrivate *priv = stage->priv;
CLUTTER_NOTE (CLIPPING, "stage_queue_actor_redraw (actor=%s, clip=%p): ",
_clutter_actor_get_debug_name (actor), clip);
if (!priv->redraw_pending)
{
ClutterMasterClock *master_clock;
CLUTTER_NOTE (PAINT, "First redraw request");
_clutter_stage_schedule_update (stage);
priv->redraw_pending = TRUE;
master_clock = _clutter_master_clock_get_default ();
_clutter_master_clock_start_running (master_clock);
}
#ifdef CLUTTER_ENABLE_DEBUG
else
{
CLUTTER_NOTE (PAINT, "Redraw request number %lu",
priv->redraw_count + 1);
priv->redraw_count += 1;
}
#endif /* CLUTTER_ENABLE_DEBUG */
if (entry)
{
/* Ignore all requests to queue a redraw for an actor if a full
* (non-clipped) redraw of the actor has already been queued. */
if (!entry->has_clip)
{
CLUTTER_NOTE (CLIPPING, "Bail from stage_queue_actor_redraw (%s): "
"Unclipped redraw of actor already queued",
_clutter_actor_get_debug_name (actor));
return entry;
}
/* If queuing a clipped redraw and a clipped redraw has
* previously been queued for this actor then combine the latest
* clip together with the existing clip */
if (clip)
clutter_paint_volume_union (&entry->clip, clip);
else
{
clutter_paint_volume_free (&entry->clip);
entry->has_clip = FALSE;
}
return entry;
}
else
{
entry = g_slice_new (ClutterStageQueueRedrawEntry);
entry->actor = g_object_ref (actor);
if (clip)
{
entry->has_clip = TRUE;
_clutter_paint_volume_init_static (&entry->clip, actor);
_clutter_paint_volume_set_from_volume (&entry->clip, clip);
}
else
entry->has_clip = FALSE;
stage->priv->pending_queue_redraws =
g_list_prepend (stage->priv->pending_queue_redraws, entry);
return entry;
}
}
static void
free_queue_redraw_entry (ClutterStageQueueRedrawEntry *entry)
{
if (entry->actor)
g_object_unref (entry->actor);
if (entry->has_clip)
clutter_paint_volume_free (&entry->clip);
g_slice_free (ClutterStageQueueRedrawEntry, entry);
}
void
_clutter_stage_queue_redraw_entry_invalidate (ClutterStageQueueRedrawEntry *entry)
{
if (entry == NULL)
return;
if (entry->actor != NULL)
{
g_object_unref (entry->actor);
entry->actor = NULL;
}
if (entry->has_clip)
{
clutter_paint_volume_free (&entry->clip);
entry->has_clip = FALSE;
}
}
static void
clutter_stage_maybe_finish_queue_redraws (ClutterStage *stage)
{
/* Note: we have to repeat until the pending_queue_redraws list is
* empty because actors are allowed to queue redraws in response to
* the queue-redraw signal. For example Clone actors or
* texture_new_from_actor actors will have to queue a redraw if
* their source queues a redraw.
*/
while (stage->priv->pending_queue_redraws)
{
GList *l;
/* XXX: we need to allow stage->priv->pending_queue_redraws to
* be updated while we process the current entries in the list
* so we steal the list pointer and then reset it to an empty
* list before processing... */
GList *stolen_list = stage->priv->pending_queue_redraws;
stage->priv->pending_queue_redraws = NULL;
for (l = stolen_list; l; l = l->next)
{
ClutterStageQueueRedrawEntry *entry = l->data;
ClutterPaintVolume *clip;
/* NB: Entries may be invalidated if the actor gets destroyed */
if (G_LIKELY (entry->actor != NULL))
{
clip = entry->has_clip ? &entry->clip : NULL;
_clutter_actor_finish_queue_redraw (entry->actor, clip);
}
free_queue_redraw_entry (entry);
}
g_list_free (stolen_list);
}
}
/**
* clutter_stage_set_accept_focus:
* @stage: a #ClutterStage
* @accept_focus: %TRUE to accept focus on show
*
* Sets whether the @stage should accept the key focus when shown.
*
* This function should be called before showing @stage using
* clutter_actor_show().
*
* Since: 1.6
*/
void
clutter_stage_set_accept_focus (ClutterStage *stage,
gboolean accept_focus)
{
ClutterStagePrivate *priv;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
accept_focus = !!accept_focus;
priv = stage->priv;
if (priv->accept_focus != accept_focus)
{
_clutter_stage_window_set_accept_focus (priv->impl, accept_focus);
g_object_notify (G_OBJECT (stage), "accept-focus");
}
}
/**
* clutter_stage_get_accept_focus:
* @stage: a #ClutterStage
*
* Retrieves the value set with clutter_stage_set_accept_focus().
*
* Return value: %TRUE if the #ClutterStage should accept focus, and %FALSE
* otherwise
*
* Since: 1.6
*/
gboolean
clutter_stage_get_accept_focus (ClutterStage *stage)
{
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), TRUE);
return stage->priv->accept_focus;
}
/**
* clutter_stage_set_motion_events_enabled:
* @stage: a #ClutterStage
* @enabled: %TRUE to enable the motion events delivery, and %FALSE
* otherwise
*
* Sets whether per-actor motion events (and relative crossing
* events) should be disabled or not.
*
* The default is %TRUE.
*
* If @enable is %FALSE the following signals will not be emitted
* by the actors children of @stage:
*
* - #ClutterActor::motion-event
* - #ClutterActor::enter-event
* - #ClutterActor::leave-event
*
* The events will still be delivered to the #ClutterStage.
*
* The main side effect of this function is that disabling the motion
* events will disable picking to detect the #ClutterActor underneath
* the pointer for each motion event. This is useful, for instance,
* when dragging a #ClutterActor across the @stage: the actor underneath
* the pointer is not going to change, so it's meaningless to perform
* a pick.
*
* Since: 1.8
*/
void
clutter_stage_set_motion_events_enabled (ClutterStage *stage,
gboolean enabled)
{
ClutterStagePrivate *priv;
g_return_if_fail (CLUTTER_IS_STAGE (stage));
priv = stage->priv;
enabled = !!enabled;
if (priv->motion_events_enabled != enabled)
priv->motion_events_enabled = enabled;
}
/**
* clutter_stage_get_motion_events_enabled:
* @stage: a #ClutterStage
*
* Retrieves the value set using clutter_stage_set_motion_events_enabled().
*
* Return value: %TRUE if the per-actor motion event delivery is enabled
* and %FALSE otherwise
*
* Since: 1.8
*/
gboolean
clutter_stage_get_motion_events_enabled (ClutterStage *stage)
{
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), FALSE);
return stage->priv->motion_events_enabled;
}
/* NB: The presumption shouldn't be that a stage can't be comprised
* of multiple internal framebuffers, so instead of simply naming
* this function _clutter_stage_get_framebuffer(), the "active"
* infix is intended to clarify that it gets the framebuffer that
* is currently in use/being painted.
*/
CoglFramebuffer *
_clutter_stage_get_active_framebuffer (ClutterStage *stage)
{
return stage->priv->active_framebuffer;
}
gint32
_clutter_stage_acquire_pick_id (ClutterStage *stage,
ClutterActor *actor)
{
ClutterStagePrivate *priv = stage->priv;
g_assert (priv->pick_id_pool != NULL);
return _clutter_id_pool_add (priv->pick_id_pool, actor);
}
void
_clutter_stage_release_pick_id (ClutterStage *stage,
gint32 pick_id)
{
ClutterStagePrivate *priv = stage->priv;
g_assert (priv->pick_id_pool != NULL);
_clutter_id_pool_remove (priv->pick_id_pool, pick_id);
}
ClutterActor *
_clutter_stage_get_actor_by_pick_id (ClutterStage *stage,
gint32 pick_id)
{
ClutterStagePrivate *priv = stage->priv;
g_assert (priv->pick_id_pool != NULL);
return _clutter_id_pool_lookup (priv->pick_id_pool, pick_id);
}
void
_clutter_stage_add_pointer_drag_actor (ClutterStage *stage,
ClutterInputDevice *device,
ClutterActor *actor)
{
GHashTable *drag_actors;
drag_actors = g_object_get_data (G_OBJECT (stage),
"__clutter_stage_pointer_drag_actors");
if (drag_actors == NULL)
{
drag_actors = g_hash_table_new (NULL, NULL);
g_object_set_data_full (G_OBJECT (stage),
"__clutter_stage_pointer_drag_actors",
drag_actors,
(GDestroyNotify) g_hash_table_destroy);
}
g_hash_table_replace (drag_actors, device, actor);
}
ClutterActor *
_clutter_stage_get_pointer_drag_actor (ClutterStage *stage,
ClutterInputDevice *device)
{
GHashTable *drag_actors;
drag_actors = g_object_get_data (G_OBJECT (stage),
"__clutter_stage_pointer_drag_actors");
if (drag_actors == NULL)
return NULL;
return g_hash_table_lookup (drag_actors, device);
}
void
_clutter_stage_remove_pointer_drag_actor (ClutterStage *stage,
ClutterInputDevice *device)
{
GHashTable *drag_actors;
drag_actors = g_object_get_data (G_OBJECT (stage),
"__clutter_stage_pointer_drag_actors");
if (drag_actors == NULL)
return;
g_hash_table_remove (drag_actors, device);
if (g_hash_table_size (drag_actors) == 0)
g_object_set_data (G_OBJECT (stage),
"__clutter_stage_pointer_drag_actors",
NULL);
}
void
_clutter_stage_add_touch_drag_actor (ClutterStage *stage,
ClutterEventSequence *sequence,
ClutterActor *actor)
{
GHashTable *drag_actors;
drag_actors = g_object_get_data (G_OBJECT (stage),
"__clutter_stage_touch_drag_actors");
if (drag_actors == NULL)
{
drag_actors = g_hash_table_new (NULL, NULL);
g_object_set_data_full (G_OBJECT (stage),
"__clutter_stage_touch_drag_actors",
drag_actors,
(GDestroyNotify) g_hash_table_destroy);
}
g_hash_table_replace (drag_actors, sequence, actor);
}
ClutterActor *
_clutter_stage_get_touch_drag_actor (ClutterStage *stage,
ClutterEventSequence *sequence)
{
GHashTable *drag_actors;
drag_actors = g_object_get_data (G_OBJECT (stage),
"__clutter_stage_touch_drag_actors");
if (drag_actors == NULL)
return NULL;
return g_hash_table_lookup (drag_actors, sequence);
}
void
_clutter_stage_remove_touch_drag_actor (ClutterStage *stage,
ClutterEventSequence *sequence)
{
GHashTable *drag_actors;
drag_actors = g_object_get_data (G_OBJECT (stage),
"__clutter_stage_touch_drag_actors");
if (drag_actors == NULL)
return;
g_hash_table_remove (drag_actors, sequence);
if (g_hash_table_size (drag_actors) == 0)
g_object_set_data (G_OBJECT (stage),
"__clutter_stage_touch_drag_actors",
NULL);
}
/*< private >
* _clutter_stage_get_state:
* @stage: a #ClutterStage
*
* Retrieves the current #ClutterStageState flags associated to the @stage.
*
* Return value: a bitwise OR of #ClutterStageState flags
*/
ClutterStageState
_clutter_stage_get_state (ClutterStage *stage)
{
return stage->priv->current_state;
}
/*< private >
* _clutter_stage_is_activated:
* @stage: a #ClutterStage
*
* Checks whether the @stage state includes %CLUTTER_STAGE_STATE_ACTIVATED.
*
* Return value: %TRUE if the @stage is active
*/
gboolean
_clutter_stage_is_activated (ClutterStage *stage)
{
return (stage->priv->current_state & CLUTTER_STAGE_STATE_ACTIVATED) != 0;
}
/*< private >
* _clutter_stage_is_fullscreen:
* @stage: a #ClutterStage
*
* Checks whether the @stage state includes %CLUTTER_STAGE_STATE_FULLSCREEN.
*
* Return value: %TRUE if the @stage is fullscreen
*/
gboolean
_clutter_stage_is_fullscreen (ClutterStage *stage)
{
return (stage->priv->current_state & CLUTTER_STAGE_STATE_FULLSCREEN) != 0;
}
/*< private >
* _clutter_stage_update_state:
* @stage: a #ClutterStage
* @unset_flags: flags to unset
* @set_flags: flags to set
*
* Updates the state of @stage, by unsetting the @unset_flags and setting
* the @set_flags.
*
* If the stage state has been changed, this function will queue a
* #ClutterEvent of type %CLUTTER_STAGE_STATE.
*
* Return value: %TRUE if the state was updated, and %FALSE otherwise
*/
gboolean
_clutter_stage_update_state (ClutterStage *stage,
ClutterStageState unset_flags,
ClutterStageState set_flags)
{
ClutterStageState new_state;
ClutterEvent event;
new_state = stage->priv->current_state;
new_state |= set_flags;
new_state &= ~unset_flags;
if (new_state == stage->priv->current_state)
return FALSE;
memset (&event, 0, sizeof (event));
event.type = CLUTTER_STAGE_STATE;
clutter_event_set_stage (&event, stage);
event.stage_state.new_state = new_state;
event.stage_state.changed_mask = new_state ^ stage->priv->current_state;
stage->priv->current_state = new_state;
clutter_stage_event (stage, &event);
return TRUE;
}
/**
* clutter_stage_set_sync_delay:
* @stage: a #ClutterStage
* @sync_delay: number of milliseconds after frame presentation to wait
* before painting the next frame. If less than zero, restores the
* default behavior where redraw is throttled to the refresh rate but
* not synchronized to it.
*
* This function enables an alternate behavior where Clutter draws at
* a fixed point in time after the frame presentation time (also known
* as the VBlank time). This is most useful when the application
* wants to show incoming data with predictable latency. (The primary
* example of this would be a window system compositor.) By synchronizing
* to provide new data before Clutter redraws, an external source of
* updates (in the compositor, an application) can get a reliable latency.
*
* The appropriate value of @sync_delay depends on the complexity of
* drawing the stage's scene graph - in general a value of between 0
* and 8 ms (up to one-half of a typical 60hz frame rate) is appropriate.
* using a larger value will reduce latency but risks skipping a frame if
* drawing the stage takes too long.
*
* Since: 1.14
* Stability: unstable
*/
void
clutter_stage_set_sync_delay (ClutterStage *stage,
gint sync_delay)
{
g_return_if_fail (CLUTTER_IS_STAGE (stage));
stage->priv->sync_delay = sync_delay;
}
/**
* clutter_stage_skip_sync_delay:
* @stage: a #ClutterStage
*
* Causes the next frame for the stage to be drawn as quickly as
* possible, ignoring any delay that clutter_stage_set_sync_delay()
* would normally cause.
*
* Since: 1.14
* Stability: unstable
*/
void
clutter_stage_skip_sync_delay (ClutterStage *stage)
{
ClutterStageWindow *stage_window;
stage_window = _clutter_stage_get_window (stage);
if (stage_window)
_clutter_stage_window_schedule_update (stage_window, -1);
}
void
_clutter_stage_set_scale_factor (ClutterStage *stage,
int factor)
{
ClutterStagePrivate *priv = stage->priv;
if (CLUTTER_ACTOR_IN_DESTRUCTION (stage))
return;
if (priv->impl == NULL)
return;
_clutter_stage_window_set_scale_factor (priv->impl, factor);
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
}
|