📄 mfbgc.c
字号:
/***********************************************************Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,and the Massachusetts Institute of Technology, Cambridge, Massachusetts. All Rights ReservedPermission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and thatboth that copyright notice and this permission notice appear in supporting documentation, and that the names of Digital or MIT not beused in advertising or publicity pertaining to distribution of thesoftware without specific, written prior permission. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDINGALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALLDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES ORANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THISSOFTWARE.******************************************************************//* $XConsortium: mfbgc.c,v 5.25 91/05/26 09:22:58 rws Exp $ */#include "X.h"#include "Xmd.h"#include "Xproto.h"#include "mfb.h"#include "dixfontstr.h"#include "fontstruct.h"#include "gcstruct.h"#include "windowstr.h"#include "pixmapstr.h"#include "scrnintstr.h"#include "region.h"#include "mistruct.h"#include "maskbits.h"static void mfbDestroyOps();static GCFuncs mfbFuncs = { mfbValidateGC, mfbChangeGC, mfbCopyGC, mfbDestroyGC, mfbChangeClip, mfbDestroyClip, mfbCopyClip,};static GCOps whiteTECopyOps = { mfbWhiteSolidFS, mfbSetSpans, mfbPutImage, mfbCopyArea, mfbCopyPlane, mfbPolyPoint, mfbLineSS, mfbSegmentSS, miPolyRectangle, mfbZeroPolyArcSS, miFillPolygon, mfbPolyFillRect, mfbPolyFillArcSolid, miPolyText8, miPolyText16, miImageText8, miImageText16, mfbTEGlyphBltWhite, mfbPolyGlyphBltWhite, mfbSolidPP, NULL,};static GCOps blackTECopyOps = { mfbBlackSolidFS, mfbSetSpans, mfbPutImage, mfbCopyArea, mfbCopyPlane, mfbPolyPoint, mfbLineSS, mfbSegmentSS, miPolyRectangle, mfbZeroPolyArcSS, miFillPolygon, mfbPolyFillRect, mfbPolyFillArcSolid, miPolyText8, miPolyText16, miImageText8, miImageText16, mfbTEGlyphBltBlack, mfbPolyGlyphBltBlack, mfbSolidPP, NULL,};static GCOps whiteTEInvertOps = { mfbInvertSolidFS, mfbSetSpans, mfbPutImage, mfbCopyArea, mfbCopyPlane, mfbPolyPoint, mfbLineSS, mfbSegmentSS, miPolyRectangle, miZeroPolyArc, miFillPolygon, mfbPolyFillRect, mfbPolyFillArcSolid, miPolyText8, miPolyText16, miImageText8, miImageText16, mfbTEGlyphBltWhite, mfbPolyGlyphBltInvert, mfbSolidPP, NULL,};static GCOps blackTEInvertOps = { mfbInvertSolidFS, mfbSetSpans, mfbPutImage, mfbCopyArea, mfbCopyPlane, mfbPolyPoint, mfbLineSS, mfbSegmentSS, miPolyRectangle, miZeroPolyArc, miFillPolygon, mfbPolyFillRect, mfbPolyFillArcSolid, miPolyText8, miPolyText16, miImageText8, miImageText16, mfbTEGlyphBltBlack, mfbPolyGlyphBltInvert, mfbSolidPP, NULL,};static GCOps whiteCopyOps = { mfbWhiteSolidFS, mfbSetSpans, mfbPutImage, mfbCopyArea, mfbCopyPlane, mfbPolyPoint, mfbLineSS, mfbSegmentSS, miPolyRectangle, mfbZeroPolyArcSS, miFillPolygon, mfbPolyFillRect, mfbPolyFillArcSolid, miPolyText8, miPolyText16, miImageText8, miImageText16, mfbImageGlyphBltWhite, mfbPolyGlyphBltWhite, mfbSolidPP, NULL,};static GCOps blackCopyOps = { mfbBlackSolidFS, mfbSetSpans, mfbPutImage, mfbCopyArea, mfbCopyPlane, mfbPolyPoint, mfbLineSS, mfbSegmentSS, miPolyRectangle, mfbZeroPolyArcSS, miFillPolygon, mfbPolyFillRect, mfbPolyFillArcSolid, miPolyText8, miPolyText16, miImageText8, miImageText16, mfbImageGlyphBltBlack, mfbPolyGlyphBltBlack, mfbSolidPP, NULL,};static GCOps whiteInvertOps = { mfbInvertSolidFS, mfbSetSpans, mfbPutImage, mfbCopyArea, mfbCopyPlane, mfbPolyPoint, mfbLineSS, mfbSegmentSS, miPolyRectangle, miZeroPolyArc, miFillPolygon, mfbPolyFillRect, mfbPolyFillArcSolid, miPolyText8, miPolyText16, miImageText8, miImageText16, mfbImageGlyphBltWhite, mfbPolyGlyphBltInvert, mfbSolidPP, NULL,};static GCOps blackInvertOps = { mfbInvertSolidFS, mfbSetSpans, mfbPutImage, mfbCopyArea, mfbCopyPlane, mfbPolyPoint, mfbLineSS, mfbSegmentSS, miPolyRectangle, miZeroPolyArc, miFillPolygon, mfbPolyFillRect, mfbPolyFillArcSolid, miPolyText8, miPolyText16, miImageText8, miImageText16, mfbImageGlyphBltBlack, mfbPolyGlyphBltInvert, mfbSolidPP, NULL,};static GCOps whiteWhiteCopyOps = { mfbWhiteSolidFS, mfbSetSpans, mfbPutImage, mfbCopyArea, mfbCopyPlane, mfbPolyPoint, mfbLineSS, mfbSegmentSS, miPolyRectangle, mfbZeroPolyArcSS, miFillPolygon, mfbPolyFillRect, mfbPolyFillArcSolid, miPolyText8, miPolyText16, miImageText8, miImageText16, miImageGlyphBlt, mfbPolyGlyphBltWhite, mfbSolidPP, NULL,};static GCOps blackBlackCopyOps = { mfbBlackSolidFS, mfbSetSpans, mfbPutImage, mfbCopyArea, mfbCopyPlane, mfbPolyPoint, mfbLineSS, mfbSegmentSS, miPolyRectangle, mfbZeroPolyArcSS, miFillPolygon, mfbPolyFillRect, mfbPolyFillArcSolid, miPolyText8, miPolyText16, miImageText8, miImageText16, miImageGlyphBlt, mfbPolyGlyphBltBlack, mfbSolidPP, NULL,};static GCOps fgEqBgInvertOps = { mfbInvertSolidFS, mfbSetSpans, mfbPutImage, mfbCopyArea, mfbCopyPlane, mfbPolyPoint, mfbLineSS, mfbSegmentSS, miPolyRectangle, miZeroPolyArc, miFillPolygon, mfbPolyFillRect, mfbPolyFillArcSolid, miPolyText8, miPolyText16, miImageText8, miImageText16, miImageGlyphBlt, mfbPolyGlyphBltInvert, mfbSolidPP, NULL,};struct commonOps { int fg, bg; int rrop; int terminalFont; GCOps *ops; void (*fillArea)();};static struct commonOps mfbCommonOps[] = { { 1, 0, RROP_WHITE, 1, &whiteTECopyOps, mfbSolidWhiteArea }, { 0, 1, RROP_BLACK, 1, &blackTECopyOps, mfbSolidBlackArea }, { 1, 0, RROP_INVERT, 1, &whiteTEInvertOps, mfbSolidInvertArea }, { 0, 1, RROP_INVERT, 1, &blackTEInvertOps, mfbSolidInvertArea }, { 1, 0, RROP_WHITE, 0, &whiteCopyOps, mfbSolidWhiteArea }, { 0, 1, RROP_BLACK, 0, &blackCopyOps, mfbSolidBlackArea }, { 1, 0, RROP_INVERT, 0, &whiteInvertOps, mfbSolidInvertArea }, { 0, 1, RROP_INVERT, 0, &blackInvertOps, mfbSolidInvertArea }, { 1, 1, RROP_WHITE, 0, &whiteWhiteCopyOps, mfbSolidWhiteArea }, { 0, 0, RROP_BLACK, 0, &blackBlackCopyOps, mfbSolidBlackArea }, { 1, 1, RROP_INVERT, 0, &fgEqBgInvertOps, mfbSolidInvertArea }, { 0, 0, RROP_INVERT, 0, &fgEqBgInvertOps, mfbSolidInvertArea },};#define numberCommonOps (sizeof (mfbCommonOps) / sizeof (mfbCommonOps[0]))static GCOps *matchCommon (pGC) GCPtr pGC;{ int i; struct commonOps *cop; mfbPrivGC *priv; if (pGC->lineWidth != 0) return 0; if (pGC->lineStyle != LineSolid) return 0; if (pGC->fillStyle != FillSolid) return 0; if (!pGC->font || FONTMAXBOUNDS(pGC->font,rightSideBearing) - FONTMINBOUNDS(pGC->font,leftSideBearing) > 32 || FONTMINBOUNDS(pGC->font,characterWidth) < 0) return 0; priv = (mfbPrivGC *) pGC->devPrivates[mfbGCPrivateIndex].ptr; for (i = 0; i < numberCommonOps; i++) { cop = &mfbCommonOps[i]; if ((pGC->fgPixel & 1) != cop->fg) continue; if ((pGC->bgPixel & 1) != cop->bg) continue; if (priv->rop != cop->rrop) continue; if (cop->terminalFont && !TERMINALFONT(pGC->font)) continue; priv->FillArea = cop->fillArea; return cop->ops; } return 0;} /* to let hp displays with bit blt override the mfbCopyArea routine. XXX: currently ignores the pScreen argument XXX: and will break if multiple screens of different types are attached. */voidmfbRegisterCopyAreaProc(pScreen, proc) ScreenPtr pScreen; RegionPtr (* proc)();{ whiteTECopyOps.CopyArea = proc; blackTECopyOps.CopyArea = proc; whiteTEInvertOps.CopyArea = proc; blackTEInvertOps.CopyArea = proc; whiteCopyOps.CopyArea = proc; blackCopyOps.CopyArea = proc; whiteInvertOps.CopyArea = proc; blackInvertOps.CopyArea = proc; whiteWhiteCopyOps.CopyArea = proc; blackBlackCopyOps.CopyArea = proc; fgEqBgInvertOps.CopyArea = proc;}BoolmfbCreateGC(pGC) register GCPtr pGC;{ mfbPrivGC *pPriv; pGC->clientClip = NULL; pGC->clientClipType = CT_NONE; /* some of the output primitives aren't really necessary, since they will be filled in ValidateGC because of dix/CreateGC() setting all the change bits. Others are necessary because although they depend on being a monochrome frame buffer, they don't change */ pGC->ops = &whiteCopyOps; pGC->funcs = &mfbFuncs; /* mfb wants to translate before scan convesion */ pGC->miTranslate = 1; pPriv = (mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr); pPriv->rop = mfbReduceRop(pGC->alu, pGC->fgPixel); pPriv->fExpose = TRUE; pPriv->pRotatedPixmap = NullPixmap; pPriv->freeCompClip = FALSE; pPriv->FillArea = mfbSolidInvertArea; return TRUE;}/*ARGSUSED*/voidmfbChangeGC(pGC, mask) GC *pGC; BITS32 mask;{ return;}/*ARGSUSED*/voidmfbCopyGC (pGCSrc, changes, pGCDst) GCPtr pGCSrc; Mask changes; GCPtr pGCDst;{ return;}voidmfbDestroyGC(pGC) GC *pGC;{ mfbPrivGC *pPriv; pPriv = (mfbPrivGC *)(pGC->devPrivates[mfbGCPrivateIndex].ptr); if (pPriv->pRotatedPixmap) mfbDestroyPixmap(pPriv->pRotatedPixmap); if (pPriv->freeCompClip) (*pGC->pScreen->RegionDestroy)(pPriv->pCompositeClip); mfbDestroyOps (pGC->ops);}/* * create a private op array for a gc */static GCOps *mfbCreateOps (prototype) GCOps *prototype;{ GCOps *ret; extern Bool Must_have_memory; /* XXX */ Must_have_memory = TRUE; ret = (GCOps *) xalloc (sizeof *ret); /* XXX */ Must_have_memory = FALSE; if (!ret) return 0; *ret = *prototype; ret->devPrivate.val = 1; return ret;}static voidmfbDestroyOps (ops) GCOps *ops;{ if (ops->devPrivate.val) xfree (ops);}/* Clipping conventions if the drawable is a window CT_REGION ==> pCompositeClip really is the composite CT_other ==> pCompositeClip is the window clip region if the drawable is a pixmap CT_REGION ==> pCompositeClip is the translated client region clipped to the pixmap boundary CT_other ==> pCompositeClip is the pixmap bounding box*//*ARGSUSED*/voidmfbValidateGC(pGC, changes, pDrawable) register GCPtr pGC; Mask changes; DrawablePtr pDrawable;{ register mfbPrivGCPtr devPriv; WindowPtr pWin; int mask; /* stateChanges */ int index; /* used for stepping through bitfields */ int xrot, yrot; /* rotations for tile and stipple pattern */ int rrop; /* reduced rasterop */ /* flags for changing the proc vector and updating things in devPriv */ int new_rotate, new_rrop, new_line, new_text, new_fill; DDXPointRec oldOrg; /* origin of thing GC was last used with */ oldOrg = pGC->lastWinOrg; pGC->lastWinOrg.x = pDrawable->x; pGC->lastWinOrg.y = pDrawable->y; if (pDrawable->type == DRAWABLE_WINDOW) pWin = (WindowPtr)pDrawable; else pWin = (WindowPtr)NULL; /* we need to re-rotate the tile if the previous window/pixmap origin (oldOrg) differs from the new window/pixmap origin (pGC->lastWinOrg) */ new_rotate = (oldOrg.x != pGC->lastWinOrg.x) || (oldOrg.y != pGC->lastWinOrg.y); devPriv = ((mfbPrivGCPtr) (pGC->devPrivates[mfbGCPrivateIndex].ptr)); /* if the client clip is different or moved OR the subwindowMode has changed OR the window's clip has changed since the last validation we need to recompute the composite clip */ if ((changes & (GCClipXOrigin|GCClipYOrigin|GCClipMask|GCSubwindowMode)) || (pDrawable->serialNumber != (pGC->serialNumber & DRAWABLE_SERIAL_BITS)) ) { ScreenPtr pScreen = pGC->pScreen; if (pWin) { Bool freeTmpClip, freeCompClip; RegionPtr pregWin; /* clip for this window, without client clip */ if (pGC->subWindowMode == IncludeInferiors) { pregWin = NotClippedByChildren(pWin); freeTmpClip = TRUE; } else { pregWin = &pWin->clipList; freeTmpClip = FALSE; } freeCompClip = devPriv->freeCompClip; /* if there is no client clip, we can get by with just keeping the pointer we got, and remembering whether or not should destroy (or maybe re-use) it later. this way, we avoid unnecessary copying of regions. (this wins especially if many clients clip by children and have no client clip.) */ if (pGC->clientClipType == CT_NONE) { if(freeCompClip) (*pScreen->RegionDestroy) (devPriv->pCompositeClip); devPriv->pCompositeClip = pregWin; devPriv->freeCompClip = freeTmpClip; } else { /* we need one 'real' region to put into the composite clip. if pregWin and the current composite clip are real, we can get rid of one. if the current composite clip is real and pregWin isn't, intersect the client clip and pregWin into the existing composite clip. if pregWin is real and the current composite clip isn't, intersect pregWin with the client clip and replace the composite clip with it. if neither is real, create a new region and do the intersection into it. */ (*pScreen->TranslateRegion)(pGC->clientClip, pDrawable->x + pGC->clipOrg.x, pDrawable->y + pGC->clipOrg.y); if (freeCompClip) { (*pScreen->Intersect)(devPriv->pCompositeClip, pregWin, pGC->clientClip); if (freeTmpClip) (*pScreen->RegionDestroy)(pregWin); } else if (freeTmpClip) { (*pScreen->Intersect)(pregWin, pregWin, pGC->clientClip); devPriv->pCompositeClip = pregWin; } else { devPriv->pCompositeClip = (*pScreen->RegionCreate)(NullBox, 0); (*pScreen->Intersect)(devPriv->pCompositeClip, pregWin, pGC->clientClip); } devPriv->freeCompClip = TRUE; (*pScreen->TranslateRegion)(pGC->clientClip, -(pDrawable->x + pGC->clipOrg.x), -(pDrawable->y + pGC->clipOrg.y)); } } /* end of composite clip for a window */ else { BoxRec pixbounds; /* XXX should we translate by drawable.x/y here ? */ pixbounds.x1 = 0; pixbounds.y1 = 0; pixbounds.x2 = pDrawable->width; pixbounds.y2 = pDrawable->height; if (devPriv->freeCompClip) (*pScreen->RegionReset)(devPriv->pCompositeClip, &pixbounds); else { devPriv->freeCompClip = TRUE; devPriv->pCompositeClip = (*pScreen->RegionCreate)(&pixbounds, 1); } if (pGC->clientClipType == CT_REGION) { (*pScreen->TranslateRegion)(devPriv->pCompositeClip, -pGC->clipOrg.x, -pGC->clipOrg.y); (*pScreen->Intersect)(devPriv->pCompositeClip, devPriv->pCompositeClip, pGC->clientClip); (*pScreen->TranslateRegion)(devPriv->pCompositeClip, pGC->clipOrg.x, pGC->clipOrg.y); } } /* end of composite clip for pixmap */ } new_rrop = FALSE; new_line = FALSE; new_text = FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -