VirtualBox

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

Last change on this file since 98103 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

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