winscrinit.c revision 6747b715
105b261ecSmrg/* 205b261ecSmrg *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. 305b261ecSmrg * 405b261ecSmrg *Permission is hereby granted, free of charge, to any person obtaining 505b261ecSmrg * a copy of this software and associated documentation files (the 605b261ecSmrg *"Software"), to deal in the Software without restriction, including 705b261ecSmrg *without limitation the rights to use, copy, modify, merge, publish, 805b261ecSmrg *distribute, sublicense, and/or sell copies of the Software, and to 905b261ecSmrg *permit persons to whom the Software is furnished to do so, subject to 1005b261ecSmrg *the following conditions: 1105b261ecSmrg * 1205b261ecSmrg *The above copyright notice and this permission notice shall be 1305b261ecSmrg *included in all copies or substantial portions of the Software. 1405b261ecSmrg * 1505b261ecSmrg *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 1605b261ecSmrg *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 1705b261ecSmrg *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 1805b261ecSmrg *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR 1905b261ecSmrg *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 2005b261ecSmrg *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 2105b261ecSmrg *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2205b261ecSmrg * 2305b261ecSmrg *Except as contained in this notice, the name of the XFree86 Project 2405b261ecSmrg *shall not be used in advertising or otherwise to promote the sale, use 2505b261ecSmrg *or other dealings in this Software without prior written authorization 2605b261ecSmrg *from the XFree86 Project. 2705b261ecSmrg * 2805b261ecSmrg * Authors: Dakshinamurthy Karra 2905b261ecSmrg * Suhaib M Siddiqi 3005b261ecSmrg * Peter Busch 3105b261ecSmrg * Harold L Hunt II 3205b261ecSmrg * Kensuke Matsuzaki 3305b261ecSmrg */ 3405b261ecSmrg 3505b261ecSmrg#ifdef HAVE_XWIN_CONFIG_H 3605b261ecSmrg#include <xwin-config.h> 3705b261ecSmrg#endif 3805b261ecSmrg#include "win.h" 3905b261ecSmrg#include "winmsg.h" 4005b261ecSmrg 4105b261ecSmrg 4205b261ecSmrg#ifdef XWIN_MULTIWINDOWEXTWM 4305b261ecSmrgstatic RootlessFrameProcsRec 4405b261ecSmrgwinMWExtWMProcs = { 4505b261ecSmrg winMWExtWMCreateFrame, 4605b261ecSmrg winMWExtWMDestroyFrame, 4705b261ecSmrg 4805b261ecSmrg winMWExtWMMoveFrame, 4905b261ecSmrg winMWExtWMResizeFrame, 5005b261ecSmrg winMWExtWMRestackFrame, 5105b261ecSmrg winMWExtWMReshapeFrame, 5205b261ecSmrg winMWExtWMUnmapFrame, 5305b261ecSmrg 5405b261ecSmrg winMWExtWMStartDrawing, 5505b261ecSmrg winMWExtWMStopDrawing, 5605b261ecSmrg winMWExtWMUpdateRegion, 5705b261ecSmrg#ifndef ROOTLESS_TRACK_DAMAGE 5805b261ecSmrg winMWExtWMDamageRects, 5905b261ecSmrg#endif 6005b261ecSmrg winMWExtWMRootlessSwitchWindow, 616747b715Smrg NULL,//winMWExtWMDoReorderWindow, 626747b715Smrg NULL,//winMWExtWMHideWindow, 636747b715Smrg NULL,//winMWExtWMUpdateColorMap, 646747b715Smrg 6505b261ecSmrg NULL,//winMWExtWMCopyBytes, 6605b261ecSmrg NULL,//winMWExtWMFillBytes, 6705b261ecSmrg NULL,//winMWExtWMCompositePixels, 6805b261ecSmrg winMWExtWMCopyWindow 6905b261ecSmrg}; 7005b261ecSmrg#endif 7105b261ecSmrg 7205b261ecSmrg 7305b261ecSmrg/* 7405b261ecSmrg * References to external symbols 7505b261ecSmrg */ 7605b261ecSmrg 7705b261ecSmrgextern Bool g_fSoftwareCursor; 7805b261ecSmrg 7905b261ecSmrg 8005b261ecSmrg/* 8105b261ecSmrg * Prototypes 8205b261ecSmrg */ 8305b261ecSmrg 8405b261ecSmrgBool 8505b261ecSmrgwinRandRInit (ScreenPtr pScreen); 8605b261ecSmrg 8705b261ecSmrg 8805b261ecSmrg/* 8905b261ecSmrg * Local functions 9005b261ecSmrg */ 9105b261ecSmrg 9205b261ecSmrgstatic Bool 9305b261ecSmrgwinSaveScreen (ScreenPtr pScreen, int on); 9405b261ecSmrg 9505b261ecSmrg 9605b261ecSmrg/* 9705b261ecSmrg * Determine what type of screen we are initializing 9805b261ecSmrg * and call the appropriate procedure to intiailize 9905b261ecSmrg * that type of screen. 10005b261ecSmrg */ 10105b261ecSmrg 10205b261ecSmrgBool 10305b261ecSmrgwinScreenInit (int index, 10405b261ecSmrg ScreenPtr pScreen, 10505b261ecSmrg int argc, char **argv) 10605b261ecSmrg{ 10705b261ecSmrg winScreenInfoPtr pScreenInfo = &g_ScreenInfo[index]; 10805b261ecSmrg winPrivScreenPtr pScreenPriv; 10905b261ecSmrg HDC hdc; 11005b261ecSmrg 11105b261ecSmrg#if CYGDEBUG || YES 11205b261ecSmrg winDebug ("winScreenInit - dwWidth: %ld dwHeight: %ld\n", 11305b261ecSmrg pScreenInfo->dwWidth, pScreenInfo->dwHeight); 11405b261ecSmrg#endif 11505b261ecSmrg 11605b261ecSmrg /* Allocate privates for this screen */ 11705b261ecSmrg if (!winAllocatePrivates (pScreen)) 11805b261ecSmrg { 11905b261ecSmrg ErrorF ("winScreenInit - Couldn't allocate screen privates\n"); 12005b261ecSmrg return FALSE; 12105b261ecSmrg } 12205b261ecSmrg 12305b261ecSmrg /* Get a pointer to the privates structure that was allocated */ 12405b261ecSmrg pScreenPriv = winGetScreenPriv (pScreen); 12505b261ecSmrg 12605b261ecSmrg /* Save a pointer to this screen in the screen info structure */ 12705b261ecSmrg pScreenInfo->pScreen = pScreen; 12805b261ecSmrg 12905b261ecSmrg /* Save a pointer to the screen info in the screen privates structure */ 13005b261ecSmrg /* This allows us to get back to the screen info from a screen pointer */ 13105b261ecSmrg pScreenPriv->pScreenInfo = pScreenInfo; 13205b261ecSmrg 13305b261ecSmrg /* 13405b261ecSmrg * Determine which engine to use. 13505b261ecSmrg * 13605b261ecSmrg * NOTE: This is done once per screen because each screen possibly has 13705b261ecSmrg * a preferred engine specified on the command line. 13805b261ecSmrg */ 13905b261ecSmrg if (!winSetEngine (pScreen)) 14005b261ecSmrg { 14105b261ecSmrg ErrorF ("winScreenInit - winSetEngine () failed\n"); 14205b261ecSmrg return FALSE; 14305b261ecSmrg } 14405b261ecSmrg 14505b261ecSmrg /* Adjust the video mode for our engine type */ 14605b261ecSmrg if (!(*pScreenPriv->pwinAdjustVideoMode) (pScreen)) 14705b261ecSmrg { 14805b261ecSmrg ErrorF ("winScreenInit - winAdjustVideoMode () failed\n"); 14905b261ecSmrg return FALSE; 15005b261ecSmrg } 15105b261ecSmrg 15205b261ecSmrg /* Check for supported display depth */ 15305b261ecSmrg if (!(WIN_SUPPORTED_BPPS & (1 << (pScreenInfo->dwBPP - 1)))) 15405b261ecSmrg { 15505b261ecSmrg ErrorF ("winScreenInit - Unsupported display depth: %d\n" \ 15605b261ecSmrg "Change your Windows display depth to 15, 16, 24, or 32 bits " 15705b261ecSmrg "per pixel.\n", 15805b261ecSmrg (int) pScreenInfo->dwBPP); 15905b261ecSmrg ErrorF ("winScreenInit - Supported depths: %08x\n", 16005b261ecSmrg WIN_SUPPORTED_BPPS); 16105b261ecSmrg#if WIN_CHECK_DEPTH 16205b261ecSmrg return FALSE; 16305b261ecSmrg#endif 16405b261ecSmrg } 16505b261ecSmrg 16605b261ecSmrg /* 16705b261ecSmrg * Check that all monitors have the same display depth if we are using 16805b261ecSmrg * multiple monitors 16905b261ecSmrg */ 17005b261ecSmrg if (pScreenInfo->fMultipleMonitors 17105b261ecSmrg && !GetSystemMetrics (SM_SAMEDISPLAYFORMAT)) 17205b261ecSmrg { 17305b261ecSmrg ErrorF ("winScreenInit - Monitors do not all have same pixel format / " 17405b261ecSmrg "display depth.\n" 17505b261ecSmrg "Using primary display only.\n"); 17605b261ecSmrg pScreenInfo->fMultipleMonitors = FALSE; 17705b261ecSmrg } 17805b261ecSmrg 17905b261ecSmrg /* Create display window */ 18005b261ecSmrg if (!(*pScreenPriv->pwinCreateBoundingWindow) (pScreen)) 18105b261ecSmrg { 18205b261ecSmrg ErrorF ("winScreenInit - pwinCreateBoundingWindow () " 18305b261ecSmrg "failed\n"); 18405b261ecSmrg return FALSE; 18505b261ecSmrg } 18605b261ecSmrg 18705b261ecSmrg /* Get a device context */ 18805b261ecSmrg hdc = GetDC (pScreenPriv->hwndScreen); 18905b261ecSmrg 19005b261ecSmrg /* Store the initial height, width, and depth of the display */ 19105b261ecSmrg /* Are we using multiple monitors? */ 19205b261ecSmrg if (pScreenInfo->fMultipleMonitors) 19305b261ecSmrg { 19405b261ecSmrg pScreenPriv->dwLastWindowsWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN); 19505b261ecSmrg pScreenPriv->dwLastWindowsHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN); 19605b261ecSmrg 19705b261ecSmrg /* 19805b261ecSmrg * In this case, some of the defaults set in 1996747b715Smrg * winInitializeScreenDefaults() are not correct ... 20005b261ecSmrg */ 20105b261ecSmrg if (!pScreenInfo->fUserGaveHeightAndWidth) 20205b261ecSmrg { 20305b261ecSmrg pScreenInfo->dwWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN); 20405b261ecSmrg pScreenInfo->dwHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN); 20505b261ecSmrg pScreenInfo->dwWidth_mm = (pScreenInfo->dwWidth / 20605b261ecSmrg WIN_DEFAULT_DPI) * 25.4; 20705b261ecSmrg pScreenInfo->dwHeight_mm = (pScreenInfo->dwHeight / 20805b261ecSmrg WIN_DEFAULT_DPI) * 25.4; 20905b261ecSmrg } 21005b261ecSmrg } 21105b261ecSmrg else 21205b261ecSmrg { 21305b261ecSmrg pScreenPriv->dwLastWindowsWidth = GetSystemMetrics (SM_CXSCREEN); 21405b261ecSmrg pScreenPriv->dwLastWindowsHeight = GetSystemMetrics (SM_CYSCREEN); 21505b261ecSmrg } 21605b261ecSmrg 21705b261ecSmrg /* Save the original bits per pixel */ 21805b261ecSmrg pScreenPriv->dwLastWindowsBitsPixel = GetDeviceCaps (hdc, BITSPIXEL); 21905b261ecSmrg 22005b261ecSmrg /* Release the device context */ 22105b261ecSmrg ReleaseDC (pScreenPriv->hwndScreen, hdc); 22205b261ecSmrg 22305b261ecSmrg /* Clear the visuals list */ 22405b261ecSmrg miClearVisualTypes (); 22505b261ecSmrg 22605b261ecSmrg /* Set the padded screen width */ 22705b261ecSmrg pScreenInfo->dwPaddedWidth = PixmapBytePad (pScreenInfo->dwWidth, 22805b261ecSmrg pScreenInfo->dwBPP); 22905b261ecSmrg 23005b261ecSmrg /* Call the engine dependent screen initialization procedure */ 23105b261ecSmrg if (!((*pScreenPriv->pwinFinishScreenInit) (index, pScreen, argc, argv))) 23205b261ecSmrg { 23305b261ecSmrg ErrorF ("winScreenInit - winFinishScreenInit () failed\n"); 23405b261ecSmrg return FALSE; 23505b261ecSmrg } 23605b261ecSmrg 23705b261ecSmrg if (!g_fSoftwareCursor) 23805b261ecSmrg winInitCursor(pScreen); 23905b261ecSmrg else 24005b261ecSmrg winErrorFVerb(2, "winScreenInit - Using software cursor\n"); 24105b261ecSmrg 2426747b715Smrg /* 2436747b715Smrg Note the screen origin in a normalized coordinate space where (0,0) is at the top left 2446747b715Smrg of the native virtual desktop area 2456747b715Smrg */ 2466747b715Smrg pScreen->x = pScreenInfo->dwInitialX - GetSystemMetrics(SM_XVIRTUALSCREEN); 2476747b715Smrg pScreen->y = pScreenInfo->dwInitialY - GetSystemMetrics(SM_YVIRTUALSCREEN); 2486747b715Smrg 2496747b715Smrg ErrorF("Screen %d added at virtual desktop coordinate (%d,%d).\n", 2506747b715Smrg index, pScreen->x, pScreen->y); 2516747b715Smrg 25205b261ecSmrg#if CYGDEBUG || YES 25305b261ecSmrg winDebug ("winScreenInit - returning\n"); 25405b261ecSmrg#endif 25505b261ecSmrg 25605b261ecSmrg return TRUE; 25705b261ecSmrg} 25805b261ecSmrg 2596747b715Smrgstatic Bool 2606747b715SmrgwinCreateScreenResources(ScreenPtr pScreen) 2616747b715Smrg{ 2626747b715Smrg winScreenPriv(pScreen); 2636747b715Smrg Bool result; 2646747b715Smrg 2656747b715Smrg result = pScreenPriv->pwinCreateScreenResources(pScreen); 2666747b715Smrg 2676747b715Smrg /* Now the screen bitmap has been wrapped in a pixmap, 2686747b715Smrg add that to the Shadow framebuffer */ 2696747b715Smrg if (!shadowAdd(pScreen, pScreen->devPrivate, 2706747b715Smrg pScreenPriv->pwinShadowUpdate, NULL, 0, 0)) 2716747b715Smrg { 2726747b715Smrg ErrorF ("winCreateScreenResources - shadowAdd () failed\n"); 2736747b715Smrg return FALSE; 2746747b715Smrg } 2756747b715Smrg 2766747b715Smrg return result; 2776747b715Smrg} 27805b261ecSmrg 27905b261ecSmrg/* See Porting Layer Definition - p. 20 */ 28005b261ecSmrgBool 28105b261ecSmrgwinFinishScreenInitFB (int index, 28205b261ecSmrg ScreenPtr pScreen, 28305b261ecSmrg int argc, char **argv) 28405b261ecSmrg{ 28505b261ecSmrg winScreenPriv(pScreen); 28605b261ecSmrg winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; 28705b261ecSmrg VisualPtr pVisual = NULL; 28805b261ecSmrg char *pbits = NULL; 28905b261ecSmrg#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW) 29005b261ecSmrg int iReturn; 29105b261ecSmrg#endif 29205b261ecSmrg 29305b261ecSmrg /* Create framebuffer */ 29405b261ecSmrg if (!(*pScreenPriv->pwinAllocateFB) (pScreen)) 29505b261ecSmrg { 29605b261ecSmrg ErrorF ("winFinishScreenInitFB - Could not allocate framebuffer\n"); 29705b261ecSmrg return FALSE; 29805b261ecSmrg } 29905b261ecSmrg 30005b261ecSmrg /* 30105b261ecSmrg * Grab the number of bits that are used to represent color in each pixel. 30205b261ecSmrg */ 30305b261ecSmrg if (pScreenInfo->dwBPP == 8) 30405b261ecSmrg pScreenInfo->dwDepth = 8; 30505b261ecSmrg else 30605b261ecSmrg pScreenInfo->dwDepth = winCountBits (pScreenPriv->dwRedMask) 30705b261ecSmrg + winCountBits (pScreenPriv->dwGreenMask) 30805b261ecSmrg + winCountBits (pScreenPriv->dwBlueMask); 30905b261ecSmrg 31005b261ecSmrg winErrorFVerb (2, "winFinishScreenInitFB - Masks: %08x %08x %08x\n", 31105b261ecSmrg (unsigned int) pScreenPriv->dwRedMask, 31205b261ecSmrg (unsigned int) pScreenPriv->dwGreenMask, 31305b261ecSmrg (unsigned int) pScreenPriv->dwBlueMask); 31405b261ecSmrg 31505b261ecSmrg /* Init visuals */ 31605b261ecSmrg if (!(*pScreenPriv->pwinInitVisuals) (pScreen)) 31705b261ecSmrg { 31805b261ecSmrg ErrorF ("winFinishScreenInitFB - winInitVisuals failed\n"); 31905b261ecSmrg return FALSE; 32005b261ecSmrg } 32105b261ecSmrg 32205b261ecSmrg /* Setup a local variable to point to the framebuffer */ 32305b261ecSmrg pbits = pScreenInfo->pfb; 32405b261ecSmrg 32505b261ecSmrg /* Apparently we need this for the render extension */ 32605b261ecSmrg miSetPixmapDepths (); 32705b261ecSmrg 32805b261ecSmrg /* Start fb initialization */ 32905b261ecSmrg if (!fbSetupScreen (pScreen, 33005b261ecSmrg pScreenInfo->pfb, 33105b261ecSmrg pScreenInfo->dwWidth, pScreenInfo->dwHeight, 33205b261ecSmrg monitorResolution, monitorResolution, 33305b261ecSmrg pScreenInfo->dwStride, 33405b261ecSmrg pScreenInfo->dwBPP)) 33505b261ecSmrg { 33605b261ecSmrg ErrorF ("winFinishScreenInitFB - fbSetupScreen failed\n"); 33705b261ecSmrg return FALSE; 33805b261ecSmrg } 33905b261ecSmrg 34005b261ecSmrg /* Override default colormap routines if visual class is dynamic */ 34105b261ecSmrg if (pScreenInfo->dwDepth == 8 34205b261ecSmrg && (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_GDI 34305b261ecSmrg || (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL 34405b261ecSmrg && pScreenInfo->fFullScreen) 34505b261ecSmrg || (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD 34605b261ecSmrg && pScreenInfo->fFullScreen))) 34705b261ecSmrg { 34805b261ecSmrg winSetColormapFunctions (pScreen); 34905b261ecSmrg 35005b261ecSmrg /* 35105b261ecSmrg * NOTE: Setting whitePixel to 255 causes Magic 7.1 to allocate its 35205b261ecSmrg * own colormap, as it cannot allocate 7 planes in the default 35305b261ecSmrg * colormap. Setting whitePixel to 1 allows Magic to get 7 35405b261ecSmrg * planes in the default colormap, so it doesn't create its 35505b261ecSmrg * own colormap. This latter situation is highly desireable, 35605b261ecSmrg * as it keeps the Magic window viewable when switching to 35705b261ecSmrg * other X clients that use the default colormap. 35805b261ecSmrg */ 35905b261ecSmrg pScreen->blackPixel = 0; 36005b261ecSmrg pScreen->whitePixel = 1; 36105b261ecSmrg } 36205b261ecSmrg 36305b261ecSmrg /* Place our save screen function */ 36405b261ecSmrg pScreen->SaveScreen = winSaveScreen; 36505b261ecSmrg 36605b261ecSmrg /* Finish fb initialization */ 36705b261ecSmrg if (!fbFinishScreenInit (pScreen, 36805b261ecSmrg pScreenInfo->pfb, 36905b261ecSmrg pScreenInfo->dwWidth, pScreenInfo->dwHeight, 37005b261ecSmrg monitorResolution, monitorResolution, 37105b261ecSmrg pScreenInfo->dwStride, 37205b261ecSmrg pScreenInfo->dwBPP)) 37305b261ecSmrg { 37405b261ecSmrg ErrorF ("winFinishScreenInitFB - fbFinishScreenInit failed\n"); 37505b261ecSmrg return FALSE; 37605b261ecSmrg } 37705b261ecSmrg 37805b261ecSmrg /* Save a pointer to the root visual */ 37905b261ecSmrg for (pVisual = pScreen->visuals; 38005b261ecSmrg pVisual->vid != pScreen->rootVisual; 38105b261ecSmrg pVisual++); 38205b261ecSmrg pScreenPriv->pRootVisual = pVisual; 38305b261ecSmrg 38405b261ecSmrg /* 38505b261ecSmrg * Setup points to the block and wakeup handlers. Pass a pointer 38605b261ecSmrg * to the current screen as pWakeupdata. 38705b261ecSmrg */ 38805b261ecSmrg pScreen->BlockHandler = winBlockHandler; 38905b261ecSmrg pScreen->WakeupHandler = winWakeupHandler; 39005b261ecSmrg pScreen->blockData = pScreen; 39105b261ecSmrg pScreen->wakeupData = pScreen; 39205b261ecSmrg 39305b261ecSmrg /* Render extension initialization, calls miPictureInit */ 39405b261ecSmrg if (!fbPictureInit (pScreen, NULL, 0)) 39505b261ecSmrg { 39605b261ecSmrg ErrorF ("winFinishScreenInitFB - fbPictureInit () failed\n"); 39705b261ecSmrg return FALSE; 39805b261ecSmrg } 39905b261ecSmrg 40005b261ecSmrg#ifdef RANDR 40105b261ecSmrg /* Initialize resize and rotate support */ 40205b261ecSmrg if (!winRandRInit (pScreen)) 40305b261ecSmrg { 40405b261ecSmrg ErrorF ("winFinishScreenInitFB - winRandRInit () failed\n"); 40505b261ecSmrg return FALSE; 40605b261ecSmrg } 40705b261ecSmrg#endif 40805b261ecSmrg 40905b261ecSmrg /* 41005b261ecSmrg * Backing store support should reduce network traffic and increase 41105b261ecSmrg * performance. 41205b261ecSmrg */ 41305b261ecSmrg miInitializeBackingStore (pScreen); 41405b261ecSmrg 41505b261ecSmrg /* KDrive does miDCInitialize right after miInitializeBackingStore */ 41605b261ecSmrg /* Setup the cursor routines */ 41705b261ecSmrg#if CYGDEBUG 41805b261ecSmrg winDebug ("winFinishScreenInitFB - Calling miDCInitialize ()\n"); 41905b261ecSmrg#endif 42005b261ecSmrg miDCInitialize (pScreen, &g_winPointerCursorFuncs); 42105b261ecSmrg 42205b261ecSmrg /* KDrive does winCreateDefColormap right after miDCInitialize */ 42305b261ecSmrg /* Create a default colormap */ 42405b261ecSmrg#if CYGDEBUG 42505b261ecSmrg winDebug ("winFinishScreenInitFB - Calling winCreateDefColormap ()\n"); 42605b261ecSmrg#endif 42705b261ecSmrg if (!winCreateDefColormap (pScreen)) 42805b261ecSmrg { 42905b261ecSmrg ErrorF ("winFinishScreenInitFB - Could not create colormap\n"); 43005b261ecSmrg return FALSE; 43105b261ecSmrg } 43205b261ecSmrg 43305b261ecSmrg /* Initialize the shadow framebuffer layer */ 43405b261ecSmrg if ((pScreenInfo->dwEngine == WIN_SERVER_SHADOW_GDI 43505b261ecSmrg || pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD 43605b261ecSmrg || pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL) 43705b261ecSmrg#ifdef XWIN_MULTIWINDOWEXTWM 43805b261ecSmrg && !pScreenInfo->fMWExtWM 43905b261ecSmrg#endif 44005b261ecSmrg ) 44105b261ecSmrg { 44205b261ecSmrg#if CYGDEBUG 4436747b715Smrg winDebug ("winFinishScreenInitFB - Calling shadowSetup ()\n"); 44405b261ecSmrg#endif 4456747b715Smrg if (!shadowSetup(pScreen)) 44605b261ecSmrg { 4476747b715Smrg ErrorF ("winFinishScreenInitFB - shadowSetup () failed\n"); 44805b261ecSmrg return FALSE; 44905b261ecSmrg } 4506747b715Smrg 4516747b715Smrg /* Wrap CreateScreenResources so we can add the screen pixmap 4526747b715Smrg to the Shadow framebuffer after it's been created */ 4536747b715Smrg pScreenPriv->pwinCreateScreenResources = pScreen->CreateScreenResources; 4546747b715Smrg pScreen->CreateScreenResources = winCreateScreenResources; 45505b261ecSmrg } 45605b261ecSmrg 45705b261ecSmrg#ifdef XWIN_MULTIWINDOWEXTWM 45805b261ecSmrg /* Handle multi-window external window manager mode */ 45905b261ecSmrg if (pScreenInfo->fMWExtWM) 46005b261ecSmrg { 46105b261ecSmrg winDebug ("winScreenInit - MultiWindowExtWM - Calling RootlessInit\n"); 46205b261ecSmrg 46305b261ecSmrg RootlessInit(pScreen, &winMWExtWMProcs); 46405b261ecSmrg 46505b261ecSmrg winDebug ("winScreenInit - MultiWindowExtWM - RootlessInit returned\n"); 46605b261ecSmrg 46705b261ecSmrg rootless_CopyBytes_threshold = 0; 46805b261ecSmrg rootless_FillBytes_threshold = 0; 46905b261ecSmrg rootless_CompositePixels_threshold = 0; 47005b261ecSmrg /* FIXME: How many? Profiling needed? */ 47105b261ecSmrg rootless_CopyWindow_threshold = 1; 47205b261ecSmrg 47305b261ecSmrg winWindowsWMExtensionInit (); 47405b261ecSmrg } 47505b261ecSmrg#endif 47605b261ecSmrg 47705b261ecSmrg /* Handle rootless mode */ 47805b261ecSmrg if (pScreenInfo->fRootless) 47905b261ecSmrg { 48005b261ecSmrg /* Define the WRAP macro temporarily for local use */ 48105b261ecSmrg#define WRAP(a) \ 48205b261ecSmrg if (pScreen->a) { \ 48305b261ecSmrg pScreenPriv->a = pScreen->a; \ 48405b261ecSmrg } else { \ 48505b261ecSmrg ErrorF("null screen fn " #a "\n"); \ 48605b261ecSmrg pScreenPriv->a = NULL; \ 48705b261ecSmrg } 48805b261ecSmrg 48905b261ecSmrg /* Save a pointer to each lower-level window procedure */ 49005b261ecSmrg WRAP(CreateWindow); 49105b261ecSmrg WRAP(DestroyWindow); 49205b261ecSmrg WRAP(RealizeWindow); 49305b261ecSmrg WRAP(UnrealizeWindow); 49405b261ecSmrg WRAP(PositionWindow); 49505b261ecSmrg WRAP(ChangeWindowAttributes); 49605b261ecSmrg WRAP(SetShape); 49705b261ecSmrg 49805b261ecSmrg /* Assign rootless window procedures to be top level procedures */ 49905b261ecSmrg pScreen->CreateWindow = winCreateWindowRootless; 50005b261ecSmrg pScreen->DestroyWindow = winDestroyWindowRootless; 50105b261ecSmrg pScreen->PositionWindow = winPositionWindowRootless; 50205b261ecSmrg /*pScreen->ChangeWindowAttributes = winChangeWindowAttributesRootless;*/ 50305b261ecSmrg pScreen->RealizeWindow = winMapWindowRootless; 50405b261ecSmrg pScreen->UnrealizeWindow = winUnmapWindowRootless; 50505b261ecSmrg pScreen->SetShape = winSetShapeRootless; 50605b261ecSmrg 50705b261ecSmrg /* Undefine the WRAP macro, as it is not needed elsewhere */ 50805b261ecSmrg#undef WRAP 50905b261ecSmrg } 51005b261ecSmrg 51105b261ecSmrg 51205b261ecSmrg#ifdef XWIN_MULTIWINDOW 51305b261ecSmrg /* Handle multi window mode */ 51405b261ecSmrg else if (pScreenInfo->fMultiWindow) 51505b261ecSmrg { 51605b261ecSmrg /* Define the WRAP macro temporarily for local use */ 51705b261ecSmrg#define WRAP(a) \ 51805b261ecSmrg if (pScreen->a) { \ 51905b261ecSmrg pScreenPriv->a = pScreen->a; \ 52005b261ecSmrg } else { \ 52105b261ecSmrg ErrorF("null screen fn " #a "\n"); \ 52205b261ecSmrg pScreenPriv->a = NULL; \ 52305b261ecSmrg } 52405b261ecSmrg 52505b261ecSmrg /* Save a pointer to each lower-level window procedure */ 52605b261ecSmrg WRAP(CreateWindow); 52705b261ecSmrg WRAP(DestroyWindow); 52805b261ecSmrg WRAP(RealizeWindow); 52905b261ecSmrg WRAP(UnrealizeWindow); 53005b261ecSmrg WRAP(PositionWindow); 53105b261ecSmrg WRAP(ChangeWindowAttributes); 53205b261ecSmrg WRAP(ReparentWindow); 53305b261ecSmrg WRAP(RestackWindow); 53405b261ecSmrg WRAP(ResizeWindow); 53505b261ecSmrg WRAP(MoveWindow); 53605b261ecSmrg WRAP(CopyWindow); 53705b261ecSmrg WRAP(SetShape); 53805b261ecSmrg 53905b261ecSmrg /* Assign multi-window window procedures to be top level procedures */ 54005b261ecSmrg pScreen->CreateWindow = winCreateWindowMultiWindow; 54105b261ecSmrg pScreen->DestroyWindow = winDestroyWindowMultiWindow; 54205b261ecSmrg pScreen->PositionWindow = winPositionWindowMultiWindow; 54305b261ecSmrg /*pScreen->ChangeWindowAttributes = winChangeWindowAttributesMultiWindow;*/ 54405b261ecSmrg pScreen->RealizeWindow = winMapWindowMultiWindow; 54505b261ecSmrg pScreen->UnrealizeWindow = winUnmapWindowMultiWindow; 54605b261ecSmrg pScreen->ReparentWindow = winReparentWindowMultiWindow; 54705b261ecSmrg pScreen->RestackWindow = winRestackWindowMultiWindow; 54805b261ecSmrg pScreen->ResizeWindow = winResizeWindowMultiWindow; 54905b261ecSmrg pScreen->MoveWindow = winMoveWindowMultiWindow; 55005b261ecSmrg pScreen->CopyWindow = winCopyWindowMultiWindow; 55105b261ecSmrg pScreen->SetShape = winSetShapeMultiWindow; 55205b261ecSmrg 55305b261ecSmrg /* Undefine the WRAP macro, as it is not needed elsewhere */ 55405b261ecSmrg#undef WRAP 55505b261ecSmrg } 55605b261ecSmrg#endif 55705b261ecSmrg 55805b261ecSmrg /* Wrap either fb's or shadow's CloseScreen with our CloseScreen */ 55905b261ecSmrg pScreenPriv->CloseScreen = pScreen->CloseScreen; 56005b261ecSmrg pScreen->CloseScreen = pScreenPriv->pwinCloseScreen; 56105b261ecSmrg 56205b261ecSmrg#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW) 56305b261ecSmrg /* Create a mutex for modules in separate threads to wait for */ 56405b261ecSmrg iReturn = pthread_mutex_init (&pScreenPriv->pmServerStarted, NULL); 56505b261ecSmrg if (iReturn != 0) 56605b261ecSmrg { 56705b261ecSmrg ErrorF ("winFinishScreenInitFB - pthread_mutex_init () failed: %d\n", 56805b261ecSmrg iReturn); 56905b261ecSmrg return FALSE; 57005b261ecSmrg } 57105b261ecSmrg 57205b261ecSmrg /* Own the mutex for modules in separate threads */ 57305b261ecSmrg iReturn = pthread_mutex_lock (&pScreenPriv->pmServerStarted); 57405b261ecSmrg if (iReturn != 0) 57505b261ecSmrg { 57605b261ecSmrg ErrorF ("winFinishScreenInitFB - pthread_mutex_lock () failed: %d\n", 57705b261ecSmrg iReturn); 57805b261ecSmrg return FALSE; 57905b261ecSmrg } 58005b261ecSmrg 58105b261ecSmrg /* Set the ServerStarted flag to false */ 58205b261ecSmrg pScreenPriv->fServerStarted = FALSE; 58305b261ecSmrg#endif 58405b261ecSmrg 58505b261ecSmrg#ifdef XWIN_MULTIWINDOWEXTWM 58605b261ecSmrg pScreenPriv->fRestacking = FALSE; 58705b261ecSmrg#endif 58805b261ecSmrg 58905b261ecSmrg#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM) 59005b261ecSmrg if (FALSE 59105b261ecSmrg#ifdef XWIN_MULTIWINDOW 59205b261ecSmrg || pScreenInfo->fMultiWindow 59305b261ecSmrg#endif 59405b261ecSmrg#ifdef XWIN_MULTIWINDOWEXTWM 59505b261ecSmrg || pScreenInfo->fInternalWM 59605b261ecSmrg#endif 59705b261ecSmrg ) 59805b261ecSmrg { 59905b261ecSmrg#if CYGDEBUG || YES 60005b261ecSmrg winDebug ("winFinishScreenInitFB - Calling winInitWM.\n"); 60105b261ecSmrg#endif 60205b261ecSmrg 60305b261ecSmrg /* Initialize multi window mode */ 60405b261ecSmrg if (!winInitWM (&pScreenPriv->pWMInfo, 60505b261ecSmrg &pScreenPriv->ptWMProc, 60605b261ecSmrg &pScreenPriv->ptXMsgProc, 60705b261ecSmrg &pScreenPriv->pmServerStarted, 60805b261ecSmrg pScreenInfo->dwScreen, 60905b261ecSmrg (HWND)&pScreenPriv->hwndScreen, 61005b261ecSmrg#ifdef XWIN_MULTIWINDOWEXTWM 61105b261ecSmrg pScreenInfo->fInternalWM || 61205b261ecSmrg#endif 61305b261ecSmrg FALSE)) 61405b261ecSmrg { 61505b261ecSmrg ErrorF ("winFinishScreenInitFB - winInitWM () failed.\n"); 61605b261ecSmrg return FALSE; 61705b261ecSmrg } 61805b261ecSmrg } 61905b261ecSmrg#endif 62005b261ecSmrg 62105b261ecSmrg /* Tell the server that we are enabled */ 62205b261ecSmrg pScreenPriv->fEnabled = TRUE; 62305b261ecSmrg 62405b261ecSmrg /* Tell the server that we have a valid depth */ 62505b261ecSmrg pScreenPriv->fBadDepth = FALSE; 62605b261ecSmrg 62705b261ecSmrg#if CYGDEBUG || YES 62805b261ecSmrg winDebug ("winFinishScreenInitFB - returning\n"); 62905b261ecSmrg#endif 63005b261ecSmrg 63105b261ecSmrg return TRUE; 63205b261ecSmrg} 63305b261ecSmrg 63405b261ecSmrg#ifdef XWIN_NATIVEGDI 63505b261ecSmrg/* See Porting Layer Definition - p. 20 */ 63605b261ecSmrg 63705b261ecSmrgBool 63805b261ecSmrgwinFinishScreenInitNativeGDI (int index, 63905b261ecSmrg ScreenPtr pScreen, 64005b261ecSmrg int argc, char **argv) 64105b261ecSmrg{ 64205b261ecSmrg winScreenPriv(pScreen); 64305b261ecSmrg winScreenInfoPtr pScreenInfo = &g_ScreenInfo[index]; 64405b261ecSmrg VisualPtr pVisuals = NULL; 64505b261ecSmrg DepthPtr pDepths = NULL; 64605b261ecSmrg VisualID rootVisual = 0; 64705b261ecSmrg int nVisuals = 0, nDepths = 0, nRootDepth = 0; 64805b261ecSmrg 64905b261ecSmrg /* Ignore user input (mouse, keyboard) */ 65005b261ecSmrg pScreenInfo->fIgnoreInput = FALSE; 65105b261ecSmrg 65205b261ecSmrg /* Get device contexts for the screen and shadow bitmap */ 65305b261ecSmrg pScreenPriv->hdcScreen = GetDC (pScreenPriv->hwndScreen); 65405b261ecSmrg if (pScreenPriv->hdcScreen == NULL) 65505b261ecSmrg FatalError ("winFinishScreenInitNativeGDI - Couldn't get a DC\n"); 65605b261ecSmrg 65705b261ecSmrg /* Init visuals */ 65805b261ecSmrg if (!(*pScreenPriv->pwinInitVisuals) (pScreen)) 65905b261ecSmrg { 66005b261ecSmrg ErrorF ("winFinishScreenInitNativeGDI - pwinInitVisuals failed\n"); 66105b261ecSmrg return FALSE; 66205b261ecSmrg } 66305b261ecSmrg 66405b261ecSmrg /* Initialize the mi visuals */ 66505b261ecSmrg if (!miInitVisuals (&pVisuals, &pDepths, &nVisuals, &nDepths, &nRootDepth, 66605b261ecSmrg &rootVisual, 66705b261ecSmrg ((unsigned long)1 << (pScreenInfo->dwDepth - 1)), 8, 66805b261ecSmrg TrueColor)) 66905b261ecSmrg { 67005b261ecSmrg ErrorF ("winFinishScreenInitNativeGDI - miInitVisuals () failed\n"); 67105b261ecSmrg return FALSE; 67205b261ecSmrg } 67305b261ecSmrg 67405b261ecSmrg /* Initialize the CloseScreen procedure pointer */ 67505b261ecSmrg pScreen->CloseScreen = NULL; 67605b261ecSmrg 67705b261ecSmrg /* Initialize the mi code */ 67805b261ecSmrg if (!miScreenInit (pScreen, 67905b261ecSmrg NULL, /* No framebuffer */ 68005b261ecSmrg pScreenInfo->dwWidth, pScreenInfo->dwHeight, 68105b261ecSmrg monitorResolution, monitorResolution, 68205b261ecSmrg pScreenInfo->dwStride, 68305b261ecSmrg nRootDepth, nDepths, pDepths, rootVisual, 68405b261ecSmrg nVisuals, pVisuals)) 68505b261ecSmrg { 68605b261ecSmrg ErrorF ("winFinishScreenInitNativeGDI - miScreenInit failed\n"); 68705b261ecSmrg return FALSE; 68805b261ecSmrg } 68905b261ecSmrg 69005b261ecSmrg pScreen->defColormap = FakeClientID(0); 69105b261ecSmrg 69205b261ecSmrg /* 69305b261ecSmrg * Register our block and wakeup handlers; these procedures 69405b261ecSmrg * process messages in our Windows message queue; specifically, 69505b261ecSmrg * they process mouse and keyboard input. 69605b261ecSmrg */ 69705b261ecSmrg pScreen->BlockHandler = winBlockHandler; 69805b261ecSmrg pScreen->WakeupHandler = winWakeupHandler; 69905b261ecSmrg pScreen->blockData = pScreen; 70005b261ecSmrg pScreen->wakeupData = pScreen; 70105b261ecSmrg 70205b261ecSmrg /* Place our save screen function */ 70305b261ecSmrg pScreen->SaveScreen = winSaveScreen; 70405b261ecSmrg 70505b261ecSmrg /* Pixmaps */ 70605b261ecSmrg pScreen->CreatePixmap = winCreatePixmapNativeGDI; 70705b261ecSmrg pScreen->DestroyPixmap = winDestroyPixmapNativeGDI; 70805b261ecSmrg 70905b261ecSmrg /* Other Screen Routines */ 71005b261ecSmrg pScreen->QueryBestSize = winQueryBestSizeNativeGDI; 71105b261ecSmrg pScreen->SaveScreen = winSaveScreen; 71205b261ecSmrg pScreen->GetImage = miGetImage; 71305b261ecSmrg pScreen->GetSpans = winGetSpansNativeGDI; 71405b261ecSmrg 71505b261ecSmrg /* Window Procedures */ 71605b261ecSmrg pScreen->CreateWindow = winCreateWindowNativeGDI; 71705b261ecSmrg pScreen->DestroyWindow = winDestroyWindowNativeGDI; 71805b261ecSmrg pScreen->PositionWindow = winPositionWindowNativeGDI; 71905b261ecSmrg /*pScreen->ChangeWindowAttributes = winChangeWindowAttributesNativeGDI;*/ 72005b261ecSmrg pScreen->RealizeWindow = winMapWindowNativeGDI; 72105b261ecSmrg pScreen->UnrealizeWindow = winUnmapWindowNativeGDI; 72205b261ecSmrg 72305b261ecSmrg /* Paint window */ 72405b261ecSmrg pScreen->CopyWindow = winCopyWindowNativeGDI; 72505b261ecSmrg 72605b261ecSmrg /* Fonts */ 72705b261ecSmrg pScreen->RealizeFont = winRealizeFontNativeGDI; 72805b261ecSmrg pScreen->UnrealizeFont = winUnrealizeFontNativeGDI; 72905b261ecSmrg 73005b261ecSmrg /* GC */ 73105b261ecSmrg pScreen->CreateGC = winCreateGCNativeGDI; 73205b261ecSmrg 73305b261ecSmrg /* Colormap Routines */ 73405b261ecSmrg pScreen->CreateColormap = miInitializeColormap; 73505b261ecSmrg pScreen->DestroyColormap = (DestroyColormapProcPtr) (void (*)(void)) NoopDDA; 73605b261ecSmrg pScreen->InstallColormap = miInstallColormap; 73705b261ecSmrg pScreen->UninstallColormap = miUninstallColormap; 73805b261ecSmrg pScreen->ListInstalledColormaps = miListInstalledColormaps; 73905b261ecSmrg pScreen->StoreColors = (StoreColorsProcPtr) (void (*)(void)) NoopDDA; 74005b261ecSmrg pScreen->ResolveColor = miResolveColor; 74105b261ecSmrg 74205b261ecSmrg /* Bitmap */ 74305b261ecSmrg pScreen->BitmapToRegion = winPixmapToRegionNativeGDI; 74405b261ecSmrg 74505b261ecSmrg ErrorF ("winFinishScreenInitNativeGDI - calling miDCInitialize\n"); 74605b261ecSmrg 74705b261ecSmrg /* Set the default white and black pixel positions */ 74805b261ecSmrg pScreen->whitePixel = pScreen->blackPixel = (Pixel) 0; 74905b261ecSmrg 75005b261ecSmrg /* Initialize the cursor */ 75105b261ecSmrg if (!miDCInitialize (pScreen, &g_winPointerCursorFuncs)) 75205b261ecSmrg { 75305b261ecSmrg ErrorF ("winFinishScreenInitNativeGDI - miDCInitialize failed\n"); 75405b261ecSmrg return FALSE; 75505b261ecSmrg } 75605b261ecSmrg 75705b261ecSmrg /* Create a default colormap */ 75805b261ecSmrg if (!miCreateDefColormap (pScreen)) 75905b261ecSmrg { 76005b261ecSmrg ErrorF ("winFinishScreenInitNativeGDI - miCreateDefColormap () " 76105b261ecSmrg "failed\n"); 76205b261ecSmrg return FALSE; 76305b261ecSmrg } 76405b261ecSmrg 76505b261ecSmrg ErrorF ("winFinishScreenInitNativeGDI - miCreateDefColormap () " 76605b261ecSmrg "returned\n"); 76705b261ecSmrg 76805b261ecSmrg /* mi doesn't use a CloseScreen procedure, so no need to wrap */ 76905b261ecSmrg pScreen->CloseScreen = pScreenPriv->pwinCloseScreen; 77005b261ecSmrg 77105b261ecSmrg /* Tell the server that we are enabled */ 77205b261ecSmrg pScreenPriv->fEnabled = TRUE; 77305b261ecSmrg 77405b261ecSmrg ErrorF ("winFinishScreenInitNativeGDI - Successful addition of " 77505b261ecSmrg "screen %08x\n", 77605b261ecSmrg (unsigned int) pScreen); 77705b261ecSmrg 77805b261ecSmrg return TRUE; 77905b261ecSmrg} 78005b261ecSmrg#endif 78105b261ecSmrg 78205b261ecSmrg 78305b261ecSmrg/* See Porting Layer Definition - p. 33 */ 78405b261ecSmrgstatic Bool 78505b261ecSmrgwinSaveScreen (ScreenPtr pScreen, int on) 78605b261ecSmrg{ 78705b261ecSmrg return TRUE; 78805b261ecSmrg} 789