home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / ibm / skyway / skyBitBlt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-21  |  5.6 KB  |  247 lines

  1. /*
  2.  * skyway copy area: same as cfb except uses skyway accelerator.
  3.  */
  4.  
  5. /*
  6. Copyright 1989 by the Massachusetts Institute of Technology
  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 name of M.I.T. not be used in
  13. advertising or publicity pertaining to distribution of the software
  14. without specific, written prior permission.  M.I.T. makes no
  15. representations about the suitability of this software for any
  16. purpose.  It is provided "as is" without express or implied warranty.
  17.  
  18. */
  19. /* $XConsortium: skyBitBlt.c,v 1.2 91/11/08 19:31:16 eswu Exp $ */
  20.  
  21. #include    "X.h"
  22. #include    "Xmd.h"
  23. #include    "Xproto.h"
  24. #include    "gcstruct.h"
  25. #include    "windowstr.h"
  26. #include    "scrnintstr.h"
  27. #include    "pixmapstr.h"
  28. #include    "regionstr.h"
  29.  
  30. #include    "cfb.h"
  31. #include    "cfbmskbits.h"
  32. #include    "cfb8bit.h"
  33. #include    "fastblt.h"
  34.  
  35.  
  36. extern int  cfbDoBitbltCopy();
  37. extern int  cfbDoBitbltXor();
  38. extern int  cfbDoBitbltOr();
  39. extern int  cfbDoBitbltGeneral();
  40. extern int  cfbDoBitblt();
  41.  
  42. extern RegionPtr cfbBitBlt();
  43.  
  44.  
  45. RegionPtr
  46. skyCopyArea(pSrcDrawable, pDstDrawable,
  47.             pGC, srcx, srcy, width, height, dstx, dsty)
  48.     register DrawablePtr pSrcDrawable;
  49.     register DrawablePtr pDstDrawable;
  50.     GC *pGC;
  51.     int srcx, srcy;
  52.     int width, height;
  53.     int dstx, dsty;
  54. {
  55.     int    (*doBitBlt) ();
  56.     int skyDoBitblt_WinToWin();
  57.     
  58.     doBitBlt = cfbDoBitbltCopy;
  59.  
  60.     if ((pSrcDrawable->type == DRAWABLE_WINDOW) &&
  61.     (pDstDrawable->type == DRAWABLE_WINDOW))
  62.     {
  63.     doBitBlt = skyDoBitblt_WinToWin;
  64.     }
  65.     else if (pGC->alu != GXcopy || (pGC->planemask & PMSK) != PMSK)
  66.     {
  67.     doBitBlt = cfbDoBitbltGeneral;
  68.     if ((pGC->planemask & PMSK) == PMSK)
  69.     {
  70.         switch (pGC->alu) {
  71.         case GXxor:
  72.         doBitBlt = cfbDoBitbltXor;
  73.         break;
  74.         case GXor:
  75.         doBitBlt = cfbDoBitbltOr;
  76.         break;
  77.         }
  78.     }
  79.     }
  80.     return cfbBitBlt (pSrcDrawable, pDstDrawable,
  81.             pGC, srcx, srcy, width, height, dstx, dsty, doBitBlt, 0);
  82. }
  83.  
  84.  
  85.  
  86. int
  87. skyDoBitblt_WinToWin(pSrc, pDst, alu, prgnDst, pptSrc, planemask)
  88.     DrawablePtr        pSrc, pDst;
  89.     int            alu;
  90.     RegionPtr        prgnDst;
  91.     DDXPointPtr        pptSrc;
  92.     unsigned long   planemask;
  93. {
  94.     BoxPtr pbox;
  95.     int nbox;
  96.  
  97.     BoxPtr pboxTmp, pboxNext, pboxBase, pboxNew1, pboxNew2;
  98.                 /* temporaries for shuffling rectangles */
  99.     DDXPointPtr pptTmp, pptNew1, pptNew2;
  100.                 /* shuffling boxes entails shuffling the
  101.                    source points too */
  102.     int w, h;
  103.     int xdir;            /* 1 = left right, -1 = right left/ */
  104.     int ydir;            /* 1 = top down, -1 = bottom up */
  105.  
  106.     int careful;
  107.  
  108.  
  109.     /* XXX we have to err on the side of safety when both are windows,
  110.      * because we don't know if IncludeInferiors is being used.
  111.      */
  112.     careful = ((pSrc == pDst) ||
  113.            ((pSrc->type == DRAWABLE_WINDOW) &&
  114.         (pDst->type == DRAWABLE_WINDOW)));
  115.  
  116.     pbox = REGION_RECTS(prgnDst);
  117.     nbox = REGION_NUM_RECTS(prgnDst);
  118.  
  119.     pboxNew1 = NULL;
  120.     pptNew1 = NULL;
  121.     pboxNew2 = NULL;
  122.     pptNew2 = NULL;
  123.     if (careful && (pptSrc->y < pbox->y1))
  124.     {
  125.         /* walk source botttom to top */
  126.     ydir = -1;
  127.  
  128.     if (nbox > 1)
  129.     {
  130.         /* keep ordering in each band, reverse order of bands */
  131.         pboxNew1 = (BoxPtr)ALLOCATE_LOCAL(sizeof(BoxRec) * nbox);
  132.         if(!pboxNew1)
  133.         return;
  134.         pptNew1 = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * nbox);
  135.         if(!pptNew1)
  136.         {
  137.             DEALLOCATE_LOCAL(pboxNew1);
  138.             return;
  139.         }
  140.         pboxBase = pboxNext = pbox+nbox-1;
  141.         while (pboxBase >= pbox)
  142.         {
  143.             while ((pboxNext >= pbox) &&
  144.                (pboxBase->y1 == pboxNext->y1))
  145.             pboxNext--;
  146.             pboxTmp = pboxNext+1;
  147.             pptTmp = pptSrc + (pboxTmp - pbox);
  148.             while (pboxTmp <= pboxBase)
  149.             {
  150.             *pboxNew1++ = *pboxTmp++;
  151.             *pptNew1++ = *pptTmp++;
  152.             }
  153.             pboxBase = pboxNext;
  154.         }
  155.         pboxNew1 -= nbox;
  156.         pbox = pboxNew1;
  157.         pptNew1 -= nbox;
  158.         pptSrc = pptNew1;
  159.         }
  160.     }
  161.     else
  162.     {
  163.     /* walk source top to bottom */
  164.     ydir = 1;
  165.     }
  166.  
  167.     if (careful && (pptSrc->x < pbox->x1))
  168.     {
  169.     /* walk source right to left */
  170.         xdir = -1;
  171.  
  172.     if (nbox > 1)
  173.     {
  174.         /* reverse order of rects in each band */
  175.         pboxNew2 = (BoxPtr)ALLOCATE_LOCAL(sizeof(BoxRec) * nbox);
  176.         pptNew2 = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * nbox);
  177.         if(!pboxNew2 || !pptNew2)
  178.         {
  179.         if (pptNew2) DEALLOCATE_LOCAL(pptNew2);
  180.         if (pboxNew2) DEALLOCATE_LOCAL(pboxNew2);
  181.         if (pboxNew1)
  182.         {
  183.             DEALLOCATE_LOCAL(pptNew1);
  184.             DEALLOCATE_LOCAL(pboxNew1);
  185.         }
  186.             return;
  187.         }
  188.         pboxBase = pboxNext = pbox;
  189.         while (pboxBase < pbox+nbox)
  190.         {
  191.             while ((pboxNext < pbox+nbox) &&
  192.                (pboxNext->y1 == pboxBase->y1))
  193.             pboxNext++;
  194.             pboxTmp = pboxNext;
  195.             pptTmp = pptSrc + (pboxTmp - pbox);
  196.             while (pboxTmp != pboxBase)
  197.             {
  198.             *pboxNew2++ = *--pboxTmp;
  199.             *pptNew2++ = *--pptTmp;
  200.             }
  201.             pboxBase = pboxNext;
  202.         }
  203.         pboxNew2 -= nbox;
  204.         pbox = pboxNew2;
  205.         pptNew2 -= nbox;
  206.         pptSrc = pptNew2;
  207.     }
  208.     }
  209.     else
  210.     {
  211.     /* walk source left to right */
  212.         xdir = 1;
  213.     }
  214.  
  215.     while(nbox--)
  216.     {
  217.     w = pbox->x2 - pbox->x1;
  218.     h = pbox->y2 - pbox->y1;
  219.  
  220.  
  221.     /*-------*/
  222.  
  223.  
  224.     SkywayBitBlt(alu, pDst->pScreen, planemask,
  225.         pptSrc->x, pptSrc->y,    /* source x,y    */
  226.         pbox->x1, pbox->y1,    /* dest x,y      */
  227.         w, h);            /* width, height */
  228.  
  229.  
  230.     /*-------*/
  231.  
  232.     pbox++;
  233.     pptSrc++;
  234.     }
  235.  
  236.     if (pboxNew2)
  237.     {
  238.     DEALLOCATE_LOCAL(pptNew2);
  239.     DEALLOCATE_LOCAL(pboxNew2);
  240.     }
  241.     if (pboxNew1)
  242.     {
  243.     DEALLOCATE_LOCAL(pptNew1);
  244.     DEALLOCATE_LOCAL(pboxNew1);
  245.     }
  246. }
  247.