~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/render/mitri.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $XFree86: xc/programs/Xserver/render/mitri.c,v 1.6 2002/08/12 04:03:21 keithp Exp $
 
3
 *
 
4
 * Copyright � 2002 Keith Packard, member of The XFree86 Project, Inc.
 
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, and that the name of Keith Packard not be used in
 
11
 * advertising or publicity pertaining to distribution of the software without
 
12
 * specific, written prior permission.  Keith Packard makes no
 
13
 * representations about the suitability of this software for any purpose.  It
 
14
 * is provided "as is" without express or implied warranty.
 
15
 *
 
16
 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
17
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 
18
 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
19
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 
20
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 
21
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 
22
 * PERFORMANCE OF THIS SOFTWARE.
 
23
 */
 
24
 
 
25
#include "scrnintstr.h"
 
26
#include "gcstruct.h"
 
27
#include "pixmapstr.h"
 
28
#include "windowstr.h"
 
29
#include "mi.h"
 
30
#include "picturestr.h"
 
31
#include "mipict.h"
 
32
 
 
33
void
 
34
miPointFixedBounds (int npoint, xPointFixed *points, BoxPtr bounds)
 
35
{
 
36
    bounds->x1 = xFixedToInt (points->x);
 
37
    bounds->x2 = xFixedToInt (xFixedCeil (points->x));
 
38
    bounds->y1 = xFixedToInt (points->y);
 
39
    bounds->y2 = xFixedToInt (xFixedCeil (points->y));
 
40
    points++;
 
41
    npoint--;
 
42
    while (npoint-- > 0)
 
43
    {
 
44
        INT16   x1 = xFixedToInt (points->x);
 
45
        INT16   x2 = xFixedToInt (xFixedCeil (points->x));
 
46
        INT16   y1 = xFixedToInt (points->y);
 
47
        INT16   y2 = xFixedToInt (xFixedCeil (points->y));
 
48
 
 
49
        if (x1 < bounds->x1)
 
50
            bounds->x1 = x1;
 
51
        else if (x2 > bounds->x2)
 
52
            bounds->x2 = x2;
 
53
        if (y1 < bounds->y1)
 
54
            bounds->y1 = y1;
 
55
        else if (y2 > bounds->y2)
 
56
            bounds->y2 = y2;
 
57
        points++;
 
58
    }
 
59
}
 
60
 
 
61
void
 
62
miTriangleBounds (int ntri, xTriangle *tris, BoxPtr bounds)
 
63
{
 
64
    miPointFixedBounds (ntri * 3, (xPointFixed *) tris, bounds);
 
65
}
 
66
 
 
67
void
 
68
miRasterizeTriangle (PicturePtr pPicture,
 
69
                     xTriangle  *tri,
 
70
                     int        x_off,
 
71
                     int        y_off)
 
72
{
 
73
    ScreenPtr           pScreen = pPicture->pDrawable->pScreen;
 
74
    PictureScreenPtr    ps = GetPictureScreen(pScreen);
 
75
    xPointFixed         *top, *left, *right, *t;
 
76
    xTrapezoid          trap[2];
 
77
 
 
78
    top = &tri->p1;
 
79
    left = &tri->p2;
 
80
    right = &tri->p3;
 
81
    if (left->y < top->y) {
 
82
        t = left; left = top; top = t;
 
83
    }
 
84
    if (right->y < top->y) {
 
85
        t = right; right = top; top = t;
 
86
    }
 
87
    if (right->x < left->x) {
 
88
        t = right; right = left; left = t;
 
89
    }
 
90
    
 
91
    /*
 
92
     * Two cases:
 
93
     *
 
94
     *          +               +
 
95
     *         / \             / \
 
96
     *        /   \           /   \
 
97
     *       /     +         +     \
 
98
     *      /    --           --    \
 
99
     *     /   --               --   \
 
100
     *    / ---                   --- \
 
101
     *   +--                         --+
 
102
     */
 
103
    
 
104
    trap[0].top = top->y;
 
105
    
 
106
    trap[0].left.p1.x = top->x;
 
107
    trap[0].left.p1.y = trap[0].top;
 
108
    trap[0].left.p2.x = left->x;
 
109
    trap[0].left.p2.y = left->y;
 
110
    
 
111
    trap[0].right.p1 = trap[0].left.p1;
 
112
    trap[0].right.p2.x = right->x;
 
113
    trap[0].right.p2.y = right->y;
 
114
    
 
115
    if (right->y < left->y)
 
116
    {
 
117
        trap[0].bottom = trap[0].right.p2.y;
 
118
 
 
119
        trap[1].top = trap[0].bottom;
 
120
        trap[1].bottom = trap[0].left.p2.y;
 
121
        
 
122
        trap[1].left = trap[0].left;
 
123
        trap[1].right.p1 = trap[0].right.p2;
 
124
        trap[1].right.p2 = trap[0].left.p2;
 
125
    }
 
126
    else
 
127
    {
 
128
        trap[0].bottom = trap[0].left.p2.y;
 
129
        
 
130
        trap[1].top = trap[0].bottom;
 
131
        trap[1].bottom = trap[0].right.p2.y;
 
132
        
 
133
        trap[1].right = trap[0].right;
 
134
        trap[1].left.p1 = trap[0].left.p2;
 
135
        trap[1].left.p2 = trap[0].right.p2;
 
136
    }
 
137
    if (trap[0].top != trap[0].bottom)
 
138
        (*ps->RasterizeTrapezoid) (pPicture, &trap[0], x_off, y_off);
 
139
    if (trap[1].top != trap[1].bottom)
 
140
        (*ps->RasterizeTrapezoid) (pPicture, &trap[1], x_off, y_off);
 
141
}
 
