home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / cfb / cfbfillarc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-10  |  5.5 KB  |  243 lines

  1. /************************************************************
  2. Copyright 1989 by The Massachusetts Institute of Technology
  3.  
  4. Permission to use, copy, modify, and distribute this
  5. software and its documentation for any purpose and without
  6. fee is hereby granted, provided that the above copyright
  7. notice appear in all copies and that both that copyright
  8. notice and this permission notice appear in supporting
  9. documentation, and that the name of MIT not be used in
  10. advertising or publicity pertaining to distribution of the
  11. software without specific prior written permission.
  12. M.I.T. makes no representation about the suitability of
  13. this software for any purpose. It is provided "as is"
  14. without any express or implied warranty.
  15.  
  16. ********************************************************/
  17.  
  18. /* $XConsortium: cfbfillarc.c,v 5.12 91/04/10 11:41:49 keith Exp $ */
  19.  
  20. #include "X.h"
  21. #include "Xprotostr.h"
  22. #include "miscstruct.h"
  23. #include "gcstruct.h"
  24. #include "pixmapstr.h"
  25. #include "scrnintstr.h"
  26. #include "cfb.h"
  27. #include "cfbmskbits.h"
  28. #include "mifillarc.h"
  29. #include "cfbrrop.h"
  30.  
  31. extern void miPolyFillArc();
  32.  
  33. /* gcc 1.35 is stupid */
  34. #if defined(__GNUC__) && defined(mc68020)
  35. #define STUPID volatile
  36. #else
  37. #define STUPID
  38. #endif
  39.  
  40. static void
  41. RROP_NAME(cfbFillEllipseSolid) (pDraw, pGC, arc)
  42.     DrawablePtr pDraw;
  43.     GCPtr pGC;
  44.     xArc *arc;
  45. {
  46.     STUPID int x, y, e;
  47.     STUPID int yk, xk, ym, xm, dx, dy, xorg, yorg;
  48.     miFillArcRec info;
  49.     unsigned long *addrlt, *addrlb;
  50.     register unsigned long *addrl;
  51.     register int n;
  52.     int nlwidth;
  53.     RROP_DECLARE
  54.     register int xpos;
  55.     register int slw;
  56.     unsigned long startmask, endmask;
  57.     int    nlmiddle;
  58.  
  59.     cfbGetLongWidthAndPointer (pDraw, nlwidth, addrlt)
  60.  
  61.     RROP_FETCH_GC(pGC);
  62.     miFillArcSetup(arc, &info);
  63.     MIFILLARCSETUP();
  64.     xorg += pDraw->x;
  65.     yorg += pDraw->y;
  66.     addrlb = addrlt;
  67.     addrlt += nlwidth * (yorg - y);
  68.     addrlb += nlwidth * (yorg + y + dy);
  69.     while (y)
  70.     {
  71.     addrlt += nlwidth;
  72.     addrlb -= nlwidth;
  73.     MIFILLARCSTEP(slw);
  74.     if (!slw)
  75.         continue;
  76.     xpos = xorg - x;
  77.     addrl = addrlt + (xpos >> PWSH);
  78.     if (((xpos & PIM) + slw) <= PPW)
  79.     {
  80.         maskpartialbits(xpos, slw, startmask);
  81.         RROP_SOLID_MASK(addrl,startmask);
  82.         if (miFillArcLower(slw))
  83.         {
  84.         addrl = addrlb + (xpos >> PWSH);
  85.         RROP_SOLID_MASK(addrl, startmask);
  86.         }
  87.         continue;
  88.     }
  89.     maskbits(xpos, slw, startmask, endmask, nlmiddle);
  90.     if (startmask)
  91.     {
  92.         RROP_SOLID_MASK(addrl, startmask);
  93.         addrl++;
  94.     }
  95.     n = nlmiddle;
  96.     RROP_SPAN(addrl,n)
  97.  
  98.     if (endmask)
  99.         RROP_SOLID_MASK(addrl, endmask);
  100.     if (!miFillArcLower(slw))
  101.         continue;
  102.     addrl = addrlb + (xpos >> PWSH);
  103.     if (startmask)
  104.     {
  105.         RROP_SOLID_MASK(addrl, startmask);
  106.         addrl++;
  107.     }
  108.     n = nlmiddle;
  109.     RROP_SPAN(addrl, n);
  110.     if (endmask)
  111.         RROP_SOLID_MASK(addrl, endmask);
  112.     }
  113. }
  114.  
  115. #define FILLSPAN(xl,xr,addr) \
  116.     if (xr >= xl) \
  117.     { \
  118.     n = xr - xl + 1; \
  119.     addrl = addr + (xl >> PWSH); \
  120.     if (((xl & PIM) + n) <= PPW) \
  121.     { \
  122.         maskpartialbits(xl, n, startmask); \
  123.         RROP_SOLID_MASK(addrl, startmask); \
  124.     } \
  125.     else \
  126.     { \
  127.         maskbits(xl, n, startmask, endmask, n); \
  128.         if (startmask) \
  129.         { \
  130.         RROP_SOLID_MASK(addrl, startmask); \
  131.         addrl++; \
  132.         } \
  133.         while (n--) \
  134.         { \
  135.         RROP_SOLID(addrl); \
  136.         ++addrl; \
  137.         } \
  138.         if (endmask) \
  139.         RROP_SOLID_MASK(addrl, endmask); \
  140.     } \
  141.     }
  142.  
  143. #define FILLSLICESPANS(flip,addr) \
  144.     if (!flip) \
  145.     { \
  146.     FILLSPAN(xl, xr, addr); \
  147.     } \
  148.     else \
  149.     { \
  150.     xc = xorg - x; \
  151.     FILLSPAN(xc, xr, addr); \
  152.     xc += slw - 1; \
  153.     FILLSPAN(xl, xc, addr); \
  154.     }
  155.  
  156. static void
  157. RROP_NAME(cfbFillArcSliceSolid)(pDraw, pGC, arc)
  158.     DrawablePtr pDraw;
  159.     GCPtr pGC;
  160.     xArc *arc;
  161. {
  162.     int yk, xk, ym, xm, dx, dy, xorg, yorg, slw;
  163.     register int x, y, e;
  164.     miFillArcRec info;
  165.     miArcSliceRec slice;
  166.     int xl, xr, xc;
  167.     unsigned long *addrlt, *addrlb;
  168.     register unsigned long *addrl;
  169.     register int n;
  170.     int nlwidth;
  171.     RROP_DECLARE
  172.     unsigned long startmask, endmask;
  173.  
  174.     cfbGetLongWidthAndPointer (pDraw, nlwidth, addrlt)
  175.  
  176.     RROP_FETCH_GC(pGC);
  177.     miFillArcSetup(arc, &info);
  178.     miFillArcSliceSetup(arc, &slice, pGC);
  179.     MIFILLARCSETUP();
  180.     xorg += pDraw->x;
  181.     yorg += pDraw->y;
  182.     addrlb = addrlt;
  183.     addrlt += nlwidth * (yorg - y);
  184.     addrlb += nlwidth * (yorg + y + dy);
  185.     slice.edge1.x += pDraw->x;
  186.     slice.edge2.x += pDraw->x;
  187.     while (y > 0)
  188.     {
  189.     addrlt += nlwidth;
  190.     addrlb -= nlwidth;
  191.     MIFILLARCSTEP(slw);
  192.     MIARCSLICESTEP(slice.edge1);
  193.     MIARCSLICESTEP(slice.edge2);
  194.     if (miFillSliceUpper(slice))
  195.     {
  196.         MIARCSLICEUPPER(xl, xr, slice, slw);
  197.         FILLSLICESPANS(slice.flip_top, addrlt);
  198.     }
  199.     if (miFillSliceLower(slice))
  200.     {
  201.         MIARCSLICELOWER(xl, xr, slice, slw);
  202.         FILLSLICESPANS(slice.flip_bot, addrlb);
  203.     }
  204.     }
  205. }
  206.  
  207. void
  208. RROP_NAME(cfbPolyFillArcSolid) (pDraw, pGC, narcs, parcs)
  209.     DrawablePtr    pDraw;
  210.     GCPtr    pGC;
  211.     int        narcs;
  212.     xArc    *parcs;
  213. {
  214.     register xArc *arc;
  215.     register int i;
  216.     BoxRec box;
  217.     RegionPtr cclip;
  218.  
  219.     cclip = ((cfbPrivGC *)(pGC->devPrivates[cfbGCPrivateIndex].ptr))->pCompositeClip;
  220.     for (arc = parcs, i = narcs; --i >= 0; arc++)
  221.     {
  222.     if (miFillArcEmpty(arc))
  223.         continue;
  224.     if (miCanFillArc(arc))
  225.     {
  226.         box.x1 = arc->x + pDraw->x;
  227.         box.y1 = arc->y + pDraw->y;
  228.         box.x2 = box.x1 + (int)arc->width + 1;
  229.         box.y2 = box.y1 + (int)arc->height + 1;
  230.         if ((*pDraw->pScreen->RectIn)(cclip, &box) == rgnIN)
  231.         {
  232.         if ((arc->angle2 >= FULLCIRCLE) ||
  233.             (arc->angle2 <= -FULLCIRCLE))
  234.             RROP_NAME(cfbFillEllipseSolid)(pDraw, pGC, arc);
  235.         else
  236.             RROP_NAME(cfbFillArcSliceSolid)(pDraw, pGC, arc);
  237.         continue;
  238.         }
  239.     }
  240.     miPolyFillArc(pDraw, pGC, 1, arc);
  241.     }
  242. }
  243.