1 | /* $Id: VBoxVideo3D.h 76585 2019-01-01 06:31:29Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox 3D common tooling
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2019 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 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifndef VBOX_INCLUDED_Graphics_VBoxVideo3D_h
|
---|
28 | #define VBOX_INCLUDED_Graphics_VBoxVideo3D_h
|
---|
29 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
30 | # pragma once
|
---|
31 | #endif
|
---|
32 |
|
---|
33 | #include <iprt/cdefs.h>
|
---|
34 | #include <iprt/asm.h>
|
---|
35 | #ifndef VBoxTlsRefGetImpl
|
---|
36 | # ifdef VBoxTlsRefSetImpl
|
---|
37 | # error "VBoxTlsRefSetImpl is defined, unexpected!"
|
---|
38 | # endif
|
---|
39 | # include <iprt/thread.h>
|
---|
40 | # define VBoxTlsRefGetImpl(_tls) (RTTlsGet((RTTLS)(_tls)))
|
---|
41 | # define VBoxTlsRefSetImpl(_tls, _val) (RTTlsSet((RTTLS)(_tls), (_val)))
|
---|
42 | #else
|
---|
43 | # ifndef VBoxTlsRefSetImpl
|
---|
44 | # error "VBoxTlsRefSetImpl is NOT defined, unexpected!"
|
---|
45 | # endif
|
---|
46 | #endif
|
---|
47 |
|
---|
48 | #ifndef VBoxTlsRefAssertImpl
|
---|
49 | # define VBoxTlsRefAssertImpl(_a) do {} while (0)
|
---|
50 | #endif
|
---|
51 |
|
---|
52 | typedef DECLCALLBACK(void) FNVBOXTLSREFDTOR(void*);
|
---|
53 | typedef FNVBOXTLSREFDTOR *PFNVBOXTLSREFDTOR;
|
---|
54 |
|
---|
55 | typedef enum {
|
---|
56 | VBOXTLSREFDATA_STATE_UNDEFINED = 0,
|
---|
57 | VBOXTLSREFDATA_STATE_INITIALIZED,
|
---|
58 | VBOXTLSREFDATA_STATE_TOBE_DESTROYED,
|
---|
59 | VBOXTLSREFDATA_STATE_DESTROYING,
|
---|
60 | VBOXTLSREFDATA_STATE_32BIT_HACK = 0x7fffffff
|
---|
61 | } VBOXTLSREFDATA_STATE;
|
---|
62 |
|
---|
63 | #define VBOXTLSREFDATA \
|
---|
64 | volatile int32_t cTlsRefs; \
|
---|
65 | VBOXTLSREFDATA_STATE enmTlsRefState; \
|
---|
66 | PFNVBOXTLSREFDTOR pfnTlsRefDtor; \
|
---|
67 |
|
---|
68 | struct VBOXTLSREFDATA_DUMMY
|
---|
69 | {
|
---|
70 | VBOXTLSREFDATA
|
---|
71 | };
|
---|
72 |
|
---|
73 | #define VBOXTLSREFDATA_OFFSET(_t) RT_OFFSETOF(_t, cTlsRefs)
|
---|
74 | #define VBOXTLSREFDATA_ASSERT_OFFSET(_t) RTASSERT_OFFSET_OF(_t, cTlsRefs)
|
---|
75 | #define VBOXTLSREFDATA_SIZE() (sizeof (struct VBOXTLSREFDATA_DUMMY))
|
---|
76 | #define VBOXTLSREFDATA_COPY(_pDst, _pSrc) do { \
|
---|
77 | (_pDst)->cTlsRefs = (_pSrc)->cTlsRefs; \
|
---|
78 | (_pDst)->enmTlsRefState = (_pSrc)->enmTlsRefState; \
|
---|
79 | (_pDst)->pfnTlsRefDtor = (_pSrc)->pfnTlsRefDtor; \
|
---|
80 | } while (0)
|
---|
81 |
|
---|
82 | #define VBOXTLSREFDATA_EQUAL(_pDst, _pSrc) ( \
|
---|
83 | (_pDst)->cTlsRefs == (_pSrc)->cTlsRefs \
|
---|
84 | && (_pDst)->enmTlsRefState == (_pSrc)->enmTlsRefState \
|
---|
85 | && (_pDst)->pfnTlsRefDtor == (_pSrc)->pfnTlsRefDtor \
|
---|
86 | )
|
---|
87 |
|
---|
88 |
|
---|
89 | #define VBoxTlsRefInit(_p, _pfnDtor) do { \
|
---|
90 | (_p)->cTlsRefs = 1; \
|
---|
91 | (_p)->enmTlsRefState = VBOXTLSREFDATA_STATE_INITIALIZED; \
|
---|
92 | (_p)->pfnTlsRefDtor = (_pfnDtor); \
|
---|
93 | } while (0)
|
---|
94 |
|
---|
95 | #define VBoxTlsRefIsFunctional(_p) (!!((_p)->enmTlsRefState == VBOXTLSREFDATA_STATE_INITIALIZED))
|
---|
96 |
|
---|
97 | #define VBoxTlsRefAddRef(_p) do { \
|
---|
98 | int cRefs = ASMAtomicIncS32(&(_p)->cTlsRefs); \
|
---|
99 | VBoxTlsRefAssertImpl(cRefs > 1 || (_p)->enmTlsRefState == VBOXTLSREFDATA_STATE_DESTROYING); \
|
---|
100 | RT_NOREF(cRefs); \
|
---|
101 | } while (0)
|
---|
102 |
|
---|
103 | #define VBoxTlsRefCountGet(_p) (ASMAtomicReadS32(&(_p)->cTlsRefs))
|
---|
104 |
|
---|
105 | #define VBoxTlsRefRelease(_p) do { \
|
---|
106 | int cRefs = ASMAtomicDecS32(&(_p)->cTlsRefs); \
|
---|
107 | VBoxTlsRefAssertImpl(cRefs >= 0); \
|
---|
108 | if (!cRefs && (_p)->enmTlsRefState != VBOXTLSREFDATA_STATE_DESTROYING /* <- avoid recursion if VBoxTlsRefAddRef/Release is called from dtor */) { \
|
---|
109 | (_p)->enmTlsRefState = VBOXTLSREFDATA_STATE_DESTROYING; \
|
---|
110 | (_p)->pfnTlsRefDtor((_p)); \
|
---|
111 | } \
|
---|
112 | } while (0)
|
---|
113 |
|
---|
114 | #define VBoxTlsRefMarkDestroy(_p) do { \
|
---|
115 | (_p)->enmTlsRefState = VBOXTLSREFDATA_STATE_TOBE_DESTROYED; \
|
---|
116 | } while (0)
|
---|
117 |
|
---|
118 | #define VBoxTlsRefGetCurrent(_t, _Tsd) ((_t*) VBoxTlsRefGetImpl((_Tsd)))
|
---|
119 |
|
---|
120 | #define VBoxTlsRefGetCurrentFunctional(_val, _t, _Tsd) do { \
|
---|
121 | _t * cur = VBoxTlsRefGetCurrent(_t, _Tsd); \
|
---|
122 | if (!cur || VBoxTlsRefIsFunctional(cur)) { \
|
---|
123 | (_val) = cur; \
|
---|
124 | } else { \
|
---|
125 | VBoxTlsRefSetCurrent(_t, _Tsd, NULL); \
|
---|
126 | (_val) = NULL; \
|
---|
127 | } \
|
---|
128 | } while (0)
|
---|
129 |
|
---|
130 | #define VBoxTlsRefSetCurrent(_t, _Tsd, _p) do { \
|
---|
131 | _t * oldCur = VBoxTlsRefGetCurrent(_t, _Tsd); \
|
---|
132 | if (oldCur != (_p)) { \
|
---|
133 | VBoxTlsRefSetImpl((_Tsd), (_p)); \
|
---|
134 | if (oldCur) { \
|
---|
135 | VBoxTlsRefRelease(oldCur); \
|
---|
136 | } \
|
---|
137 | if ((_p)) { \
|
---|
138 | VBoxTlsRefAddRef((_t*)(_p)); \
|
---|
139 | } \
|
---|
140 | } \
|
---|
141 | } while (0)
|
---|
142 |
|
---|
143 |
|
---|
144 | /* host 3D->Fe[/Qt] notification mechanism defines */
|
---|
145 | #define VBOX3D_NOTIFY_EVENT_TYPE_TEST_FUNCTIONAL 3
|
---|
146 | #define VBOX3D_NOTIFY_EVENT_TYPE_3DDATA_VISIBLE 4
|
---|
147 | #define VBOX3D_NOTIFY_EVENT_TYPE_3DDATA_HIDDEN 5
|
---|
148 |
|
---|
149 |
|
---|
150 | #endif /* !VBOX_INCLUDED_Graphics_VBoxVideo3D_h */
|
---|