summaryrefslogtreecommitdiff
path: root/hw/xfree86/xaa/xaaWrapper.c
blob: 3bc2db34fea5cd61e5dcf496cd04bf7846403574 (plain)
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
#include "X.h"
#include "Xproto.h"
#include "scrnintstr.h"
#include "gcstruct.h"
#include "glyphstr.h"
#include "window.h"
#include "windowstr.h"
#include "picture.h"
#include "picturestr.h"
#include "colormapst.h"
#include "xaa.h"
#include "xaalocal.h"
#include "xaaWrapper.h"

void XAASync(ScreenPtr pScreen);

/* #include "render.h" */

#if 0
#define COND(pDraw) \
        ((pDraw)->depth \
                      != (xaaWrapperGetScrPriv(((DrawablePtr)(pDraw))->pScreen))->depth)
#endif
#define COND(pDraw) 1

#if 0
static Bool xaaWrapperPreCreateGC(GCPtr pGC);
#endif
static Bool xaaWrapperCreateGC(GCPtr pGC);
static void xaaWrapperValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDraw);
static void xaaWrapperDestroyGC(GCPtr pGC);
static void xaaWrapperChangeGC (GCPtr pGC, unsigned long   mask);
static void xaaWrapperCopyGC (GCPtr pGCSrc, unsigned long   mask, GCPtr pGCDst);
static void xaaWrapperChangeClip (GCPtr pGC, int type, pointer pvalue, int nrects);

static void xaaWrapperCopyClip(GCPtr pgcDst, GCPtr pgcSrc);
static void xaaWrapperDestroyClip(GCPtr pGC);

#if 0
static void xaaWrapperFillSpans(DrawablePtr pDraw, GC *pGC, int nInit,
			DDXPointPtr pptInit, int *pwidthInit, int fSorted);
static void xaaWrapperSetSpans(DrawablePtr pDraw, GCPtr	pGC, char *pcharsrc,
		       DDXPointPtr pptInit, int	*pwidthInit, int nspans,
		       int fSorted);
static void xaaWrapperPutImage(DrawablePtr pDraw, GCPtr	pGC, int depth, int x, int y,
		       int w, int h,int	leftPad, int format, char *pImage);
static RegionPtr xaaWrapperCopyPlane(DrawablePtr pSrc,
			     DrawablePtr pDst, GCPtr pGC,int srcx, int srcy,
			     int width, int height, int	dstx, int dsty,
			     unsigned long bitPlane);
static void xaaWrapperPolyPoint(DrawablePtr pDraw, GCPtr pGC, int mode, int npt,
			xPoint *pptInit);
static void xaaWrapperPolylines(DrawablePtr pDraw, GCPtr pGC, int mode,
			int npt, DDXPointPtr pptInit);
static void xaaWrapperPolySegment(DrawablePtr pDraw, GCPtr pGC, int nseg,
			  xSegment *pSeg);
static void xaaWrapperPolyRectangle(DrawablePtr  pDraw, GCPtr pGC, int nRects,
			    xRectangle  *pRects);
static void xaaWrapperPolyArc( DrawablePtr pDraw, GCPtr	pGC, int narcs, xArc *parcs);
static void xaaWrapperFillPolygon(DrawablePtr pDraw, GCPtr pGC, int shape,
			  int mode, int count, DDXPointPtr pptInit);
static void xaaWrapperPolyFillRect(DrawablePtr pDraw, GCPtr pGC, int nRectsInit, 
			   xRectangle *pRectsInit);
static RegionPtr xaaWrapperCopyArea(DrawablePtr pSrc, DrawablePtr pDst, GC *pGC,
			    int srcx, int srcy, int width, int height,
			    int dstx, int dsty);
static void xaaWrapperPolyFillArc(DrawablePtr pDraw, GCPtr pGC, int narcs,
			  xArc *parcs);
static int xaaWrapperPolyText8(DrawablePtr pDraw, GCPtr	pGC, int x, int	y, int count,
		       char *chars);
static int xaaWrapperPolyText16(DrawablePtr pDraw, GCPtr pGC, int x, int y,
			int count, unsigned short *chars);
static void xaaWrapperImageText8(DrawablePtr pDraw, GCPtr pGC, int x, 
			 int y, int count, char	*chars);
static void xaaWrapperImageText16(DrawablePtr pDraw, GCPtr pGC, int x, int y,
			  int count, unsigned short *chars);
static void xaaWrapperImageGlyphBlt(DrawablePtr pDraw, GCPtr pGC, int x, int y,
			    unsigned int nglyph, CharInfoPtr *ppci,
			    pointer pglyphBase);
static void xaaWrapperPolyGlyphBlt(DrawablePtr pDraw, GCPtr pGC, int x, int y,
			   unsigned int nglyph, CharInfoPtr *ppci,
			   pointer pglyphBase);
