• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * (C) Copyright IBM Corporation 2002, 2004
3  * All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * on the rights to use, copy, modify, merge, publish, distribute, sub
9  * license, and/or sell copies of the Software, and to permit persons to whom
10  * the Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
19  * THE COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22  * USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 /**
26  * \file glxextensions.c
27  *
28  * \author Ian Romanick <idr@us.ibm.com>
29  */
30 
31 #include "glxclient.h"
32 #include <X11/extensions/extutil.h>
33 #include <X11/extensions/Xext.h>
34 #include <string.h>
35 #include "glxextensions.h"
36 
37 #include "util/driconf.h"
38 
39 #define SET_BIT(m,b)   (m[ (b) / 8 ] |=  (1U << ((b) % 8)))
40 #define CLR_BIT(m,b)   (m[ (b) / 8 ] &= ~(1U << ((b) % 8)))
41 #define IS_SET(m,b)    ((m[ (b) / 8 ] & (1U << ((b) % 8))) != 0)
42 #define CONCAT(a,b) a ## b
43 #define GLX(n) "GLX_" # n, 4 + sizeof( # n ) - 1, CONCAT(n,_bit)
44 #define GL(n)  "GL_" # n,  3 + sizeof( # n ) - 1, GL_ ## n ## _bit
45 #define Y  1
46 #define N  0
47 #define EXT_ENABLED(bit,supported) (IS_SET( supported, bit ))
48 
49 
50 struct extension_info
51 {
52    const char *const name;
53    unsigned name_len;
54 
55    unsigned char bit;
56 
57    /**
58     * The direct-renderer (e.g., i965_dri.so) supports this extension.
59     *
60     * For cases where all of the infrastructure to support the extension is a
61     * required part of the loader/driver interface, this can default to Y.
62     * For most cases, extended functionality, usually in the form of DRI2
63     * extensions, is necessary to support the extension.  The loader will set
64     * the flag true if all the requirements are met.
65     *
66     * If the display is capable of direct rendering, ::direct_support is
67     * required for the extension to be enabled.
68     */
69    unsigned char direct_support;
70 
71    /**
72     * The extension only functions with direct-rendering contexts
73     *
74     * The extension has no GLX protocol, and, therefore, no explicit
75     * dependency on the server.  The functionality is contained entirely in
76     * the client library and the direct renderer.  A few of the swap-related
77     * extensions are intended to behave this way.
78     */
79    unsigned char direct_only;
80 };
81 
82 /* *INDENT-OFF* */
83 static const struct extension_info known_glx_extensions[] = {
84    { GLX(ARB_context_flush_control),      N, N },
85    { GLX(ARB_create_context),             N, N },
86    { GLX(ARB_create_context_no_error),    N, N },
87    { GLX(ARB_create_context_profile),     N, N },
88    { GLX(ARB_create_context_robustness),  N, N },
89    { GLX(ARB_fbconfig_float),             Y, N },
90    { GLX(ARB_framebuffer_sRGB),           Y, N },
91    { GLX(ARB_get_proc_address),           N, N },
92    { GLX(ARB_multisample),                Y, N },
93    { GLX(EXT_buffer_age),                 N, Y },
94    { GLX(EXT_create_context_es2_profile), N, N },
95    { GLX(EXT_create_context_es_profile),  N, N },
96    { GLX(EXT_fbconfig_packed_float),      Y, N },
97    { GLX(EXT_framebuffer_sRGB),           Y, N },
98    { GLX(EXT_import_context),             Y, N },
99    { GLX(EXT_no_config_context),          N, N },
100    { GLX(EXT_swap_control),               N, Y },
101    { GLX(EXT_swap_control_tear),          N, Y },
102    { GLX(EXT_texture_from_pixmap),        N, N },
103    { GLX(EXT_visual_info),                Y, N },
104    { GLX(EXT_visual_rating),              Y, N },
105    { GLX(ATI_pixel_format_float),         N, N },
106    { GLX(INTEL_swap_event),               N, N },
107    { GLX(MESA_copy_sub_buffer),           N, N },
108    { GLX(MESA_multithread_makecurrent),   N, Y },
109    { GLX(MESA_query_renderer),            N, Y },
110    { GLX(MESA_swap_control),              N, Y },
111    { GLX(NV_float_buffer),                N, N },
112    { GLX(OML_swap_method),                Y, N },
113    { GLX(OML_sync_control),               N, Y },
114    { GLX(SGIS_multisample),               Y, N },
115    { GLX(SGIX_fbconfig),                  Y, N },
116    { GLX(SGIX_pbuffer),                   Y, N },
117    { GLX(SGIX_visual_select_group),       Y, N },
118    { GLX(SGI_make_current_read),          N, N },
119    { GLX(SGI_swap_control),               N, N },
120    { GLX(SGI_video_sync),                 N, Y },
121    { NULL }
122 };
123 
124 static const struct extension_info known_gl_extensions[] = {
125    { GL(ARB_depth_texture),               N, N },
126    { GL(ARB_draw_buffers),                N, N },
127    { GL(ARB_fragment_program),            N, N },
128    { GL(ARB_fragment_program_shadow),     N, N },
129    { GL(ARB_framebuffer_object),          N, N },
130    { GL(ARB_imaging),                     N, N },
131    { GL(ARB_multisample),                 N, N },
132    { GL(ARB_multitexture),                N, N },
133    { GL(ARB_occlusion_query),             N, N },
134    { GL(ARB_point_parameters),            N, N },
135    { GL(ARB_point_sprite),                N, N },
136    { GL(ARB_shadow),                      N, N },
137    { GL(ARB_shadow_ambient),              N, N },
138    { GL(ARB_texture_border_clamp),        N, N },
139    { GL(ARB_texture_compression),         N, N },
140    { GL(ARB_texture_cube_map),            N, N },
141    { GL(ARB_texture_env_add),             N, N },
142    { GL(ARB_texture_env_combine),         N, N },
143    { GL(ARB_texture_env_crossbar),        N, N },
144    { GL(ARB_texture_env_dot3),            N, N },
145    { GL(ARB_texture_filter_anisotropic),  N, N },
146    { GL(ARB_texture_mirrored_repeat),     N, N },
147    { GL(ARB_texture_non_power_of_two),    N, N },
148    { GL(ARB_texture_rectangle),           N, N },
149    { GL(ARB_texture_rg),                  N, N },
150    { GL(ARB_transpose_matrix),            N, N },
151    { GL(ARB_vertex_program),              N, N },
152    { GL(ARB_window_pos),                  N, N },
153    { GL(EXT_abgr),                        N, N },
154    { GL(EXT_bgra),                        N, N },
155    { GL(EXT_blend_color),                 N, N },
156    { GL(EXT_blend_equation_separate),     N, N },
157    { GL(EXT_blend_func_separate),         N, N },
158    { GL(EXT_blend_logic_op),              N, N },
159    { GL(EXT_blend_minmax),                N, N },
160    { GL(EXT_blend_subtract),              N, N },
161    { GL(EXT_clip_volume_hint),            N, N },
162    { GL(EXT_copy_texture),                N, N },
163    { GL(EXT_draw_range_elements),         N, N },
164    { GL(EXT_fog_coord),                   N, N },
165    { GL(EXT_framebuffer_blit),            N, N },
166    { GL(EXT_framebuffer_multisample),     N, N },
167    { GL(EXT_framebuffer_object),          N, N },
168    { GL(EXT_framebuffer_sRGB),            N, N },
169    { GL(EXT_multi_draw_arrays),           N, N },
170    { GL(EXT_packed_depth_stencil),        N, N },
171    { GL(EXT_packed_pixels),               N, N },
172    { GL(EXT_paletted_texture),            N, N },
173    { GL(EXT_point_parameters),            N, N },
174    { GL(EXT_polygon_offset),              N, N },
175    { GL(EXT_rescale_normal),              N, N },
176    { GL(EXT_secondary_color),             N, N },
177    { GL(EXT_separate_specular_color),     N, N },
178    { GL(EXT_shadow_funcs),                N, N },
179    { GL(EXT_shared_texture_palette),      N, N },
180    { GL(EXT_stencil_two_side),            N, N },
181    { GL(EXT_stencil_wrap),                N, N },
182    { GL(EXT_subtexture),                  N, N },
183    { GL(EXT_texture),                     N, N },
184    { GL(EXT_texture3D),                   N, N },
185    { GL(EXT_texture_compression_dxt1),    N, N },
186    { GL(EXT_texture_compression_s3tc),    N, N },
187    { GL(EXT_texture_edge_clamp),          N, N },
188    { GL(EXT_texture_env_add),             N, N },
189    { GL(EXT_texture_env_combine),         N, N },
190    { GL(EXT_texture_env_dot3),            N, N },
191    { GL(EXT_texture_filter_anisotropic),  N, N },
192    { GL(EXT_texture_integer),             N, N },
193    { GL(EXT_texture_lod),                 N, N },
194    { GL(EXT_texture_lod_bias),            N, N },
195    { GL(EXT_texture_mirror_clamp),        N, N },
196    { GL(EXT_texture_object),              N, N },
197    { GL(EXT_texture_rectangle),           N, N },
198    { GL(EXT_vertex_array),                N, N },
199    { GL(3DFX_texture_compression_FXT1),   N, N },
200    { GL(APPLE_packed_pixels),             N, N },
201    { GL(APPLE_ycbcr_422),                 N, N },
202    { GL(ATI_draw_buffers),                N, N },
203    { GL(ATI_text_fragment_shader),        N, N },
204    { GL(ATI_texture_env_combine3),        N, N },
205    { GL(ATI_texture_float),               N, N },
206    { GL(ATI_texture_mirror_once),         N, N },
207    { GL(ATIX_texture_env_combine3),       N, N },
208    { GL(HP_convolution_border_modes),     N, N },
209    { GL(HP_occlusion_test),               N, N },
210    { GL(IBM_cull_vertex),                 N, N },
211    { GL(IBM_pixel_filter_hint),           N, N },
212    { GL(IBM_rasterpos_clip),              N, N },
213    { GL(IBM_texture_clamp_nodraw),        N, N },
214    { GL(IBM_texture_mirrored_repeat),     N, N },
215    { GL(INGR_blend_func_separate),        N, N },
216    { GL(INGR_interlace_read),             N, N },
217    { GL(MESA_pack_invert),                N, N },
218    { GL(MESA_ycbcr_texture),              N, N },
219    { GL(NV_blend_square),                 N, N },
220    { GL(NV_copy_depth_to_color),          N, N },
221    { GL(NV_depth_clamp),                  N, N },
222    { GL(NV_fog_distance),                 N, N },
223    { GL(NV_fragment_program),             N, N },
224    { GL(NV_fragment_program_option),      N, N },
225    { GL(NV_fragment_program2),            N, N },
226    { GL(NV_light_max_exponent),           N, N },
227    { GL(NV_multisample_filter_hint),      N, N },
228    { GL(NV_packed_depth_stencil),         N, N },
229    { GL(NV_point_sprite),                 N, N },
230    { GL(NV_texgen_reflection),            N, N },
231    { GL(NV_texture_compression_vtc),      N, N },
232    { GL(NV_texture_env_combine4),         N, N },
233    { GL(NV_texture_rectangle),            N, N },
234    { GL(NV_vertex_program),               N, N },
235    { GL(NV_vertex_program1_1),            N, N },
236    { GL(NV_vertex_program2),              N, N },
237    { GL(NV_vertex_program2_option),       N, N },
238    { GL(NV_vertex_program3),              N, N },
239    { GL(OES_read_format),                 N, N },
240    { GL(OES_compressed_paletted_texture), N, N },
241    { GL(SGI_color_matrix),                N, N },
242    { GL(SGI_color_table),                 N, N },
243    { GL(SGI_texture_color_table),         N, N },
244    { GL(SGIS_generate_mipmap),            N, N },
245    { GL(SGIS_multisample),                N, N },
246    { GL(SGIS_texture_border_clamp),       N, N },
247    { GL(SGIS_texture_edge_clamp),         N, N },
248    { GL(SGIS_texture_lod),                N, N },
249    { GL(SGIX_blend_alpha_minmax),         N, N },
250    { GL(SGIX_clipmap),                    N, N },
251    { GL(SGIX_depth_texture),              N, N },
252    { GL(SGIX_fog_offset),                 N, N },
253    { GL(SGIX_shadow),                     N, N },
254    { GL(SGIX_shadow_ambient),             N, N },
255    { GL(SGIX_texture_coordinate_clamp),   N, N },
256    { GL(SGIX_texture_lod_bias),           N, N },
257    { GL(SGIX_texture_range),              N, N },
258    { GL(SGIX_texture_scale_bias),         N, N },
259    { GL(SGIX_vertex_preclip),             N, N },
260    { GL(SGIX_vertex_preclip_hint),        N, N },
261    { GL(SGIX_ycrcb),                      N, N },
262    { GL(SUN_convolution_border_modes),    N, N },
263    { GL(SUN_multi_draw_arrays),           N, N },
264    { GL(SUN_slice_accum),                 N, N },
265    { NULL }
266 };
267 /* *INDENT-ON* */
268 
269 
270 /* global bit-fields of available extensions and their characteristics */
271 static unsigned char client_glx_only[__GLX_EXT_BYTES];
272 static unsigned char direct_glx_only[__GLX_EXT_BYTES];
273 
274 /**
275  * Bits representing the set of extensions that are enabled by default in all
276  * direct rendering drivers.
277  */
278 static unsigned char direct_glx_support[__GLX_EXT_BYTES];
279 
280 /* client extensions string */
281 static const char *__glXGLXClientExtensions = NULL;
282 
283 static void __glXExtensionsCtr(void);
284 static void __glXExtensionsCtrScreen(struct glx_screen * psc);
285 static void __glXProcessServerString(const struct extension_info *ext,
286                                      const char *server_string,
287                                      unsigned char *server_support);
288 
289 /**
290  * Find an extension in the list based on its name.
291  *
292  * \param ext       List of extensions where to search.
293  * \param name      Name of the extension.
294  * \param name_len  Length, in characters, of the extension name.
295  */
296 static const struct extension_info *
find_extension(const struct extension_info * ext,const char * name,unsigned name_len)297 find_extension(const struct extension_info *ext, const char *name,
298                unsigned name_len)
299 {
300    unsigned i;
301 
302    for (i = 0; ext[i].name != NULL; i++) {
303       if ((name_len == ext[i].name_len)
304           && (strncmp(ext[i].name, name, name_len) == 0)) {
305          return &ext[i];
306       }
307    }
308 
309    return NULL;
310 }
311 
312 /**
313  * Set the state of a GLX extension.
314  *
315  * \param name      Name of the extension.
316  * \param name_len  Length, in characters, of the extension name.
317  * \param state     New state (either enabled or disabled) of the extension.
318  * \param supported Table in which the state of the extension is to be set.
319  */
320 static void
set_glx_extension(const struct extension_info * ext_list,const char * name,unsigned name_len,GLboolean state,unsigned char * supported)321 set_glx_extension(const struct extension_info *ext_list,
322                   const char *name, unsigned name_len, GLboolean state,
323                   unsigned char *supported)
324 {
325    const struct extension_info *ext = find_extension(ext_list, name, name_len);
326    if (!ext)
327        return;
328 
329    if (state) {
330       SET_BIT(supported, ext->bit);
331    } else {
332       CLR_BIT(supported, ext->bit);
333    }
334 }
335 
336 
337 #define NUL '\0'
338 #define SEPARATOR ' '
339 
340 /**
341  * Convert the server's extension string to a bit-field.
342  *
343  * \param server_string   GLX extension string from the server.
344  * \param server_support  Bit-field of supported extensions.
345  *
346  * \note
347  * This function is used to process both GLX and GL extension strings.  The
348  * bit-fields used to track each of these have different sizes.  Therefore,
349  * the data pointed by \c server_support must be preinitialized to zero.
350  */
351 static void
__glXProcessServerString(const struct extension_info * ext,const char * server_string,unsigned char * server_support)352 __glXProcessServerString(const struct extension_info *ext,
353                          const char *server_string,
354                          unsigned char *server_support)
355 {
356    unsigned base;
357    unsigned len;
358 
359    for (base = 0; server_string[base] != NUL; /* empty */ ) {
360       /* Determine the length of the next extension name.
361        */
362       for (len = 0; (server_string[base + len] != SEPARATOR)
363            && (server_string[base + len] != NUL); len++) {
364          /* empty */
365       }
366 
367       /* Set the bit for the extension in the server_support table.
368        */
369       set_glx_extension(ext, &server_string[base], len, GL_TRUE,
370                         server_support);
371 
372 
373       /* Advance to the next extension string.  This means that we skip
374        * over the previous string and any trialing white-space.
375        */
376       for (base += len; (server_string[base] == SEPARATOR)
377            && (server_string[base] != NUL); base++) {
378          /* empty */
379       }
380    }
381 }
382 
383 void
__glXEnableDirectExtension(struct glx_screen * psc,const char * name)384 __glXEnableDirectExtension(struct glx_screen * psc, const char *name)
385 {
386    __glXExtensionsCtr();
387    __glXExtensionsCtrScreen(psc);
388 
389    set_glx_extension(known_glx_extensions,
390                      name, strlen(name), GL_TRUE, psc->direct_support);
391 }
392 
393 static void
__ParseExtensionOverride(struct glx_screen * psc,const struct extension_info * ext_list,unsigned char * force_enable,unsigned char * force_disable,const char * override)394 __ParseExtensionOverride(struct glx_screen *psc,
395                          const struct extension_info *ext_list,
396                          unsigned char *force_enable,
397                          unsigned char *force_disable,
398                          const char *override)
399 {
400    const struct extension_info *ext;
401    char *env, *field;
402 
403    if (override == NULL)
404        return;
405 
406    /* Copy env_const because strtok() is destructive. */
407    env = strdup(override);
408    if (env == NULL)
409       return;
410 
411    for (field = strtok(env, " "); field!= NULL; field = strtok(NULL, " ")) {
412       GLboolean enable;
413 
414       switch (field[0]) {
415       case '+':
416          enable = GL_TRUE;
417          ++field;
418          break;
419       case '-':
420          enable = GL_FALSE;
421          ++field;
422          break;
423       default:
424          enable = GL_TRUE;
425          break;
426       }
427 
428       ext = find_extension(ext_list, field, strlen(field));
429       if (ext) {
430          if (enable)
431             SET_BIT(force_enable, ext->bit);
432          else
433             SET_BIT(force_disable, ext->bit);
434       } else {
435          fprintf(stderr, "WARNING: Trying to %s the unknown extension '%s'\n",
436                  enable ? "enable" : "disable", field);
437       }
438    }
439 
440    free(env);
441 }
442 
443 /**
444  * \brief Parse the list of GLX extensions that the user wants to
445  * force-enable/disable by using \c override, and write the results to the
446  * screen's context.
447  *
448  * \param psc        Pointer to GLX per-screen record.
449  * \param override   A space-separated list of extensions to enable or disable.
450  * The list is processed thus:
451  *    - Enable recognized extension names that are prefixed with '+'.
452  *    - Disable recognized extension names that are prefixed with '-'.
453  *    - Enable recognized extension names that are not prefixed.
454  */
455 void
__glXParseExtensionOverride(struct glx_screen * psc,const char * override)456 __glXParseExtensionOverride(struct glx_screen *psc, const char *override)
457 {
458     __ParseExtensionOverride(psc, known_glx_extensions, psc->glx_force_enabled,
459                              psc->glx_force_disabled, override);
460 }
461 
462 /**
463  * \brief Parse the list of GL extensions that the user wants to
464  * force-enable/disable by using \c override, and write the results to the
465  * screen's context.
466  *
467  * \param psc        Pointer to GLX per-screen record.
468  * \param override   A space-separated list of extensions to enable or disable.
469  * The list is processed thus:
470  *    - Enable recognized extension names that are prefixed with '+'.
471  *    - Disable recognized extension names that are prefixed with '-'.
472  *    - Enable recognized extension names that are not prefixed.
473  */
474 void
__IndirectGlParseExtensionOverride(struct glx_screen * psc,const char * override)475 __IndirectGlParseExtensionOverride(struct glx_screen *psc, const char *override)
476 {
477     __ParseExtensionOverride(psc, known_gl_extensions, psc->gl_force_enabled,
478                              psc->gl_force_disabled, override);
479 }
480 
481 
482 /**
483  * Initialize global extension support tables.
484  */
485 
486 static void
__glXExtensionsCtr(void)487 __glXExtensionsCtr(void)
488 {
489    unsigned i;
490    static GLboolean ext_list_first_time = GL_TRUE;
491 
492 
493    if (ext_list_first_time) {
494       ext_list_first_time = GL_FALSE;
495 
496       (void) memset(direct_glx_support, 0, sizeof(direct_glx_support));
497       (void) memset(client_glx_only, 0, sizeof(client_glx_only));
498       (void) memset(direct_glx_only, 0, sizeof(direct_glx_only));
499 
500       SET_BIT(client_glx_only, ARB_get_proc_address_bit);
501       for (i = 0; known_glx_extensions[i].name != NULL; i++) {
502          const unsigned bit = known_glx_extensions[i].bit;
503 
504          if (known_glx_extensions[i].direct_support) {
505             SET_BIT(direct_glx_support, bit);
506          }
507 
508          if (known_glx_extensions[i].direct_only) {
509             SET_BIT(direct_glx_only, bit);
510          }
511       }
512    }
513 }
514 
515 
516 /**
517  * Make sure that per-screen direct-support table is initialized.
518  *
519  * \param psc  Pointer to GLX per-screen record.
520  */
521 
522 static void
__glXExtensionsCtrScreen(struct glx_screen * psc)523 __glXExtensionsCtrScreen(struct glx_screen * psc)
524 {
525    if (psc->ext_list_first_time) {
526       psc->ext_list_first_time = GL_FALSE;
527       (void) memcpy(psc->direct_support, direct_glx_support,
528                     sizeof(direct_glx_support));
529       (void) memset(psc->glx_force_enabled, 0,
530                     sizeof(psc->glx_force_enabled));
531       (void) memset(psc->glx_force_disabled, 0,
532                     sizeof(psc->glx_force_disabled));
533       (void) memset(psc->gl_force_enabled, 0,
534                     sizeof(psc->gl_force_enabled));
535       (void) memset(psc->gl_force_disabled, 0,
536                     sizeof(psc->gl_force_disabled));
537    }
538 }
539 
540 
541 /**
542  * Check if a certain extension is enabled on a given screen.
543  *
544  * \param psc  Pointer to GLX per-screen record.
545  * \param bit  Bit index in the direct-support table.
546  * \returns If the extension bit is enabled for the screen, \c GL_TRUE is
547  *          returned.  If the extension bit is not enabled or if \c psc is
548  *          \c NULL, then \c GL_FALSE is returned.
549  */
550 GLboolean
__glXExtensionBitIsEnabled(struct glx_screen * psc,unsigned bit)551 __glXExtensionBitIsEnabled(struct glx_screen * psc, unsigned bit)
552 {
553    GLboolean enabled = GL_FALSE;
554 
555    if (psc != NULL) {
556       __glXExtensionsCtr();
557       __glXExtensionsCtrScreen(psc);
558       enabled = EXT_ENABLED(bit, psc->direct_support);
559    }
560 
561    return enabled;
562 }
563 
564 
565 /**
566  * Check if a certain extension is enabled in a given context.
567  *
568  */
569 GLboolean
__glExtensionBitIsEnabled(struct glx_context * gc,unsigned bit)570 __glExtensionBitIsEnabled(struct glx_context *gc, unsigned bit)
571 {
572    GLboolean enabled = GL_FALSE;
573 
574    if (gc != NULL) {
575       enabled = EXT_ENABLED(bit, gc->gl_extension_bits);
576    }
577 
578    return enabled;
579 }
580 
581 
582 
583 /**
584  * Convert a bit-field to a string of supported extensions.
585  */
586 static char *
__glXGetStringFromTable(const struct extension_info * ext,const unsigned char * filter)587 __glXGetStringFromTable(const struct extension_info *ext,
588                         const unsigned char *filter)
589 {
590    unsigned i;
591    unsigned ext_str_len;
592    char *ext_str;
593    char *point;
594 
595 
596    ext_str_len = 0;
597    for (i = 0; ext[i].name != NULL; i++) {
598       if (!filter || EXT_ENABLED(ext[i].bit, filter)) {
599          ext_str_len += ext[i].name_len + 1;
600       }
601    }
602 
603    ext_str = malloc(ext_str_len + 1);
604    if (ext_str != NULL) {
605       point = ext_str;
606 
607       for (i = 0; ext[i].name != NULL; i++) {
608          if (!filter || EXT_ENABLED(ext[i].bit, filter)) {
609             (void) memcpy(point, ext[i].name, ext[i].name_len);
610             point += ext[i].name_len;
611 
612             *point = ' ';
613             point++;
614          }
615       }
616 
617       *point = '\0';
618    }
619 
620    return ext_str;
621 }
622 
623 
624 /**
625  * Get the string of client library supported extensions.
626  */
627 const char *
__glXGetClientExtensions(Display * dpy)628 __glXGetClientExtensions(Display *dpy)
629 {
630    if (__glXGLXClientExtensions == NULL) {
631       __glXExtensionsCtr();
632       __glXGLXClientExtensions = __glXGetStringFromTable(known_glx_extensions,
633                                                          NULL);
634    }
635 
636    return __glXGLXClientExtensions;
637 }
638 
639 
640 /**
641  * Calculate the list of application usable extensions.  The resulting
642  * string is stored in \c psc->effectiveGLXexts.
643  *
644  * \param psc                        Pointer to GLX per-screen record.
645  * \param display_is_direct_capable  True if the display is capable of
646  *                                   direct rendering.
647  */
648 
649 void
__glXCalculateUsableExtensions(struct glx_screen * psc,GLboolean display_is_direct_capable)650 __glXCalculateUsableExtensions(struct glx_screen * psc,
651                                GLboolean display_is_direct_capable)
652 {
653    unsigned char server_support[__GLX_EXT_BYTES];
654    unsigned char usable[__GLX_EXT_BYTES];
655    unsigned i;
656 
657    __glXExtensionsCtr();
658    __glXExtensionsCtrScreen(psc);
659 
660    (void) memset(server_support, 0, sizeof(server_support));
661    __glXProcessServerString(known_glx_extensions,
662                             psc->serverGLXexts, server_support);
663 
664 
665    /* An extension is supported if the client-side (i.e., libGL) supports
666     * it and the "server" supports it.  In this case that means that either
667     * the true server supports it or it is only for direct-rendering and
668     * the direct rendering driver supports it.
669     *
670     * If the display is not capable of direct rendering, then the extension
671     * is enabled if and only if the client-side library and the server
672     * support it.
673     */
674 
675    if (display_is_direct_capable) {
676       for (i = 0; i < __GLX_EXT_BYTES; i++) {
677          /* Enable extensions that the client supports that only have a client-side
678           * component.
679           */
680          unsigned char u = client_glx_only[i];
681 
682          /* Enable extensions that are supported for direct rendering, and either
683           * are supported by the server or only have a direct-rendering component.
684           */
685          u |= psc->direct_support[i] & (server_support[i] | direct_glx_only[i]);
686 
687          /* Finally, apply driconf options to force some extension bits either
688           * enabled or disabled.
689           */
690          u |= psc->glx_force_enabled[i];
691          u &= ~psc->glx_force_disabled[i];
692 
693          usable[i] = u;
694       }
695    }
696    else {
697       for (i = 0; i < __GLX_EXT_BYTES; i++) {
698          /* Enable extensions that the client supports that only have a
699           * client-side component.
700           */
701          unsigned char u = client_glx_only[i];
702 
703          /* Enable extensions that the client and server both support */
704          u |= server_support[i];
705 
706          /* Finally, apply driconf options to force some extension bits either
707           * enabled or disabled.
708           */
709          u |= psc->glx_force_enabled[i];
710          u &= ~psc->glx_force_disabled[i];
711 
712          usable[i] = u;
713       }
714    }
715 
716    psc->effectiveGLXexts = __glXGetStringFromTable(known_glx_extensions,
717                                                    usable);
718 }
719 
720 /**
721  * Calculate the list of application usable extensions.  The resulting
722  * string is stored in \c gc->extensions.
723  *
724  * \param gc             Pointer to GLX context.
725  * \param server_string  Extension string from the server.
726  */
727 
728 void
__glXCalculateUsableGLExtensions(struct glx_context * gc,const char * server_string)729 __glXCalculateUsableGLExtensions(struct glx_context * gc,
730                                  const char *server_string)
731 {
732    struct glx_screen *psc = gc->psc;
733    unsigned char server_support[__GL_EXT_BYTES];
734    unsigned char usable[__GL_EXT_BYTES];
735    unsigned i;
736 
737    (void) memset(server_support, 0, sizeof(server_support));
738    __glXProcessServerString(known_gl_extensions, server_string,
739                             server_support);
740 
741    /* These extensions are wholly inside the client-side indirect code */
742    (void) memset(usable, 0, sizeof(usable));
743    SET_BIT(usable, GL_ARB_transpose_matrix_bit);
744    SET_BIT(usable, GL_EXT_draw_range_elements_bit);
745    SET_BIT(usable, GL_EXT_multi_draw_arrays_bit);
746    SET_BIT(usable, GL_SUN_multi_draw_arrays_bit);
747 
748    for (i = 0; i < __GL_EXT_BYTES; i++) {
749       /* Usable if the server supports it, or if it's been forced on */
750       usable[i] = server_support[i] | psc->gl_force_enabled[i];
751 
752       /* But not if it's been forced off */
753       usable[i] &= ~psc->gl_force_disabled[i];
754    }
755 
756    gc->extensions = (unsigned char *)
757       __glXGetStringFromTable(known_gl_extensions, usable);
758    (void) memcpy(gc->gl_extension_bits, usable, sizeof(usable));
759 }
760 
761 /**
762  * Get a string representing the set of extensions supported by the client
763  * library.  This is currently only used to send the list of extensions
764  * supported by the client to the server.
765  */
766 char *
__glXGetClientGLExtensionString(void)767 __glXGetClientGLExtensionString(void)
768 {
769    return __glXGetStringFromTable(known_gl_extensions, NULL);
770 }
771