1 | /* $Id: vboxext.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox extension to Wine D3D
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef VBOX_INCLUDED_SRC_Graphics_shaderlib_vboxext_h
|
---|
29 | #define VBOX_INCLUDED_SRC_Graphics_shaderlib_vboxext_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | #ifdef VBOX_WINE_WITHOUT_LIBWINE
|
---|
35 | # ifdef _MSC_VER
|
---|
36 | # include <iprt/win/windows.h>
|
---|
37 | # else
|
---|
38 | # include <windows.h>
|
---|
39 | # endif
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | #include <iprt/list.h>
|
---|
43 |
|
---|
44 | HRESULT VBoxExtCheckInit(void);
|
---|
45 | HRESULT VBoxExtCheckTerm(void);
|
---|
46 | #if defined(VBOX_WINE_WITH_SINGLE_CONTEXT) || defined(VBOX_WINE_WITH_SINGLE_SWAPCHAIN_CONTEXT)
|
---|
47 | # ifndef VBOX_WITH_WDDM
|
---|
48 | /* Windows destroys HDC created by a given thread when the thread is terminated
|
---|
49 | * this leads to a mess-up in Wine & Chromium code in some situations, e.g.
|
---|
50 | * D3D device is created in one thread, then the thread is terminated,
|
---|
51 | * then device is started to be used in another thread */
|
---|
52 | HDC VBoxExtGetDC(HWND hWnd);
|
---|
53 | int VBoxExtReleaseDC(HWND hWnd, HDC hDC);
|
---|
54 | # endif
|
---|
55 | /* We need to do a VBoxTlsRefRelease for the current thread context on thread exit to avoid memory leaking
|
---|
56 | * Calling VBoxTlsRefRelease may result in a call to context dtor callback, which is supposed to be run under wined3d lock.
|
---|
57 | * We can not acquire a wined3d lock in DllMain since this would result in a lock order violation, which may result in a deadlock.
|
---|
58 | * In other words, wined3d may internally call Win32 API functions which result in a DLL lock acquisition while holding wined3d lock.
|
---|
59 | * So lock order should always be "wined3d lock" -> "dll lock".
|
---|
60 | * To avoid possible deadlocks we make an asynchronous call to a worker thread to make a context release from there. */
|
---|
61 | struct wined3d_context;
|
---|
62 | void VBoxExtReleaseContextAsync(struct wined3d_context *context);
|
---|
63 | #endif
|
---|
64 |
|
---|
65 | /* API for creating & destroying windows */
|
---|
66 | HRESULT VBoxExtWndDestroy(HWND hWnd, HDC hDC);
|
---|
67 | HRESULT VBoxExtWndCreate(DWORD width, DWORD height, HWND *phWnd, HDC *phDC);
|
---|
68 |
|
---|
69 |
|
---|
70 | /* hashmap */
|
---|
71 | typedef DECLCALLBACKTYPE(uint32_t, FNVBOXEXT_HASHMAP_HASH,(void *pvKey));
|
---|
72 | typedef FNVBOXEXT_HASHMAP_HASH *PFNVBOXEXT_HASHMAP_HASH;
|
---|
73 |
|
---|
74 | typedef DECLCALLBACKTYPE(bool, FNVBOXEXT_HASHMAP_EQUAL,(void *pvKey1, void *pvKey2));
|
---|
75 | typedef FNVBOXEXT_HASHMAP_EQUAL *PFNVBOXEXT_HASHMAP_EQUAL;
|
---|
76 |
|
---|
77 | struct VBOXEXT_HASHMAP;
|
---|
78 | struct VBOXEXT_HASHMAP_ENTRY;
|
---|
79 | typedef DECLCALLBACKTYPE(bool, FNVBOXEXT_HASHMAP_VISITOR,(struct VBOXEXT_HASHMAP *pMap, void *pvKey, struct VBOXEXT_HASHMAP_ENTRY *pValue, void *pvVisitor));
|
---|
80 | typedef FNVBOXEXT_HASHMAP_VISITOR *PFNVBOXEXT_HASHMAP_VISITOR;
|
---|
81 |
|
---|
82 | typedef struct VBOXEXT_HASHMAP_ENTRY
|
---|
83 | {
|
---|
84 | RTLISTNODE ListNode;
|
---|
85 | void *pvKey;
|
---|
86 | uint32_t u32Hash;
|
---|
87 | } VBOXEXT_HASHMAP_ENTRY, *PVBOXEXT_HASHMAP_ENTRY;
|
---|
88 |
|
---|
89 | typedef struct VBOXEXT_HASHMAP_BUCKET
|
---|
90 | {
|
---|
91 | RTLISTNODE EntryList;
|
---|
92 | } VBOXEXT_HASHMAP_BUCKET, *PVBOXEXT_HASHMAP_BUCKET;
|
---|
93 |
|
---|
94 | #define VBOXEXT_HASHMAP_NUM_BUCKETS 29
|
---|
95 |
|
---|
96 | typedef struct VBOXEXT_HASHMAP
|
---|
97 | {
|
---|
98 | PFNVBOXEXT_HASHMAP_HASH pfnHash;
|
---|
99 | PFNVBOXEXT_HASHMAP_EQUAL pfnEqual;
|
---|
100 | uint32_t cEntries;
|
---|
101 | VBOXEXT_HASHMAP_BUCKET aBuckets[VBOXEXT_HASHMAP_NUM_BUCKETS];
|
---|
102 | } VBOXEXT_HASHMAP, *PVBOXEXT_HASHMAP;
|
---|
103 |
|
---|
104 | void VBoxExtHashInit(PVBOXEXT_HASHMAP pMap, PFNVBOXEXT_HASHMAP_HASH pfnHash, PFNVBOXEXT_HASHMAP_EQUAL pfnEqual);
|
---|
105 | PVBOXEXT_HASHMAP_ENTRY VBoxExtHashPut(PVBOXEXT_HASHMAP pMap, void *pvKey, PVBOXEXT_HASHMAP_ENTRY pEntry);
|
---|
106 | PVBOXEXT_HASHMAP_ENTRY VBoxExtHashGet(PVBOXEXT_HASHMAP pMap, void *pvKey);
|
---|
107 | PVBOXEXT_HASHMAP_ENTRY VBoxExtHashRemove(PVBOXEXT_HASHMAP pMap, void *pvKey);
|
---|
108 | void* VBoxExtHashRemoveEntry(PVBOXEXT_HASHMAP pMap, PVBOXEXT_HASHMAP_ENTRY pEntry);
|
---|
109 | void VBoxExtHashVisit(PVBOXEXT_HASHMAP pMap, PFNVBOXEXT_HASHMAP_VISITOR pfnVisitor, void *pvVisitor);
|
---|
110 | void VBoxExtHashCleanup(PVBOXEXT_HASHMAP pMap, PFNVBOXEXT_HASHMAP_VISITOR pfnVisitor, void *pvVisitor);
|
---|
111 |
|
---|
112 | DECLINLINE(uint32_t) VBoxExtHashSize(PVBOXEXT_HASHMAP pMap)
|
---|
113 | {
|
---|
114 | return pMap->cEntries;
|
---|
115 | }
|
---|
116 |
|
---|
117 | DECLINLINE(void*) VBoxExtHashEntryKey(PVBOXEXT_HASHMAP_ENTRY pEntry)
|
---|
118 | {
|
---|
119 | return pEntry->pvKey;
|
---|
120 | }
|
---|
121 |
|
---|
122 | struct VBOXEXT_HASHCACHE_ENTRY;
|
---|
123 | typedef DECLCALLBACKTYPE(void, FNVBOXEXT_HASHCACHE_CLEANUP_ENTRY,(void *pvKey, struct VBOXEXT_HASHCACHE_ENTRY *pEntry));
|
---|
124 | typedef FNVBOXEXT_HASHCACHE_CLEANUP_ENTRY *PFNVBOXEXT_HASHCACHE_CLEANUP_ENTRY;
|
---|
125 |
|
---|
126 | typedef struct VBOXEXT_HASHCACHE_ENTRY
|
---|
127 | {
|
---|
128 | VBOXEXT_HASHMAP_ENTRY MapEntry;
|
---|
129 | uint32_t u32Usage;
|
---|
130 | } VBOXEXT_HASHCACHE_ENTRY, *PVBOXEXT_HASHCACHE_ENTRY;
|
---|
131 |
|
---|
132 | typedef struct VBOXEXT_HASHCACHE
|
---|
133 | {
|
---|
134 | VBOXEXT_HASHMAP Map;
|
---|
135 | uint32_t cMaxElements;
|
---|
136 | PFNVBOXEXT_HASHCACHE_CLEANUP_ENTRY pfnCleanupEntry;
|
---|
137 | } VBOXEXT_HASHCACHE, *PVBOXEXT_HASHCACHE;
|
---|
138 |
|
---|
139 | #define VBOXEXT_HASHCACHE_FROM_MAP(_pMap) RT_FROM_MEMBER((_pMap), VBOXEXT_HASHCACHE, Map)
|
---|
140 | #define VBOXEXT_HASHCACHE_ENTRY_FROM_MAP(_pEntry) RT_FROM_MEMBER((_pEntry), VBOXEXT_HASHCACHE_ENTRY, MapEntry)
|
---|
141 |
|
---|
142 | DECLINLINE(void) VBoxExtCacheInit(PVBOXEXT_HASHCACHE pCache, uint32_t cMaxElements,
|
---|
143 | PFNVBOXEXT_HASHMAP_HASH pfnHash,
|
---|
144 | PFNVBOXEXT_HASHMAP_EQUAL pfnEqual,
|
---|
145 | PFNVBOXEXT_HASHCACHE_CLEANUP_ENTRY pfnCleanupEntry)
|
---|
146 | {
|
---|
147 | VBoxExtHashInit(&pCache->Map, pfnHash, pfnEqual);
|
---|
148 | pCache->cMaxElements = cMaxElements;
|
---|
149 | pCache->pfnCleanupEntry = pfnCleanupEntry;
|
---|
150 | }
|
---|
151 |
|
---|
152 | DECLINLINE(PVBOXEXT_HASHCACHE_ENTRY) VBoxExtCacheGet(PVBOXEXT_HASHCACHE pCache, void *pvKey)
|
---|
153 | {
|
---|
154 | PVBOXEXT_HASHMAP_ENTRY pEntry = VBoxExtHashRemove(&pCache->Map, pvKey);
|
---|
155 | return VBOXEXT_HASHCACHE_ENTRY_FROM_MAP(pEntry);
|
---|
156 | }
|
---|
157 |
|
---|
158 | DECLINLINE(void) VBoxExtCachePut(PVBOXEXT_HASHCACHE pCache, void *pvKey, PVBOXEXT_HASHCACHE_ENTRY pEntry)
|
---|
159 | {
|
---|
160 | PVBOXEXT_HASHMAP_ENTRY pOldEntry = VBoxExtHashPut(&pCache->Map, pvKey, &pEntry->MapEntry);
|
---|
161 | PVBOXEXT_HASHCACHE_ENTRY pOld;
|
---|
162 | if (!pOldEntry)
|
---|
163 | return;
|
---|
164 | pOld = VBOXEXT_HASHCACHE_ENTRY_FROM_MAP(pOldEntry);
|
---|
165 | if (pOld != pEntry)
|
---|
166 | pCache->pfnCleanupEntry(pvKey, pOld);
|
---|
167 | }
|
---|
168 |
|
---|
169 | void VBoxExtCacheCleanup(PVBOXEXT_HASHCACHE pCache);
|
---|
170 |
|
---|
171 | DECLINLINE(void) VBoxExtCacheTerm(PVBOXEXT_HASHCACHE pCache)
|
---|
172 | {
|
---|
173 | VBoxExtCacheCleanup(pCache);
|
---|
174 | }
|
---|
175 |
|
---|
176 | #endif /* !VBOX_INCLUDED_SRC_Graphics_shaderlib_vboxext_h */
|
---|
177 |
|
---|