static void xaaWrapperPushPixels(GCPtr pGC, PixmapPtr pBitMap, DrawablePtr pDraw,
			 int	dx, int dy, int xOrg, int yOrg);
#endif
static void
xaaWrapperComposite (CARD8 op, PicturePtr pSrc, PicturePtr pMask, PicturePtr pDst,
	     INT16 xSrc, INT16 ySrc, INT16 xMask, INT16 yMask,
	     INT16 xDst, INT16 yDst, CARD16 width, CARD16 height);
static void
xaaWrapperGlyphs (CARD8 op, PicturePtr pSrc, PicturePtr pDst,
	  PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc, int nlist,
	  GlyphListPtr list, GlyphPtr *glyphs);


typedef struct {
    CloseScreenProcPtr		CloseScreen;
    CreateScreenResourcesProcPtr CreateScreenResources;
    CreateWindowProcPtr		CreateWindow;
    CopyWindowProcPtr		CopyWindow;
    PaintWindowProcPtr		PaintWindowBackground;
    PaintWindowProcPtr		PaintWindowBorder;
    WindowExposuresProcPtr	WindowExposures;
    CreateGCProcPtr		CreateGC;
    CreateColormapProcPtr	CreateColormap;
    DestroyColormapProcPtr	DestroyColormap;
    InstallColormapProcPtr	InstallColormap;
    UninstallColormapProcPtr	UninstallColormap;
    ListInstalledColormapsProcPtr ListInstalledColormaps;
    StoreColorsProcPtr		StoreColors;
#ifdef RENDER
    CompositeProcPtr		Composite;
    GlyphsProcPtr		Glyphs;
#endif    

    CloseScreenProcPtr		wrapCloseScreen;
    CreateScreenResourcesProcPtr wrapCreateScreenResources;
    CreateWindowProcPtr		wrapCreateWindow;
    CopyWindowProcPtr		wrapCopyWindow;
    PaintWindowProcPtr		wrapPaintWindowBackground;
    PaintWindowProcPtr		wrapPaintWindowBorder;
    WindowExposuresProcPtr	wrapWindowExposures;
    CreateGCProcPtr		wrapCreateGC;
    CreateColormapProcPtr	wrapCreateColormap;
    DestroyColormapProcPtr	wrapDestroyColormap;
    InstallColormapProcPtr	wrapInstallColormap;
    UninstallColormapProcPtr	wrapUninstallColormap;
    ListInstalledColormapsProcPtr wrapListInstalledColormaps;
    StoreColorsProcPtr		wrapStoreColors;
#ifdef RENDER
    CompositeProcPtr		wrapComposite;
    GlyphsProcPtr		wrapGlyphs;
#endif    
    int depth;
} xaaWrapperScrPrivRec, *xaaWrapperScrPrivPtr;

#define xaaWrapperGetScrPriv(s)	((xaaWrapperScrPrivPtr)( \
				 (xaaWrapperScrPrivateIndex != -1) \
                          ? (s)->devPrivates[xaaWrapperScrPrivateIndex].ptr\
				: NULL))
#define xaaWrapperScrPriv(s)     xaaWrapperScrPrivPtr pScrPriv = xaaWrapperGetScrPriv(s)

#define wrap(priv,real,mem,func) {\
    priv->mem = real->mem; \
    real->mem = func; \
}

#if 0
#define wrap_pre(priv,real,real_func,mem,func) {\
    priv->mem = real->real_func; \
    real->real_func = func; \
}
#endif

#define get(priv,real,func,wrap) \
    priv->wrap = real->func;

#define unwrap(priv,real,mem) {\
    real->mem = priv->mem; \
}

#if 0
#define unwrap_pre(priv,real,real_func,mem) {\
    real->real_func = priv->mem; \
}
#endif

typedef struct _xaaWrapperGCPriv {
    GCOps   *ops;
    Bool  wrap;
    GCFuncs *funcs;
    GCOps   *wrapops;
} xaaWrapperGCPrivRec, *xaaWrapperGCPrivPtr;

#define xaaWrapperGetGCPriv(pGC) ((xaaWrapperGCPrivPtr) \
				      (pGC)->devPrivates[xaaWrapperGCPrivateIndex].ptr)
#define xaaWrapperGCPriv(pGC)   xaaWrapperGCPrivPtr  pGCPriv = xaaWrapperGetGCPriv(pGC)


static int xaaWrapperScrPrivateIndex = -1;
static int xaaWrapperGCPrivateIndex = -1;
static int xaaWrapperGeneration = -1;

static Bool
xaaWrapperCreateScreenResources(ScreenPtr pScreen)
{
    xaaWrapperScrPriv(pScreen);
    Bool		ret;
    
    unwrap (pScrPriv,pScreen, CreateScreenResources);
    ret = pScreen->CreateScreenResources(pScreen);
    wrap(pScrPriv,pScreen,CreateScreenResources,xaaWrapperCreateScreenResources);
    return ret;
}

