summaryrefslogtreecommitdiff
path: root/glx/extension_string.c
blob: 616c7932e6eb8dad8adec46d1fd5e4ea27500f66 (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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
 * (C) Copyright IBM Corporation 2002-2006
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * on the rights to use, copy, modify, merge, publish, distribute, sub
 * license, and/or sell copies of the Software, and to permit persons to whom
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS 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 NON-INFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS 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 SOFTWARE OR THE
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

/**
 * \file extension_string.c
 * Routines to manage the GLX extension string and GLX version for AIGLX
 * drivers.  This code is loosely based on src/glx/x11/glxextensions.c from
 * Mesa.
 *
 * \author Ian Romanick <idr@us.ibm.com>
 */

#include <string.h>
#include "extension_string.h"

#define SET_BIT(m,b)    (m[ (b) / 8 ] |=  (1U << ((b) % 8)))
#define CLR_BIT(m,b)    (m[ (b) / 8 ] &= ~(1U << ((b) % 8)))
#define IS_SET(m,b)    ((m[ (b) / 8 ] &   (1U << ((b) % 8))) != 0)
#define CONCAT(a,b) a ## b
#define GLX(n) "GLX_" # n, 4 + sizeof( # n ) - 1, CONCAT(n,_bit)
#define VER(a,b)  a, b
#define Y  1
#define N  0
#define EXT_ENABLED(bit,supported) (IS_SET(supported, bit))

struct extension_info {
    const char *const name;
    unsigned name_len;

    unsigned char bit;

    /**
     * This is the lowest version of GLX that "requires" this extension.
     * For example, GLX 1.3 requires SGIX_fbconfig, SGIX_pbuffer, and
     * SGI_make_current_read.  If the extension is not required by any known
     * version of GLX, use 0, 0.
     */
    unsigned char version_major;
    unsigned char version_minor;

    /**
     * Is driver support forced by the ABI?
     */
    unsigned char driver_support;
};

/**
 * List of known GLX Extensions.
 * The last Y/N switch informs whether the support of this extension is always enabled.
 */
static const struct extension_info known_glx_extensions[] = {
/*   GLX_ARB_get_proc_address is implemented on the client. */
    /* *INDENT-OFF* */
    { GLX(ARB_context_flush_control),   VER(0,0), N, },
    { GLX(ARB_create_context),          VER(0,0), N, },
    { GLX(ARB_create_context_profile),  VER(0,0), N, },
    { GLX(ARB_create_context_robustness), VER(0,0), N, },
    { GLX(ARB_fbconfig_float),          VER(0,0), N, },
    { GLX(ARB_framebuffer_sRGB),        VER(0,0), N, },
    { GLX(ARB_multisample),             VER(1,4), Y, },

    { GLX(EXT_create_context_es_profile), VER(0,0), N, },
    { GLX(EXT_create_context_es2_profile), VER(0,0), N, },
    { GLX(EXT_fbconfig_packed_float),   VER(0,0), N, },
    { GLX(EXT_framebuffer_sRGB),        VER(0,0), N, },
    { GLX(EXT_import_context),          VER(0,0), Y, },
    { GLX(EXT_stereo_tree),             VER(0,0), N, },
    { GLX(EXT_texture_from_pixmap),     VER(0,0), Y, },
    { GLX(EXT_visual_info),             VER(0,0), Y, },
    { GLX(EXT_visual_rating),           VER(0,0), Y, },

    { GLX(MESA_copy_sub_buffer),        VER(0,0), N, },
    { GLX(OML_swap_method),             VER(0,0), Y, },
    { GLX(SGI_make_current_read),       VER(1,3), N, },
    { GLX(SGI_swap_control),            VER(0,0), N, },
    { GLX(SGIS_multisample),            VER(0,0), Y, },
    { GLX(SGIX_fbconfig),               VER(1,3), Y, },
    { GLX(SGIX_pbuffer),                VER(1,3), Y, },
    { GLX(SGIX_visual_select_group),    VER(0,0), Y, },
    { GLX(INTEL_swap_event),            VER(0,0), N, },
    { NULL }
    /* *INDENT-ON* */
};

/**
 * Create a GLX extension string for a set of enable bits.
 *
 * Creates a GLX extension string for the set of bit in \c enable_bits.  This
 * string is then stored in \c buffer if buffer is not \c NULL.  This allows
 * two-pass operation.  On the first pass the caller passes \c NULL for
 * \c buffer, and the function determines how much space is required to store
 * the extension string.  The caller allocates the buffer and calls the
 * function again.
 *
 * \param enable_bits  Bits representing the enabled extensions.
 * \param buffer       Buffer to store the extension string.  May be \c NULL.
 *
 * \return
 * The number of characters in \c buffer that were written to.  If \c buffer
 * is \c NULL, this is the size of buffer that must be allocated by the
 * caller.
 */
int
__glXGetExtensionString(const unsigned char *enable_bits, char *buffer)
{
    unsigned i;
    int length = 0;

    for (i = 0; known_glx_extensions[i].name != NULL; i++) {
        const unsigned bit = known_glx_extensions[i].bit;
        const size_t len = known_glx_extensions[i].name_len;

        if (EXT_ENABLED(bit, enable_bits)) {
            if (buffer != NULL) {
                (void) memcpy(&buffer[length], known_glx_extensions[i].name,
                              len);

                buffer[length + len + 0] = ' ';
                buffer[length + len + 1] = '\0';
            }

            length += len + 1;
        }
    }

    return length + 1;
}

void
__glXEnableExtension(unsigned char *enable_bits, const char *ext)
{
    const size_t ext_name_len = strlen(ext);
    unsigned i;

    for (i = 0; known_glx_extensions[i].name != NULL; i++) {
        if ((ext_name_len == known_glx_extensions[i].name_len)
            && (memcmp(ext, known_glx_extensions[i].name, ext_name_len) == 0)) {
            SET_BIT(enable_bits, known_glx_extensions[i].bit);
            break;
        }
    }
}

void
__glXInitExtensionEnableBits(unsigned char *enable_bits)
{
    unsigned i;

    (void) memset(enable_bits, 0, __GLX_EXT_BYTES);

    for (i = 0; known_glx_extensions[i].name != NULL; i++) {
        if (known_glx_extensions[i].driver_support) {
            SET_BIT(enable_bits, known_glx_extensions[i].bit);
        }
    }
}