fix some 0->NULLs
[mesa.git] / src / mesa / drivers / dri / common / utils.c
index 99dc064826acd7b4b7804bd9e2d693955ac6456d..85527f9234773d4a2123f253ca380686a871c678 100644 (file)
  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * \file utils.c
+ * Utility functions for DRI drivers.
  *
- * Authors:
- *    Ian Romanick <idr@us.ibm.com>
+ * \author Ian Romanick <idr@us.ibm.com>
  */
-/* $XFree86:$ */
 
 #include <string.h>
 #include <stdlib.h>
 #include "x86/common_x86_asm.h"
 #endif
 
+#if defined(USE_PPC_ASM)
+#include "ppc/common_ppc_features.h"
+#endif
+
 unsigned
 driParseDebugString( const char * debug, 
                     const struct dri_debug_control * control  )
@@ -64,17 +71,33 @@ driParseDebugString( const char * debug,
 
 
 
-
+/**
+ * Create the \c GL_RENDERER string for DRI drivers.
+ * 
+ * Almost all DRI drivers use a \c GL_RENDERER string of the form:
+ *
+ *    "Mesa DRI <chip> <driver date> <AGP speed) <CPU information>"
+ *
+ * Using the supplied chip name, driver data, and AGP speed, this function
+ * creates the string.
+ * 
+ * \param buffer         Buffer to hold the \c GL_RENDERER string.
+ * \param hardware_name  Name of the hardware.
+ * \param driver_date    Driver date.
+ * \param agp_mode       AGP mode (speed).
+ * 
+ * \returns
+ * The length of the string stored in \c buffer.  This does \b not include
+ * the terminating \c NUL character.
+ */
 unsigned
 driGetRendererString( char * buffer, const char * hardware_name,
                      const char * driver_date, GLuint agp_mode )
 {
-#ifdef USE_X86_ASM
-   char * x86_str = "";
-   char * mmx_str = "";
-   char * tdnow_str = "";
-   char * sse_str = "";
-#endif
+#define MAX_INFO   4
+   const char * cpu[MAX_INFO];
+   unsigned   next = 0;
+   unsigned   i;
    unsigned   offset;
 
 
@@ -98,33 +121,59 @@ driGetRendererString( char * buffer, const char * hardware_name,
     */
 #ifdef USE_X86_ASM
    if ( _mesa_x86_cpu_features ) {
-      x86_str = " x86";
+      cpu[next] = " x86";
+      next++;
    }
 # ifdef USE_MMX_ASM
    if ( cpu_has_mmx ) {
-      mmx_str = (cpu_has_mmxext) ? "/MMX+" : "/MMX";
+      cpu[next] = (cpu_has_mmxext) ? "/MMX+" : "/MMX";
+      next++;
    }
 # endif
 # ifdef USE_3DNOW_ASM
    if ( cpu_has_3dnow ) {
-      tdnow_str = (cpu_has_3dnowext) ? "/3DNow!+" : "/3DNow!";
+      cpu[next] = (cpu_has_3dnowext) ? "/3DNow!+" : "/3DNow!";
+      next++;
    }
 # endif
 # ifdef USE_SSE_ASM
    if ( cpu_has_xmm ) {
-      sse_str = (cpu_has_xmm2) ? "/SSE2" : "/SSE";
+      cpu[next] = (cpu_has_xmm2) ? "/SSE2" : "/SSE";
+      next++;
    }
 # endif
 
-   offset += sprintf( & buffer[ offset ], "%s%s%s%s", 
-                     x86_str, mmx_str, tdnow_str, sse_str );
-
 #elif defined(USE_SPARC_ASM)
 
-   offset += sprintf( & buffer[ offset ], " Sparc" );
+   cpu[0] = " SPARC";
+   next = 1;
+
+#elif defined(USE_PPC_ASM)
+   if ( _mesa_ppc_cpu_features ) {
+      cpu[next] = (cpu_has_64) ? " PowerPC 64" : " PowerPC";
+      next++;
+   }
+
+# ifdef USE_VMX_ASM
+   if ( cpu_has_vmx ) {
+      cpu[next] = "/Altivec";
+      next++;
+   }
+# endif
 
+   if ( ! cpu_has_fpu ) {
+      cpu[next] = "/No FPU";
+      next++;
+   }
 #endif
 
+   for ( i = 0 ; i < next ; i++ ) {
+      const size_t len = strlen( cpu[i] );
+
+      strncpy( & buffer[ offset ], cpu[i], len );
+      offset += len;
+   }
+
    return offset;
 }
 
@@ -208,7 +257,7 @@ driCheckDriDdxDrmVersions(__DRIscreenPrivate *sPriv,
  * \param driActual    Actual DRI version supplied __driCreateNewScreen.
  * \param driExpected  Minimum DRI version required by the driver.
  * \param ddxActual    Actual DDX version supplied __driCreateNewScreen.
- * \param ddxExpected  Minimum DDX version required by the driver.
+ * \param ddxExpected  Minimum DDX minor and range of DDX major version required by the driver.
  * \param drmActual    Actual DRM version supplied __driCreateNewScreen.
  * \param drmExpected  Minimum DRM version required by the driver.
  * 
@@ -218,16 +267,18 @@ driCheckDriDdxDrmVersions(__DRIscreenPrivate *sPriv,
  * \sa __driCreateNewScreen, driCheckDriDdxDrmVersions, __driUtilMessage
  */
 GLboolean
-driCheckDriDdxDrmVersions2(const char * driver_name,
+driCheckDriDdxDrmVersions3(const char * driver_name,
                           const __DRIversion * driActual,
                           const __DRIversion * driExpected,
                           const __DRIversion * ddxActual,
-                          const __DRIversion * ddxExpected,
+                          const __DRIutilversion2 * ddxExpected,
                           const __DRIversion * drmActual,
                           const __DRIversion * drmExpected)
 {
    static const char format[] = "%s DRI driver expected %s version %d.%d.x "
        "but got version %d.%d.%d";
+   static const char format2[] = "%s DRI driver expected %s version %d-%d.%d.x "
+       "but got version %d.%d.%d";
 
 
    /* Check the DRI version */
@@ -240,10 +291,11 @@ driCheckDriDdxDrmVersions2(const char * driver_name,
    }
 
    /* Check that the DDX driver version is compatible */
-   if ( (ddxActual->major != ddxExpected->major)
+   if ( (ddxActual->major < ddxExpected->major_min)
+       || (ddxActual->major > ddxExpected->major_max)
        || (ddxActual->minor < ddxExpected->minor) ) {
-      __driUtilMessage(format, driver_name, "DDX",
-                      ddxExpected->major, ddxExpected->minor,
+      __driUtilMessage(format2, driver_name, "DDX",
+                      ddxExpected->major_min, ddxExpected->major_max, ddxExpected->minor,
                       ddxActual->major, ddxActual->minor, ddxActual->patch);
       return GL_FALSE;
    }
@@ -260,6 +312,26 @@ driCheckDriDdxDrmVersions2(const char * driver_name,
    return GL_TRUE;
 }
 
+GLboolean
+driCheckDriDdxDrmVersions2(const char * driver_name,
+                          const __DRIversion * driActual,
+                          const __DRIversion * driExpected,
+                          const __DRIversion * ddxActual,
+                          const __DRIversion * ddxExpected,
+                          const __DRIversion * drmActual,
+                          const __DRIversion * drmExpected)
+{
+   __DRIutilversion2 ddx_expected;
+   ddx_expected.major_min = ddxExpected->major;
+   ddx_expected.major_max = ddxExpected->major;
+   ddx_expected.minor = ddxExpected->minor;
+   ddx_expected.patch = ddxExpected->patch;
+   return driCheckDriDdxDrmVersions3(driver_name, driActual,
+                               driExpected, ddxActual, & ddx_expected,
+                               drmActual, drmExpected);
+}
+
+
 
 GLboolean driClipRectToFramebuffer( const GLframebuffer *buffer,
                                    GLint *x, GLint *y,
@@ -366,12 +438,12 @@ GLboolean driClipRectToFramebuffer( const GLframebuffer *buffer,
 GLboolean
 driFillInModes( __GLcontextModes ** ptr_to_modes,
                GLenum fb_format, GLenum fb_type,
-               const uint8_t * depth_bits, const uint8_t * stencil_bits,
+               const u_int8_t * depth_bits, const u_int8_t * stencil_bits,
                unsigned num_depth_stencil_bits,
                const GLenum * db_modes, unsigned num_db_modes,
                int visType )
 {
-   static const uint8_t bits_table[3][4] = {
+   static const u_int8_t bits_table[3][4] = {
      /* R  G  B  A */
       { 5, 6, 5, 0 }, /* Any GL_UNSIGNED_SHORT_5_6_5 */
       { 8, 8, 8, 0 }, /* Any RGB with any GL_UNSIGNED_INT_8_8_8_8 */
@@ -382,7 +454,7 @@ driFillInModes( __GLcontextModes ** ptr_to_modes,
     * Given the four supported fb_type values, this results in valid array
     * indices of 3, 4, 5, and 7.
     */
-   static const uint32_t masks_table_rgb[8][4] = {
+   static const u_int32_t masks_table_rgb[8][4] = {
       { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
       { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
       { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
@@ -393,7 +465,7 @@ driFillInModes( __GLcontextModes ** ptr_to_modes,
       { 0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000 }  /* 8_8_8_8_REV */
    };
 
-   static const uint32_t masks_table_rgba[8][4] = {
+   static const u_int32_t masks_table_rgba[8][4] = {
       { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
       { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
       { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
@@ -404,7 +476,7 @@ driFillInModes( __GLcontextModes ** ptr_to_modes,
       { 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 }, /* 8_8_8_8_REV */
    };
 
-   static const uint32_t masks_table_bgr[8][4] = {
+   static const u_int32_t masks_table_bgr[8][4] = {
       { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
       { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
       { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
@@ -415,7 +487,7 @@ driFillInModes( __GLcontextModes ** ptr_to_modes,
       { 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 }, /* 8_8_8_8_REV */
    };
 
-   static const uint32_t masks_table_bgra[8][4] = {
+   static const u_int32_t masks_table_bgra[8][4] = {
       { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
       { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
       { 0x00000000, 0x00000000, 0x00000000, 0x00000000 },
@@ -426,12 +498,12 @@ driFillInModes( __GLcontextModes ** ptr_to_modes,
       { 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000 }, /* 8_8_8_8_REV */
    };
 
-   static const uint8_t bytes_per_pixel[8] = {
+   static const u_int8_t bytes_per_pixel[8] = {
       0, 0, 0, 2, 2, 4, 0, 4
    };
 
-   const uint8_t  * bits;
-   const uint32_t * masks;
+   const u_int8_t  * bits;
+   const u_int32_t * masks;
    const int index = fb_type & 0x07;
    __GLcontextModes * modes = *ptr_to_modes;
    unsigned i;
@@ -441,7 +513,7 @@ driFillInModes( __GLcontextModes ** ptr_to_modes,
 
    if ( bytes_per_pixel[ index ] == 0 ) {
       fprintf( stderr, "[%s:%u] Framebuffer type 0x%04x has 0 bytes per pixel.\n",
-              __func__, __LINE__, fb_type );
+              __FUNCTION__, __LINE__, fb_type );
       return GL_FALSE;
    }
 
@@ -479,7 +551,7 @@ driFillInModes( __GLcontextModes ** ptr_to_modes,
 
       default:
          fprintf( stderr, "[%s:%u] Framebuffer format 0x%04x is not GL_RGB, GL_RGBA, GL_BGR, or GL_BGRA.\n",
-              __func__, __LINE__, fb_format );
+              __FUNCTION__, __LINE__, fb_format );
          return GL_FALSE;
    }