static Bool
xaaWrapperCloseScreen (int iScreen, ScreenPtr pScreen)
{
    xaaWrapperScrPriv(pScreen);
    Bool		ret;

    unwrap (pScrPriv,pScreen, CloseScreen);
    ret = pScreen->CloseScreen(iScreen,pScreen);
    return TRUE;
}

static Bool
xaaWrapperCreateWindow(WindowPtr pWin)
{
    xaaWrapperScrPriv(pWin->drawable.pScreen);
    Bool ret;
    
    unwrap (pScrPriv, pWin->drawable.pScreen, CreateWindow);
    if (COND(&pWin->drawable))
	pWin->drawable.pScreen->CreateWindow
	    = pScrPriv->wrapCreateWindow;
    ret = pWin->drawable.pScreen->CreateWindow(pWin);
    wrap(pScrPriv, pWin->drawable.pScreen, CreateWindow, xaaWrapperCreateWindow);

    return ret;
}

static void
xaaWrapperCopyWindow(WindowPtr	pWin,
	     DDXPointRec	ptOldOrg,
	     RegionPtr	prgnSrc)
{
    ScreenPtr		pScreen = pWin->drawable.pScreen;
    xaaWrapperScrPriv(pScreen);
    
    unwrap (pScrPriv, pScreen, CopyWindow);
#if 0
    if (COND(&pWin->drawable))
	pWin->drawable.pScreen->CopyWindow = pScrPriv->wrapCopyWindow;
#endif
    pScreen->CopyWindow(pWin, ptOldOrg, prgnSrc);
    wrap(pScrPriv, pScreen, CopyWindow, xaaWrapperCopyWindow);
}

static void
xaaWrapperWindowExposures (WindowPtr	pWin,
			  RegionPtr	prgn,
			  RegionPtr	other_exposed)
{
    xaaWrapperScrPriv(pWin->drawable.pScreen);

    unwrap (pScrPriv, pWin->drawable.pScreen, WindowExposures);
    if (COND(&pWin->drawable))
	pWin->drawable.pScreen->WindowExposures = pScrPriv->wrapWindowExposures;
    pWin->drawable.pScreen->WindowExposures(pWin, prgn, other_exposed);
    wrap(pScrPriv, pWin->drawable.pScreen, WindowExposures, xaaWrapperWindowExposures);
}

static void
xaaWrapperPaintWindow(WindowPtr pWin, RegionPtr pRegion, int what)
{
    xaaWrapperScrPriv(pWin->drawable.pScreen);

    switch (what) {
	case PW_BORDER:
	    unwrap (pScrPriv, pWin->drawable.pScreen, PaintWindowBorder);
	    if (COND(&pWin->drawable)) {
		pWin->drawable.pScreen->PaintWindowBorder
		    = pScrPriv->wrapPaintWindowBorder;
				XAASync(pWin->drawable.pScreen);
	    }
	    pWin->drawable.pScreen->PaintWindowBorder (pWin, pRegion, what);
	    wrap(pScrPriv, pWin->drawable.pScreen, PaintWindowBorder,
		 xaaWrapperPaintWindow);
	    break;
	case PW_BACKGROUND:
	    unwrap (pScrPriv, pWin->drawable.pScreen, PaintWindowBackground);
	    if (COND(&pWin->drawable)) {
		pWin->drawable.pScreen->PaintWindowBackground
		    = pScrPriv->wrapPaintWindowBackground;
		XAASync(pWin->drawable.pScreen);
	    }
	    pWin->drawable.pScreen->PaintWindowBackground (pWin, pRegion, what);
	    wrap(pScrPriv, pWin->drawable.pScreen, PaintWindowBackground,
		 xaaWrapperPaintWindow);
	    break;
    }

}

static Bool
xaaWrapperCreateColormap(ColormapPtr pmap)
{
    xaaWrapperScrPriv(pmap->pScreen);
    Bool		ret;
    unwrap(pScrPriv,pmap->pScreen, CreateColormap);
    ret = pmap->pScreen->CreateColormap(pmap);
    wrap(pScrPriv,pmap->pScreen,CreateColormap,xaaWrapperCreateColormap);
    
    return ret;
}

static void
xaaWrapperDestroyColormap(ColormapPtr pmap)
{
    xaaWrapperScrPriv(pmap->pScreen);
    unwrap(pScrPriv,pmap->pScreen, DestroyColormap);
    pmap->pScreen->DestroyColormap(pmap);
    wrap(pScrPriv,pmap->pScreen,DestroyColormap,xaaWrapperDestroyColormap);
}

static void
xaaWrapperStoreColors(ColormapPtr pmap, int nColors, xColorItem *pColors)
{
    xaaWrapperScrPriv(pmap->pScreen);
    unwrap(pScrPriv,pmap->pScreen, StoreColors);
    pmap->pScreen->StoreColors(pmap,nColors,pColors);
    wrap(pScrPriv,pmap->pScreen,StoreColors,xaaWrapperStoreColors);
}

