VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxCrHgsmi.cpp@ 34894

Last change on this file since 34894 was 34894, checked in by vboxsync, 14 years ago

crOpenGL/xpdm: comment out asserts

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.5 KB
Line 
1#include <VBox/VBoxCrHgsmi.h>
2#include <iprt/err.h>
3
4#include "VBoxUhgsmiKmt.h"
5
6static VBOXDISPKMT_CALLBACKS g_VBoxCrHgsmiKmtCallbacks;
7static int g_bVBoxKmtCallbacksInited = 0;
8
9#ifdef VBOX_CRHGSMI_WITH_D3DDEV
10static VBOXCRHGSMI_CALLBACKS g_VBoxCrHgsmiCallbacks;
11static HMODULE g_hVBoxCrHgsmiProvider = NULL;
12static uint32_t g_cVBoxCrHgsmiProvider = 0;
13
14
15typedef VBOXWDDMDISP_DECL(int) FNVBOXDISPCRHGSMI_INIT(PVBOXCRHGSMI_CALLBACKS pCallbacks);
16typedef FNVBOXDISPCRHGSMI_INIT *PFNVBOXDISPCRHGSMI_INIT;
17
18typedef VBOXWDDMDISP_DECL(int) FNVBOXDISPCRHGSMI_TERM();
19typedef FNVBOXDISPCRHGSMI_TERM *PFNVBOXDISPCRHGSMI_TERM;
20
21typedef VBOXWDDMDISP_DECL(HVBOXCRHGSMI_CLIENT) FNVBOXDISPCRHGSMI_QUERY_CLIENT();
22typedef FNVBOXDISPCRHGSMI_QUERY_CLIENT *PFNVBOXDISPCRHGSMI_QUERY_CLIENT;
23
24static PFNVBOXDISPCRHGSMI_INIT g_pfnVBoxDispCrHgsmiInit = NULL;
25static PFNVBOXDISPCRHGSMI_TERM g_pfnVBoxDispCrHgsmiTerm = NULL;
26static PFNVBOXDISPCRHGSMI_QUERY_CLIENT g_pfnVBoxDispCrHgsmiQueryClient = NULL;
27
28VBOXCRHGSMI_DECL(int) VBoxCrHgsmiInit(PVBOXCRHGSMI_CALLBACKS pCallbacks)
29{
30 if (!g_bVBoxKmtCallbacksInited)
31 {
32 HRESULT hr = vboxDispKmtCallbacksInit(&g_VBoxCrHgsmiKmtCallbacks);
33 Assert(hr == S_OK);
34 if (hr == S_OK)
35 g_bVBoxKmtCallbacksInited = 1;
36 else
37 g_bVBoxKmtCallbacksInited = -1;
38 }
39
40 Assert(g_bVBoxKmtCallbacksInited);
41 if (g_bVBoxKmtCallbacksInited < 0)
42 {
43 Assert(0);
44 return VERR_NOT_SUPPORTED;
45 }
46
47 g_VBoxCrHgsmiCallbacks = *pCallbacks;
48 if (!g_hVBoxCrHgsmiProvider)
49 {
50 BOOL bRc = GetModuleHandleEx(0, L"VBoxDispD3D", &g_hVBoxCrHgsmiProvider);
51// g_hVBoxCrHgsmiProvider = GetModuleHandle(L"VBoxDispD3D");
52 if (bRc)
53 {
54 g_pfnVBoxDispCrHgsmiInit = (PFNVBOXDISPCRHGSMI_INIT)GetProcAddress(g_hVBoxCrHgsmiProvider, "VBoxDispCrHgsmiInit");
55 Assert(g_pfnVBoxDispCrHgsmiInit);
56 if (g_pfnVBoxDispCrHgsmiInit)
57 {
58 g_pfnVBoxDispCrHgsmiInit(pCallbacks);
59 }
60
61 g_pfnVBoxDispCrHgsmiTerm = (PFNVBOXDISPCRHGSMI_TERM)GetProcAddress(g_hVBoxCrHgsmiProvider, "VBoxDispCrHgsmiTerm");
62 Assert(g_pfnVBoxDispCrHgsmiTerm);
63
64 g_pfnVBoxDispCrHgsmiQueryClient = (PFNVBOXDISPCRHGSMI_QUERY_CLIENT)GetProcAddress(g_hVBoxCrHgsmiProvider, "VBoxDispCrHgsmiQueryClient");
65 Assert(g_pfnVBoxDispCrHgsmiQueryClient);
66 }
67#ifdef DEBUG_misha
68 else
69 {
70 DWORD winEr = GetLastError();
71 Assert(0);
72 }
73#endif
74 }
75
76 if (g_hVBoxCrHgsmiProvider)
77 {
78 if (g_pfnVBoxDispCrHgsmiInit)
79 {
80 g_pfnVBoxDispCrHgsmiInit(pCallbacks);
81 }
82 ++g_cVBoxCrHgsmiProvider;
83 return VINF_SUCCESS;
84 }
85
86 /* we're called from ogl ICD driver*/
87 Assert(0);
88
89 return VINF_SUCCESS;
90}
91
92static __declspec(thread) PVBOXUHGSMI_PRIVATE_KMT gt_pHgsmiGL = NULL;
93
94VBOXCRHGSMI_DECL(HVBOXCRHGSMI_CLIENT) VBoxCrHgsmiQueryClient()
95{
96
97 HVBOXCRHGSMI_CLIENT hClient;
98 if (g_pfnVBoxDispCrHgsmiQueryClient)
99 {
100 hClient = g_pfnVBoxDispCrHgsmiQueryClient();
101//#ifdef DEBUG_misha
102// Assert(hClient);
103//#endif
104 if (hClient)
105 return hClient;
106 }
107 PVBOXUHGSMI_PRIVATE_KMT pHgsmiGL = gt_pHgsmiGL;
108 if (pHgsmiGL)
109 {
110 Assert(pHgsmiGL->BasePrivate.hClient);
111 return pHgsmiGL->BasePrivate.hClient;
112 }
113 pHgsmiGL = (PVBOXUHGSMI_PRIVATE_KMT)RTMemAllocZ(sizeof (*pHgsmiGL));
114 if (pHgsmiGL)
115 {
116#if 0
117 HRESULT hr = vboxUhgsmiKmtCreate(pHgsmiGL, TRUE /* bD3D tmp for injection thread*/);
118#else
119 HRESULT hr = vboxUhgsmiKmtEscCreate(pHgsmiGL, TRUE /* bD3D tmp for injection thread*/);
120#endif
121 Assert(hr == S_OK);
122 if (hr == S_OK)
123 {
124 hClient = g_VBoxCrHgsmiCallbacks.pfnClientCreate(&pHgsmiGL->BasePrivate.Base);
125 Assert(hClient);
126 if (hClient)
127 {
128 pHgsmiGL->BasePrivate.hClient = hClient;
129 gt_pHgsmiGL = pHgsmiGL;
130 return hClient;
131 }
132 vboxUhgsmiKmtDestroy(pHgsmiGL);
133 }
134 RTMemFree(pHgsmiGL);
135 }
136
137 return NULL;
138}
139#else
140static int vboxCrHgsmiInitPerform(VBOXDISPKMT_CALLBACKS *pCallbacks)
141{
142 HRESULT hr = vboxDispKmtCallbacksInit(pCallbacks);
143 /*Assert(hr == S_OK);*/
144 if (hr == S_OK)
145 {
146 /* check if we can create the hgsmi */
147 PVBOXUHGSMI pHgsmi = VBoxCrHgsmiCreate();
148 if (pHgsmi)
149 {
150 /* yes, we can, so this is wddm mode */
151 VBoxCrHgsmiDestroy(pHgsmi);
152 Log(("CrHgsmi: WDDM mode supported\n"));
153 return 1;
154 }
155 vboxDispKmtCallbacksTerm(pCallbacks);
156 }
157 Log(("CrHgsmi: unsupported\n"));
158 return -1;
159}
160
161VBOXCRHGSMI_DECL(int) VBoxCrHgsmiInit()
162{
163 if (!g_bVBoxKmtCallbacksInited)
164 {
165 g_bVBoxKmtCallbacksInited = vboxCrHgsmiInitPerform(&g_VBoxCrHgsmiKmtCallbacks);
166 Assert(g_bVBoxKmtCallbacksInited);
167 }
168
169 return g_bVBoxKmtCallbacksInited > 0 ? VINF_SUCCESS : VERR_NOT_SUPPORTED;
170}
171
172VBOXCRHGSMI_DECL(PVBOXUHGSMI) VBoxCrHgsmiCreate()
173{
174 PVBOXUHGSMI_PRIVATE_KMT pHgsmiGL = (PVBOXUHGSMI_PRIVATE_KMT)RTMemAllocZ(sizeof (*pHgsmiGL));
175 if (pHgsmiGL)
176 {
177#if 0
178 HRESULT hr = vboxUhgsmiKmtCreate(pHgsmiGL, TRUE /* bD3D tmp for injection thread*/);
179#else
180 HRESULT hr = vboxUhgsmiKmtEscCreate(pHgsmiGL, TRUE /* bD3D tmp for injection thread*/);
181#endif
182 Log(("CrHgsmi: faled to create KmtEsc UHGSMI instance, hr (0x%x)\n", hr));
183 if (hr == S_OK)
184 {
185 return &pHgsmiGL->BasePrivate.Base;
186 }
187 RTMemFree(pHgsmiGL);
188 }
189
190 return NULL;
191}
192
193VBOXCRHGSMI_DECL(void) VBoxCrHgsmiDestroy(PVBOXUHGSMI pHgsmi)
194{
195 PVBOXUHGSMI_PRIVATE_KMT pHgsmiGL = VBOXUHGSMIKMT_GET(pHgsmi);
196 HRESULT hr = vboxUhgsmiKmtDestroy(pHgsmiGL);
197 Assert(hr == S_OK);
198 if (hr == S_OK)
199 {
200 RTMemFree(pHgsmiGL);
201 }
202}
203#endif
204
205VBOXCRHGSMI_DECL(int) VBoxCrHgsmiTerm()
206{
207#if 0
208 PVBOXUHGSMI_PRIVATE_KMT pHgsmiGL = gt_pHgsmiGL;
209 if (pHgsmiGL)
210 {
211 g_VBoxCrHgsmiCallbacks.pfnClientDestroy(pHgsmiGL->BasePrivate.hClient);
212 vboxUhgsmiKmtDestroy(pHgsmiGL);
213 gt_pHgsmiGL = NULL;
214 }
215
216 if (g_pfnVBoxDispCrHgsmiTerm)
217 g_pfnVBoxDispCrHgsmiTerm();
218#endif
219 if (g_bVBoxKmtCallbacksInited > 0)
220 {
221 vboxDispKmtCallbacksTerm(&g_VBoxCrHgsmiKmtCallbacks);
222 }
223 return VINF_SUCCESS;
224}
225
226VBOXCRHGSMI_DECL(void) VBoxCrHgsmiLog(char * szString)
227{
228 VBOXDISPKMT_ADAPTER Adapter;
229 HRESULT hr = vboxDispKmtOpenAdapter(&g_VBoxCrHgsmiKmtCallbacks, &Adapter);
230 Assert(hr == S_OK);
231 if (hr == S_OK)
232 {
233 uint32_t cbString = (uint32_t)strlen(szString) + 1;
234 uint32_t cbCmd = RT_OFFSETOF(VBOXDISPIFESCAPE_DBGPRINT, aStringBuf[cbString]);
235 PVBOXDISPIFESCAPE_DBGPRINT pCmd = (PVBOXDISPIFESCAPE_DBGPRINT)RTMemAllocZ(cbCmd);
236 Assert(pCmd);
237 if (pCmd)
238 {
239 pCmd->EscapeHdr.escapeCode = VBOXESC_DBGPRINT;
240 memcpy(pCmd->aStringBuf, szString, cbString);
241
242 D3DKMT_ESCAPE EscapeData = {0};
243 EscapeData.hAdapter = Adapter.hAdapter;
244 //EscapeData.hDevice = NULL;
245 EscapeData.Type = D3DKMT_ESCAPE_DRIVERPRIVATE;
246 // EscapeData.Flags.HardwareAccess = 1;
247 EscapeData.pPrivateDriverData = pCmd;
248 EscapeData.PrivateDriverDataSize = cbCmd;
249 //EscapeData.hContext = NULL;
250
251 int Status = g_VBoxCrHgsmiKmtCallbacks.pfnD3DKMTEscape(&EscapeData);
252 Assert(!Status);
253
254 RTMemFree(pCmd);
255 }
256 hr = vboxDispKmtCloseAdapter(&Adapter);
257 Assert(hr == S_OK);
258 }
259}
260
261///* to be used by injection thread and by ogl ICD driver for hgsmi initialization*/
262//VBOXCRHGSMI_DECL(int) VBoxCrHgsmiCustomCreate(PVBOXUHGSMI *ppHgsmi)
263//{
264// PVBOXUHGSMI_PRIVATE_KMT pHgsmi = RTMemAllocZ(sizeof (*pHgsmi));
265// if (pHgsmi)
266// {
267// HRESULT hr = vboxUhgsmiKmtCreate(pHgsmi, FALSE);
268// Assert(hr == S_OK);
269// if (hr == S_OK)
270// {
271// *ppHgsmi = &pHgsmi->BasePrivate.Base;
272// return VINF_SUCCESS;
273// }
274// RTMemFree(pHgsmi);
275// return VERR_GENERAL_FAILURE;
276// }
277// return VERR_NO_MEMORY;
278//}
279//
280//VBOXCRHGSMI_DECL(int) VBoxCrHgsmiCustomDestroy(PVBOXUHGSMI pHgsmi)
281//{
282// PVBOXUHGSMI_PRIVATE_KMT pHgsmiKmt = VBOXUHGSMIKMT_GET(pHgsmi);
283// HRESULT hr = vboxUhgsmiKmtDestroy(pHgsmiKmt, FALSE);
284// Assert(hr == S_OK);
285// if (hr == S_OK)
286// {
287// RTMemFree(pHgsmiKmt);
288// return VINF_SUCCESS;
289// }
290// return VERR_GENERAL_FAILURE;
291//}
292
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette