VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPCr.cpp@ 41109

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

crOpenGL,wined3d,wddm: second part of fixing resource leakage, basics for cr commands submission from r0 miniport driver (for r0 visible region reporting, WPF 3D rendering fixes w/o Aero, etc.)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 KB
Line 
1/* $Id: VBoxMPCr.cpp 41109 2012-05-02 08:37:46Z 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 <VBox/HostServices/VBoxCrOpenGLSvc.h>
23
24#include <cr_protocol.h>
25
26#if 0
27#include <cr_pack.h>
28
29typedef struct PVBOXMP_SHGSMIPACKER
30{
31 PVBOXMP_DEVEXT pDevExt;
32 CRPackContext CrPacker;
33 CRPackBuffer CrBuffer;
34} PVBOXMP_SHGSMIPACKER, *PPVBOXMP_SHGSMIPACKER;
35
36static void* vboxMpCrShgsmiBufferAlloc(PVBOXMP_DEVEXT pDevExt, HGSMISIZE cbData)
37{
38 return VBoxSHGSMIHeapBufferAlloc(&VBoxCommonFromDeviceExt(pDevExt)->guestCtx.heapCtx, cbData);
39}
40
41static void vboxMpCrShgsmiBufferFree(PVBOXMP_DEVEXT pDevExt, void *pvBuffer)
42{
43 VBoxSHGSMIHeapBufferFree(&VBoxCommonFromDeviceExt(pDevExt)->guestCtx.heapCtx, pvBuffer);
44}
45
46static void vboxMpCrShgsmiPackerCbFlush(void *pvFlush)
47{
48 PPVBOXMP_SHGSMIPACKER pPacker = (PPVBOXMP_SHGSMIPACKER)pvFlush;
49
50 crPackReleaseBuffer(&pPacker->CrPacker);
51
52 if (pPacker->CrBuffer.opcode_current != pPacker->CrBuffer.opcode_start)
53 {
54 CRMessageOpcodes *pHdr;
55 unsigned int len;
56 pHdr = vboxMpCrPackerPrependHeader(&pPacker->CrBuffer, &len, 0);
57
58 /*Send*/
59 }
60
61
62 crPackSetBuffer(&pPacker->CrPacker, &pPacker->CrBuffer);
63 crPackResetPointers(&pPacker->CrPacker);
64}
65
66static int vboxMpCrShgsmiPackerInit(PPVBOXMP_SHGSMIPACKER pPacker, PVBOXMP_DEVEXT pDevExt)
67{
68 memset(pPacker, 0, sizeof (*pPacker));
69
70 static const cbBuffer = 1000;
71 void *pvBuffer = vboxMpCrShgsmiBufferAlloc(pDevExt, cbBuffer);
72 if (!pvBuffer)
73 {
74 WARN(("vboxMpCrShgsmiBufferAlloc failed"));
75 return VERR_NO_MEMORY;
76 }
77 crPackInitBuffer(&pPacker->CrBuffer, pvBuffer, cbBuffer, cbBuffer);
78 crPackSetBuffer(&pPacker->CrPacker, &pPacker->CrBuffer);
79 crPackFlushFunc(&pPacker->CrPacker, vboxMpCrShgsmiPackerCbFlush);
80 crPackFlushArg(&pPacker->CrPacker, pPacker);
81// crPackSendHugeFunc( thread->packer, packspuHuge );
82 return VINF_SUCCESS;
83}
84#endif
85
86static int vboxMpCrCtlAddRef(PVBOXMP_CRCTLCON pCrCtlCon)
87{
88 if (pCrCtlCon->cCrCtlRefs++)
89 return VINF_ALREADY_INITIALIZED;
90
91 int rc = vboxCrCtlCreate(&pCrCtlCon->hCrCtl);
92 if (RT_SUCCESS(rc))
93 {
94 Assert(pCrCtlCon->hCrCtl);
95 return VINF_SUCCESS;
96 }
97
98 WARN(("vboxCrCtlCreate failed, rc (%d)", rc));
99
100 --pCrCtlCon->cCrCtlRefs;
101 return rc;
102}
103
104static int vboxMpCrCtlRelease(PVBOXMP_CRCTLCON pCrCtlCon)
105{
106 Assert(pCrCtlCon->cCrCtlRefs);
107 if (--pCrCtlCon->cCrCtlRefs)
108 {
109 return VINF_SUCCESS;
110 }
111
112 int rc = vboxCrCtlDestroy(pCrCtlCon->hCrCtl);
113 if (RT_SUCCESS(rc))
114 {
115 pCrCtlCon->hCrCtl = NULL;
116 return VINF_SUCCESS;
117 }
118
119 WARN(("vboxCrCtlDestroy failed, rc (%d)", rc));
120
121 ++pCrCtlCon->cCrCtlRefs;
122 return rc;
123}
124
125static int vboxMpCrCtlConSetVersion(PVBOXMP_CRCTLCON pCrCtlCon, uint32_t u32ClientID, uint32_t vMajor, uint32_t vMinor)
126{
127 CRVBOXHGCMSETVERSION parms;
128 int rc;
129
130 parms.hdr.result = VERR_WRONG_ORDER;
131 parms.hdr.u32ClientID = u32ClientID;
132 parms.hdr.u32Function = SHCRGL_GUEST_FN_SET_VERSION;
133 parms.hdr.cParms = SHCRGL_CPARMS_SET_VERSION;
134
135 parms.vMajor.type = VMMDevHGCMParmType_32bit;
136 parms.vMajor.u.value32 = vMajor;
137 parms.vMinor.type = VMMDevHGCMParmType_32bit;
138 parms.vMinor.u.value32 = vMinor;
139
140 rc = vboxCrCtlConCall(pCrCtlCon->hCrCtl, &parms.hdr, sizeof (parms));
141 if (RT_FAILURE(rc))
142 {
143 WARN(("vboxCrCtlConCall failed, rc (%d)", rc));
144 return rc;
145 }
146
147 if (RT_FAILURE(parms.hdr.result))
148 {
149 WARN(("version validation failed, rc (%d)", parms.hdr.result));
150 return parms.hdr.result;
151 }
152 return VINF_SUCCESS;
153}
154
155static int vboxMpCrCtlConSetPID(PVBOXMP_CRCTLCON pCrCtlCon, uint32_t u32ClientID)
156{
157 CRVBOXHGCMSETPID parms;
158 int rc;
159
160 parms.hdr.result = VERR_WRONG_ORDER;
161 parms.hdr.u32ClientID = u32ClientID;
162 parms.hdr.u32Function = SHCRGL_GUEST_FN_SET_PID;
163 parms.hdr.cParms = SHCRGL_CPARMS_SET_PID;
164
165 parms.u64PID.type = VMMDevHGCMParmType_64bit;
166 parms.u64PID.u.value64 = (uint64_t)PsGetCurrentProcessId();
167
168 Assert(parms.u64PID.u.value64);
169
170 rc = vboxCrCtlConCall(pCrCtlCon->hCrCtl, &parms.hdr, sizeof (parms));
171 if (RT_FAILURE(rc))
172 {
173 WARN(("vboxCrCtlConCall failed, rc (%d)", rc));
174 return rc;
175 }
176
177 if (RT_FAILURE(parms.hdr.result))
178 {
179 WARN(("set PID failed, rc (%d)", parms.hdr.result));
180 return parms.hdr.result;
181 }
182 return VINF_SUCCESS;
183}
184
185int VBoxMpCrCtlConConnect(PVBOXMP_CRCTLCON pCrCtlCon,
186 uint32_t crVersionMajor, uint32_t crVersionMinor,
187 uint32_t *pu32ClientID)
188{
189 uint32_t u32ClientID;
190 int rc = vboxMpCrCtlAddRef(pCrCtlCon);
191 if (RT_SUCCESS(rc))
192 {
193 rc = vboxCrCtlConConnect(pCrCtlCon->hCrCtl, &u32ClientID);
194 if (RT_SUCCESS(rc))
195 {
196 rc = vboxMpCrCtlConSetVersion(pCrCtlCon, u32ClientID, crVersionMajor, crVersionMinor);
197 if (RT_SUCCESS(rc))
198 {
199 rc = vboxMpCrCtlConSetPID(pCrCtlCon, u32ClientID);
200 if (RT_SUCCESS(rc))
201 {
202 *pu32ClientID = u32ClientID;
203 return VINF_SUCCESS;
204 }
205 else
206 {
207 WARN(("vboxMpCrCtlConSetPID failed, rc (%d)", rc));
208 }
209 }
210 else
211 {
212 WARN(("vboxMpCrCtlConSetVersion failed, rc (%d)", rc));
213 }
214 vboxCrCtlConDisconnect(pCrCtlCon->hCrCtl, u32ClientID);
215 }
216 else
217 {
218 WARN(("vboxCrCtlConConnect failed, rc (%d)", rc));
219 }
220 vboxMpCrCtlRelease(pCrCtlCon);
221 }
222 else
223 {
224 WARN(("vboxMpCrCtlAddRef failed, rc (%d)", rc));
225 }
226
227 *pu32ClientID = 0;
228 Assert(RT_FAILURE(rc));
229 return rc;
230}
231
232int VBoxMpCrCtlConDisconnect(PVBOXMP_CRCTLCON pCrCtlCon, uint32_t u32ClientID)
233{
234 int rc = vboxCrCtlConDisconnect(pCrCtlCon->hCrCtl, u32ClientID);
235 if (RT_SUCCESS(rc))
236 {
237 vboxMpCrCtlRelease(pCrCtlCon);
238 return VINF_SUCCESS;
239 }
240 else
241 {
242 WARN(("vboxCrCtlConDisconnect failed, rc (%d)", rc));
243 }
244 return rc;
245}
246
247int VBoxMpCrCtlConCall(PVBOXMP_CRCTLCON pCrCtlCon, VBoxGuestHGCMCallInfo *pData, uint32_t cbData)
248{
249 int rc = vboxCrCtlConCall(pCrCtlCon->hCrCtl, pData, cbData);
250 if (RT_SUCCESS(rc))
251 return VINF_SUCCESS;
252
253 WARN(("vboxCrCtlConCallUserData failed, rc(%d)", rc));
254 return rc;
255}
256
257int VBoxMpCrCtlConCallUserData(PVBOXMP_CRCTLCON pCrCtlCon, VBoxGuestHGCMCallInfo *pData, uint32_t cbData)
258{
259 int rc = vboxCrCtlConCallUserData(pCrCtlCon->hCrCtl, pData, cbData);
260 if (RT_SUCCESS(rc))
261 return VINF_SUCCESS;
262
263 WARN(("vboxCrCtlConCallUserData failed, rc(%d)", rc));
264 return rc;
265}
266
267bool VBoxMpCrCtlConIs3DSupported()
268{
269 VBOXMP_CRCTLCON CrCtlCon = {0};
270 uint32_t u32ClientID = 0;
271 int rc = VBoxMpCrCtlConConnect(&CrCtlCon, CR_PROTOCOL_VERSION_MAJOR, CR_PROTOCOL_VERSION_MINOR, &u32ClientID);
272 if (RT_FAILURE(rc))
273 {
274 LOGREL(("VBoxMpCrCtlConConnect failed with rc(%d), 3D not supported!"));
275 return false;
276 }
277
278 rc = VBoxMpCrCtlConDisconnect(&CrCtlCon, u32ClientID);
279 if (RT_FAILURE(rc))
280 WARN(("VBoxMpCrCtlConDisconnect failed, ignoring.."));
281
282 return true;
283}
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