142
 
 
143
void
 
144
miTriangles (CARD8          op,
 
145
             PicturePtr     pSrc,
 
146
             PicturePtr     pDst,
 
147
             PictFormatPtr  maskFormat,
 
148
             INT16          xSrc,
 
149
             INT16          ySrc,
 
150
             int            ntri,
 
151
             xTriangle      *tris)
 
152
{
 
153
    ScreenPtr           pScreen = pDst->pDrawable->pScreen;
 
154
    BoxRec              bounds;
 
155
    PicturePtr          pPicture = 0;
 
156
    INT16               xDst, yDst;
 
157
    INT16               xRel, yRel;
 
158
    
 
159
    xDst = tris[0].p1.x >> 16;
 
160
    yDst = tris[0].p1.y >> 16;
 
161
    
 
162
    if (maskFormat)
 
163
    {
 
164
        miTriangleBounds (ntri, tris, &bounds);
 
165
        if (bounds.x2 <= bounds.x1 || bounds.y2 <= bounds.y1)
 
166
            return;
 
167
        pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat,
 
168
                                         bounds.x2 - bounds.x1,
 
169
                                         bounds.y2 - bounds.y1);
 
170
        if (!pPicture)
 
171
            return;
 
172
    }
 
173
    for (; ntri; ntri--, tris++)
 
174
    {
 
175
        if (!maskFormat)
 
176
        {
 
177
            miTriangleBounds (1, tris, &bounds);
 
178
            if (bounds.x2 <= bounds.x1 || bounds.y2 <= bounds.y1)
 
179
                continue;
 
180
            pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat,
 
181
                                             bounds.x2 - bounds.x1,
 
182
                                             bounds.y2 - bounds.y1);
 
183
            if (!pPicture)
 
184
                break;
 
185
        }
 
186
        miRasterizeTriangle (pPicture, tris, -bounds.x1, -bounds.y1);
 
187
        if (!maskFormat)
 
188
        {
 
189
            xRel = bounds.x1 + xSrc - xDst;
 
190
            yRel = bounds.y1 + ySrc - yDst;
 
191
            CompositePicture (op, pSrc, pPicture, pDst,
 
192
                              xRel, yRel, 0, 0, bounds.x1, bounds.y1,
 
193
                              bounds.x2 - bounds.x1, bounds.y2 - bounds.y1);
 
194
            FreePicture (pPicture, 0);
 
195
        }
 
196
        /* XXX adjust xSrc and ySrc */
 
197
    }
 
198
    if (maskFormat)
 
199
    {
 
200
        xRel = bounds.x1 + xSrc - xDst;
 
201
        yRel = bounds.y1 + ySrc - yDst;
 
202
        CompositePicture (op, pSrc, pPicture, pDst,
 
203
                          xRel, yRel, 0, 0, bounds.x1, bounds.y1,
 
204
                          bounds.x2 - bounds.x1, bounds.y2 - bounds.y1);
 
205
        FreePicture (pPicture, 0);
 
206
    }
 
207
}
 
208
 
 
209
void
 
210
miTriStrip (CARD8           op,
 
211
            PicturePtr      pSrc,
 
212
            PicturePtr      pDst,
 
213
            PictFormatPtr   maskFormat,
 
214
            INT16           xSrc,
 
215
            INT16           ySrc,
 
216
            int             npoint,
 
217
            xPointFixed     *points)
 
218
{
 
219
    ScreenPtr           pScreen = pDst->pDrawable->pScreen;
 
220
    xTriangle           tri;
 
221
    BoxRec              bounds;
 
222
    PicturePtr          pPicture = 0;
 
223
    INT16               xDst, yDst;
 
224
    INT16               xRel, yRel;
 
225
    
 
226
    xDst = points[0].x >> 16;
 
227
    yDst = points[0].y >> 16;
 
228
    
 
229
    if (npoint < 3)
 
230
        return;
 
231
    if (maskFormat)
 
232
    {
 
233
        miPointFixedBounds (npoint, points, &bounds);
 
234
        if (bounds.x2 <= bounds.x1 || bounds.y2 <= bounds.y1)
 
235
            return;
 
236
        pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat,
 
237
                                         bounds.x2 - bounds.x1,
 
238
                                         bounds.y2 - bounds.y1);
 
239
        if (!pPicture)
 
240
            return;
 
241
    }
 
242
    for (; npoint >= 3; npoint--, points++)
 
