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

« back to all changes in this revision

Viewing changes to cfb/cfbzerarc.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/cfb/cfbzerarc.c,v 3.4tsi Exp $ */
 
2
/************************************************************
 
3
 
 
4
Copyright 1989, 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
 
 
28
/* $Xorg: cfbzerarc.c,v 1.4 2001/02/09 02:04:39 xorgcvs Exp $ */
 
29
 
 
30
/* Derived from:
 
31
 * "Algorithm for drawing ellipses or hyperbolae with a digital plotter"
 
32
 * by M. L. V. Pitteway
 
33
 * The Computer Journal, November 1967, Volume 10, Number 3, pp. 282-289
 
34
 */
 
35
 
 
36
#ifdef HAVE_DIX_CONFIG_H
 
37
#include <dix-config.h>
 
38
#endif
 
39
 
 
40
#include <X11/X.h>
 
41
#include <X11/Xprotostr.h>
 
42
#include "regionstr.h"
 
43
#include "gcstruct.h"
 
44
#include "pixmapstr.h"
 
45
#include "scrnintstr.h"
 
46
#include "cfb.h"
 
47
#include "cfbmskbits.h"
 
48
#include "mizerarc.h"
 
49
#include "cfbrrop.h"
 
50
#include "mi.h"
 
51
 
 
52
#ifdef PIXEL_ADDR
 
53
 
 
54
static void
 
55
RROP_NAME(cfbZeroArcSS8)(
 
56
    DrawablePtr pDraw,
 
57
    GCPtr pGC,
 
58
    xArc *arc)
 
