First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / xf8_32bpp / xf86overlay.c
blobc5585ca6d04c0fdca5c2d45d0d73e0416f9160a9
2 /*
3 Copyright (C) 1998. The XFree86 Project Inc.
5 Written by Mark Vojkovich (mvojkovi@ucsd.edu)
6 */
8 #ifdef HAVE_XORG_CONFIG_H
9 #include <xorg-config.h>
10 #endif
12 #include "misc.h"
13 #include "xf86.h"
14 #include "xf86_OSproc.h"
16 #include <X11/X.h>
17 #include "scrnintstr.h"
18 #include "regionstr.h"
19 #include "windowstr.h"
20 #include "xf86str.h"
21 #include "migc.h"
22 #include "gcstruct.h"
23 #include "pixmapstr.h"
24 #include "colormapst.h"
25 #include "cfb8_32.h"
27 #define IS_DIRTY 1
28 #define IS_SHARED 2
30 /** Screen Functions **/
32 static Bool OverlayCloseScreen (int, ScreenPtr);
33 static Bool OverlayCreateGC(GCPtr pGC);
34 static Bool OverlayDestroyPixmap(PixmapPtr);
35 static PixmapPtr OverlayCreatePixmap(ScreenPtr, int, int, int);
36 static Bool OverlayChangeWindowAttributes(WindowPtr, unsigned long);
37 static void OverlayPaintWindow(WindowPtr, RegionPtr, int);
39 /** Funcs **/
40 static void OverlayValidateGC(GCPtr, unsigned long, DrawablePtr);
41 static void OverlayChangeGC(GCPtr, unsigned long);
42 static void OverlayCopyGC(GCPtr, unsigned long, GCPtr);
43 static void OverlayDestroyGC(GCPtr);
44 static void OverlayChangeClip(GCPtr, int, pointer, int);
45 static void OverlayDestroyClip(GCPtr);
46 static void OverlayCopyClip(GCPtr, GCPtr);
49 static PixmapPtr OverlayRefreshPixmap(PixmapPtr);
51 static GCFuncs OverlayGCFuncs = {
52 OverlayValidateGC, OverlayChangeGC,
53 OverlayCopyGC, OverlayDestroyGC,
54 OverlayChangeClip, OverlayDestroyClip,
55 OverlayCopyClip
59 /** Pixmap Ops */
60 static void PixmapFillSpans(DrawablePtr, GCPtr, int, DDXPointPtr, int *,
61 int);
62 static void PixmapSetSpans(DrawablePtr, GCPtr, char *, DDXPointPtr,
63 int *, int, int);
64 static void PixmapPutImage(DrawablePtr, GCPtr, int, int, int, int, int,
65 int, int, char *);
66 static void PixmapPushPixels(GCPtr, PixmapPtr, DrawablePtr, int, int,
67 int, int);
68 static RegionPtr PixmapCopyArea(DrawablePtr, DrawablePtr, GCPtr, int, int,
69 int, int, int, int);
70 static RegionPtr PixmapCopyPlane(DrawablePtr, DrawablePtr, GCPtr, int, int,
71 int, int, int, int, unsigned long);
72 static void PixmapPolyPoint(DrawablePtr, GCPtr, int, int, xPoint *);
73 static void PixmapPolylines(DrawablePtr, GCPtr, int, int, DDXPointPtr);
74 static void PixmapPolySegment(DrawablePtr, GCPtr, int, xSegment *);
75 static void PixmapPolyRectangle(DrawablePtr, GCPtr, int, xRectangle *);
76 static void PixmapPolyArc(DrawablePtr, GCPtr, int, xArc *);
77 static void PixmapFillPolygon(DrawablePtr, GCPtr, int, int, int,
78 DDXPointPtr);
79 static void PixmapPolyFillRect(DrawablePtr, GCPtr, int, xRectangle *);
80 static void PixmapPolyFillArc(DrawablePtr, GCPtr, int, xArc *);
81 static int PixmapPolyText8(DrawablePtr, GCPtr, int, int, int, char *);
82 static int PixmapPolyText16(DrawablePtr, GCPtr, int, int, int,
83 unsigned short *);
84 static void PixmapImageText8(DrawablePtr, GCPtr, int, int, int, char *);
85 static void PixmapImageText16(DrawablePtr, GCPtr, int, int, int,
86 unsigned short *);
87 static void PixmapImageGlyphBlt(DrawablePtr, GCPtr, int, int,
88 unsigned int, CharInfoPtr *, pointer);
89 static void PixmapPolyGlyphBlt(DrawablePtr, GCPtr, int, int,
90 unsigned int, CharInfoPtr *, pointer);
92 static GCOps PixmapGCOps = {
93 PixmapFillSpans, PixmapSetSpans,
94 PixmapPutImage, PixmapCopyArea,
95 PixmapCopyPlane, PixmapPolyPoint,
96 PixmapPolylines, PixmapPolySegment,
97 PixmapPolyRectangle, PixmapPolyArc,
98 PixmapFillPolygon, PixmapPolyFillRect,
99 PixmapPolyFillArc, PixmapPolyText8,
100 PixmapPolyText16, PixmapImageText8,
101 PixmapImageText16, PixmapImageGlyphBlt,
102 PixmapPolyGlyphBlt, PixmapPushPixels,
103 {NULL} /* devPrivate */
107 /** Window Ops **/
108 static void WindowFillSpans(DrawablePtr, GCPtr, int, DDXPointPtr, int *,
109 int);
110 static void WindowSetSpans(DrawablePtr, GCPtr, char *, DDXPointPtr,
111 int *, int, int);
112 static void WindowPutImage(DrawablePtr, GCPtr, int, int, int, int, int,
113 int, int, char *);
114 static void WindowPushPixels(GCPtr, PixmapPtr, DrawablePtr, int, int,
115 int, int);
116 static RegionPtr WindowCopyArea(DrawablePtr, DrawablePtr, GCPtr, int, int,
117 int, int, int, int);
118 static RegionPtr WindowCopyPlane(DrawablePtr, DrawablePtr, GCPtr, int, int,
119 int, int, int, int, unsigned long);
120 static void WindowPolyPoint(DrawablePtr, GCPtr, int, int, xPoint *);
121 static void WindowPolylines(DrawablePtr, GCPtr, int, int, DDXPointPtr);
122 static void WindowPolySegment(DrawablePtr, GCPtr, int, xSegment *);
123 static void WindowPolyRectangle(DrawablePtr, GCPtr, int, xRectangle *);
124 static void WindowPolyArc(DrawablePtr, GCPtr, int, xArc *);
125 static void WindowFillPolygon(DrawablePtr, GCPtr, int, int, int,
126 DDXPointPtr);
127 static void WindowPolyFillRect(DrawablePtr, GCPtr, int, xRectangle *);
128 static void WindowPolyFillArc(DrawablePtr, GCPtr, int, xArc *);
129 static int WindowPolyText8(DrawablePtr, GCPtr, int, int, int, char *);
130 static int WindowPolyText16(DrawablePtr, GCPtr, int, int, int,
131 unsigned short *);
132 static void WindowImageText8(DrawablePtr, GCPtr, int, int, int, char *);
133 static void WindowImageText16(DrawablePtr, GCPtr, int, int, int,
134 unsigned short *);
135 static void WindowImageGlyphBlt(DrawablePtr, GCPtr, int, int,
136 unsigned int, CharInfoPtr *, pointer);
137 static void WindowPolyGlyphBlt(DrawablePtr, GCPtr, int, int,
138 unsigned int, CharInfoPtr *, pointer);
140 static GCOps WindowGCOps = {
141 WindowFillSpans, WindowSetSpans,
142 WindowPutImage, WindowCopyArea,
143 WindowCopyPlane, WindowPolyPoint,
144 WindowPolylines, WindowPolySegment,
145 WindowPolyRectangle, WindowPolyArc,
146 WindowFillPolygon, WindowPolyFillRect,
147 WindowPolyFillArc, WindowPolyText8,
148 WindowPolyText16, WindowImageText8,
149 WindowImageText16, WindowImageGlyphBlt,
150 WindowPolyGlyphBlt, WindowPushPixels,
151 {NULL} /* devPrivate */
154 /** privates **/
156 typedef struct {
157 CloseScreenProcPtr CloseScreen;
158 CreateGCProcPtr CreateGC;
159 CreatePixmapProcPtr CreatePixmap;
160 DestroyPixmapProcPtr DestroyPixmap;
161 ChangeWindowAttributesProcPtr ChangeWindowAttributes;
162 PaintWindowBackgroundProcPtr PaintWindowBackground;
163 PaintWindowBorderProcPtr PaintWindowBorder;
164 int LockPrivate;
165 } OverlayScreenRec, *OverlayScreenPtr;
167 typedef struct {
168 GCFuncs *wrapFuncs;
169 GCOps *wrapOps;
170 GCOps *overlayOps;
171 unsigned long fg;
172 unsigned long bg;
173 unsigned long pm;
174 PixmapPtr tile;
175 } OverlayGCRec, *OverlayGCPtr;
177 typedef struct {
178 PixmapPtr pix32;
179 CARD32 dirty;
180 } OverlayPixmapRec, *OverlayPixmapPtr;
183 static int OverlayScreenIndex = -1;
184 static int OverlayGCIndex = -1;
185 static int OverlayPixmapIndex = -1;
186 static unsigned long OverlayGeneration = 0;
188 /** Macros **/
190 #define TILE_EXISTS(pGC) (!(pGC)->tileIsPixel && (pGC)->tile.pixmap)
192 #define OVERLAY_GET_PIXMAP_PRIVATE(pPix) \
193 (OverlayPixmapPtr)((pPix)->devPrivates[OverlayPixmapIndex].ptr)
195 #define OVERLAY_GET_SCREEN_PRIVATE(pScreen) \
196 (OverlayScreenPtr)((pScreen)->devPrivates[OverlayScreenIndex].ptr)
198 #define OVERLAY_GET_GC_PRIVATE(pGC) \
199 (OverlayGCPtr)((pGC)->devPrivates[OverlayGCIndex].ptr)
201 #define OVERLAY_GC_FUNC_PROLOGUE(pGC)\
202 OverlayGCPtr pGCPriv = OVERLAY_GET_GC_PRIVATE(pGC);\
203 (pGC)->funcs = pGCPriv->wrapFuncs;\
204 if(pGCPriv->overlayOps) \
205 (pGC)->ops = pGCPriv->wrapOps
207 #define OVERLAY_GC_FUNC_EPILOGUE(pGC)\
208 pGCPriv->wrapFuncs = (pGC)->funcs;\
209 (pGC)->funcs = &OverlayGCFuncs;\
210 if(pGCPriv->overlayOps) { \
211 pGCPriv->wrapOps = (pGC)->ops;\
212 (pGC)->ops = pGCPriv->overlayOps;\
215 #define WINDOW_GC_OP_PROLOGUE(pGC)\
216 OverlayScreenPtr pScreenPriv = OVERLAY_GET_SCREEN_PRIVATE((pGC)->pScreen);\
217 OverlayGCPtr pGCPriv = OVERLAY_GET_GC_PRIVATE(pGC);\
218 unsigned long oldfg = (pGC)->fgPixel;\
219 unsigned long oldbg = (pGC)->bgPixel;\
220 unsigned long oldpm = (pGC)->planemask;\
221 PixmapPtr oldtile = (pGC)->tile.pixmap;\
222 (pGC)->fgPixel = pGCPriv->fg;\
223 (pGC)->bgPixel = pGCPriv->bg;\
224 (pGC)->planemask = pGCPriv->pm;\
225 if(pGCPriv->tile) (pGC)->tile.pixmap = pGCPriv->tile;\
226 (pGC)->funcs = pGCPriv->wrapFuncs;\
227 (pGC)->ops = pGCPriv->wrapOps;\
228 pScreenPriv->LockPrivate++
231 #define WINDOW_GC_OP_EPILOGUE(pGC)\
232 pGCPriv->wrapOps = (pGC)->ops;\
233 pGCPriv->wrapFuncs = (pGC)->funcs;\
234 (pGC)->fgPixel = oldfg;\
235 (pGC)->bgPixel = oldbg;\
236 (pGC)->planemask = oldpm;\
237 (pGC)->tile.pixmap = oldtile;\
238 (pGC)->funcs = &OverlayGCFuncs;\
239 (pGC)->ops = &WindowGCOps;\
240 pScreenPriv->LockPrivate--
243 #define PIXMAP_GC_OP_PROLOGUE(pGC)\
244 OverlayGCPtr pGCPriv = OVERLAY_GET_GC_PRIVATE(pGC);\
245 OverlayPixmapPtr pPixPriv = OVERLAY_GET_PIXMAP_PRIVATE((PixmapPtr)pDraw);\
246 pGC->funcs = pGCPriv->wrapFuncs;\
247 pGC->ops = pGCPriv->wrapOps
249 #define PIXMAP_GC_OP_EPILOGUE(pGC)\
250 pGCPriv->wrapOps = pGC->ops;\
251 pGC->funcs = &OverlayGCFuncs;\
252 pGC->ops = &PixmapGCOps;\
253 pPixPriv->dirty |= IS_DIRTY
256 Bool
257 xf86Overlay8Plus32Init (ScreenPtr pScreen)
259 OverlayScreenPtr pScreenPriv;
261 if(OverlayGeneration != serverGeneration) {
262 if(((OverlayScreenIndex = AllocateScreenPrivateIndex()) < 0) ||
263 ((OverlayGCIndex = AllocateGCPrivateIndex()) < 0) ||
264 ((OverlayPixmapIndex = AllocatePixmapPrivateIndex()) < 0))
265 return FALSE;
267 OverlayGeneration = serverGeneration;
270 if (!AllocateGCPrivate(pScreen, OverlayGCIndex, sizeof(OverlayGCRec)))
271 return FALSE;
273 if (!AllocatePixmapPrivate(pScreen, OverlayPixmapIndex,
274 sizeof(OverlayPixmapRec)))
275 return FALSE;
277 if (!(pScreenPriv = xalloc(sizeof(OverlayScreenRec))))
278 return FALSE;
280 pScreen->devPrivates[OverlayScreenIndex].ptr = (pointer)pScreenPriv;
282 pScreenPriv->CreateGC = pScreen->CreateGC;
283 pScreenPriv->CloseScreen = pScreen->CloseScreen;
284 pScreenPriv->CreatePixmap = pScreen->CreatePixmap;
285 pScreenPriv->DestroyPixmap = pScreen->DestroyPixmap;
286 pScreenPriv->ChangeWindowAttributes = pScreen->ChangeWindowAttributes;
287 pScreenPriv->PaintWindowBackground = pScreen->PaintWindowBackground;
288 pScreenPriv->PaintWindowBorder = pScreen->PaintWindowBorder;
290 pScreen->CreateGC = OverlayCreateGC;
291 pScreen->CloseScreen = OverlayCloseScreen;
292 pScreen->CreatePixmap = OverlayCreatePixmap;
293 pScreen->DestroyPixmap = OverlayDestroyPixmap;
294 pScreen->ChangeWindowAttributes = OverlayChangeWindowAttributes;
295 pScreen->PaintWindowBackground = OverlayPaintWindow;
296 pScreen->PaintWindowBorder = OverlayPaintWindow;
298 pScreenPriv->LockPrivate = 0;
300 /* allocate the key in the default map */
301 if(pScreen->defColormap) {
302 ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
303 ColormapPtr pmap;
304 xColorItem color;
306 pmap = (ColormapPtr)LookupIDByType(pScreen->defColormap, RT_COLORMAP);
308 pmap->red[pScrn->colorKey].refcnt = AllocPrivate;
309 pmap->red[pScrn->colorKey].fShared = FALSE;
310 pmap->freeRed--;
312 color.red = color.blue = color.green = 0;
313 color.pixel = pScrn->colorKey;
314 color.flags = DoRed | DoGreen | DoBlue;
316 StoreColors(pmap, 1, &color);
319 return TRUE;
323 /*********************** Screen Funcs ***********************/
325 Bool
326 OverlayCreateGC(GCPtr pGC)
328 ScreenPtr pScreen = pGC->pScreen;
329 OverlayGCPtr pGCPriv = OVERLAY_GET_GC_PRIVATE(pGC);
330 OverlayScreenPtr pScreenPriv = OVERLAY_GET_SCREEN_PRIVATE(pScreen);
331 Bool ret;
333 pScreen->CreateGC = pScreenPriv->CreateGC;
335 if((ret = (*pScreen->CreateGC)(pGC)) && (pGC->depth != 1)) {
336 pGCPriv->wrapFuncs = pGC->funcs;
337 pGC->funcs = &OverlayGCFuncs;
338 pGCPriv->wrapOps = NULL;
339 pGCPriv->overlayOps = NULL;
340 pGCPriv->tile = NULL;
343 pScreen->CreateGC = OverlayCreateGC;
345 return ret;
348 static PixmapPtr
349 OverlayCreatePixmap(ScreenPtr pScreen, int w, int h, int depth)
351 OverlayScreenPtr pScreenPriv = OVERLAY_GET_SCREEN_PRIVATE(pScreen);
352 PixmapPtr pPix;
354 pScreen->CreatePixmap = pScreenPriv->CreatePixmap;
355 pPix = (*pScreen->CreatePixmap) (pScreen, w, h, depth);
356 pScreen->CreatePixmap = OverlayCreatePixmap;
358 /* We initialize all the privates */
359 if(pPix) {
360 OverlayPixmapPtr pPriv = OVERLAY_GET_PIXMAP_PRIVATE(pPix);
361 pPriv->pix32 = NULL;
362 pPriv->dirty = IS_DIRTY;
363 if(!w || !h)
364 pPriv->dirty |= IS_SHARED;
367 return pPix;
370 static Bool
371 OverlayDestroyPixmap(PixmapPtr pPix)
373 ScreenPtr pScreen = pPix->drawable.pScreen;
374 OverlayScreenPtr pScreenPriv = OVERLAY_GET_SCREEN_PRIVATE(pScreen);
375 Bool result;
377 pScreen->DestroyPixmap = pScreenPriv->DestroyPixmap;
379 if((pPix->refcnt == 1) && (pPix->drawable.bitsPerPixel == 8)) {
380 OverlayPixmapPtr pPriv = OVERLAY_GET_PIXMAP_PRIVATE(pPix);
381 if(pPriv->pix32) {
382 if(pPriv->pix32->refcnt != 1)
383 ErrorF("Warning! private pix refcnt = %i\n", pPriv->pix32->refcnt);
384 (*pScreen->DestroyPixmap)(pPriv->pix32);
386 pPriv->pix32 = NULL;
389 result = (*pScreen->DestroyPixmap) (pPix);
390 pScreen->DestroyPixmap = OverlayDestroyPixmap;
392 return result;
395 static Bool
396 OverlayCloseScreen (int i, ScreenPtr pScreen)
398 OverlayScreenPtr pScreenPriv = OVERLAY_GET_SCREEN_PRIVATE(pScreen);
400 pScreen->CreateGC = pScreenPriv->CreateGC;
401 pScreen->CloseScreen = pScreenPriv->CloseScreen;
402 pScreen->CreatePixmap = pScreenPriv->CreatePixmap;
403 pScreen->DestroyPixmap = pScreenPriv->DestroyPixmap;
404 pScreen->ChangeWindowAttributes = pScreenPriv->ChangeWindowAttributes;
405 pScreen->PaintWindowBackground = pScreenPriv->PaintWindowBackground;
406 pScreen->PaintWindowBorder = pScreenPriv->PaintWindowBorder;
408 xfree ((pointer) pScreenPriv);
410 return (*pScreen->CloseScreen) (i, pScreen);
415 static Bool
416 OverlayChangeWindowAttributes (WindowPtr pWin, unsigned long mask)
418 ScreenPtr pScreen = pWin->drawable.pScreen;
419 OverlayScreenPtr pScreenPriv = OVERLAY_GET_SCREEN_PRIVATE(pScreen);
420 Bool result;
422 if(pWin->drawable.depth == 8) {
423 if((mask & CWBackPixmap) &&
424 (pWin->backgroundState == BackgroundPixmap))
425 OverlayRefreshPixmap(pWin->background.pixmap);
427 if((mask & CWBorderPixmap) && !pWin->borderIsPixel)
428 OverlayRefreshPixmap(pWin->border.pixmap);
431 pScreen->ChangeWindowAttributes = pScreenPriv->ChangeWindowAttributes;
432 result = (*pScreen->ChangeWindowAttributes) (pWin, mask);
433 pScreen->ChangeWindowAttributes = OverlayChangeWindowAttributes;
435 return result;
438 static void
439 OverlayPaintWindow(
440 WindowPtr pWin,
441 RegionPtr pReg,
442 int what
444 ScreenPtr pScreen = pWin->drawable.pScreen;
445 OverlayScreenPtr pScreenPriv = OVERLAY_GET_SCREEN_PRIVATE(pScreen);
446 OverlayPixmapPtr pixPriv;
447 PixmapPtr oldPix = NULL;
449 if(what == PW_BACKGROUND) {
450 if(pWin->drawable.depth == 8) {
451 if(pWin->backgroundState == ParentRelative) {
452 do {
453 pWin = pWin->parent;
454 } while (pWin->backgroundState == ParentRelative);
457 if(pWin->backgroundState == BackgroundPixmap) {
458 oldPix = pWin->background.pixmap;
459 pixPriv = OVERLAY_GET_PIXMAP_PRIVATE(oldPix);
460 /* have to do this here because alot of applications
461 incorrectly assume changes to a pixmap that is
462 a window background go into effect immediatedly */
463 if(pixPriv->dirty & IS_DIRTY)
464 OverlayRefreshPixmap(pWin->background.pixmap);
465 pWin->background.pixmap = pixPriv->pix32;
469 pScreen->PaintWindowBackground = pScreenPriv->PaintWindowBackground;
470 (*pScreen->PaintWindowBackground) (pWin, pReg, what);
471 pScreen->PaintWindowBackground = OverlayPaintWindow;
473 if(oldPix)
474 pWin->background.pixmap = oldPix;
475 } else {
476 if((pWin->drawable.depth == 8) && !pWin->borderIsPixel) {
477 oldPix = pWin->border.pixmap;
478 pixPriv = OVERLAY_GET_PIXMAP_PRIVATE(oldPix);
479 if(pixPriv->dirty & IS_DIRTY)
480 OverlayRefreshPixmap(pWin->border.pixmap);
481 pWin->border.pixmap = pixPriv->pix32;
484 pScreen->PaintWindowBorder = pScreenPriv->PaintWindowBorder;
485 (*pScreen->PaintWindowBorder) (pWin, pReg, what);
486 pScreen->PaintWindowBorder = OverlayPaintWindow;
488 if(oldPix)
489 pWin->border.pixmap = oldPix;
494 /*********************** GC Funcs *****************************/
497 static PixmapPtr
498 OverlayRefreshPixmap(PixmapPtr pix8)
500 OverlayPixmapPtr pixPriv = OVERLAY_GET_PIXMAP_PRIVATE(pix8);
501 ScreenPtr pScreen = pix8->drawable.pScreen;
503 if(!pixPriv->pix32) {
504 PixmapPtr newPix;
506 newPix = (*pScreen->CreatePixmap)(pScreen, pix8->drawable.width,
507 pix8->drawable.height, 24);
508 newPix->drawable.depth = 8; /* Bad Mark! Bad Mark! */
509 pixPriv->pix32 = newPix;
512 if(pixPriv->dirty) {
513 OverlayScreenPtr pScreenPriv = OVERLAY_GET_SCREEN_PRIVATE(pScreen);
514 GCPtr pGC;
516 pGC = GetScratchGC(8, pScreen);
518 pScreenPriv->LockPrivate++; /* don't modify this one */
519 ValidateGC((DrawablePtr)pixPriv->pix32, pGC);
521 (*pGC->ops->CopyArea)((DrawablePtr)pix8, (DrawablePtr)pixPriv->pix32,
522 pGC, 0, 0, pix8->drawable.width, pix8->drawable.height, 0, 0);
523 pScreenPriv->LockPrivate--;
524 FreeScratchGC(pGC);
526 pixPriv->dirty &= ~IS_DIRTY;
527 pixPriv->pix32->drawable.serialNumber = NEXT_SERIAL_NUMBER;
530 return pixPriv->pix32;
534 static void
535 OverlayValidateGC(
536 GCPtr pGC,
537 unsigned long changes,
538 DrawablePtr pDraw
540 OverlayScreenPtr pScreenPriv = OVERLAY_GET_SCREEN_PRIVATE(pGC->pScreen);
541 OVERLAY_GC_FUNC_PROLOGUE (pGC);
543 if(pScreenPriv->LockPrivate < 0) {
544 ErrorF("Something is wrong in OverlayValidateGC!\n");
545 pScreenPriv->LockPrivate = 0;
548 if(pGC->depth == 24) {
549 unsigned long oldpm = pGC->planemask;
550 pGCPriv->overlayOps = NULL;
552 if(pDraw->type == DRAWABLE_WINDOW)
553 pGC->planemask &= 0x00ffffff;
554 else
555 pGC->planemask |= 0xff000000;
557 if(oldpm != pGC->planemask) changes |= GCPlaneMask;
559 (*pGC->funcs->ValidateGC)(pGC, changes, pDraw);
561 } else { /* depth == 8 */
562 unsigned long newChanges = 0;
564 if(pDraw->bitsPerPixel == 32) {
566 if(pGC->fillStyle == FillTiled)
567 pGCPriv->tile = OverlayRefreshPixmap(pGC->tile.pixmap);
568 else pGCPriv->tile = NULL;
570 if(pGCPriv->overlayOps != &WindowGCOps) {
571 newChanges = GCForeground | GCBackground | GCPlaneMask;
572 if(pGCPriv->tile)
573 newChanges |= GCTile;
575 pGCPriv->overlayOps = &WindowGCOps;
577 if(!pScreenPriv->LockPrivate) {
578 unsigned long oldfg = pGC->fgPixel;
579 unsigned long oldbg = pGC->bgPixel;
580 unsigned long oldpm = pGC->planemask;
581 PixmapPtr oldtile = pGC->tile.pixmap;
583 pGC->fgPixel = pGCPriv->fg = oldfg << 24;
584 pGC->bgPixel = pGCPriv->bg = oldbg << 24;
585 pGC->planemask = pGCPriv->pm = oldpm << 24;
586 if(pGCPriv->tile)
587 pGC->tile.pixmap = pGCPriv->tile;
589 (*pGC->funcs->ValidateGC)(pGC, changes | newChanges, pDraw);
591 pGC->fgPixel = oldfg;
592 pGC->bgPixel = oldbg;
593 pGC->planemask = oldpm;
594 pGC->tile.pixmap = oldtile;
595 } else {
596 pGCPriv->fg = pGC->fgPixel;
597 pGCPriv->bg = pGC->bgPixel;
598 pGCPriv->pm = pGC->planemask;
600 (*pGC->funcs->ValidateGC)(pGC, changes | newChanges, pDraw);
603 } else { /* bitsPerPixel == 8 */
604 if(pGCPriv->overlayOps == &WindowGCOps) {
605 newChanges = GCForeground | GCBackground | GCPlaneMask;
606 if(pGCPriv->tile)
607 newChanges |= GCTile;
609 pGCPriv->overlayOps = &PixmapGCOps;
611 (*pGC->funcs->ValidateGC)(pGC, changes | newChanges, pDraw);
615 OVERLAY_GC_FUNC_EPILOGUE (pGC);
619 static void
620 OverlayDestroyGC(GCPtr pGC)
622 OVERLAY_GC_FUNC_PROLOGUE (pGC);
623 (*pGC->funcs->DestroyGC)(pGC);
624 OVERLAY_GC_FUNC_EPILOGUE (pGC);
627 static void
628 OverlayChangeGC (
629 GCPtr pGC,
630 unsigned long mask
632 OVERLAY_GC_FUNC_PROLOGUE (pGC);
633 (*pGC->funcs->ChangeGC) (pGC, mask);
634 OVERLAY_GC_FUNC_EPILOGUE (pGC);
637 static void
638 OverlayCopyGC (
639 GCPtr pGCSrc,
640 unsigned long mask,
641 GCPtr pGCDst
643 OVERLAY_GC_FUNC_PROLOGUE (pGCDst);
644 (*pGCDst->funcs->CopyGC) (pGCSrc, mask, pGCDst);
645 OVERLAY_GC_FUNC_EPILOGUE (pGCDst);
647 static void
648 OverlayChangeClip (
649 GCPtr pGC,
650 int type,
651 pointer pvalue,
652 int nrects
654 OVERLAY_GC_FUNC_PROLOGUE (pGC);
655 (*pGC->funcs->ChangeClip) (pGC, type, pvalue, nrects);
656 OVERLAY_GC_FUNC_EPILOGUE (pGC);
659 static void
660 OverlayCopyClip(GCPtr pgcDst, GCPtr pgcSrc)
662 OVERLAY_GC_FUNC_PROLOGUE (pgcDst);
663 (* pgcDst->funcs->CopyClip)(pgcDst, pgcSrc);
664 OVERLAY_GC_FUNC_EPILOGUE (pgcDst);
667 static void
668 OverlayDestroyClip(GCPtr pGC)
670 OVERLAY_GC_FUNC_PROLOGUE (pGC);
671 (* pGC->funcs->DestroyClip)(pGC);
672 OVERLAY_GC_FUNC_EPILOGUE (pGC);
677 /******************* Window GC ops ***********************/
679 static void
680 WindowFillSpans(
681 DrawablePtr pDraw,
682 GC *pGC,
683 int nInit,
684 DDXPointPtr pptInit,
685 int *pwidthInit,
686 int fSorted
688 WINDOW_GC_OP_PROLOGUE(pGC);
689 (*pGC->ops->FillSpans)(pDraw, pGC, nInit, pptInit, pwidthInit, fSorted);
690 WINDOW_GC_OP_EPILOGUE(pGC);
693 static void
694 WindowSetSpans(
695 DrawablePtr pDraw,
696 GCPtr pGC,
697 char *pcharsrc,
698 register DDXPointPtr ppt,
699 int *pwidth,
700 int nspans,
701 int fSorted
703 WINDOW_GC_OP_PROLOGUE(pGC);
704 (*pGC->ops->SetSpans)(pDraw, pGC, pcharsrc, ppt, pwidth, nspans, fSorted);
705 WINDOW_GC_OP_EPILOGUE(pGC);
708 static void
709 WindowPutImage(
710 DrawablePtr pDraw,
711 GCPtr pGC,
712 int depth,
713 int x, int y, int w, int h,
714 int leftPad,
715 int format,
716 char *pImage
718 WINDOW_GC_OP_PROLOGUE(pGC);
719 (*pGC->ops->PutImage)(pDraw, pGC, depth, x, y, w, h,
720 leftPad, format, pImage);
721 WINDOW_GC_OP_EPILOGUE(pGC);
724 static RegionPtr
725 WindowCopyArea(
726 DrawablePtr pSrc,
727 DrawablePtr pDst,
728 GC *pGC,
729 int srcx, int srcy,
730 int width, int height,
731 int dstx, int dsty
733 RegionPtr ret;
735 WINDOW_GC_OP_PROLOGUE(pGC);
736 ret = (*pGC->ops->CopyArea)(pSrc, pDst,
737 pGC, srcx, srcy, width, height, dstx, dsty);
738 WINDOW_GC_OP_EPILOGUE(pGC);
739 return ret;
742 static RegionPtr
743 WindowCopyPlane(
744 DrawablePtr pSrc,
745 DrawablePtr pDst,
746 GCPtr pGC,
747 int srcx, int srcy,
748 int width, int height,
749 int dstx, int dsty,
750 unsigned long bitPlane
752 RegionPtr ret;
754 WINDOW_GC_OP_PROLOGUE(pGC);
755 ret = (*pGC->ops->CopyPlane)(pSrc, pDst,
756 pGC, srcx, srcy, width, height, dstx, dsty, bitPlane);
757 WINDOW_GC_OP_EPILOGUE(pGC);
758 return ret;
761 static void
762 WindowPolyPoint(
763 DrawablePtr pDraw,
764 GCPtr pGC,
765 int mode,
766 int npt,
767 xPoint *pptInit
769 WINDOW_GC_OP_PROLOGUE(pGC);
770 (*pGC->ops->PolyPoint)(pDraw, pGC, mode, npt, pptInit);
771 WINDOW_GC_OP_EPILOGUE(pGC);
774 static void
775 WindowPolylines(
776 DrawablePtr pDraw,
777 GCPtr pGC,
778 int mode,
779 int npt,
780 DDXPointPtr pptInit
782 WINDOW_GC_OP_PROLOGUE(pGC);
783 (*pGC->ops->Polylines)(pDraw, pGC, mode, npt, pptInit);
784 WINDOW_GC_OP_EPILOGUE(pGC);
787 static void
788 WindowPolySegment(
789 DrawablePtr pDraw,
790 GCPtr pGC,
791 int nseg,
792 xSegment *pSeg
794 WINDOW_GC_OP_PROLOGUE(pGC);
795 (*pGC->ops->PolySegment)(pDraw, pGC, nseg, pSeg);
796 WINDOW_GC_OP_EPILOGUE(pGC);
799 static void
800 WindowPolyRectangle(
801 DrawablePtr pDraw,
802 GCPtr pGC,
803 int nRectsInit,
804 xRectangle *pRectsInit
806 WINDOW_GC_OP_PROLOGUE(pGC);
807 (*pGC->ops->PolyRectangle)(pDraw, pGC, nRectsInit, pRectsInit);
808 WINDOW_GC_OP_EPILOGUE(pGC);
811 static void
812 WindowPolyArc(
813 DrawablePtr pDraw,
814 GCPtr pGC,
815 int narcs,
816 xArc *parcs
818 WINDOW_GC_OP_PROLOGUE(pGC);
819 (*pGC->ops->PolyArc)(pDraw, pGC, narcs, parcs);
820 WINDOW_GC_OP_EPILOGUE(pGC);
823 static void
824 WindowFillPolygon(
825 DrawablePtr pDraw,
826 GCPtr pGC,
827 int shape,
828 int mode,
829 int count,
830 DDXPointPtr ptsIn
832 WINDOW_GC_OP_PROLOGUE(pGC);
833 (*pGC->ops->FillPolygon)(pDraw, pGC, shape, mode, count, ptsIn);
834 WINDOW_GC_OP_EPILOGUE(pGC);
837 static void
838 WindowPolyFillRect(
839 DrawablePtr pDraw,
840 GCPtr pGC,
841 int nrectFill,
842 xRectangle *prectInit
844 WINDOW_GC_OP_PROLOGUE(pGC);
845 (*pGC->ops->PolyFillRect)(pDraw, pGC, nrectFill, prectInit);
846 WINDOW_GC_OP_EPILOGUE(pGC);
849 static void
850 WindowPolyFillArc(
851 DrawablePtr pDraw,
852 GCPtr pGC,
853 int narcs,
854 xArc *parcs
856 WINDOW_GC_OP_PROLOGUE(pGC);
857 (*pGC->ops->PolyFillArc)(pDraw, pGC, narcs, parcs);
858 WINDOW_GC_OP_EPILOGUE(pGC);
861 static int
862 WindowPolyText8(
863 DrawablePtr pDraw,
864 GCPtr pGC,
865 int x,
866 int y,
867 int count,
868 char *chars
870 int ret;
872 WINDOW_GC_OP_PROLOGUE(pGC);
873 ret = (*pGC->ops->PolyText8)(pDraw, pGC, x, y, count, chars);
874 WINDOW_GC_OP_EPILOGUE(pGC);
875 return ret;
878 static int
879 WindowPolyText16(
880 DrawablePtr pDraw,
881 GCPtr pGC,
882 int x,
883 int y,
884 int count,
885 unsigned short *chars
887 int ret;
889 WINDOW_GC_OP_PROLOGUE(pGC);
890 ret = (*pGC->ops->PolyText16)(pDraw, pGC, x, y, count, chars);
891 WINDOW_GC_OP_EPILOGUE(pGC);
892 return ret;
895 static void
896 WindowImageText8(
897 DrawablePtr pDraw,
898 GCPtr pGC,
899 int x,
900 int y,
901 int count,
902 char *chars
904 WINDOW_GC_OP_PROLOGUE(pGC);
905 (*pGC->ops->ImageText8)(pDraw, pGC, x, y, count, chars);
906 WINDOW_GC_OP_EPILOGUE(pGC);
909 static void
910 WindowImageText16(
911 DrawablePtr pDraw,
912 GCPtr pGC,
913 int x,
914 int y,
915 int count,
916 unsigned short *chars
918 WINDOW_GC_OP_PROLOGUE(pGC);
919 (*pGC->ops->ImageText16)(pDraw, pGC, x, y, count, chars);
920 WINDOW_GC_OP_EPILOGUE(pGC);
923 static void
924 WindowImageGlyphBlt(
925 DrawablePtr pDraw,
926 GCPtr pGC,
927 int xInit, int yInit,
928 unsigned int nglyph,
929 CharInfoPtr *ppci,
930 pointer pglyphBase
932 WINDOW_GC_OP_PROLOGUE(pGC);
933 (*pGC->ops->ImageGlyphBlt)(pDraw, pGC, xInit, yInit, nglyph,
934 ppci, pglyphBase);
935 WINDOW_GC_OP_EPILOGUE(pGC);
938 static void
939 WindowPolyGlyphBlt(
940 DrawablePtr pDraw,
941 GCPtr pGC,
942 int xInit, int yInit,
943 unsigned int nglyph,
944 CharInfoPtr *ppci,
945 pointer pglyphBase
947 WINDOW_GC_OP_PROLOGUE(pGC);
948 (*pGC->ops->PolyGlyphBlt)(pDraw, pGC, xInit, yInit, nglyph,
949 ppci, pglyphBase);
950 WINDOW_GC_OP_EPILOGUE(pGC);
953 static void
954 WindowPushPixels(
955 GCPtr pGC,
956 PixmapPtr pBitMap,
957 DrawablePtr pDraw,
958 int dx, int dy, int xOrg, int yOrg
960 WINDOW_GC_OP_PROLOGUE(pGC);
961 (*pGC->ops->PushPixels)(pGC, pBitMap, pDraw, dx, dy, xOrg, yOrg);
962 WINDOW_GC_OP_EPILOGUE(pGC);
966 /******************* Pixmap GC ops ***********************/
968 static void
969 PixmapFillSpans(
970 DrawablePtr pDraw,
971 GC *pGC,
972 int nInit,
973 DDXPointPtr pptInit,
974 int *pwidthInit,
975 int fSorted
977 PIXMAP_GC_OP_PROLOGUE(pGC);
978 (*pGC->ops->FillSpans)(pDraw, pGC, nInit, pptInit, pwidthInit, fSorted);
979 PIXMAP_GC_OP_EPILOGUE(pGC);
982 static void
983 PixmapSetSpans(
984 DrawablePtr pDraw,
985 GCPtr pGC,
986 char *pcharsrc,
987 register DDXPointPtr ppt,
988 int *pwidth,
989 int nspans,
990 int fSorted
992 PIXMAP_GC_OP_PROLOGUE(pGC);
993 (*pGC->ops->SetSpans)(pDraw, pGC, pcharsrc, ppt, pwidth, nspans, fSorted);
994 PIXMAP_GC_OP_EPILOGUE(pGC);
997 static void
998 PixmapPutImage(
999 DrawablePtr pDraw,
1000 GCPtr pGC,
1001 int depth,
1002 int x, int y, int w, int h,
1003 int leftPad,
1004 int format,
1005 char *pImage
1007 PIXMAP_GC_OP_PROLOGUE(pGC);
1008 (*pGC->ops->PutImage)(pDraw, pGC, depth, x, y, w, h,
1009 leftPad, format, pImage);
1010 PIXMAP_GC_OP_EPILOGUE(pGC);
1013 static RegionPtr
1014 PixmapCopyArea(
1015 DrawablePtr pSrc,
1016 DrawablePtr pDraw,
1017 GC *pGC,
1018 int srcx, int srcy,
1019 int width, int height,
1020 int dstx, int dsty
1022 RegionPtr ret;
1024 PIXMAP_GC_OP_PROLOGUE(pGC);
1025 ret = (*pGC->ops->CopyArea)(pSrc, pDraw,
1026 pGC, srcx, srcy, width, height, dstx, dsty);
1027 PIXMAP_GC_OP_EPILOGUE(pGC);
1028 return ret;
1031 static RegionPtr
1032 PixmapCopyPlane(
1033 DrawablePtr pSrc,
1034 DrawablePtr pDraw,
1035 GCPtr pGC,
1036 int srcx, int srcy,
1037 int width, int height,
1038 int dstx, int dsty,
1039 unsigned long bitPlane
1041 RegionPtr ret;
1043 PIXMAP_GC_OP_PROLOGUE(pGC);
1044 ret = (*pGC->ops->CopyPlane)(pSrc, pDraw,
1045 pGC, srcx, srcy, width, height, dstx, dsty, bitPlane);
1046 PIXMAP_GC_OP_EPILOGUE(pGC);
1047 return ret;
1050 static void
1051 PixmapPolyPoint(
1052 DrawablePtr pDraw,
1053 GCPtr pGC,
1054 int mode,
1055 int npt,
1056 xPoint *pptInit
1058 PIXMAP_GC_OP_PROLOGUE(pGC);
1059 (*pGC->ops->PolyPoint)(pDraw, pGC, mode, npt, pptInit);
1060 PIXMAP_GC_OP_EPILOGUE(pGC);
1063 static void
1064 PixmapPolylines(
1065 DrawablePtr pDraw,
1066 GCPtr pGC,
1067 int mode,
1068 int npt,
1069 DDXPointPtr pptInit
1071 PIXMAP_GC_OP_PROLOGUE(pGC);
1072 (*pGC->ops->Polylines)(pDraw, pGC, mode, npt, pptInit);
1073 PIXMAP_GC_OP_EPILOGUE(pGC);
1076 static void
1077 PixmapPolySegment(
1078 DrawablePtr pDraw,
1079 GCPtr pGC,
1080 int nseg,
1081 xSegment *pSeg
1083 PIXMAP_GC_OP_PROLOGUE(pGC);
1084 (*pGC->ops->PolySegment)(pDraw, pGC, nseg, pSeg);
1085 PIXMAP_GC_OP_EPILOGUE(pGC);
1088 static void
1089 PixmapPolyRectangle(
1090 DrawablePtr pDraw,
1091 GCPtr pGC,
1092 int nRectsInit,
1093 xRectangle *pRectsInit
1095 PIXMAP_GC_OP_PROLOGUE(pGC);
1096 (*pGC->ops->PolyRectangle)(pDraw, pGC, nRectsInit, pRectsInit);
1097 PIXMAP_GC_OP_EPILOGUE(pGC);
1100 static void
1101 PixmapPolyArc(
1102 DrawablePtr pDraw,
1103 GCPtr pGC,
1104 int narcs,
1105 xArc *parcs
1107 PIXMAP_GC_OP_PROLOGUE(pGC);
1108 (*pGC->ops->PolyArc)(pDraw, pGC, narcs, parcs);
1109 PIXMAP_GC_OP_EPILOGUE(pGC);
1112 static void
1113 PixmapFillPolygon(
1114 DrawablePtr pDraw,
1115 GCPtr pGC,
1116 int shape,
1117 int mode,
1118 int count,
1119 DDXPointPtr ptsIn
1121 PIXMAP_GC_OP_PROLOGUE(pGC);
1122 (*pGC->ops->FillPolygon)(pDraw, pGC, shape, mode, count, ptsIn);
1123 PIXMAP_GC_OP_EPILOGUE(pGC);
1126 static void
1127 PixmapPolyFillRect(
1128 DrawablePtr pDraw,
1129 GCPtr pGC,
1130 int nrectFill,
1131 xRectangle *prectInit
1133 PIXMAP_GC_OP_PROLOGUE(pGC);
1134 (*pGC->ops->PolyFillRect)(pDraw, pGC, nrectFill, prectInit);
1135 PIXMAP_GC_OP_EPILOGUE(pGC);
1138 static void
1139 PixmapPolyFillArc(
1140 DrawablePtr pDraw,
1141 GCPtr pGC,
1142 int narcs,
1143 xArc *parcs
1145 PIXMAP_GC_OP_PROLOGUE(pGC);
1146 (*pGC->ops->PolyFillArc)(pDraw, pGC, narcs, parcs);
1147 PIXMAP_GC_OP_EPILOGUE(pGC);
1150 static int
1151 PixmapPolyText8(
1152 DrawablePtr pDraw,
1153 GCPtr pGC,
1154 int x,
1155 int y,
1156 int count,
1157 char *chars
1159 int ret;
1161 PIXMAP_GC_OP_PROLOGUE(pGC);
1162 ret = (*pGC->ops->PolyText8)(pDraw, pGC, x, y, count, chars);
1163 PIXMAP_GC_OP_EPILOGUE(pGC);
1164 return ret;
1167 static int
1168 PixmapPolyText16(
1169 DrawablePtr pDraw,
1170 GCPtr pGC,
1171 int x,
1172 int y,
1173 int count,
1174 unsigned short *chars
1176 int ret;
1178 PIXMAP_GC_OP_PROLOGUE(pGC);
1179 ret = (*pGC->ops->PolyText16)(pDraw, pGC, x, y, count, chars);
1180 PIXMAP_GC_OP_EPILOGUE(pGC);
1181 return ret;
1184 static void
1185 PixmapImageText8(
1186 DrawablePtr pDraw,
1187 GCPtr pGC,
1188 int x,
1189 int y,
1190 int count,
1191 char *chars
1193 PIXMAP_GC_OP_PROLOGUE(pGC);
1194 (*pGC->ops->ImageText8)(pDraw, pGC, x, y, count, chars);
1195 PIXMAP_GC_OP_EPILOGUE(pGC);
1198 static void
1199 PixmapImageText16(
1200 DrawablePtr pDraw,
1201 GCPtr pGC,
1202 int x,
1203 int y,
1204 int count,
1205 unsigned short *chars
1207 PIXMAP_GC_OP_PROLOGUE(pGC);
1208 (*pGC->ops->ImageText16)(pDraw, pGC, x, y, count, chars);
1209 PIXMAP_GC_OP_EPILOGUE(pGC);
1212 static void
1213 PixmapImageGlyphBlt(
1214 DrawablePtr pDraw,
1215 GCPtr pGC,
1216 int xInit, int yInit,
1217 unsigned int nglyph,
1218 CharInfoPtr *ppci,
1219 pointer pglyphBase
1221 PIXMAP_GC_OP_PROLOGUE(pGC);
1222 (*pGC->ops->ImageGlyphBlt)(pDraw, pGC, xInit, yInit, nglyph,
1223 ppci, pglyphBase);
1224 PIXMAP_GC_OP_EPILOGUE(pGC);
1227 static void
1228 PixmapPolyGlyphBlt(
1229 DrawablePtr pDraw,
1230 GCPtr pGC,
1231 int xInit, int yInit,
1232 unsigned int nglyph,
1233 CharInfoPtr *ppci,
1234 pointer pglyphBase
1236 PIXMAP_GC_OP_PROLOGUE(pGC);
1237 (*pGC->ops->PolyGlyphBlt)(pDraw, pGC, xInit, yInit, nglyph,
1238 ppci, pglyphBase);
1239 PIXMAP_GC_OP_EPILOGUE(pGC);
1242 static void
1243 PixmapPushPixels(
1244 GCPtr pGC,
1245 PixmapPtr pBitMap,
1246 DrawablePtr pDraw,
1247 int dx, int dy, int xOrg, int yOrg
1249 PIXMAP_GC_OP_PROLOGUE(pGC);
1250 (*pGC->ops->PushPixels)(pGC, pBitMap, pDraw, dx, dy, xOrg, yOrg);
1251 PIXMAP_GC_OP_EPILOGUE(pGC);