1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * Copyright © 1998 Keith Packard
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Permission to use, copy, modify, distribute, and sell this software and its
5*4882a593Smuzhiyun * documentation for any purpose is hereby granted without fee, provided that
6*4882a593Smuzhiyun * the above copyright notice appear in all copies and that both that
7*4882a593Smuzhiyun * copyright notice and this permission notice appear in supporting
8*4882a593Smuzhiyun * documentation, and that the name of Keith Packard not be used in
9*4882a593Smuzhiyun * advertising or publicity pertaining to distribution of the software without
10*4882a593Smuzhiyun * specific, written prior permission. Keith Packard makes no
11*4882a593Smuzhiyun * representations about the suitability of this software for any purpose. It
12*4882a593Smuzhiyun * is provided "as is" without express or implied warranty.
13*4882a593Smuzhiyun *
14*4882a593Smuzhiyun * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15*4882a593Smuzhiyun * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16*4882a593Smuzhiyun * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17*4882a593Smuzhiyun * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18*4882a593Smuzhiyun * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19*4882a593Smuzhiyun * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20*4882a593Smuzhiyun * PERFORMANCE OF THIS SOFTWARE.
21*4882a593Smuzhiyun */
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun #ifdef HAVE_DIX_CONFIG_H
24*4882a593Smuzhiyun #include <dix-config.h>
25*4882a593Smuzhiyun #endif
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun #include "fb.h"
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun void
fbPolyFillRect(DrawablePtr pDrawable,GCPtr pGC,int nrect,xRectangle * prect)30*4882a593Smuzhiyun fbPolyFillRect(DrawablePtr pDrawable, GCPtr pGC, int nrect, xRectangle *prect)
31*4882a593Smuzhiyun {
32*4882a593Smuzhiyun RegionPtr pClip = fbGetCompositeClip(pGC);
33*4882a593Smuzhiyun register BoxPtr pbox;
34*4882a593Smuzhiyun BoxPtr pextent;
35*4882a593Smuzhiyun int extentX1, extentX2, extentY1, extentY2;
36*4882a593Smuzhiyun int fullX1, fullX2, fullY1, fullY2;
37*4882a593Smuzhiyun int partX1, partX2, partY1, partY2;
38*4882a593Smuzhiyun int xorg, yorg;
39*4882a593Smuzhiyun int n;
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun xorg = pDrawable->x;
42*4882a593Smuzhiyun yorg = pDrawable->y;
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun pextent = RegionExtents(pClip);
45*4882a593Smuzhiyun extentX1 = pextent->x1;
46*4882a593Smuzhiyun extentY1 = pextent->y1;
47*4882a593Smuzhiyun extentX2 = pextent->x2;
48*4882a593Smuzhiyun extentY2 = pextent->y2;
49*4882a593Smuzhiyun while (nrect--) {
50*4882a593Smuzhiyun fullX1 = prect->x + xorg;
51*4882a593Smuzhiyun fullY1 = prect->y + yorg;
52*4882a593Smuzhiyun fullX2 = fullX1 + (int) prect->width;
53*4882a593Smuzhiyun fullY2 = fullY1 + (int) prect->height;
54*4882a593Smuzhiyun prect++;
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun if (fullX1 < extentX1)
57*4882a593Smuzhiyun fullX1 = extentX1;
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun if (fullY1 < extentY1)
60*4882a593Smuzhiyun fullY1 = extentY1;
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun if (fullX2 > extentX2)
63*4882a593Smuzhiyun fullX2 = extentX2;
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun if (fullY2 > extentY2)
66*4882a593Smuzhiyun fullY2 = extentY2;
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun if ((fullX1 >= fullX2) || (fullY1 >= fullY2))
69*4882a593Smuzhiyun continue;
70*4882a593Smuzhiyun n = RegionNumRects(pClip);
71*4882a593Smuzhiyun if (n == 1) {
72*4882a593Smuzhiyun fbFill(pDrawable,
73*4882a593Smuzhiyun pGC, fullX1, fullY1, fullX2 - fullX1, fullY2 - fullY1);
74*4882a593Smuzhiyun }
75*4882a593Smuzhiyun else {
76*4882a593Smuzhiyun pbox = RegionRects(pClip);
77*4882a593Smuzhiyun /*
78*4882a593Smuzhiyun * clip the rectangle to each box in the clip region
79*4882a593Smuzhiyun * this is logically equivalent to calling Intersect()
80*4882a593Smuzhiyun */
81*4882a593Smuzhiyun while (n--) {
82*4882a593Smuzhiyun partX1 = pbox->x1;
83*4882a593Smuzhiyun if (partX1 < fullX1)
84*4882a593Smuzhiyun partX1 = fullX1;
85*4882a593Smuzhiyun partY1 = pbox->y1;
86*4882a593Smuzhiyun if (partY1 < fullY1)
87*4882a593Smuzhiyun partY1 = fullY1;
88*4882a593Smuzhiyun partX2 = pbox->x2;
89*4882a593Smuzhiyun if (partX2 > fullX2)
90*4882a593Smuzhiyun partX2 = fullX2;
91*4882a593Smuzhiyun partY2 = pbox->y2;
92*4882a593Smuzhiyun if (partY2 > fullY2)
93*4882a593Smuzhiyun partY2 = fullY2;
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun pbox++;
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun if (partX1 < partX2 && partY1 < partY2)
98*4882a593Smuzhiyun fbFill(pDrawable, pGC,
99*4882a593Smuzhiyun partX1, partY1, partX2 - partX1, partY2 - partY1);
100*4882a593Smuzhiyun }
101*4882a593Smuzhiyun }
102*4882a593Smuzhiyun }
103*4882a593Smuzhiyun }
104