VirtualBox

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

Last change on this file since 50940 was 50928, checked in by vboxsync, 11 years ago

wddm/DevVga/crOpenGL: new command submission working for 3D

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