home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / cfb / cfbtile32.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-14  |  8.2 KB  |  339 lines

  1. /*
  2.  * Fill 32 bit tiled rectangles.  Used by both PolyFillRect and PaintWindow.
  3.  * no depth dependencies.
  4.  */
  5.  
  6. /*
  7. Copyright 1989 by the Massachusetts Institute of Technology
  8.  
  9. Permission to use, copy, modify, and distribute this software and its
  10. documentation for any purpose and without fee is hereby granted,
  11. provided that the above copyright notice appear in all copies and that
  12. both that copyright notice and this permission notice appear in
  13. supporting documentation, and that the name of M.I.T. not be used in
  14. advertising or publicity pertaining to distribution of the software
  15. without specific, written prior permission.  M.I.T. makes no
  16. representations about the suitability of this software for any
  17. purpose.  It is provided "as is" without express or implied warranty.
  18. */
  19.  
  20. /* $XConsortium: cfbtile32.c,v 1.5 91/07/14 13:49:46 keith Exp $ */
  21.  
  22. #include "X.h"
  23. #include "Xmd.h"
  24. #include "servermd.h"
  25. #include "gcstruct.h"
  26. #include "window.h"
  27. #include "pixmapstr.h"
  28. #include "scrnintstr.h"
  29. #include "windowstr.h"
  30.  
  31. #include "cfb.h"
  32. #include "cfbmskbits.h"
  33. #include "cfb8bit.h"
  34.  
  35. #include "mergerop.h"
  36.  
  37. #ifdef sparc
  38. #define SHARED_IDCACHE
  39. #endif
  40.  
  41. #define STORE(p)    (*(p) = MROP_PREBUILT_SOLID(srcpix,*(p)))
  42.  
  43. #if (MROP == Mcopy) && defined(FAST_CONSTANT_OFFSET_MODE) && defined(SHARED_IDCACHE)
  44. # define Expand(left,right) {\
  45.     int part = nlwMiddle & 7; \
  46.     nlwMiddle >>= 3; \
  47.     while (h--) { \
  48.     srcpix = psrc[srcy]; \
  49.     MROP_PREBUILD(srcpix); \
  50.     ++srcy; \
  51.     if (srcy == tileHeight) \
  52.         srcy = 0; \
  53.     left \
  54.     p += part; \
  55.     switch (part) { \
  56.     case 7: \
  57.         STORE(p - 7); \
  58.     case 6: \
  59.         STORE(p - 6); \
  60.     case 5: \
  61.         STORE(p - 5); \
  62.     case 4: \
  63.         STORE(p - 4); \
  64.     case 3: \
  65.         STORE(p - 3); \
  66.     case 2: \
  67.         STORE(p - 2); \
  68.     case 1: \
  69.         STORE(p - 1); \
  70.     } \
  71.     nlw = nlwMiddle; \
  72.     while (nlw) { \
  73.         STORE (p + 0); \
  74.         STORE (p + 1); \
  75.         STORE (p + 2); \
  76.         STORE (p + 3); \
  77.         STORE (p + 4); \
  78.         STORE (p + 5); \
  79.         STORE (p + 6); \
  80.         STORE (p + 7); \
  81.         p += 8; \
  82.         nlw--; \
  83.     } \
  84.     right \
  85.     p += nlwExtra; \
  86.     } \
  87. }
  88. #else
  89. #define Expand(left,right) {\
  90.     while (h--)    { \
  91.     srcpix = psrc[srcy]; \
  92.     MROP_PREBUILD(srcpix); \
  93.     ++srcy; \
  94.     if (srcy == tileHeight) \
  95.         srcy = 0; \
  96.     left \
  97.     nlw = nlwMiddle; \
  98.     while (nlw--) \
  99.     { \
  100.         STORE(p); \
  101.         p++; \
  102.     } \
  103.     right \
  104.     p += nlwExtra; \
  105.     } \
  106. }
  107. #endif
  108.  
  109. void
  110. MROP_NAME(cfbFillRectTile32) (pDrawable, pGC, nBox, pBox)
  111.     DrawablePtr        pDrawable;
  112.     GCPtr        pGC;
  113.     int            nBox;    /* number of boxes to fill */
  114.     BoxPtr         pBox;    /* pointer to list of boxes to fill */
  115. {
  116.     register unsigned long srcpix;    
  117.     unsigned long *psrc;        /* pointer to bits in tile, if needed */
  118.     int tileHeight;    /* height of the tile */
  119.  
  120.     int nlwDst;        /* width in longwords of the dest pixmap */
  121.     int w;        /* width of current box */
  122.     register int h;    /* height of current box */
  123.     register unsigned long startmask;
  124.     register unsigned long endmask; /* masks for reggedy bits at either end of line */
  125.     int nlwMiddle;    /* number of longwords between sides of boxes */
  126.     int nlwExtra;    /* to get from right of box to left of next span */
  127.     register int nlw;    /* loop version of nlwMiddle */
  128.     register unsigned long *p;    /* pointer to bits we're writing */
  129.     int y;        /* current scan line */
  130.     int srcy;        /* current tile position */
  131.  
  132.     unsigned long *pbits;/* pointer to start of pixmap */
  133.     PixmapPtr        tile;    /* rotated, expanded tile */
  134.     MROP_DECLARE_REG()
  135.     MROP_PREBUILT_DECLARE()
  136.  
  137.     tile = ((cfbPrivGCPtr) (pGC->devPrivates[cfbGCPrivateIndex].ptr))->pRotatedPixmap;
  138.     tileHeight = tile->drawable.height;
  139.     psrc = (unsigned long *)tile->devPrivate.ptr;
  140.  
  141.     MROP_INITIALIZE(pGC->alu, pGC->planemask);
  142.  
  143.     cfbGetLongWidthAndPointer (pDrawable, nlwDst, pbits)
  144.  
  145.     while (nBox--)
  146.     {
  147.     w = pBox->x2 - pBox->x1;
  148.     h = pBox->y2 - pBox->y1;
  149.     y = pBox->y1;
  150.     p = pbits + (y * nlwDst) + (pBox->x1 >> PWSH);
  151.     srcy = y % tileHeight;
  152.  
  153.     if ( ((pBox->x1 & PIM) + w) <= PPW)
  154.     {
  155.         maskpartialbits(pBox->x1, w, startmask);
  156.         nlwExtra = nlwDst;
  157.         while (h--)
  158.         {
  159.         srcpix = psrc[srcy];
  160.         MROP_PREBUILD(srcpix);
  161.         ++srcy;
  162.         if (srcy == tileHeight)
  163.             srcy = 0;
  164.         *p = MROP_PREBUILT_MASK (srcpix, *p, startmask);
  165.         p += nlwExtra;
  166.         }
  167.     }
  168.     else
  169.     {
  170.         maskbits(pBox->x1, w, startmask, endmask, nlwMiddle);
  171.         nlwExtra = nlwDst - nlwMiddle;
  172.  
  173.         if (startmask)
  174.         {
  175.         nlwExtra -= 1;
  176.         if (endmask)
  177.         {
  178.             Expand(*p = MROP_PREBUILT_MASK(srcpix, *p, startmask); p++;,
  179.                *p = MROP_PREBUILT_MASK(srcpix, *p, endmask);)
  180.         }
  181.         else
  182.         {
  183.             Expand(*p = MROP_PREBUILT_MASK(srcpix, *p, startmask); p++;,
  184.                ;)
  185.         }
  186.         }
  187.         else
  188.         {
  189.         if (endmask)
  190.         {
  191.             Expand(;,
  192.                *p = MROP_PREBUILT_MASK(srcpix, *p, endmask);)
  193.         }
  194.         else
  195.         {
  196.             Expand(;,
  197.                ;)
  198.         }
  199.         }
  200.     }
  201.         pBox++;
  202.     }
  203. }
  204.  
  205. void
  206. MROP_NAME(cfbTile32FS)(pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)
  207.     DrawablePtr pDrawable;
  208.     GCPtr    pGC;
  209.     int        nInit;            /* number of spans to fill */
  210.     DDXPointPtr pptInit;        /* pointer to list of start points */
  211.     int        *pwidthInit;        /* pointer to list of n widths */
  212.     int     fSorted;
  213. {
  214.                 /* next three parameters are post-clip */
  215.     int            n;    /* number of spans to fill */
  216.     DDXPointPtr        ppt;    /* pointer to list of start points */
  217.     int            *pwidth;/* pointer to list of n widths */
  218.     unsigned long    *pbits;    /* pointer to start of bitmap */
  219.     int            nlwDst;    /* width in longwords of bitmap */
  220.     register unsigned long *p;    /* pointer to current longword in bitmap */
  221.     register int    w;    /* current span width */
  222.     register int    nlw;
  223.     register int    x;
  224.     register unsigned long startmask;
  225.     register unsigned long endmask;
  226.     register unsigned long  srcpix;
  227.     int            y;
  228.     int            *pwidthFree;/* copies of the pointers to free */
  229.     DDXPointPtr        pptFree;
  230.     PixmapPtr        tile;
  231.     unsigned long    *psrc;    /* pointer to bits in tile */
  232.     int            tileHeight;/* height of the tile */
  233.     MROP_DECLARE_REG ()
  234.     MROP_PREBUILT_DECLARE()
  235.  
  236.     n = nInit * miFindMaxBand(((cfbPrivGC *)(pGC->devPrivates[cfbGCPrivateIndex].ptr))->pCompositeClip);
  237.     pwidthFree = (int *)ALLOCATE_LOCAL(n * sizeof(int));
  238.     pptFree = (DDXPointRec *)ALLOCATE_LOCAL(n * sizeof(DDXPointRec));
  239.     if(!pptFree || !pwidthFree)
  240.     {
  241.     if (pptFree) DEALLOCATE_LOCAL(pptFree);
  242.     if (pwidthFree) DEALLOCATE_LOCAL(pwidthFree);
  243.     return;
  244.     }
  245.     pwidth = pwidthFree;
  246.     ppt = pptFree;
  247.     n = miClipSpans(((cfbPrivGC *)(pGC->devPrivates[cfbGCPrivateIndex].ptr))->pCompositeClip,
  248.              pptInit, pwidthInit, nInit,
  249.              ppt, pwidth, fSorted);
  250.  
  251.     tile = ((cfbPrivGCPtr) (pGC->devPrivates[cfbGCPrivateIndex].ptr))->pRotatedPixmap;
  252.     tileHeight = tile->drawable.height;
  253.     psrc = (unsigned long *)tile->devPrivate.ptr;
  254.  
  255.     MROP_INITIALIZE(pGC->alu, pGC->planemask);
  256.  
  257.     cfbGetLongWidthAndPointer (pDrawable, nlwDst, pbits)
  258.  
  259. #if MROP == Mcopy
  260.     if (!(tileHeight & (tileHeight-1)))
  261.     {
  262.     tileHeight--;
  263.         while (n--)
  264.         {
  265.         x = ppt->x;
  266.         y = ppt->y;
  267.         ++ppt;
  268.         w = *pwidth++;
  269.         p = pbits + (y * nlwDst) + (x >> PWSH);
  270.         srcpix = psrc[y & tileHeight];
  271.         MROP_PREBUILD(srcpix);
  272.     
  273.         if ((x & PIM) + w < PPW)
  274.         {
  275.             maskpartialbits(x, w, startmask);
  276.             *p = MROP_PREBUILT_MASK (srcpix, *p, startmask);
  277.         }
  278.         else
  279.         {
  280.             maskbits(x, w, startmask, endmask, nlw);
  281.             if (startmask)
  282.             {
  283.             *p = MROP_PREBUILT_MASK(srcpix, *p, startmask);
  284.             p++;
  285.             }
  286.             while (nlw--)
  287.             {
  288.             STORE(p);
  289.             ++p;
  290.             }
  291.             if (endmask)
  292.             {
  293.             *p = MROP_PREBUILT_MASK(srcpix, *p, endmask);
  294.             }
  295.         }
  296.         }
  297.     }
  298.     else
  299. #endif
  300.     {
  301.         while (n--)
  302.         {
  303.         x = ppt->x;
  304.         y = ppt->y;
  305.         ++ppt;
  306.         w = *pwidth++;
  307.         p = pbits + (y * nlwDst) + (x >> PWSH);
  308.         srcpix = psrc[y % tileHeight];
  309.         MROP_PREBUILD(srcpix);
  310.     
  311.         if ((x & PIM) + w < PPW)
  312.         {
  313.             maskpartialbits(x, w, startmask);
  314.             *p = MROP_PREBUILT_MASK (srcpix, *p, startmask);
  315.         }
  316.         else
  317.         {
  318.             maskbits(x, w, startmask, endmask, nlw);
  319.             if (startmask)
  320.             {
  321.             *p = MROP_PREBUILT_MASK(srcpix, *p, startmask);
  322.             p++;
  323.             }
  324.             while (nlw--)
  325.             {
  326.             STORE(p);
  327.             ++p;
  328.             }
  329.             if (endmask)
  330.             {
  331.             *p = MROP_PREBUILT_MASK(srcpix, *p, endmask);
  332.             }
  333.         }
  334.         }
  335.     }
  336.     DEALLOCATE_LOCAL(pptFree);
  337.     DEALLOCATE_LOCAL(pwidthFree);
  338. }
  339.