First import
[xorg_rtime.git] / xorg-server-1.4 / fb / fbpush.c
blob891572f0d380b4fae3aee36e6c4f3723daec6489
1 /*
2 * Copyright © 1998 Keith Packard
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Keith Packard not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Keith Packard makes no
11 * representations about the suitability of this software for any purpose. It
12 * is provided "as is" without express or implied warranty.
14 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
23 #ifdef HAVE_DIX_CONFIG_H
24 #include <dix-config.h>
25 #endif
27 #include "fb.h"
29 void
30 fbPushPattern (DrawablePtr pDrawable,
31 GCPtr pGC,
33 FbStip *src,
34 FbStride srcStride,
35 int srcX,
37 int x,
38 int y,
40 int width,
41 int height)
43 FbStip *s, bitsMask, bitsMask0, bits;
44 int xspan;
45 int w;
46 int lenspan;
48 src += srcX >> FB_STIP_SHIFT;
49 srcX &= FB_STIP_MASK;
51 bitsMask0 = FbStipMask (srcX, 1);
53 while (height--)
55 bitsMask = bitsMask0;
56 w = width;
57 s = src;
58 src += srcStride;
59 bits = READ(s++);
60 xspan = x;
61 while (w)
63 if (bits & bitsMask)
65 lenspan = 0;
68 lenspan++;
69 if (lenspan == w)
70 break;
71 bitsMask = FbStipRight (bitsMask, 1);
72 if (!bitsMask)
74 bits = READ(s++);
75 bitsMask = FbBitsMask(0,1);
77 } while (bits & bitsMask);
78 fbFill (pDrawable, pGC, xspan, y, lenspan, 1);
79 xspan += lenspan;
80 w -= lenspan;
82 else
86 w--;
87 xspan++;
88 if (!w)
89 break;
90 bitsMask = FbStipRight (bitsMask, 1);
91 if (!bitsMask)
93 bits = READ(s++);
94 bitsMask = FbBitsMask(0,1);
96 } while (!(bits & bitsMask));
99 y++;
103 void
104 fbPushFill (DrawablePtr pDrawable,
105 GCPtr pGC,
107 FbStip *src,
108 FbStride srcStride,
109 int srcX,
111 int x,
112 int y,
113 int width,
114 int height)
116 FbGCPrivPtr pPriv = fbGetGCPrivate(pGC);
118 if (pGC->fillStyle == FillSolid)
120 FbBits *dst;
121 FbStride dstStride;
122 int dstBpp;
123 int dstXoff, dstYoff;
124 int dstX;
125 int dstWidth;
127 fbGetDrawable (pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
128 dst = dst + (y + dstYoff) * dstStride;
129 dstX = (x + dstXoff) * dstBpp;
130 dstWidth = width * dstBpp;
131 if (dstBpp == 1)
133 fbBltStip (src,
134 srcStride,
135 srcX,
137 (FbStip *) dst,
138 FbBitsStrideToStipStride (dstStride),
139 dstX,
141 dstWidth,
142 height,
144 FbStipple1Rop(pGC->alu,pGC->fgPixel),
145 pPriv->pm,
146 dstBpp);
148 else
150 fbBltOne (src,
151 srcStride,
152 srcX,
154 dst,
155 dstStride,
156 dstX,
157 dstBpp,
159 dstWidth,
160 height,
162 pPriv->and, pPriv->xor,
163 fbAnd(GXnoop,(FbBits) 0,FB_ALLONES),
164 fbXor(GXnoop,(FbBits) 0,FB_ALLONES));
166 fbFinishAccess (pDrawable);
168 else
170 fbPushPattern (pDrawable, pGC, src, srcStride, srcX,
171 x, y, width, height);
175 void
176 fbPushImage (DrawablePtr pDrawable,
177 GCPtr pGC,
179 FbStip *src,
180 FbStride srcStride,
181 int srcX,
183 int x,
184 int y,
185 int width,
186 int height)
188 RegionPtr pClip = fbGetCompositeClip (pGC);
189 int nbox;
190 BoxPtr pbox;
191 int x1, y1, x2, y2;
193 for (nbox = REGION_NUM_RECTS (pClip),
194 pbox = REGION_RECTS(pClip);
195 nbox--;
196 pbox++)
198 x1 = x;
199 y1 = y;
200 x2 = x + width;
201 y2 = y + height;
202 if (x1 < pbox->x1)
203 x1 = pbox->x1;
204 if (y1 < pbox->y1)
205 y1 = pbox->y1;
206 if (x2 > pbox->x2)
207 x2 = pbox->x2;
208 if (y2 > pbox->y2)
209 y2 = pbox->y2;
210 if (x1 >= x2 || y1 >= y2)
211 continue;
212 fbPushFill (pDrawable,
213 pGC,
215 src + (y1 - y) * srcStride,
216 srcStride,
217 srcX + (x1 - x),
221 x2 - x1,
222 y2 - y1);
226 void
227 fbPushPixels (GCPtr pGC,
228 PixmapPtr pBitmap,
229 DrawablePtr pDrawable,
230 int dx,
231 int dy,
232 int xOrg,
233 int yOrg)
235 FbStip *stip;
236 FbStride stipStride;
237 int stipBpp;
238 int stipXoff, stipYoff; /* Assumed to be zero */
240 fbGetStipDrawable (&pBitmap->drawable, stip, stipStride, stipBpp, stipXoff, stipYoff);
242 fbPushImage (pDrawable, pGC,
243 stip, stipStride, 0,
244 xOrg, yOrg, dx, dy);