xref: /OK3568_Linux_fs/external/xserver/fb/fbpoint.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * Copyright © 1998 Keith Packard
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation, and that the name of Keith Packard not be used in
9  * advertising or publicity pertaining to distribution of the software without
10  * specific, written prior permission.  Keith Packard makes no
11  * representations about the suitability of this software for any purpose.  It
12  * is provided "as is" without express or implied warranty.
13  *
14  * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16  * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20  * PERFORMANCE OF THIS SOFTWARE.
21  */
22 
23 #ifdef HAVE_DIX_CONFIG_H
24 #include <dix-config.h>
25 #endif
26 
27 #include "fb.h"
28 
29 typedef void (*FbDots) (FbBits * dst,
30                         FbStride dstStride,
31                         int dstBpp,
32                         BoxPtr pBox,
33                         xPoint * pts,
34                         int npt,
35                         int xorg,
36                         int yorg, int xoff, int yoff, FbBits and, FbBits xor);
37 
38 static void
fbDots(FbBits * dstOrig,FbStride dstStride,int dstBpp,BoxPtr pBox,xPoint * pts,int npt,int xorg,int yorg,int xoff,int yoff,FbBits andOrig,FbBits xorOrig)39 fbDots(FbBits * dstOrig,
40        FbStride dstStride,
41        int dstBpp,
42        BoxPtr pBox,
43        xPoint * pts,
44        int npt,
45        int xorg, int yorg, int xoff, int yoff, FbBits andOrig, FbBits xorOrig)
46 {
47     FbStip *dst = (FbStip *) dstOrig;
48     int x1, y1, x2, y2;
49     int x, y;
50     FbStip *d;
51     FbStip and = andOrig;
52     FbStip xor = xorOrig;
53 
54     dstStride = FbBitsStrideToStipStride(dstStride);
55     x1 = pBox->x1;
56     y1 = pBox->y1;
57     x2 = pBox->x2;
58     y2 = pBox->y2;
59     while (npt--) {
60         x = pts->x + xorg;
61         y = pts->y + yorg;
62         pts++;
63         if (x1 <= x && x < x2 && y1 <= y && y < y2) {
64             FbStip mask;
65             x = (x + xoff) * dstBpp;
66             d = dst + ((y + yoff) * dstStride) + (x >> FB_STIP_SHIFT);
67             x &= FB_STIP_MASK;
68 
69             mask = FbStipMask(x, dstBpp);
70             WRITE(d, FbDoMaskRRop(READ(d), and, xor, mask));
71         }
72     }
73 }
74 
75 void
fbPolyPoint(DrawablePtr pDrawable,GCPtr pGC,int mode,int nptInit,xPoint * pptInit)76 fbPolyPoint(DrawablePtr pDrawable,
77             GCPtr pGC, int mode, int nptInit, xPoint * pptInit)
78 {
79     FbGCPrivPtr pPriv = fbGetGCPrivate(pGC);
80     RegionPtr pClip = fbGetCompositeClip(pGC);
81     FbBits *dst;
82     FbStride dstStride;
83     int dstBpp;
84     int dstXoff, dstYoff;
85     FbDots dots;
86     FbBits and, xor;
87     xPoint *ppt;
88     int npt;
89     BoxPtr pBox;
90     int nBox;
91 
92     /* make pointlist origin relative */
93     ppt = pptInit;
94     npt = nptInit;
95     if (mode == CoordModePrevious) {
96         npt--;
97         while (npt--) {
98             ppt++;
99             ppt->x += (ppt - 1)->x;
100             ppt->y += (ppt - 1)->y;
101         }
102     }
103     fbGetDrawable(pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
104     and = pPriv->and;
105     xor = pPriv->xor;
106     dots = fbDots;
107     switch (dstBpp) {
108     case 8:
109         dots = fbDots8;
110         break;
111     case 16:
112         dots = fbDots16;
113         break;
114     case 32:
115         dots = fbDots32;
116         break;
117     }
118     for (nBox = RegionNumRects(pClip), pBox = RegionRects(pClip);
119          nBox--; pBox++)
120         (*dots) (dst, dstStride, dstBpp, pBox, pptInit, nptInit,
121                  pDrawable->x, pDrawable->y, dstXoff, dstYoff, and, xor);
122     fbFinishAccess(pDrawable);
123 }
124