summaryrefslogtreecommitdiff
path: root/xc/programs/Xserver/hw/xfree86/xf4bpp/ppcGC.c
blob: 67c6e5c883a915d952733a7c91884961b182ce88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
/* $XFree86: xc/programs/Xserver/hw/xfree86/xf4bpp/ppcGC.c,v 1.4 1999/06/06 08:48:59 dawes Exp $ */
/*

Copyright (c) 1987  X Consortium

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

Except as contained in this notice, the name of the X Consortium shall
not be used in advertising or otherwise to promote the sale, use or
other dealings in this Software without prior written authorization
from the X Consortium.


Copyright IBM Corporation 1987,1988,1989
All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that 
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of IBM not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.


Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Digital not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.

*/

/* $XConsortium: ppcGC.c /main/6 1996/02/21 17:57:38 kaleb $ */

#include "xf4bpp.h"
#include "mfbmap.h"
#include "mfb.h"
#include "mi.h"
#include "scrnintstr.h"
#include "ppcGCstr.h"
#include "vgaVideo.h"
#include "ibmTrace.h"

#define ppcGCInterestValidateMask \
( GCLineStyle | GCLineWidth | GCJoinStyle | GCBackground | GCForeground \
| GCFunction | GCPlaneMask | GCFillStyle | GC_CALL_VALIDATE_BIT         \
| GCClipXOrigin | GCClipYOrigin | GCClipMask | GCSubwindowMode )


/* GJA -- we modified the following function to get rid of
 * the records in file vgaData.c
 */
static GCFuncs vgaGCFuncs = {
	xf4bppValidateGC,
	(void (*)())NoopDDA,
	(void (*)())NoopDDA,
	xf4bppDestroyGC,
	xf4bppChangeClip,
	xf4bppDestroyClip,
	xf4bppCopyClip
};


static ppcPrivGC vgaPrototypeGCPriv = {
	GXcopy,	/* unsigned char	rop */
	0,	/* unsigned char	ropOpStip */
	0,	/* unsigned char	ropFillArea */
	{0, },	/* unsigned char	unused[sizeof(long) - 3] */
	xf4bppAreaFill,	/* void 	(* FillArea)() */
		{
		    VGA_ALLPLANES,	/* unsigned long	planemask */
		    1,			/* unsigned long	fgPixel */
		    0,			/* unsigned long	bgPixel */
		    GXcopy,		/* int			alu */
		    FillSolid,		/* int			fillStyle */
		}, /* ppcReducedRrop	colorRrop  */
	-1,	/* short lastDrawableType */
	-1,	/* short lastDrawableDepth */
	0	/* pointer devPriv */
} ;

static GCOps vgaGCOps = {
	xf4bppSolidWindowFS,	/*  void (* FillSpans)() */
	xf4bppSetSpans,		/*  void (* SetSpans)()	 */
	miPutImage,		/*  void (* PutImage)()	 */
	xf4bppCopyArea,		/*  RegionPtr (* CopyArea)()	 */
	miCopyPlane,		/*  void (* CopyPlane)() */
	xf4bppPolyPoint,		/*  void (* PolyPoint)() */
	miZeroLine,		/*  void (* Polylines)() */
	miPolySegment,		/*  void (* PolySegment)() */
	miPolyRectangle,	/*  void (* PolyRectangle)() */
	xf4bppZeroPolyArc,		/*  void (* PolyArc)()	 */
	miFillPolygon,		/*  void (* FillPolygon)() */
	miPolyFillRect,		/*  void (* PolyFillRect)() */
	xf4bppPolyFillArc,		/*  void (* PolyFillArc)() */
	miPolyText8,		/*  int (* PolyText8)()	 */
	miPolyText16,		/*  int (* PolyText16)() */
	miImageText8,		/*  void (* ImageText8)() */
	miImageText16,		/*  void (* ImageText16)() */
	(void (*)())xf4bppImageGlyphBlt,	/*  GJA -- void (* ImageGlyphBlt)() */
	miPolyGlyphBlt,		/*  GJA -- void (* PolyGlyphBlt)() */
	miPushPixels,		/*  void (* PushPixels)() */
#ifdef NEED_LINEHELPER
	miMiter,		/*  void (* LineHelper)() */
#endif
	NULL
};

