VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxDisplay.cpp@ 63103

Last change on this file since 63103 was 63100, checked in by vboxsync, 8 years ago

GA/NT/VBoxTray: warnings

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette