1 | /* $Id: VBoxVideo3D.h 69107 2017-10-17 10:53:48Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox 3D common tooling
|
---|
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 | * 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_Graphics_VBoxVideo3D_h
|
---|
28 | #define ___VBox_Graphics_VBoxVideo3D_h
|
---|
29 |
|
---|
30 | #include <iprt/cdefs.h>
|
---|
31 | #include <iprt/asm.h>
|
---|
32 | #ifndef VBoxTlsRefGetImpl
|
---|
33 | # ifdef VBoxTlsRefSetImpl
|
---|
34 | # error "VBoxTlsRefSetImpl is defined, unexpected!"
|
---|
35 | # endif
|
---|
36 | # include <iprt/thread.h>
|
---|
37 | # define VBoxTlsRefGetImpl(_tls) (RTTlsGet((RTTLS)(_tls)))
|
---|
38 | # define VBoxTlsRefSetImpl(_tls, _val) (RTTlsSet((RTTLS)(_tls), (_val)))
|
---|
39 | #else
|
---|
40 | # ifndef VBoxTlsRefSetImpl
|
---|
41 | # error "VBoxTlsRefSetImpl is NOT defined, unexpected!"
|
---|
42 | # endif
|
---|
43 | #endif
|
---|
44 |
|
---|
45 | #ifndef VBoxTlsRefAssertImpl
|
---|
46 | # define VBoxTlsRefAssertImpl(_a) do {} while (0)
|
---|
47 | #endif
|
---|
48 |
|
---|
49 | typedef DECLCALLBACK(void) FNVBOXTLSREFDTOR(void*);
|
---|
50 | typedef FNVBOXTLSREFDTOR *PFNVBOXTLSREFDTOR;
|
---|
51 |
|
---|
52 | typedef enum {
|
---|
53 | VBOXTLSREFDATA_STATE_UNDEFINED = 0,
|
---|
54 | VBOXTLSREFDATA_STATE_INITIALIZED,
|
---|
55 | VBOXTLSREFDATA_STATE_TOBE_DESTROYED,
|
---|
56 | VBOXTLSREFDATA_STATE_DESTROYING,
|
---|
57 | VBOXTLSREFDATA_STATE_32BIT_HACK = 0x7fffffff
|
---|
58 | } VBOXTLSREFDATA_STATE;
|
---|
59 |
|
---|
60 | #define VBOXTLSREFDATA \
|
---|
61 | volatile int32_t cTlsRefs; \
|
---|
62 | VBOXTLSREFDATA_STATE enmTlsRefState; \
|
---|
63 | PFNVBOXTLSREFDTOR pfnTlsRefDtor; \
|
---|
64 |
|
---|
65 | struct VBOXTLSREFDATA_DUMMY
|
---|
66 | {
|
---|
67 | VBOXTLSREFDATA
|
---|
68 | };
|
---|
69 |
|
---|
70 | #define VBOXTLSREFDATA_OFFSET(_t) RT_OFFSETOF(_t, cTlsRefs)
|
---|
71 | #define VBOXTLSREFDATA_ASSERT_OFFSET(_t) RTASSERT_OFFSET_OF(_t, cTlsRefs)
|
---|
72 | #define VBOXTLSREFDATA_SIZE() (sizeof (struct VBOXTLSREFDATA_DUMMY))
|
---|
73 | #define VBOXTLSREFDATA_COPY(_pDst, _pSrc) do { \
|
---|
74 | (_pDst)->cTlsRefs = (_pSrc)->cTlsRefs; \
|
---|
75 | (_pDst)->enmTlsRefState = (_pSrc)->enmTlsRefState; \
|
---|
76 | (_pDst)->pfnTlsRefDtor = (_pSrc)->pfnTlsRefDtor; \
|
---|
77 | } while (0)
|
---|
78 |
|
---|
79 | #define VBOXTLSREFDATA_EQUAL(_pDst, _pSrc) ( \
|
---|
80 | (_pDst)->cTlsRefs == (_pSrc)->cTlsRefs \
|
---|
81 | && (_pDst)->enmTlsRefState == (_pSrc)->enmTlsRefState \
|
---|
82 | && (_pDst)->pfnTlsRefDtor == (_pSrc)->pfnTlsRefDtor \
|
---|
83 | )
|
---|
84 |
|
---|
85 |
|
---|
86 | #define VBoxTlsRefInit(_p, _pfnDtor) do { \
|
---|
87 | (_p)->cTlsRefs = 1; \
|
---|
88 | (_p)->enmTlsRefState = VBOXTLSREFDATA_STATE_INITIALIZED; \
|
---|
89 | (_p)->pfnTlsRefDtor = (_pfnDtor); \
|
---|
90 | } while (0)
|
---|
91 |
|
---|
92 | #define VBoxTlsRefIsFunctional(_p) (!!((_p)->enmTlsRefState == VBOXTLSREFDATA_STATE_INITIALIZED))
|
---|
93 |
|
---|
94 | #define VBoxTlsRefAddRef(_p) do { \
|
---|
95 | int cRefs = ASMAtomicIncS32(&(_p)->cTlsRefs); \
|
---|
96 | VBoxTlsRefAssertImpl(cRefs > 1 || (_p)->enmTlsRefState == VBOXTLSREFDATA_STATE_DESTROYING); \
|
---|
97 | RT_NOREF(cRefs); \
|
---|
98 | } while (0)
|
---|
99 |
|
---|
100 | #define VBoxTlsRefCountGet(_p) (ASMAtomicReadS32(&(_p)->cTlsRefs))
|
---|
101 |
|
---|
102 | #define VBoxTlsRefRelease(_p) do { \
|
---|
103 | int cRefs = ASMAtomicDecS32(&(_p)->cTlsRefs); \
|
---|
104 | VBoxTlsRefAssertImpl(cRefs >= 0); \
|
---|
105 | if (!cRefs && (_p)->enmTlsRefState != VBOXTLSREFDATA_STATE_DESTROYING /* <- avoid recursion if VBoxTlsRefAddRef/Release is called from dtor */) { \
|
---|
106 | (_p)->enmTlsRefState = VBOXTLSREFDATA_STATE_DESTROYING; \
|
---|
107 | (_p)->pfnTlsRefDtor((_p)); \
|
---|
108 | } \
|
---|
109 | } while (0)
|
---|
110 |
|
---|
111 | #define VBoxTlsRefMarkDestroy(_p) do { \
|
---|
112 | (_p)->enmTlsRefState = VBOXTLSREFDATA_STATE_TOBE_DESTROYED; \
|
---|
113 | } while (0)
|
---|
114 |
|
---|
115 | #define VBoxTlsRefGetCurrent(_t, _Tsd) ((_t*) VBoxTlsRefGetImpl((_Tsd)))
|
---|
116 |
|
---|
117 | #define VBoxTlsRefGetCurrentFunctional(_val, _t, _Tsd) do { \
|
---|
118 | _t * cur = VBoxTlsRefGetCurrent(_t, _Tsd); \
|
---|
119 | if (!cur || VBoxTlsRefIsFunctional(cur)) { \
|
---|
120 | (_val) = cur; \
|
---|
121 | } else { \
|
---|
122 | VBoxTlsRefSetCurrent(_t, _Tsd, NULL); \
|
---|
123 | (_val) = NULL; \
|
---|
124 | } \
|
---|
125 | } while (0)
|
---|
126 |
|
---|
127 | #define VBoxTlsRefSetCurrent(_t, _Tsd, _p) do { \
|
---|
128 | _t * oldCur = VBoxTlsRefGetCurrent(_t, _Tsd); \
|
---|
129 | if (oldCur != (_p)) { \
|
---|
130 | VBoxTlsRefSetImpl((_Tsd), (_p)); \
|
---|
131 | if (oldCur) { \
|
---|
132 | VBoxTlsRefRelease(oldCur); \
|
---|
133 | } \
|
---|
134 | if ((_p)) { \
|
---|
135 | VBoxTlsRefAddRef((_t*)(_p)); \
|
---|
136 | } \
|
---|
137 | } \
|
---|
138 | } while (0)
|
---|
139 |
|
---|
140 |
|
---|
141 | /* host 3D->Fe[/Qt] notification mechanism defines */
|
---|
142 | #define VBOX3D_NOTIFY_EVENT_TYPE_TEST_FUNCTIONAL 3
|
---|
143 | #define VBOX3D_NOTIFY_EVENT_TYPE_3DDATA_VISIBLE 4
|
---|
144 | #define VBOX3D_NOTIFY_EVENT_TYPE_3DDATA_HIDDEN 5
|
---|
145 |
|
---|
146 |
|
---|
147 | #endif /* #ifndef ___VBox_Graphics_VBoxVideo3D_h */
|
---|