VirtualBox

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

Last change on this file since 93956 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 KB
Line 
1/* $Id: vboxext.h 93115 2022-01-01 11:31:46Z vboxsync $ */
2/** @file
3 * VBox extension to Wine D3D
4 */
5
6/*
7 * Copyright (C) 2011-2022 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
34HRESULT VBoxExtCheckInit(void);
35HRESULT 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 */
42HDC VBoxExtGetDC(HWND hWnd);
43int 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. */
51struct wined3d_context;
52void VBoxExtReleaseContextAsync(struct wined3d_context *context);
53#endif
54
55/* API for creating & destroying windows */
56HRESULT VBoxExtWndDestroy(HWND hWnd, HDC hDC);
57HRESULT VBoxExtWndCreate(DWORD width, DWORD height, HWND *phWnd, HDC *phDC);
58
59
60/* hashmap */
61typedef DECLCALLBACKTYPE(uint32_t, FNVBOXEXT_HASHMAP_HASH,(void *pvKey));
62typedef FNVBOXEXT_HASHMAP_HASH *PFNVBOXEXT_HASHMAP_HASH;
63
64typedef DECLCALLBACKTYPE(bool, FNVBOXEXT_HASHMAP_EQUAL,(void *pvKey1, void *pvKey2));
65typedef FNVBOXEXT_HASHMAP_EQUAL *PFNVBOXEXT_HASHMAP_EQUAL;
66
67struct VBOXEXT_HASHMAP;
68struct VBOXEXT_HASHMAP_ENTRY;
69typedef DECLCALLBACKTYPE(bool, FNVBOXEXT_HASHMAP_VISITOR,(struct VBOXEXT_HASHMAP *pMap, void *pvKey, struct VBOXEXT_HASHMAP_ENTRY *pValue, void *pvVisitor));
70typedef FNVBOXEXT_HASHMAP_VISITOR *PFNVBOXEXT_HASHMAP_VISITOR;
71
72typedef struct VBOXEXT_HASHMAP_ENTRY
73{
74 RTLISTNODE ListNode;
75 void *pvKey;
76 uint32_t u32Hash;
77} VBOXEXT_HASHMAP_ENTRY, *PVBOXEXT_HASHMAP_ENTRY;
78
79typedef struct VBOXEXT_HASHMAP_BUCKET
80{
81 RTLISTNODE EntryList;
82} VBOXEXT_HASHMAP_BUCKET, *PVBOXEXT_HASHMAP_BUCKET;
83
84#define VBOXEXT_HASHMAP_NUM_BUCKETS 29
85
86typedef 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
94void VBoxExtHashInit(PVBOXEXT_HASHMAP pMap, PFNVBOXEXT_HASHMAP_HASH pfnHash, PFNVBOXEXT_HASHMAP_EQUAL pfnEqual);
95PVBOXEXT_HASHMAP_ENTRY VBoxExtHashPut(PVBOXEXT_HASHMAP pMap, void *pvKey, PVBOXEXT_HASHMAP_ENTRY pEntry);
96PVBOXEXT_HASHMAP_ENTRY VBoxExtHashGet(PVBOXEXT_HASHMAP pMap, void *pvKey);
97PVBOXEXT_HASHMAP_ENTRY VBoxExtHashRemove(PVBOXEXT_HASHMAP pMap, void *pvKey);
98void* VBoxExtHashRemoveEntry(PVBOXEXT_HASHMAP pMap, PVBOXEXT_HASHMAP_ENTRY pEntry);
99void VBoxExtHashVisit(PVBOXEXT_HASHMAP pMap, PFNVBOXEXT_HASHMAP_VISITOR pfnVisitor, void *pvVisitor);
100void VBoxExtHashCleanup(PVBOXEXT_HASHMAP pMap, PFNVBOXEXT_HASHMAP_VISITOR pfnVisitor, void *pvVisitor);
101
102DECLINLINE(uint32_t) VBoxExtHashSize(PVBOXEXT_HASHMAP pMap)
103{
104 return pMap->cEntries;
105}
106
107DECLINLINE(void*) VBoxExtHashEntryKey(PVBOXEXT_HASHMAP_ENTRY pEntry)
108{
109 return pEntry->pvKey;
110}
111
112struct VBOXEXT_HASHCACHE_ENTRY;
113typedef DECLCALLBACKTYPE(void, FNVBOXEXT_HASHCACHE_CLEANUP_ENTRY,(void *pvKey, struct VBOXEXT_HASHCACHE_ENTRY *pEntry));
114typedef FNVBOXEXT_HASHCACHE_CLEANUP_ENTRY *PFNVBOXEXT_HASHCACHE_CLEANUP_ENTRY;
115
116typedef struct VBOXEXT_HASHCACHE_ENTRY
117{
118 VBOXEXT_HASHMAP_ENTRY MapEntry;
119 uint32_t u32Usage;
120} VBOXEXT_HASHCACHE_ENTRY, *PVBOXEXT_HASHCACHE_ENTRY;
121
122typedef 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
132DECLINLINE(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
142DECLINLINE(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
148DECLINLINE(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
159void VBoxExtCacheCleanup(PVBOXEXT_HASHCACHE pCache);
160
161DECLINLINE(void) VBoxExtCacheTerm(PVBOXEXT_HASHCACHE pCache)
162{
163 VBoxExtCacheCleanup(pCache);
164}
165
166#endif /* !VBOX_INCLUDED_SRC_Graphics_shaderlib_vboxext_h */
167
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