243
    {
 
244
        tri.p1 = points[0];
 
245
        tri.p2 = points[1];
 
246
        tri.p3 = points[2];
 
247
        if (!maskFormat)
 
248
        {
 
249
            miTriangleBounds (1, &tri, &bounds);
 
250
            if (bounds.x2 <= bounds.x1 || bounds.y2 <= bounds.y1)
 
251
                continue;
 
252
            pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat, 
 
253
                                             bounds.x2 - bounds.x1,
 
254
                                             bounds.y2 - bounds.y1);
 
255
            if (!pPicture)
 
256
                continue;
 
257
        }
 
258
        miRasterizeTriangle (pPicture, &tri, -bounds.x1, -bounds.y1);
 
259
        if (!maskFormat)
 
260
        {
 
261
            xRel = bounds.x1 + xSrc - xDst;
 
262
            yRel = bounds.y1 + ySrc - yDst;
 
263
            CompositePicture (op, pSrc, pPicture, pDst,
 
264
                              xRel, yRel, 0, 0, bounds.x1, bounds.y1,
 
265
                              bounds.x2 - bounds.x1, bounds.y2 - bounds.y1);
 
266
            FreePicture (pPicture, 0);
 
267
        }
 
268
    }
 
269
    if (maskFormat)
 
270
    {
 
271
        xRel = bounds.x1 + xSrc - xDst;
 
272
        yRel = bounds.y1 + ySrc - yDst;
 
273
        CompositePicture (op, pSrc, pPicture, pDst,
 
274
                          xRel, yRel, 0, 0, bounds.x1, bounds.y1,
 
275
                          bounds.x2 - bounds.x1, bounds.y2 - bounds.y1);
 
276
        FreePicture (pPicture, 0);
 
277
    }
 
278
}
 
279
 
 
280
void
 
281
miTriFan (CARD8         op,
 
282
          PicturePtr    pSrc,
 
283
          PicturePtr    pDst,
 
284
          PictFormatPtr maskFormat,
 
285
          INT16         xSrc,
 
286
          INT16         ySrc,
 
287
          int           npoint,
 
288
          xPointFixed   *points)
 
289
{
 
290
    ScreenPtr           pScreen = pDst->pDrawable->pScreen;
 
291
    xTriangle           tri;
 
292
    BoxRec              bounds;
 
293
    PicturePtr          pPicture = 0;
 
294
    xPointFixed         *first;
 
295
    INT16               xDst, yDst;
 
296
    INT16               xRel, yRel;
 
297
    
 
298
    xDst = points[0].x >> 16;
 
299
    yDst = points[0].y >> 16;
 
300
    
 
301
    if (npoint < 3)
 
302
        return;
 
303
    if (maskFormat)
 
304
    {
 
305
        miPointFixedBounds (npoint, points, &bounds);
 
306
        if (bounds.x2 <= bounds.x1 || bounds.y2 <= bounds.y1)
 
307
            return;
 
308
        pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat,
 
309
                                         bounds.x2 - bounds.x1,
 
310
                                         bounds.y2 - bounds.y1);
 
311
        if (!pPicture)
 
312
            return;
 
313
    }
 
314
    first = points++;
 
315
    npoint--;
 
316
    for (; npoint >= 2; npoint--, points++)
 
317
    {
 
318
        tri.p1 = *first;
 
319
        tri.p2 = points[0];
 
320
        tri.p3 = points[1];
 
321
        if (!maskFormat)
 
322
        {
 
323
            miTriangleBounds (1, &tri, &bounds);
 
324
            if (bounds.x2 <= bounds.x1 || bounds.y2 <= bounds.y1)
 
325
                continue;
 
326
            pPicture = miCreateAlphaPicture (pScreen, pDst, maskFormat, 
 
327
                                             bounds.x2 - bounds.x1,
 
328
                                             bounds.y2 - bounds.y1);
 
329
            if (!pPicture)
 
330
                continue;
 
331
        }
 
332
        miRasterizeTriangle (pPicture, &tri, -bounds.x1, -bounds.y1);
 
333
        if (!maskFormat)
 
334
        {
 
335
            xRel = bounds.x1 + xSrc - xDst;
 
336
            yRel = bounds.y1 + ySrc - yDst;
 
337
            CompositePicture (op, pSrc, pPicture, pDst,
 
338
                              xRel, yRel, 0, 0, bounds.x1, bounds.y1,
 
339
                              bounds.x2 - bounds.x1, bounds.y2 - bounds.y1);
 
340
            FreePicture (pPicture, 0);
 
341
        }
 
342
    }
 
343
    if (maskFormat)
 
344
    {
 
345
        xRel = bounds.x1 + xSrc - xDst;
 
346
        yRel = bounds.y1 + ySrc - yDst;
 
347
        CompositePicture (op, pSrc, pPicture, pDst,
 
348
                          xRel, yRel, 0, 0, bounds.x1, bounds.y1,
 
349
                          bounds.x2 - bounds.x1, bounds.y2 - bounds.y1);
 
350
        FreePicture (pPicture, 0);
 
351
    }
 
352
}