~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to mfb/mfbclip.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XFree86: xc/programs/Xserver/mfb/mfbclip.c,v 1.5 2001/12/14 20:00:05 dawes Exp $ */
 
2
/***********************************************************
 
3
 
 
4
Copyright 1987, 1998  The Open Group
 
5
 
 
6
Permission to use, copy, modify, distribute, and sell this software and its
 
7
documentation for any purpose is hereby granted without fee, provided that
 
8
the above copyright notice appear in all copies and that both that
 
9
copyright notice and this permission notice appear in supporting
 
10
documentation.
 
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
OPEN GROUP 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 Open Group 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 Open Group.
 
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
/* $Xorg: mfbclip.c,v 1.4 2001/02/09 02:05:18 xorgcvs Exp $ */
 
49
#ifdef HAVE_DIX_CONFIG_H
 
50
#include <dix-config.h>
 
51
#endif
 
52
 
 
53
#include <X11/X.h>
 
54
#include "regionstr.h"
 
55
#include "pixmapstr.h"
 
56
#include "scrnintstr.h"
 
57
#include "regionstr.h"
 
58
#include "gc.h"
 
59
#include "maskbits.h"
 
60
#include "mi.h"
 
61
#include "mfb.h"
 
62
 
 
63
#define ADDRECT(reg,r,fr,rx1,ry1,rx2,ry2)                       \
 
64
if (((rx1) < (rx2)) && ((ry1) < (ry2)) &&                       \
 
65
    (!((reg)->data->numRects &&                                 \
 
66
       ((r-1)->y1 == (ry1)) &&                                  \
 
67
       ((r-1)->y2 == (ry2)) &&                                  \
 
68
       ((r-1)->x1 <= (rx1)) &&                                  \
 
69
       ((r-1)->x2 >= (rx2)))))                                  \
 
70
{                                                               \
 
71
    if ((reg)->data->numRects == (reg)->data->size)             \
 
72
    {                                                           \
 
73
        miRectAlloc(reg, 1);                                    \
 
74
        fr = REGION_BOXPTR(reg);                                \
 
75
        r = fr + (reg)->data->numRects;                         \
 
76
    }                                                           \
 
77
    r->x1 = (rx1);                                              \
 
78
    r->y1 = (ry1);                                              \
 
79
    r->x2 = (rx2);                                              \
 
80
    r->y2 = (ry2);                                              \
 
81
    (reg)->data->numRects++;                                    \
 
82
    if(r->x1 < (reg)->extents.x1)                               \
 
83
        (reg)->extents.x1 = r->x1;                              \
 
84
    if(r->x2 > (reg)->extents.x2)                               \
 
85
        (reg)->extents.x2 = r->x2;                              \
 
86
    r++;                                                        \
 
87
}
 
88
 
 
89
/* Convert bitmap clip mask into clipping region. 
 
90
 * First, goes through each line and makes boxes by noting the transitions
 
91
 * from 0 to 1 and 1 to 0.
 
92
 * Then it coalesces the current line with the previous if they have boxes
 
93
 * at the same X coordinates.
 
94
 */
 
95
RegionPtr
 
96
mfbPixmapToRegion(pPix)
 
97
    PixmapPtr   pPix;
 