Bool
xf4bppCreateGC( pGC )
register GCPtr pGC ;
{
	ppcPrivGC *pPriv ;
	GCOps *pOps ;

	if ( pGC->depth == 1 )
		{
		return (mfbCreateGC(pGC));
		}

	if ( !( pPriv = xalloc( sizeof( ppcPrivGC ) ) ) )
		return FALSE ;

	if ( !( pOps = xalloc( sizeof( GCOps ) ) ) ) {
		xfree(pPriv);
		return FALSE;
	}
	
        /* Now we initialize the GC fields */
	pGC->miTranslate = 1;
	pGC->unused = 0;
	pGC->planemask = VGA_ALLPLANES;
	pGC->fgPixel = VGA_BLACK_PIXEL;
	pGC->bgPixel = VGA_WHITE_PIXEL;
	pGC->funcs = &vgaGCFuncs;
	/* ops, -- see below */

	pGC->fExpose = TRUE;
	pGC->freeCompClip = FALSE;
	pGC->pRotatedPixmap = NullPixmap;
	
	/* GJA: I don't like this code:
         * they allocated a mfbPrivGC, ignore the allocated data and place
         * a pointer to a ppcPrivGC in its slot.
         */
	*pPriv = vgaPrototypeGCPriv;
	(pGC->devPrivates[mfbGCPrivateIndex].ptr) = (pointer) pPriv;

	/* Set the vgaGCOps */
	*pOps = vgaGCOps;
	pOps->devPrivate.val = 1;
	pGC->ops = pOps;

	return TRUE ;
}

void
xf4bppDestroyGC( pGC )
    register GC	*pGC ;

{
    TRACE( ( "xf4bppDestroyGC(pGC=0x%x)\n", pGC ) ) ;

    /* (ef) 11/9/87 -- ppc doesn't use rotated tile or stipple, but */
    /*		*does* call mfbValidateGC under some conditions.    */
    /*		mfbValidateGC *does* use rotated tile and stipple   */
    if ( pGC->pRotatedPixmap )
	mfbDestroyPixmap( pGC->pRotatedPixmap ) ;

    if ( pGC->freeCompClip && pGC->pCompositeClip )
	REGION_DESTROY(pGC->pScreen, pGC->pCompositeClip);
    if(pGC->ops->devPrivate.val) xfree( pGC->ops );
    xfree( pGC->devPrivates[mfbGCPrivateIndex].ptr ) ;
    return ;
}

static Mask
ppcChangePixmapGC
(
	register GC *pGC,
	register Mask changes
)
{
register ppcPrivGCPtr devPriv = (ppcPrivGCPtr) (pGC->devPrivates[mfbGCPrivateIndex].ptr ) ;
register unsigned long int idx ; /* used for stepping through bitfields */

#define LOWBIT( x ) ( x & - x ) /* Two's complement */
while ((idx = LOWBIT(changes))) {
    switch ( idx ) {

	case GCLineStyle:
	case GCLineWidth:
	    pGC->ops->Polylines = ( ! pGC->lineWidth )
		 ? miZeroLine
		 : ( ( pGC->lineStyle == LineSolid )
			 ? miWideLine : miWideDash ) ;
	    changes &= ~( GCLineStyle | GCLineWidth ) ;
	    break ;

	case GCJoinStyle:
#ifdef NEED_LINEHELPER
	    pGC->ops->LineHelper = ( pGC->joinStyle == JoinMiter )
			    ? miMiter : miNotMiter ;
#endif
	    changes &= ~ idx ; /* i.e. changes &= ~ GCJoinStyle */
	    break ;

	case GCBackground:
	    if ( pGC->fillStyle != FillOpaqueStippled ) {
		changes &= ~ idx ; /* i.e. changes &= ~GCBackground */
		break ;
	    } /* else Fall Through */
	case GCForeground:
	    if ( pGC->fillStyle == FillTiled ) {
		changes &= ~ idx ; /* i.e. changes &= ~GCForeground */
		break ;
	    } /* else Fall Through */
	case GCFunction:
	case GCPlaneMask:
	case GCFillStyle:
	    { /* new_fill */
		int fillStyle = devPriv->colorRrop.fillStyle ;
		/* install a suitable fillspans */
		if ( fillStyle == FillSolid )
		    pGC->ops->FillSpans = xf4bppSolidPixmapFS ;
		else if ( fillStyle == FillStippled )
		    pGC->ops->FillSpans = xf4bppStipplePixmapFS ;
		else if ( fillStyle == FillOpaqueStippled )
		    pGC->ops->FillSpans = xf4bppOpStipplePixmapFS ;
		else /*  fillStyle == FillTiled */
		    pGC->ops->FillSpans = xf4bppTilePixmapFS ;
		changes &= ~( GCBackground | GCForeground
			    | GCFunction | GCPlaneMask | GCFillStyle ) ;
		break ;
	    } /* end of new_fill */

	default:
	    ErrorF( "ppcChangePixmapGC: Unexpected GC Change\n" ) ;
	    changes &= ~ idx ; /* Remove it anyway */
	    break ;
	}
}

return 0 ;
}

