First import
[xorg_rtime.git] / xorg-server-1.4 / mfb / mfbfillrct.c
blobf9209d096e5bd3d75ec3030035d47630e136cc4b
1 /* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
2 /***********************************************************
4 Copyright 1987, 1998 The Open Group
6 Permission to use, copy, modify, distribute, and sell this software and its
7 documentation for any purpose is hereby granted without fee, provided that
8 the above copyright notice appear in all copies and that both that
9 copyright notice and this permission notice appear in supporting
10 documentation.
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of The Open Group shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from The Open Group.
27 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
29 All Rights Reserved
31 Permission to use, copy, modify, and distribute this software and its
32 documentation for any purpose and without fee is hereby granted,
33 provided that the above copyright notice appear in all copies and that
34 both that copyright notice and this permission notice appear in
35 supporting documentation, and that the name of Digital not be
36 used in advertising or publicity pertaining to distribution of the
37 software without specific, written prior permission.
39 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
45 SOFTWARE.
47 ******************************************************************/
48 #ifdef HAVE_DIX_CONFIG_H
49 #include <dix-config.h>
50 #endif
52 #include <X11/X.h>
53 #include <X11/Xprotostr.h>
54 #include "pixmapstr.h"
55 #include "gcstruct.h"
56 #include "windowstr.h"
57 #include "miscstruct.h"
58 #include "regionstr.h"
59 #include "scrnintstr.h"
61 #include "mfb.h"
62 #include "maskbits.h"
64 #define MODEQ(a, b) ((a) %= (b))
66 /*
67 filled rectangles.
68 translate the rectangles, clip them, and call the
69 helper function in the GC.
72 #define NUM_STACK_RECTS 1024
74 void
75 mfbPolyFillRect(pDrawable, pGC, nrectFill, prectInit)
76 DrawablePtr pDrawable;
77 GCPtr pGC;
78 int nrectFill; /* number of rectangles to fill */
79 xRectangle *prectInit; /* Pointer to first rectangle to fill */
81 xRectangle *prect;
82 RegionPtr prgnClip;
83 register BoxPtr pbox;
84 register BoxPtr pboxClipped;
85 BoxPtr pboxClippedBase;
86 BoxPtr pextent;
87 BoxRec stackRects[NUM_STACK_RECTS];
88 int numRects;
89 int n;
90 int xorg, yorg;
91 mfbPrivGC *priv;
92 int alu;
93 mfbFillAreaProcPtr pfn;
94 PixmapPtr ppix;
96 if (!(pGC->planemask & 1))
97 return;
99 priv = (mfbPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr;
100 alu = priv->ropFillArea;
101 pfn = priv->FillArea;
102 ppix = pGC->pRotatedPixmap;
103 prgnClip = pGC->pCompositeClip;
105 prect = prectInit;
106 xorg = pDrawable->x;
107 yorg = pDrawable->y;
108 if (xorg || yorg)
110 prect = prectInit;
111 n = nrectFill;
112 Duff (n, prect->x += xorg; prect->y += yorg; prect++);
116 prect = prectInit;
118 numRects = REGION_NUM_RECTS(prgnClip) * nrectFill;
119 if (numRects > NUM_STACK_RECTS)
121 pboxClippedBase = (BoxPtr)ALLOCATE_LOCAL(numRects * sizeof(BoxRec));
122 if (!pboxClippedBase)
123 return;
125 else
126 pboxClippedBase = stackRects;
128 pboxClipped = pboxClippedBase;
130 if (REGION_NUM_RECTS(prgnClip) == 1)
132 int x1, y1, x2, y2, bx2, by2;
134 pextent = REGION_RECTS(prgnClip);
135 x1 = pextent->x1;
136 y1 = pextent->y1;
137 x2 = pextent->x2;
138 y2 = pextent->y2;
139 while (nrectFill--)
141 if ((pboxClipped->x1 = prect->x) < x1)
142 pboxClipped->x1 = x1;
144 if ((pboxClipped->y1 = prect->y) < y1)
145 pboxClipped->y1 = y1;
147 bx2 = (int) prect->x + (int) prect->width;
148 if (bx2 > x2)
149 bx2 = x2;
150 pboxClipped->x2 = bx2;
152 by2 = (int) prect->y + (int) prect->height;
153 if (by2 > y2)
154 by2 = y2;
155 pboxClipped->y2 = by2;
157 prect++;
158 if ((pboxClipped->x1 < pboxClipped->x2) &&
159 (pboxClipped->y1 < pboxClipped->y2))
161 pboxClipped++;
165 else
167 int x1, y1, x2, y2, bx2, by2;
169 pextent = REGION_EXTENTS(pGC->pScreen, prgnClip);
170 x1 = pextent->x1;
171 y1 = pextent->y1;
172 x2 = pextent->x2;
173 y2 = pextent->y2;
174 while (nrectFill--)
176 BoxRec box;
178 if ((box.x1 = prect->x) < x1)
179 box.x1 = x1;
181 if ((box.y1 = prect->y) < y1)
182 box.y1 = y1;
184 bx2 = (int) prect->x + (int) prect->width;
185 if (bx2 > x2)
186 bx2 = x2;
187 box.x2 = bx2;
189 by2 = (int) prect->y + (int) prect->height;
190 if (by2 > y2)
191 by2 = y2;
192 box.y2 = by2;
194 prect++;
196 if ((box.x1 >= box.x2) || (box.y1 >= box.y2))
197 continue;
199 n = REGION_NUM_RECTS (prgnClip);
200 pbox = REGION_RECTS(prgnClip);
202 /* clip the rectangle to each box in the clip region
203 this is logically equivalent to calling Intersect()
205 while(n--)
207 pboxClipped->x1 = max(box.x1, pbox->x1);
208 pboxClipped->y1 = max(box.y1, pbox->y1);
209 pboxClipped->x2 = min(box.x2, pbox->x2);
210 pboxClipped->y2 = min(box.y2, pbox->y2);
211 pbox++;
213 /* see if clipping left anything */
214 if(pboxClipped->x1 < pboxClipped->x2 &&
215 pboxClipped->y1 < pboxClipped->y2)
217 pboxClipped++;
222 if (pboxClipped != pboxClippedBase)
223 (*pfn) (pDrawable,pboxClipped-pboxClippedBase, pboxClippedBase, alu, ppix);
224 if (pboxClippedBase != stackRects)
225 DEALLOCATE_LOCAL(pboxClippedBase);