miscrinit.c revision 706f2543
11.43Sad/* 21.39Sdholland 31.1SdhollandCopyright 1990, 1998 The Open Group 41.1Sdholland 51.1SdhollandPermission to use, copy, modify, distribute, and sell this software and its 61.1Sdhollanddocumentation for any purpose is hereby granted without fee, provided that 71.1Sdhollandthe above copyright notice appear in all copies and that both that 81.1Sdhollandcopyright notice and this permission notice appear in supporting 91.1Sdhollanddocumentation. 101.1Sdholland 111.1SdhollandThe above copyright notice and this permission notice shall be included 121.1Sdhollandin all copies or substantial portions of the Software. 131.1Sdholland 141.1SdhollandTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 151.1SdhollandOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 161.1SdhollandMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 171.1SdhollandIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 181.1SdhollandOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 191.1SdhollandARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 201.1SdhollandOTHER DEALINGS IN THE SOFTWARE. 211.1Sdholland 221.1SdhollandExcept as contained in this notice, the name of The Open Group shall 231.1Sdhollandnot be used in advertising or otherwise to promote the sale, use or 241.1Sdhollandother dealings in this Software without prior written authorization 251.1Sdhollandfrom The Open Group. 261.1Sdholland 271.1Sdholland*/ 281.1Sdholland 291.1Sdholland#ifdef HAVE_DIX_CONFIG_H 301.1Sdholland#include <dix-config.h> 311.1Sdholland#endif 321.1Sdholland 331.1Sdholland#include <X11/X.h> 341.1Sdholland#include "servermd.h" 351.1Sdholland#include "misc.h" 361.1Sdholland#include "mi.h" 371.1Sdholland#include "scrnintstr.h" 381.1Sdholland#include "pixmapstr.h" 391.1Sdholland#include "dix.h" 401.1Sdholland#include "miline.h" 411.43Sad#ifdef MITSHM 421.1Sdholland#include <X11/extensions/shm.h> 431.1Sdholland#include "shmint.h" 441.3Sdholland#endif 451.1Sdholland 461.1Sdholland/* We use this structure to propogate some information from miScreenInit to 471.1Sdholland * miCreateScreenResources. miScreenInit allocates the structure, fills it 481.1Sdholland * in, and puts it into pScreen->devPrivate. miCreateScreenResources 491.1Sdholland * extracts the info and frees the structure. We could've accomplished the 501.1Sdholland * same thing by adding fields to the screen structure, but they would have 511.1Sdholland * ended up being redundant, and would have exposed this mi implementation 521.1Sdholland * detail to the whole server. 531.1Sdholland */ 541.1Sdholland 551.1Sdhollandtypedef struct 561.1Sdholland{ 571.1Sdholland pointer pbits; /* pointer to framebuffer */ 581.1Sdholland int width; /* delta to add to a framebuffer addr to move one row down */ 591.1Sdholland} miScreenInitParmsRec, *miScreenInitParmsPtr; 601.26Sdholland 611.26Sdholland 621.13Sdholland/* this plugs into pScreen->ModifyPixmapHeader */ 631.13SdhollandBool 641.2SdhollandmiModifyPixmapHeader(PixmapPtr pPixmap, int width, int height, int depth, 651.3Sdholland int bitsPerPixel, int devKind, pointer pPixData) 661.2Sdholland{ 671.1Sdholland if (!pPixmap) 681.2Sdholland return FALSE; 691.2Sdholland 701.2Sdholland /* 711.1Sdholland * If all arguments are specified, reinitialize everything (including 721.1Sdholland * validated state). 731.1Sdholland */ 741.1Sdholland if ((width > 0) && (height > 0) && (depth > 0) && (bitsPerPixel > 0) && 751.5Sdholland (devKind > 0) && pPixData) { 761.1Sdholland pPixmap->drawable.depth = depth; 771.5Sdholland pPixmap->drawable.bitsPerPixel = bitsPerPixel; 781.1Sdholland pPixmap->drawable.id = 0; 791.1Sdholland pPixmap->drawable.x = 0; 801.1Sdholland pPixmap->drawable.y = 0; 811.1Sdholland pPixmap->drawable.width = width; 821.1Sdholland pPixmap->drawable.height = height; 831.1Sdholland pPixmap->devKind = devKind; 841.1Sdholland pPixmap->refcnt = 1; 851.1Sdholland pPixmap->devPrivate.ptr = pPixData; 861.1Sdholland } else { 871.1Sdholland /* 881.1Sdholland * Only modify specified fields, keeping all others intact. 891.1Sdholland */ 901.1Sdholland 911.1Sdholland if (width > 0) 921.1Sdholland pPixmap->drawable.width = width; 931.1Sdholland 941.1Sdholland if (height > 0) 951.1Sdholland pPixmap->drawable.height = height; 961.1Sdholland 971.4Sdholland if (depth > 0) 981.1Sdholland pPixmap->drawable.depth = depth; 991.1Sdholland 1001.1Sdholland if (bitsPerPixel > 0) 1011.1Sdholland pPixmap->drawable.bitsPerPixel = bitsPerPixel; 1021.1Sdholland else if ((bitsPerPixel < 0) && (depth > 0)) 1031.1Sdholland pPixmap->drawable.bitsPerPixel = BitsPerPixel(depth); 1041.1Sdholland 1051.1Sdholland /* 1061.1Sdholland * CAVEAT: Non-SI DDXen may use devKind and devPrivate fields for 1071.1Sdholland * other purposes. 1081.1Sdholland */ 1091.1Sdholland if (devKind > 0) 1101.1Sdholland pPixmap->devKind = devKind; 1111.1Sdholland else if ((devKind < 0) && ((width > 0) || (depth > 0))) 1121.1Sdholland pPixmap->devKind = PixmapBytePad(pPixmap->drawable.width, 1131.1Sdholland pPixmap->drawable.depth); 1141.4Sdholland 1151.1Sdholland if (pPixData) 1161.19Shannken pPixmap->devPrivate.ptr = pPixData; 1171.1Sdholland } 1181.1Sdholland pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER; 1191.1Sdholland return TRUE; 1201.1Sdholland} 1211.1Sdholland 1221.1Sdhollandstatic Bool 1231.1SdhollandmiCloseScreen (int iScreen, ScreenPtr pScreen) 1241.34Sdholland{ 1251.1Sdholland return ((*pScreen->DestroyPixmap)((PixmapPtr)pScreen->devPrivate)); 1261.1Sdholland} 1271.1Sdholland 1281.1Sdholland/* With the introduction of pixmap privates, the "screen pixmap" can no 1291.1Sdholland * longer be created in miScreenInit, since all the modules that could 1301.1Sdholland * possibly ask for pixmap private space have not been initialized at 1311.1Sdholland * that time. pScreen->CreateScreenResources is called after all 1321.1Sdholland * possible private-requesting modules have been inited; we create the 1331.1Sdholland * screen pixmap here. 1341.1Sdholland */ 1351.1SdhollandBool 1361.1SdhollandmiCreateScreenResources(ScreenPtr pScreen) 1371.1Sdholland{ 1381.1Sdholland miScreenInitParmsPtr pScrInitParms; 1391.1Sdholland pointer value; 1401.1Sdholland 1411.24Shannken pScrInitParms = (miScreenInitParmsPtr)pScreen->devPrivate; 1421.1Sdholland 1431.1Sdholland /* if width is non-zero, pScreen->devPrivate will be a pixmap 1441.1Sdholland * else it will just take the value pbits 1451.1Sdholland */ 1461.1Sdholland if (pScrInitParms->width) 1471.1Sdholland { 1481.1Sdholland PixmapPtr pPixmap; 1491.1Sdholland 1501.1Sdholland /* create a pixmap with no data, then redirect it to point to 1511.15Sdholland * the screen 1521.15Sdholland */ 1531.1Sdholland pPixmap = (*pScreen->CreatePixmap)(pScreen, 0, 0, pScreen->rootDepth, 0); 1541.4Sdholland if (!pPixmap) 1551.1Sdholland return FALSE; 1561.1Sdholland 1571.1Sdholland if (!(*pScreen->ModifyPixmapHeader)(pPixmap, pScreen->width, 1581.1Sdholland pScreen->height, pScreen->rootDepth, 1591.1Sdholland BitsPerPixel(pScreen->rootDepth), 1601.1Sdholland PixmapBytePad(pScrInitParms->width, pScreen->rootDepth), 1611.1Sdholland pScrInitParms->pbits)) 1621.1Sdholland return FALSE; 1631.1Sdholland value = (pointer)pPixmap; 1641.1Sdholland } 1651.1Sdholland else 1661.1Sdholland { 1671.1Sdholland value = pScrInitParms->pbits; 1681.1Sdholland } 1691.1Sdholland free(pScreen->devPrivate); /* freeing miScreenInitParmsRec */ 1701.1Sdholland pScreen->devPrivate = value; /* pPixmap or pbits */ 1711.1Sdholland return TRUE; 1721.1Sdholland} 1731.1Sdholland 1741.1SdhollandBool 1751.1SdhollandmiScreenDevPrivateInit(ScreenPtr pScreen, int width, pointer pbits) 1761.1Sdholland{ 1771.1Sdholland miScreenInitParmsPtr pScrInitParms; 1781.1Sdholland 1791.1Sdholland /* Stash pbits and width in a short-lived miScreenInitParmsRec attached 1801.1Sdholland * to the screen, until CreateScreenResources can put them in the 1811.1Sdholland * screen pixmap. 1821.1Sdholland */ 1831.1Sdholland pScrInitParms = malloc(sizeof(miScreenInitParmsRec)); 1841.1Sdholland if (!pScrInitParms) 1851.1Sdholland return FALSE; 1861.1Sdholland pScrInitParms->pbits = pbits; 1871.1Sdholland pScrInitParms->width = width; 1881.43Sad pScreen->devPrivate = (pointer)pScrInitParms; 1891.43Sad return TRUE; 1901.43Sad} 1911.43Sad 1921.43Sadstatic PixmapPtr 1931.43SadmiGetScreenPixmap(ScreenPtr pScreen) 1941.43Sad{ 1951.43Sad return (PixmapPtr)(pScreen->devPrivate); 1961.43Sad} 1971.43Sad 1981.43Sadstatic void 1991.43SadmiSetScreenPixmap(PixmapPtr pPix) 2001.43Sad{ 2011.1Sdholland if (pPix) 2021.1Sdholland pPix->drawable.pScreen->devPrivate = (pointer)pPix; 2031.1Sdholland} 2041.1Sdholland 2051.1SdhollandBool 2061.1SdhollandmiScreenInit( 2071.1Sdholland ScreenPtr pScreen, 2081.1Sdholland pointer pbits, /* pointer to screen bits */ 2091.1Sdholland int xsize, int ysize, /* in pixels */ 2101.1Sdholland int dpix, int dpiy, /* dots per inch */ 2111.1Sdholland int width, /* pixel width of frame buffer */ 2121.1Sdholland int rootDepth, /* depth of root window */ 2131.1Sdholland int numDepths, /* number of depths supported */ 2141.1Sdholland DepthRec *depths, /* supported depths */ 2151.1Sdholland VisualID rootVisual, /* root visual */ 2161.1Sdholland int numVisuals, /* number of visuals supported */ 2171.1Sdholland VisualRec *visuals /* supported visuals */ 2181.1Sdholland ) 2191.1Sdholland{ 2201.1Sdholland pScreen->width = xsize; 2211.1Sdholland pScreen->height = ysize; 2221.1Sdholland pScreen->mmWidth = (xsize * 254 + dpix * 5) / (dpix * 10); 2231.1Sdholland pScreen->mmHeight = (ysize * 254 + dpiy * 5) / (dpiy * 10); 2241.1Sdholland pScreen->numDepths = numDepths; 2251.33Sdholland pScreen->rootDepth = rootDepth; 2261.1Sdholland pScreen->allowedDepths = depths; 2271.1Sdholland pScreen->rootVisual = rootVisual; 2281.1Sdholland /* defColormap */ 2291.1Sdholland pScreen->minInstalledCmaps = 1; 2301.1Sdholland pScreen->maxInstalledCmaps = 1; 2311.1Sdholland pScreen->backingStoreSupport = NotUseful; 2321.1Sdholland pScreen->saveUnderSupport = NotUseful; 2331.1Sdholland /* whitePixel, blackPixel */ 2341.1Sdholland pScreen->ModifyPixmapHeader = miModifyPixmapHeader; 2351.1Sdholland pScreen->CreateScreenResources = miCreateScreenResources; 2361.1Sdholland pScreen->GetScreenPixmap = miGetScreenPixmap; 2371.1Sdholland pScreen->SetScreenPixmap = miSetScreenPixmap; 2381.1Sdholland pScreen->numVisuals = numVisuals; 2391.1Sdholland pScreen->visuals = visuals; 2401.1Sdholland if (width) 2411.3Sdholland { 2421.1Sdholland#ifdef MITSHM 2431.1Sdholland ShmRegisterFbFuncs(pScreen); 2441.1Sdholland#endif 2451.4Sdholland pScreen->CloseScreen = miCloseScreen; 2461.1Sdholland } 2471.1Sdholland /* else CloseScreen */ 2481.4Sdholland /* QueryBestSize, SaveScreen, GetImage, GetSpans */ 2491.1Sdholland pScreen->SourceValidate = (SourceValidateProcPtr) 0; 2501.1Sdholland /* CreateWindow, DestroyWindow, PositionWindow, ChangeWindowAttributes */ 2511.1Sdholland /* RealizeWindow, UnrealizeWindow */ 2521.4Sdholland pScreen->ValidateTree = miValidateTree; 2531.1Sdholland pScreen->PostValidateTree = (PostValidateTreeProcPtr) 0; 2541.1Sdholland pScreen->WindowExposures = miWindowExposures; 2551.1Sdholland /* CopyWindow */ 2561.4Sdholland pScreen->ClearToBackground = miClearToBackground; 2571.1Sdholland pScreen->ClipNotify = (ClipNotifyProcPtr) 0; 2581.1Sdholland pScreen->RestackWindow = (RestackWindowProcPtr) 0; 2591.1Sdholland /* CreatePixmap, DestroyPixmap */ 2601.1Sdholland /* RealizeFont, UnrealizeFont */ 2611.1Sdholland /* CreateGC */ 2621.1Sdholland /* CreateColormap, DestroyColormap, InstallColormap, UninstallColormap */ 2631.1Sdholland /* ListInstalledColormaps, StoreColors, ResolveColor */ 2641.4Sdholland /* BitmapToRegion */ 2651.1Sdholland pScreen->SendGraphicsExpose = miSendGraphicsExpose; 2661.1Sdholland pScreen->BlockHandler = (ScreenBlockHandlerProcPtr)NoopDDA; 2671.34Sdholland pScreen->WakeupHandler = (ScreenWakeupHandlerProcPtr)NoopDDA; 2681.1Sdholland pScreen->blockData = (pointer)0; 2691.1Sdholland pScreen->wakeupData = (pointer)0; 2701.1Sdholland pScreen->MarkWindow = miMarkWindow; 2711.1Sdholland pScreen->MarkOverlappedWindows = miMarkOverlappedWindows; 2721.1Sdholland pScreen->MoveWindow = miMoveWindow; 2731.1Sdholland pScreen->ResizeWindow = miSlideAndSizeWindow; 2741.1Sdholland pScreen->GetLayerWindow = miGetLayerWindow; 2751.1Sdholland pScreen->HandleExposures = miHandleValidateExposures; 2761.1Sdholland pScreen->ReparentWindow = (ReparentWindowProcPtr) 0; 2771.1Sdholland pScreen->ChangeBorderWidth = miChangeBorderWidth; 2781.3Sdholland pScreen->SetShape = miSetShape; 2791.1Sdholland pScreen->MarkUnrealizedWindow = miMarkUnrealizedWindow; 2801.1Sdholland 2811.1Sdholland miSetZeroLineBias(pScreen, DEFAULTZEROLINEBIAS); 2821.1Sdholland 2831.1Sdholland return miScreenDevPrivateInit(pScreen, width, pbits); 2841.1Sdholland} 2851.1Sdholland 2861.1SdhollandDevPrivateKeyRec miZeroLineScreenKeyRec; 2871.1Sdholland 2881.4Sdhollandvoid 2891.1SdhollandmiSetZeroLineBias(ScreenPtr pScreen, unsigned int bias) 2901.1Sdholland{ 2911.1Sdholland if (!dixRegisterPrivateKey(&miZeroLineScreenKeyRec, PRIVATE_SCREEN, 0)) 2921.21Sjoerg return; 2931.1Sdholland 2941.1Sdholland dixSetPrivate(&pScreen->devPrivates, miZeroLineScreenKey, 2951.1Sdholland (unsigned long *)(unsigned long)bias); 2961.1Sdholland} 2971.1Sdholland