VirtualBox

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

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