static void
xaaWrapperInstallColormap(ColormapPtr pmap)
{
    xaaWrapperScrPriv(pmap->pScreen);
    
    unwrap(pScrPriv,pmap->pScreen, InstallColormap);
    pmap->pScreen->InstallColormap(pmap);
    wrap(pScrPriv,pmap->pScreen,InstallColormap,xaaWrapperInstallColormap);
}

static void
xaaWrapperUninstallColormap(ColormapPtr pmap)
{
    xaaWrapperScrPriv(pmap->pScreen);

    unwrap(pScrPriv,pmap->pScreen, UninstallColormap);
    pmap->pScreen->UninstallColormap(pmap);
    wrap(pScrPriv,pmap->pScreen,UninstallColormap,xaaWrapperUninstallColormap);
}

static int
xaaWrapperListInstalledColormaps(ScreenPtr pScreen, Colormap *pCmapIds)
{
    int			n;
    xaaWrapperScrPriv(pScreen);

    unwrap(pScrPriv,pScreen, ListInstalledColormaps);
    n = pScreen->ListInstalledColormaps(pScreen, pCmapIds);
    wrap (pScrPriv,pScreen,ListInstalledColormaps,xaaWrapperListInstalledColormaps);
    return n;
}

Bool
xaaSetupWrapper(ScreenPtr pScreen, XAAInfoRecPtr infoPtr, int depth, SyncFunc *func)
{
    Bool ret;
    xaaWrapperScrPrivPtr pScrPriv;
#ifdef RENDER
    PictureScreenPtr	ps = GetPictureScreenIfSet(pScreen);
#endif
    if (xaaWrapperGeneration != serverGeneration) {
	xaaWrapperScrPrivateIndex = AllocateScreenPrivateIndex ();
	if (xaaWrapperScrPrivateIndex == -1)
	    return FALSE;
	xaaWrapperGCPrivateIndex = AllocateGCPrivateIndex ();
	if (xaaWrapperGCPrivateIndex == -1)
	    return FALSE;
	xaaWrapperGeneration = serverGeneration;
    }

    if (!AllocateGCPrivate (pScreen, xaaWrapperGCPrivateIndex,
			    sizeof (xaaWrapperGCPrivRec)))
	return FALSE;

    pScrPriv = (xaaWrapperScrPrivPtr) xalloc (sizeof (xaaWrapperScrPrivRec));
    if (!pScrPriv)
	return FALSE;

    get (pScrPriv, pScreen, CloseScreen, wrapCloseScreen);
    get (pScrPriv, pScreen, CreateScreenResources, wrapCreateScreenResources);
    get (pScrPriv, pScreen, CreateWindow, wrapCreateWindow);
    get (pScrPriv, pScreen, CopyWindow, wrapCopyWindow);
    get (pScrPriv, pScreen, PaintWindowBorder, wrapPaintWindowBorder);
    get (pScrPriv, pScreen, PaintWindowBackground, wrapPaintWindowBackground);
    get (pScrPriv, pScreen, WindowExposures, wrapWindowExposures);
#if 0
    wrap_pre (pScrPriv, pScreen, CreateGC, wrapCreateGC, xaaWrapperPreCreateGC);
#else
    get (pScrPriv, pScreen, CreateGC, wrapCreateGC);
#endif
    get (pScrPriv, pScreen, CreateColormap, wrapCreateColormap);
    get (pScrPriv, pScreen, DestroyColormap, wrapDestroyColormap);
    get (pScrPriv, pScreen, InstallColormap, wrapInstallColormap);
    get (pScrPriv, pScreen, UninstallColormap, wrapUninstallColormap);
    get (pScrPriv, pScreen, ListInstalledColormaps, wrapListInstalledColormaps);
    get (pScrPriv, pScreen, StoreColors, wrapStoreColors);
#ifdef RENDER
    if (ps) {
	get (pScrPriv, ps, Glyphs, wrapGlyphs);
	get (pScrPriv, ps, Composite, wrapComposite);
    }
#endif
    if (!(ret = XAAInit(pScreen,infoPtr)))
	return FALSE;
    
    wrap (pScrPriv, pScreen, CloseScreen, xaaWrapperCloseScreen);
    wrap (pScrPriv, pScreen, CreateScreenResources,
	  xaaWrapperCreateScreenResources);
    wrap (pScrPriv, pScreen, CreateWindow, xaaWrapperCreateWindow);
    wrap (pScrPriv, pScreen, CopyWindow, xaaWrapperCopyWindow);
    wrap (pScrPriv, pScreen, PaintWindowBorder, xaaWrapperPaintWindow);
    wrap (pScrPriv, pScreen, PaintWindowBackground, xaaWrapperPaintWindow);
    wrap (pScrPriv, pScreen, WindowExposures, xaaWrapperWindowExposures);
    wrap (pScrPriv, pScreen, CreateGC, xaaWrapperCreateGC);
    wrap (pScrPriv, pScreen, CreateColormap, xaaWrapperCreateColormap);
    wrap (pScrPriv, pScreen, DestroyColormap, xaaWrapperDestroyColormap);
    wrap (pScrPriv, pScreen, InstallColormap, xaaWrapperInstallColormap);
    wrap (pScrPriv, pScreen, UninstallColormap, xaaWrapperUninstallColormap);
    wrap (pScrPriv, pScreen, ListInstalledColormaps,
	  xaaWrapperListInstalledColormaps);
    wrap (pScrPriv, pScreen, StoreColors, xaaWrapperStoreColors);

#ifdef RENDER
    if (ps) {
	wrap (pScrPriv, ps, Glyphs, xaaWrapperGlyphs);
	wrap (pScrPriv, ps, Composite, xaaWrapperComposite);
    }
#endif
    pScrPriv->depth = depth;
    pScreen->devPrivates[xaaWrapperScrPrivateIndex].ptr = (pointer) pScrPriv;

    *func = XAASync;
    
    return ret;
}

