First import
[xorg_rtime.git] / xorg-server-1.4 / mfb / mfbsetsp.c
blob24add836cf3c9f32bcda861241ae8543103f90b0
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 ******************************************************************/
49 #ifdef HAVE_DIX_CONFIG_H
50 #include <dix-config.h>
51 #endif
53 #include <X11/X.h>
54 #include <X11/Xmd.h>
56 #include "misc.h"
57 #include "regionstr.h"
58 #include "gcstruct.h"
59 #include "windowstr.h"
60 #include "pixmapstr.h"
61 #include "scrnintstr.h"
63 #include "mfb.h"
64 #include "maskbits.h"
66 #include "servermd.h"
69 /* mfbSetScanline -- copies the bits from psrc to the drawable starting at
70 * (xStart, y) and continuing to (xEnd, y). xOrigin tells us where psrc
71 * starts on the scanline. (I.e., if this scanline passes through multiple
72 * boxes, we may not want to start grabbing bits at psrc but at some offset
73 * further on.)
75 void
76 mfbSetScanline(y, xOrigin, xStart, xEnd, psrc, alu, pdstBase, widthDst)
77 int y;
78 int xOrigin; /* where this scanline starts */
79 int xStart; /* first bit to use from scanline */
80 int xEnd; /* last bit to use from scanline + 1 */
81 register PixelType *psrc;
82 register int alu; /* raster op */
83 PixelType *pdstBase; /* start of the drawable */
84 int widthDst; /* width of drawable in words */
86 int w; /* width of scanline in bits */
87 register PixelType *pdst; /* where to put the bits */
88 register PixelType tmpSrc; /* scratch buffer to collect bits in */
89 int dstBit; /* offset in bits from beginning of
90 * word */
91 register int nstart; /* number of bits from first partial */
92 register int nend; /* " " last partial word */
93 int offSrc;
94 PixelType startmask, endmask;
95 int nlMiddle, nl;
97 pdst = mfbScanline(pdstBase, xStart, y, widthDst);
98 psrc += (xStart - xOrigin) >> PWSH;
99 offSrc = (xStart - xOrigin) & PIM;
100 w = xEnd - xStart;
101 dstBit = xStart & PIM;
103 if (dstBit + w <= PPW)
105 getandputrop(psrc, offSrc, dstBit, w, pdst, alu)
107 else
110 maskbits(xStart, w, startmask, endmask, nlMiddle);
111 if (startmask)
112 nstart = PPW - dstBit;
113 else
114 nstart = 0;
115 if (endmask)
116 nend = xEnd & PIM;
117 else
118 nend = 0;
119 if (startmask)
121 getandputrop(psrc, offSrc, dstBit, nstart, pdst, alu)
122 pdst++;
123 offSrc += nstart;
124 if (offSrc > PLST)
126 psrc++;
127 offSrc -= PPW;
130 nl = nlMiddle;
131 while (nl--)
133 getbits(psrc, offSrc, PPW, tmpSrc);
134 DoRop(*pdst, alu, tmpSrc, *pdst);
135 pdst++;
136 psrc++;
138 if (endmask)
140 getandputrop0(psrc, offSrc, nend, pdst, alu);
148 /* SetSpans -- for each span copy pwidth[i] bits from psrc to pDrawable at
149 * ppt[i] using the raster op from the GC. If fSorted is TRUE, the scanlines
150 * are in increasing Y order.
151 * Source bit lines are server scanline padded so that they always begin
152 * on a word boundary.
154 void
155 mfbSetSpans(pDrawable, pGC, pcharsrc, ppt, pwidth, nspans, fSorted)
156 DrawablePtr pDrawable;
157 GCPtr pGC;
158 char *pcharsrc;
159 register DDXPointPtr ppt;
160 int *pwidth;
161 int nspans;
162 int fSorted;
164 PixelType *psrc = (PixelType *)(pointer)pcharsrc;
165 PixelType *pdstBase; /* start of dst bitmap */
166 int widthDst; /* width of bitmap in words */
167 register BoxPtr pbox, pboxLast, pboxTest;
168 register DDXPointPtr pptLast;
169 int alu;
170 RegionPtr prgnDst;
171 int xStart, xEnd;
172 int yMax;
174 alu = pGC->alu;
175 prgnDst = pGC->pCompositeClip;
177 pptLast = ppt + nspans;
179 yMax = pDrawable->y + (int) pDrawable->height;
180 mfbGetPixelWidthAndPointer(pDrawable, widthDst, pdstBase);
182 pbox = REGION_RECTS(prgnDst);
183 pboxLast = pbox + REGION_NUM_RECTS(prgnDst);
185 if(fSorted)
187 /* scan lines sorted in ascending order. Because they are sorted, we
188 * don't have to check each scanline against each clip box. We can be
189 * sure that this scanline only has to be clipped to boxes at or after the
190 * beginning of this y-band
192 pboxTest = pbox;
193 while(ppt < pptLast)
195 pbox = pboxTest;
196 if(ppt->y >= yMax)
197 break;
198 while(pbox < pboxLast)
200 if(pbox->y1 > ppt->y)
202 /* scanline is before clip box */
203 break;
205 else if(pbox->y2 <= ppt->y)
207 /* clip box is before scanline */
208 pboxTest = ++pbox;
209 continue;
211 else if(pbox->x1 > ppt->x + *pwidth)
213 /* clip box is to right of scanline */
214 break;
216 else if(pbox->x2 <= ppt->x)
218 /* scanline is to right of clip box */
219 pbox++;
220 continue;
223 /* at least some of the scanline is in the current clip box */
224 xStart = max(pbox->x1, ppt->x);
225 xEnd = min(ppt->x + *pwidth, pbox->x2);
226 mfbSetScanline(ppt->y, ppt->x, xStart, xEnd, psrc, alu,
227 pdstBase, widthDst);
228 if(ppt->x + *pwidth <= pbox->x2)
230 /* End of the line, as it were */
231 break;
233 else
234 pbox++;
236 /* We've tried this line against every box; it must be outside them
237 * all. move on to the next point */
238 ppt++;
239 psrc += PixmapWidthInPadUnits(*pwidth, 1);
240 pwidth++;
243 else
245 /* scan lines not sorted. We must clip each line against all the boxes */
246 while(ppt < pptLast)
248 if(ppt->y >= 0 && ppt->y < yMax)
251 for(pbox = REGION_RECTS(prgnDst); pbox< pboxLast; pbox++)
253 if(pbox->y1 > ppt->y)
255 /* rest of clip region is above this scanline,
256 * skip it */
257 break;
259 if(pbox->y2 <= ppt->y)
261 /* clip box is below scanline */
262 pbox++;
263 break;
265 if(pbox->x1 <= ppt->x + *pwidth &&
266 pbox->x2 > ppt->x)
268 xStart = max(pbox->x1, ppt->x);
269 xEnd = min(pbox->x2, ppt->x + *pwidth);
270 mfbSetScanline(ppt->y, ppt->x, xStart, xEnd,
271 psrc, alu, pdstBase, widthDst);
276 psrc += PixmapWidthInPadUnits(*pwidth, 1);
277 ppt++;
278 pwidth++;