do_rects.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*****************************************************************************
  2. Copyright 1988, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
  3. All Rights Reserved
  4. Permission to use, copy, modify, and distribute this software and its
  5. documentation for any purpose and without fee is hereby granted,
  6. provided that the above copyright notice appear in all copies and that
  7. both that copyright notice and this permission notice appear in
  8. supporting documentation, and that the name of Digital not be
  9. used in advertising or publicity pertaining to distribution of the
  10. software without specific, written prior permission.
  11. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  12. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  13. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  14. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  15. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  16. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  17. SOFTWARE.
  18. ******************************************************************************/
  19. #include "x11perf.h"
  20. #include "bitmaps.h"
  21. static XRectangle *rects;
  22. static GC pgc;
  23. int
  24. InitRectangles(XParms xp, Parms p, int64_t reps)
  25. {
  26. int i;
  27. int size = p->special;
  28. int step;
  29. int x, y;
  30. int rows;
  31. int lw = 0;
  32. pgc = xp->fggc;
  33. if (p->bfont)
  34. {
  35. lw = atoi (p->bfont);
  36. XSetLineAttributes(xp->d, xp->bggc, lw, LineSolid, CapButt, JoinMiter);
  37. XSetLineAttributes(xp->d, xp->fggc, lw, LineSolid, CapButt, JoinMiter);
  38. lw = (lw >> 1) + 1;
  39. }
  40. rects = (XRectangle *)malloc(p->objects * sizeof(XRectangle));
  41. x = lw;
  42. y = lw;
  43. rows = 0;
  44. if (xp->pack) {
  45. /* Pack rectangles as close as possible, mainly for debugging faster
  46. tiling, stippling routines in a server */
  47. step = size;
  48. } else {
  49. /* Try to exercise all alignments...any odd number is okay */
  50. step = size + 1 + (size % 2);
  51. }
  52. for (i = 0; i != p->objects; i++) {
  53. rects[i].x = x;
  54. rects[i].y = y;
  55. rects[i].width = rects[i].height = size;
  56. y += step;
  57. rows++;
  58. if (y + size > HEIGHT || rows == MAXROWS) {
  59. rows = 0;
  60. y = lw;
  61. x += step;
  62. if (x + size > WIDTH) {
  63. x = lw;
  64. }
  65. }
  66. }
  67. SetFillStyle(xp, p);
  68. return reps;
  69. }
  70. void
  71. DoRectangles(XParms xp, Parms p, int64_t reps)
  72. {
  73. int i;
  74. for (i = 0; i != reps; i++) {
  75. XFillRectangles(xp->d, xp->w, pgc, rects, p->objects);
  76. if (pgc == xp->bggc)
  77. pgc = xp->fggc;
  78. else
  79. pgc = xp->bggc;
  80. CheckAbort ();
  81. }
  82. }
  83. void
  84. DoOutlineRectangles(XParms xp, Parms p, int64_t reps)
  85. {
  86. int i;
  87. for (i = 0; i != reps; i++) {
  88. XDrawRectangles (xp->d, xp->w, pgc, rects, p->objects);
  89. if (pgc == xp->bggc)
  90. pgc = xp->fggc;
  91. else
  92. pgc = xp->bggc;
  93. CheckAbort ();
  94. }
  95. }
  96. void
  97. EndRectangles(XParms xp, Parms p)
  98. {
  99. free(rects);
  100. }