fbfillrect.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. #ifdef HAVE_DIX_CONFIG_H
  23. #include <dix-config.h>
  24. #endif
  25. #include "fb.h"
  26. void
  27. fbPolyFillRect(DrawablePtr pDrawable, GCPtr pGC, int nrect, xRectangle *prect)
  28. {
  29. RegionPtr pClip = fbGetCompositeClip(pGC);
  30. register BoxPtr pbox;
  31. BoxPtr pextent;
  32. int extentX1, extentX2, extentY1, extentY2;
  33. int fullX1, fullX2, fullY1, fullY2;
  34. int partX1, partX2, partY1, partY2;
  35. int xorg, yorg;
  36. int n;
  37. xorg = pDrawable->x;
  38. yorg = pDrawable->y;
  39. pextent = RegionExtents(pClip);
  40. extentX1 = pextent->x1;
  41. extentY1 = pextent->y1;
  42. extentX2 = pextent->x2;
  43. extentY2 = pextent->y2;
  44. while (nrect--) {
  45. fullX1 = prect->x + xorg;
  46. fullY1 = prect->y + yorg;
  47. fullX2 = fullX1 + (int) prect->width;
  48. fullY2 = fullY1 + (int) prect->height;
  49. prect++;
  50. if (fullX1 < extentX1)
  51. fullX1 = extentX1;
  52. if (fullY1 < extentY1)
  53. fullY1 = extentY1;
  54. if (fullX2 > extentX2)
  55. fullX2 = extentX2;
  56. if (fullY2 > extentY2)
  57. fullY2 = extentY2;
  58. if ((fullX1 >= fullX2) || (fullY1 >= fullY2))
  59. continue;
  60. n = RegionNumRects(pClip);
  61. if (n == 1) {
  62. fbFill(pDrawable,
  63. pGC, fullX1, fullY1, fullX2 - fullX1, fullY2 - fullY1);
  64. }
  65. else {
  66. pbox = RegionRects(pClip);
  67. /*
  68. * clip the rectangle to each box in the clip region
  69. * this is logically equivalent to calling Intersect()
  70. */
  71. while (n--) {
  72. partX1 = pbox->x1;
  73. if (partX1 < fullX1)
  74. partX1 = fullX1;
  75. partY1 = pbox->y1;
  76. if (partY1 < fullY1)
  77. partY1 = fullY1;
  78. partX2 = pbox->x2;
  79. if (partX2 > fullX2)
  80. partX2 = fullX2;
  81. partY2 = pbox->y2;
  82. if (partY2 > fullY2)
  83. partY2 = fullY2;
  84. pbox++;
  85. if (partX1 < partX2 && partY1 < partY2)
  86. fbFill(pDrawable, pGC,
  87. partX1, partY1, partX2 - partX1, partY2 - partY1);
  88. }
  89. }
  90. }
  91. }