home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / x / x11p-13.zip / RCS / do_segs.c,v < prev    next >
Text File  |  1989-12-13  |  14KB  |  757 lines

  1. head     2.10;
  2. access   ;
  3. symbols  pre-merge:2.0;
  4. locks    ; strict;
  5. comment  @ * @;
  6.  
  7.  
  8. 2.10
  9. date     89.12.13.19.09.07;  author joel;  state Exp;
  10. branches ;
  11. next     2.9;
  12.  
  13. 2.9
  14. date     89.12.13.11.03.55;  author joel;  state Exp;
  15. branches ;
  16. next     2.8;
  17.  
  18. 2.8
  19. date     89.12.07.16.34.50;  author joel;  state Exp;
  20. branches ;
  21. next     2.7;
  22.  
  23. 2.7
  24. date     89.11.20.13.26.47;  author joel;  state Exp;
  25. branches ;
  26. next     2.6;
  27.  
  28. 2.6
  29. date     89.10.23.18.11.25;  author joel;  state Exp;
  30. branches ;
  31. next     2.5;
  32.  
  33. 2.5
  34. date     89.06.23.14.13.48;  author joel;  state Exp;
  35. branches ;
  36. next     2.4;
  37.  
  38. 2.4
  39. date     89.05.11.16.44.43;  author joel;  state Exp;
  40. branches ;
  41. next     2.3;
  42.  
  43. 2.3
  44. date     89.05.03.14.17.58;  author joel;  state Exp;
  45. branches ;
  46. next     2.2;
  47.  
  48. 2.2
  49. date     89.04.20.11.54.43;  author joel;  state Exp;
  50. branches ;
  51. next     2.1;
  52.  
  53. 2.1
  54. date     89.04.18.14.13.55;  author joel;  state Exp;
  55. branches ;
  56. next     2.0;
  57.  
  58. 2.0
  59. date     89.02.28.19.19.39;  author erik;  state Exp;
  60. branches ;
  61. next     1.1;
  62.  
  63. 1.1
  64. date     89.02.28.19.19.39;  author joel;  state Exp;
  65. branches ;
  66. next     ;
  67.  
  68.  
  69. desc
  70. @Segments code, for unconnected line benchmarking
  71. @
  72.  
  73.  
  74. 2.10
  75. log
  76. @Make sure that all angles of compass treated equally.
  77. Generate slightly different patter...more boring for 100 pixels, more
  78. interesting for 10 and 500.
  79. @
  80. text
  81. @/*****************************************************************************
  82. Copyright 1988, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
  83.  
  84.                         All Rights Reserved
  85.  
  86. Permission to use, copy, modify, and distribute this software and its 
  87. documentation for any purpose and without fee is hereby granted, 
  88. provided that the above copyright notice appear in all copies and that
  89. both that copyright notice and this permission notice appear in 
  90. supporting documentation, and that the name of Digital not be
  91. used in advertising or publicity pertaining to distribution of the
  92. software without specific, written prior permission.  
  93.  
  94. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  95. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  96. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  97. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  98. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  99. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  100. SOFTWARE.
  101.  
  102. ******************************************************************************/
  103.  
  104. #include "x11perf.h"
  105.  
  106. static XSegment *segments;
  107. static GC       pgc;
  108.  
  109. int InitSegments(xp, p, reps)
  110.     XParms  xp;
  111.     Parms   p;
  112.     int     reps;
  113. {
  114.     int size;
  115.     int     half;
  116.     int i;
  117.     int     rows;       /* Number of rows filled in current column      */
  118.     int x, y;        /* base of square to draw in            */
  119.     int x1, y1, x2, y2;    /* offsets into square                */
  120.     int phase;        /* how far into 0..8*size we are        */
  121.     int phaseinc;       /* how much to increment phase at each segment  */
  122.     int size8;        /* 8 * size                    */
  123.     XGCValues   gcv;
  124.  
  125.     pgc = xp->fggc;
  126.  
  127.     size = p->special;
  128.     size8 = 8 * size;
  129.     half = (size + 19) / 20;
  130.  
  131.     segments = (XSegment *)malloc((p->objects) * sizeof(XSegment));
  132.  
  133.     /* All this x, x1, etc. stuff is to create a pattern that
  134.     (1) scans down the screen vertically, with each new segment going
  135.         into a square of size^2.
  136.  
  137.     (2) rotates the endpoints clockwise around the square
  138.  
  139.     (3) rotates by ``large'' steps if we aren't going to paint enough
  140.         segments to get full coverage
  141.  
  142.     (4) uses CapNotLast so we can create segments of length 1 that
  143.         nonetheless have a distinct direction
  144.     */
  145.  
  146.     x     = half;  y     = half;
  147.     phase = 0;
  148.     phaseinc = size8 / p->objects;
  149.     if (phaseinc == 0) phaseinc = 1;
  150.     rows = 0;
  151.  
  152.     for (i = 0; i != p->objects; i++) {    
  153.     switch (phase / size) {
  154.     case 0:
  155.         x1 = 0;
  156.         y1 = 0;
  157.         x2 = size;
  158.         y2 = phase;
  159.         break;
  160.  
  161.     case 1:
  162.         x1 = phase % size;    
  163.         y1 = 0;
  164.         x2 = size;
  165.         y2 = size;
  166.         break;
  167.  
  168.     case 2:
  169.         x1 = size;
  170.         y1 = 0;
  171.         x2 = size - phase % size;
  172.         y2 = size;
  173.         break;
  174.  
  175.     case 3:
  176.         x1 = size;
  177.         y1 = phase % size;
  178.         x2 = 0;
  179.         y2 = size;
  180.         break;
  181.  
  182.     case 4:
  183.         x1 = size;
  184.         y1 = size;
  185.         x2 = 0;
  186.         y2 = size - phase % size;
  187.         break;
  188.  
  189.     case 5:
  190.         x1 = size - phase % size;
  191.         y1 = size;
  192.         x2 = 0;
  193.         y2 = 0;
  194.         break;
  195.  
  196.     case 6:
  197.         x1 = 0;
  198.         y1 = size;
  199.         x2 = phase % size;
  200.         y2 = 0;
  201.         break;
  202.  
  203.     case 7:
  204.         x1 = 0;
  205.         y1 = size - phase % size;
  206.         x2 = size;
  207.         y2 = 0;
  208.         break;
  209.     } /* end switch */
  210.  
  211.     segments[i].x1 = x + x1;
  212.     segments[i].y1 = y + y1;
  213.     segments[i].x2 = x + x2;
  214.     segments[i].y2 = y + y2;
  215.  
  216.     /* Change square to draw segment in */
  217.     rows++;
  218.     y += size;
  219.     if (y >= HEIGHT - size - half || rows == MAXROWS) {
  220.         /* Go to next column */
  221.         rows = 0;
  222.         y = half;
  223.         x += size;
  224.         if (x >= WIDTH - size - half) {
  225.         x = half;
  226.         }
  227.     }
  228.  
  229.     /* Increment phase */
  230.     phase += phaseinc;
  231.     if (phase >= size8) phase -= size8;
  232.  
  233.     }
  234.  
  235.     gcv.cap_style = CapNotLast;
  236.     XChangeGC(xp->d, xp->fggc, GCCapStyle, &gcv);
  237.     XChangeGC(xp->d, xp->bggc, GCCapStyle, &gcv);
  238.     
  239.     return reps;
  240. }
  241.    
  242.  
  243. int InitDashedSegments(xp, p, reps)
  244.     XParms  xp;
  245.     Parms   p;
  246.     int     reps;
  247. {
  248.     char dashes[2];
  249.  
  250.     (void)InitSegments(xp, p, reps);
  251.  
  252.     /* Modify GCs to draw dashed */
  253.     XSetLineAttributes
  254.     (xp->d, xp->bggc, 0, LineOnOffDash, CapNotLast, JoinMiter);
  255.     XSetLineAttributes
  256.     (xp->d, xp->fggc, 0, LineOnOffDash, CapNotLast, JoinMiter);
  257.     dashes[0] = 3;   dashes[1] = 2;
  258.     XSetDashes(xp->d, xp->fggc, 0, dashes, 2);
  259.     XSetDashes(xp->d, xp->bggc, 0, dashes, 2);
  260.     return reps;
  261. }
  262.  
  263. int InitDoubleDashedSegments(xp, p, reps)
  264.     XParms  xp;
  265.     Parms   p;
  266.     int     reps;
  267. {
  268.     char dashes[2];
  269.  
  270.     (void)InitSegments(xp, p, reps);
  271.  
  272.     /* Modify GCs to draw dashed */
  273.     XSetLineAttributes
  274.     (xp->d, xp->bggc, 0, LineDoubleDash, CapNotLast, JoinMiter);
  275.     XSetLineAttributes
  276.     (xp->d, xp->fggc, 0, LineDoubleDash, CapNotLast, JoinMiter);
  277.     dashes[0] = 3;   dashes[1] = 2;
  278.     XSetDashes(xp->d, xp->fggc, 0, dashes, 2);
  279.     XSetDashes(xp->d, xp->bggc, 0, dashes, 2);
  280.     return reps;
  281. }
  282.  
  283. void DoSegments(xp, p, reps)
  284.     XParms  xp;
  285.     Parms   p;
  286.     int     reps;
  287. {
  288.     int i;
  289.  
  290.     for (i = 0; i != reps; i++) {
  291.         XDrawSegments(xp->d, xp->w, pgc, segments, p->objects);
  292.         if (pgc == xp->bggc)
  293.             pgc = xp->fggc;
  294.         else
  295.             pgc = xp->bggc;
  296.     }
  297. }
  298.  
  299. void EndSegments(xp, p)
  300.     XParms  xp;
  301.     Parms p;
  302. {
  303.     free(segments);
  304. }
  305.  
  306. @
  307.  
  308.  
  309. 2.9
  310. log
  311. @Use CapNotLast, don't reduce size, so that 1-pixel segs have a definite
  312. direction.
  313. @
  314. text
  315. @a24 1
  316. #include "stdio.h"
  317. d39 4
  318. a42 4
  319.     int x1, y1;        /* offsets into square                */
  320.     int x1inc, y1inc;   /* How to get to next x1, y1            */
  321.     int minorphase;     /* # iterations left with current x1inc, y1inc  */
  322.     int majorphase;     /* count 0..3 for which type of x1inc, y1inc    */
  323. d48 1
  324. d53 1
  325. a53 1
  326.     /* All this x, x1, x1inc, etc. stuff is to create a pattern that
  327. d55 1
  328. a55 1
  329.         into a square of size x size.
  330. d59 5
  331. a63 2
  332.     (3) CapNotLast used so we can create segments of length 1 that
  333.         nonetheless have a distince direction
  334. d67 3
  335. a69 5
  336.     x1    = 0;     y1    = 0;
  337.     x1inc = 1;     y1inc = 0;
  338.     minorphase = size;
  339.     majorphase = 0;
  340.  
  341. d73 58
  342. d133 2
  343. a134 2
  344.     segments[i].x2 = x + size - x1;
  345.     segments[i].y2 = y + size - y1;
  346. a135 6
  347. /*
  348.     if (i < 20) {
  349.         printf("%d %d %d %d\n", segments[i].x1, segments[i].y1,
  350.             segments[i].x2, segments[i].y2);
  351.     }
  352. */
  353. d138 1
  354. a138 1
  355.     y += size + 1;
  356. d143 1
  357. a143 1
  358.         x += size + 1;
  359. d149 3
  360. a151 3
  361.     /* Change coordinates of offsets in square */
  362.     x1 += x1inc;
  363.     y1 += y1inc;
  364. a152 12
  365.     /* Change increments if needed */
  366.     minorphase--;
  367.     if (minorphase <= 0) {
  368.         minorphase = size;
  369.         majorphase = (majorphase + 1) % 4;
  370.         switch (majorphase) {
  371.         case 0: x1inc =  1; y1inc =  0; break;
  372.         case 1: x1inc =  0; y1inc =  1; break;
  373.         case 2: x1inc = -1; y1inc =  0; break;
  374.         case 3: x1inc =  0; y1inc = -1; break;
  375.         }
  376.     }
  377. @
  378.  
  379.  
  380. 2.8
  381. log
  382. @Changed interface to p->reps
  383. @
  384. text
  385. @d25 1
  386. d44 1
  387. a52 2
  388.     size--;        /* Because endcap counts as 1 pixel        */
  389.  
  390. d59 2
  391. d77 6
  392. d113 5
  393. d132 4
  394. a135 2
  395.     XSetLineAttributes(xp->d, xp->bggc, 0, LineOnOffDash, CapButt, JoinMiter);
  396.     XSetLineAttributes(xp->d, xp->fggc, 0, LineOnOffDash, CapButt, JoinMiter);
  397. d152 4
  398. a155 2
  399.     XSetLineAttributes(xp->d, xp->bggc, 0, LineDoubleDash, CapButt, JoinMiter);
  400.     XSetLineAttributes(xp->d, xp->fggc, 0, LineDoubleDash, CapButt, JoinMiter);
  401. @
  402.  
  403.  
  404. 2.7
  405. log
  406. @done
  407. done
  408. Declare pgc as static, so switch between fggc and bggc happens every time,
  409. not just within one iteration of tests.  (Helps make things look better on
  410. slow machines, which may only run 1 iteration.)
  411. @
  412. text
  413. @d29 1
  414. a29 1
  415. Bool InitSegs(xp, p)
  416. d32 1
  417. d105 1
  418. a105 1
  419.     return True;
  420. d109 1
  421. a109 1
  422. Bool InitDashedSegs(xp, p)
  423. d112 1
  424. d116 1
  425. a116 1
  426.     (void)InitSegs(xp, p);
  427. d124 1
  428. a124 1
  429.     return True;
  430. d127 1
  431. a127 1
  432. Bool InitDoubleDashedSegs(xp, p)
  433. d130 1
  434. d134 1
  435. a134 1
  436.     (void)InitSegs(xp, p);
  437. d142 1
  438. a142 1
  439.     return True;
  440. d145 1
  441. a145 1
  442. void DoSegs(xp, p)
  443. d148 1
  444. d152 1
  445. a152 1
  446.     for (i = 0; i != p->reps; i++) {
  447. d161 1
  448. a161 1
  449. void EndSegs(xp, p)
  450. @
  451.  
  452.  
  453. 2.6
  454. log
  455. @Make sure that wide lines aren't clipped.
  456. @
  457. text
  458. @d27 1
  459. d43 2
  460. a145 1
  461.     GC pgc;
  462. a147 1
  463.     pgc = xp->fggc;
  464. @
  465.  
  466.  
  467. 2.5
  468. log
  469. @Added double-dashed segments
  470. @
  471. text
  472. @d33 1
  473. d43 1
  474. d57 3
  475. a59 3
  476.     x     = 0;  y     = 0;
  477.     x1    = 0;  y1    = 0;
  478.     x1inc = 1;  y1inc = 0;
  479. d74 1
  480. a74 1
  481.     if (y >= HEIGHT - size || rows == MAXROWS) {
  482. d77 1
  483. a77 1
  484.         y = 0;
  485. d79 2
  486. a80 2
  487.         if (x >= WIDTH - size) {
  488.         x = 0;
  489. @
  490.  
  491.  
  492. 2.4
  493. log
  494. @Parameters to all routines now (xp, p)
  495. MAXROWS used in all routines
  496. Junked most global communication variables
  497. @
  498. text
  499. @d120 17
  500. @
  501.  
  502.  
  503. 2.3
  504. log
  505. @Massive changes, I'm not going to go into details.
  506. @
  507. text
  508. @d1 23
  509. a25 1
  510. static Window   w;
  511. a26 1
  512. static GC bggc, fggc;
  513. d28 2
  514. a29 2
  515. Bool InitSegs(d, p)
  516.     Display *d;
  517. d32 1
  518. a32 1
  519.     int     size;
  520. d34 1
  521. d61 3
  522. a63 1
  523.     for (i = 0; i < (p->objects); i++) {    
  524. d70 1
  525. d72 1
  526. a72 1
  527.     if (y >= HEIGHT - size) {
  528. d74 1
  529. a98 1
  530.     CreatePerfStuff(d, 1, WIDTH, HEIGHT, &w, &bggc, &fggc);
  531. d103 2
  532. a104 2
  533. Bool InitDashedSegs(d, p)
  534.     Display *d;
  535. d109 1
  536. a109 1
  537.     (void)InitSegs(d, p);
  538. d112 5
  539. a116 5
  540.     XSetLineAttributes(d, bggc, 0, LineOnOffDash, CapButt, JoinMiter);
  541.     XSetLineAttributes(d, fggc, 0, LineOnOffDash, CapButt, JoinMiter);
  542.     dashes[0] = 1;   dashes[1] = 3;
  543.     XSetDashes(d, fggc, 0, dashes, 2);
  544.     XSetDashes(d, bggc, 0, dashes, 2);
  545. d120 3
  546. a122 3
  547. void DoSegs(d, p)
  548.     Display *d;
  549.     Parms p;
  550. d127 5
  551. a131 6
  552.     pgc = bggc;
  553.     for (i=0; i<p->reps; i++)
  554.     {
  555.         XDrawSegments(d, w, pgc, segments, p->objects);
  556.         if (pgc == bggc)
  557.             pgc = fggc;
  558. d133 1
  559. a133 1
  560.             pgc = bggc;
  561. d137 2
  562. a138 2
  563. void EndSegs(d, p)
  564.     Display *d;
  565. a140 3
  566.     XDestroyWindow(d, w);
  567.     XFreeGC(d, bggc);
  568.     XFreeGC(d, fggc);
  569. @
  570.  
  571.  
  572. 2.2
  573. log
  574. @Changed overlapping windows to screw clipping up more
  575. @
  576. text
  577. @d3 1
  578. a5 6
  579. static Window w[4];
  580. static XRectangle ws[3] = {
  581.     {150, 150, 90, 90},
  582.     {300, 180, 90, 90},
  583.     {450, 210, 90, 90}
  584.   };
  585. d7 1
  586. a7 1
  587. void InitSizedSegs(d, p, size)
  588. d10 1
  589. a11 1
  590. {
  591. d19 2
  592. a20 3
  593.     for (i = 0; i < 4; i++)
  594.     w[i] = None;
  595.     i = 0;
  596. d73 2
  597. a74 5
  598.     CreatePerfStuff(d, 1, WIDTH, HEIGHT, w, &bggc, &fggc);
  599.     for (i = 0; i < p->special; i++)
  600.     w[i+1] = CreatePerfWindow(
  601.         d, ws[i].x, ws[i].y, ws[i].width, ws[i].height);
  602.     
  603. a76 6
  604. void InitSegs1(d, p)
  605.     Display *d;
  606.     Parms p;
  607. {
  608.     InitSizedSegs(d, p, 1);
  609. }
  610. d78 1
  611. a78 2
  612.  
  613. void InitSegs10(d, p)
  614. d80 1
  615. a80 1
  616.     Parms p;
  617. d82 1
  618. a82 2
  619.     InitSizedSegs(d, p, 10);
  620. }
  621. d84 1
  622. d86 7
  623. a92 5
  624. void InitSegs100(d, p)
  625.     Display *d;
  626.     Parms p;
  627. {
  628.     InitSizedSegs(d, p, 100);
  629. a94 9
  630.  
  631. void InitSegs500(d, p)
  632.     Display *d;
  633.     Parms p;
  634. {
  635.     InitSizedSegs(d, p, 500);
  636. }
  637.  
  638.  
  639. d105 1
  640. a105 1
  641.         XDrawSegments(d, w[0], pgc, segments, p->objects);
  642. d117 1
  643. a117 4
  644.     int i;
  645.     for (i = 0; i < 4; i++)
  646.     if (w[i] != None)
  647.         XDestroyWindow(d, w[i]);
  648. @
  649.  
  650.  
  651. 2.1
  652. log
  653. @Non-random segment painting, in columns down screen to make TLB faulting
  654. as bad as possible, and in all possible orientations of a line of the
  655. given length.
  656. @
  657. text
  658. @d7 3
  659. a9 3
  660.     {100, 100, 200, 200},
  661.     {150, 150, 200, 200},
  662.     {200, 200, 200, 200}
  663. d86 1
  664. a86 1
  665. void InitSmallSegs(d, p)
  666. d94 1
  667. a94 1
  668. void InitMedSegs(d, p)
  669. d102 1
  670. a102 1
  671. void InitSegs(d, p)
  672. d106 8
  673. d116 1
  674. @
  675.  
  676.  
  677. 2.0
  678. log
  679. @version from /usr/src/pmax
  680. @
  681. text
  682. @a2 4
  683. /* define CONTINUOUS if you want each line segment to join with the previous */
  684. #define CONTINUOUS
  685.  
  686.  
  687. d17 6
  688. a22 2
  689.     int i, incr;
  690.     int prevx, prevy;
  691. a26 2
  692.     prevx = WIDTH / 2;
  693.     prevy = HEIGHT / 2;
  694. d28 32
  695. a59 13
  696.     for (i = 0; i < (p->objects); i++)
  697.     {    
  698. #ifdef CONTINUOUS
  699.     segments[i].x1 = prevx;
  700.     segments[i].y1 = prevy;
  701. #else
  702.     segments[i].x1 = rand() % WIDTH;
  703.     segments[i].y1 = rand() % HEIGHT;
  704. #endif
  705.     if (segments[i].x1 < size || ((rand() >> 12) & 1)) {
  706.         segments[i].x2 = segments[i].x1 + size;
  707.     } else {
  708.         segments[i].x2 = segments[i].x1 - size;
  709. d61 16
  710. a76 4
  711.     if (segments[i].y1 < size || ((rand() >> 12) & 1)) {
  712.         segments[i].y2 = segments[i].y1 + size;
  713.     } else {
  714.         segments[i].y2 = segments[i].y1 - size;
  715. a77 4
  716. #ifdef CONTINUOUS
  717.     prevx = segments[i].x2;
  718.     prevy = segments[i].y2;
  719. #endif
  720. d106 1
  721. a106 26
  722.     int i;
  723.     int prevx, prevy;
  724.  
  725.     for (i = 0; i < 4; i++)
  726.     w[i] = None;
  727.     i = 0;
  728.     segments = (XSegment *)malloc((p->objects) * sizeof(XSegment));
  729.     prevx = rand() % WIDTH;
  730.     prevy = rand() % HEIGHT;
  731.     for (i = 0; i < (p->objects); i++)
  732.     {    
  733. #ifdef CONTINUOUS
  734.     segments[i].x1 = prevx;
  735.     segments[i].y1 = prevy;
  736. #else
  737.         segments[i].x1 = rand() % WIDTH;
  738.         segments[i].y1 = rand() % HEIGHT;
  739. #endif
  740.         segments[i].x2 = prevx = rand() % WIDTH;
  741.         segments[i].y2 = prevy = rand() % HEIGHT;
  742.     }
  743.     CreatePerfStuff(d, 1, WIDTH, HEIGHT, w, &bggc, &fggc);
  744.     for (i = 0; i < p->special; i++)
  745.     w[i+1] = CreatePerfWindow(
  746.         d, ws[i].x, ws[i].y, ws[i].width, ws[i].height);
  747.     
  748. @
  749.  
  750.  
  751. 1.1
  752. log
  753. @Initial revision
  754. @
  755. text
  756. @@
  757.