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

  1. /*
  2.  * Fill 32 bit stippled rectangles for 8 bit frame buffers
  3.  */
  4. /*
  5. Copyright 1989 by the Massachusetts Institute of Technology
  6.  
  7. Permission to use, copy, modify, and distribute this software and its
  8. documentation for any purpose and without fee is hereby granted,
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in
  11. supporting documentation, and that the name of M.I.T. not be used in
  12. advertising or publicity pertaining to distribution of the software
  13. without specific, written prior permission.  M.I.T. makes no
  14. representations about the suitability of this software for any
  15. purpose.  It is provided "as is" without express or implied warranty.
  16.  
  17. Author: Keith Packard, MIT X Consortium
  18.  
  19. */
  20.  
  21. /* $XConsortium: cfbrctstp8.c,v 1.13 91/04/10 11:41:33 keith Exp $ */
  22.  
  23. #include "X.h"
  24. #include "Xmd.h"
  25. #include "servermd.h"
  26. #include "gcstruct.h"
  27. #include "window.h"
  28. #include "pixmapstr.h"
  29. #include "scrnintstr.h"
  30. #include "windowstr.h"
  31.  
  32. #include "cfb.h"
  33. #include "cfbmskbits.h"
  34. #include "cfb8bit.h"
  35.  
  36. #if (PPW == 4)
  37.  
  38.  
  39. void
  40. cfb8FillRectOpaqueStippled32 (pDrawable, pGC, nBox, pBox)
  41.     DrawablePtr        pDrawable;
  42.     GCPtr        pGC;
  43.     int            nBox;    /* number of boxes to fill */
  44.     register BoxPtr pBox;    /* pointer to list of boxes to fill */
  45. {
  46.     unsigned long   *src;
  47.     int stippleHeight;
  48.  
  49.     int nlwDst;        /* width in longwords of the dest pixmap */
  50.     int w;        /* width of current box */
  51.     register int h;    /* height of current box */
  52.     unsigned long startmask;
  53.     unsigned long endmask;    /* masks for reggedy bits at either end of line */
  54.     int nlwMiddle;    /* number of longwords between sides of boxes */
  55.     register int nlw;            /* loop version of nlwMiddle */
  56.     unsigned long *dstLine;
  57.     register unsigned long *dst;    /* pointer to bits we're writing */
  58.     unsigned long *dstTmp;
  59.     int y;                /* current scan line */
  60.  
  61.     unsigned long *pbits;/* pointer to start of pixmap */
  62.     register unsigned long bits;    /* bits from stipple */
  63.     int    rot, lastStop, i;
  64.     register unsigned long  xor, and;
  65.     cfbPrivGCPtr        devPriv;
  66.     PixmapPtr            stipple;
  67.     int        wEnd;
  68.  
  69.     devPriv = ((cfbPrivGCPtr) pGC->devPrivates[cfbGCPrivateIndex].ptr);
  70.     stipple = devPriv->pRotatedPixmap;
  71.  
  72.     cfb8CheckOpaqueStipple(pGC->alu, pGC->fgPixel, pGC->bgPixel, pGC->planemask);
  73.  
  74.     stippleHeight = stipple->drawable.height;
  75.     src = (unsigned long *)stipple->devPrivate.ptr;
  76.  
  77.     cfbGetLongWidthAndPointer (pDrawable, nlwDst, pbits)
  78.  
  79.     while (nBox--)
  80.     {
  81.     w = pBox->x2 - pBox->x1;
  82.     h = pBox->y2 - pBox->y1;
  83.     y = pBox->y1;
  84.     dstLine = pbits + (pBox->y1 * nlwDst) + ((pBox->x1 & ~3) >> PWSH);
  85.     if (((pBox->x1 & PIM) + w) <= PPW)
  86.     {
  87.         maskpartialbits(pBox->x1, w, startmask);
  88.         nlwMiddle = 0;
  89.         endmask = 0;
  90.     }
  91.     else
  92.     {
  93.         maskbits (pBox->x1, w, startmask, endmask, nlwMiddle);
  94.     }
  95.     rot = (pBox->x1 & (31 & ~3));
  96.     pBox++;
  97.     y = y % stippleHeight;
  98.     if (cfb8StippleRRop == GXcopy)
  99.     {
  100.         if (w < 64)
  101.         {
  102.             while (h--)
  103.             {
  104.                 bits = src[y];
  105.                 y++;
  106.                 if (y == stippleHeight)
  107.                 y = 0;
  108.                 if (rot)
  109.                 RotBitsLeft(bits,rot);
  110.             dst = dstLine;
  111.                 dstLine += nlwDst;
  112.                 if (startmask)
  113.                 {
  114.                 *dst = *dst & ~startmask |
  115.                 GetFourPixels (bits) & startmask;
  116.                 dst++;
  117.                 RotBitsLeft (bits, 4);
  118.                 }
  119.             nlw = nlwMiddle;
  120.                 while (nlw--)
  121.                 {
  122.             *dst++ = GetFourPixels(bits);
  123.                 RotBitsLeft (bits, 4);
  124.                 }
  125.                 if (endmask)
  126.                 {
  127.             *dst = *dst & ~endmask |
  128.                   GetFourPixels (bits) & endmask;
  129.                 }
  130.             }
  131.         }
  132.         else
  133.         {
  134.         wEnd = 7 - (nlwMiddle & 7);
  135.         nlwMiddle = (nlwMiddle >> 3) + 1;
  136.             while (h--)
  137.             {
  138.             bits = src[y];
  139.             y++;
  140.             if (y == stippleHeight)
  141.             y = 0;
  142.                 if (rot != 0)
  143.             RotBitsLeft (bits, rot);
  144.                 dstTmp = dstLine;
  145.                 dstLine += nlwDst;
  146.             if (startmask)
  147.             {
  148.             *dstTmp = *dstTmp & ~startmask |
  149.                    GetFourPixels (bits) & startmask;
  150.             dstTmp++;
  151.             RotBitsLeft (bits, 4);
  152.             }
  153.             w = 7 - wEnd;
  154.             while (w--)
  155.             {
  156.             nlw = nlwMiddle;
  157.             dst = dstTmp;
  158.             dstTmp++;
  159.             xor = GetFourPixels (bits);
  160.             while (nlw--)
  161.             {
  162.                 *dst = xor;
  163.                 dst += 8;
  164.             }
  165.             NextFourBits (bits);
  166.             }
  167.             nlwMiddle--;
  168.             w = wEnd + 1;
  169.             if (endmask)
  170.             {
  171.             dst = dstTmp + (nlwMiddle << 3);
  172.             *dst = (*dst & ~endmask) |
  173.                    GetFourPixels (bits) & endmask;
  174.             }
  175.             while (w--)
  176.             {
  177.             nlw = nlwMiddle;
  178.             dst = dstTmp;
  179.             dstTmp++;
  180.             xor = GetFourPixels (bits);
  181.             while (nlw--)
  182.             {
  183.                 *dst = xor;
  184.                 dst += 8;
  185.             }
  186.             NextFourBits (bits);
  187.             }
  188.             nlwMiddle++;
  189.         }
  190.         }
  191.     }
  192.     else
  193.     {
  194.         while (h--)
  195.         {
  196.             bits = src[y];
  197.             y++;
  198.             if (y == stippleHeight)
  199.             y = 0;
  200.             if (rot)
  201.             RotBitsLeft(bits,rot);
  202.         dst = dstLine;
  203.             dstLine += nlwDst;
  204.             if (startmask)
  205.             {
  206.             xor = GetFourBits(bits);
  207.             *dst = MaskRRopPixels(*dst, xor, startmask);
  208.             dst++;
  209.             RotBitsLeft (bits, 4);
  210.             }
  211.         nlw = nlwMiddle;
  212.             while (nlw--)
  213.             {
  214.             RRopFourBits(dst, GetFourBits(bits));
  215.             dst++;
  216.             RotBitsLeft (bits, 4);
  217.             }
  218.             if (endmask)
  219.             {
  220.             xor = GetFourBits(bits);
  221.             *dst = MaskRRopPixels(*dst, xor, endmask);
  222.             }
  223.         }
  224.     }
  225.     }
  226. }
  227.  
  228.  
  229. cfb8FillRectTransparentStippled32 (pDrawable, pGC, nBox, pBox)
  230.     DrawablePtr        pDrawable;
  231.     GCPtr        pGC;
  232.     int            nBox;    /* number of boxes to fill */
  233.     BoxPtr         pBox;    /* pointer to list of boxes to fill */
  234. {
  235.     int            x, y, w, h;
  236.     int            nlwMiddle, nlwDst, nlwTmp;
  237.     unsigned long   startmask, endmask;
  238.     register unsigned long   *dst;
  239.     unsigned long   *dstLine, *pbits, *dstTmp;
  240.     unsigned long   *src;
  241.     register unsigned long   xor;
  242.     register unsigned long   bits, mask;
  243.     int            rot;
  244.     int            wEnd;
  245.     cfbPrivGCPtr    devPriv;
  246.     PixmapPtr        stipple;
  247.     int            stippleHeight;
  248.     register int    nlw;
  249.     
  250.     devPriv = ((cfbPrivGCPtr) pGC->devPrivates[cfbGCPrivateIndex].ptr);
  251.     stipple = devPriv->pRotatedPixmap;
  252.     src = (unsigned long *)stipple->devPrivate.ptr;
  253.     stippleHeight = stipple->drawable.height;
  254.  
  255.     cfb8CheckStipple (pGC->alu, pGC->fgPixel, pGC->planemask);
  256.  
  257.     cfbGetLongWidthAndPointer (pDrawable, nlwDst, pbits)
  258.  
  259.     while (nBox--)
  260.     {
  261.     x = pBox->x1;
  262.         w = pBox->x2 - x;
  263.     if (((x & PIM) + w) <= PPW)
  264.     {
  265.         maskpartialbits(x, w, startmask);
  266.         endmask = 0;
  267.         nlwMiddle = 0;
  268.     }
  269.     else
  270.     {
  271.         maskbits (x, w, startmask, endmask, nlwMiddle);
  272.     }
  273.     rot = (x & (31 & ~3));
  274.         y = pBox->y1;
  275.         dstLine = pbits + (y * nlwDst) + (x >> PWSH);
  276.         h = pBox->y2 - y;
  277.     pBox++;
  278.     y %= stippleHeight;
  279.     if (cfb8StippleRRop == GXcopy)
  280.     {
  281.         xor = devPriv->xor;
  282.         if (w < 64)
  283.         {
  284.             while (h--)
  285.             {
  286.             bits = src[y];
  287.             y++;
  288.             if (y == stippleHeight)
  289.             y = 0;
  290.                 if (rot != 0)
  291.             RotBitsLeft (bits, rot);
  292.                 dst = dstLine;
  293.                 dstLine += nlwDst;
  294.                 if (startmask)
  295.                 {
  296.                 mask = cfb8PixelMasks[GetFourBits(bits)];
  297.                 *dst = (*dst & ~(mask & startmask)) |
  298.                           (xor & (mask & startmask));
  299.                 dst++;
  300.                 RotBitsLeft (bits, 4);
  301.                 }
  302.             nlw = nlwMiddle;
  303.                 while (nlw--)
  304.                 {
  305.                 WriteFourBits (dst,xor,GetFourBits(bits))
  306.                 dst++;
  307.                 RotBitsLeft (bits, 4);
  308.                 }
  309.                 if (endmask)
  310.                 {
  311.                 mask = cfb8PixelMasks[GetFourBits(bits)];
  312.                 *dst = (*dst & ~(mask & endmask)) |
  313.                           (xor & (mask & endmask));
  314.                 }
  315.             }
  316.         }
  317.         else
  318.         {
  319.         wEnd = 7 - (nlwMiddle & 7);
  320.         nlwMiddle = (nlwMiddle >> 3) + 1;
  321.             while (h--)
  322.             {
  323.             bits = src[y];
  324.             y++;
  325.             if (y == stippleHeight)
  326.             y = 0;
  327.                 if (rot != 0)
  328.             RotBitsLeft (bits, rot);
  329.                 dstTmp = dstLine;
  330.                 dstLine += nlwDst;
  331.             if (startmask)
  332.             {
  333.                 mask = cfb8PixelMasks[GetFourBits(bits)];
  334.                 *dstTmp = (*dstTmp & ~(mask & startmask)) |
  335.                           (xor & (mask & startmask));
  336.                 dstTmp++;
  337.                 RotBitsLeft (bits, 4);
  338.             }
  339.             w = 7 - wEnd;
  340.             while (w--)
  341.             {
  342.             nlw = nlwMiddle;
  343.             dst = dstTmp;
  344.             dstTmp++;
  345. #if defined(__GNUC__) && defined(mc68020)
  346.             mask = cfb8PixelMasks[GetFourBits(bits)];
  347.             xor = xor & mask;
  348.             mask = ~mask;
  349.             while (nlw--)
  350.             {
  351.                 *dst = (*dst & mask) | xor;
  352.                 dst += 8;
  353.             }
  354.             xor = devPriv->xor;
  355. #else
  356. #define SwitchBitsLoop(body) \
  357.     while (nlw--)    \
  358.     {        \
  359.         body    \
  360.         dst += 8;    \
  361.     }
  362.             SwitchFourBits(dst, xor, GetFourBits(bits));
  363. #undef SwitchBitsLoop
  364. #endif
  365.             NextFourBits (bits);
  366.             }
  367.             nlwMiddle--;
  368.             w = wEnd + 1;
  369.             if (endmask)
  370.             {
  371.             mask = cfb8PixelMasks[GetFourBits(bits)];
  372.             dst = dstTmp + (nlwMiddle << 3);
  373.             *dst = (*dst & ~(mask & endmask)) |
  374.                    (xor &  (mask & endmask));
  375.             }
  376.             while (w--)
  377.             {
  378.             nlw = nlwMiddle;
  379.             dst = dstTmp;
  380.             dstTmp++;
  381. #if defined(__GNUC__) && defined(mc68020)
  382.             mask = cfb8PixelMasks[GetFourBits(bits)];
  383.             xor = xor & mask;
  384.             mask = ~mask;
  385.             while (nlw--)
  386.             {
  387.                 *dst = (*dst & mask) | xor;
  388.                 dst += 8;
  389.             }
  390.             xor = devPriv->xor;
  391. #else
  392. #define SwitchBitsLoop(body) \
  393.     while (nlw--)    \
  394.     {        \
  395.         body    \
  396.         dst += 8;    \
  397.     }
  398.             SwitchFourBits(dst, xor, GetFourBits(bits));
  399. #undef SwitchBitsLoop
  400. #endif
  401.             NextFourBits (bits);
  402.             }
  403.             nlwMiddle++;
  404.         }
  405.         }
  406.     }
  407.     else
  408.     {
  409.         while (h--)
  410.         {
  411.         bits = src[y];
  412.         y++;
  413.         if (y == stippleHeight)
  414.             y = 0;
  415.             if (rot != 0)
  416.             RotBitsLeft (bits, rot);
  417.             dst = dstLine;
  418.             dstLine += nlwDst;
  419.             if (startmask)
  420.             {
  421.             xor = GetFourBits(bits);
  422.             *dst = MaskRRopPixels(*dst, xor, startmask);
  423.             dst++;
  424.             RotBitsLeft (bits, 4);
  425.             }
  426.         nlw = nlwMiddle;
  427.             while (nlw--)
  428.             {
  429.             RRopFourBits(dst, GetFourBits(bits));
  430.             dst++;
  431.             RotBitsLeft (bits, 4);
  432.             }
  433.             if (endmask)
  434.             {
  435.             xor = GetFourBits(bits);
  436.             *dst = MaskRRopPixels(*dst, xor, endmask);
  437.             }
  438.         }
  439.     }
  440.     }
  441. }
  442.  
  443.  
  444. void
  445. cfb8FillRectStippledUnnatural (pDrawable, pGC, nBox, pBox)
  446.     DrawablePtr        pDrawable;
  447.     GCPtr        pGC;
  448.     int            nBox;
  449.     register BoxPtr pBox;
  450. {
  451.     unsigned long   *pdstBase;    /* pointer to start of bitmap */
  452.     unsigned long   *pdstLine;    /* current destination line */
  453.     int            nlwDst;    /* width in longwords of bitmap */
  454.     PixmapPtr        pStipple;    /* pointer to stipple we want to fill with */
  455.     int            nlwMiddle;
  456.     register int    nlw;
  457.     int            x, y, w, h, xrem, xSrc, ySrc;
  458.     int            stwidth, stippleWidth;
  459.     int            stippleHeight;
  460.     register unsigned long  bits, inputBits;
  461.     register int    partBitsLeft;
  462.     int            nextPartBits;
  463.     int            bitsLeft, bitsWhole;
  464.     register unsigned long    *pdst;    /* pointer to current word in bitmap */
  465.     unsigned long   *srcTemp, *srcStart;
  466.     unsigned long   *psrcBase;
  467.     unsigned long   startmask, endmask;
  468.  
  469.     if (pGC->fillStyle == FillStippled)
  470.     cfb8CheckStipple (pGC->alu, pGC->fgPixel, pGC->planemask);
  471.     else
  472.     cfb8CheckOpaqueStipple (pGC->alu, pGC->fgPixel, pGC->bgPixel, pGC->planemask);
  473.  
  474.     if (cfb8StippleRRop == GXnoop)
  475.     return;
  476.  
  477.     /*
  478.      *  OK,  so what's going on here?  We have two Drawables:
  479.      *
  480.      *  The Stipple:
  481.      *        Depth = 1
  482.      *        Width = stippleWidth
  483.      *        Words per scanline = stwidth
  484.      *        Pointer to pixels = pStipple->devPrivate.ptr
  485.      */
  486.  
  487.     pStipple = pGC->stipple;
  488.  
  489.     stwidth = pStipple->devKind >> 2;
  490.     stippleWidth = pStipple->drawable.width;
  491.     stippleHeight = pStipple->drawable.height;
  492.     psrcBase = (unsigned long *) pStipple->devPrivate.ptr;
  493.  
  494.     /*
  495.      *    The Target:
  496.      *        Depth = PSZ
  497.      *        Width = determined from *pwidth
  498.      *        Words per scanline = nlwDst
  499.      *        Pointer to pixels = addrlBase
  500.      */
  501.  
  502.     xSrc = pDrawable->x;
  503.     ySrc = pDrawable->y;
  504.  
  505.     cfbGetLongWidthAndPointer (pDrawable, nlwDst, pdstBase)
  506.  
  507.     /* this replaces rotating the stipple. Instead we just adjust the offset
  508.      * at which we start grabbing bits from the stipple.
  509.      * Ensure that ppt->x - xSrc >= 0 and ppt->y - ySrc >= 0,
  510.      * so that iline and xrem always stay within the stipple bounds.
  511.      */
  512.  
  513.     xSrc += (pGC->patOrg.x % stippleWidth) - stippleWidth;
  514.     ySrc += (pGC->patOrg.y % stippleHeight) - stippleHeight;
  515.  
  516.     bitsWhole = stippleWidth;
  517.  
  518.     while (nBox--)
  519.     {
  520.     x = pBox->x1;
  521.     y = pBox->y1;
  522.     w = pBox->x2 - x;
  523.     h = pBox->y2 - y;
  524.     pBox++;
  525.     pdstLine = pdstBase + y * nlwDst + (x >> PWSH);
  526.     y = (y - ySrc) % stippleHeight;
  527.     srcStart = psrcBase + y * stwidth;
  528.     xrem = ((x & ~3) - xSrc) % stippleWidth;
  529.     if (((x & PIM) + w) < PPW)
  530.     {
  531.         maskpartialbits (x, w, startmask);
  532.         nlwMiddle = 0;
  533.         endmask = 0;
  534.     }
  535.     else
  536.     {
  537.         maskbits (x, w, startmask, endmask, nlwMiddle);
  538.     }
  539.     while (h--)
  540.     {
  541.             srcTemp = srcStart + (xrem >> 5);
  542.             bitsLeft = stippleWidth - (xrem & ~0x1f);
  543.         NextUnnaturalStippleWord
  544.         NextSomeBits (inputBits, (xrem & 0x1f));
  545.         partBitsLeft -= (xrem & 0x1f);
  546.         NextUnnaturalStippleBits
  547.         nlw = nlwMiddle;
  548.         pdst = pdstLine;
  549.         if (startmask)
  550.         {
  551.         *pdst = MaskRRopPixels(*pdst,bits,startmask);
  552.         pdst++;
  553.         NextUnnaturalStippleBits
  554.         }
  555.         while (nlw--)
  556.         {
  557.         *pdst = RRopPixels(*pdst,bits);
  558.         pdst++;
  559.         NextUnnaturalStippleBits
  560.         }
  561.         if (endmask)
  562.         *pdst = MaskRRopPixels(*pdst,bits,endmask);
  563.         pdstLine += nlwDst;
  564.         y++;
  565.         srcStart += stwidth;
  566.         if (y == stippleHeight)
  567.         {
  568.         y = 0;
  569.         srcStart = psrcBase;
  570.         }
  571.     }
  572.     }
  573. }
  574.  
  575. #endif
  576.