59
{
 
60
    miZeroArcRec info;
 
61
    Bool do360;
 
62
    register int x;
 
63
    PixelType *addrp;
 
64
    register PixelType *yorgp, *yorgop;
 
65
#if PSZ == 24
 
66
    int xorg, xorg3, xorgo, xorgo3;
 
67
    register int xtmp;
 
68
#endif
 
69
    RROP_DECLARE
 
70
    register int yoffset;
 
71
    int npwidth, dyoffset;
 
72
    register int y, a, b, d, mask;
 
73
    register int k1, k3, dx, dy;
 
74
 
 
75
    cfbGetPixelWidthAndPointer(pDraw,npwidth, addrp)
 
76
 
 
77
    RROP_FETCH_GC (pGC);
 
78
    do360 = miZeroArcSetup(arc, &info, TRUE);
 
79
    yorgp = addrp + ((info.yorg + pDraw->y) * npwidth);
 
80
    yorgop = addrp + ((info.yorgo + pDraw->y) * npwidth);
 
81
    info.xorg += pDraw->x;
 
82
    info.xorgo += pDraw->x;
 
83
#if PSZ == 24
 
84
    xorg = info.xorg;
 
85
    xorg3 = xorg * 3;
 
86
    info.xorg = (info.xorg * 3) >> 2;
 
87
    xorgo = info.xorgo;
 
88
    xorgo3 = xorgo * 3; 
 
89
    info.xorgo = (info.xorgo * 3) >> 2;
 
90
#endif
 
91
    MIARCSETUP();
 
92
    yoffset = y ? npwidth : 0;
 
93
    dyoffset = 0;
 
94
    mask = info.initialMask;
 
95
    if (!(arc->width & 1))
 
96
    {
 
97
#if PSZ == 24
 
98
        if (mask & 2)
 
99
            RROP_SOLID24((yorgp + info.xorgo), xorgo);
 
100
        if (mask & 8)
 
101
            RROP_SOLID24((yorgop + info.xorgo), xorgo);
 
102
#else
 
103
        if (mask & 2)
 
104
            RROP_SOLID((yorgp + info.xorgo));
 
105
        if (mask & 8)
 
106
            RROP_SOLID((yorgop + info.xorgo));
 
107
#endif /* PSZ == 24 */
 
108
    }
 
109
    if (!info.end.x || !info.end.y)
 
110
    {
 
111
        mask = info.end.mask;
 
112
        info.end = info.altend;
 
113
    }
 
114
    if (do360 && (arc->width == arc->height) && !(arc->width & 1))
 
115
    {
 
116
        register int xoffset = npwidth;
 
117
#if PSZ == 24
 
118
        PixelType *yorghb = yorgp + (info.h * npwidth);
 
119
        register int tmp1, tmp2, tmp1_3, tmp2_3;
 
120
 
 
121
        tmp1 = xorg + info.h;
 
122
        tmp1_3 = tmp1 * 3;
 
123
        tmp2 = xorg - info.h;
 
124
        tmp2_3 = tmp2 * 3;
 
125
        while (1)
 
126
        {
 
127
            xtmp = (xorg3 + x * 3) >> 2;
 
128
            RROP_SOLID24(yorgp + yoffset + xtmp, xorg + x);
 
129
            RROP_SOLID24(yorgop - yoffset + xtmp, xorg + x);
 
130
            xtmp = (xorg3 - x * 3) >> 2;
 
131
            RROP_SOLID24(yorgp + yoffset + xtmp, xorg - x);
 
132
            RROP_SOLID24(yorgop - yoffset + xtmp, xorg - x);
 
133
            if (a < 0)
 
134
                break;
 
135
            xtmp = (tmp1_3 - y * 3) >> 2;
 
136
            RROP_SOLID24(yorghb - xoffset + xtmp, tmp1 - y);
 
137
            RROP_SOLID24(yorghb + xoffset + xtmp, tmp1 - y);
 
138
            xtmp = (tmp2_3 + y * 3) >> 2;
 
139
            RROP_SOLID24(yorghb - xoffset + xtmp, tmp2 + y);
 
140
            RROP_SOLID24(yorghb + xoffset + xtmp, tmp2 + y);
 
141
            xoffset += npwidth;
 
142
            MIARCCIRCLESTEP(yoffset += npwidth;);
 
143
        }
 
144
#else
 
145
        PixelType *yorghb = yorgp + (info.h * npwidth) + info.xorg;
 
146
        PixelType *yorgohb = yorghb - info.h;
 
147
 
 
148
        yorgp += info.xorg;
 
149
        yorgop += info.xorg;
 
150
        yorghb += info.h;
 
151
        while (1)
 
152
        {
 
153
            RROP_SOLID(yorgp + yoffset + x);
 
154
            RROP_SOLID(yorgp + yoffset - x);
 
155
            RROP_SOLID(yorgop - yoffset - x);
 
156
            RROP_SOLID(yorgop - yoffset + x);
 
157
            if (a < 0)
 
158
                break;
 
159
            RROP_SOLID(yorghb - xoffset - y);
 
160
            RROP_SOLID(yorgohb - xoffset + y);
 
161
            RROP_SOLID(yorgohb + xoffset + y);
 
162
            RROP_SOLID(yorghb + xoffset - y);
 
163
            xoffset += npwidth;
 
164
            MIARCCIRCLESTEP(yoffset += npwidth;);
 
165
        }
 
166
        yorgp -= info.xorg;
 
167
        yorgop -= info.xorg;
 
168
#endif /* PSZ == 24 */
 
169
        x = info.w;
 
170
        yoffset = info.h * npwidth;
 
171
    }
 
172
    else if (do360)
 
173
    {
 
174
        while (y < info.h || x < info.w)
 
175
        {
 
176
            MIARCOCTANTSHIFT(dyoffset = npwidth;);
 
177
#if PSZ == 24
 
178
            xtmp = (xorg3 + x * 3) >> 2;
 
179
            RROP_SOLID24(yorgp + yoffset + xtmp, xorg + x);
 
180
            RROP_SOLID24(yorgop - yoffset + xtmp, xorg + x);
 
181
            xtmp = (xorgo3 - x * 3) >> 2;
 
182
            RROP_SOLID24(yorgp + yoffset + xtmp, xorgo - x);
 
183
            RROP_SOLID24(yorgop - yoffset + xtmp, xorgo - x);
 
184
#else
 
185
            RROP_SOLID(yorgp + yoffset + info.xorg + x);
 
186
            RROP_SOLID(yorgp + yoffset + info.xorgo - x);
 
187
            RROP_SOLID(yorgop - yoffset + info.xorgo - x);
 
188
            RROP_SOLID(yorgop - yoffset + info.xorg + x);
 
189
#endif
 
190
            MIARCSTEP(yoffset += dyoffset;, yoffset += npwidth;);
 
191
        }
 
192
    }
 
193
    else
 
194
    {
 
195
        while (y < info.h || x < info.w)
 
196
        {
 
197
            MIARCOCTANTSHIFT(dyoffset = npwidth;);
 
198
            if ((x == info.start.x) || (y == info.start.y))
 
199
            {
 
200
                mask = info.start.mask;
 
201
                info.start = info.altstart;
 
202
            }
 
203
#if PSZ == 24
 
204
            if (mask & 1){
 
205
              xtmp = (xorg3 + x * 3) >> 2;
 
206
              RROP_SOLID24(yorgp + yoffset + xtmp, xorg + x);
 
207
            }
 
208
            if (mask & 2){
 
209
              xtmp = (xorgo3 - x * 3) >> 2;
 
210
              RROP_SOLID24(yorgp + yoffset + xtmp, xorgo - x);
 
211
            }
 
212
            if (mask & 4){
 
213
              xtmp = (xorgo3 - x * 3) >> 2;
 
214
              RROP_SOLID24(yorgop - yoffset + xtmp, xorgo - x);
 
215
            }
 
216
            if (mask & 8){
 
217
              xtmp = (xorg3 + x * 3) >> 2;
 
218
              RROP_SOLID24(yorgop - yoffset + xtmp, xorg + x);
 
219
            }
 
220
#else
 
221
            if (mask & 1)
 
222
                RROP_SOLID(yorgp + yoffset + info.xorg + x);
 
223
            if (mask & 2)
 
224
                RROP_SOLID(yorgp + yoffset + info.xorgo - x);
 
225
            if (mask & 4)
 
226
                RROP_SOLID(yorgop - yoffset + info.xorgo - x);
 
227
            if (mask & 8)
 
228
                RROP_SOLID(yorgop - yoffset + info.xorg + x);
 
229
#endif /* PSZ == 24 */
 
230
            if ((x == info.end.x) || (y == info.end.y))
 
231
            {
 
232
                mask = info.end.mask;
 
233
                info.end = info.altend;
 
234
            }
 
235
            MIARCSTEP(yoffset += dyoffset;, yoffset += npwidth;);
 
236
        }
 
237
    }
 
238
    if ((x == info.start.x) || (y == info.start.y))
 
239
        mask = info.start.mask;
 
240
#if PSZ == 24
 
241
    if (mask & 1){
 
242
      xtmp = (xorg3 + x * 3) >> 2;
 
243
      RROP_SOLID24(yorgp + yoffset + xtmp, xorg + x);
 
244
    }
 
245
    if (mask & 4){
 
246
      xtmp = (xorgo3 - x * 3) >> 2;
 
247
      RROP_SOLID24(yorgop - yoffset + xtmp, xorgo - x);
 
248
    }
 
249
#else
 
250
    if (mask & 1)
 
251
        RROP_SOLID(yorgp + yoffset + info.xorg + x);
 
252
    if (mask & 4)
 
253
        RROP_SOLID(yorgop - yoffset + info.xorgo - x);
 
254
#endif /* PSZ == 24 */
 
255
    if (arc->height & 1)
 
256
    {
 
257
#if PSZ == 24
 
258
        if (mask & 2){
 
259
          xtmp = (xorgo3 - x * 3) >> 2;
 
260
          RROP_SOLID24(yorgp + yoffset + xtmp, xorgo - x);
 
261
        }
 
262
        if (mask & 8){
 
263
          xtmp = (xorg3 + x * 3) >> 2;
 
264
          RROP_SOLID24(yorgop - yoffset + xtmp, xorg + x);
 
265
        }
 
266
#else
 
267
        if (mask & 2)
 
268
            RROP_SOLID(yorgp + yoffset + info.xorgo - x);
 
269
        if (mask & 8)
 
270
            RROP_SOLID(yorgop - yoffset + info.xorg + x);
 
271
#endif /* PSZ == 24 */
 
272
    }
 
273
    RROP_UNDECLARE
 
274
}
 