GCFuncs xaaWrapperGCFuncs = {
    xaaWrapperValidateGC, xaaWrapperChangeGC, xaaWrapperCopyGC,
    xaaWrapperDestroyGC, xaaWrapperChangeClip, xaaWrapperDestroyClip,
    xaaWrapperCopyClip
};

#if 0
GCOps xaaWrapperGCOps = {
    xaaWrapperFillSpans, xaaWrapperSetSpans, 
    xaaWrapperPutImage, xaaWrapperCopyArea, 
    xaaWrapperCopyPlane, xaaWrapperPolyPoint, 
    xaaWrapperPolylines, xaaWrapperPolySegment, 
    xaaWrapperPolyRectangle, xaaWrapperPolyArc, 
    xaaWrapperFillPolygon, xaaWrapperPolyFillRect, 
    xaaWrapperPolyFillArc, xaaWrapperPolyText8, 
    xaaWrapperPolyText16, xaaWrapperImageText8, 
    xaaWrapperImageText16, xaaWrapperImageGlyphBlt, 
    xaaWrapperPolyGlyphBlt, xaaWrapperPushPixels,
#ifdef NEED_LINEHELPER
    NULL,
#endif
    {NULL}		/* devPrivate */
};
#endif

#define XAAWRAPPER_GC_FUNC_PROLOGUE(pGC) \
    xaaWrapperGCPriv(pGC); \
    unwrap(pGCPriv, pGC, funcs); \
    if (pGCPriv->wrap) unwrap(pGCPriv, pGC, ops)

#define XAAWRAPPER_GC_FUNC_EPILOGUE(pGC) \
    wrap(pGCPriv, pGC, funcs, &xaaWrapperGCFuncs);  \
    if (pGCPriv->wrap) wrap(pGCPriv, pGC, ops, pGCPriv->wrapops)

#if 0
static Bool
xaaWrapperPreCreateGC(GCPtr pGC)
{
    ScreenPtr		pScreen = pGC->pScreen;
    xaaWrapperScrPriv(pScreen);
    xaaWrapperGCPriv(pGC);
    Bool ret;

    unwrap_pre (pScrPriv, pScreen, CreateGC, wrapCreateGC);
    ret = (*pScreen->CreateGC) (pGC);
    wrap_pre (pScrPriv, pScreen, CreateGC, wrapCreateGC, xaaWrapperPreCreateGC);

    return ret;
}
#endif

static Bool
xaaWrapperCreateGC(GCPtr pGC)
{
    ScreenPtr		pScreen = pGC->pScreen;
    xaaWrapperScrPriv(pScreen);
    xaaWrapperGCPriv(pGC);
    Bool ret;

    unwrap (pScrPriv, pScreen, CreateGC);
    if((ret = (*pScreen->CreateGC) (pGC))) {
	pGCPriv->wrap = FALSE;
	pGCPriv->funcs = pGC->funcs;
	pGCPriv->wrapops = pGC->ops;
	pGC->funcs = &xaaWrapperGCFuncs;
    }
    wrap (pScrPriv, pScreen, CreateGC, xaaWrapperCreateGC);

    return ret;
}

static void
xaaWrapperValidateGC(
   GCPtr         pGC,
   unsigned long changes,
   DrawablePtr   pDraw 
){
    XAAWRAPPER_GC_FUNC_PROLOGUE (pGC);
    (*pGC->funcs->ValidateGC)(pGC, changes, pDraw);

    if(COND(pDraw)) 
	pGCPriv->wrap = TRUE;
    
    XAAWRAPPER_GC_FUNC_EPILOGUE (pGC);
}

static void
xaaWrapperDestroyGC(GCPtr pGC)
{
    XAAWRAPPER_GC_FUNC_PROLOGUE (pGC);
    (*pGC->funcs->DestroyGC)(pGC);
    XAAWRAPPER_GC_FUNC_EPILOGUE (pGC);
}

