VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Miniport/Helper.cpp@ 27239

Last change on this file since 27239 was 27239, checked in by vboxsync, 15 years ago

wddm: VidPn fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.0 KB
Line 
1/** @file
2 *
3 * VBoxGuest -- VirtualBox Win 2000/XP guest video driver
4 *
5 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
6 *
7 * This file is part of VirtualBox Open Source Edition (OSE), as
8 * available from http://www.virtualbox.org. This file is free software;
9 * you can redistribute it and/or modify it under the terms of the GNU
10 * General Public License (GPL) as published by the Free Software
11 * Foundation, in version 2 as it comes in the "COPYING" file of the
12 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
13 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
14 *
15 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
16 * Clara, CA 95054 USA or visit http://www.sun.com if you need
17 * additional information or have any questions.
18 */
19
20// enable backdoor logging
21//#define LOG_ENABLED
22#ifndef VBOXWDDM
23extern "C"
24{
25# include <ntddk.h>
26}
27#else
28# include "VBoxVideo.h"
29#endif
30
31#include <VBox/err.h>
32
33#include <VBox/VBoxGuestLib.h>
34
35#ifndef VBOXWDDM
36/* the video miniport headers not compatible with the NT DDK headers */
37typedef struct _VIDEO_POINTER_ATTRIBUTES
38{
39 ULONG Flags;
40 ULONG Width;
41 ULONG Height;
42 ULONG WidthInBytes;
43 ULONG Enable;
44 SHORT Column;
45 SHORT Row;
46 UCHAR Pixels[1];
47} VIDEO_POINTER_ATTRIBUTES, *PVIDEO_POINTER_ATTRIBUTES;
48#define VIDEO_MODE_COLOR_POINTER 0x04 // 1 if a color hardware pointer is
49 // supported.
50#endif /* #ifndef VBOXWDDM */
51
52#include "Helper.h"
53
54#ifdef DEBUG_misha
55bool g_bVBoxVDbgBreakF = true;
56bool g_bVBoxVDbgBreakFv = false;
57#endif
58
59/**
60 * Globals
61 */
62/* note: should not do that but we can't use these datatypes in the global header */
63
64#pragma alloc_text(PAGE, vboxQueryDisplayRequest)
65#pragma alloc_text(PAGE, vboxLikesVideoMode)
66#pragma alloc_text(PAGE, vboxGetHeightReduction)
67#pragma alloc_text(PAGE, vboxQueryPointerPos)
68#pragma alloc_text(PAGE, vboxQueryHostWantsAbsolute)
69#pragma alloc_text(PAGE, vboxQueryWinVersion)
70
71BOOLEAN vboxQueryDisplayRequest(uint32_t *xres, uint32_t *yres, uint32_t *bpp, uint32_t *pDisplayId)
72{
73 BOOLEAN bRC = FALSE;
74
75 dprintf(("VBoxVideo::vboxQueryDisplayRequest: xres = 0x%p, yres = 0x%p bpp = 0x%p\n", xres, yres, bpp));
76
77 VMMDevDisplayChangeRequest2 *req = NULL;
78
79 int rc = VbglGRAlloc ((VMMDevRequestHeader **)&req, sizeof (VMMDevDisplayChangeRequest2), VMMDevReq_GetDisplayChangeRequest2);
80
81 if (RT_FAILURE(rc))
82 {
83 dprintf(("VBoxVideo::vboxQueryDisplayRequest: ERROR allocating request, rc = %Rrc\n", rc));
84 }
85 else
86 {
87 req->eventAck = 0;
88
89 rc = VbglGRPerform (&req->header);
90
91 if (RT_SUCCESS(rc))
92 {
93 if (xres)
94 *xres = req->xres;
95 if (yres)
96 *yres = req->yres;
97 if (bpp)
98 *bpp = req->bpp;
99 if (pDisplayId)
100 *pDisplayId = req->display;
101 dprintf(("VBoxVideo::vboxQueryDisplayRequest: returning %d x %d @ %d for %d\n",
102 req->xres, req->yres, req->bpp, req->display));
103 bRC = TRUE;
104 }
105 else
106 {
107 dprintf(("VBoxVideo::vboxQueryDisplayRequest: ERROR querying display request from VMMDev. "
108 "rc = %Rrc\n", rc));
109 }
110
111 VbglGRFree (&req->header);
112 }
113
114 return bRC;
115}
116
117BOOLEAN vboxLikesVideoMode(uint32_t width, uint32_t height, uint32_t bpp)
118{
119 BOOLEAN bRC = FALSE;
120
121 VMMDevVideoModeSupportedRequest *req = NULL;
122
123 int rc = VbglGRAlloc((VMMDevRequestHeader**)&req, sizeof(VMMDevVideoModeSupportedRequest), VMMDevReq_VideoModeSupported);
124 if (RT_FAILURE(rc))
125 {
126#ifndef DEBUG_misha
127 dprintf(("VBoxVideo::vboxLikesVideoMode: ERROR allocating request, rc = %Rrc\n", rc));
128#else
129 /* @todo: fixme: remove this ifdef*/
130#endif
131 /* Most likely the VBoxGuest driver is not loaded.
132 * To get at least the video working, report the mode as supported.
133 */
134 bRC = TRUE;
135 }
136 else
137 {
138 req->width = width;
139 req->height = height;
140 req->bpp = bpp;
141 rc = VbglGRPerform(&req->header);
142 if (RT_SUCCESS(rc))
143 {
144 bRC = req->fSupported;
145 }
146 else
147 {
148 dprintf(("VBoxVideo::vboxLikesVideoMode: ERROR querying video mode supported status from VMMDev."
149 "rc = %Rrc\n", rc));
150 }
151 VbglGRFree(&req->header);
152 }
153#ifndef DEBUG_misha
154 dprintf(("VBoxVideo::vboxLikesVideoMode: width: %d, height: %d, bpp: %d -> %s\n", width, height, bpp, (bRC == 1) ? "OK" : "FALSE"));
155#else
156 /* @todo: fixme: remove this ifdef*/
157#endif
158
159 return bRC;
160}
161
162ULONG vboxGetHeightReduction()
163{
164 ULONG retHeight = 0;
165
166#ifndef DEBUG_misha
167 dprintf(("VBoxVideo::vboxGetHeightReduction\n"));
168#endif
169
170 VMMDevGetHeightReductionRequest *req = NULL;
171
172 int rc = VbglGRAlloc((VMMDevRequestHeader**)&req, sizeof(VMMDevGetHeightReductionRequest), VMMDevReq_GetHeightReduction);
173 if (RT_FAILURE(rc))
174 {
175#ifndef DEBUG_misha
176 dprintf(("VBoxVideo::vboxGetHeightReduction: ERROR allocating request, rc = %Rrc\n", rc));
177#endif
178 }
179 else
180 {
181 rc = VbglGRPerform(&req->header);
182 if (RT_SUCCESS(rc))
183 {
184 retHeight = (ULONG)req->heightReduction;
185 }
186 else
187 {
188 dprintf(("VBoxVideo::vboxGetHeightReduction: ERROR querying height reduction value from VMMDev. "
189 "rc = %Rrc\n", rc));
190 }
191 VbglGRFree(&req->header);
192 }
193
194 dprintf(("VBoxVideoMode::vboxGetHeightReduction: returning %d\n", retHeight));
195 return retHeight;
196}
197
198static BOOLEAN vboxQueryPointerPosInternal (uint16_t *pointerXPos, uint16_t *pointerYPos)
199{
200 BOOLEAN bRC = FALSE;
201
202 /* Activate next line only when really needed; floods the log very quickly! */
203 /*dprintf(("VBoxVideo::vboxQueryPointerPosInternal: pointerXPos = %p, pointerYPos = %p\n", pointerXPos, pointerYPos));*/
204
205 VMMDevReqMouseStatus *req = NULL;
206
207 int rc = VbglGRAlloc ((VMMDevRequestHeader **)&req, sizeof (VMMDevReqMouseStatus), VMMDevReq_GetMouseStatus);
208
209 if (RT_FAILURE(rc))
210 {
211 dprintf(("VBoxVideo::vboxQueryPointerPosInternal: ERROR allocating request, rc = %Rrc\n", rc));
212 }
213 else
214 {
215 rc = VbglGRPerform (&req->header);
216
217 if (RT_SUCCESS(rc))
218 {
219 if (req->mouseFeatures & VMMDEV_MOUSE_HOST_CAN_ABSOLUTE)
220 {
221 if (pointerXPos)
222 {
223 *pointerXPos = req->pointerXPos;
224 }
225
226 if (pointerYPos)
227 {
228 *pointerYPos = req->pointerYPos;
229 }
230
231 bRC = TRUE;
232 }
233 }
234 else
235 {
236 dprintf(("VBoxVideo::vboxQueryPointerPosInternal: ERROR querying mouse capabilities from VMMDev. "
237 "rc = %Rrc\n", rc));
238 }
239
240 VbglGRFree (&req->header);
241 }
242
243 return bRC;
244}
245
246/**
247 * Return the current absolute mouse position in normalized format
248 * (between 0 and 0xFFFF).
249 *
250 * @returns BOOLEAN success indicator
251 * @param pointerXPos address of result variable for x pos
252 * @param pointerYPos address of result variable for y pos
253 */
254BOOLEAN vboxQueryPointerPos(uint16_t *pointerXPos, uint16_t *pointerYPos)
255{
256 if (!pointerXPos || !pointerYPos)
257 {
258 return FALSE;
259 }
260
261 return vboxQueryPointerPosInternal (pointerXPos, pointerYPos);
262}
263
264/**
265 * Returns whether the host wants us to take absolute coordinates.
266 *
267 * @returns BOOLEAN TRUE if the host wants to send absolute coordinates.
268 */
269BOOLEAN vboxQueryHostWantsAbsolute (void)
270{
271 return vboxQueryPointerPosInternal (NULL, NULL);
272}
273
274winVersion_t vboxQueryWinVersion()
275{
276 static winVersion_t winVersion = UNKNOWN_WINVERSION;
277 ULONG majorVersion;
278 ULONG minorVersion;
279 ULONG buildNumber;
280
281 if (winVersion != UNKNOWN_WINVERSION)
282 return winVersion;
283
284 PsGetVersion(&majorVersion, &minorVersion, &buildNumber, NULL);
285
286 dprintf(("VBoxVideo::vboxQueryWinVersion: running on Windows NT version %d.%d, build %d\n",
287 majorVersion, minorVersion, buildNumber));
288 if(majorVersion == 6)
289 {
290 if (minorVersion == 1)
291 winVersion = WIN7;
292 else if (minorVersion == 0)
293 winVersion = WINVISTA; /* Or Windows Server 2008. */
294 }
295 else if (majorVersion == 5)
296 {
297 if (minorVersion >= 1)
298 {
299 winVersion = WINXP;
300 } else
301 {
302 winVersion = WIN2K;
303 }
304 }
305 else if (majorVersion == 4)
306 {
307 winVersion = WINNT4;
308 }
309 else
310 {
311 dprintf(("VBoxVideo::vboxQueryWinVersion: NT4 required!\n"));
312 }
313 return winVersion;
314}
315
316#ifndef VBOX_WITH_HGSMI
317/**
318 * Sends the pointer shape to the VMMDev
319 *
320 * @returns success indicator
321 * @param pointerAttr pointer description
322 */
323BOOLEAN vboxUpdatePointerShape(PVIDEO_POINTER_ATTRIBUTES pointerAttr, uint32_t cbLength)
324{
325 uint32_t cbData = 0;
326
327 if (pointerAttr->Enable & VBOX_MOUSE_POINTER_SHAPE)
328 {
329 cbData = ((((pointerAttr->Width + 7) / 8) * pointerAttr->Height + 3) & ~3)
330 + pointerAttr->Width * 4 * pointerAttr->Height;
331 }
332
333 if (cbData > cbLength - sizeof(VIDEO_POINTER_ATTRIBUTES))
334 {
335 dprintf(("vboxUpdatePointerShape: calculated pointer data size is too big (%d bytes, limit %d)\n",
336 cbData, cbLength - sizeof(VIDEO_POINTER_ATTRIBUTES)));
337 return FALSE;
338 }
339
340 BOOLEAN bRC = FALSE;
341
342 VMMDevReqMousePointer *req = NULL;
343
344 int rc = VbglGRAlloc ((VMMDevRequestHeader **)&req, sizeof (VMMDevReqMousePointer) + cbData, VMMDevReq_SetPointerShape);
345
346 if (RT_FAILURE(rc))
347 {
348 dprintf(("VBoxVideo::vboxUpdatePointerShape: ERROR allocating request, rc = %Rrc\n", rc));
349 }
350 else
351 {
352 /* Activate next line only when really needed; floods the log very quickly! */
353 /*dprintf(("VBoxVideo::vboxUpdatePointerShape: req->u32Version = %08X\n", req->header.version));*/
354
355 /* We have our custom flags in the field */
356 req->fFlags = pointerAttr->Enable & 0xFFFF;
357
358 /* Even if pointer is invisible, we have to pass following data,
359 * so host could create the pointer with initial status - invisible
360 */
361 req->xHot = (pointerAttr->Enable >> 16) & 0xFF;
362 req->yHot = (pointerAttr->Enable >> 24) & 0xFF;
363 req->width = pointerAttr->Width;
364 req->height = pointerAttr->Height;
365
366 if (req->fFlags & VBOX_MOUSE_POINTER_SHAPE)
367 {
368 /* copy the actual pointer data */
369 memcpy (req->pointerData, pointerAttr->Pixels, cbData);
370 }
371
372 rc = VbglGRPerform (&req->header);
373
374 if (RT_SUCCESS(rc) && RT_SUCCESS(req->header.rc))
375 {
376 bRC = TRUE;
377 }
378 else
379 {
380 dprintf(("VBoxVideo::vboxUpdatePointerShape: ERROR querying mouse capabilities from VMMDev. "
381 "rc = %Rrc\n", rc));
382 }
383
384 dprintf(("VBoxVideo::vboxUpdatePointerShape: req->u32Version = %08X\n", req->header.version));
385
386 VbglGRFree (&req->header);
387 }
388
389 return bRC;
390}
391#endif /* VBOX_WITH_HGSMI */
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