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