VirtualBox

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

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

wddm/3d: chromium hgsmi: better alloc/submit engine

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.5 KB
Line 
1#include <VBox/VBoxCrHgsmi.h>
2#include <iprt/err.h>
3
4#include "VBoxUhgsmiKmt.h"
5
6static VBOXCRHGSMI_CALLBACKS g_VBoxCrHgsmiCallbacks;
7static HMODULE g_hVBoxCrHgsmiProvider = NULL;
8static uint32_t g_cVBoxCrHgsmiProvider = 0;
9
10static VBOXDISPKMT_CALLBACKS g_VBoxCrHgsmiKmtCallbacks;
11
12typedef VBOXWDDMDISP_DECL(int) FNVBOXDISPCRHGSMI_INIT(PVBOXCRHGSMI_CALLBACKS pCallbacks);
13typedef FNVBOXDISPCRHGSMI_INIT *PFNVBOXDISPCRHGSMI_INIT;
14
15typedef VBOXWDDMDISP_DECL(int) FNVBOXDISPCRHGSMI_TERM();
16typedef FNVBOXDISPCRHGSMI_TERM *PFNVBOXDISPCRHGSMI_TERM;
17
18typedef VBOXWDDMDISP_DECL(HVBOXCRHGSMI_CLIENT) FNVBOXDISPCRHGSMI_QUERY_CLIENT();
19typedef FNVBOXDISPCRHGSMI_QUERY_CLIENT *PFNVBOXDISPCRHGSMI_QUERY_CLIENT;
20
21static PFNVBOXDISPCRHGSMI_INIT g_pfnVBoxDispCrHgsmiInit = NULL;
22static PFNVBOXDISPCRHGSMI_TERM g_pfnVBoxDispCrHgsmiTerm = NULL;
23static PFNVBOXDISPCRHGSMI_QUERY_CLIENT g_pfnVBoxDispCrHgsmiQueryClient = NULL;
24
25VBOXCRHGSMI_DECL(int) VBoxCrHgsmiInit(PVBOXCRHGSMI_CALLBACKS pCallbacks)
26{
27 static int bKmtCallbacksInited = 0;
28 if (!bKmtCallbacksInited)
29 {
30 HRESULT hr = vboxDispKmtCallbacksInit(&g_VBoxCrHgsmiKmtCallbacks);
31 Assert(hr == S_OK);
32 if (hr == S_OK)
33 bKmtCallbacksInited = 1;
34 else
35 bKmtCallbacksInited = -1;
36 }
37
38 Assert(bKmtCallbacksInited);
39 if (bKmtCallbacksInited < 0)
40 {
41 Assert(0);
42 return VERR_NOT_SUPPORTED;
43 }
44
45 g_VBoxCrHgsmiCallbacks = *pCallbacks;
46 if (!g_hVBoxCrHgsmiProvider)
47 {
48 BOOL bRc = GetModuleHandleEx(0, L"VBoxDispD3D", &g_hVBoxCrHgsmiProvider);
49// g_hVBoxCrHgsmiProvider = GetModuleHandle(L"VBoxDispD3D");
50 if (bRc)
51 {
52 g_pfnVBoxDispCrHgsmiInit = (PFNVBOXDISPCRHGSMI_INIT)GetProcAddress(g_hVBoxCrHgsmiProvider, "VBoxDispCrHgsmiInit");
53 Assert(g_pfnVBoxDispCrHgsmiInit);
54 if (g_pfnVBoxDispCrHgsmiInit)
55 {
56 g_pfnVBoxDispCrHgsmiInit(pCallbacks);
57 }
58
59 g_pfnVBoxDispCrHgsmiTerm = (PFNVBOXDISPCRHGSMI_TERM)GetProcAddress(g_hVBoxCrHgsmiProvider, "VBoxDispCrHgsmiTerm");
60 Assert(g_pfnVBoxDispCrHgsmiTerm);
61
62 g_pfnVBoxDispCrHgsmiQueryClient = (PFNVBOXDISPCRHGSMI_QUERY_CLIENT)GetProcAddress(g_hVBoxCrHgsmiProvider, "VBoxDispCrHgsmiQueryClient");
63 Assert(g_pfnVBoxDispCrHgsmiQueryClient);
64 }
65#ifdef DEBUG_misha
66 else
67 {
68 DWORD winEr = GetLastError();
69 Assert(0);
70 }
71#endif
72 }
73
74 if (g_hVBoxCrHgsmiProvider)
75 {
76 if (g_pfnVBoxDispCrHgsmiInit)
77 {
78 g_pfnVBoxDispCrHgsmiInit(pCallbacks);
79 }
80 ++g_cVBoxCrHgsmiProvider;
81 return VINF_SUCCESS;
82 }
83
84 /* we're called from ogl ICD driver*/
85 Assert(0);
86
87 return VINF_SUCCESS;
88}
89
90static __declspec(thread) PVBOXUHGSMI_PRIVATE_KMT gt_pHgsmiGL = NULL;
91
92VBOXCRHGSMI_DECL(HVBOXCRHGSMI_CLIENT) VBoxCrHgsmiQueryClient()
93{
94
95 HVBOXCRHGSMI_CLIENT hClient;
96 if (g_pfnVBoxDispCrHgsmiQueryClient)
97 {
98 hClient = g_pfnVBoxDispCrHgsmiQueryClient();
99//#ifdef DEBUG_misha
100// Assert(hClient);
101//#endif
102 if (hClient)
103 return hClient;
104 }
105 PVBOXUHGSMI_PRIVATE_KMT pHgsmiGL = gt_pHgsmiGL;
106 if (pHgsmiGL)
107 {
108 Assert(pHgsmiGL->BasePrivate.hClient);
109 return pHgsmiGL->BasePrivate.hClient;
110 }
111 pHgsmiGL = (PVBOXUHGSMI_PRIVATE_KMT)RTMemAllocZ(sizeof (*pHgsmiGL));
112 if (pHgsmiGL)
113 {
114#if 0
115 HRESULT hr = vboxUhgsmiKmtCreate(pHgsmiGL, TRUE /* bD3D tmp for injection thread*/);
116#else
117 HRESULT hr = vboxUhgsmiKmtEscCreate(pHgsmiGL, TRUE /* bD3D tmp for injection thread*/);
118#endif
119 Assert(hr == S_OK);
120 if (hr == S_OK)
121 {
122 hClient = g_VBoxCrHgsmiCallbacks.pfnClientCreate(&pHgsmiGL->BasePrivate.Base);
123 Assert(hClient);
124 pHgsmiGL->BasePrivate.hClient = hClient;
125 gt_pHgsmiGL = pHgsmiGL;
126 }
127 }
128 else
129 hClient = NULL;
130 return hClient;
131}
132
133VBOXCRHGSMI_DECL(int) VBoxCrHgsmiTerm()
134{
135 Assert(0);
136#if 0
137 PVBOXUHGSMI_PRIVATE_KMT pHgsmiGL = gt_pHgsmiGL;
138 if (pHgsmiGL)
139 {
140 g_VBoxCrHgsmiCallbacks.pfnClientDestroy(pHgsmiGL->BasePrivate.hClient);
141 vboxUhgsmiKmtDestroy(pHgsmiGL);
142 gt_pHgsmiGL = NULL;
143 }
144
145 if (g_pfnVBoxDispCrHgsmiTerm)
146 g_pfnVBoxDispCrHgsmiTerm();
147#endif
148 return VINF_SUCCESS;
149}
150
151VBOXCRHGSMI_DECL(void) VBoxCrHgsmiLog(char * szString)
152{
153 VBOXDISPKMT_ADAPTER Adapter;
154 HRESULT hr = vboxDispKmtOpenAdapter(&g_VBoxCrHgsmiKmtCallbacks, &Adapter);
155 Assert(hr == S_OK);
156 if (hr == S_OK)
157 {
158 uint32_t cbString = (uint32_t)strlen(szString) + 1;
159 uint32_t cbCmd = RT_OFFSETOF(VBOXDISPIFESCAPE_DBGPRINT, aStringBuf[cbString]);
160 PVBOXDISPIFESCAPE_DBGPRINT pCmd = (PVBOXDISPIFESCAPE_DBGPRINT)RTMemAllocZ(cbCmd);
161 Assert(pCmd);
162 if (pCmd)
163 {
164 pCmd->EscapeHdr.escapeCode = VBOXESC_DBGPRINT;
165 memcpy(pCmd->aStringBuf, szString, cbString);
166
167 D3DKMT_ESCAPE EscapeData = {0};
168 EscapeData.hAdapter = Adapter.hAdapter;
169 //EscapeData.hDevice = NULL;
170 EscapeData.Type = D3DKMT_ESCAPE_DRIVERPRIVATE;
171 // EscapeData.Flags.HardwareAccess = 1;
172 EscapeData.pPrivateDriverData = pCmd;
173 EscapeData.PrivateDriverDataSize = cbCmd;
174 //EscapeData.hContext = NULL;
175
176 int Status = g_VBoxCrHgsmiKmtCallbacks.pfnD3DKMTEscape(&EscapeData);
177 Assert(!Status);
178
179 RTMemFree(pCmd);
180 }
181 hr = vboxDispKmtCloseAdapter(&Adapter);
182 Assert(hr == S_OK);
183 }
184}
185
186///* to be used by injection thread and by ogl ICD driver for hgsmi initialization*/
187//VBOXCRHGSMI_DECL(int) VBoxCrHgsmiCustomCreate(PVBOXUHGSMI *ppHgsmi)
188//{
189// PVBOXUHGSMI_PRIVATE_KMT pHgsmi = RTMemAllocZ(sizeof (*pHgsmi));
190// if (pHgsmi)
191// {
192// HRESULT hr = vboxUhgsmiKmtCreate(pHgsmi, FALSE);
193// Assert(hr == S_OK);
194// if (hr == S_OK)
195// {
196// *ppHgsmi = &pHgsmi->BasePrivate.Base;
197// return VINF_SUCCESS;
198// }
199// RTMemFree(pHgsmi);
200// return VERR_GENERAL_FAILURE;
201// }
202// return VERR_NO_MEMORY;
203//}
204//
205//VBOXCRHGSMI_DECL(int) VBoxCrHgsmiCustomDestroy(PVBOXUHGSMI pHgsmi)
206//{
207// PVBOXUHGSMI_PRIVATE_KMT pHgsmiKmt = VBOXUHGSMIKMT_GET(pHgsmi);
208// HRESULT hr = vboxUhgsmiKmtDestroy(pHgsmiKmt, FALSE);
209// Assert(hr == S_OK);
210// if (hr == S_OK)
211// {
212// RTMemFree(pHgsmiKmt);
213// return VINF_SUCCESS;
214// }
215// return VERR_GENERAL_FAILURE;
216//}
217
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