do_rects.c revision 264fa531
1264fa531Smrg/* $Xorg: do_rects.c,v 1.4 2000/08/17 19:54:09 cpqbld Exp $ */
2264fa531Smrg/*****************************************************************************
3264fa531SmrgCopyright 1988, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
4264fa531Smrg
5264fa531Smrg                        All Rights Reserved
6264fa531Smrg
7264fa531SmrgPermission to use, copy, modify, and distribute this software and its
8264fa531Smrgdocumentation for any purpose and without fee is hereby granted,
9264fa531Smrgprovided that the above copyright notice appear in all copies and that
10264fa531Smrgboth that copyright notice and this permission notice appear in
11264fa531Smrgsupporting documentation, and that the name of Digital not be
12264fa531Smrgused in advertising or publicity pertaining to distribution of the
13264fa531Smrgsoftware without specific, written prior permission.
14264fa531Smrg
15264fa531SmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
16264fa531SmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
17264fa531SmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
18264fa531SmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19264fa531SmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
20264fa531SmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
21264fa531SmrgSOFTWARE.
22264fa531Smrg
23264fa531Smrg******************************************************************************/
24264fa531Smrg/* $XFree86: xc/programs/x11perf/do_rects.c,v 1.4 2000/11/29 08:58:19 keithp Exp $ */
25264fa531Smrg
26264fa531Smrg#include "x11perf.h"
27264fa531Smrg#include "bitmaps.h"
28264fa531Smrg
29264fa531Smrgstatic XRectangle   *rects;
30264fa531Smrgstatic GC	    pgc;
31264fa531Smrg
32264fa531Smrgint
33264fa531SmrgInitRectangles(XParms xp, Parms p, int reps)
34264fa531Smrg{
35264fa531Smrg    int i;
36264fa531Smrg    int size = p->special;
37264fa531Smrg    int step;
38264fa531Smrg    int x, y;
39264fa531Smrg    int rows;
40264fa531Smrg    int	lw = 0;
41264fa531Smrg
42264fa531Smrg    pgc = xp->fggc;
43264fa531Smrg
44264fa531Smrg    if (p->bfont)
45264fa531Smrg    {
46264fa531Smrg	lw = atoi (p->bfont);
47264fa531Smrg
48264fa531Smrg	XSetLineAttributes(xp->d, xp->bggc, lw, LineSolid, CapButt, JoinMiter);
49264fa531Smrg	XSetLineAttributes(xp->d, xp->fggc, lw, LineSolid, CapButt, JoinMiter);
50264fa531Smrg	lw = (lw >> 1) + 1;
51264fa531Smrg    }
52264fa531Smrg
53264fa531Smrg    rects = (XRectangle *)malloc(p->objects * sizeof(XRectangle));
54264fa531Smrg    x = lw;
55264fa531Smrg    y = lw;
56264fa531Smrg    rows = 0;
57264fa531Smrg    if (xp->pack) {
58264fa531Smrg	/* Pack rectangles as close as possible, mainly for debugging faster
59264fa531Smrg	   tiling, stippling routines in a server */
60264fa531Smrg	step = size;
61264fa531Smrg    } else {
62264fa531Smrg	/* Try to exercise all alignments...any odd number is okay */
63264fa531Smrg	step = size + 1 + (size % 2);
64264fa531Smrg    }
65264fa531Smrg
66264fa531Smrg    for (i = 0; i != p->objects; i++) {
67264fa531Smrg	rects[i].x = x;
68264fa531Smrg        rects[i].y = y;
69264fa531Smrg	rects[i].width = rects[i].height = size;
70264fa531Smrg
71264fa531Smrg	y += step;
72264fa531Smrg	rows++;
73264fa531Smrg	if (y + size > HEIGHT || rows == MAXROWS) {
74264fa531Smrg	    rows = 0;
75264fa531Smrg	    y = lw;
76264fa531Smrg	    x += step;
77264fa531Smrg	    if (x + size > WIDTH) {
78264fa531Smrg		x = lw;
79264fa531Smrg	    }
80264fa531Smrg	}
81264fa531Smrg    }
82264fa531Smrg
83264fa531Smrg    SetFillStyle(xp, p);
84264fa531Smrg
85264fa531Smrg    return reps;
86264fa531Smrg}
87264fa531Smrg
88264fa531Smrgvoid
89264fa531SmrgDoRectangles(XParms xp, Parms p, int reps)
90264fa531Smrg{
91264fa531Smrg    int i;
92264fa531Smrg
93264fa531Smrg    for (i = 0; i != reps; i++) {
94264fa531Smrg        XFillRectangles(xp->d, xp->w, pgc, rects, p->objects);
95264fa531Smrg        if (pgc == xp->bggc)
96264fa531Smrg            pgc = xp->fggc;
97264fa531Smrg        else
98264fa531Smrg            pgc = xp->bggc;
99264fa531Smrg	CheckAbort ();
100264fa531Smrg    }
101264fa531Smrg}
102264fa531Smrg
103264fa531Smrgvoid
104264fa531SmrgDoOutlineRectangles(XParms xp, Parms  p, int reps)
105264fa531Smrg{
106264fa531Smrg    int	i;
107264fa531Smrg
108264fa531Smrg    for (i = 0; i != reps; i++) {
109264fa531Smrg	XDrawRectangles (xp->d, xp->w, pgc, rects, p->objects);
110264fa531Smrg        if (pgc == xp->bggc)
111264fa531Smrg            pgc = xp->fggc;
112264fa531Smrg        else
113264fa531Smrg            pgc = xp->bggc;
114264fa531Smrg	CheckAbort ();
115264fa531Smrg    }
116264fa531Smrg}
117264fa531Smrg
118264fa531Smrgvoid
119264fa531SmrgEndRectangles(XParms xp, Parms p)
120264fa531Smrg{
121264fa531Smrg    free(rects);
122264fa531Smrg}
123264fa531Smrg
124