1706f2543Smrg/* 2706f2543Smrg * (C) Copyright IBM Corporation 2002-2006 3706f2543Smrg * All Rights Reserved. 4706f2543Smrg * 5706f2543Smrg * Permission is hereby granted, free of charge, to any person obtaining a 6706f2543Smrg * copy of this software and associated documentation files (the "Software"), 7706f2543Smrg * to deal in the Software without restriction, including without limitation 8706f2543Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub 9706f2543Smrg * license, and/or sell copies of the Software, and to permit persons to whom 10706f2543Smrg * the Software is furnished to do so, subject to the following conditions: 11706f2543Smrg * 12706f2543Smrg * The above copyright notice and this permission notice (including the next 13706f2543Smrg * paragraph) shall be included in all copies or substantial portions of the 14706f2543Smrg * Software. 15706f2543Smrg * 16706f2543Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17706f2543Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18706f2543Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 19706f2543Smrg * THE COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 20706f2543Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 21706f2543Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 22706f2543Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE. 23706f2543Smrg */ 24706f2543Smrg 25706f2543Smrg/** 26706f2543Smrg * \file extension_string.c 27706f2543Smrg * Routines to manage the GLX extension string and GLX version for AIGLX 28706f2543Smrg * drivers. This code is loosely based on src/glx/x11/glxextensions.c from 29706f2543Smrg * Mesa. 30706f2543Smrg * 31706f2543Smrg * \author Ian Romanick <idr@us.ibm.com> 32706f2543Smrg */ 33706f2543Smrg 34706f2543Smrg#include <string.h> 35706f2543Smrg#include "extension_string.h" 36706f2543Smrg 37706f2543Smrg#define SET_BIT(m,b) (m[ (b) / 8 ] |= (1U << ((b) % 8))) 38706f2543Smrg#define CLR_BIT(m,b) (m[ (b) / 8 ] &= ~(1U << ((b) % 8))) 39706f2543Smrg#define IS_SET(m,b) ((m[ (b) / 8 ] & (1U << ((b) % 8))) != 0) 40706f2543Smrg#define CONCAT(a,b) a ## b 41706f2543Smrg#define GLX(n) "GLX_" # n, 4 + sizeof( # n ) - 1, CONCAT(n,_bit) 42706f2543Smrg#define VER(a,b) a, b 43706f2543Smrg#define Y 1 44706f2543Smrg#define N 0 45706f2543Smrg#define EXT_ENABLED(bit,supported) (IS_SET(supported, bit)) 46706f2543Smrg 47706f2543Smrgstruct extension_info { 48706f2543Smrg const char * const name; 49706f2543Smrg unsigned name_len; 50706f2543Smrg 51706f2543Smrg unsigned char bit; 52706f2543Smrg 53706f2543Smrg /** 54706f2543Smrg * This is the lowest version of GLX that "requires" this extension. 55706f2543Smrg * For example, GLX 1.3 requires SGIX_fbconfig, SGIX_pbuffer, and 56706f2543Smrg * SGI_make_current_read. If the extension is not required by any known 57706f2543Smrg * version of GLX, use 0, 0. 58706f2543Smrg */ 59706f2543Smrg unsigned char version_major; 60706f2543Smrg unsigned char version_minor; 61706f2543Smrg 62706f2543Smrg /** 63706f2543Smrg * Is driver support forced by the ABI? 64706f2543Smrg */ 65706f2543Smrg unsigned char driver_support; 66706f2543Smrg}; 67706f2543Smrg 68706f2543Smrgstatic const struct extension_info known_glx_extensions[] = { 69706f2543Smrg/* GLX_ARB_get_proc_address is implemented on the client. */ 70706f2543Smrg { GLX(ARB_multisample), VER(1,4), Y, }, 71706f2543Smrg 72706f2543Smrg { GLX(EXT_import_context), VER(0,0), Y, }, 73706f2543Smrg { GLX(EXT_texture_from_pixmap), VER(0,0), Y, }, 74706f2543Smrg { GLX(EXT_visual_info), VER(0,0), Y, }, 75706f2543Smrg { GLX(EXT_visual_rating), VER(0,0), Y, }, 76706f2543Smrg 77706f2543Smrg { GLX(MESA_copy_sub_buffer), VER(0,0), N, }, 78706f2543Smrg { GLX(OML_swap_method), VER(0,0), Y, }, 79706f2543Smrg { GLX(SGI_make_current_read), VER(1,3), N, }, 80706f2543Smrg { GLX(SGI_swap_control), VER(0,0), N, }, 81706f2543Smrg { GLX(SGIS_multisample), VER(0,0), Y, }, 82706f2543Smrg { GLX(SGIX_fbconfig), VER(1,3), Y, }, 83706f2543Smrg { GLX(SGIX_pbuffer), VER(1,3), Y, }, 84706f2543Smrg { GLX(SGIX_visual_select_group), VER(0,0), Y, }, 85706f2543Smrg { GLX(INTEL_swap_event), VER(1,4), N, }, 86706f2543Smrg { NULL } 87706f2543Smrg}; 88706f2543Smrg 89706f2543Smrg 90706f2543Smrg/** 91706f2543Smrg * Create a GLX extension string for a set of enable bits. 92706f2543Smrg * 93706f2543Smrg * Creates a GLX extension string for the set of bit in \c enable_bits. This 94706f2543Smrg * string is then stored in \c buffer if buffer is not \c NULL. This allows 95706f2543Smrg * two-pass operation. On the first pass the caller passes \c NULL for 96706f2543Smrg * \c buffer, and the function determines how much space is required to store 97706f2543Smrg * the extension string. The caller allocates the buffer and calls the 98706f2543Smrg * function again. 99706f2543Smrg * 100706f2543Smrg * \param enable_bits Bits representing the enabled extensions. 101706f2543Smrg * \param buffer Buffer to store the extension string. May be \c NULL. 102706f2543Smrg * 103706f2543Smrg * \return 104706f2543Smrg * The number of characters in \c buffer that were written to. If \c buffer 105706f2543Smrg * is \c NULL, this is the size of buffer that must be allocated by the 106706f2543Smrg * caller. 107706f2543Smrg */ 108706f2543Smrgint 109706f2543Smrg__glXGetExtensionString(const unsigned char *enable_bits, char *buffer) 110706f2543Smrg{ 111706f2543Smrg unsigned i; 112706f2543Smrg int length = 0; 113706f2543Smrg 114706f2543Smrg 115706f2543Smrg for (i = 0; known_glx_extensions[i].name != NULL; i++) { 116706f2543Smrg const unsigned bit = known_glx_extensions[i].bit; 117706f2543Smrg const size_t len = known_glx_extensions[i].name_len; 118706f2543Smrg 119706f2543Smrg if (EXT_ENABLED(bit, enable_bits)) { 120706f2543Smrg if (buffer != NULL) { 121706f2543Smrg (void) memcpy(& buffer[length], known_glx_extensions[i].name, 122706f2543Smrg len); 123706f2543Smrg 124706f2543Smrg buffer[length + len + 0] = ' '; 125706f2543Smrg buffer[length + len + 1] = '\0'; 126706f2543Smrg } 127706f2543Smrg 128706f2543Smrg length += len + 1; 129706f2543Smrg } 130706f2543Smrg } 131706f2543Smrg 132706f2543Smrg return length + 1; 133706f2543Smrg} 134706f2543Smrg 135706f2543Smrg 136706f2543Smrgvoid 137706f2543Smrg__glXEnableExtension(unsigned char *enable_bits, const char *ext) 138706f2543Smrg{ 139706f2543Smrg const size_t ext_name_len = strlen(ext); 140706f2543Smrg unsigned i; 141706f2543Smrg 142706f2543Smrg 143706f2543Smrg for (i = 0; known_glx_extensions[i].name != NULL; i++) { 144706f2543Smrg if ((ext_name_len == known_glx_extensions[i].name_len) 145706f2543Smrg && (memcmp(ext, known_glx_extensions[i].name, ext_name_len) == 0)) { 146706f2543Smrg SET_BIT(enable_bits, known_glx_extensions[i].bit); 147706f2543Smrg break; 148706f2543Smrg } 149706f2543Smrg } 150706f2543Smrg} 151706f2543Smrg 152706f2543Smrg 153706f2543Smrgvoid 154706f2543Smrg__glXInitExtensionEnableBits(unsigned char *enable_bits) 155706f2543Smrg{ 156706f2543Smrg unsigned i; 157706f2543Smrg 158706f2543Smrg 159706f2543Smrg (void) memset(enable_bits, 0, __GLX_EXT_BYTES); 160706f2543Smrg 161706f2543Smrg for (i = 0; known_glx_extensions[i].name != NULL; i++) { 162706f2543Smrg if (known_glx_extensions[i].driver_support) { 163706f2543Smrg SET_BIT(enable_bits, known_glx_extensions[i].bit); 164706f2543Smrg } 165706f2543Smrg } 166706f2543Smrg} 167