/* Clipping conventions
	if the drawable is a window
	    CT_REGION ==> pCompositeClip really is the composite
	    CT_other ==> pCompositeClip is the window clip region
	if the drawable is a pixmap
	    CT_REGION ==> pCompositeClip is the translated client region
		clipped to the pixmap boundary
	    CT_other ==> pCompositeClip is the pixmap bounding box
*/

void
xf4bppValidateGC( pGC, changes, pDrawable )
    register GCPtr	pGC ;
    register Mask	changes ;
    DrawablePtr		pDrawable ;
{
    register ppcPrivGCPtr devPriv ;
    WindowPtr pWin ;

    devPriv = (ppcPrivGCPtr) (pGC->devPrivates[mfbGCPrivateIndex].ptr ) ;

    if ( pDrawable->type != devPriv->lastDrawableType ) {
	devPriv->lastDrawableType = pDrawable->type ;
	xf4bppChangeGCtype( pGC, devPriv ) ;
	changes = (unsigned)~0 ;
    }

    if ( pDrawable->depth == 1 ) {
/*	ibmAbort(); */
	xf4bppNeverCalled();
    }

    if ( pDrawable->type == DRAWABLE_WINDOW ) {
	pWin = (WindowPtr) pDrawable ;
	pGC->lastWinOrg.x = pWin->drawable.x ;
	pGC->lastWinOrg.y = pWin->drawable.y ;
    }
    else {
	pWin = (WindowPtr) NULL ;
	pGC->lastWinOrg.x = 0 ;
	pGC->lastWinOrg.y = 0 ;
    }

    changes &= ppcGCInterestValidateMask ;
    /* If Nothing REALLY Changed, Just Return */
    if ( pDrawable->serialNumber == (pGC->serialNumber & DRAWABLE_SERIAL_BITS) )
	if ( !( changes &= ~ GC_CALL_VALIDATE_BIT ) )
	    return ;

    /* GJA -- start of cfb code */
    /*
     * if the client clip is different or moved OR the subwindowMode has
     * changed OR the window's clip has changed since the last validation
     * we need to recompute the composite clip 
     */
  
     if ((changes & (GCClipXOrigin|GCClipYOrigin|GCClipMask|GCSubwindowMode)) ||
 	(pDrawable->serialNumber != (pGC->serialNumber & DRAWABLE_SERIAL_BITS))
 	)
     {
 	ScreenPtr pScreen = pGC->pScreen;
  
 	if (pWin) {
 	    RegionPtr   pregWin;
 	    Bool        freeTmpClip, freeCompClip;
  
 	    if (pGC->subWindowMode == IncludeInferiors) {
 		pregWin = NotClippedByChildren(pWin);
 		freeTmpClip = TRUE;
  	    }
  	    else {
 		pregWin = &pWin->clipList;
 		freeTmpClip = FALSE;
  	    }
 	    freeCompClip = pGC->freeCompClip;
  
 	    /*
 	     * if there is no client clip, we can get by with just keeping
 	     * the pointer we got, and remembering whether or not should
 	     * destroy (or maybe re-use) it later.  this way, we avoid
 	     * unnecessary copying of regions.  (this wins especially if
 	     * many clients clip by children and have no client clip.) 
 	     */
 	    if (pGC->clientClipType == CT_NONE) {
 		if (freeCompClip)
 		    REGION_DESTROY(pScreen, pGC->pCompositeClip);
 		pGC->pCompositeClip = pregWin;
 		pGC->freeCompClip = freeTmpClip;
  	    }
  	    else {
 		/*
 		 * we need one 'real' region to put into the composite
 		 * clip. if pregWin the current composite clip are real,
 		 * we can get rid of one. if pregWin is real and the
 		 * current composite clip isn't, use pregWin for the
 		 * composite clip. if the current composite clip is real
 		 * and pregWin isn't, use the current composite clip. if
 		 * neither is real, create a new region. 
 		 */
  
 		REGION_TRANSLATE(pScreen, pGC->clientClip,
				 pDrawable->x + pGC->clipOrg.x,
				 pDrawable->y + pGC->clipOrg.y);
 						  
 		if (freeCompClip)
 		{
 		    REGION_INTERSECT(pGC->pScreen, pGC->pCompositeClip,
				     pregWin, pGC->clientClip);
 		    if (freeTmpClip)
 			REGION_DESTROY(pScreen, pregWin);
  		}
 		else if (freeTmpClip)
 		{
 		    REGION_INTERSECT(pScreen, pregWin, pregWin,
				     pGC->clientClip);
 		    pGC->pCompositeClip = pregWin;
  		}
 		else
 		{
 		    pGC->pCompositeClip = REGION_CREATE(pScreen, NullBox, 0);
 		    REGION_INTERSECT(pScreen, pGC->pCompositeClip,
				     pregWin, pGC->clientClip);
 		}
 		pGC->freeCompClip = TRUE;
 		REGION_TRANSLATE(pScreen, pGC->clientClip,
				 -(pDrawable->x + pGC->clipOrg.x),
				 -(pDrawable->y + pGC->clipOrg.y));
 						  
  	    }
 	}			/* end of composite clip for a window */
  	else {
 	    BoxRec      pixbounds;
  
 	    /* XXX should we translate by drawable.x/y here ? */
 	    pixbounds.x1 = 0;
 	    pixbounds.y1 = 0;
 	    pixbounds.x2 = pDrawable->width;
 	    pixbounds.y2 = pDrawable->height;
  
 	    if (pGC->freeCompClip) {
 		REGION_RESET(pScreen, pGC->pCompositeClip, &pixbounds);
  	    } else {
 		pGC->freeCompClip = TRUE;
 		pGC->pCompositeClip = REGION_CREATE(pScreen, &pixbounds, 1);
  	    }
  
 	    if (pGC->clientClipType == CT_REGION)
 	    {
 		REGION_TRANSLATE(pScreen, pGC->pCompositeClip,
				 -pGC->clipOrg.x, -pGC->clipOrg.y);
 		REGION_INTERSECT(pScreen, pGC->pCompositeClip,
				 pGC->pCompositeClip, pGC->clientClip);
 		REGION_TRANSLATE(pScreen, pGC->pCompositeClip,
				 pGC->clipOrg.x, pGC->clipOrg.y);
 	    }
	}			/* end of composute clip for pixmap */
     }
    /* GJA -- End of cfb code */

    changes &= ~ ( GCClipXOrigin | GCClipYOrigin | GCClipMask | GCSubwindowMode
		| GC_CALL_VALIDATE_BIT ) ;

    /* If needed, Calculate the Color Reduced Raster-Op */
    if ( changes & ( GCFillStyle | GCBackground | GCForeground
		   | GCPlaneMask | GCFunction ) )
		xf4bppGetReducedColorRrop( pGC, pDrawable->depth,
					&devPriv->colorRrop ) ;

	(* ( ( pDrawable->type == DRAWABLE_WINDOW )
	     ? xf4bppChangeWindowGC
	     : ppcChangePixmapGC ) )( pGC, changes ) ;

    return ;
}