util: require debug options to be separated by commas
[mesa.git] / src / gallium / auxiliary / util / u_debug.c
index 504e6d2a18ff1aa05346dc30af3ad4b3f42349e5..8cf76608e681eee8d698a3763992633262586b9f 100644 (file)
 #include "util/u_string.h" 
 #include "util/u_math.h" 
 #include "util/u_tile.h" 
-#include "util/u_prim.h" 
+#include "util/u_prim.h"
+#include "util/u_surface.h"
 
 #include <limits.h> /* CHAR_BIT */
 
 void _debug_vprintf(const char *format, va_list ap)
 {
+#if defined(PIPE_OS_WINDOWS) || defined(PIPE_OS_EMBEDDED)
    /* We buffer until we find a newline. */
    static char buf[4096] = {'\0'};
    size_t len = strlen(buf);
@@ -54,6 +56,10 @@ void _debug_vprintf(const char *format, va_list ap)
       os_log_message(buf);
       buf[0] = '\0';
    }
+#else
+   /* Just print as-is to stderr */
+   vfprintf(stderr, format, ap);
+#endif
 }
 
 
@@ -174,6 +180,43 @@ debug_get_num_option(const char *name, long dfault)
    return result;
 }
 
+static boolean str_has_option(const char *str, const char *name)
+{
+   const char *substr;
+
+   /* OPTION=all */
+   if (!util_strcmp(str, "all")) {
+      return TRUE;
+   }
+
+   /* OPTION=name */
+   if (!util_strcmp(str, name)) {
+      return TRUE;
+   }
+
+   substr = util_strstr(str, name);
+
+   if (substr) {
+      unsigned name_len = strlen(name);
+
+      /* OPTION=name,... */
+      if (substr == str && substr[name_len] == ',') {
+         return TRUE;
+      }
+
+      /* OPTION=...,name */
+      if (substr+name_len == str+strlen(str) && substr[-1] == ',') {
+         return TRUE;
+      }
+
+      /* OPTION=...,name,... */
+      if (substr[-1] == ',' && substr[name_len] == ',') {
+         return TRUE;
+      }
+   }
+
+   return FALSE;
+}
 
 unsigned long
 debug_get_flags_option(const char *name, 
@@ -201,7 +244,7 @@ debug_get_flags_option(const char *name,
    else {
       result = 0;
       while( flags->name ) {
-        if (!util_strcmp(str, "all") || util_strstr(str, flags->name ))
+        if (str_has_option(str, flags->name))
            result |= flags->value;
         ++flags;
       }
@@ -353,6 +396,41 @@ const char *u_prim_name( unsigned prim )
 
 
 
+#ifdef DEBUG
+int fl_indent = 0;
+const char* fl_function[1024];
+
+int debug_funclog_enter(const char* f, const int line, const char* file)
+{
+   int i;
+
+   for (i = 0; i < fl_indent; i++)
+      debug_printf("  ");
+   debug_printf("%s\n", f);
+
+   assert(fl_indent < 1023);
+   fl_function[fl_indent++] = f;
+
+   return 0;
+}
+
+void debug_funclog_exit(const char* f, const int line, const char* file)
+{
+   --fl_indent;
+   assert(fl_indent >= 0);
+   assert(fl_function[fl_indent] == f);
+}
+
+void debug_funclog_enter_exit(const char* f, const int line, const char* file)
+{
+   int i;
+   for (i = 0; i < fl_indent; i++)
+      debug_printf("  ");
+   debug_printf("%s\n", f);
+}
+#endif
+
+
 
 #ifdef DEBUG
 /**
@@ -453,9 +531,10 @@ void debug_dump_image(const char *prefix,
 #endif
 }
 
+/* FIXME: dump resources, not surfaces... */
 void debug_dump_surface(struct pipe_context *pipe,
-                       const char *prefix,
-                        struct pipe_surface *surface)     
+                        const char *prefix,
+                        struct pipe_surface *surface)
 {
    struct pipe_resource *texture;
    struct pipe_transfer *transfer;
@@ -472,23 +551,23 @@ void debug_dump_surface(struct pipe_context *pipe,
     */
    texture = surface->texture;
 
-   transfer = pipe_get_transfer(pipe, texture, surface->face,
-                                    surface->level, surface->zslice,
-                                    PIPE_TRANSFER_READ, 0, 0, surface->width,
-                                    surface->height);
-   
+   transfer = pipe_get_transfer(pipe, texture, surface->u.tex.level,
+                                surface->u.tex.first_layer,
+                                PIPE_TRANSFER_READ,
+                                0, 0, surface->width, surface->height);
+
    data = pipe->transfer_map(pipe, transfer);
    if(!data)
       goto error;
-   
-   debug_dump_image(prefix, 
+
+   debug_dump_image(prefix,
                     texture->format,
-                    util_format_get_blocksize(texture->format), 
+                    util_format_get_blocksize(texture->format),
                     util_format_get_nblocksx(texture->format, surface->width),
                     util_format_get_nblocksy(texture->format, surface->height),
                     transfer->stride,
                     data);
-   
+
    pipe->transfer_unmap(pipe, transfer);
 error:
    pipe->transfer_destroy(pipe, transfer);
@@ -499,20 +578,18 @@ void debug_dump_texture(struct pipe_context *pipe,
                         const char *prefix,
                         struct pipe_resource *texture)
 {
-   struct pipe_surface *surface;
-   struct pipe_screen *screen;
+   struct pipe_surface *surface, surf_tmpl;
 
    if (!texture)
       return;
 
-   screen = texture->screen;
-
-   /* XXX for now, just dump image for face=0, level=0 */
-   surface = screen->get_tex_surface(screen, texture, 0, 0, 0,
-                                     PIPE_BIND_SAMPLER_VIEW);
+   /* XXX for now, just dump image for layer=0, level=0 */
+   memset(&surf_tmpl, 0, sizeof(surf_tmpl));
+   u_surface_default_template(&surf_tmpl, texture, 0 /* no bind flag - not a surface */);
+   surface = pipe->create_surface(pipe, texture, &surf_tmpl);
    if (surface) {
       debug_dump_surface(pipe, prefix, surface);
-      screen->tex_surface_destroy(surface);
+      pipe->surface_destroy(pipe, surface);
    }
 }
 
@@ -550,17 +627,16 @@ struct bmp_rgb_quad {
 
 void
 debug_dump_surface_bmp(struct pipe_context *pipe,
-                      const char *filename,
+                       const char *filename,
                        struct pipe_surface *surface)
 {
 #ifndef PIPE_SUBSYSTEM_WINDOWS_MINIPORT
    struct pipe_transfer *transfer;
    struct pipe_resource *texture = surface->texture;
 
-   transfer = pipe_get_transfer(pipe, texture, surface->face,
-                               surface->level, surface->zslice,
-                               PIPE_TRANSFER_READ, 0, 0, surface->width,
-                               surface->height);
+   transfer = pipe_get_transfer(pipe, texture, surface->u.tex.level,
+                                surface->u.tex.first_layer, PIPE_TRANSFER_READ,
+                                0, 0, surface->width, surface->height);
 
    debug_dump_transfer_bmp(pipe, filename, transfer);