VirtualBox

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

Last change on this file since 53315 was 53313, checked in by vboxsync, 10 years ago

VBoxTray: keep monitor layout when resizing with WDDM driver, logging.

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