home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / mfb / mfbfillrct.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-25  |  5.1 KB  |  202 lines

  1. /* Combined Purdue/PurduePlus patches, level 2.0, 1/17/89 */
  2. /***********************************************************
  3. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  4. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  5.  
  6.                         All Rights Reserved
  7.  
  8. Permission to use, copy, modify, and distribute this software and its 
  9. documentation for any purpose and without fee is hereby granted, 
  10. provided that the above copyright notice appear in all copies and that
  11. both that copyright notice and this permission notice appear in 
  12. supporting documentation, and that the names of Digital or MIT not be
  13. used in advertising or publicity pertaining to distribution of the
  14. software without specific, written prior permission.  
  15.  
  16. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  17. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  18. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  19. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  21. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  22. SOFTWARE.
  23.  
  24. ******************************************************************/
  25. /* $XConsortium: mfbfillrct.c,v 5.8 91/05/25 19:00:50 rws Exp $ */
  26. #include "X.h"
  27. #include "Xprotostr.h"
  28. #include "pixmapstr.h"
  29. #include "gcstruct.h"
  30. #include "windowstr.h"
  31. #include "miscstruct.h"
  32. #include "regionstr.h"
  33. #include "scrnintstr.h"
  34.  
  35. #include "mfb.h"
  36. #include "maskbits.h"
  37.  
  38. #define MODEQ(a, b) ((a) %= (b))
  39. void mfbPaintOddSize();
  40.  
  41. /* 
  42.     filled rectangles.
  43.     translate the rectangles, clip them, and call the
  44. helper function in the GC.
  45. */
  46.  
  47. #define NUM_STACK_RECTS    1024
  48.  
  49. void
  50. mfbPolyFillRect(pDrawable, pGC, nrectFill, prectInit)
  51.     DrawablePtr pDrawable;
  52.     GCPtr    pGC;
  53.     int        nrectFill;     /* number of rectangles to fill */
  54.     xRectangle    *prectInit;      /* Pointer to first rectangle to fill */
  55. {
  56.     xRectangle        *prect;
  57.     RegionPtr        prgnClip;
  58.     register BoxPtr pbox;
  59.     register BoxPtr pboxClipped;
  60.     BoxPtr        pboxClippedBase;
  61.     BoxPtr        pextent;
  62.     BoxRec        stackRects[NUM_STACK_RECTS];
  63.     int            numRects;
  64.     int            n;
  65.     int            xorg, yorg;
  66.     mfbPrivGC    *priv;
  67.     int alu;
  68.     void (* pfn) ();
  69.     PixmapPtr ppix;
  70.  
  71.     if (!(pGC->planemask & 1))
  72.     return;
  73.  
  74.     priv = (mfbPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr;
  75.     alu = priv->ropFillArea;
  76.     pfn = priv->FillArea;
  77.     ppix = priv->pRotatedPixmap;
  78.     prgnClip = priv->pCompositeClip;
  79.  
  80.     prect = prectInit;
  81.     xorg = pDrawable->x;
  82.     yorg = pDrawable->y;
  83.     if (xorg || yorg)
  84.     {
  85.         prect = prectInit;
  86.     n = nrectFill;
  87.     Duff (n, prect->x += xorg; prect->y += yorg; prect++);
  88.     }
  89.  
  90.  
  91.     prect = prectInit;
  92.  
  93.     numRects = REGION_NUM_RECTS(prgnClip) * nrectFill;
  94.     if (numRects > NUM_STACK_RECTS)
  95.     {
  96.     pboxClippedBase = (BoxPtr)ALLOCATE_LOCAL(numRects * sizeof(BoxRec));
  97.     if (!pboxClippedBase)
  98.         return;
  99.     }
  100.     else
  101.     pboxClippedBase = stackRects;
  102.  
  103.     pboxClipped = pboxClippedBase;
  104.     
  105.     if (REGION_NUM_RECTS(prgnClip) == 1)
  106.     {
  107.     int x1, y1, x2, y2, bx2, by2;
  108.  
  109.     pextent = REGION_RECTS(prgnClip);
  110.     x1 = pextent->x1;
  111.     y1 = pextent->y1;
  112.     x2 = pextent->x2;
  113.     y2 = pextent->y2;
  114.         while (nrectFill--)
  115.         {
  116.         if ((pboxClipped->x1 = prect->x) < x1)
  117.         pboxClipped->x1 = x1;
  118.     
  119.         if ((pboxClipped->y1 = prect->y) < y1)
  120.         pboxClipped->y1 = y1;
  121.     
  122.         bx2 = (int) prect->x + (int) prect->width;
  123.         if (bx2 > x2)
  124.         bx2 = x2;
  125.         pboxClipped->x2 = bx2;
  126.     
  127.         by2 = (int) prect->y + (int) prect->height;
  128.         if (by2 > y2)
  129.         by2 = y2;
  130.         pboxClipped->y2 = by2;
  131.  
  132.         prect++;
  133.         if ((pboxClipped->x1 < pboxClipped->x2) &&
  134.         (pboxClipped->y1 < pboxClipped->y2))
  135.         {
  136.         pboxClipped++;
  137.         }
  138.         }
  139.     }
  140.     else
  141.     {
  142.     int x1, y1, x2, y2, bx2, by2;
  143.  
  144.     pextent = (*pGC->pScreen->RegionExtents)(prgnClip);
  145.     x1 = pextent->x1;
  146.     y1 = pextent->y1;
  147.     x2 = pextent->x2;
  148.     y2 = pextent->y2;
  149.         while (nrectFill--)
  150.         {
  151.         BoxRec box;
  152.     
  153.         if ((box.x1 = prect->x) < x1)
  154.         box.x1 = x1;
  155.     
  156.         if ((box.y1 = prect->y) < y1)
  157.         box.y1 = y1;
  158.     
  159.         bx2 = (int) prect->x + (int) prect->width;
  160.         if (bx2 > x2)
  161.         bx2 = x2;
  162.         box.x2 = bx2;
  163.     
  164.         by2 = (int) prect->y + (int) prect->height;
  165.         if (by2 > y2)
  166.         by2 = y2;
  167.         box.y2 = by2;
  168.     
  169.         prect++;
  170.     
  171.         if ((box.x1 >= box.x2) || (box.y1 >= box.y2))
  172.             continue;
  173.     
  174.         n = REGION_NUM_RECTS (prgnClip);
  175.         pbox = REGION_RECTS(prgnClip);
  176.     
  177.         /* clip the rectangle to each box in the clip region
  178.            this is logically equivalent to calling Intersect()
  179.         */
  180.         while(n--)
  181.         {
  182.         pboxClipped->x1 = max(box.x1, pbox->x1);
  183.         pboxClipped->y1 = max(box.y1, pbox->y1);
  184.         pboxClipped->x2 = min(box.x2, pbox->x2);
  185.         pboxClipped->y2 = min(box.y2, pbox->y2);
  186.         pbox++;
  187.  
  188.         /* see if clipping left anything */
  189.         if(pboxClipped->x1 < pboxClipped->x2 && 
  190.            pboxClipped->y1 < pboxClipped->y2)
  191.         {
  192.             pboxClipped++;
  193.         }
  194.         }
  195.         }
  196.     }
  197.     if (pboxClipped != pboxClippedBase)
  198.     (*pfn) (pDrawable,pboxClipped-pboxClippedBase, pboxClippedBase, alu, ppix);
  199.     if (pboxClippedBase != stackRects)
  200.         DEALLOCATE_LOCAL(pboxClippedBase);
  201. }
  202.