#ifdef HAVE_XWIN_CONFIG_H
#include <xwin-config.h>
#endif
#include "win.h"
#include "winmsg.h"
#include "safeAlpha.h"
#ifdef XWIN_MULTIWINDOWEXTWM
static RootlessFrameProcsRec
winMWExtWMProcs = {
winMWExtWMCreateFrame,
winMWExtWMDestroyFrame,
winMWExtWMMoveFrame,
winMWExtWMResizeFrame,
winMWExtWMRestackFrame,
winMWExtWMReshapeFrame,
winMWExtWMUnmapFrame,
winMWExtWMStartDrawing,
winMWExtWMStopDrawing,
winMWExtWMUpdateRegion,
#ifndef ROOTLESS_TRACK_DAMAGE
winMWExtWMDamageRects,
#endif
winMWExtWMRootlessSwitchWindow,
NULL,
NULL, NULL, NULL, winMWExtWMCopyWindow
};
#endif
extern winScreenInfo g_ScreenInfo[];
extern miPointerScreenFuncRec g_winPointerCursorFuncs;
extern int g_iScreenPrivateIndex;
extern Bool g_fSoftwareCursor;
Bool
winRandRInit (ScreenPtr pScreen);
static Bool
winSaveScreen (ScreenPtr pScreen, int on);
Bool
winScreenInit (int index,
ScreenPtr pScreen,
int argc, char **argv)
{
winScreenInfoPtr pScreenInfo = &g_ScreenInfo[index];
winPrivScreenPtr pScreenPriv;
HDC hdc;
#if CYGDEBUG || YES
winDebug ("winScreenInit - dwWidth: %ld dwHeight: %ld\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",
(int) 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 (!g_fSoftwareCursor)
winInitCursor(pScreen);
else
winErrorFVerb(2, "winScreenInit - Using software cursor\n");
#if CYGDEBUG || YES
winDebug ("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;
#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)
int iReturn;
#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);
winErrorFVerb (2, "winFinishScreenInitFB - Masks: %08x %08x %08x\n",
(unsigned int) pScreenPriv->dwRedMask,
(unsigned int) pScreenPriv->dwGreenMask,
(unsigned int) 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)))
{
winSetColormapFunctions (pScreen);
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 XWIN_MULTIWINDOWEXTWM
if (pScreenInfo->fMWExtWM)
{
if (!RootlessAccelInit (pScreen))
{
ErrorF ("winFinishScreenInitFB - RootlessAccelInit () failed\n");
return FALSE;
}
}
#endif
#ifdef RENDER
if (!fbPictureInit (pScreen, NULL, 0))
{
ErrorF ("winFinishScreenInitFB - fbPictureInit () failed\n");
return FALSE;
}
#endif
#ifdef RANDR
if (!winRandRInit (pScreen))
{
ErrorF ("winFinishScreenInitFB - winRandRInit () failed\n");
return FALSE;
}
#endif
miInitializeBackingStore (pScreen);
#if CYGDEBUG
winDebug ("winFinishScreenInitFB - Calling miDCInitialize ()\n");
#endif
miDCInitialize (pScreen, &g_winPointerCursorFuncs);
#if CYGDEBUG
winDebug ("winFinishScreenInitFB - Calling winCreateDefColormap ()\n");
#endif
if (!winCreateDefColormap (pScreen))
{
ErrorF ("winFinishScreenInitFB - Could not create colormap\n");
return FALSE;
}
if ((pScreenInfo->dwEngine == WIN_SERVER_SHADOW_GDI
|| pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD
|| pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL)
#ifdef XWIN_MULTIWINDOWEXTWM
&& !pScreenInfo->fMWExtWM
#endif
)
{
#if CYGDEBUG
winDebug ("winFinishScreenInitFB - Calling shadowInit ()\n");
#endif
if (!shadowInit (pScreen,
pScreenPriv->pwinShadowUpdate,
NULL))
{
ErrorF ("winFinishScreenInitFB - shadowInit () failed\n");
return FALSE;
}
}
#ifdef XWIN_MULTIWINDOWEXTWM
if (pScreenInfo->fMWExtWM)
{
winDebug ("winScreenInit - MultiWindowExtWM - Calling RootlessInit\n");
RootlessInit(pScreen, &winMWExtWMProcs);
winDebug ("winScreenInit - MultiWindowExtWM - RootlessInit returned\n");
rootless_CopyBytes_threshold = 0;
rootless_FillBytes_threshold = 0;
rootless_CompositePixels_threshold = 0;
rootless_CopyWindow_threshold = 1;
winWindowsWMExtensionInit ();
}
#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 = winCreateWindowRootless;
pScreen->DestroyWindow = winDestroyWindowRootless;
pScreen->PositionWindow = winPositionWindowRootless;
pScreen->RealizeWindow = winMapWindowRootless;
pScreen->UnrealizeWindow = winUnmapWindowRootless;
#ifdef SHAPE
pScreen->SetShape = winSetShapeRootless;
#endif
#undef WRAP
}
#ifdef XWIN_MULTIWINDOW
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);
WRAP(ResizeWindow);
WRAP(MoveWindow);
WRAP(CopyWindow);
#ifdef SHAPE
WRAP(SetShape);
#endif
pScreen->CreateWindow = winCreateWindowMultiWindow;
pScreen->DestroyWindow = winDestroyWindowMultiWindow;
pScreen->PositionWindow = winPositionWindowMultiWindow;
pScreen->RealizeWindow = winMapWindowMultiWindow;
pScreen->UnrealizeWindow = winUnmapWindowMultiWindow;
pScreen->ReparentWindow = winReparentWindowMultiWindow;
pScreen->RestackWindow = winRestackWindowMultiWindow;
pScreen->ResizeWindow = winResizeWindowMultiWindow;
pScreen->MoveWindow = winMoveWindowMultiWindow;
pScreen->CopyWindow = winCopyWindowMultiWindow;
#ifdef SHAPE
pScreen->SetShape = winSetShapeMultiWindow;
#endif
#undef WRAP
}
#endif
pScreenPriv->CloseScreen = pScreen->CloseScreen;
pScreen->CloseScreen = pScreenPriv->pwinCloseScreen;
#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)
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;
#endif
#ifdef XWIN_MULTIWINDOWEXTWM
pScreenPriv->fRestacking = FALSE;
#endif
#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
if (FALSE
#ifdef XWIN_MULTIWINDOW
|| pScreenInfo->fMultiWindow
#endif
#ifdef XWIN_MULTIWINDOWEXTWM
|| pScreenInfo->fInternalWM
#endif
)
{
#if CYGDEBUG || YES
winDebug ("winFinishScreenInitFB - Calling winInitWM.\n");
#endif
if (!winInitWM (&pScreenPriv->pWMInfo,
&pScreenPriv->ptWMProc,
&pScreenPriv->ptXMsgProc,
&pScreenPriv->pmServerStarted,
pScreenInfo->dwScreen,
(HWND)&pScreenPriv->hwndScreen,
#ifdef XWIN_MULTIWINDOWEXTWM
pScreenInfo->fInternalWM ||
#endif
FALSE))
{
ErrorF ("winFinishScreenInitFB - winInitWM () failed.\n");
return FALSE;
}
}
#endif
pScreenPriv->fEnabled = TRUE;
pScreenPriv->fBadDepth = FALSE;
#if CYGDEBUG || YES
winDebug ("winFinishScreenInitFB - returning\n");
#endif
return TRUE;
}
#ifdef XWIN_NATIVEGDI
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->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 (*)(void)) NoopDDA;
pScreen->InstallColormap = miInstallColormap;
pScreen->UninstallColormap = miUninstallColormap;
pScreen->ListInstalledColormaps = miListInstalledColormaps;
pScreen->StoreColors = (StoreColorsProcPtr) (void (*)(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",
(unsigned int) pScreen);
return TRUE;
}
#endif
static Bool
winSaveScreen (ScreenPtr pScreen, int on)
{
return TRUE;
}