summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary/util/u_debug.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/auxiliary/util/u_debug.c')
-rw-r--r--src/gallium/auxiliary/util/u_debug.c298
1 files changed, 91 insertions, 207 deletions
diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c
index 9b4e6ca2a7..4821b8a143 100644
--- a/src/gallium/auxiliary/util/u_debug.c
+++ b/src/gallium/auxiliary/util/u_debug.c
@@ -29,125 +29,30 @@
#include "pipe/p_config.h"
-#include <stdarg.h>
-
-
-#ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
-
-#include <windows.h>
-#include <winddi.h>
-
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_CE)
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <windows.h>
-#include <types.h>
-
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
-
-#ifndef WIN32_LEAN_AND_MEAN
-#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
-#endif
-#include <windows.h>
-#include <stdio.h>
-
-#else
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#endif
-
-#include "pipe/p_compiler.h"
+#include "pipe/p_compiler.h"
+#include "os/os_stream.h"
#include "util/u_debug.h"
#include "pipe/p_format.h"
#include "pipe/p_state.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
#include "util/u_format.h"
#include "util/u_memory.h"
#include "util/u_string.h"
-#include "util/u_stream.h"
#include "util/u_math.h"
#include "util/u_tile.h"
#include "util/u_prim.h"
-#ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
-static INLINE void
-_EngDebugPrint(const char *format, ...)
-{
- va_list ap;
- va_start(ap, format);
- EngDebugPrint("", (PCHAR)format, ap);
- va_end(ap);
-}
-#endif
-
-
void _debug_vprintf(const char *format, va_list ap)
{
-#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
- /* EngDebugPrint does not handle float point arguments, so we need to use
- * our own vsnprintf implementation. It is also very slow, so buffer until
- * we find a newline. */
- static char buf[512] = {'\0'};
- size_t len = strlen(buf);
- int ret = util_vsnprintf(buf + len, sizeof(buf) - len, format, ap);
- if(ret > (int)(sizeof(buf) - len - 1) || util_strchr(buf + len, '\n')) {
- _EngDebugPrint("%s", buf);
- buf[0] = '\0';
- }
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
- /* OutputDebugStringA can be very slow, so buffer until we find a newline. */
+ /* We buffer until we find a newline. */
static char buf[4096] = {'\0'};
size_t len = strlen(buf);
int ret = util_vsnprintf(buf + len, sizeof(buf) - len, format, ap);
if(ret > (int)(sizeof(buf) - len - 1) || util_strchr(buf + len, '\n')) {
- OutputDebugStringA(buf);
+ os_log_message(buf);
buf[0] = '\0';
}
-
- if(GetConsoleWindow() && !IsDebuggerPresent()) {
- fflush(stdout);
- vfprintf(stderr, format, ap);
- fflush(stderr);
- }
-
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_CE)
- wchar_t *wide_format;
- long wide_str_len;
- char buf[512];
- int ret;
-#if (_WIN32_WCE < 600)
- ret = vsprintf(buf, format, ap);
- if(ret < 0){
- sprintf(buf, "Cant handle debug print!");
- ret = 25;
- }
-#else
- ret = vsprintf_s(buf, 512, format, ap);
- if(ret < 0){
- sprintf_s(buf, 512, "Cant handle debug print!");
- ret = 25;
- }
-#endif
- buf[ret] = '\0';
- /* Format is ascii - needs to be converted to wchar_t for printing */
- wide_str_len = MultiByteToWideChar(CP_ACP, 0, (const char *) buf, -1, NULL, 0);
- wide_format = (wchar_t *) malloc((wide_str_len+1) * sizeof(wchar_t));
- if (wide_format) {
- MultiByteToWideChar(CP_ACP, 0, (const char *) buf, -1,
- wide_format, wide_str_len);
- NKDbgPrintfW(wide_format, wide_format);
- free(wide_format);
- }
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
- /* TODO */
-#else /* !PIPE_SUBSYSTEM_WINDOWS */
- fflush(stdout);
- vfprintf(stderr, format, ap);
-#endif
}
@@ -169,108 +74,12 @@ void debug_print_blob( const char *name,
#endif
-#ifndef debug_break
-void debug_break(void)
-{
-#if defined(PIPE_SUBSYSTEM_WINDOWS_USER)
- DebugBreak();
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
- EngDebugBreak();
-#else
- abort();
-#endif
-}
-#endif
-
-
-#ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
-static const char *
-find(const char *start, const char *end, char c)
-{
- const char *p;
- for(p = start; !end || p != end; ++p) {
- if(*p == c)
- return p;
- if(*p < 32)
- break;
- }
- return NULL;
-}
-
-static int
-compare(const char *start, const char *end, const char *s)
-{
- const char *p, *q;
- for(p = start, q = s; p != end && *q != '\0'; ++p, ++q) {
- if(*p != *q)
- return 0;
- }
- return p == end && *q == '\0';
-}
-
-static void
-copy(char *dst, const char *start, const char *end, size_t n)
-{
- const char *p;
- char *q;
- for(p = start, q = dst, n = n - 1; p != end && n; ++p, ++q, --n)
- *q = *p;
- *q = '\0';
-}
-#endif
-
-
-static INLINE const char *
-_debug_get_option(const char *name)
-{
-#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
- /* EngMapFile creates the file if it does not exists, so it must either be
- * disabled on release versions (or put in a less conspicuous place). */
-#ifdef DEBUG
- const char *result = NULL;
- ULONG_PTR iFile = 0;
- const void *pMap = NULL;
- const char *sol, *eol, *sep;
- static char output[1024];
-
- pMap = EngMapFile(L"\\??\\c:\\gallium.cfg", 0, &iFile);
- if(pMap) {
- sol = (const char *)pMap;
- while(1) {
- /* TODO: handle LF line endings */
- eol = find(sol, NULL, '\r');
- if(!eol || eol == sol)
- break;
- sep = find(sol, eol, '=');
- if(!sep)
- break;
- if(compare(sol, sep, name)) {
- copy(output, sep + 1, eol, sizeof(output));
- result = output;
- break;
- }
- sol = eol + 2;
- }
- EngUnmapFile(iFile);
- }
- return result;
-#else
- return NULL;
-#endif
-#elif defined(PIPE_SUBSYSTEM_WINDOWS_CE) || defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
- /* TODO: implement */
- return NULL;
-#else
- return getenv(name);
-#endif
-}
-
const char *
debug_get_option(const char *name, const char *dfault)
{
const char *result;
- result = _debug_get_option(name);
+ result = os_get_option(name);
if(!result)
result = dfault;
@@ -282,7 +91,7 @@ debug_get_option(const char *name, const char *dfault)
boolean
debug_get_bool_option(const char *name, boolean dfault)
{
- const char *str = _debug_get_option(name);
+ const char *str = os_get_option(name);
boolean result;
if(str == NULL)
@@ -312,7 +121,7 @@ debug_get_num_option(const char *name, long dfault)
long result;
const char *str;
- str = _debug_get_option(name);
+ str = os_get_option(name);
if(!str)
result = dfault;
else {
@@ -348,7 +157,7 @@ debug_get_flags_option(const char *name,
unsigned long result;
const char *str;
- str = _debug_get_option(name);
+ str = os_get_option(name);
if(!str)
result = dfault;
else if (!util_strcmp(str, "help")) {
@@ -389,7 +198,7 @@ void _debug_assert_fail(const char *expr,
#else
if (debug_get_bool_option("GALLIUM_ABORT_ON_ASSERT", TRUE))
#endif
- debug_break();
+ os_abort();
else
_debug_printf("continuing...\n");
}
@@ -631,6 +440,14 @@ const char *u_prim_name( unsigned prim )
#ifdef DEBUG
+/**
+ * Dump an image to a .raw or .ppm file (depends on OS).
+ * \param format PIPE_FORMAT_x
+ * \param cpp bytes per pixel
+ * \param width width in pixels
+ * \param height height in pixels
+ * \param stride row stride in bytes
+ */
void debug_dump_image(const char *prefix,
unsigned format, unsigned cpp,
unsigned width, unsigned height,
@@ -672,6 +489,52 @@ void debug_dump_image(const char *prefix,
}
EngUnmapFile(iFile);
+#elif defined(PIPE_OS_UNIX)
+ /* write a ppm file */
+ char filename[256];
+ FILE *f;
+
+ util_snprintf(filename, sizeof(filename), "%s.ppm", prefix);
+
+ f = fopen(filename, "w");
+ if (f) {
+ int i, x, y;
+ int r, g, b;
+ const uint8_t *ptr = (uint8_t *) data;
+
+ /* XXX this is a hack */
+ switch (format) {
+ case PIPE_FORMAT_A8R8G8B8_UNORM:
+ r = 2;
+ g = 1;
+ b = 0;
+ break;
+ default:
+ r = 0;
+ g = 1;
+ b = 1;
+ }
+
+ fprintf(f, "P6\n");
+ fprintf(f, "# ppm-file created by osdemo.c\n");
+ fprintf(f, "%i %i\n", width, height);
+ fprintf(f, "255\n");
+ fclose(f);
+
+ f = fopen(filename, "ab"); /* reopen in binary append mode */
+ for (y = 0; y < height; y++) {
+ for (x = 0; x < width; x++) {
+ i = y * stride + x * cpp;
+ fputc(ptr[i + r], f); /* write red */
+ fputc(ptr[i + g], f); /* write green */
+ fputc(ptr[i + b], f); /* write blue */
+ }
+ }
+ fclose(f);
+ }
+ else {
+ fprintf(stderr, "Can't open %s for writing\n", filename);
+ }
#endif
}
@@ -712,6 +575,27 @@ error:
}
+void debug_dump_texture(const char *prefix,
+ struct pipe_texture *texture)
+{
+ struct pipe_surface *surface;
+ struct pipe_screen *screen;
+
+ 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_TEXTURE_USAGE_SAMPLER);
+ if (surface) {
+ debug_dump_surface(prefix, surface);
+ screen->tex_surface_destroy(surface);
+ }
+}
+
+
#pragma pack(push,2)
struct bmp_file_header {
uint16_t bfType;
@@ -797,7 +681,7 @@ debug_dump_float_rgba_bmp(const char *filename,
float *rgba, unsigned stride)
{
#ifndef PIPE_SUBSYSTEM_WINDOWS_MINIPORT
- struct util_stream *stream;
+ struct os_stream *stream;
struct bmp_file_header bmfh;
struct bmp_info_header bmih;
unsigned x, y;
@@ -823,12 +707,12 @@ debug_dump_float_rgba_bmp(const char *filename,
bmih.biClrUsed = 0;
bmih.biClrImportant = 0;
- stream = util_stream_create(filename, bmfh.bfSize);
+ stream = os_stream_create(filename, bmfh.bfSize);
if(!stream)
goto error1;
- util_stream_write(stream, &bmfh, 14);
- util_stream_write(stream, &bmih, 40);
+ os_stream_write(stream, &bmfh, 14);
+ os_stream_write(stream, &bmih, 40);
y = height;
while(y--) {
@@ -840,11 +724,11 @@ debug_dump_float_rgba_bmp(const char *filename,
pixel.rgbGreen = float_to_ubyte(ptr[x*4 + 1]);
pixel.rgbBlue = float_to_ubyte(ptr[x*4 + 2]);
pixel.rgbAlpha = 255;
- util_stream_write(stream, &pixel, 4);
+ os_stream_write(stream, &pixel, 4);
}
}
- util_stream_close(stream);
+ os_stream_close(stream);
error1:
;
#endif