utils.c revision f7d80aa00611917bc8ce637136d982b151b8f44f
193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell/*
274396056977776919aaa7c22be1a3d17774ae321Ian Romanick * (C) Copyright IBM Corporation 2002, 2004
393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * All Rights Reserved.
493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell *
593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a
693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * copy of this software and associated documentation files (the "Software"),
793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * to deal in the Software without restriction, including without limitation
893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * on the rights to use, copy, modify, merge, publish, distribute, sub
993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * license, and/or sell copies of the Software, and to permit persons to whom
1093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * the Software is furnished to do so, subject to the following conditions:
1193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell *
1293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * The above copyright notice and this permission notice (including the next
1393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * paragraph) shall be included in all copies or substantial portions of the
1493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * Software.
1593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell *
1693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
1993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
2093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * USE OR OTHER DEALINGS IN THE SOFTWARE.
23447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick */
24447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick
25447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick/**
26447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick * \file utils.c
27447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick * Utility functions for DRI drivers.
2893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell *
29447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick * \author Ian Romanick <idr@us.ibm.com>
3093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell */
3193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
3293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#include <string.h>
3393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#include <stdlib.h>
3493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#include "mtypes.h"
3593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#include "extensions.h"
3693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#include "utils.h"
371585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick#include "dispatch.h"
381585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick
39126c89e35fb5179fe077f7593f31ea874c89dd65Ian Romanickint driDispatchRemapTable[ driDispatchRemapTable_size ];
4093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
4193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#if defined(USE_X86_ASM)
42ecb1a5f7f98b9e42965318db99b6996f12b87e59Alan Hourihane#include "x86/common_x86_asm.h"
4393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#endif
4493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
45447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick#if defined(USE_PPC_ASM)
46447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick#include "ppc/common_ppc_features.h"
47447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick#endif
48447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick
4993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwellunsigned
5093a458840c77b784fb74738f734ba2c5d22ca7a7Keith WhitwelldriParseDebugString( const char * debug,
5193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell		     const struct dri_debug_control * control  )
5293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell{
5393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   unsigned   flag;
5493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
5593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
5693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   flag = 0;
5793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   if ( debug != NULL ) {
5893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      while( control->string != NULL ) {
59462183fe4cb6df6d90632d9e2cee881c8d26b1cbAlan Hourihane	 if ( !strcmp( debug, "all" ) ||
60462183fe4cb6df6d90632d9e2cee881c8d26b1cbAlan Hourihane	      strstr( debug, control->string ) != NULL ) {
6193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell	    flag |= control->flag;
6293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell	 }
6393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
6493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell	 control++;
6593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      }
6693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
6793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
6893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   return flag;
6993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell}
7093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
7193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
7293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
73b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick/**
74b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * Create the \c GL_RENDERER string for DRI drivers.
75b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick *
76b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * Almost all DRI drivers use a \c GL_RENDERER string of the form:
77b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick *
78b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick *    "Mesa DRI <chip> <driver date> <AGP speed) <CPU information>"
79b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick *
80b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * Using the supplied chip name, driver data, and AGP speed, this function
81b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * creates the string.
82b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick *
83b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * \param buffer         Buffer to hold the \c GL_RENDERER string.
84b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * \param hardware_name  Name of the hardware.
85b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * \param driver_date    Driver date.
86b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * \param agp_mode       AGP mode (speed).
87b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick *
88b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * \returns
89b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * The length of the string stored in \c buffer.  This does \b not include
90b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * the terminating \c NUL character.
91b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick */
9293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwellunsigned
9393a458840c77b784fb74738f734ba2c5d22ca7a7Keith WhitwelldriGetRendererString( char * buffer, const char * hardware_name,
9493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell		      const char * driver_date, GLuint agp_mode )
9593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell{
96b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick#define MAX_INFO   4
97b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick   const char * cpu[MAX_INFO];
98b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick   unsigned   next = 0;
99b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick   unsigned   i;
10093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   unsigned   offset;
10193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
10293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
10393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   offset = sprintf( buffer, "Mesa DRI %s %s", hardware_name, driver_date );
10493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
10593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   /* Append any AGP-specific information.
10693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell    */
10793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   switch ( agp_mode ) {
10893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   case 1:
10993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   case 2:
11093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   case 4:
11193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   case 8:
11293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      offset += sprintf( & buffer[ offset ], " AGP %ux", agp_mode );
11393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      break;
11493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
11593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   default:
11693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      break;
11793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
11893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
11993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   /* Append any CPU-specific information.
12093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell    */
12193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#ifdef USE_X86_ASM
12293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   if ( _mesa_x86_cpu_features ) {
123b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick      cpu[next] = " x86";
124b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick      next++;
12593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
12693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell# ifdef USE_MMX_ASM
12793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   if ( cpu_has_mmx ) {
128b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick      cpu[next] = (cpu_has_mmxext) ? "/MMX+" : "/MMX";
129b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick      next++;
13093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
13193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell# endif
13293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell# ifdef USE_3DNOW_ASM
13393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   if ( cpu_has_3dnow ) {
134b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick      cpu[next] = (cpu_has_3dnowext) ? "/3DNow!+" : "/3DNow!";
135b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick      next++;
13693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
13793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell# endif
13893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell# ifdef USE_SSE_ASM
13993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   if ( cpu_has_xmm ) {
140b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick      cpu[next] = (cpu_has_xmm2) ? "/SSE2" : "/SSE";
141b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick      next++;
14293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
14393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell# endif
14493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
14593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#elif defined(USE_SPARC_ASM)
14693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
147b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick   cpu[0] = " SPARC";
148b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick   next = 1;
14993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
150447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick#elif defined(USE_PPC_ASM)
151447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick   if ( _mesa_ppc_cpu_features ) {
152447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick      cpu[next] = (cpu_has_64) ? " PowerPC 64" : " PowerPC";
153447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick      next++;
154447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick   }
155447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick
156447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick# ifdef USE_VMX_ASM
157447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick   if ( cpu_has_vmx ) {
158447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick      cpu[next] = "/Altivec";
159447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick      next++;
160447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick   }
161447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick# endif
162447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick
163447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick   if ( ! cpu_has_fpu ) {
164447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick      cpu[next] = "/No FPU";
165447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick      next++;
166447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick   }
16793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#endif
16893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
169b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick   for ( i = 0 ; i < next ; i++ ) {
170b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick      const size_t len = strlen( cpu[i] );
171b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick
172b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick      strncpy( & buffer[ offset ], cpu[i], len );
173b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick      offset += len;
174b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick   }
175b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick
17693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   return offset;
17793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell}
17893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
17993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
18093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
18193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
1821585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick#define need_GL_ARB_multisample
1831585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick#define need_GL_ARB_transpose_matrix
1841585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick#define need_GL_ARB_window_pos
1851585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick#define need_GL_EXT_compiled_vertex_array
1861585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick#define need_GL_EXT_polygon_offset
1871585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick#define need_GL_EXT_texture_object
1881585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick#define need_GL_EXT_vertex_array
1891585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick#define need_GL_MESA_window_pos
1901585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick
1911b8d0f149e0afac859c4c1e1e47772bb19da0187Ian Romanick/* These are needed in *all* drivers because Mesa internally implements
1921b8d0f149e0afac859c4c1e1e47772bb19da0187Ian Romanick * certain functionality in terms of functions provided by these extensions.
1931b8d0f149e0afac859c4c1e1e47772bb19da0187Ian Romanick * For example, glBlendFunc is implemented by calling glBlendFuncSeparateEXT.
194126c89e35fb5179fe077f7593f31ea874c89dd65Ian Romanick */
195126c89e35fb5179fe077f7593f31ea874c89dd65Ian Romanick#define need_GL_EXT_blend_func_separate
1961b8d0f149e0afac859c4c1e1e47772bb19da0187Ian Romanick#define need_GL_NV_vertex_program
197126c89e35fb5179fe077f7593f31ea874c89dd65Ian Romanick
1981585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick#include "extension_helper.h"
1991585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick
2001585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanickstatic const struct dri_extension all_mesa_extensions[] = {
2011585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick   { "GL_ARB_multisample",           GL_ARB_multisample_functions },
2021585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick   { "GL_ARB_transpose_matrix",      GL_ARB_transpose_matrix_functions },
2031585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick   { "GL_ARB_window_pos",            GL_ARB_window_pos_functions },
204126c89e35fb5179fe077f7593f31ea874c89dd65Ian Romanick   { "GL_EXT_blend_func_separate",   GL_EXT_blend_func_separate_functions },
2051585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick   { "GL_EXT_compiled_vertex_array", GL_EXT_compiled_vertex_array_functions },
2061585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick   { "GL_EXT_polygon_offset",        GL_EXT_polygon_offset_functions },
2071585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick   { "GL_EXT_texture_object",        GL_EXT_texture_object_functions },
2081585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick   { "GL_EXT_vertex_array",          GL_EXT_vertex_array_functions },
2091585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick   { "GL_MESA_window_pos",           GL_MESA_window_pos_functions },
2101b8d0f149e0afac859c4c1e1e47772bb19da0187Ian Romanick   { "GL_NV_vertex_program",         GL_NV_vertex_program_functions },
2111585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick   { NULL,                           NULL }
2121585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick};
2131585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick
2141585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick
215c212abf99af494f024b0b981a83350f7ac9821efIan Romanick/**
216c212abf99af494f024b0b981a83350f7ac9821efIan Romanick * Enable extensions supported by the driver.
217c212abf99af494f024b0b981a83350f7ac9821efIan Romanick *
218c212abf99af494f024b0b981a83350f7ac9821efIan Romanick * \bug
219c212abf99af494f024b0b981a83350f7ac9821efIan Romanick * ARB_imaging isn't handled properly.  In Mesa, enabling ARB_imaging also
220c212abf99af494f024b0b981a83350f7ac9821efIan Romanick * enables all the sub-extensions that are folded into it.  This means that
221c212abf99af494f024b0b981a83350f7ac9821efIan Romanick * we need to add entry-points (via \c driInitSingleExtension) for those
222c212abf99af494f024b0b981a83350f7ac9821efIan Romanick * new functions here.
223c212abf99af494f024b0b981a83350f7ac9821efIan Romanick */
22493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwellvoid driInitExtensions( GLcontext * ctx,
225c212abf99af494f024b0b981a83350f7ac9821efIan Romanick			const struct dri_extension * extensions_to_enable,
226c212abf99af494f024b0b981a83350f7ac9821efIan Romanick			GLboolean enable_imaging )
22793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell{
2281585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick   static int first_time = 1;
22993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   unsigned   i;
23093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
2311585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick   if ( first_time ) {
232126c89e35fb5179fe077f7593f31ea874c89dd65Ian Romanick      for ( i = 0 ; i < driDispatchRemapTable_size ; i++ ) {
233126c89e35fb5179fe077f7593f31ea874c89dd65Ian Romanick	 driDispatchRemapTable[i] = -1;
234126c89e35fb5179fe077f7593f31ea874c89dd65Ian Romanick      }
235126c89e35fb5179fe077f7593f31ea874c89dd65Ian Romanick
2361585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick      first_time = 0;
2371585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick      driInitExtensions( ctx, all_mesa_extensions, GL_FALSE );
2381585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick   }
2391585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick
2401585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick   if ( (ctx != NULL) && enable_imaging ) {
24193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      _mesa_enable_imaging_extensions( ctx );
24293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
24393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
244c212abf99af494f024b0b981a83350f7ac9821efIan Romanick   for ( i = 0 ; extensions_to_enable[i].name != NULL ; i++ ) {
245c212abf99af494f024b0b981a83350f7ac9821efIan Romanick       driInitSingleExtension( ctx, & extensions_to_enable[i] );
24693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
24793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell}
24893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
24993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
25093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
25193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
252c212abf99af494f024b0b981a83350f7ac9821efIan Romanick/**
253c212abf99af494f024b0b981a83350f7ac9821efIan Romanick * Enable and add dispatch functions for a single extension
254c212abf99af494f024b0b981a83350f7ac9821efIan Romanick *
255c212abf99af494f024b0b981a83350f7ac9821efIan Romanick * \param ctx  Context where extension is to be enabled.
256c212abf99af494f024b0b981a83350f7ac9821efIan Romanick * \param ext  Extension that is to be enabled.
257c212abf99af494f024b0b981a83350f7ac9821efIan Romanick *
258c212abf99af494f024b0b981a83350f7ac9821efIan Romanick * \sa driInitExtensions, _mesa_enable_extension, _glapi_add_entrypoint
259c212abf99af494f024b0b981a83350f7ac9821efIan Romanick *
260c212abf99af494f024b0b981a83350f7ac9821efIan Romanick * \todo
261c212abf99af494f024b0b981a83350f7ac9821efIan Romanick * Determine if it would be better to use \c strlen instead of the hardcoded
262c212abf99af494f024b0b981a83350f7ac9821efIan Romanick * for-loops.
263c212abf99af494f024b0b981a83350f7ac9821efIan Romanick */
264c212abf99af494f024b0b981a83350f7ac9821efIan Romanickvoid driInitSingleExtension( GLcontext * ctx,
265c212abf99af494f024b0b981a83350f7ac9821efIan Romanick			     const struct dri_extension * ext )
266c212abf99af494f024b0b981a83350f7ac9821efIan Romanick{
267c212abf99af494f024b0b981a83350f7ac9821efIan Romanick    unsigned i;
268c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
2691585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick
270c212abf99af494f024b0b981a83350f7ac9821efIan Romanick    if ( ext->functions != NULL ) {
271c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	for ( i = 0 ; ext->functions[i].strings != NULL ; i++ ) {
272c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    const char * functions[16];
273c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    const char * parameter_signature;
274c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    const char * str = ext->functions[i].strings;
275c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    unsigned j;
2761585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick	    unsigned offset;
277c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
278c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
279c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    /* Separate the parameter signature from the rest of the string.
280c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	     * If the parameter signature is empty (i.e., the string starts
281c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	     * with a NUL character), then the function has a void parameter
282c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	     * list.
283c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	     */
284c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    parameter_signature = str;
285c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    while ( str[0] != '\0' ) {
286c212abf99af494f024b0b981a83350f7ac9821efIan Romanick		str++;
287c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    }
288c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    str++;
289c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
290c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
291c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    /* Divide the string into the substrings that name each
292c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	     * entry-point for the function.
293c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	     */
294c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    for ( j = 0 ; j < 16 ; j++ ) {
295c212abf99af494f024b0b981a83350f7ac9821efIan Romanick		if ( str[0] == '\0' ) {
296c212abf99af494f024b0b981a83350f7ac9821efIan Romanick		    functions[j] = NULL;
297c212abf99af494f024b0b981a83350f7ac9821efIan Romanick		    break;
298c212abf99af494f024b0b981a83350f7ac9821efIan Romanick		}
299c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
300c212abf99af494f024b0b981a83350f7ac9821efIan Romanick		functions[j] = str;
301c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
302c212abf99af494f024b0b981a83350f7ac9821efIan Romanick		while ( str[0] != '\0' ) {
303c212abf99af494f024b0b981a83350f7ac9821efIan Romanick		    str++;
304c212abf99af494f024b0b981a83350f7ac9821efIan Romanick		}
305c212abf99af494f024b0b981a83350f7ac9821efIan Romanick		str++;
306c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    }
307c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
308c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
309c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    /* Add each entry-point to the dispatch table.
310c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	     */
3111585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick	    offset = _glapi_add_dispatch( functions, parameter_signature );
3128fbe16d4dd0664f7766f5241c055efb582cc06e5Ian Romanick	    if (offset == -1) {
313eb9efc6ad5544b8c643f81c03fcc09438aa0316cBrian Paul#if 0 /* this causes noise with egl */
3148fbe16d4dd0664f7766f5241c055efb582cc06e5Ian Romanick		fprintf(stderr, "DISPATCH ERROR! _glapi_add_dispatch failed "
3158fbe16d4dd0664f7766f5241c055efb582cc06e5Ian Romanick			"to add %s!\n", functions[0]);
316eb9efc6ad5544b8c643f81c03fcc09438aa0316cBrian Paul#endif
3171585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick	    }
3188fbe16d4dd0664f7766f5241c055efb582cc06e5Ian Romanick	    else if (ext->functions[i].remap_index != -1) {
3198fbe16d4dd0664f7766f5241c055efb582cc06e5Ian Romanick		driDispatchRemapTable[ ext->functions[i].remap_index ] =
3208fbe16d4dd0664f7766f5241c055efb582cc06e5Ian Romanick		  offset;
3218fbe16d4dd0664f7766f5241c055efb582cc06e5Ian Romanick	    }
3228fbe16d4dd0664f7766f5241c055efb582cc06e5Ian Romanick	    else if (ext->functions[i].offset != offset) {
3238fbe16d4dd0664f7766f5241c055efb582cc06e5Ian Romanick		fprintf(stderr, "DISPATCH ERROR! %s -> %u != %u\n",
3248fbe16d4dd0664f7766f5241c055efb582cc06e5Ian Romanick			functions[0], offset, ext->functions[i].offset);
325c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    }
326c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	}
327c212abf99af494f024b0b981a83350f7ac9821efIan Romanick    }
328c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
3291585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick    if ( ctx != NULL ) {
3301585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick	_mesa_enable_extension( ctx, ext->name );
3311585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick    }
332c212abf99af494f024b0b981a83350f7ac9821efIan Romanick}
333c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
334c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
3355b98ada88071a752b6000756949a1951183cdd0bIan Romanick/**
3365b98ada88071a752b6000756949a1951183cdd0bIan Romanick * Utility function used by drivers to test the verions of other components.
3375b98ada88071a752b6000756949a1951183cdd0bIan Romanick *
3385b98ada88071a752b6000756949a1951183cdd0bIan Romanick * If one of the version requirements is not met, a message is logged using
3395b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \c __driUtilMessage.
3405b98ada88071a752b6000756949a1951183cdd0bIan Romanick *
3415b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param driver_name  Name of the driver.  Used in error messages.
3425b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param driActual    Actual DRI version supplied __driCreateNewScreen.
3435b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param driExpected  Minimum DRI version required by the driver.
3445b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param ddxActual    Actual DDX version supplied __driCreateNewScreen.
3457104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger * \param ddxExpected  Minimum DDX minor and range of DDX major version required by the driver.
3465b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param drmActual    Actual DRM version supplied __driCreateNewScreen.
3475b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param drmExpected  Minimum DRM version required by the driver.
3485b98ada88071a752b6000756949a1951183cdd0bIan Romanick *
3495b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \returns \c GL_TRUE if all version requirements are met.  Otherwise,
3505b98ada88071a752b6000756949a1951183cdd0bIan Romanick *          \c GL_FALSE is returned.
3515b98ada88071a752b6000756949a1951183cdd0bIan Romanick *
352c39bf5e273a4995a279ae2af59fc29e06ab47e29Ian Romanick * \sa __driCreateNewScreen, driCheckDriDdxDrmVersions2, __driUtilMessage
353c39bf5e273a4995a279ae2af59fc29e06ab47e29Ian Romanick *
354c39bf5e273a4995a279ae2af59fc29e06ab47e29Ian Romanick * \todo
355c39bf5e273a4995a279ae2af59fc29e06ab47e29Ian Romanick * Now that the old \c driCheckDriDdxDrmVersions function is gone, this
356c39bf5e273a4995a279ae2af59fc29e06ab47e29Ian Romanick * function and \c driCheckDriDdxDrmVersions2 should be renamed.
3575b98ada88071a752b6000756949a1951183cdd0bIan Romanick */
3585b98ada88071a752b6000756949a1951183cdd0bIan RomanickGLboolean
3597104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland ScheideggerdriCheckDriDdxDrmVersions3(const char * driver_name,
3605b98ada88071a752b6000756949a1951183cdd0bIan Romanick			   const __DRIversion * driActual,
3615b98ada88071a752b6000756949a1951183cdd0bIan Romanick			   const __DRIversion * driExpected,
3625b98ada88071a752b6000756949a1951183cdd0bIan Romanick			   const __DRIversion * ddxActual,
3637104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger			   const __DRIutilversion2 * ddxExpected,
3645b98ada88071a752b6000756949a1951183cdd0bIan Romanick			   const __DRIversion * drmActual,
3655b98ada88071a752b6000756949a1951183cdd0bIan Romanick			   const __DRIversion * drmExpected)
3665b98ada88071a752b6000756949a1951183cdd0bIan Romanick{
3675b98ada88071a752b6000756949a1951183cdd0bIan Romanick   static const char format[] = "%s DRI driver expected %s version %d.%d.x "
368278736ff6f0659163e69392cf9e96006138746caDave Airlie       "but got version %d.%d.%d\n";
3697104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger   static const char format2[] = "%s DRI driver expected %s version %d-%d.%d.x "
370278736ff6f0659163e69392cf9e96006138746caDave Airlie       "but got version %d.%d.%d\n";
3715b98ada88071a752b6000756949a1951183cdd0bIan Romanick
3725b98ada88071a752b6000756949a1951183cdd0bIan Romanick
3735b98ada88071a752b6000756949a1951183cdd0bIan Romanick   /* Check the DRI version */
3745b98ada88071a752b6000756949a1951183cdd0bIan Romanick   if ( (driActual->major != driExpected->major)
3755b98ada88071a752b6000756949a1951183cdd0bIan Romanick	|| (driActual->minor < driExpected->minor) ) {
376278736ff6f0659163e69392cf9e96006138746caDave Airlie      fprintf(stderr, format, driver_name, "DRI",
3775b98ada88071a752b6000756949a1951183cdd0bIan Romanick		       driExpected->major, driExpected->minor,
3785b98ada88071a752b6000756949a1951183cdd0bIan Romanick		       driActual->major, driActual->minor, driActual->patch);
3795b98ada88071a752b6000756949a1951183cdd0bIan Romanick      return GL_FALSE;
3805b98ada88071a752b6000756949a1951183cdd0bIan Romanick   }
3815b98ada88071a752b6000756949a1951183cdd0bIan Romanick
3825b98ada88071a752b6000756949a1951183cdd0bIan Romanick   /* Check that the DDX driver version is compatible */
383225148ea0719a28d9b4eb286c4ab2bac52610bb3Dave Airlie   /* for miniglx we pass in -1 so we can ignore the DDX version */
384225148ea0719a28d9b4eb286c4ab2bac52610bb3Dave Airlie   if ( (ddxActual->major != -1) && ((ddxActual->major < ddxExpected->major_min)
3857104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger	|| (ddxActual->major > ddxExpected->major_max)
386225148ea0719a28d9b4eb286c4ab2bac52610bb3Dave Airlie	|| (ddxActual->minor < ddxExpected->minor)) ) {
387278736ff6f0659163e69392cf9e96006138746caDave Airlie      fprintf(stderr, format2, driver_name, "DDX",
3887104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger		       ddxExpected->major_min, ddxExpected->major_max, ddxExpected->minor,
3895b98ada88071a752b6000756949a1951183cdd0bIan Romanick		       ddxActual->major, ddxActual->minor, ddxActual->patch);
3905b98ada88071a752b6000756949a1951183cdd0bIan Romanick      return GL_FALSE;
3915b98ada88071a752b6000756949a1951183cdd0bIan Romanick   }
3925b98ada88071a752b6000756949a1951183cdd0bIan Romanick
3935b98ada88071a752b6000756949a1951183cdd0bIan Romanick   /* Check that the DRM driver version is compatible */
3945b98ada88071a752b6000756949a1951183cdd0bIan Romanick   if ( (drmActual->major != drmExpected->major)
3955b98ada88071a752b6000756949a1951183cdd0bIan Romanick	|| (drmActual->minor < drmExpected->minor) ) {
396278736ff6f0659163e69392cf9e96006138746caDave Airlie      fprintf(stderr, format, driver_name, "DRM",
3975b98ada88071a752b6000756949a1951183cdd0bIan Romanick		       drmExpected->major, drmExpected->minor,
3985b98ada88071a752b6000756949a1951183cdd0bIan Romanick		       drmActual->major, drmActual->minor, drmActual->patch);
3995b98ada88071a752b6000756949a1951183cdd0bIan Romanick      return GL_FALSE;
4005b98ada88071a752b6000756949a1951183cdd0bIan Romanick   }
4015b98ada88071a752b6000756949a1951183cdd0bIan Romanick
4025b98ada88071a752b6000756949a1951183cdd0bIan Romanick   return GL_TRUE;
4035b98ada88071a752b6000756949a1951183cdd0bIan Romanick}
4045b98ada88071a752b6000756949a1951183cdd0bIan Romanick
4057104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland ScheideggerGLboolean
4067104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland ScheideggerdriCheckDriDdxDrmVersions2(const char * driver_name,
4077104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger			   const __DRIversion * driActual,
4087104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger			   const __DRIversion * driExpected,
4097104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger			   const __DRIversion * ddxActual,
4107104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger			   const __DRIversion * ddxExpected,
4117104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger			   const __DRIversion * drmActual,
4127104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger			   const __DRIversion * drmExpected)
4137104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger{
4147104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger   __DRIutilversion2 ddx_expected;
4157104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger   ddx_expected.major_min = ddxExpected->major;
4167104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger   ddx_expected.major_max = ddxExpected->major;
4177104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger   ddx_expected.minor = ddxExpected->minor;
4187104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger   ddx_expected.patch = ddxExpected->patch;
4197104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger   return driCheckDriDdxDrmVersions3(driver_name, driActual,
4207104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger				driExpected, ddxActual, & ddx_expected,
4217104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger				drmActual, drmExpected);
4227104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger}
4237104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger
4247ed58285abede813fbf5fa0a2e29982043f1bbbeKeith WhitwellGLboolean driClipRectToFramebuffer( const GLframebuffer *buffer,
4257ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell				    GLint *x, GLint *y,
4267ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell				    GLsizei *width, GLsizei *height )
4277ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell{
4287ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   /* left clipping */
4297ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   if (*x < buffer->_Xmin) {
4307ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      *width -= (buffer->_Xmin - *x);
4317ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      *x = buffer->_Xmin;
4327ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   }
4337ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
4347ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   /* right clipping */
4357ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   if (*x + *width > buffer->_Xmax)
4367ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      *width -= (*x + *width - buffer->_Xmax - 1);
4377ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
4387ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   if (*width <= 0)
4397ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      return GL_FALSE;
4407ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
4417ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   /* bottom clipping */
4427ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   if (*y < buffer->_Ymin) {
4437ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      *height -= (buffer->_Ymin - *y);
4447ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      *y = buffer->_Ymin;
4457ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   }
4467ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
4477ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   /* top clipping */
4487ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   if (*y + *height > buffer->_Ymax)
4497ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      *height -= (*y + *height - buffer->_Ymax - 1);
4507ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
4517ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   if (*height <= 0)
4527ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      return GL_FALSE;
4537ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
4547ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   return GL_TRUE;
4557ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell}
45674396056977776919aaa7c22be1a3d17774ae321Ian Romanick
45774396056977776919aaa7c22be1a3d17774ae321Ian Romanick/**
45874396056977776919aaa7c22be1a3d17774ae321Ian Romanick * Creates a set of \c __GLcontextModes that a driver will expose.
45974396056977776919aaa7c22be1a3d17774ae321Ian Romanick *
46074396056977776919aaa7c22be1a3d17774ae321Ian Romanick * A set of \c __GLcontextModes will be created based on the supplied
46174396056977776919aaa7c22be1a3d17774ae321Ian Romanick * parameters.  The number of modes processed will be 2 *
46274396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c num_depth_stencil_bits * \c num_db_modes.
46374396056977776919aaa7c22be1a3d17774ae321Ian Romanick *
46474396056977776919aaa7c22be1a3d17774ae321Ian Romanick * For the most part, data is just copied from \c depth_bits, \c stencil_bits,
46574396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c db_modes, and \c visType into each \c __GLcontextModes element.
46674396056977776919aaa7c22be1a3d17774ae321Ian Romanick * However, the meanings of \c fb_format and \c fb_type require further
46774396056977776919aaa7c22be1a3d17774ae321Ian Romanick * explanation.  The \c fb_format specifies which color components are in
46874396056977776919aaa7c22be1a3d17774ae321Ian Romanick * each pixel and what the default order is.  For example, \c GL_RGB specifies
46974396056977776919aaa7c22be1a3d17774ae321Ian Romanick * that red, green, blue are available and red is in the "most significant"
47074396056977776919aaa7c22be1a3d17774ae321Ian Romanick * position and blue is in the "least significant".  The \c fb_type specifies
47174396056977776919aaa7c22be1a3d17774ae321Ian Romanick * the bit sizes of each component and the actual ordering.  For example, if
47274396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GL_UNSIGNED_SHORT_5_6_5_REV is specified with \c GL_RGB, bits [15:11]
47374396056977776919aaa7c22be1a3d17774ae321Ian Romanick * are the blue value, bits [10:5] are the green value, and bits [4:0] are
47474396056977776919aaa7c22be1a3d17774ae321Ian Romanick * the red value.
47574396056977776919aaa7c22be1a3d17774ae321Ian Romanick *
47674396056977776919aaa7c22be1a3d17774ae321Ian Romanick * One sublte issue is the combination of \c GL_RGB  or \c GL_BGR and either
47774396056977776919aaa7c22be1a3d17774ae321Ian Romanick * of the \c GL_UNSIGNED_INT_8_8_8_8 modes.  The resulting mask values in the
47874396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c __GLcontextModes structure is \b identical to the \c GL_RGBA or
47974396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GL_BGRA case, except the \c alphaMask is zero.  This means that, as
48074396056977776919aaa7c22be1a3d17774ae321Ian Romanick * far as this routine is concerned, \c GL_RGB with \c GL_UNSIGNED_INT_8_8_8_8
48174396056977776919aaa7c22be1a3d17774ae321Ian Romanick * still uses 32-bits.
48274396056977776919aaa7c22be1a3d17774ae321Ian Romanick *
48374396056977776919aaa7c22be1a3d17774ae321Ian Romanick * If in doubt, look at the tables used in the function.
48474396056977776919aaa7c22be1a3d17774ae321Ian Romanick *
48574396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param ptr_to_modes  Pointer to a pointer to a linked list of
48674396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c __GLcontextModes.  Upon completion, a pointer to
48774396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      the next element to be process will be stored here.
48874396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      If the function fails and returns \c GL_FALSE, this
48974396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      value will be unmodified, but some elements in the
49074396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      linked list may be modified.
49174396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param fb_format     Format of the framebuffer.  Currently only \c GL_RGB,
49274396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c GL_RGBA, \c GL_BGR, and \c GL_BGRA are supported.
49374396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param fb_type       Type of the pixels in the framebuffer.  Currently only
49474396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c GL_UNSIGNED_SHORT_5_6_5,
49574396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c GL_UNSIGNED_SHORT_5_6_5_REV,
49674396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c GL_UNSIGNED_INT_8_8_8_8, and
49774396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c GL_UNSIGNED_INT_8_8_8_8_REV are supported.
49874396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param depth_bits    Array of depth buffer sizes to be exposed.
49974396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param stencil_bits  Array of stencil buffer sizes to be exposed.
50074396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param num_depth_stencil_bits  Number of entries in both \c depth_bits and
50174396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c stencil_bits.
50274396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param db_modes      Array of buffer swap modes.  If an element has a
50374396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      value of \c GLX_NONE, then it represents a
50474396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      single-buffered mode.  Other valid values are
50574396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c GLX_SWAP_EXCHANGE_OML, \c GLX_SWAP_COPY_OML, and
50674396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c GLX_SWAP_UNDEFINED_OML.  See the
50774396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      GLX_OML_swap_method extension spec for more details.
50874396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param num_db_modes  Number of entries in \c db_modes.
509429a08384c2ea66d446e46beb28e33ee3b764d52Roland Scheidegger * \param msaa_samples  Array of msaa sample count. 0 represents a visual
510429a08384c2ea66d446e46beb28e33ee3b764d52Roland Scheidegger *                      without a multisample buffer.
511429a08384c2ea66d446e46beb28e33ee3b764d52Roland Scheidegger * \param num_msaa_modes Number of entries in \c msaa_samples.
51274396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param visType       GLX visual type.  Usually either \c GLX_TRUE_COLOR or
51374396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c GLX_DIRECT_COLOR.
51474396056977776919aaa7c22be1a3d17774ae321Ian Romanick *
51574396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \returns
51674396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GL_TRUE on success or \c GL_FALSE on failure.  Currently the only
51774396056977776919aaa7c22be1a3d17774ae321Ian Romanick * cause of failure is a bad parameter (i.e., unsupported \c fb_format or
51874396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c fb_type).
51974396056977776919aaa7c22be1a3d17774ae321Ian Romanick *
52074396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \todo
52174396056977776919aaa7c22be1a3d17774ae321Ian Romanick * There is currently no way to support packed RGB modes (i.e., modes with
52274396056977776919aaa7c22be1a3d17774ae321Ian Romanick * exactly 3 bytes per pixel) or floating-point modes.  This could probably
52374396056977776919aaa7c22be1a3d17774ae321Ian Romanick * be done by creating some new, private enums with clever names likes
52474396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GL_UNSIGNED_3BYTE_8_8_8, \c GL_4FLOAT_32_32_32_32,
52574396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GL_4HALF_16_16_16_16, etc.  We can cross that bridge when we come to it.
52674396056977776919aaa7c22be1a3d17774ae321Ian Romanick */
527e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg__DRIconfig **
528e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian HøgsbergdriCreateConfigs(GLenum fb_format, GLenum fb_type,
529e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg		 const u_int8_t * depth_bits, const u_int8_t * stencil_bits,
530e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg		 unsigned num_depth_stencil_bits,
531f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		 const GLenum * db_modes, unsigned num_db_modes,
532f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane	 	 const u_int8_t * msaa_samples, unsigned num_msaa_modes)
53374396056977776919aaa7c22be1a3d17774ae321Ian Romanick{
534b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis   static const u_int8_t bits_table[4][4] = {
53574396056977776919aaa7c22be1a3d17774ae321Ian Romanick     /* R  G  B  A */
536b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis      { 3, 3, 2, 0 }, /* Any GL_UNSIGNED_BYTE_3_3_2 */
53774396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 5, 6, 5, 0 }, /* Any GL_UNSIGNED_SHORT_5_6_5 */
53874396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 8, 8, 8, 0 }, /* Any RGB with any GL_UNSIGNED_INT_8_8_8_8 */
53974396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 8, 8, 8, 8 }  /* Any RGBA with any GL_UNSIGNED_INT_8_8_8_8 */
54074396056977776919aaa7c22be1a3d17774ae321Ian Romanick   };
54174396056977776919aaa7c22be1a3d17774ae321Ian Romanick
542b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis   static const u_int32_t masks_table_rgb[6][4] = {
543b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis      { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 3_3_2       */
544b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis      { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 2_3_3_REV   */
545fff749e893b0adbfb57d08370cb4d2a10608bc52Ian Romanick      { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5       */
54674396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV   */
54774396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000 }, /* 8_8_8_8     */
54874396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000 }  /* 8_8_8_8_REV */
54974396056977776919aaa7c22be1a3d17774ae321Ian Romanick   };
55074396056977776919aaa7c22be1a3d17774ae321Ian Romanick
551b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis   static const u_int32_t masks_table_rgba[6][4] = {
552b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis      { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 3_3_2       */
553b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis      { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 2_3_3_REV   */
554fff749e893b0adbfb57d08370cb4d2a10608bc52Ian Romanick      { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5       */
55574396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV   */
55674396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF }, /* 8_8_8_8     */
55774396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 }, /* 8_8_8_8_REV */
55874396056977776919aaa7c22be1a3d17774ae321Ian Romanick   };
55974396056977776919aaa7c22be1a3d17774ae321Ian Romanick
560b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis   static const u_int32_t masks_table_bgr[6][4] = {
561b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis      { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 3_3_2       */
562b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis      { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 2_3_3_REV   */
56374396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5       */
564fff749e893b0adbfb57d08370cb4d2a10608bc52Ian Romanick      { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV   */
56574396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x00000000 }, /* 8_8_8_8     */
56674396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 }, /* 8_8_8_8_REV */
56774396056977776919aaa7c22be1a3d17774ae321Ian Romanick   };
56874396056977776919aaa7c22be1a3d17774ae321Ian Romanick
569b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis   static const u_int32_t masks_table_bgra[6][4] = {
570b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis      { 0x00000007, 0x00000038, 0x000000C0, 0x00000000 }, /* 3_3_2       */
571b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis      { 0x000000E0, 0x0000001C, 0x00000003, 0x00000000 }, /* 2_3_3_REV   */
57274396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5       */
573fff749e893b0adbfb57d08370cb4d2a10608bc52Ian Romanick      { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV   */
57474396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x000000FF }, /* 8_8_8_8     */
57574396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000 }, /* 8_8_8_8_REV */
57674396056977776919aaa7c22be1a3d17774ae321Ian Romanick   };
57774396056977776919aaa7c22be1a3d17774ae321Ian Romanick
578b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis   static const u_int8_t bytes_per_pixel[6] = {
579b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis      1, /* 3_3_2       */
580b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis      1, /* 2_3_3_REV   */
581b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis      2, /* 5_6_5       */
582b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis      2, /* 5_6_5_REV   */
583b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis      4, /* 8_8_8_8     */
584b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis      4  /* 8_8_8_8_REV */
58574396056977776919aaa7c22be1a3d17774ae321Ian Romanick   };
58674396056977776919aaa7c22be1a3d17774ae321Ian Romanick
58738b317d508a2a3a4cc6d700ebca80c3b06c913e2Alan Hourihane   const u_int8_t  * bits;
58838b317d508a2a3a4cc6d700ebca80c3b06c913e2Alan Hourihane   const u_int32_t * masks;
589b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis   int index;
590e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   __DRIconfig **configs, **c;
591e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   __GLcontextModes *modes;
592f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane   unsigned i, j, k, h;
593e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   unsigned num_modes;
594e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   unsigned num_accum_bits = 2;
59574396056977776919aaa7c22be1a3d17774ae321Ian Romanick
596b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis   switch ( fb_type ) {
597b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis      case GL_UNSIGNED_BYTE_3_3_2:
598b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis	 index = 0;
599b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis	 break;
600b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis      case GL_UNSIGNED_BYTE_2_3_3_REV:
601b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis	 index = 1;
602b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis	 break;
603b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis      case GL_UNSIGNED_SHORT_5_6_5:
604b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis	 index = 2;
605b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis	 break;
606b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis      case GL_UNSIGNED_SHORT_5_6_5_REV:
607b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis	 index = 3;
608b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis	 break;
609b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis      case GL_UNSIGNED_INT_8_8_8_8:
610b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis	 index = 4;
611b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis	 break;
612b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis      case GL_UNSIGNED_INT_8_8_8_8_REV:
613b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis	 index = 5;
614b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis	 break;
615b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis      default:
616b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis	 fprintf( stderr, "[%s:%u] Unknown framebuffer type 0x%04x.\n",
617b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis               __FUNCTION__, __LINE__, fb_type );
618b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis	 return NULL;
61974396056977776919aaa7c22be1a3d17774ae321Ian Romanick   }
62074396056977776919aaa7c22be1a3d17774ae321Ian Romanick
62174396056977776919aaa7c22be1a3d17774ae321Ian Romanick
62274396056977776919aaa7c22be1a3d17774ae321Ian Romanick   /* Valid types are GL_UNSIGNED_SHORT_5_6_5 and GL_UNSIGNED_INT_8_8_8_8 and
62374396056977776919aaa7c22be1a3d17774ae321Ian Romanick    * the _REV versions.
62474396056977776919aaa7c22be1a3d17774ae321Ian Romanick    *
62574396056977776919aaa7c22be1a3d17774ae321Ian Romanick    * Valid formats are GL_RGBA, GL_RGB, and GL_BGRA.
62674396056977776919aaa7c22be1a3d17774ae321Ian Romanick    */
62774396056977776919aaa7c22be1a3d17774ae321Ian Romanick
62874396056977776919aaa7c22be1a3d17774ae321Ian Romanick   switch ( fb_format ) {
62974396056977776919aaa7c22be1a3d17774ae321Ian Romanick      case GL_RGB:
63074396056977776919aaa7c22be1a3d17774ae321Ian Romanick         masks = masks_table_rgb[ index ];
63174396056977776919aaa7c22be1a3d17774ae321Ian Romanick         break;
63274396056977776919aaa7c22be1a3d17774ae321Ian Romanick
63374396056977776919aaa7c22be1a3d17774ae321Ian Romanick      case GL_RGBA:
63474396056977776919aaa7c22be1a3d17774ae321Ian Romanick         masks = masks_table_rgba[ index ];
63574396056977776919aaa7c22be1a3d17774ae321Ian Romanick         break;
63674396056977776919aaa7c22be1a3d17774ae321Ian Romanick
63774396056977776919aaa7c22be1a3d17774ae321Ian Romanick      case GL_BGR:
63874396056977776919aaa7c22be1a3d17774ae321Ian Romanick         masks = masks_table_bgr[ index ];
63974396056977776919aaa7c22be1a3d17774ae321Ian Romanick         break;
64074396056977776919aaa7c22be1a3d17774ae321Ian Romanick
64174396056977776919aaa7c22be1a3d17774ae321Ian Romanick      case GL_BGRA:
64274396056977776919aaa7c22be1a3d17774ae321Ian Romanick         masks = masks_table_bgra[ index ];
64374396056977776919aaa7c22be1a3d17774ae321Ian Romanick         break;
64474396056977776919aaa7c22be1a3d17774ae321Ian Romanick
64574396056977776919aaa7c22be1a3d17774ae321Ian Romanick      default:
646b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis         fprintf( stderr, "[%s:%u] Unknown framebuffer format 0x%04x.\n",
647b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis               __FUNCTION__, __LINE__, fb_format );
648e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg         return NULL;
64974396056977776919aaa7c22be1a3d17774ae321Ian Romanick   }
65074396056977776919aaa7c22be1a3d17774ae321Ian Romanick
651b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis   switch ( bytes_per_pixel[ index ] ) {
652b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis      case 1:
653b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis	 bits = bits_table[0];
654b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis	 break;
655b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis      case 2:
656b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis	 bits = bits_table[1];
657b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis	 break;
658b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis      default:
659b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis	 bits = ((fb_format == GL_RGB) || (fb_format == GL_BGR))
660b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis	    ? bits_table[2]
661b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis	    : bits_table[3];
662b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis	 break;
663b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis   }
664b4a4829cd50f7110ddbdd0770297cd845ab4764dGeorge Sapountzis
665e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   num_modes = num_depth_stencil_bits * num_db_modes * num_accum_bits;
666e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   configs = _mesa_calloc((num_modes + 1) * sizeof *configs);
667e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   if (configs == NULL)
668e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg       return NULL;
66974396056977776919aaa7c22be1a3d17774ae321Ian Romanick
670e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    c = configs;
67174396056977776919aaa7c22be1a3d17774ae321Ian Romanick    for ( k = 0 ; k < num_depth_stencil_bits ; k++ ) {
67274396056977776919aaa7c22be1a3d17774ae321Ian Romanick	for ( i = 0 ; i < num_db_modes ; i++ ) {
673f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane	    for ( h = 0 ; h < num_msaa_modes; h++ ) {
674f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane	    	for ( j = 0 ; j < num_accum_bits ; j++ ) {
675f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    *c = _mesa_malloc (sizeof **c);
676f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes = &(*c)->modes;
677f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    c++;
678f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane
679f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    memset(modes, 0, sizeof *modes);
680f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->redBits   = bits[0];
681f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->greenBits = bits[1];
682f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->blueBits  = bits[2];
683f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->alphaBits = bits[3];
684f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->redMask   = masks[0];
685f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->greenMask = masks[1];
686f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->blueMask  = masks[2];
687f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->alphaMask = masks[3];
688f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->rgbBits   = modes->redBits + modes->greenBits
689f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    	+ modes->blueBits + modes->alphaBits;
690f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane
691f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->accumRedBits   = 16 * j;
692f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->accumGreenBits = 16 * j;
693f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->accumBlueBits  = 16 * j;
694f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->accumAlphaBits = (masks[3] != 0) ? 16 * j : 0;
695f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->visualRating = (j == 0) ? GLX_NONE : GLX_SLOW_CONFIG;
696f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane
697f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->stencilBits = stencil_bits[k];
698f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->depthBits = depth_bits[k];
699f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane
700f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->transparentPixel = GLX_NONE;
701f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->transparentRed = GLX_DONT_CARE;
702f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->transparentGreen = GLX_DONT_CARE;
703f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->transparentBlue = GLX_DONT_CARE;
704f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->transparentAlpha = GLX_DONT_CARE;
705f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->transparentIndex = GLX_DONT_CARE;
706f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->visualType = GLX_DONT_CARE;
707f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->renderType = GLX_RGBA_BIT;
708f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->drawableType = GLX_WINDOW_BIT;
709f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->rgbMode = GL_TRUE;
710f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane
711f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    if ( db_modes[i] == GLX_NONE ) {
712f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    	modes->doubleBufferMode = GL_FALSE;
713f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    }
714f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    else {
715f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    	modes->doubleBufferMode = GL_TRUE;
716f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    	modes->swapMethod = db_modes[i];
717f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    }
718f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane
719f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->samples = msaa_samples[h];
720f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->sampleBuffers = modes->samples ? 1 : 0;
721f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane
722f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane
723f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->haveAccumBuffer = ((modes->accumRedBits +
7247f8e10f96c1970d2c81ec8d4f3a45a3b006b3be1Keith Whitwell					   modes->accumGreenBits +
7257f8e10f96c1970d2c81ec8d4f3a45a3b006b3be1Keith Whitwell					   modes->accumBlueBits +
7267f8e10f96c1970d2c81ec8d4f3a45a3b006b3be1Keith Whitwell					   modes->accumAlphaBits) > 0);
727f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->haveDepthBuffer = (modes->depthBits > 0);
728f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->haveStencilBuffer = (modes->stencilBits > 0);
729f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane
730f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->bindToTextureRgb = GL_TRUE;
731f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->bindToTextureRgba = GL_TRUE;
732f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->bindToMipmapTexture = GL_FALSE;
733f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes->bindToTextureTargets = modes->rgbMode ?
734f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    	__DRI_ATTRIB_TEXTURE_1D_BIT |
735f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    	__DRI_ATTRIB_TEXTURE_2D_BIT |
736f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    	__DRI_ATTRIB_TEXTURE_RECTANGLE_BIT :
737f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    	0;
738f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane
739f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		    modes = modes->next;
740f7d80aa00611917bc8ce637136d982b151b8f44fAlan Hourihane		}
74174396056977776919aaa7c22be1a3d17774ae321Ian Romanick	    }
74274396056977776919aaa7c22be1a3d17774ae321Ian Romanick	}
74374396056977776919aaa7c22be1a3d17774ae321Ian Romanick    }
744e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    *c = NULL;
745e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg
746e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    return configs;
747e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg}
74874396056977776919aaa7c22be1a3d17774ae321Ian Romanick
749e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsbergconst __DRIconfig **driConcatConfigs(__DRIconfig **a, __DRIconfig **b)
750e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg{
751e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    const __DRIconfig **all;
752e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    int i, j, index;
753e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg
754e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    i = 0;
755e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    while (a[i] != NULL)
756e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg	i++;
757e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    j = 0;
758e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    while (b[j] != NULL)
759e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg	j++;
760e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg
761e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    all = _mesa_malloc((i + j + 1) * sizeof *all);
762e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    index = 0;
763e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    for (i = 0; a[i] != NULL; i++)
764e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg	all[index++] = a[i];
765e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    for (j = 0; b[j] != NULL; j++)
766e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg	all[index++] = b[j];
767e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    all[index++] = NULL;
768e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg
769e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    _mesa_free(a);
770e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    _mesa_free(b);
771e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg
772e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    return all;
77374396056977776919aaa7c22be1a3d17774ae321Ian Romanick}
774c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis
775c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis#define __ATTRIB(attrib, field) \
776c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    { attrib, offsetof(__GLcontextModes, field) }
777c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis
778c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzisstatic const struct { unsigned int attrib, offset; } attribMap[] = {
779c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_BUFFER_SIZE,			rgbBits),
780c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_LEVEL,			level),
781c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_RED_SIZE,			redBits),
782c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_GREEN_SIZE,			greenBits),
783c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_BLUE_SIZE,			blueBits),
784c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_ALPHA_SIZE,			alphaBits),
785c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_DEPTH_SIZE,			depthBits),
786c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_STENCIL_SIZE,			stencilBits),
787c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_ACCUM_RED_SIZE,		accumRedBits),
788c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_ACCUM_GREEN_SIZE,		accumGreenBits),
789c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_ACCUM_BLUE_SIZE,		accumBlueBits),
790c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_ACCUM_ALPHA_SIZE,		accumAlphaBits),
791c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_SAMPLE_BUFFERS,		sampleBuffers),
792c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_SAMPLES,			samples),
793c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_DOUBLE_BUFFER,		doubleBufferMode),
794c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_STEREO,			stereoMode),
795c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_AUX_BUFFERS,			numAuxBuffers),
796c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_TRANSPARENT_TYPE,		transparentPixel),
797c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_TRANSPARENT_INDEX_VALUE,	transparentPixel),
798c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_TRANSPARENT_RED_VALUE,	transparentRed),
799c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_TRANSPARENT_GREEN_VALUE,	transparentGreen),
800c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_TRANSPARENT_BLUE_VALUE,	transparentBlue),
801c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE,	transparentAlpha),
802c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_FLOAT_MODE,			floatMode),
803c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_RED_MASK,			redMask),
804c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_GREEN_MASK,			greenMask),
805c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_BLUE_MASK,			blueMask),
806c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_ALPHA_MASK,			alphaMask),
807c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_WIDTH,		maxPbufferWidth),
808c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_HEIGHT,		maxPbufferHeight),
809c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_PIXELS,		maxPbufferPixels),
810c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH,	optimalPbufferWidth),
811c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT,	optimalPbufferHeight),
812c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_SWAP_METHOD,			swapMethod),
813c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGB,		bindToTextureRgb),
814c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGBA,		bindToTextureRgba),
815c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE,	bindToMipmapTexture),
816c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS,	bindToTextureTargets),
817c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_YINVERTED,			yInverted),
818c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis
819c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    /* The struct field doesn't matter here, these are handled by the
820c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis     * switch in driGetConfigAttribIndex.  We need them in the array
821c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis     * so the iterator includes them though.*/
822c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_RENDER_TYPE,			level),
823c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_CONFIG_CAVEAT,		level),
824c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    __ATTRIB(__DRI_ATTRIB_SWAP_METHOD,			level)
825c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis};
826c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis
827c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
828c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis
829c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzisstatic int
830c95e66120be049ee51ff84868b1da3379b312fabGeorge SapountzisdriGetConfigAttribIndex(const __DRIconfig *config,
831c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis			unsigned int index, unsigned int *value)
832c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis{
833c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    switch (attribMap[index].attrib) {
834c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    case __DRI_ATTRIB_RENDER_TYPE:
835c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis	if (config->modes.rgbMode)
836c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis	    *value = __DRI_ATTRIB_RGBA_BIT;
837c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis	else
838c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis	    *value = __DRI_ATTRIB_COLOR_INDEX_BIT;
839c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis	break;
840c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    case __DRI_ATTRIB_CONFIG_CAVEAT:
841c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis	if (config->modes.visualRating == GLX_NON_CONFORMANT_CONFIG)
842c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis	    *value = __DRI_ATTRIB_NON_CONFORMANT_CONFIG;
843c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis	else if (config->modes.visualRating == GLX_SLOW_CONFIG)
844c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis	    *value = __DRI_ATTRIB_SLOW_BIT;
845c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis	else
846c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis	    *value = 0;
847c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis	break;
848c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    case __DRI_ATTRIB_SWAP_METHOD:
849c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis	break;
850c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis
8511724334d7c82abe55b6506dfe369df4facae6f06Dave Miller    case __DRI_ATTRIB_FLOAT_MODE:
8521724334d7c82abe55b6506dfe369df4facae6f06Dave Miller        *value = config->modes.floatMode;
8531724334d7c82abe55b6506dfe369df4facae6f06Dave Miller        break;
8541724334d7c82abe55b6506dfe369df4facae6f06Dave Miller
855c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    default:
856c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis	*value = *(unsigned int *)
857c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis	    ((char *) &config->modes + attribMap[index].offset);
858c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis
859c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis	break;
860c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    }
861c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis
862c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    return GL_TRUE;
863c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis}
864c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis
865c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzisint
866c95e66120be049ee51ff84868b1da3379b312fabGeorge SapountzisdriGetConfigAttrib(const __DRIconfig *config,
867c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis		   unsigned int attrib, unsigned int *value)
868c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis{
869c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    int i;
870c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis
871c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    for (i = 0; i < ARRAY_SIZE(attribMap); i++)
872c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis	if (attribMap[i].attrib == attrib)
873c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis	    return driGetConfigAttribIndex(config, i, value);
874c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis
875c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    return GL_FALSE;
876c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis}
877c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis
878c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzisint
879c95e66120be049ee51ff84868b1da3379b312fabGeorge SapountzisdriIndexConfigAttrib(const __DRIconfig *config, int index,
880c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis		     unsigned int *attrib, unsigned int *value)
881c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis{
882c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    if (index >= 0 && index < ARRAY_SIZE(attribMap)) {
883c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis	*attrib = attribMap[index].attrib;
884c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis	return driGetConfigAttribIndex(config, index, value);
885c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    }
886c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis
887c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis    return GL_FALSE;
888c95e66120be049ee51ff84868b1da3379b312fabGeorge Sapountzis}
889