utils.c revision 447cdd536fe4539b724e8a7024659e3f4cd724d1
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" 3793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 38aaebfc88c08c79cd70f1e0d1d262a25e9ded47d1Jon Smirl#if !defined( DRI_NEW_INTERFACE_ONLY ) 395b98ada88071a752b6000756949a1951183cdd0bIan Romanick#include "xf86dri.h" /* For XF86DRIQueryVersion prototype. */ 405b98ada88071a752b6000756949a1951183cdd0bIan Romanick#endif 415b98ada88071a752b6000756949a1951183cdd0bIan Romanick 4293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#if defined(USE_X86_ASM) 43ecb1a5f7f98b9e42965318db99b6996f12b87e59Alan Hourihane#include "x86/common_x86_asm.h" 4493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#endif 4593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 46447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick#if defined(USE_PPC_ASM) 47447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick#include "ppc/common_ppc_features.h" 48447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick#endif 49447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick 5093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwellunsigned 5193a458840c77b784fb74738f734ba2c5d22ca7a7Keith WhitwelldriParseDebugString( const char * debug, 5293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell const struct dri_debug_control * control ) 5393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell{ 5493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell unsigned flag; 5593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 5693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 5793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell flag = 0; 5893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell if ( debug != NULL ) { 5993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell while( control->string != NULL ) { 60462183fe4cb6df6d90632d9e2cee881c8d26b1cbAlan Hourihane if ( !strcmp( debug, "all" ) || 61462183fe4cb6df6d90632d9e2cee881c8d26b1cbAlan Hourihane strstr( debug, control->string ) != NULL ) { 6293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell flag |= control->flag; 6393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell } 6493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 6593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell control++; 6693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell } 6793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell } 6893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 6993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell return flag; 7093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell} 7193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 7293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 7393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 74b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick/** 75b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * Create the \c GL_RENDERER string for DRI drivers. 76b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * 77b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * Almost all DRI drivers use a \c GL_RENDERER string of the form: 78b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * 79b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * "Mesa DRI <chip> <driver date> <AGP speed) <CPU information>" 80b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * 81b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * Using the supplied chip name, driver data, and AGP speed, this function 82b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * creates the string. 83b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * 84b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * \param buffer Buffer to hold the \c GL_RENDERER string. 85b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * \param hardware_name Name of the hardware. 86b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * \param driver_date Driver date. 87b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * \param agp_mode AGP mode (speed). 88b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * 89b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * \returns 90b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * The length of the string stored in \c buffer. This does \b not include 91b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick * the terminating \c NUL character. 92b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick */ 9393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwellunsigned 9493a458840c77b784fb74738f734ba2c5d22ca7a7Keith WhitwelldriGetRendererString( char * buffer, const char * hardware_name, 9593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell const char * driver_date, GLuint agp_mode ) 9693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell{ 97b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick#define MAX_INFO 4 98b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick const char * cpu[MAX_INFO]; 99b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick unsigned next = 0; 100b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick unsigned i; 10193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell unsigned offset; 10293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 10393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 10493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell offset = sprintf( buffer, "Mesa DRI %s %s", hardware_name, driver_date ); 10593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 10693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell /* Append any AGP-specific information. 10793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell */ 10893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell switch ( agp_mode ) { 10993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell case 1: 11093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell case 2: 11193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell case 4: 11293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell case 8: 11393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell offset += sprintf( & buffer[ offset ], " AGP %ux", agp_mode ); 11493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell break; 11593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 11693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell default: 11793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell break; 11893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell } 11993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 12093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell /* Append any CPU-specific information. 12193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell */ 12293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#ifdef USE_X86_ASM 12393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell if ( _mesa_x86_cpu_features ) { 124b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick cpu[next] = " x86"; 125b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick next++; 12693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell } 12793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell# ifdef USE_MMX_ASM 12893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell if ( cpu_has_mmx ) { 129b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick cpu[next] = (cpu_has_mmxext) ? "/MMX+" : "/MMX"; 130b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick next++; 13193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell } 13293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell# endif 13393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell# ifdef USE_3DNOW_ASM 13493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell if ( cpu_has_3dnow ) { 135b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick cpu[next] = (cpu_has_3dnowext) ? "/3DNow!+" : "/3DNow!"; 136b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick next++; 13793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell } 13893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell# endif 13993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell# ifdef USE_SSE_ASM 14093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell if ( cpu_has_xmm ) { 141b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick cpu[next] = (cpu_has_xmm2) ? "/SSE2" : "/SSE"; 142b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick next++; 14393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell } 14493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell# endif 14593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 14693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#elif defined(USE_SPARC_ASM) 14793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 148b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick cpu[0] = " SPARC"; 149b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick next = 1; 15093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 151447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick#elif defined(USE_PPC_ASM) 152447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick if ( _mesa_ppc_cpu_features ) { 153447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick cpu[next] = (cpu_has_64) ? " PowerPC 64" : " PowerPC"; 154447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick next++; 155447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick } 156447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick 157447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick# ifdef USE_VMX_ASM 158447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick if ( cpu_has_vmx ) { 159447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick cpu[next] = "/Altivec"; 160447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick next++; 161447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick } 162447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick# endif 163447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick 164447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick if ( ! cpu_has_fpu ) { 165447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick cpu[next] = "/No FPU"; 166447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick next++; 167447cdd536fe4539b724e8a7024659e3f4cd724d1Ian Romanick } 16893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#endif 16993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 170b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick for ( i = 0 ; i < next ; i++ ) { 171b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick const size_t len = strlen( cpu[i] ); 172b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick 173b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick strncpy( & buffer[ offset ], cpu[i], len ); 174b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick offset += len; 175b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick } 176b72ed81818e63a70c1ded2789b9e22ee4c516aaeIan Romanick 17793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell return offset; 17893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell} 17993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 18093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 18193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 18293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 18393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwellvoid driInitExtensions( GLcontext * ctx, 18493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell const char * const extensions_to_enable[], 18593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell GLboolean enable_imaging ) 18693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell{ 18793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell unsigned i; 18893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 18993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell if ( enable_imaging ) { 19093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell _mesa_enable_imaging_extensions( ctx ); 19193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell } 19293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 19393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell for ( i = 0 ; extensions_to_enable[i] != NULL ; i++ ) { 19493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell _mesa_enable_extension( ctx, extensions_to_enable[i] ); 19593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell } 19693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell} 19793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 19893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 19993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 20093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 2015b98ada88071a752b6000756949a1951183cdd0bIan Romanick#ifndef DRI_NEW_INTERFACE_ONLY 2025b98ada88071a752b6000756949a1951183cdd0bIan Romanick/** 2035b98ada88071a752b6000756949a1951183cdd0bIan Romanick * Utility function used by drivers to test the verions of other components. 2045b98ada88071a752b6000756949a1951183cdd0bIan Romanick * 2055b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \deprecated 2065b98ada88071a752b6000756949a1951183cdd0bIan Romanick * All drivers using the new interface should use \c driCheckDriDdxVersions2 2075b98ada88071a752b6000756949a1951183cdd0bIan Romanick * instead. This function is implemented using a call that is not available 2085b98ada88071a752b6000756949a1951183cdd0bIan Romanick * to drivers using the new interface. Furthermore, the information gained 2095b98ada88071a752b6000756949a1951183cdd0bIan Romanick * by this call (the DRI and DDX version information) is already provided to 2105b98ada88071a752b6000756949a1951183cdd0bIan Romanick * the driver via the new interface. 2115b98ada88071a752b6000756949a1951183cdd0bIan Romanick */ 21293a458840c77b784fb74738f734ba2c5d22ca7a7Keith WhitwellGLboolean 21393a458840c77b784fb74738f734ba2c5d22ca7a7Keith WhitwelldriCheckDriDdxDrmVersions(__DRIscreenPrivate *sPriv, 21493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell const char * driver_name, 21593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell int dri_major, int dri_minor, 21693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell int ddx_major, int ddx_minor, 21793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell int drm_major, int drm_minor) 21893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell{ 21993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell static const char format[] = "%s DRI driver expected %s version %d.%d.x " 22093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell "but got version %d.%d.%d"; 22193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell int major, minor, patch; 22293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 22393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell /* Check the DRI version */ 22493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell if (XF86DRIQueryVersion(sPriv->display, &major, &minor, &patch)) { 22593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell if (major != dri_major || minor < dri_minor) { 2265b98ada88071a752b6000756949a1951183cdd0bIan Romanick __driUtilMessage(format, driver_name, "DRI", dri_major, dri_minor, 22793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell major, minor, patch); 22893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell return GL_FALSE; 22993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell } 23093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell } 23135de80d0cb9889e2557373e8896ab4062f593803Dave Airlie 23293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell /* Check that the DDX driver version is compatible */ 23393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell if (sPriv->ddxMajor != ddx_major || sPriv->ddxMinor < ddx_minor) { 2345b98ada88071a752b6000756949a1951183cdd0bIan Romanick __driUtilMessage(format, driver_name, "DDX", ddx_major, ddx_minor, 23593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell sPriv->ddxMajor, sPriv->ddxMinor, sPriv->ddxPatch); 23693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell return GL_FALSE; 23793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell } 23835de80d0cb9889e2557373e8896ab4062f593803Dave Airlie 23993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell /* Check that the DRM driver version is compatible */ 24093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell if (sPriv->drmMajor != drm_major || sPriv->drmMinor < drm_minor) { 2415b98ada88071a752b6000756949a1951183cdd0bIan Romanick __driUtilMessage(format, driver_name, "DRM", drm_major, drm_minor, 24293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell sPriv->drmMajor, sPriv->drmMinor, sPriv->drmPatch); 24393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell return GL_FALSE; 24493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell } 24593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell 24693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell return GL_TRUE; 24793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell} 2485b98ada88071a752b6000756949a1951183cdd0bIan Romanick#endif /* DRI_NEW_INTERFACE_ONLY */ 2495b98ada88071a752b6000756949a1951183cdd0bIan Romanick 2505b98ada88071a752b6000756949a1951183cdd0bIan Romanick/** 2515b98ada88071a752b6000756949a1951183cdd0bIan Romanick * Utility function used by drivers to test the verions of other components. 2525b98ada88071a752b6000756949a1951183cdd0bIan Romanick * 2535b98ada88071a752b6000756949a1951183cdd0bIan Romanick * If one of the version requirements is not met, a message is logged using 2545b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \c __driUtilMessage. 2555b98ada88071a752b6000756949a1951183cdd0bIan Romanick * 2565b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param driver_name Name of the driver. Used in error messages. 2575b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param driActual Actual DRI version supplied __driCreateNewScreen. 2585b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param driExpected Minimum DRI version required by the driver. 2595b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param ddxActual Actual DDX version supplied __driCreateNewScreen. 2605b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param ddxExpected Minimum DDX version required by the driver. 2615b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param drmActual Actual DRM version supplied __driCreateNewScreen. 2625b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param drmExpected Minimum DRM version required by the driver. 2635b98ada88071a752b6000756949a1951183cdd0bIan Romanick * 2645b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \returns \c GL_TRUE if all version requirements are met. Otherwise, 2655b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \c GL_FALSE is returned. 2665b98ada88071a752b6000756949a1951183cdd0bIan Romanick * 2675b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \sa __driCreateNewScreen, driCheckDriDdxDrmVersions, __driUtilMessage 2685b98ada88071a752b6000756949a1951183cdd0bIan Romanick */ 2695b98ada88071a752b6000756949a1951183cdd0bIan RomanickGLboolean 2705b98ada88071a752b6000756949a1951183cdd0bIan RomanickdriCheckDriDdxDrmVersions2(const char * driver_name, 2715b98ada88071a752b6000756949a1951183cdd0bIan Romanick const __DRIversion * driActual, 2725b98ada88071a752b6000756949a1951183cdd0bIan Romanick const __DRIversion * driExpected, 2735b98ada88071a752b6000756949a1951183cdd0bIan Romanick const __DRIversion * ddxActual, 2745b98ada88071a752b6000756949a1951183cdd0bIan Romanick const __DRIversion * ddxExpected, 2755b98ada88071a752b6000756949a1951183cdd0bIan Romanick const __DRIversion * drmActual, 2765b98ada88071a752b6000756949a1951183cdd0bIan Romanick const __DRIversion * drmExpected) 2775b98ada88071a752b6000756949a1951183cdd0bIan Romanick{ 2785b98ada88071a752b6000756949a1951183cdd0bIan Romanick static const char format[] = "%s DRI driver expected %s version %d.%d.x " 2795b98ada88071a752b6000756949a1951183cdd0bIan Romanick "but got version %d.%d.%d"; 2805b98ada88071a752b6000756949a1951183cdd0bIan Romanick 2815b98ada88071a752b6000756949a1951183cdd0bIan Romanick 2825b98ada88071a752b6000756949a1951183cdd0bIan Romanick /* Check the DRI version */ 2835b98ada88071a752b6000756949a1951183cdd0bIan Romanick if ( (driActual->major != driExpected->major) 2845b98ada88071a752b6000756949a1951183cdd0bIan Romanick || (driActual->minor < driExpected->minor) ) { 2855b98ada88071a752b6000756949a1951183cdd0bIan Romanick __driUtilMessage(format, driver_name, "DRI", 2865b98ada88071a752b6000756949a1951183cdd0bIan Romanick driExpected->major, driExpected->minor, 2875b98ada88071a752b6000756949a1951183cdd0bIan Romanick driActual->major, driActual->minor, driActual->patch); 2885b98ada88071a752b6000756949a1951183cdd0bIan Romanick return GL_FALSE; 2895b98ada88071a752b6000756949a1951183cdd0bIan Romanick } 2905b98ada88071a752b6000756949a1951183cdd0bIan Romanick 2915b98ada88071a752b6000756949a1951183cdd0bIan Romanick /* Check that the DDX driver version is compatible */ 2925b98ada88071a752b6000756949a1951183cdd0bIan Romanick if ( (ddxActual->major != ddxExpected->major) 2935b98ada88071a752b6000756949a1951183cdd0bIan Romanick || (ddxActual->minor < ddxExpected->minor) ) { 2945b98ada88071a752b6000756949a1951183cdd0bIan Romanick __driUtilMessage(format, driver_name, "DDX", 2955b98ada88071a752b6000756949a1951183cdd0bIan Romanick ddxExpected->major, ddxExpected->minor, 2965b98ada88071a752b6000756949a1951183cdd0bIan Romanick ddxActual->major, ddxActual->minor, ddxActual->patch); 2975b98ada88071a752b6000756949a1951183cdd0bIan Romanick return GL_FALSE; 2985b98ada88071a752b6000756949a1951183cdd0bIan Romanick } 2995b98ada88071a752b6000756949a1951183cdd0bIan Romanick 3005b98ada88071a752b6000756949a1951183cdd0bIan Romanick /* Check that the DRM driver version is compatible */ 3015b98ada88071a752b6000756949a1951183cdd0bIan Romanick if ( (drmActual->major != drmExpected->major) 3025b98ada88071a752b6000756949a1951183cdd0bIan Romanick || (drmActual->minor < drmExpected->minor) ) { 3035b98ada88071a752b6000756949a1951183cdd0bIan Romanick __driUtilMessage(format, driver_name, "DRM", 3045b98ada88071a752b6000756949a1951183cdd0bIan Romanick drmExpected->major, drmExpected->minor, 3055b98ada88071a752b6000756949a1951183cdd0bIan Romanick drmActual->major, drmActual->minor, drmActual->patch); 3065b98ada88071a752b6000756949a1951183cdd0bIan Romanick return GL_FALSE; 3075b98ada88071a752b6000756949a1951183cdd0bIan Romanick } 3085b98ada88071a752b6000756949a1951183cdd0bIan Romanick 3095b98ada88071a752b6000756949a1951183cdd0bIan Romanick return GL_TRUE; 3105b98ada88071a752b6000756949a1951183cdd0bIan Romanick} 3115b98ada88071a752b6000756949a1951183cdd0bIan Romanick 3127ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell 3137ed58285abede813fbf5fa0a2e29982043f1bbbeKeith WhitwellGLboolean driClipRectToFramebuffer( const GLframebuffer *buffer, 3147ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell GLint *x, GLint *y, 3157ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell GLsizei *width, GLsizei *height ) 3167ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell{ 3177ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell /* left clipping */ 3187ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell if (*x < buffer->_Xmin) { 3197ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell *width -= (buffer->_Xmin - *x); 3207ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell *x = buffer->_Xmin; 3217ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell } 3227ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell 3237ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell /* right clipping */ 3247ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell if (*x + *width > buffer->_Xmax) 3257ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell *width -= (*x + *width - buffer->_Xmax - 1); 3267ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell 3277ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell if (*width <= 0) 3287ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell return GL_FALSE; 3297ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell 3307ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell /* bottom clipping */ 3317ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell if (*y < buffer->_Ymin) { 3327ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell *height -= (buffer->_Ymin - *y); 3337ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell *y = buffer->_Ymin; 3347ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell } 3357ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell 3367ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell /* top clipping */ 3377ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell if (*y + *height > buffer->_Ymax) 3387ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell *height -= (*y + *height - buffer->_Ymax - 1); 3397ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell 3407ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell if (*height <= 0) 3417ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell return GL_FALSE; 3427ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell 3437ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell return GL_TRUE; 3447ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell} 34574396056977776919aaa7c22be1a3d17774ae321Ian Romanick 34674396056977776919aaa7c22be1a3d17774ae321Ian Romanick 34774396056977776919aaa7c22be1a3d17774ae321Ian Romanick 34874396056977776919aaa7c22be1a3d17774ae321Ian Romanick/** 34974396056977776919aaa7c22be1a3d17774ae321Ian Romanick * Creates a set of \c __GLcontextModes that a driver will expose. 35074396056977776919aaa7c22be1a3d17774ae321Ian Romanick * 35174396056977776919aaa7c22be1a3d17774ae321Ian Romanick * A set of \c __GLcontextModes will be created based on the supplied 35274396056977776919aaa7c22be1a3d17774ae321Ian Romanick * parameters. The number of modes processed will be 2 * 35374396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c num_depth_stencil_bits * \c num_db_modes. 35474396056977776919aaa7c22be1a3d17774ae321Ian Romanick * 35574396056977776919aaa7c22be1a3d17774ae321Ian Romanick * For the most part, data is just copied from \c depth_bits, \c stencil_bits, 35674396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c db_modes, and \c visType into each \c __GLcontextModes element. 35774396056977776919aaa7c22be1a3d17774ae321Ian Romanick * However, the meanings of \c fb_format and \c fb_type require further 35874396056977776919aaa7c22be1a3d17774ae321Ian Romanick * explanation. The \c fb_format specifies which color components are in 35974396056977776919aaa7c22be1a3d17774ae321Ian Romanick * each pixel and what the default order is. For example, \c GL_RGB specifies 36074396056977776919aaa7c22be1a3d17774ae321Ian Romanick * that red, green, blue are available and red is in the "most significant" 36174396056977776919aaa7c22be1a3d17774ae321Ian Romanick * position and blue is in the "least significant". The \c fb_type specifies 36274396056977776919aaa7c22be1a3d17774ae321Ian Romanick * the bit sizes of each component and the actual ordering. For example, if 36374396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GL_UNSIGNED_SHORT_5_6_5_REV is specified with \c GL_RGB, bits [15:11] 36474396056977776919aaa7c22be1a3d17774ae321Ian Romanick * are the blue value, bits [10:5] are the green value, and bits [4:0] are 36574396056977776919aaa7c22be1a3d17774ae321Ian Romanick * the red value. 36674396056977776919aaa7c22be1a3d17774ae321Ian Romanick * 36774396056977776919aaa7c22be1a3d17774ae321Ian Romanick * One sublte issue is the combination of \c GL_RGB or \c GL_BGR and either 36874396056977776919aaa7c22be1a3d17774ae321Ian Romanick * of the \c GL_UNSIGNED_INT_8_8_8_8 modes. The resulting mask values in the 36974396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c __GLcontextModes structure is \b identical to the \c GL_RGBA or 37074396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GL_BGRA case, except the \c alphaMask is zero. This means that, as 37174396056977776919aaa7c22be1a3d17774ae321Ian Romanick * far as this routine is concerned, \c GL_RGB with \c GL_UNSIGNED_INT_8_8_8_8 37274396056977776919aaa7c22be1a3d17774ae321Ian Romanick * still uses 32-bits. 37374396056977776919aaa7c22be1a3d17774ae321Ian Romanick * 37474396056977776919aaa7c22be1a3d17774ae321Ian Romanick * If in doubt, look at the tables used in the function. 37574396056977776919aaa7c22be1a3d17774ae321Ian Romanick * 37674396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param ptr_to_modes Pointer to a pointer to a linked list of 37774396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c __GLcontextModes. Upon completion, a pointer to 37874396056977776919aaa7c22be1a3d17774ae321Ian Romanick * the next element to be process will be stored here. 37974396056977776919aaa7c22be1a3d17774ae321Ian Romanick * If the function fails and returns \c GL_FALSE, this 38074396056977776919aaa7c22be1a3d17774ae321Ian Romanick * value will be unmodified, but some elements in the 38174396056977776919aaa7c22be1a3d17774ae321Ian Romanick * linked list may be modified. 38274396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param fb_format Format of the framebuffer. Currently only \c GL_RGB, 38374396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GL_RGBA, \c GL_BGR, and \c GL_BGRA are supported. 38474396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param fb_type Type of the pixels in the framebuffer. Currently only 38574396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GL_UNSIGNED_SHORT_5_6_5, 38674396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GL_UNSIGNED_SHORT_5_6_5_REV, 38774396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GL_UNSIGNED_INT_8_8_8_8, and 38874396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GL_UNSIGNED_INT_8_8_8_8_REV are supported. 38974396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param depth_bits Array of depth buffer sizes to be exposed. 39074396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param stencil_bits Array of stencil buffer sizes to be exposed. 39174396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param num_depth_stencil_bits Number of entries in both \c depth_bits and 39274396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c stencil_bits. 39374396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param db_modes Array of buffer swap modes. If an element has a 39474396056977776919aaa7c22be1a3d17774ae321Ian Romanick * value of \c GLX_NONE, then it represents a 39574396056977776919aaa7c22be1a3d17774ae321Ian Romanick * single-buffered mode. Other valid values are 39674396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GLX_SWAP_EXCHANGE_OML, \c GLX_SWAP_COPY_OML, and 39774396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GLX_SWAP_UNDEFINED_OML. See the 39874396056977776919aaa7c22be1a3d17774ae321Ian Romanick * GLX_OML_swap_method extension spec for more details. 39974396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param num_db_modes Number of entries in \c db_modes. 40074396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \param visType GLX visual type. Usually either \c GLX_TRUE_COLOR or 40174396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GLX_DIRECT_COLOR. 40274396056977776919aaa7c22be1a3d17774ae321Ian Romanick * 40374396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \returns 40474396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GL_TRUE on success or \c GL_FALSE on failure. Currently the only 40574396056977776919aaa7c22be1a3d17774ae321Ian Romanick * cause of failure is a bad parameter (i.e., unsupported \c fb_format or 40674396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c fb_type). 40774396056977776919aaa7c22be1a3d17774ae321Ian Romanick * 40874396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \todo 40974396056977776919aaa7c22be1a3d17774ae321Ian Romanick * There is currently no way to support packed RGB modes (i.e., modes with 41074396056977776919aaa7c22be1a3d17774ae321Ian Romanick * exactly 3 bytes per pixel) or floating-point modes. This could probably 41174396056977776919aaa7c22be1a3d17774ae321Ian Romanick * be done by creating some new, private enums with clever names likes 41274396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GL_UNSIGNED_3BYTE_8_8_8, \c GL_4FLOAT_32_32_32_32, 41374396056977776919aaa7c22be1a3d17774ae321Ian Romanick * \c GL_4HALF_16_16_16_16, etc. We can cross that bridge when we come to it. 41474396056977776919aaa7c22be1a3d17774ae321Ian Romanick */ 41574396056977776919aaa7c22be1a3d17774ae321Ian RomanickGLboolean 41674396056977776919aaa7c22be1a3d17774ae321Ian RomanickdriFillInModes( __GLcontextModes ** ptr_to_modes, 41774396056977776919aaa7c22be1a3d17774ae321Ian Romanick GLenum fb_format, GLenum fb_type, 41874396056977776919aaa7c22be1a3d17774ae321Ian Romanick const uint8_t * depth_bits, const uint8_t * stencil_bits, 41974396056977776919aaa7c22be1a3d17774ae321Ian Romanick unsigned num_depth_stencil_bits, 42074396056977776919aaa7c22be1a3d17774ae321Ian Romanick const GLenum * db_modes, unsigned num_db_modes, 42174396056977776919aaa7c22be1a3d17774ae321Ian Romanick int visType ) 42274396056977776919aaa7c22be1a3d17774ae321Ian Romanick{ 42374396056977776919aaa7c22be1a3d17774ae321Ian Romanick static const uint8_t bits_table[3][4] = { 42474396056977776919aaa7c22be1a3d17774ae321Ian Romanick /* R G B A */ 42574396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 5, 6, 5, 0 }, /* Any GL_UNSIGNED_SHORT_5_6_5 */ 42674396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 8, 8, 8, 0 }, /* Any RGB with any GL_UNSIGNED_INT_8_8_8_8 */ 42774396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 8, 8, 8, 8 } /* Any RGBA with any GL_UNSIGNED_INT_8_8_8_8 */ 42874396056977776919aaa7c22be1a3d17774ae321Ian Romanick }; 42974396056977776919aaa7c22be1a3d17774ae321Ian Romanick 43074396056977776919aaa7c22be1a3d17774ae321Ian Romanick /* The following arrays are all indexed by the fb_type masked with 0x07. 43174396056977776919aaa7c22be1a3d17774ae321Ian Romanick * Given the four supported fb_type values, this results in valid array 43274396056977776919aaa7c22be1a3d17774ae321Ian Romanick * indices of 3, 4, 5, and 7. 43374396056977776919aaa7c22be1a3d17774ae321Ian Romanick */ 43474396056977776919aaa7c22be1a3d17774ae321Ian Romanick static const uint32_t masks_table_rgb[8][4] = { 43574396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, 43674396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, 43774396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, 438fff749e893b0adbfb57d08370cb4d2a10608bc52Ian Romanick { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5 */ 43974396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV */ 44074396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000 }, /* 8_8_8_8 */ 44174396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, 44274396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000 } /* 8_8_8_8_REV */ 44374396056977776919aaa7c22be1a3d17774ae321Ian Romanick }; 44474396056977776919aaa7c22be1a3d17774ae321Ian Romanick 44574396056977776919aaa7c22be1a3d17774ae321Ian Romanick static const uint32_t masks_table_rgba[8][4] = { 44674396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, 44774396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, 44874396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, 449fff749e893b0adbfb57d08370cb4d2a10608bc52Ian Romanick { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5 */ 45074396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5_REV */ 45174396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF }, /* 8_8_8_8 */ 45274396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, 45374396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 }, /* 8_8_8_8_REV */ 45474396056977776919aaa7c22be1a3d17774ae321Ian Romanick }; 45574396056977776919aaa7c22be1a3d17774ae321Ian Romanick 45674396056977776919aaa7c22be1a3d17774ae321Ian Romanick static const uint32_t masks_table_bgr[8][4] = { 45774396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, 45874396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, 45974396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, 46074396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5 */ 461fff749e893b0adbfb57d08370cb4d2a10608bc52Ian Romanick { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV */ 46274396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x00000000 }, /* 8_8_8_8 */ 46374396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, 46474396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 }, /* 8_8_8_8_REV */ 46574396056977776919aaa7c22be1a3d17774ae321Ian Romanick }; 46674396056977776919aaa7c22be1a3d17774ae321Ian Romanick 46774396056977776919aaa7c22be1a3d17774ae321Ian Romanick static const uint32_t masks_table_bgra[8][4] = { 46874396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, 46974396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, 47074396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, 47174396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0x0000001F, 0x000007E0, 0x0000F800, 0x00000000 }, /* 5_6_5 */ 472fff749e893b0adbfb57d08370cb4d2a10608bc52Ian Romanick { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 }, /* 5_6_5_REV */ 47374396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0x0000FF00, 0x00FF0000, 0xFF000000, 0x000000FF }, /* 8_8_8_8 */ 47474396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, 47574396056977776919aaa7c22be1a3d17774ae321Ian Romanick { 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000 }, /* 8_8_8_8_REV */ 47674396056977776919aaa7c22be1a3d17774ae321Ian Romanick }; 47774396056977776919aaa7c22be1a3d17774ae321Ian Romanick 47874396056977776919aaa7c22be1a3d17774ae321Ian Romanick static const uint8_t bytes_per_pixel[8] = { 47974396056977776919aaa7c22be1a3d17774ae321Ian Romanick 0, 0, 0, 2, 2, 4, 0, 4 48074396056977776919aaa7c22be1a3d17774ae321Ian Romanick }; 48174396056977776919aaa7c22be1a3d17774ae321Ian Romanick 48274396056977776919aaa7c22be1a3d17774ae321Ian Romanick const uint8_t * bits; 48374396056977776919aaa7c22be1a3d17774ae321Ian Romanick const uint32_t * masks; 48474396056977776919aaa7c22be1a3d17774ae321Ian Romanick const int index = fb_type & 0x07; 48574396056977776919aaa7c22be1a3d17774ae321Ian Romanick __GLcontextModes * modes = *ptr_to_modes; 48674396056977776919aaa7c22be1a3d17774ae321Ian Romanick unsigned i; 48774396056977776919aaa7c22be1a3d17774ae321Ian Romanick unsigned j; 48874396056977776919aaa7c22be1a3d17774ae321Ian Romanick unsigned k; 48974396056977776919aaa7c22be1a3d17774ae321Ian Romanick 49074396056977776919aaa7c22be1a3d17774ae321Ian Romanick 49174396056977776919aaa7c22be1a3d17774ae321Ian Romanick if ( bytes_per_pixel[ index ] == 0 ) { 49274396056977776919aaa7c22be1a3d17774ae321Ian Romanick fprintf( stderr, "[%s:%u] Framebuffer type 0x%04x has 0 bytes per pixel.\n", 49374396056977776919aaa7c22be1a3d17774ae321Ian Romanick __func__, __LINE__, fb_type ); 49474396056977776919aaa7c22be1a3d17774ae321Ian Romanick return GL_FALSE; 49574396056977776919aaa7c22be1a3d17774ae321Ian Romanick } 49674396056977776919aaa7c22be1a3d17774ae321Ian Romanick 49774396056977776919aaa7c22be1a3d17774ae321Ian Romanick 49874396056977776919aaa7c22be1a3d17774ae321Ian Romanick /* Valid types are GL_UNSIGNED_SHORT_5_6_5 and GL_UNSIGNED_INT_8_8_8_8 and 49974396056977776919aaa7c22be1a3d17774ae321Ian Romanick * the _REV versions. 50074396056977776919aaa7c22be1a3d17774ae321Ian Romanick * 50174396056977776919aaa7c22be1a3d17774ae321Ian Romanick * Valid formats are GL_RGBA, GL_RGB, and GL_BGRA. 50274396056977776919aaa7c22be1a3d17774ae321Ian Romanick */ 50374396056977776919aaa7c22be1a3d17774ae321Ian Romanick 50474396056977776919aaa7c22be1a3d17774ae321Ian Romanick switch ( fb_format ) { 50574396056977776919aaa7c22be1a3d17774ae321Ian Romanick case GL_RGB: 50674396056977776919aaa7c22be1a3d17774ae321Ian Romanick bits = (bytes_per_pixel[ index ] == 2) 50774396056977776919aaa7c22be1a3d17774ae321Ian Romanick ? bits_table[0] : bits_table[1]; 50874396056977776919aaa7c22be1a3d17774ae321Ian Romanick masks = masks_table_rgb[ index ]; 50974396056977776919aaa7c22be1a3d17774ae321Ian Romanick break; 51074396056977776919aaa7c22be1a3d17774ae321Ian Romanick 51174396056977776919aaa7c22be1a3d17774ae321Ian Romanick case GL_RGBA: 51274396056977776919aaa7c22be1a3d17774ae321Ian Romanick bits = (bytes_per_pixel[ index ] == 2) 51374396056977776919aaa7c22be1a3d17774ae321Ian Romanick ? bits_table[0] : bits_table[2]; 51474396056977776919aaa7c22be1a3d17774ae321Ian Romanick masks = masks_table_rgba[ index ]; 51574396056977776919aaa7c22be1a3d17774ae321Ian Romanick break; 51674396056977776919aaa7c22be1a3d17774ae321Ian Romanick 51774396056977776919aaa7c22be1a3d17774ae321Ian Romanick case GL_BGR: 51874396056977776919aaa7c22be1a3d17774ae321Ian Romanick bits = (bytes_per_pixel[ index ] == 2) 51974396056977776919aaa7c22be1a3d17774ae321Ian Romanick ? bits_table[0] : bits_table[1]; 52074396056977776919aaa7c22be1a3d17774ae321Ian Romanick masks = masks_table_bgr[ index ]; 52174396056977776919aaa7c22be1a3d17774ae321Ian Romanick break; 52274396056977776919aaa7c22be1a3d17774ae321Ian Romanick 52374396056977776919aaa7c22be1a3d17774ae321Ian Romanick case GL_BGRA: 52474396056977776919aaa7c22be1a3d17774ae321Ian Romanick bits = (bytes_per_pixel[ index ] == 2) 52574396056977776919aaa7c22be1a3d17774ae321Ian Romanick ? bits_table[0] : bits_table[2]; 52674396056977776919aaa7c22be1a3d17774ae321Ian Romanick masks = masks_table_bgra[ index ]; 52774396056977776919aaa7c22be1a3d17774ae321Ian Romanick break; 52874396056977776919aaa7c22be1a3d17774ae321Ian Romanick 52974396056977776919aaa7c22be1a3d17774ae321Ian Romanick default: 53074396056977776919aaa7c22be1a3d17774ae321Ian Romanick fprintf( stderr, "[%s:%u] Framebuffer format 0x%04x is not GL_RGB, GL_RGBA, GL_BGR, or GL_BGRA.\n", 53174396056977776919aaa7c22be1a3d17774ae321Ian Romanick __func__, __LINE__, fb_format ); 53274396056977776919aaa7c22be1a3d17774ae321Ian Romanick return GL_FALSE; 53374396056977776919aaa7c22be1a3d17774ae321Ian Romanick } 53474396056977776919aaa7c22be1a3d17774ae321Ian Romanick 53574396056977776919aaa7c22be1a3d17774ae321Ian Romanick 53674396056977776919aaa7c22be1a3d17774ae321Ian Romanick for ( k = 0 ; k < num_depth_stencil_bits ; k++ ) { 53774396056977776919aaa7c22be1a3d17774ae321Ian Romanick for ( i = 0 ; i < num_db_modes ; i++ ) { 53874396056977776919aaa7c22be1a3d17774ae321Ian Romanick for ( j = 0 ; j < 2 ; j++ ) { 53974396056977776919aaa7c22be1a3d17774ae321Ian Romanick 54074396056977776919aaa7c22be1a3d17774ae321Ian Romanick modes->redBits = bits[0]; 54174396056977776919aaa7c22be1a3d17774ae321Ian Romanick modes->greenBits = bits[1]; 54274396056977776919aaa7c22be1a3d17774ae321Ian Romanick modes->blueBits = bits[2]; 54374396056977776919aaa7c22be1a3d17774ae321Ian Romanick modes->alphaBits = bits[3]; 54474396056977776919aaa7c22be1a3d17774ae321Ian Romanick modes->redMask = masks[0]; 54574396056977776919aaa7c22be1a3d17774ae321Ian Romanick modes->greenMask = masks[1]; 54674396056977776919aaa7c22be1a3d17774ae321Ian Romanick modes->blueMask = masks[2]; 54774396056977776919aaa7c22be1a3d17774ae321Ian Romanick modes->alphaMask = masks[3]; 54874396056977776919aaa7c22be1a3d17774ae321Ian Romanick modes->rgbBits = modes->redBits + modes->greenBits 54974396056977776919aaa7c22be1a3d17774ae321Ian Romanick + modes->blueBits + modes->alphaBits; 55074396056977776919aaa7c22be1a3d17774ae321Ian Romanick 55174396056977776919aaa7c22be1a3d17774ae321Ian Romanick modes->accumRedBits = 16 * j; 55274396056977776919aaa7c22be1a3d17774ae321Ian Romanick modes->accumGreenBits = 16 * j; 55374396056977776919aaa7c22be1a3d17774ae321Ian Romanick modes->accumBlueBits = 16 * j; 55474396056977776919aaa7c22be1a3d17774ae321Ian Romanick modes->accumAlphaBits = (masks[3] != 0) ? 16 * j : 0; 55574396056977776919aaa7c22be1a3d17774ae321Ian Romanick modes->visualRating = (j == 0) ? GLX_NONE : GLX_SLOW_CONFIG; 55674396056977776919aaa7c22be1a3d17774ae321Ian Romanick 55774396056977776919aaa7c22be1a3d17774ae321Ian Romanick modes->stencilBits = stencil_bits[k]; 55874396056977776919aaa7c22be1a3d17774ae321Ian Romanick modes->depthBits = depth_bits[k]; 55974396056977776919aaa7c22be1a3d17774ae321Ian Romanick 56074396056977776919aaa7c22be1a3d17774ae321Ian Romanick modes->visualType = visType; 56174396056977776919aaa7c22be1a3d17774ae321Ian Romanick modes->renderType = GLX_RGBA_BIT; 56274396056977776919aaa7c22be1a3d17774ae321Ian Romanick modes->drawableType = GLX_WINDOW_BIT; 56374396056977776919aaa7c22be1a3d17774ae321Ian Romanick modes->rgbMode = GL_TRUE; 56474396056977776919aaa7c22be1a3d17774ae321Ian Romanick 56574396056977776919aaa7c22be1a3d17774ae321Ian Romanick if ( db_modes[i] == GLX_NONE ) { 56674396056977776919aaa7c22be1a3d17774ae321Ian Romanick modes->doubleBufferMode = GL_FALSE; 56774396056977776919aaa7c22be1a3d17774ae321Ian Romanick } 56874396056977776919aaa7c22be1a3d17774ae321Ian Romanick else { 56974396056977776919aaa7c22be1a3d17774ae321Ian Romanick modes->doubleBufferMode = GL_TRUE; 57074396056977776919aaa7c22be1a3d17774ae321Ian Romanick modes->swapMethod = db_modes[i]; 57174396056977776919aaa7c22be1a3d17774ae321Ian Romanick } 57274396056977776919aaa7c22be1a3d17774ae321Ian Romanick 57374396056977776919aaa7c22be1a3d17774ae321Ian Romanick modes = modes->next; 57474396056977776919aaa7c22be1a3d17774ae321Ian Romanick } 57574396056977776919aaa7c22be1a3d17774ae321Ian Romanick } 57674396056977776919aaa7c22be1a3d17774ae321Ian Romanick } 57774396056977776919aaa7c22be1a3d17774ae321Ian Romanick 57874396056977776919aaa7c22be1a3d17774ae321Ian Romanick *ptr_to_modes = modes; 57974396056977776919aaa7c22be1a3d17774ae321Ian Romanick return GL_TRUE; 58074396056977776919aaa7c22be1a3d17774ae321Ian Romanick} 581