VirtualBox

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

Last change on this file since 40747 was 38765, checked in by vboxsync, 13 years ago

more Windows 8 fixes

  • 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 38765 2011-09-15 14:11:47Z 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 return s_WinVersion;
53
54 checkedBuild = PsGetVersion(&major, &minor, &build, NULL);
55 LOG(("running on version %d.%d, build %d(checked=%d)", major, minor, build, (int)checkedBuild));
56
57 if(major == 6)
58 {
59 if (minor == 2)
60 s_WinVersion = WIN8;
61 else if (minor == 1)
62 s_WinVersion = WIN7;
63 else if (minor == 0)
64 s_WinVersion = WINVISTA; /* Or Windows Server 2008. */
65 }
66 else if (major == 5)
67 s_WinVersion = (minor>=1) ? WINXP:WIN2K;
68 else if (major == 4)
69 s_WinVersion = WINNT4;
70 else
71 WARN(("NT4 required!"));
72 return s_WinVersion;
73}
74
75uint32_t VBoxGetHeightReduction()
76{
77 uint32_t retHeight = 0;
78 int rc;
79
80 LOGF_ENTER();
81
82 VMMDevGetHeightReductionRequest *req = NULL;
83
84 rc = VbglGRAlloc((VMMDevRequestHeader**)&req, sizeof(VMMDevGetHeightReductionRequest), VMMDevReq_GetHeightReduction);
85 if (RT_FAILURE(rc))
86 {
87 WARN(("ERROR allocating request, rc = %#xrc", rc));
88 }
89 else
90 {
91 rc = VbglGRPerform(&req->header);
92 if (RT_SUCCESS(rc))
93 {
94 retHeight = req->heightReduction;
95 }
96 else
97 {
98 WARN(("ERROR querying height reduction value from VMMDev. rc = %#xrc", rc));
99 }
100 VbglGRFree(&req->header);
101 }
102
103 LOGF_LEAVE();
104 return retHeight;
105}
106
107bool VBoxLikesVideoMode(uint32_t display, uint32_t width, uint32_t height, uint32_t bpp)
108{
109 bool bRC = FALSE;
110
111 VMMDevVideoModeSupportedRequest2 *req2 = NULL;
112
113 int rc = VbglGRAlloc((VMMDevRequestHeader**)&req2, sizeof(VMMDevVideoModeSupportedRequest2), VMMDevReq_VideoModeSupported2);
114 if (RT_FAILURE(rc))
115 {
116 LOG(("ERROR allocating request, rc = %#xrc", 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 req2->display = display;
125 req2->width = width;
126 req2->height = height;
127 req2->bpp = bpp;
128 rc = VbglGRPerform(&req2->header);
129 if (RT_SUCCESS(rc))
130 {
131 bRC = req2->fSupported;
132 }
133 else
134 {
135 /* Retry using old interface. */
136 AssertCompile(sizeof(VMMDevVideoModeSupportedRequest2) >= sizeof(VMMDevVideoModeSupportedRequest));
137 VMMDevVideoModeSupportedRequest *req = (VMMDevVideoModeSupportedRequest *)req2;
138 req->header.size = sizeof(VMMDevVideoModeSupportedRequest);
139 req->header.version = VMMDEV_REQUEST_HEADER_VERSION;
140 req->header.requestType = VMMDevReq_VideoModeSupported;
141 req->header.rc = VERR_GENERAL_FAILURE;
142 req->header.reserved1 = 0;
143 req->header.reserved2 = 0;
144 req->width = width;
145 req->height = height;
146 req->bpp = bpp;
147
148 rc = VbglGRPerform(&req->header);
149 if (RT_SUCCESS(rc))
150 {
151 bRC = req->fSupported;
152 }
153 else
154 {
155 WARN(("ERROR querying video mode supported status from VMMDev. rc = %#xrc", rc));
156 }
157 }
158 VbglGRFree(&req2->header);
159 }
160
161 LOG(("width: %d, height: %d, bpp: %d -> %s", width, height, bpp, (bRC == 1) ? "OK" : "FALSE"));
162
163 return bRC;
164}
165
166bool VBoxQueryDisplayRequest(uint32_t *xres, uint32_t *yres, uint32_t *bpp, uint32_t *pDisplayId)
167{
168 bool bRC = FALSE;
169 VMMDevDisplayChangeRequest2 *req = NULL;
170
171 LOGF_ENTER();
172
173 int rc = VbglGRAlloc ((VMMDevRequestHeader **)&req, sizeof (VMMDevDisplayChangeRequest2), VMMDevReq_GetDisplayChangeRequest2);
174
175 if (RT_FAILURE(rc))
176 {
177 LOG(("ERROR allocating request, rc = %#xrc", rc));
178 }
179 else
180 {
181 req->eventAck = 0;
182
183 rc = VbglGRPerform (&req->header);
184
185 if (RT_SUCCESS(rc))
186 {
187 if (xres)
188 *xres = req->xres;
189 if (yres)
190 *yres = req->yres;
191 if (bpp)
192 *bpp = req->bpp;
193 if (pDisplayId)
194 *pDisplayId = req->display;
195 LOG(("returning %d x %d @ %d for %d", req->xres, req->yres, req->bpp, req->display));
196 bRC = TRUE;
197 }
198 else
199 {
200 WARN(("ERROR querying display request from VMMDev. rc = %#xrc", rc));
201 }
202
203 VbglGRFree (&req->header);
204 }
205
206 LOGF_LEAVE();
207 return bRC;
208}
209
210static bool VBoxQueryPointerPosInternal(uint16_t *pPosX, uint16_t *pPosY)
211{
212 bool bRC = FALSE;
213
214 VMMDevReqMouseStatus *req = NULL;
215
216 int rc = VbglGRAlloc((VMMDevRequestHeader **)&req, sizeof(VMMDevReqMouseStatus), VMMDevReq_GetMouseStatus);
217
218 if (RT_FAILURE(rc))
219 {
220 LOG(("ERROR allocating request, rc = %#xrc", rc));
221 }
222 else
223 {
224 rc = VbglGRPerform(&req->header);
225
226 if (RT_SUCCESS(rc))
227 {
228 if (req->mouseFeatures & VMMDEV_MOUSE_HOST_WANTS_ABSOLUTE)
229 {
230 if (pPosX)
231 {
232 *pPosX = req->pointerXPos;
233 }
234
235 if (pPosY)
236 {
237 *pPosY = req->pointerYPos;
238 }
239
240 bRC = TRUE;
241 }
242 }
243 else
244 {
245 LOG(("ERROR querying mouse capabilities from VMMDev. rc = %#xrc", rc));
246 }
247
248 VbglGRFree(&req->header);
249 }
250
251 return bRC;
252}
253
254/* Returns if the host wants us to take absolute pointer coordinates. */
255bool VBoxQueryHostWantsAbsolute()
256{
257 return VBoxQueryPointerPosInternal(NULL, NULL);
258}
259
260bool VBoxQueryPointerPos(uint16_t *pPosX, uint16_t *pPosY)
261{
262 if (!pPosX || !pPosY)
263 {
264 return FALSE;
265 }
266
267 return VBoxQueryPointerPosInternal(pPosX, pPosY);
268}
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