home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xibm.zip / apa16 / apa16BBlt.c next >
C/C++ Source or Header  |  1992-02-01  |  15KB  |  514 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. /***********************************************************
  26.         Copyright IBM Corporation 1987,1988
  27.  
  28.                       All Rights Reserved
  29.  
  30. Permission to use, copy, modify, and distribute this software and its 
  31. documentation for any purpose and without fee is hereby granted, 
  32. provided that the above copyright notice appear in all copies and that
  33. both that copyright notice and this permission notice appear in 
  34. supporting documentation, and that the name of IBM not be
  35. used in advertising or publicity pertaining to distribution of the
  36. software without specific, written prior permission.  
  37.  
  38. IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  39. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  40. IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  41. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  42. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  43. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  44. SOFTWARE.
  45.  
  46. ******************************************************************/
  47. /***********************************************************
  48. Copyright 1989 by the Massachusetts Institute of Technology
  49.  
  50.                      All rights reserved.
  51.  
  52. Permission to use, copy, modify, and distribute this software and its
  53. documentation for any purpose and without fee is hereby granted,
  54. provided that the above copyright notice appear in all copies and that
  55. both that copyright notice and this permission notice appear in
  56. supporting documentation, and that the name of the Massachusetts
  57. Institute of Technology (M.I.T.) not be used in advertising or publicity
  58. pertaining to distribution of the software without specific, written
  59. prior permission.
  60.  
  61. M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  62. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  63. M.I.T. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  64. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  65. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  66. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  67. SOFTWARE.
  68.  
  69. ******************************************************************/
  70. /* $XConsortium: apa16BBlt.c,v 1.2 90/03/05 13:52:48 swick Exp $ */
  71. #include "X.h"
  72. #include "Xprotostr.h"
  73.  
  74. #include "miscstruct.h"
  75. #include "regionstr.h"
  76. #include "gcstruct.h"
  77. #include "windowstr.h"
  78. #include "pixmapstr.h"
  79. #include "scrnintstr.h"
  80.  
  81. #include "mi.h"
  82.  
  83. #include "mfb.h"
  84. #include "maskbits.h"
  85.  
  86. #include "OScompiler.h"
  87. #include "apa16Hdwr.h"
  88. #include "ibmTrace.h"
  89.  
  90. /* CopyArea and CopyPlane for a monchrome frame buffer
  91.  
  92.  
  93.     clip the source rectangle to the source's available bits.  (this
  94. avoids copying unnecessary pieces that will just get exposed anyway.)
  95. this becomes the new shape of the destination.
  96.     clip the destination region to the composite clip in the
  97. GC.  this requires translating the destination region to (dstx, dsty).
  98.     build a list of source points, one for each rectangle in the
  99. destination.  this is a simple translation.
  100.     go do the multiple rectangle copies
  101.     do graphics exposures
  102. */
  103. RegionPtr 
  104. apa16CopyArea(pSrcDrawable, pDstDrawable,
  105.                     pGC, srcx, srcy, width, height, dstx, dsty)
  106. register DrawablePtr pSrcDrawable;
  107. register DrawablePtr pDstDrawable;
  108. GC *pGC;
  109. int srcx, srcy;
  110. int width, height;
  111. int dstx, dsty;
  112. {
  113.     BoxRec srcBox;
  114.     RegionPtr prgnSrcClip;    /* may be a new region, or just a copy */
  115.     int realSrcClip = 0;    /* non-0 if we've created a src clip */
  116.  
  117.     RegionPtr prgnExposed;
  118.     RegionRec rgnDst;
  119.     DDXPointPtr pptSrc;
  120.     register DDXPointPtr ppt;
  121.     register BoxPtr pbox;
  122.     int i;
  123.     register int dx;
  124.     register int dy;
  125.     xRectangle origSource;
  126.     DDXPointRec origDest;
  127.     int numRects;
  128.  
  129.     TRACE(("apa16CopyArea(pSrcDrawable= 0x%x, pDstDrawable= 0x%x, pGC= 0x%x, srcx= %d, srcy= %d, width= %d, height= %d, dstx= %d, dsty= %d)\n",pSrcDrawable,pDstDrawable,pGC,srcx,srcy,width,height,dstx,dsty));
  130.  
  131.     if ((pSrcDrawable->type!=DRAWABLE_WINDOW)||
  132.     (pDstDrawable->type!=DRAWABLE_WINDOW)) {
  133.     if ((pSrcDrawable->type == DRAWABLE_WINDOW) ||
  134.         (pDstDrawable->type == DRAWABLE_WINDOW))
  135.         QUEUE_WAIT();
  136.     return(mfbCopyArea(pSrcDrawable,pDstDrawable,pGC,srcx,srcy,
  137.                         width,height,dstx,dsty));
  138.     }
  139.  
  140.     prgnExposed= NULL;
  141.     origSource.x = srcx;
  142.     origSource.y = srcy;
  143.     origSource.width = width;
  144.     origSource.height = height;
  145.     origDest.x = dstx;
  146.     origDest.y = dsty;
  147.  
  148.     /*
  149.        clip the left and top edges of the source - Is this still needed? XXX
  150.     */
  151.     if (srcx < 0) {
  152.         width += srcx;
  153.         srcx = 0;
  154.     }
  155.     if (srcy < 0) {
  156.         height += srcy;
  157.         srcy = 0;
  158.     }
  159.  
  160.     /* clip the source */
  161.  
  162.     srcx += pSrcDrawable->x;
  163.     srcy += pSrcDrawable->y;
  164.     if (pGC->subWindowMode == IncludeInferiors)
  165.     {
  166.     if ((pSrcDrawable == pDstDrawable) &&
  167.         (pGC->clientClipType == CT_NONE))
  168.     {
  169.         prgnSrcClip = ((mfbPrivGC *)(pGC->
  170.                      devPrivates[mfbGCPrivateIndex].ptr))->
  171.                        pCompositeClip;
  172.     }
  173.     else
  174.     {
  175.         prgnSrcClip = NotClippedByChildren((WindowPtr)pSrcDrawable);
  176.         realSrcClip = TRUE;
  177.     }
  178.     }
  179.     else
  180.     {
  181.     prgnSrcClip = &((WindowPtr)pSrcDrawable)->clipList;
  182.     }
  183.  
  184.     srcBox.x1 = srcx;
  185.     srcBox.y1 = srcy;
  186.     srcBox.x2 = srcx + width;
  187.     srcBox.y2 = srcy + height;
  188.  
  189.     (*pGC->pScreen->RegionInit)(&rgnDst, &srcBox, 1);
  190.     (*pGC->pScreen->Intersect)(&rgnDst, &rgnDst, prgnSrcClip);
  191.  
  192.     if (!((WindowPtr)pDstDrawable)->realized) {
  193.     goto freeRegions;
  194.     }
  195.     dstx += pDstDrawable->x;
  196.     dsty += pDstDrawable->y;
  197.  
  198.     dx = srcx - dstx;
  199.     dy = srcy - dsty;
  200.  
  201.     /* clip the shape of the dst to the destination composite clip */
  202.     (*pGC->pScreen->TranslateRegion)(&rgnDst, -dx, -dy);
  203.     (*pGC->pScreen->Intersect)(&rgnDst,
  204.         &rgnDst,
  205.         ((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->
  206.                    pCompositeClip);
  207.  
  208.     numRects = REGION_NUM_RECTS(&rgnDst);
  209.     if (!numRects)
  210.     {
  211.     goto freeRegions;
  212.     }
  213.     if(!(pptSrc = (DDXPointPtr)ALLOCATE_LOCAL( numRects *
  214.                           sizeof(DDXPointRec))))
  215.       {
  216.     goto freeRegions;
  217.       }
  218.     pbox = REGION_RECTS(&rgnDst);
  219.     ppt = pptSrc;
  220.     for (i=numRects; --i >= 0; pbox++, ppt++)
  221.     {
  222.     ppt->x = pbox->x1 + dx;
  223.     ppt->y = pbox->y1 + dy;
  224.     }
  225.  
  226.     if (pGC->planemask&1)
  227.     apa16DoBitblt(pSrcDrawable, pDstDrawable, pGC->alu, &rgnDst, pptSrc);
  228.  
  229.     if (((mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr))->fExpose) {
  230.         prgnExposed= miHandleExposures(pSrcDrawable, pDstDrawable, pGC,
  231.                       origSource.x, origSource.y,
  232.                       (int) origSource.width, (int) origSource.height,
  233.                                 origDest.x, origDest.y, (unsigned long) 0);
  234.     }
  235.         
  236.     DEALLOCATE_LOCAL(pptSrc);
  237. freeRegions:
  238.     (*pGC->pScreen->RegionUninit)(&rgnDst);
  239.     if (realSrcClip)
  240.       (*pGC->pScreen->RegionDestroy)(prgnSrcClip);
  241.     return(prgnExposed);
  242. }
  243.  
  244. /* 
  245.  *DoBitblt() does multiple rectangle moves into the rectangles
  246.  */
  247.  
  248. apa16DoBitblt(pSrcDrawable, pDstDrawable, alu, prgnDst, pptSrc)
  249. DrawablePtr pSrcDrawable;
  250. DrawablePtr pDstDrawable;
  251. int alu;
  252. RegionPtr      prgnDst;
  253. register DDXPointPtr pptSrc;
  254. {
  255.     int widthSrc, widthDst;    /* add to get to same position in next line */
  256.  
  257.     register BoxPtr pbox;
  258.     int nbox;
  259.  
  260.     BoxPtr pboxTmp, pboxNext, pboxBase, pboxNew1, pboxNew2;
  261.                 /* temporaries for shuffling rectangles */
  262.     DDXPointPtr pptTmp, pptNew1,pptNew2;
  263.                 /* shuffling boxes entails shuffling the
  264.                    source points too */
  265.  
  266.     register unsigned     cmd;    /* apa16 rasterop command word */
  267.  
  268.     TRACE(("apa16DoBitblt(pSrcDrawable= 0x%x, pDstDrawable= 0%x, alu= 0x%x, prgnDst= 0x%x, pptSrc= 0x%x)\n",pSrcDrawable,pDstDrawable,alu,prgnDst,pptSrc));
  269.  
  270.     if ((pSrcDrawable->type != DRAWABLE_WINDOW)||
  271.     (pDstDrawable->type != DRAWABLE_WINDOW)||
  272.         (alu==GXorReverse)||(alu==GXequiv)||
  273.     REGION_NUM_RECTS(prgnDst) * 7 >= QUEUE_DANGER) {
  274.         if ((pSrcDrawable->type == DRAWABLE_WINDOW) ||
  275.         (pDstDrawable->type == DRAWABLE_WINDOW))
  276.         QUEUE_WAIT();
  277.     mfbDoBitblt(pSrcDrawable,pDstDrawable,alu,prgnDst,pptSrc);
  278.     return;
  279.     }
  280.     if (alu==GXnoop)    return;
  281.  
  282.     widthSrc = (int)
  283.         ((PixmapPtr)(pSrcDrawable->pScreen->devPrivate))->devKind>>2;
  284.     widthDst = (int)
  285.         ((PixmapPtr)(pDstDrawable->pScreen->devPrivate))->devKind>>2;
  286.  
  287.     pbox = REGION_RECTS(prgnDst);
  288.     nbox = REGION_NUM_RECTS(prgnDst);
  289.  
  290.     pboxNew1 = NULL;
  291.     pptNew1 = NULL;
  292.     pboxNew2 = NULL;
  293.     pptNew2 = NULL;
  294.     if (pptSrc->y < pbox->y1) 
  295.     {
  296.         /* walk source botttom to top */
  297.     widthSrc = -widthSrc;
  298.     widthDst = -widthDst;
  299.  
  300.     if (nbox > 1)
  301.     {
  302.         /* keep ordering in each band, reverse order of bands */
  303.         pboxNew1 = (BoxPtr)ALLOCATE_LOCAL(sizeof(BoxRec) * nbox);
  304.         if (!pboxNew1)    
  305.         return;
  306.         pptNew1 = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * nbox);
  307.         if(!pptNew1)
  308.         {
  309.             DEALLOCATE_LOCAL(pboxNew1);
  310.             return;
  311.         }
  312.         pboxBase = pboxNext = pbox+nbox-1;
  313.         while (pboxBase >= pbox)
  314.         {
  315.             while ((pboxNext >= pbox) && 
  316.                (pboxBase->y1 == pboxNext->y1))
  317.             pboxNext--;
  318.             pboxTmp = pboxNext+1;
  319.             pptTmp = pptSrc + (pboxTmp - pbox);
  320.             while (pboxTmp <= pboxBase)
  321.             {
  322.             *pboxNew1++ = *pboxTmp++;
  323.             *pptNew1++ = *pptTmp++;
  324.             }
  325.             pboxBase = pboxNext;
  326.         }
  327.         pboxNew1 -= nbox;
  328.         pbox = pboxNew1;
  329.         pptNew1 -= nbox;
  330.         pptSrc = pptNew1;
  331.         }
  332.     }
  333.  
  334.     if (pptSrc->x < pbox->x1)
  335.     {
  336.     if (nbox > 1)
  337.     {
  338.         /* reverse order of rects in each band */
  339.         pboxNew2 = (BoxPtr)ALLOCATE_LOCAL(sizeof(BoxRec) * nbox);
  340.         pptNew2 = (DDXPointPtr)ALLOCATE_LOCAL(sizeof(DDXPointRec) * nbox);
  341.         pboxBase = pboxNext = pbox;
  342.         if(!pboxNew2 || !pptNew2)
  343.         {
  344.             if (pptNew2) DEALLOCATE_LOCAL(pptNew2);
  345.             if (pboxNew2) DEALLOCATE_LOCAL(pboxNew2);
  346.         if (pboxNew1)
  347.         {
  348.             DEALLOCATE_LOCAL(pptNew1);
  349.             DEALLOCATE_LOCAL(pboxNew1);
  350.         }
  351.             return;
  352.         }
  353.         while (pboxBase < pbox+nbox)
  354.         {
  355.             while ((pboxNext < pbox+nbox) &&
  356.                (pboxNext->y1 == pboxBase->y1))
  357.             pboxNext++;
  358.             pboxTmp = pboxNext;
  359.             pptTmp = pptSrc + (pboxTmp - pbox);
  360.             while (pboxTmp != pboxBase)
  361.             {
  362.             *(pboxNew2++) = *(--pboxTmp);
  363.             *(pptNew2++) = *(--pptTmp);
  364.             }
  365.             pboxBase = pboxNext;
  366.         }
  367.         pboxNew2 -= nbox;
  368.         pbox = pboxNew2;
  369.         pptNew2 -= nbox;
  370.         pptSrc = pptNew2;
  371.     }
  372.     }
  373.  
  374.     APA16_GET_CMD_COPY(ROP_RECT_COPY,alu,cmd);
  375.     if (cmd&STYPE_MASK) { /* hardware can handle copy */
  376.     /* Earlier code checked that nbox * 7 <= QUEUE_DANGER
  377.        If there are more than 143 regions to be copied, it is
  378.        probably faster to do it with mfb because they are so small. */
  379.     RESERVE_QUEUE(nbox * 7);
  380.     cmd |= EXEC_MASK;
  381.     while(nbox--) {
  382.       register int w,h;
  383.       w = pbox->x2 - pbox->x1;
  384.       h = pbox->y2 - pbox->y1;
  385.       if (w > 0 && h > 0)
  386.         {
  387.           pptSrc->x+= w;
  388.           pptSrc->y+= h;
  389.           COPY_RECT_NOCHECK(cmd,pbox->x2,pbox->y2,pptSrc->x,pptSrc->y,w,h);
  390.         }
  391.       pbox++;
  392.       pptSrc++;
  393.     }
  394.     }
  395.     else { /* special case, lend a hand */
  396.     switch (alu) {
  397.         case GXcopyInverted: /* copy and invert. simple, no? */
  398.         { register unsigned cmd2;
  399.         APA16_GET_CMD_COPY(ROP_RECT_COPY,GXcopy,cmd);
  400.         APA16_GET_CMD_FILL(GXinvert,cmd2);
  401.         while (nbox--) {
  402.             register int w,h;
  403.             w = pbox->x2 - pbox->x1;
  404.             h = pbox->y2 - pbox->y1;
  405.             if (w > 0 && h > 0)
  406.               {
  407.             pptSrc->x+= w;
  408.             pptSrc->y+= h;
  409.             COPY_RECT(cmd,pbox->x2,pbox->y2,pptSrc->x,pptSrc->y,w,h);
  410.             FILL_RECT(cmd2,pbox->x2,pbox->y2,w,h);
  411.               }
  412.             pbox++;
  413.             pptSrc++;
  414.         }
  415.         break;
  416.         }
  417.             /* really rectangle fill! */
  418.         case GXclear:
  419.         case GXinvert:
  420.         case GXset:    
  421.         APA16_GET_CMD_FILL(alu,cmd);
  422.         cmd |= EXEC_MASK;
  423.         RESERVE_QUEUE(5 * nbox);
  424.         while (nbox--) {
  425.             register int w,h;
  426.             w = pbox->x2 - pbox->x1;
  427.             h = pbox->y2 - pbox->y1;
  428.             if (w > 0 && h > 0)
  429.               {
  430.             pptSrc->x+= w;
  431.             pptSrc->y+= h;
  432.             FILL_RECT_NOCHECK(cmd,pbox->x2,pbox->y2,w,h);
  433.               }
  434.             pbox++;
  435.             pptSrc++;
  436.         }
  437.         break;
  438.        }
  439.     }
  440.     if (pboxNew2)
  441.     {
  442.     DEALLOCATE_LOCAL(pptNew2);
  443.     DEALLOCATE_LOCAL(pboxNew2);
  444.     }
  445.     if (pboxNew1)
  446.     {
  447.     DEALLOCATE_LOCAL(pptNew1);
  448.     DEALLOCATE_LOCAL(pboxNew1);
  449.     }
  450. }
  451.  
  452.  
  453. /*
  454.     if fg == 1 and bg ==0, we can do an ordinary CopyArea.
  455.     if fg == bg, we can do a CopyArea with alu = mfbReduceRop(alu, fg)
  456.     if fg == 0 and bg == 1, we use the same rasterop, with
  457.     source operand inverted.
  458.  
  459.     CopyArea deals with all of the graphics exposure events.
  460.     This code depends on knowing that we can change the
  461. alu in the GC without having to call ValidateGC() before calling
  462. CopyArea().
  463.  
  464. */
  465.  
  466. RegionPtr
  467. apa16CopyPlane(pSrcDrawable, pDstDrawable,
  468.            pGC, srcx, srcy, width, height, dstx, dsty, plane)
  469. DrawablePtr pSrcDrawable, pDstDrawable;
  470. register GC *pGC;
  471. int srcx, srcy;
  472. int width, height;
  473. int dstx, dsty;
  474. unsigned long plane;
  475. {
  476.     int alu;
  477.     RegionPtr    prgnExposed;
  478.  
  479.     /* XXX a deeper screen ought to wrap ValidateGC to get around this */
  480.     if (pSrcDrawable->depth != 1)
  481.     return miCopyPlane(pSrcDrawable, pDstDrawable,
  482.                pGC, srcx, srcy, width, height, dstx, dsty, plane);
  483.     if (plane != 1)
  484.     return NULL;
  485.  
  486.     if ((pGC->fgPixel == 1) && (pGC->bgPixel == 0))
  487.     {
  488.     prgnExposed = (*pGC->ops->CopyArea)(pSrcDrawable, pDstDrawable,
  489.              pGC, srcx, srcy, width, height, dstx, dsty);
  490.     }
  491.     else if (pGC->fgPixel == pGC->bgPixel)
  492.     {
  493.     alu = pGC->alu;
  494.     pGC->alu = apa16ReduceRop(pGC->alu, pGC->fgPixel);
  495.     prgnExposed = (*pGC->ops->CopyArea)(pSrcDrawable, pDstDrawable,
  496.              pGC, srcx, srcy, width, height, dstx, dsty);
  497.     pGC->alu = alu;
  498.     }
  499.     else /* need to invert the src */
  500.     {
  501.     alu = pGC->alu;
  502.     pGC->alu = InverseAlu[alu];
  503.     prgnExposed = (*pGC->ops->CopyArea)(pSrcDrawable, pDstDrawable,
  504.              pGC, srcx, srcy, width, height, dstx, dsty);
  505.     pGC->alu = alu;
  506.     }
  507.     return prgnExposed;
  508. }
  509.  
  510.  
  511.  
  512.  
  513.  
  514.