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
|
/* $Xorg: mibstore.c,v 1.4 2001/02/09 02:05:20 xorgcvs Exp $ */
/***********************************************************
Copyright 1987, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
Copyright 1987 by the Regents of the University of California
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation, and that the name The Open Group not be used in advertising or publicity
pertaining to distribution of the software without specific, written prior
permission.
The University of California makes no representations about the suitability
of this software for any purpose. It is provided "as is" without express or
implied warranty.
******************************************************************/
/* $XFree86: xc/programs/Xserver/mi/mibstore.c,v 1.11 2003/11/10 18:22:47 tsi Exp $ */
#define NEED_EVENTS
#include "X.h"
#include "Xmd.h"
#include "Xproto.h"
#include "misc.h"
#include "regionstr.h"
#include "scrnintstr.h"
#include "gcstruct.h"
#include "windowstr.h"
#include "pixmapstr.h"
#include "fontstruct.h"
#include "dixfontstr.h"
#include "dixstruct.h" /* For requestingClient */
#include "mi.h"
#include "mibstorest.h"
/*
* When the server fails to allocate a backing store pixmap, if you want
* it to dynamically retry to allocate backing store on every subsequent
* graphics op, you can enable BSEAGER; otherwise, backing store will be
* disabled on the window until it is unmapped and then remapped.
*/
/* #define BSEAGER */
/*-
* NOTES ON USAGE:
*
* The functions in this file implement a machine-independent backing-store
* scheme. To use it, the output library must do the following:
* - Provide a SaveAreas function that takes a destination pixmap, a
* region of the areas to save (in the pixmap's coordinate system)
* and the screen origin of the region. It should copy the areas from
* the screen into the pixmap.
* - Provide a RestoreAreas function that takes a source pixmap, a region
* of the areas to restore (in the screen's coordinate system) and the
* origin of the pixmap on the screen. It should copy the areas from
* the pixmap into the screen.
* - Provide a SetClipmaskRgn function that takes a gc and a region
* and merges the region into any CT_PIXMAP client clip that
* is specified in the GC. This routine is only needed if
* miValidateBackingStore will see CT_PIXMAP clip lists; not
* true for any of the sample servers (which convert the PIXMAP
* clip lists into CT_REGION clip lists; an expensive but simple
* to code option).
* - The function placed in a window's ClearToBackground vector must call
* pScreen->ClearBackingStore with the window, followed by
* the window-relative x and y coordinates, followed by the width and
* height of the area to be cleared, followed by the generateExposures
* flag. This has been taken care of in miClearToBackground.
* - Whatever determines GraphicsExpose events for the CopyArea and
* CopyPlane requests should call pWin->backStorage->ExposeCopy
* with the source and destination drawables, the GC used, a source-
* window-relative region of exposed areas, the source and destination
* coordinates and the bitplane copied, if CopyPlane, or 0, if
* CopyArea.
*
* JUSTIFICATION
* This is a cross between saving everything and just saving the
* obscued areas (as in Pike's layers.) This method has the advantage
* of only doing each output operation once per pixel, visible or
* invisible, and avoids having to do all the crufty storage
* management of keeping several separate rectangles. Since the
* ddx layer ouput primitives are required to draw through clipping
* rectangles anyway, sending multiple drawing requests for each of
* several rectangles isn't necessary. (Of course, it could be argued
* that the ddx routines should just take one rectangle each and
* get called multiple times, but that would make taking advantage of
* smart hardware harder, and probably be slower as well.)
*/
#define SETUP_BACKING_TERSE(pGC) \
miBSGCPtr pGCPrivate = (miBSGCPtr)(pGC)->devPrivates[miBSGCIndex].ptr; \
GCFuncs *oldFuncs = pGC->funcs;
#define SETUP_BACKING(pDrawable,pGC) \
miBSWindowPtr pBackingStore = \
(miBSWindowPtr)((WindowPtr)(pDrawable))->backStorage; \
DrawablePtr pBackingDrawable = (DrawablePtr) \
pBackingStore->pBackingPixmap; \
SETUP_BACKING_TERSE(pGC) \
GCPtr pBackingGC = pGCPrivate->pBackingGC;
#define PROLOGUE(pGC) { \
pGC->ops = pGCPrivate->wrapOps;\
pGC->funcs = pGCPrivate->wrapFuncs; \
}
#define EPILOGUE(pGC) { \
pGCPrivate->wrapOps = (pGC)->ops; \
(pGC)->ops = &miBSGCOps; \
(pGC)->funcs = oldFuncs; \
}
static void miCreateBSPixmap(WindowPtr pWin, BoxPtr pExtents);
static void miDestroyBSPixmap(WindowPtr pWin);
static void miTileVirtualBS(WindowPtr pWin);
static void miBSAllocate(WindowPtr pWin), miBSFree(WindowPtr pWin);
static Bool miBSCreateGCPrivate(GCPtr pGC);
static void miBSClearBackingRegion(WindowPtr pWin, RegionPtr pRgn);
#define MoreCopy0 ;
#define MoreCopy2 *dstCopy++ = *srcCopy++; *dstCopy++ = *srcCopy++;
#define MoreCopy4 MoreCopy2 MoreCopy2
#define copyData(src,dst,n,morecopy) \
{ \
register short *srcCopy = (short *)(src); \
register short *dstCopy = (short *)(dst); \
register int i; \
register int bsx = pBackingStore->x; \
register int bsy = pBackingStore->y; \
for (i = n; --i >= 0; ) \
{ \
*dstCopy++ = *srcCopy++ - bsx; \
*dstCopy++ = *srcCopy++ - bsy; \
morecopy \
} \
}
#define copyPoints(src,dst,n,mode) \
if (mode == CoordModeOrigin) \
{ \
copyData(src,dst,n,MoreCopy0); \
} \
else \
{ \
memmove((char *)(dst), (char *)(src), (n) << 2); \
*((short *)(dst)) -= pBackingStore->x; \
*((short *)(dst) + 1) -= pBackingStore->y; \
}
/*
* wrappers for screen funcs
*/
static int miBSScreenIndex;
static unsigned long miBSGeneration = 0;
static Bool miBSCloseScreen(int i, ScreenPtr pScreen);
static void miBSGetImage(DrawablePtr pDrawable, int sx, int sy,
int w, int h, unsigned int format,
unsigned long planemask, char *pdstLine);
static void miBSGetSpans(DrawablePtr pDrawable, int wMax,
DDXPointPtr ppt, int *pwidth, int nspans,
char *pdstStart);
static Bool miBSChangeWindowAttributes(WindowPtr pWin,
unsigned long mask);
static Bool miBSCreateGC(GCPtr pGC);
static Bool miBSDestroyWindow(WindowPtr pWin);
/*
* backing store screen functions
*/
static void miBSSaveDoomedAreas(WindowPtr pWin, RegionPtr pObscured,
int dx, int dy);
static RegionPtr miBSRestoreAreas(WindowPtr pWin, RegionPtr prgnExposed);
static void miBSExposeCopy(WindowPtr pSrc, DrawablePtr pDst,
GCPtr pGC, RegionPtr prgnExposed,
int srcx, int srcy, int dstx, int dsty,
unsigned long plane);
static RegionPtr miBSTranslateBackingStore(WindowPtr pWin, int windx,
int windy, RegionPtr oldClip,
int oldx, int oldy);
static RegionPtr miBSClearBackingStore(WindowPtr pWin, int x, int y,
int w, int h, Bool generateExposures);
static void miBSDrawGuarantee(WindowPtr pWin, GCPtr pGC,
int guarantee);
/*
* wrapper vectors for GC funcs and ops
*/
static int miBSGCIndex;
static void miBSValidateGC(GCPtr pGC, unsigned long stateChanges,
DrawablePtr pDrawable);
static void miBSCopyGC(GCPtr pGCSrc, unsigned long mask, GCPtr pGCDst);
static void miBSDestroyGC(GCPtr pGC);
static void miBSChangeGC(GCPtr pGC, unsigned long mask);
static void miBSChangeClip(GCPtr pGC, int type, pointer pvalue, int nrects);
static void miBSDestroyClip(GCPtr pGC);
static void miBSCopyClip(GCPtr pgcDst, GCPtr pgcSrc);
static GCFuncs miBSGCFuncs = {
miBSValidateGC,
miBSChangeGC,
miBSCopyGC,
miBSDestroyGC,
miBSChangeClip,
miBSDestroyClip,
miBSCopyClip,
};
static void miBSFillSpans(DrawablePtr pDrawable, GCPtr pGC, int nInit,
DDXPointPtr pptInit, int *pwidthInit,
int fSorted);
static void miBSSetSpans(DrawablePtr pDrawable, GCPtr pGC, char *psrc,
DDXPointPtr ppt, int *pwidth, int nspans,
int fSorted);
static void miBSPutImage(DrawablePtr pDrawable, GCPtr pGC, int depth,
int x, int y, int w, int h, int leftPad,
int format, char *pBits);
static RegionPtr miBSCopyArea(DrawablePtr pSrc, DrawablePtr pDst,
GCPtr pGC, int srcx, int srcy, int w, int h,
int dstx, int dsty);
static RegionPtr miBSCopyPlane(DrawablePtr pSrc, DrawablePtr pDst,
GCPtr pGC, int srcx, int srcy, int w, int h,
int dstx, int dsty, unsigned long plane);
static void miBSPolyPoint(DrawablePtr pDrawable, GCPtr pGC, int mode,
int npt, xPoint *pptInit);
static void miBSPolylines(DrawablePtr pDrawable, GCPtr pGC, int mode,
int npt, DDXPointPtr pptInit);
static void miBSPolySegment(DrawablePtr pDrawable, GCPtr pGC, int nseg,
xSegment *pSegs);
static void miBSPolyRectangle(DrawablePtr pDrawable, GCPtr pGC,
int nrects, xRectangle *pRects);
static void miBSPolyArc(DrawablePtr pDrawable, GCPtr pGC, int narcs,
xArc *parcs);
static void miBSFillPolygon(DrawablePtr pDrawable, GCPtr pGC,
int shape, int mode, int count,
DDXPointPtr pPts);
static void miBSPolyFillRect(DrawablePtr pDrawable, GCPtr pGC,
int nrectFill, xRectangle *prectInit);
static void miBSPolyFillArc(DrawablePtr pDrawable, GCPtr pGC,
int narcs, xArc *parcs);
static int miBSPolyText8(DrawablePtr pDrawable, GCPtr pGC,
int x, int y, int count, char *chars);
static int miBSPolyText16(DrawablePtr pDrawable, GCPtr pGC,
int x, int y, int count,
unsigned short *chars);
static void miBSImageText8(DrawablePtr pDrawable, GCPtr pGC,
int x, int y, int count, char *chars);
static void miBSImageText16(DrawablePtr pDrawable, GCPtr pGC,
int x, int y, int count,
unsigned short *chars);
static void miBSImageGlyphBlt(DrawablePtr pDrawable, GCPtr pGC,
int x, int y, unsigned int nglyph,
CharInfoPtr *ppci, pointer pglyphBase);
static void miBSPolyGlyphBlt(DrawablePtr pDrawable, GCPtr pGC,
int x, int y, unsigned int nglyph,
CharInfoPtr *ppci, pointer pglyphBase);
static void miBSPushPixels(GCPtr pGC, PixmapPtr pBitMap,
DrawablePtr pDst, int w, int h,
int x, int y);
#ifdef NEED_LINEHELPER
static void miBSLineHelper(void);
#endif
static GCOps miBSGCOps = {
miBSFillSpans, miBSSetSpans, miBSPutImage,
miBSCopyArea, miBSCopyPlane, miBSPolyPoint,
miBSPolylines, miBSPolySegment, miBSPolyRectangle,
miBSPolyArc, miBSFillPolygon, miBSPolyFillRect,
miBSPolyFillArc, miBSPolyText8, miBSPolyText16,
miBSImageText8, miBSImageText16, miBSImageGlyphBlt,
miBSPolyGlyphBlt, miBSPushPixels
#ifdef NEED_LINEHELPER
, miBSLineHelper
#endif
};
#define FUNC_PROLOGUE(pGC, pPriv) \
((pGC)->funcs = pPriv->wrapFuncs),\
((pGC)->ops = pPriv->wrapOps)
#define FUNC_EPILOGUE(pGC, pPriv) \
((pGC)->funcs = &miBSGCFuncs),\
((pGC)->ops = &miBSGCOps)
/*
* every GC in the server is initially wrapped with these
* "cheap" functions. This allocates no memory and is used
* to discover GCs used with windows which have backing
* store enabled
*/
static void miBSCheapValidateGC(GCPtr pGC, unsigned long stateChanges,
DrawablePtr pDrawable);
static void miBSCheapCopyGC(GCPtr pGCSrc, unsigned long mask, GCPtr pGCDst);
static void miBSCheapDestroyGC(GCPtr pGC);
static void miBSCheapChangeGC(GCPtr pGC, unsigned long mask);
static void miBSCheapChangeClip(GCPtr pGC, int type, pointer pvalue,
int nrects);
static void miBSCheapDestroyClip(GCPtr pGC);
static void miBSCheapCopyClip(GCPtr pgcDst, GCPtr pgcSrc);
static GCFuncs miBSCheapGCFuncs = {
miBSCheapValidateGC,
miBSCheapChangeGC,
miBSCheapCopyGC,
miBSCheapDestroyGC,
miBSCheapChangeClip,
miBSCheapDestroyClip,
miBSCheapCopyClip,
};
#define CHEAP_FUNC_PROLOGUE(pGC) \
((pGC)->funcs = (GCFuncs *) (pGC)->devPrivates[miBSGCIndex].ptr)
#define CHEAP_FUNC_EPILOGUE(pGC) \
((pGC)->funcs = &miBSCheapGCFuncs)
/*
* called from device screen initialization proc. Gets a GCPrivateIndex
* and wraps appropriate per-screen functions. pScreen->BackingStoreFuncs
* must be previously initialized.
*/
void
miInitializeBackingStore (pScreen)
ScreenPtr pScreen;
{
miBSScreenPtr pScreenPriv;
if (miBSGeneration != serverGeneration)
{
miBSScreenIndex = AllocateScreenPrivateIndex ();
if (miBSScreenIndex < 0)
return;
miBSGCIndex = AllocateGCPrivateIndex ();
miBSGeneration = serverGeneration;
}
if (!AllocateGCPrivate(pScreen, miBSGCIndex, 0))
return;
pScreenPriv = (miBSScreenPtr) xalloc (sizeof (miBSScreenRec));
if (!pScreenPriv)
return;
pScreenPriv->CloseScreen = pScreen->CloseScreen;
pScreenPriv->GetImage = pScreen->GetImage;
pScreenPriv->GetSpans = pScreen->GetSpans;
pScreenPriv->ChangeWindowAttributes = pScreen->ChangeWindowAttributes;
pScreenPriv->CreateGC = pScreen->CreateGC;
pScreenPriv->DestroyWindow = pScreen->DestroyWindow;
pScreen->CloseScreen = miBSCloseScreen;
pScreen->GetImage = miBSGetImage;
pScreen->GetSpans = miBSGetSpans;
pScreen->ChangeWindowAttributes = miBSChangeWindowAttributes;
pScreen->CreateGC = miBSCreateGC;
pScreen->DestroyWindow = miBSDestroyWindow;
pScreen->SaveDoomedAreas = miBSSaveDoomedAreas;
pScreen->RestoreAreas = miBSRestoreAreas;
pScreen->ExposeCopy = miBSExposeCopy;
pScreen->TranslateBackingStore = miBSTranslateBackingStore;
pScreen->ClearBackingStore = miBSClearBackingStore;
pScreen->DrawGuarantee = miBSDrawGuarantee;
pScreen->devPrivates[miBSScreenIndex].ptr = (pointer) pScreenPriv;
}
/*
* Screen function wrappers
*/
#define SCREEN_PROLOGUE(pScreen, field)\
((pScreen)->field = \
((miBSScreenPtr) \
(pScreen)->devPrivates[miBSScreenIndex].ptr)->field)
#define SCREEN_EPILOGUE(pScreen, field, wrapper)\
((pScreen)->field = wrapper)
/*
* CloseScreen wrapper -- unwrap everything, free the private data
* and call the wrapped function
*/
static Bool
miBSCloseScreen (i, pScreen)
int i;
ScreenPtr pScreen;
{
miBSScreenPtr pScreenPriv;
pScreenPriv = (miBSScreenPtr) pScreen->devPrivates[miBSScreenIndex].ptr;
pScreen->CloseScreen = pScreenPriv->CloseScreen;
pScreen->GetImage = pScreenPriv->GetImage;
pScreen->GetSpans = pScreenPriv->GetSpans;
pScreen->ChangeWindowAttributes = pScreenPriv->ChangeWindowAttributes;
pScreen->CreateGC = pScreenPriv->CreateGC;
xfree ((pointer) pScreenPriv);
return (*pScreen->CloseScreen) (i, pScreen);
}
static void miBSFillVirtualBits(DrawablePtr pDrawable, GCPtr pGC,
RegionPtr pRgn, int x, int y, int state,
PixUnion pixunion, unsigned long planemask);
static void
miBSGetImage (pDrawable, sx, sy, w, h, format, planemask, pdstLine)
DrawablePtr pDrawable;
int sx, sy, w, h;
unsigned int format;
unsigned long planemask;
char *pdstLine;
{
ScreenPtr pScreen = pDrawable->pScreen;
BoxRec bounds;
unsigned char depth;
SCREEN_PROLOGUE (pScreen, GetImage);
if (pDrawable->type != DRAWABLE_PIXMAP &&
((WindowPtr) pDrawable)->visibility != VisibilityUnobscured)
{
PixmapPtr pPixmap;
miBSWindowPtr pWindowPriv;
GCPtr pGC = NULL;
WindowPtr pWin, pSrcWin;
int xoff, yoff;
RegionRec Remaining;
RegionRec Border;
RegionRec Inside;
BoxPtr pBox;
int n;
pWin = (WindowPtr) pDrawable;
pPixmap = 0;
depth = pDrawable->depth;
bounds.x1 = sx + pDrawable->x;
bounds.y1 = sy + pDrawable->y;
bounds.x2 = bounds.x1 + w;
bounds.y2 = bounds.y1 + h;
REGION_INIT(pScreen, &Remaining, &bounds, 0);
for (;;)
{
bounds.x1 = sx + pDrawable->x - pWin->drawable.x;
bounds.y1 = sy + pDrawable->y - pWin->drawable.y;
bounds.x2 = bounds.x1 + w;
bounds.y2 = bounds.y1 + h;
if (pWin->viewable && pWin->backStorage &&
pWin->drawable.depth == depth &&
(RECT_IN_REGION(pScreen, &(pWindowPriv =
(miBSWindowPtr) pWin->backStorage)->SavedRegion,
&bounds) != rgnOUT ||
RECT_IN_REGION(pScreen, &Remaining,
REGION_EXTENTS(pScreen, &pWin->borderSize)) != rgnOUT))
{
if (!pPixmap)
{
XID subWindowMode = IncludeInferiors;
int x, y;
pPixmap = (*pScreen->CreatePixmap) (pScreen, w, h, depth);
if (!pPixmap)
goto punt;
pGC = GetScratchGC (depth, pScreen);
if (!pGC)
{
(*pScreen->DestroyPixmap) (pPixmap);
goto punt;
}
ChangeGC (pGC, GCSubwindowMode, &subWindowMode);
ValidateGC ((DrawablePtr)pPixmap, pGC);
REGION_NULL(pScreen, &Border);
REGION_NULL(pScreen, &Inside);
pSrcWin = (WindowPtr) pDrawable;
x = sx;
y = sy;
if (pSrcWin->parent)
{
x += pSrcWin->origin.x;
y += pSrcWin->origin.y;
pSrcWin = pSrcWin->parent;
}
(*pGC->ops->CopyArea) ((DrawablePtr)pSrcWin,
(DrawablePtr)pPixmap, pGC,
x, y, w, h,
0, 0);
REGION_SUBTRACT(pScreen, &Remaining, &Remaining,
&((WindowPtr) pDrawable)->borderClip);
}
REGION_INTERSECT(pScreen, &Inside, &Remaining, &pWin->winSize);
REGION_TRANSLATE(pScreen, &Inside,
-pWin->drawable.x,
-pWin->drawable.y);
REGION_INTERSECT(pScreen, &Inside, &Inside,
&pWindowPriv->SavedRegion);
/* offset of sub-window in GetImage pixmap */
xoff = pWin->drawable.x - pDrawable->x - sx;
yoff = pWin->drawable.y - pDrawable->y - sy;
if (REGION_NUM_RECTS(&Inside) > 0)
{
switch (pWindowPriv->status)
{
case StatusContents:
pBox = REGION_RECTS(&Inside);
for (n = REGION_NUM_RECTS(&Inside); --n >= 0;)
{
(*pGC->ops->CopyArea) (
(DrawablePtr)pWindowPriv->pBackingPixmap,
(DrawablePtr)pPixmap, pGC,
pBox->x1 - pWindowPriv->x,
pBox->y1 - pWindowPriv->y,
pBox->x2 - pBox->x1,
pBox->y2 - pBox->y1,
pBox->x1 + xoff,
pBox->y1 + yoff);
++pBox;
}
break;
case StatusVirtual:
case StatusVDirty:
if (pWindowPriv->backgroundState == BackgroundPixmap ||
pWindowPriv->backgroundState == BackgroundPixel)
miBSFillVirtualBits ((DrawablePtr) pPixmap, pGC, &Inside,
xoff, yoff,
(int) pWindowPriv->backgroundState,
pWindowPriv->background, ~0L);
break;
}
}
REGION_SUBTRACT(pScreen, &Border, &pWin->borderSize,
&pWin->winSize);
REGION_INTERSECT(pScreen, &Border, &Border, &Remaining);
if (REGION_NUM_RECTS(&Border) > 0)
{
REGION_TRANSLATE(pScreen, &Border, -pWin->drawable.x,
-pWin->drawable.y);
miBSFillVirtualBits ((DrawablePtr) pPixmap, pGC, &Border,
xoff, yoff,
pWin->borderIsPixel ? (int)BackgroundPixel : (int)BackgroundPixmap,
pWin->border, ~0L);
}
}
if (pWin->viewable && pWin->firstChild)
pWin = pWin->firstChild;
else
{
while (!pWin->nextSib && pWin != (WindowPtr) pDrawable)
pWin = pWin->parent;
if (pWin == (WindowPtr) pDrawable)
break;
pWin = pWin->nextSib;
}
}
REGION_UNINIT(pScreen, &Remaining);
if (pPixmap)
{
REGION_UNINIT(pScreen, &Border);
REGION_UNINIT(pScreen, &Inside);
(*pScreen->GetImage) ((DrawablePtr) pPixmap,
0, 0, w, h, format, planemask, pdstLine);
(*pScreen->DestroyPixmap) (pPixmap);
FreeScratchGC (pGC);
}
else
{
goto punt;
}
}
else
{
punt: ;
(*pScreen->GetImage) (pDrawable, sx, sy, w, h,
format, planemask, pdstLine);
}
SCREEN_EPILOGUE (pScreen, GetImage, miBSGetImage);
}
static void
miBSGetSpans (pDrawable, wMax, ppt, pwidth, nspans, pdstStart)
DrawablePtr pDrawable;
int wMax;
DDXPointPtr ppt;
int *pwidth;
int nspans;
char *pdstStart;
{
ScreenPtr pScreen = pDrawable->pScreen;
BoxRec bounds;
int i;
WindowPtr pWin;
int dx, dy;
SCREEN_PROLOGUE (pScreen, GetSpans);
if (pDrawable->type != DRAWABLE_PIXMAP && ((WindowPtr) pDrawable)->backStorage)
{
PixmapPtr pPixmap;
miBSWindowPtr pWindowPriv;
GCPtr pGC;
pWin = (WindowPtr) pDrawable;
pWindowPriv = (miBSWindowPtr) pWin->backStorage;
pPixmap = pWindowPriv->pBackingPixmap;
bounds.x1 = ppt->x;
bounds.y1 = ppt->y;
bounds.x2 = bounds.x1 + *pwidth;
bounds.y2 = ppt->y;
for (i = 0; i < nspans; i++)
{
if (ppt[i].x < bounds.x1)
bounds.x1 = ppt[i].x;
if (ppt[i].x + pwidth[i] > bounds.x2)
bounds.x2 = ppt[i].x + pwidth[i];
if (ppt[i].y < bounds.y1)
bounds.y1 = ppt[i].y;
else if (ppt[i].y > bounds.y2)
bounds.y2 = ppt[i].y;
}
switch (RECT_IN_REGION(pScreen, &pWindowPriv->SavedRegion, &bounds))
{
case rgnPART:
if (!pPixmap)
{
miCreateBSPixmap (pWin, NullBox);
if (!(pPixmap = pWindowPriv->pBackingPixmap))
break;
}
pWindowPriv->status = StatusNoPixmap;
pGC = GetScratchGC(pPixmap->drawable.depth,
pPixmap->drawable.pScreen);
if (pGC)
{
ValidateGC ((DrawablePtr) pPixmap, pGC);
(*pGC->ops->CopyArea)
(pDrawable, (DrawablePtr) pPixmap, pGC,
bounds.x1, bounds.y1,
bounds.x2 - bounds.x1, bounds.y2 - bounds.y1,
bounds.x1 + pPixmap->drawable.x - pWin->drawable.x -
pWindowPriv->x,
bounds.y1 + pPixmap->drawable.y - pWin->drawable.y -
pWindowPriv->y);
FreeScratchGC(pGC);
}
pWindowPriv->status = StatusContents;
/* fall through */
case rgnIN:
if (!pPixmap)
{
miCreateBSPixmap (pWin, NullBox);
if (!(pPixmap = pWindowPriv->pBackingPixmap))
break;
}
dx = pPixmap->drawable.x - pWin->drawable.x - pWindowPriv->x;
dy = pPixmap->drawable.y - pWin->drawable.y - pWindowPriv->y;
for (i = 0; i < nspans; i++)
{
ppt[i].x += dx;
ppt[i].y += dy;
}
(*pScreen->GetSpans) ((DrawablePtr) pPixmap, wMax, ppt, pwidth,
nspans, pdstStart);
break;
case rgnOUT:
(*pScreen->GetSpans) (pDrawable, wMax, ppt, pwidth, nspans,
pdstStart);
break;
}
}
else
{
(*pScreen->GetSpans) (pDrawable, wMax, ppt, pwidth, nspans, pdstStart);
}
SCREEN_EPILOGUE (pScreen, GetSpans, miBSGetSpans);
}
static Bool
miBSChangeWindowAttributes (pWin, mask)
WindowPtr pWin;
unsigned long mask;
{
ScreenPtr pScreen;
Bool ret;
pScreen = pWin->drawable.pScreen;
SCREEN_PROLOGUE (pScreen, ChangeWindowAttributes);
ret = (*pScreen->ChangeWindowAttributes) (pWin, mask);
if (ret && (mask & CWBackingStore))
{
if (pWin->backingStore != NotUseful || pWin->DIXsaveUnder)
miBSAllocate (pWin);
else
miBSFree (pWin);
}
SCREEN_EPILOGUE (pScreen, ChangeWindowAttributes, miBSChangeWindowAttributes);
return ret;
}
/*
* GC Create wrapper. Set up the cheap GC func wrappers to track
* GC validation on BackingStore windows
*/
static Bool
miBSCreateGC (pGC)
GCPtr pGC;
{
ScreenPtr pScreen = pGC->pScreen;
Bool ret;
SCREEN_PROLOGUE (pScreen, CreateGC);
if ( (ret = (*pScreen->CreateGC) (pGC)) )
{
pGC->devPrivates[miBSGCIndex].ptr = (pointer) pGC->funcs;
pGC->funcs = &miBSCheapGCFuncs;
}
SCREEN_EPILOGUE (pScreen, CreateGC, miBSCreateGC);
return ret;
}
static Bool
miBSDestroyWindow (pWin)
WindowPtr pWin;
{
ScreenPtr pScreen = pWin->drawable.pScreen;
Bool ret;
SCREEN_PROLOGUE (pScreen, DestroyWindow);
ret = (*pScreen->DestroyWindow) (pWin);
miBSFree (pWin);
SCREEN_EPILOGUE (pScreen, DestroyWindow, miBSDestroyWindow);
return ret;
}
/*
* cheap GC func wrappers. Simply track validation on windows
* with backing store to enable the real func/op wrappers
*/
static void
miBSCheapValidateGC (pGC, stateChanges, pDrawable)
GCPtr pGC;
unsigned long stateChanges;
DrawablePtr pDrawable;
{
CHEAP_FUNC_PROLOGUE (pGC);
if (pDrawable->type != DRAWABLE_PIXMAP &&
((WindowPtr) pDrawable)->backStorage != NULL &&
miBSCreateGCPrivate (pGC))
{
(*pGC->funcs->ValidateGC) (pGC, stateChanges, pDrawable);
}
else
{
(*pGC->funcs->ValidateGC) (pGC, stateChanges, pDrawable);
/* rewrap funcs as Validate may have changed them */
pGC->devPrivates[miBSGCIndex].ptr = (pointer) pGC->funcs;
CHEAP_FUNC_EPILOGUE (pGC);
}
}
static void
miBSCheapChangeGC (pGC, mask)
GCPtr pGC;
unsigned long mask;
{
CHEAP_FUNC_PROLOGUE (pGC);
(*pGC->funcs->ChangeGC) (pGC, mask);
CHEAP_FUNC_EPILOGUE (pGC);
}
static void
miBSCheapCopyGC (pGCSrc, mask, pGCDst)
GCPtr pGCSrc, pGCDst;
unsigned long mask;
{
CHEAP_FUNC_PROLOGUE (pGCDst);
(*pGCDst->funcs->CopyGC) (pGCSrc, mask, pGCDst);
CHEAP_FUNC_EPILOGUE (pGCDst);
}
static void
miBSCheapDestroyGC (pGC)
GCPtr pGC;
{
CHEAP_FUNC_PROLOGUE (pGC);
(*pGC->funcs->DestroyGC) (pGC);
/* leave it unwrapped */
}
static void
miBSCheapChangeClip (pGC, type, pvalue, nrects)
GCPtr pGC;
int type;
pointer pvalue;
int nrects;
{
CHEAP_FUNC_PROLOGUE (pGC);
(*pGC->funcs->ChangeClip) (pGC, type, pvalue, nrects);
CHEAP_FUNC_EPILOGUE (pGC);
}
static void
miBSCheapCopyClip(pgcDst, pgcSrc)
GCPtr pgcDst, pgcSrc;
{
CHEAP_FUNC_PROLOGUE (pgcDst);
(* pgcDst->funcs->CopyClip)(pgcDst, pgcSrc);
CHEAP_FUNC_EPILOGUE (pgcDst);
}
static void
miBSCheapDestroyClip(pGC)
GCPtr pGC;
{
CHEAP_FUNC_PROLOGUE (pGC);
(* pGC->funcs->DestroyClip)(pGC);
CHEAP_FUNC_EPILOGUE (pGC);
}
/*
* create the full func/op wrappers for a GC
*/
static Bool
miBSCreateGCPrivate (pGC)
GCPtr pGC;
{
miBSGCRec *pPriv;
pPriv = (miBSGCRec *) xalloc (sizeof (miBSGCRec));
if (!pPriv)
return FALSE;
pPriv->pBackingGC = NULL;
pPriv->guarantee = GuaranteeNothing;
pPriv->serialNumber = 0;
pPriv->stateChanges = (1 << (GCLastBit + 1)) - 1;
pPriv->wrapOps = pGC->ops;
pPriv->wrapFuncs = pGC->funcs;
pGC->funcs = &miBSGCFuncs;
pGC->ops = &miBSGCOps;
pGC->devPrivates[miBSGCIndex].ptr = (pointer) pPriv;
return TRUE;
}
static void
miBSDestroyGCPrivate (GCPtr pGC)
{
miBSGCRec *pPriv;
pPriv = (miBSGCRec *) pGC->devPrivates[miBSGCIndex].ptr;
if (pPriv)
{
pGC->devPrivates[miBSGCIndex].ptr = (pointer) pPriv->wrapFuncs;
pGC->funcs = &miBSCheapGCFuncs;
pGC->ops = pPriv->wrapOps;
if (pPriv->pBackingGC)
FreeGC (pPriv->pBackingGC, (GContext) 0);
xfree ((pointer) pPriv);
}
}
/*
* GC ops -- wrap each GC operation with our own function
*/
/*-
*-----------------------------------------------------------------------
* miBSFillSpans --
* Perform a FillSpans, routing output to backing-store as needed.
*
* Results:
* None.
*
* Side Effects:
*
*-----------------------------------------------------------------------
*/
static void
miBSFillSpans(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
DrawablePtr pDrawable;
GCPtr pGC;
int nInit; /* number of spans to fill */
DDXPointPtr pptInit; /* pointer to list of start points */
int *pwidthInit; /* pointer to list of n widths */
int fSorted;
{
DDXPointPtr pptCopy, pptReset;
int *pwidthCopy;
SETUP_BACKING (pDrawable, pGC);
PROLOGUE(pGC);
pptCopy = (DDXPointPtr)ALLOCATE_LOCAL(nInit*sizeof(DDXPointRec));
pwidthCopy=(int *)ALLOCATE_LOCAL(nInit*sizeof(int));
if (pptCopy && pwidthCopy)
{
copyData(pptInit, pptCopy, nInit, MoreCopy0);
memmove((char *)pwidthCopy,(char *)pwidthInit,nInit*sizeof(int));
(* pGC->ops->FillSpans)(pDrawable, pGC, nInit, pptInit,
pwidthInit, fSorted);
if (pGC->miTranslate)
{
int dx, dy;
int nReset;
pptReset = pptCopy;
dx = pDrawable->x - pBackingDrawable->x;
dy = pDrawable->y - pBackingDrawable->y;
nReset = nInit;
while (nReset--)
{
pptReset->x -= dx;
pptReset->y -= dy;
++pptReset;
}
}
(* pBackingGC->ops->FillSpans)(pBackingDrawable,
pBackingGC, nInit, pptCopy, pwidthCopy,
fSorted);
}
if (pwidthCopy) DEALLOCATE_LOCAL(pwidthCopy);
if (pptCopy) DEALLOCATE_LOCAL(pptCopy);
EPILOGUE (pGC);
}
/*-
*-----------------------------------------------------------------------
* miBSSetSpans --
* Perform a SetSpans, routing output to backing-store as needed.
*
* Results:
* None.
*
* Side Effects:
*
*-----------------------------------------------------------------------
*/
static void
miBSSetSpans(pDrawable, pGC, psrc, ppt, pwidth, nspans, fSorted)
DrawablePtr pDrawable;
GCPtr pGC;
char *psrc;
register DDXPointPtr ppt;
int *pwidth;
int nspans;
int fSorted;
{
DDXPointPtr pptCopy, pptReset;
int *pwidthCopy;
SETUP_BACKING (pDrawable, pGC);
PROLOGUE(pGC);
pptCopy = (DDXPointPtr)ALLOCATE_LOCAL(nspans*sizeof(DDXPointRec));
pwidthCopy=(int *)ALLOCATE_LOCAL(nspans*sizeof(int));
if (pptCopy && pwidthCopy)
{
copyData(ppt, pptCopy, nspans, MoreCopy0);
memmove((char *)pwidthCopy,(char *)pwidth,nspans*sizeof(int));
(* pGC->ops->SetSpans)(pDrawable, pGC, psrc, ppt, pwidth,
nspans, fSorted);
if (pGC->miTranslate)
{
int dx, dy;
int nReset;
pptReset = pptCopy;
dx = pDrawable->x - pBackingDrawable->x;
dy = pDrawable->y - pBackingDrawable->y;
nReset = nspans;
while (nReset--)
{
pptReset->x -= dx;
pptReset->y -= dy;
++pptReset;
}
}
(* pBackingGC->ops->SetSpans)(pBackingDrawable, pBackingGC,
psrc, pptCopy, pwidthCopy, nspans, fSorted);
}
if (pwidthCopy) DEALLOCATE_LOCAL(pwidthCopy);
if (pptCopy) DEALLOCATE_LOCAL(pptCopy);
EPILOGUE (pGC);
}
/*-
*-----------------------------------------------------------------------
* miBSPutImage --
* Perform a PutImage, routing output to backing-store as needed.
*
* Results:
* None.
*
* Side Effects:
*
*-----------------------------------------------------------------------
*/
static void
miBSPutImage(pDrawable, pGC, depth, x, y, w, h, leftPad, format, pBits)
DrawablePtr pDrawable;
GCPtr pGC;
int depth;
int x;
int y;
int w;
int h;
int leftPad;
int format;
char *pBits;
{
SETUP_BACKING (pDrawable, pGC);
PROLOGUE(pGC);
(*pGC->ops->PutImage)(pDrawable, pGC,
depth, x, y, w, h, leftPad, format, pBits);
(*pBackingGC->ops->PutImage)(pBackingDrawable, pBackingGC,
depth, x - pBackingStore->x, y - pBackingStore->y,
w, h, leftPad, format, pBits);
EPILOGUE (pGC);
}
typedef RegionPtr (* CopyAreaProcPtr)(DrawablePtr, DrawablePtr, GCPtr,
int, int, int, int, int, int);
typedef RegionPtr (* CopyPlaneProcPtr)(DrawablePtr, DrawablePtr, GCPtr,
int, int, int, int, int, int,
unsigned long bitPlane);
/*-
*-----------------------------------------------------------------------
* miBSDoCopy --
* Perform a CopyArea or CopyPlane within a window that has backing
* store enabled.
*
* Results:
* TRUE if the copy was performed or FALSE if a regular one should
* be done.
*
* Side Effects:
* Things are copied (no s***!)
*
* Notes:
* The idea here is to form two regions that cover the source box.
* One contains the exposed rectangles while the other contains
* the obscured ones. An array of <box, drawable> pairs is then
* formed where the <box> indicates the area to be copied and the
* <drawable> indicates from where it is to be copied (exposed regions
* come from the screen while obscured ones come from the backing
* pixmap). The array 'sequence' is then filled with the indices of
* the pairs in the order in which they should be copied to prevent
* things from getting screwed up. A call is also made through the
* backingGC to take care of any copying into the backing pixmap.
*
*-----------------------------------------------------------------------
*/
static Bool
miBSDoCopy(
WindowPtr pWin, /* Window being scrolled */
GCPtr pGC, /* GC we're called through */
int srcx, /* X of source rectangle */
int srcy, /* Y of source rectangle */
int w, /* Width of source rectangle */
int h, /* Height of source rectangle */
int dstx, /* X of destination rectangle */
int dsty, /* Y of destination rectangle */
unsigned long plane, /* Plane to copy (0 for CopyArea) */
CopyPlaneProcPtr copyProc, /* Procedure to call to perform the copy */
RegionPtr *ppRgn) /* resultant Graphics Expose region */
{
RegionPtr pRgnExp; /* Exposed region */
RegionPtr pRgnObs; /* Obscured region */
BoxRec box; /* Source box (screen coord) */
struct BoxDraw {
BoxPtr pBox; /* Source box */
enum {
win, pix
} source; /* Place from which to copy */
} *boxes; /* Array of box/drawable pairs covering
* source box. */
int *sequence; /* Sequence of boxes to move */
register int i, j, k, l, y;
register BoxPtr pBox;
int dx, dy, nrects;
Bool graphicsExposures;
CopyPlaneProcPtr pixCopyProc;
int numRectsExp, numRectsObs;
BoxPtr pBoxExp, pBoxObs;
SETUP_BACKING (pWin, pGC);
(void)oldFuncs;
/*
* Create a region of exposed boxes in pRgnExp.
*/
box.x1 = srcx + pWin->drawable.x;
box.x2 = box.x1 + w;
box.y1 = srcy + pWin->drawable.y;
box.y2 = box.y1 + h;
pRgnExp = REGION_CREATE(pGC->pScreen, &box, 1);
REGION_INTERSECT(pGC->pScreen, pRgnExp, pRgnExp, &pWin->clipList);
pRgnObs = REGION_CREATE(pGC->pScreen, NULL, 1);
REGION_INVERSE( pGC->pScreen, pRgnObs, pRgnExp, &box);
/*
* Translate regions into window coordinates for proper calls
* to the copyProc, then make sure none of the obscured region sticks
* into invalid areas of the backing pixmap.
*/
REGION_TRANSLATE(pGC->pScreen, pRgnExp,
-pWin->drawable.x,
-pWin->drawable.y);
REGION_TRANSLATE(pGC->pScreen, pRgnObs,
-pWin->drawable.x,
-pWin->drawable.y);
REGION_INTERSECT(pGC->pScreen, pRgnObs, pRgnObs, &pBackingStore->SavedRegion);
/*
* If the obscured region is empty, there's no point being fancy.
*/
if (!REGION_NOTEMPTY(pGC->pScreen, pRgnObs))
{
REGION_DESTROY(pGC->pScreen, pRgnExp);
REGION_DESTROY(pGC->pScreen, pRgnObs);
return (FALSE);
}
numRectsExp = REGION_NUM_RECTS(pRgnExp);
pBoxExp = REGION_RECTS(pRgnExp);
pBoxObs = REGION_RECTS(pRgnObs);
numRectsObs = REGION_NUM_RECTS(pRgnObs);
nrects = numRectsExp + numRectsObs;
boxes = (struct BoxDraw *)ALLOCATE_LOCAL(nrects * sizeof(struct BoxDraw));
sequence = (int *) ALLOCATE_LOCAL(nrects * sizeof(int));
*ppRgn = NULL;
if (!boxes || !sequence)
{
if (sequence) DEALLOCATE_LOCAL(sequence);
if (boxes) DEALLOCATE_LOCAL(boxes);
REGION_DESTROY(pGC->pScreen, pRgnExp);
REGION_DESTROY(pGC->pScreen, pRgnObs);
return(TRUE);
}
/*
* Order the boxes in the two regions so we know from which drawable
* to copy which box, storing the result in the boxes array
*/
for (i = 0, j = 0, k = 0;
(i < numRectsExp) && (j < numRectsObs);
k++)
{
if (pBoxExp[i].y1 < pBoxObs[j].y1)
{
boxes[k].pBox = &pBoxExp[i];
boxes[k].source = win;
i++;
}
else if ((pBoxObs[j].y1 < pBoxExp[i].y1) ||
(pBoxObs[j].x1 < pBoxExp[i].x1))
{
boxes[k].pBox = &pBoxObs[j];
boxes[k].source = pix;
j++;
}
else
{
boxes[k].pBox = &pBoxExp[i];
boxes[k].source = win;
i++;
}
}
/*
* Catch any leftover boxes from either region (note that only
* one can have leftover boxes...)
*/
if (i != numRectsExp)
{
do
{
boxes[k].pBox = &pBoxExp[i];
boxes[k].source = win;
i++;
k++;
} while (i < numRectsExp);
}
else
{
do
{
boxes[k].pBox = &pBoxObs[j];
boxes[k].source = pix;
j++;
k++;
} while (j < numRectsObs);
}
if (dsty <= srcy)
{
/*
* Scroll up or vertically stationary, so vertical order is ok.
*/
if (dstx <= srcx)
{
/*
* Scroll left or horizontally stationary, so horizontal order
* is ok as well.
*/
for (i = 0; i < nrects; i++)
{
sequence[i] = i;
}
}
else
{
/*
* Scroll right. Need to reverse the rectangles within each
* band.
*/
for (i = 0, j = 1, k = 0;
i < nrects;
j = i + 1, k = i)
{
y = boxes[i].pBox->y1;
while ((j < nrects) && (boxes[j].pBox->y1 == y))
{
j++;
}
for (j--; j >= k; j--, i++)
{
sequence[i] = j;
}
}
}
}
else
{
/*
* Scroll down. Must reverse vertical banding, at least.
*/
if (dstx < srcx)
{
/*
* Scroll left. Horizontal order is ok.
*/
for (i = nrects - 1, j = i - 1, k = i, l = 0;
i >= 0;
j = i - 1, k = i)
{
/*
* Find extent of current horizontal band, then reverse
* the order of the whole band.
*/
y = boxes[i].pBox->y1;
while ((j >= 0) && (boxes[j].pBox->y1 == y))
{
j--;
}
for (j++; j <= k; j++, i--, l++)
{
sequence[l] = j;
}
}
}
else
{
/*
* Scroll right or horizontal stationary.
* Reverse horizontal order as well (if stationary, horizontal
* order can be swapped without penalty and this is faster
* to compute).
*/
for (i = 0, j = nrects - 1; i < nrects; i++, j--)
{
sequence[i] = j;
}
}
}
/*
* XXX: To avoid getting multiple NoExpose events from this operation,
* we turn OFF graphicsExposures in the gc and deal with any uncopied
* areas later, if there's something not in backing-store.
*/
graphicsExposures = pGC->graphicsExposures;
pGC->graphicsExposures = FALSE;
dx = dstx - srcx;
dy = dsty - srcy;
/*
* Figure out which copy procedure to use from the backing GC. Note we
* must do this because some implementations (sun's, e.g.) have
* pBackingGC a fake GC with the real one below it, thus the devPriv for
* pBackingGC won't be what the output library expects.
*/
if (plane != 0)
{
pixCopyProc = pBackingGC->ops->CopyPlane;
}
else
{
pixCopyProc = (CopyPlaneProcPtr)pBackingGC->ops->CopyArea;
}
for (i = 0; i < nrects; i++)
{
pBox = boxes[sequence[i]].pBox;
/*
* If we're copying from the pixmap, we need to place its contents
* onto the screen before scrolling the pixmap itself. If we're copying
* from the window, we need to copy its contents into the pixmap before
* we scroll the window itself.
*/
if (boxes[sequence[i]].source == pix)
{
(void) (* copyProc) (pBackingDrawable, &(pWin->drawable), pGC,
pBox->x1 - pBackingStore->x,
pBox->y1 - pBackingStore->y,
pBox->x2 - pBox->x1, pBox->y2 - pBox->y1,
pBox->x1 + dx, pBox->y1 + dy, plane);
(void) (* pixCopyProc) (pBackingDrawable, pBackingDrawable, pBackingGC,
pBox->x1 - pBackingStore->x,
pBox->y1 - pBackingStore->y,
pBox->x2 - pBox->x1, pBox->y2 - pBox->y1,
pBox->x1 + dx - pBackingStore->x,
pBox->y1 + dy - pBackingStore->y, plane);
}
else
{
(void) (* pixCopyProc) (&(pWin->drawable), pBackingDrawable, pBackingGC,
pBox->x1, pBox->y1,
pBox->x2 - pBox->x1, pBox->y2 - pBox->y1,
pBox->x1 + dx - pBackingStore->x,
pBox->y1 + dy - pBackingStore->y, plane);
(void) (* copyProc) (&(pWin->drawable), &(pWin->drawable), pGC,
pBox->x1, pBox->y1,
pBox->x2 - pBox->x1, pBox->y2 - pBox->y1,
pBox->x1 + dx, pBox->y1 + dy, plane);
}
}
DEALLOCATE_LOCAL(sequence);
DEALLOCATE_LOCAL(boxes);
pGC->graphicsExposures = graphicsExposures;
/*
* Form union of rgnExp and rgnObs and see if covers entire area
* to be copied. Store the resultant region for miBSCopyArea
* to return to dispatch which will send the appropriate expose
* events.
*/
REGION_UNION(pGC->pScreen, pRgnExp, pRgnExp, pRgnObs);
box.x1 = srcx;
box.x2 = srcx + w;
box.y1 = srcy;
box.y2 = srcy + h;
if (RECT_IN_REGION(pGC->pScreen, pRgnExp, &box) == rgnIN)
{
REGION_EMPTY(pGC->pScreen, pRgnExp);
}
else
{
REGION_INVERSE( pGC->pScreen, pRgnExp, pRgnExp, &box);
REGION_TRANSLATE( pGC->pScreen, pRgnExp,
dx + pWin->drawable.x,
dy + pWin->drawable.y);
REGION_INTERSECT( pGC->pScreen, pRgnObs, pRgnExp, &pWin->clipList);
(*pWin->drawable.pScreen->PaintWindowBackground) (pWin,
pRgnObs, PW_BACKGROUND);
REGION_TRANSLATE( pGC->pScreen, pRgnExp,
-pWin->drawable.x,
-pWin->drawable.y);
miBSClearBackingRegion (pWin, pRgnExp);
}
if (graphicsExposures)
*ppRgn = pRgnExp;
else
REGION_DESTROY(pGC->pScreen, pRgnExp);
REGION_DESTROY(pGC->pScreen, pRgnObs);
return (TRUE);
}
/*-
*-----------------------------------------------------------------------
* miBSCopyArea --
* Perform a CopyArea from the source to the destination, extracting
* from the source's backing-store and storing into the destination's
* backing-store without messing anything up. If the source and
* destination are different, there's not too much to worry about:
* we can just issue several calls to the regular CopyArea function.
*
* Results:
* None.
*
* Side Effects:
*
*-----------------------------------------------------------------------
*/
static RegionPtr
miBSCopyArea (pSrc, pDst, pGC, srcx, srcy, w, h, dstx, dsty)
DrawablePtr pSrc;
DrawablePtr pDst;
GCPtr pGC;
int srcx;
int srcy;
int w;
int h;
int dstx;
int dsty;
{
BoxPtr pExtents;
long dx, dy;
int bsrcx, bsrcy, bw, bh, bdstx, bdsty;
RegionPtr pixExposed = 0, winExposed = 0;
SETUP_BACKING(pDst, pGC);
PROLOGUE(pGC);
if ((pSrc != pDst) ||
(!miBSDoCopy((WindowPtr)pSrc, pGC, srcx, srcy, w, h, dstx, dsty,
(unsigned long) 0, (CopyPlaneProcPtr)pGC->ops->CopyArea,
&winExposed)))
{
/*
* always copy to the backing store first, miBSDoCopy
* returns FALSE if the *source* region is disjoint
* from the backing store saved region. So, copying
* *to* the backing store is always safe
*/
if (pGC->clientClipType != CT_PIXMAP)
{
/*
* adjust srcx, srcy, w, h, dstx, dsty to be clipped to
* the backing store. An unnecessary optimisation,
* but a useful one when GetSpans is slow.
*/
pExtents = REGION_EXTENTS(pDst->pScreen,
(RegionPtr)pBackingGC->clientClip);
bsrcx = srcx;
bsrcy = srcy;
bw = w;
bh = h;
bdstx = dstx;
bdsty = dsty;
dx = pExtents->x1 - bdstx;
if (dx > 0)
{
bsrcx += dx;
bdstx += dx;
bw -= dx;
}
dy = pExtents->y1 - bdsty;
if (dy > 0)
{
bsrcy += dy;
bdsty += dy;
bh -= dy;
}
dx = (bdstx + bw) - pExtents->x2;
if (dx > 0)
bw -= dx;
dy = (bdsty + bh) - pExtents->y2;
if (dy > 0)
bh -= dy;
if (bw > 0 && bh > 0)
pixExposed = (* pBackingGC->ops->CopyArea) (pSrc,
pBackingDrawable, pBackingGC,
bsrcx, bsrcy, bw, bh, bdstx - pBackingStore->x,
bdsty - pBackingStore->y);
}
else
pixExposed = (* pBackingGC->ops->CopyArea) (pSrc,
pBackingDrawable, pBackingGC,
srcx, srcy, w, h,
dstx - pBackingStore->x, dsty - pBackingStore->y);
winExposed = (* pGC->ops->CopyArea) (pSrc, pDst, pGC, srcx, srcy, w, h, dstx, dsty);
}
/*
* compute the composite graphics exposure region
*/
if (winExposed)
{
if (pixExposed){
REGION_UNION(pDst->pScreen, winExposed, winExposed, pixExposed);
REGION_DESTROY(pDst->pScreen, pixExposed);
}
} else
winExposed = pixExposed;
EPILOGUE (pGC);
return winExposed;
}
/*-
*-----------------------------------------------------------------------
* miBSCopyPlane --
*
* Results:
* None.
*
* Side Effects:
*
*-----------------------------------------------------------------------
*/
static RegionPtr
miBSCopyPlane (pSrc, pDst, pGC, srcx, srcy, w, h, dstx, dsty, plane)
DrawablePtr pSrc;
DrawablePtr pDst;
register GC *pGC;
int srcx,
srcy;
int w,
h;
int dstx,
dsty;
unsigned long plane;
{
BoxPtr pExtents;
long dx, dy;
int bsrcx, bsrcy, bw, bh, bdstx, bdsty;
RegionPtr winExposed = 0, pixExposed = 0;
SETUP_BACKING(pDst, pGC);
PROLOGUE(pGC);
if ((pSrc != pDst) ||
(!miBSDoCopy((WindowPtr)pSrc, pGC, srcx, srcy, w, h, dstx, dsty,
plane, pGC->ops->CopyPlane, &winExposed)))
{
/*
* always copy to the backing store first, miBSDoCopy
* returns FALSE if the *source* region is disjoint
* from the backing store saved region. So, copying
* *to* the backing store is always safe
*/
if (pGC->clientClipType != CT_PIXMAP)
{
/*
* adjust srcx, srcy, w, h, dstx, dsty to be clipped to
* the backing store. An unnecessary optimisation,
* but a useful one when GetSpans is slow.
*/
pExtents = REGION_EXTENTS(pDst->pScreen,
(RegionPtr)pBackingGC->clientClip);
bsrcx = srcx;
bsrcy = srcy;
bw = w;
bh = h;
bdstx = dstx;
bdsty = dsty;
dx = pExtents->x1 - bdstx;
if (dx > 0)
{
bsrcx += dx;
bdstx += dx;
bw -= dx;
}
dy = pExtents->y1 - bdsty;
if (dy > 0)
{
bsrcy += dy;
bdsty += dy;
bh -= dy;
}
dx = (bdstx + bw) - pExtents->x2;
if (dx > 0)
bw -= dx;
dy = (bdsty + bh) - pExtents->y2;
if (dy > 0)
bh -= dy;
if (bw > 0 && bh > 0)
pixExposed = (* pBackingGC->ops->CopyPlane) (pSrc,
pBackingDrawable,
pBackingGC, bsrcx, bsrcy, bw, bh,
bdstx - pBackingStore->x,
bdsty - pBackingStore->y, plane);
}
else
pixExposed = (* pBackingGC->ops->CopyPlane) (pSrc,
pBackingDrawable,
pBackingGC, srcx, srcy, w, h,
dstx - pBackingStore->x,
dsty - pBackingStore->y, plane);
winExposed = (* pGC->ops->CopyPlane) (pSrc, pDst, pGC, srcx, srcy, w, h,
dstx, dsty, plane);
}
/*
* compute the composite graphics exposure region
*/
if (winExposed)
{
if (pixExposed)
{
REGION_UNION(pDst->pScreen, winExposed, winExposed, pixExposed);
REGION_DESTROY(pDst->pScreen, pixExposed);
}
} else
winExposed = pixExposed;
EPILOGUE (pGC);
return winExposed;
}
/*-
*-----------------------------------------------------------------------
* miBSPolyPoint --
* Perform a PolyPoint, routing output to backing-store as needed.
*
* Results:
* None.
*
* Side Effects:
*
*-----------------------------------------------------------------------
*/
static void
miBSPolyPoint (pDrawable, pGC, mode, npt, pptInit)
DrawablePtr pDrawable;
GCPtr pGC;
int mode; /* Origin or Previous */
int npt;
xPoint *pptInit;
{
xPoint *pptCopy;
SETUP_BACKING (pDrawable, pGC);
PROLOGUE(pGC);
pptCopy = (xPoint *)ALLOCATE_LOCAL(npt*sizeof(xPoint));
if (pptCopy)
{
copyPoints(pptInit, pptCopy, npt, mode);
(* pGC->ops->PolyPoint) (pDrawable, pGC, mode, npt, pptInit);
(* pBackingGC->ops->PolyPoint) (pBackingDrawable,
pBackingGC, mode, npt, pptCopy);
DEALLOCATE_LOCAL(pptCopy);
}
EPILOGUE (pGC);
}
/*-
*-----------------------------------------------------------------------
* miBSPolyLines --
* Perform a Polylines, routing output to backing-store as needed.
*
* Results:
*
* Side Effects:
*
*-----------------------------------------------------------------------
*/
static void
miBSPolylines (pDrawable, pGC, mode, npt, pptInit)
DrawablePtr pDrawable;
GCPtr pGC;
int mode;
int npt;
DDXPointPtr pptInit;
{
DDXPointPtr pptCopy;
SETUP_BACKING (pDrawable, pGC);
PROLOGUE(pGC);
pptCopy = (DDXPointPtr)ALLOCATE_LOCAL(npt*sizeof(DDXPointRec));
if (pptCopy)
{
copyPoints(pptInit, pptCopy, npt, mode);
(* pGC->ops->Polylines)(pDrawable, pGC, mode, npt, pptInit);
(* pBackingGC->ops->Polylines)(pBackingDrawable,
pBackingGC, mode, npt, pptCopy);
DEALLOCATE_LOCAL(pptCopy);
}
EPILOGUE (pGC);
}
/*-
*-----------------------------------------------------------------------
* miBSPolySegment --
* Perform a PolySegment, routing output to backing-store as needed.
*
* Results:
* None.
*
* Side Effects:
*
*-----------------------------------------------------------------------
*/
static void
miBSPolySegment(pDrawable, pGC, nseg, pSegs)
DrawablePtr pDrawable;
GCPtr pGC;
int nseg;
xSegment *pSegs;
{
xSegment *pSegsCopy;
SETUP_BACKING (pDrawable, pGC);
PROLOGUE(pGC);
pSegsCopy = (xSegment *)ALLOCATE_LOCAL(nseg*sizeof(xSegment));
if (pSegsCopy)
{
copyData(pSegs, pSegsCopy, nseg << 1, MoreCopy0);
(* pGC->ops->PolySegment)(pDrawable, pGC, nseg, pSegs);
(* pBackingGC->ops->PolySegment)(pBackingDrawable,
pBackingGC, nseg, pSegsCopy);
DEALLOCATE_LOCAL(pSegsCopy);
}
EPILOGUE (pGC);
}
/*-
*-----------------------------------------------------------------------
* miBSPolyRectangle --
* Perform a PolyRectangle, routing output to backing-store as needed.
*
* Results:
* None
*
* Side Effects:
*
*-----------------------------------------------------------------------
*/
static void
miBSPolyRectangle(pDrawable, pGC, nrects, pRects)
DrawablePtr pDrawable;
GCPtr pGC;
int nrects;
xRectangle *pRects;
{
xRectangle *pRectsCopy;
SETUP_BACKING (pDrawable, pGC);
PROLOGUE(pGC);
pRectsCopy =(xRectangle *)ALLOCATE_LOCAL(nrects*sizeof(xRectangle));
if (pRectsCopy)
{
copyData(pRects, pRectsCopy, nrects, MoreCopy2);
(* pGC->ops->PolyRectangle)(pDrawable, pGC, nrects, pRects);
(* pBackingGC->ops->PolyRectangle)(pBackingDrawable,
pBackingGC, nrects, pRectsCopy);
DEALLOCATE_LOCAL(pRectsCopy);
}
EPILOGUE (pGC);
}
/*-
*-----------------------------------------------------------------------
* miBSPolyArc --
* Perform a PolyArc, routing output to backing-store as needed.
*
* Results:
*
* Side Effects:
*
*-----------------------------------------------------------------------
*/
static void
miBSPolyArc(pDrawable, pGC, narcs, parcs)
DrawablePtr pDrawable;
GCPtr pGC;
int narcs;
xArc *parcs;
{
xArc *pArcsCopy;
SETUP_BACKING (pDrawable, pGC);
PROLOGUE(pGC);
pArcsCopy = (xArc *)ALLOCATE_LOCAL(narcs*sizeof(xArc));
if (pArcsCopy)
{
copyData(parcs, pArcsCopy, narcs, MoreCopy4);
(* pGC->ops->PolyArc)(pDrawable, pGC, narcs, parcs);
(* pBackingGC->ops->PolyArc)(pBackingDrawable, pBackingGC,
narcs, pArcsCopy);
DEALLOCATE_LOCAL(pArcsCopy);
}
EPILOGUE (pGC);
}
/*-
*-----------------------------------------------------------------------
* miBSFillPolygon --
* Perform a FillPolygon, routing output to backing-store as needed.
*
* Results:
* None.
*
* Side Effects:
*
*-----------------------------------------------------------------------
*/
static void
miBSFillPolygon(pDrawable, pGC, shape, mode, count, pPts)
DrawablePtr pDrawable;
register GCPtr pGC;
int shape, mode;
register int count;
DDXPointPtr pPts;
{
DDXPointPtr pPtsCopy;
SETUP_BACKING (pDrawable, pGC);
PROLOGUE(pGC);
pPtsCopy = (DDXPointPtr)ALLOCATE_LOCAL(count*sizeof(DDXPointRec));
if (pPtsCopy)
{
copyPoints(pPts, pPtsCopy, count, mode);
(* pGC->ops->FillPolygon)(pDrawable, pGC, shape, mode, count, pPts);
(* pBackingGC->ops->FillPolygon)(pBackingDrawable,
pBackingGC, shape, mode,
count, pPtsCopy);
DEALLOCATE_LOCAL(pPtsCopy);
}
EPILOGUE (pGC);
}
/*-
*-----------------------------------------------------------------------
* miBSPolyFillRect --
* Perform a PolyFillRect, routing output to backing-store as needed.
*
* Results:
* None.
*
* Side Effects:
*
*-----------------------------------------------------------------------
*/
static void
miBSPolyFillRect(pDrawable, pGC, nrectFill, prectInit)
DrawablePtr pDrawable;
GCPtr pGC;
int nrectFill; /* number of rectangles to fill */
xRectangle *prectInit; /* Pointer to first rectangle to fill */
{
xRectangle *pRectCopy;
SETUP_BACKING (pDrawable, pGC);
PROLOGUE(pGC);
pRectCopy =
(xRectangle *)ALLOCATE_LOCAL(nrectFill*sizeof(xRectangle));
if (pRectCopy)
{
copyData(prectInit, pRectCopy, nrectFill, MoreCopy2);
(* pGC->ops->PolyFillRect)(pDrawable, pGC, nrectFill, prectInit);
(* pBackingGC->ops->PolyFillRect)(pBackingDrawable,
pBackingGC, nrectFill, pRectCopy);
DEALLOCATE_LOCAL(pRectCopy);
}
EPILOGUE (pGC);
}
/*-
*-----------------------------------------------------------------------
* miBSPolyFillArc --
* Perform a PolyFillArc, routing output to backing-store as needed.
*
* Results:
* None.
*
* Side Effects:
*
*-----------------------------------------------------------------------
*/
static void
miBSPolyFillArc(pDrawable, pGC, narcs, parcs)
DrawablePtr pDrawable;
GCPtr pGC;
int narcs;
xArc *parcs;
{
xArc *pArcsCopy;
SETUP_BACKING (pDrawable, pGC);
PROLOGUE(pGC);
pArcsCopy = (xArc *)ALLOCATE_LOCAL(narcs*sizeof(xArc));
if (pArcsCopy)
{
copyData(parcs, pArcsCopy, narcs, MoreCopy4);
(* pGC->ops->PolyFillArc)(pDrawable, pGC, narcs, parcs);
(* pBackingGC->ops->PolyFillArc)(pBackingDrawable,
pBackingGC, narcs, pArcsCopy);
DEALLOCATE_LOCAL(pArcsCopy);
}
EPILOGUE (pGC);
}
/*-
*-----------------------------------------------------------------------
* miBSPolyText8 --
* Perform a PolyText8, routing output to backing-store as needed.
*
* Results:
*
* Side Effects:
*
*-----------------------------------------------------------------------
*/
static int
miBSPolyText8(pDrawable, pGC, x, y, count, chars)
DrawablePtr pDrawable;
GCPtr pGC;
int x, y;
int count;
char *chars;
{
int result;
SETUP_BACKING (pDrawable, pGC);
PROLOGUE(pGC);
result = (* pGC->ops->PolyText8)(pDrawable, pGC, x, y, count, chars);
(* pBackingGC->ops->PolyText8)(pBackingDrawable, pBackingGC,
x - pBackingStore->x, y - pBackingStore->y,
count, chars);
EPILOGUE (pGC);
return result;
}
/*-
*-----------------------------------------------------------------------
* miBSPolyText16 --
* Perform a PolyText16, routing output to backing-store as needed.
*
* Results:
*
* Side Effects:
*
*-----------------------------------------------------------------------
*/
static int
miBSPolyText16(pDrawable, pGC, x, y, count, chars)
DrawablePtr pDrawable;
GCPtr pGC;
int x, y;
int count;
unsigned short *chars;
{
int result;
SETUP_BACKING (pDrawable, pGC);
PROLOGUE(pGC);
result = (* pGC->ops->PolyText16)(pDrawable, pGC, x, y, count, chars);
(* pBackingGC->ops->PolyText16)(pBackingDrawable, pBackingGC,
x - pBackingStore->x, y - pBackingStore->y,
count, chars);
EPILOGUE (pGC);
return result;
}
/*-
*-----------------------------------------------------------------------
* miBSImageText8 --
* Perform a ImageText8, routing output to backing-store as needed.
*
* Results:
*
* Side Effects:
*
*-----------------------------------------------------------------------
*/
static void
miBSImageText8(pDrawable, pGC, x, y, count, chars)
DrawablePtr pDrawable;
GCPtr pGC;
int x, y;
int count;
char *chars;
{
SETUP_BACKING (pDrawable, pGC);
PROLOGUE(pGC);
(* pGC->ops->ImageText8)(pDrawable, pGC, x, y, count, chars);
(* pBackingGC->ops->ImageText8)(pBackingDrawable, pBackingGC,
x - pBackingStore->x, y - pBackingStore->y,
count, chars);
EPILOGUE (pGC);
}
/*-
*-----------------------------------------------------------------------
* miBSImageText16 --
* Perform a ImageText16, routing output to backing-store as needed.
*
* Results:
*
* Side Effects:
*
*-----------------------------------------------------------------------
*/
static void
miBSImageText16(pDrawable, pGC, x, y, count, chars)
DrawablePtr pDrawable;
GCPtr pGC;
int x, y;
int count;
unsigned short *chars;
{
SETUP_BACKING (pDrawable, pGC);
PROLOGUE(pGC);
(* pGC->ops->ImageText16)(pDrawable, pGC, x, y, count, chars);
(* pBackingGC->ops->ImageText16)(pBackingDrawable, pBackingGC,
x - pBackingStore->x, y - pBackingStore->y,
count, chars);
EPILOGUE (pGC);
}
/*-
*-----------------------------------------------------------------------
* miBSImageGlyphBlt --
* Perform a ImageGlyphBlt, routing output to backing-store as needed.
*
* Results:
*
* Side Effects:
*
*-----------------------------------------------------------------------
*/
static void
miBSImageGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
DrawablePtr pDrawable;
GCPtr pGC;
int x, y;
unsigned int nglyph;
CharInfoPtr *ppci; /* array of character info */
pointer pglyphBase; /* start of array of glyphs */
{
SETUP_BACKING (pDrawable, pGC);
PROLOGUE(pGC);
(* pGC->ops->ImageGlyphBlt)(pDrawable, pGC, x, y, nglyph, ppci,
pglyphBase);
(* pBackingGC->ops->ImageGlyphBlt)(pBackingDrawable, pBackingGC,
x - pBackingStore->x, y - pBackingStore->y,
nglyph, ppci, pglyphBase);
EPILOGUE (pGC);
}
/*-
*-----------------------------------------------------------------------
* miBSPolyGlyphBlt --
* Perform a PolyGlyphBlt, routing output to backing-store as needed.
*
* Results:
*
* Side Effects:
*
*-----------------------------------------------------------------------
*/
static void
miBSPolyGlyphBlt(pDrawable, pGC, x, y, nglyph, ppci, pglyphBase)
DrawablePtr pDrawable;
GCPtr pGC;
int x, y;
unsigned int nglyph;
CharInfoPtr *ppci; /* array of character info */
pointer pglyphBase; /* start of array of glyphs */
{
SETUP_BACKING (pDrawable, pGC);
PROLOGUE(pGC);
(* pGC->ops->PolyGlyphBlt)(pDrawable, pGC, x, y, nglyph,
ppci, pglyphBase);
(* pBackingGC->ops->PolyGlyphBlt)(pBackingDrawable, pBackingGC,
x - pBackingStore->x, y - pBackingStore->y,
nglyph, ppci, pglyphBase);
EPILOGUE (pGC);
}
/*-
*-----------------------------------------------------------------------
* miBSPushPixels --
* Perform a PushPixels, routing output to backing-store as needed.
*
* Results:
*
* Side Effects:
*
*-----------------------------------------------------------------------
*/
static void
miBSPushPixels(pGC, pBitMap, pDst, w, h, x, y)
GCPtr pGC;
PixmapPtr pBitMap;
DrawablePtr pDst;
int w, h, x, y;
{
SETUP_BACKING (pDst, pGC);
PROLOGUE(pGC);
(* pGC->ops->PushPixels)(pGC, pBitMap, pDst, w, h, x, y);
if (pGC->miTranslate) {
x -= pDst->x;
y -= pDst->y;
}
(* pBackingGC->ops->PushPixels)(pBackingGC, pBitMap,
pBackingDrawable, w, h,
x - pBackingStore->x, y - pBackingStore->y);
EPILOGUE (pGC);
}
#ifdef NEED_LINEHELPER
/*-
*-----------------------------------------------------------------------
* miBSLineHelper --
*
* Results: should never be called
*
* Side Effects: server dies
*
*-----------------------------------------------------------------------
*/
static void
miBSLineHelper()
{
FatalError("miBSLineHelper called\n");
}
#endif
/*-
*-----------------------------------------------------------------------
* miBSClearBackingStore --
* Clear the given area of the backing pixmap with the background of
* the window, whatever it is. If generateExposures is TRUE, generate
* exposure events for the area. Note that if the area has any
* part outside the saved portions of the window, we do not allow the
* count in the expose events to be 0, since there will be more
* expose events to come.
*
* Results:
* None.
*
* Side Effects:
* Areas of pixmap are cleared and Expose events are generated.
*
*-----------------------------------------------------------------------
*/
static RegionPtr
miBSClearBackingStore(pWin, x, y, w, h, generateExposures)
WindowPtr pWin;
int x;
int y;
int w;
int h;
Bool generateExposures;
{
RegionPtr pRgn;
int i;
miBSWindowPtr pBackingStore;
ScreenPtr pScreen;
GCPtr pGC;
int ts_x_origin,
ts_y_origin;
pointer gcvalues[4];
unsigned long gcmask;
xRectangle *rects;
BoxPtr pBox;
BoxRec box;
PixUnion background;
char backgroundState;
int numRects;
pBackingStore = (miBSWindowPtr)pWin->backStorage;
pScreen = pWin->drawable.pScreen;
if ((pBackingStore->status == StatusNoPixmap) ||
(pBackingStore->status == StatusBadAlloc))
return NullRegion;
if (w == 0)
w = (int) pWin->drawable.width - x;
if (h == 0)
h = (int) pWin->drawable.height - y;
box.x1 = x;
box.y1 = y;
box.x2 = x + w;
box.y2 = y + h;
pRgn = REGION_CREATE(pWin->drawable.pScreen, &box, 1);
if (!pRgn)
return NullRegion;
REGION_INTERSECT( pScreen, pRgn, pRgn, &pBackingStore->SavedRegion);
if (REGION_NOTEMPTY( pScreen, pRgn))
{
/*
* if clearing entire window, simply make new virtual
* tile. For the root window, we also destroy the pixmap
* to save a pile of memory
*/
if (x == 0 && y == 0 &&
w == pWin->drawable.width &&
h == pWin->drawable.height)
{
if (!pWin->parent)
miDestroyBSPixmap (pWin);
if (pBackingStore->status != StatusContents)
miTileVirtualBS (pWin);
}
ts_x_origin = ts_y_origin = 0;
backgroundState = pWin->backgroundState;
background = pWin->background;
if (backgroundState == ParentRelative) {
WindowPtr pParent;
pParent = pWin;
while (pParent->backgroundState == ParentRelative) {
ts_x_origin -= pParent->origin.x;
ts_y_origin -= pParent->origin.y;
pParent = pParent->parent;
}
backgroundState = pParent->backgroundState;
background = pParent->background;
}
if ((backgroundState != None) &&
((pBackingStore->status == StatusContents) ||
!SameBackground (pBackingStore->backgroundState,
pBackingStore->background,
backgroundState,
background)))
{
if (!pBackingStore->pBackingPixmap)
miCreateBSPixmap(pWin, NullBox);
pGC = GetScratchGC(pWin->drawable.depth, pScreen);
if (pGC && pBackingStore->pBackingPixmap)
{
/*
* First take care of any ParentRelative stuff by altering the
* tile/stipple origin to match the coordinates of the upper-left
* corner of the first ancestor without a ParentRelative background.
* This coordinate is, of course, negative.
*/
if (backgroundState == BackgroundPixel)
{
gcvalues[0] = (pointer) background.pixel;
gcvalues[1] = (pointer)FillSolid;
gcmask = GCForeground|GCFillStyle;
}
else
{
gcvalues[0] = (pointer)FillTiled;
gcvalues[1] = (pointer) background.pixmap;
gcmask = GCFillStyle|GCTile;
}
gcvalues[2] = (pointer)(long)(ts_x_origin - pBackingStore->x);
gcvalues[3] = (pointer)(long)(ts_y_origin - pBackingStore->y);
gcmask |= GCTileStipXOrigin|GCTileStipYOrigin;
DoChangeGC(pGC, gcmask, (XID *)gcvalues, TRUE);
ValidateGC((DrawablePtr)pBackingStore->pBackingPixmap, pGC);
/*
* Figure out the array of rectangles to fill and fill them with
* PolyFillRect in the proper mode, as set in the GC above.
*/
numRects = REGION_NUM_RECTS(pRgn);
rects = (xRectangle *)ALLOCATE_LOCAL(numRects*sizeof(xRectangle));
if (rects)
{
for (i = 0, pBox = REGION_RECTS(pRgn);
i < numRects;
i++, pBox++)
{
rects[i].x = pBox->x1 - pBackingStore->x;
rects[i].y = pBox->y1 - pBackingStore->y;
rects[i].width = pBox->x2 - pBox->x1;
rects[i].height = pBox->y2 - pBox->y1;
}
(* pGC->ops->PolyFillRect) (
(DrawablePtr)pBackingStore->pBackingPixmap,
pGC, numRects, rects);
DEALLOCATE_LOCAL(rects);
}
FreeScratchGC(pGC);
}
}
if (!generateExposures)
{
REGION_DESTROY(pScreen, pRgn);
pRgn = NULL;
}
else
{
/*
* result must be screen relative, but is currently
* drawable relative.
*/
REGION_TRANSLATE(pScreen, pRgn, pWin->drawable.x,
pWin->drawable.y);
}
}
else
{
REGION_DESTROY( pScreen, pRgn);
pRgn = NULL;
}
return pRgn;
}
static void
miBSClearBackingRegion (pWin, pRgn)
WindowPtr pWin;
RegionPtr pRgn;
{
BoxPtr pBox;
int i;
i = REGION_NUM_RECTS(pRgn);
pBox = REGION_RECTS(pRgn);
while (i--)
{
(void) miBSClearBackingStore(pWin, pBox->x1, pBox->y1,
pBox->x2 - pBox->x1,
pBox->y2 - pBox->y1,
FALSE);
pBox++;
}
}
/*
* fill a region of the destination with virtual bits
*
* pRgn is to be translated by (x,y)
*/
static void
miBSFillVirtualBits (pDrawable, pGC, pRgn, x, y, state, pixunion, planeMask)
DrawablePtr pDrawable;
GCPtr pGC;
RegionPtr pRgn;
int x, y;
int state;
PixUnion pixunion;
unsigned long planeMask;
{
int i;
BITS32 gcmask;
pointer gcval[5];
xRectangle *pRect;
BoxPtr pBox;
WindowPtr pWin;
int numRects;
if (state == None)
return;
numRects = REGION_NUM_RECTS(pRgn);
pRect = (xRectangle *)ALLOCATE_LOCAL(numRects * sizeof(xRectangle));
if (!pRect)
return;
pWin = 0;
if (pDrawable->type != DRAWABLE_PIXMAP)
{
pWin = (WindowPtr) pDrawable;
if (!pWin->backStorage)
pWin = 0;
}
i = 0;
gcmask = 0;
gcval[i++] = (pointer)planeMask;
gcmask |= GCPlaneMask;
if (state == BackgroundPixel)
{
if (pGC->fgPixel != pixunion.pixel)
{
gcval[i++] = (pointer)pixunion.pixel;
gcmask |= GCForeground;
}
if (pGC->fillStyle != FillSolid)
{
gcval[i++] = (pointer)FillSolid;
gcmask |= GCFillStyle;
}
}
else
{
if (pGC->fillStyle != FillTiled)
{
gcval[i++] = (pointer)FillTiled;
gcmask |= GCFillStyle;
}
if (pGC->tileIsPixel || pGC->tile.pixmap != pixunion.pixmap)
{
gcval[i++] = (pointer)pixunion.pixmap;
gcmask |= GCTile;
}
if (pGC->patOrg.x != x)
{
gcval[i++] = (pointer)(long)x;
gcmask |= GCTileStipXOrigin;
}
if (pGC->patOrg.y != y)
{
gcval[i++] = (pointer)(long)y;
gcmask |= GCTileStipYOrigin;
}
}
if (gcmask)
DoChangeGC (pGC, gcmask, (XID *)gcval, 1);
if (pWin)
(*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeVisBack);
if (pDrawable->serialNumber != pGC->serialNumber)
ValidateGC (pDrawable, pGC);
pBox = REGION_RECTS(pRgn);
for (i = numRects; --i >= 0; pBox++, pRect++)
{
pRect->x = pBox->x1 + x;
pRect->y = pBox->y1 + y;
pRect->width = pBox->x2 - pBox->x1;
pRect->height = pBox->y2 - pBox->y1;
}
pRect -= numRects;
(*pGC->ops->PolyFillRect) (pDrawable, pGC, numRects, pRect);
if (pWin)
(*pWin->drawable.pScreen->DrawGuarantee) (pWin, pGC, GuaranteeNothing);
DEALLOCATE_LOCAL (pRect);
}
/*-
*-----------------------------------------------------------------------
* miBSAllocate --
* Create and install backing store info for a window
*
*-----------------------------------------------------------------------
*/
static void
miBSAllocate(pWin)
WindowPtr pWin;
{
register miBSWindowPtr pBackingStore;
register ScreenPtr pScreen;
if (pWin->drawable.pScreen->backingStoreSupport == NotUseful)
return;
pScreen = pWin->drawable.pScreen;
if (!(pBackingStore = (miBSWindowPtr)pWin->backStorage))
{
pBackingStore = (miBSWindowPtr)xalloc(sizeof(miBSWindowRec));
if (!pBackingStore)
return;
pBackingStore->pBackingPixmap = NullPixmap;
pBackingStore->x = 0;
pBackingStore->y = 0;
REGION_NULL( pScreen, &pBackingStore->SavedRegion);
pBackingStore->viewable = (char)pWin->viewable;
pBackingStore->status = StatusNoPixmap;
pBackingStore->backgroundState = None;
pWin->backStorage = (pointer) pBackingStore;
}
/*
* Now want to initialize the backing pixmap and SavedRegion if
* necessary. The initialization consists of finding all the
* currently-obscured regions, by taking the inverse of the window's
* clip list, storing the result in SavedRegion, and exposing those
* areas of the window.
*/
if (pBackingStore->status == StatusNoPixmap &&
((pWin->backingStore == WhenMapped && pWin->viewable) ||
(pWin->backingStore == Always)))
{
BoxRec box;
RegionPtr pSavedRegion;
pSavedRegion = &pBackingStore->SavedRegion;
box.x1 = pWin->drawable.x;
box.x2 = box.x1 + (int) pWin->drawable.width;
box.y1 = pWin->drawable.y;
box.y2 = pWin->drawable.y + (int) pWin->drawable.height;
REGION_INVERSE( pScreen, pSavedRegion, &pWin->clipList, &box);
REGION_TRANSLATE( pScreen, pSavedRegion,
-pWin->drawable.x,
-pWin->drawable.y);
#ifdef SHAPE
if (wBoundingShape (pWin))
REGION_INTERSECT(pScreen, pSavedRegion, pSavedRegion,
wBoundingShape (pWin));
if (wClipShape (pWin))
REGION_INTERSECT(pScreen, pSavedRegion, pSavedRegion,
wClipShape (pWin));
#endif
/* if window is already on-screen, assume it has been drawn to */
if (pWin->viewable)
pBackingStore->status = StatusVDirty;
miTileVirtualBS (pWin);
/*
* deliver all the newly available regions
* as exposure events to the window
*/
miSendExposures(pWin, pSavedRegion, 0, 0);
}
else if (!pWin->viewable)
{
/*
* Turn off backing store when we're not supposed to
* be saving anything
*/
if (pBackingStore->status != StatusNoPixmap)
{
REGION_EMPTY( pScreen, &pBackingStore->SavedRegion);
miDestroyBSPixmap (pWin);
}
}
}
/*-
*-----------------------------------------------------------------------
* miBSFree --
* Destroy and free all the stuff associated with the backing-store
* for the given window.
*
* Results:
* None.
*
* Side Effects:
* The backing pixmap and all the regions and GC's are destroyed.
*
*-----------------------------------------------------------------------
*/
static void
miBSFree(pWin)
WindowPtr pWin;
{
miBSWindowPtr pBackingStore;
register ScreenPtr pScreen;
pScreen = pWin->drawable.pScreen;
pBackingStore = (miBSWindowPtr)pWin->backStorage;
if (pBackingStore)
{
miDestroyBSPixmap (pWin);
REGION_UNINIT( pScreen, &pBackingStore->SavedRegion);
xfree(pBackingStore);
pWin->backStorage = NULL;
}
}
/*-
*-----------------------------------------------------------------------
* miResizeBackingStore --
* Alter the size of the backing pixmap as necessary when the
* SavedRegion changes size. The contents of the old pixmap are
* copied/shifted into the new/same pixmap.
*
* Results:
* The new Pixmap is created as necessary.
*
* Side Effects:
* The old pixmap is destroyed.
*
*-----------------------------------------------------------------------
*/
static void
miResizeBackingStore(
WindowPtr pWin,
int dx, /* bits are moving this far */
int dy, /* bits are moving this far */
Bool saveBits) /* bits are useful */
{
miBSWindowPtr pBackingStore;
PixmapPtr pBackingPixmap;
ScreenPtr pScreen;
GC *pGC;
BoxPtr extents;
PixmapPtr pNewPixmap;
int nx, ny;
int nw, nh;
pBackingStore = (miBSWindowPtr)(pWin->backStorage);
pBackingPixmap = pBackingStore->pBackingPixmap;
if (!pBackingPixmap)
return;
pScreen = pWin->drawable.pScreen;
extents = REGION_EXTENTS(pScreen, &pBackingStore->SavedRegion);
pNewPixmap = pBackingPixmap;
nw = extents->x2 - extents->x1;
nh = extents->y2 - extents->y1;
/* the policy here could be more sophisticated */
if (nw != pBackingPixmap->drawable.width ||
nh != pBackingPixmap->drawable.height)
{
if (!saveBits || !nw || !nh)
{
pNewPixmap = NullPixmap;
pBackingStore->status = StatusNoPixmap;
}
else
{
pNewPixmap = (PixmapPtr)(*pScreen->CreatePixmap)
(pScreen,
nw, nh,
pWin->drawable.depth);
if (!pNewPixmap)
{
#ifdef BSEAGER
pBackingStore->status = StatusNoPixmap;
#else
pBackingStore->status = StatusBadAlloc;
#endif
}
}
}
if (!pNewPixmap)
{
pBackingStore->x = 0;
pBackingStore->y = 0;
}
else
{
nx = pBackingStore->x - extents->x1 + dx;
ny = pBackingStore->y - extents->y1 + dy;
pBackingStore->x = extents->x1;
pBackingStore->y = extents->y1;
if (saveBits && (pNewPixmap != pBackingPixmap || nx != 0 || ny != 0))
{
pGC = GetScratchGC(pNewPixmap->drawable.depth, pScreen);
if (pGC)
{
ValidateGC((DrawablePtr)pNewPixmap, pGC);
/* if we implement a policy where the pixmap can be larger than
* the region extents, we might want to optimize this copyarea
* by only copying the old extents, rather than the entire
* pixmap
*/
(*pGC->ops->CopyArea)((DrawablePtr)pBackingPixmap,
(DrawablePtr)pNewPixmap, pGC,
0, 0,
pBackingPixmap->drawable.width,
pBackingPixmap->drawable.height,
nx, ny);
FreeScratchGC(pGC);
}
}
}
/* SavedRegion is used in the backingGC clip; force an update */
pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER;
if (pNewPixmap != pBackingPixmap)
{
(* pScreen->DestroyPixmap)(pBackingPixmap);
pBackingStore->pBackingPixmap = pNewPixmap;
}
}
/*-
*-----------------------------------------------------------------------
* miBSSaveDoomedAreas --
* Saved the areas of the given window that are about to be
* obscured. If the window has moved, pObscured is expected to
* be at the new screen location and (dx,dy) is expected to be the offset
* to the window's previous location.
*
* Results:
* None.
*
* Side Effects:
* The region is copied from the screen into pBackingPixmap and
* SavedRegion is updated.
*
*-----------------------------------------------------------------------
*/
static void
miBSSaveDoomedAreas(pWin, pObscured, dx, dy)
register WindowPtr pWin;
RegionPtr pObscured;
int dx, dy;
{
miBSWindowPtr pBackingStore;
ScreenPtr pScreen;
int x, y;
pBackingStore = (miBSWindowPtr)pWin->backStorage;
pScreen = pWin->drawable.pScreen;
/*
* If the window isn't realized, it's being unmapped, thus we don't
* want to save anything if backingStore isn't Always.
*/
if (!pWin->realized)
{
pBackingStore->viewable = (char)pWin->viewable;
if (pWin->backingStore != Always)
{
REGION_EMPTY( pScreen, &pBackingStore->SavedRegion);
miDestroyBSPixmap (pWin);
return;
}
if (pBackingStore->status == StatusBadAlloc)
pBackingStore->status = StatusNoPixmap;
}
/* Don't even pretend to save anything for a virtual background None */
if ((pBackingStore->status == StatusVirtual) &&
(pBackingStore->backgroundState == None))
return;
if (REGION_NOTEMPTY(pScreen, pObscured))
{
BoxRec oldExtents;
x = pWin->drawable.x;
y = pWin->drawable.y;
REGION_TRANSLATE(pScreen, pObscured, -x, -y);
oldExtents = *REGION_EXTENTS(pScreen, &pBackingStore->SavedRegion);
REGION_UNION( pScreen, &pBackingStore->SavedRegion,
&pBackingStore->SavedRegion,
pObscured);
/*
* only save the bits if we've actually
* started using backing store
*/
if (pBackingStore->status != StatusVirtual)
{
if (!pBackingStore->pBackingPixmap)
miCreateBSPixmap (pWin, &oldExtents);
else
miResizeBackingStore(pWin, 0, 0, TRUE);
if (pBackingStore->pBackingPixmap) {
if (pBackingStore->x | pBackingStore->y)
{
REGION_TRANSLATE( pScreen, pObscured,
-pBackingStore->x,
-pBackingStore->y);
x += pBackingStore->x;
y += pBackingStore->y;
}
(* pScreen->BackingStoreFuncs.SaveAreas)
(pBackingStore->pBackingPixmap, pObscured,
x - dx, y - dy, pWin);
}
}
REGION_TRANSLATE(pScreen, pObscured, x, y);
}
else
{
if (REGION_BROKEN (pScreen, pObscured))
{
REGION_EMPTY( pScreen, &pBackingStore->SavedRegion);
miDestroyBSPixmap (pWin);
return;
}
}
}
/*-
*-----------------------------------------------------------------------
* miBSRestoreAreas --
* Restore areas from backing-store that are no longer obscured.
* expects prgnExposed to contain a screen-relative area.
*
* Results:
* The region to generate exposure events on (which may be
* different from the region to paint).
*
* Side Effects:
* Areas are copied from pBackingPixmap to the screen. prgnExposed
* is altered to contain the region that could not be restored from
* backing-store.
*
* Notes:
* This is called before sending any exposure events to the client,
* and so might be called if the window has grown. Changing the backing
* pixmap doesn't require revalidating the backingGC because the
* client's next output request will result in a call to ValidateGC,
* since the window clip region has changed, which will in turn call
* miValidateBackingStore.
*-----------------------------------------------------------------------
*/
static RegionPtr
miBSRestoreAreas(pWin, prgnExposed)
register WindowPtr pWin;
RegionPtr prgnExposed;
{
PixmapPtr pBackingPixmap;
miBSWindowPtr pBackingStore;
RegionPtr prgnSaved;
RegionPtr prgnRestored;
register ScreenPtr pScreen;
RegionPtr exposures = prgnExposed;
pScreen = pWin->drawable.pScreen;
pBackingStore = (miBSWindowPtr)pWin->backStorage;
pBackingPixmap = pBackingStore->pBackingPixmap;
prgnSaved = &pBackingStore->SavedRegion;
if (pBackingStore->status == StatusContents)
{
REGION_TRANSLATE(pScreen, prgnSaved, pWin->drawable.x,
pWin->drawable.y);
prgnRestored = REGION_CREATE( pScreen, (BoxPtr)NULL, 1);
REGION_INTERSECT( pScreen, prgnRestored, prgnExposed, prgnSaved);
/*
* Since prgnExposed is no longer obscured, we no longer
* will have a valid copy of it in backing-store, but there is a valid
* copy of it on screen, so subtract the area we just restored from
* from the area to be exposed.
*/
if (REGION_NOTEMPTY( pScreen, prgnRestored))
{
REGION_SUBTRACT( pScreen, prgnSaved, prgnSaved, prgnExposed);
REGION_SUBTRACT( pScreen, prgnExposed, prgnExposed, prgnRestored);
/*
* Do the actual restoration
*/
(* pScreen->BackingStoreFuncs.RestoreAreas) (pBackingPixmap,
prgnRestored,
pWin->drawable.x + pBackingStore->x,
pWin->drawable.y + pBackingStore->y,
pWin);
/*
* if the saved region is completely empty, dispose of the
* backing pixmap, otherwise, retranslate the saved
* region to window relative
*/
if (REGION_NOTEMPTY(pScreen, prgnSaved))
{
REGION_TRANSLATE(pScreen, prgnSaved,
-pWin->drawable.x,
-pWin->drawable.y);
miResizeBackingStore(pWin, 0, 0, TRUE);
}
else
miDestroyBSPixmap (pWin);
}
else
REGION_TRANSLATE(pScreen, prgnSaved,
-pWin->drawable.x, -pWin->drawable.y);
REGION_DESTROY( pScreen, prgnRestored);
}
else if ((pBackingStore->status == StatusVirtual) ||
(pBackingStore->status == StatusVDirty))
{
REGION_TRANSLATE(pScreen, prgnSaved,
pWin->drawable.x, pWin->drawable.y);
exposures = REGION_CREATE( pScreen, NullBox, 1);
if (SameBackground (pBackingStore->backgroundState,
pBackingStore->background,
pWin->backgroundState,
pWin->background))
{
REGION_SUBTRACT( pScreen, exposures, prgnExposed, prgnSaved);
}
else
{
miTileVirtualBS(pWin);
/* we need to expose all we have (virtually) retiled */
REGION_UNION( pScreen, exposures, prgnExposed, prgnSaved);
}
REGION_SUBTRACT( pScreen, prgnSaved, prgnSaved, prgnExposed);
REGION_TRANSLATE(pScreen, prgnSaved,
-pWin->drawable.x, -pWin->drawable.y);
}
else if (pWin->viewable && !pBackingStore->viewable &&
pWin->backingStore != Always)
{
/*
* The window was just mapped and nothing has been saved in
* backing-store from the last time it was mapped. We want to capture
* any output to regions that are already obscured but there are no
* bits to snag off the screen, so we initialize things just as we did
* in miBSAllocate, above.
*/
BoxRec box;
prgnSaved = &pBackingStore->SavedRegion;
box.x1 = pWin->drawable.x;
box.x2 = box.x1 + (int) pWin->drawable.width;
box.y1 = pWin->drawable.y;
box.y2 = box.y1 + (int) pWin->drawable.height;
REGION_INVERSE( pScreen, prgnSaved, &pWin->clipList, &box);
REGION_TRANSLATE( pScreen, prgnSaved,
-pWin->drawable.x,
-pWin->drawable.y);
#ifdef SHAPE
if (wBoundingShape (pWin))
REGION_INTERSECT(pScreen, prgnSaved, prgnSaved,
wBoundingShape (pWin));
if (wClipShape (pWin))
REGION_INTERSECT(pScreen, prgnSaved, prgnSaved,
wClipShape (pWin));
#endif
miTileVirtualBS(pWin);
exposures = REGION_CREATE( pScreen, &box, 1);
}
pBackingStore->viewable = (char)pWin->viewable;
return exposures;
}
/*-
*-----------------------------------------------------------------------
* miBSTranslateBackingStore --
* Shift the backing-store in the given direction. Called when bit
* gravity is shifting things around.
*
* Results:
* An occluded region of the window which should be sent exposure events.
* This region should be in absolute coordinates (i.e. include
* new window position).
*
* Side Effects:
* If the window changed size as well as position, the backing pixmap
* is resized. The contents of the backing pixmap are shifted
*
* Warning:
* Bob and I have rewritten this routine quite a few times, each
* time it gets a few more cases correct, and introducing some
* interesting bugs. Naturally, I think the code is correct this
* time.
*
* Let me try to explain what this routine is for:
*
* It's called from SlideAndSizeWindow whenever a window
* with backing store is resized. There are two separate
* possibilities:
*
* a) The window has ForgetGravity
*
* In this case, windx, windy will be 0 and oldClip will
* be NULL. This indicates that all of the window contents
* currently saved offscreen should be discarded, and the
* entire window exposed. TranslateBackingStore, then, should
* prepare a completely new backing store region based on the
* new window clipList and return that region for exposure.
*
* b) The window has some other gravity
*
* In this case, windx, windy will be set to the distance
* that the bits should move within the window. oldClip
* will be set to the old visible portion of the window.
* TranslateBackingStore, then, should adjust the backing
* store to accommodate the portion of the existing backing
* store bits which coorespond to backing store bits which
* will still be occluded in the new configuration. oldx,oldy
* are set to the old position of the window on the screen.
*
* Furthermore, in this case any contents of the screen which
* are about to become occluded should be fetched from the screen
* and placed in backing store. This is to avoid the eventual
* occlusion by the win gravity shifting the child window bits around
* on top of this window, and potentially losing information
*
* It's also called from SetShape, but I think (he says not
* really knowing for sure) that this code will even work
* in that case.
*-----------------------------------------------------------------------
*/
static RegionPtr
miBSTranslateBackingStore(pWin, windx, windy, oldClip, oldx, oldy)
WindowPtr pWin;
int windx; /* bit translation distance in window */
int windy;
RegionPtr oldClip; /* Region being copied */
int oldx; /* old window position */
int oldy;
{
register miBSWindowPtr pBackingStore;
register RegionPtr pSavedRegion;
register RegionPtr newSaved, doomed;
register ScreenPtr pScreen;
BoxRec extents;
int scrdx; /* bit translation distance on screen */
int scrdy;
int dx; /* distance window moved on screen */
int dy;
pScreen = pWin->drawable.pScreen;
pBackingStore = (miBSWindowPtr)(pWin->backStorage);
if ((pBackingStore->status == StatusNoPixmap) ||
(pBackingStore->status == StatusBadAlloc))
return NullRegion;
/*
* Compute the new saved region
*/
newSaved = REGION_CREATE( pScreen, NullBox, 1);
extents.x1 = pWin->drawable.x;
extents.x2 = pWin->drawable.x + (int) pWin->drawable.width;
extents.y1 = pWin->drawable.y;
extents.y2 = pWin->drawable.y + (int) pWin->drawable.height;
REGION_INVERSE( pScreen, newSaved, &pWin->clipList, &extents);
REGION_TRANSLATE( pScreen, newSaved,
-pWin->drawable.x, -pWin->drawable.y);
#ifdef SHAPE
if (wBoundingShape (pWin) || wClipShape (pWin)) {
if (wBoundingShape (pWin))
REGION_INTERSECT( pScreen, newSaved, newSaved,
wBoundingShape (pWin));
if (wClipShape (pWin))
REGION_INTERSECT( pScreen, newSaved, newSaved, wClipShape (pWin));
}
#endif
pSavedRegion = &pBackingStore->SavedRegion;
/* now find any visible areas we can save from the screen */
/* and then translate newSaved to old local coordinates */
if (oldClip)
{
/* bit gravity makes things virtually too hard, punt */
if (((windx != 0) || (windy != 0)) &&
(pBackingStore->status != StatusContents))
miCreateBSPixmap(pWin, NullBox);
/*
* The window is moving this far on the screen
*/
dx = pWin->drawable.x - oldx;
dy = pWin->drawable.y - oldy;
/*
* The bits will be moving on the screen by the
* amount the window is moving + the amount the
* bits are moving within the window
*/
scrdx = windx + dx;
scrdy = windy + dy;
/*
* intersect at old bit position to discover the
* bits on the screen which can be put into the
* new backing store
*/
REGION_TRANSLATE( pScreen, oldClip, windx - oldx, windy - oldy);
doomed = REGION_CREATE( pScreen, NullBox, 1);
REGION_INTERSECT( pScreen, doomed, oldClip, newSaved);
REGION_TRANSLATE( pScreen, oldClip, oldx - windx, oldy - windy);
/*
* Translate the old saved region to the position in the
* window where it will appear to be
*/
REGION_TRANSLATE( pScreen, pSavedRegion, windx, windy);
/*
* Add the old saved region to the new saved region, so
* that calls to RestoreAreas will be able to fetch those
* bits back
*/
REGION_UNION( pScreen, newSaved, newSaved, pSavedRegion);
/*
* Swap the new saved region into the window
*/
{
RegionRec tmp;
tmp = *pSavedRegion;
*pSavedRegion = *newSaved;
*newSaved = tmp;
}
miResizeBackingStore (pWin, windx, windy, TRUE);
/*
* Compute the newly enabled region
* of backing store. This region will be
* set to background in the backing pixmap and
* sent as exposure events to the client.
*/
REGION_SUBTRACT( pScreen, newSaved, pSavedRegion, newSaved);
/*
* Fetch bits which will be obscured from
* the screen
*/
if (REGION_NOTEMPTY( pScreen, doomed))
{
/*
* Don't clear regions which have bits on the
* screen
*/
REGION_SUBTRACT( pScreen, newSaved, newSaved, doomed);
/*
* Make the region to SaveDoomedAreas absolute, instead
* of window relative.
*/
REGION_TRANSLATE( pScreen, doomed,
pWin->drawable.x, pWin->drawable.y);
(* pScreen->SaveDoomedAreas) (pWin, doomed, scrdx, scrdy);
}
REGION_DESTROY(pScreen, doomed);
/*
* and clear whatever there is that's new
*/
if (REGION_NOTEMPTY( pScreen, newSaved))
{
miBSClearBackingRegion (pWin, newSaved);
/*
* Make the exposed region absolute
*/
REGION_TRANSLATE(pScreen, newSaved,
pWin->drawable.x,
pWin->drawable.y);
}
else
{
REGION_DESTROY(pScreen, newSaved);
newSaved = NullRegion;
}
}
else
{
/*
* ForgetGravity: just reset backing store and
* expose the whole mess
*/
REGION_COPY( pScreen, pSavedRegion, newSaved);
REGION_TRANSLATE( pScreen, newSaved,
pWin->drawable.x, pWin->drawable.y);
miResizeBackingStore (pWin, 0, 0, FALSE);
(void) miBSClearBackingStore (pWin, 0, 0, 0, 0, FALSE);
}
return newSaved;
}
/*
* Inform the backing store layer that you are about to validate
* a gc with a window, and that subsequent output to the window
* is (or is not) guaranteed to be already clipped to the visible
* regions of the window.
*/
static void
miBSDrawGuarantee (pWin, pGC, guarantee)
WindowPtr pWin;
GCPtr pGC;
int guarantee;
{
miBSGCPtr pPriv;
if (pWin->backStorage)
{
pPriv = (miBSGCPtr)pGC->devPrivates[miBSGCIndex].ptr;
if (!pPriv)
(void) miBSCreateGCPrivate (pGC);
pPriv = (miBSGCPtr)pGC->devPrivates[miBSGCIndex].ptr;
if (pPriv)
{
/*
* XXX KLUDGE ALERT
*
* when the GC is Cheap pPriv will point
* at some device's gc func structure. guarantee
* will point at the ChangeGC entry of that struct
* and will never match a valid guarantee value.
*/
switch (pPriv->guarantee)
{
case GuaranteeNothing:
case GuaranteeVisBack:
pPriv->guarantee = guarantee;
break;
}
}
}
}
#define noBackingCopy (GCGraphicsExposures|GCClipXOrigin|GCClipYOrigin| \
GCClipMask|GCSubwindowMode| \
GCTileStipXOrigin|GCTileStipYOrigin)
/*-
*-----------------------------------------------------------------------
* miBSValidateGC --
* Wrapper around output-library's ValidateGC routine
*
* Results:
* None.
*
* Side Effects:
*
* Notes:
* The idea here is to perform several functions:
* - All the output calls must be intercepted and routed to
* backing-store as necessary.
* - pGC in the window's devBackingStore must be set up with the
* clip list appropriate for writing to pBackingPixmap (i.e.
* the inverse of the window's clipList intersected with the
* clientClip of the GC). Since the destination for this GC is
* a pixmap, it is sufficient to set the clip list as its
* clientClip.
*-----------------------------------------------------------------------
*/
static void
miBSValidateGC (pGC, stateChanges, pDrawable)
GCPtr pGC;
unsigned long stateChanges;
DrawablePtr pDrawable;
{
GCPtr pBackingGC;
miBSWindowPtr pWindowPriv = NULL;
miBSGCPtr pPriv;
WindowPtr pWin;
int lift_functions;
RegionPtr backingCompositeClip = NULL;
if (pDrawable->type != DRAWABLE_PIXMAP)
{
pWin = (WindowPtr) pDrawable;
pWindowPriv = (miBSWindowPtr) pWin->backStorage;
lift_functions = (pWindowPriv == (miBSWindowPtr) NULL);
}
else
{
pWin = (WindowPtr) NULL;
lift_functions = TRUE;
}
pPriv = (miBSGCPtr)pGC->devPrivates[miBSGCIndex].ptr;
FUNC_PROLOGUE (pGC, pPriv);
(*pGC->funcs->ValidateGC) (pGC, stateChanges, pDrawable);
/*
* rewrap funcs and ops as Validate may have changed them
*/
pPriv->wrapFuncs = pGC->funcs;
pPriv->wrapOps = pGC->ops;
if (!lift_functions && ((pPriv->guarantee == GuaranteeVisBack) ||
(pWindowPriv->status == StatusNoPixmap) ||
(pWindowPriv->status == StatusBadAlloc)))
lift_functions = TRUE;
/*
* check to see if a new backingCompositeClip region must
* be generated
*/
if (!lift_functions &&
((pDrawable->serialNumber != pPriv->serialNumber) ||
(stateChanges&(GCClipXOrigin|GCClipYOrigin|GCClipMask|GCSubwindowMode))))
{
if (REGION_NOTEMPTY(pGC->pScreen, &pWindowPriv->SavedRegion))
{
backingCompositeClip = REGION_CREATE(pGC->pScreen, NULL, 1);
if ((pGC->clientClipType == CT_NONE) ||
(pGC->clientClipType == CT_PIXMAP))
{
REGION_COPY(pGC->pScreen, backingCompositeClip,
&pWindowPriv->SavedRegion);
}
else
{
/*
* Make a new copy of the client clip, translated to
* its proper origin.
*/
REGION_COPY(pGC->pScreen, backingCompositeClip,
pGC->clientClip);
REGION_TRANSLATE(pGC->pScreen, backingCompositeClip,
pGC->clipOrg.x,
pGC->clipOrg.y);
REGION_INTERSECT(pGC->pScreen, backingCompositeClip,
backingCompositeClip,
&pWindowPriv->SavedRegion);
}
if (pGC->subWindowMode == IncludeInferiors)
{
RegionPtr translatedClip;
/* XXX
* any output in IncludeInferiors mode will not
* be redirected to Inferiors backing store. This
* can be fixed only at great cost to the shadow routines.
*/
translatedClip = NotClippedByChildren (pWin);
REGION_TRANSLATE(pGC->pScreen, translatedClip,
-pDrawable->x,
-pDrawable->y);
REGION_SUBTRACT(pGC->pScreen, backingCompositeClip,
backingCompositeClip, translatedClip);
REGION_DESTROY(pGC->pScreen, translatedClip);
}
if (!REGION_NOTEMPTY(pGC->pScreen, backingCompositeClip))
lift_functions = TRUE;
}
else
{
lift_functions = TRUE;
}
/* Reset the status when drawing to an unoccluded window so that
* future SaveAreas will actually copy bits from the screen. Note that
* output to root window in IncludeInferiors mode will not cause this
* to change. This causes all transient graphics by the window
* manager to the root window to not enable backing store.
*/
if (lift_functions && (pWindowPriv->status == StatusVirtual) &&
(pWin->parent || pGC->subWindowMode != IncludeInferiors))
pWindowPriv->status = StatusVDirty;
}
/*
* if no backing store has been allocated, and it's needed,
* create it now.
*/
if (!lift_functions && !pWindowPriv->pBackingPixmap)
{
miCreateBSPixmap (pWin, NullBox);
if (!pWindowPriv->pBackingPixmap)
lift_functions = TRUE;
}
/*
* create the backing GC if needed, lift functions
* if the creation fails
*/
if (!lift_functions && !pPriv->pBackingGC)
{
int status;
XID noexpose = xFalse;
/* We never want ops with the backingGC to generate GraphicsExpose */
pBackingGC = CreateGC ((DrawablePtr)pWindowPriv->pBackingPixmap,
GCGraphicsExposures, &noexpose, &status);
if (status != Success)
lift_functions = TRUE;
else
pPriv->pBackingGC = pBackingGC;
}
pBackingGC = pPriv->pBackingGC;
pPriv->stateChanges |= stateChanges;
if (lift_functions)
{
if (backingCompositeClip)
REGION_DESTROY( pGC->pScreen, backingCompositeClip);
/* unwrap the GC again */
miBSDestroyGCPrivate (pGC);
return;
}
/*
* the rest of this function gets the pBackingGC
* into shape for possible draws
*/
pPriv->stateChanges &= ~noBackingCopy;
if (pPriv->stateChanges)
CopyGC(pGC, pBackingGC, pPriv->stateChanges);
if ((pGC->patOrg.x - pWindowPriv->x) != pBackingGC->patOrg.x ||
(pGC->patOrg.y - pWindowPriv->y) != pBackingGC->patOrg.y)
{
XID vals[2];
vals[0] = pGC->patOrg.x - pWindowPriv->x;
vals[1] = pGC->patOrg.y - pWindowPriv->y;
DoChangeGC(pBackingGC, GCTileStipXOrigin|GCTileStipYOrigin, vals, 0);
}
pPriv->stateChanges = 0;
if (backingCompositeClip)
{
XID vals[2];
if (pGC->clientClipType == CT_PIXMAP)
{
(*pBackingGC->funcs->CopyClip)(pBackingGC, pGC);
REGION_TRANSLATE(pGC->pScreen, backingCompositeClip,
-pGC->clipOrg.x, -pGC->clipOrg.y);
vals[0] = pGC->clipOrg.x - pWindowPriv->x;
vals[1] = pGC->clipOrg.y - pWindowPriv->y;
DoChangeGC(pBackingGC, GCClipXOrigin|GCClipYOrigin, vals, 0);
(* pGC->pScreen->BackingStoreFuncs.SetClipmaskRgn)
(pBackingGC, backingCompositeClip);
REGION_DESTROY( pGC->pScreen, backingCompositeClip);
}
else
{
vals[0] = -pWindowPriv->x;
vals[1] = -pWindowPriv->y;
DoChangeGC(pBackingGC, GCClipXOrigin|GCClipYOrigin, vals, 0);
(*pBackingGC->funcs->ChangeClip) (pBackingGC, CT_REGION, backingCompositeClip, 0);
}
pPriv->serialNumber = pDrawable->serialNumber;
}
if (pWindowPriv->pBackingPixmap->drawable.serialNumber
!= pBackingGC->serialNumber)
{
ValidateGC((DrawablePtr)pWindowPriv->pBackingPixmap, pBackingGC);
}
if (pBackingGC->clientClip == 0)
ErrorF ("backing store clip list nil");
FUNC_EPILOGUE (pGC, pPriv);
}
static void
miBSChangeGC (pGC, mask)
GCPtr pGC;
unsigned long mask;
{
miBSGCPtr pPriv = (miBSGCPtr) (pGC)->devPrivates[miBSGCIndex].ptr;
FUNC_PROLOGUE (pGC, pPriv);
(*pGC->funcs->ChangeGC) (pGC, mask);
FUNC_EPILOGUE (pGC, pPriv);
}
static void
miBSCopyGC (pGCSrc, mask, pGCDst)
GCPtr pGCSrc, pGCDst;
unsigned long mask;
{
miBSGCPtr pPriv = (miBSGCPtr) (pGCDst)->devPrivates[miBSGCIndex].ptr;
FUNC_PROLOGUE (pGCDst, pPriv);
(*pGCDst->funcs->CopyGC) (pGCSrc, mask, pGCDst);
FUNC_EPILOGUE (pGCDst, pPriv);
}
static void
miBSDestroyGC (pGC)
GCPtr pGC;
{
miBSGCPtr pPriv = (miBSGCPtr) (pGC)->devPrivates[miBSGCIndex].ptr;
FUNC_PROLOGUE (pGC, pPriv);
if (pPriv->pBackingGC)
FreeGC(pPriv->pBackingGC, (GContext)0);
(*pGC->funcs->DestroyGC) (pGC);
FUNC_EPILOGUE (pGC, pPriv);
xfree(pPriv);
}
static void
miBSChangeClip(pGC, type, pvalue, nrects)
GCPtr pGC;
int type;
pointer pvalue;
int nrects;
{
miBSGCPtr pPriv = (miBSGCPtr) (pGC)->devPrivates[miBSGCIndex].ptr;
FUNC_PROLOGUE (pGC, pPriv);
(* pGC->funcs->ChangeClip)(pGC, type, pvalue, nrects);
FUNC_EPILOGUE (pGC, pPriv);
}
static void
miBSCopyClip(pgcDst, pgcSrc)
GCPtr pgcDst, pgcSrc;
{
miBSGCPtr pPriv = (miBSGCPtr) (pgcDst)->devPrivates[miBSGCIndex].ptr;
FUNC_PROLOGUE (pgcDst, pPriv);
(* pgcDst->funcs->CopyClip)(pgcDst, pgcSrc);
FUNC_EPILOGUE (pgcDst, pPriv);
}
static void
miBSDestroyClip(pGC)
GCPtr pGC;
{
miBSGCPtr pPriv = (miBSGCPtr) (pGC)->devPrivates[miBSGCIndex].ptr;
FUNC_PROLOGUE (pGC, pPriv);
(* pGC->funcs->DestroyClip)(pGC);
FUNC_EPILOGUE (pGC, pPriv);
}
static void
miDestroyBSPixmap (pWin)
WindowPtr pWin;
{
miBSWindowPtr pBackingStore;
ScreenPtr pScreen;
pScreen = pWin->drawable.pScreen;
pBackingStore = (miBSWindowPtr) pWin->backStorage;
if (pBackingStore->pBackingPixmap)
(* pScreen->DestroyPixmap)(pBackingStore->pBackingPixmap);
pBackingStore->pBackingPixmap = NullPixmap;
pBackingStore->x = 0;
pBackingStore->y = 0;
if (pBackingStore->backgroundState == BackgroundPixmap)
(* pScreen->DestroyPixmap)(pBackingStore->background.pixmap);
pBackingStore->backgroundState = None;
pBackingStore->status = StatusNoPixmap;
pWin->drawable.serialNumber = NEXT_SERIAL_NUMBER;
}
static void
miTileVirtualBS (pWin)
WindowPtr pWin;
{
miBSWindowPtr pBackingStore;
pBackingStore = (miBSWindowPtr) pWin->backStorage;
if (pBackingStore->backgroundState == BackgroundPixmap)
(* pWin->drawable.pScreen->DestroyPixmap)
(pBackingStore->background.pixmap);
pBackingStore->backgroundState = pWin->backgroundState;
pBackingStore->background = pWin->background;
if (pBackingStore->backgroundState == BackgroundPixmap)
pBackingStore->background.pixmap->refcnt++;
if (pBackingStore->status != StatusVDirty)
pBackingStore->status = StatusVirtual;
/*
* punt parent relative tiles and do it now
*/
if (pBackingStore->backgroundState == ParentRelative)
miCreateBSPixmap (pWin, NullBox);
}
#ifdef DEBUG
static int BSAllocationsFailed = 0;
#define FAILEDSIZE 32
static struct { int w, h; } failedRecord[FAILEDSIZE];
static int failedIndex;
#endif
static void
miCreateBSPixmap (pWin, pExtents)
WindowPtr pWin;
BoxPtr pExtents;
{
miBSWindowPtr pBackingStore;
ScreenPtr pScreen;
PixUnion background;
char backgroundState = 0;
BoxPtr extents;
Bool backSet;
pScreen = pWin->drawable.pScreen;
pBackingStore = (miBSWindowPtr) pWin->backStorage;
if (pBackingStore->status == StatusBadAlloc)
return;
backSet = ((pBackingStore->status == StatusVirtual) ||
(pBackingStore->status == StatusVDirty));
extents = REGION_EXTENTS( pScreen, &pBackingStore->SavedRegion);
if (!pBackingStore->pBackingPixmap &&
extents->x2 != extents->x1 &&
extents->y2 != extents->y1)
{
/* the policy here could be more sophisticated */
pBackingStore->x = extents->x1;
pBackingStore->y = extents->y1;
pBackingStore->pBackingPixmap =
(PixmapPtr)(* pScreen->CreatePixmap)
(pScreen,
extents->x2 - extents->x1,
extents->y2 - extents->y1,
pWin->drawable.depth);
}
if (!pBackingStore->pBackingPixmap)
{
#ifdef DEBUG
BSAllocationsFailed++;
/*
* record failed allocations
*/
failedRecord[failedIndex].w = pWin->drawable.width;
failedRecord[failedIndex].h = pWin->drawable.height;
failedIndex++;
if (failedIndex == FAILEDSIZE)
failedIndex = 0;
#endif
#ifdef BSEAGER
pBackingStore->status = StatusNoPixmap;
#else
pBackingStore->status = StatusBadAlloc;
#endif
return;
}
pBackingStore->status = StatusContents;
if (backSet)
{
backgroundState = pWin->backgroundState;
background = pWin->background;
pWin->backgroundState = pBackingStore->backgroundState;
pWin->background = pBackingStore->background;
if (pWin->backgroundState == BackgroundPixmap)
pWin->background.pixmap->refcnt++;
}
if (!pExtents)
pExtents = extents;
if (pExtents->y1 != pExtents->y2)
{
RegionPtr exposed;
exposed = miBSClearBackingStore(pWin,
pExtents->x1, pExtents->y1,
pExtents->x2 - pExtents->x1,
pExtents->y2 - pExtents->y1,
!backSet);
if (exposed)
{
miSendExposures(pWin, exposed, pWin->drawable.x, pWin->drawable.y);
REGION_DESTROY( pScreen, exposed);
}
}
if (backSet)
{
if (pWin->backgroundState == BackgroundPixmap)
(* pScreen->DestroyPixmap) (pWin->background.pixmap);
pWin->backgroundState = backgroundState;
pWin->background = background;
if (pBackingStore->backgroundState == BackgroundPixmap)
(* pScreen->DestroyPixmap) (pBackingStore->background.pixmap);
pBackingStore->backgroundState = None;
}
}
/*-
*-----------------------------------------------------------------------
* miBSExposeCopy --
* Handle the restoration of areas exposed by graphics operations.
*
* Results:
* None.
*
* Side Effects:
* prgnExposed has the areas exposed from backing-store removed
* from it.
*
*-----------------------------------------------------------------------
*/
static void
miBSExposeCopy (pSrc, pDst, pGC, prgnExposed, srcx, srcy, dstx, dsty, plane)
WindowPtr pSrc;
DrawablePtr pDst;
GCPtr pGC;
RegionPtr prgnExposed;
int srcx, srcy;
int dstx, dsty;
unsigned long plane;
{
RegionRec tempRgn;
miBSWindowPtr pBackingStore;
CopyPlaneProcPtr copyProc;
GCPtr pScratchGC;
register BoxPtr pBox;
register int i;
register int dx, dy;
BITS32 gcMask;
if (!REGION_NOTEMPTY(pGC->pScreen, prgnExposed))
return;
pBackingStore = (miBSWindowPtr)pSrc->backStorage;
if ((pBackingStore->status == StatusNoPixmap) ||
(pBackingStore->status == StatusBadAlloc))
return;
REGION_NULL( pGC->pScreen, &tempRgn);
REGION_INTERSECT( pGC->pScreen, &tempRgn, prgnExposed,
&pBackingStore->SavedRegion);
REGION_SUBTRACT( pGC->pScreen, prgnExposed, prgnExposed, &tempRgn);
if (plane != 0) {
copyProc = pGC->ops->CopyPlane;
} else {
copyProc = (CopyPlaneProcPtr)pGC->ops->CopyArea;
}
dx = dstx - srcx;
dy = dsty - srcy;
switch (pBackingStore->status) {
case StatusVirtual:
case StatusVDirty:
pScratchGC = GetScratchGC (pDst->depth, pDst->pScreen);
if (pScratchGC)
{
gcMask = 0;
if (pGC->alu != pScratchGC->alu)
gcMask = GCFunction;
if (pGC->planemask != pScratchGC->planemask)
gcMask |= GCPlaneMask;
if (gcMask)
CopyGC (pGC, pScratchGC, gcMask);
miBSFillVirtualBits (pDst, pScratchGC, &tempRgn, dx, dy,
(int) pBackingStore->backgroundState,
pBackingStore->background,
~0L);
FreeScratchGC (pScratchGC);
}
break;
case StatusContents:
for (i = REGION_NUM_RECTS(&tempRgn), pBox = REGION_RECTS(&tempRgn);
--i >= 0;
pBox++)
{
(* copyProc) (&(pBackingStore->pBackingPixmap->drawable), pDst, pGC,
pBox->x1 - pBackingStore->x,
pBox->y1 - pBackingStore->y,
pBox->x2 - pBox->x1, pBox->y2 - pBox->y1,
pBox->x1 + dx, pBox->y1 + dy, plane);
}
break;
}
REGION_UNINIT( pGC->pScreen, &tempRgn);
}
|