VirtualBox

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

Last change on this file since 58049 was 57741, checked in by vboxsync, 9 years ago

Additions/VBoxTray:

  • Refactored internal services to use the RTThread API.
  • First take on cleaning up VBoxTray, separating the services more and more. See @todos.
  • Updated some code areas where deprecated APIs were used.
  • A lot of log formatting fixes and renaming.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 44.5 KB
Line 
1/* $Id: VBoxDisplay.cpp 57741 2015-09-14 15:24:42Z vboxsync $ */
2/** @file
3 * VBoxSeamless - Display notifications.
4 */
5
6/*
7 * Copyright (C) 2006-2015 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 <VBoxGuestInternal.h>
37#include <VBoxHook.h>
38
39
40
41typedef struct _VBOXDISPLAYCONTEXT
42{
43 const VBOXSERVICEENV *pEnv;
44 BOOL fAnyX;
45 /** ChangeDisplaySettingsEx does not exist in NT. ResizeDisplayDevice uses the function. */
46 LONG (WINAPI * pfnChangeDisplaySettingsEx)(LPCTSTR lpszDeviceName, LPDEVMODE lpDevMode, HWND hwnd, DWORD dwflags, LPVOID lParam);
47 /** EnumDisplayDevices does not exist in NT. isVBoxDisplayDriverActive et al. are using these functions. */
48 BOOL (WINAPI * pfnEnumDisplayDevices)(IN LPCSTR lpDevice, IN DWORD iDevNum, OUT PDISPLAY_DEVICEA lpDisplayDevice, IN DWORD dwFlags);
49 /** Display driver interface, XPDM - WDDM abstraction see VBOXDISPIF** definitions above */
50 VBOXDISPIF dispIf;
51} VBOXDISPLAYCONTEXT, *PVBOXDISPLAYCONTEXT;
52
53static VBOXDISPLAYCONTEXT g_Ctx = { 0 };
54
55#ifdef VBOX_WITH_WDDM
56typedef enum
57{
58 VBOXDISPLAY_DRIVER_TYPE_UNKNOWN = 0,
59 VBOXDISPLAY_DRIVER_TYPE_XPDM = 1,
60 VBOXDISPLAY_DRIVER_TYPE_WDDM = 2
61} VBOXDISPLAY_DRIVER_TYPE;
62
63static VBOXDISPLAY_DRIVER_TYPE getVBoxDisplayDriverType (VBOXDISPLAYCONTEXT *pCtx);
64#endif
65
66static DECLCALLBACK(int) VBoxDisplayInit(const PVBOXSERVICEENV pEnv, void **ppInstance)
67{
68 LogFlowFuncEnter();
69
70 PVBOXDISPLAYCONTEXT pCtx = &g_Ctx; /** @todo r=andy Use instance data via service lookup (add void *pInstance). */
71 AssertPtr(pCtx);
72
73 OSVERSIONINFO OSinfo; /** @todo r=andy Use VBoxTray's g_dwMajorVersion? */
74 OSinfo.dwOSVersionInfoSize = sizeof(OSinfo);
75 GetVersionEx (&OSinfo);
76
77 int rc;
78 HMODULE hUser = GetModuleHandle("user32.dll"); /** @todo r=andy Use RTLdrXXX and friends. */
79
80 pCtx->pEnv = pEnv;
81
82 if (NULL == hUser)
83 {
84 LogFlowFunc(("Could not get module handle of USER32.DLL!\n"));
85 rc = VERR_NOT_IMPLEMENTED;
86 }
87 else if (OSinfo.dwMajorVersion >= 5) /* APIs available only on W2K and up. */
88 {
89 /** @todo r=andy Use RTLdrXXX and friends. */
90 /** @todo r=andy No unicode version available? */
91 *(uintptr_t *)&pCtx->pfnChangeDisplaySettingsEx = (uintptr_t)GetProcAddress(hUser, "ChangeDisplaySettingsExA");
92 LogFlowFunc(("pfnChangeDisplaySettingsEx = %p\n", pCtx->pfnChangeDisplaySettingsEx));
93
94 *(uintptr_t *)&pCtx->pfnEnumDisplayDevices = (uintptr_t)GetProcAddress(hUser, "EnumDisplayDevicesA");
95 LogFlowFunc(("pfnEnumDisplayDevices = %p\n", pCtx->pfnEnumDisplayDevices));
96
97#ifdef VBOX_WITH_WDDM
98 if (OSinfo.dwMajorVersion >= 6)
99 {
100 /* This is Vista and up, check if we need to switch the display driver if to WDDM mode. */
101 LogFlowFunc(("this is Windows Vista and up\n"));
102 VBOXDISPLAY_DRIVER_TYPE enmType = getVBoxDisplayDriverType(pCtx);
103 if (enmType == VBOXDISPLAY_DRIVER_TYPE_WDDM)
104 {
105 LogFlowFunc(("WDDM driver is installed, switching display driver if to WDDM mode\n"));
106 /* This is hacky, but the most easiest way. */
107 VBOXDISPIF_MODE enmMode = (OSinfo.dwMajorVersion > 6 || OSinfo.dwMinorVersion > 0) ? VBOXDISPIF_MODE_WDDM_W7 : VBOXDISPIF_MODE_WDDM;
108 DWORD dwErr = VBoxDispIfSwitchMode(const_cast<PVBOXDISPIF>(&pEnv->dispIf), enmMode, NULL /* old mode, we don't care about it */);
109 if (dwErr == NO_ERROR)
110 {
111 LogFlowFunc(("DispIf successfully switched to WDDM mode\n"));
112 rc = VINF_SUCCESS;
113 }
114 else
115 {
116 LogFlowFunc(("Failed to switch DispIf to WDDM mode, error (%d)\n", dwErr));
117 rc = RTErrConvertFromWin32(dwErr);
118 }
119 }
120 else
121 rc = VINF_SUCCESS;
122 }
123 else
124 rc = VINF_SUCCESS;
125#endif
126 }
127 else if (OSinfo.dwMajorVersion <= 4) /* Windows NT 4.0. */
128 {
129 /* Nothing to do here yet. */
130 /** @todo r=andy Has this been tested? */
131 rc = VINF_SUCCESS;
132 }
133 else /* Unsupported platform. */
134 {
135 LogFlowFunc(("Warning: Display for platform not handled yet!\n"));
136 rc = VERR_NOT_IMPLEMENTED;
137 }
138
139 if (RT_SUCCESS(rc))
140 {
141 VBOXDISPIFESCAPE_ISANYX IsAnyX = { 0 };
142 IsAnyX.EscapeHdr.escapeCode = VBOXESC_ISANYX;
143 DWORD err = VBoxDispIfEscapeInOut(&pEnv->dispIf, &IsAnyX.EscapeHdr, sizeof(uint32_t));
144 if (err == NO_ERROR)
145 pCtx->fAnyX = !!IsAnyX.u32IsAnyX;
146 else
147 pCtx->fAnyX = TRUE;
148
149 *ppInstance = pCtx;
150 }
151
152 LogFlowFuncLeaveRC(rc);
153 return rc;
154}
155
156static DECLCALLBACK(void) VBoxDisplayDestroy(void *pInstance)
157{
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
464 return NO_ERROR;
465}
466
467/* Returns TRUE to try again. */
468/** @todo r=andy Why not using the VMMDevDisplayChangeRequestEx structure for all those parameters here? */
469static BOOL ResizeDisplayDevice(PVBOXDISPLAYCONTEXT pCtx,
470 UINT Id, DWORD Width, DWORD Height, DWORD BitsPerPixel,
471 BOOL fEnabled, LONG dwNewPosX, LONG dwNewPosY, bool fChangeOrigin,
472 BOOL fExtDispSup)
473{
474 BOOL fDispAlreadyEnabled = false; /* check whether the monitor with ID is already enabled. */
475 BOOL fModeReset = (Width == 0 && Height == 0 && BitsPerPixel == 0 &&
476 dwNewPosX == 0 && dwNewPosY == 0 && !fChangeOrigin);
477 DWORD dmFields = 0;
478
479 LogFlowFunc(("[%d] %dx%d at %d,%d fChangeOrigin %d fEnabled %d fExtDisSup %d\n",
480 Id, Width, Height, dwNewPosX, dwNewPosY, fChangeOrigin, fEnabled, fExtDispSup));
481
482 if (!pCtx->fAnyX)
483 Width &= 0xFFF8;
484
485 VBoxDispIfCancelPendingResize(&pCtx->pEnv->dispIf);
486
487 DWORD NumDevices = VBoxDisplayGetCount();
488
489 if (NumDevices == 0 || Id >= NumDevices)
490 {
491 LogFlowFunc(("ResizeDisplayDevice: Requested identifier %d is invalid. err %d\n", Id, GetLastError ()));
492 return FALSE;
493 }
494
495 LogFlowFunc(("ResizeDisplayDevice: Found total %d devices. err %d\n", NumDevices, GetLastError ()));
496
497 DISPLAY_DEVICE *paDisplayDevices = (DISPLAY_DEVICE *)alloca (sizeof (DISPLAY_DEVICE) * NumDevices);
498 DEVMODE *paDeviceModes = (DEVMODE *)alloca (sizeof (DEVMODE) * NumDevices);
499 RECTL *paRects = (RECTL *)alloca (sizeof (RECTL) * NumDevices);
500 DWORD DevNum = 0;
501 DWORD DevPrimaryNum = 0;
502 DWORD dwStatus = VBoxDisplayGetConfig(NumDevices, &DevPrimaryNum, &DevNum, paDisplayDevices, paDeviceModes);
503 if (dwStatus != NO_ERROR)
504 {
505 LogFlowFunc(("ResizeDisplayDevice: VBoxGetDisplayConfig failed, %d\n", dwStatus));
506 return dwStatus;
507 }
508
509 if (NumDevices != DevNum)
510 LogFlowFunc(("ResizeDisplayDevice: NumDevices(%d) != DevNum(%d)\n", NumDevices, DevNum));
511
512 DWORD i = 0;
513
514 for (i = 0; i < DevNum; ++i)
515 {
516 if (fExtDispSup)
517 {
518 LogRel(("Extended Display Support.\n"));
519 LogFlowFunc(("[%d] %dx%dx%d at %d,%d, dmFields 0x%x\n",
520 i,
521 paDeviceModes[i].dmPelsWidth,
522 paDeviceModes[i].dmPelsHeight,
523 paDeviceModes[i].dmBitsPerPel,
524 paDeviceModes[i].dmPosition.x,
525 paDeviceModes[i].dmPosition.y,
526 paDeviceModes[i].dmFields));
527 }
528 else
529 {
530 LogRel(("NO Ext Display Support \n"));
531 }
532
533 paRects[i].left = paDeviceModes[i].dmPosition.x;
534 paRects[i].top = paDeviceModes[i].dmPosition.y;
535 paRects[i].right = paDeviceModes[i].dmPosition.x + paDeviceModes[i].dmPelsWidth;
536 paRects[i].bottom = paDeviceModes[i].dmPosition.y + paDeviceModes[i].dmPelsHeight;
537 }
538
539 /* Keep a record if the display with ID is already active or not. */
540 if (paDisplayDevices[Id].StateFlags & DISPLAY_DEVICE_ACTIVE)
541 {
542 LogRel(("Display with ID=%d already enabled\n", Id));
543 fDispAlreadyEnabled = TRUE;
544 }
545
546 /* Width, height equal to 0 means that this value must be not changed.
547 * Update input parameters if necessary.
548 * Note: BitsPerPixel is taken into account later, when new rectangles
549 * are assigned to displays.
550 */
551 if (Width == 0)
552 Width = paRects[Id].right - paRects[Id].left;
553 else
554 dmFields |= DM_PELSWIDTH;
555
556 if (Height == 0)
557 Height = paRects[Id].bottom - paRects[Id].top;
558 else
559 dmFields |= DM_PELSHEIGHT;
560
561 if (BitsPerPixel == 0)
562 BitsPerPixel = paDeviceModes[Id].dmBitsPerPel;
563 else
564 dmFields |= DM_BITSPERPEL;
565
566 if (!fChangeOrigin)
567 {
568 /* Use existing position. */
569 dwNewPosX = paRects[Id].left;
570 dwNewPosY = paRects[Id].top;
571 LogFlowFunc(("existing dwNewPosX %d, dwNewPosY %d\n", dwNewPosX, dwNewPosY));
572 }
573
574 /* Always update the position.
575 * It is either explicitly requested or must be set to the existing position.
576 */
577 dmFields |= DM_POSITION;
578
579 /* Check whether a mode reset or a change is requested.
580 * Rectangle position is recalculated only if fEnabled is 1.
581 * For non extended supported modes (old Host VMs), fEnabled
582 * is always 1.
583 */
584 /* Handled the case where previouseresolution of secondary monitor
585 * was for eg. 1024*768*32 and monitor was in disabled state.
586 * User gives the command
587 * setvideomode 1024 768 32 1 yes.
588 * Now in this case the resolution request is same as previous one but
589 * monitor is going from disabled to enabled state so the below condition
590 * shour return false
591 * The below condition will only return true , if no mode reset has
592 * been requested AND fEnabled is 1 and fDispAlreadyEnabled is also 1 AND
593 * all rect conditions are true. Thus in this case nothing has to be done.
594 */
595 if ( !fModeReset && (!fEnabled == !fDispAlreadyEnabled)
596 && paRects[Id].left == dwNewPosX
597 && paRects[Id].top == dwNewPosY
598 && paRects[Id].right - paRects[Id].left == Width
599 && paRects[Id].bottom - paRects[Id].top == Height
600 && paDeviceModes[Id].dmBitsPerPel == BitsPerPixel)
601 {
602 LogRel(("Already at desired resolution. No Change.\n"));
603 return FALSE;
604 }
605
606 hlpResizeRect(paRects, NumDevices, DevPrimaryNum, Id,
607 fEnabled ? Width : 0, fEnabled ? Height : 0, dwNewPosX, dwNewPosY);
608#ifdef Log
609 for (i = 0; i < NumDevices; i++)
610 {
611 LogFlowFunc(("ResizeDisplayDevice: [%d]: %d,%d %dx%d\n",
612 i, paRects[i].left, paRects[i].top,
613 paRects[i].right - paRects[i].left,
614 paRects[i].bottom - paRects[i].top));
615 }
616#endif /* Log */
617
618#ifdef VBOX_WITH_WDDM
619 VBOXDISPLAY_DRIVER_TYPE enmDriverType = getVBoxDisplayDriverType (pCtx);
620 if (enmDriverType == VBOXDISPLAY_DRIVER_TYPE_WDDM)
621 {
622 /* Assign the new rectangles to displays. */
623 for (i = 0; i < NumDevices; i++)
624 {
625 paDeviceModes[i].dmPosition.x = paRects[i].left;
626 paDeviceModes[i].dmPosition.y = paRects[i].top;
627 paDeviceModes[i].dmPelsWidth = paRects[i].right - paRects[i].left;
628 paDeviceModes[i].dmPelsHeight = paRects[i].bottom - paRects[i].top;
629
630 if (i == Id)
631 paDeviceModes[i].dmBitsPerPel = BitsPerPixel;
632
633 paDeviceModes[i].dmFields |= dmFields;
634
635 /* On Vista one must specify DM_BITSPERPEL.
636 * Note that the current mode dmBitsPerPel is already in the DEVMODE structure.
637 */
638 if (!(paDeviceModes[i].dmFields & DM_BITSPERPEL))
639 {
640 LogFlowFunc(("no DM_BITSPERPEL\n"));
641 paDeviceModes[i].dmFields |= DM_BITSPERPEL;
642 paDeviceModes[i].dmBitsPerPel = 32;
643 }
644
645 LogFlowFunc(("ResizeDisplayDevice: pfnChangeDisplaySettingsEx %x: %dx%dx%d at %d,%d fields 0x%X\n",
646 pCtx->pfnChangeDisplaySettingsEx,
647 paDeviceModes[i].dmPelsWidth,
648 paDeviceModes[i].dmPelsHeight,
649 paDeviceModes[i].dmBitsPerPel,
650 paDeviceModes[i].dmPosition.x,
651 paDeviceModes[i].dmPosition.y,
652 paDeviceModes[i].dmFields));
653 }
654
655 LogFlowFunc(("Request to resize the displa\n"));
656 DWORD err = VBoxDispIfResizeModes(&pCtx->pEnv->dispIf, Id, fEnabled, fExtDispSup, paDisplayDevices, paDeviceModes, DevNum);
657 if (err == NO_ERROR || err != ERROR_RETRY)
658 {
659 if (err == NO_ERROR)
660 LogFlowFunc(("VBoxDispIfResizeModes succeeded\n"));
661 else
662 LogFlowFunc(("Failure VBoxDispIfResizeModes (%d)\n", err));
663 return FALSE;
664 }
665
666 LogFlowFunc(("ResizeDisplayDevice: RETRY requested\n"));
667 return TRUE;
668 }
669#endif
670 /* Without this, Windows will not ask the miniport for its
671 * mode table but uses an internal cache instead.
672 */
673 for (i = 0; i < NumDevices; i++)
674 {
675 DEVMODE tempDevMode;
676 ZeroMemory (&tempDevMode, sizeof (tempDevMode));
677 tempDevMode.dmSize = sizeof(DEVMODE);
678 EnumDisplaySettings((LPSTR)paDisplayDevices[i].DeviceName, 0xffffff, &tempDevMode);
679 LogFlowFunc(("ResizeDisplayDevice: EnumDisplaySettings last error %d\n", GetLastError ()));
680 }
681
682 /* Assign the new rectangles to displays. */
683 for (i = 0; i < NumDevices; i++)
684 {
685 paDeviceModes[i].dmPosition.x = paRects[i].left;
686 paDeviceModes[i].dmPosition.y = paRects[i].top;
687 paDeviceModes[i].dmPelsWidth = paRects[i].right - paRects[i].left;
688 paDeviceModes[i].dmPelsHeight = paRects[i].bottom - paRects[i].top;
689
690 /* On Vista one must specify DM_BITSPERPEL.
691 * Note that the current mode dmBitsPerPel is already in the DEVMODE structure.
692 */
693 paDeviceModes[i].dmFields = DM_POSITION | DM_PELSHEIGHT | DM_PELSWIDTH | DM_BITSPERPEL;
694
695 if ( i == Id
696 && BitsPerPixel != 0)
697 {
698 /* Change dmBitsPerPel if requested. */
699 paDeviceModes[i].dmBitsPerPel = BitsPerPixel;
700 }
701
702 LogFlowFunc(("ResizeDisplayDevice: pfnChangeDisplaySettingsEx Current MonitorId=%d: %dx%dx%d at %d,%d\n",
703 i,
704 paDeviceModes[i].dmPelsWidth,
705 paDeviceModes[i].dmPelsHeight,
706 paDeviceModes[i].dmBitsPerPel,
707 paDeviceModes[i].dmPosition.x,
708 paDeviceModes[i].dmPosition.y));
709
710 LONG status = pCtx->pfnChangeDisplaySettingsEx((LPSTR)paDisplayDevices[i].DeviceName,
711 &paDeviceModes[i], NULL, CDS_NORESET | CDS_UPDATEREGISTRY, NULL);
712 LogFlowFunc(("ResizeDisplayDevice: ChangeDisplaySettingsEx position status %d, err %d\n", status, GetLastError ()));
713 }
714
715 LogFlowFunc(("Enable And Resize Device. Id = %d, Width=%d Height=%d, \
716 dwNewPosX = %d, dwNewPosY = %d fEnabled=%d & fExtDispSupport = %d \n",
717 Id, Width, Height, dwNewPosX, dwNewPosY, fEnabled, fExtDispSup));
718 dwStatus = EnableAndResizeDispDev(paDeviceModes, paDisplayDevices, DevNum, Id, Width, Height, BitsPerPixel,
719 dwNewPosX, dwNewPosY, fEnabled, fExtDispSup);
720 if (dwStatus == DISP_CHANGE_SUCCESSFUL || dwStatus == DISP_CHANGE_BADMODE)
721 {
722 /* Successfully set new video mode or our driver can not set
723 * the requested mode. Stop trying.
724 */
725 return FALSE;
726 }
727 /* Retry the request. */
728 return TRUE;
729}
730
731/**
732 * Thread function to wait for and process display change
733 * requests
734 */
735DECLCALLBACK(int) VBoxDisplayWorker(void *pInstance, bool volatile *pfShutdown)
736{
737 AssertPtr(pInstance);
738 LogFlowFunc(("pInstance=%p\n", pInstance));
739
740 /*
741 * Tell the control thread that it can continue
742 * spawning services.
743 */
744 RTThreadUserSignal(RTThreadSelf());
745
746 PVBOXDISPLAYCONTEXT pCtx = (PVBOXDISPLAYCONTEXT)pInstance;
747
748 HANDLE gVBoxDriver = pCtx->pEnv->hDriver;
749 VBoxGuestFilterMaskInfo maskInfo;
750 DWORD cbReturned;
751
752 maskInfo.u32OrMask = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST | VMMDEV_EVENT_MOUSE_CAPABILITIES_CHANGED;
753 maskInfo.u32NotMask = 0;
754 if (!DeviceIoControl(gVBoxDriver, VBOXGUEST_IOCTL_CTL_FILTER_MASK, &maskInfo, sizeof (maskInfo), NULL, 0, &cbReturned, NULL))
755 {
756 DWORD dwErr = GetLastError();
757 LogFlowFunc(("DeviceIOControl(CtlMask - or) failed with %ld, exiting\n", dwErr));
758 return RTErrConvertFromWin32(dwErr);
759 }
760
761 PostMessage(g_hwndToolWindow, WM_VBOX_GRAPHICS_SUPPORTED, 0, 0);
762
763 VBoxDispIfResizeStarted(&pCtx->pEnv->dispIf);
764
765 int rc = VINF_SUCCESS;
766
767 for (;;)
768 {
769 BOOL fExtDispSup = TRUE;
770 /* Wait for a display change event. */
771 VBoxGuestWaitEventInfo waitEvent;
772 waitEvent.u32TimeoutIn = 1000;
773 waitEvent.u32EventMaskIn = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST | VMMDEV_EVENT_MOUSE_CAPABILITIES_CHANGED;
774 if (DeviceIoControl(gVBoxDriver, VBOXGUEST_IOCTL_WAITEVENT, &waitEvent, sizeof(waitEvent), &waitEvent, sizeof(waitEvent), &cbReturned, NULL))
775 {
776 /*LogFlowFunc(("DeviceIOControl succeeded\n"));*/
777
778 if (NULL == pCtx) {
779 LogFlowFunc(("Invalid context detected!\n"));
780 break;
781 }
782
783 if (NULL == pCtx->pEnv) {
784 LogFlowFunc(("Invalid context environment detected!\n"));
785 break;
786 }
787
788 /* are we supposed to stop? */
789 if (*pfShutdown)
790 break;
791
792 /*LogFlowFunc(("checking event\n"));*/
793
794 /* did we get the right event? */
795 if (waitEvent.u32EventFlagsOut & VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
796 {
797 LogFlowFunc(("going to get display change information\n"));
798 BOOL fDisplayChangeQueried;
799
800
801 /* We got at least one event. Read the requested resolution
802 * and try to set it until success. New events will not be seen
803 * but a new resolution will be read in this poll loop.
804 */
805 /* Try if extended mode display information is available from the host. */
806 VMMDevDisplayChangeRequestEx displayChangeRequest = {0};
807 fExtDispSup = TRUE;
808 displayChangeRequest.header.size = sizeof(VMMDevDisplayChangeRequestEx);
809 displayChangeRequest.header.version = VMMDEV_REQUEST_HEADER_VERSION;
810 displayChangeRequest.header.requestType = VMMDevReq_GetDisplayChangeRequestEx;
811 displayChangeRequest.eventAck = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
812 fDisplayChangeQueried = DeviceIoControl(gVBoxDriver, VBOXGUEST_IOCTL_VMMREQUEST(sizeof(VMMDevDisplayChangeRequestEx)), &displayChangeRequest, sizeof(VMMDevDisplayChangeRequestEx),
813 &displayChangeRequest, sizeof(VMMDevDisplayChangeRequestEx), &cbReturned, NULL);
814
815 if (!fDisplayChangeQueried)
816 {
817 LogFlowFunc(("Extended Display Not Supported. Trying VMMDevDisplayChangeRequest2\n"));
818 fExtDispSup = FALSE; /* Extended display Change request is not supported */
819
820 displayChangeRequest.header.size = sizeof(VMMDevDisplayChangeRequest2);
821 displayChangeRequest.header.version = VMMDEV_REQUEST_HEADER_VERSION;
822 displayChangeRequest.header.requestType = VMMDevReq_GetDisplayChangeRequest2;
823 displayChangeRequest.eventAck = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
824 fDisplayChangeQueried = DeviceIoControl(gVBoxDriver, VBOXGUEST_IOCTL_VMMREQUEST(sizeof(VMMDevDisplayChangeRequest2)), &displayChangeRequest, sizeof(VMMDevDisplayChangeRequest2),
825 &displayChangeRequest, sizeof(VMMDevDisplayChangeRequest2), &cbReturned, NULL);
826 displayChangeRequest.cxOrigin = 0;
827 displayChangeRequest.cyOrigin = 0;
828 displayChangeRequest.fChangeOrigin = 0;
829 displayChangeRequest.fEnabled = 1; /* Always Enabled for old VMs on Host.*/
830 }
831
832 if (!fDisplayChangeQueried)
833 {
834 LogFlowFunc(("Extended Display Not Supported. Trying VMMDevDisplayChangeRequest\n"));
835 fExtDispSup = FALSE; /*Extended display Change request is not supported */
836 /* Try the old version of the request for old VBox hosts. */
837 displayChangeRequest.header.size = sizeof(VMMDevDisplayChangeRequest);
838 displayChangeRequest.header.version = VMMDEV_REQUEST_HEADER_VERSION;
839 displayChangeRequest.header.requestType = VMMDevReq_GetDisplayChangeRequest;
840 displayChangeRequest.eventAck = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
841 fDisplayChangeQueried = DeviceIoControl(gVBoxDriver, VBOXGUEST_IOCTL_VMMREQUEST(sizeof(VMMDevDisplayChangeRequest)), &displayChangeRequest, sizeof(VMMDevDisplayChangeRequest),
842 &displayChangeRequest, sizeof(VMMDevDisplayChangeRequest), &cbReturned, NULL);
843 displayChangeRequest.display = 0;
844 displayChangeRequest.cxOrigin = 0;
845 displayChangeRequest.cyOrigin = 0;
846 displayChangeRequest.fChangeOrigin = 0;
847 displayChangeRequest.fEnabled = 1; /* Always Enabled for old VMs on Host.*/
848 }
849
850 if (fDisplayChangeQueried)
851 {
852 /* Try to set the requested video mode. Repeat until it is successful or is rejected by the driver. */
853 for (;;)
854 {
855 LogFlowFunc(("VMMDevReq_GetDisplayChangeRequest2: %dx%dx%d at %d\n", displayChangeRequest.xres, displayChangeRequest.yres, displayChangeRequest.bpp, displayChangeRequest.display));
856
857 /*
858 * Only try to change video mode if the active display driver is VBox additions.
859 */
860#ifdef VBOX_WITH_WDDM
861 VBOXDISPLAY_DRIVER_TYPE enmDriverType = getVBoxDisplayDriverType (pCtx);
862
863 if (enmDriverType == VBOXDISPLAY_DRIVER_TYPE_WDDM)
864 LogFlowFunc(("Detected WDDM Driver\n"));
865
866 if (enmDriverType != VBOXDISPLAY_DRIVER_TYPE_UNKNOWN)
867#else
868 if (isVBoxDisplayDriverActive (pCtx))
869#endif
870 {
871 LogFlowFunc(("Display driver is active!\n"));
872
873 if (pCtx->pfnChangeDisplaySettingsEx != 0)
874 {
875 LogFlowFunc(("Detected W2K or later\n"));
876 /* W2K or later. */
877 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",
878 displayChangeRequest.display,
879 displayChangeRequest.xres,
880 displayChangeRequest.yres,
881 displayChangeRequest.bpp,
882 displayChangeRequest.fEnabled,
883 displayChangeRequest.cxOrigin,
884 displayChangeRequest.cyOrigin,
885 displayChangeRequest.fChangeOrigin));
886 if (!ResizeDisplayDevice(pCtx,
887 displayChangeRequest.display,
888 displayChangeRequest.xres,
889 displayChangeRequest.yres,
890 displayChangeRequest.bpp,
891 displayChangeRequest.fEnabled,
892 displayChangeRequest.cxOrigin,
893 displayChangeRequest.cyOrigin,
894 displayChangeRequest.fChangeOrigin,
895 fExtDispSup
896 ))
897 {
898 LogFlowFunc(("ResizeDipspalyDevice return 0\n"));
899 break;
900 }
901
902 }
903 else
904 {
905 LogFlowFunc(("Detected NT\n"));
906
907 /* Single monitor NT. */
908 DEVMODE devMode;
909 RT_ZERO(devMode);
910 devMode.dmSize = sizeof(DEVMODE);
911
912 /* get the current screen setup */
913 if (EnumDisplaySettings(NULL, ENUM_REGISTRY_SETTINGS, &devMode))
914 {
915 LogFlowFunc(("Current mode: %d x %d x %d at %d,%d\n",
916 devMode.dmPelsWidth, devMode.dmPelsHeight, devMode.dmBitsPerPel, devMode.dmPosition.x, devMode.dmPosition.y));
917
918 /* Check whether a mode reset or a change is requested. */
919 if (displayChangeRequest.xres || displayChangeRequest.yres || displayChangeRequest.bpp)
920 {
921 /* A change is requested.
922 * Set values which are not to be changed to the current values.
923 */
924 if (!displayChangeRequest.xres)
925 displayChangeRequest.xres = devMode.dmPelsWidth;
926 if (!displayChangeRequest.yres)
927 displayChangeRequest.yres = devMode.dmPelsHeight;
928 if (!displayChangeRequest.bpp)
929 displayChangeRequest.bpp = devMode.dmBitsPerPel;
930 }
931 else
932 {
933 /* All zero values means a forced mode reset. Do nothing. */
934 LogFlowFunc(("Forced mode reset\n"));
935 }
936
937 /* Verify that the mode is indeed changed. */
938 if ( devMode.dmPelsWidth == displayChangeRequest.xres
939 && devMode.dmPelsHeight == displayChangeRequest.yres
940 && devMode.dmBitsPerPel == displayChangeRequest.bpp)
941 {
942 LogFlowFunc(("already at desired resolution\n"));
943 break;
944 }
945
946 // without this, Windows will not ask the miniport for its
947 // mode table but uses an internal cache instead
948 DEVMODE tempDevMode = {0};
949 tempDevMode.dmSize = sizeof(DEVMODE);
950 EnumDisplaySettings(NULL, 0xffffff, &tempDevMode);
951
952 /* adjust the values that are supposed to change */
953 if (displayChangeRequest.xres)
954 devMode.dmPelsWidth = displayChangeRequest.xres;
955 if (displayChangeRequest.yres)
956 devMode.dmPelsHeight = displayChangeRequest.yres;
957 if (displayChangeRequest.bpp)
958 devMode.dmBitsPerPel = displayChangeRequest.bpp;
959
960 LogFlowFunc(("setting new mode %d x %d, %d BPP\n",
961 devMode.dmPelsWidth, devMode.dmPelsHeight, devMode.dmBitsPerPel));
962
963 /* set the new mode */
964 LONG status = ChangeDisplaySettings(&devMode, CDS_UPDATEREGISTRY);
965 if (status != DISP_CHANGE_SUCCESSFUL)
966 {
967 LogFlowFunc(("error from ChangeDisplaySettings: %d\n", status));
968
969 if (status == DISP_CHANGE_BADMODE)
970 {
971 /* Our driver can not set the requested mode. Stop trying. */
972 break;
973 }
974 }
975 else
976 {
977 /* Successfully set new video mode. */
978 break;
979 }
980 }
981 else
982 {
983 LogFlowFunc(("error from EnumDisplaySettings: %d\n", GetLastError ()));
984 break;
985 }
986 }
987 }
988 else
989 {
990 LogFlowFunc(("vboxDisplayDriver is not active\n"));
991 }
992
993 /* Retry the change a bit later. */
994 RTThreadSleep(1000);
995 }
996 }
997 else
998 {
999 /* sleep a bit to not eat too much CPU while retrying */
1000 RTThreadSleep(50);
1001 }
1002 }
1003
1004 /* are we supposed to stop? */
1005 if (*pfShutdown)
1006 break;
1007
1008 if (waitEvent.u32EventFlagsOut & VMMDEV_EVENT_MOUSE_CAPABILITIES_CHANGED)
1009 hlpReloadCursor();
1010 }
1011 else
1012 {
1013 /* sleep a bit to not eat too much CPU in case the above call always fails */
1014 RTThreadSleep(10);
1015
1016 if (*pfShutdown)
1017 break;
1018 }
1019 }
1020
1021 /*
1022 * Remove event filter and graphics capability report.
1023 */
1024 maskInfo.u32OrMask = 0;
1025 maskInfo.u32NotMask = VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST | VMMDEV_EVENT_MOUSE_CAPABILITIES_CHANGED;
1026 if (!DeviceIoControl(gVBoxDriver, VBOXGUEST_IOCTL_CTL_FILTER_MASK, &maskInfo, sizeof (maskInfo), NULL, 0, &cbReturned, NULL))
1027 LogFlowFunc(("DeviceIOControl(CtlMask - not) failed\n"));
1028 PostMessage(g_hwndToolWindow, WM_VBOX_GRAPHICS_UNSUPPORTED, 0, 0);
1029
1030 LogFlowFuncLeaveRC(rc);
1031 return rc;
1032}
1033
1034/**
1035 * The service description.
1036 */
1037VBOXSERVICEDESC g_SvcDescDisplay =
1038{
1039 /* pszName. */
1040 "display",
1041 /* pszDescription. */
1042 "Display Notifications",
1043 /* methods */
1044 VBoxDisplayInit,
1045 VBoxDisplayWorker,
1046 NULL /* pfnStop */,
1047 VBoxDisplayDestroy
1048};
1049
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