static void
xaaWrapperChangeGC (
    GCPtr	    pGC,
    unsigned long   mask
){
    XAAWRAPPER_GC_FUNC_PROLOGUE (pGC);
    (*pGC->funcs->ChangeGC) (pGC, mask);
    XAAWRAPPER_GC_FUNC_EPILOGUE (pGC);
}

static void
xaaWrapperCopyGC (
    GCPtr	    pGCSrc, 
    unsigned long   mask,
    GCPtr	    pGCDst
){
    XAAWRAPPER_GC_FUNC_PROLOGUE (pGCDst);
    (*pGCDst->funcs->CopyGC) (pGCSrc, mask, pGCDst);
    XAAWRAPPER_GC_FUNC_EPILOGUE (pGCDst);
}

static void
xaaWrapperChangeClip (
    GCPtr   pGC,
    int		type,
    pointer	pvalue,
    int		nrects 
){
    XAAWRAPPER_GC_FUNC_PROLOGUE (pGC);
    (*pGC->funcs->ChangeClip) (pGC, type, pvalue, nrects);
    XAAWRAPPER_GC_FUNC_EPILOGUE (pGC);
}

static void
xaaWrapperCopyClip(GCPtr pgcDst, GCPtr pgcSrc)
{
    XAAWRAPPER_GC_FUNC_PROLOGUE (pgcDst);
    (* pgcDst->funcs->CopyClip)(pgcDst, pgcSrc);
    XAAWRAPPER_GC_FUNC_EPILOGUE (pgcDst);
}

static void
xaaWrapperDestroyClip(GCPtr pGC)
{
    XAAWRAPPER_GC_FUNC_PROLOGUE (pGC);
    (* pGC->funcs->DestroyClip)(pGC);
    XAAWRAPPER_GC_FUNC_EPILOGUE (pGC);
}

#if 0
#define XAAWRAPPER_GC_OP_PROLOGUE(pGC,pDraw) \
/*     xaaWrapperScrPriv(pDraw->pScreen); */\
    xaaWrapperGCPriv(pGC);  \
    GCFuncs *oldFuncs = pGC->funcs; \
    unwrap(pGCPriv, pGC, funcs);  \
    unwrap(pGCPriv, pGC, ops); \
	
#define XAAWRAPPER_GC_OP_EPILOGUE(pGC,pDraw) \
    wrap(pGCPriv, pGC, funcs, oldFuncs); \
    wrap(pGCPriv, pGC, ops, &xaaWrapperGCOps)

static void
xaaWrapperFillSpans(
    DrawablePtr pDraw,
    GC		*pGC,
    int		nInit,	
    DDXPointPtr pptInit,	
    int 	*pwidthInit,		
    int 	fSorted 
){
    XAAWRAPPER_GC_OP_PROLOGUE(pGC, pDraw);
    (*pGC->ops->FillSpans)(pDraw, pGC, nInit, pptInit, pwidthInit, fSorted);
    XAAWRAPPER_GC_OP_EPILOGUE(pGC, pDraw);
}

static void
xaaWrapperSetSpans(
    DrawablePtr		pDraw,
    GCPtr		pGC,
    char		*pcharsrc,
    DDXPointPtr 	pptInit,
    int			*pwidthInit,
    int			nspans,
    int			fSorted 
){
    XAAWRAPPER_GC_OP_PROLOGUE(pGC, pDraw);

    (*pGC->ops->SetSpans)(pDraw, pGC, pcharsrc, pptInit, 
			  pwidthInit, nspans, fSorted);
    XAAWRAPPER_GC_OP_EPILOGUE(pGC, pDraw);
}


static void
xaaWrapperPutImage(
    DrawablePtr pDraw,
    GCPtr	pGC,
    int		depth, 
    int x, int y, int w, int h,
    int		leftPad,
    int		format,
    char 	*pImage 
){
    XAAWRAPPER_GC_OP_PROLOGUE(pGC, pDraw);
    (*pGC->ops->PutImage)(pDraw, pGC, depth, x, y, w, h, 
		leftPad, format, pImage);
    XAAWRAPPER_GC_OP_EPILOGUE(pGC, pDraw);
}

static RegionPtr
xaaWrapperCopyArea(
    DrawablePtr pSrc,
    DrawablePtr pDst,
    GC *pGC,
    int srcx, int srcy,
    int width, int height,
    int dstx, int dsty 
){
    RegionPtr ret;
    XAAWRAPPER_GC_OP_PROLOGUE(pGC, pDst);
    ret = (*pGC->ops->CopyArea)(pSrc, pDst,
            pGC, srcx, srcy, width, height, dstx, dsty);
    XAAWRAPPER_GC_OP_EPILOGUE(pGC, pDst);

    return ret;
}


