1706f2543Smrg
2706f2543Smrg#ifdef HAVE_XORG_CONFIG_H
3706f2543Smrg#include <xorg-config.h>
4706f2543Smrg#endif
5706f2543Smrg
6706f2543Smrg#include "misc.h"
7706f2543Smrg#include "xf86.h"
8706f2543Smrg#include "xf86_OSproc.h"
9706f2543Smrg
10706f2543Smrg#include <X11/X.h>
11706f2543Smrg#include "scrnintstr.h"
12706f2543Smrg#include "pixmapstr.h"
13706f2543Smrg#include "xf86str.h"
14706f2543Smrg#include "mi.h"
15706f2543Smrg#include "mispans.h"
16706f2543Smrg#include "xaa.h"
17706f2543Smrg#include "xaalocal.h"
18706f2543Smrg
19706f2543Smrg
20706f2543Smrgstatic void XAARenderSolidSpans(
21706f2543Smrg	GCPtr, int, DDXPointPtr, int*, int, int, int);
22706f2543Smrgstatic void XAARenderColor8x8Spans(
23706f2543Smrg	GCPtr, int, DDXPointPtr, int*, int, int, int);
24706f2543Smrgstatic void XAARenderMono8x8Spans(
25706f2543Smrg	GCPtr, int, DDXPointPtr, int*, int, int, int);
26706f2543Smrgstatic void XAARenderCacheBltSpans(
27706f2543Smrg	GCPtr, int, DDXPointPtr, int*, int, int, int);
28706f2543Smrgstatic void XAARenderColorExpandSpans(
29706f2543Smrg	GCPtr, int, DDXPointPtr, int*, int, int, int);
30706f2543Smrgstatic void XAARenderCacheExpandSpans(
31706f2543Smrg	GCPtr, int, DDXPointPtr, int*, int, int, int);
32706f2543Smrgstatic void XAARenderPixmapCopySpans(
33706f2543Smrg	GCPtr, int, DDXPointPtr, int*, int, int, int);
34706f2543Smrg
35706f2543Smrgvoid
36706f2543SmrgXAAFillSpans(
37706f2543Smrg    DrawablePtr pDraw,
38706f2543Smrg    GC		*pGC,
39706f2543Smrg    int		nInit,		/* number of spans to fill */
40706f2543Smrg    DDXPointPtr pptInit,	/* pointer to list of start points */
41706f2543Smrg    int *pwidthInit,		/* pointer to list of n widths */
42706f2543Smrg    int fSorted
43706f2543Smrg){
44706f2543Smrg    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
45706f2543Smrg    int type = 0;
46706f2543Smrg    ClipAndRenderSpansFunc function;
47706f2543Smrg    Bool fastClip = FALSE;
48706f2543Smrg
49706f2543Smrg    if((nInit <= 0) || !pGC->planemask)
50706f2543Smrg        return;
51706f2543Smrg
52706f2543Smrg    if(!RegionNumRects(pGC->pCompositeClip))
53706f2543Smrg	return;
54706f2543Smrg
55706f2543Smrg    switch(pGC->fillStyle) {
56706f2543Smrg    case FillSolid:
57706f2543Smrg	type = DO_SOLID;
58706f2543Smrg	break;
59706f2543Smrg    case FillStippled:
60706f2543Smrg	type = (*infoRec->StippledFillChooser)(pGC);
61706f2543Smrg	break;
62706f2543Smrg    case FillOpaqueStippled:
63706f2543Smrg	if((pGC->fgPixel == pGC->bgPixel) && infoRec->FillSpansSolid &&
64706f2543Smrg                CHECK_PLANEMASK(pGC,infoRec->FillSpansSolidFlags) &&
65706f2543Smrg                CHECK_ROP(pGC,infoRec->FillSpansSolidFlags) &&
66706f2543Smrg                CHECK_ROPSRC(pGC,infoRec->FillSpansSolidFlags) &&
67706f2543Smrg                CHECK_FG(pGC,infoRec->FillSpansSolidFlags))
68706f2543Smrg	    type = DO_SOLID;
69706f2543Smrg	else
70706f2543Smrg	    type = (*infoRec->OpaqueStippledFillChooser)(pGC);
71706f2543Smrg	break;
72706f2543Smrg    case FillTiled:
73706f2543Smrg	type = (*infoRec->TiledFillChooser)(pGC);
74706f2543Smrg	break;
75706f2543Smrg    }
76706f2543Smrg
77706f2543Smrg    switch(type) {
78706f2543Smrg    case DO_SOLID:
79706f2543Smrg	function = XAARenderSolidSpans;
80706f2543Smrg	if(infoRec->ClippingFlags & HARDWARE_CLIP_SOLID_FILL)
81706f2543Smrg		fastClip = TRUE;
82706f2543Smrg	break;
83706f2543Smrg    case DO_COLOR_8x8:
84706f2543Smrg	function = XAARenderColor8x8Spans;
85706f2543Smrg	if(infoRec->ClippingFlags & HARDWARE_CLIP_COLOR_8x8_FILL)
86706f2543Smrg		fastClip = TRUE;
87706f2543Smrg	break;
88706f2543Smrg    case DO_MONO_8x8:
89706f2543Smrg	function = XAARenderMono8x8Spans;
90706f2543Smrg	if(infoRec->ClippingFlags & HARDWARE_CLIP_MONO_8x8_FILL)
91706f2543Smrg		fastClip = TRUE;
92706f2543Smrg	break;
93706f2543Smrg    case DO_CACHE_BLT:
94706f2543Smrg	function = XAARenderCacheBltSpans;
95706f2543Smrg	if(infoRec->ClippingFlags & HARDWARE_CLIP_SCREEN_TO_SCREEN_COPY)
96706f2543Smrg		fastClip = TRUE;
97706f2543Smrg	break;
98706f2543Smrg    case DO_COLOR_EXPAND:
99706f2543Smrg	function = XAARenderColorExpandSpans;
100706f2543Smrg	break;
101706f2543Smrg    case DO_CACHE_EXPAND:
102706f2543Smrg	function = XAARenderCacheExpandSpans;
103706f2543Smrg	if(infoRec->ClippingFlags &
104706f2543Smrg			HARDWARE_CLIP_SCREEN_TO_SCREEN_COLOR_EXPAND)
105706f2543Smrg		fastClip = TRUE;
106706f2543Smrg	break;
107706f2543Smrg    case DO_PIXMAP_COPY:
108706f2543Smrg	function = XAARenderPixmapCopySpans;
109706f2543Smrg	if(infoRec->ClippingFlags & HARDWARE_CLIP_SCREEN_TO_SCREEN_COPY)
110706f2543Smrg		fastClip = TRUE;
111706f2543Smrg	break;
112706f2543Smrg    case DO_IMAGE_WRITE:
113706f2543Smrg    default:
114706f2543Smrg	(*XAAFallbackOps.FillSpans)(pDraw, pGC, nInit, pptInit,
115706f2543Smrg				pwidthInit, fSorted);
116706f2543Smrg	return;
117706f2543Smrg    }
118706f2543Smrg
119706f2543Smrg
120706f2543Smrg    if((nInit < 10) || (RegionNumRects(pGC->pCompositeClip) != 1))
121706f2543Smrg	fastClip = FALSE;
122706f2543Smrg
123706f2543Smrg    if(fastClip) {
124706f2543Smrg	infoRec->ClipBox = &pGC->pCompositeClip->extents;
125706f2543Smrg	(*function)(pGC, nInit, pptInit, pwidthInit, fSorted,
126706f2543Smrg					pDraw->x, pDraw->y);
127706f2543Smrg	infoRec->ClipBox = NULL;
128706f2543Smrg    } else
129706f2543Smrg	XAAClipAndRenderSpans(pGC, pptInit, pwidthInit, nInit, fSorted,
130706f2543Smrg					function, pDraw->x, pDraw->y);
131706f2543Smrg}
132706f2543Smrg
133706f2543Smrg
134706f2543Smrg	/*********************\
135706f2543Smrg	|     Solid Spans     |
136706f2543Smrg	\*********************/
137706f2543Smrg
138706f2543Smrg
139706f2543Smrgstatic void
140706f2543SmrgXAARenderSolidSpans(
141706f2543Smrg    GCPtr pGC,
142706f2543Smrg    int	n,
143706f2543Smrg    DDXPointPtr ppt,
144706f2543Smrg    int *pwidth,
145706f2543Smrg    int fSorted,
146706f2543Smrg    int xorg, int yorg
147706f2543Smrg){
148706f2543Smrg    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
149706f2543Smrg
150706f2543Smrg    (*infoRec->FillSolidSpans) (infoRec->pScrn, pGC->fgPixel,
151706f2543Smrg		pGC->alu, pGC->planemask, n, ppt, pwidth, fSorted);
152706f2543Smrg}
153706f2543Smrg
154706f2543Smrg
155706f2543Smrg	/************************\
156706f2543Smrg	|     Mono 8x8 Spans     |
157706f2543Smrg	\************************/
158706f2543Smrg
159706f2543Smrg
160706f2543Smrgstatic void
161706f2543SmrgXAARenderMono8x8Spans(
162706f2543Smrg    GCPtr pGC,
163706f2543Smrg    int	n,
164706f2543Smrg    DDXPointPtr ppt,
165706f2543Smrg    int *pwidth,
166706f2543Smrg    int fSorted,
167706f2543Smrg    int xorg, int yorg
168706f2543Smrg){
169706f2543Smrg   XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
170706f2543Smrg   XAAPixmapPtr pPriv;
171706f2543Smrg   int fg, bg;
172706f2543Smrg
173706f2543Smrg   switch(pGC->fillStyle) {
174706f2543Smrg   case FillStippled:
175706f2543Smrg      pPriv = XAA_GET_PIXMAP_PRIVATE(pGC->stipple);
176706f2543Smrg      fg = pGC->fgPixel;  bg = -1;
177706f2543Smrg      break;
178706f2543Smrg   case FillOpaqueStippled:
179706f2543Smrg      pPriv = XAA_GET_PIXMAP_PRIVATE(pGC->stipple);
180706f2543Smrg      fg = pGC->fgPixel;  bg = pGC->bgPixel;
181706f2543Smrg      break;
182706f2543Smrg   case FillTiled:
183706f2543Smrg      pPriv = XAA_GET_PIXMAP_PRIVATE(pGC->tile.pixmap);
184706f2543Smrg      fg = pPriv->fg;  bg = pPriv->bg;
185706f2543Smrg      break;
186706f2543Smrg   default:	/* Muffle compiler */
187706f2543Smrg      pPriv = NULL;	/* Kaboom */
188706f2543Smrg      fg = -1;  bg = -1;
189706f2543Smrg      break;
190706f2543Smrg   }
191706f2543Smrg
192706f2543Smrg   (*infoRec->FillMono8x8PatternSpans) (infoRec->pScrn,
193706f2543Smrg                fg, bg, pGC->alu, pGC->planemask,
194706f2543Smrg                n, ppt, pwidth, fSorted, pPriv->pattern0, pPriv->pattern1,
195706f2543Smrg                (xorg + pGC->patOrg.x), (yorg + pGC->patOrg.y));
196706f2543Smrg}
197706f2543Smrg
198706f2543Smrg
199706f2543Smrg	/*************************\
200706f2543Smrg	|     Color 8x8 Spans     |
201706f2543Smrg	\*************************/
202706f2543Smrg
203706f2543Smrg
204706f2543Smrgstatic void
205706f2543SmrgXAARenderColor8x8Spans(
206706f2543Smrg    GCPtr pGC,
207706f2543Smrg    int	n,
208706f2543Smrg    DDXPointPtr ppt,
209706f2543Smrg    int *pwidth,
210706f2543Smrg    int fSorted,
211706f2543Smrg    int xorg, int yorg
212706f2543Smrg){
213706f2543Smrg   XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
214706f2543Smrg   XAACacheInfoPtr pCache;
215706f2543Smrg   PixmapPtr pPix;
216706f2543Smrg   int fg, bg;
217706f2543Smrg
218706f2543Smrg   switch(pGC->fillStyle) {
219706f2543Smrg   case FillStippled:
220706f2543Smrg      pPix = pGC->stipple;
221706f2543Smrg      fg = pGC->fgPixel;  bg = -1;
222706f2543Smrg      break;
223706f2543Smrg   case FillOpaqueStippled:
224706f2543Smrg      pPix = pGC->stipple;
225706f2543Smrg      fg = pGC->fgPixel;  bg = pGC->bgPixel;
226706f2543Smrg      break;
227706f2543Smrg   case FillTiled:
228706f2543Smrg      pPix = pGC->tile.pixmap;
229706f2543Smrg      fg = -1;  bg = -1;
230706f2543Smrg      break;
231706f2543Smrg   default:	/* Muffle compiler */
232706f2543Smrg      pPix = NULL;
233706f2543Smrg      fg = -1;  bg = -1;
234706f2543Smrg      break;
235706f2543Smrg   }
236706f2543Smrg
237706f2543Smrg   pCache = (*infoRec->CacheColor8x8Pattern)(infoRec->pScrn, pPix, fg, bg);
238706f2543Smrg
239706f2543Smrg   (*infoRec->FillColor8x8PatternSpans) (infoRec->pScrn,
240706f2543Smrg                pGC->alu, pGC->planemask, n, ppt, pwidth, fSorted, pCache,
241706f2543Smrg                (yorg + pGC->patOrg.x), (xorg + pGC->patOrg.y));
242706f2543Smrg}
243706f2543Smrg
244706f2543Smrg
245706f2543Smrg	/****************************\
246706f2543Smrg	|     Color Expand Spans     |
247706f2543Smrg	\****************************/
248706f2543Smrg
249706f2543Smrg
250706f2543Smrgstatic void
251706f2543SmrgXAARenderColorExpandSpans(
252706f2543Smrg    GCPtr pGC,
253706f2543Smrg    int	n,
254706f2543Smrg    DDXPointPtr ppt,
255706f2543Smrg    int *pwidth,
256706f2543Smrg    int fSorted,
257706f2543Smrg    int xorg, int yorg
258706f2543Smrg){
259706f2543Smrg   XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
260706f2543Smrg   int fg, bg;
261706f2543Smrg
262706f2543Smrg   switch(pGC->fillStyle) {
263706f2543Smrg   case FillStippled:
264706f2543Smrg      fg = pGC->fgPixel;  bg = -1;
265706f2543Smrg      break;
266706f2543Smrg   case FillOpaqueStippled:
267706f2543Smrg      fg = pGC->fgPixel;  bg = pGC->bgPixel;
268706f2543Smrg      break;
269706f2543Smrg   default:	/* Muffle compiler */
270706f2543Smrg      fg = -1;  bg = -1;
271706f2543Smrg      break;
272706f2543Smrg   }
273706f2543Smrg
274706f2543Smrg   (*infoRec->FillColorExpandSpans) (infoRec->pScrn, fg, bg,
275706f2543Smrg                pGC->alu, pGC->planemask, n, ppt, pwidth, fSorted,
276706f2543Smrg                (xorg + pGC->patOrg.x), (yorg + pGC->patOrg.y),
277706f2543Smrg                pGC->stipple);
278706f2543Smrg
279706f2543Smrg}
280706f2543Smrg
281706f2543Smrg
282706f2543Smrg	/*************************\
283706f2543Smrg	|     Cache Blt Spans     |
284706f2543Smrg	\*************************/
285706f2543Smrg
286706f2543Smrg
287706f2543Smrgstatic void
288706f2543SmrgXAARenderCacheBltSpans(
289706f2543Smrg    GCPtr pGC,
290706f2543Smrg    int	n,
291706f2543Smrg    DDXPointPtr ppt,
292706f2543Smrg    int *pwidth,
293706f2543Smrg    int fSorted,
294706f2543Smrg    int xorg, int yorg
295706f2543Smrg){
296706f2543Smrg   XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
297706f2543Smrg   XAACacheInfoPtr pCache;
298706f2543Smrg
299706f2543Smrg   switch(pGC->fillStyle) {
300706f2543Smrg   case FillStippled:
301706f2543Smrg      pCache = (*infoRec->CacheStipple)(infoRec->pScrn, pGC->stipple,
302706f2543Smrg					pGC->fgPixel, -1);
303706f2543Smrg      break;
304706f2543Smrg   case FillOpaqueStippled:
305706f2543Smrg      pCache = (*infoRec->CacheStipple)(infoRec->pScrn, pGC->stipple,
306706f2543Smrg					pGC->fgPixel, pGC->bgPixel);
307706f2543Smrg      break;
308706f2543Smrg   case FillTiled:
309706f2543Smrg      pCache = (*infoRec->CacheTile)(infoRec->pScrn, pGC->tile.pixmap);
310706f2543Smrg      break;
311706f2543Smrg   default:	/* Muffle compiler */
312706f2543Smrg      pCache = NULL;
313706f2543Smrg      break;
314706f2543Smrg   }
315706f2543Smrg
316706f2543Smrg   (*infoRec->FillCacheBltSpans) (infoRec->pScrn,
317706f2543Smrg                pGC->alu, pGC->planemask, n, ppt, pwidth, fSorted, pCache,
318706f2543Smrg                (xorg + pGC->patOrg.x), (yorg + pGC->patOrg.y));
319706f2543Smrg
320706f2543Smrg}
321706f2543Smrg
322706f2543Smrg
323706f2543Smrg	/****************************\
324706f2543Smrg	|     Cache Expand Spans     |
325706f2543Smrg	\****************************/
326706f2543Smrg
327706f2543Smrg
328706f2543Smrgstatic void
329706f2543SmrgXAARenderCacheExpandSpans(
330706f2543Smrg    GCPtr pGC,
331706f2543Smrg    int	n,
332706f2543Smrg    DDXPointPtr ppt,
333706f2543Smrg    int *pwidth,
334706f2543Smrg    int fSorted,
335706f2543Smrg    int xorg, int yorg
336706f2543Smrg){
337706f2543Smrg   XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
338706f2543Smrg   int fg, bg;
339706f2543Smrg
340706f2543Smrg   switch(pGC->fillStyle) {
341706f2543Smrg   case FillStippled:
342706f2543Smrg      fg = pGC->fgPixel;  bg = -1;
343706f2543Smrg      break;
344706f2543Smrg   case FillOpaqueStippled:
345706f2543Smrg      fg = pGC->fgPixel;  bg = pGC->bgPixel;
346706f2543Smrg      break;
347706f2543Smrg   default:	/* Muffle compiler */
348706f2543Smrg      fg = -1;  bg = -1;
349706f2543Smrg      break;
350706f2543Smrg   }
351706f2543Smrg
352706f2543Smrg   (*infoRec->FillCacheExpandSpans) (infoRec->pScrn, fg, bg,
353706f2543Smrg                pGC->alu, pGC->planemask, n, ppt, pwidth, fSorted,
354706f2543Smrg                (xorg + pGC->patOrg.x), (yorg + pGC->patOrg.y),
355706f2543Smrg                pGC->stipple);
356706f2543Smrg}
357706f2543Smrg
358706f2543Smrg
359706f2543Smrg	/***************************\
360706f2543Smrg	|     Pixmap Copy Spans     |
361706f2543Smrg	\***************************/
362706f2543Smrg
363706f2543Smrg
364706f2543Smrgstatic void
365706f2543SmrgXAARenderPixmapCopySpans(
366706f2543Smrg    GCPtr pGC,
367706f2543Smrg    int	n,
368706f2543Smrg    DDXPointPtr ppt,
369706f2543Smrg    int *pwidth,
370706f2543Smrg    int fSorted,
371706f2543Smrg    int xorg, int yorg
372706f2543Smrg){
373706f2543Smrg   XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
374706f2543Smrg   XAACacheInfoPtr pCache = &(infoRec->ScratchCacheInfoRec);
375706f2543Smrg   XAAPixmapPtr pPriv = XAA_GET_PIXMAP_PRIVATE(pGC->tile.pixmap);
376706f2543Smrg
377706f2543Smrg   pCache->x = pPriv->offscreenArea->box.x1;
378706f2543Smrg   pCache->y = pPriv->offscreenArea->box.y1;
379706f2543Smrg   pCache->w = pCache->orig_w =
380706f2543Smrg		pPriv->offscreenArea->box.x2 - pCache->x;
381706f2543Smrg   pCache->h = pCache->orig_h =
382706f2543Smrg		pPriv->offscreenArea->box.y2 - pCache->y;
383706f2543Smrg   pCache->trans_color = -1;
384706f2543Smrg
385706f2543Smrg   (*infoRec->FillCacheBltSpans) (infoRec->pScrn,
386706f2543Smrg                pGC->alu, pGC->planemask, n, ppt, pwidth, fSorted, pCache,
387706f2543Smrg                (xorg + pGC->patOrg.x), (yorg + pGC->patOrg.y));
388706f2543Smrg}
389706f2543Smrg
390706f2543Smrg
391706f2543Smrg
392706f2543Smrg
393706f2543Smrg
394706f2543Smrg	/****************\
395706f2543Smrg	|     Solid      |
396706f2543Smrg	\****************/
397706f2543Smrg
398706f2543Smrg
399706f2543Smrgvoid
400706f2543SmrgXAAFillSolidSpans(
401706f2543Smrg   ScrnInfoPtr pScrn,
402706f2543Smrg   int fg, int rop,
403706f2543Smrg   unsigned int planemask,
404706f2543Smrg   int n,
405706f2543Smrg   DDXPointPtr ppt,
406706f2543Smrg   int *pwidth, int fSorted
407706f2543Smrg){
408706f2543Smrg    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
409706f2543Smrg
410706f2543Smrg    (*infoRec->SetupForSolidFill)(pScrn, fg, rop, planemask);
411706f2543Smrg
412706f2543Smrg    if(infoRec->ClipBox)
413706f2543Smrg	(*infoRec->SetClippingRectangle)(infoRec->pScrn,
414706f2543Smrg		infoRec->ClipBox->x1, infoRec->ClipBox->y1,
415706f2543Smrg		infoRec->ClipBox->x2 - 1, infoRec->ClipBox->y2 - 1);
416706f2543Smrg
417706f2543Smrg    while(n--) {
418706f2543Smrg	if (*pwidth > 0)
419706f2543Smrg            (*infoRec->SubsequentSolidFillRect)(pScrn, ppt->x, ppt->y,
420706f2543Smrg								*pwidth, 1);
421706f2543Smrg	ppt++; pwidth++;
422706f2543Smrg    }
423706f2543Smrg
424706f2543Smrg    if(infoRec->ClipBox)
425706f2543Smrg	(*infoRec->DisableClipping)(infoRec->pScrn);
426706f2543Smrg
427706f2543Smrg    SET_SYNC_FLAG(infoRec);
428706f2543Smrg}
429706f2543Smrg
430706f2543Smrg	/***************\
431706f2543Smrg	|   Mono 8x8    |
432706f2543Smrg	\***************/
433706f2543Smrg
434706f2543Smrg
435706f2543Smrgvoid
436706f2543SmrgXAAFillMono8x8PatternSpansScreenOrigin(
437706f2543Smrg   ScrnInfoPtr pScrn,
438706f2543Smrg   int fg, int bg, int rop,
439706f2543Smrg   unsigned int planemask,
440706f2543Smrg   int n,
441706f2543Smrg   DDXPointPtr ppt,
442706f2543Smrg   int *pwidth, int fSorted,
443706f2543Smrg   int pattern0, int pattern1,
444706f2543Smrg   int xorigin, int yorigin
445706f2543Smrg){
446706f2543Smrg    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
447706f2543Smrg    int patx = pattern0, paty = pattern1;
448706f2543Smrg    int xorg = (-xorigin) & 0x07;
449706f2543Smrg    int yorg = (-yorigin) & 0x07;
450706f2543Smrg
451706f2543Smrg
452706f2543Smrg    if(infoRec->Mono8x8PatternFillFlags & HARDWARE_PATTERN_PROGRAMMED_BITS) {
453706f2543Smrg   	if(!(infoRec->Mono8x8PatternFillFlags &
454706f2543Smrg				HARDWARE_PATTERN_PROGRAMMED_ORIGIN)){
455706f2543Smrg	    XAARotateMonoPattern(&patx, &paty, xorg, yorg,
456706f2543Smrg				(infoRec->Mono8x8PatternFillFlags &
457706f2543Smrg				BIT_ORDER_IN_BYTE_MSBFIRST));
458706f2543Smrg	    xorg = patx; yorg = paty;
459706f2543Smrg        }
460706f2543Smrg    } else {
461706f2543Smrg	XAACacheInfoPtr pCache =
462706f2543Smrg		(*infoRec->CacheMono8x8Pattern)(pScrn, pattern0, pattern1);
463706f2543Smrg	patx = pCache->x;  paty = pCache->y;
464706f2543Smrg   	if(!(infoRec->Mono8x8PatternFillFlags &
465706f2543Smrg				HARDWARE_PATTERN_PROGRAMMED_ORIGIN)){
466706f2543Smrg	    int slot = (yorg << 3) + xorg;
467706f2543Smrg	    patx += pCache->offsets[slot].x;
468706f2543Smrg	    paty += pCache->offsets[slot].y;
469706f2543Smrg	    xorg = patx;  yorg = paty;
470706f2543Smrg	}
471706f2543Smrg    }
472706f2543Smrg
473706f2543Smrg    (*infoRec->SetupForMono8x8PatternFill)(pScrn, patx, paty,
474706f2543Smrg	fg, bg, rop, planemask);
475706f2543Smrg
476706f2543Smrg    if(infoRec->ClipBox)
477706f2543Smrg	(*infoRec->SetClippingRectangle)(infoRec->pScrn,
478706f2543Smrg		infoRec->ClipBox->x1, infoRec->ClipBox->y1,
479706f2543Smrg		infoRec->ClipBox->x2 - 1, infoRec->ClipBox->y2 - 1);
480706f2543Smrg
481706f2543Smrg     while(n--) {
482706f2543Smrg        (*infoRec->SubsequentMono8x8PatternFillRect)(pScrn,
483706f2543Smrg			xorg, yorg, ppt->x, ppt->y, *pwidth, 1);
484706f2543Smrg	ppt++; pwidth++;
485706f2543Smrg     }
486706f2543Smrg
487706f2543Smrg     if(infoRec->ClipBox)
488706f2543Smrg	(*infoRec->DisableClipping)(infoRec->pScrn);
489706f2543Smrg
490706f2543Smrg     SET_SYNC_FLAG(infoRec);
491706f2543Smrg}
492706f2543Smrg
493706f2543Smrg
494706f2543Smrgvoid
495706f2543SmrgXAAFillMono8x8PatternSpans(
496706f2543Smrg   ScrnInfoPtr pScrn,
497706f2543Smrg   int fg, int bg, int rop,
498706f2543Smrg   unsigned int planemask,
499706f2543Smrg   int n,
500706f2543Smrg   DDXPointPtr ppt,
501706f2543Smrg   int *pwidth, int fSorted,
502706f2543Smrg   int pattern0, int pattern1,
503706f2543Smrg   int xorigin, int yorigin
504706f2543Smrg){
505706f2543Smrg    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
506706f2543Smrg    int patx = pattern0, paty = pattern1;
507706f2543Smrg    int xorg, yorg, slot;
508706f2543Smrg    XAACacheInfoPtr pCache = NULL;
509706f2543Smrg
510706f2543Smrg
511706f2543Smrg    if(!(infoRec->Mono8x8PatternFillFlags & HARDWARE_PATTERN_PROGRAMMED_BITS)){
512706f2543Smrg	pCache = (*infoRec->CacheMono8x8Pattern)(pScrn, pattern0, pattern1);
513706f2543Smrg	patx = pCache->x;  paty = pCache->y;
514706f2543Smrg    }
515706f2543Smrg
516706f2543Smrg    (*infoRec->SetupForMono8x8PatternFill)(pScrn, patx, paty,
517706f2543Smrg					fg, bg, rop, planemask);
518706f2543Smrg
519706f2543Smrg    if(infoRec->ClipBox)
520706f2543Smrg	(*infoRec->SetClippingRectangle)(infoRec->pScrn,
521706f2543Smrg		infoRec->ClipBox->x1, infoRec->ClipBox->y1,
522706f2543Smrg		infoRec->ClipBox->x2 - 1, infoRec->ClipBox->y2 - 1);
523706f2543Smrg
524706f2543Smrg     while(n--) {
525706f2543Smrg	xorg = (ppt->x - xorigin) & 0x07;
526706f2543Smrg	yorg = (ppt->y - yorigin) & 0x07;
527706f2543Smrg
528706f2543Smrg   	if(!(infoRec->Mono8x8PatternFillFlags &
529706f2543Smrg				HARDWARE_PATTERN_PROGRAMMED_ORIGIN)){
530706f2543Smrg	    if(infoRec->Mono8x8PatternFillFlags &
531706f2543Smrg				HARDWARE_PATTERN_PROGRAMMED_BITS) {
532706f2543Smrg		patx = pattern0; paty = pattern1;
533706f2543Smrg		XAARotateMonoPattern(&patx, &paty, xorg, yorg,
534706f2543Smrg				(infoRec->Mono8x8PatternFillFlags &
535706f2543Smrg				BIT_ORDER_IN_BYTE_MSBFIRST));
536706f2543Smrg		xorg = patx; yorg = paty;
537706f2543Smrg	    } else {
538706f2543Smrg		slot = (yorg << 3) + xorg;
539706f2543Smrg	    	xorg = patx + pCache->offsets[slot].x;
540706f2543Smrg	    	yorg = paty + pCache->offsets[slot].y;
541706f2543Smrg	    }
542706f2543Smrg        }
543706f2543Smrg
544706f2543Smrg        (*infoRec->SubsequentMono8x8PatternFillRect)(pScrn,
545706f2543Smrg			xorg, yorg, ppt->x, ppt->y, *pwidth, 1);
546706f2543Smrg	ppt++; pwidth++;
547706f2543Smrg     }
548706f2543Smrg
549706f2543Smrg     if(infoRec->ClipBox)
550706f2543Smrg	(*infoRec->DisableClipping)(infoRec->pScrn);
551706f2543Smrg
552706f2543Smrg     SET_SYNC_FLAG(infoRec);
553706f2543Smrg}
554706f2543Smrg
555706f2543Smrg
556706f2543Smrg
557706f2543Smrg	/****************\
558706f2543Smrg	|   Color 8x8    |
559706f2543Smrg	\****************/
560706f2543Smrg
561706f2543Smrg
562706f2543Smrgvoid
563706f2543SmrgXAAFillColor8x8PatternSpansScreenOrigin(
564706f2543Smrg   ScrnInfoPtr pScrn,
565706f2543Smrg   int rop,
566706f2543Smrg   unsigned int planemask,
567706f2543Smrg   int n,
568706f2543Smrg   DDXPointPtr ppt,
569706f2543Smrg   int *pwidth, int fSorted,
570706f2543Smrg   XAACacheInfoPtr pCache,
571706f2543Smrg   int xorigin, int yorigin
572706f2543Smrg){
573706f2543Smrg    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
574706f2543Smrg    int patx = pCache->x, paty = pCache->y;
575706f2543Smrg    int xorg = (-xorigin) & 0x07;
576706f2543Smrg    int yorg = (-yorigin) & 0x07;
577706f2543Smrg
578706f2543Smrg
579706f2543Smrg    if(!(infoRec->Color8x8PatternFillFlags &
580706f2543Smrg					HARDWARE_PATTERN_PROGRAMMED_ORIGIN)){
581706f2543Smrg	int slot = (yorg << 3) + xorg;
582706f2543Smrg	paty += pCache->offsets[slot].y;
583706f2543Smrg	patx += pCache->offsets[slot].x;
584706f2543Smrg	xorg = patx;  yorg = paty;
585706f2543Smrg    }
586706f2543Smrg
587706f2543Smrg    (*infoRec->SetupForColor8x8PatternFill)(pScrn, patx, paty,
588706f2543Smrg			 rop, planemask, pCache->trans_color);
589706f2543Smrg
590706f2543Smrg    if(infoRec->ClipBox)
591706f2543Smrg	(*infoRec->SetClippingRectangle)(infoRec->pScrn,
592706f2543Smrg		infoRec->ClipBox->x1, infoRec->ClipBox->y1,
593706f2543Smrg		infoRec->ClipBox->x2 - 1, infoRec->ClipBox->y2 - 1);
594706f2543Smrg
595706f2543Smrg     while(n--) {
596706f2543Smrg        (*infoRec->SubsequentColor8x8PatternFillRect)(pScrn,
597706f2543Smrg			xorg, yorg, ppt->x, ppt->y, *pwidth, 1);
598706f2543Smrg	ppt++; pwidth++;
599706f2543Smrg     }
600706f2543Smrg
601706f2543Smrg    if(infoRec->ClipBox)
602706f2543Smrg	(*infoRec->DisableClipping)(infoRec->pScrn);
603706f2543Smrg
604706f2543Smrg     SET_SYNC_FLAG(infoRec);
605706f2543Smrg}
606706f2543Smrg
607706f2543Smrg
608706f2543Smrgvoid
609706f2543SmrgXAAFillColor8x8PatternSpans(
610706f2543Smrg   ScrnInfoPtr pScrn,
611706f2543Smrg   int rop,
612706f2543Smrg   unsigned int planemask,
613706f2543Smrg   int n,
614706f2543Smrg   DDXPointPtr ppt,
615706f2543Smrg   int *pwidth, int fSorted,
616706f2543Smrg   XAACacheInfoPtr pCache,
617706f2543Smrg   int xorigin, int yorigin
618706f2543Smrg){
619706f2543Smrg    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
620706f2543Smrg    int xorg, yorg, slot;
621706f2543Smrg
622706f2543Smrg    (*infoRec->SetupForColor8x8PatternFill)(pScrn, pCache->x, pCache->y,
623706f2543Smrg			 rop, planemask, pCache->trans_color);
624706f2543Smrg
625706f2543Smrg    if(infoRec->ClipBox)
626706f2543Smrg	(*infoRec->SetClippingRectangle)(infoRec->pScrn,
627706f2543Smrg		infoRec->ClipBox->x1, infoRec->ClipBox->y1,
628706f2543Smrg		infoRec->ClipBox->x2 - 1, infoRec->ClipBox->y2 - 1);
629706f2543Smrg
630706f2543Smrg     while(n--) {
631706f2543Smrg	xorg = (ppt->x - xorigin) & 0x07;
632706f2543Smrg	yorg = (ppt->y - yorigin) & 0x07;
633706f2543Smrg
634706f2543Smrg   	if(!(infoRec->Color8x8PatternFillFlags &
635706f2543Smrg				HARDWARE_PATTERN_PROGRAMMED_ORIGIN)){
636706f2543Smrg	    slot = (yorg << 3) + xorg;
637706f2543Smrg	    yorg = pCache->y + pCache->offsets[slot].y;
638706f2543Smrg	    xorg = pCache->x + pCache->offsets[slot].x;
639706f2543Smrg        }
640706f2543Smrg
641706f2543Smrg        (*infoRec->SubsequentColor8x8PatternFillRect)(pScrn,
642706f2543Smrg			xorg, yorg, ppt->x, ppt->y, *pwidth, 1);
643706f2543Smrg	ppt++; pwidth++;
644706f2543Smrg     }
645706f2543Smrg
646706f2543Smrg     if(infoRec->ClipBox)
647706f2543Smrg	(*infoRec->DisableClipping)(infoRec->pScrn);
648706f2543Smrg
649706f2543Smrg     SET_SYNC_FLAG(infoRec);
650706f2543Smrg}
651706f2543Smrg
652706f2543Smrg	/*****************\
653706f2543Smrg	|   Cache Blit    |
654706f2543Smrg	\*****************/
655706f2543Smrg
656706f2543Smrg
657706f2543Smrgvoid
658706f2543SmrgXAAFillCacheBltSpans(
659706f2543Smrg   ScrnInfoPtr pScrn,
660706f2543Smrg   int rop,
661706f2543Smrg   unsigned int planemask,
662706f2543Smrg   int n,
663706f2543Smrg   DDXPointPtr ppt,
664706f2543Smrg   int *pwidth,
665706f2543Smrg   int fSorted,
666706f2543Smrg   XAACacheInfoPtr pCache,
667706f2543Smrg   int xorg, int yorg
668706f2543Smrg){
669706f2543Smrg    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
670706f2543Smrg    int x, w, phaseX, phaseY, blit_w;
671706f2543Smrg
672706f2543Smrg    (*infoRec->SetupForScreenToScreenCopy)(pScrn, 1, 1, rop, planemask,
673706f2543Smrg		pCache->trans_color);
674706f2543Smrg
675706f2543Smrg    if(infoRec->ClipBox)
676706f2543Smrg	(*infoRec->SetClippingRectangle)(infoRec->pScrn,
677706f2543Smrg		infoRec->ClipBox->x1, infoRec->ClipBox->y1,
678706f2543Smrg		infoRec->ClipBox->x2 - 1, infoRec->ClipBox->y2 - 1);
679706f2543Smrg
680706f2543Smrg     while(n--) {
681706f2543Smrg	x = ppt->x;
682706f2543Smrg	w = *pwidth;
683706f2543Smrg	phaseX = (x - xorg) % pCache->orig_w;
684706f2543Smrg	if(phaseX < 0) phaseX += pCache->orig_w;
685706f2543Smrg	phaseY = (ppt->y - yorg) % pCache->orig_h;
686706f2543Smrg	if(phaseY < 0) phaseY += pCache->orig_h;
687706f2543Smrg
688706f2543Smrg	while(1) {
689706f2543Smrg	    blit_w = pCache->w - phaseX;
690706f2543Smrg	    if(blit_w > w) blit_w = w;
691706f2543Smrg
692706f2543Smrg            (*infoRec->SubsequentScreenToScreenCopy)(pScrn,
693706f2543Smrg		pCache->x + phaseX, pCache->y + phaseY,
694706f2543Smrg		x, ppt->y, blit_w, 1);
695706f2543Smrg
696706f2543Smrg	    w -= blit_w;
697706f2543Smrg	    if(!w) break;
698706f2543Smrg	    x += blit_w;
699706f2543Smrg	    phaseX = (phaseX + blit_w) % pCache->orig_w;
700706f2543Smrg	}
701706f2543Smrg	ppt++; pwidth++;
702706f2543Smrg     }
703706f2543Smrg
704706f2543Smrg     if(infoRec->ClipBox)
705706f2543Smrg	(*infoRec->DisableClipping)(infoRec->pScrn);
706706f2543Smrg
707706f2543Smrg     SET_SYNC_FLAG(infoRec);
708706f2543Smrg}
709706f2543Smrg
710706f2543Smrg
711706f2543Smrg	/****************\
712706f2543Smrg	|  Cache Expand  |
713706f2543Smrg	\****************/
714706f2543Smrg
715706f2543Smrg
716706f2543Smrgvoid
717706f2543SmrgXAAFillCacheExpandSpans(
718706f2543Smrg   ScrnInfoPtr pScrn,
719706f2543Smrg   int fg, int bg, int rop,
720706f2543Smrg   unsigned int planemask,
721706f2543Smrg   int n,
722706f2543Smrg   DDXPointPtr ppt,
723706f2543Smrg   int *pwidth,
724706f2543Smrg   int fSorted,
725706f2543Smrg   int xorg, int yorg,
726706f2543Smrg   PixmapPtr pPix
727706f2543Smrg){
728706f2543Smrg    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
729706f2543Smrg    int x, w, phaseX, phaseY, blit_w, cacheWidth;
730706f2543Smrg    XAACacheInfoPtr pCache;
731706f2543Smrg
732706f2543Smrg    pCache = (*infoRec->CacheMonoStipple)(pScrn, pPix);
733706f2543Smrg
734706f2543Smrg    cacheWidth = (pCache->w * pScrn->bitsPerPixel) /
735706f2543Smrg	infoRec->CacheColorExpandDensity;
736706f2543Smrg
737706f2543Smrg    (*infoRec->SetupForScreenToScreenColorExpandFill)(pScrn, fg, bg, rop,
738706f2543Smrg							planemask);
739706f2543Smrg
740706f2543Smrg    if(infoRec->ClipBox)
741706f2543Smrg	(*infoRec->SetClippingRectangle)(infoRec->pScrn,
742706f2543Smrg		infoRec->ClipBox->x1, infoRec->ClipBox->y1,
743706f2543Smrg		infoRec->ClipBox->x2 - 1, infoRec->ClipBox->y2 - 1);
744706f2543Smrg
745706f2543Smrg     while(n--) {
746706f2543Smrg	x = ppt->x;
747706f2543Smrg	w = *pwidth;
748706f2543Smrg	phaseX = (x - xorg) % pCache->orig_w;
749706f2543Smrg	if(phaseX < 0) phaseX += pCache->orig_w;
750706f2543Smrg	phaseY = (ppt->y - yorg) % pCache->orig_h;
751706f2543Smrg	if(phaseY < 0) phaseY += pCache->orig_h;
752706f2543Smrg
753706f2543Smrg	while(1) {
754706f2543Smrg	    blit_w = cacheWidth - phaseX;
755706f2543Smrg	    if(blit_w > w) blit_w = w;
756706f2543Smrg
757706f2543Smrg	    (*infoRec->SubsequentScreenToScreenColorExpandFill)(
758706f2543Smrg			pScrn, x, ppt->y, blit_w, 1,
759706f2543Smrg			pCache->x, pCache->y + phaseY, phaseX);
760706f2543Smrg
761706f2543Smrg	    w -= blit_w;
762706f2543Smrg	    if(!w) break;
763706f2543Smrg	    x += blit_w;
764706f2543Smrg	    phaseX = (phaseX + blit_w) % pCache->orig_w;
765706f2543Smrg	}
766706f2543Smrg	ppt++; pwidth++;
767706f2543Smrg     }
768706f2543Smrg
769706f2543Smrg     if(infoRec->ClipBox)
770706f2543Smrg	(*infoRec->DisableClipping)(infoRec->pScrn);
771706f2543Smrg
772706f2543Smrg     SET_SYNC_FLAG(infoRec);
773706f2543Smrg}
774706f2543Smrg
775706f2543Smrg
776706f2543Smrg
777706f2543Smrgvoid
778706f2543SmrgXAAClipAndRenderSpans(
779706f2543Smrg    GCPtr pGC,
780706f2543Smrg    DDXPointPtr	ppt,
781706f2543Smrg    int		*pwidth,
782706f2543Smrg    int		nspans,
783706f2543Smrg    int		fSorted,
784706f2543Smrg    ClipAndRenderSpansFunc func,
785706f2543Smrg    int 	xorg,
786706f2543Smrg    int		yorg
787706f2543Smrg){
788706f2543Smrg    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_GC(pGC);
789706f2543Smrg    DDXPointPtr pptNew, pptBase;
790706f2543Smrg    int	*pwidthBase, *pwidthNew;
791706f2543Smrg    int	Right, numRects, MaxBoxes;
792706f2543Smrg
793706f2543Smrg    MaxBoxes = infoRec->PreAllocSize/(sizeof(DDXPointRec) + sizeof(int));
794706f2543Smrg    pptBase = (DDXPointRec*)infoRec->PreAllocMem;
795706f2543Smrg    pwidthBase = (int*)(&pptBase[MaxBoxes]);
796706f2543Smrg
797706f2543Smrg    pptNew = pptBase;
798706f2543Smrg    pwidthNew = pwidthBase;
799706f2543Smrg
800706f2543Smrg    numRects = RegionNumRects(pGC->pCompositeClip);
801706f2543Smrg
802706f2543Smrg    if(numRects == 1) {
803706f2543Smrg        BoxPtr pextent = RegionRects(pGC->pCompositeClip);
804706f2543Smrg
805706f2543Smrg	while(nspans--) {
806706f2543Smrg	    if ((pextent->y1 <= ppt->y) && (ppt->y < pextent->y2)) {
807706f2543Smrg		pptNew->x = max(pextent->x1, ppt->x);
808706f2543Smrg		Right = ppt->x + *pwidth;
809706f2543Smrg		*pwidthNew = min(pextent->x2, Right) - pptNew->x;
810706f2543Smrg
811706f2543Smrg		if (*pwidthNew > 0) {
812706f2543Smrg		    pptNew->y = ppt->y;
813706f2543Smrg		    pptNew++;
814706f2543Smrg		    pwidthNew++;
815706f2543Smrg
816706f2543Smrg		    if(pptNew >= (pptBase + MaxBoxes)) {
817706f2543Smrg			(*func)(pGC, MaxBoxes, pptBase, pwidthBase, fSorted,
818706f2543Smrg								xorg, yorg);
819706f2543Smrg			pptNew = pptBase;
820706f2543Smrg			pwidthNew = pwidthBase;
821706f2543Smrg		    }
822706f2543Smrg		}
823706f2543Smrg	    }
824706f2543Smrg	    ppt++;
825706f2543Smrg	    pwidth++;
826706f2543Smrg	}
827706f2543Smrg    } else if (numRects) {
828706f2543Smrg	BoxPtr	pbox;
829706f2543Smrg	int nbox;
830706f2543Smrg
831706f2543Smrg	while(nspans--) {
832706f2543Smrg	    nbox = numRects;
833706f2543Smrg	    pbox = RegionRects(pGC->pCompositeClip);
834706f2543Smrg
835706f2543Smrg	    /* find the first band */
836706f2543Smrg	    while(nbox && (pbox->y2 <= ppt->y)) {
837706f2543Smrg		pbox++;
838706f2543Smrg		nbox--;
839706f2543Smrg	    }
840706f2543Smrg
841706f2543Smrg	    if(nbox && (pbox->y1 <= ppt->y)) {
842706f2543Smrg		int orig_y = pbox->y1;
843706f2543Smrg		Right = ppt->x + *pwidth;
844706f2543Smrg		while(nbox && (orig_y == pbox->y1)) {
845706f2543Smrg		    if(pbox->x2 <= ppt->x) {
846706f2543Smrg			nbox--;
847706f2543Smrg			pbox++;
848706f2543Smrg			continue;
849706f2543Smrg		    }
850706f2543Smrg
851706f2543Smrg		    if(pbox->x1 >= Right) {
852706f2543Smrg			nbox = 0;
853706f2543Smrg			break;
854706f2543Smrg		    }
855706f2543Smrg
856706f2543Smrg		    pptNew->x = max(pbox->x1, ppt->x);
857706f2543Smrg		    *pwidthNew = min(pbox->x2, Right) - pptNew->x;
858706f2543Smrg		    if(*pwidthNew > 0) {
859706f2543Smrg			pptNew->y = ppt->y;
860706f2543Smrg			pptNew++;
861706f2543Smrg			pwidthNew++;
862706f2543Smrg
863706f2543Smrg			if(pptNew >= (pptBase + MaxBoxes)) {
864706f2543Smrg			    (*func)(pGC, MaxBoxes, pptBase, pwidthBase,
865706f2543Smrg							fSorted, xorg, yorg);
866706f2543Smrg			    pptNew = pptBase;
867706f2543Smrg			    pwidthNew = pwidthBase;
868706f2543Smrg			}
869706f2543Smrg		    }
870706f2543Smrg		    pbox++;
871706f2543Smrg		    nbox--;
872706f2543Smrg		}
873706f2543Smrg	    }
874706f2543Smrg	    ppt++;
875706f2543Smrg	    pwidth++;
876706f2543Smrg	}
877706f2543Smrg    }
878706f2543Smrg
879706f2543Smrg    if(pptNew != pptBase)
880706f2543Smrg	(*func)(pGC, pptNew - pptBase, pptBase, pwidthBase, fSorted,
881706f2543Smrg						xorg, yorg);
882706f2543Smrg}
883