275
 
 
276
void
 
277
RROP_NAME (cfbZeroPolyArcSS8) (pDraw, pGC, narcs, parcs)
 
278
    register DrawablePtr        pDraw;
 
279
    GCPtr       pGC;
 
280
    int         narcs;
 
281
    xArc        *parcs;
 
282
{
 
283
    register xArc *arc;
 
284
    register int i;
 
285
    BoxRec box;
 
286
    int x2, y2;
 
287
    RegionPtr cclip;
 
288
 
 
289
    cclip = cfbGetCompositeClip(pGC);
 
290
    for (arc = parcs, i = narcs; --i >= 0; arc++)
 
291
    {
 
292
        if (miCanZeroArc(arc))
 
293
        {
 
294
            box.x1 = arc->x + pDraw->x;
 
295
            box.y1 = arc->y + pDraw->y;
 
296
            /*
 
297
             * Because box.x2 and box.y2 get truncated to 16 bits, and the
 
298
             * RECT_IN_REGION test treats the resulting number as a signed
 
299
             * integer, the RECT_IN_REGION test alone can go the wrong way.
 
300
             * This can result in a server crash because the rendering
 
301
             * routines in this file deal directly with cpu addresses
 
302
             * of pixels to be stored, and do not clip or otherwise check
 
303
             * that all such addresses are within their respective pixmaps.
 
304
             * So we only allow the RECT_IN_REGION test to be used for
 
305
             * values that can be expressed correctly in a signed short.
 
306
             */
 
307
            x2 = box.x1 + (int)arc->width + 1;
 
308
            box.x2 = x2;
 
309
            y2 = box.y1 + (int)arc->height + 1;
 
310
            box.y2 = y2;
 
311
            if ( (x2 <= MAXSHORT) && (y2 <= MAXSHORT) &&
 
312
                    (RECT_IN_REGION(pDraw->pScreen, cclip, &box) == rgnIN) )
 
313
                RROP_NAME (cfbZeroArcSS8) (pDraw, pGC, arc);
 
314
            else
 
315
                miZeroPolyArc(pDraw, pGC, 1, arc);
 
316
        }
 
317
        else
 
318
            miPolyArc(pDraw, pGC, 1, arc);
 
319
    }
 
320
}
 
321
 
 
322
#endif