First import
[xorg_rtime.git] / xorg-server-1.4 / cfb / cfbfillsp.c
blobddd4f1421e07e5629e5c08af2247c1b1500c5551
1 /************************************************************
2 Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
4 All Rights Reserved
6 Permission to use, copy, modify, and distribute this
7 software and its documentation for any purpose and without
8 fee is hereby granted, provided that the above copyright no-
9 tice appear in all copies and that both that copyright no-
10 tice and this permission notice appear in supporting docu-
11 mentation, and that the names of Sun or The Open Group
12 not be used in advertising or publicity pertaining to
13 distribution of the software without specific prior
14 written permission. Sun and The Open Group make no
15 representations about the suitability of this software for
16 any purpose. It is provided "as is" without any express or
17 implied warranty.
19 SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
20 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
21 NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE LI-
22 ABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
23 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
24 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
25 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
26 THE USE OR PERFORMANCE OF THIS SOFTWARE.
28 ********************************************************/
30 /***********************************************************
32 Copyright 1987, 1998 The Open Group
34 Permission to use, copy, modify, distribute, and sell this software and its
35 documentation for any purpose is hereby granted without fee, provided that
36 the above copyright notice appear in all copies and that both that
37 copyright notice and this permission notice appear in supporting
38 documentation.
40 The above copyright notice and this permission notice shall be included in
41 all copies or substantial portions of the Software.
43 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
44 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
45 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
46 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
47 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
48 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
50 Except as contained in this notice, the name of The Open Group shall not be
51 used in advertising or otherwise to promote the sale, use or other dealings
52 in this Software without prior written authorization from The Open Group.
55 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
57 All Rights Reserved
59 Permission to use, copy, modify, and distribute this software and its
60 documentation for any purpose and without fee is hereby granted,
61 provided that the above copyright notice appear in all copies and that
62 both that copyright notice and this permission notice appear in
63 supporting documentation, and that the name of Digital not be
64 used in advertising or publicity pertaining to distribution of the
65 software without specific, written prior permission.
67 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
68 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
69 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
70 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
71 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
72 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
73 SOFTWARE.
75 ******************************************************************/
78 #ifdef HAVE_DIX_CONFIG_H
79 #include <dix-config.h>
80 #endif
82 #include <X11/X.h>
83 #include <X11/Xmd.h>
84 #include "servermd.h"
85 #include "gcstruct.h"
86 #include "window.h"
87 #include "pixmapstr.h"
88 #include "scrnintstr.h"
89 #include "windowstr.h"
91 #include "cfb.h"
92 #include "cfbmskbits.h"
94 #include "mergerop.h"
96 #if PSZ == 8
97 #include "cfb8bit.h"
98 #endif
100 #define MFB_CONSTS_ONLY
101 #include "maskbits.h"
103 #include "mi.h"
104 #include "mispans.h"
106 /* scanline filling for color frame buffer
107 written by drewry, oct 1986 modified by smarks
108 changes for compatibility with Little-endian systems Jul 1987; MIT:yba.
110 these routines all clip. they assume that anything that has called
111 them has already translated the points (i.e. pGC->miTranslate is
112 non-zero, which is howit gets set in cfbCreateGC().)
114 the number of new scnalines created by clipping ==
115 MaxRectsPerBand * nSpans.
117 FillSolid is overloaded to be used for OpaqueStipple as well,
118 if fgPixel == bgPixel.
119 Note that for solids, PrivGC.rop == PrivGC.ropOpStip
122 FillTiled is overloaded to be used for OpaqueStipple, if
123 fgPixel != bgPixel. based on the fill style, it uses
124 {RotatedTile, gc.alu} or {RotatedStipple, PrivGC.ropOpStip}
127 #ifdef notdef
128 #include <stdio.h>
129 static
130 dumpspans(n, ppt, pwidth)
131 int n;
132 DDXPointPtr ppt;
133 int *pwidth;
135 fprintf(stderr,"%d spans\n", n);
136 while (n--) {
137 fprintf(stderr, "[%d,%d] %d\n", ppt->x, ppt->y, *pwidth);
138 ppt++;
139 pwidth++;
141 fprintf(stderr, "\n");
143 #endif
145 /* Fill spans with tiles that aren't 32 bits wide */
146 void
147 cfbUnnaturalTileFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
148 DrawablePtr pDrawable;
149 GC *pGC;
150 int nInit; /* number of spans to fill */
151 DDXPointPtr pptInit; /* pointer to list of start points */
152 int *pwidthInit; /* pointer to list of n widths */
153 int fSorted;
155 int n; /* number of spans to fill */
156 register DDXPointPtr ppt; /* pointer to list of start points */
157 register int *pwidth; /* pointer to list of n widths */
158 void (*fill)(DrawablePtr, int, DDXPointPtr, int *, PixmapPtr, int, int, int, unsigned long);
159 int xrot, yrot;
161 if (!(pGC->planemask))
162 return;
164 #if PSZ == 24
165 if (pGC->tile.pixmap->drawable.width & 3)
166 #else
167 if (pGC->tile.pixmap->drawable.width & PIM)
168 #endif
170 fill = cfbFillSpanTileOddGeneral;
171 if ((pGC->planemask & PMSK) == PMSK)
173 if (pGC->alu == GXcopy)
174 fill = cfbFillSpanTileOddCopy;
177 else
179 fill = cfbFillSpanTile32sGeneral;
180 if ((pGC->planemask & PMSK) == PMSK)
182 if (pGC->alu == GXcopy)
183 fill = cfbFillSpanTile32sCopy;
186 n = nInit * miFindMaxBand( cfbGetCompositeClip(pGC) );
187 if ( n == 0 )
188 return;
189 pwidth = (int *)ALLOCATE_LOCAL(n * sizeof(int));
190 ppt = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
191 if(!ppt || !pwidth)
193 if (ppt) DEALLOCATE_LOCAL(ppt);
194 if (pwidth) DEALLOCATE_LOCAL(pwidth);
195 return;
197 n = miClipSpans( cfbGetCompositeClip(pGC),
198 pptInit, pwidthInit, nInit,
199 ppt, pwidth, fSorted);
201 xrot = pDrawable->x + pGC->patOrg.x;
202 yrot = pDrawable->y + pGC->patOrg.y;
204 (*fill) (pDrawable, n, ppt, pwidth, pGC->tile.pixmap, xrot, yrot, pGC->alu, pGC->planemask);
206 DEALLOCATE_LOCAL(ppt);
207 DEALLOCATE_LOCAL(pwidth);
210 #if PSZ == 8
212 void
213 cfbUnnaturalStippleFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
214 DrawablePtr pDrawable;
215 GC *pGC;
216 int nInit; /* number of spans to fill */
217 DDXPointPtr pptInit; /* pointer to list of start points */
218 int *pwidthInit; /* pointer to list of n widths */
219 int fSorted;
221 /* next three parameters are post-clip */
222 int n; /* number of spans to fill */
223 DDXPointPtr ppt; /* pointer to list of start points */
224 int *pwidth; /* pointer to list of n widths */
225 int *pwidthFree;/* copies of the pointers to free */
226 DDXPointPtr pptFree;
227 CfbBits *pdstBase; /* pointer to start of bitmap */
228 int nlwDst; /* width in longwords of bitmap */
229 register CfbBits *pdst; /* pointer to current word in bitmap */
230 PixmapPtr pStipple; /* pointer to stipple we want to fill with */
231 int nlw;
232 int x, y, w, xrem, xSrc, ySrc;
233 int stwidth, stippleWidth;
234 int stippleHeight;
235 register CfbBits bits, inputBits;
236 register int partBitsLeft;
237 int nextPartBits;
238 int bitsLeft, bitsWhole;
239 CfbBits *srcTemp, *srcStart;
240 CfbBits *psrcBase;
241 CfbBits startmask, endmask;
243 if (pGC->fillStyle == FillStippled)
244 cfb8CheckStipple (pGC->alu, pGC->fgPixel, pGC->planemask);
245 else
246 cfb8CheckOpaqueStipple (pGC->alu, pGC->fgPixel, pGC->bgPixel, pGC->planemask);
248 if (cfb8StippleRRop == GXnoop)
249 return;
251 n = nInit * miFindMaxBand( cfbGetCompositeClip(pGC) );
252 if ( n == 0 )
253 return;
254 pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
255 pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
256 if(!pptFree || !pwidthFree)
258 if (pptFree) DEALLOCATE_LOCAL(pptFree);
259 if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
260 return;
263 pwidth = pwidthFree;
264 ppt = pptFree;
265 n = miClipSpans( cfbGetCompositeClip(pGC),
266 pptInit, pwidthInit, nInit,
267 ppt, pwidth, fSorted);
270 * OK, so what's going on here? We have two Drawables:
272 * The Stipple:
273 * Depth = 1
274 * Width = stippleWidth
275 * Words per scanline = stwidth
276 * Pointer to pixels = pStipple->devPrivate.ptr
279 pStipple = pGC->stipple;
281 stwidth = pStipple->devKind >> PWSH;
282 stippleWidth = pStipple->drawable.width;
283 stippleHeight = pStipple->drawable.height;
284 psrcBase = (CfbBits *) pStipple->devPrivate.ptr;
287 * The Target:
288 * Depth = PSZ
289 * Width = determined from *pwidth
290 * Words per scanline = nlwDst
291 * Pointer to pixels = addrlBase
294 cfbGetLongWidthAndPointer (pDrawable, nlwDst, pdstBase)
296 /* this replaces rotating the stipple. Instead we just adjust the offset
297 * at which we start grabbing bits from the stipple.
298 * Ensure that ppt->x - xSrc >= 0 and ppt->y - ySrc >= 0,
299 * so that iline and xrem always stay within the stipple bounds.
302 modulus (pGC->patOrg.x, stippleWidth, xSrc);
303 xSrc += pDrawable->x - stippleWidth;
304 modulus (pGC->patOrg.y, stippleHeight, ySrc);
305 ySrc += pDrawable->y - stippleHeight;
307 bitsWhole = stippleWidth;
309 while (n--)
311 x = ppt->x;
312 y = ppt->y;
313 ppt++;
314 w = *pwidth++;
315 pdst = pdstBase + y * nlwDst + (x >> PWSH);
316 y = (y - ySrc) % stippleHeight;
317 srcStart = psrcBase + y * stwidth;
318 xrem = ((x & ~(PGSZB-1)) - xSrc) % stippleWidth;
319 srcTemp = srcStart + (xrem >> MFB_PWSH);
320 bitsLeft = stippleWidth - (xrem & ~MFB_PIM);
321 xrem &= MFB_PIM;
322 NextUnnaturalStippleWord
323 if (partBitsLeft < xrem)
324 FatalError ("cfbUnnaturalStippleFS bad partBitsLeft %d xrem %d",
325 partBitsLeft, xrem);
326 NextSomeBits (inputBits, xrem);
327 partBitsLeft -= xrem;
328 if (((x & PIM) + w) <= PPW)
330 maskpartialbits (x, w, startmask)
331 NextUnnaturalStippleBits
332 *pdst = MaskRRopPixels(*pdst,bits,startmask);
334 else
336 maskbits (x, w, startmask, endmask, nlw);
337 nextPartBits = (x & (PGSZB-1)) + w;
338 if (nextPartBits < partBitsLeft)
340 if (startmask)
342 MaskRRopBitGroup(pdst,GetBitGroup(inputBits),startmask)
343 pdst++;
344 NextBitGroup (inputBits);
346 while (nlw--)
348 RRopBitGroup (pdst, GetBitGroup (inputBits));
349 pdst++;
350 NextBitGroup (inputBits);
352 if (endmask)
354 MaskRRopBitGroup(pdst,GetBitGroup(inputBits),endmask)
357 else if (bitsLeft != bitsWhole && nextPartBits < partBitsLeft + bitsLeft)
359 NextUnnaturalStippleBitsFast
360 if (startmask)
362 *pdst = MaskRRopPixels(*pdst,bits,startmask);
363 pdst++;
364 NextUnnaturalStippleBitsFast
366 while (nlw--)
368 *pdst = RRopPixels(*pdst,bits);
369 pdst++;
370 NextUnnaturalStippleBitsFast
372 if (endmask)
373 *pdst = MaskRRopPixels (*pdst,bits,endmask);
375 else
377 NextUnnaturalStippleBits
378 if (startmask)
380 *pdst = MaskRRopPixels(*pdst,bits,startmask);
381 pdst++;
382 NextUnnaturalStippleBits
384 while (nlw--)
386 *pdst = RRopPixels(*pdst,bits);
387 pdst++;
388 NextUnnaturalStippleBits
390 if (endmask)
391 *pdst = MaskRRopPixels(*pdst,bits,endmask);
395 DEALLOCATE_LOCAL(pptFree);
396 DEALLOCATE_LOCAL(pwidthFree);
399 #else /* PSZ != 8 */
401 /* Fill spans with stipples that aren't 32 bits wide */
402 void
403 cfbUnnaturalStippleFS(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
404 DrawablePtr pDrawable;
405 GC *pGC;
406 int nInit; /* number of spans to fill */
407 DDXPointPtr pptInit; /* pointer to list of start points */
408 int *pwidthInit; /* pointer to list of n widths */
409 int fSorted;
411 /* next three parameters are post-clip */
412 int n; /* number of spans to fill */
413 register DDXPointPtr ppt; /* pointer to list of start points */
414 register int *pwidth; /* pointer to list of n widths */
415 int iline; /* first line of tile to use */
416 CfbBits *addrlBase; /* pointer to start of bitmap */
417 int nlwidth; /* width in longwords of bitmap */
418 register CfbBits *pdst; /* pointer to current word in bitmap */
419 PixmapPtr pStipple; /* pointer to stipple we want to fill with */
420 register int w;
421 int width, x, xrem, xSrc, ySrc;
422 CfbBits tmpSrc, tmpDst1, tmpDst2;
423 int stwidth, stippleWidth;
424 CfbBits *psrcS;
425 int rop, stiprop = 0;
426 int stippleHeight;
427 int *pwidthFree; /* copies of the pointers to free */
428 DDXPointPtr pptFree;
429 CfbBits fgfill, bgfill;
431 if (!(pGC->planemask))
432 return;
434 n = nInit * miFindMaxBand( cfbGetCompositeClip(pGC) );
435 if ( n == 0 )
436 return;
437 pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
438 pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
439 if(!pptFree || !pwidthFree)
441 if (pptFree) DEALLOCATE_LOCAL(pptFree);
442 if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
443 return;
445 pwidth = pwidthFree;
446 ppt = pptFree;
447 n = miClipSpans( cfbGetCompositeClip(pGC),
448 pptInit, pwidthInit, nInit,
449 ppt, pwidth, fSorted);
450 rop = pGC->alu;
451 if (pGC->fillStyle == FillStippled) {
452 switch (rop) {
453 case GXand:
454 case GXcopy:
455 case GXnoop:
456 case GXor:
457 stiprop = rop;
458 break;
459 default:
460 stiprop = rop;
461 rop = GXcopy;
464 fgfill = PFILL(pGC->fgPixel);
465 bgfill = PFILL(pGC->bgPixel);
468 * OK, so what's going on here? We have two Drawables:
470 * The Stipple:
471 * Depth = 1
472 * Width = stippleWidth
473 * Words per scanline = stwidth
474 * Pointer to pixels = pStipple->devPrivate.ptr
476 pStipple = pGC->stipple;
478 stwidth = pStipple->devKind / PGSZB;
479 stippleWidth = pStipple->drawable.width;
480 stippleHeight = pStipple->drawable.height;
483 * The Target:
484 * Depth = PSZ
485 * Width = determined from *pwidth
486 * Words per scanline = nlwidth
487 * Pointer to pixels = addrlBase
490 cfbGetLongWidthAndPointer (pDrawable, nlwidth, addrlBase)
492 /* this replaces rotating the stipple. Instead we just adjust the offset
493 * at which we start grabbing bits from the stipple.
494 * Ensure that ppt->x - xSrc >= 0 and ppt->y - ySrc >= 0,
495 * so that iline and xrem always stay within the stipple bounds.
497 modulus (pGC->patOrg.x, stippleWidth, xSrc);
498 xSrc += pDrawable->x - stippleWidth;
499 modulus (pGC->patOrg.y, stippleHeight, ySrc);
500 ySrc += pDrawable->y - stippleHeight;
502 while (n--)
504 iline = (ppt->y - ySrc) % stippleHeight;
505 x = ppt->x;
506 pdst = addrlBase + (ppt->y * nlwidth);
507 psrcS = (CfbBits *) pStipple->devPrivate.ptr + (iline * stwidth);
509 if (*pwidth)
511 width = *pwidth;
512 while(width > 0)
514 int xtemp;
515 #if PSZ != 32 || PPW != 1
516 int tmpx;
517 #endif
518 register CfbBits *ptemp;
519 register CfbBits *pdsttmp;
521 * Do a stripe through the stipple & destination w pixels
522 * wide. w is not more than:
523 * - the width of the destination
524 * - the width of the stipple
525 * - the distance between x and the next word
526 * boundary in the destination
527 * - the distance between x and the next word
528 * boundary in the stipple
531 /* width of dest/stipple */
532 xrem = (x - xSrc) % stippleWidth;
533 #if PSZ == 24
534 w = 1;
535 #else
536 w = min((stippleWidth - xrem), width);
537 /* dist to word bound in dest */
538 w = min(w, PPW - (x & PIM));
539 /* dist to word bound in stip */
540 w = min(w, MFB_PPW - (x & MFB_PIM));
541 #endif
543 xtemp = (xrem & MFB_PIM);
544 ptemp = (CfbBits *)(psrcS + (xrem >> MFB_PWSH));
545 #if PSZ == 24
546 tmpx = x & 3;
547 pdsttmp = pdst + ((x * 3)>>2);
548 #else
549 #if PSZ != 32 || PPW != 1
550 tmpx = x & PIM;
551 #endif
552 pdsttmp = pdst + (x>>PWSH);
553 #endif
554 switch ( pGC->fillStyle ) {
555 case FillOpaqueStippled:
556 #if PSZ == 24
557 getstipplepixels24(ptemp, xtemp, 0, &bgfill, &tmpDst1, xrem);
558 getstipplepixels24(ptemp, xtemp, 1, &fgfill, &tmpDst2, xrem);
559 #else
560 getstipplepixels(ptemp, xtemp, w, 0, &bgfill, &tmpDst1);
561 getstipplepixels(ptemp, xtemp, w, 1, &fgfill, &tmpDst2);
562 #endif
563 break;
564 case FillStippled:
565 /* Fill tmpSrc with the source pixels */
566 #if PSZ == 24
567 getbits24(pdsttmp, tmpSrc, x);
568 getstipplepixels24(ptemp, xtemp, 0, &tmpSrc, &tmpDst1, xrem);
569 #else
570 getbits(pdsttmp, tmpx, w, tmpSrc);
571 getstipplepixels(ptemp, xtemp, w, 0, &tmpSrc, &tmpDst1);
572 #endif
573 if (rop != stiprop) {
574 #if PSZ == 24
575 putbitsrop24(fgfill, 0, &tmpSrc, pGC->planemask, stiprop);
576 #else
577 putbitsrop(fgfill, 0, w, &tmpSrc, pGC->planemask, stiprop);
578 #endif
579 } else {
580 tmpSrc = fgfill;
582 #if PSZ == 24
583 getstipplepixels24(ptemp, xtemp, 1, &tmpSrc, &tmpDst2, xrem);
584 #else
585 getstipplepixels(ptemp, xtemp, w, 1, &tmpSrc, &tmpDst2);
586 #endif
587 break;
589 tmpDst2 |= tmpDst1;
590 #if PSZ == 24
591 putbitsrop24(tmpDst2, tmpx, pdsttmp, pGC->planemask, rop);
592 #else
593 putbitsrop(tmpDst2, tmpx, w, pdsttmp, pGC->planemask, rop);
594 #endif
595 x += w;
596 width -= w;
599 ppt++;
600 pwidth++;
602 DEALLOCATE_LOCAL(pptFree);
603 DEALLOCATE_LOCAL(pwidthFree);
606 #endif /* PSZ == 8 */
608 #if PSZ == 8
610 void
611 cfb8Stipple32FS (pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
612 DrawablePtr pDrawable;
613 GCPtr pGC;
614 int nInit; /* number of spans to fill */
615 DDXPointPtr pptInit; /* pointer to list of start points */
616 int *pwidthInit; /* pointer to list of n widths */
617 int fSorted;
619 /* next three parameters are post-clip */
620 int n; /* number of spans to fill */
621 DDXPointPtr ppt; /* pointer to list of start points */
622 int *pwidth; /* pointer to list of n widths */
623 CfbBits *src; /* pointer to bits in stipple, if needed */
624 int stippleHeight; /* height of the stipple */
625 PixmapPtr stipple;
627 int nlwDst; /* width in longwords of the dest pixmap */
628 int x,y,w; /* current span */
629 CfbBits startmask;
630 CfbBits endmask;
631 register CfbBits *dst; /* pointer to bits we're writing */
632 register int nlw;
633 CfbBits *dstTmp;
634 int nlwTmp;
636 CfbBits *pbits; /* pointer to start of pixmap */
637 register CfbBits xor;
638 register CfbBits mask;
639 register CfbBits bits; /* bits from stipple */
640 int wEnd;
642 int *pwidthFree; /* copies of the pointers to free */
643 DDXPointPtr pptFree;
644 cfbPrivGCPtr devPriv;
646 devPriv = cfbGetGCPrivate(pGC);
647 cfb8CheckStipple (pGC->alu, pGC->fgPixel, pGC->planemask);
648 n = nInit * miFindMaxBand(pGC->pCompositeClip);
649 if ( n == 0 )
650 return;
651 pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
652 pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
653 if(!pptFree || !pwidthFree)
655 if (pptFree) DEALLOCATE_LOCAL(pptFree);
656 if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
657 return;
659 pwidth = pwidthFree;
660 ppt = pptFree;
661 n = miClipSpans(pGC->pCompositeClip, pptInit, pwidthInit, nInit,
662 ppt, pwidth, fSorted);
664 stipple = pGC->pRotatedPixmap;
665 src = (CfbBits *)stipple->devPrivate.ptr;
666 stippleHeight = stipple->drawable.height;
668 cfbGetLongWidthAndPointer (pDrawable, nlwDst, pbits)
670 while (n--)
672 w = *pwidth++;
673 x = ppt->x;
674 y = ppt->y;
675 ppt++;
676 dst = pbits + (y * nlwDst) + (x >> PWSH);
677 if (((x & PIM) + w) <= PPW)
679 maskpartialbits(x, w, startmask);
680 endmask = 0;
681 nlw = 0;
683 else
685 maskbits (x, w, startmask, endmask, nlw);
687 bits = src[y % stippleHeight];
688 RotBitsLeft (bits, (x & ((PGSZ-1) & ~PIM)));
689 #if PPW == 4
690 if (cfb8StippleRRop == GXcopy)
692 xor = devPriv->xor;
693 if (w < (PGSZ*2))
695 if (startmask)
697 mask = cfb8PixelMasks[GetBitGroup(bits)];
698 *dst = (*dst & ~(mask & startmask)) |
699 (xor & (mask & startmask));
700 dst++;
701 RotBitsLeft (bits, PGSZB);
703 while (nlw--)
705 WriteBitGroup (dst,xor,GetBitGroup(bits))
706 dst++;
707 RotBitsLeft (bits, PGSZB);
709 if (endmask)
711 mask = cfb8PixelMasks[GetBitGroup(bits)];
712 *dst = (*dst & ~(mask & endmask)) |
713 (xor & (mask & endmask));
716 else
717 { /* XXX constants probably not OK here */
718 wEnd = 7 - (nlw & 7);
719 nlw = (nlw >> 3) + 1;
720 dstTmp = dst;
721 nlwTmp = nlw;
722 if (startmask)
724 mask = cfb8PixelMasks[GetBitGroup(bits)];
725 *dstTmp = (*dstTmp & ~(mask & startmask)) |
726 (xor & (mask & startmask));
727 dstTmp++;
728 RotBitsLeft (bits, PGSZB);
730 w = 7 - wEnd;
731 while (w--)
733 dst = dstTmp;
734 dstTmp++;
735 nlw = nlwTmp;
736 #if defined(__GNUC__) && defined(mc68020)
737 mask = cfb8PixelMasks[GetBitGroup(bits)];
738 xor = xor & mask;
739 mask = ~mask;
740 while (nlw--)
742 *dst = (*dst & mask) | xor;
743 dst += 8;
745 xor = devPriv->xor;
746 #else
747 #define SwitchBitsLoop(body) \
748 while (nlw--) \
750 body \
751 dst += 8; \
753 SwitchBitGroup(dst, xor, GetBitGroup(bits));
754 #undef SwitchBitsLoop
755 #endif
756 NextBitGroup (bits);
758 nlwTmp--;
759 w = wEnd + 1;
760 if (endmask)
762 mask = cfb8PixelMasks[GetBitGroup(bits)];
763 dst = dstTmp + (nlwTmp << 3);
764 *dst = (*dst & ~(mask & endmask)) |
765 (xor & (mask & endmask));
767 while (w--)
769 nlw = nlwTmp;
770 dst = dstTmp;
771 dstTmp++;
772 #if defined(__GNUC__) && defined(mc68020)
773 mask = cfb8PixelMasks[GetBitGroup(bits)];
774 xor = xor & mask;
775 mask = ~mask;
776 while (nlw--)
778 *dst = (*dst & mask) | xor;
779 dst += 8;
781 xor = devPriv->xor;
782 #else
783 #define SwitchBitsLoop(body) \
784 while (nlw--) \
786 body \
787 dst += 8; \
789 SwitchBitGroup(dst, xor, GetBitGroup(bits));
790 #undef SwitchBitsLoop
791 #endif
792 NextBitGroup (bits);
796 else
797 #endif /* PPW == 4 */
799 if (startmask)
801 xor = GetBitGroup(bits);
802 *dst = MaskRRopPixels(*dst, xor, startmask);
803 dst++;
804 RotBitsLeft (bits, PGSZB);
806 while (nlw--)
808 RRopBitGroup(dst, GetBitGroup(bits));
809 dst++;
810 RotBitsLeft (bits, PGSZB);
812 if (endmask)
814 xor = GetBitGroup(bits);
815 *dst = MaskRRopPixels(*dst, xor, endmask);
819 DEALLOCATE_LOCAL(pptFree);
820 DEALLOCATE_LOCAL(pwidthFree);
823 void
824 cfb8OpaqueStipple32FS (pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
825 DrawablePtr pDrawable;
826 GCPtr pGC;
827 int nInit; /* number of spans to fill */
828 DDXPointPtr pptInit; /* pointer to list of start points */
829 int *pwidthInit; /* pointer to list of n widths */
830 int fSorted;
832 /* next three parameters are post-clip */
833 int n; /* number of spans to fill */
834 DDXPointPtr ppt; /* pointer to list of start points */
835 int *pwidth; /* pointer to list of n widths */
836 CfbBits *src; /* pointer to bits in stipple, if needed */
837 int stippleHeight; /* height of the stipple */
838 PixmapPtr stipple;
840 int nlwDst; /* width in longwords of the dest pixmap */
841 int x,y,w; /* current span */
842 CfbBits startmask;
843 CfbBits endmask;
844 register CfbBits *dst; /* pointer to bits we're writing */
845 register int nlw;
846 CfbBits *dstTmp;
847 int nlwTmp;
849 CfbBits *pbits; /* pointer to start of pixmap */
850 register CfbBits xor;
851 register CfbBits bits; /* bits from stipple */
852 int wEnd;
854 int *pwidthFree; /* copies of the pointers to free */
855 DDXPointPtr pptFree;
856 cfbPrivGCPtr devPriv;
858 devPriv = cfbGetGCPrivate(pGC);
860 cfb8CheckOpaqueStipple(pGC->alu, pGC->fgPixel, pGC->bgPixel, pGC->planemask);
862 n = nInit * miFindMaxBand(pGC->pCompositeClip);
863 if ( n == 0 )
864 return;
865 pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
866 pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
867 if(!pptFree || !pwidthFree)
869 if (pptFree) DEALLOCATE_LOCAL(pptFree);
870 if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
871 return;
873 pwidth = pwidthFree;
874 ppt = pptFree;
875 n = miClipSpans(pGC->pCompositeClip, pptInit, pwidthInit, nInit,
876 ppt, pwidth, fSorted);
878 stipple = pGC->pRotatedPixmap;
879 src = (CfbBits *)stipple->devPrivate.ptr;
880 stippleHeight = stipple->drawable.height;
882 cfbGetLongWidthAndPointer (pDrawable, nlwDst, pbits)
884 while (n--)
886 w = *pwidth++;
887 x = ppt->x;
888 y = ppt->y;
889 ppt++;
890 dst = pbits + (y * nlwDst) + (x >> PWSH);
891 if (((x & PIM) + w) <= PPW)
893 maskpartialbits(x, w, startmask);
894 endmask = 0;
895 nlw = 0;
897 else
899 maskbits (x, w, startmask, endmask, nlw);
901 bits = src[y % stippleHeight];
902 RotBitsLeft (bits, (x & ((PGSZ-1) & ~PIM)));
903 #if PPW == 4
904 if (cfb8StippleRRop == GXcopy)
906 xor = devPriv->xor;
907 if (w < PGSZ*2)
909 if (startmask)
911 *dst = (*dst & ~startmask) |
912 (GetPixelGroup (bits) & startmask);
913 dst++;
914 RotBitsLeft (bits, PGSZB);
916 while (nlw--)
918 *dst++ = GetPixelGroup(bits);
919 RotBitsLeft (bits, PGSZB);
921 if (endmask)
923 *dst = (*dst & ~endmask) |
924 (GetPixelGroup (bits) & endmask);
927 else
928 { /* XXX consts probably not OK here */
929 wEnd = 7 - (nlw & 7);
930 nlw = (nlw >> 3) + 1;
931 dstTmp = dst;
932 nlwTmp = nlw;
933 if (startmask)
935 *dstTmp = (*dstTmp & ~startmask) |
936 (GetPixelGroup (bits) & startmask);
937 dstTmp++;
938 RotBitsLeft (bits, PGSZB);
940 w = 7 - wEnd;
941 while (w--)
943 nlw = nlwTmp;
944 dst = dstTmp;
945 dstTmp++;
946 xor = GetPixelGroup (bits);
947 while (nlw--)
949 *dst = xor;
950 dst += 8;
952 NextBitGroup (bits);
954 nlwTmp--;
955 w = wEnd + 1;
956 if (endmask)
958 dst = dstTmp + (nlwTmp << 3);
959 *dst = (*dst & ~endmask) |
960 (GetPixelGroup (bits) & endmask);
962 while (w--)
964 nlw = nlwTmp;
965 dst = dstTmp;
966 dstTmp++;
967 xor = GetPixelGroup (bits);
968 while (nlw--)
970 *dst = xor;
971 dst += 8;
973 NextBitGroup (bits);
977 else
978 #endif /* PPW == 4 */
980 if (startmask)
982 xor = GetBitGroup(bits);
983 *dst = MaskRRopPixels(*dst, xor, startmask);
984 dst++;
985 RotBitsLeft (bits, PGSZB);
987 while (nlw--)
989 RRopBitGroup(dst, GetBitGroup(bits));
990 dst++;
991 RotBitsLeft (bits, PGSZB);
993 if (endmask)
995 xor = GetBitGroup(bits);
996 *dst = MaskRRopPixels(*dst, xor, endmask);
1000 DEALLOCATE_LOCAL(pptFree);
1001 DEALLOCATE_LOCAL(pwidthFree);
1004 #endif /* PSZ == 8 */