VirtualBox

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

Last change on this file since 8383 was 8155, checked in by vboxsync, 17 years ago

The Big Sun Rebranding Header Change

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.3 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 bRC = TRUE;
90 }
91 else
92 {
93 dprintf(("VBoxVideo::vboxQueryDisplayRequest: ERROR querying display request from VMMDev."
94 "rc = %Vrc, VMMDev rc = %Vrc\n", rc, req->header.rc));
95 }
96
97 VbglGRFree (&req->header);
98 }
99
100 return bRC;
101}
102
103BOOLEAN vboxLikesVideoMode(uint32_t width, uint32_t height, uint32_t bpp)
104{
105 BOOLEAN bRC = FALSE;
106
107 dprintf(("VBoxVideo::vboxLikesVideoMode: width: %d, height: %d, bpp: %d\n", width, height, bpp));
108
109 VMMDevVideoModeSupportedRequest *req = NULL;
110
111 int rc = VbglGRAlloc((VMMDevRequestHeader**)&req, sizeof(VMMDevVideoModeSupportedRequest), VMMDevReq_VideoModeSupported);
112 if (VBOX_FAILURE(rc))
113 {
114 dprintf(("VBoxVideo::vboxLikesVideoMode: ERROR allocating request, rc = %Vrc\n", rc));
115 /* Most likely the VBoxGuest driver is not loaded.
116 * To get at least the video working, report the mode as supported.
117 */
118 bRC = TRUE;
119 }
120 else
121 {
122 req->width = width;
123 req->height = height;
124 req->bpp = bpp;
125 rc = VbglGRPerform(&req->header);
126 if (VBOX_SUCCESS(rc) && VBOX_SUCCESS(req->header.rc))
127 {
128 bRC = req->fSupported;
129 }
130 else
131 {
132 dprintf(("VBoxVideo::vboxLikesVideoMode: ERROR querying video mode supported status from VMMDev."
133 "rc = %Vrc, VMMDev rc = %Vrc\n", rc, req->header.rc));
134 }
135 VbglGRFree(&req->header);
136 }
137
138 dprintf(("VBoxVideoMode::vboxLikesVideoMode: returning %d\n", bRC));
139 return bRC;
140}
141
142ULONG vboxGetHeightReduction()
143{
144 ULONG retHeight = 0;
145
146 dprintf(("VBoxVideo::vboxGetHeightReduction\n"));
147
148 VMMDevGetHeightReductionRequest *req = NULL;
149
150 int rc = VbglGRAlloc((VMMDevRequestHeader**)&req, sizeof(VMMDevGetHeightReductionRequest), VMMDevReq_GetHeightReduction);
151 if (VBOX_FAILURE(rc))
152 {
153 dprintf(("VBoxVideo::vboxGetHeightReduction: ERROR allocating request, rc = %Vrc\n", rc));
154 }
155 else
156 {
157 rc = VbglGRPerform(&req->header);
158 if (VBOX_SUCCESS(rc) && VBOX_SUCCESS(req->header.rc))
159 {
160 retHeight = (ULONG)req->heightReduction;
161 }
162 else
163 {
164 dprintf(("VBoxVideo::vboxGetHeightReduction: ERROR querying height reduction value from VMMDev."
165 "rc = %Vrc, VMMDev rc = %Vrc\n", rc, req->header.rc));
166 }
167 VbglGRFree(&req->header);
168 }
169
170 dprintf(("VBoxVideoMode::vboxGetHeightReduction: returning %d\n", retHeight));
171 return retHeight;
172}
173
174static BOOLEAN vboxQueryPointerPosInternal (uint16_t *pointerXPos, uint16_t *pointerYPos)
175{
176 BOOLEAN bRC = FALSE;
177
178 dprintf(("VBoxVideo::vboxQueryPointerPosInternal: pointerXPos = %p, pointerYPos = %p\n", pointerXPos, pointerYPos));
179
180 VMMDevReqMouseStatus *req = NULL;
181
182 int rc = VbglGRAlloc ((VMMDevRequestHeader **)&req, sizeof (VMMDevReqMouseStatus), VMMDevReq_GetMouseStatus);
183
184 if (VBOX_FAILURE(rc))
185 {
186 dprintf(("VBoxVideo::vboxQueryPointerPosInternal: ERROR allocating request, rc = %Vrc\n", rc));
187 }
188 else
189 {
190 rc = VbglGRPerform (&req->header);
191
192 if (VBOX_SUCCESS(rc) && VBOX_SUCCESS(req->header.rc))
193 {
194 if (req->mouseFeatures & VBOXGUEST_MOUSE_HOST_CAN_ABSOLUTE)
195 {
196 if (pointerXPos)
197 {
198 *pointerXPos = req->pointerXPos;
199 }
200
201 if (pointerYPos)
202 {
203 *pointerYPos = req->pointerYPos;
204 }
205
206 bRC = TRUE;
207 }
208 }
209 else
210 {
211 dprintf(("VBoxVideo::vboxQueryPointerPosInternal: ERROR querying mouse capabilities from VMMDev."
212 "rc = %Vrc, VMMDev rc = %Vrc\n", rc, req->header.rc));
213 }
214
215 VbglGRFree (&req->header);
216 }
217
218 return bRC;
219}
220
221/**
222 * Return the current absolute mouse position in normalized format
223 * (between 0 and 0xFFFF).
224 *
225 * @returns BOOLEAN success indicator
226 * @param pointerXPos address of result variable for x pos
227 * @param pointerYPos address of result variable for y pos
228 */
229BOOLEAN vboxQueryPointerPos(uint16_t *pointerXPos, uint16_t *pointerYPos)
230{
231 if (!pointerXPos || !pointerYPos)
232 {
233 return FALSE;
234 }
235
236 return vboxQueryPointerPosInternal (pointerXPos, pointerYPos);
237}
238
239/**
240 * Returns whether the host wants us to take absolute coordinates.
241 *
242 * @returns BOOLEAN TRUE if the host wants to send absolute coordinates.
243 */
244BOOLEAN vboxQueryHostWantsAbsolute (void)
245{
246 return vboxQueryPointerPosInternal (NULL, NULL);
247}
248
249winVersion_t vboxQueryWinVersion()
250{
251 static winVersion_t winVersion = UNKNOWN_WINVERSION;
252 ULONG majorVersion;
253 ULONG minorVersion;
254 ULONG buildNumber;
255
256 if (winVersion != UNKNOWN_WINVERSION)
257 return winVersion;
258
259 PsGetVersion(&majorVersion, &minorVersion, &buildNumber, NULL);
260
261 dprintf(("VBoxVideo::vboxQueryWinVersion: running on Windows NT version %d.%d, build %d\n",
262 majorVersion, minorVersion, buildNumber));
263
264 if (majorVersion >= 5)
265 {
266 if (minorVersion >= 1)
267 {
268 winVersion = WINXP;
269 } else
270 {
271 winVersion = WIN2K;
272 }
273 } else
274 if (majorVersion == 4)
275 {
276 winVersion = WINNT4;
277 } else
278 {
279 dprintf(("VBoxVideo::vboxQueryWinVersion: NT4 required!\n"));
280 }
281 return winVersion;
282}
283
284/**
285 * Sends the pointer shape to the VMMDev
286 *
287 * @returns success indicator
288 * @param pointerAttr pointer description
289 */
290BOOLEAN vboxUpdatePointerShape(PVIDEO_POINTER_ATTRIBUTES pointerAttr, uint32_t cbLength)
291{
292 uint32_t cbData = 0;
293
294 if (pointerAttr->Enable & VBOX_MOUSE_POINTER_SHAPE)
295 {
296 cbData = ((((pointerAttr->Width + 7) / 8) * pointerAttr->Height + 3) & ~3)
297 + pointerAttr->Width * 4 * pointerAttr->Height;
298 }
299
300 if (cbData > cbLength - sizeof(VIDEO_POINTER_ATTRIBUTES))
301 {
302 dprintf(("vboxUpdatePointerShape: calculated pointer data size is too big (%d bytes, limit %d)\n",
303 cbData, cbLength - sizeof(VIDEO_POINTER_ATTRIBUTES)));
304 return FALSE;
305 }
306
307 BOOLEAN bRC = FALSE;
308
309 VMMDevReqMousePointer *req = NULL;
310
311 int rc = VbglGRAlloc ((VMMDevRequestHeader **)&req, sizeof (VMMDevReqMousePointer) + cbData, VMMDevReq_SetPointerShape);
312
313 if (VBOX_FAILURE(rc))
314 {
315 dprintf(("VBoxVideo::vboxUpdatePointerShape: ERROR allocating request, rc = %Vrc\n", rc));
316 }
317 else
318 {
319 dprintf(("VBoxVideo::vboxUpdatePointerShape: req->u32Version = %08X\n", req->header.version));
320
321 /* We have our custom flags in the field */
322 req->fFlags = pointerAttr->Enable & 0xFFFF;
323
324 /* Even if pointer is invisible, we have to pass following data,
325 * so host could create the pointer with initial status - invisible
326 */
327 req->xHot = (pointerAttr->Enable >> 16) & 0xFF;
328 req->yHot = (pointerAttr->Enable >> 24) & 0xFF;
329 req->width = pointerAttr->Width;
330 req->height = pointerAttr->Height;
331
332 if (req->fFlags & VBOX_MOUSE_POINTER_SHAPE)
333 {
334 /* copy the actual pointer data */
335 memcpy (req->pointerData, pointerAttr->Pixels, cbData);
336 }
337
338 rc = VbglGRPerform (&req->header);
339
340 if (VBOX_SUCCESS(rc) && VBOX_SUCCESS(req->header.rc))
341 {
342 bRC = TRUE;
343 }
344 else
345 {
346 dprintf(("VBoxVideo::vboxUpdatePointerShape: ERROR querying mouse capabilities from VMMDev."
347 "rc = %Vrc, VMMDev rc = %Vrc\n", rc, req->header.rc));
348 }
349
350 dprintf(("VBoxVideo::vboxUpdatePointerShape: req->u32Version = %08X\n", req->header.version));
351
352 VbglGRFree (&req->header);
353 }
354
355 return bRC;
356}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette