VBoxDispIf.cpp revision 51df2768ddb5c4dd975267b4ba82ba02da82d20a
/** @file
* VBoxTray - Display Settings Interface abstraction for XPDM & WDDM
*/
/*
* Copyright (C) 2006-2012 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 "VBoxTray.h"
#define _WIN32_WINNT 0x0601
#include <malloc.h>
#ifdef VBOX_WITH_WDDM
#endif
/* APIs specific to win7 and above WDDM architecture. Not available for Vista WDDM.
* This is the reason they have not been put in the VBOXDISPIF struct in VBoxDispIf.h
*/
typedef struct _VBOXDISPLAYWDDMAPICONTEXT
{
LONG (WINAPI * pfnSetDisplayConfig)(UINT numPathArrayElements,DISPLAYCONFIG_PATH_INFO *pathArray,UINT numModeInfoArrayElements,
LONG (WINAPI * pfnQueryDisplayConfig)(UINT Flags,UINT *pNumPathArrayElements, DISPLAYCONFIG_PATH_INFO *pPathInfoArray,
LONG (WINAPI * pfnGetDisplayConfigBufferSizes)(UINT Flags, UINT *pNumPathArrayElements, UINT *pNumModeInfoArrayElements);
static _VBOXDISPLAYWDDMAPICONTEXT gCtx = {0};
/* 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;
}
#ifdef VBOX_WITH_WDDM
#endif
{
#ifdef VBOX_WITH_WDDM
{
}
#endif
return NO_ERROR;
}
static DWORD vboxDispIfEscapeXPDM(PCVBOXDISPIF pIf, PVBOXDISPIFESCAPE pEscape, int cbData, int iDirection)
{
iDirection >= 0 ? cbData : 0,
iDirection <= 0 ? cbData : 0,
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));
/* for win 7 and above */
{
*(uintptr_t *)&gCtx.pfnGetDisplayConfigBufferSizes = (uintptr_t)GetProcAddress(hUser, "GetDisplayConfigBufferSizes");
Log((__FUNCTION__": VBoxDisplayInit: pfnGetDisplayConfigBufferSizes = %p\n", gCtx.pfnGetDisplayConfigBufferSizes));
}
/* 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));
pIf->modeData.wddm.pfnD3DKMTPollDisplayChildren = (PFND3DKMT_POLLDISPLAYCHILDREN)GetProcAddress(hGdi32, "D3DKMTPollDisplayChildren");
Log((__FUNCTION__": pfnD3DKMTPollDisplayChildren = %p\n", pIf->modeData.wddm.pfnD3DKMTPollDisplayChildren));
if (!bSupported)
{
}
}
else
{
}
}
else
{
}
}
else
{
}
if (err == ERROR_SUCCESS)
{
}
return err;
}
{
for (int i = 0; ; ++i)
{
pDev, 0 /* DWORD dwFlags*/))
{
{
if (hDc)
{
return NO_ERROR;
}
else
{
winEr = GetLastError();
break;
}
}
}
else
{
winEr = GetLastError();
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
{
}
}
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;
}
static DWORD vboxDispIfEscapeWDDM(PCVBOXDISPIF pIf, PVBOXDISPIFESCAPE pEscape, int cbData, BOOL fHwAccess)
{
if (fHwAccess)
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;
}
}
{
{
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;
}
}
#ifdef VBOX_WITH_WDDM
#define VBOXRR_TIMER_ID 1234
typedef struct VBOXRR
{
static void vboxRrRetryStopLocked()
{
{
if (pMon->paDisplayDevices)
{
}
if (pMon->paDeviceModes)
{
}
{
}
}
}
static void VBoxRrRetryStop()
{
}
static DWORD vboxDispIfWddmValidateFixResize(PCVBOXDISPIF const pIf, DISPLAY_DEVICE *paDisplayDevices, DEVMODE *paDeviceModes, UINT cDevModes);
static void vboxRrRetryReschedule()
{
}
static void VBoxRrRetrySchedule(PCVBOXDISPIF const pIf, DISPLAY_DEVICE *paDisplayDevices, DEVMODE *paDeviceModes, UINT cDevModes)
{
if (cDevModes)
{
if (!pMon->paDisplayDevices)
{
Log(("malloc failed!"));
return;
}
if (!pMon->paDeviceModes)
{
Log(("malloc failed!"));
return;
}
}
{
}
}
static void vboxRrRetryPerform()
{
{
DWORD dwErr = vboxDispIfWddmValidateFixResize(pMon->pIf, pMon->paDisplayDevices, pMon->paDeviceModes, pMon->cDevModes);
if (ERROR_RETRY != dwErr)
else
}
}
)
{
switch(uMsg)
{
case WM_DISPLAYCHANGE:
{
Log(("VBoxTray: WM_DISPLAYCHANGE\n"));
return 0;
}
case WM_TIMER:
{
if (wParam == VBOXRR_TIMER_ID)
{
Log(("VBoxTray: VBOXRR_TIMER_ID\n"));
return 0;
}
break;
}
case WM_CLOSE:
return 0;
case WM_DESTROY:
return 0;
case WM_NCHITTEST:
return HTNOWHERE;
default:
break;
}
}
#define VBOXRRWND_NAME "VBoxRrWnd"
{
/* Register the Window Class. */
{
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
if (!RegisterClass(&wc))
{
}
}
{
-100, -100,
10, 10,
NULL, //GetDesktopWindow() /* hWndParent */,
NULL /* hMenu */,
NULL /* lpParam */);
if (hWnd)
{
}
else
{
}
}
return hr;
}
{
if (bResult)
return S_OK;
return HRESULT_FROM_WIN32(winErr);
}
static HRESULT vboxRrWndInit()
{
}
{
return S_OK;
}
{
NULL /* HWND hWnd */,
WM_USER /* UINT wMsgFilterMin */,
WM_USER /* UINT wMsgFilterMax */,
do
{
0 /*HWND hWnd*/,
0 /*UINT wMsgFilterMin*/,
0 /*UINT wMsgFilterMax*/
);
if(!bResult) /* WM_QUIT was posted */
{
Log(("VBoxTray: GetMessage returned FALSE\n"));
break;
}
{
Assert(0);
/* just ensure we never return success in this case */
break;
}
{
case WM_VBOXRR_INIT_QUIT:
case WM_CLOSE:
{
PostQuitMessage(0);
break;
}
default:
break;
}
} while (1);
return 0;
}
{
if (!bRc)
{
}
{
}
return 0;
}
{
TRUE, /* BOOL bManualReset*/
FALSE, /* BOOL bInitialState */
NULL /* LPCTSTR lpName */
);
{
0 /* SIZE_T dwStackSize */,
pMon,
0 /* DWORD dwCreationFlags */,
{
if (dwResult == WAIT_OBJECT_0)
return S_OK;
else
{
Log(("WaitForSingleObject failed!"));
}
}
else
{
}
}
else
{
}
return hr;
}
{
return;
if (bResult
|| (winErr = GetLastError()) == ERROR_INVALID_THREAD_ID) /* <- could be that the thread is terminated */
{
if (dwErr == WAIT_OBJECT_0)
{
}
else
{
winErr = GetLastError();
}
}
else
{
}
}
typedef struct VBOXDISPIF_WDDM_INTERNAL
{
static BOOL vboxDispIfWddmValidateResize(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;
}
/* with Win8 WDDM Display-only driver, it seems like sometimes we get an auto-resize setting being stored in registry, although current settings do not match */
{
/* 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;
}
/* No ENUM_REGISTRY_SETTINGS yet. Seen on Vista after installation.
* Get the current video mode then.
*/
if ( RegDevMode.dmPelsWidth != 0
&& RegDevMode.dmPelsHeight == 0)
{
{
Log(("VBoxTray: vboxDispIfValidateResize: current settings do not match registry settings, trating as no-match"));
return FALSE;
}
}
UINT j = 0;
for (; j < cDevModes; ++j)
{
if (!strncmp(DisplayDevice.DeviceName, paDisplayDevices[j].DeviceName, RT_ELEMENTS(CurDevMode.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;
}
}
}
static DWORD vboxDispIfWddmValidateFixResize(PCVBOXDISPIF const pIf, DISPLAY_DEVICE *paDisplayDevices, DEVMODE *paDeviceModes, UINT cDevModes)
{
return NO_ERROR;
/* now try to resize in a "regular" way */
/* Assign the new rectangles to displays. */
{
/* 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));
/* the miniport might have been adjusted the display mode stuff,
* adjust the paDeviceModes[i] by picking the closest available one */
// DEVMODE AdjustedMode = paDeviceModes[i];
// vboxDispIfAdjustMode(&paDisplayDevices[i], &AdjustedMode);
LONG tmpStatus = pIf->modeData.wddm.pfnChangeDisplaySettingsEx((LPSTR)paDisplayDevices[i].DeviceName,
Log(("VBoxTray: ResizeDisplayDevice: ChangeDisplaySettingsEx position status %d, err %d\n", tmpStatus, GetLastError ()));
if (tmpStatus != DISP_CHANGE_SUCCESSFUL)
{
}
}
/* A second call to ChangeDisplaySettings updates the monitor. */
if (tmpStatus == DISP_CHANGE_SUCCESSFUL)
{
if (status == DISP_CHANGE_SUCCESSFUL)
{
Log(("VBoxTray: resize succeeded\n"));
return NO_ERROR;
}
}
else
{
if (status == DISP_CHANGE_SUCCESSFUL)
}
if (status == DISP_CHANGE_FAILED)
{
Log(("VBoxTray: DISP_CHANGE_FAILED, retrying..\n"));
return ERROR_RETRY;
}
return ERROR_GEN_FAILURE;
}
{
{
return ERROR_SUCCESS;
}
return ERROR_GEN_FAILURE;
}
{
VBoxRrTerm();
}
typedef struct VBOXDISPIF_REINITMODES_OP
{
static DECLCALLBACK(BOOLEAN) vboxDispIfReninitModesWDDMOp(PCVBOXDISPIF pIf, D3DKMT_HANDLE hAdapter, DISPLAY_DEVICE *pDev, PVOID pContext)
{
// Ctx.EscapeFlags.HardwareAccess = 0;
DWORD err = vboxDispIfWDDMAdapterOp(pIf, -1 /* iDisplay, -1 means primary */, vboxDispIfEscapeWDDMOp, &Ctx);
{
else
{
else
}
}
else
if (Status != 0)
{
}
return TRUE;
}
static DWORD vboxDispIfReninitModesWDDM(PCVBOXDISPIF const pIf, uint8_t *pScreenIdMask, BOOL fReconnectDisplaysOnChange)
{
VBOXDISPIF_REINITMODES_OP OpData = {0};
OpData.EscData.EscapeHdr.u32CmdSpecific = VBOXWDDM_REINITVIDEOMODESBYMASK_F_RECONNECT_DISPLAYS_ON_CHANGE;
DWORD err = vboxDispIfWDDMAdapterOp(pIf, -1 /* iDisplay, -1 means primary */, vboxDispIfReninitModesWDDMOp, &OpData);
return err;
}
{
Log(("VBoxTray: cancelling pending resize\n"));
return NO_ERROR;
}
{
DWORD i = 0;
for (; ; ++i)
{
CurMode.dmDriverExtra = 0;
break;
{
Log(("Exact match found"));
*pDeviceMode = CurMode;
return NO_ERROR;
}
- 1 /* <- to make higher bpp take precedence over lower ones */
);
if (i == 0
|| diffCurrHW < diffWH
{
/* first run */
diffWH = diffCurrHW;
continue;
}
}
if (i == 0)
{
Log(("No modes found!"));
return NO_ERROR;
}
return NO_ERROR;
}
static DWORD vboxDispIfAdjustModeValues(PCVBOXDISPIF const pIf, DISPLAY_DEVICE *pDisplayDevice, DEVMODE *pDeviceMode)
{
}
DWORD err = vboxDispIfEscapeWDDM(pIf, &Data.EscapeHdr, sizeof (Data) - sizeof (Data.EscapeHdr), TRUE);
{
}
return err;
}
DWORD vboxDispIfResizeModesWDDM(PCVBOXDISPIF const pIf, UINT iChangedMode, DISPLAY_DEVICE *paDisplayDevices, DEVMODE *paDeviceModes, UINT cDevModes)
{
UINT i = 0;
Log(("VBoxTray: vboxDispIfResizeModesWDDM\n"));
for (; i < cDevModes; i++)
{
if (!OpenAdapterData.hDc)
{
winEr = GetLastError();
Log(("VBoxTray: WARNING: Failed to get dc for display device %s, winEr %d\n", paDisplayDevices[i].DeviceName, winEr));
break;
}
if (Status)
{
break;
}
if (i == iChangedMode && (paDeviceModes[i].dmPosition.x != 0 || paDeviceModes[i].dmPosition.y != 0) )
{
/* change position values only if not equal to 0*/
LogRel(("VBoxTray: (WDDM) Change Position x=%d*y=%d Display Device ID=%d\n", paDeviceModes[i].dmPosition.x, paDeviceModes[i].dmPosition.y, i));
}
if (!hAdapter)
{
}
else
{
if (Status)
}
}
{
if (Status)
{
}
else
{
}
}
if (hAdapter)
{
if (Status)
}
// for (i = 0; i < cDevModes; i++)
// {
// vboxDispIfAdjustMode(&paDisplayDevices[i], &paDeviceModes[i]);
// }
{
Log(("VBoxTray: Invalidating VidPn Worked!\n"));
GetVersionEx (&OSinfo);
/* for win 7 and above calling ChangeDisplaySettingsEx to resize a specific display, is having
* a side affect for enabling all the monitors including the disabled ones. So using
* WDDM win 7 APIs to resize the display for OSes Win7 and above.
*/
else
}
else
{
Log(("VBoxTray: Falling back to monitor mode reinit\n"));
/* fallback impl needed for display-only driver
* since D3DKMTInvalidateActiveVidPn is not available for WDDM > 1.0:
* make the driver invalidate VidPn,
* which is done by emulating a monitor re-plug currently */
GetVersionEx (&OSinfo);
else
}
if (winEr == ERROR_RETRY)
{
/* just pretend everything is fine so far */
}
return winEr;
}
{
UINT numPathArrayElements = 0;
dwStatus = gCtx.pfnGetDisplayConfigBufferSizes(fEnabled ? QDC_ALL_PATHS : QDC_ONLY_ACTIVE_PATHS, &numPathArrayElements, &numModeInfoArrayElements);
if (dwStatus != ERROR_SUCCESS)
{
LogFlow(("VBoxTray: (WDDM) Failed GetDisplayConfigBufferSizes \n"));
return dwStatus;
}
pPathInfoArray = (DISPLAYCONFIG_PATH_INFO *)malloc(numPathArrayElements * sizeof(DISPLAYCONFIG_PATH_INFO));
if (!pPathInfoArray)
return ERROR_OUTOFMEMORY;
pModeInfoArray = (DISPLAYCONFIG_MODE_INFO *)malloc(numModeInfoArrayElements * sizeof(DISPLAYCONFIG_MODE_INFO));
if (!pModeInfoArray )
{
if (pPathInfoArray)
{
}
return ERROR_OUTOFMEMORY;
}
dwStatus = gCtx.pfnQueryDisplayConfig(fEnabled ? QDC_ALL_PATHS : QDC_ONLY_ACTIVE_PATHS, &numPathArrayElements, pPathInfoArray,&numModeInfoArrayElements, pModeInfoArray, NULL);
if (dwStatus != ERROR_SUCCESS)
{
LogFlow(("VBoxTray: (WDDM) Failed QueryDisplayConfig \n"));
return dwStatus;
}
for (unsigned int i=0; i < numPathArrayElements; ++i)
{
LogRel(("Sourceid= %d and targetid = %d\n", pPathInfoArray[i].sourceInfo.id, pPathInfoArray[i].targetInfo.id));
{
if (fEnabled)
{
LogRel(("VBoxTray: (WDDM) Enable the Display Device i =%d \n", i));
break;
}
else
{
LogRel(("VBoxTray: (WDDM) Disable the Display Device Path ID=%d and Sourceid=%d\n", i, pPathInfoArray[i].sourceInfo.id));
pPathInfoArray[i].flags=0;
break;
}
}
}
dwStatus = gCtx.pfnSetDisplayConfig(numPathArrayElements, pPathInfoArray, numModeInfoArrayElements, pModeInfoArray, (SDC_APPLY | SDC_SAVE_TO_DATABASE| SDC_ALLOW_CHANGES | SDC_USE_SUPPLIED_DISPLAY_CONFIG));
if (dwStatus != ERROR_SUCCESS)
{
LogRel(("VBoxTray:(WDDM) Failed to Enable/ disable the monitor."));
return dwStatus;
}
return ERROR_SUCCESS;
}
DWORD vboxDispIfWddmResizeDisplay(PCVBOXDISPIF const pIf, UINT Id, DISPLAY_DEVICE * paDisplayDevices, DEVMODE *paDeviceMode, UINT devModes)
{
UINT numPathArrayElements = 0;
bool fFoundDisplay = false;
dwStatus = gCtx.pfnGetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &numPathArrayElements, &numModeInfoArrayElements);
if (dwStatus != ERROR_SUCCESS)
{
LogFlow(("VBoxTray: (WDDM) Failed GetDisplayConfigBufferSizes \n"));
return dwStatus;
}
pPathInfoArray = (DISPLAYCONFIG_PATH_INFO *)malloc(numPathArrayElements * sizeof(DISPLAYCONFIG_PATH_INFO));
if (!pPathInfoArray)
return ERROR_OUTOFMEMORY;
pModeInfoArray = (DISPLAYCONFIG_MODE_INFO *)malloc(numModeInfoArrayElements * sizeof(DISPLAYCONFIG_MODE_INFO));
if (!pModeInfoArray )
{
if (pPathInfoArray)
{
}
return ERROR_OUTOFMEMORY;
}
dwStatus = gCtx.pfnQueryDisplayConfig( QDC_ONLY_ACTIVE_PATHS, &numPathArrayElements, pPathInfoArray,&numModeInfoArrayElements, pModeInfoArray, NULL);
if (dwStatus != ERROR_SUCCESS)
{
LogFlow(("VBoxTray: (WDDM) Failed QueryDisplayConfig \n"));
return dwStatus;
}
{
LogFlow(("Sourceid= %d and targetid = %d iter =%d and id = %d\n", pPathInfoArray[iter].sourceInfo.id, pPathInfoArray[iter].targetInfo.id, iter, Id));
{
{
}
fFoundDisplay = true;
break;
}
}
if (fFoundDisplay)
{
/* Call SetDisplayConfig only if displaywith ID=Id has been found. */
dwStatus = gCtx.pfnSetDisplayConfig(numPathArrayElements, pPathInfoArray, numModeInfoArrayElements, pModeInfoArray,(SDC_APPLY | SDC_SAVE_TO_DATABASE| SDC_ALLOW_CHANGES | SDC_USE_SUPPLIED_DISPLAY_CONFIG));
if (dwStatus != ERROR_SUCCESS)
{
LogRel(("VBoxTray:(WDDM) Failed to resize the monitor.\n"));
if (dwStatus == ERROR_GEN_FAILURE)
{
LogRel(("VBoxTray:(WDDM) going to retry\n"));
return ERROR_RETRY; /* <- to make sure we retry */
}
return dwStatus;
}
}
return ERROR_SUCCESS;
}
#endif /* VBOX_WITH_WDDM */
DWORD VBoxDispIfResizeModes(PCVBOXDISPIF const pIf, UINT iChangedMode, 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;
}
}
{
{
case VBOXDISPIF_MODE_XPDM_NT4:
return NO_ERROR;
case VBOXDISPIF_MODE_XPDM:
return NO_ERROR;
#ifdef VBOX_WITH_WDDM
case VBOXDISPIF_MODE_WDDM:
return vboxDispIfCancelPendingResizeWDDM(pIf);
#endif
default:
return ERROR_INVALID_PARAMETER;
}
}
DWORD VBoxDispIfReninitModes(PCVBOXDISPIF const pIf, uint8_t *pScreenIdMask, BOOL fReconnectDisplaysOnChange)
{
{
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 NO_ERROR;
#ifdef VBOX_WITH_WDDM
{
}
#endif
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;
}