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 / sline.c < prev    next >
C/C++ Source or Header  |  1990-03-01  |  2KB  |  96 lines

  1. static char SCCSID[] = "@(#)sline.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    256
  27.  
  28. /*
  29.  * sloped lines
  30.  */
  31. sline_setup(dpy, win, len)
  32. Display *dpy;
  33. Window win;
  34. {
  35.     int screen = DefaultScreen(dpy);
  36.     int i;
  37.     XSegment *sp;
  38.  
  39.     drawWhite = XCreateGC(dpy, win, 0L, NULL);
  40.     if (! drawWhite) return 1;
  41.     XSetForeground(dpy, drawWhite, WhitePixel(dpy, screen));
  42.     XSetBackground(dpy, drawWhite, BlackPixel(dpy, screen));
  43.  
  44.     drawBlack = XCreateGC(dpy, win, 0L, NULL);
  45.     if (!drawBlack) return 1;
  46.     XSetForeground(dpy, drawBlack, BlackPixel(dpy, screen));
  47.     XSetBackground(dpy, drawBlack, WhitePixel(dpy, screen));
  48.  
  49.     segments = (XSegment *)malloc(sizeof(XSegment) * NSEG);
  50.     if (segments == (XSegment *)0)
  51.         return 1;
  52.  
  53.     sp = segments;
  54.     for (i=0; i<NSEG; i++) {
  55.         sp->x1 = i; sp->y1 = 0;
  56.         sp->x2 = i+len; sp->y2 = i+len;
  57.         sp++;
  58.     }
  59.     return 0;
  60. }
  61.  
  62. sline_cleanup(dpy, win, dummy)
  63. Display *dpy;
  64. Window win;
  65. {
  66.     XFreeGC(dpy, drawWhite);
  67.     XFreeGC(dpy, drawBlack);
  68.     free(segments);
  69. }
  70.  
  71. sline_bench(dpy, win, len)
  72. Display *dpy;
  73. Window win;
  74. {
  75.     int nline;
  76.  
  77.     nline = 0;
  78.     while (benchRunning) {
  79.         XDrawSegments(dpy, win, drawWhite, segments, NSEG);
  80.         XDrawSegments(dpy, win, drawBlack, segments, NSEG);
  81.         nline += NSEG*2;
  82.     }
  83.     return nline;
  84. }
  85.  
  86. sline_msg(deltaT, nline, len, rate)
  87. double rate;
  88. {
  89.     printf("SLOPED (DIAGONAL) LINES\n");
  90.     printf("\n");
  91.     printf("%d diagonal vectors of len. %d in %d secs\n",
  92.                 nline, len, deltaT);
  93.     printf("rate = %8.2f vectors/sec (%d Pixels/sec)\n",
  94.                 rate, (nline*len)/deltaT);
  95. }
  96.