utils.c revision 5b98ada88071a752b6000756949a1951183cdd0b
193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell/*
293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * (c) Copyright IBM Corporation 2002
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.
2393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell *
2493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell * Authors:
2593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell *    Ian Romanick <idr@us.ibm.com>
2693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell */
2793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell/* $XFree86:$ */
2893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
2993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#include <string.h>
3093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#include <stdlib.h>
3193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#include "mtypes.h"
3293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#include "extensions.h"
3393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#include "utils.h"
3493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
355b98ada88071a752b6000756949a1951183cdd0bIan Romanick#if !defined( DRI_NEW_INTERFACE_ONLY ) && !defined( _SOLO )
365b98ada88071a752b6000756949a1951183cdd0bIan Romanick#include "xf86dri.h"        /* For XF86DRIQueryVersion prototype. */
375b98ada88071a752b6000756949a1951183cdd0bIan Romanick#endif
385b98ada88071a752b6000756949a1951183cdd0bIan Romanick
3993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#if defined(USE_X86_ASM)
40ecb1a5f7f98b9e42965318db99b6996f12b87e59Alan Hourihane#include "x86/common_x86_asm.h"
4193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#endif
4293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
4393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwellunsigned
4493a458840c77b784fb74738f734ba2c5d22ca7a7Keith WhitwelldriParseDebugString( const char * debug,
4593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell		     const struct dri_debug_control * control  )
4693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell{
4793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   unsigned   flag;
4893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
4993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
5093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   flag = 0;
5193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   if ( debug != NULL ) {
5293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      while( control->string != NULL ) {
53462183fe4cb6df6d90632d9e2cee881c8d26b1cbAlan Hourihane	 if ( !strcmp( debug, "all" ) ||
54462183fe4cb6df6d90632d9e2cee881c8d26b1cbAlan Hourihane	      strstr( debug, control->string ) != NULL ) {
5593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell	    flag |= control->flag;
5693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell	 }
5793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
5893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell	 control++;
5993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      }
6093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
6193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
6293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   return flag;
6393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell}
6493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
6593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
6693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
6793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
6893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwellunsigned
6993a458840c77b784fb74738f734ba2c5d22ca7a7Keith WhitwelldriGetRendererString( char * buffer, const char * hardware_name,
7093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell		      const char * driver_date, GLuint agp_mode )
7193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell{
7293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#ifdef USE_X86_ASM
7393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   char * x86_str = "";
7493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   char * mmx_str = "";
7593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   char * tdnow_str = "";
7693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   char * sse_str = "";
7793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#endif
7893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   unsigned   offset;
7993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
8093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
8193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   offset = sprintf( buffer, "Mesa DRI %s %s", hardware_name, driver_date );
8293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
8393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   /* Append any AGP-specific information.
8493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell    */
8593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   switch ( agp_mode ) {
8693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   case 1:
8793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   case 2:
8893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   case 4:
8993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   case 8:
9093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      offset += sprintf( & buffer[ offset ], " AGP %ux", agp_mode );
9193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      break;
9293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
9393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   default:
9493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      break;
9593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
9693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
9793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   /* Append any CPU-specific information.
9893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell    */
9993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#ifdef USE_X86_ASM
10093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   if ( _mesa_x86_cpu_features ) {
10193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      x86_str = " x86";
10293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
10393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell# ifdef USE_MMX_ASM
10493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   if ( cpu_has_mmx ) {
10593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      mmx_str = (cpu_has_mmxext) ? "/MMX+" : "/MMX";
10693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
10793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell# endif
10893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell# ifdef USE_3DNOW_ASM
10993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   if ( cpu_has_3dnow ) {
11093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      tdnow_str = (cpu_has_3dnowext) ? "/3DNow!+" : "/3DNow!";
11193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
11293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell# endif
11393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell# ifdef USE_SSE_ASM
11493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   if ( cpu_has_xmm ) {
11593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      sse_str = (cpu_has_xmm2) ? "/SSE2" : "/SSE";
11693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
11793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell# endif
11893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
11993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   offset += sprintf( & buffer[ offset ], "%s%s%s%s",
12093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell		      x86_str, mmx_str, tdnow_str, sse_str );
12193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
12293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#elif defined(USE_SPARC_ASM)
12393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
12493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   offset += sprintf( & buffer[ offset ], " Sparc" );
12593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
12693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#endif
12793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
12893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   return offset;
12993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell}
13093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
13193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
13293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
13393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
13493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwellvoid driInitExtensions( GLcontext * ctx,
13593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell			const char * const extensions_to_enable[],
13693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell			GLboolean  enable_imaging )
13793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell{
13893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   unsigned   i;
13993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
14093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   if ( enable_imaging ) {
14193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      _mesa_enable_imaging_extensions( ctx );
14293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
14393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
14493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   for ( i = 0 ; extensions_to_enable[i] != NULL ; i++ ) {
14593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      _mesa_enable_extension( ctx, extensions_to_enable[i] );
14693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
14793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell}
14893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
14993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
15093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
15193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
1525b98ada88071a752b6000756949a1951183cdd0bIan Romanick#ifndef DRI_NEW_INTERFACE_ONLY
1535b98ada88071a752b6000756949a1951183cdd0bIan Romanick/**
1545b98ada88071a752b6000756949a1951183cdd0bIan Romanick * Utility function used by drivers to test the verions of other components.
1555b98ada88071a752b6000756949a1951183cdd0bIan Romanick *
1565b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \deprecated
1575b98ada88071a752b6000756949a1951183cdd0bIan Romanick * All drivers using the new interface should use \c driCheckDriDdxVersions2
1585b98ada88071a752b6000756949a1951183cdd0bIan Romanick * instead.  This function is implemented using a call that is not available
1595b98ada88071a752b6000756949a1951183cdd0bIan Romanick * to drivers using the new interface.  Furthermore, the information gained
1605b98ada88071a752b6000756949a1951183cdd0bIan Romanick * by this call (the DRI and DDX version information) is already provided to
1615b98ada88071a752b6000756949a1951183cdd0bIan Romanick * the driver via the new interface.
1625b98ada88071a752b6000756949a1951183cdd0bIan Romanick */
16393a458840c77b784fb74738f734ba2c5d22ca7a7Keith WhitwellGLboolean
16493a458840c77b784fb74738f734ba2c5d22ca7a7Keith WhitwelldriCheckDriDdxDrmVersions(__DRIscreenPrivate *sPriv,
16593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell			  const char * driver_name,
16693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell			  int dri_major, int dri_minor,
16793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell			  int ddx_major, int ddx_minor,
16893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell			  int drm_major, int drm_minor)
16993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell{
17093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   static const char format[] = "%s DRI driver expected %s version %d.%d.x "
17193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell       "but got version %d.%d.%d";
17293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   int major, minor, patch;
17393a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
17493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell#ifndef _SOLO
17593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   /* Check the DRI version */
17693a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   if (XF86DRIQueryVersion(sPriv->display, &major, &minor, &patch)) {
17793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      if (major != dri_major || minor < dri_minor) {
1785b98ada88071a752b6000756949a1951183cdd0bIan Romanick	 __driUtilMessage(format, driver_name, "DRI", dri_major, dri_minor,
17993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell			  major, minor, patch);
18093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell	 return GL_FALSE;
18193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      }
18293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
18335de80d0cb9889e2557373e8896ab4062f593803Dave Airlie
18493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   /* Check that the DDX driver version is compatible */
18593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   if (sPriv->ddxMajor != ddx_major || sPriv->ddxMinor < ddx_minor) {
1865b98ada88071a752b6000756949a1951183cdd0bIan Romanick      __driUtilMessage(format, driver_name, "DDX", ddx_major, ddx_minor,
18793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell		       sPriv->ddxMajor, sPriv->ddxMinor, sPriv->ddxPatch);
18893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      return GL_FALSE;
18993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
19035de80d0cb9889e2557373e8896ab4062f593803Dave Airlie#else
19135de80d0cb9889e2557373e8896ab4062f593803Dave Airlie   (void)major;(void)minor;(void)patch;
19235de80d0cb9889e2557373e8896ab4062f593803Dave Airlie#endif
19335de80d0cb9889e2557373e8896ab4062f593803Dave Airlie
19493a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   /* Check that the DRM driver version is compatible */
19593a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   if (sPriv->drmMajor != drm_major || sPriv->drmMinor < drm_minor) {
1965b98ada88071a752b6000756949a1951183cdd0bIan Romanick      __driUtilMessage(format, driver_name, "DRM", drm_major, drm_minor,
19793a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell		       sPriv->drmMajor, sPriv->drmMinor, sPriv->drmPatch);
19893a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell      return GL_FALSE;
19993a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   }
20093a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell
20193a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell   return GL_TRUE;
20293a458840c77b784fb74738f734ba2c5d22ca7a7Keith Whitwell}
2035b98ada88071a752b6000756949a1951183cdd0bIan Romanick#endif /* DRI_NEW_INTERFACE_ONLY */
2045b98ada88071a752b6000756949a1951183cdd0bIan Romanick
2055b98ada88071a752b6000756949a1951183cdd0bIan Romanick/**
2065b98ada88071a752b6000756949a1951183cdd0bIan Romanick * Utility function used by drivers to test the verions of other components.
2075b98ada88071a752b6000756949a1951183cdd0bIan Romanick *
2085b98ada88071a752b6000756949a1951183cdd0bIan Romanick * If one of the version requirements is not met, a message is logged using
2095b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \c __driUtilMessage.
2105b98ada88071a752b6000756949a1951183cdd0bIan Romanick *
2115b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param driver_name  Name of the driver.  Used in error messages.
2125b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param driActual    Actual DRI version supplied __driCreateNewScreen.
2135b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param driExpected  Minimum DRI version required by the driver.
2145b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param ddxActual    Actual DDX version supplied __driCreateNewScreen.
2155b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param ddxExpected  Minimum DDX version required by the driver.
2165b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param drmActual    Actual DRM version supplied __driCreateNewScreen.
2175b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \param drmExpected  Minimum DRM version required by the driver.
2185b98ada88071a752b6000756949a1951183cdd0bIan Romanick *
2195b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \returns \c GL_TRUE if all version requirements are met.  Otherwise,
2205b98ada88071a752b6000756949a1951183cdd0bIan Romanick *          \c GL_FALSE is returned.
2215b98ada88071a752b6000756949a1951183cdd0bIan Romanick *
2225b98ada88071a752b6000756949a1951183cdd0bIan Romanick * \sa __driCreateNewScreen, driCheckDriDdxDrmVersions, __driUtilMessage
2235b98ada88071a752b6000756949a1951183cdd0bIan Romanick */
2245b98ada88071a752b6000756949a1951183cdd0bIan RomanickGLboolean
2255b98ada88071a752b6000756949a1951183cdd0bIan RomanickdriCheckDriDdxDrmVersions2(const char * driver_name,
2265b98ada88071a752b6000756949a1951183cdd0bIan Romanick			   const __DRIversion * driActual,
2275b98ada88071a752b6000756949a1951183cdd0bIan Romanick			   const __DRIversion * driExpected,
2285b98ada88071a752b6000756949a1951183cdd0bIan Romanick			   const __DRIversion * ddxActual,
2295b98ada88071a752b6000756949a1951183cdd0bIan Romanick			   const __DRIversion * ddxExpected,
2305b98ada88071a752b6000756949a1951183cdd0bIan Romanick			   const __DRIversion * drmActual,
2315b98ada88071a752b6000756949a1951183cdd0bIan Romanick			   const __DRIversion * drmExpected)
2325b98ada88071a752b6000756949a1951183cdd0bIan Romanick{
2335b98ada88071a752b6000756949a1951183cdd0bIan Romanick   static const char format[] = "%s DRI driver expected %s version %d.%d.x "
2345b98ada88071a752b6000756949a1951183cdd0bIan Romanick       "but got version %d.%d.%d";
2355b98ada88071a752b6000756949a1951183cdd0bIan Romanick
2365b98ada88071a752b6000756949a1951183cdd0bIan Romanick
2375b98ada88071a752b6000756949a1951183cdd0bIan Romanick   /* Check the DRI version */
2385b98ada88071a752b6000756949a1951183cdd0bIan Romanick   if ( (driActual->major != driExpected->major)
2395b98ada88071a752b6000756949a1951183cdd0bIan Romanick	|| (driActual->minor < driExpected->minor) ) {
2405b98ada88071a752b6000756949a1951183cdd0bIan Romanick      __driUtilMessage(format, driver_name, "DRI",
2415b98ada88071a752b6000756949a1951183cdd0bIan Romanick		       driExpected->major, driExpected->minor,
2425b98ada88071a752b6000756949a1951183cdd0bIan Romanick		       driActual->major, driActual->minor, driActual->patch);
2435b98ada88071a752b6000756949a1951183cdd0bIan Romanick      return GL_FALSE;
2445b98ada88071a752b6000756949a1951183cdd0bIan Romanick   }
2455b98ada88071a752b6000756949a1951183cdd0bIan Romanick
2465b98ada88071a752b6000756949a1951183cdd0bIan Romanick   /* Check that the DDX driver version is compatible */
2475b98ada88071a752b6000756949a1951183cdd0bIan Romanick   if ( (ddxActual->major != ddxExpected->major)
2485b98ada88071a752b6000756949a1951183cdd0bIan Romanick	|| (ddxActual->minor < ddxExpected->minor) ) {
2495b98ada88071a752b6000756949a1951183cdd0bIan Romanick      __driUtilMessage(format, driver_name, "DDX",
2505b98ada88071a752b6000756949a1951183cdd0bIan Romanick		       ddxExpected->major, ddxExpected->minor,
2515b98ada88071a752b6000756949a1951183cdd0bIan Romanick		       ddxActual->major, ddxActual->minor, ddxActual->patch);
2525b98ada88071a752b6000756949a1951183cdd0bIan Romanick      return GL_FALSE;
2535b98ada88071a752b6000756949a1951183cdd0bIan Romanick   }
2545b98ada88071a752b6000756949a1951183cdd0bIan Romanick
2555b98ada88071a752b6000756949a1951183cdd0bIan Romanick   /* Check that the DRM driver version is compatible */
2565b98ada88071a752b6000756949a1951183cdd0bIan Romanick   if ( (drmActual->major != drmExpected->major)
2575b98ada88071a752b6000756949a1951183cdd0bIan Romanick	|| (drmActual->minor < drmExpected->minor) ) {
2585b98ada88071a752b6000756949a1951183cdd0bIan Romanick      __driUtilMessage(format, driver_name, "DRM",
2595b98ada88071a752b6000756949a1951183cdd0bIan Romanick		       drmExpected->major, drmExpected->minor,
2605b98ada88071a752b6000756949a1951183cdd0bIan Romanick		       drmActual->major, drmActual->minor, drmActual->patch);
2615b98ada88071a752b6000756949a1951183cdd0bIan Romanick      return GL_FALSE;
2625b98ada88071a752b6000756949a1951183cdd0bIan Romanick   }
2635b98ada88071a752b6000756949a1951183cdd0bIan Romanick
2645b98ada88071a752b6000756949a1951183cdd0bIan Romanick   return GL_TRUE;
2655b98ada88071a752b6000756949a1951183cdd0bIan Romanick}
2665b98ada88071a752b6000756949a1951183cdd0bIan Romanick
2677ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
2687ed58285abede813fbf5fa0a2e29982043f1bbbeKeith WhitwellGLboolean driClipRectToFramebuffer( const GLframebuffer *buffer,
2697ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell				    GLint *x, GLint *y,
2707ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell				    GLsizei *width, GLsizei *height )
2717ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell{
2727ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   /* left clipping */
2737ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   if (*x < buffer->_Xmin) {
2747ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      *width -= (buffer->_Xmin - *x);
2757ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      *x = buffer->_Xmin;
2767ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   }
2777ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
2787ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   /* right clipping */
2797ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   if (*x + *width > buffer->_Xmax)
2807ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      *width -= (*x + *width - buffer->_Xmax - 1);
2817ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
2827ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   if (*width <= 0)
2837ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      return GL_FALSE;
2847ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
2857ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   /* bottom clipping */
2867ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   if (*y < buffer->_Ymin) {
2877ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      *height -= (buffer->_Ymin - *y);
2887ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      *y = buffer->_Ymin;
2897ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   }
2907ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
2917ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   /* top clipping */
2927ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   if (*y + *height > buffer->_Ymax)
2937ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      *height -= (*y + *height - buffer->_Ymax - 1);
2947ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
2957ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   if (*height <= 0)
2967ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell      return GL_FALSE;
2977ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell
2987ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell   return GL_TRUE;
2997ed58285abede813fbf5fa0a2e29982043f1bbbeKeith Whitwell}
300