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