VBoxDispIf.cpp revision 92c6075e59a61be1eb07bf370501a93e6cd2d6ca
/** @file
* VBoxTray - Display Settings Interface abstraction for XPDM & WDDM
*/
/*
* Copyright (C) 2006-2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include "VBoxDispIf.h"
#include <malloc.h>
/* display driver interface abstraction for XPDM & WDDM
* with WDDM we can not use ExtEscape to communicate with our driver
* because we do not have XPDM display driver any more, i.e. escape requests are handled by cdd
* that knows nothing about us */
{
return NO_ERROR;
}
{
return NO_ERROR;
}
{
if (iRet > 0)
return VINF_SUCCESS;
else if (iRet == 0)
return ERROR_NOT_SUPPORTED;
/* else */
return ERROR_GEN_FAILURE;
}
#ifdef VBOX_WITH_WDDM
{
GetVersionEx (&OSinfo);
bool bSupported = true;
{
if (hUser)
{
*(uintptr_t *)&pIf->modeData.wddm.pfnChangeDisplaySettingsEx = (uintptr_t)GetProcAddress(hUser, "ChangeDisplaySettingsExA");
Log((__FUNCTION__": VBoxDisplayInit: pfnChangeDisplaySettingsEx = %p\n", pIf->modeData.wddm.pfnChangeDisplaySettingsEx));
*(uintptr_t *)&pIf->modeData.wddm.pfnEnumDisplayDevices = (uintptr_t)GetProcAddress(hUser, "EnumDisplayDevicesA");
Log((__FUNCTION__": VBoxDisplayInit: pfnEnumDisplayDevices = %p\n", pIf->modeData.wddm.pfnEnumDisplayDevices));
/* this is vista and up */
{
pIf->modeData.wddm.pfnD3DKMTOpenAdapterFromHdc = (PFND3DKMT_OPENADAPTERFROMHDC)GetProcAddress(hGdi32, "D3DKMTOpenAdapterFromHdc");
Log((__FUNCTION__"pfnD3DKMTOpenAdapterFromHdc = %p\n", pIf->modeData.wddm.pfnD3DKMTOpenAdapterFromHdc));
pIf->modeData.wddm.pfnD3DKMTOpenAdapterFromGdiDisplayName = (PFND3DKMT_OPENADAPTERFROMGDIDISPLAYNAME)GetProcAddress(hGdi32, "D3DKMTOpenAdapterFromGdiDisplayName");
Log((__FUNCTION__": pfnD3DKMTOpenAdapterFromGdiDisplayName = %p\n", pIf->modeData.wddm.pfnD3DKMTOpenAdapterFromGdiDisplayName));
pIf->modeData.wddm.pfnD3DKMTCloseAdapter = (PFND3DKMT_CLOSEADAPTER)GetProcAddress(hGdi32, "D3DKMTCloseAdapter");
pIf->modeData.wddm.pfnD3DKMTInvalidateActiveVidPn = (PFND3DKMT_INVALIDATEACTIVEVIDPN)GetProcAddress(hGdi32, "D3DKMTInvalidateActiveVidPn");
Log((__FUNCTION__": pfnD3DKMTInvalidateActiveVidPn = %p\n", pIf->modeData.wddm.pfnD3DKMTInvalidateActiveVidPn));
if (!bSupported)
{
}
}
else
{
}
}
else
{
}
}
else
{
}
return err;
}
{
for (int i = 0; ; ++i)
{
pDev, 0 /* DWORD dwFlags*/))
{
{
if (hDc)
{
return NO_ERROR;
}
else
{
winEr = GetLastError();
Assert(0);
break;
}
}
}
else
{
winEr = GetLastError();
Assert(0);
break;
}
}
return winEr;
}
typedef DECLCALLBACK(BOOLEAN) FNVBOXDISPIFWDDM_ADAPTEROP(PCVBOXDISPIF pIf, D3DKMT_HANDLE hAdapter, DISPLAY_DEVICE *pDev, PVOID pContext);
static DWORD vboxDispIfWDDMAdapterOp(PCVBOXDISPIF pIf, int iDisplay, PFNVBOXDISPIFWDDM_ADAPTEROP pfnOp, PVOID pContext)
{
{
if (!Status)
{
if (bCloseAdapter)
{
if (Status)
{
}
}
}
else
{
}
}
return err;
}
typedef struct
{
int cbData;
DECLCALLBACK(BOOLEAN) vboxDispIfEscapeWDDMOp(PCVBOXDISPIF pIf, D3DKMT_HANDLE hAdapter, DISPLAY_DEVICE *pDev, PVOID pContext)
{
D3DKMT_ESCAPE EscapeData = {0};
//EscapeData.hDevice = NULL;
//EscapeData.hContext = NULL;
return TRUE;
}
{
DWORD err = vboxDispIfWDDMAdapterOp(pIf, -1 /* iDisplay, -1 means primary */, vboxDispIfEscapeWDDMOp, &Ctx);
{
else
{
else
}
}
else
return err;
}
typedef struct
{
DECLCALLBACK(BOOLEAN) vboxDispIfResizeWDDMOp(PCVBOXDISPIF pIf, D3DKMT_HANDLE hAdapter, DISPLAY_DEVICE *pDev, PVOID pContext)
{
if (pData)
{
}
else
{
}
return TRUE;
}
static DWORD vboxDispIfResizeWDDM(PCVBOXDISPIF const pIf, ULONG Id, DWORD Width, DWORD Height, DWORD BitsPerPixel)
{
DWORD err = vboxDispIfWDDMAdapterOp(pIf, -1, /* (int)Id - always say -1 to use primary display since the display does not really matter here */
{
else
{
else
}
}
else
return err;
}
#endif
{
{
case VBOXDISPIF_MODE_XPDM_NT4:
case VBOXDISPIF_MODE_XPDM:
#ifdef VBOX_WITH_WDDM
case VBOXDISPIF_MODE_WDDM:
#endif
default:
return ERROR_INVALID_PARAMETER;
}
}
static DWORD vboxDispIfResizeXPDM(PCVBOXDISPIF const pIf, ULONG Id, DWORD Width, DWORD Height, DWORD BitsPerPixel)
{
return ERROR_NOT_SUPPORTED;
}
DWORD VBoxDispIfResize(PCVBOXDISPIF const pIf, ULONG Id, DWORD Width, DWORD Height, DWORD BitsPerPixel)
{
{
case VBOXDISPIF_MODE_XPDM_NT4:
return ERROR_NOT_SUPPORTED;
case VBOXDISPIF_MODE_XPDM:
#ifdef VBOX_WITH_WDDM
case VBOXDISPIF_MODE_WDDM:
#endif
default:
return ERROR_INVALID_PARAMETER;
}
}
static BOOL vboxDispIfValidateResize(DISPLAY_DEVICE *paDisplayDevices, DEVMODE *paDeviceModes, UINT cDevModes)
{
int i = 0;
for (int i = 0; ; ++i)
{
break;
{
bFetchDevice = TRUE;
}
{
bFetchDevice = TRUE;
}
if (bFetchDevice)
{
{
return FALSE;
}
/* First try to get the video mode stored in registry (ENUM_REGISTRY_SETTINGS).
* A secondary display could be not active at the moment and would not have
* a current video mode (ENUM_CURRENT_SETTINGS).
*/
{
return FALSE;
}
if ( DeviceMode.dmPelsWidth == 0
|| DeviceMode.dmPelsHeight == 0)
{
/* No ENUM_REGISTRY_SETTINGS yet. Seen on Vista after installation.
* Get the current video mode then.
*/
{
/* ENUM_CURRENT_SETTINGS returns FALSE when the display is not active:
* for example a disabled secondary display */
Log(("VBoxTray: vboxDispIfValidateResize: EnumDisplaySettings(ENUM_CURRENT_SETTINGS) error %d\n", GetLastError ()));
return FALSE;
}
}
UINT j = 0;
for (; j < cDevModes; ++j)
{
if (!strncmp(DisplayDevice.DeviceName, paDisplayDevices[j].DeviceName, RT_ELEMENTS(DeviceMode.dmDeviceName)))
{
|| (paDisplayDevices[j].StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) == (DisplayDevice.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP))
{
return FALSE;
}
break;
}
}
if (j == cDevModes)
return FALSE;
++cMatched;
}
}
}
DWORD vboxDispIfResizeModesWDDM(PCVBOXDISPIF const pIf, DISPLAY_DEVICE *paDisplayDevices, DEVMODE *paDeviceModes, UINT cDevModes)
{
UINT i = 0;
for (; i < cDevModes; i++)
{
if (!OpenAdapterData.hDc)
{
winEr = GetLastError();
Assert(0);
break;
}
if (Status)
{
Assert(0);
break;
}
if (!hAdapter)
{
}
else
{
}
}
{
if (Status)
{
}
}
if (hAdapter)
{
}
/* ignore any prev errors and just check if resize is OK */
{
/* now try to resize in a "regular" way */
/* Assign the new rectangles to displays. */
for (i = 0; i < cDevModes; i++)
{
/* On Vista one must specify DM_BITSPERPEL.
* Note that the current mode dmBitsPerPel is already in the DEVMODE structure.
*/
Log(("VBoxTray: ResizeDisplayDevice: pfnChangeDisplaySettingsEx %x: %dx%dx%d at %d,%d\n",
paDeviceModes[i].dmPosition.x,
paDeviceModes[i].dmPosition.y));
Log(("VBoxTray: ResizeDisplayDevice: ChangeDisplaySettingsEx position status %d, err %d\n", status, GetLastError ()));
}
/* A second call to ChangeDisplaySettings updates the monitor. */
if (status == DISP_CHANGE_SUCCESSFUL)
{
}
else if (status == DISP_CHANGE_BADMODE)
{
/* Successfully set new video mode or our driver can not set the requested mode. Stop trying. */
winEr = ERROR_RETRY;
}
else
{
}
}
else
{
}
return winEr;
}
DWORD VBoxDispIfResizeModes(PCVBOXDISPIF const pIf, DISPLAY_DEVICE *paDisplayDevices, DEVMODE *paDeviceModes, UINT cDevModes)
{
{
case VBOXDISPIF_MODE_XPDM_NT4:
return ERROR_NOT_SUPPORTED;
case VBOXDISPIF_MODE_XPDM:
return ERROR_NOT_SUPPORTED;
#ifdef VBOX_WITH_WDDM
case VBOXDISPIF_MODE_WDDM:
#endif
default:
return ERROR_INVALID_PARAMETER;
}
}
{
return NO_ERROR;
}
{
GetVersionEx (&OSinfo);
{
{
bool bSupported = true;
*(uintptr_t *)&pIf->modeData.xpdm.pfnChangeDisplaySettingsEx = (uintptr_t)GetProcAddress(hUser, "ChangeDisplaySettingsExA");
Log((__FUNCTION__": pfnChangeDisplaySettingsEx = %p\n", pIf->modeData.xpdm.pfnChangeDisplaySettingsEx));
if (!bSupported)
{
}
}
else
{
}
}
else
{
}
return err;
}
{
/* @todo: may need to addd synchronization in case we want to change modes dynamically
* i.e. currently the mode is supposed to be initialized once on service initialization */
if (penmOldMode)
return VINF_ALREADY_INITIALIZED;
switch (enmMode)
{
case VBOXDISPIF_MODE_XPDM_NT4:
{
}
else
break;
case VBOXDISPIF_MODE_XPDM:
{
}
else
break;
#ifdef VBOX_WITH_WDDM
case VBOXDISPIF_MODE_WDDM:
{
{
}
else
break;
}
#endif
default:
break;
}
return err;
}