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