home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xibm.zip / ppc / ppcWindow.c < prev    next >
C/C++ Source or Header  |  1991-01-10  |  11KB  |  367 lines

  1. /*
  2.  * Copyright IBM Corporation 1987,1988,1989
  3.  *
  4.  * All Rights Reserved
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software and its
  7.  * documentation for any purpose and without fee is hereby granted,
  8.  * provided that the above copyright notice appear in all copies and that 
  9.  * both that copyright notice and this permission notice appear in
  10.  * supporting documentation, and that the name of IBM not be
  11.  * used in advertising or publicity pertaining to distribution of the
  12.  * software without specific, written prior permission.
  13.  *
  14.  * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  15.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  16.  * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  17.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  18.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  19.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  20.  * SOFTWARE.
  21.  *
  22. */
  23. /***********************************************************
  24. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  25. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  26.  
  27.             All Rights Reserved
  28.  
  29. Permission to use, copy, modify, and distribute this software and its 
  30. documentation for any purpose and without fee is hereby granted, 
  31. provided that the above copyright notice appear in all copies and that
  32. both that copyright notice and this permission notice appear in 
  33. supporting documentation, and that the names of Digital or MIT not be
  34. used in advertising or publicity pertaining to distribution of the
  35. software without specific, written prior permission.  
  36.  
  37. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  38. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  39. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  40. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  41. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  42. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  43. SOFTWARE.
  44.  
  45. ******************************************************************/
  46.  
  47. #include "X.h"
  48. #include "scrnintstr.h"
  49. #include "windowstr.h"
  50. #include "mfb.h"
  51. #include "mistruct.h"
  52. #include "regionstr.h"
  53.  
  54. #include "ppc.h"
  55. #include "ibmTrace.h"
  56.  
  57. extern    int        ibmAllowBackingStore ;
  58.  
  59. /*
  60.    ppcCopyWindow copies only the parts of the destination that are
  61. visible in the source.
  62. */
  63.  
  64. void 
  65. ppcCopyWindow(pWin, ptOldOrg, prgnSrc)
  66.     register WindowPtr pWin ;
  67.     DDXPointRec ptOldOrg ;
  68.     RegionPtr prgnSrc ;
  69. {
  70.     RegionPtr prgnDst ;
  71.     register BoxPtr pbox ;
  72.     register int dx, dy ;
  73.     register int nbox ;
  74.     register int pm ;
  75.  
  76.     register void (*fnp)() ;
  77.     BoxPtr pboxTmp, pboxNext, pboxBase, pboxNew ;
  78.                 /* temporaries for shuffling rectangles */
  79.  
  80.     TRACE(("ppcCopyWindow(pWin= 0x%x, ptOldOrg= 0x%x, prgnSrc= 0x%x)\n", pWin, ptOldOrg, prgnSrc)) ;
  81.  
  82.  
  83.     dx = ptOldOrg.x - pWin->drawable.x ;
  84.     dy = ptOldOrg.y - pWin->drawable.y ;
  85.     (* pWin->drawable.pScreen->TranslateRegion)(prgnSrc, -dx, -dy) ;
  86.  
  87.     prgnDst = (* pWin->drawable.pScreen->RegionCreate)(NULL, 1);
  88.     (* pWin->drawable.pScreen->Intersect)(prgnDst, &pWin->borderClip, prgnSrc) ;
  89.  
  90.     if ( !( nbox = REGION_NUM_RECTS(prgnDst) ) )
  91.     return;
  92.  
  93.     pbox = REGION_RECTS(prgnDst);
  94.  
  95.     pboxNew = 0 ;
  96.     if ( nbox > 1 ) {
  97.     if ( dy < 0 ) {
  98.         if ( dx > 0 ) {
  99.         /* walk source bottom to top */
  100.         /* keep ordering in each band, reverse order of bands */
  101.         if ( !( pboxNew =
  102.             (BoxPtr) ALLOCATE_LOCAL( sizeof( BoxRec ) * nbox ) ) )
  103.             return ;
  104.         pboxBase = pboxNext = pbox+nbox - 1 ;
  105.         while ( pboxBase >= pbox ) {
  106.             while ( ( pboxNext >= pbox )
  107.                  && ( pboxBase->y1 == pboxNext->y1 ) )
  108.                 pboxNext-- ;
  109.             pboxTmp = pboxNext + 1 ;
  110.             while ( pboxTmp <= pboxBase )
  111.                 *pboxNew++ = *pboxTmp++ ;
  112.             pboxBase = pboxNext ;
  113.         }
  114.         pboxNew -= nbox ;
  115.         pbox = pboxNew ;
  116.         }
  117.         else { /* dx <= 0 */
  118.         /* we can just reverse the entire list in place */
  119.         /* Do three-position swaps */
  120.         BoxRec tmpBox ;
  121.  
  122.         pboxBase = pbox ;
  123.         pboxNext = pbox + nbox - 1 ;
  124.         while ( pboxBase < pboxNext ) {
  125.             /* ****** Warning Structure Assignment !! ****** */
  126.             tmpBox    = *pboxBase ;
  127.             *pboxBase = *pboxNext ;
  128.             *pboxNext = tmpBox ;
  129.             pboxBase++ ;
  130.             pboxNext-- ;
  131.         }
  132.         }
  133.     }
  134.         else if ( dx < 0 ) {
  135.     /* walk source right to left */
  136.         /* reverse order of rects in each band */
  137.         if ( !( pboxNew = (BoxPtr)ALLOCATE_LOCAL(sizeof(BoxRec) * nbox) ) )
  138.         return ;
  139.         pboxBase = pboxNext = pbox ;
  140.         while (pboxBase < pbox+nbox)
  141.         {
  142.         while ((pboxNext < pbox+nbox) &&
  143.                (pboxNext->y1 == pboxBase->y1))
  144.             pboxNext++ ;
  145.         pboxTmp = pboxNext ;
  146.         while (pboxTmp != pboxBase)
  147.             *pboxNew++ = *--pboxTmp ;
  148.         pboxBase = pboxNext ;
  149.         }
  150.         pboxNew -= nbox ;
  151.         pbox = pboxNew ;
  152.     }
  153.     } /* END if nbox > 1 */
  154.  
  155.     /*
  156.      * call blit several times, the parms are:
  157.      *   blit( alu,rplanes, wplanes, srcx, srcy, destx, desty, width, height ) ;
  158.      */
  159.  
  160.     pm = ( 1 << pWin->drawable.depth ) - 1 ;
  161.     fnp = ((ppcScrnPriv *)(pWin->drawable.pScreen->devPrivate))->blit ;
  162.     for ( ; nbox-- ; pbox++ )
  163.     (* fnp)( GXcopy, pm, pm, 
  164.          pbox->x1 + dx, pbox->y1 + dy, 
  165.          pbox->x1, pbox->y1, 
  166.          pbox->x2 - pbox->x1, pbox->y2 - pbox->y1) ;
  167.  
  168.     /* free up stuff */
  169.     if ( pboxNew )
  170.     DEALLOCATE_LOCAL( pboxNew ) ;
  171.  
  172.     (* pWin->drawable.pScreen->RegionDestroy)(prgnDst) ;
  173.     return ;
  174. }
  175.  
  176. /* As The Name Says -- Used For ega, vga and apa8c */
  177. void 
  178. ppcCopyWindowForXYhardware(pWin, ptOldOrg, prgnSrc)
  179.     register WindowPtr pWin ;
  180.     DDXPointRec ptOldOrg ;
  181.     RegionPtr prgnSrc ;
  182. {
  183.     RegionPtr prgnDst ;
  184.     register BoxPtr pbox ;
  185.     register int dx, dy ;
  186.     register int nbox ;
  187.     register int pm ;
  188.     int box_direction = 1 ; /* go forward */
  189.  
  190.     register void (*fnp)() ;
  191.     BoxPtr pboxTmp, pboxNext, pboxBase, pboxNew ;
  192.                 /* temporaries for shuffling rectangles */
  193.  
  194.     TRACE(("ppcCopyWindow(pWin= 0x%x, ptOldOrg= 0x%x, prgnSrc= 0x%x)\n", pWin, ptOldOrg, prgnSrc)) ;
  195.  
  196.  
  197.     dx = ptOldOrg.x - pWin->drawable.x ;
  198.     dy = ptOldOrg.y - pWin->drawable.y ;
  199.  
  200.     prgnDst = (* pWin->drawable.pScreen->RegionCreate)(NULL, 1);
  201.     (* pWin->drawable.pScreen->RegionCopy)( prgnDst, prgnSrc ) ;
  202.     (* pWin->drawable.pScreen->TranslateRegion)(prgnDst, -dx, -dy) ;
  203.     (* pWin->drawable.pScreen->Intersect)(prgnDst, &pWin->borderClip, prgnDst) ;
  204.  
  205.     if ( !( nbox = REGION_NUM_RECTS(prgnDst)))
  206.     return ;
  207.  
  208.     pbox = REGION_RECTS(prgnDst);
  209.  
  210.     pboxNew = 0 ;
  211.     if ( nbox > 1 ) {
  212.     if ( dy < 0 ) {
  213.         if ( dx > 0 ) {
  214.         /* walk source bottom to top */
  215.         /* keep ordering in each band, reverse order of bands */
  216.         if ( !( pboxNew =
  217.             (BoxPtr) ALLOCATE_LOCAL( sizeof( BoxRec ) * nbox ) ) )
  218.             return ;
  219.         pboxBase = pboxNext = pbox+nbox - 1 ;
  220.         while ( pboxBase >= pbox ) {
  221.             while ( ( pboxNext >= pbox )
  222.                  && ( pboxBase->y1 == pboxNext->y1 ) )
  223.                 pboxNext-- ;
  224.             pboxTmp = pboxNext + 1 ;
  225.             while ( pboxTmp <= pboxBase )
  226.                 *pboxNew++ = *pboxTmp++ ;
  227.             pboxBase = pboxNext ;
  228.         }
  229.         pboxNew -= nbox ;
  230.         pbox = pboxNew ;
  231.         }
  232.         else { /* dx <= 0 */
  233.         /* we can just reverse the entire list in place */
  234.         /* Do three-position swaps */
  235.         /* ****** Warning Structure Assignment !! ****** */
  236.         box_direction = -1 ;
  237.         }
  238.     }
  239.         else if ( dx < 0 ) {
  240.     /* walk source right to left */
  241.         /* reverse order of rects in each band */
  242.         if ( !( pboxNew = (BoxPtr)ALLOCATE_LOCAL(sizeof(BoxRec) * nbox) ) )
  243.         return ;
  244.         pboxBase = pboxNext = pbox ;
  245.         while ( pboxBase < pbox + nbox ) {
  246.         while ( ( pboxNext < pbox + nbox )
  247.              && ( pboxNext->y1 == pboxBase->y1 ) )
  248.             pboxNext++ ;
  249.         pboxTmp = pboxNext ;
  250.         while ( pboxTmp != pboxBase )
  251.             *pboxNew++ = *--pboxTmp ;
  252.         pboxBase = pboxNext ;
  253.         }
  254.         pboxNew -= nbox ;
  255.         pbox = pboxNew ;
  256.     }
  257.     } /* END if nbox > 1 */
  258.  
  259.     /*
  260.      *  OPTIMIZATION FOR XY-Oriented Hardware:
  261.      * Only Move Planes That The Client Has Declared An Interest In !!
  262.      *
  263.      * call blit several times, the parms are:
  264.      *   blit( alu,rplanes, wplanes, srcx, srcy, destx, desty, width, height ) ;
  265.      */
  266.  
  267.     pm = (~( ~0 << pWin->drawable.depth ) ) & pWin->optional->backingBitPlanes ;
  268.     fnp = ((ppcScrnPriv *)(pWin->drawable.pScreen->devPrivate))->blit ;
  269.     if ( box_direction < 0 )
  270.     pbox += nbox - 1 ;
  271.     for ( ; nbox-- ; pbox += box_direction )
  272.     (* fnp)( GXcopy, pm, pm, 
  273.          pbox->x1 + dx, pbox->y1 + dy, 
  274.          pbox->x1, pbox->y1, 
  275.          pbox->x2 - pbox->x1, pbox->y2 - pbox->y1) ;
  276.     /*
  277.      * Fill In the non-overlapping regions with backing pixel !!
  278.      * (* ... ->solidFill)( color, alu, planes, x0, y0, lx, ly )
  279.      */
  280.     if ( pm = ( ~( ~0 << pWin->drawable.depth ) ) & ~ pWin->optional->backingBitPlanes ) {
  281.     (* pWin->drawable.pScreen->Subtract)( prgnDst, prgnDst, prgnSrc ) ;
  282.     if ( nbox = REGION_NUM_RECTS(prgnDst)) {
  283.         unsigned long int fg = pWin->optional->backingPixel ;
  284.  
  285.         fnp =
  286.           ((ppcScrnPriv *)(pWin->drawable.pScreen->devPrivate))->solidFill ;
  287.         for ( pbox = REGION_RECTS(prgnDst) ; nbox-- ; pbox++ )
  288.         (* fnp)( fg, GXcopy, pm,
  289.              pbox->x1, pbox->y1,
  290.              pbox->x2 - pbox->x1, pbox->y2 - pbox->y1 ) ;
  291.         }
  292.     }
  293.  
  294.     /* free up stuff */
  295.     if ( pboxNew )
  296.     DEALLOCATE_LOCAL( pboxNew ) ;
  297.  
  298.     (* pWin->drawable.pScreen->RegionDestroy)(prgnDst) ;
  299.     return ;
  300. }
  301.  
  302. Bool ppcPositionWindow(pWin, x, y)
  303. register WindowPtr pWin ;
  304. register int x, y ;
  305. {
  306.     return TRUE ;
  307. }
  308.  
  309. Bool
  310. ppcUnrealizeWindow( pWindow, x, y)
  311. register WindowPtr pWindow ;
  312. register int x,y ;
  313. {
  314. return pWindow ? TRUE : FALSE ;
  315. }
  316.  
  317. Bool
  318. ppcRealizeWindow( pWindow )
  319. register WindowPtr pWindow ;
  320. {
  321. return pWindow ? TRUE : FALSE ;
  322. }
  323.  
  324. Bool 
  325. ppcDestroyWindow(pWin)
  326. register WindowPtr pWin ;
  327. {
  328. return pWin ? TRUE : FALSE ;
  329. }
  330.  
  331. Bool
  332. ppcCreateWindow(pWin)
  333. register WindowPtr pWin ;
  334. {
  335.     register mfbPrivWin *pPrivWin;
  336.  
  337.     TRACE(("ppcCreateWindow(pWin= 0x%x)\n", pWin));
  338.  
  339.     pPrivWin = (mfbPrivWin *)pWin->devPrivates[mfbWindowPrivateIndex].ptr;
  340.     pPrivWin->pRotatedBorder = NullPixmap;
  341.     pPrivWin->pRotatedBackground = NullPixmap;
  342.     pPrivWin->fastBackground = 0;
  343.     pPrivWin->fastBorder = 0;
  344.  
  345.     return TRUE;
  346. }
  347.  
  348. /* As The Name Says -- Used For ega, vga and apa8c */
  349. Bool
  350. ppcCreateWindowForXYhardware(pWin)
  351. register WindowPtr pWin ;
  352. {
  353.     register mfbPrivWin *pPrivWin;
  354.  
  355.     TRACE(("ppcCreateWindowForXYhardware (pWin= 0x%x)\n", pWin));
  356.  
  357.     pPrivWin = (mfbPrivWin *)pWin->devPrivates[mfbWindowPrivateIndex].ptr;
  358.     pPrivWin->pRotatedBorder = NullPixmap;
  359.     pPrivWin->pRotatedBackground = NullPixmap;
  360.     pPrivWin->fastBackground = 0;
  361.     pPrivWin->fastBorder = 0;
  362.  
  363.     pWin->drawable.pScreen->CopyWindow = ppcCopyWindowForXYhardware ;
  364.  
  365.     return TRUE;
  366. }
  367.