home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / mfb / mfbsetsp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-13  |  7.1 KB  |  266 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: mfbsetsp.c,v 5.3 89/09/13 18:58:28 rws Exp $ */
  26.  
  27. #include "X.h"
  28. #include "Xmd.h"
  29.  
  30. #include "misc.h"
  31. #include "regionstr.h"
  32. #include "gcstruct.h"
  33. #include "windowstr.h"
  34. #include "pixmapstr.h"
  35. #include "scrnintstr.h"
  36.  
  37. #include "mfb.h"
  38. #include "maskbits.h"
  39.  
  40. #include "servermd.h"
  41.  
  42.  
  43. /* mfbSetScanline -- copies the bits from psrc to the drawable starting at
  44.  * (xStart, y) and continuing to (xEnd, y).  xOrigin tells us where psrc 
  45.  * starts on the scanline. (I.e., if this scanline passes through multiple
  46.  * boxes, we may not want to start grabbing bits at psrc but at some offset
  47.  * further on.) 
  48.  */
  49. mfbSetScanline(y, xOrigin, xStart, xEnd, psrc, alu, pdstBase, widthDst)
  50.     int            y;
  51.     int            xOrigin;    /* where this scanline starts */
  52.     int            xStart;        /* first bit to use from scanline */
  53.     int            xEnd;        /* last bit to use from scanline + 1 */
  54.     register int    *psrc;
  55.     register int    alu;        /* raster op */
  56.     int            *pdstBase;    /* start of the drawable */
  57.     int            widthDst;    /* width of drawable in words */
  58. {
  59.     int            w;        /* width of scanline in bits */
  60.     register int    *pdst;        /* where to put the bits */
  61.     register int    tmpSrc;        /* scratch buffer to collect bits in */
  62.     int            dstBit;        /* offset in bits from beginning of 
  63.                      * word */
  64.     register int    nstart;     /* number of bits from first partial */
  65.     register int    nend;         /* " " last partial word */
  66.     int        offSrc;
  67.     int        startmask, endmask, nlMiddle, nl;
  68.  
  69.     pdst = pdstBase + (y * widthDst) + (xStart >> 5); 
  70.     psrc += (xStart - xOrigin) >> 5;
  71.     offSrc = (xStart - xOrigin) & 0x1f;
  72.     w = xEnd - xStart;
  73.     dstBit = xStart & 0x1f;
  74.  
  75.     if (dstBit + w <= 32) 
  76.     { 
  77.     getandputrop(psrc, offSrc, dstBit, w, pdst, alu)
  78.     } 
  79.     else 
  80.     { 
  81.  
  82.     maskbits(xStart, w, startmask, endmask, nlMiddle);
  83.     if (startmask) 
  84.         nstart = 32 - dstBit; 
  85.     else 
  86.         nstart = 0; 
  87.     if (endmask) 
  88.         nend = xEnd & 0x1f; 
  89.     else 
  90.         nend = 0; 
  91.     if (startmask) 
  92.     { 
  93.         getandputrop(psrc, offSrc, dstBit, nstart, pdst, alu)
  94.         pdst++; 
  95.         offSrc += nstart;
  96.         if (offSrc > 31)
  97.         {
  98.         psrc++;
  99.         offSrc -= 32;
  100.         }
  101.     } 
  102.     nl = nlMiddle; 
  103.     while (nl--) 
  104.     { 
  105.         getbits(psrc, offSrc, 32, tmpSrc);
  106.         DoRop(*pdst, alu, tmpSrc, *pdst); 
  107.         pdst++; 
  108.         psrc++; 
  109.     } 
  110.     if (endmask) 
  111.     { 
  112.         getandputrop0(psrc, offSrc, nend, pdst, alu);
  113.     } 
  114.      
  115.     } 
  116. }
  117.  
  118.  
  119.  
  120. /* SetSpans -- for each span copy pwidth[i] bits from psrc to pDrawable at
  121.  * ppt[i] using the raster op from the GC.  If fSorted is TRUE, the scanlines
  122.  * are in increasing Y order.
  123.  * Source bit lines are server scanline padded so that they always begin
  124.  * on a word boundary.
  125.  */ 
  126. void
  127. mfbSetSpans(pDrawable, pGC, psrc, ppt, pwidth, nspans, fSorted)
  128.     DrawablePtr        pDrawable;
  129.     GCPtr        pGC;
  130.     int            *psrc;
  131.     register DDXPointPtr ppt;
  132.     int            *pwidth;
  133.     int            nspans;
  134.     int            fSorted;
  135. {
  136.     int         *pdstBase;    /* start of dst bitmap */
  137.     int         widthDst;    /* width of bitmap in words */
  138.     register BoxPtr     pbox, pboxLast, pboxTest;
  139.     register DDXPointPtr pptLast;
  140.     int         alu;
  141.     RegionPtr         prgnDst;
  142.     int            xStart, xEnd;
  143.     int            yMax;
  144.  
  145.     alu = pGC->alu;
  146.     prgnDst = ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip;
  147.  
  148.     pptLast = ppt + nspans;
  149.  
  150.     yMax = pDrawable->y + (int) pDrawable->height;
  151.     if (pDrawable->type == DRAWABLE_WINDOW)
  152.     {
  153.     pdstBase = (int *)
  154.         (((PixmapPtr)(pDrawable->pScreen->devPrivate))->devPrivate.ptr);
  155.     widthDst = (int)
  156.            ((PixmapPtr)(pDrawable->pScreen->devPrivate))->devKind
  157.             >> 2;
  158.     }
  159.     else
  160.     {
  161.     pdstBase = (int *)(((PixmapPtr)pDrawable)->devPrivate.ptr);
  162.     widthDst = (int)(((PixmapPtr)pDrawable)->devKind) >> 2;
  163.     }
  164.  
  165.     pbox =  REGION_RECTS(prgnDst);
  166.     pboxLast = pbox + REGION_NUM_RECTS(prgnDst);
  167.  
  168.     if(fSorted)
  169.     {
  170.     /* scan lines sorted in ascending order. Because they are sorted, we
  171.      * don't have to check each scanline against each clip box.  We can be
  172.      * sure that this scanline only has to be clipped to boxes at or after the
  173.      * beginning of this y-band 
  174.      */
  175.     pboxTest = pbox;
  176.     while(ppt < pptLast)
  177.     {
  178.         pbox = pboxTest;
  179.         if(ppt->y >= yMax)
  180.         break;
  181.         while(pbox < pboxLast)
  182.         {
  183.         if(pbox->y1 > ppt->y)
  184.         {
  185.             /* scanline is before clip box */
  186.             break;
  187.         }
  188.         else if(pbox->y2 <= ppt->y)
  189.         {
  190.             /* clip box is before scanline */
  191.             pboxTest = ++pbox;
  192.             continue;
  193.         }
  194.         else if(pbox->x1 > ppt->x + *pwidth) 
  195.         {
  196.             /* clip box is to right of scanline */
  197.             break;
  198.         }
  199.         else if(pbox->x2 <= ppt->x)
  200.         {
  201.             /* scanline is to right of clip box */
  202.             pbox++;
  203.             continue;
  204.         }
  205.  
  206.         /* at least some of the scanline is in the current clip box */
  207.         xStart = max(pbox->x1, ppt->x);
  208.         xEnd = min(ppt->x + *pwidth, pbox->x2);
  209.         mfbSetScanline(ppt->y, ppt->x, xStart, xEnd, psrc, alu,
  210.                    pdstBase, widthDst);
  211.         if(ppt->x + *pwidth <= pbox->x2)
  212.         {
  213.             /* End of the line, as it were */
  214.             break;
  215.         }
  216.         else
  217.             pbox++;
  218.         }
  219.         /* We've tried this line against every box; it must be outside them
  220.          * all.  move on to the next point */
  221.         ppt++;
  222.         psrc += PixmapWidthInPadUnits(*pwidth, 1);
  223.         pwidth++;
  224.     }
  225.     }
  226.     else
  227.     {
  228.     /* scan lines not sorted. We must clip each line against all the boxes */
  229.     while(ppt < pptLast)
  230.     {
  231.         if(ppt->y >= 0 && ppt->y < yMax)
  232.         {
  233.         
  234.         for(pbox = REGION_RECTS(prgnDst); pbox< pboxLast; pbox++)
  235.         {
  236.             if(pbox->y1 > ppt->y)
  237.             {
  238.             /* rest of clip region is above this scanline,
  239.              * skip it */
  240.             break;
  241.             }
  242.             if(pbox->y2 <= ppt->y)
  243.             {
  244.             /* clip box is below scanline */
  245.             pbox++;
  246.             break;
  247.             }
  248.             if(pbox->x1 <= ppt->x + *pwidth &&
  249.                pbox->x2 > ppt->x)
  250.             {
  251.             xStart = max(pbox->x1, ppt->x);
  252.             xEnd = min(pbox->x2, ppt->x + *pwidth);
  253.             mfbSetScanline(ppt->y, ppt->x, xStart, xEnd, 
  254.                        psrc, alu, pdstBase, widthDst);
  255.             }
  256.  
  257.         }
  258.         }
  259.     psrc += PixmapWidthInPadUnits(*pwidth, 1);
  260.     ppt++;
  261.     pwidth++;
  262.     }
  263.     }
  264. }
  265.  
  266.