First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / xaa / xaaGC.c
blobf3434c9f45edfb5e4412b49b2284cd09db15dfe1
2 #ifdef HAVE_XORG_CONFIG_H
3 #include <xorg-config.h>
4 #endif
6 #include <string.h>
8 #include "misc.h"
9 #include "xf86.h"
10 #include "xf86_OSproc.h"
12 #include <X11/X.h>
13 #include "scrnintstr.h"
14 #include "xf86str.h"
15 #include "xaa.h"
16 #include "xaalocal.h"
17 #include "migc.h"
18 #include "gcstruct.h"
19 #include "pixmapstr.h"
20 #include "xaawrap.h"
22 static void XAAValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDraw);
23 static void XAAChangeGC(GCPtr pGC, unsigned long mask);
24 static void XAACopyGC(GCPtr pGCSrc, unsigned long mask, GCPtr pGCDst);
25 static void XAADestroyGC(GCPtr pGC);
26 static void XAAChangeClip(GCPtr pGC, int type, pointer pvalue, int nrects);
27 static void XAADestroyClip(GCPtr pGC);
28 static void XAACopyClip(GCPtr pgcDst, GCPtr pgcSrc);
30 GCFuncs XAAGCFuncs = {
31 XAAValidateGC, XAAChangeGC, XAACopyGC, XAADestroyGC,
32 XAAChangeClip, XAADestroyClip, XAACopyClip
35 extern GCOps XAAPixmapOps;
37 Bool
38 XAACreateGC(GCPtr pGC)
40 ScreenPtr pScreen = pGC->pScreen;
41 XAAGCPtr pGCPriv = (XAAGCPtr)(pGC->devPrivates[XAAGetGCIndex()].ptr);
42 Bool ret;
44 XAA_SCREEN_PROLOGUE(pScreen,CreateGC);
46 if((ret = (*pScreen->CreateGC)(pGC))) {
47 pGCPriv->wrapOps = NULL;
48 pGCPriv->wrapFuncs = pGC->funcs;
49 pGCPriv->XAAOps = &XAAFallbackOps;
50 pGCPriv->flags = 0;
51 pGCPriv->DashLength = 0;
52 pGCPriv->DashPattern = NULL;
53 pGCPriv->changes = 0;
54 /* initialize any other private fields here */
55 pGC->funcs = &XAAGCFuncs;
58 XAA_SCREEN_EPILOGUE(pScreen,CreateGC,XAACreateGC);
60 return ret;
64 static void
65 XAAValidateGC(
66 GCPtr pGC,
67 unsigned long changes,
68 DrawablePtr pDraw
70 XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
71 XAA_GC_FUNC_PROLOGUE(pGC);
73 (*pGC->funcs->ValidateGC)(pGC, changes, pDraw);
75 if((changes & GCPlaneMask) &&
76 ((pGC->planemask & infoRec->FullPlanemasks[pGC->depth - 1]) ==
77 infoRec->FullPlanemasks[pGC->depth - 1]))
79 pGC->planemask = ~0;
82 if(pGC->depth != 32) {
83 if(pGC->bgPixel == -1) /* -1 is reserved for transparency */
84 pGC->bgPixel = 0x7fffffff;
85 if(pGC->fgPixel == -1) /* -1 is reserved for transparency */
86 pGC->fgPixel = 0x7fffffff;
89 if((pDraw->type == DRAWABLE_PIXMAP) && !IS_OFFSCREEN_PIXMAP(pDraw)){
90 pGCPriv->flags = OPS_ARE_PIXMAP;
91 pGCPriv->changes |= changes;
93 /* make sure we're not using videomemory pixmaps to render
94 onto system memory drawables */
96 if((pGC->fillStyle == FillTiled) &&
97 IS_OFFSCREEN_PIXMAP(pGC->tile.pixmap) &&
98 !OFFSCREEN_PIXMAP_LOCKED(pGC->tile.pixmap)) {
100 XAAPixmapPtr pPriv = XAA_GET_PIXMAP_PRIVATE(pGC->tile.pixmap);
101 FBAreaPtr area = pPriv->offscreenArea;
103 XAARemoveAreaCallback(area); /* clobbers pPriv->offscreenArea */
104 xf86FreeOffscreenArea(area);
107 else if(!infoRec->pScrn->vtSema && (pDraw->type == DRAWABLE_WINDOW)) {
108 pGCPriv->flags = 0;
109 pGCPriv->changes |= changes;
111 else {
112 if(!(pGCPriv->flags & OPS_ARE_ACCEL)) {
113 changes |= pGCPriv->changes;
114 pGCPriv->changes = 0;
116 pGCPriv->flags = OPS_ARE_ACCEL;
118 #if 1
119 /* Ugh. If we can't use the blitter on offscreen pixmaps used
120 as tiles, then we need to move them out as cfb can't handle
121 tiles with non-zero origins */
123 if((pGC->fillStyle == FillTiled) &&
124 IS_OFFSCREEN_PIXMAP(pGC->tile.pixmap) &&
125 (DO_PIXMAP_COPY != (*infoRec->TiledFillChooser)(pGC))) {
127 XAAPixmapPtr pPriv = XAA_GET_PIXMAP_PRIVATE(pGC->tile.pixmap);
128 FBAreaPtr area = pPriv->offscreenArea;
130 XAARemoveAreaCallback(area); /* clobbers pPriv->offscreenArea */
131 xf86FreeOffscreenArea(area);
133 #endif
136 XAA_GC_FUNC_EPILOGUE(pGC);
138 if(!(pGCPriv->flags & OPS_ARE_ACCEL)) return;
140 if((changes & GCTile) && !pGC->tileIsPixel && pGC->tile.pixmap){
141 XAAPixmapPtr pixPriv = XAA_GET_PIXMAP_PRIVATE(pGC->tile.pixmap);
143 if(pixPriv->flags & DIRTY) {
144 pixPriv->flags &= ~(DIRTY | REDUCIBILITY_MASK);
145 pGC->tile.pixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
148 if((changes & GCStipple) && pGC->stipple){
149 XAAPixmapPtr pixPriv = XAA_GET_PIXMAP_PRIVATE(pGC->stipple);
151 if(pixPriv->flags & DIRTY) {
152 pixPriv->flags &= ~(DIRTY | REDUCIBILITY_MASK);
153 pGC->stipple->drawable.serialNumber = NEXT_SERIAL_NUMBER;
157 /* If our Ops are still the default ones we need to allocate new ones */
158 if(pGC->ops == &XAAFallbackOps) {
159 if(!(pGCPriv->XAAOps = xalloc(sizeof(GCOps)))) {
160 pGCPriv->XAAOps = &XAAFallbackOps;
161 return;
163 /* make a modifiable copy of the default ops */
164 memcpy(pGCPriv->XAAOps, &XAAFallbackOps, sizeof(GCOps));
165 pGC->ops = pGCPriv->XAAOps;
166 changes = ~0;
169 if(!changes) return;
171 if((changes & GCDashList) && infoRec->ComputeDash)
172 infoRec->ComputeDash(pGC);
174 if(changes & infoRec->FillSpansMask)
175 (*infoRec->ValidateFillSpans)(pGC, changes, pDraw);
177 if(changes & infoRec->SetSpansMask)
178 (*infoRec->ValidateSetSpans)(pGC, changes, pDraw);
180 if(changes & infoRec->PutImageMask)
181 (*infoRec->ValidatePutImage)(pGC, changes, pDraw);
183 if(changes & infoRec->CopyAreaMask)
184 (*infoRec->ValidateCopyArea)(pGC, changes, pDraw);
186 if(changes & infoRec->CopyPlaneMask)
187 (*infoRec->ValidateCopyPlane)(pGC, changes, pDraw);
189 if(changes & infoRec->PolyPointMask)
190 (*infoRec->ValidatePolyPoint)(pGC, changes, pDraw);
192 if(changes & infoRec->PolylinesMask)
193 (*infoRec->ValidatePolylines)(pGC, changes, pDraw);
195 if(changes & infoRec->PolySegmentMask)
196 (*infoRec->ValidatePolySegment)(pGC, changes, pDraw);
198 if(changes & infoRec->PolyRectangleMask)
199 (*infoRec->ValidatePolyRectangle)(pGC, changes, pDraw);
201 if(changes & infoRec->PolyArcMask)
202 (*infoRec->ValidatePolyArc)(pGC, changes, pDraw);
204 if(changes & infoRec->FillPolygonMask)
205 (*infoRec->ValidateFillPolygon)(pGC, changes, pDraw);
207 if(changes & infoRec->PolyFillRectMask)
208 (*infoRec->ValidatePolyFillRect)(pGC, changes, pDraw);
210 if(changes & infoRec->PolyFillArcMask)
211 (*infoRec->ValidatePolyFillArc)(pGC, changes, pDraw);
213 if(changes & infoRec->PolyGlyphBltMask)
214 (*infoRec->ValidatePolyGlyphBlt)(pGC, changes, pDraw);
216 if(changes & infoRec->ImageGlyphBltMask)
217 (*infoRec->ValidateImageGlyphBlt)(pGC, changes, pDraw);
219 if(changes & infoRec->PolyText8Mask)
220 (*infoRec->ValidatePolyText8)(pGC, changes, pDraw);
222 if(changes & infoRec->PolyText16Mask)
223 (*infoRec->ValidatePolyText16)(pGC, changes, pDraw);
225 if(changes & infoRec->ImageText8Mask)
226 (*infoRec->ValidateImageText8)(pGC, changes, pDraw);
228 if(changes & infoRec->ImageText16Mask)
229 (*infoRec->ValidateImageText16)(pGC, changes, pDraw);
231 if(changes & infoRec->PushPixelsMask)
232 (*infoRec->ValidatePushPixels)(pGC, changes, pDraw);
236 static void
237 XAADestroyGC(GCPtr pGC)
239 XAA_GC_FUNC_PROLOGUE (pGC);
241 if(pGCPriv->XAAOps != &XAAFallbackOps)
242 xfree(pGCPriv->XAAOps);
244 if(pGCPriv->DashPattern)
245 xfree(pGCPriv->DashPattern);
247 (*pGC->funcs->DestroyGC)(pGC);
248 XAA_GC_FUNC_EPILOGUE (pGC);
251 static void
252 XAAChangeGC (
253 GCPtr pGC,
254 unsigned long mask
257 XAA_GC_FUNC_PROLOGUE (pGC);
258 (*pGC->funcs->ChangeGC) (pGC, mask);
259 XAA_GC_FUNC_EPILOGUE (pGC);
261 /* we have to assume that shared memory pixmaps are dirty
262 because we can't wrap all operations on them */
264 if((mask & GCTile) && !pGC->tileIsPixel &&
265 PIXMAP_IS_SHARED(pGC->tile.pixmap))
267 XAAPixmapPtr pPixPriv = XAA_GET_PIXMAP_PRIVATE(pGC->tile.pixmap);
268 pPixPriv->flags |= DIRTY;
271 if((mask & GCStipple) && PIXMAP_IS_SHARED(pGC->stipple)){
272 XAAPixmapPtr pPixPriv = XAA_GET_PIXMAP_PRIVATE(pGC->stipple);
273 pPixPriv->flags |= DIRTY;
277 static void
278 XAACopyGC (
279 GCPtr pGCSrc,
280 unsigned long mask,
281 GCPtr pGCDst)
283 XAA_GC_FUNC_PROLOGUE (pGCDst);
284 (*pGCDst->funcs->CopyGC) (pGCSrc, mask, pGCDst);
285 XAA_GC_FUNC_EPILOGUE (pGCDst);
287 static void
288 XAAChangeClip (
289 GCPtr pGC,
290 int type,
291 pointer pvalue,
292 int nrects )
294 XAA_GC_FUNC_PROLOGUE (pGC);
295 (*pGC->funcs->ChangeClip) (pGC, type, pvalue, nrects);
296 XAA_GC_FUNC_EPILOGUE (pGC);
299 static void
300 XAACopyClip(GCPtr pgcDst, GCPtr pgcSrc)
302 XAA_GC_FUNC_PROLOGUE (pgcDst);
303 (* pgcDst->funcs->CopyClip)(pgcDst, pgcSrc);
304 XAA_GC_FUNC_EPILOGUE (pgcDst);
307 static void
308 XAADestroyClip(GCPtr pGC)
310 XAA_GC_FUNC_PROLOGUE (pGC);
311 (* pGC->funcs->DestroyClip)(pGC);
312 XAA_GC_FUNC_EPILOGUE (pGC);
315 /**** Pixmap Wrappers ****/
319 static void
320 XAAFillSpansPixmap(
321 DrawablePtr pDraw,
322 GC *pGC,
323 int nInit,
324 DDXPointPtr pptInit,
325 int *pwidthInit,
326 int fSorted
328 XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
329 (*pGC->ops->FillSpans)(pDraw, pGC, nInit, pptInit, pwidthInit, fSorted);
330 XAA_PIXMAP_OP_EPILOGUE(pGC);
333 static void
334 XAASetSpansPixmap(
335 DrawablePtr pDraw,
336 GCPtr pGC,
337 char *pcharsrc,
338 register DDXPointPtr ppt,
339 int *pwidth,
340 int nspans,
341 int fSorted
343 XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
344 (*pGC->ops->SetSpans)(pDraw, pGC, pcharsrc, ppt, pwidth, nspans, fSorted);
345 XAA_PIXMAP_OP_EPILOGUE(pGC);
348 static void
349 XAAPutImagePixmap(
350 DrawablePtr pDraw,
351 GCPtr pGC,
352 int depth,
353 int x, int y, int w, int h,
354 int leftPad,
355 int format,
356 char *pImage
358 XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
359 (*pGC->ops->PutImage)(pDraw, pGC, depth, x, y, w, h,
360 leftPad, format, pImage);
361 XAA_PIXMAP_OP_EPILOGUE(pGC);
364 static RegionPtr
365 XAACopyAreaPixmap(
366 DrawablePtr pSrc,
367 DrawablePtr pDst,
368 GC *pGC,
369 int srcx, int srcy,
370 int width, int height,
371 int dstx, int dsty
373 XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
374 RegionPtr ret;
376 if(infoRec->pScrn->vtSema &&
377 ((pSrc->type == DRAWABLE_WINDOW) || IS_OFFSCREEN_PIXMAP(pSrc)))
379 if(infoRec->ReadPixmap && (pGC->alu == GXcopy) &&
380 (pSrc->bitsPerPixel == pDst->bitsPerPixel) &&
381 ((pGC->planemask & infoRec->FullPlanemasks[pSrc->depth - 1])
382 == infoRec->FullPlanemasks[pSrc->depth - 1]))
384 XAAPixmapPtr pixPriv = XAA_GET_PIXMAP_PRIVATE((PixmapPtr)(pDst));
385 pixPriv->flags |= DIRTY;
387 return (XAABitBlt( pSrc, pDst, pGC,
388 srcx, srcy, width, height, dstx, dsty,
389 XAADoImageRead, 0L));
390 } else
391 if(infoRec->NeedToSync) {
392 (*infoRec->Sync)(infoRec->pScrn);
393 infoRec->NeedToSync = FALSE;
398 XAA_PIXMAP_OP_PROLOGUE(pGC, pDst);
399 ret = (*pGC->ops->CopyArea)(pSrc, pDst,
400 pGC, srcx, srcy, width, height, dstx, dsty);
401 XAA_PIXMAP_OP_EPILOGUE(pGC);
403 return ret;
406 static RegionPtr
407 XAACopyPlanePixmap(
408 DrawablePtr pSrc,
409 DrawablePtr pDst,
410 GCPtr pGC,
411 int srcx, int srcy,
412 int width, int height,
413 int dstx, int dsty,
414 unsigned long bitPlane
416 XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
417 RegionPtr ret;
419 XAA_PIXMAP_OP_PROLOGUE(pGC, pDst);
421 if(infoRec->pScrn->vtSema &&
422 ((pSrc->type == DRAWABLE_WINDOW) || IS_OFFSCREEN_PIXMAP(pSrc))){
423 if(infoRec->NeedToSync) {
424 (*infoRec->Sync)(infoRec->pScrn);
425 infoRec->NeedToSync = FALSE;
429 ret = (*pGC->ops->CopyPlane)(pSrc, pDst,
430 pGC, srcx, srcy, width, height, dstx, dsty, bitPlane);
431 XAA_PIXMAP_OP_EPILOGUE(pGC);
432 return ret;
435 static void
436 XAAPolyPointPixmap(
437 DrawablePtr pDraw,
438 GCPtr pGC,
439 int mode,
440 int npt,
441 xPoint *pptInit
443 XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
444 (*pGC->ops->PolyPoint)(pDraw, pGC, mode, npt, pptInit);
445 XAA_PIXMAP_OP_EPILOGUE(pGC);
449 static void
450 XAAPolylinesPixmap(
451 DrawablePtr pDraw,
452 GCPtr pGC,
453 int mode,
454 int npt,
455 DDXPointPtr pptInit
457 XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
458 (*pGC->ops->Polylines)(pDraw, pGC, mode, npt, pptInit);
459 XAA_PIXMAP_OP_EPILOGUE(pGC);
462 static void
463 XAAPolySegmentPixmap(
464 DrawablePtr pDraw,
465 GCPtr pGC,
466 int nseg,
467 xSegment *pSeg
469 XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
470 (*pGC->ops->PolySegment)(pDraw, pGC, nseg, pSeg);
471 XAA_PIXMAP_OP_EPILOGUE(pGC);
474 static void
475 XAAPolyRectanglePixmap(
476 DrawablePtr pDraw,
477 GCPtr pGC,
478 int nRectsInit,
479 xRectangle *pRectsInit
481 XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
482 (*pGC->ops->PolyRectangle)(pDraw, pGC, nRectsInit, pRectsInit);
483 XAA_PIXMAP_OP_EPILOGUE(pGC);
486 static void
487 XAAPolyArcPixmap(
488 DrawablePtr pDraw,
489 GCPtr pGC,
490 int narcs,
491 xArc *parcs
493 XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
494 (*pGC->ops->PolyArc)(pDraw, pGC, narcs, parcs);
495 XAA_PIXMAP_OP_EPILOGUE(pGC);
498 static void
499 XAAFillPolygonPixmap(
500 DrawablePtr pDraw,
501 GCPtr pGC,
502 int shape,
503 int mode,
504 int count,
505 DDXPointPtr ptsIn
507 XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
508 (*pGC->ops->FillPolygon)(pDraw, pGC, shape, mode, count, ptsIn);
509 XAA_PIXMAP_OP_EPILOGUE(pGC);
513 static void
514 XAAPolyFillRectPixmap(
515 DrawablePtr pDraw,
516 GCPtr pGC,
517 int nrectFill,
518 xRectangle *prectInit
520 XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
521 (*pGC->ops->PolyFillRect)(pDraw, pGC, nrectFill, prectInit);
522 XAA_PIXMAP_OP_EPILOGUE(pGC);
526 static void
527 XAAPolyFillArcPixmap(
528 DrawablePtr pDraw,
529 GCPtr pGC,
530 int narcs,
531 xArc *parcs
533 XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
534 (*pGC->ops->PolyFillArc)(pDraw, pGC, narcs, parcs);
535 XAA_PIXMAP_OP_EPILOGUE(pGC);
538 static int
539 XAAPolyText8Pixmap(
540 DrawablePtr pDraw,
541 GCPtr pGC,
542 int x,
543 int y,
544 int count,
545 char *chars
547 int ret;
549 XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
550 ret = (*pGC->ops->PolyText8)(pDraw, pGC, x, y, count, chars);
551 XAA_PIXMAP_OP_EPILOGUE(pGC);
552 return ret;
555 static int
556 XAAPolyText16Pixmap(
557 DrawablePtr pDraw,
558 GCPtr pGC,
559 int x,
560 int y,
561 int count,
562 unsigned short *chars
564 int ret;
566 XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
567 ret = (*pGC->ops->PolyText16)(pDraw, pGC, x, y, count, chars);
568 XAA_PIXMAP_OP_EPILOGUE(pGC);
569 return ret;
572 static void
573 XAAImageText8Pixmap(
574 DrawablePtr pDraw,
575 GCPtr pGC,
576 int x,
577 int y,
578 int count,
579 char *chars
581 XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
582 (*pGC->ops->ImageText8)(pDraw, pGC, x, y, count, chars);
583 XAA_PIXMAP_OP_EPILOGUE(pGC);
585 static void
586 XAAImageText16Pixmap(
587 DrawablePtr pDraw,
588 GCPtr pGC,
589 int x,
590 int y,
591 int count,
592 unsigned short *chars
594 XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
595 (*pGC->ops->ImageText16)(pDraw, pGC, x, y, count, chars);
596 XAA_PIXMAP_OP_EPILOGUE(pGC);
600 static void
601 XAAImageGlyphBltPixmap(
602 DrawablePtr pDraw,
603 GCPtr pGC,
604 int xInit, int yInit,
605 unsigned int nglyph,
606 CharInfoPtr *ppci,
607 pointer pglyphBase
609 XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
610 (*pGC->ops->ImageGlyphBlt)(pDraw, pGC, xInit, yInit, nglyph,
611 ppci, pglyphBase);
612 XAA_PIXMAP_OP_EPILOGUE(pGC);
615 static void
616 XAAPolyGlyphBltPixmap(
617 DrawablePtr pDraw,
618 GCPtr pGC,
619 int xInit, int yInit,
620 unsigned int nglyph,
621 CharInfoPtr *ppci,
622 pointer pglyphBase
624 XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
625 (*pGC->ops->PolyGlyphBlt)(pDraw, pGC, xInit, yInit, nglyph,
626 ppci, pglyphBase);
627 XAA_PIXMAP_OP_EPILOGUE(pGC);
630 static void
631 XAAPushPixelsPixmap(
632 GCPtr pGC,
633 PixmapPtr pBitMap,
634 DrawablePtr pDraw,
635 int dx, int dy, int xOrg, int yOrg
637 XAA_PIXMAP_OP_PROLOGUE(pGC, pDraw);
638 (*pGC->ops->PushPixels)(pGC, pBitMap, pDraw, dx, dy, xOrg, yOrg);
639 XAA_PIXMAP_OP_EPILOGUE(pGC);
642 GCOps XAAPixmapOps = {
643 XAAFillSpansPixmap, XAASetSpansPixmap,
644 XAAPutImagePixmap, XAACopyAreaPixmap,
645 XAACopyPlanePixmap, XAAPolyPointPixmap,
646 XAAPolylinesPixmap, XAAPolySegmentPixmap,
647 XAAPolyRectanglePixmap, XAAPolyArcPixmap,
648 XAAFillPolygonPixmap, XAAPolyFillRectPixmap,
649 XAAPolyFillArcPixmap, XAAPolyText8Pixmap,
650 XAAPolyText16Pixmap, XAAImageText8Pixmap,
651 XAAImageText16Pixmap, XAAImageGlyphBltPixmap,
652 XAAPolyGlyphBltPixmap, XAAPushPixelsPixmap,
653 {NULL} /* devPrivate */