VirtualBox

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

Last change on this file since 58152 was 46521, checked in by vboxsync, 12 years ago

wine/new: export

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