1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright © 2004 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
29*4882a593Smuzhiyun #include "picturestr.h"
30*4882a593Smuzhiyun #include "mipict.h"
31*4882a593Smuzhiyun #include "fbpict.h"
32*4882a593Smuzhiyun #include "damage.h"
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun void
fbAddTraps(PicturePtr pPicture,INT16 x_off,INT16 y_off,int ntrap,xTrap * traps)35*4882a593Smuzhiyun fbAddTraps(PicturePtr pPicture,
36*4882a593Smuzhiyun INT16 x_off, INT16 y_off, int ntrap, xTrap * traps)
37*4882a593Smuzhiyun {
38*4882a593Smuzhiyun pixman_image_t *image;
39*4882a593Smuzhiyun int dst_xoff, dst_yoff;
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun if (!(image = image_from_pict(pPicture, FALSE, &dst_xoff, &dst_yoff)))
42*4882a593Smuzhiyun return;
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun pixman_add_traps(image, x_off + dst_xoff, y_off + dst_yoff,
45*4882a593Smuzhiyun ntrap, (pixman_trap_t *) traps);
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun free_pixman_pict(pPicture, image);
48*4882a593Smuzhiyun }
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun void
fbRasterizeTrapezoid(PicturePtr pPicture,xTrapezoid * trap,int x_off,int y_off)51*4882a593Smuzhiyun fbRasterizeTrapezoid(PicturePtr pPicture,
52*4882a593Smuzhiyun xTrapezoid * trap, int x_off, int y_off)
53*4882a593Smuzhiyun {
54*4882a593Smuzhiyun pixman_image_t *image;
55*4882a593Smuzhiyun int dst_xoff, dst_yoff;
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun if (!(image = image_from_pict(pPicture, FALSE, &dst_xoff, &dst_yoff)))
58*4882a593Smuzhiyun return;
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun pixman_rasterize_trapezoid(image, (pixman_trapezoid_t *) trap,
61*4882a593Smuzhiyun x_off + dst_xoff, y_off + dst_yoff);
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun free_pixman_pict(pPicture, image);
64*4882a593Smuzhiyun }
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun void
fbAddTriangles(PicturePtr pPicture,INT16 x_off,INT16 y_off,int ntri,xTriangle * tris)67*4882a593Smuzhiyun fbAddTriangles(PicturePtr pPicture,
68*4882a593Smuzhiyun INT16 x_off, INT16 y_off, int ntri, xTriangle * tris)
69*4882a593Smuzhiyun {
70*4882a593Smuzhiyun pixman_image_t *image;
71*4882a593Smuzhiyun int dst_xoff, dst_yoff;
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun if (!(image = image_from_pict(pPicture, FALSE, &dst_xoff, &dst_yoff)))
74*4882a593Smuzhiyun return;
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun pixman_add_triangles(image,
77*4882a593Smuzhiyun dst_xoff + x_off, dst_yoff + y_off,
78*4882a593Smuzhiyun ntri, (pixman_triangle_t *) tris);
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun free_pixman_pict(pPicture, image);
81*4882a593Smuzhiyun }
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun typedef void (*CompositeShapesFunc) (pixman_op_t op,
84*4882a593Smuzhiyun pixman_image_t * src,
85*4882a593Smuzhiyun pixman_image_t * dst,
86*4882a593Smuzhiyun pixman_format_code_t mask_format,
87*4882a593Smuzhiyun int x_src, int y_src,
88*4882a593Smuzhiyun int x_dst, int y_dst,
89*4882a593Smuzhiyun int n_shapes, const uint8_t * shapes);
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun static void
fbShapes(CompositeShapesFunc composite,pixman_op_t op,PicturePtr pSrc,PicturePtr pDst,PictFormatPtr maskFormat,int16_t xSrc,int16_t ySrc,int nshapes,int shape_size,const uint8_t * shapes)92*4882a593Smuzhiyun fbShapes(CompositeShapesFunc composite,
93*4882a593Smuzhiyun pixman_op_t op,
94*4882a593Smuzhiyun PicturePtr pSrc,
95*4882a593Smuzhiyun PicturePtr pDst,
96*4882a593Smuzhiyun PictFormatPtr maskFormat,
97*4882a593Smuzhiyun int16_t xSrc,
98*4882a593Smuzhiyun int16_t ySrc, int nshapes, int shape_size, const uint8_t * shapes)
99*4882a593Smuzhiyun {
100*4882a593Smuzhiyun pixman_image_t *src, *dst;
101*4882a593Smuzhiyun int src_xoff, src_yoff;
102*4882a593Smuzhiyun int dst_xoff, dst_yoff;
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun miCompositeSourceValidate(pSrc);
105*4882a593Smuzhiyun
106*4882a593Smuzhiyun src = image_from_pict(pSrc, FALSE, &src_xoff, &src_yoff);
107*4882a593Smuzhiyun dst = image_from_pict(pDst, TRUE, &dst_xoff, &dst_yoff);
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun if (src && dst) {
110*4882a593Smuzhiyun pixman_format_code_t format;
111*4882a593Smuzhiyun
112*4882a593Smuzhiyun DamageRegionAppend(pDst->pDrawable, pDst->pCompositeClip);
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun if (!maskFormat) {
115*4882a593Smuzhiyun int i;
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun if (pDst->polyEdge == PolyEdgeSharp)
118*4882a593Smuzhiyun format = PIXMAN_a1;
119*4882a593Smuzhiyun else
120*4882a593Smuzhiyun format = PIXMAN_a8;
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun for (i = 0; i < nshapes; ++i) {
123*4882a593Smuzhiyun composite(op, src, dst, format,
124*4882a593Smuzhiyun xSrc + src_xoff,
125*4882a593Smuzhiyun ySrc + src_yoff,
126*4882a593Smuzhiyun dst_xoff, dst_yoff, 1, shapes + i * shape_size);
127*4882a593Smuzhiyun }
128*4882a593Smuzhiyun }
129*4882a593Smuzhiyun else {
130*4882a593Smuzhiyun switch (PICT_FORMAT_A(maskFormat->format)) {
131*4882a593Smuzhiyun case 1:
132*4882a593Smuzhiyun format = PIXMAN_a1;
133*4882a593Smuzhiyun break;
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun case 4:
136*4882a593Smuzhiyun format = PIXMAN_a4;
137*4882a593Smuzhiyun break;
138*4882a593Smuzhiyun
139*4882a593Smuzhiyun default:
140*4882a593Smuzhiyun case 8:
141*4882a593Smuzhiyun format = PIXMAN_a8;
142*4882a593Smuzhiyun break;
143*4882a593Smuzhiyun }
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun composite(op, src, dst, format,
146*4882a593Smuzhiyun xSrc + src_xoff,
147*4882a593Smuzhiyun ySrc + src_yoff, dst_xoff, dst_yoff, nshapes, shapes);
148*4882a593Smuzhiyun }
149*4882a593Smuzhiyun
150*4882a593Smuzhiyun DamageRegionProcessPending(pDst->pDrawable);
151*4882a593Smuzhiyun }
152*4882a593Smuzhiyun
153*4882a593Smuzhiyun free_pixman_pict(pSrc, src);
154*4882a593Smuzhiyun free_pixman_pict(pDst, dst);
155*4882a593Smuzhiyun }
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun void
fbTrapezoids(CARD8 op,PicturePtr pSrc,PicturePtr pDst,PictFormatPtr maskFormat,INT16 xSrc,INT16 ySrc,int ntrap,xTrapezoid * traps)158*4882a593Smuzhiyun fbTrapezoids(CARD8 op,
159*4882a593Smuzhiyun PicturePtr pSrc,
160*4882a593Smuzhiyun PicturePtr pDst,
161*4882a593Smuzhiyun PictFormatPtr maskFormat,
162*4882a593Smuzhiyun INT16 xSrc, INT16 ySrc, int ntrap, xTrapezoid * traps)
163*4882a593Smuzhiyun {
164*4882a593Smuzhiyun xSrc -= (traps[0].left.p1.x >> 16);
165*4882a593Smuzhiyun ySrc -= (traps[0].left.p1.y >> 16);
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun fbShapes((CompositeShapesFunc) pixman_composite_trapezoids,
168*4882a593Smuzhiyun op, pSrc, pDst, maskFormat,
169*4882a593Smuzhiyun xSrc, ySrc, ntrap, sizeof(xTrapezoid), (const uint8_t *) traps);
170*4882a593Smuzhiyun }
171*4882a593Smuzhiyun
172*4882a593Smuzhiyun void
fbTriangles(CARD8 op,PicturePtr pSrc,PicturePtr pDst,PictFormatPtr maskFormat,INT16 xSrc,INT16 ySrc,int ntris,xTriangle * tris)173*4882a593Smuzhiyun fbTriangles(CARD8 op,
174*4882a593Smuzhiyun PicturePtr pSrc,
175*4882a593Smuzhiyun PicturePtr pDst,
176*4882a593Smuzhiyun PictFormatPtr maskFormat,
177*4882a593Smuzhiyun INT16 xSrc, INT16 ySrc, int ntris, xTriangle * tris)
178*4882a593Smuzhiyun {
179*4882a593Smuzhiyun xSrc -= (tris[0].p1.x >> 16);
180*4882a593Smuzhiyun ySrc -= (tris[0].p1.y >> 16);
181*4882a593Smuzhiyun
182*4882a593Smuzhiyun fbShapes((CompositeShapesFunc) pixman_composite_triangles,
183*4882a593Smuzhiyun op, pSrc, pDst, maskFormat,
184*4882a593Smuzhiyun xSrc, ySrc, ntris, sizeof(xTriangle), (const uint8_t *) tris);
185*4882a593Smuzhiyun }
186