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 / mpelPoly.c < prev    next >
C/C++ Source or Header  |  1991-01-10  |  11KB  |  430 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: /afs/rel-eng.athena.mit.edu/project/release/current/source/third/common/X11R4/server/ddx/ibm/mpel/RCS/mpelPoly.c,v 1.2 91/01/10 15:20:16 jfc Exp $ */
  47. /* $Source: /afs/rel-eng.athena.mit.edu/project/release/current/source/third/common/X11R4/server/ddx/ibm/mpel/RCS/mpelPoly.c,v $ */
  48.  
  49. #ifndef lint
  50. static char *rcsid = "$Header: /afs/rel-eng.athena.mit.edu/project/release/current/source/third/common/X11R4/server/ddx/ibm/mpel/RCS/mpelPoly.c,v 1.2 91/01/10 15:20:16 jfc Exp $";
  51. #endif
  52.  
  53. /* 
  54.  * solid polygon fill
  55.  */
  56.  
  57. #include     "X.h"
  58. #include        "misc.h"
  59. #include        "gcstruct.h"
  60. #include        "windowstr.h"
  61. #include        "scrnintstr.h"
  62. #include    "region.h"
  63. #include        "regionstr.h"
  64.  
  65. #include        "OScompiler.h"
  66. #include        "ppc.h"
  67.  
  68. #include        "ibmTrace.h"
  69.  
  70. #include    "mpel.h"
  71. #include    "mpelHdwr.h"
  72. #include    "mpelFifo.h"
  73.  
  74. /* Cursor Stuff */
  75. extern int mpelcursorSemaphore ;
  76. extern int mpelCheckCursor() ;
  77. extern void mpelReplaceCursor() ;
  78.  
  79. /***==================================================================***/
  80.  
  81. void
  82. mpelFillPolygon(pDraw, pGC, shape, mode, count, pPts)
  83.     DrawablePtr        pDraw;
  84.     GCPtr        pGC;
  85.     int            shape, mode;
  86.     int            count;
  87.     DDXPointPtr        pPts;
  88. {
  89.     int cursor_saved ;
  90.     RegionPtr        pCC;
  91.     int            nbox;
  92.     int            i;
  93.     BoxRec        *pbox,bbox;
  94.     mpelRectangle    scissor;
  95.     DDXPointPtr        ppt;
  96.     int            scissorOn,allIn;
  97.     unsigned long int    fg ;
  98.     unsigned long int    pm ;
  99.     int            alu ;
  100.     ppcPrivGC        *pPriv = (ppcPrivGC *)pGC->devPrivates[mfbGCPrivateIndex].ptr;
  101.  
  102.  
  103.     TRACE(("mpelFillPolygon( pDraw=x%x, pGC=x%x, count=%d, pPts=x%x )\n",
  104.                         pDraw, pGC, count, pPts));
  105.  
  106.     if (count == 0)
  107.      return;
  108.  
  109.     if ( ( alu = pPriv->colorRrop.alu ) == GXnoop )
  110.     return ;
  111.     pm = pPriv->colorRrop.planemask ;
  112.     fg = pPriv->colorRrop.fgPixel ;
  113.     if ((pDraw->type != DRAWABLE_WINDOW)||(pGC->fillStyle!=FillSolid)) {
  114.     ErrorF("WSGO! bad call to mpelFillPolygon\n");
  115.     ErrorF("\tpDraw->type = %d =? %d\n",pDraw->type, DRAWABLE_WINDOW);
  116.     ErrorF("\tpGC->fillStyle = %d =? %d\n",pGC->fillStyle, FillSolid);
  117.     miFillPolygon(pDraw, pGC, shape, mode, count, pPts);
  118.     return;
  119.     }
  120.  
  121.     if (mode == CoordModePrevious) {
  122.     ppt = &pPts[1];
  123.     for (i = 1; i<count; i++) {
  124.         ppt->x += (ppt-1)->x;
  125.         ppt->y += (ppt-1)->y;
  126.         ppt++;
  127.     }
  128.     }
  129.  
  130.     pCC = pPriv->pCompositeClip;
  131.     nbox= REGION_NUM_RECTS(pCC);
  132.     if (nbox==0)
  133.     return;
  134.  
  135.     bbox.x1= bbox.y1= 1024;
  136.     bbox.x2= bbox.y2= 0;
  137.  
  138.     for (i=0;i<count;i++) {
  139.     pPts[i].x+= pDraw->x;
  140.     pPts[i].y+= pDraw->y;
  141.     bbox.x1= MIN(bbox.x1,pPts[i].x);
  142.     bbox.y1= MIN(bbox.y1,pPts[i].y);
  143.     bbox.x2= MAX(bbox.x2,pPts[i].x);
  144.     bbox.y2= MAX(bbox.y2,pPts[i].y);
  145.     pPts[i].y= 1023-pPts[i].y;
  146.     }
  147.  
  148.     /* If Cursor Is In The Way Remove It */
  149.     cursor_saved = !mpelcursorSemaphore
  150.             && mpelCheckCursor( bbox.x1, bbox.y1,
  151.                     bbox.x2-bbox.x1, bbox.y2-bbox.y1 ) ;
  152.  
  153.     MPELSetPgonEdgeColor( fg );
  154.     MPELSetPgonEdgeFlag(DRAW_EDGE);
  155.     MPELSetPgonInteriorColor( fg );
  156.     MPELSetPgonInteriorStyle(2);
  157.     mpelSetALU( alu );
  158.     mpelSetPlaneMask( pm );
  159.  
  160.     allIn= scissorOn= FALSE;
  161.  
  162.     pbox = REGION_RECTS(pCC);
  163.     for (i=0;(i<nbox)&&(!allIn);i++,pbox++) {
  164.     switch (mpelRectIntersect(pbox,&bbox)) {
  165.         case rgnOUT:    continue;
  166.         case rgnPART:    scissor.uright.x=     pbox->x2-1;
  167.                 scissor.uright.y=     1023-pbox->y1;
  168.                 scissor.lleft.x=      pbox->x1;
  169.                 scissor.lleft.y=    1023-(pbox->y2-1);
  170.                 MPELSetScissor(&scissor);
  171.                 scissorOn= TRUE;
  172.                 break;
  173.         case rgnIN:        allIn= TRUE;
  174.                 if (scissorOn)  {
  175.                     MPELResetScissor();
  176.                     scissorOn= FALSE;
  177.                 }
  178.                 break;
  179.     }
  180. #ifdef AIXrt
  181.     if (shape==Convex) {
  182.         if ((pPts[0].x==pPts[count-1].x)&&(pPts[0].y==pPts[count-1].y)) {
  183.         MPELConvexPoly(count,pPts);
  184.         }
  185.         else {
  186.         MPELOpenConvexPoly(count,pPts);
  187.         MPELCloseConvexPoly(&pPts[0]);
  188.         }
  189.         continue;
  190.     }
  191. #endif
  192.     MPELBeginPgon();
  193.         MPELPolyline(count,pPts);
  194.         MPELEndPgon();
  195.     }
  196.     if (scissorOn)
  197.     MPELResetScissor();
  198.  
  199.     if ( cursor_saved )
  200.     mpelReplaceCursor() ;
  201.  
  202.     return ;
  203. }
  204.  
  205.  
  206. /* 
  207.  * Tiled polygon fill
  208.  * Paquin 5/16/88, plagiarized above solid fill with user pattern for tile.
  209.  * Only works on tiles which can expand to 16x16
  210.  */
  211.  
  212. void
  213. mpelTilePolygon(pDraw, pGC, shape, mode, count, pPts)
  214.     DrawablePtr        pDraw;
  215.     GCPtr        pGC;
  216.     int            shape, mode;
  217.     int            count;
  218.     DDXPointPtr        pPts;
  219. {
  220.     int cursor_saved ;
  221.     RegionPtr        pCC;
  222.     int            nbox;
  223.     int            i;
  224.     BoxRec        *pbox,bbox;
  225.     mpelRectangle    scissor;
  226.     DDXPointPtr        ppt;
  227.     int            scissorOn,allIn;
  228.     unsigned long int    fg ;
  229.     unsigned long int    pm ;
  230.     int            alu ;
  231.     int            expand_w, expand_h;
  232.     ppcPrivGC        *pPriv = (ppcPrivGC *)pGC->devPrivates[mfbGCPrivateIndex].ptr;
  233.  
  234.  
  235.     TRACE(("mpelTilePolygon( pDraw=x%x, pGC=x%x, count=%d, pPts=x%x )\n",
  236.                         pDraw, pGC, count, pPts));
  237.  
  238.     if (count == 0)
  239.      return;
  240.  
  241.     if ( ( alu = pPriv->colorRrop.alu ) == GXnoop )
  242.     return ;
  243.     pm = pPriv->colorRrop.planemask ;
  244.     fg = pPriv->colorRrop.fgPixel ;
  245.  
  246.     if (
  247.     (pDraw->type != DRAWABLE_WINDOW) ||    
  248.     (pGC->fillStyle!=FillTiled)    
  249.     ) {
  250.     ErrorF("WSGO! bad call to mpelTilePolygon\n");
  251.     miFillPolygon(pDraw, pGC, shape, mode, count, pPts);
  252.     return;
  253.     }
  254.  
  255.     switch(pGC->tile.pixmap->drawable.width)
  256.     {
  257.     case 1:    
  258.         expand_w = 16; break;
  259.     case 2:     
  260.         expand_w = 8; break;
  261.     case 4:     
  262.         expand_w = 4; break;
  263.     case 8:     
  264.         expand_w = 2; break;
  265.     case 16:    
  266.         expand_w = 1; break;
  267.     default:
  268.         miFillPolygon(pDraw, pGC, shape, mode, count, pPts);
  269.         return;
  270.     }
  271.  
  272.     switch(pGC->tile.pixmap->drawable.height)
  273.     {
  274.     case 1:    
  275.         expand_h = 16; break;
  276.     case 2:     
  277.         expand_h = 8; break;
  278.     case 4:     
  279.         expand_h = 4; break;
  280.     case 8:     
  281.         expand_h = 2; break;
  282.     case 16:    
  283.         expand_h = 1; break;
  284.     default:
  285.         miFillPolygon(pDraw, pGC, shape, mode, count, pPts);
  286.         return;
  287.     }
  288.  
  289.     if (mode == CoordModePrevious) {
  290.     ppt = &pPts[1];
  291.     for (i = 1; i<count; i++) {
  292.         ppt->x += (ppt-1)->x;
  293.         ppt->y += (ppt-1)->y;
  294.         ppt++;
  295.     }
  296.     }
  297.  
  298.     pCC = pPriv->pCompositeClip;
  299.     nbox= REGION_NUM_RECTS(pCC);
  300.     if (nbox==0)
  301.     return;
  302.  
  303.     bbox.x1= bbox.y1= 1024;
  304.     bbox.x2= bbox.y2= 0;
  305.  
  306.     for (i=0;i<count;i++) {
  307.     pPts[i].x+= pDraw->x;
  308.     pPts[i].y+= pDraw->y;
  309.     bbox.x1= MIN(bbox.x1,pPts[i].x);
  310.     bbox.y1= MIN(bbox.y1,pPts[i].y);
  311.     bbox.x2= MAX(bbox.x2,pPts[i].x);
  312.     bbox.y2= MAX(bbox.y2,pPts[i].y);
  313.     pPts[i].y= 1023-pPts[i].y;
  314.     }
  315.  
  316.     /* If Cursor Is In The Way Remove It */
  317.     cursor_saved = !mpelcursorSemaphore
  318.             && mpelCheckCursor( bbox.x1, bbox.y1,
  319.                     bbox.x2-bbox.x1, bbox.y2-bbox.y1 ) ;
  320.  
  321.     MPELSetPgonEdgeColor( fg );
  322.     MPELSetPgonEdgeFlag(DONT_DRAW_EDGE);
  323.     MPELSetPgonInteriorStyle(3);
  324.     MPELSetPgonInteriorStyleIndex(1);
  325.     mpelSetALU( alu );
  326.     mpelSetPlaneMask( pm );
  327.  
  328.     {/* SET THE PATTERN IN MPEL PATTERN AREA */
  329.     register unsigned char *data = (unsigned char *)MPEL_PAT1;
  330.     register unsigned char *src;
  331.     register int tile_row, iw;
  332.     int pix, tlx, tly;
  333.     PixmapRec *pTile;
  334.     int xSrc, ySrc, hoffset, voffset;
  335.  
  336.     pTile = pGC->tile.pixmap;
  337.     tlx = pTile->drawable.width;
  338.     tly = pTile->drawable.height;
  339.  
  340.     xSrc = pGC->patOrg.x + pDraw->x;
  341.     ySrc = pGC->patOrg.y + pDraw->y;
  342.  
  343.     if ((hoffset = ((-xSrc)%tlx)) < 0) hoffset += tlx;
  344.     if ((voffset = ((-ySrc)%tly)) < 0) voffset += tly;
  345.  
  346.     while (expand_h--)
  347.     {
  348.     src = pTile->devPrivate.ptr + (voffset * pTile->devKind);
  349.     for (tile_row = voffset; tile_row < tly; tile_row++)
  350.         {
  351.         for(iw = 0; iw< expand_w; iw++) 
  352.             {
  353.             for (pix = hoffset; pix < tlx; pix++)
  354.                 {
  355.                 *data++ = src[pix];
  356.                 }
  357.             for (pix = 0; pix < hoffset; pix++)
  358.                 {
  359.                 *data++ = src[pix];
  360.                 }
  361.             }
  362.         src += pTile->devKind;
  363.         }
  364.  
  365.     src = pTile->devPrivate.ptr;
  366.     for (tile_row = 0; tile_row < voffset; tile_row++)
  367.         {
  368.         for(iw = 0; iw< expand_w; iw++) 
  369.             {
  370.             for (pix = hoffset; pix < tlx; pix++)
  371.                 {
  372.                 *data++ = src[pix];
  373.                 }
  374.             for (pix = 0; pix < hoffset; pix++)
  375.                 {
  376.                 *data++ = src[pix];
  377.                 }
  378.             }
  379.         src += pTile->devKind;
  380.         }
  381.     }
  382.     }
  383.  
  384.  
  385.     allIn= scissorOn= FALSE;
  386.  
  387.     pbox = REGION_RECTS(pCC);
  388.     for (i=0;(i<nbox)&&(!allIn);i++,pbox++) {
  389.     switch (mpelRectIntersect(pbox,&bbox)) {
  390.         case rgnOUT:    continue;
  391.         case rgnPART:    scissor.uright.x=     pbox->x2-1;
  392.                 scissor.uright.y=     1023-pbox->y1;
  393.                 scissor.lleft.x=      pbox->x1;
  394.                 scissor.lleft.y=    1023-(pbox->y2-1);
  395.                 MPELSetScissor(&scissor);
  396.                 scissorOn= TRUE;
  397.                 break;
  398.         case rgnIN:        allIn= TRUE;
  399.                 if (scissorOn)  {
  400.                     MPELResetScissor();
  401.                     scissorOn= FALSE;
  402.                 }
  403.                 break;
  404.     }
  405. #ifdef AIXrt
  406.     if (shape==Convex) {
  407.         if ((pPts[0].x==pPts[count-1].x)&&(pPts[0].y==pPts[count-1].y)) {
  408.         MPELConvexPoly(count,pPts);
  409.         }
  410.         else {
  411.         MPELOpenConvexPoly(count,pPts);
  412.         MPELCloseConvexPoly(&pPts[0]);
  413.         }
  414.         continue;
  415.     }
  416. #endif
  417.     MPELBeginPgon();
  418.         MPELPolyline(count,pPts);
  419.         MPELEndPgon();
  420.     }
  421.     if (scissorOn)
  422.     MPELResetScissor();
  423.  
  424.     MPELResetPlaneMask();
  425.     if ( cursor_saved )
  426.     mpelReplaceCursor() ;
  427.  
  428.     return ;
  429. }
  430.