VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/wined3d/vboxext.h@ 73097

Last change on this file since 73097 was 73097, checked in by vboxsync, 6 years ago

*: Made RT_UOFFSETOF, RT_OFFSETOF, RT_UOFFSETOF_ADD and RT_OFFSETOF_ADD work like builtin_offsetof() and require compile time resolvable requests, adding RT_UOFFSETOF_DYN for the dynamic questions that can only be answered at runtime.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.9 KB
Line 
1/* $Id: vboxext.h 73097 2018-07-12 21:06:33Z vboxsync $ */
2/** @file
3 * VBox extension to Wine D3D
4 */
5
6/*
7 * Copyright (C) 2011-2017 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef ___VBOXEXT_H__
19#define ___VBOXEXT_H__
20
21#ifdef VBOX_WINE_WITHOUT_LIBWINE
22# include <iprt/win/windows.h>
23#endif
24
25#include <iprt/list.h>
26
27HRESULT VBoxExtCheckInit(void);
28HRESULT VBoxExtCheckTerm(void);
29#if defined(VBOX_WINE_WITH_SINGLE_CONTEXT) || defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
30# ifndef VBOX_WITH_WDDM
31/* Windows destroys HDC created by a given thread when the thread is terminated
32 * this leads to a mess-up in Wine & Chromium code in some situations, e.g.
33 * D3D device is created in one thread, then the thread is terminated,
34 * then device is started to be used in another thread */
35HDC VBoxExtGetDC(HWND hWnd);
36int VBoxExtReleaseDC(HWND hWnd, HDC hDC);
37# endif
38/* We need to do a VBoxTlsRefRelease for the current thread context on thread exit to avoid memory leaking
39 * Calling VBoxTlsRefRelease may result in a call to context dtor callback, which is supposed to be run under wined3d lock.
40 * We can not acquire a wined3d lock in DllMain since this would result in a lock order violation, which may result in a deadlock.
41 * In other words, wined3d may internally call Win32 API functions which result in a DLL lock acquisition while holding wined3d lock.
42 * So lock order should always be "wined3d lock" -> "dll lock".
43 * To avoid possible deadlocks we make an asynchronous call to a worker thread to make a context release from there. */
44struct wined3d_context;
45void VBoxExtReleaseContextAsync(struct wined3d_context *context);
46#endif
47
48/* API for creating & destroying windows */
49HRESULT VBoxExtWndDestroy(HWND hWnd, HDC hDC);
50HRESULT VBoxExtWndCreate(DWORD width, DWORD height, HWND *phWnd, HDC *phDC);
51
52
53/* hashmap */
54typedef DECLCALLBACK(uint32_t) FNVBOXEXT_HASHMAP_HASH(void *pvKey);
55typedef FNVBOXEXT_HASHMAP_HASH *PFNVBOXEXT_HASHMAP_HASH;
56
57typedef DECLCALLBACK(bool) FNVBOXEXT_HASHMAP_EQUAL(void *pvKey1, void *pvKey2);
58typedef FNVBOXEXT_HASHMAP_EQUAL *PFNVBOXEXT_HASHMAP_EQUAL;
59
60struct VBOXEXT_HASHMAP;
61struct VBOXEXT_HASHMAP_ENTRY;
62typedef DECLCALLBACK(bool) FNVBOXEXT_HASHMAP_VISITOR(struct VBOXEXT_HASHMAP *pMap, void *pvKey, struct VBOXEXT_HASHMAP_ENTRY *pValue, void *pvVisitor);
63typedef FNVBOXEXT_HASHMAP_VISITOR *PFNVBOXEXT_HASHMAP_VISITOR;
64
65typedef struct VBOXEXT_HASHMAP_ENTRY
66{
67 RTLISTNODE ListNode;
68 void *pvKey;
69 uint32_t u32Hash;
70} VBOXEXT_HASHMAP_ENTRY, *PVBOXEXT_HASHMAP_ENTRY;
71
72typedef struct VBOXEXT_HASHMAP_BUCKET
73{
74 RTLISTNODE EntryList;
75} VBOXEXT_HASHMAP_BUCKET, *PVBOXEXT_HASHMAP_BUCKET;
76
77#define VBOXEXT_HASHMAP_NUM_BUCKETS 29
78
79typedef struct VBOXEXT_HASHMAP
80{
81 PFNVBOXEXT_HASHMAP_HASH pfnHash;
82 PFNVBOXEXT_HASHMAP_EQUAL pfnEqual;
83 uint32_t cEntries;
84 VBOXEXT_HASHMAP_BUCKET aBuckets[VBOXEXT_HASHMAP_NUM_BUCKETS];
85} VBOXEXT_HASHMAP, *PVBOXEXT_HASHMAP;
86
87void VBoxExtHashInit(PVBOXEXT_HASHMAP pMap, PFNVBOXEXT_HASHMAP_HASH pfnHash, PFNVBOXEXT_HASHMAP_EQUAL pfnEqual);
88PVBOXEXT_HASHMAP_ENTRY VBoxExtHashPut(PVBOXEXT_HASHMAP pMap, void *pvKey, PVBOXEXT_HASHMAP_ENTRY pEntry);
89PVBOXEXT_HASHMAP_ENTRY VBoxExtHashGet(PVBOXEXT_HASHMAP pMap, void *pvKey);
90PVBOXEXT_HASHMAP_ENTRY VBoxExtHashRemove(PVBOXEXT_HASHMAP pMap, void *pvKey);
91void* VBoxExtHashRemoveEntry(PVBOXEXT_HASHMAP pMap, PVBOXEXT_HASHMAP_ENTRY pEntry);
92void VBoxExtHashVisit(PVBOXEXT_HASHMAP pMap, PFNVBOXEXT_HASHMAP_VISITOR pfnVisitor, void *pvVisitor);
93void VBoxExtHashCleanup(PVBOXEXT_HASHMAP pMap, PFNVBOXEXT_HASHMAP_VISITOR pfnVisitor, void *pvVisitor);
94
95DECLINLINE(uint32_t) VBoxExtHashSize(PVBOXEXT_HASHMAP pMap)
96{
97 return pMap->cEntries;
98}
99
100DECLINLINE(void*) VBoxExtHashEntryKey(PVBOXEXT_HASHMAP_ENTRY pEntry)
101{
102 return pEntry->pvKey;
103}
104
105struct VBOXEXT_HASHCACHE_ENTRY;
106typedef DECLCALLBACK(void) FNVBOXEXT_HASHCACHE_CLEANUP_ENTRY(void *pvKey, struct VBOXEXT_HASHCACHE_ENTRY *pEntry);
107typedef FNVBOXEXT_HASHCACHE_CLEANUP_ENTRY *PFNVBOXEXT_HASHCACHE_CLEANUP_ENTRY;
108
109typedef struct VBOXEXT_HASHCACHE_ENTRY
110{
111 VBOXEXT_HASHMAP_ENTRY MapEntry;
112 uint32_t u32Usage;
113} VBOXEXT_HASHCACHE_ENTRY, *PVBOXEXT_HASHCACHE_ENTRY;
114
115typedef struct VBOXEXT_HASHCACHE
116{
117 VBOXEXT_HASHMAP Map;
118 uint32_t cMaxElements;
119 PFNVBOXEXT_HASHCACHE_CLEANUP_ENTRY pfnCleanupEntry;
120} VBOXEXT_HASHCACHE, *PVBOXEXT_HASHCACHE;
121
122#define VBOXEXT_HASHCACHE_FROM_MAP(_pMap) RT_FROM_MEMBER((_pMap), VBOXEXT_HASHCACHE, Map)
123#define VBOXEXT_HASHCACHE_ENTRY_FROM_MAP(_pEntry) RT_FROM_MEMBER((_pEntry), VBOXEXT_HASHCACHE_ENTRY, MapEntry)
124
125DECLINLINE(void) VBoxExtCacheInit(PVBOXEXT_HASHCACHE pCache, uint32_t cMaxElements,
126 PFNVBOXEXT_HASHMAP_HASH pfnHash,
127 PFNVBOXEXT_HASHMAP_EQUAL pfnEqual,
128 PFNVBOXEXT_HASHCACHE_CLEANUP_ENTRY pfnCleanupEntry)
129{
130 VBoxExtHashInit(&pCache->Map, pfnHash, pfnEqual);
131 pCache->cMaxElements = cMaxElements;
132 pCache->pfnCleanupEntry = pfnCleanupEntry;
133}
134
135DECLINLINE(PVBOXEXT_HASHCACHE_ENTRY) VBoxExtCacheGet(PVBOXEXT_HASHCACHE pCache, void *pvKey)
136{
137 PVBOXEXT_HASHMAP_ENTRY pEntry = VBoxExtHashRemove(&pCache->Map, pvKey);
138 return VBOXEXT_HASHCACHE_ENTRY_FROM_MAP(pEntry);
139}
140
141DECLINLINE(void) VBoxExtCachePut(PVBOXEXT_HASHCACHE pCache, void *pvKey, PVBOXEXT_HASHCACHE_ENTRY pEntry)
142{
143 PVBOXEXT_HASHMAP_ENTRY pOldEntry = VBoxExtHashPut(&pCache->Map, pvKey, &pEntry->MapEntry);
144 PVBOXEXT_HASHCACHE_ENTRY pOld;
145 if (!pOldEntry)
146 return;
147 pOld = VBOXEXT_HASHCACHE_ENTRY_FROM_MAP(pOldEntry);
148 if (pOld != pEntry)
149 pCache->pfnCleanupEntry(pvKey, pOld);
150}
151
152void VBoxExtCacheCleanup(PVBOXEXT_HASHCACHE pCache);
153
154DECLINLINE(void) VBoxExtCacheTerm(PVBOXEXT_HASHCACHE pCache)
155{
156 VBoxExtCacheCleanup(pCache);
157}
158
159#ifdef VBOX_WINE_WITH_PROFILE
160
161#include <iprt/time.h>
162
163void vboxWDbgPrintF(char * szString, ...);
164
165#define VBOXWINEPROFILE_GET_TIME_NANO() RTTimeNanoTS()
166#define VBOXWINEPROFILE_GET_TIME_MILLI() RTTimeMilliTS()
167
168# define PRLOG(_m) do {\
169 vboxWDbgPrintF _m ; \
170 } while (0)
171
172typedef struct VBOXWINEPROFILE_ELEMENT
173{
174 uint64_t u64Time;
175 uint32_t cu32Calls;
176} VBOXWINEPROFILE_ELEMENT, *PVBOXWINEPROFILE_ELEMENT;
177
178typedef struct VBOXWINEPROFILE_HASHMAP_ELEMENT
179{
180 VBOXEXT_HASHMAP_ENTRY MapEntry;
181 VBOXWINEPROFILE_ELEMENT Data;
182} VBOXWINEPROFILE_HASHMAP_ELEMENT, *PVBOXWINEPROFILE_HASHMAP_ELEMENT;
183
184#define VBOXWINEPROFILE_HASHMAP_ELEMENT_FROMENTRY(_p) ((PVBOXWINEPROFILE_HASHMAP_ELEMENT)(((uint8_t*)(_p)) - RT_UOFFSETOF(VBOXWINEPROFILE_HASHMAP_ELEMENT, MapEntry)))
185
186#define VBOXWINEPROFILE_ELEMENT_DUMP(_p, _pn) do { \
187 PRLOG(("%s: t(%u);c(%u)\n", \
188 (_pn), \
189 (uint32_t)((_p)->u64Time / 1000000), \
190 (_p)->cu32Calls \
191 )); \
192 } while (0)
193
194#define VBOXWINEPROFILE_ELEMENT_RESET(_p) do { \
195 memset(_p, 0, sizeof (*(_p))); \
196 } while (0)
197
198#define VBOXWINEPROFILE_ELEMENT_STEP(_p, _t) do { \
199 (_p)->u64Time += (_t); \
200 ++(_p)->cu32Calls; \
201 } while (0)
202
203#define VBOXWINEPROFILE_HASHMAP_ELEMENT_CREATE() ( (PVBOXWINEPROFILE_HASHMAP_ELEMENT)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof (VBOXWINEPROFILE_HASHMAP_ELEMENT)) )
204
205#define VBOXWINEPROFILE_HASHMAP_ELEMENT_TERM(_pe) do { \
206 HeapFree(GetProcessHeap(), 0, (_pe)); \
207 } while (0)
208
209DECLINLINE(PVBOXWINEPROFILE_HASHMAP_ELEMENT) vboxWineProfileHashMapElementGet(PVBOXEXT_HASHMAP pMap, void *pvKey)
210{
211 PVBOXEXT_HASHMAP_ENTRY pEntry = VBoxExtHashGet(pMap, pvKey);
212 if (pEntry)
213 {
214 return VBOXWINEPROFILE_HASHMAP_ELEMENT_FROMENTRY(pEntry);
215 }
216 else
217 {
218 PVBOXWINEPROFILE_HASHMAP_ELEMENT pElement = VBOXWINEPROFILE_HASHMAP_ELEMENT_CREATE();
219 Assert(pElement);
220 if (pElement)
221 VBoxExtHashPut(pMap, pvKey, &pElement->MapEntry);
222 return pElement;
223 }
224}
225
226#define VBOXWINEPROFILE_HASHMAP_ELEMENT_STEP(_pm, _pk, _t) do { \
227 PVBOXWINEPROFILE_HASHMAP_ELEMENT pElement = vboxWineProfileHashMapElementGet(_pm, _pk); \
228 VBOXWINEPROFILE_ELEMENT_STEP(&pElement->Data, _t); \
229 } while (0)
230
231static DECLCALLBACK(bool) vboxWineProfileElementResetCb(struct VBOXEXT_HASHMAP *pMap, void *pvKey, struct VBOXEXT_HASHMAP_ENTRY *pValue, void *pvVisitor)
232{
233 PVBOXWINEPROFILE_HASHMAP_ELEMENT pElement = VBOXWINEPROFILE_HASHMAP_ELEMENT_FROMENTRY(pValue);
234 VBOXWINEPROFILE_ELEMENT_RESET(&pElement->Data);
235 return true;
236}
237
238static DECLCALLBACK(bool) vboxWineProfileElementDumpCb(struct VBOXEXT_HASHMAP *pMap, void *pvKey, struct VBOXEXT_HASHMAP_ENTRY *pValue, void *pvVisitor)
239{
240 PVBOXWINEPROFILE_HASHMAP_ELEMENT pElement = VBOXWINEPROFILE_HASHMAP_ELEMENT_FROMENTRY(pValue);
241 char *pName = (char*)pvVisitor;
242 PRLOG(("%s[%d]:", pName, (uint32_t)pvKey));
243 VBOXWINEPROFILE_ELEMENT_DUMP(&pElement->Data, "");
244 return true;
245}
246
247
248#define VBOXWINEPROFILE_HASHMAP_RESET(_pm) do { \
249 VBoxExtHashVisit((_pm), vboxWineProfileElementResetCb, NULL); \
250 } while (0)
251
252#define VBOXWINEPROFILE_HASHMAP_DUMP(_pm, _pn) do { \
253 VBoxExtHashVisit((_pm), vboxWineProfileElementDumpCb, (_pn)); \
254 } while (0)
255
256static DECLCALLBACK(bool) vboxWineProfileElementCleanupCb(struct VBOXEXT_HASHMAP *pMap, void *pvKey, struct VBOXEXT_HASHMAP_ENTRY *pValue, void *pvVisitor)
257{
258 PVBOXWINEPROFILE_HASHMAP_ELEMENT pElement = VBOXWINEPROFILE_HASHMAP_ELEMENT_FROMENTRY(pValue);
259 VBOXWINEPROFILE_HASHMAP_ELEMENT_TERM(pElement);
260 return true;
261}
262
263#define VBOXWINEPROFILE_HASHMAP_TERM(_pm) do { \
264 VBoxExtHashCleanup((_pm), vboxWineProfileElementCleanupCb, NULL); \
265 VBoxExtHashVisit((_pm), vboxWineProfileElementResetCb, NULL); \
266 } while (0)
267
268typedef struct VBOXWINEPROFILE_DRAWPRIM
269{
270 uint64_t u64LoadLocationTime;
271 uint64_t u64CtxAcquireTime;
272 uint64_t u64PostProcess;
273 VBOXEXT_HASHMAP MapDrawPrimSlowVs;
274 VBOXEXT_HASHMAP MapDrawPrimSlow;
275 VBOXEXT_HASHMAP MapDrawPrimStrided;
276 VBOXEXT_HASHMAP MapDrawPrimFast;
277 uint32_t cu32Calls;
278} VBOXWINEPROFILE_DRAWPRIM, *PVBOXWINEPROFILE_DRAWPRIM;
279
280#define VBOXWINEPROFILE_DRAWPRIM_RESET_NEXT(_p) do { \
281 (_p)->u64LoadLocationTime = 0; \
282 (_p)->u64CtxAcquireTime = 0; \
283 (_p)->u64PostProcess = 0; \
284 VBOXWINEPROFILE_HASHMAP_RESET(&(_p)->MapDrawPrimSlowVs); \
285 VBOXWINEPROFILE_HASHMAP_RESET(&(_p)->MapDrawPrimSlow); \
286 VBOXWINEPROFILE_HASHMAP_RESET(&(_p)->MapDrawPrimStrided); \
287 VBOXWINEPROFILE_HASHMAP_RESET(&(_p)->MapDrawPrimFast); \
288 } while (0)
289
290static DECLCALLBACK(uint32_t) vboxWineProfileDrawPrimHashMapHash(void *pvKey)
291{
292 return (uint32_t)pvKey;
293}
294
295static DECLCALLBACK(bool) vboxWineProfileDrawPrimHashMapEqual(void *pvKey1, void *pvKey2)
296{
297 return ((uint32_t)pvKey1) == ((uint32_t)pvKey2);
298}
299
300#define VBOXWINEPROFILE_DRAWPRIM_INIT(_p) do { \
301 memset((_p), 0, sizeof (*(_p))); \
302 VBoxExtHashInit(&(_p)->MapDrawPrimSlowVs, vboxWineProfileDrawPrimHashMapHash, vboxWineProfileDrawPrimHashMapEqual); \
303 VBoxExtHashInit(&(_p)->MapDrawPrimSlow, vboxWineProfileDrawPrimHashMapHash, vboxWineProfileDrawPrimHashMapEqual); \
304 VBoxExtHashInit(&(_p)->MapDrawPrimStrided, vboxWineProfileDrawPrimHashMapHash, vboxWineProfileDrawPrimHashMapEqual); \
305 VBoxExtHashInit(&(_p)->MapDrawPrimFast, vboxWineProfileDrawPrimHashMapHash, vboxWineProfileDrawPrimHashMapEqual); \
306 } while (0)
307
308#define VBOXWINEPROFILE_DRAWPRIM_TERM(_p) do { \
309 memset((_p), 0, sizeof (*(_p))); \
310 VBOXWINEPROFILE_HASHMAP_TERM(&(_p)->MapDrawPrimSlowVs); \
311 VBOXWINEPROFILE_HASHMAP_TERM(&(_p)->MapDrawPrimSlow); \
312 VBOXWINEPROFILE_HASHMAP_TERM(&(_p)->MapDrawPrimStrided); \
313 VBOXWINEPROFILE_HASHMAP_TERM(&(_p)->MapDrawPrimFast); \
314 } while (0)
315#else
316# define PRLOG(_m) do {} while (0)
317#endif
318
319#endif /* #ifndef ___VBOXEXT_H__*/
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