static RegionPtr
xaaWrapperCopyPlane(
    DrawablePtr	pSrc,
    DrawablePtr	pDst,
    GCPtr pGC,
    int	srcx, int srcy,
    int	width, int height,
    int	dstx, int dsty,
    unsigned long bitPlane 
){
    RegionPtr ret;
    XAAWRAPPER_GC_OP_PROLOGUE(pGC, pDst);
    ret = (*pGC->ops->CopyPlane)(pSrc, pDst,
	       pGC, srcx, srcy, width, height, dstx, dsty, bitPlane);
    XAAWRAPPER_GC_OP_EPILOGUE(pGC, pDst);
    return ret;
}

static void
xaaWrapperPolyPoint(
    DrawablePtr pDraw,
    GCPtr pGC,
    int mode,
    int npt,
    xPoint *pptInit 
){
    XAAWRAPPER_GC_OP_PROLOGUE(pGC, pDraw);
    (*pGC->ops->PolyPoint)(pDraw, pGC, mode, npt, pptInit);
    XAAWRAPPER_GC_OP_EPILOGUE(pGC, pDraw);
}

static void
xaaWrapperPolylines(
    DrawablePtr pDraw,
    GCPtr	pGC,
    int		mode,		
    int		npt,		
    DDXPointPtr pptInit 
){
    XAAWRAPPER_GC_OP_PROLOGUE(pGC, pDraw);
    (*pGC->ops->Polylines)(pDraw, pGC, mode, npt, pptInit);
    XAAWRAPPER_GC_OP_EPILOGUE(pGC, pDraw);
}

static void 
xaaWrapperPolySegment(
    DrawablePtr	pDraw,
    GCPtr	pGC,
    int		nseg,
    xSegment	*pSeg
    ){
    XAAWRAPPER_GC_OP_PROLOGUE(pGC, pDraw);
    (*pGC->ops->PolySegment)(pDraw, pGC, nseg, pSeg);
    XAAWRAPPER_GC_OP_EPILOGUE(pGC, pDraw);
}

static void
xaaWrapperPolyRectangle(
    DrawablePtr  pDraw,
    GCPtr        pGC,
    int	         nRects,
    xRectangle  *pRects 
){
    XAAWRAPPER_GC_OP_PROLOGUE(pGC, pDraw);
    (*pGC->ops->PolyRectangle)(pDraw, pGC, nRects, pRects);
    XAAWRAPPER_GC_OP_EPILOGUE(pGC, pDraw);
}

static void
xaaWrapperPolyArc(
    DrawablePtr	pDraw,
    GCPtr	pGC,
    int		narcs,
    xArc	*parcs 
){
    XAAWRAPPER_GC_OP_PROLOGUE(pGC, pDraw);
    (*pGC->ops->PolyArc)(pDraw, pGC, narcs, parcs);
    XAAWRAPPER_GC_OP_EPILOGUE(pGC, pDraw);
}

static void
xaaWrapperFillPolygon(
    DrawablePtr	pDraw,
    GCPtr	pGC,
    int		shape,
    int		mode,
    int		count,
    DDXPointPtr	pptInit 
){
    XAAWRAPPER_GC_OP_PROLOGUE(pGC, pDraw);
    (*pGC->ops->FillPolygon)(pDraw, pGC, shape, mode, count, pptInit);
    XAAWRAPPER_GC_OP_EPILOGUE(pGC, pDraw);
}

static void 
xaaWrapperPolyFillRect(
    DrawablePtr	pDraw,
    GCPtr	pGC,
    int		nRectsInit, 
    xRectangle	*pRectsInit 
){
    XAAWRAPPER_GC_OP_PROLOGUE(pGC, pDraw);
    (*pGC->ops->PolyFillRect)(pDraw, pGC, nRectsInit, pRectsInit);
    XAAWRAPPER_GC_OP_EPILOGUE(pGC, pDraw);
}

static void
xaaWrapperPolyFillArc(
    DrawablePtr	pDraw,
    GCPtr	pGC,
    int		narcs,
    xArc	*parcs 
){
    XAAWRAPPER_GC_OP_PROLOGUE(pGC, pDraw);
    (*pGC->ops->PolyFillArc)(pDraw, pGC, narcs, parcs);
    XAAWRAPPER_GC_OP_EPILOGUE(pGC, pDraw);
}

static int
xaaWrapperPolyText8(
    DrawablePtr pDraw,
    GCPtr	pGC,
    int		x, 
    int 	y,
    int 	count,
    char	*chars 
){
    int width;
    
    XAAWRAPPER_GC_OP_PROLOGUE(pGC, pDraw);
    width = (*pGC->ops->PolyText8)(pDraw, pGC, x, y, count, chars);
    XAAWRAPPER_GC_OP_EPILOGUE(pGC, pDraw);

    return width;
}

