First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xprint / ps / PsGC.c
blob3ec07a77a92d43cbc7b6a9dbbd4d1fa80790b37a
1 /*
3 Copyright 1996, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
27 * (c) Copyright 1996 Hewlett-Packard Company
28 * (c) Copyright 1996 International Business Machines Corp.
29 * (c) Copyright 1996 Sun Microsystems, Inc.
30 * (c) Copyright 1996 Novell, Inc.
31 * (c) Copyright 1996 Digital Equipment Corp.
32 * (c) Copyright 1996 Fujitsu Limited
33 * (c) Copyright 1996 Hitachi, Ltd.
35 * Permission is hereby granted, free of charge, to any person obtaining
36 * a copy of this software and associated documentation files (the
37 * "Software"), to deal in the Software without restriction, including
38 * without limitation the rights to use, copy, modify, merge, publish,
39 * distribute, sublicense, and/or sell copies of the Software, and to
40 * permit persons to whom the Software is furnished to do so, subject
41 * to the following conditions:
43 * The above copyright notice and this permission notice shall be included
44 * in all copies or substantial portions of the Software.
46 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
47 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
48 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
49 * THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
50 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
51 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
52 * SOFTWARE.
54 * Except as contained in this notice, the names of the copyright holders
55 * shall not be used in advertising or otherwise to promote the sale, use
56 * or other dealings in this Software without prior written authorization
57 * from said copyright holders.
60 /*******************************************************************
62 ** *********************************************************
63 ** *
64 ** * File: PsGC.c
65 ** *
66 ** * Contents: Graphics Context handling for the PS driver
67 ** *
68 ** * Created By: Roger Helmendach (Liberty Systems)
69 ** *
70 ** * Copyright: Copyright 1996 The Open Group, Inc.
71 ** *
72 ** *********************************************************
73 **
74 ********************************************************************/
76 #ifdef HAVE_DIX_CONFIG_H
77 #include <dix-config.h>
78 #endif
80 #include "Ps.h"
81 #include "gcstruct.h"
82 #include "pixmapstr.h"
83 #include "windowstr.h"
84 #include "migc.h"
85 #include "scrnintstr.h"
87 static GCOps PsGCOps =
89 PsFillSpans,
90 PsSetSpans,
91 PsPutImage,
92 PsCopyArea,
93 PsCopyPlane,
94 PsPolyPoint,
95 PsPolyLine,
96 PsPolySegment,
97 PsPolyRectangle,
98 PsPolyArc,
99 PsFillPolygon,
100 PsPolyFillRect,
101 PsPolyFillArc,
102 PsPolyText8,
103 PsPolyText16,
104 PsImageText8,
105 PsImageText16,
106 PsImageGlyphBlt,
107 PsPolyGlyphBlt,
108 PsPushPixels
112 static GCFuncs PsGCFuncs =
114 PsValidateGC,
115 PsChangeGC,
116 PsCopyGC,
117 PsDestroyGC,
118 PsChangeClip,
119 PsDestroyClip,
120 PsCopyClip
123 Bool
124 PsCreateGC(pGC)
125 GCPtr pGC;
127 pGC->clientClip = NULL;
128 pGC->clientClipType = CT_NONE;
130 pGC->ops = &PsGCOps;
131 pGC->funcs = &PsGCFuncs;
133 pGC->clientClip = (pointer)xalloc(sizeof(PsClipRec));
134 memset(pGC->clientClip, 0, sizeof(PsClipRec));
135 return TRUE;
138 static int
139 PsGetDrawablePrivateStuff(
140 DrawablePtr pDrawable,
141 GC *gc,
142 unsigned long *valid,
143 PsOutPtr *psOut,
144 ColormapPtr *cMap)
146 XpContextPtr pCon;
147 PsContextPrivPtr cPriv;
148 PsScreenPrivPtr sPriv;
150 switch(pDrawable->type)
152 case DRAWABLE_PIXMAP:
153 return FALSE;
154 case DRAWABLE_WINDOW:
155 pCon = PsGetContextFromWindow((WindowPtr)pDrawable);
156 if( pCon==NULL ) return FALSE;
157 else
159 Colormap c;
160 ColormapPtr cmap;
162 c = wColormap((WindowPtr)pDrawable);
163 cmap = (ColormapPtr)LookupIDByType(c, RT_COLORMAP);
165 cPriv = pCon->devPrivates[PsContextPrivateIndex].ptr;
166 sPriv = (PsScreenPrivPtr)
167 pDrawable->pScreen->devPrivates[PsScreenPrivateIndex].ptr;
168 *gc = cPriv->lastGC;
169 *valid = cPriv->validGC;
170 *psOut = cPriv->pPsOut;
171 *cMap = cmap;
172 return TRUE;
174 default:
175 return FALSE;
179 PsContextPrivPtr
180 PsGetPsContextPriv( DrawablePtr pDrawable )
182 XpContextPtr pCon;
184 switch(pDrawable->type)
186 case DRAWABLE_PIXMAP:
187 return FALSE;
188 case DRAWABLE_WINDOW:
189 pCon = PsGetContextFromWindow((WindowPtr)pDrawable);
190 if (pCon != NULL)
192 return pCon->devPrivates[PsContextPrivateIndex].ptr;
195 return NULL;
199 PsUpdateDrawableGC(
200 GCPtr pGC,
201 DrawablePtr pDrawable,
202 PsOutPtr *psOut,
203 ColormapPtr *cMap)
205 GC dGC;
206 unsigned long valid;
207 int i;
208 PsContextPrivPtr cPriv;
209 BoxPtr boxes;
211 if (!PsGetDrawablePrivateStuff(pDrawable, &dGC, &valid, psOut, cMap))
212 return FALSE;
214 switch (pDrawable->type) {
216 case DRAWABLE_PIXMAP:
217 /* we don't support pixmaps yet! */
218 return FALSE;
219 break;
220 case DRAWABLE_WINDOW:
221 if( pGC )
223 RegionPtr pReg;
224 WindowPtr pWin = (WindowPtr)pDrawable;
225 Bool freeClip;
226 PsClipPtr clp = (PsClipPtr)pGC->clientClip;
227 if( clp->outterClips )
228 { xfree(clp->outterClips); clp->outterClips = 0; }
229 clp->nOutterClips = 0;
230 if( pGC->subWindowMode==IncludeInferiors )
232 pReg = NotClippedByChildren(pWin);
233 freeClip = TRUE;
235 else
237 pReg = &pWin->clipList;
238 freeClip = FALSE;
241 if( pReg->data )
243 boxes = (BoxPtr)((char *)pReg->data+sizeof(long)*2);
244 clp->nOutterClips = pReg->data->numRects;
245 clp->outterClips =
246 (PsRectPtr)xalloc(clp->nOutterClips*sizeof(PsRectRec));
247 for( i=0 ; i<clp->nOutterClips ; i++ )
249 clp->outterClips[i].x = boxes[i].x1;
250 clp->outterClips[i].y = boxes[i].y1;
251 clp->outterClips[i].w = (boxes[i].x2-boxes[i].x1)+1;
252 clp->outterClips[i].h = (boxes[i].y2-boxes[i].y1)+1;
256 if( freeClip ) REGION_DESTROY(pGC->pScreen, pReg);
257 PsOut_Offset(*psOut, pDrawable->x, pDrawable->y);
258 PsOut_Clip(*psOut, pGC->clientClipType, (PsClipPtr)pGC->clientClip);
260 cPriv = ( PsGetContextFromWindow( (WindowPtr)pDrawable ) )
261 ->devPrivates[PsContextPrivateIndex].ptr;
262 break;
264 return TRUE;
267 void
268 PsValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr pDrawable)
270 pGC->ops = &PsGCOps;
273 void
274 PsChangeGC(GCPtr pGC, unsigned long changes)
278 void
279 PsCopyGC(GCPtr pGCSrc, unsigned long mask, GCPtr pGCDst)
283 void
284 PsDestroyGC(GCPtr pGC)
286 PsDestroyClip(pGC);
287 xfree(pGC->clientClip);
290 void
291 PsChangeClip(GCPtr pGC, int type, pointer pValue, int nrects)
293 int i;
294 PsClipPtr clp = (PsClipPtr)pGC->clientClip;
295 RegionPtr rgn;
296 BoxPtr boxes;
297 xRectangle *rects;
299 PsDestroyClip(pGC);
300 pGC->clientClipType = type;
301 switch(type)
303 case CT_NONE: break;
304 case CT_PIXMAP:
305 clp->elms = PsCreateFillElementList((PixmapPtr)pValue, &clp->nElms);
306 (*pGC->pScreen->DestroyPixmap)((PixmapPtr)pValue);
307 break;
308 case CT_REGION:
309 rgn = (RegionPtr)pValue;
310 boxes = (BoxPtr)((char *)rgn->data+sizeof(long)*2);
311 clp->nRects = rgn->data->numRects;
312 clp->rects = (PsRectPtr)xalloc(clp->nRects*sizeof(PsRectRec));
313 for( i=0 ; i<clp->nRects ; i++ )
315 clp->rects[i].x = boxes[i].x1;
316 clp->rects[i].y = boxes[i].y1;
317 clp->rects[i].w = (boxes[i].x2-boxes[i].x1)+1;
318 clp->rects[i].h = (boxes[i].y2-boxes[i].y1)+1;
320 REGION_DESTROY(pGC->pScreen, (RegionPtr)pValue);
321 break;
322 case CT_UNSORTED:
323 case CT_YSORTED:
324 case CT_YXSORTED:
325 case CT_YXBANDED:
326 rects = (xRectangle *)pValue;
327 clp->nRects = nrects;
328 clp->rects = (PsRectPtr)xalloc(clp->nRects*sizeof(PsRectRec));
329 for( i=0 ; i<clp->nRects ; i++ )
331 clp->rects[i].x = rects[i].x;
332 clp->rects[i].y = rects[i].y;
333 clp->rects[i].w = rects[i].width;
334 clp->rects[i].h = rects[i].height;
336 xfree(pValue);
337 break;
341 void
342 PsDestroyClip(GCPtr pGC)
344 PsClipPtr clp = (PsClipPtr)pGC->clientClip;
346 if( clp->rects ) xfree(clp->rects);
347 if( clp->outterClips ) xfree(clp->outterClips);
348 clp->rects = (PsRectPtr)0;
349 clp->outterClips = (PsRectPtr)0;
350 clp->nRects = 0;
351 clp->nOutterClips = 0;
352 if( clp->elms ) PsDestroyFillElementList(clp->nElms, clp->elms);
353 clp->elms = (PsElmPtr)0;
354 clp->nElms = 0;
355 pGC->clientClipType = CT_NONE;
358 void
359 PsCopyClip(GCPtr pDst, GCPtr pSrc)
361 PsClipPtr src = (PsClipPtr)pSrc->clientClip;
362 PsClipPtr dst = (PsClipPtr)pDst->clientClip;
364 PsDestroyClip(pDst);
365 pDst->clientClipType = pSrc->clientClipType;
366 *dst = *src;
367 if( src->rects )
369 dst->rects = (PsRectPtr)xalloc(src->nRects*sizeof(PsRectRec));
370 memcpy(dst->rects, src->rects, src->nRects*sizeof(PsRectRec));
372 if( src->elms )
373 dst->elms = PsCloneFillElementList(src->nElms, src->elms);
377 GCPtr
378 PsCreateAndCopyGC(DrawablePtr pDrawable, GCPtr pSrc)
380 GCPtr pDst;
382 if (pSrc == NULL) {
383 /* https://freedesktop.org/bugzilla/show_bug.cgi?id=1416 ("'x11perf
384 * -copypixpix500' crashes Xprt's PostScript DDX [PsCreateAndCopyGC"):
385 * I have no clue whether this is the real fix or just wallpapering
386 * over the crash (that's why we warn here loudly when this
387 * happens) ... */
388 fprintf(stderr, "PsCreateAndCopyGC: pSrc == NULL\n");
389 return NULL;
392 if ((pDst =
393 CreateScratchGC(pDrawable->pScreen, pDrawable->depth)) == NULL)
395 return NULL;
398 if (CopyGC(pSrc, pDst,
399 GCFunction | GCPlaneMask | GCForeground | GCBackground |
400 GCLineWidth | GCLineStyle | GCCapStyle | GCJoinStyle |
401 GCFillStyle | GCFillRule | GCTile | GCStipple |
402 GCTileStipXOrigin | GCTileStipYOrigin | GCFont |
403 GCSubwindowMode | GCGraphicsExposures | GCClipXOrigin |
404 GCClipYOrigin | GCClipMask | GCDashOffset | GCDashList |
405 GCArcMode) != Success)
407 (void)FreeGC(pDst, (GContext)0);
409 return NULL;
412 return pDst;