]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/mfb/mfbpixmap.c
8feccd18091ef60cdf44e4ca1496781878f3bc72
[rdpsrv] / Xserver / programs / Xserver / mfb / mfbpixmap.c
1 /***********************************************************
2
3 Copyright (c) 1987  X Consortium
4
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
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 X CONSORTIUM 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.
21
22 Except as contained in this notice, the name of the X Consortium 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 X Consortium.
25
26
27 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
28
29                         All Rights Reserved
30
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.  
38
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.
46
47 ******************************************************************/
48 /* $XConsortium: mfbpixmap.c,v 5.13 94/04/17 20:28:28 dpw Exp $ */
49
50 /* pixmap management
51    written by drewry, september 1986
52
53    on a monchrome device, a pixmap is a bitmap.
54 */
55
56 #include "Xmd.h"
57 #include "scrnintstr.h"
58 #include "pixmapstr.h"
59 #include "maskbits.h"
60
61 #include "mfb.h"
62 #include "mi.h"
63
64 #include "servermd.h"
65
66 PixmapPtr
67 mfbCreatePixmap (pScreen, width, height, depth)
68     ScreenPtr   pScreen;
69     int         width;
70     int         height;
71     int         depth;
72 {
73     PixmapPtr pPixmap;
74     int datasize;
75     int paddedWidth;
76
77     if (depth != 1)
78         return NullPixmap;
79     paddedWidth = BitmapBytePad(width);
80     datasize = height * paddedWidth;
81     pPixmap = AllocatePixmap(pScreen, datasize);
82     if (!pPixmap)
83         return NullPixmap;
84     pPixmap->drawable.type = DRAWABLE_PIXMAP;
85     pPixmap->drawable.class = 0;
86     pPixmap->drawable.pScreen = pScreen;
87     pPixmap->drawable.depth = depth;
88     pPixmap->drawable.bitsPerPixel = depth;
89     pPixmap->drawable.id = 0;
90     pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
91     pPixmap->drawable.x = 0;
92     pPixmap->drawable.y = 0;
93     pPixmap->drawable.width = width;
94     pPixmap->drawable.height = height;
95     pPixmap->devKind = paddedWidth;
96     pPixmap->refcnt = 1;
97 #ifdef PIXPRIV
98     pPixmap->devPrivate.ptr =  datasize ?
99                 (pointer)((char *)pPixmap + pScreen->totalPixmapSize) : NULL;
100 #else
101     pPixmap->devPrivate.ptr = (pointer)(pPixmap + 1);
102 #endif
103     return pPixmap;
104 }
105
106 Bool
107 mfbDestroyPixmap(pPixmap)
108     PixmapPtr pPixmap;
109 {
110     if(--pPixmap->refcnt)
111         return TRUE;
112     xfree(pPixmap);
113     return TRUE;
114 }
115
116
117 PixmapPtr
118 mfbCopyPixmap(pSrc)
119     register PixmapPtr  pSrc;
120 {
121     register PixmapPtr  pDst;
122     int         size;
123     ScreenPtr pScreen;
124
125     size = pSrc->drawable.height * pSrc->devKind;
126     pScreen = pSrc->drawable.pScreen;
127     pDst = (*pScreen->CreatePixmap) (pScreen, pSrc->drawable.width, 
128                                 pSrc->drawable.height, pSrc->drawable.depth);
129     if (!pDst)
130         return NullPixmap;
131     memmove((char *)pDst->devPrivate.ptr, (char *)pSrc->devPrivate.ptr, size);
132     return pDst;
133 }
134
135
136 /* replicates a pattern to be a full 32 bits wide.
137    relies on the fact that each scnaline is longword padded.
138    doesn't do anything if pixmap is not a factor of 32 wide.
139    changes width field of pixmap if successful, so that the fast
140         XRotatePixmap code gets used if we rotate the pixmap later.
141
142    calculate number of times to repeat
143    for each scanline of pattern
144       zero out area to be filled with replicate
145       left shift and or in original as many times as needed
146 */
147 void
148 mfbPadPixmap(pPixmap)
149     PixmapPtr pPixmap;
150 {
151     register int width = pPixmap->drawable.width;
152     register int h;
153     register PixelType mask;
154     register PixelType *p;
155     register PixelType bits;    /* real pattern bits */
156     register int i;
157     int rep;                    /* repeat count for pattern */
158
159     if (width >= PPW)
160         return;
161
162     rep = PPW/width;
163     if (rep*width != PPW)
164         return;
165
166     mask = endtab[width];
167
168     p = (PixelType *)(pPixmap->devPrivate.ptr);
169     for (h=0; h < pPixmap->drawable.height; h++)
170     {
171         *p &= mask;
172         bits = *p;
173         for(i=1; i<rep; i++)
174         {
175             bits = SCRRIGHT(bits, width);
176             *p |= bits;
177         }
178         p++;
179     }
180     pPixmap->drawable.width = PPW;
181 }
182
183 /* Rotates pixmap pPix by w pixels to the right on the screen. Assumes that
184  * words are PPW bits wide, and that the least significant bit appears on the
185  * left.
186  */
187 void
188 mfbXRotatePixmap(pPix, rw)
189     PixmapPtr   pPix;
190     register int rw;
191 {
192     register PixelType  *pw, *pwFinal;
193     register PixelType  t;
194
195     if (pPix == NullPixmap)
196         return;
197
198     pw = (PixelType *)pPix->devPrivate.ptr;
199     rw %= (int)pPix->drawable.width;
200     if (rw < 0)
201         rw += (int)pPix->drawable.width;
202     if(pPix->drawable.width == PPW)
203     {
204         pwFinal = pw + pPix->drawable.height;
205         while(pw < pwFinal)
206         {
207             t = *pw;
208             *pw++ = SCRRIGHT(t, rw) | 
209                     (SCRLEFT(t, (PPW-rw)) & endtab[rw]);
210         }
211     }
212     else
213     {
214         /* We no longer do this.  Validate doesn't try to rotate odd-size
215          * tiles or stipples.  mfbUnnatural<tile/stipple>FS works directly off
216          * the unrotate tile/stipple in the GC
217          */
218         ErrorF("X internal error: trying to rotate odd-sized pixmap.\n");
219     }
220
221 }
222
223 /* Rotates pixmap pPix by h lines.  Assumes that h is always less than
224    pPix->height
225    works on any width.
226  */
227 void
228 mfbYRotatePixmap(pPix, rh)
229     register PixmapPtr  pPix;
230     int rh;
231 {
232     int nbyDown;        /* bytes to move down to row 0; also offset of
233                            row rh */
234     int nbyUp;          /* bytes to move up to line rh; also
235                            offset of first line moved down to 0 */
236     char *pbase;
237     char *ptmp;
238     int height;
239
240     if (pPix == NullPixmap)
241         return;
242     height = (int) pPix->drawable.height;
243     rh %= height;
244     if (rh < 0)
245         rh += height;
246
247     pbase = (char *)pPix->devPrivate.ptr;
248
249     nbyDown = rh * pPix->devKind;
250     nbyUp = (pPix->devKind * height) - nbyDown;
251     if(!(ptmp = (char *)ALLOCATE_LOCAL(nbyUp)))
252         return;
253
254     memmove(ptmp, pbase, nbyUp);                /* save the low rows */
255     memmove(pbase, pbase+nbyUp, nbyDown);       /* slide the top rows down */
256     memmove(pbase+nbyDown, ptmp, nbyUp);        /* move lower rows up to row rh */
257     DEALLOCATE_LOCAL(ptmp);
258 }
259
260 void
261 mfbCopyRotatePixmap(psrcPix, ppdstPix, xrot, yrot)
262     register PixmapPtr psrcPix, *ppdstPix;
263     int xrot, yrot;
264 {
265     register PixmapPtr pdstPix;
266
267     if ((pdstPix = *ppdstPix) &&
268         (pdstPix->devKind == psrcPix->devKind) &&
269         (pdstPix->drawable.height == psrcPix->drawable.height))
270     {
271         memmove((char *)pdstPix->devPrivate.ptr,
272                 (char *)psrcPix->devPrivate.ptr,
273               psrcPix->drawable.height * psrcPix->devKind);
274         pdstPix->drawable.width = psrcPix->drawable.width;
275         pdstPix->drawable.serialNumber = NEXT_SERIAL_NUMBER;
276     }
277     else
278     {
279         if (pdstPix)
280             /* FIX XBUG 6168 */
281             (*pdstPix->drawable.pScreen->DestroyPixmap)(pdstPix);
282         *ppdstPix = pdstPix = mfbCopyPixmap(psrcPix);
283         if (!pdstPix)
284             return;
285     }
286     mfbPadPixmap(pdstPix);
287     if (xrot)
288         mfbXRotatePixmap(pdstPix, xrot);
289     if (yrot)
290         mfbYRotatePixmap(pdstPix, yrot);
291 }