VirtualBox

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

Last change on this file since 45761 was 45761, checked in by vboxsync, 12 years ago

VBoxTray: missing file commit

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