[26562] | 1 | /* $Id: VBoxDisplay.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
[8387] | 2 | /** @file
|
---|
[21219] | 3 | * VBoxSeamless - Display notifications.
|
---|
[8387] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[8155] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[8387] | 26 | */
|
---|
[68630] | 27 |
|
---|
| 28 |
|
---|
| 29 | /*********************************************************************************************************************************
|
---|
| 30 | * Header Files *
|
---|
| 31 | *********************************************************************************************************************************/
|
---|
[8850] | 32 | #include "VBoxTray.h"
|
---|
[33966] | 33 | #include "VBoxHelpers.h"
|
---|
[8387] | 34 | #include "VBoxSeamless.h"
|
---|
[51469] | 35 |
|
---|
[68630] | 36 | #include <iprt/alloca.h>
|
---|
[8387] | 37 | #include <iprt/assert.h>
|
---|
[42217] | 38 | #ifdef VBOX_WITH_WDDM
|
---|
[51469] | 39 | # include <iprt/asm.h>
|
---|
[42217] | 40 | #endif
|
---|
[95961] | 41 | #include <iprt/log.h>
|
---|
[78937] | 42 | #include <iprt/system.h>
|
---|
[8387] | 43 |
|
---|
[51469] | 44 | #include <VBoxDisplay.h>
|
---|
| 45 | #include <VBoxHook.h>
|
---|
| 46 |
|
---|
| 47 |
|
---|
[68630] | 48 | /*********************************************************************************************************************************
|
---|
| 49 | * Structures and Typedefs *
|
---|
| 50 | *********************************************************************************************************************************/
|
---|
[8387] | 51 | typedef struct _VBOXDISPLAYCONTEXT
|
---|
| 52 | {
|
---|
| 53 | const VBOXSERVICEENV *pEnv;
|
---|
[42232] | 54 | BOOL fAnyX;
|
---|
[57741] | 55 | /** ChangeDisplaySettingsEx does not exist in NT. ResizeDisplayDevice uses the function. */
|
---|
[85121] | 56 | DECLCALLBACKMEMBER_EX(LONG,WINAPI, pfnChangeDisplaySettingsEx,(LPCTSTR lpszDeviceName, LPDEVMODE lpDevMode, HWND hwnd,
|
---|
| 57 | DWORD dwflags, LPVOID lParam));
|
---|
[95962] | 58 | /** EnumDisplayDevices does not exist in NT. */
|
---|
[85121] | 59 | DECLCALLBACKMEMBER_EX(BOOL, WINAPI, pfnEnumDisplayDevices,(IN LPCSTR lpDevice, IN DWORD iDevNum,
|
---|
| 60 | OUT PDISPLAY_DEVICEA lpDisplayDevice, IN DWORD dwFlags));
|
---|
[57741] | 61 | /** Display driver interface, XPDM - WDDM abstraction see VBOXDISPIF** definitions above */
|
---|
| 62 | VBOXDISPIF dispIf;
|
---|
| 63 | } VBOXDISPLAYCONTEXT, *PVBOXDISPLAYCONTEXT;
|
---|
[8387] | 64 |
|
---|
[27955] | 65 | typedef enum
|
---|
| 66 | {
|
---|
| 67 | VBOXDISPLAY_DRIVER_TYPE_UNKNOWN = 0,
|
---|
| 68 | VBOXDISPLAY_DRIVER_TYPE_XPDM = 1,
|
---|
| 69 | VBOXDISPLAY_DRIVER_TYPE_WDDM = 2
|
---|
| 70 | } VBOXDISPLAY_DRIVER_TYPE;
|
---|
| 71 |
|
---|
| 72 |
|
---|
[68630] | 73 | /*********************************************************************************************************************************
|
---|
| 74 | * Global Variables *
|
---|
| 75 | *********************************************************************************************************************************/
|
---|
| 76 | static VBOXDISPLAYCONTEXT g_Ctx = { 0 };
|
---|
| 77 |
|
---|
| 78 |
|
---|
| 79 | /*********************************************************************************************************************************
|
---|
| 80 | * Internal Functions *
|
---|
| 81 | *********************************************************************************************************************************/
|
---|
| 82 | static VBOXDISPLAY_DRIVER_TYPE getVBoxDisplayDriverType(VBOXDISPLAYCONTEXT *pCtx);
|
---|
| 83 |
|
---|
| 84 |
|
---|
[57741] | 85 | static DECLCALLBACK(int) VBoxDisplayInit(const PVBOXSERVICEENV pEnv, void **ppInstance)
|
---|
[8387] | 86 | {
|
---|
[57741] | 87 | LogFlowFuncEnter();
|
---|
[32592] | 88 |
|
---|
[57741] | 89 | PVBOXDISPLAYCONTEXT pCtx = &g_Ctx; /** @todo r=andy Use instance data via service lookup (add void *pInstance). */
|
---|
| 90 | AssertPtr(pCtx);
|
---|
| 91 |
|
---|
| 92 | int rc;
|
---|
| 93 | HMODULE hUser = GetModuleHandle("user32.dll"); /** @todo r=andy Use RTLdrXXX and friends. */
|
---|
[8387] | 94 |
|
---|
[57741] | 95 | pCtx->pEnv = pEnv;
|
---|
[8387] | 96 |
|
---|
[78937] | 97 | uint64_t const uNtVersion = RTSystemGetNtVersion();
|
---|
| 98 |
|
---|
[8387] | 99 | if (NULL == hUser)
|
---|
| 100 | {
|
---|
[51469] | 101 | LogFlowFunc(("Could not get module handle of USER32.DLL!\n"));
|
---|
[57741] | 102 | rc = VERR_NOT_IMPLEMENTED;
|
---|
[8387] | 103 | }
|
---|
[78937] | 104 | else if (uNtVersion >= RTSYSTEM_MAKE_NT_VERSION(5, 0, 0)) /* APIs available only on W2K and up. */
|
---|
[8387] | 105 | {
|
---|
[57741] | 106 | /** @todo r=andy Use RTLdrXXX and friends. */
|
---|
| 107 | /** @todo r=andy No unicode version available? */
|
---|
| 108 | *(uintptr_t *)&pCtx->pfnChangeDisplaySettingsEx = (uintptr_t)GetProcAddress(hUser, "ChangeDisplaySettingsExA");
|
---|
| 109 | LogFlowFunc(("pfnChangeDisplaySettingsEx = %p\n", pCtx->pfnChangeDisplaySettingsEx));
|
---|
[8387] | 110 |
|
---|
[57741] | 111 | *(uintptr_t *)&pCtx->pfnEnumDisplayDevices = (uintptr_t)GetProcAddress(hUser, "EnumDisplayDevicesA");
|
---|
| 112 | LogFlowFunc(("pfnEnumDisplayDevices = %p\n", pCtx->pfnEnumDisplayDevices));
|
---|
[27955] | 113 |
|
---|
[32622] | 114 | #ifdef VBOX_WITH_WDDM
|
---|
[78937] | 115 | if (uNtVersion >= RTSYSTEM_MAKE_NT_VERSION(6, 0, 0))
|
---|
[27955] | 116 | {
|
---|
[57741] | 117 | /* This is Vista and up, check if we need to switch the display driver if to WDDM mode. */
|
---|
[51469] | 118 | LogFlowFunc(("this is Windows Vista and up\n"));
|
---|
[57741] | 119 | VBOXDISPLAY_DRIVER_TYPE enmType = getVBoxDisplayDriverType(pCtx);
|
---|
[27955] | 120 | if (enmType == VBOXDISPLAY_DRIVER_TYPE_WDDM)
|
---|
| 121 | {
|
---|
[51469] | 122 | LogFlowFunc(("WDDM driver is installed, switching display driver if to WDDM mode\n"));
|
---|
[57741] | 123 | /* This is hacky, but the most easiest way. */
|
---|
[78937] | 124 | VBOXDISPIF_MODE enmMode = uNtVersion < RTSYSTEM_MAKE_NT_VERSION(6, 1, 0)
|
---|
| 125 | ? VBOXDISPIF_MODE_WDDM : VBOXDISPIF_MODE_WDDM_W7;
|
---|
[57741] | 126 | DWORD dwErr = VBoxDispIfSwitchMode(const_cast<PVBOXDISPIF>(&pEnv->dispIf), enmMode, NULL /* old mode, we don't care about it */);
|
---|
| 127 | if (dwErr == NO_ERROR)
|
---|
| 128 | {
|
---|
| 129 | LogFlowFunc(("DispIf successfully switched to WDDM mode\n"));
|
---|
| 130 | rc = VINF_SUCCESS;
|
---|
| 131 | }
|
---|
[27955] | 132 | else
|
---|
[57741] | 133 | {
|
---|
| 134 | LogFlowFunc(("Failed to switch DispIf to WDDM mode, error (%d)\n", dwErr));
|
---|
| 135 | rc = RTErrConvertFromWin32(dwErr);
|
---|
| 136 | }
|
---|
[27955] | 137 | }
|
---|
[57741] | 138 | else
|
---|
| 139 | rc = VINF_SUCCESS;
|
---|
[27955] | 140 | }
|
---|
[57741] | 141 | else
|
---|
| 142 | rc = VINF_SUCCESS;
|
---|
[27955] | 143 | #endif
|
---|
[8387] | 144 | }
|
---|
[78937] | 145 | else if (uNtVersion < RTSYSTEM_MAKE_NT_VERSION(5, 0, 0)) /* Windows NT 4.0. */
|
---|
[8387] | 146 | {
|
---|
[57741] | 147 | /* Nothing to do here yet. */
|
---|
| 148 | /** @todo r=andy Has this been tested? */
|
---|
| 149 | rc = VINF_SUCCESS;
|
---|
[8387] | 150 | }
|
---|
[57741] | 151 | else /* Unsupported platform. */
|
---|
[8387] | 152 | {
|
---|
[57741] | 153 | LogFlowFunc(("Warning: Display for platform not handled yet!\n"));
|
---|
| 154 | rc = VERR_NOT_IMPLEMENTED;
|
---|
[8387] | 155 | }
|
---|
| 156 |
|
---|
[57741] | 157 | if (RT_SUCCESS(rc))
|
---|
| 158 | {
|
---|
[93299] | 159 | VBOXDISPIFESCAPE_ISANYX IsAnyX = { {0} };
|
---|
[57741] | 160 | IsAnyX.EscapeHdr.escapeCode = VBOXESC_ISANYX;
|
---|
| 161 | DWORD err = VBoxDispIfEscapeInOut(&pEnv->dispIf, &IsAnyX.EscapeHdr, sizeof(uint32_t));
|
---|
| 162 | if (err == NO_ERROR)
|
---|
| 163 | pCtx->fAnyX = !!IsAnyX.u32IsAnyX;
|
---|
| 164 | else
|
---|
| 165 | pCtx->fAnyX = TRUE;
|
---|
[42232] | 166 |
|
---|
[57741] | 167 | *ppInstance = pCtx;
|
---|
| 168 | }
|
---|
[8387] | 169 |
|
---|
[57741] | 170 | LogFlowFuncLeaveRC(rc);
|
---|
| 171 | return rc;
|
---|
[8387] | 172 | }
|
---|
| 173 |
|
---|
[57741] | 174 | static DECLCALLBACK(void) VBoxDisplayDestroy(void *pInstance)
|
---|
[8387] | 175 | {
|
---|
[63100] | 176 | RT_NOREF(pInstance);
|
---|
[8387] | 177 | return;
|
---|
| 178 | }
|
---|
| 179 |
|
---|
[57741] | 180 | static VBOXDISPLAY_DRIVER_TYPE getVBoxDisplayDriverType(PVBOXDISPLAYCONTEXT pCtx)
|
---|
[8387] | 181 | {
|
---|
[27955] | 182 | VBOXDISPLAY_DRIVER_TYPE enmType = VBOXDISPLAY_DRIVER_TYPE_UNKNOWN;
|
---|
[8387] | 183 |
|
---|
[68367] | 184 | if (pCtx->pfnEnumDisplayDevices)
|
---|
[8387] | 185 | {
|
---|
| 186 | INT devNum = 0;
|
---|
| 187 | DISPLAY_DEVICE dispDevice;
|
---|
| 188 | FillMemory(&dispDevice, sizeof(DISPLAY_DEVICE), 0);
|
---|
| 189 | dispDevice.cb = sizeof(DISPLAY_DEVICE);
|
---|
| 190 |
|
---|
[68367] | 191 | LogFlowFunc(("getVBoxDisplayDriverType: Checking for active VBox display driver (W2K+) ...\n"));
|
---|
[8387] | 192 |
|
---|
| 193 | while (EnumDisplayDevices(NULL,
|
---|
| 194 | devNum,
|
---|
| 195 | &dispDevice,
|
---|
| 196 | 0))
|
---|
| 197 | {
|
---|
[68367] | 198 | LogFlowFunc(("getVBoxDisplayDriverType: DevNum:%d\nName:%s\nString:%s\nID:%s\nKey:%s\nFlags=%08X\n\n",
|
---|
[8387] | 199 | devNum,
|
---|
| 200 | &dispDevice.DeviceName[0],
|
---|
| 201 | &dispDevice.DeviceString[0],
|
---|
| 202 | &dispDevice.DeviceID[0],
|
---|
| 203 | &dispDevice.DeviceKey[0],
|
---|
| 204 | dispDevice.StateFlags));
|
---|
[21219] | 205 |
|
---|
[8387] | 206 | if (dispDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
|
---|
| 207 | {
|
---|
[68367] | 208 | LogFlowFunc(("getVBoxDisplayDriverType: Primary device\n"));
|
---|
[21219] | 209 |
|
---|
[68367] | 210 | /* WDDM driver can now have multiple incarnations,
|
---|
| 211 | * if the driver name contains VirtualBox, and does NOT match the XPDM name,
|
---|
| 212 | * assume it to be WDDM */
|
---|
[8387] | 213 | if (strcmp(&dispDevice.DeviceString[0], "VirtualBox Graphics Adapter") == 0)
|
---|
[27955] | 214 | enmType = VBOXDISPLAY_DRIVER_TYPE_XPDM;
|
---|
[42098] | 215 | else if (strstr(&dispDevice.DeviceString[0], "VirtualBox"))
|
---|
[27955] | 216 | enmType = VBOXDISPLAY_DRIVER_TYPE_WDDM;
|
---|
[68367] | 217 |
|
---|
[8387] | 218 | break;
|
---|
| 219 | }
|
---|
[21219] | 220 |
|
---|
[8387] | 221 | FillMemory(&dispDevice, sizeof(DISPLAY_DEVICE), 0);
|
---|
[21219] | 222 |
|
---|
[8387] | 223 | dispDevice.cb = sizeof(DISPLAY_DEVICE);
|
---|
[21219] | 224 |
|
---|
[8387] | 225 | devNum++;
|
---|
| 226 | }
|
---|
| 227 | }
|
---|
| 228 | else /* This must be NT 4 or something really old, so don't use EnumDisplayDevices() here ... */
|
---|
[21219] | 229 | {
|
---|
[68367] | 230 | LogFlowFunc(("getVBoxDisplayDriverType: Checking for active VBox display driver (NT or older) ...\n"));
|
---|
[8387] | 231 |
|
---|
| 232 | DEVMODE tempDevMode;
|
---|
| 233 | ZeroMemory (&tempDevMode, sizeof (tempDevMode));
|
---|
| 234 | tempDevMode.dmSize = sizeof(DEVMODE);
|
---|
| 235 | EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &tempDevMode); /* Get current display device settings */
|
---|
| 236 |
|
---|
| 237 | /* Check for the short name, because all long stuff would be truncated */
|
---|
| 238 | if (strcmp((char*)&tempDevMode.dmDeviceName[0], "VBoxDisp") == 0)
|
---|
[27955] | 239 | enmType = VBOXDISPLAY_DRIVER_TYPE_XPDM;
|
---|
[8387] | 240 | }
|
---|
| 241 |
|
---|
[27955] | 242 | return enmType;
|
---|
[8387] | 243 | }
|
---|
| 244 |
|
---|
[57741] | 245 | /** @todo r=andy The "display", "seamless" (and VBoxCaps facility in VBoxTray.cpp indirectly) is using this.
|
---|
| 246 | * Add a PVBOXDISPLAYCONTEXT here for properly getting the display (XPDM/WDDM) abstraction interfaces. */
|
---|
| 247 | DWORD EnableAndResizeDispDev(DEVMODE *paDeviceModes, DISPLAY_DEVICE *paDisplayDevices,
|
---|
| 248 | DWORD totalDispNum, UINT Id, DWORD aWidth, DWORD aHeight,
|
---|
| 249 | DWORD aBitsPerPixel, LONG aPosX, LONG aPosY, BOOL fEnabled, BOOL fExtDispSup)
|
---|
[44161] | 250 | {
|
---|
[44557] | 251 | DISPLAY_DEVICE displayDeviceTmp;
|
---|
| 252 | DISPLAY_DEVICE displayDevice;
|
---|
| 253 | DEVMODE deviceMode;
|
---|
| 254 | DWORD dwStatus = DISP_CHANGE_SUCCESSFUL;
|
---|
[44648] | 255 | DWORD iter ;
|
---|
[44161] | 256 |
|
---|
[57741] | 257 | PVBOXDISPLAYCONTEXT pCtx = &g_Ctx; /* See todo above. */
|
---|
| 258 |
|
---|
[44648] | 259 | deviceMode = paDeviceModes[Id];
|
---|
| 260 | displayDevice = paDisplayDevices[Id];
|
---|
[44161] | 261 |
|
---|
[44648] | 262 | for (iter = 0; iter < totalDispNum; iter++)
|
---|
[44161] | 263 | {
|
---|
[44648] | 264 | if (iter != 0 && iter != Id && !(paDisplayDevices[iter].StateFlags & DISPLAY_DEVICE_ACTIVE))
|
---|
[44161] | 265 | {
|
---|
[57741] | 266 | LogRel(("Display: Initially disabling monitor with ID=%ld; total monitor count is %ld\n", iter, totalDispNum));
|
---|
[44557] | 267 | DEVMODE deviceModeTmp;
|
---|
| 268 | ZeroMemory(&deviceModeTmp, sizeof(DEVMODE));
|
---|
| 269 | deviceModeTmp.dmSize = sizeof(DEVMODE);
|
---|
| 270 | deviceModeTmp.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_POSITION
|
---|
[44161] | 271 | | DM_DISPLAYFREQUENCY | DM_DISPLAYFLAGS ;
|
---|
[44648] | 272 | displayDeviceTmp = paDisplayDevices[iter];
|
---|
[57741] | 273 | pCtx->pfnChangeDisplaySettingsEx(displayDeviceTmp.DeviceName, &deviceModeTmp, NULL,
|
---|
| 274 | (CDS_UPDATEREGISTRY | CDS_NORESET), NULL);
|
---|
[44161] | 275 | }
|
---|
| 276 | }
|
---|
| 277 |
|
---|
[44648] | 278 | if (fExtDispSup) /* Extended Display Support possible*/
|
---|
[44161] | 279 | {
|
---|
[44648] | 280 | if (fEnabled)
|
---|
[44161] | 281 | {
|
---|
[44648] | 282 | /* Special case for enabling the secondary monitor. */
|
---|
| 283 | if(!(displayDevice.StateFlags & DISPLAY_DEVICE_ACTIVE))
|
---|
| 284 | {
|
---|
[57741] | 285 | LogRel(("Display [ID=%ld, name='%s']: Is a secondary monitor and disabled -- enabling it\n", Id, displayDevice.DeviceName));
|
---|
[44648] | 286 | deviceMode.dmPosition.x = paDeviceModes[0].dmPelsWidth;
|
---|
| 287 | deviceMode.dmPosition.y = 0;
|
---|
| 288 | deviceMode.dmBitsPerPel = 32;
|
---|
[44161] | 289 |
|
---|
[78937] | 290 | uint64_t const uNtVersion = RTSystemGetNtVersion();
|
---|
| 291 | if (uNtVersion < RTSYSTEM_MAKE_NT_VERSION(6, 0, 0))
|
---|
[44648] | 292 | /* dont any more flags here as, only DM_POISITON is used to enable the secondary display */
|
---|
| 293 | deviceMode.dmFields = DM_POSITION;
|
---|
| 294 | else /* for win 7 and above */
|
---|
[48979] | 295 | /* for vista and above DM_BITSPERPEL is necessary */
|
---|
[78937] | 296 | deviceMode.dmFields = DM_BITSPERPEL | DM_DISPLAYFLAGS | DM_DISPLAYFREQUENCY | DM_POSITION;
|
---|
[44648] | 297 |
|
---|
[57741] | 298 | dwStatus = pCtx->pfnChangeDisplaySettingsEx((LPSTR)displayDevice.DeviceName,&deviceMode, NULL, (CDS_UPDATEREGISTRY | CDS_NORESET), NULL);
|
---|
[44648] | 299 | /* A second call to ChangeDisplaySettings updates the monitor.*/
|
---|
[57741] | 300 | pCtx->pfnChangeDisplaySettingsEx(NULL, NULL, NULL,0, NULL);
|
---|
[44194] | 301 | }
|
---|
[44648] | 302 | else /* secondary monitor already enabled. Request to change the resolution or position. */
|
---|
[44194] | 303 | {
|
---|
[44557] | 304 | if (aWidth !=0 && aHeight != 0)
|
---|
| 305 | {
|
---|
[57741] | 306 | LogRel(("Display [ID=%ld, name='%s']: Changing resolution to %ldx%ld\n", Id, displayDevice.DeviceName, aWidth, aHeight));
|
---|
[44648] | 307 | deviceMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL
|
---|
| 308 | | DM_DISPLAYFREQUENCY | DM_DISPLAYFLAGS;
|
---|
[44557] | 309 | deviceMode.dmPelsWidth = aWidth;
|
---|
| 310 | deviceMode.dmPelsHeight = aHeight;
|
---|
| 311 | deviceMode.dmBitsPerPel = aBitsPerPixel;
|
---|
| 312 | }
|
---|
[44648] | 313 | if (aPosX != 0 || aPosY != 0)
|
---|
| 314 | {
|
---|
[57741] | 315 | LogRel(("Display [ID=%ld, name='%s']: Changing position to %ld,%ld\n", Id, displayDevice.DeviceName, aPosX, aPosY));
|
---|
[44648] | 316 | deviceMode.dmFields |= DM_POSITION;
|
---|
| 317 | deviceMode.dmPosition.x = aPosX;
|
---|
| 318 | deviceMode.dmPosition.y = aPosY;
|
---|
| 319 | }
|
---|
[57741] | 320 | dwStatus = pCtx->pfnChangeDisplaySettingsEx((LPSTR)displayDevice.DeviceName,
|
---|
| 321 | &deviceMode, NULL, CDS_NORESET|CDS_UPDATEREGISTRY, NULL);
|
---|
[44648] | 322 | /* A second call to ChangeDisplaySettings updates the monitor. */
|
---|
[57741] | 323 | pCtx->pfnChangeDisplaySettingsEx(NULL, NULL, NULL,0, NULL);
|
---|
[44194] | 324 | }
|
---|
| 325 | }
|
---|
[44648] | 326 | else /* Request is there to disable the monitor with ID = Id*/
|
---|
| 327 | {
|
---|
[57741] | 328 | LogRel(("Display [ID=%ld, name='%s']: Disalbing\n", Id, displayDevice.DeviceName));
|
---|
[44648] | 329 |
|
---|
| 330 | DEVMODE deviceModeTmp;
|
---|
| 331 | ZeroMemory(&deviceModeTmp, sizeof(DEVMODE));
|
---|
| 332 | deviceModeTmp.dmSize = sizeof(DEVMODE);
|
---|
| 333 | deviceModeTmp.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_POSITION
|
---|
| 334 | | DM_DISPLAYFREQUENCY | DM_DISPLAYFLAGS ;
|
---|
| 335 | displayDeviceTmp = paDisplayDevices[Id];
|
---|
[57741] | 336 | dwStatus = pCtx->pfnChangeDisplaySettingsEx(displayDeviceTmp.DeviceName, &deviceModeTmp, NULL,
|
---|
| 337 | (CDS_UPDATEREGISTRY | CDS_NORESET), NULL);
|
---|
| 338 | pCtx->pfnChangeDisplaySettingsEx(NULL, NULL, NULL,0, NULL);
|
---|
[44648] | 339 | }
|
---|
[44194] | 340 | }
|
---|
[44161] | 341 | return dwStatus;
|
---|
[48070] | 342 | }
|
---|
[44161] | 343 |
|
---|
[57741] | 344 | DWORD VBoxDisplayGetCount(void)
|
---|
[8387] | 345 | {
|
---|
| 346 | DISPLAY_DEVICE DisplayDevice;
|
---|
| 347 |
|
---|
[44557] | 348 | ZeroMemory(&DisplayDevice, sizeof(DISPLAY_DEVICE));
|
---|
| 349 | DisplayDevice.cb = sizeof(DISPLAY_DEVICE);
|
---|
[21219] | 350 |
|
---|
[8387] | 351 | /* Find out how many display devices the system has */
|
---|
| 352 | DWORD NumDevices = 0;
|
---|
| 353 | DWORD i = 0;
|
---|
| 354 | while (EnumDisplayDevices (NULL, i, &DisplayDevice, 0))
|
---|
[21219] | 355 | {
|
---|
[51469] | 356 | LogFlowFunc(("ResizeDisplayDevice: [%d] %s\n", i, DisplayDevice.DeviceName));
|
---|
[8387] | 357 |
|
---|
| 358 | if (DisplayDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
|
---|
| 359 | {
|
---|
[51469] | 360 | LogFlowFunc(("ResizeDisplayDevice: Found primary device. err %d\n", GetLastError ()));
|
---|
[8387] | 361 | NumDevices++;
|
---|
| 362 | }
|
---|
| 363 | else if (!(DisplayDevice.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER))
|
---|
| 364 | {
|
---|
[21219] | 365 |
|
---|
[51469] | 366 | LogFlowFunc(("ResizeDisplayDevice: Found secondary device. err %d\n", GetLastError ()));
|
---|
[8387] | 367 | NumDevices++;
|
---|
| 368 | }
|
---|
[21219] | 369 |
|
---|
[8387] | 370 | ZeroMemory(&DisplayDevice, sizeof(DisplayDevice));
|
---|
| 371 | DisplayDevice.cb = sizeof(DisplayDevice);
|
---|
| 372 | i++;
|
---|
| 373 | }
|
---|
[21219] | 374 |
|
---|
[48070] | 375 | return NumDevices;
|
---|
| 376 | }
|
---|
[21219] | 377 |
|
---|
[57741] | 378 | DWORD VBoxDisplayGetConfig(const DWORD NumDevices, DWORD *pDevPrimaryNum, DWORD *pNumDevices,
|
---|
| 379 | DISPLAY_DEVICE *paDisplayDevices, DEVMODE *paDeviceModes)
|
---|
[48070] | 380 | {
|
---|
[8387] | 381 | /* Fetch information about current devices and modes. */
|
---|
| 382 | DWORD DevNum = 0;
|
---|
| 383 | DWORD DevPrimaryNum = 0;
|
---|
[21219] | 384 |
|
---|
[48070] | 385 | DISPLAY_DEVICE DisplayDevice;
|
---|
| 386 |
|
---|
[8387] | 387 | ZeroMemory(&DisplayDevice, sizeof(DISPLAY_DEVICE));
|
---|
| 388 | DisplayDevice.cb = sizeof(DISPLAY_DEVICE);
|
---|
[21219] | 389 |
|
---|
[48070] | 390 | DWORD i = 0;
|
---|
[8387] | 391 | while (EnumDisplayDevices (NULL, i, &DisplayDevice, 0))
|
---|
[21219] | 392 | {
|
---|
[51469] | 393 | LogFlowFunc(("ResizeDisplayDevice: [%d(%d)] %s\n", i, DevNum, DisplayDevice.DeviceName));
|
---|
[21219] | 394 |
|
---|
[8387] | 395 | BOOL bFetchDevice = FALSE;
|
---|
| 396 |
|
---|
| 397 | if (DisplayDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
|
---|
| 398 | {
|
---|
[51469] | 399 | LogFlowFunc(("ResizeDisplayDevice: Found primary device. err %d\n", GetLastError ()));
|
---|
[8387] | 400 | DevPrimaryNum = DevNum;
|
---|
| 401 | bFetchDevice = TRUE;
|
---|
| 402 | }
|
---|
| 403 | else if (!(DisplayDevice.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER))
|
---|
| 404 | {
|
---|
[21219] | 405 |
|
---|
[51469] | 406 | LogFlowFunc(("ResizeDisplayDevice: Found secondary device. err %d\n", GetLastError ()));
|
---|
[8387] | 407 | bFetchDevice = TRUE;
|
---|
| 408 | }
|
---|
[21219] | 409 |
|
---|
[8387] | 410 | if (bFetchDevice)
|
---|
| 411 | {
|
---|
| 412 | if (DevNum >= NumDevices)
|
---|
| 413 | {
|
---|
[51469] | 414 | LogFlowFunc(("ResizeDisplayDevice: %d >= %d\n", NumDevices, DevNum));
|
---|
[48070] | 415 | return ERROR_BUFFER_OVERFLOW;
|
---|
[8387] | 416 | }
|
---|
[21219] | 417 |
|
---|
[8387] | 418 | paDisplayDevices[DevNum] = DisplayDevice;
|
---|
[21219] | 419 |
|
---|
[19836] | 420 | /* First try to get the video mode stored in registry (ENUM_REGISTRY_SETTINGS).
|
---|
| 421 | * A secondary display could be not active at the moment and would not have
|
---|
| 422 | * a current video mode (ENUM_CURRENT_SETTINGS).
|
---|
| 423 | */
|
---|
[8387] | 424 | ZeroMemory(&paDeviceModes[DevNum], sizeof(DEVMODE));
|
---|
| 425 | paDeviceModes[DevNum].dmSize = sizeof(DEVMODE);
|
---|
| 426 | if (!EnumDisplaySettings((LPSTR)DisplayDevice.DeviceName,
|
---|
| 427 | ENUM_REGISTRY_SETTINGS, &paDeviceModes[DevNum]))
|
---|
| 428 | {
|
---|
[51469] | 429 | LogFlowFunc(("ResizeDisplayDevice: EnumDisplaySettings error %d\n", GetLastError ()));
|
---|
[8387] | 430 | }
|
---|
[21219] | 431 |
|
---|
[19836] | 432 | if ( paDeviceModes[DevNum].dmPelsWidth == 0
|
---|
| 433 | || paDeviceModes[DevNum].dmPelsHeight == 0)
|
---|
| 434 | {
|
---|
| 435 | /* No ENUM_REGISTRY_SETTINGS yet. Seen on Vista after installation.
|
---|
| 436 | * Get the current video mode then.
|
---|
| 437 | */
|
---|
| 438 | ZeroMemory(&paDeviceModes[DevNum], sizeof(DEVMODE));
|
---|
| 439 | paDeviceModes[DevNum].dmSize = sizeof(DEVMODE);
|
---|
| 440 | if (!EnumDisplaySettings((LPSTR)DisplayDevice.DeviceName,
|
---|
| 441 | ENUM_CURRENT_SETTINGS, &paDeviceModes[DevNum]))
|
---|
| 442 | {
|
---|
[20201] | 443 | /* ENUM_CURRENT_SETTINGS returns FALSE when the display is not active:
|
---|
| 444 | * for example a disabled secondary display.
|
---|
| 445 | * Do not return here, ignore the error and set the display info to 0x0x0.
|
---|
| 446 | */
|
---|
[51469] | 447 | LogFlowFunc(("ResizeDisplayDevice: EnumDisplaySettings(ENUM_CURRENT_SETTINGS) error %d\n", GetLastError ()));
|
---|
[19836] | 448 | }
|
---|
| 449 | }
|
---|
[21219] | 450 |
|
---|
[48070] | 451 |
|
---|
[8387] | 452 | DevNum++;
|
---|
| 453 | }
|
---|
[21219] | 454 |
|
---|
[8387] | 455 | ZeroMemory(&DisplayDevice, sizeof(DISPLAY_DEVICE));
|
---|
| 456 | DisplayDevice.cb = sizeof(DISPLAY_DEVICE);
|
---|
| 457 | i++;
|
---|
| 458 | }
|
---|
[48070] | 459 |
|
---|
| 460 | *pNumDevices = DevNum;
|
---|
[61620] | 461 | *pDevPrimaryNum = DevPrimaryNum;
|
---|
[48070] | 462 |
|
---|
| 463 | return NO_ERROR;
|
---|
| 464 | }
|
---|
| 465 |
|
---|
[68375] | 466 | static void ResizeDisplayDeviceNT4(DWORD dwNewXRes, DWORD dwNewYRes, DWORD dwNewBpp)
|
---|
| 467 | {
|
---|
| 468 | DEVMODE devMode;
|
---|
| 469 |
|
---|
| 470 | RT_ZERO(devMode);
|
---|
| 471 | devMode.dmSize = sizeof(DEVMODE);
|
---|
| 472 |
|
---|
| 473 | /* get the current screen setup */
|
---|
| 474 | if (!EnumDisplaySettings(NULL, ENUM_REGISTRY_SETTINGS, &devMode))
|
---|
| 475 | {
|
---|
| 476 | LogFlowFunc(("error from EnumDisplaySettings: %d\n", GetLastError()));
|
---|
| 477 | return;
|
---|
| 478 | }
|
---|
| 479 |
|
---|
| 480 | LogFlowFunc(("Current mode: %d x %d x %d at %d,%d\n",
|
---|
| 481 | devMode.dmPelsWidth, devMode.dmPelsHeight, devMode.dmBitsPerPel, devMode.dmPosition.x, devMode.dmPosition.y));
|
---|
| 482 |
|
---|
| 483 | /* Check whether a mode reset or a change is requested. */
|
---|
| 484 | if (dwNewXRes || dwNewYRes || dwNewBpp)
|
---|
| 485 | {
|
---|
| 486 | /* A change is requested.
|
---|
| 487 | * Set values which are not to be changed to the current values.
|
---|
| 488 | */
|
---|
| 489 | if (!dwNewXRes)
|
---|
| 490 | dwNewXRes = devMode.dmPelsWidth;
|
---|
| 491 | if (!dwNewYRes)
|
---|
| 492 | dwNewYRes = devMode.dmPelsHeight;
|
---|
| 493 | if (!dwNewBpp)
|
---|
| 494 | dwNewBpp = devMode.dmBitsPerPel;
|
---|
| 495 | }
|
---|
| 496 | else
|
---|
| 497 | {
|
---|
| 498 | /* All zero values means a forced mode reset. Do nothing. */
|
---|
| 499 | LogFlowFunc(("Forced mode reset\n"));
|
---|
| 500 | }
|
---|
| 501 |
|
---|
| 502 | /* Verify that the mode is indeed changed. */
|
---|
| 503 | if (devMode.dmPelsWidth == dwNewXRes
|
---|
| 504 | && devMode.dmPelsHeight == dwNewYRes
|
---|
| 505 | && devMode.dmBitsPerPel == dwNewBpp)
|
---|
| 506 | {
|
---|
| 507 | LogFlowFunc(("already at desired resolution\n"));
|
---|
| 508 | return;
|
---|
| 509 | }
|
---|
| 510 |
|
---|
| 511 | // without this, Windows will not ask the miniport for its
|
---|
| 512 | // mode table but uses an internal cache instead
|
---|
| 513 | DEVMODE tempDevMode = { 0 };
|
---|
| 514 | tempDevMode.dmSize = sizeof(DEVMODE);
|
---|
| 515 | EnumDisplaySettings(NULL, 0xffffff, &tempDevMode);
|
---|
| 516 |
|
---|
| 517 | /* adjust the values that are supposed to change */
|
---|
| 518 | if (dwNewXRes)
|
---|
| 519 | devMode.dmPelsWidth = dwNewXRes;
|
---|
| 520 | if (dwNewYRes)
|
---|
| 521 | devMode.dmPelsHeight = dwNewYRes;
|
---|
| 522 | if (dwNewBpp)
|
---|
| 523 | devMode.dmBitsPerPel = dwNewBpp;
|
---|
| 524 |
|
---|
| 525 | LogFlowFunc(("setting new mode %d x %d, %d BPP\n",
|
---|
| 526 | devMode.dmPelsWidth, devMode.dmPelsHeight, devMode.dmBitsPerPel));
|
---|
| 527 |
|
---|
| 528 | /* set the new mode */
|
---|
| 529 | LONG status = ChangeDisplaySettings(&devMode, CDS_UPDATEREGISTRY);
|
---|
| 530 | if (status != DISP_CHANGE_SUCCESSFUL)
|
---|
| 531 | {
|
---|
| 532 | LogFlowFunc(("error from ChangeDisplaySettings: %d\n", status));
|
---|
| 533 |
|
---|
| 534 | if (status == DISP_CHANGE_BADMODE)
|
---|
| 535 | {
|
---|
| 536 | /* Our driver can not set the requested mode. Stop trying. */
|
---|
| 537 | return;
|
---|
| 538 | }
|
---|
| 539 | }
|
---|
| 540 | }
|
---|
| 541 |
|
---|
[48070] | 542 | /* Returns TRUE to try again. */
|
---|
[57741] | 543 | /** @todo r=andy Why not using the VMMDevDisplayChangeRequestEx structure for all those parameters here? */
|
---|
| 544 | static BOOL ResizeDisplayDevice(PVBOXDISPLAYCONTEXT pCtx,
|
---|
| 545 | UINT Id, DWORD Width, DWORD Height, DWORD BitsPerPixel,
|
---|
[53313] | 546 | BOOL fEnabled, LONG dwNewPosX, LONG dwNewPosY, bool fChangeOrigin,
|
---|
[57741] | 547 | BOOL fExtDispSup)
|
---|
[48070] | 548 | {
|
---|
| 549 | BOOL fDispAlreadyEnabled = false; /* check whether the monitor with ID is already enabled. */
|
---|
[68437] | 550 | BOOL fModeReset = ( Width == 0 && Height == 0 && BitsPerPixel == 0
|
---|
| 551 | && dwNewPosX == 0 && dwNewPosY == 0 && !fChangeOrigin);
|
---|
[48070] | 552 | DWORD dmFields = 0;
|
---|
[69180] | 553 | VBOXDISPLAY_DRIVER_TYPE enmDriverType = getVBoxDisplayDriverType(pCtx);
|
---|
[48070] | 554 |
|
---|
[53313] | 555 | LogFlowFunc(("[%d] %dx%d at %d,%d fChangeOrigin %d fEnabled %d fExtDisSup %d\n",
|
---|
[68437] | 556 | Id, Width, Height, dwNewPosX, dwNewPosY, fChangeOrigin, fEnabled, fExtDispSup));
|
---|
[48070] | 557 |
|
---|
[57741] | 558 | if (!pCtx->fAnyX)
|
---|
[48070] | 559 | Width &= 0xFFF8;
|
---|
| 560 |
|
---|
| 561 | VBoxDispIfCancelPendingResize(&pCtx->pEnv->dispIf);
|
---|
| 562 |
|
---|
[57741] | 563 | DWORD NumDevices = VBoxDisplayGetCount();
|
---|
[48070] | 564 |
|
---|
| 565 | if (NumDevices == 0 || Id >= NumDevices)
|
---|
| 566 | {
|
---|
[51469] | 567 | LogFlowFunc(("ResizeDisplayDevice: Requested identifier %d is invalid. err %d\n", Id, GetLastError ()));
|
---|
[48070] | 568 | return FALSE;
|
---|
| 569 | }
|
---|
| 570 |
|
---|
[51469] | 571 | LogFlowFunc(("ResizeDisplayDevice: Found total %d devices. err %d\n", NumDevices, GetLastError ()));
|
---|
[48070] | 572 |
|
---|
[68630] | 573 | DISPLAY_DEVICE *paDisplayDevices = (DISPLAY_DEVICE *)alloca(sizeof (DISPLAY_DEVICE) * NumDevices);
|
---|
| 574 | DEVMODE *paDeviceModes = (DEVMODE *)alloca(sizeof (DEVMODE) * NumDevices);
|
---|
[48070] | 575 | RECTL *paRects = (RECTL *)alloca (sizeof (RECTL) * NumDevices);
|
---|
| 576 | DWORD DevNum = 0;
|
---|
| 577 | DWORD DevPrimaryNum = 0;
|
---|
[57741] | 578 | DWORD dwStatus = VBoxDisplayGetConfig(NumDevices, &DevPrimaryNum, &DevNum, paDisplayDevices, paDeviceModes);
|
---|
[48070] | 579 | if (dwStatus != NO_ERROR)
|
---|
| 580 | {
|
---|
[51469] | 581 | LogFlowFunc(("ResizeDisplayDevice: VBoxGetDisplayConfig failed, %d\n", dwStatus));
|
---|
[48070] | 582 | return dwStatus;
|
---|
| 583 | }
|
---|
| 584 |
|
---|
| 585 | if (NumDevices != DevNum)
|
---|
[51469] | 586 | LogFlowFunc(("ResizeDisplayDevice: NumDevices(%d) != DevNum(%d)\n", NumDevices, DevNum));
|
---|
[48070] | 587 |
|
---|
[68437] | 588 | DWORD i;
|
---|
[48070] | 589 | for (i = 0; i < DevNum; ++i)
|
---|
| 590 | {
|
---|
| 591 | if (fExtDispSup)
|
---|
| 592 | {
|
---|
[51469] | 593 | LogRel(("Extended Display Support.\n"));
|
---|
[53313] | 594 | LogFlowFunc(("[%d] %dx%dx%d at %d,%d, dmFields 0x%x\n",
|
---|
| 595 | i,
|
---|
| 596 | paDeviceModes[i].dmPelsWidth,
|
---|
| 597 | paDeviceModes[i].dmPelsHeight,
|
---|
| 598 | paDeviceModes[i].dmBitsPerPel,
|
---|
| 599 | paDeviceModes[i].dmPosition.x,
|
---|
| 600 | paDeviceModes[i].dmPosition.y,
|
---|
| 601 | paDeviceModes[i].dmFields));
|
---|
[48070] | 602 | }
|
---|
| 603 | else
|
---|
| 604 | {
|
---|
[51469] | 605 | LogRel(("NO Ext Display Support \n"));
|
---|
[48070] | 606 | }
|
---|
| 607 |
|
---|
| 608 | paRects[i].left = paDeviceModes[i].dmPosition.x;
|
---|
| 609 | paRects[i].top = paDeviceModes[i].dmPosition.y;
|
---|
| 610 | paRects[i].right = paDeviceModes[i].dmPosition.x + paDeviceModes[i].dmPelsWidth;
|
---|
| 611 | paRects[i].bottom = paDeviceModes[i].dmPosition.y + paDeviceModes[i].dmPelsHeight;
|
---|
| 612 | }
|
---|
| 613 |
|
---|
[44557] | 614 | /* Keep a record if the display with ID is already active or not. */
|
---|
| 615 | if (paDisplayDevices[Id].StateFlags & DISPLAY_DEVICE_ACTIVE)
|
---|
| 616 | {
|
---|
[51469] | 617 | LogRel(("Display with ID=%d already enabled\n", Id));
|
---|
[44557] | 618 | fDispAlreadyEnabled = TRUE;
|
---|
| 619 | }
|
---|
[21219] | 620 |
|
---|
[8434] | 621 | /* Width, height equal to 0 means that this value must be not changed.
|
---|
[8396] | 622 | * Update input parameters if necessary.
|
---|
[8434] | 623 | * Note: BitsPerPixel is taken into account later, when new rectangles
|
---|
| 624 | * are assigned to displays.
|
---|
[8396] | 625 | */
|
---|
[8387] | 626 | if (Width == 0)
|
---|
| 627 | Width = paRects[Id].right - paRects[Id].left;
|
---|
[48070] | 628 | else
|
---|
| 629 | dmFields |= DM_PELSWIDTH;
|
---|
[8387] | 630 |
|
---|
| 631 | if (Height == 0)
|
---|
[48070] | 632 | Height = paRects[Id].bottom - paRects[Id].top;
|
---|
| 633 | else
|
---|
| 634 | dmFields |= DM_PELSHEIGHT;
|
---|
| 635 |
|
---|
| 636 | if (BitsPerPixel == 0)
|
---|
| 637 | BitsPerPixel = paDeviceModes[Id].dmBitsPerPel;
|
---|
| 638 | else
|
---|
| 639 | dmFields |= DM_BITSPERPEL;
|
---|
| 640 |
|
---|
[53313] | 641 | if (!fChangeOrigin)
|
---|
[8387] | 642 | {
|
---|
[53313] | 643 | /* Use existing position. */
|
---|
[48070] | 644 | dwNewPosX = paRects[Id].left;
|
---|
| 645 | dwNewPosY = paRects[Id].top;
|
---|
[53313] | 646 | LogFlowFunc(("existing dwNewPosX %d, dwNewPosY %d\n", dwNewPosX, dwNewPosY));
|
---|
[8387] | 647 | }
|
---|
| 648 |
|
---|
[53313] | 649 | /* Always update the position.
|
---|
| 650 | * It is either explicitly requested or must be set to the existing position.
|
---|
| 651 | */
|
---|
| 652 | dmFields |= DM_POSITION;
|
---|
| 653 |
|
---|
[44194] | 654 | /* Check whether a mode reset or a change is requested.
|
---|
| 655 | * Rectangle position is recalculated only if fEnabled is 1.
|
---|
| 656 | * For non extended supported modes (old Host VMs), fEnabled
|
---|
| 657 | * is always 1.
|
---|
| 658 | */
|
---|
[44305] | 659 | /* Handled the case where previouseresolution of secondary monitor
|
---|
| 660 | * was for eg. 1024*768*32 and monitor was in disabled state.
|
---|
| 661 | * User gives the command
|
---|
| 662 | * setvideomode 1024 768 32 1 yes.
|
---|
| 663 | * Now in this case the resolution request is same as previous one but
|
---|
| 664 | * monitor is going from disabled to enabled state so the below condition
|
---|
| 665 | * shour return false
|
---|
| 666 | * The below condition will only return true , if no mode reset has
|
---|
| 667 | * been requested AND fEnabled is 1 and fDispAlreadyEnabled is also 1 AND
|
---|
| 668 | * all rect conditions are true. Thus in this case nothing has to be done.
|
---|
| 669 | */
|
---|
[68437] | 670 | if ( !fModeReset
|
---|
| 671 | && (!fEnabled == !fDispAlreadyEnabled)
|
---|
[57741] | 672 | && paRects[Id].left == dwNewPosX
|
---|
| 673 | && paRects[Id].top == dwNewPosY
|
---|
[63100] | 674 | && paRects[Id].right - paRects[Id].left == (LONG)Width
|
---|
| 675 | && paRects[Id].bottom - paRects[Id].top == (LONG)Height
|
---|
[8387] | 676 | && paDeviceModes[Id].dmBitsPerPel == BitsPerPixel)
|
---|
| 677 | {
|
---|
[51469] | 678 | LogRel(("Already at desired resolution. No Change.\n"));
|
---|
[8387] | 679 | return FALSE;
|
---|
| 680 | }
|
---|
| 681 |
|
---|
[48070] | 682 | hlpResizeRect(paRects, NumDevices, DevPrimaryNum, Id,
|
---|
| 683 | fEnabled ? Width : 0, fEnabled ? Height : 0, dwNewPosX, dwNewPosY);
|
---|
[69180] | 684 |
|
---|
[8387] | 685 | for (i = 0; i < NumDevices; i++)
|
---|
| 686 | {
|
---|
[51469] | 687 | LogFlowFunc(("ResizeDisplayDevice: [%d]: %d,%d %dx%d\n",
|
---|
[8387] | 688 | i, paRects[i].left, paRects[i].top,
|
---|
| 689 | paRects[i].right - paRects[i].left,
|
---|
| 690 | paRects[i].bottom - paRects[i].top));
|
---|
| 691 | }
|
---|
[21219] | 692 |
|
---|
[69180] | 693 | /* Assign the new rectangles to displays. */
|
---|
| 694 | for (i = 0; i < NumDevices; i++)
|
---|
[34130] | 695 | {
|
---|
[69180] | 696 | paDeviceModes[i].dmPosition.x = paRects[i].left;
|
---|
| 697 | paDeviceModes[i].dmPosition.y = paRects[i].top;
|
---|
| 698 | paDeviceModes[i].dmPelsWidth = paRects[i].right - paRects[i].left;
|
---|
| 699 | paDeviceModes[i].dmPelsHeight = paRects[i].bottom - paRects[i].top;
|
---|
[34130] | 700 |
|
---|
[69180] | 701 | if (i == Id)
|
---|
| 702 | paDeviceModes[i].dmBitsPerPel = BitsPerPixel;
|
---|
[48070] | 703 |
|
---|
[69180] | 704 | if (enmDriverType >= VBOXDISPLAY_DRIVER_TYPE_WDDM)
|
---|
| 705 | {
|
---|
[48070] | 706 | paDeviceModes[i].dmFields |= dmFields;
|
---|
| 707 |
|
---|
[34130] | 708 | /* On Vista one must specify DM_BITSPERPEL.
|
---|
[69180] | 709 | * Note that the current mode dmBitsPerPel is already in the DEVMODE structure.
|
---|
| 710 | */
|
---|
[48070] | 711 | if (!(paDeviceModes[i].dmFields & DM_BITSPERPEL))
|
---|
[34130] | 712 | {
|
---|
[51469] | 713 | LogFlowFunc(("no DM_BITSPERPEL\n"));
|
---|
[48070] | 714 | paDeviceModes[i].dmFields |= DM_BITSPERPEL;
|
---|
| 715 | paDeviceModes[i].dmBitsPerPel = 32;
|
---|
[34130] | 716 | }
|
---|
| 717 | }
|
---|
[69180] | 718 | else
|
---|
| 719 | {
|
---|
| 720 | paDeviceModes[i].dmFields = DM_POSITION | DM_PELSHEIGHT | DM_PELSWIDTH | DM_BITSPERPEL;
|
---|
| 721 | }
|
---|
[34130] | 722 |
|
---|
[69180] | 723 | LogFlowFunc(("ResizeDisplayDevice: Going to resize display %d to %dx%dx%d at %d,%d fields 0x%X\n",
|
---|
| 724 | i,
|
---|
| 725 | paDeviceModes[i].dmPelsWidth,
|
---|
| 726 | paDeviceModes[i].dmPelsHeight,
|
---|
| 727 | paDeviceModes[i].dmBitsPerPel,
|
---|
| 728 | paDeviceModes[i].dmPosition.x,
|
---|
| 729 | paDeviceModes[i].dmPosition.y,
|
---|
| 730 | paDeviceModes[i].dmFields));
|
---|
| 731 | }
|
---|
| 732 |
|
---|
| 733 | if (enmDriverType == VBOXDISPLAY_DRIVER_TYPE_WDDM)
|
---|
| 734 | {
|
---|
[48070] | 735 | DWORD err = VBoxDispIfResizeModes(&pCtx->pEnv->dispIf, Id, fEnabled, fExtDispSup, paDisplayDevices, paDeviceModes, DevNum);
|
---|
| 736 |
|
---|
[69201] | 737 | return (err == ERROR_RETRY);
|
---|
[34130] | 738 | }
|
---|
[69201] | 739 |
|
---|
| 740 | /* The XPDM code path goes below.
|
---|
| 741 | * Re-requesting modes with EnumDisplaySettings forces Windows to again ask the miniport for its mode table.
|
---|
[8387] | 742 | */
|
---|
[27185] | 743 | for (i = 0; i < NumDevices; i++)
|
---|
| 744 | {
|
---|
| 745 | DEVMODE tempDevMode;
|
---|
| 746 | ZeroMemory (&tempDevMode, sizeof (tempDevMode));
|
---|
| 747 | tempDevMode.dmSize = sizeof(DEVMODE);
|
---|
| 748 | EnumDisplaySettings((LPSTR)paDisplayDevices[i].DeviceName, 0xffffff, &tempDevMode);
|
---|
[51469] | 749 | LogFlowFunc(("ResizeDisplayDevice: EnumDisplaySettings last error %d\n", GetLastError ()));
|
---|
[27185] | 750 | }
|
---|
[8387] | 751 |
|
---|
| 752 | /* Assign the new rectangles to displays. */
|
---|
| 753 | for (i = 0; i < NumDevices; i++)
|
---|
| 754 | {
|
---|
[57741] | 755 | LONG status = pCtx->pfnChangeDisplaySettingsEx((LPSTR)paDisplayDevices[i].DeviceName,
|
---|
| 756 | &paDeviceModes[i], NULL, CDS_NORESET | CDS_UPDATEREGISTRY, NULL);
|
---|
[63100] | 757 | LogFlowFunc(("ResizeDisplayDevice: ChangeDisplaySettingsEx position status %d, err %d\n", status, GetLastError()));
|
---|
| 758 | NOREF(status);
|
---|
[8387] | 759 | }
|
---|
[44194] | 760 |
|
---|
[68437] | 761 | LogFlowFunc(("Enable And Resize Device. Id = %d, Width=%d Height=%d, dwNewPosX = %d, dwNewPosY = %d fEnabled=%d & fExtDispSupport = %d \n",
|
---|
| 762 | Id, Width, Height, dwNewPosX, dwNewPosY, fEnabled, fExtDispSup));
|
---|
[44648] | 763 | dwStatus = EnableAndResizeDispDev(paDeviceModes, paDisplayDevices, DevNum, Id, Width, Height, BitsPerPixel,
|
---|
[48070] | 764 | dwNewPosX, dwNewPosY, fEnabled, fExtDispSup);
|
---|
[44161] | 765 | if (dwStatus == DISP_CHANGE_SUCCESSFUL || dwStatus == DISP_CHANGE_BADMODE)
|
---|
| 766 | {
|
---|
| 767 | /* Successfully set new video mode or our driver can not set
|
---|
| 768 | * the requested mode. Stop trying.
|
---|
| 769 | */
|
---|
[19836] | 770 | return FALSE;
|
---|
[8387] | 771 | }
|
---|
[19836] | 772 | /* Retry the request. */
|
---|
| 773 | return TRUE;
|
---|
[8387] | 774 | }
|
---|
| 775 |
|
---|
[72352] | 776 | static void doResize(PVBOXDISPLAYCONTEXT pCtx,
|
---|
| 777 | uint32_t iDisplay,
|
---|
| 778 | uint32_t cx,
|
---|
| 779 | uint32_t cy,
|
---|
| 780 | uint32_t cBits,
|
---|
| 781 | bool fEnabled,
|
---|
| 782 | uint32_t cxOrigin,
|
---|
| 783 | uint32_t cyOrigin,
|
---|
| 784 | bool fChangeOrigin)
|
---|
| 785 | {
|
---|
| 786 | for (;;)
|
---|
| 787 | {
|
---|
| 788 | VBOXDISPLAY_DRIVER_TYPE enmDriverType = getVBoxDisplayDriverType(pCtx);
|
---|
| 789 | if (enmDriverType == VBOXDISPLAY_DRIVER_TYPE_UNKNOWN)
|
---|
| 790 | {
|
---|
| 791 | LogFlowFunc(("vboxDisplayDriver is not active\n"));
|
---|
| 792 | break;
|
---|
| 793 | }
|
---|
| 794 |
|
---|
| 795 | if (pCtx->pfnChangeDisplaySettingsEx != 0)
|
---|
| 796 | {
|
---|
| 797 | LogFlowFunc(("Detected W2K or later\n"));
|
---|
| 798 | if (!ResizeDisplayDevice(pCtx,
|
---|
| 799 | iDisplay,
|
---|
| 800 | cx,
|
---|
| 801 | cy,
|
---|
| 802 | cBits,
|
---|
| 803 | fEnabled,
|
---|
| 804 | cxOrigin,
|
---|
| 805 | cyOrigin,
|
---|
| 806 | fChangeOrigin,
|
---|
| 807 | true /*fExtDispSup*/ ))
|
---|
| 808 | {
|
---|
| 809 | LogFlowFunc(("ResizeDipspalyDevice return 0\n"));
|
---|
| 810 | break;
|
---|
| 811 | }
|
---|
| 812 |
|
---|
| 813 | }
|
---|
| 814 | else
|
---|
| 815 | {
|
---|
| 816 | LogFlowFunc(("Detected NT\n"));
|
---|
| 817 | ResizeDisplayDeviceNT4(cx, cy, cBits);
|
---|
| 818 | break;
|
---|
| 819 | }
|
---|
| 820 |
|
---|
| 821 | /* Retry the change a bit later. */
|
---|
| 822 | RTThreadSleep(1000);
|
---|
| 823 | }
|
---|
| 824 | }
|
---|
| 825 |
|
---|
[73724] | 826 | static BOOL DisplayChangeRequestHandler(PVBOXDISPLAYCONTEXT pCtx)
|
---|
| 827 | {
|
---|
| 828 | VMMDevDisplayDef aDisplays[64];
|
---|
| 829 | uint32_t cDisplays = RT_ELEMENTS(aDisplays);
|
---|
| 830 | int rc = VINF_SUCCESS;
|
---|
| 831 |
|
---|
[73966] | 832 | /* Multidisplay resize is still implemented only for Win7 and newer guests. */
|
---|
| 833 | if (pCtx->pEnv->dispIf.enmMode >= VBOXDISPIF_MODE_WDDM_W7 &&
|
---|
| 834 | RT_SUCCESS(rc = VbglR3GetDisplayChangeRequestMulti(cDisplays, &cDisplays, &aDisplays[0], true /* fAck */)))
|
---|
[73724] | 835 | {
|
---|
| 836 | uint32_t i;
|
---|
| 837 |
|
---|
| 838 | LogRel(("Got multi resize request %d displays\n", cDisplays));
|
---|
| 839 |
|
---|
| 840 | for (i = 0; i < cDisplays; ++i)
|
---|
| 841 | {
|
---|
| 842 | LogRel(("[%d]: %d 0x%02X %d,%d %dx%d %d\n",
|
---|
| 843 | i, aDisplays[i].idDisplay,
|
---|
| 844 | aDisplays[i].fDisplayFlags,
|
---|
| 845 | aDisplays[i].xOrigin,
|
---|
| 846 | aDisplays[i].yOrigin,
|
---|
| 847 | aDisplays[i].cx,
|
---|
| 848 | aDisplays[i].cy,
|
---|
| 849 | aDisplays[i].cBitsPerPixel));
|
---|
| 850 | }
|
---|
| 851 |
|
---|
[73966] | 852 | return VBoxDispIfResizeDisplayWin7(&pCtx->pEnv->dispIf, cDisplays, &aDisplays[0]);
|
---|
[73724] | 853 | }
|
---|
| 854 |
|
---|
| 855 | /* Fall back to the single monitor resize request. */
|
---|
| 856 |
|
---|
| 857 | /*
|
---|
| 858 | * We got at least one event. (bird: What does that mean actually? The driver wakes us up immediately upon
|
---|
| 859 | * receiving the event. Or are we refering to mouse & display? In the latter case it's misleading.)
|
---|
| 860 | *
|
---|
| 861 | * Read the requested resolution and try to set it until success.
|
---|
| 862 | * New events will not be seen but a new resolution will be read in
|
---|
| 863 | * this poll loop.
|
---|
| 864 | *
|
---|
| 865 | * Note! The interface we're using here was added in VBox 4.2.4. As of 2017-08-16, this
|
---|
| 866 | * version has been unsupported for a long time and we therefore don't bother
|
---|
| 867 | * implementing fallbacks using VMMDevDisplayChangeRequest2 and VMMDevDisplayChangeRequest.
|
---|
| 868 | */
|
---|
| 869 | uint32_t cx = 0;
|
---|
| 870 | uint32_t cy = 0;
|
---|
| 871 | uint32_t cBits = 0;
|
---|
| 872 | uint32_t iDisplay = 0;
|
---|
| 873 | uint32_t cxOrigin = 0;
|
---|
| 874 | uint32_t cyOrigin = 0;
|
---|
| 875 | bool fChangeOrigin = false;
|
---|
| 876 | bool fEnabled = false;
|
---|
| 877 | rc = VbglR3GetDisplayChangeRequest(&cx, &cy, &cBits, &iDisplay, &cxOrigin, &cyOrigin, &fEnabled, &fChangeOrigin,
|
---|
| 878 | true /*fAck*/);
|
---|
| 879 | if (RT_SUCCESS(rc))
|
---|
| 880 | {
|
---|
| 881 | /* Try to set the requested video mode. Repeat until it is successful or is rejected by the driver. */
|
---|
| 882 | LogFlowFunc(("DisplayChangeReqEx parameters iDisplay=%d x cx=%d x cy=%d x cBits=%d x SecondayMonEnb=%d x NewOriginX=%d x NewOriginY=%d x ChangeOrigin=%d\n",
|
---|
| 883 | iDisplay, cx, cy, cBits, fEnabled, cxOrigin, cyOrigin, fChangeOrigin));
|
---|
| 884 |
|
---|
| 885 | doResize(pCtx,
|
---|
| 886 | iDisplay,
|
---|
| 887 | cx,
|
---|
| 888 | cy,
|
---|
| 889 | cBits,
|
---|
| 890 | fEnabled,
|
---|
| 891 | cxOrigin,
|
---|
| 892 | cyOrigin,
|
---|
| 893 | fChangeOrigin);
|
---|
| 894 | }
|
---|
| 895 |
|
---|
| 896 | return rc;
|
---|
| 897 | }
|
---|
| 898 |
|
---|
[8387] | 899 | /**
|
---|
[68437] | 900 | * Thread function to wait for and process display change requests.
|
---|
[8387] | 901 | */
|
---|
[68437] | 902 | static DECLCALLBACK(int) VBoxDisplayWorker(void *pvInstance, bool volatile *pfShutdown)
|
---|
[8387] | 903 | {
|
---|
[68437] | 904 | AssertPtr(pvInstance);
|
---|
| 905 | PVBOXDISPLAYCONTEXT pCtx = (PVBOXDISPLAYCONTEXT)pvInstance;
|
---|
| 906 | AssertPtr(pCtx->pEnv);
|
---|
| 907 | LogFlowFunc(("pvInstance=%p\n", pvInstance));
|
---|
[32592] | 908 |
|
---|
[57741] | 909 | /*
|
---|
| 910 | * Tell the control thread that it can continue
|
---|
| 911 | * spawning services.
|
---|
| 912 | */
|
---|
| 913 | RTThreadUserSignal(RTThreadSelf());
|
---|
| 914 |
|
---|
[68437] | 915 | int rc = VbglR3CtlFilterMask(VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST | VMMDEV_EVENT_MOUSE_CAPABILITIES_CHANGED, 0 /*fNot*/);
|
---|
| 916 | if (RT_FAILURE(rc))
|
---|
[8387] | 917 | {
|
---|
[68437] | 918 | LogFlowFunc(("VbglR3CtlFilterMask(mask,0): %Rrc\n", rc));
|
---|
| 919 | return rc;
|
---|
[8387] | 920 | }
|
---|
[32687] | 921 |
|
---|
[57741] | 922 | PostMessage(g_hwndToolWindow, WM_VBOX_GRAPHICS_SUPPORTED, 0, 0);
|
---|
[8387] | 923 |
|
---|
[48070] | 924 | VBoxDispIfResizeStarted(&pCtx->pEnv->dispIf);
|
---|
| 925 |
|
---|
[68437] | 926 | for (;;)
|
---|
[8387] | 927 | {
|
---|
[68437] | 928 | /*
|
---|
| 929 | * Wait for a display change event, checking for shutdown both before and after.
|
---|
| 930 | */
|
---|
| 931 | if (*pfShutdown)
|
---|
[8387] | 932 | {
|
---|
[68437] | 933 | rc = VINF_SUCCESS;
|
---|
| 934 | break;
|
---|
| 935 | }
|
---|
[8387] | 936 |
|
---|
[68437] | 937 | uint32_t fEvents = 0;
|
---|
| 938 | rc = VbglR3WaitEvent(VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST | VMMDEV_EVENT_MOUSE_CAPABILITIES_CHANGED, 1000 /*ms*/, &fEvents);
|
---|
[8887] | 939 |
|
---|
[68437] | 940 | if (*pfShutdown)
|
---|
| 941 | {
|
---|
| 942 | rc = VINF_SUCCESS;
|
---|
| 943 | break;
|
---|
| 944 | }
|
---|
[8887] | 945 |
|
---|
[68437] | 946 | if (RT_SUCCESS(rc))
|
---|
| 947 | {
|
---|
| 948 | if (fEvents & VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
|
---|
[73724] | 949 | DisplayChangeRequestHandler(pCtx);
|
---|
[8387] | 950 |
|
---|
[68437] | 951 | if (fEvents & VMMDEV_EVENT_MOUSE_CAPABILITIES_CHANGED)
|
---|
[34025] | 952 | hlpReloadCursor();
|
---|
[48070] | 953 | }
|
---|
| 954 | else
|
---|
[8387] | 955 | {
|
---|
[62865] | 956 | // Checking once a second whether or not WM_DISPLAYCHANGED happened.
|
---|
| 957 | if (ASMAtomicXchgU32(&g_fGuestDisplaysChanged, 0))
|
---|
| 958 | {
|
---|
| 959 | // XPDM driver has VBoxDispDrvNotify to receive such a notifications
|
---|
| 960 | if (pCtx->pEnv->dispIf.enmMode >= VBOXDISPIF_MODE_WDDM)
|
---|
| 961 | {
|
---|
| 962 | VBOXDISPIFESCAPE EscapeHdr = { 0 };
|
---|
| 963 | EscapeHdr.escapeCode = VBOXESC_GUEST_DISPLAYCHANGED;
|
---|
| 964 |
|
---|
| 965 | DWORD err = VBoxDispIfEscapeInOut(&pCtx->pEnv->dispIf, &EscapeHdr, 0);
|
---|
[63100] | 966 | LogFlowFunc(("VBoxDispIfEscapeInOut returned %d\n", err)); NOREF(err);
|
---|
[62865] | 967 | }
|
---|
| 968 | }
|
---|
[68437] | 969 |
|
---|
[8387] | 970 | /* sleep a bit to not eat too much CPU in case the above call always fails */
|
---|
[68437] | 971 | if (rc != VERR_TIMEOUT)
|
---|
| 972 | RTThreadSleep(10);
|
---|
[8387] | 973 | }
|
---|
[57741] | 974 | }
|
---|
[8387] | 975 |
|
---|
[32687] | 976 | /*
|
---|
| 977 | * Remove event filter and graphics capability report.
|
---|
| 978 | */
|
---|
[68437] | 979 | int rc2 = VbglR3CtlFilterMask(0 /*fOr*/, VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST | VMMDEV_EVENT_MOUSE_CAPABILITIES_CHANGED /*fNot*/);
|
---|
| 980 | if (RT_FAILURE(rc2))
|
---|
| 981 | LogFlowFunc(("VbglR3CtlFilterMask failed: %Rrc\n", rc2));
|
---|
[57741] | 982 | PostMessage(g_hwndToolWindow, WM_VBOX_GRAPHICS_UNSUPPORTED, 0, 0);
|
---|
[8387] | 983 |
|
---|
[57741] | 984 | LogFlowFuncLeaveRC(rc);
|
---|
| 985 | return rc;
|
---|
[8387] | 986 | }
|
---|
[57741] | 987 |
|
---|
| 988 | /**
|
---|
| 989 | * The service description.
|
---|
| 990 | */
|
---|
| 991 | VBOXSERVICEDESC g_SvcDescDisplay =
|
---|
| 992 | {
|
---|
| 993 | /* pszName. */
|
---|
| 994 | "display",
|
---|
| 995 | /* pszDescription. */
|
---|
| 996 | "Display Notifications",
|
---|
| 997 | /* methods */
|
---|
| 998 | VBoxDisplayInit,
|
---|
| 999 | VBoxDisplayWorker,
|
---|
| 1000 | NULL /* pfnStop */,
|
---|
| 1001 | VBoxDisplayDestroy
|
---|
| 1002 | };
|
---|
| 1003 |
|
---|