📄 draw.c
字号:
/* * draw.c - drawing routines for the RFB X server. This is a set of * wrappers around the standard MI/MFB/CFB drawing routines which work out * to a fair approximation the region of the screen being modified by the * drawing. If the RFB client is ready then the modified region of the screen * is sent to the client, otherwise the modified region will simply grow with * each drawing request until the client is ready. *//* * Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved. * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this software; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. *//*Copyright (c) 1989 X ConsortiumPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER INAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR INCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.Except as contained in this notice, the name of the X Consortium shall not beused in advertising or otherwise to promote the sale, use or other dealingsin this Software without prior written authorization from the X Consortium.*/#include <stdio.h>#include "scrnintstr.h"#include "gcstruct.h"#include "windowstr.h"#include "regionstr.h"#include "dixfontstr.h"#include "rfb.h"#include "mfb.h"extern WindowPtr *WindowTable; /* Why isn't this in a header file? */int rfbDeferUpdateTime = 40; /* ms *//****************************************************************************//* * Macro definitions *//****************************************************************************//* SLIGHTLY DIRTY HACK - use Composite Clip region calculated by mfb */#define WINDOW_CLIP_REGION(_w, _gc) \ (((mfbPrivGCPtr)((_gc)->devPrivates[mfbGCPrivateIndex].ptr))->pCompositeClip)#define TRC(x) /* (fprintf x) *//* ADD_TO_MODIFIED_REGION adds the given region to the modified region for each client */#define ADD_TO_MODIFIED_REGION(pScreen,reg) \ { \ rfbClientPtr cl; \ for (cl = rfbClientHead; cl; cl = cl->next) { \ REGION_UNION((pScreen),&cl->modifiedRegion,&cl->modifiedRegion,reg);\ } \ }/* SCHEDULE_FB_UPDATE is used at the end of each drawing routine to schedule an update to be sent to each client if there is one pending and the client is ready for it. */#define SCHEDULE_FB_UPDATE(pScreen,prfb) \ if (!prfb->dontSendFramebufferUpdate) { \ rfbClientPtr cl, nextCl; \ for (cl = rfbClientHead; cl; cl = nextCl) { \ nextCl = cl->next; \ if (!cl->deferredUpdateScheduled && FB_UPDATE_PENDING(cl) && \ REGION_NOTEMPTY(pScreen,&cl->requestedRegion)) \ { \ rfbScheduleDeferredUpdate(cl); \ } \ } \ }/* function prototypes */static void rfbScheduleDeferredUpdate(rfbClientPtr cl);static void rfbCopyRegion(ScreenPtr pScreen, rfbClientPtr cl, RegionPtr src, RegionPtr dst, int dx, int dy);static void PrintRegion(ScreenPtr pScreen, RegionPtr reg);/* GC funcs */static void rfbValidateGC(GCPtr, unsigned long /*changes*/, DrawablePtr);static void rfbChangeGC(GCPtr, unsigned long /*mask*/);static void rfbCopyGC(GCPtr /*src*/, unsigned long /*mask*/, GCPtr /*dst*/);static void rfbDestroyGC(GCPtr);static void rfbChangeClip(GCPtr, int /*type*/, pointer /*pValue*/, int /*nrects*/);static void rfbDestroyClip(GCPtr);static void rfbCopyClip(GCPtr /*dst*/, GCPtr /*src*/);/* GC ops */static void rfbFillSpans();static void rfbSetSpans();static void rfbPutImage();static RegionPtr rfbCopyArea();static RegionPtr rfbCopyPlane();static void rfbPolyPoint();static void rfbPolylines();static void rfbPolySegment();static void rfbPolyRectangle();static void rfbPolyArc();static void rfbFillPolygon();static void rfbPolyFillRect();static void rfbPolyFillArc();static int rfbPolyText8();static int rfbPolyText16();static void rfbImageText8();static void rfbImageText16();static void rfbImageGlyphBlt();static void rfbPolyGlyphBlt();static void rfbPushPixels();static GCFuncs rfbGCFuncs = { rfbValidateGC, rfbChangeGC, rfbCopyGC, rfbDestroyGC, rfbChangeClip, rfbDestroyClip, rfbCopyClip,};static GCOps rfbGCOps = { rfbFillSpans, rfbSetSpans, rfbPutImage, rfbCopyArea, rfbCopyPlane, rfbPolyPoint, rfbPolylines, rfbPolySegment, rfbPolyRectangle, rfbPolyArc, rfbFillPolygon, rfbPolyFillRect, rfbPolyFillArc, rfbPolyText8, rfbPolyText16, rfbImageText8, rfbImageText16, rfbImageGlyphBlt, rfbPolyGlyphBlt, rfbPushPixels};/****************************************************************************//* * Screen functions wrapper stuff *//****************************************************************************/#define SCREEN_PROLOGUE(scrn, field) \ ScreenPtr pScreen = scrn; \ rfbScreenInfoPtr prfb = &rfbScreen; \ pScreen->field = prfb->field;#define SCREEN_EPILOGUE(field, wrapper) \ pScreen->field = wrapper;/* * CloseScreen wrapper -- unwrap everything, free the private data * and call the wrapped CloseScreen function. */BoolrfbCloseScreen (i, pScreen) int i; ScreenPtr pScreen;{ rfbScreenInfoPtr prfb = &rfbScreen; pScreen->CloseScreen = prfb->CloseScreen; pScreen->CreateGC = prfb->CreateGC; pScreen->PaintWindowBackground = prfb->PaintWindowBackground; pScreen->PaintWindowBorder = prfb->PaintWindowBorder; pScreen->CopyWindow = prfb->CopyWindow; pScreen->ClearToBackground = prfb->ClearToBackground; pScreen->RestoreAreas = prfb->RestoreAreas; TRC((stderr,"Unwrapped screen functions\n")); return (*pScreen->CloseScreen) (i, pScreen);}/* * CreateGC - wrap the GC funcs (the GC ops will be wrapped when the GC * func "ValidateGC" is called). */BoolrfbCreateGC (pGC) GCPtr pGC;{ Bool ret; rfbGCPtr pGCPriv; SCREEN_PROLOGUE(pGC->pScreen,CreateGC); pGCPriv = (rfbGCPtr)pGC->devPrivates[rfbGCIndex].ptr; ret = (*pScreen->CreateGC) (pGC); TRC((stderr,"rfbCreateGC called\n")); pGCPriv->wrapOps = NULL; pGCPriv->wrapFuncs = pGC->funcs; pGC->funcs = &rfbGCFuncs; SCREEN_EPILOGUE(CreateGC,rfbCreateGC); return ret;}/* * PaintWindowBackground - the region being modified is just the given region. */voidrfbPaintWindowBackground (pWin, pRegion, what) WindowPtr pWin; RegionPtr pRegion; int what;{ SCREEN_PROLOGUE(pWin->drawable.pScreen,PaintWindowBackground); TRC((stderr,"rfbPaintWindowBackground called\n")); ADD_TO_MODIFIED_REGION(pScreen,pRegion); (*pScreen->PaintWindowBackground) (pWin, pRegion, what); SCHEDULE_FB_UPDATE(pScreen, prfb); SCREEN_EPILOGUE(PaintWindowBackground,rfbPaintWindowBackground);}/* * PaintWindowBorder - the region being modified is just the given region. */voidrfbPaintWindowBorder (pWin, pRegion, what) WindowPtr pWin; RegionPtr pRegion; int what;{ SCREEN_PROLOGUE(pWin->drawable.pScreen,PaintWindowBorder); TRC((stderr,"rfbPaintWindowBorder called\n")); ADD_TO_MODIFIED_REGION(pScreen,pRegion); (*pScreen->PaintWindowBorder) (pWin, pRegion, what); SCHEDULE_FB_UPDATE(pScreen, prfb); SCREEN_EPILOGUE(PaintWindowBorder,rfbPaintWindowBorder);}/* * CopyWindow - the region being modified is the translation of the old * region, clipped to the border clip region of the window. Note that any * parts of the window which have become newly-visible will not be affected by * this call - a separate PaintWindowBackground/Border will be called to do * that. If the client will accept CopyRect messages then use rfbCopyRegion to * optimise the pending screen changes into a single "copy region" plus the * ordinary modified region. */voidrfbCopyWindow (pWin, ptOldOrg, pOldRegion) WindowPtr pWin; DDXPointRec ptOldOrg; RegionPtr pOldRegion;{ rfbClientPtr cl; RegionRec srcRegion, dstRegion; SCREEN_PROLOGUE(pWin->drawable.pScreen,CopyWindow); TRC((stderr,"rfbCopyWindow called\n")); REGION_INIT(pScreen,&dstRegion,NullBox,0); REGION_COPY(pScreen,&dstRegion,pOldRegion); REGION_TRANSLATE(pWin->drawable.pScreen, &dstRegion, pWin->drawable.x - ptOldOrg.x, pWin->drawable.y - ptOldOrg.y); REGION_INTERSECT(pWin->drawable.pScreen, &dstRegion, &dstRegion, &pWin->borderClip); for (cl = rfbClientHead; cl; cl = cl->next) { if (cl->useCopyRect) { REGION_INIT(pScreen,&srcRegion,NullBox,0); REGION_COPY(pScreen,&srcRegion,pOldRegion); rfbCopyRegion(pScreen, cl, &srcRegion, &dstRegion, pWin->drawable.x - ptOldOrg.x, pWin->drawable.y - ptOldOrg.y); REGION_UNINIT(pSrc->pScreen, &srcRegion); } else { REGION_UNION(pScreen, &cl->modifiedRegion, &cl->modifiedRegion, &dstRegion); } } REGION_UNINIT(pSrc->pScreen, &dstRegion); (*pScreen->CopyWindow) (pWin, ptOldOrg, pOldRegion); SCHEDULE_FB_UPDATE(pScreen, prfb); SCREEN_EPILOGUE(CopyWindow,rfbCopyWindow);}/* * ClearToBackground - when generateExposures is false, the region being * modified is the given rectangle (clipped to the "window clip region"). */voidrfbClearToBackground (pWin, x, y, w, h, generateExposures) WindowPtr pWin; int x,y,w,h; Bool generateExposures;{ RegionRec tmpRegion; BoxRec box; SCREEN_PROLOGUE(pWin->drawable.pScreen,ClearToBackground); TRC((stderr,"rfbClearToBackground called\n")); if (!generateExposures) { box.x1 = x + pWin->drawable.x; box.y1 = y + pWin->drawable.y; box.x2 = w ? (box.x1 + w) : (pWin->drawable.x + pWin->drawable.width); box.y2 = h ? (box.y1 + h) : (pWin->drawable.y + pWin->drawable.height); SAFE_REGION_INIT(pScreen, &tmpRegion, &box, 0); REGION_INTERSECT(pScreen, &tmpRegion, &tmpRegion, &pWin->clipList); ADD_TO_MODIFIED_REGION(pScreen, &tmpRegion); REGION_UNINIT(pScreen, &tmpRegion); } (*pScreen->ClearToBackground) (pWin, x, y, w, h, generateExposures); if (!generateExposures) { SCHEDULE_FB_UPDATE(pScreen, prfb); } SCREEN_EPILOGUE(ClearToBackground,rfbClearToBackground);}/* * RestoreAreas - just be safe here - the region being modified is the whole * exposed region. */RegionPtrrfbRestoreAreas (pWin, prgnExposed) WindowPtr pWin; RegionPtr prgnExposed;{ RegionPtr result; SCREEN_PROLOGUE(pWin->drawable.pScreen,RestoreAreas); TRC((stderr,"rfbRestoreAreas called\n")); ADD_TO_MODIFIED_REGION(pScreen, prgnExposed); result = (*pScreen->RestoreAreas) (pWin, prgnExposed); SCHEDULE_FB_UPDATE(pScreen, prfb); SCREEN_EPILOGUE(RestoreAreas,rfbRestoreAreas); return result;}/****************************************************************************//* * GC funcs wrapper stuff * * We only really want to wrap the GC ops, but to do this we need to wrap * ValidateGC and so all the other GC funcs must be wrapped as well. *//****************************************************************************/#define GC_FUNC_PROLOGUE(pGC) \ rfbGCPtr pGCPriv = (rfbGCPtr) (pGC)->devPrivates[rfbGCIndex].ptr; \ (pGC)->funcs = pGCPriv->wrapFuncs; \ if (pGCPriv->wrapOps) \ (pGC)->ops = pGCPriv->wrapOps;#define GC_FUNC_EPILOGUE(pGC) \ pGCPriv->wrapFuncs = (pGC)->funcs; \ (pGC)->funcs = &rfbGCFuncs; \ if (pGCPriv->wrapOps) { \ pGCPriv->wrapOps = (pGC)->ops; \ (pGC)->ops = &rfbGCOps; \ }/* * ValidateGC - call the wrapped ValidateGC, then wrap the resulting GC ops if * the drawing will be to a viewable window. */static voidrfbValidateGC (pGC, changes, pDrawable) GCPtr pGC; unsigned long changes; DrawablePtr pDrawable;{ GC_FUNC_PROLOGUE(pGC); TRC((stderr,"rfbValidateGC called\n")); (*pGC->funcs->ValidateGC) (pGC, changes, pDrawable); pGCPriv->wrapOps = NULL; if (pDrawable->type == DRAWABLE_WINDOW && ((WindowPtr)pDrawable)->viewable) { WindowPtr pWin = (WindowPtr) pDrawable; RegionPtr pRegion = &pWin->clipList; if (pGC->subWindowMode == IncludeInferiors) pRegion = &pWin->borderClip; if (REGION_NOTEMPTY(pDrawable->pScreen, pRegion)) { pGCPriv->wrapOps = pGC->ops; TRC((stderr,"rfbValidateGC: wrapped GC ops\n")); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -