VirtualBox

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

Last change on this file since 68458 was 62683, checked in by vboxsync, 8 years ago

Use the iprt/nt/ntddk.h wrapper for ntddk.h, eliminating duplicate ugly warning workarounds.

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