summaryrefslogtreecommitdiff
path: root/src/mapi/glapi/glapi_dispatch.c
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@bitplanet.net>2010-09-09 12:59:14 -0400
committerKristian Høgsberg <krh@bitplanet.net>2010-09-09 13:21:15 -0400
commitb9abc6139a310677a37754ea7172d976dbf56979 (patch)
treedd42377907938fe8a5e9eb3c24ec3df678a0fe25 /src/mapi/glapi/glapi_dispatch.c
parent94118fe2d4b1e5d0b9f39d9d2c44706db462e97e (diff)
glapi: Implement optional dispatch logging
There's a useful feature buried in glapi to log all API calls to stderr. Unfortunately it requires editing the code and then it's enabled unconditionally for that build. This patch builds in API logging for debug builds and makes it run-time switchable by setting MESA_DEBUG=dispatch.
Diffstat (limited to 'src/mapi/glapi/glapi_dispatch.c')
-rw-r--r--src/mapi/glapi/glapi_dispatch.c80
1 files changed, 64 insertions, 16 deletions
diff --git a/src/mapi/glapi/glapi_dispatch.c b/src/mapi/glapi/glapi_dispatch.c
index 7421a36d35..0d41c9499b 100644
--- a/src/mapi/glapi/glapi_dispatch.c
+++ b/src/mapi/glapi/glapi_dispatch.c
@@ -41,7 +41,6 @@
#include "glapi/glapitable.h"
#include "glapi/glapidispatch.h"
-
#if !(defined(USE_X86_ASM) || defined(USE_X86_64_ASM) || defined(USE_SPARC_ASM))
#if defined(WIN32)
@@ -58,27 +57,12 @@
#define NAME(func) gl##func
#endif
-#if 0 /* Use this to log GL calls to stdout (for DEBUG only!) */
-
-#define F stdout
-#define DISPATCH(FUNC, ARGS, MESSAGE) \
- fprintf MESSAGE; \
- CALL_ ## FUNC(GET_DISPATCH(), ARGS);
-
-#define RETURN_DISPATCH(FUNC, ARGS, MESSAGE) \
- fprintf MESSAGE; \
- return CALL_ ## FUNC(GET_DISPATCH(), ARGS);
-
-#else
-
#define DISPATCH(FUNC, ARGS, MESSAGE) \
CALL_ ## FUNC(GET_DISPATCH(), ARGS);
#define RETURN_DISPATCH(FUNC, ARGS, MESSAGE) \
return CALL_ ## FUNC(GET_DISPATCH(), ARGS);
-#endif /* logging */
-
#ifndef GLAPIENTRY
#define GLAPIENTRY
@@ -91,3 +75,67 @@
#include "glapi/glapitemp.h"
#endif /* USE_X86_ASM */
+
+
+#ifdef DEBUG
+
+static void *logger_data;
+static void (*logger_func)(void *data, const char *fmt, ...);
+static struct _glapi_table *real_dispatch; /* FIXME: This need to be TLS etc */
+
+#define KEYWORD1 static
+#define KEYWORD1_ALT static
+#define KEYWORD2
+#define NAME(func) log_##func
+#define F logger_data
+
+static void
+log_Unused(void)
+{
+}
+
+#define DISPATCH(FUNC, ARGS, MESSAGE) \
+ logger_func MESSAGE; \
+ CALL_ ## FUNC(real_dispatch, ARGS);
+
+#define RETURN_DISPATCH(FUNC, ARGS, MESSAGE) \
+ logger_func MESSAGE; \
+ return CALL_ ## FUNC(real_dispatch, ARGS);
+
+#define DISPATCH_TABLE_NAME __glapi_logging_table
+
+#define TABLE_ENTRY(func) (_glapi_proc) log_##func
+
+#include "glapi/glapitemp.h"
+
+int
+_glapi_logging_available(void)
+{
+ return 1;
+}
+
+void
+_glapi_enable_logging(void (*func)(void *data, const char *fmt, ...),
+ void *data)
+{
+ real_dispatch = GET_DISPATCH();
+ logger_func = func;
+ logger_data = data;
+ _glapi_set_dispatch(&__glapi_logging_table);
+}
+
+#else
+
+int
+_glapi_logging_available(void)
+{
+ return 0
+}
+
+void
+_glapi_enable_logging(void (*func)(void *data, const char *fmt, ...),
+ void *data)
+{
+}
+
+#endif