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