home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / mfb / mfbpntarea.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-11-24  |  7.6 KB  |  302 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: mfbpntarea.c,v 5.2 89/11/24 18:06:43 rws Exp $ */
  26. #include "X.h"
  27.  
  28. #include "windowstr.h"
  29. #include "regionstr.h"
  30. #include "pixmapstr.h"
  31. #include "scrnintstr.h"
  32.  
  33. #include "mfb.h"
  34. #include "maskbits.h"
  35.  
  36. /* 
  37.    the solid fillers are called for rectangles and window backgrounds.
  38.    the boxes are already translated.
  39.    maybe this should always take a pixmap instead of a drawable?
  40.  
  41.    NOTE:
  42.    iy = ++iy < tileHeight ? iy : 0
  43. is equivalent to iy%= tileheight, and saves a division.
  44. */
  45.  
  46. /*
  47.     MFBSOLIDFILLAREA    OPEQ    EQWHOLEOWRD
  48.     mfbSolidWhiteArea    |=    = ~0
  49.     mfbSolidBlackArea    &=~    = 0
  50.     mfbSolidInvertArea    ^=    ^= ~0
  51.  
  52. EQWHOLEWORD is used to write whole longwords.  it could use OPEQ,
  53. but *p++ |= ~0 on at least two compilers generates much
  54. worse code than *p++ = ~0.  similarly for *p++ &= ~~0
  55. and *p++ = 0.
  56.  
  57. */
  58.  
  59. /*ARGSUSED*/
  60. void
  61. MFBSOLIDFILLAREA(pDraw, nbox, pbox, alu, nop)
  62.     DrawablePtr pDraw;
  63.     int nbox;
  64.     BoxPtr pbox;
  65.     int alu;
  66.     PixmapPtr nop;
  67. {
  68.     int nlwidth;    /* width in longwords of the drawable */
  69.     int w;        /* width of current box */
  70.     register int h;    /* height of current box */
  71.     register unsigned int *p;    /* pointer to bits we're writing */
  72.     register int nlw;    /* loop version of nlwMiddle */
  73.     register int startmask;
  74.     register int endmask;/* masks for reggedy bits at either end of line */
  75.     register int nlwExtra;    
  76.                 /* to get from right of box to left of next span */
  77.     int nlwMiddle;    /* number of longwords between sides of boxes */
  78.     unsigned int *pbits;    /* pointer to start of drawable */
  79.  
  80.     if (pDraw->type == DRAWABLE_WINDOW)
  81.     {
  82.     pbits = (unsigned int *)
  83.         (((PixmapPtr)(pDraw->pScreen->devPrivate))->devPrivate.ptr);
  84.     nlwidth = (int)
  85.         (((PixmapPtr)(pDraw->pScreen->devPrivate))->devKind) >> 2;
  86.     }
  87.     else
  88.     {
  89.     pbits = (unsigned int *)(((PixmapPtr)pDraw)->devPrivate.ptr);
  90.     nlwidth = (int)(((PixmapPtr)pDraw)->devKind) >> 2;
  91.     }
  92.  
  93.  
  94.     while (nbox--)
  95.     {
  96.     w = pbox->x2 - pbox->x1;
  97.     h = pbox->y2 - pbox->y1;
  98.     p = pbits + (pbox->y1 * nlwidth) + (pbox->x1 >> 5);
  99.  
  100.     if ( ((pbox->x1 & 0x1f) + w) < 32)
  101.     {
  102.         maskpartialbits(pbox->x1, w, startmask);
  103.         nlwExtra = nlwidth;
  104.         Duff(h, *p OPEQ startmask; p += nlwExtra);
  105.     }
  106.     else
  107.     {
  108.         maskbits(pbox->x1, w, startmask, endmask, nlwMiddle);
  109.         nlwExtra = nlwidth - nlwMiddle;
  110.  
  111.         if (startmask && endmask)
  112.         {
  113.         nlwExtra -= 1;
  114.         while (h--)
  115.         {
  116.             nlw = nlwMiddle;
  117.             *p OPEQ startmask;
  118.             p++;
  119.             Duff(nlw, *p++ EQWHOLEWORD);
  120.             *p OPEQ endmask;
  121.             p += nlwExtra;
  122.         }
  123.         }
  124.         else if (startmask && !endmask)
  125.         {
  126.         nlwExtra -= 1;
  127.         while (h--)
  128.         {
  129.             nlw = nlwMiddle;
  130.             *p OPEQ startmask;
  131.             p++;
  132.             Duff(nlw, *p++ EQWHOLEWORD);
  133.             p += nlwExtra;
  134.         }
  135.         }
  136.         else if (!startmask && endmask)
  137.         {
  138.         while (h--)
  139.         {
  140.             nlw = nlwMiddle;
  141.             Duff(nlw, *p++ EQWHOLEWORD);
  142.             *p OPEQ endmask;
  143.             p += nlwExtra;
  144.         }
  145.         }
  146.         else /* no ragged bits at either end */
  147.         {
  148.         while (h--)
  149.         {
  150.             nlw = nlwMiddle;
  151.             Duff(nlw, *p++ EQWHOLEWORD);
  152.             p += nlwExtra;
  153.         }
  154.         }
  155.     }
  156.         pbox++;
  157.     }
  158. }
  159.  
  160.  
  161.  
  162. /* stipple a list of boxes
  163.  
  164. you can use the reduced rasterop for stipples.  if rrop is
  165. black, AND the destination with (not stipple pattern).  if rrop is
  166. white OR the destination with the stipple pattern.  if rrop is invert,
  167. XOR the destination with the stipple pattern.
  168.  
  169.     MFBSTIPPLEFILLAREA    OPEQ
  170.     mfbStippleWhiteArea    |=
  171.     mfbStippleBlackArea    &=~
  172.     mfbStippleInveryArea    ^=
  173. */
  174.  
  175. /*ARGSUSED*/
  176. void
  177. MFBSTIPPLEFILLAREA(pDraw, nbox, pbox, alu, pstipple)
  178.     DrawablePtr pDraw;
  179.     int nbox;
  180.     BoxPtr pbox;
  181.     int alu;
  182.     PixmapPtr pstipple;
  183. {
  184.     register unsigned int *psrc;
  185.             /* pointer to bits in tile, if needed */
  186.     int tileHeight;    /* height of the tile */
  187.     register unsigned int srcpix;    
  188.  
  189.     int nlwidth;    /* width in longwords of the drawable */
  190.     int w;        /* width of current box */
  191.     register int nlw;    /* loop version of nlwMiddle */
  192.     register unsigned int *p;    /* pointer to bits we're writing */
  193.     register int h;    /* height of current box */
  194.     int startmask;
  195.     int endmask;    /* masks for reggedy bits at either end of line */
  196.     int nlwMiddle;    /* number of longwords between sides of boxes */
  197.     int nlwExtra;    /* to get from right of box to left of next span */
  198.     
  199.     register int iy;    /* index of current scanline in tile */
  200.  
  201.  
  202.     unsigned int *pbits;    /* pointer to start of drawable */
  203.  
  204.     if (pDraw->type == DRAWABLE_WINDOW)
  205.     {
  206.     pbits = (unsigned int *)
  207.         (((PixmapPtr)(pDraw->pScreen->devPrivate))->devPrivate.ptr);
  208.     nlwidth = (int)
  209.         (((PixmapPtr)(pDraw->pScreen->devPrivate))->devKind) >> 2;
  210.     }
  211.     else
  212.     {
  213.     pbits = (unsigned int *)(((PixmapPtr)pDraw)->devPrivate.ptr);
  214.     nlwidth = (int)(((PixmapPtr)pDraw)->devKind) >> 2;
  215.     }
  216.  
  217.     tileHeight = pstipple->drawable.height;
  218.     psrc = (unsigned int *)(pstipple->devPrivate.ptr);
  219.  
  220.     while (nbox--)
  221.     {
  222.     w = pbox->x2 - pbox->x1;
  223.     h = pbox->y2 - pbox->y1;
  224.     iy = pbox->y1 % tileHeight;
  225.     p = pbits + (pbox->y1 * nlwidth) + (pbox->x1 >> 5);
  226.  
  227.     if ( ((pbox->x1 & 0x1f) + w) < 32)
  228.     {
  229.         maskpartialbits(pbox->x1, w, startmask);
  230.         nlwExtra = nlwidth;
  231.         while (h--)
  232.         {
  233.         srcpix = psrc[iy];
  234.         iy = ++iy < tileHeight ? iy : 0;
  235.         *p OPEQ (srcpix & startmask);
  236.         p += nlwExtra;
  237.         }
  238.     }
  239.     else
  240.     {
  241.         maskbits(pbox->x1, w, startmask, endmask, nlwMiddle);
  242.         nlwExtra = nlwidth - nlwMiddle;
  243.  
  244.         if (startmask && endmask)
  245.         {
  246.         nlwExtra -= 1;
  247.         while (h--)
  248.         {
  249.             srcpix = psrc[iy];
  250.             iy = ++iy < tileHeight ? iy : 0;
  251.             nlw = nlwMiddle;
  252.             *p OPEQ (srcpix & startmask);
  253.             p++;
  254.             Duff (nlw, *p++ OPEQ srcpix);
  255.             *p OPEQ (srcpix & endmask);
  256.             p += nlwExtra;
  257.         }
  258.         }
  259.         else if (startmask && !endmask)
  260.         {
  261.         nlwExtra -= 1;
  262.         while (h--)
  263.         {
  264.             srcpix = psrc[iy];
  265.             iy = ++iy < tileHeight ? iy : 0;
  266.             nlw = nlwMiddle;
  267.             *p OPEQ (srcpix & startmask);
  268.             p++;
  269.             Duff(nlw, *p++ OPEQ srcpix);
  270.             p += nlwExtra;
  271.         }
  272.         }
  273.         else if (!startmask && endmask)
  274.         {
  275.         while (h--)
  276.         {
  277.             srcpix = psrc[iy];
  278.             iy = ++iy < tileHeight ? iy : 0;
  279.             nlw = nlwMiddle;
  280.             Duff(nlw, *p++ OPEQ srcpix);
  281.             *p OPEQ (srcpix & endmask);
  282.             p += nlwExtra;
  283.         }
  284.         }
  285.         else /* no ragged bits at either end */
  286.         {
  287.         while (h--)
  288.         {
  289.             srcpix = psrc[iy];
  290.             iy = ++iy < tileHeight ? iy : 0;
  291.             nlw = nlwMiddle;
  292.             Duff(nlw, *p++ OPEQ srcpix);
  293.             p += nlwExtra;
  294.         }
  295.         }
  296.     }
  297.         pbox++;
  298.     }
  299. }
  300.  
  301.  
  302.