First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / xaa / xaaWrapper.c
blob6d8107b61c68cbe6a0c2021c9b395773d1537e34
1 #ifdef HAVE_XORG_CONFIG_H
2 #include <xorg-config.h>
3 #endif
5 #include <X11/X.h>
6 #include <X11/Xproto.h>
7 #include "scrnintstr.h"
8 #include "gcstruct.h"
9 #include "glyphstr.h"
10 #include "window.h"
11 #include "windowstr.h"
12 #include "picture.h"
13 #include "picturestr.h"
14 #include "colormapst.h"
15 #include "xaa.h"
16 #include "xaalocal.h"
17 #include "xaaWrapper.h"
19 void XAASync(ScreenPtr pScreen);
21 /* #include "render.h" */
23 #if 1
24 #define COND(pDraw) \
25 ((pDraw)->depth \
26 != (xaaWrapperGetScrPriv(((DrawablePtr)(pDraw))->pScreen))->depth)
27 #else
28 #define COND(pDraw) 1
29 #endif
31 static Bool xaaWrapperCreateGC(GCPtr pGC);
32 static void xaaWrapperValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDraw);
33 static void xaaWrapperDestroyGC(GCPtr pGC);
34 static void xaaWrapperChangeGC (GCPtr pGC, unsigned long mask);
35 static void xaaWrapperCopyGC (GCPtr pGCSrc, unsigned long mask, GCPtr pGCDst);
36 static void xaaWrapperChangeClip (GCPtr pGC, int type, pointer pvalue, int nrects);
38 static void xaaWrapperCopyClip(GCPtr pgcDst, GCPtr pgcSrc);
39 static void xaaWrapperDestroyClip(GCPtr pGC);
42 static void
43 xaaWrapperComposite (CARD8 op, PicturePtr pSrc, PicturePtr pMask, PicturePtr pDst,
44 INT16 xSrc, INT16 ySrc, INT16 xMask, INT16 yMask,
45 INT16 xDst, INT16 yDst, CARD16 width, CARD16 height);
46 static void
47 xaaWrapperGlyphs (CARD8 op, PicturePtr pSrc, PicturePtr pDst,
48 PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc, int nlist,
49 GlyphListPtr list, GlyphPtr *glyphs);
52 typedef struct {
53 CloseScreenProcPtr CloseScreen;
54 CreateScreenResourcesProcPtr CreateScreenResources;
55 CreateWindowProcPtr CreateWindow;
56 CopyWindowProcPtr CopyWindow;
57 PaintWindowProcPtr PaintWindowBackground;
58 PaintWindowProcPtr PaintWindowBorder;
59 WindowExposuresProcPtr WindowExposures;
60 CreateGCProcPtr CreateGC;
61 CreateColormapProcPtr CreateColormap;
62 DestroyColormapProcPtr DestroyColormap;
63 InstallColormapProcPtr InstallColormap;
64 UninstallColormapProcPtr UninstallColormap;
65 ListInstalledColormapsProcPtr ListInstalledColormaps;
66 StoreColorsProcPtr StoreColors;
67 #ifdef RENDER
68 CompositeProcPtr Composite;
69 GlyphsProcPtr Glyphs;
70 #endif
72 CloseScreenProcPtr wrapCloseScreen;
73 CreateScreenResourcesProcPtr wrapCreateScreenResources;
74 CreateWindowProcPtr wrapCreateWindow;
75 CopyWindowProcPtr wrapCopyWindow;
76 PaintWindowProcPtr wrapPaintWindowBackground;
77 PaintWindowProcPtr wrapPaintWindowBorder;
78 WindowExposuresProcPtr wrapWindowExposures;
79 CreateGCProcPtr wrapCreateGC;
80 CreateColormapProcPtr wrapCreateColormap;
81 DestroyColormapProcPtr wrapDestroyColormap;
82 InstallColormapProcPtr wrapInstallColormap;
83 UninstallColormapProcPtr wrapUninstallColormap;
84 ListInstalledColormapsProcPtr wrapListInstalledColormaps;
85 StoreColorsProcPtr wrapStoreColors;
86 #ifdef RENDER
87 CompositeProcPtr wrapComposite;
88 GlyphsProcPtr wrapGlyphs;
89 #endif
90 int depth;
91 } xaaWrapperScrPrivRec, *xaaWrapperScrPrivPtr;
93 #define xaaWrapperGetScrPriv(s) ((xaaWrapperScrPrivPtr)( \
94 (xaaWrapperScrPrivateIndex != -1) \
95 ? (s)->devPrivates[xaaWrapperScrPrivateIndex].ptr\
96 : NULL))
97 #define xaaWrapperScrPriv(s) xaaWrapperScrPrivPtr pScrPriv = xaaWrapperGetScrPriv(s)
99 #define wrap(priv,real,mem,func) {\
100 priv->mem = real->mem; \
101 real->mem = func; \
104 #define unwrap(priv,real,mem) {\
105 real->mem = priv->mem; \
108 #define cond_wrap(priv,cond,real,mem,wrapmem,func) {\
109 if (COND(cond)) \
110 priv->wrapmem = real->mem; \
111 else \
112 priv->mem = real->mem; \
113 real->mem = func; \
116 #define cond_unwrap(priv,cond,real,mem,wrapmem) {\
117 if (COND(cond)) \
118 real->mem = priv->wrapmem; \
119 else \
120 real->mem = priv->mem; \
123 #define get(priv,real,func,wrap) \
124 priv->wrap = real->func;
126 typedef struct _xaaWrapperGCPriv {
127 GCOps *ops;
128 Bool wrap;
129 GCFuncs *funcs;
130 GCOps *wrapops;
131 } xaaWrapperGCPrivRec, *xaaWrapperGCPrivPtr;
133 #define xaaWrapperGetGCPriv(pGC) ((xaaWrapperGCPrivPtr) \
134 (pGC)->devPrivates[xaaWrapperGCPrivateIndex].ptr)
135 #define xaaWrapperGCPriv(pGC) xaaWrapperGCPrivPtr pGCPriv = xaaWrapperGetGCPriv(pGC)
138 static int xaaWrapperScrPrivateIndex = -1;
139 static int xaaWrapperGCPrivateIndex = -1;
140 static int xaaWrapperGeneration = -1;
142 static Bool
143 xaaWrapperCreateScreenResources(ScreenPtr pScreen)
145 xaaWrapperScrPriv(pScreen);
146 Bool ret;
148 unwrap (pScrPriv,pScreen, CreateScreenResources);
149 ret = pScreen->CreateScreenResources(pScreen);
150 wrap(pScrPriv,pScreen,CreateScreenResources,xaaWrapperCreateScreenResources);
151 return ret;
154 static Bool
155 xaaWrapperCloseScreen (int iScreen, ScreenPtr pScreen)
157 xaaWrapperScrPriv(pScreen);
158 Bool ret;
160 unwrap (pScrPriv,pScreen, CloseScreen);
161 ret = pScreen->CloseScreen(iScreen,pScreen);
162 return TRUE;
165 static Bool
166 xaaWrapperCreateWindow(WindowPtr pWin)
168 xaaWrapperScrPriv(pWin->drawable.pScreen);
169 Bool ret;
171 cond_unwrap(pScrPriv, &pWin->drawable, pWin->drawable.pScreen,
172 CreateWindow, wrapCreateWindow);
173 ret = pWin->drawable.pScreen->CreateWindow(pWin);
174 cond_wrap(pScrPriv, &pWin->drawable, pWin->drawable.pScreen, CreateWindow,
175 wrapCreateWindow, xaaWrapperCreateWindow);
177 return ret;
180 static void
181 xaaWrapperCopyWindow(WindowPtr pWin,
182 DDXPointRec ptOldOrg,
183 RegionPtr prgnSrc)
185 ScreenPtr pScreen = pWin->drawable.pScreen;
186 xaaWrapperScrPriv(pScreen);
188 unwrap (pScrPriv, pScreen, CopyWindow);
189 #if 0
190 if (COND(&pWin->drawable))
191 pWin->drawable.pScreen->CopyWindow = pScrPriv->wrapCopyWindow;
192 #endif
193 pScreen->CopyWindow(pWin, ptOldOrg, prgnSrc);
194 wrap(pScrPriv, pScreen, CopyWindow, xaaWrapperCopyWindow);
197 static void
198 xaaWrapperWindowExposures (WindowPtr pWin,
199 RegionPtr prgn,
200 RegionPtr other_exposed)
202 xaaWrapperScrPriv(pWin->drawable.pScreen);
204 cond_unwrap(pScrPriv, &pWin->drawable, pWin->drawable.pScreen,
205 WindowExposures, wrapWindowExposures);
206 pWin->drawable.pScreen->WindowExposures(pWin, prgn, other_exposed);
207 cond_wrap(pScrPriv, &pWin->drawable, pWin->drawable.pScreen,
208 WindowExposures, wrapWindowExposures, xaaWrapperWindowExposures);
211 static void
212 xaaWrapperPaintWindow(WindowPtr pWin, RegionPtr pRegion, int what)
214 xaaWrapperScrPriv(pWin->drawable.pScreen);
216 switch (what) {
217 case PW_BORDER:
218 cond_unwrap(pScrPriv, &pWin->drawable, pWin->drawable.pScreen,
219 PaintWindowBorder, wrapPaintWindowBorder);
221 pWin->drawable.pScreen->PaintWindowBorder (pWin, pRegion, what);
222 cond_wrap(pScrPriv, &pWin->drawable, pWin->drawable.pScreen,
223 PaintWindowBorder, wrapPaintWindowBorder,
224 xaaWrapperPaintWindow);
225 break;
226 case PW_BACKGROUND:
227 cond_unwrap(pScrPriv, &pWin->drawable, pWin->drawable.pScreen,
228 PaintWindowBackground, wrapPaintWindowBackground);
230 pWin->drawable.pScreen->PaintWindowBackground (pWin, pRegion, what);
231 cond_wrap(pScrPriv, &pWin->drawable, pWin->drawable.pScreen,
232 PaintWindowBackground, wrapPaintWindowBackground,
233 xaaWrapperPaintWindow);
234 break;
238 static Bool
239 xaaWrapperCreateColormap(ColormapPtr pmap)
241 xaaWrapperScrPriv(pmap->pScreen);
242 Bool ret;
243 unwrap(pScrPriv,pmap->pScreen, CreateColormap);
244 ret = pmap->pScreen->CreateColormap(pmap);
245 wrap(pScrPriv,pmap->pScreen,CreateColormap,xaaWrapperCreateColormap);
247 return ret;
250 static void
251 xaaWrapperDestroyColormap(ColormapPtr pmap)
253 xaaWrapperScrPriv(pmap->pScreen);
254 unwrap(pScrPriv,pmap->pScreen, DestroyColormap);
255 pmap->pScreen->DestroyColormap(pmap);
256 wrap(pScrPriv,pmap->pScreen,DestroyColormap,xaaWrapperDestroyColormap);
259 static void
260 xaaWrapperStoreColors(ColormapPtr pmap, int nColors, xColorItem *pColors)
262 xaaWrapperScrPriv(pmap->pScreen);
263 unwrap(pScrPriv,pmap->pScreen, StoreColors);
264 pmap->pScreen->StoreColors(pmap,nColors,pColors);
265 wrap(pScrPriv,pmap->pScreen,StoreColors,xaaWrapperStoreColors);
268 static void
269 xaaWrapperInstallColormap(ColormapPtr pmap)
271 xaaWrapperScrPriv(pmap->pScreen);
273 unwrap(pScrPriv,pmap->pScreen, InstallColormap);
274 pmap->pScreen->InstallColormap(pmap);
275 wrap(pScrPriv,pmap->pScreen,InstallColormap,xaaWrapperInstallColormap);
278 static void
279 xaaWrapperUninstallColormap(ColormapPtr pmap)
281 xaaWrapperScrPriv(pmap->pScreen);
283 unwrap(pScrPriv,pmap->pScreen, UninstallColormap);
284 pmap->pScreen->UninstallColormap(pmap);
285 wrap(pScrPriv,pmap->pScreen,UninstallColormap,xaaWrapperUninstallColormap);
288 static int
289 xaaWrapperListInstalledColormaps(ScreenPtr pScreen, Colormap *pCmapIds)
291 int n;
292 xaaWrapperScrPriv(pScreen);
294 unwrap(pScrPriv,pScreen, ListInstalledColormaps);
295 n = pScreen->ListInstalledColormaps(pScreen, pCmapIds);
296 wrap (pScrPriv,pScreen,ListInstalledColormaps,xaaWrapperListInstalledColormaps);
297 return n;
300 Bool
301 xaaSetupWrapper(ScreenPtr pScreen, XAAInfoRecPtr infoPtr, int depth, SyncFunc *func)
303 Bool ret;
304 xaaWrapperScrPrivPtr pScrPriv;
305 #ifdef RENDER
306 PictureScreenPtr ps = GetPictureScreenIfSet(pScreen);
307 #endif
308 if (xaaWrapperGeneration != serverGeneration) {
309 xaaWrapperScrPrivateIndex = AllocateScreenPrivateIndex ();
310 if (xaaWrapperScrPrivateIndex == -1)
311 return FALSE;
312 xaaWrapperGCPrivateIndex = AllocateGCPrivateIndex ();
313 if (xaaWrapperGCPrivateIndex == -1)
314 return FALSE;
315 xaaWrapperGeneration = serverGeneration;
318 if (!AllocateGCPrivate (pScreen, xaaWrapperGCPrivateIndex,
319 sizeof (xaaWrapperGCPrivRec)))
320 return FALSE;
322 pScrPriv = (xaaWrapperScrPrivPtr) xalloc (sizeof (xaaWrapperScrPrivRec));
323 if (!pScrPriv)
324 return FALSE;
326 get (pScrPriv, pScreen, CloseScreen, wrapCloseScreen);
327 get (pScrPriv, pScreen, CreateScreenResources, wrapCreateScreenResources);
328 get (pScrPriv, pScreen, CreateWindow, wrapCreateWindow);
329 get (pScrPriv, pScreen, CopyWindow, wrapCopyWindow);
330 get (pScrPriv, pScreen, PaintWindowBorder, wrapPaintWindowBorder);
331 get (pScrPriv, pScreen, PaintWindowBackground, wrapPaintWindowBackground);
332 get (pScrPriv, pScreen, WindowExposures, wrapWindowExposures);
333 get (pScrPriv, pScreen, CreateGC, wrapCreateGC);
334 get (pScrPriv, pScreen, CreateColormap, wrapCreateColormap);
335 get (pScrPriv, pScreen, DestroyColormap, wrapDestroyColormap);
336 get (pScrPriv, pScreen, InstallColormap, wrapInstallColormap);
337 get (pScrPriv, pScreen, UninstallColormap, wrapUninstallColormap);
338 get (pScrPriv, pScreen, ListInstalledColormaps, wrapListInstalledColormaps);
339 get (pScrPriv, pScreen, StoreColors, wrapStoreColors);
340 #ifdef RENDER
341 if (ps) {
342 get (pScrPriv, ps, Glyphs, wrapGlyphs);
343 get (pScrPriv, ps, Composite, wrapComposite);
345 #endif
346 if (!(ret = XAAInit(pScreen,infoPtr)))
347 return FALSE;
349 wrap (pScrPriv, pScreen, CloseScreen, xaaWrapperCloseScreen);
350 wrap (pScrPriv, pScreen, CreateScreenResources,
351 xaaWrapperCreateScreenResources);
352 wrap (pScrPriv, pScreen, CreateWindow, xaaWrapperCreateWindow);
353 wrap (pScrPriv, pScreen, CopyWindow, xaaWrapperCopyWindow);
354 wrap (pScrPriv, pScreen, PaintWindowBorder, xaaWrapperPaintWindow);
355 wrap (pScrPriv, pScreen, PaintWindowBackground, xaaWrapperPaintWindow);
356 wrap (pScrPriv, pScreen, WindowExposures, xaaWrapperWindowExposures);
357 wrap (pScrPriv, pScreen, CreateGC, xaaWrapperCreateGC);
358 wrap (pScrPriv, pScreen, CreateColormap, xaaWrapperCreateColormap);
359 wrap (pScrPriv, pScreen, DestroyColormap, xaaWrapperDestroyColormap);
360 wrap (pScrPriv, pScreen, InstallColormap, xaaWrapperInstallColormap);
361 wrap (pScrPriv, pScreen, UninstallColormap, xaaWrapperUninstallColormap);
362 wrap (pScrPriv, pScreen, ListInstalledColormaps,
363 xaaWrapperListInstalledColormaps);
364 wrap (pScrPriv, pScreen, StoreColors, xaaWrapperStoreColors);
366 #ifdef RENDER
367 if (ps) {
368 wrap (pScrPriv, ps, Glyphs, xaaWrapperGlyphs);
369 wrap (pScrPriv, ps, Composite, xaaWrapperComposite);
371 #endif
372 pScrPriv->depth = depth;
373 pScreen->devPrivates[xaaWrapperScrPrivateIndex].ptr = (pointer) pScrPriv;
375 *func = XAASync;
377 return ret;
380 GCFuncs xaaWrapperGCFuncs = {
381 xaaWrapperValidateGC, xaaWrapperChangeGC, xaaWrapperCopyGC,
382 xaaWrapperDestroyGC, xaaWrapperChangeClip, xaaWrapperDestroyClip,
383 xaaWrapperCopyClip
386 #define XAAWRAPPER_GC_FUNC_PROLOGUE(pGC) \
387 xaaWrapperGCPriv(pGC); \
388 unwrap(pGCPriv, pGC, funcs); \
389 if (pGCPriv->wrap) unwrap(pGCPriv, pGC, ops)
391 #define XAAWRAPPER_GC_FUNC_EPILOGUE(pGC) \
392 wrap(pGCPriv, pGC, funcs, &xaaWrapperGCFuncs); \
393 if (pGCPriv->wrap) wrap(pGCPriv, pGC, ops, pGCPriv->wrapops)
395 static Bool
396 xaaWrapperCreateGC(GCPtr pGC)
398 ScreenPtr pScreen = pGC->pScreen;
399 xaaWrapperScrPriv(pScreen);
400 xaaWrapperGCPriv(pGC);
401 Bool ret;
403 unwrap (pScrPriv, pScreen, CreateGC);
404 if((ret = (*pScreen->CreateGC) (pGC))) {
405 pGCPriv->wrap = FALSE;
406 pGCPriv->funcs = pGC->funcs;
407 pGCPriv->wrapops = pGC->ops;
408 pGC->funcs = &xaaWrapperGCFuncs;
410 wrap (pScrPriv, pScreen, CreateGC, xaaWrapperCreateGC);
412 return ret;
415 static void
416 xaaWrapperValidateGC(
417 GCPtr pGC,
418 unsigned long changes,
419 DrawablePtr pDraw
421 XAAWRAPPER_GC_FUNC_PROLOGUE (pGC);
422 (*pGC->funcs->ValidateGC)(pGC, changes, pDraw);
424 if(COND(pDraw))
425 pGCPriv->wrap = TRUE;
427 XAAWRAPPER_GC_FUNC_EPILOGUE (pGC);
430 static void
431 xaaWrapperDestroyGC(GCPtr pGC)
433 XAAWRAPPER_GC_FUNC_PROLOGUE (pGC);
434 (*pGC->funcs->DestroyGC)(pGC);
435 XAAWRAPPER_GC_FUNC_EPILOGUE (pGC);
438 static void
439 xaaWrapperChangeGC (
440 GCPtr pGC,
441 unsigned long mask
443 XAAWRAPPER_GC_FUNC_PROLOGUE (pGC);
444 (*pGC->funcs->ChangeGC) (pGC, mask);
445 XAAWRAPPER_GC_FUNC_EPILOGUE (pGC);
448 static void
449 xaaWrapperCopyGC (
450 GCPtr pGCSrc,
451 unsigned long mask,
452 GCPtr pGCDst
454 XAAWRAPPER_GC_FUNC_PROLOGUE (pGCDst);
455 (*pGCDst->funcs->CopyGC) (pGCSrc, mask, pGCDst);
456 XAAWRAPPER_GC_FUNC_EPILOGUE (pGCDst);
459 static void
460 xaaWrapperChangeClip (
461 GCPtr pGC,
462 int type,
463 pointer pvalue,
464 int nrects
466 XAAWRAPPER_GC_FUNC_PROLOGUE (pGC);
467 (*pGC->funcs->ChangeClip) (pGC, type, pvalue, nrects);
468 XAAWRAPPER_GC_FUNC_EPILOGUE (pGC);
471 static void
472 xaaWrapperCopyClip(GCPtr pgcDst, GCPtr pgcSrc)
474 XAAWRAPPER_GC_FUNC_PROLOGUE (pgcDst);
475 (* pgcDst->funcs->CopyClip)(pgcDst, pgcSrc);
476 XAAWRAPPER_GC_FUNC_EPILOGUE (pgcDst);
479 static void
480 xaaWrapperDestroyClip(GCPtr pGC)
482 XAAWRAPPER_GC_FUNC_PROLOGUE (pGC);
483 (* pGC->funcs->DestroyClip)(pGC);
484 XAAWRAPPER_GC_FUNC_EPILOGUE (pGC);
487 #ifdef RENDER
488 static void
489 xaaWrapperComposite (CARD8 op, PicturePtr pSrc, PicturePtr pMask, PicturePtr pDst,
490 INT16 xSrc, INT16 ySrc, INT16 xMask, INT16 yMask,
491 INT16 xDst, INT16 yDst, CARD16 width, CARD16 height)
493 ScreenPtr pScreen = pDst->pDrawable->pScreen;
494 PictureScreenPtr ps = GetPictureScreen(pScreen);
495 xaaWrapperScrPriv(pScreen);
497 unwrap (pScrPriv, ps, Composite);
498 (*ps->Composite) (op, pSrc, pMask, pDst, xSrc, ySrc, xMask, yMask,
499 xDst, yDst, width, height);
500 wrap (pScrPriv, ps, Composite, xaaWrapperComposite);
504 static void
505 xaaWrapperGlyphs (CARD8 op, PicturePtr pSrc, PicturePtr pDst,
506 PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc, int nlist,
507 GlyphListPtr list, GlyphPtr *glyphs)
509 ScreenPtr pScreen = pDst->pDrawable->pScreen;
510 PictureScreenPtr ps = GetPictureScreen(pScreen);
511 xaaWrapperScrPriv(pScreen);
513 unwrap (pScrPriv, ps, Glyphs);
514 (*ps->Glyphs) (op, pSrc, pDst, maskFormat, xSrc, ySrc,
515 nlist, list, glyphs);
516 wrap (pScrPriv, ps, Glyphs, xaaWrapperGlyphs);
519 #endif
521 void
522 XAASync(ScreenPtr pScreen)
524 XAAScreenPtr pScreenPriv =
525 (XAAScreenPtr) pScreen->devPrivates[XAAGetScreenIndex()].ptr;
526 XAAInfoRecPtr infoRec = pScreenPriv->AccelInfoRec;
528 if(infoRec->NeedToSync) {
529 (*infoRec->Sync)(infoRec->pScrn);
530 infoRec->NeedToSync = FALSE;