home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xibm.zip / mpel / mpelTile.c < prev    next >
C/C++ Source or Header  |  1989-11-09  |  8KB  |  267 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 IBM Corporation 1987,1988
  25.  
  26.                       All Rights Reserved
  27.  
  28. Permission to use, copy, modify, and distribute this software and its
  29. documentation for any purpose and without fee is hereby granted,
  30. provided that the above copyright notice appear in all copies and that
  31. both that copyright notice and this permission notice appear in
  32. supporting documentation, and that the name of IBM not be
  33. used in advertising or publicity pertaining to distribution of the
  34. software without specific, written prior permission.
  35.  
  36. IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  37. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  38. IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  39. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  40. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  41. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  42. SOFTWARE.
  43.  
  44. ******************************************************************/
  45.  
  46. /* $Header: /andrew/X11/r3src/release/server/ddx/ibm/mpel/RCS/mpelTile.c,v 6.6 89/04/29 21:38:28 jeff Exp $ */
  47. /* $Source: /andrew/X11/r3src/release/server/ddx/ibm/mpel/RCS/mpelTile.c,v $ */
  48.  
  49. #ifndef lint
  50. static char *rcsid = "$Header: /andrew/X11/r3src/release/server/ddx/ibm/mpel/RCS/mpelTile.c,v 6.6 89/04/29 21:38:28 jeff Exp $" ;
  51. #endif
  52.  
  53. /*
  54.  * mpeltile.c
  55.  * fast tiles for the megapel
  56.  * by Jeff
  57.  */
  58.  
  59. #include "X.h"
  60. #include "Xmd.h"
  61. #include "pixmapstr.h"
  62. #include "regionstr.h"
  63.  
  64. #include "OScompiler.h"
  65.  
  66. #include "mpel.h"
  67. #include "mpelHdwr.h"
  68. #include "mpelFifo.h"
  69.  
  70. #include "ibmTrace.h"
  71.  
  72. extern PixmapPtr ppcCreatePixmap() ;
  73.  
  74. /* Cursor Stuff */
  75. extern int mpelcursorSemaphore ;
  76. extern int mpelCheckCursor() ;
  77. extern void mpelReplaceCursor() ;
  78.  
  79. /***==================================================================***/
  80.  
  81. void
  82. mpelTile( pTile, alu, planemask, x, y, w, h, xSrc, ySrc )
  83.     PixmapPtr pTile ;
  84.     int alu ;
  85.     unsigned long int planemask ;
  86.     int x, y, w, h, xSrc, ySrc ;
  87. {
  88.     register int        line ;
  89.     int             tilew, tileh ;
  90.     int             xrot, yrot ;
  91.     register unsigned char    *psrc ;
  92.     register volatile unsigned char     *pdst ;
  93.     unsigned char        *psrcSave ;
  94.     int                cursor_saved ;
  95.     mpelTileBLTVPMWMask     tilearg ;
  96.     PixmapPtr            pRotTile = (PixmapPtr)NULL ;
  97.     PixmapPtr            pTmpTile ;
  98.     int             widthIterations ;
  99.     int             heightIterations ;
  100.     int             widthLeftOver ;
  101.     int             heightLeftOver ;
  102.  
  103.     TRACE(("mpelTile(0x%x,%d,0x%x,%d,%d,%d,%d,0x%x,0x%x)\n",
  104.         pTile,alu,planemask,x,y,w,h,xSrc,ySrc)) ;
  105.  
  106.     if ( w <= 0 || h <= 0 )
  107.     return ;
  108.  
  109.     switch ( alu ) {
  110.     case GXclear:
  111.     case GXset:
  112.     case GXinvert:
  113.         mpelFillSolid( MPEL_ALLPLANES, alu, planemask, x, y, w, h ) ;
  114.     case GXnoop:
  115.         return ;
  116.  
  117.     case GXcopy:
  118.     case GXcopyInverted:
  119. #if (HCVERSION>21000) && (HCVERSION<21007)
  120.         /* 10/21/88 (ef) -- hc version 2.1d passes a bad    */
  121.         /*    argument to ppcTileRect.  a call to NoopDDA()    */
  122.         /*    (or any other function) fakes it out.        */
  123.         /*    Ain't compiler bugs fun??            */
  124.         NoopDDA() ;
  125. #endif
  126.         ppcTileRect( pTile, alu, planemask, x, y, w, h, xSrc, ySrc ) ;
  127.         return ; /* ppc is fast for those cases */
  128.     default: break ;
  129.         /* fall through */
  130.     }
  131.  
  132.     tilew = pTile->drawable.width ;
  133.     tileh = pTile->drawable.height ;
  134.  
  135.     if ( ( tilew * tileh ) > ( MPEL_BLIT_STAGE_SIZE / 2 ) ) {
  136.     ppcTileRect( pTile, alu, planemask, x, y, w, h, xSrc, ySrc ) ;
  137.     return ;
  138.     }
  139.  
  140.     if ( (xrot = (( x - xSrc ) % tilew )) < 0 ) xrot += tilew ;
  141.     if ( (yrot = (( y - ySrc ) % tileh )) < 0 ) yrot += tileh ;
  142.  
  143.     if ( xrot || yrot ) {
  144.     if ( !( pRotTile = ppcCreatePixmap( pTile->drawable.pScreen,
  145.                         tilew, tileh,
  146.                         pTile->drawable.depth ) ) ) {
  147.         ErrorF( "mpelTile: failed to create rot pixmap\n" ) ;
  148.         return ;
  149.     }
  150.  
  151.     if ( !( pTmpTile = ppcCreatePixmap( pTile->drawable.pScreen,
  152.                         tilew, tileh,
  153.                         pTile->drawable.depth ) ) ) {
  154.         ErrorF( "mpelTile: failed to create tmp pixmap\n" ) ;
  155.         return ;
  156.     }
  157.  
  158.     if ( xrot && !yrot )
  159.         ppcRotZ8mapLeft( pTile, pRotTile, xrot ) ;
  160.     else if ( yrot && !xrot )
  161.         ppcRotZ8mapUp( pTile, pRotTile, yrot ) ;
  162.     else {
  163.         ppcRotZ8mapLeft( pTile, pTmpTile, xrot ) ;
  164.         ppcRotZ8mapUp( pTmpTile, pRotTile, yrot ) ;
  165.     }
  166.     mfbDestroyPixmap( pTmpTile ) ;
  167.     psrcSave = psrc = pRotTile->devPrivate.ptr ;
  168.     }
  169.     else
  170.     psrcSave = psrc = pTile->devPrivate.ptr ;
  171.  
  172.     /* If Cursor Is In The Way Remove It */
  173.     cursor_saved = !mpelcursorSemaphore && mpelCheckCursor( x, y, w, h ) ;
  174.  
  175.     mpelSetPlaneMask( planemask ) ;
  176.  
  177.     heightLeftOver = h % tileh ;
  178.     heightIterations = h / tileh ;
  179.     widthLeftOver = w % tilew ;
  180.     widthIterations = w / tilew ;
  181.  
  182.     tilearg.alu =        alu + 1 ;
  183.  
  184.     if ( widthIterations ) {
  185.     MPELWaitFifo() ; /* If The 'SetPlaneMask is done Go On */
  186.     pdst = (volatile unsigned char *) MPEL_BLIT_STAGE ;
  187.     for ( line = tileh ; line-- ;  ) {
  188.         MOVE( psrc, pdst, tilew ) ;
  189.         psrc += pTile->devKind ;
  190.         pdst += tilew ;
  191.     }
  192.     /*
  193.      * tile the upper left area
  194.      */
  195.     if ( heightIterations ) {
  196.         tilearg.tileaddr=         mpelAddr(MPEL_BLIT_STAGE) ;
  197.         tilearg.twidth=         tilew ;
  198.         tilearg.theight=         tileh ;
  199.         tilearg.dest.lleft.x=     x ;
  200.         tilearg.dest.lleft.y=    1023-(y+(heightIterations*tileh)-1) ;
  201.         tilearg.dest.uright.x=    x + ( widthIterations * tilew ) - 1 ;
  202.         tilearg.dest.uright.y=     1023 - y ;
  203.         MPELTileBLTVPMNoMask( &tilearg ) ;
  204.     }
  205.     if ( heightLeftOver ) {
  206.         tilearg.tileaddr=        mpelAddr(MPEL_BLIT_STAGE) ;
  207.         tilearg.twidth=        tilew ;
  208.         tilearg.theight=        heightLeftOver ;
  209.         tilearg.dest.lleft.x=    x ;
  210.         tilearg.dest.lleft.y=    1023 - ( y + h - 1 ) ;
  211.         tilearg.dest.uright.x=    x + ( widthIterations * tilew ) - 1 ;
  212.         tilearg.dest.uright.y=    1023 - ( y + heightIterations * tileh ) ;
  213.         MPELTileBLTVPMNoMask( &tilearg ) ;
  214.     }
  215.     }
  216.  
  217.     if ( widthLeftOver ) {
  218.     MPELNoOp( 2, &MPELNoOpData ) ;
  219.     pdst = ( (volatile unsigned char *)MPEL_BLIT_STAGE )
  220.          + MPEL_BLIT_STAGE_SIZE/2 ;
  221.     psrc = psrcSave ;
  222.     MPELWaitFifo() ;
  223.     for ( line = tileh ; line-- ;  ) {
  224.         MOVE( psrc, pdst, widthLeftOver ) ;
  225.         psrc += pTile->devKind ;
  226.         pdst += widthLeftOver ;
  227.     }
  228.     /*
  229.      * tile the upper left area
  230.      */
  231.     if ( heightIterations ) {
  232.         tilearg.tileaddr=    (long) mpelAddr( MPEL_BLIT_STAGE ) +
  233.                         ( MPEL_BLIT_STAGE_SIZE / 4 ) ;
  234.         tilearg.twidth=        widthLeftOver ;
  235.         tilearg.theight=        tileh ;
  236.         tilearg.dest.lleft.x=    x + widthIterations * tilew ;
  237.         tilearg.dest.lleft.y=    MPEL_HEIGHT
  238.                     - ( y + ( heightIterations * tileh ) ) ;
  239.         tilearg.dest.uright.x=    x + w - 1 ;
  240.         tilearg.dest.uright.y=    MPEL_HEIGHT - 1 - y ;
  241.         MPELTileBLTVPMNoMask( &tilearg ) ;
  242.     }
  243.     if ( heightLeftOver ) {
  244.         tilearg.tileaddr= (long) mpelAddr(MPEL_BLIT_STAGE)
  245.                 + (MPEL_BLIT_STAGE_SIZE / 4) ;
  246.         tilearg.twidth=        widthLeftOver ;
  247.         tilearg.theight=        heightLeftOver ;
  248.         tilearg.dest.lleft.x=    x + widthIterations * tilew ;
  249.         tilearg.dest.lleft.y=    MPEL_HEIGHT - ( y + h ) ;
  250.         tilearg.dest.uright.x=    x + w - 1 ;
  251.         tilearg.dest.uright.y=    MPEL_HEIGHT - 1
  252.                     - ( y + heightIterations * tileh ) ;
  253.         MPELTileBLTVPMNoMask( &tilearg ) ;
  254.     }
  255.     }
  256.     /*
  257.      * destroy the rotated pixmap
  258.      */
  259.     if ( pRotTile )
  260.     mfbDestroyPixmap( pRotTile ) ;
  261.  
  262.     if ( cursor_saved )
  263.     mpelReplaceCursor() ;
  264.  
  265.     return ;
  266. }
  267.