1/*
2 * Copyright © 1998 Keith Packard
3 * Copyright © 2012 Intel Corporation
4 *
5 * Permission to use, copy, modify, distribute, and sell this software and its
6 * documentation for any purpose is hereby granted without fee, provided that
7 * the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of Keith Packard not be used in
10 * advertising or publicity pertaining to distribution of the software without
11 * specific, written prior permission.  Keith Packard makes no
12 * representations about the suitability of this software for any purpose.  It
13 * is provided "as is" without express or implied warranty.
14 *
15 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21 * PERFORMANCE OF THIS SOFTWARE.
22 */
23
24#include "fb.h"
25#include <mi.h>
26#include <mizerarc.h>
27#include <limits.h>
28
29#define ARC	    fbArc8
30#define BITS	    BYTE
31#define BITS2	    CARD16
32#define BITS4	    CARD32
33#include "fbarcbits.h"
34#undef BITS
35#undef BITS2
36#undef BITS4
37#undef ARC
38
39#define ARC	    fbArc16
40#define BITS	    CARD16
41#define BITS2	    CARD32
42#include "fbarcbits.h"
43#undef BITS
44#undef BITS2
45#undef ARC
46
47#define ARC	    fbArc32
48#define BITS	    CARD32
49#include "fbarcbits.h"
50#undef BITS
51#undef ARC
52
53void
54fbPolyArc(DrawablePtr drawable, GCPtr gc, int n, xArc *arc)
55{
56	DBG(("%s x %d, width=%d, fill=%d, line=%d\n",
57	     __FUNCTION__, n, gc->lineWidth, gc->lineStyle, gc->fillStyle));
58
59	if (gc->lineWidth == 0) {
60		void (*raster)(FbBits *dst, FbStride dstStride, int dstBpp,
61			       xArc *arc, int dx, int dy,
62			       FbBits and, FbBits xor);
63
64		raster = 0;
65		if (gc->lineStyle == LineSolid && gc->fillStyle == FillSolid) {
66			switch (drawable->bitsPerPixel) {
67			case 8:
68				raster = fbArc8;
69				break;
70			case 16:
71				raster = fbArc16;
72				break;
73			case 32:
74				raster = fbArc32;
75				break;
76			}
77		}
78		if (raster) {
79			FbGCPrivPtr pgc = fb_gc(gc);
80			FbBits *dst;
81			FbStride dstStride;
82			int dstBpp;
83			int dstXoff, dstYoff;
84			BoxRec box;
85			int x2, y2;
86
87			fbGetDrawable(drawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
88			while (n--) {
89				if (miCanZeroArc(arc)) {
90					box.x1 = arc->x + drawable->x;
91					box.y1 = arc->y + drawable->y;
92					/*
93					 * Because box.x2 and box.y2 get truncated to 16 bits, and the
94					 * RECT_IN_REGION test treats the resulting number as a signed
95					 * integer, the RECT_IN_REGION test alone can go the wrong way.
96					 * This can result in a server crash because the rendering
97					 * routines in this file deal directly with cpu addresses
98					 * of pixels to be stored, and do not clip or otherwise check
99					 * that all such addresses are within their respective pixmaps.
100					 * So we only allow the RECT_IN_REGION test to be used for
101					 * values that can be expressed correctly in a signed short.
102					 */
103					x2 = box.x1 + (int) arc->width + 1;
104					box.x2 = x2;
105					y2 = box.y1 + (int) arc->height + 1;
106					box.y2 = y2;
107					if ((x2 <= SHRT_MAX) && (y2 <= SHRT_MAX) &&
108					    (RegionContainsRect(gc->pCompositeClip, &box) == rgnIN)) {
109						raster(dst, dstStride, dstBpp,
110						       arc, drawable->x + dstXoff,
111							drawable->y + dstYoff, pgc->and, pgc->xor);
112					} else
113						miZeroPolyArc(drawable, gc, 1, arc);
114				} else
115					miPolyArc(drawable, gc, 1, arc);
116				arc++;
117			}
118		} else
119			miZeroPolyArc(drawable, gc, n, arc);
120	} else
121		miPolyArc(drawable, gc, n, arc);
122}
123