VirtualBox

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

Last change on this file since 12738 was 12738, checked in by vboxsync, 16 years ago

Windows Guest Additions Video Miniport: Be more quiet when debugging.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.6 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
23extern "C"
24{
25#include <ntddk.h>
26}
27
28#include <VBox/err.h>
29
30#include <VBox/VBoxGuestLib.h>
31
32/* the video miniport headers not compatible with the NT DDK headers */
33typedef struct _VIDEO_POINTER_ATTRIBUTES
34{
35 ULONG Flags;
36 ULONG Width;
37 ULONG Height;
38 ULONG WidthInBytes;
39 ULONG Enable;
40 SHORT Column;
41 SHORT Row;
42 UCHAR Pixels[1];
43} VIDEO_POINTER_ATTRIBUTES, *PVIDEO_POINTER_ATTRIBUTES;
44#define VIDEO_MODE_COLOR_POINTER 0x04 // 1 if a color hardware pointer is
45 // supported.
46
47#include "Helper.h"
48
49/**
50 * Globals
51 */
52/* note: should not do that but we can't use these datatypes in the global header */
53
54#pragma alloc_text(PAGE, vboxQueryDisplayRequest)
55#pragma alloc_text(PAGE, vboxLikesVideoMode)
56#pragma alloc_text(PAGE, vboxGetHeightReduction)
57#pragma alloc_text(PAGE, vboxQueryPointerPos)
58#pragma alloc_text(PAGE, vboxQueryHostWantsAbsolute)
59#pragma alloc_text(PAGE, vboxQueryWinVersion)
60
61BOOLEAN vboxQueryDisplayRequest(uint32_t *xres, uint32_t *yres, uint32_t *bpp)
62{
63 BOOLEAN bRC = FALSE;
64
65 dprintf(("VBoxVideo::vboxQueryDisplayRequest: xres = %p, yres = %p bpp = %p\n", xres, yres, bpp));
66
67 VMMDevDisplayChangeRequest *req = NULL;
68
69 int rc = VbglGRAlloc ((VMMDevRequestHeader **)&req, sizeof (VMMDevDisplayChangeRequest), VMMDevReq_GetDisplayChangeRequest);
70
71 if (VBOX_FAILURE(rc))
72 {
73 dprintf(("VBoxVideo::vboxQueryDisplayRequest: ERROR allocating request, rc = %Vrc\n", rc));
74 }
75 else
76 {
77 req->eventAck = 0;
78
79 rc = VbglGRPerform (&req->header);
80
81 if (VBOX_SUCCESS(rc) && VBOX_SUCCESS(req->header.rc))
82 {
83 if (xres)
84 *xres = req->xres;
85 if (yres)
86 *yres = req->yres;
87 if (bpp)
88 *bpp = req->bpp;
89 dprintf(("VBoxVideo::vboxQueryDisplayRequest: returning %d x %d @ %d\n",
90 req->xres, req->yres, req->bpp));
91 bRC = TRUE;
92 }
93 else
94 {
95 dprintf(("VBoxVideo::vboxQueryDisplayRequest: ERROR querying display request from VMMDev."
96 "rc = %Vrc, VMMDev rc = %Vrc\n", rc, req->header.rc));
97 }
98
99 VbglGRFree (&req->header);
100 }
101
102 return bRC;
103}
104
105BOOLEAN vboxLikesVideoMode(uint32_t width, uint32_t height, uint32_t bpp)
106{
107 BOOLEAN bRC = FALSE;
108
109 dprintf(("VBoxVideo::vboxLikesVideoMode: width: %d, height: %d, bpp: %d\n", width, height, bpp));
110
111 VMMDevVideoModeSupportedRequest *req = NULL;
112
113 int rc = VbglGRAlloc((VMMDevRequestHeader**)&req, sizeof(VMMDevVideoModeSupportedRequest), VMMDevReq_VideoModeSupported);
114 if (VBOX_FAILURE(rc))
115 {
116 dprintf(("VBoxVideo::vboxLikesVideoMode: ERROR allocating request, rc = %Vrc\n", rc));
117 /* Most likely the VBoxGuest driver is not loaded.
118 * To get at least the video working, report the mode as supported.
119 */
120 bRC = TRUE;
121 }
122 else
123 {
124 req->width = width;
125 req->height = height;
126 req->bpp = bpp;
127 rc = VbglGRPerform(&req->header);
128 if (VBOX_SUCCESS(rc) && VBOX_SUCCESS(req->header.rc))
129 {
130 bRC = req->fSupported;
131 }
132 else
133 {
134 dprintf(("VBoxVideo::vboxLikesVideoMode: ERROR querying video mode supported status from VMMDev."
135 "rc = %Vrc, VMMDev rc = %Vrc\n", rc, req->header.rc));
136 }
137 VbglGRFree(&req->header);
138 }
139
140 dprintf(("VBoxVideoMode::vboxLikesVideoMode: returning %d\n", bRC));
141 return bRC;
142}
143
144ULONG vboxGetHeightReduction()
145{
146 ULONG retHeight = 0;
147
148 dprintf(("VBoxVideo::vboxGetHeightReduction\n"));
149
150 VMMDevGetHeightReductionRequest *req = NULL;
151
152 int rc = VbglGRAlloc((VMMDevRequestHeader**)&req, sizeof(VMMDevGetHeightReductionRequest), VMMDevReq_GetHeightReduction);
153 if (VBOX_FAILURE(rc))
154 {
155 dprintf(("VBoxVideo::vboxGetHeightReduction: ERROR allocating request, rc = %Vrc\n", rc));
156 }
157 else
158 {
159 rc = VbglGRPerform(&req->header);
160 if (VBOX_SUCCESS(rc) && VBOX_SUCCESS(req->header.rc))
161 {
162 retHeight = (ULONG)req->heightReduction;
163 }
164 else
165 {
166 dprintf(("VBoxVideo::vboxGetHeightReduction: ERROR querying height reduction value from VMMDev."
167 "rc = %Vrc, VMMDev rc = %Vrc\n", rc, req->header.rc));
168 }
169 VbglGRFree(&req->header);
170 }
171
172 dprintf(("VBoxVideoMode::vboxGetHeightReduction: returning %d\n", retHeight));
173 return retHeight;
174}
175
176static BOOLEAN vboxQueryPointerPosInternal (uint16_t *pointerXPos, uint16_t *pointerYPos)
177{
178 BOOLEAN bRC = FALSE;
179
180 /* Activate next line only when really needed; floods the log very quickly! */
181 /*dprintf(("VBoxVideo::vboxQueryPointerPosInternal: pointerXPos = %p, pointerYPos = %p\n", pointerXPos, pointerYPos));*/
182
183 VMMDevReqMouseStatus *req = NULL;
184
185 int rc = VbglGRAlloc ((VMMDevRequestHeader **)&req, sizeof (VMMDevReqMouseStatus), VMMDevReq_GetMouseStatus);
186
187 if (VBOX_FAILURE(rc))
188 {
189 dprintf(("VBoxVideo::vboxQueryPointerPosInternal: ERROR allocating request, rc = %Vrc\n", rc));
190 }
191 else
192 {
193 rc = VbglGRPerform (&req->header);
194
195 if (VBOX_SUCCESS(rc) && VBOX_SUCCESS(req->header.rc))
196 {
197 if (req->mouseFeatures & VBOXGUEST_MOUSE_HOST_CAN_ABSOLUTE)
198 {
199 if (pointerXPos)
200 {
201 *pointerXPos = req->pointerXPos;
202 }
203
204 if (pointerYPos)
205 {
206 *pointerYPos = req->pointerYPos;
207 }
208
209 bRC = TRUE;
210 }
211 }
212 else
213 {
214 dprintf(("VBoxVideo::vboxQueryPointerPosInternal: ERROR querying mouse capabilities from VMMDev."
215 "rc = %Vrc, VMMDev rc = %Vrc\n", rc, req->header.rc));
216 }
217
218 VbglGRFree (&req->header);
219 }
220
221 return bRC;
222}
223
224/**
225 * Return the current absolute mouse position in normalized format
226 * (between 0 and 0xFFFF).
227 *
228 * @returns BOOLEAN success indicator
229 * @param pointerXPos address of result variable for x pos
230 * @param pointerYPos address of result variable for y pos
231 */
232BOOLEAN vboxQueryPointerPos(uint16_t *pointerXPos, uint16_t *pointerYPos)
233{
234 if (!pointerXPos || !pointerYPos)
235 {
236 return FALSE;
237 }
238
239 return vboxQueryPointerPosInternal (pointerXPos, pointerYPos);
240}
241
242/**
243 * Returns whether the host wants us to take absolute coordinates.
244 *
245 * @returns BOOLEAN TRUE if the host wants to send absolute coordinates.
246 */
247BOOLEAN vboxQueryHostWantsAbsolute (void)
248{
249 return vboxQueryPointerPosInternal (NULL, NULL);
250}
251
252winVersion_t vboxQueryWinVersion()
253{
254 static winVersion_t winVersion = UNKNOWN_WINVERSION;
255 ULONG majorVersion;
256 ULONG minorVersion;
257 ULONG buildNumber;
258
259 if (winVersion != UNKNOWN_WINVERSION)
260 return winVersion;
261
262 PsGetVersion(&majorVersion, &minorVersion, &buildNumber, NULL);
263
264 dprintf(("VBoxVideo::vboxQueryWinVersion: running on Windows NT version %d.%d, build %d\n",
265 majorVersion, minorVersion, buildNumber));
266
267 if (majorVersion >= 5)
268 {
269 if (minorVersion >= 1)
270 {
271 winVersion = WINXP;
272 } else
273 {
274 winVersion = WIN2K;
275 }
276 } else
277 if (majorVersion == 4)
278 {
279 winVersion = WINNT4;
280 } else
281 {
282 dprintf(("VBoxVideo::vboxQueryWinVersion: NT4 required!\n"));
283 }
284 return winVersion;
285}
286
287/**
288 * Sends the pointer shape to the VMMDev
289 *
290 * @returns success indicator
291 * @param pointerAttr pointer description
292 */
293BOOLEAN vboxUpdatePointerShape(PVIDEO_POINTER_ATTRIBUTES pointerAttr, uint32_t cbLength)
294{
295 uint32_t cbData = 0;
296
297 if (pointerAttr->Enable & VBOX_MOUSE_POINTER_SHAPE)
298 {
299 cbData = ((((pointerAttr->Width + 7) / 8) * pointerAttr->Height + 3) & ~3)
300 + pointerAttr->Width * 4 * pointerAttr->Height;
301 }
302
303 if (cbData > cbLength - sizeof(VIDEO_POINTER_ATTRIBUTES))
304 {
305 dprintf(("vboxUpdatePointerShape: calculated pointer data size is too big (%d bytes, limit %d)\n",
306 cbData, cbLength - sizeof(VIDEO_POINTER_ATTRIBUTES)));
307 return FALSE;
308 }
309
310 BOOLEAN bRC = FALSE;
311
312 VMMDevReqMousePointer *req = NULL;
313
314 int rc = VbglGRAlloc ((VMMDevRequestHeader **)&req, sizeof (VMMDevReqMousePointer) + cbData, VMMDevReq_SetPointerShape);
315
316 if (VBOX_FAILURE(rc))
317 {
318 dprintf(("VBoxVideo::vboxUpdatePointerShape: ERROR allocating request, rc = %Vrc\n", rc));
319 }
320 else
321 {
322 /* Activate next line only when really needed; floods the log very quickly! */
323 /*dprintf(("VBoxVideo::vboxUpdatePointerShape: req->u32Version = %08X\n", req->header.version));*/
324
325 /* We have our custom flags in the field */
326 req->fFlags = pointerAttr->Enable & 0xFFFF;
327
328 /* Even if pointer is invisible, we have to pass following data,
329 * so host could create the pointer with initial status - invisible
330 */
331 req->xHot = (pointerAttr->Enable >> 16) & 0xFF;
332 req->yHot = (pointerAttr->Enable >> 24) & 0xFF;
333 req->width = pointerAttr->Width;
334 req->height = pointerAttr->Height;
335
336 if (req->fFlags & VBOX_MOUSE_POINTER_SHAPE)
337 {
338 /* copy the actual pointer data */
339 memcpy (req->pointerData, pointerAttr->Pixels, cbData);
340 }
341
342 rc = VbglGRPerform (&req->header);
343
344 if (VBOX_SUCCESS(rc) && VBOX_SUCCESS(req->header.rc))
345 {
346 bRC = TRUE;
347 }
348 else
349 {
350 dprintf(("VBoxVideo::vboxUpdatePointerShape: ERROR querying mouse capabilities from VMMDev."
351 "rc = %Vrc, VMMDev rc = %Vrc\n", rc, req->header.rc));
352 }
353
354 dprintf(("VBoxVideo::vboxUpdatePointerShape: req->u32Version = %08X\n", req->header.version));
355
356 VbglGRFree (&req->header);
357 }
358
359 return bRC;
360}
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