VirtualBox

source: vbox/trunk/src/VBox/Devices/Graphics/shaderlib/vboxext.h@ 104027

Last change on this file since 104027 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.5 KB
Line 
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
44HRESULT VBoxExtCheckInit(void);
45HRESULT 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 */
52HDC VBoxExtGetDC(HWND hWnd);
53int 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. */
61struct wined3d_context;
62void VBoxExtReleaseContextAsync(struct wined3d_context *context);
63#endif
64
65/* API for creating & destroying windows */
66HRESULT VBoxExtWndDestroy(HWND hWnd, HDC hDC);
67HRESULT VBoxExtWndCreate(DWORD width, DWORD height, HWND *phWnd, HDC *phDC);
68
69
70/* hashmap */
71typedef DECLCALLBACKTYPE(uint32_t, FNVBOXEXT_HASHMAP_HASH,(void *pvKey));
72typedef FNVBOXEXT_HASHMAP_HASH *PFNVBOXEXT_HASHMAP_HASH;
73
74typedef DECLCALLBACKTYPE(bool, FNVBOXEXT_HASHMAP_EQUAL,(void *pvKey1, void *pvKey2));
75typedef FNVBOXEXT_HASHMAP_EQUAL *PFNVBOXEXT_HASHMAP_EQUAL;
76
77struct VBOXEXT_HASHMAP;
78struct VBOXEXT_HASHMAP_ENTRY;
79typedef DECLCALLBACKTYPE(bool, FNVBOXEXT_HASHMAP_VISITOR,(struct VBOXEXT_HASHMAP *pMap, void *pvKey, struct VBOXEXT_HASHMAP_ENTRY *pValue, void *pvVisitor));
80typedef FNVBOXEXT_HASHMAP_VISITOR *PFNVBOXEXT_HASHMAP_VISITOR;
81
82typedef struct VBOXEXT_HASHMAP_ENTRY
83{
84 RTLISTNODE ListNode;
85 void *pvKey;
86 uint32_t u32Hash;
87} VBOXEXT_HASHMAP_ENTRY, *PVBOXEXT_HASHMAP_ENTRY;
88
89typedef struct VBOXEXT_HASHMAP_BUCKET
90{
91 RTLISTNODE EntryList;
92} VBOXEXT_HASHMAP_BUCKET, *PVBOXEXT_HASHMAP_BUCKET;
93
94#define VBOXEXT_HASHMAP_NUM_BUCKETS 29
95
96typedef 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
104void VBoxExtHashInit(PVBOXEXT_HASHMAP pMap, PFNVBOXEXT_HASHMAP_HASH pfnHash, PFNVBOXEXT_HASHMAP_EQUAL pfnEqual);
105PVBOXEXT_HASHMAP_ENTRY VBoxExtHashPut(PVBOXEXT_HASHMAP pMap, void *pvKey, PVBOXEXT_HASHMAP_ENTRY pEntry);
106PVBOXEXT_HASHMAP_ENTRY VBoxExtHashGet(PVBOXEXT_HASHMAP pMap, void *pvKey);
107PVBOXEXT_HASHMAP_ENTRY VBoxExtHashRemove(PVBOXEXT_HASHMAP pMap, void *pvKey);
108void* VBoxExtHashRemoveEntry(PVBOXEXT_HASHMAP pMap, PVBOXEXT_HASHMAP_ENTRY pEntry);
109void VBoxExtHashVisit(PVBOXEXT_HASHMAP pMap, PFNVBOXEXT_HASHMAP_VISITOR pfnVisitor, void *pvVisitor);
110void VBoxExtHashCleanup(PVBOXEXT_HASHMAP pMap, PFNVBOXEXT_HASHMAP_VISITOR pfnVisitor, void *pvVisitor);
111
112DECLINLINE(uint32_t) VBoxExtHashSize(PVBOXEXT_HASHMAP pMap)
113{
114 return pMap->cEntries;
115}
116
117DECLINLINE(void*) VBoxExtHashEntryKey(PVBOXEXT_HASHMAP_ENTRY pEntry)
118{
119 return pEntry->pvKey;
120}
121
122struct VBOXEXT_HASHCACHE_ENTRY;
123typedef DECLCALLBACKTYPE(void, FNVBOXEXT_HASHCACHE_CLEANUP_ENTRY,(void *pvKey, struct VBOXEXT_HASHCACHE_ENTRY *pEntry));
124typedef FNVBOXEXT_HASHCACHE_CLEANUP_ENTRY *PFNVBOXEXT_HASHCACHE_CLEANUP_ENTRY;
125
126typedef struct VBOXEXT_HASHCACHE_ENTRY
127{
128 VBOXEXT_HASHMAP_ENTRY MapEntry;
129 uint32_t u32Usage;
130} VBOXEXT_HASHCACHE_ENTRY, *PVBOXEXT_HASHCACHE_ENTRY;
131
132typedef 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
142DECLINLINE(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
152DECLINLINE(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
158DECLINLINE(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
169void VBoxExtCacheCleanup(PVBOXEXT_HASHCACHE pCache);
170
171DECLINLINE(void) VBoxExtCacheTerm(PVBOXEXT_HASHCACHE pCache)
172{
173 VBoxExtCacheCleanup(pCache);
174}
175
176#endif /* !VBOX_INCLUDED_SRC_Graphics_shaderlib_vboxext_h */
177
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