Blame src/GLX/libglxcurrent.h

Packit 5af8b3
/*
Packit 5af8b3
 * Copyright (c) 2013, NVIDIA CORPORATION.
Packit 5af8b3
 *
Packit 5af8b3
 * Permission is hereby granted, free of charge, to any person obtaining a
Packit 5af8b3
 * copy of this software and/or associated documentation files (the
Packit 5af8b3
 * "Materials"), to deal in the Materials without restriction, including
Packit 5af8b3
 * without limitation the rights to use, copy, modify, merge, publish,
Packit 5af8b3
 * distribute, sublicense, and/or sell copies of the Materials, and to
Packit 5af8b3
 * permit persons to whom the Materials are furnished to do so, subject to
Packit 5af8b3
 * the following conditions:
Packit 5af8b3
 *
Packit 5af8b3
 * The above copyright notice and this permission notice shall be included
Packit 5af8b3
 * unaltered in all copies or substantial portions of the Materials.
Packit 5af8b3
 * Any additions, deletions, or changes to the original source files
Packit 5af8b3
 * must be clearly indicated in accompanying documentation.
Packit 5af8b3
 *
Packit 5af8b3
 * If only executable code is distributed, then the accompanying
Packit 5af8b3
 * documentation must state that "this software is based in part on the
Packit 5af8b3
 * work of the Khronos Group."
Packit 5af8b3
 *
Packit 5af8b3
 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Packit 5af8b3
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit 5af8b3
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Packit 5af8b3
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
Packit 5af8b3
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
Packit 5af8b3
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
Packit 5af8b3
 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
Packit 5af8b3
 */
Packit 5af8b3
Packit 5af8b3
#if !defined(__LIB_GLX_TLS)
Packit 5af8b3
#define __LIB_GLX_TLS
Packit 5af8b3
Packit 5af8b3
#include <pthread.h>
Packit 5af8b3
Packit 5af8b3
#include "libglxthread.h"
Packit 5af8b3
#include "libglxabipriv.h"
Packit 5af8b3
#include "libglxmapping.h"
Packit 5af8b3
#include "GLdispatch.h"
Packit 5af8b3
#include "lkdhash.h"
Packit 5af8b3
#include "glvnd_list.h"
Packit 5af8b3
Packit 5af8b3
typedef struct __GLXcontextInfoRec __GLXcontextInfo;
Packit 5af8b3
Packit 5af8b3
/*!
Packit 5af8b3
 * Define current API library state here.
Packit 5af8b3
 *
Packit 5af8b3
 * A thread will have a __GLXThreadState struct if and only if it has a current
Packit 5af8b3
 * GLX context. If we don't have a current context, then there's nothing useful
Packit 5af8b3
 * to store in it.
Packit 5af8b3
 *
Packit 5af8b3
 * The pointer to the current __GLXThreadState is stored in libGLdispatch, since
Packit 5af8b3
 * it's also the current __GLdispatchThreadState struct.
Packit 5af8b3
 */
Packit 5af8b3
typedef struct __GLXThreadStateRec {
Packit 5af8b3
    __GLdispatchThreadState glas; /* Must be the first entry! */
Packit 5af8b3
Packit 5af8b3
    __GLXvendorInfo *currentVendor;
Packit 5af8b3
Packit 5af8b3
    Display *currentDisplay;
Packit 5af8b3
    GLXDrawable currentDraw;
Packit 5af8b3
    GLXDrawable currentRead;
Packit 5af8b3
    __GLXcontextInfo *currentContext;
Packit 5af8b3
Packit 5af8b3
    struct glvnd_list entry;
Packit 5af8b3
} __GLXThreadState;
Packit 5af8b3
Packit 5af8b3
/*!
Packit 5af8b3
 * Looks up the current thread state.
Packit 5af8b3
 *
Packit 5af8b3
 * If there isn't a current context, or if the current context was set by
Packit 5af8b3
 * another library like EGL, then this will return \c NULL.
Packit 5af8b3
 */
Packit 5af8b3
static inline __GLXThreadState *__glXGetCurrentThreadState(void)
Packit 5af8b3
{
Packit 5af8b3
    __GLdispatchThreadState *glas = __glDispatchGetCurrentThreadState();
Packit 5af8b3
    if (unlikely(!glas ||
Packit 5af8b3
                 (glas->tag != GLDISPATCH_API_GLX))) {
Packit 5af8b3
        return NULL;
Packit 5af8b3
    } else {
Packit 5af8b3
        return (__GLXThreadState *)(glas);
Packit 5af8b3
    }
Packit 5af8b3
}
Packit 5af8b3
Packit 5af8b3
/*!
Packit 5af8b3
 * This gets the current GLX dynamic dispatch table, which is stored in the
Packit 5af8b3
 * thread state.
Packit 5af8b3
 */
Packit 5af8b3
__GLXvendorInfo *__glXGetCurrentDynDispatch(void);
Packit 5af8b3
Packit 5af8b3
#endif // !defined(__LIB_GLX_TLS)