2N/A/** @file
2N/A *
2N/A * VirtualBox 3D common tooling
2N/A */
2N/A
2N/A/*
2N/A * Copyright (C) 2011-2012 Oracle Corporation
2N/A *
2N/A * This file is part of VirtualBox Open Source Edition (OSE), as
2N/A * available from http://www.virtualbox.org. This file is free software;
2N/A * you can redistribute it and/or modify it under the terms of the GNU
2N/A * General Public License (GPL) as published by the Free Software
2N/A * Foundation, in version 2 as it comes in the "COPYING" file of the
2N/A * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
2N/A * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
2N/A *
2N/A * The contents of this file may alternatively be used under the terms
2N/A * of the Common Development and Distribution License Version 1.0
2N/A * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
2N/A * VirtualBox OSE distribution, in which case the provisions of the
2N/A * CDDL are applicable instead of those of the GPL.
2N/A *
2N/A * You may elect to license modified versions of this file under the
2N/A * terms and conditions of either the GPL or the CDDL or both.
2N/A */
2N/A
2N/A#ifndef ___VBox_VBoxVideo3D_h
2N/A#define ___VBox_VBoxVideo3D_h
2N/A
2N/A#include <iprt/cdefs.h>
2N/A#include <iprt/asm.h>
2N/A#ifndef VBoxTlsRefGetImpl
2N/A# ifdef VBoxTlsRefSetImpl
2N/A# error "VBoxTlsRefSetImpl is defined, unexpected!"
2N/A# endif
2N/A# include <iprt/thread.h>
2N/A# define VBoxTlsRefGetImpl(_tls) (RTTlsGet((RTTLS)(_tls)))
2N/A# define VBoxTlsRefSetImpl(_tls, _val) (RTTlsSet((RTTLS)(_tls), (_val)))
2N/A#else
2N/A# ifndef VBoxTlsRefSetImpl
2N/A# error "VBoxTlsRefSetImpl is NOT defined, unexpected!"
2N/A# endif
2N/A#endif
2N/A
2N/A#ifndef VBoxTlsRefAssertImpl
2N/A# define VBoxTlsRefAssertImpl(_a) do {} while (0)
2N/A#endif
2N/A
2N/Atypedef DECLCALLBACK(void) FNVBOXTLSREFDTOR(void*);
2N/Atypedef FNVBOXTLSREFDTOR *PFNVBOXTLSREFDTOR;
2N/A
2N/Atypedef enum {
2N/A VBOXTLSREFDATA_STATE_UNDEFINED = 0,
2N/A VBOXTLSREFDATA_STATE_INITIALIZED,
2N/A VBOXTLSREFDATA_STATE_TOBE_DESTROYED,
2N/A VBOXTLSREFDATA_STATE_DESTROYING,
2N/A VBOXTLSREFDATA_STATE_32BIT_HACK = 0x7fffffff
2N/A} VBOXTLSREFDATA_STATE;
2N/A
2N/A#define VBOXTLSREFDATA \
2N/A volatile int32_t cTlsRefs; \
2N/A VBOXTLSREFDATA_STATE enmTlsRefState; \
2N/A PFNVBOXTLSREFDTOR pfnTlsRefDtor; \
2N/A
2N/Astruct VBOXTLSREFDATA_DUMMY
2N/A{
2N/A VBOXTLSREFDATA
2N/A};
2N/A
2N/A#define VBOXTLSREFDATA_OFFSET(_t) RT_OFFSETOF(_t, cTlsRefs)
2N/A#define VBOXTLSREFDATA_SIZE() (sizeof (struct VBOXTLSREFDATA_DUMMY))
2N/A#define VBOXTLSREFDATA_COPY(_pDst, _pSrc) do { \
2N/A (_pDst)->cTlsRefs = (_pSrc)->cTlsRefs; \
2N/A (_pDst)->enmTlsRefState = (_pSrc)->enmTlsRefState; \
2N/A (_pDst)->pfnTlsRefDtor = (_pSrc)->pfnTlsRefDtor; \
2N/A } while (0)
2N/A
2N/A#define VBOXTLSREFDATA_EQUAL(_pDst, _pSrc) ( \
2N/A (_pDst)->cTlsRefs == (_pSrc)->cTlsRefs \
2N/A && (_pDst)->enmTlsRefState == (_pSrc)->enmTlsRefState \
2N/A && (_pDst)->pfnTlsRefDtor == (_pSrc)->pfnTlsRefDtor \
2N/A )
2N/A
2N/A
2N/A#define VBoxTlsRefInit(_p, _pfnDtor) do { \
2N/A (_p)->cTlsRefs = 1; \
2N/A (_p)->enmTlsRefState = VBOXTLSREFDATA_STATE_INITIALIZED; \
2N/A (_p)->pfnTlsRefDtor = (_pfnDtor); \
2N/A } while (0)
2N/A
2N/A#define VBoxTlsRefIsFunctional(_p) (!!((_p)->enmTlsRefState == VBOXTLSREFDATA_STATE_INITIALIZED))
2N/A
2N/A#define VBoxTlsRefAddRef(_p) do { \
2N/A int cRefs = ASMAtomicIncS32(&(_p)->cTlsRefs); \
2N/A VBoxTlsRefAssertImpl(cRefs > 1 || (_p)->enmTlsRefState == VBOXTLSREFDATA_STATE_DESTROYING); \
2N/A } while (0)
2N/A
2N/A#define VBoxTlsRefCountGet(_p) (ASMAtomicReadS32(&(_p)->cTlsRefs))
2N/A
2N/A#define VBoxTlsRefRelease(_p) do { \
2N/A int cRefs = ASMAtomicDecS32(&(_p)->cTlsRefs); \
2N/A VBoxTlsRefAssertImpl(cRefs >= 0); \
2N/A if (!cRefs && (_p)->enmTlsRefState != VBOXTLSREFDATA_STATE_DESTROYING /* <- avoid recursion if VBoxTlsRefAddRef/Release is called from dtor */) { \
2N/A (_p)->enmTlsRefState = VBOXTLSREFDATA_STATE_DESTROYING; \
2N/A (_p)->pfnTlsRefDtor((_p)); \
2N/A } \
2N/A } while (0)
2N/A
2N/A#define VBoxTlsRefMarkDestroy(_p) do { \
2N/A (_p)->enmTlsRefState = VBOXTLSREFDATA_STATE_TOBE_DESTROYED; \
2N/A } while (0)
2N/A
#define VBoxTlsRefGetCurrent(_t, _Tsd) ((_t*) VBoxTlsRefGetImpl((_Tsd)))
#define VBoxTlsRefGetCurrentFunctional(_val, _t, _Tsd) do { \
_t * cur = VBoxTlsRefGetCurrent(_t, _Tsd); \
if (!cur || VBoxTlsRefIsFunctional(cur)) { \
(_val) = cur; \
} else { \
VBoxTlsRefSetCurrent(_t, _Tsd, NULL); \
(_val) = NULL; \
} \
} while (0)
#define VBoxTlsRefSetCurrent(_t, _Tsd, _p) do { \
_t * oldCur = VBoxTlsRefGetCurrent(_t, _Tsd); \
if (oldCur != (_p)) { \
VBoxTlsRefSetImpl((_Tsd), (_p)); \
if (oldCur) { \
VBoxTlsRefRelease(oldCur); \
} \
if ((_p)) { \
VBoxTlsRefAddRef((_t*)(_p)); \
} \
} \
} while (0)
/* host 3D->Fe[/Qt] notification mechanism defines */
#define VBOX3D_NOTIFY_EVENT_TYPE_TEST_FUNCTIONAL 3
#define VBOX3D_NOTIFY_EVENT_TYPE_3DDATA_VISIBLE 4
#define VBOX3D_NOTIFY_EVENT_TYPE_3DDATA_HIDDEN 5
#endif /* #ifndef ___VBox_VBoxVideo3D_h */