mesa: add bool param to _mesa_free_context_data
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_debug.h
index 2b35044fb66fb38f495afc59f04f750add00c0e1..8f56ec6769b710210742436c8053966ca0feb76f 100644 (file)
@@ -30,8 +30,7 @@
 #ifndef RADEON_DEBUG_H_INCLUDED
 #define RADEON_DEBUG_H_INCLUDED
 
-#include <stdarg.h>
-#include <stdio.h>
+#include <stdlib.h>
 
 typedef enum radeon_debug_levels {
        RADEON_CRITICAL  = 0, /* Only errors */
@@ -48,7 +47,11 @@ typedef enum radeon_debug_levels {
  * errors.
  */
 #ifndef RADEON_DEBUG_LEVEL
-#define RADEON_DEBUG_LEVEL RADEON_VERBOSE
+# ifdef DEBUG
+#  define RADEON_DEBUG_LEVEL RADEON_TRACE
+# else
+#  define RADEON_DEBUG_LEVEL RADEON_VERBOSE
+# endif
 #endif
 
 typedef enum radeon_debug_types {
@@ -71,95 +74,100 @@ typedef enum radeon_debug_types {
        RADEON_GENERAL   = 0x10000   /* Used for errors and warnings */
 } radeon_debug_type_t;
 
-extern radeon_debug_type_t radeon_enabled_debug_types;
+#define RADEON_MAX_INDENT 5
+
+struct radeon_debug {
+       size_t indent_depth;
+       char indent[RADEON_MAX_INDENT];
+};
 
 /**
  * Compabibility layer for old debug code
  **/
-#define RADEON_DEBUG radeon_enabled_debug_types
+#if defined(RADEON_R200)
+extern radeon_debug_type_t r200_enabled_debug_types;
+#define RADEON_DEBUG r200_enabled_debug_types
+#elif defined(RADEON_R100)
+extern radeon_debug_type_t r100_enabled_debug_types;
+#define RADEON_DEBUG r100_enabled_debug_types
+#else
+#error "Neither RADEON_R100 nor RADEON_R200 are defined."
+#endif
 
 static inline int radeon_is_debug_enabled(const radeon_debug_type_t type,
           const radeon_debug_level_t level)
 {
-       return RADEON_DEBUG_LEVEL <= level
-               && (type & radeon_enabled_debug_types);
+       return RADEON_DEBUG_LEVEL >= level
+               && (type & RADEON_DEBUG);
 }
-/*
- * define macro for gcc specific __attribute__ if using alternative compiler
- */
-#ifndef __GNUC__
-#define  __attribute__(x)  /*empty*/
-#endif
 
-/**
- * Format attribute requires declaration for setting it. Don't ask me why!
- */
-static inline void radeon_print(const radeon_debug_type_t type,
+extern void _radeon_print(const radeon_debug_type_t type,
           const radeon_debug_level_t level,
           const char* message,
-          ...) __attribute__((format(printf,3,4)));
-
+          ...)  PRINTFLIKE(3, 4);
 /**
  * Print out debug message if channel specified by type is enabled
  * and compile time debugging level is at least as high as level parameter
  */
-static inline void radeon_print(const radeon_debug_type_t type,
-          const radeon_debug_level_t level,
-          const char* message,
-          ...)
-{
-       /* Compile out if level of message is too high */
-       if (radeon_is_debug_enabled(type, level)) {
-
-               va_list values;
-               va_start( values, message );
-               vfprintf(stderr, message, values);
-               va_end( values );
-       }
-}
+#define radeon_print(type, level, ...) do {                    \
+       const radeon_debug_level_t _debug_level = (level);      \
+       const radeon_debug_type_t _debug_type = (type);         \
+       /* Compile out if level of message is too high */       \
+       if (radeon_is_debug_enabled(type, level)) {             \
+               _radeon_print(_debug_type, _debug_level,        \
+                       __VA_ARGS__);                           \
+       }                                                       \
+} while(0)
 
-static inline void radeon_error(const char* message, ...)  __attribute__((format(printf,1,2)));
 /**
  * printf style function for writing error messages.
  */
-static inline void radeon_error(const char* message, ...)
-{
-       va_list values;
-       va_start( values, message );
-       radeon_print(RADEON_GENERAL, RADEON_CRITICAL, message, values);
-       va_end( values );
-}
+#define radeon_error(...) do {                                 \
+       radeon_print(RADEON_GENERAL, RADEON_CRITICAL,           \
+               __VA_ARGS__);                                   \
+} while(0)
 
-static inline void radeon_warning(const char* message, ...)  __attribute__((format(printf,1,2)));
 /**
  * printf style function for writing warnings.
  */
-static inline void radeon_warning(const char* message, ...)
+#define radeon_warning(...) do {                               \
+       radeon_print(RADEON_GENERAL, RADEON_IMPORTANT,          \
+               __VA_ARGS__);                                   \
+} while(0)
+
+extern void radeon_init_debug(void);
+extern void _radeon_debug_add_indent(void);
+extern void _radeon_debug_remove_indent(void);
+
+static inline void radeon_debug_add_indent(void)
+{
+       if (RADEON_DEBUG_LEVEL >= RADEON_VERBOSE) {
+             _radeon_debug_add_indent();
+       }
+}
+static inline void radeon_debug_remove_indent(void)
 {
-       va_list values;
-       va_start( values, message );
-       radeon_print(RADEON_GENERAL, RADEON_IMPORTANT, message, values);
-       va_end( values );
+       if (RADEON_DEBUG_LEVEL >= RADEON_VERBOSE) {
+             _radeon_debug_remove_indent();
+       }
 }
 
 
-extern void radeon_init_debug(void);
-
 /* From http://gcc. gnu.org/onlinedocs/gcc-3.2.3/gcc/Variadic-Macros.html .
    I suppose we could inline this and use macro to fetch out __LINE__ and stuff in case we run into trouble
    with other compilers ... GLUE!
 */
-#define WARN_ONCE(a, ...)      { \
-       static int warn##__LINE__=1; \
-       if(warn##__LINE__){ \
+#define WARN_ONCE(...)      do { \
+       static int __warn_once=1; \
+       if(__warn_once){ \
                radeon_warning("*********************************WARN_ONCE*********************************\n"); \
                radeon_warning("File %s function %s line %d\n", \
-                       __FILE__, __FUNCTION__, __LINE__); \
-               radeon_warning(  (a), ## __VA_ARGS__);\
+                       __FILE__, __func__, __LINE__); \
+               radeon_warning(__VA_ARGS__);\
                radeon_warning("***************************************************************************\n"); \
-               warn##__LINE__=0;\
+               __warn_once=0;\
                } \
-       }
+       } while(0)
 
 
 #endif