miscrinit.c revision 4e185dc0
105b261ecSmrg/* 205b261ecSmrg 305b261ecSmrgCopyright 1990, 1998 The Open Group 405b261ecSmrg 505b261ecSmrgPermission to use, copy, modify, distribute, and sell this software and its 605b261ecSmrgdocumentation for any purpose is hereby granted without fee, provided that 705b261ecSmrgthe above copyright notice appear in all copies and that both that 805b261ecSmrgcopyright notice and this permission notice appear in supporting 905b261ecSmrgdocumentation. 1005b261ecSmrg 1105b261ecSmrgThe above copyright notice and this permission notice shall be included 1205b261ecSmrgin all copies or substantial portions of the Software. 1305b261ecSmrg 1405b261ecSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 1505b261ecSmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 1605b261ecSmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 1705b261ecSmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 1805b261ecSmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 1905b261ecSmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 2005b261ecSmrgOTHER DEALINGS IN THE SOFTWARE. 2105b261ecSmrg 2205b261ecSmrgExcept as contained in this notice, the name of The Open Group shall 2305b261ecSmrgnot be used in advertising or otherwise to promote the sale, use or 2405b261ecSmrgother dealings in this Software without prior written authorization 2505b261ecSmrgfrom The Open Group. 2605b261ecSmrg 2705b261ecSmrg*/ 2805b261ecSmrg 2905b261ecSmrg#ifdef HAVE_DIX_CONFIG_H 3005b261ecSmrg#include <dix-config.h> 3105b261ecSmrg#endif 3205b261ecSmrg 3305b261ecSmrg#include <X11/X.h> 3405b261ecSmrg#include "servermd.h" 3505b261ecSmrg#include "misc.h" 3605b261ecSmrg#include "mi.h" 3705b261ecSmrg#include "scrnintstr.h" 3805b261ecSmrg#include "pixmapstr.h" 3905b261ecSmrg#include "dix.h" 4005b261ecSmrg#include "miline.h" 4105b261ecSmrg#ifdef MITSHM 424202a189Smrg#include <X11/extensions/shm.h> 434202a189Smrg#include "shmint.h" 4405b261ecSmrg#endif 4505b261ecSmrg 4605b261ecSmrg/* We use this structure to propogate some information from miScreenInit to 4705b261ecSmrg * miCreateScreenResources. miScreenInit allocates the structure, fills it 48f7df2e56Smrg * in, and puts it into pScreen->devPrivate. miCreateScreenResources 4905b261ecSmrg * extracts the info and frees the structure. We could've accomplished the 5005b261ecSmrg * same thing by adding fields to the screen structure, but they would have 5105b261ecSmrg * ended up being redundant, and would have exposed this mi implementation 5205b261ecSmrg * detail to the whole server. 5305b261ecSmrg */ 5405b261ecSmrg 55f7df2e56Smrgtypedef struct { 56f7df2e56Smrg void *pbits; /* pointer to framebuffer */ 57f7df2e56Smrg int width; /* delta to add to a framebuffer addr to move one row down */ 5805b261ecSmrg} miScreenInitParmsRec, *miScreenInitParmsPtr; 5905b261ecSmrg 6005b261ecSmrg/* this plugs into pScreen->ModifyPixmapHeader */ 614202a189SmrgBool 624642e01fSmrgmiModifyPixmapHeader(PixmapPtr pPixmap, int width, int height, int depth, 63f7df2e56Smrg int bitsPerPixel, int devKind, void *pPixData) 6405b261ecSmrg{ 6505b261ecSmrg if (!pPixmap) 66f7df2e56Smrg return FALSE; 6705b261ecSmrg 6805b261ecSmrg /* 6905b261ecSmrg * If all arguments are specified, reinitialize everything (including 7005b261ecSmrg * validated state). 7105b261ecSmrg */ 7205b261ecSmrg if ((width > 0) && (height > 0) && (depth > 0) && (bitsPerPixel > 0) && 73f7df2e56Smrg (devKind > 0) && pPixData) { 74f7df2e56Smrg pPixmap->drawable.depth = depth; 75f7df2e56Smrg pPixmap->drawable.bitsPerPixel = bitsPerPixel; 76f7df2e56Smrg pPixmap->drawable.id = 0; 77f7df2e56Smrg pPixmap->drawable.x = 0; 78f7df2e56Smrg pPixmap->drawable.y = 0; 79f7df2e56Smrg pPixmap->drawable.width = width; 80f7df2e56Smrg pPixmap->drawable.height = height; 81f7df2e56Smrg pPixmap->devKind = devKind; 82f7df2e56Smrg pPixmap->refcnt = 1; 83f7df2e56Smrg pPixmap->devPrivate.ptr = pPixData; 84f7df2e56Smrg } 85f7df2e56Smrg else { 86f7df2e56Smrg /* 87f7df2e56Smrg * Only modify specified fields, keeping all others intact. 88f7df2e56Smrg */ 89f7df2e56Smrg 90f7df2e56Smrg if (width > 0) 91f7df2e56Smrg pPixmap->drawable.width = width; 92f7df2e56Smrg 93f7df2e56Smrg if (height > 0) 94f7df2e56Smrg pPixmap->drawable.height = height; 95f7df2e56Smrg 96f7df2e56Smrg if (depth > 0) 97f7df2e56Smrg pPixmap->drawable.depth = depth; 98f7df2e56Smrg 99f7df2e56Smrg if (bitsPerPixel > 0) 100f7df2e56Smrg pPixmap->drawable.bitsPerPixel = bitsPerPixel; 101f7df2e56Smrg else if ((bitsPerPixel < 0) && (depth > 0)) 102f7df2e56Smrg pPixmap->drawable.bitsPerPixel = BitsPerPixel(depth); 103f7df2e56Smrg 104f7df2e56Smrg /* 105f7df2e56Smrg * CAVEAT: Non-SI DDXen may use devKind and devPrivate fields for 106f7df2e56Smrg * other purposes. 107f7df2e56Smrg */ 108f7df2e56Smrg if (devKind > 0) 109f7df2e56Smrg pPixmap->devKind = devKind; 110f7df2e56Smrg else if ((devKind < 0) && ((width > 0) || (depth > 0))) 111f7df2e56Smrg pPixmap->devKind = PixmapBytePad(pPixmap->drawable.width, 112f7df2e56Smrg pPixmap->drawable.depth); 113f7df2e56Smrg 114f7df2e56Smrg if (pPixData) 115f7df2e56Smrg pPixmap->devPrivate.ptr = pPixData; 11605b261ecSmrg } 1174202a189Smrg pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER; 11805b261ecSmrg return TRUE; 11905b261ecSmrg} 12005b261ecSmrg 12105b261ecSmrgstatic Bool 122f7df2e56SmrgmiCloseScreen(ScreenPtr pScreen) 12305b261ecSmrg{ 124f7df2e56Smrg return ((*pScreen->DestroyPixmap) ((PixmapPtr) pScreen->devPrivate)); 12505b261ecSmrg} 12605b261ecSmrg 1274e185dc0Smrgvoid 1284e185dc0SmrgmiSourceValidate(DrawablePtr pDrawable, int x, int y, int w, int h, 1294e185dc0Smrg unsigned int subWindowMode) 1304e185dc0Smrg{ 1314e185dc0Smrg} 1324e185dc0Smrg 13305b261ecSmrg/* With the introduction of pixmap privates, the "screen pixmap" can no 13405b261ecSmrg * longer be created in miScreenInit, since all the modules that could 13505b261ecSmrg * possibly ask for pixmap private space have not been initialized at 13605b261ecSmrg * that time. pScreen->CreateScreenResources is called after all 13705b261ecSmrg * possible private-requesting modules have been inited; we create the 13805b261ecSmrg * screen pixmap here. 13905b261ecSmrg */ 1404202a189SmrgBool 1414642e01fSmrgmiCreateScreenResources(ScreenPtr pScreen) 14205b261ecSmrg{ 14305b261ecSmrg miScreenInitParmsPtr pScrInitParms; 144f7df2e56Smrg void *value; 14505b261ecSmrg 146f7df2e56Smrg pScrInitParms = (miScreenInitParmsPtr) pScreen->devPrivate; 14705b261ecSmrg 14805b261ecSmrg /* if width is non-zero, pScreen->devPrivate will be a pixmap 14905b261ecSmrg * else it will just take the value pbits 15005b261ecSmrg */ 151f7df2e56Smrg if (pScrInitParms->width) { 152f7df2e56Smrg PixmapPtr pPixmap; 153f7df2e56Smrg 154f7df2e56Smrg /* create a pixmap with no data, then redirect it to point to 155f7df2e56Smrg * the screen 156f7df2e56Smrg */ 157f7df2e56Smrg pPixmap = 158f7df2e56Smrg (*pScreen->CreatePixmap) (pScreen, 0, 0, pScreen->rootDepth, 0); 159f7df2e56Smrg if (!pPixmap) 160f7df2e56Smrg return FALSE; 161f7df2e56Smrg 162f7df2e56Smrg if (!(*pScreen->ModifyPixmapHeader) (pPixmap, pScreen->width, 163f7df2e56Smrg pScreen->height, 164f7df2e56Smrg pScreen->rootDepth, 165f7df2e56Smrg BitsPerPixel(pScreen->rootDepth), 166f7df2e56Smrg PixmapBytePad(pScrInitParms->width, 167f7df2e56Smrg pScreen->rootDepth), 168f7df2e56Smrg pScrInitParms->pbits)) 169f7df2e56Smrg return FALSE; 170f7df2e56Smrg value = (void *) pPixmap; 17105b261ecSmrg } 172f7df2e56Smrg else { 173f7df2e56Smrg value = pScrInitParms->pbits; 17405b261ecSmrg } 175f7df2e56Smrg free(pScreen->devPrivate); /* freeing miScreenInitParmsRec */ 176f7df2e56Smrg pScreen->devPrivate = value; /* pPixmap or pbits */ 17705b261ecSmrg return TRUE; 17805b261ecSmrg} 17905b261ecSmrg 18005b261ecSmrgBool 181f7df2e56SmrgmiScreenDevPrivateInit(ScreenPtr pScreen, int width, void *pbits) 18205b261ecSmrg{ 18305b261ecSmrg miScreenInitParmsPtr pScrInitParms; 18405b261ecSmrg 18505b261ecSmrg /* Stash pbits and width in a short-lived miScreenInitParmsRec attached 18605b261ecSmrg * to the screen, until CreateScreenResources can put them in the 18705b261ecSmrg * screen pixmap. 18805b261ecSmrg */ 1894202a189Smrg pScrInitParms = malloc(sizeof(miScreenInitParmsRec)); 19005b261ecSmrg if (!pScrInitParms) 191f7df2e56Smrg return FALSE; 19205b261ecSmrg pScrInitParms->pbits = pbits; 19305b261ecSmrg pScrInitParms->width = width; 194f7df2e56Smrg pScreen->devPrivate = (void *) pScrInitParms; 19505b261ecSmrg return TRUE; 19605b261ecSmrg} 19705b261ecSmrg 1984642e01fSmrgstatic PixmapPtr 1994642e01fSmrgmiGetScreenPixmap(ScreenPtr pScreen) 2004642e01fSmrg{ 201f7df2e56Smrg return (PixmapPtr) (pScreen->devPrivate); 2024642e01fSmrg} 2034642e01fSmrg 2044642e01fSmrgstatic void 2054642e01fSmrgmiSetScreenPixmap(PixmapPtr pPix) 2064642e01fSmrg{ 2074642e01fSmrg if (pPix) 208f7df2e56Smrg pPix->drawable.pScreen->devPrivate = (void *) pPix; 2094642e01fSmrg} 2104642e01fSmrg 2114202a189SmrgBool 212f7df2e56SmrgmiScreenInit(ScreenPtr pScreen, void *pbits, /* pointer to screen bits */ 213f7df2e56Smrg int xsize, int ysize, /* in pixels */ 214f7df2e56Smrg int dpix, int dpiy, /* dots per inch */ 215f7df2e56Smrg int width, /* pixel width of frame buffer */ 216f7df2e56Smrg int rootDepth, /* depth of root window */ 217f7df2e56Smrg int numDepths, /* number of depths supported */ 218f7df2e56Smrg DepthRec * depths, /* supported depths */ 219f7df2e56Smrg VisualID rootVisual, /* root visual */ 220f7df2e56Smrg int numVisuals, /* number of visuals supported */ 221f7df2e56Smrg VisualRec * visuals /* supported visuals */ 2224642e01fSmrg ) 22305b261ecSmrg{ 22405b261ecSmrg pScreen->width = xsize; 22505b261ecSmrg pScreen->height = ysize; 22605b261ecSmrg pScreen->mmWidth = (xsize * 254 + dpix * 5) / (dpix * 10); 22705b261ecSmrg pScreen->mmHeight = (ysize * 254 + dpiy * 5) / (dpiy * 10); 22805b261ecSmrg pScreen->numDepths = numDepths; 22905b261ecSmrg pScreen->rootDepth = rootDepth; 23005b261ecSmrg pScreen->allowedDepths = depths; 23105b261ecSmrg pScreen->rootVisual = rootVisual; 23205b261ecSmrg /* defColormap */ 23305b261ecSmrg pScreen->minInstalledCmaps = 1; 23405b261ecSmrg pScreen->maxInstalledCmaps = 1; 23505b261ecSmrg pScreen->backingStoreSupport = NotUseful; 23605b261ecSmrg pScreen->saveUnderSupport = NotUseful; 23705b261ecSmrg /* whitePixel, blackPixel */ 23805b261ecSmrg pScreen->ModifyPixmapHeader = miModifyPixmapHeader; 23905b261ecSmrg pScreen->CreateScreenResources = miCreateScreenResources; 24005b261ecSmrg pScreen->GetScreenPixmap = miGetScreenPixmap; 24105b261ecSmrg pScreen->SetScreenPixmap = miSetScreenPixmap; 24205b261ecSmrg pScreen->numVisuals = numVisuals; 24305b261ecSmrg pScreen->visuals = visuals; 244f7df2e56Smrg if (width) { 24505b261ecSmrg#ifdef MITSHM 246f7df2e56Smrg ShmRegisterFbFuncs(pScreen); 24705b261ecSmrg#endif 248f7df2e56Smrg pScreen->CloseScreen = miCloseScreen; 24905b261ecSmrg } 25005b261ecSmrg /* else CloseScreen */ 25105b261ecSmrg /* QueryBestSize, SaveScreen, GetImage, GetSpans */ 2524e185dc0Smrg pScreen->SourceValidate = miSourceValidate; 25305b261ecSmrg /* CreateWindow, DestroyWindow, PositionWindow, ChangeWindowAttributes */ 25405b261ecSmrg /* RealizeWindow, UnrealizeWindow */ 25505b261ecSmrg pScreen->ValidateTree = miValidateTree; 25605b261ecSmrg pScreen->PostValidateTree = (PostValidateTreeProcPtr) 0; 25705b261ecSmrg pScreen->WindowExposures = miWindowExposures; 2584642e01fSmrg /* CopyWindow */ 25905b261ecSmrg pScreen->ClearToBackground = miClearToBackground; 26005b261ecSmrg pScreen->ClipNotify = (ClipNotifyProcPtr) 0; 26105b261ecSmrg pScreen->RestackWindow = (RestackWindowProcPtr) 0; 262f7df2e56Smrg pScreen->PaintWindow = miPaintWindow; 26305b261ecSmrg /* CreatePixmap, DestroyPixmap */ 26405b261ecSmrg /* RealizeFont, UnrealizeFont */ 26505b261ecSmrg /* CreateGC */ 26605b261ecSmrg /* CreateColormap, DestroyColormap, InstallColormap, UninstallColormap */ 26705b261ecSmrg /* ListInstalledColormaps, StoreColors, ResolveColor */ 26805b261ecSmrg /* BitmapToRegion */ 269f7df2e56Smrg pScreen->BlockHandler = (ScreenBlockHandlerProcPtr) NoopDDA; 270f7df2e56Smrg pScreen->WakeupHandler = (ScreenWakeupHandlerProcPtr) NoopDDA; 27105b261ecSmrg pScreen->MarkWindow = miMarkWindow; 27205b261ecSmrg pScreen->MarkOverlappedWindows = miMarkOverlappedWindows; 27305b261ecSmrg pScreen->MoveWindow = miMoveWindow; 274f7df2e56Smrg pScreen->ResizeWindow = miResizeWindow; 27505b261ecSmrg pScreen->GetLayerWindow = miGetLayerWindow; 27605b261ecSmrg pScreen->HandleExposures = miHandleValidateExposures; 27705b261ecSmrg pScreen->ReparentWindow = (ReparentWindowProcPtr) 0; 27805b261ecSmrg pScreen->ChangeBorderWidth = miChangeBorderWidth; 27905b261ecSmrg pScreen->SetShape = miSetShape; 28005b261ecSmrg pScreen->MarkUnrealizedWindow = miMarkUnrealizedWindow; 281f7df2e56Smrg pScreen->XYToWindow = miXYToWindow; 28205b261ecSmrg 28305b261ecSmrg miSetZeroLineBias(pScreen, DEFAULTZEROLINEBIAS); 28405b261ecSmrg 28505b261ecSmrg return miScreenDevPrivateInit(pScreen, width, pbits); 28605b261ecSmrg} 28705b261ecSmrg 2884202a189SmrgDevPrivateKeyRec miZeroLineScreenKeyRec; 28905b261ecSmrg 2904202a189Smrgvoid 2914642e01fSmrgmiSetZeroLineBias(ScreenPtr pScreen, unsigned int bias) 29205b261ecSmrg{ 2934202a189Smrg if (!dixRegisterPrivateKey(&miZeroLineScreenKeyRec, PRIVATE_SCREEN, 0)) 294f7df2e56Smrg return; 2954202a189Smrg 296f7df2e56Smrg dixSetPrivate(&pScreen->devPrivates, miZeroLineScreenKey, 297f7df2e56Smrg (unsigned long *) (unsigned long) bias); 29805b261ecSmrg} 299