utils.c revision e82dd8c6e1fa2fff5b960de26961080ba5e9651d
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) {
3138fbe16d4dd0664f7766f5241c055efb582cc06e5Ian Romanick		fprintf(stderr, "DISPATCH ERROR! _glapi_add_dispatch failed "
3148fbe16d4dd0664f7766f5241c055efb582cc06e5Ian Romanick			"to add %s!\n", functions[0]);
3151585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick	    }
3168fbe16d4dd0664f7766f5241c055efb582cc06e5Ian Romanick	    else if (ext->functions[i].remap_index != -1) {
3178fbe16d4dd0664f7766f5241c055efb582cc06e5Ian Romanick		driDispatchRemapTable[ ext->functions[i].remap_index ] =
3188fbe16d4dd0664f7766f5241c055efb582cc06e5Ian Romanick		  offset;
3198fbe16d4dd0664f7766f5241c055efb582cc06e5Ian Romanick	    }
3208fbe16d4dd0664f7766f5241c055efb582cc06e5Ian Romanick	    else if (ext->functions[i].offset != offset) {
3218fbe16d4dd0664f7766f5241c055efb582cc06e5Ian Romanick		fprintf(stderr, "DISPATCH ERROR! %s -> %u != %u\n",
3228fbe16d4dd0664f7766f5241c055efb582cc06e5Ian Romanick			functions[0], offset, ext->functions[i].offset);
323c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	    }
324c212abf99af494f024b0b981a83350f7ac9821efIan Romanick	}
325c212abf99af494f024b0b981a83350f7ac9821efIan Romanick    }
326c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
3271585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick    if ( ctx != NULL ) {
3281585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick	_mesa_enable_extension( ctx, ext->name );
3291585c234e0db4bfb7cd85c4111594f6da1582e6fIan Romanick    }
330c212abf99af494f024b0b981a83350f7ac9821efIan Romanick}
331c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
332c212abf99af494f024b0b981a83350f7ac9821efIan Romanick
3335b98ada88071a752b6000756949a1951183cdd0bIan Romanick/**
3345b98ada88071a752b6000756949a1951183cdd0bIan Romanick * Utility function used by drivers to test the verions of other components.
3355b98ada88071a752b6000756949a1951183cdd0bIan Romanick *
3365b98ada88071a752b6000756949a1951183cdd0bIan Romanick * If one of the version requirements is not met, a message is logged using
3375b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \c __driUtilMessage.
3385b98ada88071a752b6000756949a1951183cdd0bIan Romanick *
3395b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param driver_name  Name of the driver.  Used in error messages.
3405b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param driActual    Actual DRI version supplied __driCreateNewScreen.
3415b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param driExpected  Minimum DRI version required by the driver.
3425b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param ddxActual    Actual DDX version supplied __driCreateNewScreen.
3437104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger * \param ddxExpected  Minimum DDX minor and range of DDX major version required by the driver.
3445b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param drmActual    Actual DRM version supplied __driCreateNewScreen.
3455b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param drmExpected  Minimum DRM version required by the driver.
3465b98ada88071a752b6000756949a1951183cdd0bIan Romanick *
3475b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \returns \c GL_TRUE if all version requirements are met.  Otherwise,
3485b98ada88071a752b6000756949a1951183cdd0bIan Romanick *          \c GL_FALSE is returned.
3495b98ada88071a752b6000756949a1951183cdd0bIan Romanick *
350c39bf5e273a4995a279ae2af59fc29e06ab47e29Ian Romanick * \sa __driCreateNewScreen, driCheckDriDdxDrmVersions2, __driUtilMessage
351c39bf5e273a4995a279ae2af59fc29e06ab47e29Ian Romanick *
352c39bf5e273a4995a279ae2af59fc29e06ab47e29Ian Romanick * \todo
353c39bf5e273a4995a279ae2af59fc29e06ab47e29Ian Romanick * Now that the old \c driCheckDriDdxDrmVersions function is gone, this
354c39bf5e273a4995a279ae2af59fc29e06ab47e29Ian Romanick * function and \c driCheckDriDdxDrmVersions2 should be renamed.
3555b98ada88071a752b6000756949a1951183cdd0bIan Romanick */
3565b98ada88071a752b6000756949a1951183cdd0bIan RomanickGLboolean
3577104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland ScheideggerdriCheckDriDdxDrmVersions3(const char * driver_name,
3585b98ada88071a752b6000756949a1951183cdd0bIan Romanick			   const __DRIversion * driActual,
3595b98ada88071a752b6000756949a1951183cdd0bIan Romanick			   const __DRIversion * driExpected,
3605b98ada88071a752b6000756949a1951183cdd0bIan Romanick			   const __DRIversion * ddxActual,
3617104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger			   const __DRIutilversion2 * ddxExpected,
3625b98ada88071a752b6000756949a1951183cdd0bIan Romanick			   const __DRIversion * drmActual,
3635b98ada88071a752b6000756949a1951183cdd0bIan Romanick			   const __DRIversion * drmExpected)
3645b98ada88071a752b6000756949a1951183cdd0bIan Romanick{
3655b98ada88071a752b6000756949a1951183cdd0bIan Romanick   static const char format[] = "%s DRI driver expected %s version %d.%d.x "
366278736ff6f0659163e69392cf9e96006138746caDave Airlie       "but got version %d.%d.%d\n";
3677104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger   static const char format2[] = "%s DRI driver expected %s version %d-%d.%d.x "
368278736ff6f0659163e69392cf9e96006138746caDave Airlie       "but got version %d.%d.%d\n";
3695b98ada88071a752b6000756949a1951183cdd0bIan Romanick
3705b98ada88071a752b6000756949a1951183cdd0bIan Romanick
3715b98ada88071a752b6000756949a1951183cdd0bIan Romanick   /* Check the DRI version */
3725b98ada88071a752b6000756949a1951183cdd0bIan Romanick   if ( (driActual->major != driExpected->major)
3735b98ada88071a752b6000756949a1951183cdd0bIan Romanick	|| (driActual->minor < driExpected->minor) ) {
374278736ff6f0659163e69392cf9e96006138746caDave Airlie      fprintf(stderr, format, driver_name, "DRI",
3755b98ada88071a752b6000756949a1951183cdd0bIan Romanick		       driExpected->major, driExpected->minor,
3765b98ada88071a752b6000756949a1951183cdd0bIan Romanick		       driActual->major, driActual->minor, driActual->patch);
3775b98ada88071a752b6000756949a1951183cdd0bIan Romanick      return GL_FALSE;
3785b98ada88071a752b6000756949a1951183cdd0bIan Romanick   }
3795b98ada88071a752b6000756949a1951183cdd0bIan Romanick
3805b98ada88071a752b6000756949a1951183cdd0bIan Romanick   /* Check that the DDX driver version is compatible */
381225148ea0719a28d9b4eb286c4ab2bac52610bb3Dave Airlie   /* for miniglx we pass in -1 so we can ignore the DDX version */
382225148ea0719a28d9b4eb286c4ab2bac52610bb3Dave Airlie   if ( (ddxActual->major != -1) && ((ddxActual->major < ddxExpected->major_min)
3837104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger	|| (ddxActual->major > ddxExpected->major_max)
384225148ea0719a28d9b4eb286c4ab2bac52610bb3Dave Airlie	|| (ddxActual->minor < ddxExpected->minor)) ) {
385278736ff6f0659163e69392cf9e96006138746caDave Airlie      fprintf(stderr, format2, driver_name, "DDX",
3867104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger		       ddxExpected->major_min, ddxExpected->major_max, ddxExpected->minor,
3875b98ada88071a752b6000756949a1951183cdd0bIan Romanick		       ddxActual->major, ddxActual->minor, ddxActual->patch);
3885b98ada88071a752b6000756949a1951183cdd0bIan Romanick      return GL_FALSE;
3895b98ada88071a752b6000756949a1951183cdd0bIan Romanick   }
3905b98ada88071a752b6000756949a1951183cdd0bIan Romanick
3915b98ada88071a752b6000756949a1951183cdd0bIan Romanick   /* Check that the DRM driver version is compatible */
3925b98ada88071a752b6000756949a1951183cdd0bIan Romanick   if ( (drmActual->major != drmExpected->major)
3935b98ada88071a752b6000756949a1951183cdd0bIan Romanick	|| (drmActual->minor < drmExpected->minor) ) {
394278736ff6f0659163e69392cf9e96006138746caDave Airlie      fprintf(stderr, format, driver_name, "DRM",
3955b98ada88071a752b6000756949a1951183cdd0bIan Romanick		       drmExpected->major, drmExpected->minor,
3965b98ada88071a752b6000756949a1951183cdd0bIan Romanick		       drmActual->major, drmActual->minor, drmActual->patch);
3975b98ada88071a752b6000756949a1951183cdd0bIan Romanick      return GL_FALSE;
3985b98ada88071a752b6000756949a1951183cdd0bIan Romanick   }
3995b98ada88071a752b6000756949a1951183cdd0bIan Romanick
4005b98ada88071a752b6000756949a1951183cdd0bIan Romanick   return GL_TRUE;
4015b98ada88071a752b6000756949a1951183cdd0bIan Romanick}
4025b98ada88071a752b6000756949a1951183cdd0bIan Romanick
4037104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland ScheideggerGLboolean
4047104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland ScheideggerdriCheckDriDdxDrmVersions2(const char * driver_name,
4057104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger			   const __DRIversion * driActual,
4067104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger			   const __DRIversion * driExpected,
4077104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger			   const __DRIversion * ddxActual,
4087104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger			   const __DRIversion * ddxExpected,
4097104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger			   const __DRIversion * drmActual,
4107104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger			   const __DRIversion * drmExpected)
4117104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger{
4127104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger   __DRIutilversion2 ddx_expected;
4137104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger   ddx_expected.major_min = ddxExpected->major;
4147104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger   ddx_expected.major_max = ddxExpected->major;
4157104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger   ddx_expected.minor = ddxExpected->minor;
4167104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger   ddx_expected.patch = ddxExpected->patch;
4177104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger   return driCheckDriDdxDrmVersions3(driver_name, driActual,
4187104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger				driExpected, ddxActual, & ddx_expected,
4197104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger				drmActual, drmExpected);
4207104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger}
4217104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger
4227104ce0a0e8f25bf097ad695d007b1a4b3e5d051Roland Scheidegger
4237ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
424638ece315f4ee7be7f0fe0a0acd2550b4ccb8a7dMichel DänzerGLint
425638ece315f4ee7be7f0fe0a0acd2550b4ccb8a7dMichel DänzerdriIntersectArea( drm_clip_rect_t rect1, drm_clip_rect_t rect2 )
426638ece315f4ee7be7f0fe0a0acd2550b4ccb8a7dMichel Dänzer{
427638ece315f4ee7be7f0fe0a0acd2550b4ccb8a7dMichel Dänzer   if (rect2.x1 > rect1.x1) rect1.x1 = rect2.x1;
428638ece315f4ee7be7f0fe0a0acd2550b4ccb8a7dMichel Dänzer   if (rect2.x2 < rect1.x2) rect1.x2 = rect2.x2;
429638ece315f4ee7be7f0fe0a0acd2550b4ccb8a7dMichel Dänzer   if (rect2.y1 > rect1.y1) rect1.y1 = rect2.y1;
430638ece315f4ee7be7f0fe0a0acd2550b4ccb8a7dMichel Dänzer   if (rect2.y2 < rect1.y2) rect1.y2 = rect2.y2;
431638ece315f4ee7be7f0fe0a0acd2550b4ccb8a7dMichel Dänzer
432638ece315f4ee7be7f0fe0a0acd2550b4ccb8a7dMichel Dänzer   if (rect1.x1 > rect1.x2 || rect1.y1 > rect1.y2) return 0;
433638ece315f4ee7be7f0fe0a0acd2550b4ccb8a7dMichel Dänzer
434638ece315f4ee7be7f0fe0a0acd2550b4ccb8a7dMichel Dänzer   return (rect1.x2 - rect1.x1) * (rect1.y2 - rect1.y1);
435638ece315f4ee7be7f0fe0a0acd2550b4ccb8a7dMichel Dänzer}
436638ece315f4ee7be7f0fe0a0acd2550b4ccb8a7dMichel Dänzer
4377ed58285abede813fbf5fa0a2e29982043f1bbbeKeith WhitwellGLboolean driClipRectToFramebuffer( const GLframebuffer *buffer,
4387ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell				    GLint *x, GLint *y,
4397ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell				    GLsizei *width, GLsizei *height )
4407ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell{
4417ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   /* left clipping */
4427ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   if (*x < buffer->_Xmin) {
4437ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      *width -= (buffer->_Xmin - *x);
4447ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      *x = buffer->_Xmin;
4457ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   }
4467ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
4477ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   /* right clipping */
4487ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   if (*x + *width > buffer->_Xmax)
4497ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      *width -= (*x + *width - buffer->_Xmax - 1);
4507ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
4517ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   if (*width <= 0)
4527ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      return GL_FALSE;
4537ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
4547ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   /* bottom clipping */
4557ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   if (*y < buffer->_Ymin) {
4567ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      *height -= (buffer->_Ymin - *y);
4577ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      *y = buffer->_Ymin;
4587ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   }
4597ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
4607ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   /* top clipping */
4617ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   if (*y + *height > buffer->_Ymax)
4627ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      *height -= (*y + *height - buffer->_Ymax - 1);
4637ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
4647ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   if (*height <= 0)
4657ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      return GL_FALSE;
4667ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
4677ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   return GL_TRUE;
4687ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell}
46974396056977776919aaa7c22be1a3d17774ae321Ian Romanick
47074396056977776919aaa7c22be1a3d17774ae321Ian Romanick/**
47174396056977776919aaa7c22be1a3d17774ae321Ian Romanick * Creates a set of \c __GLcontextModes that a driver will expose.
47274396056977776919aaa7c22be1a3d17774ae321Ian Romanick *
47374396056977776919aaa7c22be1a3d17774ae321Ian Romanick * A set of \c __GLcontextModes will be created based on the supplied
47474396056977776919aaa7c22be1a3d17774ae321Ian Romanick * parameters.  The number of modes processed will be 2 *
47574396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c num_depth_stencil_bits * \c num_db_modes.
47674396056977776919aaa7c22be1a3d17774ae321Ian Romanick *
47774396056977776919aaa7c22be1a3d17774ae321Ian Romanick * For the most part, data is just copied from \c depth_bits, \c stencil_bits,
47874396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c db_modes, and \c visType into each \c __GLcontextModes element.
47974396056977776919aaa7c22be1a3d17774ae321Ian Romanick * However, the meanings of \c fb_format and \c fb_type require further
48074396056977776919aaa7c22be1a3d17774ae321Ian Romanick * explanation.  The \c fb_format specifies which color components are in
48174396056977776919aaa7c22be1a3d17774ae321Ian Romanick * each pixel and what the default order is.  For example, \c GL_RGB specifies
48274396056977776919aaa7c22be1a3d17774ae321Ian Romanick * that red, green, blue are available and red is in the "most significant"
48374396056977776919aaa7c22be1a3d17774ae321Ian Romanick * position and blue is in the "least significant".  The \c fb_type specifies
48474396056977776919aaa7c22be1a3d17774ae321Ian Romanick * the bit sizes of each component and the actual ordering.  For example, if
48574396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GL_UNSIGNED_SHORT_5_6_5_REV is specified with \c GL_RGB, bits [15:11]
48674396056977776919aaa7c22be1a3d17774ae321Ian Romanick * are the blue value, bits [10:5] are the green value, and bits [4:0] are
48774396056977776919aaa7c22be1a3d17774ae321Ian Romanick * the red value.
48874396056977776919aaa7c22be1a3d17774ae321Ian Romanick *
48974396056977776919aaa7c22be1a3d17774ae321Ian Romanick * One sublte issue is the combination of \c GL_RGB  or \c GL_BGR and either
49074396056977776919aaa7c22be1a3d17774ae321Ian Romanick * of the \c GL_UNSIGNED_INT_8_8_8_8 modes.  The resulting mask values in the
49174396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c __GLcontextModes structure is \b identical to the \c GL_RGBA or
49274396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GL_BGRA case, except the \c alphaMask is zero.  This means that, as
49374396056977776919aaa7c22be1a3d17774ae321Ian Romanick * far as this routine is concerned, \c GL_RGB with \c GL_UNSIGNED_INT_8_8_8_8
49474396056977776919aaa7c22be1a3d17774ae321Ian Romanick * still uses 32-bits.
49574396056977776919aaa7c22be1a3d17774ae321Ian Romanick *
49674396056977776919aaa7c22be1a3d17774ae321Ian Romanick * If in doubt, look at the tables used in the function.
49774396056977776919aaa7c22be1a3d17774ae321Ian Romanick *
49874396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param ptr_to_modes  Pointer to a pointer to a linked list of
49974396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c __GLcontextModes.  Upon completion, a pointer to
50074396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      the next element to be process will be stored here.
50174396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      If the function fails and returns \c GL_FALSE, this
50274396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      value will be unmodified, but some elements in the
50374396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      linked list may be modified.
50474396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param fb_format     Format of the framebuffer.  Currently only \c GL_RGB,
50574396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c GL_RGBA, \c GL_BGR, and \c GL_BGRA are supported.
50674396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param fb_type       Type of the pixels in the framebuffer.  Currently only
50774396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c GL_UNSIGNED_SHORT_5_6_5,
50874396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c GL_UNSIGNED_SHORT_5_6_5_REV,
50974396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c GL_UNSIGNED_INT_8_8_8_8, and
51074396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c GL_UNSIGNED_INT_8_8_8_8_REV are supported.
51174396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param depth_bits    Array of depth buffer sizes to be exposed.
51274396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param stencil_bits  Array of stencil buffer sizes to be exposed.
51374396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param num_depth_stencil_bits  Number of entries in both \c depth_bits and
51474396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c stencil_bits.
51574396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param db_modes      Array of buffer swap modes.  If an element has a
51674396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      value of \c GLX_NONE, then it represents a
51774396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      single-buffered mode.  Other valid values are
51874396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c GLX_SWAP_EXCHANGE_OML, \c GLX_SWAP_COPY_OML, and
51974396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c GLX_SWAP_UNDEFINED_OML.  See the
52074396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      GLX_OML_swap_method extension spec for more details.
52174396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param num_db_modes  Number of entries in \c db_modes.
52274396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param visType       GLX visual type.  Usually either \c GLX_TRUE_COLOR or
52374396056977776919aaa7c22be1a3d17774ae321Ian Romanick *                      \c GLX_DIRECT_COLOR.
52474396056977776919aaa7c22be1a3d17774ae321Ian Romanick *
52574396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \returns
52674396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GL_TRUE on success or \c GL_FALSE on failure.  Currently the only
52774396056977776919aaa7c22be1a3d17774ae321Ian Romanick * cause of failure is a bad parameter (i.e., unsupported \c fb_format or
52874396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c fb_type).
52974396056977776919aaa7c22be1a3d17774ae321Ian Romanick *
53074396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \todo
53174396056977776919aaa7c22be1a3d17774ae321Ian Romanick * There is currently no way to support packed RGB modes (i.e., modes with
53274396056977776919aaa7c22be1a3d17774ae321Ian Romanick * exactly 3 bytes per pixel) or floating-point modes.  This could probably
53374396056977776919aaa7c22be1a3d17774ae321Ian Romanick * be done by creating some new, private enums with clever names likes
53474396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GL_UNSIGNED_3BYTE_8_8_8, \c GL_4FLOAT_32_32_32_32,
53574396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GL_4HALF_16_16_16_16, etc.  We can cross that bridge when we come to it.
53674396056977776919aaa7c22be1a3d17774ae321Ian Romanick */
537e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg__DRIconfig **
538e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian HøgsbergdriCreateConfigs(GLenum fb_format, GLenum fb_type,
539e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg		 const u_int8_t * depth_bits, const u_int8_t * stencil_bits,
540e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg		 unsigned num_depth_stencil_bits,
541e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg		 const GLenum * db_modes, unsigned num_db_modes)
54274396056977776919aaa7c22be1a3d17774ae321Ian Romanick{
54338b317d508a2a3a4cc6d700ebca80c3b06c913e2Alan Hourihane   static const u_int8_t bits_table[3][4] = {
54474396056977776919aaa7c22be1a3d17774ae321Ian Romanick     /* R  G  B  A */
54574396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 5, 6, 5, 0 }, /* Any GL_UNSIGNED_SHORT_5_6_5 */
54674396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 8, 8, 8, 0 }, /* Any RGB with any GL_UNSIGNED_INT_8_8_8_8 */
54774396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 8, 8, 8, 8 }  /* Any RGBA with any GL_UNSIGNED_INT_8_8_8_8 */
54874396056977776919aaa7c22be1a3d17774ae321Ian Romanick   };
54974396056977776919aaa7c22be1a3d17774ae321Ian Romanick
55074396056977776919aaa7c22be1a3d17774ae321Ian Romanick   /* The following arrays are all indexed by the fb_type masked with 0x07.
55174396056977776919aaa7c22be1a3d17774ae321Ian Romanick    * Given the four supported fb_type values, this results in valid array
55274396056977776919aaa7c22be1a3d17774ae321Ian Romanick    * indices of 3, 4, 5, and 7.
55374396056977776919aaa7c22be1a3d17774ae321Ian Romanick    */
55438b317d508a2a3a4cc6d700ebca80c3b06c913e2Alan Hourihane   static const u_int32_t masks_table_rgb[8][4] = {
55574396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
55674396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
55774396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
558fff749e893b0adbfb57d08370cb4d2a10608bc52Ian Romanick      { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5       */
55974396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV   */
56074396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000 }, /* 8_8_8_8     */
56174396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
56274396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000 }  /* 8_8_8_8_REV */
56374396056977776919aaa7c22be1a3d17774ae321Ian Romanick   };
56474396056977776919aaa7c22be1a3d17774ae321Ian Romanick
56538b317d508a2a3a4cc6d700ebca80c3b06c913e2Alan Hourihane   static const u_int32_t masks_table_rgba[8][4] = {
56674396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
56774396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
56874396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
569fff749e893b0adbfb57d08370cb4d2a10608bc52Ian Romanick      { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5       */
57074396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV   */
57174396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF }, /* 8_8_8_8     */
57274396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
57374396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 }, /* 8_8_8_8_REV */
57474396056977776919aaa7c22be1a3d17774ae321Ian Romanick   };
57574396056977776919aaa7c22be1a3d17774ae321Ian Romanick
57638b317d508a2a3a4cc6d700ebca80c3b06c913e2Alan Hourihane   static const u_int32_t masks_table_bgr[8][4] = {
57774396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
57874396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
57974396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
58074396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5       */
581fff749e893b0adbfb57d08370cb4d2a10608bc52Ian Romanick      { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV   */
58274396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x00000000 }, /* 8_8_8_8     */
58374396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
58474396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 }, /* 8_8_8_8_REV */
58574396056977776919aaa7c22be1a3d17774ae321Ian Romanick   };
58674396056977776919aaa7c22be1a3d17774ae321Ian Romanick
58738b317d508a2a3a4cc6d700ebca80c3b06c913e2Alan Hourihane   static const u_int32_t masks_table_bgra[8][4] = {
58874396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
58974396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
59074396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
59174396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5       */
592fff749e893b0adbfb57d08370cb4d2a10608bc52Ian Romanick      { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV   */
59374396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x000000FF }, /* 8_8_8_8     */
59474396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
59574396056977776919aaa7c22be1a3d17774ae321Ian Romanick      { 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000 }, /* 8_8_8_8_REV */
59674396056977776919aaa7c22be1a3d17774ae321Ian Romanick   };
59774396056977776919aaa7c22be1a3d17774ae321Ian Romanick
59838b317d508a2a3a4cc6d700ebca80c3b06c913e2Alan Hourihane   static const u_int8_t bytes_per_pixel[8] = {
59974396056977776919aaa7c22be1a3d17774ae321Ian Romanick      0, 0, 0, 2, 2, 4, 0, 4
60074396056977776919aaa7c22be1a3d17774ae321Ian Romanick   };
60174396056977776919aaa7c22be1a3d17774ae321Ian Romanick
60238b317d508a2a3a4cc6d700ebca80c3b06c913e2Alan Hourihane   const u_int8_t  * bits;
60338b317d508a2a3a4cc6d700ebca80c3b06c913e2Alan Hourihane   const u_int32_t * masks;
60474396056977776919aaa7c22be1a3d17774ae321Ian Romanick   const int index = fb_type & 0x07;
605e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   __DRIconfig **configs, **c;
606e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   __GLcontextModes *modes;
60774396056977776919aaa7c22be1a3d17774ae321Ian Romanick   unsigned i;
60874396056977776919aaa7c22be1a3d17774ae321Ian Romanick   unsigned j;
60974396056977776919aaa7c22be1a3d17774ae321Ian Romanick   unsigned k;
610e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   unsigned num_modes;
611e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   unsigned num_accum_bits = 2;
61274396056977776919aaa7c22be1a3d17774ae321Ian Romanick
61374396056977776919aaa7c22be1a3d17774ae321Ian Romanick   if ( bytes_per_pixel[ index ] == 0 ) {
61474396056977776919aaa7c22be1a3d17774ae321Ian Romanick      fprintf( stderr, "[%s:%u] Framebuffer type 0x%04x has 0 bytes per pixel.\n",
61538b317d508a2a3a4cc6d700ebca80c3b06c913e2Alan Hourihane	       __FUNCTION__, __LINE__, fb_type );
616e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg      return NULL;
61774396056977776919aaa7c22be1a3d17774ae321Ian Romanick   }
61874396056977776919aaa7c22be1a3d17774ae321Ian Romanick
61974396056977776919aaa7c22be1a3d17774ae321Ian Romanick
62074396056977776919aaa7c22be1a3d17774ae321Ian Romanick   /* Valid types are GL_UNSIGNED_SHORT_5_6_5 and GL_UNSIGNED_INT_8_8_8_8 and
62174396056977776919aaa7c22be1a3d17774ae321Ian Romanick    * the _REV versions.
62274396056977776919aaa7c22be1a3d17774ae321Ian Romanick    *
62374396056977776919aaa7c22be1a3d17774ae321Ian Romanick    * Valid formats are GL_RGBA, GL_RGB, and GL_BGRA.
62474396056977776919aaa7c22be1a3d17774ae321Ian Romanick    */
62574396056977776919aaa7c22be1a3d17774ae321Ian Romanick
62674396056977776919aaa7c22be1a3d17774ae321Ian Romanick   switch ( fb_format ) {
62774396056977776919aaa7c22be1a3d17774ae321Ian Romanick      case GL_RGB:
62874396056977776919aaa7c22be1a3d17774ae321Ian Romanick         bits = (bytes_per_pixel[ index ] == 2)
62974396056977776919aaa7c22be1a3d17774ae321Ian Romanick	     ? bits_table[0] : bits_table[1];
63074396056977776919aaa7c22be1a3d17774ae321Ian Romanick         masks = masks_table_rgb[ index ];
63174396056977776919aaa7c22be1a3d17774ae321Ian Romanick         break;
63274396056977776919aaa7c22be1a3d17774ae321Ian Romanick
63374396056977776919aaa7c22be1a3d17774ae321Ian Romanick      case GL_RGBA:
63474396056977776919aaa7c22be1a3d17774ae321Ian Romanick         bits = (bytes_per_pixel[ index ] == 2)
63574396056977776919aaa7c22be1a3d17774ae321Ian Romanick	     ? bits_table[0] : bits_table[2];
63674396056977776919aaa7c22be1a3d17774ae321Ian Romanick         masks = masks_table_rgba[ index ];
63774396056977776919aaa7c22be1a3d17774ae321Ian Romanick         break;
63874396056977776919aaa7c22be1a3d17774ae321Ian Romanick
63974396056977776919aaa7c22be1a3d17774ae321Ian Romanick      case GL_BGR:
64074396056977776919aaa7c22be1a3d17774ae321Ian Romanick         bits = (bytes_per_pixel[ index ] == 2)
64174396056977776919aaa7c22be1a3d17774ae321Ian Romanick	     ? bits_table[0] : bits_table[1];
64274396056977776919aaa7c22be1a3d17774ae321Ian Romanick         masks = masks_table_bgr[ index ];
64374396056977776919aaa7c22be1a3d17774ae321Ian Romanick         break;
64474396056977776919aaa7c22be1a3d17774ae321Ian Romanick
64574396056977776919aaa7c22be1a3d17774ae321Ian Romanick      case GL_BGRA:
64674396056977776919aaa7c22be1a3d17774ae321Ian Romanick         bits = (bytes_per_pixel[ index ] == 2)
64774396056977776919aaa7c22be1a3d17774ae321Ian Romanick	     ? bits_table[0] : bits_table[2];
64874396056977776919aaa7c22be1a3d17774ae321Ian Romanick         masks = masks_table_bgra[ index ];
64974396056977776919aaa7c22be1a3d17774ae321Ian Romanick         break;
65074396056977776919aaa7c22be1a3d17774ae321Ian Romanick
65174396056977776919aaa7c22be1a3d17774ae321Ian Romanick      default:
65274396056977776919aaa7c22be1a3d17774ae321Ian Romanick         fprintf( stderr, "[%s:%u] Framebuffer format 0x%04x is not GL_RGB, GL_RGBA, GL_BGR, or GL_BGRA.\n",
65338b317d508a2a3a4cc6d700ebca80c3b06c913e2Alan Hourihane	       __FUNCTION__, __LINE__, fb_format );
654e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg         return NULL;
65574396056977776919aaa7c22be1a3d17774ae321Ian Romanick   }
65674396056977776919aaa7c22be1a3d17774ae321Ian Romanick
657e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   num_modes = num_depth_stencil_bits * num_db_modes * num_accum_bits;
658e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   configs = _mesa_calloc((num_modes + 1) * sizeof *configs);
659e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg   if (configs == NULL)
660e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg       return NULL;
66174396056977776919aaa7c22be1a3d17774ae321Ian Romanick
662e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    c = configs;
66374396056977776919aaa7c22be1a3d17774ae321Ian Romanick    for ( k = 0 ; k < num_depth_stencil_bits ; k++ ) {
66474396056977776919aaa7c22be1a3d17774ae321Ian Romanick	for ( i = 0 ; i < num_db_modes ; i++ ) {
665e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg	    for ( j = 0 ; j < num_accum_bits ; j++ ) {
666e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg		*c = _mesa_malloc (sizeof **c);
667e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg		modes = &(*c)->modes;
668e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg		c++;
66974396056977776919aaa7c22be1a3d17774ae321Ian Romanick
670e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg		memset(modes, 0, sizeof *modes);
67174396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->redBits   = bits[0];
67274396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->greenBits = bits[1];
67374396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->blueBits  = bits[2];
67474396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->alphaBits = bits[3];
67574396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->redMask   = masks[0];
67674396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->greenMask = masks[1];
67774396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->blueMask  = masks[2];
67874396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->alphaMask = masks[3];
67974396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->rgbBits   = modes->redBits + modes->greenBits
68074396056977776919aaa7c22be1a3d17774ae321Ian Romanick		    + modes->blueBits + modes->alphaBits;
68174396056977776919aaa7c22be1a3d17774ae321Ian Romanick
68274396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->accumRedBits   = 16 * j;
68374396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->accumGreenBits = 16 * j;
68474396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->accumBlueBits  = 16 * j;
68574396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->accumAlphaBits = (masks[3] != 0) ? 16 * j : 0;
68674396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->visualRating = (j == 0) ? GLX_NONE : GLX_SLOW_CONFIG;
68774396056977776919aaa7c22be1a3d17774ae321Ian Romanick
68874396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->stencilBits = stencil_bits[k];
68974396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->depthBits = depth_bits[k];
69074396056977776919aaa7c22be1a3d17774ae321Ian Romanick
691e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg		modes->transparentPixel = GLX_NONE;
692e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg		modes->transparentRed = GLX_DONT_CARE;
693e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg		modes->transparentGreen = GLX_DONT_CARE;
694e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg		modes->transparentBlue = GLX_DONT_CARE;
695e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg		modes->transparentAlpha = GLX_DONT_CARE;
696e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg		modes->transparentIndex = GLX_DONT_CARE;
697e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg		modes->visualType = GLX_DONT_CARE;
69874396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->renderType = GLX_RGBA_BIT;
69974396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->drawableType = GLX_WINDOW_BIT;
70074396056977776919aaa7c22be1a3d17774ae321Ian Romanick		modes->rgbMode = GL_TRUE;
70174396056977776919aaa7c22be1a3d17774ae321Ian Romanick
70274396056977776919aaa7c22be1a3d17774ae321Ian Romanick		if ( db_modes[i] == GLX_NONE ) {
70374396056977776919aaa7c22be1a3d17774ae321Ian Romanick		    modes->doubleBufferMode = GL_FALSE;
70474396056977776919aaa7c22be1a3d17774ae321Ian Romanick		}
70574396056977776919aaa7c22be1a3d17774ae321Ian Romanick		else {
70674396056977776919aaa7c22be1a3d17774ae321Ian Romanick		    modes->doubleBufferMode = GL_TRUE;
70774396056977776919aaa7c22be1a3d17774ae321Ian Romanick		    modes->swapMethod = db_modes[i];
70874396056977776919aaa7c22be1a3d17774ae321Ian Romanick		}
70974396056977776919aaa7c22be1a3d17774ae321Ian Romanick
7107f8e10f96c1970d2c81ec8d4f3a45a3b006b3be1Keith Whitwell		modes->haveAccumBuffer = ((modes->accumRedBits +
7117f8e10f96c1970d2c81ec8d4f3a45a3b006b3be1Keith Whitwell					   modes->accumGreenBits +
7127f8e10f96c1970d2c81ec8d4f3a45a3b006b3be1Keith Whitwell					   modes->accumBlueBits +
7137f8e10f96c1970d2c81ec8d4f3a45a3b006b3be1Keith Whitwell					   modes->accumAlphaBits) > 0);
7147f8e10f96c1970d2c81ec8d4f3a45a3b006b3be1Keith Whitwell		modes->haveDepthBuffer = (modes->depthBits > 0);
7157f8e10f96c1970d2c81ec8d4f3a45a3b006b3be1Keith Whitwell		modes->haveStencilBuffer = (modes->stencilBits > 0);
71674396056977776919aaa7c22be1a3d17774ae321Ian Romanick	    }
71774396056977776919aaa7c22be1a3d17774ae321Ian Romanick	}
71874396056977776919aaa7c22be1a3d17774ae321Ian Romanick    }
719e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    *c = NULL;
720e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg
721e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    return configs;
722e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg}
72374396056977776919aaa7c22be1a3d17774ae321Ian Romanick
724e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsbergconst __DRIconfig **driConcatConfigs(__DRIconfig **a, __DRIconfig **b)
725e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg{
726e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    const __DRIconfig **all;
727e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    int i, j, index;
728e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg
729e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    i = 0;
730e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    while (a[i] != NULL)
731e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg	i++;
732e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    j = 0;
733e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    while (b[j] != NULL)
734e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg	j++;
735e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg
736e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    all = _mesa_malloc((i + j + 1) * sizeof *all);
737e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    index = 0;
738e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    for (i = 0; a[i] != NULL; i++)
739e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg	all[index++] = a[i];
740e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    for (j = 0; b[j] != NULL; j++)
741e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg	all[index++] = b[j];
742e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    all[index++] = NULL;
743e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg
744e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    _mesa_free(a);
745e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    _mesa_free(b);
746e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg
747e82dd8c6e1fa2fff5b960de26961080ba5e9651dKristian Høgsberg    return all;
74874396056977776919aaa7c22be1a3d17774ae321Ian Romanick}
749