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 / ppcPixmapFS.c < prev    next >
C/C++ Source or Header  |  1989-11-14  |  16KB  |  425 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. /******************************************************************
  25. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  26. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  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 names of Digital or MIT not be
  35. used in advertising or publicity pertaining to distribution of the
  36. software without specific, written prior permission.
  37.  
  38. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  39. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  40. DIGITAL 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. /* $Header: /andrew/X11/r3src/release/server/ddx/ibm/ppc/RCS/ppcPixmapFS.c,v 1.2 89/04/29 22:13:30 jeff Exp $ */
  49. /* $Source: /andrew/X11/r3src/release/server/ddx/ibm/ppc/RCS/ppcPixmapFS.c,v $ */
  50.  
  51. #ifndef lint
  52. static char *rcsid = "$Header: /andrew/X11/r3src/release/server/ddx/ibm/ppc/RCS/ppcPixmapFS.c,v 1.2 89/04/29 22:13:30 jeff Exp $" ;
  53. #endif
  54.  
  55. #include "X.h"
  56. #include "misc.h"
  57. #include "gcstruct.h"
  58. #include "window.h"
  59. #include "pixmapstr.h"
  60. #include "scrnintstr.h"
  61. #include "windowstr.h"
  62.  
  63. #include "mfb.h"
  64. #include "maskbits.h"
  65.  
  66. #include "OScompiler.h"
  67.  
  68. #include "ppc.h"
  69. #include "ppcSpMcro.h"
  70.  
  71. #include "ibmTrace.h"
  72. extern int mfbGCPrivateIndex;
  73.  
  74. #define LeftMostBitInScreenLongWord SCRLEFT( 0xFFFFFFFF, 31 )
  75. /*
  76. ********** ********** ********** ********** ********** ********** **********
  77.    these routines all clip.  they assume that anything that has called
  78. them has already translated the points (i.e. pGC->miTranslate is
  79. non-zero, which is howit gets set in mfbCreateGC().)
  80.  
  81.    the number of new scnalines created by clipping ==
  82. MaxRectsPerBand * nSpans.
  83. ********** ********** ********** ********** ********** ********** **********
  84. */
  85.  
  86. void
  87. ppcSolidPixmapFS( pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted )
  88.     DrawablePtr pDrawable ;
  89.     GCPtr    pGC ;
  90.     int        nInit ;            /* number of spans to fill */
  91.     DDXPointPtr pptInit ;        /* pointer to list of start points */
  92.     int        *pwidthInit ;        /* pointer to list of n widths */
  93.     int     fSorted ;
  94. {
  95.     register unsigned long int pm, npm ;
  96.     register unsigned long int fg ;
  97.     register int alu ;
  98.                 /* next three parameters are post-clip */
  99.     int n ;            /* number of spans to fill */
  100.     register DDXPointPtr ppt ;    /* pointer to list of start points */
  101.     register int *pwidth ;    /* pointer to list of n widths */
  102.     register unsigned char *addrl ;    /* pointer to current longword in bitmap */
  103.     int i ;
  104.     int *pwidthFree ;        /* copies of the pointers to free */
  105.     DDXPointPtr pptFree ;
  106.  
  107.     TRACE(("ppcSolidPixmapFS(pDrawable=0x%x, pGC=0x%x, nInit=%d, pptInit=0x%x, pwidthInit=0x%x, fSorted=%d)\n", pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)) ;
  108.  
  109.     if ( pDrawable->type != DRAWABLE_PIXMAP ) {
  110.     ErrorF("ppcSolidPixmapFS: drawable is not a pixmap\n") ;
  111.     return ;
  112.     }
  113.  
  114.     if ( ( alu = ( (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr )->colorRrop.alu ) == GXnoop )
  115.     return ;
  116.  
  117.     n = nInit * miFindMaxBand( ( (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr )->pCompositeClip) ;
  118.     if ( !( pwidth = (int *) ALLOCATE_LOCAL( n * sizeof( int ) ) ) )
  119.     return ;
  120.     pwidthFree = pwidth ;
  121.  
  122.     if ( !( ppt = (DDXPointRec *)
  123.         ALLOCATE_LOCAL( n * sizeof( DDXPointRec ) ) ) ) {
  124.     DEALLOCATE_LOCAL( pwidth ) ;
  125.     return ;
  126.     }
  127.     pptFree = ppt ;
  128.  
  129.     n = miClipSpans( ( (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr )->pCompositeClip,
  130.              pptInit, pwidthInit, nInit, ppt, pwidth, fSorted ) ;
  131.  
  132.     pm = ( (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr )->colorRrop.planemask ;
  133.     fg = ( (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr )->colorRrop.fgPixel ;
  134.     npm = ( ~ pm ) & ( ( 1 << pDrawable->depth ) - 1 ) ;
  135.  
  136.     for ( ; n-- ; ppt++, pwidth++ ) {
  137.         addrl = ( (unsigned char *) ( ( (PixmapPtr) pDrawable )->devPrivate.ptr ) )
  138.           + ( ppt->y * ( (int) ( ( (PixmapPtr) pDrawable )->devKind ) ) )
  139.           + ppt->x ;
  140.     for ( i = *pwidth ; i-- ; addrl++ )
  141.         {
  142.         unsigned _p;
  143.         DoRop( _p, alu, fg, *addrl );
  144.         *addrl = ( *addrl & npm ) | ( pm & _p ) ;
  145.         }
  146. #ifdef notdef /* PURDUE */
  147.         *addrl = ( *addrl & npm ) | ( pm & DoRop( alu, fg, *addrl ) ) ;
  148. #endif /* PURDUE */
  149.     }
  150.     DEALLOCATE_LOCAL( pptFree ) ;
  151.     DEALLOCATE_LOCAL( pwidthFree ) ;
  152.     return ;
  153. }
  154.  
  155. void
  156. ppcStipplePixmapFS( pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted )
  157. register DrawablePtr pDrawable ;
  158. GC *pGC ;
  159. int nInit ;            /* number of spans to fill */
  160. DDXPointPtr pptInit ;        /* pointer to list of start points */
  161. int *pwidthInit ;        /* pointer to list of n widths */
  162. int fSorted ;
  163. {
  164.     register unsigned char *pdst ; /* pointer to current word in bitmap */
  165.     register int *psrc ;        /* pointer to current word in tile */
  166.     register unsigned long int pm, npm ;
  167.     register unsigned long int fg ;
  168.     register int alu ;
  169.                 /* next three parameters are post-clip */
  170.     int n ;            /* number of spans to fill */
  171.     register DDXPointPtr ppt ;    /* pointer to list of start points */
  172.     register int *pwidth ;    /* pointer to list of n widths */
  173.     PixmapPtr    pTile ;        /* pointer to tile we want to fill with */
  174.     int        width,  x, xSrc, ySrc ;
  175.     int     tlwidth, tileWidth, *psrcT ;
  176.     int *pwidthFree ;        /* copies of the pointers to free */
  177.     DDXPointPtr pptFree ;
  178.     int xoff, count, stip, i ;
  179.  
  180.     TRACE(("ppcStipplePixmapFS(pDrawable=0x%x, pGC=0x%x, nInit=%d, pptInit=0x%x, pwidthInit=0x%x, fSorted=%d)\n",
  181.          pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted)) ;
  182.  
  183.     if ( pDrawable->type != DRAWABLE_PIXMAP ) {
  184.     ErrorF( "ppcStippleWindowFS: drawable is not a pixmap\n") ;
  185.     return ;
  186.     }
  187.     if ( pGC->stipple->drawable.depth != 1 ) {
  188.     ErrorF( "ppcStippleFS: bad depth\ntype = %d, depth = %d\n",
  189.         pDrawable->type, pGC->stipple->drawable.depth ) ;
  190.     return ;
  191.     }
  192.  
  193.     if ( ( alu = ( (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr )->colorRrop.alu ) == GXnoop )
  194.     return ;
  195.  
  196.     SETSPANPTRS( nInit, n, pwidthInit, pwidth, pptInit,
  197.         ppt, pwidthFree, pptFree, fSorted ) ;
  198.  
  199.     pm = ( (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr )->colorRrop.planemask ;
  200.     fg = ( (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr )->colorRrop.fgPixel ;
  201.  
  202.     pTile = pGC->stipple ;
  203.     tlwidth = pTile->devKind >> 2 ;
  204.  
  205.     tileWidth = pTile->drawable.width ;
  206.  
  207.     npm = ( ~ pm ) & ( ( 1 << pDrawable->depth ) - 1 ) ;
  208.  
  209.     /* this replaces rotating the stipple.  Instead, we just adjust the offset
  210.      * at which we start grabbing bits from the stipple */
  211.     xSrc = pGC->patOrg.x ;
  212.     ySrc = pGC->patOrg.y ;
  213.     while ( n-- ) {
  214.         pdst = ( (unsigned char *) ( (PixmapPtr) pDrawable )->devPrivate.ptr )
  215.          + ( ppt->y * ( (int) ( ( (PixmapPtr) pDrawable )->devKind ) ) )
  216.          + ppt->x ;
  217.         psrcT = (int *) pTile->devPrivate.ptr
  218.           + ( ( ( ppt->y - ySrc ) % pTile->drawable.height ) * tlwidth ) ;
  219.     x = ppt->x ;
  220.  
  221.     xoff = ( x + xSrc ) % tileWidth ;
  222.     psrc = psrcT + ( xoff >> 5 ) ;
  223.     for ( width = *pwidth ; width ; psrc++, width -= count ) {
  224.         if ( psrc >= ( psrcT + tlwidth ) )
  225.         psrc = psrcT ;
  226.         if ( ( psrc != ( psrcT + tlwidth - 1 ) )
  227.           || !( count = ( tileWidth & 0x1F ) ) )
  228.         count = 32 ;
  229.         if ( count > width )
  230.         count = width ;
  231.         getbits( psrc, xoff & 0x1F, count, stip ) ;
  232.         for ( i = count ; i-- ; ) {
  233.         if ( stip & LeftMostBitInScreenLongWord )
  234.             {
  235.             unsigned _p;
  236.             DoRop( _p, alu, fg, *pdst ) ;
  237.             *pdst = ( *pdst & npm ) | ( pm & _p ) ;
  238.             }
  239. #ifdef notdef /* PURDUE */
  240.             *pdst = ( *pdst & npm ) | ( pm & DoRop( alu, fg, *pdst ) ) ;
  241. #endif /* PURDUE */
  242.         pdst++ ;
  243.         stip = SCRLEFT( stip, 1 ) ;
  244.         }
  245.     }
  246.     ppt++ ;
  247.     pwidth++ ;
  248.     }
  249.     DEALLOCATE_LOCAL( pptFree ) ;
  250.     DEALLOCATE_LOCAL( pwidthFree ) ;
  251.     return ;
  252. }
  253.  
  254. void
  255. ppcOpStipplePixmapFS( pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted )
  256. DrawablePtr pDrawable ;
  257. GC *pGC ;
  258. int nInit ;            /* number of spans to fill */
  259. DDXPointPtr pptInit ;        /* pointer to list of start points */
  260. int *pwidthInit ;        /* pointer to list of n widths */
  261. int fSorted ;
  262. {
  263.     register unsigned char *pdst ;    /* pointer to current word in bitmap */
  264.     register unsigned long int pm, npm ;
  265.     register unsigned long int fg, bg ;
  266.     register int alu ;
  267.                 /* next three parameters are post-clip */
  268.     int n ;            /* number of spans to fill */
  269.     register DDXPointPtr ppt ;    /* pointer to list of start points */
  270.     register int *pwidth ;    /* pointer to list of n widths */
  271.     register int *psrc ;    /* pointer to current word in tile */
  272.     PixmapPtr pTile ;        /* pointer to tile we want to fill with */
  273.     int    width ;
  274.     int tlwidth, tileWidth, *psrcT ;
  275.     int *pwidthFree ;        /* copies of the pointers to free */
  276.     DDXPointPtr pptFree ;
  277.     int xoff, count, stip, i ;
  278.  
  279.     TRACE( ( "ppcOpStipplePixmapFS(pDrawable=0x%x,pGC=0x%x,nInit=%d,pptInit=0x%x,pwidthInit=0x%x,fSorted=%d)\n",
  280.        pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted ) ) ;
  281.  
  282.     if ( pGC->stipple->drawable.depth != 1 ) {
  283.     ErrorF( "ppcOpStipplePixmapFS: bad depth\ntype = %d, depth = %d\n",
  284.         pDrawable->type, pGC->stipple->drawable.depth ) ;
  285.     return ;
  286.     }
  287.  
  288.     if ( ( alu = ( (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr )->colorRrop.alu ) == GXnoop )
  289.     return ;
  290.  
  291.     SETSPANPTRS( nInit, n, pwidthInit, pwidth, pptInit,
  292.          ppt, pwidthFree, pptFree, fSorted ) ;
  293.  
  294.     fg = ( (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr )->colorRrop.fgPixel ;
  295.     bg = ( (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr )->colorRrop.bgPixel ;
  296.     pm = ( (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr )->colorRrop.planemask ;
  297.     npm = ( ~ pm ) & ( ( 1 << pDrawable->depth ) - 1 ) ;
  298.  
  299.     pTile = pGC->stipple ;
  300.     tlwidth = pTile->devKind >> 2 ;
  301.     tileWidth = pTile->drawable.width ;
  302.  
  303.     /* this replaces rotating the stipple.  Instead, we just adjust the offset
  304.      * at which we start grabbing bits from the stipple */
  305.     for ( ; n-- ; ppt++, pwidth++ ) {
  306.         pdst = ( (unsigned char *) ( (PixmapPtr) pDrawable )->devPrivate.ptr )
  307.          + ( ppt->y * ( (int) ( (PixmapPtr) pDrawable )->devKind ) )
  308.          + ppt->x ;
  309.         psrcT = (int *) pTile->devPrivate.ptr
  310.           + ( ( ( ppt->y - pGC->patOrg.y ) % pTile->drawable.height ) * tlwidth ) ;
  311.  
  312.     xoff = ( ppt->x + pGC->patOrg.x ) % tileWidth ;
  313.     psrc = psrcT + ( xoff >> 5 ) ;
  314.     for ( width = *pwidth ; width ; psrc++, width -= count ) {
  315.         if ( psrc >= ( psrcT + tlwidth ) )
  316.         psrc = psrcT ;
  317.         if ( ( psrc != ( psrcT + tlwidth - 1 ) )
  318.          || !( count = tileWidth & 0x1F ) )
  319.             count = 32 ;
  320.         if ( count > width )
  321.         count = width ;
  322.         getbits( psrc, xoff & 0x1F, count, stip ) ;
  323.         for ( i = count ; i-- ; pdst++, stip = SCRLEFT( stip, 1 ) )
  324.         if ( stip & LeftMostBitInScreenLongWord )
  325.             {
  326.             unsigned _p;
  327.             DoRop( _p, alu, fg, *pdst ) ;
  328.             *pdst = ( *pdst & npm ) | ( pm & _p ) ;
  329.             }
  330. #ifdef notdef /* PURDUE */
  331.             *pdst = ( *pdst & npm ) | ( pm & DoRop( alu, fg, *pdst ) ) ;
  332. #endif /* PURDUE */
  333.         else
  334.             {
  335.             unsigned _p;
  336.             DoRop( _p, alu, bg, *pdst ) ;
  337.             *pdst = ( *pdst & npm ) | ( pm & _p ) ;
  338.             }
  339. #ifdef notdef /* PURDUE */
  340.             *pdst = ( *pdst & npm ) | ( pm & DoRop( alu, bg, *pdst ) ) ;
  341. #endif /* PURDUE */
  342.     }
  343.     }
  344.     DEALLOCATE_LOCAL( pptFree ) ;
  345.     DEALLOCATE_LOCAL( pwidthFree ) ;
  346.     return ;
  347. }
  348.  
  349. void
  350. ppcTilePixmapFS( pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted )
  351. register DrawablePtr pDrawable ;
  352. GC *pGC ;
  353. int nInit ;            /* number of spans to fill */
  354. DDXPointPtr pptInit ;        /* pointer to list of start points */
  355. int *pwidthInit ;        /* pointer to list of n widths */
  356. int fSorted ;
  357. {
  358.     register DDXPointPtr ppt ;    /* pointer to list of start points */
  359.     register int *pwidth ;    /* pointer to list of n widths */
  360.     register unsigned char *pdst ;    /* pointer to current word in bitmap */
  361.     register unsigned char *psrc ;    /* pointer to current word in tile */
  362.     register PixmapPtr pTile ;    /* pointer to tile we want to fill with */
  363.     int i ;
  364.     int alu ;
  365.     unsigned char pm, npm ;
  366.                 /* next three parameters are post-clip */
  367.     int n ;            /* number of spans to fill */
  368.     int tileWidth ;
  369.     unsigned char *psrcT ;
  370.     int *pwidthFree ;        /* copies of the pointers to free */
  371.     DDXPointPtr pptFree ;
  372.  
  373.     TRACE( ( "ppcTileFS(pDrawable=0x%x,pGC=0x%x,nInit=%d,pptInit=0x%x,pwidthInit=0x%x,fSorted=%d)\n",
  374.         pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted ) ) ;
  375.  
  376.     if ( ( pDrawable->depth == 1 ) && ( pDrawable->type == DRAWABLE_PIXMAP ) ) {
  377.     mfbTileFS( pDrawable, pGC, nInit, pptInit, pwidthInit, fSorted ) ;
  378.     return ;
  379.     }
  380.     if ( !ppcDepthOK( pDrawable, pGC->tile.pixmap->drawable.depth ) ) {
  381.     ErrorF( "ppcTileFS: bad depth\ntype = %d, depth = %d\n",
  382.         pDrawable->type, pDrawable->depth) ;
  383.     return ;
  384.     }
  385.  
  386.     if ( ( alu = ( (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr )->colorRrop.alu ) == GXnoop )
  387.     return ;
  388.  
  389.     SETSPANPTRS( nInit, n, pwidthInit, pwidth, pptInit,
  390.          ppt, pwidthFree, pptFree, fSorted ) ;
  391.  
  392.     /* the following code is for 8 bits per pixel addressable memory only */
  393.     pm = ( (ppcPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr )->colorRrop.planemask ;
  394.     npm = ( ~ pm ) & ( ( 1 << pDrawable->depth ) - 1 ) ;
  395.     pTile = pGC->tile.pixmap ;
  396.     tileWidth = pTile->drawable.width ;
  397.  
  398.     /* this replaces rotating the tile. Instead we just adjust the offset
  399.      * at which we start grabbing bits from the tile */
  400.     for ( ; n-- ; ppt++, pwidth++ ) {
  401.         pdst = ( (unsigned char *) ( (PixmapPtr) pDrawable )->devPrivate.ptr )
  402.          + ( ppt->y * ( (int) ( (PixmapPtr) pDrawable )->devKind ) )
  403.          + ppt->x ;
  404.         psrcT = (unsigned char *) pTile->devPrivate.ptr
  405.       + ( ( ( ppt->y - pGC->patOrg.y ) % pTile->drawable.height ) * pTile->devKind ) ;
  406.  
  407.     psrc = psrcT + ( ( pGC->patOrg.x + ppt->x ) % tileWidth ) ;
  408.     for ( i = *pwidth ; i-- ; pdst++, psrc++ ) {
  409.         if ( psrc >= ( psrcT + tileWidth ) )
  410.         psrc = psrcT ;
  411.         {
  412.         unsigned _p;
  413.         DoRop( _p, alu, *psrc, *pdst ) ;
  414.         *pdst = ( *pdst & npm ) | ( pm & _p ) ;
  415.         }
  416. #ifdef notdef /* PURDUE */
  417.         *pdst = ( *pdst & npm ) | ( pm & DoRop( alu, *psrc, *pdst ) ) ;
  418. #endif /* PURDUE */
  419.     }
  420.     }
  421.     DEALLOCATE_LOCAL( pptFree ) ;
  422.     DEALLOCATE_LOCAL( pwidthFree ) ;
  423.     return ;
  424. }
  425.