do_traps.c revision 533545b5
1/***************************************************************************** 2Copyright 1988, 1989 by Digital Equipment Corporation, Maynard, Massachusetts. 3 4 All Rights Reserved 5 6Permission to use, copy, modify, and distribute this software and its 7documentation for any purpose and without fee is hereby granted, 8provided that the above copyright notice appear in all copies and that 9both that copyright notice and this permission notice appear in 10supporting documentation, and that the name of Digital not be 11used in advertising or publicity pertaining to distribution of the 12software without specific, written prior permission. 13 14DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 15ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 16DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 17ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 18WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 19ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 20SOFTWARE. 21 22******************************************************************************/ 23 24#include "x11perf.h" 25#include "bitmaps.h" 26 27#define NUM_POINTS 4 /* 4 points to a trapezoid */ 28static XPoint *points; 29static GC pgc; 30 31int 32InitTrapezoids(XParms xp, Parms p, int64_t reps) 33{ 34 int i, numPoints; 35 int rows; 36 int x, y; 37 int size, skew; 38 XPoint *curPoint; 39 40 pgc = xp->fggc; 41 42 size = p->special; 43 numPoints = (p->objects) * NUM_POINTS; 44 points = (XPoint *)malloc(numPoints * sizeof(XPoint)); 45 curPoint = points; 46 x = size; 47 y = 0; 48 rows = 0; 49 skew = size; 50 51 for (i = 0; i != p->objects; i++, curPoint += NUM_POINTS) { 52 curPoint[0].x = x - skew; 53 curPoint[0].y = y; 54 curPoint[1].x = x - skew + size; 55 curPoint[1].y = y; 56 curPoint[2].x = x + skew; 57 curPoint[2].y = y + size; 58 curPoint[3].x = x + skew - size; 59 curPoint[3].y = y + size; 60 61 skew--; 62 if (skew < 0) skew = size; 63 64 y += size; 65 rows++; 66 if (y + size > HEIGHT || rows == MAXROWS) { 67 rows = 0; 68 y = 0; 69 x += 2 * size; 70 if (x + size > WIDTH) { 71 x = size; 72 } 73 } 74 } 75 76 SetFillStyle(xp, p); 77 return reps; 78} 79 80void 81DoTrapezoids(XParms xp, Parms p, int64_t reps) 82{ 83 int i, j; 84 XPoint *curPoint; 85 86 for (i = 0; i != reps; i++) { 87 curPoint = points; 88 for (j = 0; j != p->objects; j++) { 89 XFillPolygon(xp->d, xp->w, pgc, curPoint, NUM_POINTS, Convex, 90 CoordModeOrigin); 91 curPoint += NUM_POINTS; 92 } 93 if (pgc == xp->bggc) 94 pgc = xp->fggc; 95 else 96 pgc = xp->bggc; 97 CheckAbort (); 98 } 99} 100 101void 102EndTrapezoids(XParms xp, Parms p) 103{ 104 free(points); 105} 106 107#if defined(XRENDER) && defined(XFT) 108#include <X11/extensions/Xrender.h> 109#include <X11/Xft/Xft.h> 110 111static XTrap *traps; 112static XTrapezoid *trapezoids; 113static XftDraw *aadraw; 114static XftColor aablack, aawhite; 115static XRenderColor transparent = { 0, 0, 0, 0 }; 116static XRenderPictFormat *maskFormat; 117static Pixmap maskPixmap; 118static Picture mask; 119 120int 121InitFixedTraps(XParms xp, Parms p, int64_t reps) 122{ 123 int i, numTraps; 124 int rows; 125 int x, y; 126 int size, skew; 127 XTrap *curTrap; 128 XRenderColor color; 129 int major, minor; 130 int depth; 131 int width; 132 int std_fmt; 133 134 XRenderQueryVersion (xp->d, &major, &minor); 135 if (major == 0 && minor < 9) 136 return 0; 137 138 pgc = xp->fggc; 139 140 size = p->special; 141 numTraps = p->objects; 142 traps = (XTrap *)malloc(numTraps * sizeof(XTrap)); 143 curTrap = traps; 144 x = size; 145 y = 0; 146 rows = 0; 147 skew = size; 148 aadraw = XftDrawCreate (xp->d, xp->w, 149 xp->vinfo.visual, 150 xp->cmap); 151 152 depth = 0; 153 width = 0; 154 if (p->font) 155 sscanf (p->font, "%d,%d", &depth, &width); 156 157 switch (depth) { 158 case 8: 159 default: 160 depth = 8; 161 std_fmt = PictStandardA8; 162 break; 163 case 4: 164 std_fmt = PictStandardA4; 165 break; 166 case 1: 167 std_fmt = PictStandardA1; 168 break; 169 } 170 maskFormat = XRenderFindStandardFormat (xp->d, std_fmt); 171 172 maskPixmap = XCreatePixmap (xp->d, xp->w, WIDTH, HEIGHT, depth); 173 174 mask = XRenderCreatePicture (xp->d, maskPixmap, maskFormat, 0, NULL); 175 176 color.red = 0; 177 color.green = 0; 178 color.blue = 0; 179 color.alpha = 0xffff; 180 if (!XftColorAllocValue (xp->d, 181 xp->vinfo.visual, 182 xp->cmap, 183 &color, &aablack)) 184 { 185 XftDrawDestroy (aadraw); 186 aadraw = NULL; 187 return 0; 188 } 189 color.red = 0xffff; 190 color.green = 0xffff; 191 color.blue = 0xffff; 192 color.alpha = 0xffff; 193 if (!XftColorAllocValue (xp->d, 194 xp->vinfo.visual, 195 xp->cmap, 196 &color, &aawhite)) 197 { 198 XftDrawDestroy (aadraw); 199 aadraw = NULL; 200 return 0; 201 } 202 203 if (width == 0) 204 width = size; 205 for (i = 0; i != p->objects; i++, curTrap ++) { 206 curTrap->top.y = XDoubleToFixed (y); 207 curTrap->top.left = XDoubleToFixed (x - skew); 208 curTrap->top.right = XDoubleToFixed (x - skew + width); 209 curTrap->bottom.y = XDoubleToFixed (y + size); 210 curTrap->bottom.left = XDoubleToFixed (x + skew - width); 211 curTrap->bottom.right = XDoubleToFixed (x + skew); 212 213 skew--; 214 if (skew < 0) skew = size; 215 216 y += size; 217 rows++; 218 if (y + size > HEIGHT || rows == MAXROWS) { 219 rows = 0; 220 y = 0; 221 x += 2 * size; 222 if (x + size > WIDTH) { 223 x = size; 224 } 225 } 226 } 227 228 SetFillStyle(xp, p); 229 return reps; 230} 231 232void 233DoFixedTraps(XParms xp, Parms p, int64_t reps) 234{ 235 int i; 236 Picture white, black, src, dst; 237 238 white = XftDrawSrcPicture (aadraw, &aawhite); 239 black = XftDrawSrcPicture (aadraw, &aablack); 240 dst = XftDrawPicture (aadraw); 241 242 src = black; 243 for (i = 0; i != reps; i++) { 244 XRenderFillRectangle (xp->d, PictOpSrc, mask, &transparent, 245 0, 0, WIDTH, HEIGHT); 246 XRenderAddTraps (xp->d, mask, 0, 0, traps, p->objects); 247 XRenderComposite (xp->d, PictOpOver, src, mask, dst, 248 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT); 249 if (src == black) 250 src = white; 251 else 252 src = black; 253 CheckAbort (); 254 } 255} 256 257void 258EndFixedTraps (XParms xp, Parms p) 259{ 260 free (traps); 261 XftDrawDestroy (aadraw); 262 XRenderFreePicture (xp->d, mask); 263 XFreePixmap (xp->d, maskPixmap); 264} 265 266int 267InitFixedTrapezoids(XParms xp, Parms p, int64_t reps) 268{ 269 int i, numTraps; 270 int rows; 271 int x, y; 272 int size, skew; 273 XTrapezoid *curTrap; 274 XRenderColor color; 275 276 pgc = xp->fggc; 277 278 size = p->special; 279 numTraps = p->objects; 280 trapezoids = (XTrapezoid *)malloc(numTraps * sizeof(XTrapezoid)); 281 curTrap = trapezoids; 282 x = size; 283 y = 0; 284 rows = 0; 285 skew = size; 286 aadraw = XftDrawCreate (xp->d, xp->w, 287 xp->vinfo.visual, 288 xp->cmap); 289 if (p->font && !strcmp (p->font, "add")) 290 { 291 XRenderPictFormat templ; 292 templ.type = PictTypeDirect; 293 templ.depth = 8; 294 templ.direct.alpha = 0; 295 templ.direct.alphaMask = 0xff; 296 maskFormat = XRenderFindFormat (xp->d, 297 PictFormatType | 298 PictFormatDepth | 299 PictFormatAlpha | 300 PictFormatAlphaMask, 301 &templ, 302 0); 303 } 304 else 305 maskFormat = NULL; 306 color.red = 0; 307 color.green = 0; 308 color.blue = 0; 309 color.alpha = 0xffff; 310 if (!XftColorAllocValue (xp->d, 311 xp->vinfo.visual, 312 xp->cmap, 313 &color, &aablack)) 314 { 315 XftDrawDestroy (aadraw); 316 aadraw = NULL; 317 return 0; 318 } 319 color.red = 0xffff; 320 color.green = 0xffff; 321 color.blue = 0xffff; 322 color.alpha = 0xffff; 323 if (!XftColorAllocValue (xp->d, 324 xp->vinfo.visual, 325 xp->cmap, 326 &color, &aawhite)) 327 { 328 XftDrawDestroy (aadraw); 329 aadraw = NULL; 330 return 0; 331 } 332 333 for (i = 0; i != p->objects; i++, curTrap ++) { 334 curTrap->top = XDoubleToFixed (y); 335 curTrap->bottom = XDoubleToFixed (y + size); 336 curTrap->left.p1.x = XDoubleToFixed (x - skew); 337 curTrap->left.p1.y = XDoubleToFixed (y); 338 curTrap->left.p2.x = XDoubleToFixed (x + skew - size); 339 curTrap->left.p2.y = XDoubleToFixed (y + size); 340 341 curTrap->right.p1.x = XDoubleToFixed (x - skew + size); 342 curTrap->right.p1.y = XDoubleToFixed (y); 343 curTrap->right.p2.x = XDoubleToFixed (x + skew); 344 curTrap->right.p2.y = XDoubleToFixed (y + size); 345 346 skew--; 347 if (skew < 0) skew = size; 348 349 y += size; 350 rows++; 351 if (y + size > HEIGHT || rows == MAXROWS) { 352 rows = 0; 353 y = 0; 354 x += 2 * size; 355 if (x + size > WIDTH) { 356 x = size; 357 } 358 } 359 } 360 361 362 SetFillStyle(xp, p); 363 return reps; 364} 365 366void 367DoFixedTrapezoids(XParms xp, Parms p, int64_t reps) 368{ 369 int i; 370 Picture white, black, src, dst; 371 372 white = XftDrawSrcPicture (aadraw, &aawhite); 373 black = XftDrawSrcPicture (aadraw, &aablack); 374 dst = XftDrawPicture (aadraw); 375 376 src = black; 377 for (i = 0; i != reps; i++) { 378 XRenderCompositeTrapezoids (xp->d, PictOpOver, src, dst, maskFormat, 379 0, 0, trapezoids, p->objects); 380 if (src == black) 381 src = white; 382 else 383 src = black; 384 CheckAbort (); 385 } 386} 387 388void 389EndFixedTrapezoids (XParms xp, Parms p) 390{ 391 free (trapezoids); 392 XftDrawDestroy (aadraw); 393} 394 395#endif /* XRENDER */ 396