static int
xaaWrapperPolyText16(
    DrawablePtr pDraw,
    GCPtr	pGC,
    int		x,
    int		y,
    int 	count,
    unsigned short *chars 
){
    int width;
    
    XAAWRAPPER_GC_OP_PROLOGUE(pGC, pDraw);
    width = (*pGC->ops->PolyText16)(pDraw, pGC, x, y, count, chars);
    XAAWRAPPER_GC_OP_EPILOGUE(pGC, pDraw);

    return width;
}

static void
xaaWrapperImageText8(
    DrawablePtr pDraw,
    GCPtr	pGC,
    int		x, 
    int		y,
    int 	count,
    char	*chars 
){
    XAAWRAPPER_GC_OP_PROLOGUE(pGC, pDraw);
    (*pGC->ops->ImageText8)(pDraw, pGC, x, y, count, chars);
    XAAWRAPPER_GC_OP_EPILOGUE(pGC, pDraw);
}

static void
xaaWrapperImageText16(
    DrawablePtr pDraw,
    GCPtr	pGC,
    int		x,
    int		y,
    int 	count,
    unsigned short *chars 
){
    XAAWRAPPER_GC_OP_PROLOGUE(pGC, pDraw);
    (*pGC->ops->ImageText16)(pDraw, pGC, x, y, count, chars);
    XAAWRAPPER_GC_OP_EPILOGUE(pGC, pDraw);
}

static void
xaaWrapperImageGlyphBlt(
    DrawablePtr pDraw,
    GCPtr pGC,
    int x, int y,
    unsigned int nglyph,
    CharInfoPtr *ppci,
    pointer pglyphBase 
){
    XAAWRAPPER_GC_OP_PROLOGUE(pGC, pDraw);
    (*pGC->ops->ImageGlyphBlt)(pDraw, pGC, x, y, nglyph, 
					ppci, pglyphBase);
    XAAWRAPPER_GC_OP_EPILOGUE(pGC, pDraw);
}

static void
xaaWrapperPolyGlyphBlt(
    DrawablePtr pDraw,
    GCPtr pGC,
    int x, int y,
    unsigned int nglyph,
    CharInfoPtr *ppci,
    pointer pglyphBase 
){
    XAAWRAPPER_GC_OP_PROLOGUE(pGC, pDraw);
    (*pGC->ops->PolyGlyphBlt)(pDraw, pGC, x, y, nglyph, 
				ppci, pglyphBase);
    XAAWRAPPER_GC_OP_EPILOGUE(pGC, pDraw);
}

static void
xaaWrapperPushPixels(
    GCPtr	pGC,
    PixmapPtr	pBitMap,
    DrawablePtr pDraw,
    int	dx, int dy, int xOrg, int yOrg 
){
    XAAWRAPPER_GC_OP_PROLOGUE(pGC, pDraw);
    (*pGC->ops->PushPixels)(pGC, pBitMap, pDraw, dx, dy, xOrg, yOrg);
    XAAWRAPPER_GC_OP_EPILOGUE(pGC, pDraw);
}
#endif

#ifdef RENDER
static void
xaaWrapperComposite (CARD8 op, PicturePtr pSrc, PicturePtr pMask, PicturePtr pDst,
	     INT16 xSrc, INT16 ySrc, INT16 xMask, INT16 yMask,
    INT16 xDst, INT16 yDst, CARD16 width, CARD16 height)
{
    ScreenPtr		pScreen = pDst->pDrawable->pScreen;
    PictureScreenPtr	ps = GetPictureScreen(pScreen);
    xaaWrapperScrPriv(pScreen);

    unwrap (pScrPriv, ps, Composite);
    (*ps->Composite) (op, pSrc, pMask, pDst, xSrc, ySrc, xMask, yMask,
		      xDst, yDst, width, height);
    wrap (pScrPriv, ps, Composite, xaaWrapperComposite);
}


static void
xaaWrapperGlyphs (CARD8 op, PicturePtr pSrc, PicturePtr pDst,
	  PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc, int nlist,
	  GlyphListPtr list, GlyphPtr *glyphs)
{
    ScreenPtr		pScreen = pDst->pDrawable->pScreen;
    PictureScreenPtr	ps = GetPictureScreen(pScreen);
    xaaWrapperScrPriv(pScreen);

    unwrap (pScrPriv, ps, Glyphs);
    (*ps->Glyphs) (op, pSrc, pDst, maskFormat, xSrc, ySrc,
		   nlist, list, glyphs);
    wrap (pScrPriv, ps, Glyphs, xaaWrapperGlyphs);

}
#endif

void
XAASync(ScreenPtr pScreen)
{
    XAAScreenPtr pScreenPriv = 
	(XAAScreenPtr) pScreen->devPrivates[XAAScreenIndex].ptr;
    XAAInfoRecPtr infoRec = pScreenPriv->AccelInfoRec;

    if(infoRec->NeedToSync) {
        (*infoRec->Sync)(infoRec->pScrn);
        infoRec->NeedToSync = FALSE;
    }
}