VirtualBox

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

Last change on this file since 61497 was 56292, checked in by vboxsync, 10 years ago

Devices: Updated (C) year.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.0 KB
Line 
1/* $Id: vboxext.h 56292 2015-06-09 14:20:46Z vboxsync $ */
2/** @file
3 *
4 * VBox extension to Wine D3D
5 *
6 * Copyright (C) 2011-2015 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. */
42struct wined3d_context;
43void VBoxExtReleaseContextAsync(struct wined3d_context *context);
44#endif
45
46/* API for creating & destroying windows */
47HRESULT VBoxExtWndDestroy(HWND hWnd, HDC hDC);
48HRESULT VBoxExtWndCreate(DWORD width, DWORD height, HWND *phWnd, HDC *phDC);
49
50
51/* hashmap */
52typedef DECLCALLBACK(uint32_t) FNVBOXEXT_HASHMAP_HASH(void *pvKey);
53typedef FNVBOXEXT_HASHMAP_HASH *PFNVBOXEXT_HASHMAP_HASH;
54
55typedef DECLCALLBACK(bool) FNVBOXEXT_HASHMAP_EQUAL(void *pvKey1, void *pvKey2);
56typedef FNVBOXEXT_HASHMAP_EQUAL *PFNVBOXEXT_HASHMAP_EQUAL;
57
58struct VBOXEXT_HASHMAP;
59struct VBOXEXT_HASHMAP_ENTRY;
60typedef DECLCALLBACK(bool) FNVBOXEXT_HASHMAP_VISITOR(struct VBOXEXT_HASHMAP *pMap, void *pvKey, struct VBOXEXT_HASHMAP_ENTRY *pValue, void *pvVisitor);
61typedef FNVBOXEXT_HASHMAP_VISITOR *PFNVBOXEXT_HASHMAP_VISITOR;
62
63typedef struct VBOXEXT_HASHMAP_ENTRY
64{
65 RTLISTNODE ListNode;
66 void *pvKey;
67 uint32_t u32Hash;
68} VBOXEXT_HASHMAP_ENTRY, *PVBOXEXT_HASHMAP_ENTRY;
69
70typedef struct VBOXEXT_HASHMAP_BUCKET
71{
72 RTLISTNODE EntryList;
73} VBOXEXT_HASHMAP_BUCKET, *PVBOXEXT_HASHMAP_BUCKET;
74
75#define VBOXEXT_HASHMAP_NUM_BUCKETS 29
76
77typedef struct VBOXEXT_HASHMAP
78{
79 PFNVBOXEXT_HASHMAP_HASH pfnHash;
80 PFNVBOXEXT_HASHMAP_EQUAL pfnEqual;
81 uint32_t cEntries;
82 VBOXEXT_HASHMAP_BUCKET aBuckets[VBOXEXT_HASHMAP_NUM_BUCKETS];
83} VBOXEXT_HASHMAP, *PVBOXEXT_HASHMAP;
84
85void VBoxExtHashInit(PVBOXEXT_HASHMAP pMap, PFNVBOXEXT_HASHMAP_HASH pfnHash, PFNVBOXEXT_HASHMAP_EQUAL pfnEqual);
86PVBOXEXT_HASHMAP_ENTRY VBoxExtHashPut(PVBOXEXT_HASHMAP pMap, void *pvKey, PVBOXEXT_HASHMAP_ENTRY pEntry);
87PVBOXEXT_HASHMAP_ENTRY VBoxExtHashGet(PVBOXEXT_HASHMAP pMap, void *pvKey);
88PVBOXEXT_HASHMAP_ENTRY VBoxExtHashRemove(PVBOXEXT_HASHMAP pMap, void *pvKey);
89void* VBoxExtHashRemoveEntry(PVBOXEXT_HASHMAP pMap, PVBOXEXT_HASHMAP_ENTRY pEntry);
90void VBoxExtHashVisit(PVBOXEXT_HASHMAP pMap, PFNVBOXEXT_HASHMAP_VISITOR pfnVisitor, void *pvVisitor);
91void VBoxExtHashCleanup(PVBOXEXT_HASHMAP pMap, PFNVBOXEXT_HASHMAP_VISITOR pfnVisitor, void *pvVisitor);
92
93DECLINLINE(uint32_t) VBoxExtHashSize(PVBOXEXT_HASHMAP pMap)
94{
95 return pMap->cEntries;
96}
97
98DECLINLINE(void*) VBoxExtHashEntryKey(PVBOXEXT_HASHMAP_ENTRY pEntry)
99{
100 return pEntry->pvKey;
101}
102
103struct VBOXEXT_HASHCACHE_ENTRY;
104typedef DECLCALLBACK(void) FNVBOXEXT_HASHCACHE_CLEANUP_ENTRY(void *pvKey, struct VBOXEXT_HASHCACHE_ENTRY *pEntry);
105typedef FNVBOXEXT_HASHCACHE_CLEANUP_ENTRY *PFNVBOXEXT_HASHCACHE_CLEANUP_ENTRY;
106
107typedef struct VBOXEXT_HASHCACHE_ENTRY
108{
109 VBOXEXT_HASHMAP_ENTRY MapEntry;
110 uint32_t u32Usage;
111} VBOXEXT_HASHCACHE_ENTRY, *PVBOXEXT_HASHCACHE_ENTRY;
112
113typedef struct VBOXEXT_HASHCACHE
114{
115 VBOXEXT_HASHMAP Map;
116 uint32_t cMaxElements;
117 PFNVBOXEXT_HASHCACHE_CLEANUP_ENTRY pfnCleanupEntry;
118} VBOXEXT_HASHCACHE, *PVBOXEXT_HASHCACHE;
119
120#define VBOXEXT_HASHCACHE_FROM_MAP(_pMap) RT_FROM_MEMBER((_pMap), VBOXEXT_HASHCACHE, Map)
121#define VBOXEXT_HASHCACHE_ENTRY_FROM_MAP(_pEntry) RT_FROM_MEMBER((_pEntry), VBOXEXT_HASHCACHE_ENTRY, MapEntry)
122
123DECLINLINE(void) VBoxExtCacheInit(PVBOXEXT_HASHCACHE pCache, uint32_t cMaxElements,
124 PFNVBOXEXT_HASHMAP_HASH pfnHash,
125 PFNVBOXEXT_HASHMAP_EQUAL pfnEqual,
126 PFNVBOXEXT_HASHCACHE_CLEANUP_ENTRY pfnCleanupEntry)
127{
128 VBoxExtHashInit(&pCache->Map, pfnHash, pfnEqual);
129 pCache->cMaxElements = cMaxElements;
130 pCache->pfnCleanupEntry = pfnCleanupEntry;
131}
132
133DECLINLINE(PVBOXEXT_HASHCACHE_ENTRY) VBoxExtCacheGet(PVBOXEXT_HASHCACHE pCache, void *pvKey)
134{
135 PVBOXEXT_HASHMAP_ENTRY pEntry = VBoxExtHashRemove(&pCache->Map, pvKey);
136 return VBOXEXT_HASHCACHE_ENTRY_FROM_MAP(pEntry);
137}
138
139DECLINLINE(void) VBoxExtCachePut(PVBOXEXT_HASHCACHE pCache, void *pvKey, PVBOXEXT_HASHCACHE_ENTRY pEntry)
140{
141 PVBOXEXT_HASHMAP_ENTRY pOldEntry = VBoxExtHashPut(&pCache->Map, pvKey, &pEntry->MapEntry);
142 PVBOXEXT_HASHCACHE_ENTRY pOld;
143 if (!pOldEntry)
144 return;
145 pOld = VBOXEXT_HASHCACHE_ENTRY_FROM_MAP(pOldEntry);
146 if (pOld != pEntry)
147 pCache->pfnCleanupEntry(pvKey, pOld);
148}
149
150void VBoxExtCacheCleanup(PVBOXEXT_HASHCACHE pCache);
151
152DECLINLINE(void) VBoxExtCacheTerm(PVBOXEXT_HASHCACHE pCache)
153{
154 VBoxExtCacheCleanup(pCache);
155}
156
157#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