summaryrefslogtreecommitdiff
path: root/xc/programs/Xserver/hw/xfree86/vga16/ibm/ppcPushPxl.c
blob: 357624738884e2f53fe573765b1f8ad767d453c2 (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
/* $XConsortium: ppcPushPxl.c,v 1.2 94/10/12 21:06:18 kaleb Exp $ */
/* $XFree86: xc/programs/Xserver/hw/xfree86/vga16/ibm/ppcPushPxl.c,v 3.0 1994/05/04 15:03:34 dawes Exp $ */
/*
 * 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.
 *
*/


/* ppc PushPixels */

#include "X.h"
#include "misc.h"
#include "gcstruct.h"
#include "windowstr.h"
#include "regionstr.h"
#include "pixmapstr.h"
#include "scrnintstr.h"
#include "miscstruct.h"

#include "ppc.h"
#include "ppcBitMacs.h"

#include "OScompiler.h"
#include "ibmTrace.h"

extern int mfbGCPrivateIndex;

static void
BitMapMerge( pDst, pSrc, pStp, xOffset, yOffset, srcInvert )
PixmapPtr	pDst;
PixmapPtr	pSrc ;
PixmapPtr	pStp ;
int		xOffset, yOffset ; /* Offset To Stipple Tmp bitmap */
int		srcInvert ; /* used for opaqueness */
{
register unsigned long int	bits ;
register unsigned long int	*bitptr ;
register int			wordOffset ;
register unsigned long int	*pDstPriv =
			(unsigned long int *) pDst->devPrivate.ptr ;
unsigned long int	*pSrcPriv =
			(unsigned long int *) pSrc->devPrivate.ptr ;
register int			j ;
register int			i ;
register unsigned long int	*pStipSrc ;
unsigned long int	*pStpPriv = (unsigned long int *) pStp->devPrivate.ptr ;
unsigned long int	stipOffset ;
unsigned long int	stpWidth	= pStp->drawable.width ;
unsigned long int	stpPaddedWidth	= pStp->devKind >> 2 ;
unsigned long int	stpHeight	= pStp->drawable.height ;
unsigned long int	dstHeight	= pDst->drawable.height ;
unsigned long int	dstWidth	= pDst->devKind >> 2 ;

if ( ( xOffset %= stpWidth ) < 0 )
	xOffset += stpWidth ;
if ( ( yOffset %= stpHeight ) < 0 )
	yOffset += stpHeight ;

if ( stpWidth > 32 ) {
	/* **************************** */
	/* Only Works if stpWidth >= 32 */
	/* **************************** */
	if ( srcInvert )
		for ( i = 0 ; i < dstHeight ; i++ ) { /* For Each Line */
			pStipSrc = pStpPriv
				+ ( ( ( yOffset + i ) % stpHeight ) * stpPaddedWidth ) ;
			for ( j = dstWidth, stipOffset = xOffset ; j-- ; ) {
				wordOffset = stipOffset & 0x1F ;
				if ( stipOffset <= stpWidth - 32 ) {
					bitptr = pStipSrc + ( stipOffset >> 5 ) ;
				  bits = SCRLEFT( bitptr[0], wordOffset )
					 | SCRRIGHT( bitptr[1],
					      ( 32 - wordOffset )) ;
				}
				else { /* stipOffset > stpWidth - 32 */
				    bits = SCRLEFT(
					   pStipSrc[ stipOffset >> 5 ],
					    wordOffset )
					 | SCRRIGHT( pStipSrc[0],
						( 32 - wordOffset )) ;
					stipOffset -= stpWidth ;
				}
				*pDstPriv++ = *pSrcPriv++ & ~ bits ;
			}
		}
	else
		for ( i = 0 ; i < dstHeight ; i++ ) { /* For Each Line */
			pStipSrc = pStpPriv
				+ ( ( ( yOffset + i ) % stpHeight ) * stpPaddedWidth ) ;
			for ( j = dstWidth, stipOffset = xOffset ; j-- ; ) {
				wordOffset = stipOffset & 0x1F ;
				if ( stipOffset <= stpWidth - 32 ) {
					bitptr = pStipSrc + ( stipOffset >> 5 ) ;
					bits = SCRLEFT( bitptr[0], wordOffset )
					     | SCRRIGHT( bitptr[1],
							 ( 32 - wordOffset ) ) ;
				}
				else { /* stipOffset > stpWidth - 32 */
					bits = SCRLEFT(
						pStipSrc[ stipOffset >> 5 ],
						wordOffset )
					     | SCRRIGHT( pStipSrc[0],
							 ( 32 - wordOffset ) ) ;
					stipOffset -= stpWidth ;
				}
				*pDstPriv++ = *pSrcPriv++ & bits ;
			}
		}
}
else { /* stpWidth <= 32 */
	for ( i = stpWidth ; i < 32 ; i <<= 1 ) ; /* Test For A Power Of 2 */
	if ( i == 32 ) { /* Best Case - Started w/ Power Of 2 */
	   if (srcInvert) {
		for ( i = 0 ; i < dstHeight ; i++ ) { /* For Each Line */
				bits = pStpPriv[ ( yOffset + i ) % stpHeight ] ;
			/* Pad Out The Bit Mask To A Full Word */
			for ( j = stpWidth ; j != 32 ; j <<= 1 )
				bits |= SCRRIGHT( bits, j ) ;
			/* If Needed Rotate The Mask */
			if ( xOffset )
				bits = SCRLEFT( bits, xOffset )
				     | SCRRIGHT( bits, 32 - xOffset ) ;
			/* For Each Word In The Line */
			for ( j = dstWidth ; j-- ; )
				*pDstPriv++ = *pSrcPriv++ & ~bits ;
		}
	   } else {
		for ( i = 0 ; i < dstHeight ; i++ ) { /* For Each Line */
				bits = pStpPriv[ ( yOffset + i ) % stpHeight ] ;
			/* Pad Out The Bit Mask To A Full Word */
			for ( j = stpWidth ; j != 32 ; j <<= 1 )
				bits |= SCRRIGHT( bits, j ) ;
			/* If Needed Rotate The Mask */
			if ( xOffset )
				bits = SCRLEFT( bits, xOffset )
				     | SCRRIGHT( bits, 32 - xOffset ) ;
			/* For Each Word In The Line */
			for ( j = dstWidth ; j-- ; )
				*pDstPriv++ = *pSrcPriv++ & bits ;
		}
	   }
	} else { /* Case - Didn't Start w/ Power Of 2 */
		int goalWidth = i >> 1 ;
	   if (srcInvert) {

		for ( i = 0 ; i < dstHeight ; i++ ) { /* For Each Line */
				bits = pStpPriv[ ( yOffset + i ) % stpHeight ] ;
			/* Pad Out The Bit Mask To A Full Word */
			for ( j = stpWidth ; j <= goalWidth ; j <<= 1 )
				bits |= SCRRIGHT( bits, j ) ;
			/* If Needed Rotate The Mask */
			if ( xOffset )
				bits = ~(SCRLEFT( bits, xOffset )
				     | SCRRIGHT( bits, goalWidth - xOffset)) ;
			/* For Each Word In The Line */
			for ( j = dstWidth ; j-- ; ) {
				*pDstPriv++ = *pSrcPriv++ & bits ;
				bits = ~(SCRLEFT( bits, 32 - goalWidth )
				     | SCRRIGHT( bits,
						( goalWidth << 1 ) - 32 )) ;
			}
		}
	   } else {
		for ( i = 0 ; i < dstHeight ; i++ ) { /* For Each Line */
				bits = pStpPriv[ ( yOffset + i ) % stpHeight ] ;
			/* Pad Out The Bit Mask To A Full Word */
			for ( j = stpWidth ; j <= goalWidth ; j <<= 1 )
				bits |= SCRRIGHT( bits, j ) ;
			/* If Needed Rotate The Mask */
			if ( xOffset )
				bits = SCRLEFT( bits, xOffset )
				     | SCRRIGHT( bits, goalWidth - xOffset ) ;
			/* For Each Word In The Line */
			for ( j = dstWidth ; j-- ; ) {
				*pDstPriv++ = *pSrcPriv++ & bits ;
				bits = SCRLEFT( bits, 32 - goalWidth )
				     | SCRRIGHT( bits,
						( goalWidth << 1 ) - 32 ) ;
			}
		}
	   }
	}
}

return ;
}

/* Note: pushPixels operates with the current Fill Style
	 thus the ppc's colorRrop is initially valid.
*/

void
ppcPushPixels( pGC, pBitMap, pDrawable, dx, dy, xOrg, yOrg )
    GCPtr	pGC ;
    PixmapPtr	pBitMap ;
    DrawablePtr pDrawable ;
    int		dx, dy, xOrg, yOrg ;
{
ppcPrivGC		*gcPriv  = (ppcPrivGC *) ( pGC->devPrivates[mfbGCPrivateIndex].ptr ) ;
ScreenPtr		pScrn ;
ppcScrnPriv		*scrPriv ;
RegionPtr		prgnDst ;
int			alu ;
int			fillStyle ;
int			xSrc, ySrc ;
BoxPtr			pbox ;
unsigned int		nbox ;

if ( ( pDrawable->type != DRAWABLE_WINDOW )
  || ( fillStyle = gcPriv->colorRrop.fillStyle ) == FillTiled ) {
	miPushPixels( pGC, pBitMap, pDrawable, dx, dy, xOrg, yOrg ) ;
	return ;
}
pScrn   = (ScreenPtr) pDrawable->pScreen ;
scrPriv = (ppcScrnPriv *) ( pScrn->devPrivate ) ;

/* Note: pushPixels operates with the current Fill Style
	 thus the ppc's colorRrop is initially valid. */
if ( ( alu = gcPriv->colorRrop.alu ) == GXnoop )
	return ;

/* Find The Actual Regions To Fill
 * by intersecting the destination's clip-region with
 * the box defined by our arguments.
 */
{
	BoxRec		dstBox ;

	dstBox.x2 = ( dstBox.x1 = xOrg ) + dx ;
	dstBox.y2 = ( dstBox.y1 = yOrg ) + dy ;

	prgnDst = (* pScrn->RegionCreate )( &dstBox,
					    REGION_NUM_RECTS(gcPriv->pCompositeClip));
	(* pScrn->Intersect)( prgnDst, prgnDst, gcPriv->pCompositeClip ) ;
	if ( !( nbox = REGION_NUM_RECTS(prgnDst))) {
	   (* pScrn->RegionDestroy)( prgnDst ) ;
	   return;
        } 
 	pbox = REGION_RECTS(prgnDst);
}

/* ASSUME ( pDrawable->type == DRAWABLE_WINDOW ) */
xSrc = pGC->patOrg.x + pDrawable->x ;
ySrc = pGC->patOrg.y + pDrawable->y ;

{ /* Begin Sub-Block */
	PixmapPtr		ptmpBitmap = (PixmapPtr) 0 ;
				/* Temp bitmap Make Sure It's Zero'ed Here */
	int			BitmapIsCopy = FALSE ;
	unsigned long int	fg = gcPriv->colorRrop.fgPixel ;
	unsigned long int	bg = gcPriv->colorRrop.bgPixel ;
	unsigned long int	pm = gcPriv->colorRrop.planemask ;

	/* Now Do The Needed Fill */
	switch ( fillStyle ) {

		case FillOpaqueStippled : { /* Create two (2) Tmp stipples */
			/* Create The Scratch Bitmap */
			ptmpBitmap = (* pScrn->CreatePixmap)( pScrn,
							pBitMap->drawable.width,
							pBitMap->drawable.height, 1 ) ;

			/* Now take the logical "AND-Not" of the pBitmap argument
			 * and the GC's stipple */
			BitMapMerge( ptmpBitmap, pBitMap, pGC->stipple,
				     ( xOrg - xSrc ), ( yOrg - ySrc ), TRUE ) ;
			for ( nbox = REGION_NUM_RECTS(prgnDst), pbox = REGION_RECTS(prgnDst);
			      nbox-- ;
			      pbox++ ) {
				vgaFillStipple( (WindowPtr)pDrawable,
					      ptmpBitmap, bg, alu, pm,
					      pbox->x1,
					      pbox->y1,
					      pbox->x2 - pbox->x1,
					      pbox->y2 - pbox->y1,
					      xOrg, yOrg ) ;
				}
			} /* Now Fall-Though To Do Foreground */
		case FillStippled : /* Create Tmp stipple from pBitmap AND stipple */
			if ( !ptmpBitmap ) {
				ptmpBitmap = (* pScrn->CreatePixmap)( pScrn,
								pBitMap->drawable.width,
								pBitMap->drawable.height, 1 ) ;
			}
			/* Now take the logical "AND" of the GC's stipple
			 * and the pBitmap argument */
			BitMapMerge( ptmpBitmap, pBitMap, pGC->stipple,
				     ( xOrg - xSrc ), ( yOrg - ySrc ), FALSE ) ;

			/* Now Fall-Though To REALLY Do Foreground */
		case FillSolid : /* Easiest case -- Just Stipple it in ! */
			if ( !ptmpBitmap ) {
				ptmpBitmap = pBitMap ;
				BitmapIsCopy = TRUE ;
			}
			for ( nbox = REGION_NUM_RECTS(prgnDst), pbox = REGION_RECTS(prgnDst);
			      nbox-- ;
			      pbox++ ) {
				vgaFillStipple( (WindowPtr)pDrawable,
					      ptmpBitmap, fg, alu, pm,
					      pbox->x1,
					      pbox->y1,
					      pbox->x2 - pbox->x1,
					      pbox->y2 - pbox->y1,
					      xOrg, yOrg ) ;
				}
			if ( BitmapIsCopy == FALSE )
				(* pScrn->DestroyPixmap)( ptmpBitmap ) ;
			break ;

		case FillTiled : /* Hardest case */
			/* Not Yet Implimented Here -- Calls "mi" above */
			break ;
		default :
			ErrorF( "ppcPushPixels: Unknown fill Style\n" ) ;
			break ;
	}
} /* End Sub-Block */
(* pScrn->RegionDestroy)( prgnDst ) ;

return ;
}