home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / server / ddx / cfb / cfbgc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-18  |  21.5 KB  |  955 lines

  1. /***********************************************************
  2. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  3. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.                         All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its 
  8. documentation for any purpose and without fee is hereby granted, 
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in 
  11. supporting documentation, and that the names of Digital or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.  
  14.  
  15. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ******************************************************************/
  24.  
  25. /* $XConsortium: cfbgc.c,v 5.51 91/07/18 23:36:42 keith Exp $ */
  26.  
  27. #include "X.h"
  28. #include "Xmd.h"
  29. #include "Xproto.h"
  30. #include "cfb.h"
  31. #include "fontstruct.h"
  32. #include "dixfontstr.h"
  33. #include "gcstruct.h"
  34. #include "windowstr.h"
  35. #include "pixmapstr.h"
  36. #include "scrnintstr.h"
  37. #include "region.h"
  38.  
  39. #include "mistruct.h"
  40. #include "mibstore.h"
  41.  
  42. #include "cfbmskbits.h"
  43. #include "cfb8bit.h"
  44.  
  45. void cfbValidateGC(), cfbChangeGC(), cfbCopyGC(), cfbDestroyGC();
  46. void cfbChangeClip(), cfbDestroyClip(), cfbCopyClip();
  47.  
  48. GCFuncs cfbGCFuncs = {
  49.     cfbValidateGC,
  50.     cfbChangeGC,
  51.     cfbCopyGC,
  52.     cfbDestroyGC,
  53.     cfbChangeClip,
  54.     cfbDestroyClip,
  55.     cfbCopyClip,
  56. };
  57.  
  58. GCOps    cfbTEOps1Rect = {
  59.     cfbSolidSpansCopy,
  60.     cfbSetSpans,
  61.     cfbPutImage,
  62.     cfbCopyArea,
  63.     cfbCopyPlane,
  64.     cfbPolyPoint,
  65. #if PPW == 4
  66.     cfb8LineSS1Rect,
  67.     cfb8SegmentSS1Rect,
  68. #else
  69.     cfbLineSS,
  70.     cfbSegmentSS,
  71. #endif
  72.     miPolyRectangle,
  73. #if PPW == 4
  74.     cfbZeroPolyArcSS8Copy,
  75. #else
  76.     miZeroPolyArc,
  77. #endif
  78.     cfbFillPoly1RectCopy,
  79.     cfbPolyFillRect,
  80.     cfbPolyFillArcSolidCopy,
  81.     miPolyText8,
  82.     miPolyText16,
  83.     miImageText8,
  84.     miImageText16,
  85. #if PPW == 4
  86.     cfbTEGlyphBlt8,
  87.     cfbPolyGlyphBlt8,
  88.     cfbPushPixels8,
  89. #else
  90.     cfbTEGlyphBlt,
  91.     miPolyGlyphBlt,
  92.     mfbPushPixels,
  93. #endif
  94.     NULL,
  95. };
  96.  
  97. GCOps    cfbTEOps = {
  98.     cfbSolidSpansCopy,
  99.     cfbSetSpans,
  100.     cfbPutImage,
  101.     cfbCopyArea,
  102.     cfbCopyPlane,
  103.     cfbPolyPoint,
  104.     cfbLineSS,
  105.     cfbSegmentSS,
  106.     miPolyRectangle,
  107. #if PPW == 4
  108.     cfbZeroPolyArcSS8Copy,
  109. #else
  110.     miZeroPolyArc,
  111. #endif
  112.     miFillPolygon,
  113.     cfbPolyFillRect,
  114.     cfbPolyFillArcSolidCopy,
  115.     miPolyText8,
  116.     miPolyText16,
  117.     miImageText8,
  118.     miImageText16,
  119. #if PPW == 4
  120.     cfbTEGlyphBlt8,
  121.     cfbPolyGlyphBlt8,
  122.     cfbPushPixels8,
  123. #else
  124.     cfbTEGlyphBlt,
  125.     miPolyGlyphBlt,
  126.     mfbPushPixels,
  127. #endif
  128.     NULL,
  129. };
  130.  
  131. GCOps    cfbNonTEOps1Rect = {
  132.     cfbSolidSpansCopy,
  133.     cfbSetSpans,
  134.     cfbPutImage,
  135.     cfbCopyArea,
  136.     cfbCopyPlane,
  137.     cfbPolyPoint,
  138. #if PPW == 4
  139.     cfb8LineSS1Rect,
  140.     cfb8SegmentSS1Rect,
  141. #else
  142.     cfbLineSS,
  143.     cfbSegmentSS,
  144. #endif
  145.     miPolyRectangle,
  146. #if PPW == 4
  147.     cfbZeroPolyArcSS8Copy,
  148. #else
  149.     miZeroPolyArc,
  150. #endif
  151.     cfbFillPoly1RectCopy,
  152.     cfbPolyFillRect,
  153.     cfbPolyFillArcSolidCopy,
  154.     miPolyText8,
  155.     miPolyText16,
  156.     miImageText8,
  157.     miImageText16,
  158.     cfbImageGlyphBlt8,
  159.     cfbPolyGlyphBlt8,
  160.     cfbPushPixels8,
  161.     NULL,
  162. };
  163.  
  164. GCOps    cfbNonTEOps = {
  165.     cfbSolidSpansCopy,
  166.     cfbSetSpans,
  167.     cfbPutImage,
  168.     cfbCopyArea,
  169.     cfbCopyPlane,
  170.     cfbPolyPoint,
  171.     cfbLineSS,
  172.     cfbSegmentSS,
  173.     miPolyRectangle,
  174. #if PPW == 4
  175.     cfbZeroPolyArcSS8Copy,
  176. #else
  177.     miZeroPolyArc,
  178. #endif
  179.     miFillPolygon,
  180.     cfbPolyFillRect,
  181.     cfbPolyFillArcSolidCopy,
  182.     miPolyText8,
  183.     miPolyText16,
  184.     miImageText8,
  185.     miImageText16,
  186. #if PPW == 4
  187.     cfbImageGlyphBlt8,
  188.     cfbPolyGlyphBlt8,
  189.     cfbPushPixels8,
  190. #else
  191.     miImageGlyphBlt,
  192.     miPolyGlyphBlt,
  193.     mfbPushPixels,
  194. #endif
  195.     NULL,
  196. };
  197.  
  198. GCOps *
  199. cfbMatchCommon (pGC, devPriv)
  200.     GCPtr        pGC;
  201.     cfbPrivGCPtr    devPriv;
  202. {
  203.     if (pGC->lineWidth != 0)
  204.     return 0;
  205.     if (pGC->lineStyle != LineSolid)
  206.     return 0;
  207.     if (pGC->fillStyle != FillSolid)
  208.     return 0;
  209.     if (devPriv->rop != GXcopy)
  210.     return 0;
  211.     if (pGC->font &&
  212.     FONTMAXBOUNDS(pGC->font,rightSideBearing) -
  213.         FONTMINBOUNDS(pGC->font,leftSideBearing) <= 32 &&
  214.     FONTMINBOUNDS(pGC->font,characterWidth) >= 0)
  215.     {
  216.     if (TERMINALFONT(pGC->font)
  217. #if PPW == 4
  218.         && FONTMAXBOUNDS(pGC->font,characterWidth) >= 4
  219. #endif
  220.     )
  221.         if (devPriv->oneRect)
  222.         return &cfbTEOps1Rect;
  223.         else
  224.         return &cfbTEOps;
  225.     else
  226.         if (devPriv->oneRect)
  227.         return &cfbNonTEOps1Rect;
  228.         else
  229.         return &cfbNonTEOps;
  230.     }
  231.     return 0;
  232. }
  233.  
  234. Bool
  235. cfbCreateGC(pGC)
  236.     register GCPtr pGC;
  237. {
  238.     cfbPrivGC  *pPriv;
  239.  
  240.     if (pGC->depth == 1)
  241.     return (mfbCreateGC(pGC));
  242.     pGC->clientClip = NULL;
  243.     pGC->clientClipType = CT_NONE;
  244.  
  245.     /*
  246.      * some of the output primitives aren't really necessary, since they
  247.      * will be filled in ValidateGC because of dix/CreateGC() setting all
  248.      * the change bits.  Others are necessary because although they depend
  249.      * on being a color frame buffer, they don't change 
  250.      */
  251.  
  252.     pGC->ops = &cfbNonTEOps;
  253.     pGC->funcs = &cfbGCFuncs;
  254.  
  255.     /* cfb wants to translate before scan conversion */
  256.     pGC->miTranslate = 1;
  257.  
  258.     pPriv = (cfbPrivGC *)(pGC->devPrivates[cfbGCPrivateIndex].ptr);
  259.     pPriv->rop = pGC->alu;
  260.     pPriv->oneRect = FALSE;
  261.     pPriv->fExpose = TRUE;
  262.     pPriv->freeCompClip = FALSE;
  263.     pPriv->pRotatedPixmap = (PixmapPtr) NULL;
  264.     return TRUE;
  265. }
  266.  
  267. /*ARGSUSED*/
  268. void
  269. cfbChangeGC(pGC, mask)
  270.     GC            *pGC;
  271.     BITS32        mask;
  272. {
  273.     return;
  274. }
  275.  
  276. void
  277. cfbDestroyGC(pGC)
  278.     GC             *pGC;
  279. {
  280.     cfbPrivGC *pPriv;
  281.  
  282.     pPriv = (cfbPrivGC *)(pGC->devPrivates[cfbGCPrivateIndex].ptr);
  283.     if (pPriv->pRotatedPixmap)
  284.     cfbDestroyPixmap(pPriv->pRotatedPixmap);
  285.     if (pPriv->freeCompClip)
  286.     (*pGC->pScreen->RegionDestroy)(pPriv->pCompositeClip);
  287.     cfbDestroyOps (pGC->ops);
  288. }
  289.  
  290. /*
  291.  * create a private op array for a gc
  292.  */
  293.  
  294. GCOps *
  295. cfbCreateOps (prototype)
  296.     GCOps    *prototype;
  297. {
  298.     GCOps    *ret;
  299.     extern Bool    Must_have_memory;
  300.  
  301.     /* XXX */ Must_have_memory = TRUE;
  302.     ret = (GCOps *) xalloc (sizeof(GCOps));
  303.     /* XXX */ Must_have_memory = FALSE;
  304.     if (!ret)
  305.     return 0;
  306.     *ret = *prototype;
  307.     ret->devPrivate.val = 1;
  308.     return ret;
  309. }
  310.  
  311. cfbDestroyOps (ops)
  312.     GCOps   *ops;
  313. {
  314.     if (ops->devPrivate.val)
  315.     xfree (ops);
  316. }
  317.  
  318. /* Clipping conventions
  319.     if the drawable is a window
  320.         CT_REGION ==> pCompositeClip really is the composite
  321.         CT_other ==> pCompositeClip is the window clip region
  322.     if the drawable is a pixmap
  323.         CT_REGION ==> pCompositeClip is the translated client region
  324.         clipped to the pixmap boundary
  325.         CT_other ==> pCompositeClip is the pixmap bounding box
  326. */
  327.  
  328. void
  329. cfbValidateGC(pGC, changes, pDrawable)
  330.     register GCPtr  pGC;
  331.     Mask        changes;
  332.     DrawablePtr        pDrawable;
  333. {
  334.     WindowPtr   pWin;
  335.     int         mask;        /* stateChanges */
  336.     int         index;        /* used for stepping through bitfields */
  337.     int        new_rrop;
  338.     int         new_line, new_text, new_fillspans, new_fillarea;
  339.     int        new_rotate;
  340.     int        xrot, yrot;
  341.     /* flags for changing the proc vector */
  342.     cfbPrivGCPtr devPriv;
  343.     int        oneRect;
  344.  
  345.     new_rotate = pGC->lastWinOrg.x != pDrawable->x ||
  346.          pGC->lastWinOrg.y != pDrawable->y;
  347.  
  348.     pGC->lastWinOrg.x = pDrawable->x;
  349.     pGC->lastWinOrg.y = pDrawable->y;
  350.     if (pDrawable->type == DRAWABLE_WINDOW)
  351.     {
  352.     pWin = (WindowPtr) pDrawable;
  353.     }
  354.     else
  355.     {
  356.     pWin = (WindowPtr) NULL;
  357.     }
  358.  
  359.     devPriv = ((cfbPrivGCPtr) (pGC->devPrivates[cfbGCPrivateIndex].ptr));
  360.  
  361.     new_rrop = FALSE;
  362.     new_line = FALSE;
  363.     new_text = FALSE;
  364.     new_fillspans = FALSE;
  365.     new_fillarea = FALSE;
  366.  
  367.     /*
  368.      * if the client clip is different or moved OR the subwindowMode has
  369.      * changed OR the window's clip has changed since the last validation
  370.      * we need to recompute the composite clip 
  371.      */
  372.  
  373.     if ((changes & (GCClipXOrigin|GCClipYOrigin|GCClipMask|GCSubwindowMode)) ||
  374.     (pDrawable->serialNumber != (pGC->serialNumber & DRAWABLE_SERIAL_BITS))
  375.     )
  376.     {
  377.     ScreenPtr pScreen = pGC->pScreen;
  378.  
  379.     if (pWin) {
  380.         RegionPtr   pregWin;
  381.         Bool        freeTmpClip, freeCompClip;
  382.  
  383.         if (pGC->subWindowMode == IncludeInferiors) {
  384.         pregWin = NotClippedByChildren(pWin);
  385.         freeTmpClip = TRUE;
  386.         }
  387.         else {
  388.         pregWin = &pWin->clipList;
  389.         freeTmpClip = FALSE;
  390.         }
  391.         freeCompClip = devPriv->freeCompClip;
  392.  
  393.         /*
  394.          * if there is no client clip, we can get by with just keeping
  395.          * the pointer we got, and remembering whether or not should
  396.          * destroy (or maybe re-use) it later.  this way, we avoid
  397.          * unnecessary copying of regions.  (this wins especially if
  398.          * many clients clip by children and have no client clip.) 
  399.          */
  400.         if (pGC->clientClipType == CT_NONE) {
  401.         if (freeCompClip)
  402.             (*pScreen->RegionDestroy) (devPriv->pCompositeClip);
  403.         devPriv->pCompositeClip = pregWin;
  404.         devPriv->freeCompClip = freeTmpClip;
  405.         }
  406.         else {
  407.         /*
  408.          * we need one 'real' region to put into the composite
  409.          * clip. if pregWin the current composite clip are real,
  410.          * we can get rid of one. if pregWin is real and the
  411.          * current composite clip isn't, use pregWin for the
  412.          * composite clip. if the current composite clip is real
  413.          * and pregWin isn't, use the current composite clip. if
  414.          * neither is real, create a new region. 
  415.          */
  416.  
  417.         (*pScreen->TranslateRegion)(pGC->clientClip,
  418.                         pDrawable->x + pGC->clipOrg.x,
  419.                         pDrawable->y + pGC->clipOrg.y);
  420.                           
  421.         if (freeCompClip)
  422.         {
  423.             (*pGC->pScreen->Intersect)(devPriv->pCompositeClip,
  424.                            pregWin, pGC->clientClip);
  425.             if (freeTmpClip)
  426.             (*pScreen->RegionDestroy)(pregWin);
  427.         }
  428.         else if (freeTmpClip)
  429.         {
  430.             (*pScreen->Intersect)(pregWin, pregWin, pGC->clientClip);
  431.             devPriv->pCompositeClip = pregWin;
  432.         }
  433.         else
  434.         {
  435.             devPriv->pCompositeClip = (*pScreen->RegionCreate)(NullBox,
  436.                                        0);
  437.             (*pScreen->Intersect)(devPriv->pCompositeClip,
  438.                       pregWin, pGC->clientClip);
  439.         }
  440.         devPriv->freeCompClip = TRUE;
  441.         (*pScreen->TranslateRegion)(pGC->clientClip,
  442.                         -(pDrawable->x + pGC->clipOrg.x),
  443.                         -(pDrawable->y + pGC->clipOrg.y));
  444.                           
  445.         }
  446.     }            /* end of composite clip for a window */
  447.     else {
  448.         BoxRec      pixbounds;
  449.  
  450.         /* XXX should we translate by drawable.x/y here ? */
  451.         pixbounds.x1 = 0;
  452.         pixbounds.y1 = 0;
  453.         pixbounds.x2 = pDrawable->width;
  454.         pixbounds.y2 = pDrawable->height;
  455.  
  456.         if (devPriv->freeCompClip)
  457.         (*pScreen->RegionReset)(devPriv->pCompositeClip, &pixbounds);
  458.         else {
  459.         devPriv->freeCompClip = TRUE;
  460.         devPriv->pCompositeClip = (*pScreen->RegionCreate)(&pixbounds,
  461.                                    1);
  462.         }
  463.  
  464.         if (pGC->clientClipType == CT_REGION)
  465.         {
  466.         (*pScreen->TranslateRegion)(devPriv->pCompositeClip,
  467.                         -pGC->clipOrg.x, -pGC->clipOrg.y);
  468.         (*pScreen->Intersect)(devPriv->pCompositeClip,
  469.                       devPriv->pCompositeClip,
  470.                       pGC->clientClip);
  471.         (*pScreen->TranslateRegion)(devPriv->pCompositeClip,
  472.                         pGC->clipOrg.x, pGC->clipOrg.y);
  473.         }
  474.     }            /* end of composute clip for pixmap */
  475.     oneRect = REGION_NUM_RECTS(devPriv->pCompositeClip) == 1;
  476.     if (oneRect != devPriv->oneRect)
  477.         new_line = TRUE;
  478.     devPriv->oneRect = oneRect;
  479.     }
  480.  
  481.     mask = changes;
  482.     while (mask) {
  483.     index = lowbit (mask);
  484.     mask &= ~index;
  485.  
  486.     /*
  487.      * this switch acculmulates a list of which procedures might have
  488.      * to change due to changes in the GC.  in some cases (e.g.
  489.      * changing one 16 bit tile for another) we might not really need
  490.      * a change, but the code is being paranoid. this sort of batching
  491.      * wins if, for example, the alu and the font have been changed,
  492.      * or any other pair of items that both change the same thing. 
  493.      */
  494.     switch (index) {
  495.     case GCFunction:
  496.     case GCForeground:
  497.         new_rrop = TRUE;
  498.         break;
  499.     case GCPlaneMask:
  500.         new_rrop = TRUE;
  501.         new_text = TRUE;
  502.         break;
  503.     case GCBackground:
  504.         break;
  505.     case GCLineStyle:
  506.     case GCLineWidth:
  507.         new_line = TRUE;
  508.         break;
  509.     case GCJoinStyle:
  510.     case GCCapStyle:
  511.         break;
  512.     case GCFillStyle:
  513.         new_text = TRUE;
  514.         new_fillspans = TRUE;
  515.         new_line = TRUE;
  516.         new_fillarea = TRUE;
  517.         break;
  518.     case GCFillRule:
  519.         break;
  520.     case GCTile:
  521.         new_fillspans = TRUE;
  522.         new_fillarea = TRUE;
  523.         break;
  524.  
  525.     case GCStipple:
  526.         if (pGC->stipple)
  527.         {
  528.         int width = pGC->stipple->drawable.width;
  529.         PixmapPtr nstipple;
  530.  
  531.         if ((width <= 32) && !(width & (width - 1)) &&
  532.             (nstipple = cfbCopyPixmap(pGC->stipple)))
  533.         {
  534.             cfbPadPixmap(nstipple);
  535.             cfbDestroyPixmap(pGC->stipple);
  536.             pGC->stipple = nstipple;
  537.         }
  538.         }
  539.         new_fillspans = TRUE;
  540.         new_fillarea = TRUE;
  541.         break;
  542.  
  543.     case GCTileStipXOrigin:
  544.         new_rotate = TRUE;
  545.         break;
  546.  
  547.     case GCTileStipYOrigin:
  548.         new_rotate = TRUE;
  549.         break;
  550.  
  551.     case GCFont:
  552.         new_text = TRUE;
  553.         break;
  554.     case GCSubwindowMode:
  555.         break;
  556.     case GCGraphicsExposures:
  557.         break;
  558.     case GCClipXOrigin:
  559.         break;
  560.     case GCClipYOrigin:
  561.         break;
  562.     case GCClipMask:
  563.         break;
  564.     case GCDashOffset:
  565.         break;
  566.     case GCDashList:
  567.         break;
  568.     case GCArcMode:
  569.         break;
  570.     default:
  571.         break;
  572.     }
  573.     }
  574.  
  575.     /*
  576.      * If the drawable has changed,  ensure suitable
  577.      * entries are in the proc vector. 
  578.      */
  579.     if (pDrawable->serialNumber != (pGC->serialNumber & (DRAWABLE_SERIAL_BITS))) {
  580.     new_fillspans = TRUE;    /* deal with FillSpans later */
  581.     }
  582.  
  583.     if (new_rotate || new_fillspans)
  584.     {
  585.     Bool new_pix = FALSE;
  586.  
  587.     xrot = pGC->patOrg.x + pDrawable->x;
  588.     yrot = pGC->patOrg.y + pDrawable->y;
  589.  
  590.     switch (pGC->fillStyle)
  591.     {
  592.     case FillTiled:
  593.         if (!pGC->tileIsPixel)
  594.         {
  595.         int width = pGC->tile.pixmap->drawable.width * PSZ;
  596.  
  597.         if ((width <= 32) && !(width & (width - 1)))
  598.         {
  599.             cfbCopyRotatePixmap(pGC->tile.pixmap,
  600.                     &devPriv->pRotatedPixmap,
  601.                     xrot, yrot);
  602.             new_pix = TRUE;
  603.         }
  604.         }
  605.         break;
  606. #if (PPW == 4)
  607.     case FillStippled:
  608.     case FillOpaqueStippled:
  609.         {
  610.         int width = pGC->stipple->drawable.width;
  611.  
  612.         if ((width <= 32) && !(width & (width - 1)))
  613.         {
  614.             mfbCopyRotatePixmap(pGC->stipple,
  615.                     &devPriv->pRotatedPixmap, xrot, yrot);
  616.             new_pix = TRUE;
  617.         }
  618.         }
  619.         break;
  620. #endif
  621.     }
  622.     if (!new_pix && devPriv->pRotatedPixmap)
  623.     {
  624.         cfbDestroyPixmap(devPriv->pRotatedPixmap);
  625.         devPriv->pRotatedPixmap = (PixmapPtr) NULL;
  626.     }
  627.     }
  628.  
  629.     if (new_rrop)
  630.     {
  631.     int old_rrop;
  632.  
  633.     old_rrop = devPriv->rop;
  634.     devPriv->rop = cfbReduceRasterOp (pGC->alu, pGC->fgPixel,
  635.                        pGC->planemask,
  636.                        &devPriv->and, &devPriv->xor);
  637.     if (old_rrop == devPriv->rop)
  638.         new_rrop = FALSE;
  639.     else
  640.     {
  641. #if PPW ==  4
  642.         new_line = TRUE;
  643.         new_text = TRUE;
  644. #endif
  645.         new_fillspans = TRUE;
  646.         new_fillarea = TRUE;
  647.     }
  648.     }
  649.  
  650.     if (new_rrop || new_fillspans || new_text || new_fillarea || new_line)
  651.     {
  652.     GCOps    *newops;
  653.  
  654.     if (newops = cfbMatchCommon (pGC, devPriv))
  655.      {
  656.         if (pGC->ops->devPrivate.val)
  657.         cfbDestroyOps (pGC->ops);
  658.         pGC->ops = newops;
  659.         new_rrop = new_line = new_fillspans = new_text = new_fillarea = 0;
  660.     }
  661.      else
  662.      {
  663.         if (!pGC->ops->devPrivate.val)
  664.         {
  665.         pGC->ops = cfbCreateOps (pGC->ops);
  666.         pGC->ops->devPrivate.val = 1;
  667.         }
  668.     }
  669.     }
  670.  
  671.     /* deal with the changes we've collected */
  672.     if (new_line)
  673.     {
  674.     pGC->ops->FillPolygon = miFillPolygon;
  675.     if (devPriv->oneRect && pGC->fillStyle == FillSolid)
  676.     {
  677.         switch (devPriv->rop) {
  678.         case GXcopy:
  679.         pGC->ops->FillPolygon = cfbFillPoly1RectCopy;
  680.         break;
  681.         default:
  682.         pGC->ops->FillPolygon = cfbFillPoly1RectGeneral;
  683.         break;
  684.         }
  685.     }
  686.     if (pGC->lineWidth == 0)
  687.     {
  688. #if PPW == 4
  689.         if ((pGC->lineStyle == LineSolid) && (pGC->fillStyle == FillSolid))
  690.         {
  691.         switch (devPriv->rop)
  692.         {
  693.         case GXxor:
  694.             pGC->ops->PolyArc = cfbZeroPolyArcSS8Xor;
  695.             break;
  696.         case GXcopy:
  697.             pGC->ops->PolyArc = cfbZeroPolyArcSS8Copy;
  698.             break;
  699.         default:
  700.             pGC->ops->PolyArc = cfbZeroPolyArcSS8General;
  701.             break;
  702.         }
  703.         }
  704.         else
  705. #endif
  706.         pGC->ops->PolyArc = miZeroPolyArc;
  707.     }
  708.     else
  709.         pGC->ops->PolyArc = miPolyArc;
  710.     pGC->ops->PolySegment = miPolySegment;
  711.     switch (pGC->lineStyle)
  712.     {
  713.     case LineSolid:
  714.         if(pGC->lineWidth == 0)
  715.         {
  716.         if (pGC->fillStyle == FillSolid)
  717.         {
  718. #if PPW == 4
  719.             if (devPriv->oneRect)
  720.             {
  721.             pGC->ops->Polylines = cfb8LineSS1Rect;
  722.             pGC->ops->PolySegment = cfb8SegmentSS1Rect;
  723.             } else
  724. #endif
  725.             {
  726.                 pGC->ops->Polylines = cfbLineSS;
  727.                 pGC->ops->PolySegment = cfbSegmentSS;
  728.             }
  729.         }
  730.          else
  731.             pGC->ops->Polylines = miZeroLine;
  732.         }
  733.         else
  734.         pGC->ops->Polylines = miWideLine;
  735.         break;
  736.     case LineOnOffDash:
  737.     case LineDoubleDash:
  738.         if (pGC->lineWidth == 0 && pGC->fillStyle == FillSolid)
  739.         {
  740.         pGC->ops->Polylines = cfbLineSD;
  741.         pGC->ops->PolySegment = cfbSegmentSD;
  742.         } else
  743.         pGC->ops->Polylines = miWideDash;
  744.         break;
  745.     }
  746.     }
  747.  
  748.     if (new_text && (pGC->font))
  749.     {
  750.         if (FONTMAXBOUNDS(pGC->font,rightSideBearing) -
  751.             FONTMINBOUNDS(pGC->font,leftSideBearing) > 32 ||
  752.         FONTMINBOUNDS(pGC->font,characterWidth) < 0)
  753.         {
  754.             pGC->ops->PolyGlyphBlt = miPolyGlyphBlt;
  755.             pGC->ops->ImageGlyphBlt = miImageGlyphBlt;
  756.         }
  757.         else
  758.         {
  759. #if PPW == 4
  760.         if (pGC->fillStyle == FillSolid)
  761.         {
  762.         if (devPriv->rop == GXcopy)
  763.             pGC->ops->PolyGlyphBlt = cfbPolyGlyphBlt8;
  764.         else
  765.             pGC->ops->PolyGlyphBlt = cfbPolyGlyphRop8;
  766.         }
  767.         else
  768. #endif
  769.         pGC->ops->PolyGlyphBlt = miPolyGlyphBlt;
  770.             /* special case ImageGlyphBlt for terminal emulator fonts */
  771.             if (TERMINALFONT(pGC->font) &&
  772.         (pGC->planemask & PMSK) == PMSK
  773. #if PPW == 4
  774.         && FONTMAXBOUNDS(pGC->font,characterWidth) >= 4
  775. #endif
  776.         )
  777.         {
  778. #if PPW == 4
  779.                 pGC->ops->ImageGlyphBlt = cfbTEGlyphBlt8;
  780. #else
  781.                 pGC->ops->ImageGlyphBlt = cfbTEGlyphBlt;
  782. #endif
  783.         }
  784.             else
  785.         {
  786. #if PPW == 4
  787.         pGC->ops->ImageGlyphBlt = cfbImageGlyphBlt8;
  788. #else
  789.                 pGC->ops->ImageGlyphBlt = miImageGlyphBlt;
  790. #endif
  791.         }
  792.         }
  793.     }    
  794.  
  795.  
  796.     if (new_fillspans) {
  797.     switch (pGC->fillStyle) {
  798.     case FillSolid:
  799.         switch (devPriv->rop) {
  800.         case GXcopy:
  801.         pGC->ops->FillSpans = cfbSolidSpansCopy;
  802.         break;
  803.         case GXxor:
  804.         pGC->ops->FillSpans = cfbSolidSpansXor;
  805.         break;
  806.         default:
  807.         pGC->ops->FillSpans = cfbSolidSpansGeneral;
  808.         break;
  809.         }
  810.         break;
  811.     case FillTiled:
  812.         if (devPriv->pRotatedPixmap)
  813.         {
  814.         if (pGC->alu == GXcopy && (pGC->planemask & PMSK) == PMSK)
  815.             pGC->ops->FillSpans = cfbTile32FSCopy;
  816.         else
  817.             pGC->ops->FillSpans = cfbTile32FSGeneral;
  818.         }
  819.         else
  820.         pGC->ops->FillSpans = cfbUnnaturalTileFS;
  821.         break;
  822.     case FillStippled:
  823. #if PPW == 4
  824.         if (devPriv->pRotatedPixmap)
  825.         pGC->ops->FillSpans = cfb8Stipple32FS;
  826.         else
  827. #endif
  828.         pGC->ops->FillSpans = cfbUnnaturalStippleFS;
  829.         break;
  830.     case FillOpaqueStippled:
  831. #if PPW == 4
  832.         if (devPriv->pRotatedPixmap)
  833.         pGC->ops->FillSpans = cfb8OpaqueStipple32FS;
  834.         else
  835. #endif
  836.         pGC->ops->FillSpans = cfbUnnaturalStippleFS;
  837.         break;
  838.     default:
  839.         FatalError("cfbValidateGC: illegal fillStyle\n");
  840.     }
  841.     } /* end of new_fillspans */
  842.  
  843.     if (new_fillarea) {
  844. #if PPW != 4
  845.     pGC->ops->PolyFillRect = miPolyFillRect;
  846.     if (pGC->fillStyle == FillSolid || pGC->fillStyle == FillTiled)
  847.     {
  848.         pGC->ops->PolyFillRect = cfbPolyFillRect;
  849.     }
  850. #endif
  851. #if PPW == 4
  852.     pGC->ops->PushPixels = mfbPushPixels;
  853.     if (pGC->fillStyle == FillSolid && devPriv->rop == GXcopy)
  854.         pGC->ops->PushPixels = cfbPushPixels8;
  855. #endif
  856.     pGC->ops->PolyFillArc = miPolyFillArc;
  857.     if (pGC->fillStyle == FillSolid)
  858.     {
  859.         switch (devPriv->rop)
  860.         {
  861.         case GXcopy:
  862.         pGC->ops->PolyFillArc = cfbPolyFillArcSolidCopy;
  863.         break;
  864.         default:
  865.         pGC->ops->PolyFillArc = cfbPolyFillArcSolidGeneral;
  866.         break;
  867.         }
  868.     }
  869.     }
  870. }
  871.  
  872. void
  873. cfbDestroyClip(pGC)
  874.     GCPtr    pGC;
  875. {
  876.     if(pGC->clientClipType == CT_NONE)
  877.     return;
  878.     else if (pGC->clientClipType == CT_PIXMAP)
  879.     {
  880.     cfbDestroyPixmap((PixmapPtr)(pGC->clientClip));
  881.     }
  882.     else
  883.     {
  884.     /* we know we'll never have a list of rectangles, since
  885.        ChangeClip immediately turns them into a region 
  886.     */
  887.         (*pGC->pScreen->RegionDestroy)(pGC->clientClip);
  888.     }
  889.     pGC->clientClip = NULL;
  890.     pGC->clientClipType = CT_NONE;
  891. }
  892.  
  893. void
  894. cfbChangeClip(pGC, type, pvalue, nrects)
  895.     GCPtr    pGC;
  896.     int        type;
  897.     pointer    pvalue;
  898.     int        nrects;
  899. {
  900.     cfbDestroyClip(pGC);
  901.     if(type == CT_PIXMAP)
  902.     {
  903.     pGC->clientClip = (pointer) (*pGC->pScreen->BitmapToRegion)((PixmapPtr)pvalue);
  904.     (*pGC->pScreen->DestroyPixmap)(pvalue);
  905.     }
  906.     else if (type == CT_REGION) {
  907.     /* stuff the region in the GC */
  908.     pGC->clientClip = pvalue;
  909.     }
  910.     else if (type != CT_NONE)
  911.     {
  912.     pGC->clientClip = (pointer) (*pGC->pScreen->RectsToRegion)(nrects,
  913.                             (xRectangle *)pvalue,
  914.                             type);
  915.     xfree(pvalue);
  916.     }
  917.     pGC->clientClipType = (type != CT_NONE && pGC->clientClip) ? CT_REGION :
  918.                                  CT_NONE;
  919.     pGC->stateChanges |= GCClipMask;
  920. }
  921.  
  922. void
  923. cfbCopyClip (pgcDst, pgcSrc)
  924.     GCPtr pgcDst, pgcSrc;
  925. {
  926.     RegionPtr prgnNew;
  927.  
  928.     switch(pgcSrc->clientClipType)
  929.     {
  930.       case CT_PIXMAP:
  931.     ((PixmapPtr) pgcSrc->clientClip)->refcnt++;
  932.     /* Fall through !! */
  933.       case CT_NONE:
  934.         cfbChangeClip(pgcDst, (int)pgcSrc->clientClipType, pgcSrc->clientClip,
  935.               0);
  936.         break;
  937.       case CT_REGION:
  938.         prgnNew = (*pgcSrc->pScreen->RegionCreate)(NULL, 1);
  939.         (*pgcSrc->pScreen->RegionCopy)(prgnNew,
  940.                                        (RegionPtr)(pgcSrc->clientClip));
  941.         cfbChangeClip(pgcDst, CT_REGION, (pointer)prgnNew, 0);
  942.         break;
  943.     }
  944. }
  945.  
  946. /*ARGSUSED*/
  947. void
  948. cfbCopyGC (pGCSrc, changes, pGCDst)
  949.     GCPtr    pGCSrc;
  950.     Mask     changes;
  951.     GCPtr    pGCDst;
  952. {
  953.     return;
  954. }
  955.