First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xfree86 / xf4bpp / ppcGC.c
blobb59dab312383a7f4db00f333c423c462ea0aac05
1 /*
3 Copyright (c) 1987 X Consortium
5 Permission is hereby granted, free of charge, to any person obtaining
6 a copy of this software and associated documentation files (the
7 "Software"), to deal in the Software without restriction, including
8 without limitation the rights to use, copy, modify, merge, publish,
9 distribute, sublicense, and/or sell copies of the Software, and to
10 permit persons to whom the Software is furnished to do so, subject to
11 the following conditions:
13 The above copyright notice and this permission notice shall be included
14 in all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 OTHER DEALINGS IN THE SOFTWARE.
24 Except as contained in this notice, the name of the X Consortium shall
25 not be used in advertising or otherwise to promote the sale, use or
26 other dealings in this Software without prior written authorization
27 from the X Consortium.
30 Copyright IBM Corporation 1987,1988,1989
31 All Rights Reserved
33 Permission to use, copy, modify, and distribute this software and its
34 documentation for any purpose and without fee is hereby granted,
35 provided that the above copyright notice appear in all copies and that
36 both that copyright notice and this permission notice appear in
37 supporting documentation, and that the name of IBM not be
38 used in advertising or publicity pertaining to distribution of the
39 software without specific, written prior permission.
41 IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
42 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
43 IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
44 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
45 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
46 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
47 SOFTWARE.
50 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
51 All Rights Reserved
53 Permission to use, copy, modify, and distribute this software and its
54 documentation for any purpose and without fee is hereby granted,
55 provided that the above copyright notice appear in all copies and that
56 both that copyright notice and this permission notice appear in
57 supporting documentation, and that the name of Digital not be
58 used in advertising or publicity pertaining to distribution of the
59 software without specific, written prior permission.
61 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
62 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
63 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
64 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
65 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
66 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
67 SOFTWARE.
71 #ifdef HAVE_XORG_CONFIG_H
72 #include <xorg-config.h>
73 #endif
75 #include <stdlib.h>
77 #include "xf4bpp.h"
78 #include "mfbmap.h"
79 #include "mfb.h"
80 #include "mi.h"
81 #include "scrnintstr.h"
82 #include "ppcGCstr.h"
83 #include "vgaVideo.h"
84 #include "ibmTrace.h"
86 #define ppcGCInterestValidateMask \
87 ( GCLineStyle | GCLineWidth | GCJoinStyle | GCBackground | GCForeground \
88 | GCFunction | GCPlaneMask | GCFillStyle | GC_CALL_VALIDATE_BIT \
89 | GCClipXOrigin | GCClipYOrigin | GCClipMask | GCSubwindowMode )
91 static void xf4bppValidateGC(GCPtr, unsigned long, DrawablePtr);
92 static void xf4bppDestroyGC(GC *);
94 static GCFuncs vgaGCFuncs = {
95 xf4bppValidateGC,
96 (void (*)(GCPtr, unsigned long))NoopDDA,
97 (void (*)(GCPtr, unsigned long, GCPtr))NoopDDA,
98 xf4bppDestroyGC,
99 xf4bppChangeClip,
100 xf4bppDestroyClip,
101 xf4bppCopyClip,
102 { NULL }
106 static ppcPrivGC vgaPrototypeGCPriv = {
107 GXcopy, /* unsigned char rop */
108 0, /* unsigned char ropOpStip */
109 0, /* unsigned char ropFillArea */
110 {0, }, /* unsigned char unused[sizeof(long) - 3] */
111 NULL, /* mfbFillAreaProcPtr FillArea */
113 VGA_ALLPLANES, /* unsigned long planemask */
114 1, /* unsigned long fgPixel */
115 0, /* unsigned long bgPixel */
116 GXcopy, /* int alu */
117 FillSolid, /* int fillStyle */
118 }, /* ppcReducedRrop colorRrop */
119 -1, /* short lastDrawableType */
120 -1, /* short lastDrawableDepth */
121 0 /* pointer devPriv */
124 static GCOps vgaGCOps = {
125 xf4bppSolidWindowFS, /* void (* FillSpans)() */
126 xf4bppSetSpans, /* void (* SetSpans)() */
127 miPutImage, /* void (* PutImage)() */
128 xf4bppCopyArea, /* RegionPtr (* CopyArea)() */
129 miCopyPlane, /* void (* CopyPlane)() */
130 xf4bppPolyPoint, /* void (* PolyPoint)() */
131 miZeroLine, /* void (* Polylines)() */
132 miPolySegment, /* void (* PolySegment)() */
133 miPolyRectangle, /* void (* PolyRectangle)() */
134 xf4bppZeroPolyArc, /* void (* PolyArc)() */
135 miFillPolygon, /* void (* FillPolygon)() */
136 miPolyFillRect, /* void (* PolyFillRect)() */
137 xf4bppPolyFillArc, /* void (* PolyFillArc)() */
138 miPolyText8, /* int (* PolyText8)() */
139 miPolyText16, /* int (* PolyText16)() */
140 miImageText8, /* void (* ImageText8)() */
141 miImageText16, /* void (* ImageText16)() */
142 xf4bppImageGlyphBlt, /* GJA -- void (* ImageGlyphBlt)() */
143 miPolyGlyphBlt, /* GJA -- void (* PolyGlyphBlt)() */
144 miPushPixels, /* void (* PushPixels)() */
145 {NULL} /* devPrivate */
148 Bool
149 xf4bppCreateGC( pGC )
150 register GCPtr pGC ;
152 ppcPrivGC *pPriv ;
153 GCOps *pOps ;
155 if ( pGC->depth == 1 )
157 return (mfbCreateGC(pGC));
160 if ( !( pPriv = xalloc( sizeof( ppcPrivGC ) ) ) )
161 return FALSE ;
163 if ( !( pOps = xalloc( sizeof( GCOps ) ) ) ) {
164 xfree(pPriv);
165 return FALSE;
168 /* Now we initialize the GC fields */
169 pGC->miTranslate = 1;
170 pGC->unused = 0;
171 pGC->planemask = VGA_ALLPLANES;
172 pGC->fgPixel = VGA_BLACK_PIXEL;
173 pGC->bgPixel = VGA_WHITE_PIXEL;
174 pGC->funcs = &vgaGCFuncs;
175 /* ops, -- see below */
177 pGC->fExpose = TRUE;
178 pGC->freeCompClip = FALSE;
179 pGC->pRotatedPixmap = NullPixmap;
181 /* GJA: I don't like this code:
182 * they allocated a mfbPrivGC, ignore the allocated data and place
183 * a pointer to a ppcPrivGC in its slot.
185 *pPriv = vgaPrototypeGCPriv;
186 (pGC->devPrivates[mfbGetGCPrivateIndex()].ptr) = (pointer) pPriv;
188 /* Set the vgaGCOps */
189 *pOps = vgaGCOps;
190 pOps->devPrivate.val = 1;
191 pGC->ops = pOps;
193 return TRUE ;
196 static void
197 xf4bppDestroyGC( pGC )
198 register GC *pGC ;
201 TRACE( ( "xf4bppDestroyGC(pGC=0x%x)\n", pGC ) ) ;
203 /* (ef) 11/9/87 -- ppc doesn't use rotated tile or stipple, but */
204 /* *does* call mfbValidateGC under some conditions. */
205 /* mfbValidateGC *does* use rotated tile and stipple */
206 if ( pGC->pRotatedPixmap )
207 mfbDestroyPixmap( pGC->pRotatedPixmap ) ;
209 if ( pGC->freeCompClip && pGC->pCompositeClip )
210 REGION_DESTROY(pGC->pScreen, pGC->pCompositeClip);
211 if(pGC->ops->devPrivate.val) xfree( pGC->ops );
212 xfree( pGC->devPrivates[mfbGetGCPrivateIndex()].ptr ) ;
213 return ;
216 static Mask
217 ppcChangePixmapGC
219 register GC *pGC,
220 register Mask changes
223 register ppcPrivGCPtr devPriv = (ppcPrivGCPtr) (pGC->devPrivates[mfbGetGCPrivateIndex()].ptr ) ;
224 register unsigned long int idx ; /* used for stepping through bitfields */
226 #define LOWBIT( x ) ( x & - x ) /* Two's complement */
227 while ((idx = LOWBIT(changes))) {
228 switch ( idx ) {
230 case GCLineStyle:
231 case GCLineWidth:
232 pGC->ops->Polylines = ( ! pGC->lineWidth )
233 ? miZeroLine
234 : ( ( pGC->lineStyle == LineSolid )
235 ? miWideLine : miWideDash ) ;
236 changes &= ~( GCLineStyle | GCLineWidth ) ;
237 break ;
239 case GCJoinStyle:
240 changes &= ~ idx ; /* i.e. changes &= ~ GCJoinStyle */
241 break ;
243 case GCBackground:
244 if ( pGC->fillStyle != FillOpaqueStippled ) {
245 changes &= ~ idx ; /* i.e. changes &= ~GCBackground */
246 break ;
247 } /* else Fall Through */
248 case GCForeground:
249 if ( pGC->fillStyle == FillTiled ) {
250 changes &= ~ idx ; /* i.e. changes &= ~GCForeground */
251 break ;
252 } /* else Fall Through */
253 case GCFunction:
254 case GCPlaneMask:
255 case GCFillStyle:
256 { /* new_fill */
257 int fillStyle = devPriv->colorRrop.fillStyle ;
258 /* install a suitable fillspans */
259 if ( fillStyle == FillSolid )
260 pGC->ops->FillSpans = xf4bppSolidPixmapFS ;
261 else if ( fillStyle == FillStippled )
262 pGC->ops->FillSpans = xf4bppStipplePixmapFS ;
263 else if ( fillStyle == FillOpaqueStippled )
264 pGC->ops->FillSpans = xf4bppOpStipplePixmapFS ;
265 else /* fillStyle == FillTiled */
266 pGC->ops->FillSpans = xf4bppTilePixmapFS ;
267 changes &= ~( GCBackground | GCForeground
268 | GCFunction | GCPlaneMask | GCFillStyle ) ;
269 break ;
270 } /* end of new_fill */
272 default:
273 ErrorF( "ppcChangePixmapGC: Unexpected GC Change\n" ) ;
274 changes &= ~ idx ; /* Remove it anyway */
275 break ;
279 return 0 ;
282 /* Clipping conventions
283 if the drawable is a window
284 CT_REGION ==> pCompositeClip really is the composite
285 CT_other ==> pCompositeClip is the window clip region
286 if the drawable is a pixmap
287 CT_REGION ==> pCompositeClip is the translated client region
288 clipped to the pixmap boundary
289 CT_other ==> pCompositeClip is the pixmap bounding box
292 static void
293 xf4bppValidateGC( pGC, changes, pDrawable )
294 GCPtr pGC;
295 unsigned long changes;
296 DrawablePtr pDrawable;
298 register ppcPrivGCPtr devPriv ;
299 WindowPtr pWin ;
301 devPriv = (ppcPrivGCPtr) (pGC->devPrivates[mfbGetGCPrivateIndex()].ptr ) ;
303 if ( pDrawable->type != devPriv->lastDrawableType ) {
304 devPriv->lastDrawableType = pDrawable->type ;
305 xf4bppChangeGCtype( pGC, devPriv ) ;
306 changes = (unsigned)~0 ;
309 if ( pDrawable->depth == 1 ) {
310 /* ibmAbort(); */
311 xf4bppNeverCalled();
314 if ( pDrawable->type == DRAWABLE_WINDOW ) {
315 pWin = (WindowPtr) pDrawable ;
316 pGC->lastWinOrg.x = pWin->drawable.x ;
317 pGC->lastWinOrg.y = pWin->drawable.y ;
319 else {
320 pWin = (WindowPtr) NULL ;
321 pGC->lastWinOrg.x = 0 ;
322 pGC->lastWinOrg.y = 0 ;
325 changes &= ppcGCInterestValidateMask ;
326 /* If Nothing REALLY Changed, Just Return */
327 if ( pDrawable->serialNumber == (pGC->serialNumber & DRAWABLE_SERIAL_BITS) )
328 if ( !( changes &= ~ GC_CALL_VALIDATE_BIT ) )
329 return ;
331 /* GJA -- start of cfb code */
333 * if the client clip is different or moved OR the subwindowMode has
334 * changed OR the window's clip has changed since the last validation
335 * we need to recompute the composite clip
338 if ((changes & (GCClipXOrigin|GCClipYOrigin|GCClipMask|GCSubwindowMode)) ||
339 (pDrawable->serialNumber != (pGC->serialNumber & DRAWABLE_SERIAL_BITS))
342 if (pWin) {
343 RegionPtr pregWin;
344 Bool freeTmpClip, freeCompClip;
346 if (pGC->subWindowMode == IncludeInferiors) {
347 pregWin = NotClippedByChildren(pWin);
348 freeTmpClip = TRUE;
350 else {
351 pregWin = &pWin->clipList;
352 freeTmpClip = FALSE;
354 freeCompClip = pGC->freeCompClip;
357 * if there is no client clip, we can get by with just keeping
358 * the pointer we got, and remembering whether or not should
359 * destroy (or maybe re-use) it later. this way, we avoid
360 * unnecessary copying of regions. (this wins especially if
361 * many clients clip by children and have no client clip.)
363 if (pGC->clientClipType == CT_NONE) {
364 if (freeCompClip)
365 REGION_DESTROY(pGC->pScreen, pGC->pCompositeClip);
366 pGC->pCompositeClip = pregWin;
367 pGC->freeCompClip = freeTmpClip;
369 else {
371 * we need one 'real' region to put into the composite
372 * clip. if pregWin the current composite clip are real,
373 * we can get rid of one. if pregWin is real and the
374 * current composite clip isn't, use pregWin for the
375 * composite clip. if the current composite clip is real
376 * and pregWin isn't, use the current composite clip. if
377 * neither is real, create a new region.
380 REGION_TRANSLATE(pGC->pScreen, pGC->clientClip,
381 pDrawable->x + pGC->clipOrg.x,
382 pDrawable->y + pGC->clipOrg.y);
384 if (freeCompClip)
386 REGION_INTERSECT(pGC->pScreen, pGC->pCompositeClip,
387 pregWin, pGC->clientClip);
388 if (freeTmpClip)
389 REGION_DESTROY(pGC->pScreen, pregWin);
391 else if (freeTmpClip)
393 REGION_INTERSECT(pGC->pScreen, pregWin, pregWin,
394 pGC->clientClip);
395 pGC->pCompositeClip = pregWin;
397 else
399 pGC->pCompositeClip = REGION_CREATE(pGC->pScreen, NullBox, 0);
400 REGION_INTERSECT(pGC->pScreen, pGC->pCompositeClip,
401 pregWin, pGC->clientClip);
403 pGC->freeCompClip = TRUE;
404 REGION_TRANSLATE(pGC->pScreen, pGC->clientClip,
405 -(pDrawable->x + pGC->clipOrg.x),
406 -(pDrawable->y + pGC->clipOrg.y));
409 } /* end of composite clip for a window */
410 else {
411 BoxRec pixbounds;
413 /* XXX should we translate by drawable.x/y here ? */
414 pixbounds.x1 = 0;
415 pixbounds.y1 = 0;
416 pixbounds.x2 = pDrawable->width;
417 pixbounds.y2 = pDrawable->height;
419 if (pGC->freeCompClip) {
420 REGION_RESET(pGC->pScreen, pGC->pCompositeClip, &pixbounds);
421 } else {
422 pGC->freeCompClip = TRUE;
423 pGC->pCompositeClip = REGION_CREATE(pGC->pScreen, &pixbounds, 1);
426 if (pGC->clientClipType == CT_REGION)
428 REGION_TRANSLATE(pGC->pScreen, pGC->pCompositeClip,
429 -pGC->clipOrg.x, -pGC->clipOrg.y);
430 REGION_INTERSECT(pGC->pScreen, pGC->pCompositeClip,
431 pGC->pCompositeClip, pGC->clientClip);
432 REGION_TRANSLATE(pGC->pScreen, pGC->pCompositeClip,
433 pGC->clipOrg.x, pGC->clipOrg.y);
435 } /* end of composute clip for pixmap */
437 /* GJA -- End of cfb code */
439 changes &= ~ ( GCClipXOrigin | GCClipYOrigin | GCClipMask | GCSubwindowMode
440 | GC_CALL_VALIDATE_BIT ) ;
442 /* If needed, Calculate the Color Reduced Raster-Op */
443 if ( changes & ( GCFillStyle | GCBackground | GCForeground
444 | GCPlaneMask | GCFunction ) )
445 xf4bppGetReducedColorRrop( pGC, pDrawable->depth,
446 &devPriv->colorRrop ) ;
448 (* ( ( pDrawable->type == DRAWABLE_WINDOW )
449 ? xf4bppChangeWindowGC
450 : ppcChangePixmapGC ) )( pGC, changes ) ;
452 return ;