VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/common/VBoxMPUtils.cpp@ 37207

Last change on this file since 37207 was 36955, checked in by vboxsync, 14 years ago

wddm: build fixes for DEBUG_misha

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.3 KB
Line 
1/* $Id: VBoxMPUtils.cpp 36955 2011-05-04 12:35:05Z vboxsync $ */
2
3/** @file
4 * VBox Miniport utils
5 */
6
7/*
8 * Copyright (C) 2011 Oracle Corporation
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 */
18
19#include "VBoxMPUtils.h"
20
21#ifdef VBOX_XPDM_MINIPORT
22RT_C_DECLS_BEGIN
23# include <ntddk.h>
24RT_C_DECLS_END
25#endif
26#include <VBox/VMMDev.h>
27#include <VBox/VBoxGuestLib.h>
28
29#ifdef DEBUG_misha
30/* specifies whether the vboxVDbgBreakF should break in the debugger
31 * windbg seems to have some issues when there is a lot ( >~50) of sw breakpoints defined
32 * to simplify things we just insert breaks for the case of intensive debugging WDDM driver*/
33bool g_bVBoxVDbgBreakF = false;
34bool g_bVBoxVDbgBreakFv = false;
35#endif
36
37#pragma alloc_text(PAGE, VBoxQueryWinVersion)
38#pragma alloc_text(PAGE, VBoxGetHeightReduction)
39#pragma alloc_text(PAGE, VBoxLikesVideoMode)
40#pragma alloc_text(PAGE, VBoxQueryDisplayRequest)
41#pragma alloc_text(PAGE, VBoxQueryHostWantsAbsolute)
42#pragma alloc_text(PAGE, VBoxQueryPointerPos)
43
44/*Returns the windows version we're running on*/
45vboxWinVersion_t VBoxQueryWinVersion()
46{
47 ULONG major, minor, build;
48 BOOLEAN checkedBuild;
49 static vboxWinVersion_t s_WinVersion = UNKNOWN_WINVERSION;
50
51 if (s_WinVersion != UNKNOWN_WINVERSION)
52 {
53 return s_WinVersion;
54 }
55
56 checkedBuild = PsGetVersion(&major, &minor, &build, NULL);
57 LOG(("running on version %d.%d, build %d(checked=%d)", major, minor, build, (int)checkedBuild));
58
59 if(major == 6)
60 {
61 if (minor == 1)
62 {
63 s_WinVersion = WIN7;
64 }
65 else if (minor == 0)
66 {
67 s_WinVersion = WINVISTA; /* Or Windows Server 2008. */
68 }
69 }
70 else if (major == 5)
71 {
72 s_WinVersion = (minor>=1) ? WINXP:WIN2K;
73 }
74 else if (major == 4)
75 {
76 s_WinVersion = WINNT4;
77 }
78 else
79 {
80 WARN(("NT4 required!"));
81 }
82 return s_WinVersion;
83}
84
85uint32_t VBoxGetHeightReduction()
86{
87 uint32_t retHeight = 0;
88 int rc;
89
90 LOGF_ENTER();
91
92 VMMDevGetHeightReductionRequest *req = NULL;
93
94 rc = VbglGRAlloc((VMMDevRequestHeader**)&req, sizeof(VMMDevGetHeightReductionRequest), VMMDevReq_GetHeightReduction);
95 if (RT_FAILURE(rc))
96 {
97 WARN(("ERROR allocating request, rc = %#xrc", rc));
98 }
99 else
100 {
101 rc = VbglGRPerform(&req->header);
102 if (RT_SUCCESS(rc))
103 {
104 retHeight = req->heightReduction;
105 }
106 else
107 {
108 WARN(("ERROR querying height reduction value from VMMDev. rc = %#xrc", rc));
109 }
110 VbglGRFree(&req->header);
111 }
112
113 LOGF_LEAVE();
114 return retHeight;
115}
116
117bool VBoxLikesVideoMode(uint32_t display, uint32_t width, uint32_t height, uint32_t bpp)
118{
119 bool bRC = FALSE;
120
121 VMMDevVideoModeSupportedRequest2 *req2 = NULL;
122
123 int rc = VbglGRAlloc((VMMDevRequestHeader**)&req2, sizeof(VMMDevVideoModeSupportedRequest2), VMMDevReq_VideoModeSupported2);
124 if (RT_FAILURE(rc))
125 {
126 LOG(("ERROR allocating request, rc = %#xrc", rc));
127 /* Most likely the VBoxGuest driver is not loaded.
128 * To get at least the video working, report the mode as supported.
129 */
130 bRC = TRUE;
131 }
132 else
133 {
134 req2->display = display;
135 req2->width = width;
136 req2->height = height;
137 req2->bpp = bpp;
138 rc = VbglGRPerform(&req2->header);
139 if (RT_SUCCESS(rc))
140 {
141 bRC = req2->fSupported;
142 }
143 else
144 {
145 /* Retry using old interface. */
146 AssertCompile(sizeof(VMMDevVideoModeSupportedRequest2) >= sizeof(VMMDevVideoModeSupportedRequest));
147 VMMDevVideoModeSupportedRequest *req = (VMMDevVideoModeSupportedRequest *)req2;
148 req->header.size = sizeof(VMMDevVideoModeSupportedRequest);
149 req->header.version = VMMDEV_REQUEST_HEADER_VERSION;
150 req->header.requestType = VMMDevReq_VideoModeSupported;
151 req->header.rc = VERR_GENERAL_FAILURE;
152 req->header.reserved1 = 0;
153 req->header.reserved2 = 0;
154 req->width = width;
155 req->height = height;
156 req->bpp = bpp;
157
158 rc = VbglGRPerform(&req->header);
159 if (RT_SUCCESS(rc))
160 {
161 bRC = req->fSupported;
162 }
163 else
164 {
165 WARN(("ERROR querying video mode supported status from VMMDev. rc = %#xrc", rc));
166 }
167 }
168 VbglGRFree(&req2->header);
169 }
170
171 LOG(("width: %d, height: %d, bpp: %d -> %s", width, height, bpp, (bRC == 1) ? "OK" : "FALSE"));
172
173 return bRC;
174}
175
176bool VBoxQueryDisplayRequest(uint32_t *xres, uint32_t *yres, uint32_t *bpp, uint32_t *pDisplayId)
177{
178 bool bRC = FALSE;
179 VMMDevDisplayChangeRequest2 *req = NULL;
180
181 LOGF_ENTER();
182
183 int rc = VbglGRAlloc ((VMMDevRequestHeader **)&req, sizeof (VMMDevDisplayChangeRequest2), VMMDevReq_GetDisplayChangeRequest2);
184
185 if (RT_FAILURE(rc))
186 {
187 LOG(("ERROR allocating request, rc = %#xrc", rc));
188 }
189 else
190 {
191 req->eventAck = 0;
192
193 rc = VbglGRPerform (&req->header);
194
195 if (RT_SUCCESS(rc))
196 {
197 if (xres)
198 *xres = req->xres;
199 if (yres)
200 *yres = req->yres;
201 if (bpp)
202 *bpp = req->bpp;
203 if (pDisplayId)
204 *pDisplayId = req->display;
205 LOG(("returning %d x %d @ %d for %d", req->xres, req->yres, req->bpp, req->display));
206 bRC = TRUE;
207 }
208 else
209 {
210 WARN(("ERROR querying display request from VMMDev. rc = %#xrc", rc));
211 }
212
213 VbglGRFree (&req->header);
214 }
215
216 LOGF_LEAVE();
217 return bRC;
218}
219
220static bool VBoxQueryPointerPosInternal(uint16_t *pPosX, uint16_t *pPosY)
221{
222 bool bRC = FALSE;
223
224 VMMDevReqMouseStatus *req = NULL;
225
226 int rc = VbglGRAlloc((VMMDevRequestHeader **)&req, sizeof(VMMDevReqMouseStatus), VMMDevReq_GetMouseStatus);
227
228 if (RT_FAILURE(rc))
229 {
230 LOG(("ERROR allocating request, rc = %#xrc", rc));
231 }
232 else
233 {
234 rc = VbglGRPerform(&req->header);
235
236 if (RT_SUCCESS(rc))
237 {
238 if (req->mouseFeatures & VMMDEV_MOUSE_HOST_WANTS_ABSOLUTE)
239 {
240 if (pPosX)
241 {
242 *pPosX = req->pointerXPos;
243 }
244
245 if (pPosY)
246 {
247 *pPosY = req->pointerYPos;
248 }
249
250 bRC = TRUE;
251 }
252 }
253 else
254 {
255 LOG(("ERROR querying mouse capabilities from VMMDev. rc = %#xrc", rc));
256 }
257
258 VbglGRFree(&req->header);
259 }
260
261 return bRC;
262}
263
264/* Returns if the host wants us to take absolute pointer coordinates. */
265bool VBoxQueryHostWantsAbsolute()
266{
267 return VBoxQueryPointerPosInternal(NULL, NULL);
268}
269
270bool VBoxQueryPointerPos(uint16_t *pPosX, uint16_t *pPosY)
271{
272 if (!pPosX || !pPosY)
273 {
274 return FALSE;
275 }
276
277 return VBoxQueryPointerPosInternal(pPosX, pPosY);
278}
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