extension_string.c (6719B)
1 /* 2 * (C) Copyright IBM Corporation 2002-2006 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 extension_string.c 27 * Routines to manage the GLX extension string and GLX version for AIGLX 28 * drivers. This code is loosely based on src/glx/x11/glxextensions.c from 29 * Mesa. 30 * 31 * \author Ian Romanick <idr@us.ibm.com> 32 */ 33 34 #include "dix-config.h" 35 #include "extension_string.h" 36 #include "opaque.h" 37 38 #define SET_BIT(m,b) (m[ (b) / 8 ] |= (1U << ((b) % 8))) 39 #define CLR_BIT(m,b) (m[ (b) / 8 ] &= ~(1U << ((b) % 8))) 40 #define IS_SET(m,b) ((m[ (b) / 8 ] & (1U << ((b) % 8))) != 0) 41 #define CONCAT(a,b) a ## b 42 #define GLX(n) "GLX_" # n, 4 + sizeof( # n ) - 1, CONCAT(n,_bit) 43 #define VER(a,b) a, b 44 #define Y 1 45 #define N 0 46 #define EXT_ENABLED(bit,supported) (IS_SET(supported, bit)) 47 48 struct extension_info { 49 const char *const name; 50 unsigned name_len; 51 52 unsigned char bit; 53 54 /** 55 * This is the lowest version of GLX that "requires" this extension. 56 * For example, GLX 1.3 requires SGIX_fbconfig, SGIX_pbuffer, and 57 * SGI_make_current_read. If the extension is not required by any known 58 * version of GLX, use 0, 0. 59 */ 60 unsigned char version_major; 61 unsigned char version_minor; 62 63 /** 64 * Is driver support forced by the ABI? 65 */ 66 unsigned char driver_support; 67 }; 68 69 /** 70 * List of known GLX Extensions. 71 * The last Y/N switch informs whether the support of this extension is always enabled. 72 */ 73 static const struct extension_info known_glx_extensions[] = { 74 /* GLX_ARB_get_proc_address is implemented on the client. */ 75 /* *INDENT-OFF* */ 76 { GLX(ARB_context_flush_control), VER(0,0), N, }, 77 { GLX(ARB_create_context), VER(0,0), N, }, 78 { GLX(ARB_create_context_no_error), VER(0,0), N, }, 79 { GLX(ARB_create_context_profile), VER(0,0), N, }, 80 { GLX(ARB_create_context_robustness), VER(0,0), N, }, 81 { GLX(ARB_fbconfig_float), VER(0,0), N, }, 82 { GLX(ARB_framebuffer_sRGB), VER(0,0), N, }, 83 { GLX(ARB_multisample), VER(1,4), Y, }, 84 85 { GLX(EXT_create_context_es_profile), VER(0,0), N, }, 86 { GLX(EXT_create_context_es2_profile), VER(0,0), N, }, 87 { GLX(EXT_fbconfig_packed_float), VER(0,0), N, }, 88 { GLX(EXT_framebuffer_sRGB), VER(0,0), N, }, 89 { GLX(EXT_get_drawable_type), VER(0,0), Y, }, 90 { GLX(EXT_import_context), VER(0,0), N, }, 91 { GLX(EXT_libglvnd), VER(0,0), N, }, 92 { GLX(EXT_no_config_context), VER(0,0), N, }, 93 { GLX(EXT_stereo_tree), VER(0,0), N, }, 94 { GLX(EXT_texture_from_pixmap), VER(0,0), N, }, 95 { GLX(EXT_visual_info), VER(0,0), Y, }, 96 { GLX(EXT_visual_rating), VER(0,0), Y, }, 97 98 { GLX(MESA_copy_sub_buffer), VER(0,0), N, }, 99 { GLX(OML_swap_method), VER(0,0), Y, }, 100 { GLX(SGI_make_current_read), VER(1,3), Y, }, 101 { GLX(SGI_swap_control), VER(0,0), N, }, 102 { GLX(SGIS_multisample), VER(0,0), Y, }, 103 { GLX(SGIX_fbconfig), VER(1,3), Y, }, 104 { GLX(SGIX_pbuffer), VER(1,3), Y, }, 105 { GLX(SGIX_visual_select_group), VER(0,0), Y, }, 106 { GLX(INTEL_swap_event), VER(0,0), N, }, 107 { NULL } 108 /* *INDENT-ON* */ 109 }; 110 111 /** 112 * Create a GLX extension string for a set of enable bits. 113 * 114 * Creates a GLX extension string for the set of bit in \c enable_bits. This 115 * string is then stored in \c buffer if buffer is not \c NULL. This allows 116 * two-pass operation. On the first pass the caller passes \c NULL for 117 * \c buffer, and the function determines how much space is required to store 118 * the extension string. The caller allocates the buffer and calls the 119 * function again. 120 * 121 * \param enable_bits Bits representing the enabled extensions. 122 * \param buffer Buffer to store the extension string. May be \c NULL. 123 * 124 * \return 125 * The number of characters in \c buffer that were written to. If \c buffer 126 * is \c NULL, this is the size of buffer that must be allocated by the 127 * caller. 128 */ 129 int 130 __glXGetExtensionString(const unsigned char *enable_bits, char *buffer) 131 { 132 unsigned i; 133 int length = 0; 134 135 for (i = 0; known_glx_extensions[i].name != NULL; i++) { 136 const unsigned bit = known_glx_extensions[i].bit; 137 const size_t len = known_glx_extensions[i].name_len; 138 139 if (EXT_ENABLED(bit, enable_bits)) { 140 if (buffer != NULL) { 141 (void) memcpy(&buffer[length], known_glx_extensions[i].name, 142 len); 143 144 buffer[length + len + 0] = ' '; 145 buffer[length + len + 1] = '\0'; 146 } 147 148 length += len + 1; 149 } 150 } 151 152 return length + 1; 153 } 154 155 void 156 __glXEnableExtension(unsigned char *enable_bits, const char *ext) 157 { 158 const size_t ext_name_len = strlen(ext); 159 unsigned i; 160 161 for (i = 0; known_glx_extensions[i].name != NULL; i++) { 162 if ((ext_name_len == known_glx_extensions[i].name_len) 163 && (memcmp(ext, known_glx_extensions[i].name, ext_name_len) == 0)) { 164 SET_BIT(enable_bits, known_glx_extensions[i].bit); 165 break; 166 } 167 } 168 } 169 170 void 171 __glXInitExtensionEnableBits(unsigned char *enable_bits) 172 { 173 unsigned i; 174 175 (void) memset(enable_bits, 0, __GLX_EXT_BYTES); 176 177 for (i = 0; known_glx_extensions[i].name != NULL; i++) { 178 if (known_glx_extensions[i].driver_support) { 179 SET_BIT(enable_bits, known_glx_extensions[i].bit); 180 } 181 } 182 183 if (enableIndirectGLX) 184 __glXEnableExtension(enable_bits, "GLX_EXT_import_context"); 185 }