home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / x / xbench.zip / XBENCH / wline.c < prev    next >
C/C++ Source or Header  |  1990-03-01  |  3KB  |  123 lines

  1. static char SCCSID[] = "@(#)wline.c    1.2 89/02/22";
  2. /*
  3.  * Copyright 1989 Siemens
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software and its
  6.  * documentation for any purpose and without fee is hereby granted, provided
  7.  * that the above copyright notice appear in all copies and that both that
  8.  * copyright notice and this permission notice appear in supporting
  9.  * documentation, and that the name of Siemens not be used in advertising or
  10.  * publicity pertaining to distribution of the software without specific,
  11.  * written prior permission.  Siemens makes no representations about the
  12.  * suitability of this software for any purpose.  It is provided "as is"
  13.  * without express or implied warranty.
  14.  *
  15.  * Author:  Claus Gittinger, Siemens Munich, unido!sinix!claus@uunet.uu.net
  16.  */
  17.  
  18. #include <stdio.h>
  19. #include <X11/Xlib.h>
  20. #include <X11/Xutil.h>
  21.  
  22. #include "externals.h"
  23.  
  24. static GC drawWhite, drawBlack;
  25. static XSegment *segments;
  26. #define NSEG        64
  27. #define LINEWIDTH   5
  28.  
  29. /*
  30.  * wide lines
  31.  *
  32.  * currently seldom used (becaus most implementations are slow) -
  33.  * as cad applications will appear, this (and dashed lines)
  34.  * may be used more often.
  35.  */
  36. wline_setup(dpy, win, len)
  37. Display *dpy;
  38. Window win;
  39. {
  40.     int screen = DefaultScreen(dpy);
  41.     int i;
  42.     XSegment *sp;
  43.  
  44.     drawWhite = XCreateGC(dpy, win, 0L, NULL);
  45.     if (! drawWhite) return 1;
  46.     XSetForeground(dpy, drawWhite, WhitePixel(dpy, screen));
  47.     XSetBackground(dpy, drawWhite, BlackPixel(dpy, screen));
  48.     XSetLineAttributes(dpy, drawWhite, LINEWIDTH, LineSolid, CapButt, JoinMiter);
  49.  
  50.     drawBlack = XCreateGC(dpy, win, 0L, NULL);
  51.     if (!drawBlack) return 1;
  52.     XSetForeground(dpy, drawBlack, BlackPixel(dpy, screen));
  53.     XSetBackground(dpy, drawBlack, WhitePixel(dpy, screen));
  54.     XSetLineAttributes(dpy, drawBlack, LINEWIDTH, LineSolid, CapButt, JoinMiter);
  55.  
  56.     segments = (XSegment *)malloc(sizeof(XSegment) * 6 * NSEG);
  57.     if (segments == (XSegment *)0)
  58.         return 1;
  59.  
  60.     sp = segments;
  61.     for (i=0; i<NSEG; i++) {
  62.         sp->x1 = i; sp->y1 = i;
  63.         sp->x2 = i+len; sp->y2 = i;
  64.         sp++;
  65.  
  66.         sp->x1 = i; sp->y1 = i;
  67.         sp->x2 = i; sp->y2 = i+len;
  68.         sp++;
  69.  
  70.         sp->x1 = i+len; sp->y1 = i;
  71.         sp->x2 = i; sp->y2 = i+len;
  72.         sp++;
  73.  
  74.         sp->x1 = i; sp->y1 = i;
  75.         sp->x2 = i+len; sp->y2 = i+len;
  76.         sp++;
  77.  
  78.         sp->x1 = i+len; sp->y1 = i;
  79.         sp->x2 = i+len; sp->y2 = i+len;
  80.         sp++;
  81.  
  82.         sp->x1 = i; sp->y1 = i+len;
  83.         sp->x2 = i+len; sp->y2 = i+len;
  84.         sp++;
  85.     }
  86.     return 0;
  87. }
  88.  
  89. wline_cleanup(dpy, win, dummy)
  90. Display *dpy;
  91. Window win;
  92. {
  93.     XFreeGC(dpy, drawWhite);
  94.     XFreeGC(dpy, drawBlack);
  95.     free(segments);
  96. }
  97.  
  98. wline_bench(dpy, win, len)
  99. Display *dpy;
  100. Window win;
  101. {
  102.     int nline;
  103.  
  104.     nline = 0;
  105.     while (benchRunning) {
  106.         XDrawSegments(dpy, win, drawWhite, segments, 6*NSEG);
  107.         XDrawSegments(dpy, win, drawBlack, segments, 6*NSEG);
  108.         nline += NSEG * 6 * 2;
  109.         if (sync) XSync(dpy, 0);
  110.     }
  111.     return nline;
  112. }
  113.  
  114. wline_msg(deltaT, nline, len, rate)
  115. double rate;
  116. {
  117.     printf("WIDE LINES\n");
  118.     printf("\n");
  119.     printf("%d wide vectors (linewidth=%d) of len. %d in %d secs\n",
  120.                 nline, LINEWIDTH, len, deltaT);
  121.     printf("rate = %8.2f vectors/sec\n", rate);
  122. }
  123.