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