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
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
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 ** *********************************************************
66 ** * Contents: Graphics Context handling for the PS driver
68 ** * Created By: Roger Helmendach (Liberty Systems)
70 ** * Copyright: Copyright 1996 The Open Group, Inc.
72 ** *********************************************************
74 ********************************************************************/
76 #ifdef HAVE_DIX_CONFIG_H
77 #include <dix-config.h>
82 #include "pixmapstr.h"
83 #include "windowstr.h"
85 #include "scrnintstr.h"
87 static GCOps PsGCOps
=
112 static GCFuncs PsGCFuncs
=
127 pGC
->clientClip
= NULL
;
128 pGC
->clientClipType
= CT_NONE
;
131 pGC
->funcs
= &PsGCFuncs
;
133 pGC
->clientClip
= (pointer
)xalloc(sizeof(PsClipRec
));
134 memset(pGC
->clientClip
, 0, sizeof(PsClipRec
));
139 PsGetDrawablePrivateStuff(
140 DrawablePtr pDrawable
,
142 unsigned long *valid
,
147 PsContextPrivPtr cPriv
;
148 PsScreenPrivPtr sPriv
;
150 switch(pDrawable
->type
)
152 case DRAWABLE_PIXMAP
:
154 case DRAWABLE_WINDOW
:
155 pCon
= PsGetContextFromWindow((WindowPtr
)pDrawable
);
156 if( pCon
==NULL
) return FALSE
;
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
;
169 *valid
= cPriv
->validGC
;
170 *psOut
= cPriv
->pPsOut
;
180 PsGetPsContextPriv( DrawablePtr pDrawable
)
184 switch(pDrawable
->type
)
186 case DRAWABLE_PIXMAP
:
188 case DRAWABLE_WINDOW
:
189 pCon
= PsGetContextFromWindow((WindowPtr
)pDrawable
);
192 return pCon
->devPrivates
[PsContextPrivateIndex
].ptr
;
201 DrawablePtr pDrawable
,
208 PsContextPrivPtr cPriv
;
211 if (!PsGetDrawablePrivateStuff(pDrawable
, &dGC
, &valid
, psOut
, cMap
))
214 switch (pDrawable
->type
) {
216 case DRAWABLE_PIXMAP
:
217 /* we don't support pixmaps yet! */
220 case DRAWABLE_WINDOW
:
224 WindowPtr pWin
= (WindowPtr
)pDrawable
;
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
);
237 pReg
= &pWin
->clipList
;
243 boxes
= (BoxPtr
)((char *)pReg
->data
+sizeof(long)*2);
244 clp
->nOutterClips
= pReg
->data
->numRects
;
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
;
268 PsValidateGC(GCPtr pGC
, unsigned long changes
, DrawablePtr pDrawable
)
274 PsChangeGC(GCPtr pGC
, unsigned long changes
)
279 PsCopyGC(GCPtr pGCSrc
, unsigned long mask
, GCPtr pGCDst
)
284 PsDestroyGC(GCPtr pGC
)
287 xfree(pGC
->clientClip
);
291 PsChangeClip(GCPtr pGC
, int type
, pointer pValue
, int nrects
)
294 PsClipPtr clp
= (PsClipPtr
)pGC
->clientClip
;
300 pGC
->clientClipType
= type
;
305 clp
->elms
= PsCreateFillElementList((PixmapPtr
)pValue
, &clp
->nElms
);
306 (*pGC
->pScreen
->DestroyPixmap
)((PixmapPtr
)pValue
);
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
);
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
;
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;
351 clp
->nOutterClips
= 0;
352 if( clp
->elms
) PsDestroyFillElementList(clp
->nElms
, clp
->elms
);
353 clp
->elms
= (PsElmPtr
)0;
355 pGC
->clientClipType
= CT_NONE
;
359 PsCopyClip(GCPtr pDst
, GCPtr pSrc
)
361 PsClipPtr src
= (PsClipPtr
)pSrc
->clientClip
;
362 PsClipPtr dst
= (PsClipPtr
)pDst
->clientClip
;
365 pDst
->clientClipType
= pSrc
->clientClipType
;
369 dst
->rects
= (PsRectPtr
)xalloc(src
->nRects
*sizeof(PsRectRec
));
370 memcpy(dst
->rects
, src
->rects
, src
->nRects
*sizeof(PsRectRec
));
373 dst
->elms
= PsCloneFillElementList(src
->nElms
, src
->elms
);
378 PsCreateAndCopyGC(DrawablePtr pDrawable
, GCPtr pSrc
)
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
388 fprintf(stderr
, "PsCreateAndCopyGC: pSrc == NULL\n");
393 CreateScratchGC(pDrawable
->pScreen
, pDrawable
->depth
)) == 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);