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 / apa16Tile.c < prev    next >
C/C++ Source or Header  |  1991-12-30  |  7KB  |  247 lines

  1. /***********************************************************
  2.         Copyright IBM Corporation 1988
  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 1989,1991 by the Massachusetts Institute of Technology
  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 the Massachusetts
  33. Institute of Technology (M.I.T.) not be used in advertising or publicity
  34. pertaining to distribution of the software without specific, written
  35. prior permission.
  36.  
  37. M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  38. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  39. M.I.T. 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. /* $Header: /afs/athena.mit.edu/astaff/project/x11r5/src/athena/ibm/apa16/RCS/apa16Tile.c,v 5.0 1991/12/30 19:22:51 jfc Exp $ */
  48. /* $Source: /afs/athena.mit.edu/astaff/project/x11r5/src/athena/ibm/apa16/RCS/apa16Tile.c,v $ */
  49.  
  50. #ifndef lint
  51. static char *rcsid = "$Id: apa16Tile.c,v 5.0 1991/12/30 19:22:51 jfc Exp $";
  52. #endif
  53.  
  54. #include "X.h"
  55.  
  56. #include "windowstr.h"
  57. #include "regionstr.h"
  58. #include "pixmapstr.h"
  59. #include "scrnintstr.h"
  60.  
  61. #include "OScompiler.h"
  62.  
  63. #include "mfb.h"
  64. #include "maskbits.h"
  65.  
  66. #include "apa16Hdwr.h"
  67. #include "ibmTrace.h"
  68.  
  69. /***====================================================================***/
  70.  
  71. /* This is globals so that other modules can invalidate off-screen
  72.  * scratch area
  73.  */
  74. unsigned int    *apa16CurrentTileBits=    NULL;
  75.  
  76. /* Store two adjacent copies of a 32 bit wide tile, so that the
  77.    routine which copies it onto the screen doesn't have to worry
  78.    about alignment. */
  79.  
  80. static void
  81. apa16StageTile32( pTile )
  82. PixmapPtr    pTile;
  83. {
  84. register unsigned int    *pDst;
  85. register unsigned int        *pSrc;
  86. register int              tileHeight;
  87.  
  88.     TRACE(("apa16StageTile32( pTile= 0x%x )\n"));
  89.     pSrc = (unsigned int *)(pTile->devPrivate.ptr);
  90.     apa16CurrentTileBits= pSrc;
  91.  
  92.     tileHeight = pTile->drawable.height;
  93.     pDst = (unsigned int *)SCREEN_ADDR(STAGE_X_OFFSET,STAGE_AREA_TOP);
  94.     QUEUE_WAIT();
  95.     while (tileHeight--) {
  96.     unsigned int tmp = *pSrc++;
  97.     pDst[0] = tmp;
  98.     pDst[1] = tmp;
  99.     pDst += APA16_WIDTH/32;
  100.     }
  101.  
  102.     apa16replicateArea(STAGE_X_OFFSET, STAGE_AREA_TOP,
  103.                STAGE_WIDTH, STAGE_HEIGHT,
  104.                pTile->drawable.width,
  105.                pTile->drawable.height);
  106.     return;
  107. }
  108.  
  109. /***====================================================================***/
  110.  
  111. /* 
  112.    this code could be called by the paint window background stuff,
  113. too; there would be some speed hit because of the different
  114. parameters and the need to check for a rop when filling
  115. with a tile.
  116.  
  117.    the boxes are already translated.
  118.  
  119.    NOTE:
  120.    iy = ++iy < tileHeight ? iy : 0
  121. is equivalent to iy%= tileheight, and saves a division.
  122. */
  123.  
  124. /* 
  125.     tile area with a 32 bit wide pixmap 
  126. */
  127. void
  128. apa16TileArea32( pDraw, nbox, pbox, alu, ptile )
  129.     DrawablePtr pDraw;
  130.     int nbox;
  131.     register BoxPtr pbox;
  132.     int alu;
  133.     PixmapPtr ptile;
  134. {
  135.     register unsigned int *psrc;
  136.             /* pointer to bits in tile, if needed */
  137.     unsigned short cmd;
  138.     int tileHeight;    /* height of the tile */
  139.     int tileWidth;    /* width of the tile */
  140.     int x;
  141.     int y;
  142.     int iy,ix;        /* index of current scanline in tile */
  143.     int h1;
  144.     int w;        /* width of current box */
  145.     int h;        /* height of current box */
  146.  
  147.     if ( !nbox )
  148.     return;
  149.  
  150.     switch ( alu ) {
  151.     case GXclear:        /* 0x0 Zero 0 */
  152.     case GXinvert:        /* 0xa NOT dst */
  153.     case GXset:        /* 0xf 1 */
  154.         apa16SolidFillArea( pDraw, nbox, pbox, alu, ptile );
  155.     case GXnoop:        /* 0x5 dst */
  156.         return;
  157.     default:
  158.         break;
  159.     }
  160.  
  161.     tileWidth = ptile->drawable.width;
  162.  
  163.     if (pDraw->type != DRAWABLE_WINDOW)
  164.       {
  165.     mfbTileArea32(pDraw, nbox, pbox, alu, ptile);
  166.     return;
  167.       }
  168.  
  169.     tileHeight = ptile->drawable.height;
  170.     psrc = (unsigned int *)(ptile->devPrivate.ptr);
  171.  
  172.     for( ; nbox; pbox++, nbox--) {
  173.     x = pbox->x1;
  174.     w = pbox->x2 - x;
  175.     y = pbox->y1;
  176.     h = pbox->y2 - y;
  177.  
  178.     if ( h > tileHeight || w > tileWidth ) { /* Special Iteration !! */
  179.         BoxRec tmpbox;
  180.         int currentHoriz, currentVert;
  181.  
  182.         currentHoriz = MIN(w, tileWidth);
  183.         currentVert = MIN(h, tileHeight);
  184.         switch ( alu ) {
  185.         case GXcopy:        /* 0x3 src */
  186.         case GXcopyInverted:    /* 0xc NOT src */
  187.             /* Special Case Code */
  188.             /* Draw First Tile in place then blit-replicate
  189.              * until the entire box is filled
  190.              */
  191.             tmpbox.x1 = x;
  192.             tmpbox.x2 = x + currentHoriz;
  193.             tmpbox.y1 = y;
  194.             tmpbox.y2 = y + currentVert;
  195.             apa16TileArea32(pDraw, 1, &tmpbox, alu, ptile);
  196.             apa16replicateArea(x, y, w, h,
  197.                         currentHoriz, currentVert);
  198.             continue; /* There May Be Other Boxes ! */
  199.  
  200.         /* Hard Cases Iterate over tile */
  201.         /* if possible for the easy cases use Hardware support */
  202.         case GXand:        /* 0x1 src AND dst */
  203.         case GXnor:        /* 0x8 NOT src AND NOT dst */
  204.         case GXandReverse:    /* 0x2 src AND NOT dst */
  205.         case GXandInverted:    /* 0x4 NOT src AND dst */
  206.         case GXequiv:        /* 0x9 NOT src XOR dst */
  207.         case GXxor:        /* 0x6 src XOR dst */
  208.         case GXor:        /* 0x7 src OR dst */
  209.         case GXorInverted:    /* 0xd NOT src OR dst */
  210.         case GXorReverse:    /* 0xb src OR NOT dst */
  211.         case GXnand:        /* 0xe NOT src OR NOT dst */
  212.         default:
  213.             ErrorF( "apa16TileArea: unexpected rrop" );
  214.             return;
  215.         }
  216.         /* Draw First Tile into the staging area ( off screen )
  217.          * then iterate-blit until entire box is filled
  218.          */
  219.     }
  220.     /* One copy or less of source tile */
  221.     if (psrc != apa16CurrentTileBits)
  222.       apa16StageTile32(ptile);
  223.  
  224.     iy = y % tileHeight;
  225.     ix = x % tileWidth;
  226.     h1 = MIN(tileHeight - iy, h);
  227.  
  228.     RESERVE_QUEUE(14);
  229.     APA16_GET_CMD_COPY(ROP_RECT_COPY,alu,cmd);
  230.     cmd |= EXEC_MASK;
  231.  
  232.     COPY_RECT_NOCHECK(cmd, x + w, y + h1,
  233.               APA16_STAGE_X + ix + w, APA16_STAGE_Y + iy + h1,
  234.               w, h1);
  235.  
  236.     /* Copy lower part. */
  237.     if (h > h1)
  238.       {
  239.         COPY_RECT_NOCHECK(cmd, x + w, y + h,
  240.                   APA16_STAGE_X + ix + w, APA16_STAGE_Y + h - h1,
  241.                   w, h - h1);
  242.       }
  243.     }
  244.  
  245.     return;
  246. }
  247.