📄 mbufbf.c
字号:
/*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.*//* $XConsortium: mbufbf.c,v 1.5 94/04/17 20:32:53 dpw Exp $ *//* $XFree86: xc/programs/Xserver/Xext/mbufbf.c,v 3.0 1994/05/08 05:17:30 dawes Exp $ */#define NEED_REPLIES#define NEED_EVENTS#include <stdio.h>#include "X.h"#include "Xproto.h"#include "misc.h"#include "os.h"#include "windowstr.h"#include "scrnintstr.h"#include "pixmapstr.h"#include "extnsionst.h"#include "dixstruct.h"#include "resource.h"#include "opaque.h"#include "regionstr.h"#include "gcstruct.h"#include "inputstr.h"#include "validate.h"#ifndef MINIX#include <sys/time.h>#endif#define _MULTIBUF_SERVER_ /* don't want Xlib structures */#define _MULTIBUF_BUFFER_#include "multibufst.h"/* Support for doublebuffer hardareThis code is designed to support doublebuffer hardware where thedisplayed buffer is selected on a per-pixel basis by an additional bitplane, called the select plane. It could probably be easily modifiedto work with systems that use window-id planes.This is done by creating a new drawable type, DRAWABLE_BUFFER. Thetype has the same exact layout as a window drawable. Your code shouldtreat a DRAWABLE_BUFFER the same as it would tread a DRAWABLE_WINDOWwhen handling the gc drawing functions. In addition, PaintWindowBackground,CopyWindow, and all of the gc drawing functions to be able to draw into bothframebuffers. Which framebuffer to draw into is selected by the contents of pWin->devPrivates[frameWindowPrivateIndex].The content of the devPrivate is either from frameBuffer[0] orframeBuffer[1], depending on which buffer is being drawn into. When pWin->devPrivates[frameWindowPrivateIndex] == frameBuffer[0],the functions should draw into the front framebuffer. When pWin->devPrivates[frameWindowPrivateIndex] == frameBuffer[1],the functions should draw into the back framebuffer.In addition, you need to provide a function that allows you to copybits between the buffers (optional since CopyArea can be used) and afunction that draws into the select plane. Then, you need to registeryour functions and other information, by calling:voidRegisterDoubleBufferHardware(pScreen, nInfo, pInfo, frameBuffer, selectPlane, CopyBufferBitsFunc, DrawSelectPlaneFunc) int nInfo; xMbufBufferInfo *pInfo; DevUnion *frameBuffer; DevUnion selectPlane;"pInfo" is an array indicating which visuals and depths that doublebuffering is supported on. "nInfo" is the length of the array."frameBuffer" is array of length 2. The contents of the array elementis ddx-specific. The content of frameBuffer[0] should, when placed inthe window private, indicate that framebuffer 0 should be drawn into.The contents of frameBuffer[1], when placed into the window private,should indicate that framebuffer 1 should be drawn into."selectPlane" is ddx-specific. It should contain informationneccessary for your displayProc to access the select plane.It is passed to DrawSelectPlaneFunc."CopyBufferBitsFunc" is a ddx-specific function that copies from onebuffer of a multibuffered window to another buffer. If the CopyBufferBitsFuncis NULL, a default function will be used that calls pScreen->CopyArea. void CopyBufferBitsFunc(pMBWindow, srcBufferNum, dstBufferNum) mbufWindowPtr pMBWindow; int srcBufferNum, dstBufferNum;"DrawSelectPlaneFunc" is a ddx-specific function that fills theregions "prgn" of select plane with the value "bufferNum". If selectPlane is a DrawablePtr (such as a PixmapPtr), you can passNULL for DrawSelectPlaneFunc, a default function will be used thatcalls FillRectangle on the selectPlane. void DrawSelectPlaneFunc(pScreen, selectPlane, prgn, bufferNum) ScreenPtr pScreen; DevUnion selectPlane; RegionPtr prgn; long bufferNum;.........*/#define MAX_BUFFERS 2 /* Only supports 2 buffers */#define FRONT_BUFFER 0#define BACK_BUFFER 1/* Buffer drawables have the same structure as window drawables */typedef WindowRec BufferRec;typedef WindowPtr BufferPtr;/* * Call RegisterHdwrBuffer for every screen that has doublebuffer hardware. */static int bufNumInfo[MAXSCREENS];static xMbufBufferInfo *bufInfo[MAXSCREENS];static DevUnion *bufFrameBuffer[MAXSCREENS];static DevUnion bufselectPlane[MAXSCREENS];static void (* bufCopyBufferBitsFunc[MAXSCREENS])();static void (* bufDrawSelectPlaneFunc[MAXSCREENS])();static Bool bufMultibufferInit();voidRegisterDoubleBufferHardware(pScreen, nInfo, pInfo, frameBuffer, selectPlane, CopyBufferBitsFunc, DrawSelectPlaneFunc) ScreenPtr pScreen; int nInfo; xMbufBufferInfo *pInfo; DevUnion *frameBuffer; DevUnion selectPlane; void (* CopyBufferBitsFunc)(); void (* DrawSelectPlaneFunc)();{ bufNumInfo[pScreen->myNum] = nInfo; bufInfo[pScreen->myNum] = pInfo; bufFrameBuffer[pScreen->myNum] = frameBuffer; bufselectPlane[pScreen->myNum] = selectPlane; bufCopyBufferBitsFunc[pScreen->myNum] = CopyBufferBitsFunc; bufDrawSelectPlaneFunc[pScreen->myNum] = DrawSelectPlaneFunc; /* Register ourselves with device-independent multibuffers code */ RegisterMultibufferInit(pScreen, bufMultibufferInit);}/* * Called by Multibuffer extension initialization. * Initializes mbufScreenRec and its devPrivate. */ static Bool NoopDDA_True() { return TRUE; }static Bool bufPositionWindow();static int bufCreateImageBuffers();static void bufDestroyImageBuffers();static void bufDisplayImageBuffers();static void bufClearImageBufferArea();static void bufDestroyBuffer();static void bufCopyBufferBits();static void bufDrawSelectPlane();static void bufWrapScreenFuncs();static void bufResetProc();static void bufPostValidateTree();static void bufClipNotify();static void bufWindowExposures();static Bool bufChangeWindowAttributes();static void bufClearToBackground();static void bufCopyWindow();extern WindowPtr *WindowTable;static BoolbufMultibufferInit(pScreen, pMBScreen) ScreenPtr pScreen; mbufScreenPtr pMBScreen;{ mbufBufferPrivPtr pMBPriv; BoxRec box; /* Multibuffer info */ pMBScreen->nInfo = bufNumInfo[pScreen->myNum]; pMBScreen->pInfo = bufInfo[pScreen->myNum]; /* Hooks */ pMBScreen->CreateImageBuffers = bufCreateImageBuffers; pMBScreen->DestroyImageBuffers = bufDestroyImageBuffers; pMBScreen->DisplayImageBuffers = bufDisplayImageBuffers; pMBScreen->ClearImageBufferArea = bufClearImageBufferArea; pMBScreen->ChangeMBufferAttributes = NoopDDA_True; pMBScreen->ChangeBufferAttributes = NoopDDA_True; pMBScreen->DeleteBufferDrawable = bufDestroyBuffer; pMBScreen->WrapScreenFuncs = bufWrapScreenFuncs; pMBScreen->ResetProc = bufResetProc; /* Create devPrivate part */ pMBPriv = (mbufBufferPrivPtr) xalloc(sizeof *pMBPriv); if (!pMBPriv) return (FALSE); pMBScreen->devPrivate.ptr = (pointer) pMBPriv; pMBPriv->frameBuffer = bufFrameBuffer[pScreen->myNum]; pMBPriv->selectPlane = bufselectPlane[pScreen->myNum]; /* * Initializing the subtractRgn to the screen area will ensure that * the selectPlane will get cleared on the first PostValidateTree. */ box.x1 = 0; box.y1 = 0; box.x2 = pScreen->width; box.y2 = pScreen->height; pMBPriv->rgnChanged = TRUE; REGION_INIT(pScreen, &pMBPriv->backBuffer, &box, 1); REGION_INIT(pScreen, &pMBPriv->subtractRgn, &box, 1); REGION_INIT(pScreen, &pMBPriv->unionRgn, NullBox, 0); /* Misc functions */ pMBPriv->CopyBufferBits = bufCopyBufferBitsFunc[pScreen->myNum]; pMBPriv->DrawSelectPlane = bufDrawSelectPlaneFunc[pScreen->myNum]; if (!pMBPriv->CopyBufferBits) pMBPriv->CopyBufferBits = bufCopyBufferBits; if (!pMBPriv->DrawSelectPlane) pMBPriv->DrawSelectPlane = bufDrawSelectPlane; /* screen functions */ pMBPriv->funcsWrapped = 0; pMBPriv->inClearToBackground = FALSE; pMBPriv->WindowExposures = NULL; pMBPriv->CopyWindow = NULL; pMBPriv->ClearToBackground = NULL; pMBPriv->ClipNotify = NULL; pMBPriv->ChangeWindowAttributes = NULL; /* Start out wrapped to clear select plane */ WRAP_SCREEN_FUNC(pScreen,pMBPriv,PostValidateTree, bufPostValidateTree); return TRUE;}static voidUpdateBufferFromWindow(pBuffer, pWin) BufferPtr pBuffer; WindowPtr pWin;{ pBuffer->drawable.x = pWin->drawable.x; pBuffer->drawable.y = pWin->drawable.y; pBuffer->drawable.width = pWin->drawable.width; pBuffer->drawable.height = pWin->drawable.height; pBuffer->drawable.serialNumber = NEXT_SERIAL_NUMBER; /* Update for PaintWindowBackground */ pBuffer->parent = pWin->parent; /* * Make the borderClip the same as the clipList so * NotClippedByChildren comes out with just clipList. */ pBuffer->clipList = pWin->clipList; pBuffer->borderClip = pWin->clipList; pBuffer->winSize = pWin->winSize; pBuffer->borderSize = pWin->borderSize; pBuffer->origin = pWin->origin;}static BufferPtrbufCreateBuffer(pScreen, pWin, bufferNum) ScreenPtr pScreen; WindowPtr pWin; int bufferNum;{ mbufBufferPrivPtr pMBPriv; DevUnion *devPrivates; BufferPtr pBuffer; int i; pMBPriv = MB_SCREEN_PRIV_BUFFER(pScreen); pBuffer = AllocateWindow(pWin->drawable.pScreen); if (!pBuffer) return (NULL); /* XXX- Until we know what is needed, copy everything. */ devPrivates = pBuffer->devPrivates; *pBuffer = *pWin; pBuffer->devPrivates = devPrivates; pBuffer->drawable.type = DRAWABLE_BUFFER; pBuffer->drawable.serialNumber = NEXT_SERIAL_NUMBER; pBuffer->nextSib = NULL; pBuffer->prevSib = NULL; pBuffer->firstChild = NULL; pBuffer->lastChild = NULL; /* XXX - Worry about backingstore later */ pBuffer->backStorage = NULL; pBuffer->backingStore = NotUseful; /* XXX - Need to call pScreen->CreateWindow for tile/stipples * or should I just copy the devPrivates? */ for (i=0; i < pScreen->WindowPrivateLen; i++) pBuffer->devPrivates[i] = pWin->devPrivates[i]; pBuffer->devPrivates[frameWindowPrivateIndex] = pMBPriv->frameBuffer[bufferNum]; return pBuffer;}static voidbufDestroyBuffer(pDrawable) DrawablePtr pDrawable;{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -