~ubuntu-branches/ubuntu/edgy/xorg-server/edgy-updates

« back to all changes in this revision

Viewing changes to ilbm/ilbmpixmap.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Parra Novo
  • Date: 2006-07-25 20:06:28 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20060725200628-gjmmd9gxfxdc4ejs
Tags: 1:1.1.1-0ubuntu1
* New Upstream version
* Changed Build-Depends from mesa-swrast-source to mesa-swx11-source,
  following Debian package nomenclature
* Re-did 12_security_policy_in_etc.diff for 1.1.1
* Dropped 15_security_allocate_local.diff (applied upstream)
* Dropped 16_SECURITY_setuid.diff (applied upstream)
* Dropped 000_ubuntu_fix_read_kernel_mapping.patch (applied upstream)
* Dropped 002_ubuntu_fix_for_certain_intel_chipsets.patch (applied upstream)
* Updated versioned Build-Depends on mesa-swx11-source to version
  6.5.0.cvs.20060725-0ubuntu1
* Added arrayobj.c, arrayobj.h, bitset.h & rbadaptors.h to
  GL/symlink-mesa.sh (linked from mesa-swx11-source)
* Added arrayobj.c to default build target on GL/mesa/main

Show diffs side-by-side

added added

removed removed

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