1706f2543Smrg/***********************************************************
2706f2543Smrg
3706f2543SmrgCopyright 1987, 1998  The Open Group
4706f2543Smrg
5706f2543SmrgPermission to use, copy, modify, distribute, and sell this software and its
6706f2543Smrgdocumentation for any purpose is hereby granted without fee, provided that
7706f2543Smrgthe above copyright notice appear in all copies and that both that
8706f2543Smrgcopyright notice and this permission notice appear in supporting
9706f2543Smrgdocumentation.
10706f2543Smrg
11706f2543SmrgThe above copyright notice and this permission notice shall be included in
12706f2543Smrgall copies or substantial portions of the Software.
13706f2543Smrg
14706f2543SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15706f2543SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16706f2543SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17706f2543SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18706f2543SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19706f2543SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20706f2543Smrg
21706f2543SmrgExcept as contained in this notice, the name of The Open Group shall not be
22706f2543Smrgused in advertising or otherwise to promote the sale, use or other dealings
23706f2543Smrgin this Software without prior written authorization from The Open Group.
24706f2543Smrg
25706f2543Smrg
26706f2543SmrgCopyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
27706f2543Smrg
28706f2543Smrg                        All Rights Reserved
29706f2543Smrg
30706f2543SmrgPermission to use, copy, modify, and distribute this software and its
31706f2543Smrgdocumentation for any purpose and without fee is hereby granted,
32706f2543Smrgprovided that the above copyright notice appear in all copies and that
33706f2543Smrgboth that copyright notice and this permission notice appear in
34706f2543Smrgsupporting documentation, and that the name of Digital not be
35706f2543Smrgused in advertising or publicity pertaining to distribution of the
36706f2543Smrgsoftware without specific, written prior permission.
37706f2543Smrg
38706f2543SmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39706f2543SmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40706f2543SmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41706f2543SmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42706f2543SmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43706f2543SmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
44706f2543SmrgSOFTWARE.
45706f2543Smrg
46706f2543Smrg******************************************************************/
47706f2543Smrg
48706f2543Smrg#ifdef HAVE_DIX_CONFIG_H
49706f2543Smrg#include <dix-config.h>
50706f2543Smrg#endif
51706f2543Smrg
52706f2543Smrg#include <X11/X.h>
53706f2543Smrg#include <X11/Xprotostr.h>
54706f2543Smrg#include "gcstruct.h"
55706f2543Smrg#include "windowstr.h"
56706f2543Smrg#include "pixmap.h"
57706f2543Smrg#include "mi.h"
58706f2543Smrg#include "misc.h"
59706f2543Smrg
60706f2543Smrg/* mi rectangles
61706f2543Smrg   written by newman, with debts to all and sundry
62706f2543Smrg*/
63706f2543Smrg
64706f2543Smrg/* MIPOLYFILLRECT -- public entry for PolyFillRect request
65706f2543Smrg * very straight forward: translate rectangles if necessary
66706f2543Smrg * then call FillSpans to fill each rectangle.  We let FillSpans worry about
67706f2543Smrg * clipping to the destination
68706f2543Smrg */
69706f2543Smrgvoid
70706f2543SmrgmiPolyFillRect(
71706f2543Smrg    DrawablePtr	pDrawable,
72706f2543Smrg    GCPtr	pGC,
73706f2543Smrg    int		nrectFill,	/* number of rectangles to fill */
74706f2543Smrg    xRectangle	*prectInit	/* Pointer to first rectangle to fill */
75706f2543Smrg    )
76706f2543Smrg{
77706f2543Smrg    int i;
78706f2543Smrg    int	height;
79706f2543Smrg    int	width;
80706f2543Smrg    xRectangle *prect;
81706f2543Smrg    int	xorg;
82706f2543Smrg    int	yorg;
83706f2543Smrg    int	maxheight;
84706f2543Smrg    DDXPointPtr	pptFirst;
85706f2543Smrg    DDXPointPtr ppt;
86706f2543Smrg    int	*pwFirst;
87706f2543Smrg    int *pw;
88706f2543Smrg
89706f2543Smrg    if (pGC->miTranslate)
90706f2543Smrg    {
91706f2543Smrg	xorg = pDrawable->x;
92706f2543Smrg	yorg = pDrawable->y;
93706f2543Smrg        prect = prectInit;
94706f2543Smrg        maxheight = 0;
95706f2543Smrg        for (i = 0; i<nrectFill; i++, prect++)
96706f2543Smrg        {
97706f2543Smrg	    prect->x += xorg;
98706f2543Smrg	    prect->y += yorg;
99706f2543Smrg	    maxheight = max(maxheight, prect->height);
100706f2543Smrg        }
101706f2543Smrg    }
102706f2543Smrg    else
103706f2543Smrg    {
104706f2543Smrg        prect = prectInit;
105706f2543Smrg        maxheight = 0;
106706f2543Smrg        for (i = 0; i<nrectFill; i++, prect++)
107706f2543Smrg	    maxheight = max(maxheight, prect->height);
108706f2543Smrg    }
109706f2543Smrg
110706f2543Smrg    pptFirst = malloc(maxheight * sizeof(DDXPointRec));
111706f2543Smrg    pwFirst = malloc(maxheight * sizeof(int));
112706f2543Smrg    if(!pptFirst || !pwFirst)
113706f2543Smrg    {
114706f2543Smrg	free(pwFirst);
115706f2543Smrg	free(pptFirst);
116706f2543Smrg	return;
117706f2543Smrg    }
118706f2543Smrg
119706f2543Smrg    prect = prectInit;
120706f2543Smrg    while(nrectFill--)
121706f2543Smrg    {
122706f2543Smrg	ppt = pptFirst;
123706f2543Smrg	pw = pwFirst;
124706f2543Smrg	height = prect->height;
125706f2543Smrg	width = prect->width;
126706f2543Smrg	xorg = prect->x;
127706f2543Smrg	yorg = prect->y;
128706f2543Smrg	while(height--)
129706f2543Smrg	{
130706f2543Smrg	    *pw++ = width;
131706f2543Smrg	    ppt->x = xorg;
132706f2543Smrg	    ppt->y = yorg;
133706f2543Smrg	    ppt++;
134706f2543Smrg	    yorg++;
135706f2543Smrg	}
136706f2543Smrg	(* pGC->ops->FillSpans)(pDrawable, pGC,
137706f2543Smrg			   prect->height, pptFirst, pwFirst,
138706f2543Smrg			   1);
139706f2543Smrg	prect++;
140706f2543Smrg    }
141706f2543Smrg    free(pwFirst);
142706f2543Smrg    free(pptFirst);
143706f2543Smrg}
144