98
{
 
99
    register RegionPtr  pReg;
 
100
    register PixelType  *pw, w;
 
101
    register int        ib;
 
102
    int                 width, h, base, rx1 = 0, crects;
 
103
    PixelType           *pwLineEnd;
 
104
    int                 irectPrevStart, irectLineStart;
 
105
    register BoxPtr     prectO, prectN;
 
106
    BoxPtr              FirstRect, rects, prectLineStart;
 
107
    Bool                fInBox, fSame;
 
108
    register PixelType  mask0 = mask[0];
 
109
    PixelType           *pwLine;
 
110
    int                 nWidth;
 
111
 
 
112
    pReg = REGION_CREATE(pPix->drawable.pScreen, NULL, 1);
 
113
    if(!pReg)
 
114
        return NullRegion;
 
115
    FirstRect = REGION_BOXPTR(pReg);
 
116
    rects = FirstRect;
 
117
 
 
118
    pwLine = (PixelType *) pPix->devPrivate.ptr;
 
119
    nWidth = pPix->devKind / PGSZB;
 
120
 
 
121
    width = pPix->drawable.width;
 
122
    pReg->extents.x1 = width - 1;
 
123
    pReg->extents.x2 = 0;
 
124
    irectPrevStart = -1;
 
125
    for(h = 0; h < pPix->drawable.height; h++)
 
126
    {
 
127
        pw = pwLine;
 
128
        pwLine += nWidth;
 
129
        irectLineStart = rects - FirstRect;
 
130
        /* If the Screen left most bit of the word is set, we're starting in
 
131
         * a box */
 
132
        if(*pw & mask0)
 
133
        {
 
134
            fInBox = TRUE;
 
135
            rx1 = 0;
 
136
        }
 
137
        else
 
138
            fInBox = FALSE;
 
139
        /* Process all words which are fully in the pixmap */
 
140
        pwLineEnd = pw + (width >> PWSH);
 
141
        for (base = 0; pw < pwLineEnd; base += PPW)
 
142
        {
 
143
            w = *pw++;
 
144
            if (fInBox)
 
145
            {
 
146
                if (!~w)
 
147
                    continue;
 
148
            }
 
149
            else
 
150
            {
 
151
                if (!w)
 
152
                    continue;
 
153
            }
 
154
            for(ib = 0; ib < PPW; ib++)
 
155
            {
 
156
                /* If the Screen left most bit of the word is set, we're
 
157
                 * starting a box */
 
158
                if(w & mask0)
 
159
                {
 
160
                    if(!fInBox)
 
161
                    {
 
162
                        rx1 = base + ib;
 
163
                        /* start new box */
 
164
                        fInBox = TRUE;
 
165
                    }
 
166
                }
 
167
                else
 
168
                {
 
169
                    if(fInBox)
 
170
                    {
 
171
                        /* end box */
 
172
                        ADDRECT(pReg, rects, FirstRect,
 
173
                                rx1, h, base + ib, h + 1);
 
174
                        fInBox = FALSE;
 
175
                    }
 
176
                }
 
177
                /* Shift the word VISUALLY left one. */
 
178
                w = SCRLEFT(w, 1);
 
179
            }
 
180
        }
 
181
        if(width & PIM)
 
182
        {
 
183
            /* Process final partial word on line */
 
184
            w = *pw++;
 
185
            for(ib = 0; ib < (width & PIM); ib++)
 
186
            {
 
187
                /* If the Screen left most bit of the word is set, we're
 
188
                 * starting a box */
 
189
                if(w & mask0)
 
190
                {
 
191
                    if(!fInBox)
 
192
                    {
 
193
                        rx1 = base + ib;
 
194
                        /* start new box */
 
195
                        fInBox = TRUE;
 
196
                    }
 
197
                }
 
198
                else
 
199
                {
 
200
                    if(fInBox)
 
201
                    {
 
202
                        /* end box */
 
203
                        ADDRECT(pReg, rects, FirstRect,
 
204
                                rx1, h, base + ib, h + 1);
 
205
                        fInBox = FALSE;
 
206
                    }
 
207
                }
 
208
                /* Shift the word VISUALLY left one. */
 
209
                w = SCRLEFT(w, 1);
 
210
            }
 
211
        }
 
212
        /* If scanline ended with last bit set, end the box */
 
213
        if(fInBox)
 
214
        {
 
215
            ADDRECT(pReg, rects, FirstRect,
 
216
                    rx1, h, base + (width & PIM), h + 1);
 
217
        }
 
218
        /* if all rectangles on this line have the same x-coords as
 
219
         * those on the previous line, then add 1 to all the previous  y2s and 
 
220
         * throw away all the rectangles from this line 
 
221
         */
 
222
        fSame = FALSE;
 
223
        if(irectPrevStart != -1)
 
224
        {
 
225
            crects = irectLineStart - irectPrevStart;
 
226
            if(crects == ((rects - FirstRect) - irectLineStart))
 
227
            {
 
228
                prectO = FirstRect + irectPrevStart;
 
229
                prectN = prectLineStart = FirstRect + irectLineStart;
 
230
                fSame = TRUE;
 
231
                while(prectO < prectLineStart)
 
232
                {
 
233
                    if((prectO->x1 != prectN->x1) || (prectO->x2 != prectN->x2))
 
234
                    {
 
235
                          fSame = FALSE;
 
236
                          break;
 
237
                    }
 
238
                    prectO++;
 
239
                    prectN++;
 
240
                }
 
241
                if (fSame)
 
242
                {
 
243
                    prectO = FirstRect + irectPrevStart;
 
244
                    while(prectO < prectLineStart)
 
245
                    {
 
246
                        prectO->y2 += 1;
 
247
                        prectO++;
 
248
                    }
 
249
                    rects -= crects;
 
250
                    pReg->data->numRects -= crects;
 
251
                }
 
252
            }
 
253
        }
 
254
        if(!fSame)
 
255
            irectPrevStart = irectLineStart;
 
256
    }
 
257
    if (!pReg->data->numRects)
 
258
        pReg->extents.x1 = pReg->extents.x2 = 0;
 
259
    else
 
260
    {
 
261
        pReg->extents.y1 = REGION_BOXPTR(pReg)->y1;
 
262
        pReg->extents.y2 = REGION_END(pReg)->y2;
 
263
        if (pReg->data->numRects == 1)
 
264
        {
 
265
            xfree(pReg->data);
 
266
            pReg->data = (RegDataPtr)NULL;
 
267
        }
 
268
    }
 
269
#ifdef DEBUG
 
270
    if (!miValidRegion(pReg))
 
271
        FatalError("Assertion failed file %s, line %d: expr\n", __FILE__, __LINE__);
 
272
#endif
 
273
    return(pReg);
 
274
}
 
275
 
 
276
mfbPixmapToRegionProc *
 
277
mfbPixmapToRegionWeak(void)
 
278
{
 
279
    return mfbPixmapToRegion;
 
280
}