Initial commit
[xorg_rtime.git] / xorg-server-1.4 / afb / afbsetsp.c
blobcb36dba991e2790ea9749b3b4f2a51ae4c5dd635
1 /* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
2 /***********************************************************
4 Copyright (c) 1987 X Consortium
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 Except as contained in this notice, the name of the X Consortium shall not be
24 used in advertising or otherwise to promote the sale, use or other dealings
25 in this Software without prior written authorization from the X Consortium.
28 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
30 All Rights Reserved
32 Permission to use, copy, modify, and distribute this software and its
33 documentation for any purpose and without fee is hereby granted,
34 provided that the above copyright notice appear in all copies and that
35 both that copyright notice and this permission notice appear in
36 supporting documentation, and that the name of Digital not be
37 used in advertising or publicity pertaining to distribution of the
38 software without specific, written prior permission.
40 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
41 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
42 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
43 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
44 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
45 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
46 SOFTWARE.
48 ******************************************************************/
50 #ifdef HAVE_DIX_CONFIG_H
51 #include <dix-config.h>
52 #endif
54 #include <X11/X.h>
55 #include <X11/Xmd.h>
57 #include "misc.h"
58 #include "regionstr.h"
59 #include "gcstruct.h"
60 #include "windowstr.h"
61 #include "pixmapstr.h"
62 #include "scrnintstr.h"
64 #include "afb.h"
65 #include "maskbits.h"
67 #include "servermd.h"
70 /* afbSetScanline -- copies the bits from psrc to the drawable starting at
71 * (xStart, y) and continuing to (xEnd, y). xOrigin tells us where psrc
72 * starts on the scanline. (I.e., if this scanline passes through multiple
73 * boxes, we may not want to start grabbing bits at psrc but at some offset
74 * further on.)
76 static void
77 afbSetScanline(int y, int xOrigin, int xStart, int xEnd, PixelType *psrc,
78 int alu, PixelType *pdstBase, int widthDst, int sizeDst,
79 int depthDst, int sizeSrc)
81 int w; /* width of scanline in bits */
82 register PixelType *pdst; /* where to put the bits */
83 register PixelType tmpSrc; /* scratch buffer to collect bits in */
84 int dstBit; /* offset in bits from beginning of
85 * word */
86 register int nstart; /* number of bits from first partial */
87 register int nend; /* " " last partial word */
88 int offSrc;
89 PixelType startmask, endmask;
90 PixelType *savePsrc = psrc + ((xStart - xOrigin) >> PWSH);
91 int nlMiddle, nl;
92 int d;
94 for (d = 0; d < depthDst; d++) {
95 pdst = afbScanline(pdstBase, xStart, y, widthDst) + sizeDst * d; /* @@@ NEXT PLANE @@@ */
96 psrc = savePsrc + sizeSrc * d; /* @@@ NEXT PLANE @@@ */
97 offSrc = (xStart - xOrigin) & PIM;
98 w = xEnd - xStart;
99 dstBit = xStart & PIM;
101 if (dstBit + w <= PPW) {
102 getandputrop(psrc, offSrc, dstBit, w, pdst, alu)
103 } else {
104 maskbits(xStart, w, startmask, endmask, nlMiddle);
105 if (startmask)
106 nstart = PPW - dstBit;
107 else
108 nstart = 0;
109 if (endmask)
110 nend = xEnd & PIM;
111 else
112 nend = 0;
113 if (startmask) {
114 getandputrop(psrc, offSrc, dstBit, nstart, pdst, alu)
115 pdst++;
116 offSrc += nstart;
117 if (offSrc > PLST) {
118 psrc++;
119 offSrc -= PPW;
122 nl = nlMiddle;
123 while (nl--) {
124 getbits(psrc, offSrc, PPW, tmpSrc);
125 DoRop(*pdst, alu, tmpSrc, *pdst);
126 pdst++;
127 psrc++;
129 if (endmask) {
130 getandputrop0(psrc, offSrc, nend, pdst, alu);
138 /* SetSpans -- for each span copy pwidth[i] bits from psrc to pDrawable at
139 * ppt[i] using the raster op from the GC. If fSorted is TRUE, the scanlines
140 * are in increasing Y order.
141 * Source bit lines are server scanline padded so that they always begin
142 * on a word boundary.
144 void
145 afbSetSpans(pDrawable, pGC, pcharsrc, ppt, pwidth, nspans, fSorted)
146 DrawablePtr pDrawable;
147 GCPtr pGC;
148 char *pcharsrc;
149 register DDXPointPtr ppt;
150 int *pwidth;
151 int nspans;
152 int fSorted;
154 PixelType *psrc = (PixelType *)pcharsrc;
155 PixelType *pdstBase; /* start of dst bitmap */
156 int widthDst; /* width of bitmap in words */
157 int sizeDst;
158 int depthDst;
159 int sizeSrc = 0;
160 register BoxPtr pbox, pboxLast, pboxTest;
161 register DDXPointPtr pptLast;
162 int alu;
163 RegionPtr prgnDst;
164 int xStart, xEnd;
165 int yMax;
167 alu = pGC->alu;
168 prgnDst = pGC->pCompositeClip;
170 pptLast = ppt + nspans;
172 yMax = pDrawable->y + (int) pDrawable->height;
173 afbGetPixelWidthSizeDepthAndPointer(pDrawable, widthDst, sizeDst, depthDst,
174 pdstBase);
176 pbox = REGION_RECTS(prgnDst);
177 pboxLast = pbox + REGION_NUM_RECTS(prgnDst);
179 if(fSorted) {
180 /* scan lines sorted in ascending order. Because they are sorted, we
181 * don't have to check each scanline against each clip box. We can be
182 * sure that this scanline only has to be clipped to boxes at or after the
183 * beginning of this y-band
185 pboxTest = pbox;
186 while(ppt < pptLast) {
187 pbox = pboxTest;
188 if(ppt->y >= yMax)
189 break;
190 while(pbox < pboxLast) {
191 if(pbox->y1 > ppt->y) {
192 /* scanline is before clip box */
193 break;
194 } else if(pbox->y2 <= ppt->y) {
195 /* clip box is before scanline */
196 pboxTest = ++pbox;
197 continue;
198 } else if(pbox->x1 > ppt->x + *pwidth) {
199 /* clip box is to right of scanline */
200 break;
201 } else if(pbox->x2 <= ppt->x) {
202 /* scanline is to right of clip box */
203 pbox++;
204 continue;
207 /* at least some of the scanline is in the current clip box */
208 xStart = max(pbox->x1, ppt->x);
209 xEnd = min(ppt->x + *pwidth, pbox->x2);
210 sizeSrc = PixmapWidthInPadUnits(*pwidth, 1);
211 afbSetScanline(ppt->y, ppt->x, xStart, xEnd, psrc, alu, pdstBase,
212 widthDst, sizeDst, depthDst, sizeSrc);
213 if(ppt->x + *pwidth <= pbox->x2) {
214 /* End of the line, as it were */
215 break;
216 } else
217 pbox++;
219 /* We've tried this line against every box; it must be outside them
220 * all. move on to the next point */
221 ppt++;
222 psrc += sizeSrc * depthDst;
223 pwidth++;
225 } else {
226 /* scan lines not sorted. We must clip each line against all the boxes */
227 while(ppt < pptLast) {
228 if(ppt->y >= 0 && ppt->y < yMax) {
229 for(pbox = REGION_RECTS(prgnDst); pbox< pboxLast; pbox++) {
230 if(pbox->y1 > ppt->y) {
231 /* rest of clip region is above this scanline,
232 * skip it */
233 break;
235 if(pbox->y2 <= ppt->y) {
236 /* clip box is below scanline */
237 pbox++;
238 break;
240 if(pbox->x1 <= ppt->x + *pwidth &&
241 pbox->x2 > ppt->x) {
242 xStart = max(pbox->x1, ppt->x);
243 xEnd = min(pbox->x2, ppt->x + *pwidth);
244 sizeSrc = PixmapWidthInPadUnits(*pwidth, 1);
245 afbSetScanline(ppt->y, ppt->x, xStart, xEnd, psrc, alu,
246 pdstBase, widthDst, sizeDst, depthDst,
247 sizeSrc);
252 psrc += sizeSrc * depthDst;
253 ppt++;
254 pwidth++;