1 | /* $Id: VBoxMPCr.cpp 40897 2012-04-12 18:16:40Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | * VBox WDDM Miniport driver
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 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 "VBoxMPWddm.h"
|
---|
20 | #include "VBoxMPCr.h"
|
---|
21 |
|
---|
22 | #include <cr_protocol.h>
|
---|
23 |
|
---|
24 | #include <VBox/HostServices/VBoxCrOpenGLSvc.h>
|
---|
25 |
|
---|
26 | static int vboxMpCrCtlAddRef(PVBOXMP_CRCTLCON pCrCtlCon)
|
---|
27 | {
|
---|
28 | if (pCrCtlCon->cCrCtlRefs++)
|
---|
29 | return VINF_ALREADY_INITIALIZED;
|
---|
30 |
|
---|
31 | int rc = vboxCrCtlCreate(&pCrCtlCon->hCrCtl);
|
---|
32 | if (RT_SUCCESS(rc))
|
---|
33 | {
|
---|
34 | Assert(pCrCtlCon->hCrCtl);
|
---|
35 | return VINF_SUCCESS;
|
---|
36 | }
|
---|
37 |
|
---|
38 | WARN(("vboxCrCtlCreate failed, rc (%d)", rc));
|
---|
39 |
|
---|
40 | --pCrCtlCon->cCrCtlRefs;
|
---|
41 | return rc;
|
---|
42 | }
|
---|
43 |
|
---|
44 | static int vboxMpCrCtlRelease(PVBOXMP_CRCTLCON pCrCtlCon)
|
---|
45 | {
|
---|
46 | Assert(pCrCtlCon->cCrCtlRefs);
|
---|
47 | if (--pCrCtlCon->cCrCtlRefs)
|
---|
48 | {
|
---|
49 | return VINF_SUCCESS;
|
---|
50 | }
|
---|
51 |
|
---|
52 | int rc = vboxCrCtlDestroy(pCrCtlCon->hCrCtl);
|
---|
53 | if (RT_SUCCESS(rc))
|
---|
54 | {
|
---|
55 | pCrCtlCon->hCrCtl = NULL;
|
---|
56 | return VINF_SUCCESS;
|
---|
57 | }
|
---|
58 |
|
---|
59 | WARN(("vboxCrCtlDestroy failed, rc (%d)", rc));
|
---|
60 |
|
---|
61 | ++pCrCtlCon->cCrCtlRefs;
|
---|
62 | return rc;
|
---|
63 | }
|
---|
64 |
|
---|
65 | static int vboxMpCrCtlConSetVersion(PVBOXMP_CRCTLCON pCrCtlCon, uint32_t u32ClientID, uint32_t vMajor, uint32_t vMinor)
|
---|
66 | {
|
---|
67 | CRVBOXHGCMSETVERSION parms;
|
---|
68 | int rc;
|
---|
69 |
|
---|
70 | parms.hdr.result = VERR_WRONG_ORDER;
|
---|
71 | parms.hdr.u32ClientID = u32ClientID;
|
---|
72 | parms.hdr.u32Function = SHCRGL_GUEST_FN_SET_VERSION;
|
---|
73 | parms.hdr.cParms = SHCRGL_CPARMS_SET_VERSION;
|
---|
74 |
|
---|
75 | parms.vMajor.type = VMMDevHGCMParmType_32bit;
|
---|
76 | parms.vMajor.u.value32 = vMajor;
|
---|
77 | parms.vMinor.type = VMMDevHGCMParmType_32bit;
|
---|
78 | parms.vMinor.u.value32 = vMinor;
|
---|
79 |
|
---|
80 | rc = vboxCrCtlConCall(pCrCtlCon->hCrCtl, &parms.hdr, sizeof (parms));
|
---|
81 | if (RT_FAILURE(rc))
|
---|
82 | {
|
---|
83 | WARN(("vboxCrCtlConCall failed, rc (%d)", rc));
|
---|
84 | return rc;
|
---|
85 | }
|
---|
86 |
|
---|
87 | if (RT_FAILURE(parms.hdr.result))
|
---|
88 | {
|
---|
89 | WARN(("version validation failed, rc (%d)", parms.hdr.result));
|
---|
90 | return parms.hdr.result;
|
---|
91 | }
|
---|
92 | return VINF_SUCCESS;
|
---|
93 | }
|
---|
94 |
|
---|
95 | static int vboxMpCrCtlConSetPID(PVBOXMP_CRCTLCON pCrCtlCon, uint32_t u32ClientID)
|
---|
96 | {
|
---|
97 | CRVBOXHGCMSETPID parms;
|
---|
98 | int rc;
|
---|
99 |
|
---|
100 | parms.hdr.result = VERR_WRONG_ORDER;
|
---|
101 | parms.hdr.u32ClientID = u32ClientID;
|
---|
102 | parms.hdr.u32Function = SHCRGL_GUEST_FN_SET_PID;
|
---|
103 | parms.hdr.cParms = SHCRGL_CPARMS_SET_PID;
|
---|
104 |
|
---|
105 | parms.u64PID.type = VMMDevHGCMParmType_64bit;
|
---|
106 | parms.u64PID.u.value64 = (uint64_t)PsGetCurrentProcessId();
|
---|
107 |
|
---|
108 | Assert(parms.u64PID.u.value64);
|
---|
109 |
|
---|
110 | rc = vboxCrCtlConCall(pCrCtlCon->hCrCtl, &parms.hdr, sizeof (parms));
|
---|
111 | if (RT_FAILURE(rc))
|
---|
112 | {
|
---|
113 | WARN(("vboxCrCtlConCall failed, rc (%d)", rc));
|
---|
114 | return rc;
|
---|
115 | }
|
---|
116 |
|
---|
117 | if (RT_FAILURE(parms.hdr.result))
|
---|
118 | {
|
---|
119 | WARN(("set PID failed, rc (%d)", parms.hdr.result));
|
---|
120 | return parms.hdr.result;
|
---|
121 | }
|
---|
122 | return VINF_SUCCESS;
|
---|
123 | }
|
---|
124 |
|
---|
125 | int VBoxMpCrCtlConConnect(PVBOXMP_CRCTLCON pCrCtlCon,
|
---|
126 | uint32_t crVersionMajor, uint32_t crVersionMinor,
|
---|
127 | uint32_t *pu32ClientID)
|
---|
128 | {
|
---|
129 | uint32_t u32ClientID;
|
---|
130 | int rc = vboxMpCrCtlAddRef(pCrCtlCon);
|
---|
131 | if (RT_SUCCESS(rc))
|
---|
132 | {
|
---|
133 | rc = vboxCrCtlConConnect(pCrCtlCon->hCrCtl, &u32ClientID);
|
---|
134 | if (RT_SUCCESS(rc))
|
---|
135 | {
|
---|
136 | rc = vboxMpCrCtlConSetVersion(pCrCtlCon, u32ClientID, crVersionMajor, crVersionMinor);
|
---|
137 | if (RT_SUCCESS(rc))
|
---|
138 | {
|
---|
139 | rc = vboxMpCrCtlConSetPID(pCrCtlCon, u32ClientID);
|
---|
140 | if (RT_SUCCESS(rc))
|
---|
141 | {
|
---|
142 | *pu32ClientID = u32ClientID;
|
---|
143 | return VINF_SUCCESS;
|
---|
144 | }
|
---|
145 | else
|
---|
146 | {
|
---|
147 | WARN(("vboxMpCrCtlConSetPID failed, rc (%d)", rc));
|
---|
148 | }
|
---|
149 | }
|
---|
150 | else
|
---|
151 | {
|
---|
152 | WARN(("vboxMpCrCtlConSetVersion failed, rc (%d)", rc));
|
---|
153 | }
|
---|
154 | vboxCrCtlConDisconnect(pCrCtlCon->hCrCtl, u32ClientID);
|
---|
155 | }
|
---|
156 | else
|
---|
157 | {
|
---|
158 | WARN(("vboxCrCtlConConnect failed, rc (%d)", rc));
|
---|
159 | }
|
---|
160 | vboxMpCrCtlRelease(pCrCtlCon);
|
---|
161 | }
|
---|
162 | else
|
---|
163 | {
|
---|
164 | WARN(("vboxMpCrCtlAddRef failed, rc (%d)", rc));
|
---|
165 | }
|
---|
166 |
|
---|
167 | *pu32ClientID = 0;
|
---|
168 | Assert(RT_FAILURE(rc));
|
---|
169 | return rc;
|
---|
170 | }
|
---|
171 |
|
---|
172 | int VBoxMpCrCtlConDisconnect(PVBOXMP_CRCTLCON pCrCtlCon, uint32_t u32ClientID)
|
---|
173 | {
|
---|
174 | int rc = vboxCrCtlConDisconnect(pCrCtlCon->hCrCtl, u32ClientID);
|
---|
175 | if (RT_SUCCESS(rc))
|
---|
176 | {
|
---|
177 | vboxMpCrCtlRelease(pCrCtlCon);
|
---|
178 | return VINF_SUCCESS;
|
---|
179 | }
|
---|
180 | else
|
---|
181 | {
|
---|
182 | WARN(("vboxCrCtlConDisconnect failed, rc (%d)", rc));
|
---|
183 | }
|
---|
184 | return rc;
|
---|
185 | }
|
---|
186 |
|
---|
187 | int VBoxMpCrCtlConCall(PVBOXMP_CRCTLCON pCrCtlCon, VBoxGuestHGCMCallInfo *pData, uint32_t cbData)
|
---|
188 | {
|
---|
189 | int rc = vboxCrCtlConCall(pCrCtlCon->hCrCtl, pData, cbData);
|
---|
190 | if (RT_SUCCESS(rc))
|
---|
191 | return VINF_SUCCESS;
|
---|
192 |
|
---|
193 | WARN(("vboxCrCtlConCallUserData failed, rc(%d)", rc));
|
---|
194 | return rc;
|
---|
195 | }
|
---|
196 |
|
---|
197 | int VBoxMpCrCtlConCallUserData(PVBOXMP_CRCTLCON pCrCtlCon, VBoxGuestHGCMCallInfo *pData, uint32_t cbData)
|
---|
198 | {
|
---|
199 | int rc = vboxCrCtlConCallUserData(pCrCtlCon->hCrCtl, pData, cbData);
|
---|
200 | if (RT_SUCCESS(rc))
|
---|
201 | return VINF_SUCCESS;
|
---|
202 |
|
---|
203 | WARN(("vboxCrCtlConCallUserData failed, rc(%d)", rc));
|
---|
204 | return rc;
|
---|
205 | }
|
---|
206 |
|
---|
207 | bool VBoxMpCrCtlConIs3DSupported()
|
---|
208 | {
|
---|
209 | VBOXMP_CRCTLCON CrCtlCon = {0};
|
---|
210 | uint32_t u32ClientID = 0;
|
---|
211 | int rc = VBoxMpCrCtlConConnect(&CrCtlCon, CR_PROTOCOL_VERSION_MAJOR, CR_PROTOCOL_VERSION_MINOR, &u32ClientID);
|
---|
212 | if (RT_FAILURE(rc))
|
---|
213 | {
|
---|
214 | LOGREL(("VBoxMpCrCtlConConnect failed with rc(%d), 3D not supported!"));
|
---|
215 | return false;
|
---|
216 | }
|
---|
217 |
|
---|
218 | rc = VBoxMpCrCtlConDisconnect(&CrCtlCon, u32ClientID);
|
---|
219 | if (RT_FAILURE(rc))
|
---|
220 | WARN(("VBoxMpCrCtlConDisconnect failed, ignoring.."));
|
---|
221 |
|
---|
222 | return true;
|
---|
223 | }
|
---|