1 | /* $Id: vboxext.h 82968 2020-02-04 10:35:17Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox extension to Wine D3D
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2020 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 VBOX_INCLUDED_SRC_Graphics_shaderlib_vboxext_h
|
---|
19 | #define VBOX_INCLUDED_SRC_Graphics_shaderlib_vboxext_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #ifdef VBOX_WINE_WITHOUT_LIBWINE
|
---|
25 | # ifdef _MSC_VER
|
---|
26 | # include <iprt/win/windows.h>
|
---|
27 | # else
|
---|
28 | # include <windows.h>
|
---|
29 | # endif
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | #include <iprt/list.h>
|
---|
33 |
|
---|
34 | HRESULT VBoxExtCheckInit(void);
|
---|
35 | HRESULT VBoxExtCheckTerm(void);
|
---|
36 | #if defined(VBOX_WINE_WITH_SINGLE_CONTEXT) || defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
|
---|
37 | # ifndef VBOX_WITH_WDDM
|
---|
38 | /* Windows destroys HDC created by a given thread when the thread is terminated
|
---|
39 | * this leads to a mess-up in Wine & Chromium code in some situations, e.g.
|
---|
40 | * D3D device is created in one thread, then the thread is terminated,
|
---|
41 | * then device is started to be used in another thread */
|
---|
42 | HDC VBoxExtGetDC(HWND hWnd);
|
---|
43 | int VBoxExtReleaseDC(HWND hWnd, HDC hDC);
|
---|
44 | # endif
|
---|
45 | /* We need to do a VBoxTlsRefRelease for the current thread context on thread exit to avoid memory leaking
|
---|
46 | * Calling VBoxTlsRefRelease may result in a call to context dtor callback, which is supposed to be run under wined3d lock.
|
---|
47 | * We can not acquire a wined3d lock in DllMain since this would result in a lock order violation, which may result in a deadlock.
|
---|
48 | * In other words, wined3d may internally call Win32 API functions which result in a DLL lock acquisition while holding wined3d lock.
|
---|
49 | * So lock order should always be "wined3d lock" -> "dll lock".
|
---|
50 | * To avoid possible deadlocks we make an asynchronous call to a worker thread to make a context release from there. */
|
---|
51 | struct wined3d_context;
|
---|
52 | void VBoxExtReleaseContextAsync(struct wined3d_context *context);
|
---|
53 | #endif
|
---|
54 |
|
---|
55 | /* API for creating & destroying windows */
|
---|
56 | HRESULT VBoxExtWndDestroy(HWND hWnd, HDC hDC);
|
---|
57 | HRESULT VBoxExtWndCreate(DWORD width, DWORD height, HWND *phWnd, HDC *phDC);
|
---|
58 |
|
---|
59 |
|
---|
60 | /* hashmap */
|
---|
61 | typedef DECLCALLBACK(uint32_t) FNVBOXEXT_HASHMAP_HASH(void *pvKey);
|
---|
62 | typedef FNVBOXEXT_HASHMAP_HASH *PFNVBOXEXT_HASHMAP_HASH;
|
---|
63 |
|
---|
64 | typedef DECLCALLBACK(bool) FNVBOXEXT_HASHMAP_EQUAL(void *pvKey1, void *pvKey2);
|
---|
65 | typedef FNVBOXEXT_HASHMAP_EQUAL *PFNVBOXEXT_HASHMAP_EQUAL;
|
---|
66 |
|
---|
67 | struct VBOXEXT_HASHMAP;
|
---|
68 | struct VBOXEXT_HASHMAP_ENTRY;
|
---|
69 | typedef DECLCALLBACK(bool) FNVBOXEXT_HASHMAP_VISITOR(struct VBOXEXT_HASHMAP *pMap, void *pvKey, struct VBOXEXT_HASHMAP_ENTRY *pValue, void *pvVisitor);
|
---|
70 | typedef FNVBOXEXT_HASHMAP_VISITOR *PFNVBOXEXT_HASHMAP_VISITOR;
|
---|
71 |
|
---|
72 | typedef struct VBOXEXT_HASHMAP_ENTRY
|
---|
73 | {
|
---|
74 | RTLISTNODE ListNode;
|
---|
75 | void *pvKey;
|
---|
76 | uint32_t u32Hash;
|
---|
77 | } VBOXEXT_HASHMAP_ENTRY, *PVBOXEXT_HASHMAP_ENTRY;
|
---|
78 |
|
---|
79 | typedef struct VBOXEXT_HASHMAP_BUCKET
|
---|
80 | {
|
---|
81 | RTLISTNODE EntryList;
|
---|
82 | } VBOXEXT_HASHMAP_BUCKET, *PVBOXEXT_HASHMAP_BUCKET;
|
---|
83 |
|
---|
84 | #define VBOXEXT_HASHMAP_NUM_BUCKETS 29
|
---|
85 |
|
---|
86 | typedef struct VBOXEXT_HASHMAP
|
---|
87 | {
|
---|
88 | PFNVBOXEXT_HASHMAP_HASH pfnHash;
|
---|
89 | PFNVBOXEXT_HASHMAP_EQUAL pfnEqual;
|
---|
90 | uint32_t cEntries;
|
---|
91 | VBOXEXT_HASHMAP_BUCKET aBuckets[VBOXEXT_HASHMAP_NUM_BUCKETS];
|
---|
92 | } VBOXEXT_HASHMAP, *PVBOXEXT_HASHMAP;
|
---|
93 |
|
---|
94 | void VBoxExtHashInit(PVBOXEXT_HASHMAP pMap, PFNVBOXEXT_HASHMAP_HASH pfnHash, PFNVBOXEXT_HASHMAP_EQUAL pfnEqual);
|
---|
95 | PVBOXEXT_HASHMAP_ENTRY VBoxExtHashPut(PVBOXEXT_HASHMAP pMap, void *pvKey, PVBOXEXT_HASHMAP_ENTRY pEntry);
|
---|
96 | PVBOXEXT_HASHMAP_ENTRY VBoxExtHashGet(PVBOXEXT_HASHMAP pMap, void *pvKey);
|
---|
97 | PVBOXEXT_HASHMAP_ENTRY VBoxExtHashRemove(PVBOXEXT_HASHMAP pMap, void *pvKey);
|
---|
98 | void* VBoxExtHashRemoveEntry(PVBOXEXT_HASHMAP pMap, PVBOXEXT_HASHMAP_ENTRY pEntry);
|
---|
99 | void VBoxExtHashVisit(PVBOXEXT_HASHMAP pMap, PFNVBOXEXT_HASHMAP_VISITOR pfnVisitor, void *pvVisitor);
|
---|
100 | void VBoxExtHashCleanup(PVBOXEXT_HASHMAP pMap, PFNVBOXEXT_HASHMAP_VISITOR pfnVisitor, void *pvVisitor);
|
---|
101 |
|
---|
102 | DECLINLINE(uint32_t) VBoxExtHashSize(PVBOXEXT_HASHMAP pMap)
|
---|
103 | {
|
---|
104 | return pMap->cEntries;
|
---|
105 | }
|
---|
106 |
|
---|
107 | DECLINLINE(void*) VBoxExtHashEntryKey(PVBOXEXT_HASHMAP_ENTRY pEntry)
|
---|
108 | {
|
---|
109 | return pEntry->pvKey;
|
---|
110 | }
|
---|
111 |
|
---|
112 | struct VBOXEXT_HASHCACHE_ENTRY;
|
---|
113 | typedef DECLCALLBACK(void) FNVBOXEXT_HASHCACHE_CLEANUP_ENTRY(void *pvKey, struct VBOXEXT_HASHCACHE_ENTRY *pEntry);
|
---|
114 | typedef FNVBOXEXT_HASHCACHE_CLEANUP_ENTRY *PFNVBOXEXT_HASHCACHE_CLEANUP_ENTRY;
|
---|
115 |
|
---|
116 | typedef struct VBOXEXT_HASHCACHE_ENTRY
|
---|
117 | {
|
---|
118 | VBOXEXT_HASHMAP_ENTRY MapEntry;
|
---|
119 | uint32_t u32Usage;
|
---|
120 | } VBOXEXT_HASHCACHE_ENTRY, *PVBOXEXT_HASHCACHE_ENTRY;
|
---|
121 |
|
---|
122 | typedef struct VBOXEXT_HASHCACHE
|
---|
123 | {
|
---|
124 | VBOXEXT_HASHMAP Map;
|
---|
125 | uint32_t cMaxElements;
|
---|
126 | PFNVBOXEXT_HASHCACHE_CLEANUP_ENTRY pfnCleanupEntry;
|
---|
127 | } VBOXEXT_HASHCACHE, *PVBOXEXT_HASHCACHE;
|
---|
128 |
|
---|
129 | #define VBOXEXT_HASHCACHE_FROM_MAP(_pMap) RT_FROM_MEMBER((_pMap), VBOXEXT_HASHCACHE, Map)
|
---|
130 | #define VBOXEXT_HASHCACHE_ENTRY_FROM_MAP(_pEntry) RT_FROM_MEMBER((_pEntry), VBOXEXT_HASHCACHE_ENTRY, MapEntry)
|
---|
131 |
|
---|
132 | DECLINLINE(void) VBoxExtCacheInit(PVBOXEXT_HASHCACHE pCache, uint32_t cMaxElements,
|
---|
133 | PFNVBOXEXT_HASHMAP_HASH pfnHash,
|
---|
134 | PFNVBOXEXT_HASHMAP_EQUAL pfnEqual,
|
---|
135 | PFNVBOXEXT_HASHCACHE_CLEANUP_ENTRY pfnCleanupEntry)
|
---|
136 | {
|
---|
137 | VBoxExtHashInit(&pCache->Map, pfnHash, pfnEqual);
|
---|
138 | pCache->cMaxElements = cMaxElements;
|
---|
139 | pCache->pfnCleanupEntry = pfnCleanupEntry;
|
---|
140 | }
|
---|
141 |
|
---|
142 | DECLINLINE(PVBOXEXT_HASHCACHE_ENTRY) VBoxExtCacheGet(PVBOXEXT_HASHCACHE pCache, void *pvKey)
|
---|
143 | {
|
---|
144 | PVBOXEXT_HASHMAP_ENTRY pEntry = VBoxExtHashRemove(&pCache->Map, pvKey);
|
---|
145 | return VBOXEXT_HASHCACHE_ENTRY_FROM_MAP(pEntry);
|
---|
146 | }
|
---|
147 |
|
---|
148 | DECLINLINE(void) VBoxExtCachePut(PVBOXEXT_HASHCACHE pCache, void *pvKey, PVBOXEXT_HASHCACHE_ENTRY pEntry)
|
---|
149 | {
|
---|
150 | PVBOXEXT_HASHMAP_ENTRY pOldEntry = VBoxExtHashPut(&pCache->Map, pvKey, &pEntry->MapEntry);
|
---|
151 | PVBOXEXT_HASHCACHE_ENTRY pOld;
|
---|
152 | if (!pOldEntry)
|
---|
153 | return;
|
---|
154 | pOld = VBOXEXT_HASHCACHE_ENTRY_FROM_MAP(pOldEntry);
|
---|
155 | if (pOld != pEntry)
|
---|
156 | pCache->pfnCleanupEntry(pvKey, pOld);
|
---|
157 | }
|
---|
158 |
|
---|
159 | void VBoxExtCacheCleanup(PVBOXEXT_HASHCACHE pCache);
|
---|
160 |
|
---|
161 | DECLINLINE(void) VBoxExtCacheTerm(PVBOXEXT_HASHCACHE pCache)
|
---|
162 | {
|
---|
163 | VBoxExtCacheCleanup(pCache);
|
---|
164 | }
|
---|
165 |
|
---|
166 | #endif /* !VBOX_INCLUDED_SRC_Graphics_shaderlib_vboxext_h */
|
---|
167 |
|
---|