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