Initial commit
[xorg_rtime.git] / xorg-server-1.4 / mfb / mfbpixmap.c
blobe3497245155ae5a34ebc0ff7ad41232f9b6072c0
1 /***********************************************************
3 Copyright 1987, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
26 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
28 All Rights Reserved
30 Permission to use, copy, modify, and distribute this software and its
31 documentation for any purpose and without fee is hereby granted,
32 provided that the above copyright notice appear in all copies and that
33 both that copyright notice and this permission notice appear in
34 supporting documentation, and that the name of Digital not be
35 used in advertising or publicity pertaining to distribution of the
36 software without specific, written prior permission.
38 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
44 SOFTWARE.
46 ******************************************************************/
48 /* pixmap management
49 written by drewry, september 1986
51 on a monchrome device, a pixmap is a bitmap.
54 #ifdef HAVE_DIX_CONFIG_H
55 #include <dix-config.h>
56 #endif
58 #include <string.h>
60 #include <X11/Xmd.h>
61 #include "scrnintstr.h"
62 #include "pixmapstr.h"
63 #include "maskbits.h"
65 #include "mfb.h"
66 #include "mi.h"
68 #include "servermd.h"
71 PixmapPtr
72 mfbCreatePixmap (pScreen, width, height, depth)
73 ScreenPtr pScreen;
74 int width;
75 int height;
76 int depth;
78 PixmapPtr pPixmap;
79 size_t datasize;
80 size_t paddedWidth;
82 if (depth != 1)
83 return NullPixmap;
84 paddedWidth = BitmapBytePad(width);
85 if (paddedWidth / 4 > 32767 || height > 32767)
86 return NullPixmap;
87 datasize = height * paddedWidth;
88 pPixmap = AllocatePixmap(pScreen, datasize);
89 if (!pPixmap)
90 return NullPixmap;
91 pPixmap->drawable.type = DRAWABLE_PIXMAP;
92 pPixmap->drawable.class = 0;
93 pPixmap->drawable.pScreen = pScreen;
94 pPixmap->drawable.depth = depth;
95 pPixmap->drawable.bitsPerPixel = depth;
96 pPixmap->drawable.id = 0;
97 pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
98 pPixmap->drawable.x = 0;
99 pPixmap->drawable.y = 0;
100 pPixmap->drawable.width = width;
101 pPixmap->drawable.height = height;
102 pPixmap->devKind = paddedWidth;
103 pPixmap->refcnt = 1;
104 pPixmap->devPrivate.ptr = datasize ?
105 (pointer)((char *)pPixmap + pScreen->totalPixmapSize) : NULL;
106 return pPixmap;
110 Bool
111 mfbDestroyPixmap(pPixmap)
112 PixmapPtr pPixmap;
114 if(--pPixmap->refcnt)
115 return TRUE;
116 xfree(pPixmap);
117 return TRUE;
121 PixmapPtr
122 mfbCopyPixmap(pSrc)
123 register PixmapPtr pSrc;
125 register PixmapPtr pDst;
126 int size;
127 ScreenPtr pScreen;
129 size = pSrc->drawable.height * pSrc->devKind;
130 pScreen = pSrc->drawable.pScreen;
131 pDst = (*pScreen->CreatePixmap) (pScreen, pSrc->drawable.width,
132 pSrc->drawable.height, pSrc->drawable.depth);
133 if (!pDst)
134 return NullPixmap;
135 memmove((char *)pDst->devPrivate.ptr, (char *)pSrc->devPrivate.ptr, size);
136 return pDst;
140 /* replicates a pattern to be a full 32 bits wide.
141 relies on the fact that each scnaline is longword padded.
142 doesn't do anything if pixmap is not a factor of 32 wide.
143 changes width field of pixmap if successful, so that the fast
144 XRotatePixmap code gets used if we rotate the pixmap later.
146 calculate number of times to repeat
147 for each scanline of pattern
148 zero out area to be filled with replicate
149 left shift and or in original as many times as needed
151 void
152 mfbPadPixmap(pPixmap)
153 PixmapPtr pPixmap;
155 register int width = pPixmap->drawable.width;
156 register int h;
157 register PixelType mask;
158 register PixelType *p;
159 register PixelType bits; /* real pattern bits */
160 register int i;
161 int rep; /* repeat count for pattern */
163 if (width >= PPW)
164 return;
166 rep = PPW/width;
167 if (rep*width != PPW)
168 return;
170 mask = endtab[width];
172 p = (PixelType *)(pPixmap->devPrivate.ptr);
173 for (h=0; h < pPixmap->drawable.height; h++)
175 *p &= mask;
176 bits = *p;
177 for(i=1; i<rep; i++)
179 bits = SCRRIGHT(bits, width);
180 *p |= bits;
182 p++;
184 pPixmap->drawable.width = PPW;
187 /* Rotates pixmap pPix by w pixels to the right on the screen. Assumes that
188 * words are PPW bits wide, and that the least significant bit appears on the
189 * left.
191 void
192 mfbXRotatePixmap(pPix, rw)
193 PixmapPtr pPix;
194 register int rw;
196 register PixelType *pw, *pwFinal;
197 register PixelType t;
199 if (pPix == NullPixmap)
200 return;
202 pw = (PixelType *)pPix->devPrivate.ptr;
203 rw %= (int)pPix->drawable.width;
204 if (rw < 0)
205 rw += (int)pPix->drawable.width;
206 if(pPix->drawable.width == PPW)
208 pwFinal = pw + pPix->drawable.height;
209 while(pw < pwFinal)
211 t = *pw;
212 *pw++ = SCRRIGHT(t, rw) |
213 (SCRLEFT(t, (PPW-rw)) & endtab[rw]);
216 else
218 /* We no longer do this. Validate doesn't try to rotate odd-size
219 * tiles or stipples. mfbUnnatural<tile/stipple>FS works directly off
220 * the unrotate tile/stipple in the GC
222 ErrorF("X internal error: trying to rotate odd-sized pixmap.\n");
227 /* Rotates pixmap pPix by h lines. Assumes that h is always less than
228 pPix->height
229 works on any width.
231 void
232 mfbYRotatePixmap(pPix, rh)
233 register PixmapPtr pPix;
234 int rh;
236 int nbyDown; /* bytes to move down to row 0; also offset of
237 row rh */
238 int nbyUp; /* bytes to move up to line rh; also
239 offset of first line moved down to 0 */
240 char *pbase;
241 char *ptmp;
242 int height;
244 if (pPix == NullPixmap)
245 return;
246 height = (int) pPix->drawable.height;
247 rh %= height;
248 if (rh < 0)
249 rh += height;
251 pbase = (char *)pPix->devPrivate.ptr;
253 nbyDown = rh * pPix->devKind;
254 nbyUp = (pPix->devKind * height) - nbyDown;
255 if(!(ptmp = (char *)ALLOCATE_LOCAL(nbyUp)))
256 return;
258 memmove(ptmp, pbase, nbyUp); /* save the low rows */
259 memmove(pbase, pbase+nbyUp, nbyDown); /* slide the top rows down */
260 memmove(pbase+nbyDown, ptmp, nbyUp); /* move lower rows up to row rh */
261 DEALLOCATE_LOCAL(ptmp);
264 void
265 mfbCopyRotatePixmap(psrcPix, ppdstPix, xrot, yrot)
266 register PixmapPtr psrcPix, *ppdstPix;
267 int xrot, yrot;
269 register PixmapPtr pdstPix;
271 if ((pdstPix = *ppdstPix) &&
272 (pdstPix->devKind == psrcPix->devKind) &&
273 (pdstPix->drawable.height == psrcPix->drawable.height))
275 memmove((char *)pdstPix->devPrivate.ptr,
276 (char *)psrcPix->devPrivate.ptr,
277 psrcPix->drawable.height * psrcPix->devKind);
278 pdstPix->drawable.width = psrcPix->drawable.width;
279 pdstPix->drawable.serialNumber = NEXT_SERIAL_NUMBER;
281 else
283 if (pdstPix)
284 /* FIX XBUG 6168 */
285 (*pdstPix->drawable.pScreen->DestroyPixmap)(pdstPix);
286 *ppdstPix = pdstPix = mfbCopyPixmap(psrcPix);
287 if (!pdstPix)
288 return;
290 mfbPadPixmap(pdstPix);
291 if (xrot)
292 mfbXRotatePixmap(pdstPix, xrot);
293 if (yrot)
294 mfbYRotatePixmap(pdstPix, yrot);