#include "win.h"
Bool
winScreenInit (int index,
ScreenPtr pScreen,
int argc, char **argv)
{
winScreenInfoPtr pScreenInfo = &g_ScreenInfo[index];
winPrivScreenPtr pScreenPriv;
HDC hdc;
#if CYGDEBUG
ErrorF ("winScreenInit - dwWidth: %d dwHeight: %d\n",
pScreenInfo->dwWidth, pScreenInfo->dwHeight);
#endif
if (!winAllocatePrivates (pScreen))
{
ErrorF ("winScreenInit - Couldn't allocate screen privates\n");
return FALSE;
}
pScreenPriv = winGetScreenPriv (pScreen);
pScreenInfo->pScreen = pScreen;
pScreenPriv->pScreenInfo = pScreenInfo;
if (!winSetEngine (pScreen))
{
ErrorF ("winScreenInit - winSetEngine () failed\n");
return FALSE;
}
if (!(*pScreenPriv->pwinAdjustVideoMode) (pScreen))
{
ErrorF ("winScreenInit - winAdjustVideoMode () failed\n");
return FALSE;
}
if (!(WIN_SUPPORTED_BPPS & (1 << (pScreenInfo->dwBPP - 1))))
{
ErrorF ("winScreenInit - Unsupported display depth: %d\n" \
"Change your Windows display depth to 15, 16, 24, or 32 bits "
"per pixel.\n",
pScreenInfo->dwBPP);
ErrorF ("winScreenInit - Supported depths: %08x\n",
WIN_SUPPORTED_BPPS);
#if WIN_CHECK_DEPTH
return FALSE;
#endif
}
if (pScreenInfo->fMultipleMonitors
&& !GetSystemMetrics (SM_SAMEDISPLAYFORMAT))
{
ErrorF ("winScreenInit - Monitors do not all have same pixel format / "
"display depth.\n"
"Using primary display only.\n");
pScreenInfo->fMultipleMonitors = FALSE;
}
if (!(*pScreenPriv->pwinCreateBoundingWindow) (pScreen))
{
ErrorF ("winScreenInit - pwinCreateBoundingWindow () "
"failed\n");
return FALSE;
}
hdc = GetDC (pScreenPriv->hwndScreen);
if (pScreenInfo->fMultipleMonitors)
{
pScreenPriv->dwLastWindowsWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN);
pScreenPriv->dwLastWindowsHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN);
if (!pScreenInfo->fUserGaveHeightAndWidth)
{
pScreenInfo->dwWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN);
pScreenInfo->dwHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN);
pScreenInfo->dwWidth_mm = (pScreenInfo->dwWidth /
WIN_DEFAULT_DPI) * 25.4;
pScreenInfo->dwHeight_mm = (pScreenInfo->dwHeight /
WIN_DEFAULT_DPI) * 25.4;
}
}
else
{
pScreenPriv->dwLastWindowsWidth = GetSystemMetrics (SM_CXSCREEN);
pScreenPriv->dwLastWindowsHeight = GetSystemMetrics (SM_CYSCREEN);
}
pScreenPriv->dwLastWindowsBitsPixel = GetDeviceCaps (hdc, BITSPIXEL);
ReleaseDC (pScreenPriv->hwndScreen, hdc);
miClearVisualTypes ();
pScreenInfo->dwPaddedWidth = PixmapBytePad (pScreenInfo->dwWidth,
pScreenInfo->dwBPP);
if (!((*pScreenPriv->pwinFinishScreenInit) (index, pScreen, argc, argv)))
{
ErrorF ("winScreenInit - winFinishScreenInit () failed\n");
return FALSE;
}
#if CYGDEBUG || YES
ErrorF ("winScreenInit - returning\n");
#endif
return TRUE;
}
Bool
winFinishScreenInitFB (int index,
ScreenPtr pScreen,
int argc, char **argv)
{
winScreenPriv(pScreen);
winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
VisualPtr pVisual = NULL;
char *pbits = NULL;
int iReturn;
#if WIN_LAYER_SUPPORT
pScreenPriv->dwLayerKind = LAYER_SHADOW;
#endif
if (!(*pScreenPriv->pwinAllocateFB) (pScreen))
{
ErrorF ("winFinishScreenInitFB - Could not allocate framebuffer\n");
return FALSE;
}
if (pScreenInfo->dwBPP == 8)
pScreenInfo->dwDepth = 8;
else
pScreenInfo->dwDepth = winCountBits (pScreenPriv->dwRedMask)
+ winCountBits (pScreenPriv->dwGreenMask)
+ winCountBits (pScreenPriv->dwBlueMask);
ErrorF ("winFinishScreenInitFB - Masks: %08x %08x %08x\n",
pScreenPriv->dwRedMask, pScreenPriv->dwGreenMask,
pScreenPriv->dwBlueMask);
if (!(*pScreenPriv->pwinInitVisuals) (pScreen))
{
ErrorF ("winFinishScreenInitFB - winInitVisuals failed\n");
return FALSE;
}
pbits = pScreenInfo->pfb;
miSetPixmapDepths ();
if (!fbSetupScreen (pScreen,
pScreenInfo->pfb,
pScreenInfo->dwWidth, pScreenInfo->dwHeight,
monitorResolution, monitorResolution,
pScreenInfo->dwStride,
pScreenInfo->dwBPP))
{
ErrorF ("winFinishScreenInitFB - fbSetupScreen failed\n");
return FALSE;
}
if (pScreenInfo->dwDepth == 8
&& (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_GDI
|| (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL
&& pScreenInfo->fFullScreen)
|| (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD
&& pScreenInfo->fFullScreen)))
{
pScreen->CreateColormap = winCreateColormap;
pScreen->DestroyColormap = winDestroyColormap;
pScreen->InstallColormap = winInstallColormap;
pScreen->UninstallColormap = winUninstallColormap;
pScreen->ListInstalledColormaps = winListInstalledColormaps;
pScreen->StoreColors = winStoreColors;
pScreen->ResolveColor = winResolveColor;
pScreen->blackPixel = 0;
pScreen->whitePixel = 1;
}
pScreen->SaveScreen = winSaveScreen;
pScreen->BackingStoreFuncs.SaveAreas = fbSaveAreas;
pScreen->BackingStoreFuncs.RestoreAreas = fbRestoreAreas;
if (!fbFinishScreenInit (pScreen,
pScreenInfo->pfb,
pScreenInfo->dwWidth, pScreenInfo->dwHeight,
monitorResolution, monitorResolution,
pScreenInfo->dwStride,
pScreenInfo->dwBPP))
{
ErrorF ("winFinishScreenInitFB - fbFinishScreenInit failed\n");
return FALSE;
}
for (pVisual = pScreen->visuals;
pVisual->vid != pScreen->rootVisual;
pVisual++);
pScreenPriv->pRootVisual = pVisual;
pScreen->BlockHandler = winBlockHandler;
pScreen->WakeupHandler = winWakeupHandler;
pScreen->blockData = pScreen;
pScreen->wakeupData = pScreen;
#ifdef RENDER
if (!fbPictureInit (pScreen, NULL, 0))
{
ErrorF ("winFinishScreenInitFB - fbPictureInit () failed\n");
return FALSE;
}
#endif
#if WIN_LAYER_SUPPORT
if (!LayerStartInit (pScreen))
{
ErrorF ("winFinishScreenInitFB - LayerStartInit () failed\n");
return FALSE;
}
if (!shadowAdd (pScreen, 0, pScreenPriv->pwinShadowUpdate, NULL, 0, 0))
{
ErrorF ("winFinishScreenInitFB - shadowAdd () failed\n");
return FALSE;
}
if (!LayerFinishInit (pScreen))
{
ErrorF ("winFinishScreenInitFB - LayerFinishInit () failed\n");
return FALSE;
}
pScreenPriv->pLayer = winLayerCreate (pScreen);
if (!pScreenPriv->pLayer)
{
ErrorF ("winFinishScreenInitFB - winLayerCreate () failed\n");
return FALSE;
}
#ifdef RANDR
if (pScreenInfo->dwDepth != 8 && !winRandRInit (pScreen))
{
ErrorF ("winFinishScreenInitFB - winRandRInit () failed\n");
return FALSE;
}
#endif
#endif
miInitializeBackingStore (pScreen);
#if CYGDEBUG
ErrorF ("winFinishScreenInitFB - Calling miDCInitialize ()\n");
#endif
miDCInitialize (pScreen, &g_winPointerCursorFuncs);
#if CYGDEBUG
ErrorF ("winFinishScreenInitFB - Calling winCreateDefColormap ()\n");
#endif
if (!winCreateDefColormap (pScreen))
{
ErrorF ("winFinishScreenInitFB - Could not create colormap\n");
return FALSE;
}
#if !WIN_LAYER_SUPPORT
if (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_GDI
|| pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD
|| pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL)
{
#if CYGDEBUG
ErrorF ("winFinishScreenInitFB - Calling shadowInit ()\n");
#endif
if (!shadowInit (pScreen,
pScreenPriv->pwinShadowUpdate,
NULL))
{
ErrorF ("winFinishScreenInitFB - shadowInit () failed\n");
return FALSE;
}
}
#endif
if (pScreenInfo->fRootless)
{
#define WRAP(a) \
if (pScreen->a) { \
pScreenPriv->a = pScreen->a; \
} else { \
ErrorF("null screen fn " #a "\n"); \
pScreenPriv->a = NULL; \
}
WRAP(CreateWindow);
WRAP(DestroyWindow);
WRAP(RealizeWindow);
WRAP(UnrealizeWindow);
WRAP(PositionWindow);
WRAP(ChangeWindowAttributes);
#ifdef SHAPE
WRAP(SetShape);
#endif
pScreen->CreateWindow = winCreateWindowPRootless;
pScreen->DestroyWindow = winDestroyWindowPRootless;
pScreen->PositionWindow = winPositionWindowPRootless;
pScreen->ChangeWindowAttributes = winChangeWindowAttributesPRootless;
pScreen->RealizeWindow = winMapWindowPRootless;
pScreen->UnrealizeWindow = winUnmapWindowPRootless;
#ifdef SHAPE
pScreen->SetShape = winSetShapePRootless;
#endif
#undef WRAP
}
else if (pScreenInfo->fMultiWindow)
{
#define WRAP(a) \
if (pScreen->a) { \
pScreenPriv->a = pScreen->a; \
} else { \
ErrorF("null screen fn " #a "\n"); \
pScreenPriv->a = NULL; \
}
WRAP(CreateWindow);
WRAP(DestroyWindow);
WRAP(RealizeWindow);
WRAP(UnrealizeWindow);
WRAP(PositionWindow);
WRAP(ChangeWindowAttributes);
WRAP(ReparentWindow);
WRAP(RestackWindow);
#ifdef SHAPE
WRAP(SetShape);
#endif
pScreen->CreateWindow = winCreateWindowMultiWindow;
pScreen->DestroyWindow = winDestroyWindowMultiWindow;
pScreen->PositionWindow = winPositionWindowMultiWindow;
pScreen->ChangeWindowAttributes = winChangeWindowAttributesMultiWindow;
pScreen->RealizeWindow = winMapWindowMultiWindow;
pScreen->UnrealizeWindow = winUnmapWindowMultiWindow;
pScreen->ReparentWindow = winReparentWindowMultiWindow;
pScreen->RestackWindow = winRestackWindowMultiWindow;
#ifdef SHAPE
pScreen->SetShape = winSetShapeMultiWindow;
#endif
#undef WRAP
}
pScreenPriv->CloseScreen = pScreen->CloseScreen;
pScreen->CloseScreen = pScreenPriv->pwinCloseScreen;
iReturn = pthread_mutex_init (&pScreenPriv->pmServerStarted, NULL);
if (iReturn != 0)
{
ErrorF ("winFinishScreenInitFB - pthread_mutex_init () failed: %d\n",
iReturn);
return FALSE;
}
iReturn = pthread_mutex_lock (&pScreenPriv->pmServerStarted);
if (iReturn != 0)
{
ErrorF ("winFinishScreenInitFB - pthread_mutex_lock () failed: %d\n",
iReturn);
return FALSE;
}
pScreenPriv->fServerStarted = FALSE;
pScreenPriv->fWindowOrderChanged = FALSE;
pScreenPriv->fRestacking = FALSE;
#if CYGDEBUG || YES
if (pScreenInfo->fMultiWindow)
ErrorF ("winFinishScreenInitFB - Calling winInitWM.\n");
#endif
if (pScreenInfo->fMultiWindow
&& !winInitWM (&pScreenPriv->pWMInfo,
&pScreenPriv->ptWMProc,
&pScreenPriv->ptXMsgProc,
&pScreenPriv->pmServerStarted,
pScreenInfo->dwScreen))
{
ErrorF ("winFinishScreenInitFB - winInitWM () failed.\n");
return FALSE;
}
#if CYGDEBUG || YES
if (pScreenInfo->fClipboard)
ErrorF ("winFinishScreenInitFB - Calling winInitClipboard.\n");
#endif
if (pScreenInfo->fClipboard
&& !winInitClipboard (&pScreenPriv->ptClipboardProc,
&pScreenPriv->pmServerStarted,
pScreenInfo->dwScreen))
{
ErrorF ("winFinishScreenInitFB - winClipboardInit () failed.\n");
return FALSE;
}
pScreenPriv->fEnabled = TRUE;
pScreenPriv->fBadDepth = FALSE;
#if CYGDEBUG || YES
ErrorF ("winFinishScreenInitFB - returning\n");
#endif
return TRUE;
}
Bool
winFinishScreenInitNativeGDI (int index,
ScreenPtr pScreen,
int argc, char **argv)
{
winScreenPriv(pScreen);
winScreenInfoPtr pScreenInfo = &g_ScreenInfo[index];
VisualPtr pVisuals = NULL;
DepthPtr pDepths = NULL;
VisualID rootVisual = 0;
int nVisuals = 0, nDepths = 0, nRootDepth = 0;
pScreenInfo->fIgnoreInput = FALSE;
pScreenPriv->hdcScreen = GetDC (pScreenPriv->hwndScreen);
if (pScreenPriv->hdcScreen == NULL)
FatalError ("winFinishScreenInitNativeGDI - Couldn't get a DC\n");
if (!(*pScreenPriv->pwinInitVisuals) (pScreen))
{
ErrorF ("winFinishScreenInitNativeGDI - pwinInitVisuals failed\n");
return FALSE;
}
if (!miInitVisuals (&pVisuals, &pDepths, &nVisuals, &nDepths, &nRootDepth,
&rootVisual,
((unsigned long)1 << (pScreenInfo->dwDepth - 1)), 8,
TrueColor))
{
ErrorF ("winFinishScreenInitNativeGDI - miInitVisuals () failed\n");
return FALSE;
}
pScreen->CloseScreen = NULL;
if (!miScreenInit (pScreen,
NULL,
pScreenInfo->dwWidth, pScreenInfo->dwHeight,
monitorResolution, monitorResolution,
pScreenInfo->dwStride,
nRootDepth, nDepths, pDepths, rootVisual,
nVisuals, pVisuals))
{
ErrorF ("winFinishScreenInitNativeGDI - miScreenInit failed\n");
return FALSE;
}
pScreen->defColormap = FakeClientID(0);
pScreen->BlockHandler = winBlockHandler;
pScreen->WakeupHandler = winWakeupHandler;
pScreen->blockData = pScreen;
pScreen->wakeupData = pScreen;
pScreen->SaveScreen = winSaveScreen;
pScreen->CreatePixmap = winCreatePixmapNativeGDI;
pScreen->DestroyPixmap = winDestroyPixmapNativeGDI;
pScreen->QueryBestSize = winQueryBestSizeNativeGDI;
pScreen->SaveScreen = winSaveScreen;
pScreen->GetImage = miGetImage;
pScreen->GetSpans = winGetSpansNativeGDI;
pScreen->CreateWindow = winCreateWindowNativeGDI;
pScreen->DestroyWindow = winDestroyWindowNativeGDI;
pScreen->PositionWindow = winPositionWindowNativeGDI;
pScreen->ChangeWindowAttributes = winChangeWindowAttributesNativeGDI;
pScreen->RealizeWindow = winMapWindowNativeGDI;
pScreen->UnrealizeWindow = winUnmapWindowNativeGDI;
pScreen->PaintWindowBackground = miPaintWindow;
pScreen->PaintWindowBorder = miPaintWindow;
pScreen->CopyWindow = winCopyWindowNativeGDI;
pScreen->RealizeFont = winRealizeFontNativeGDI;
pScreen->UnrealizeFont = winUnrealizeFontNativeGDI;
pScreen->CreateGC = winCreateGCNativeGDI;
pScreen->CreateColormap = miInitializeColormap;
pScreen->DestroyColormap = (DestroyColormapProcPtr) (void (*)()) NoopDDA;
pScreen->InstallColormap = miInstallColormap;
pScreen->UninstallColormap = miUninstallColormap;
pScreen->ListInstalledColormaps = miListInstalledColormaps;
pScreen->StoreColors = (StoreColorsProcPtr) (void (*)()) NoopDDA;
pScreen->ResolveColor = miResolveColor;
pScreen->BitmapToRegion = winPixmapToRegionNativeGDI;
ErrorF ("winFinishScreenInitNativeGDI - calling miDCInitialize\n");
pScreen->whitePixel = pScreen->blackPixel = (Pixel) 0;
if (!miDCInitialize (pScreen, &g_winPointerCursorFuncs))
{
ErrorF ("winFinishScreenInitNativeGDI - miDCInitialize failed\n");
return FALSE;
}
if (!miCreateDefColormap (pScreen))
{
ErrorF ("winFinishScreenInitNativeGDI - miCreateDefColormap () "
"failed\n");
return FALSE;
}
ErrorF ("winFinishScreenInitNativeGDI - miCreateDefColormap () "
"returned\n");
pScreen->CloseScreen = pScreenPriv->pwinCloseScreen;
pScreenPriv->fEnabled = TRUE;
ErrorF ("winFinishScreenInitNativeGDI - Successful addition of "
"screen %08x\n",
pScreen);
return TRUE;
}
Bool
winSaveScreen (ScreenPtr pScreen, int on)
{
return TRUE;
}
PixmapPtr
winGetWindowPixmap (WindowPtr pwin)
{
ErrorF ("winGetWindowPixmap ()\n");
return NULL;
}
void
winSetWindowPixmap (WindowPtr pwin, PixmapPtr pPix)
{
ErrorF ("winSetWindowPixmap ()\n");
}