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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
|
/*
* (c) Copyright IBM Corporation 2002
* 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.
*
* Authors:
* Ian Romanick <idr@us.ibm.com>
*/
/* $XFree86:$ */
#include "packsingle.h"
#include "glxclient.h"
#include <extutil.h>
#include <Xext.h>
#include <string.h>
#include "glapi.h"
#include "glxextensions.h"
#include "simple_list.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, CONCAT(n,_bit)
#define GLX2(n,b) "GLX_" # n, CONCAT(b,_bit)
#define VER(a,b) a, b
#define Y 1
#define N 0
#define EXT_ENABLED(bit,supported) ((bit < 255) && IS_SET( supported, bit ))
struct glx_extension {
struct glx_extension * next;
struct glx_extension * prev;
char * name;
GLuint name_len;
unsigned char bit;
unsigned char version_major;
unsigned char version_minor;
};
static struct {
const char * const name;
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;
unsigned char client_support:1;
unsigned char direct_support:1;
unsigned char client_only:1; /** Is the extension client-side only? */
unsigned char direct_only:1; /** Is the extension for direct
* contexts only?
*/
} default_glx_extensions[] = {
{ GLX(ARB_get_proc_address), VER(1,4), Y, N, Y, N },
{ GLX(ARB_multisample), VER(0,0), Y, N, N, N },
{ GLX(ARB_render_texture), VER(0,0), N, N, N, N },
{ GLX(ATI_pixel_format_float), VER(0,0), N, N, N, N },
{ GLX(EXT_import_context), VER(0,0), Y, Y, N, N },
{ GLX(EXT_visual_info), VER(0,0), Y, Y, N, N },
{ GLX(EXT_visual_rating), VER(0,0), Y, Y, N, N },
{ GLX(MESA_agp_offset), VER(0,0), N, N, N, Y },
{ GLX(MESA_copy_sub_buffer), VER(0,0), N, N, N, N }, /* Depricated? */
{ GLX(MESA_pixmap_colormap), VER(0,0), N, N, N, N }, /* Depricated */
{ GLX(MESA_release_buffers), VER(0,0), N, N, N, N }, /* Depricated */
{ GLX(MESA_set_3dfx_mode), VER(0,0), N, N, N, N }, /* Depricated */
{ GLX(MESA_swap_control), VER(0,0), Y, N, N, Y },
{ GLX(MESA_swap_frame_usage), VER(0,0), Y, N, N, Y },
{ GLX(NV_float_buffer), VER(0,0), N, N, N, N },
{ GLX(NV_render_depth_texture), VER(0,0), N, N, N, N },
{ GLX(NV_render_texture_rectangle), VER(0,0), N, N, N, N },
{ GLX(NV_vertex_array_range), VER(0,0), N, N, N, Y },
{ GLX(OML_swap_method), VER(0,0), Y, N, N, N },
{ GLX(OML_sync_control), VER(0,0), Y, N, N, Y },
{ GLX(SGI_cushion), VER(0,0), N, N, N, N },
{ GLX(SGI_make_current_read), VER(1,3), N, N, N, N },
{ GLX(SGI_swap_control), VER(0,0), Y, N, N, N },
{ GLX(SGI_video_sync), VER(0,0), Y, N, N, Y },
{ GLX(SGIS_blended_overlay), VER(0,0), N, N, N, N },
{ GLX(SGIS_color_range), VER(0,0), N, N, N, N },
{ GLX(SGIS_multisample), VER(0,0), Y, N, N, N },
{ GLX(SGIX_dm_buffer), VER(0,0), N, N, N, N },
{ GLX(SGIX_fbconfig), VER(1,3), Y, N, N, N },
{ GLX(SGIX_pbuffer), VER(1,3), N, N, N, N },
{ GLX(SGIX_swap_barrier), VER(0,0), N, N, N, N },
{ GLX(SGIX_swap_group), VER(0,0), N, N, N, N },
{ GLX(SGIX_video_resize), VER(0,0), N, N, N, N },
{ GLX(SGIX_video_source), VER(0,0), N, N, N, N },
{ GLX(SGIX_visual_select_group), VER(0,0), Y, N, N, N },
{ GLX(SUN_get_transparent_index), VER(0,0), N, N, N, N },
{ NULL }
};
static struct glx_extension ext_list;
static GLboolean ext_list_first_time = GL_TRUE;
static GLuint next_bit = 0;
static unsigned char client_support[8];
static unsigned char direct_support[8];
static unsigned char client_only[8];
static unsigned char direct_only[8];
static const char * __glXGLXClientExtensions = NULL;
static void __glXExtensionsCtr( void );
static void __glXProcessServerString( const char * server_string,
unsigned char * server_support );
/**
* Set the state of a GLX extension.
*
* \param name Name of the extension.
* \param name_len Length, in characters, of the extension name.
* \param state New state (either enabled or disabled) of the extension.
* \param supported Table in which the state of the extension is to be set.
*/
static void
set_glx_extension( const char * name, unsigned name_len, GLboolean state,
unsigned char * supported )
{
struct glx_extension * i;
foreach( i, & ext_list ) {
if ( (name_len == i->name_len)
&& (strncmp( i->name, name, name_len ) == 0) ) {
if ( state ) {
SET_BIT( supported, i->bit );
}
else {
CLR_BIT( supported, i->bit );
}
return;
}
}
}
#define NUL '\0'
#define SEPARATOR ' '
/**
* Convert the server's extension string to a bit-field.
*
* \param server_string GLX extension string from the server.
* \param server_support Bit-field of supported extensions.
*/
static void
__glXProcessServerString( const char * server_string,
unsigned char * server_support )
{
unsigned base;
unsigned len;
(void) memset( server_support, 0, sizeof( server_support ) );
for ( base = 0 ; server_string[ base ] != NUL ; /* empty */ ) {
/* Determine the length of the next extension name.
*/
for ( len = 0
; (server_string[ base + len ] != SEPARATOR)
&& (server_string[ base + len ] != NUL)
; len++ ) {
/* empty */
}
/* Set the bit for the extension in the server_support table.
*/
set_glx_extension( & server_string[ base ], len, GL_TRUE,
server_support );
/* Advance to the next extension string. This means that we skip
* over the previous string and any trialing white-space.
*/
for ( base += len ;
(server_string[ base ] == SEPARATOR)
&& (server_string[ base ] != NUL)
; base++ ) {
/* empty */
}
}
}
/**
* Enable a named GLX extension.
*
* \param name Name of the extension to enable.
* \param force_client Enable client-side suuport also. If this is set
* to GL_TRUE, then the driver MUST supply function
* entry-points via \c __glXRegisterGLXFunction.
* \sa __glXRegisterGLXFunction, __glXDisableExtension
*/
void
__glXEnableExtension( const char * name, GLboolean force_client )
{
if ( __glXGLXClientExtensions == NULL ) {
__glXExtensionsCtr();
set_glx_extension( name, strlen( name ), GL_TRUE, direct_support );
if ( force_client ) {
set_glx_extension( name, strlen( name ), GL_TRUE, client_support );
}
}
}
/**
* Disable a named GLX extension.
*
* \param name Name of the extension to disable.
* \sa __glXEnableExtension
*/
void
__glXDisableExtension( const char * name )
{
if ( __glXGLXClientExtensions == NULL ) {
__glXExtensionsCtr();
set_glx_extension( name, strlen( name ), GL_FALSE, direct_support );
}
}
/**
* Add an extension to the global list of known GLX extensions.
*
* \param enabled Default state of the extension.
* \param name Text name of the extension.
* \param version_major Major GLX version that requires this extension.
* \param version_minor Minor GLX version that requires this extension.
* \param bit Bit number in the global table that is set if this
* extension is enabled.
* \param client_only_flag Is this extension client-side only?
*/
static void
add_extension( const char * name, GLuint version_major, GLuint version_minor,
GLuint bit,
GLboolean client_enabled_flag, GLboolean direct_enabled_flag,
GLboolean client_only_flag, GLboolean direct_only_flag )
{
struct glx_extension * ext;
unsigned name_len;
name_len = strlen( name );
ext = Xmalloc( sizeof( *ext ) + name_len + 1 );
if ( ext != NULL ) {
ext->bit = bit;
ext->version_major = version_major;
ext->version_minor = version_minor;
if ( client_enabled_flag ) {
SET_BIT( client_support, bit );
}
else {
CLR_BIT( client_support, bit );
}
if ( direct_enabled_flag ) {
SET_BIT( direct_support, bit );
}
else {
CLR_BIT( direct_support, bit );
}
if ( client_only_flag ) {
SET_BIT( client_only, bit );
}
else {
CLR_BIT( client_only, bit );
}
if ( direct_only_flag ) {
SET_BIT( direct_only, bit );
}
else {
CLR_BIT( direct_only, bit );
}
ext->name = (char *)(ext + 1);
(void) memcpy( ext->name, name, name_len );
ext->name[ name_len ] = '\0';
ext->name_len = name_len;
insert_at_tail( & ext_list, ext );
}
}
/**
* Add a new extension string to the set of possible strings. This is
* intended to be used by drivers to advertise support for unlisted,
* proprietary extensions.
*
* \param enabled Is the extension enabled by default?
* \param name Name of the extension.
* \param client_only Is the extension client-side only?
*/
void
__glXAddExtension( GLboolean enabled, const char * name,
GLboolean client_only )
{
if ( __glXGLXClientExtensions == NULL ) {
GLuint bit;
__glXExtensionsCtr();
bit = next_bit;
if ( next_bit < 255 ) {
next_bit++;
}
add_extension( name, 0, 0, bit, enabled, enabled,
client_only, GL_TRUE );
}
}
static void
__glXExtensionsCtr( void )
{
unsigned i;
if ( ext_list_first_time ) {
ext_list_first_time = GL_FALSE;
(void) memset( client_support, 0, sizeof( client_support ) );
(void) memset( direct_support, 0, sizeof( direct_support ) );
(void) memset( client_only, 0, sizeof( client_only ) );
(void) memset( direct_only, 0, sizeof( direct_only ) );
make_empty_list( & ext_list );
for ( i = 0 ; default_glx_extensions[i].name != NULL ; i++ ) {
add_extension( default_glx_extensions[i].name,
default_glx_extensions[i].version_major,
default_glx_extensions[i].version_minor,
default_glx_extensions[i].bit,
default_glx_extensions[i].client_support,
default_glx_extensions[i].direct_support,
default_glx_extensions[i].client_only,
default_glx_extensions[i].direct_only );
if ( default_glx_extensions[i].bit >= next_bit ) {
next_bit = default_glx_extensions[i].bit + 1;
}
}
}
}
GLboolean
__glXExtensionBitIsEnabled( unsigned bit )
{
__glXExtensionsCtr();
return EXT_ENABLED( bit, direct_support );
}
/**
* Convert a bit-field to a string of supported extensions.
*/
static char *
__glXGetStringFromTable( const unsigned char * supported )
{
struct glx_extension * i;
unsigned ext_str_len;
char * ext_str;
char * point;
ext_str_len = 0;
foreach( i, & ext_list ) {
if ( EXT_ENABLED( i->bit, supported ) ) {
ext_str_len += i->name_len + 1;
}
}
ext_str = Xmalloc( ext_str_len + 1 );
if ( ext_str != NULL ) {
point = ext_str;
foreach( i, & ext_list ) {
if ( EXT_ENABLED( i->bit, supported ) ) {
(void) memcpy( point, i->name, i->name_len );
point += i->name_len;
*point = ' ';
point++;
}
}
*point = '\0';
}
return ext_str;
}
/**
* Get the string of client library supported extensions.
*/
const char *
__glXGetClientExtensions( void )
{
if ( __glXGLXClientExtensions == NULL ) {
__glXExtensionsCtr();
__glXGLXClientExtensions = __glXGetStringFromTable( client_support );
}
return __glXGLXClientExtensions;
}
/**
* Get the list of application usable extensions.
*
* \returns A pointer to the string.
*/
char *
__glXGetUsableExtensions( const char * server_string )
{
unsigned char server_support[8];
unsigned char usable[8];
unsigned i;
__glXExtensionsCtr();
__glXProcessServerString( server_string, server_support );
/* An extension is supported if the client-side (i.e., libGL) supports
* it and the "server" supports it. In this case that means that either
* the true server supports it or it is only for direct-rendering and
* the direct rendering driver supports it.
*/
for ( i = 0 ; i < 8 ; i++ ) {
usable[i] = (client_support[i] & client_only[i])
| (client_support[i] & (direct_support[i] & server_support[i]))
| (client_support[i] & (direct_support[i] & direct_only[i]));
}
return __glXGetStringFromTable( usable );
}
|