summaryrefslogtreecommitdiff
path: root/src/GLX/libglxmapping.h
blob: 2c377e78858c170d1d259229f3a167a39f56f347 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
 * Copyright (c) 2013, NVIDIA CORPORATION.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and/or associated documentation files (the
 * "Materials"), to deal in the Materials without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Materials, and to
 * permit persons to whom the Materials are furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * unaltered in all copies or substantial portions of the Materials.
 * Any additions, deletions, or changes to the original source files
 * must be clearly indicated in accompanying documentation.
 *
 * If only executable code is distributed, then the accompanying
 * documentation must state that "this software is based in part on the
 * work of the Khronos Group."
 *
 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
 */

#if !defined(__LIB_GLX_MAPPING_H)
#define __LIB_GLX_MAPPING_H

#include "libglxabipriv.h"
#include "GLdispatch.h"
#include "lkdhash.h"

#define GLX_CLIENT_STRING_LAST_ATTRIB GLX_EXTENSIONS

/*!
 * Structure containing relevant per-vendor information.
 */
struct __GLXvendorInfoRec {
    int vendorID; //< unique GLdispatch ID
    char *name; //< name of the vendor
    void *dlhandle; //< shared library handle

    /// dynamic GLX dispatch table
    DEFINE_LKDHASH(struct __GLXdispatchFuncHashRec, dynDispatchHash);

    __GLdispatchTable *glDispatch; //< GL dispatch table

    const __GLXapiImports *glxvc;
    const __GLdispatchPatchCallbacks *patchCallbacks;
    __GLXdispatchTableStatic staticDispatch; //< static GLX dispatch table
};

typedef struct __GLXvendorXIDMappingHashRec __GLXvendorXIDMappingHash;

/*!
 * Structure containing per-display information.
 */
typedef struct __GLXdisplayInfoRec {
    char *clientStrings[GLX_CLIENT_STRING_LAST_ATTRIB];

    /**
     * An array of vendors for each screen.
     *
     * Do not access this directly. Instead, call \c __glXLookupVendorByScreen.
     */
    __GLXvendorInfo **vendors;
    glvnd_rwlock_t vendorLock;

    DEFINE_LKDHASH(__GLXvendorXIDMappingHash, xidVendorHash);

    /// True if the server supports the GLX extension.
    Bool glxSupported;

    /// The major opcode for GLX, if it's supported.
    int glxMajorOpcode;
    int glxFirstError;

    Bool x11glvndSupported;
    int x11glvndMajor;
    int x11glvndMinor;
} __GLXdisplayInfo;

/*!
 * Accessor functions used to retrieve the "current" dispatch table for each of
 * the three types of dispatch tables (see libglxabi.h for an explanation of
 * these types).
 */
const __GLXdispatchTableStatic * __glXGetStaticDispatch(Display *dpy,
                                                        const int screen);
__GLXvendorInfo *__glXGetDynDispatch(Display *dpy,
                                               const int screen);
__GLdispatchTable *__glXGetGLDispatch(Display *dpy, const int screen);

/*!
 * Various functions to manage mappings used to determine the screen
 * of a particular GLX call.
 */
int __glXAddVendorContextMapping(Display *dpy, GLXContext context, __GLXvendorInfo *vendor);
void __glXRemoveVendorContextMapping(Display *dpy, GLXContext context);
__GLXvendorInfo *__glXVendorFromContext(GLXContext context);

int __glXAddVendorFBConfigMapping(Display *dpy, GLXFBConfig config, __GLXvendorInfo *vendor);
void __glXRemoveVendorFBConfigMapping(Display *dpy, GLXFBConfig config);
__GLXvendorInfo *__glXVendorFromFBConfig(Display *dpy, GLXFBConfig config);

int __glXAddVendorDrawableMapping(Display *dpy, GLXDrawable drawable, __GLXvendorInfo *vendor);
void __glXRemoveVendorDrawableMapping(Display *dpy, GLXDrawable drawable);
__GLXvendorInfo *__glXVendorFromDrawable(Display *dpy, GLXDrawable drawable);

__GLXextFuncPtr __glXGetGLXDispatchAddress(const GLubyte *procName);
__GLXextFuncPtr __glXGenerateGLXEntrypoint(const GLubyte *procName);

/*!
 * Looks up the vendor by name or screen number. This has the side effect of
 * loading the vendor library if it has not been previously loaded.
 */
__GLXvendorInfo *__glXLookupVendorByName(const char *vendorName);
__GLXvendorInfo *__glXLookupVendorByScreen(Display *dpy, const int screen);

/*!
 * Looks up the __GLXdisplayInfo structure for a display, creating it if
 * necessary.
 */
__GLXdisplayInfo *__glXLookupDisplay(Display *dpy);

/*!
 * Frees the __GLXdisplayInfo structure for a display, if one exists.
 */
void __glXFreeDisplay(Display *dpy);

/*
 * Close the vendor library and perform any relevant teardown. This should
 * be called when the API library is unloaded.
 */
void __glXMappingTeardown(Bool doReset);

#endif /* __LIB_GLX_MAPPING_H */