[Mesa-dev] [PATCH 09/21] mesa: refactor debug output get_msg
Chia-I Wu
olvaffe at gmail.com
Tue Apr 22 01:58:24 PDT 2014
Move message fetching to debug_fetch_message and message deletion to
debug_delete_messages.
Signed-off-by: Chia-I Wu <olv at lunarg.com>
---
src/mesa/main/errors.c | 61 +++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 50 insertions(+), 11 deletions(-)
diff --git a/src/mesa/main/errors.c b/src/mesa/main/errors.c
index 930e801..0d26285 100644
--- a/src/mesa/main/errors.c
+++ b/src/mesa/main/errors.c
@@ -346,6 +346,18 @@ debug_store_message(struct gl_debug_state *debug,
}
}
+static void
+debug_clear_message(struct gl_debug_state *debug,
+ struct gl_debug_msg *msg)
+{
+ (void) debug;
+
+ if (msg->message != (char*)out_of_memory)
+ free(msg->message);
+ msg->message = NULL;
+ msg->length = 0;
+}
+
/**
* 'buf' is not necessarily a null-terminated string. When logging, copy
* 'len' characters from it, store them in a new, null-terminated string,
@@ -380,6 +392,37 @@ debug_log_message(struct gl_debug_state *debug,
debug->NumMessages++;
}
+/**
+ * Return the oldest debug message out of the log.
+ */
+static const struct gl_debug_msg *
+debug_fetch_message(const struct gl_debug_state *debug)
+{
+ return (debug->NumMessages) ? &debug->Log[debug->NextMsg] : NULL;
+}
+
+/**
+ * Delete the oldest debug messages out of the log.
+ */
+static void
+debug_delete_messages(struct gl_debug_state *debug, unsigned count)
+{
+ if (count > debug->NumMessages)
+ count = debug->NumMessages;
+
+ while (count--) {
+ struct gl_debug_msg *msg = &debug->Log[debug->NextMsg];
+
+ assert(msg->length > 0 && msg->length == debug->NextMsgLength);
+ debug_clear_message(debug, msg);
+
+ debug->NumMessages--;
+ debug->NextMsg++;
+ debug->NextMsg %= MAX_DEBUG_LOGGED_MESSAGES;
+ debug->NextMsgLength = debug->Log[debug->NextMsg].length;
+ }
+}
+
/**
* Return debug state for the context. The debug state will be allocated
@@ -480,10 +523,14 @@ get_msg(struct gl_context *ctx, GLenum *source, GLenum *type,
GLuint *id, GLenum *severity, GLsizei bufSize, char *buf)
{
struct gl_debug_state *debug = _mesa_get_debug_state(ctx);
- struct gl_debug_msg *msg;
+ const struct gl_debug_msg *msg;
GLsizei length;
- if (!debug || debug->NumMessages == 0)
+ if (!debug)
+ return 0;
+
+ msg = debug_fetch_message(debug);
+ if (!msg)
return 0;
msg = &debug->Log[debug->NextMsg];
@@ -515,15 +562,7 @@ get_msg(struct gl_context *ctx, GLenum *source, GLenum *type,
(void) strncpy(buf, msg->message, (size_t)length);
}
- if (msg->message != (char*)out_of_memory)
- free(msg->message);
- msg->message = NULL;
- msg->length = 0;
-
- debug->NumMessages--;
- debug->NextMsg++;
- debug->NextMsg %= MAX_DEBUG_LOGGED_MESSAGES;
- debug->NextMsgLength = debug->Log[debug->NextMsg].length;
+ debug_delete_messages(debug, 1);
return length;
}
--
1.8.5.3
More information about the mesa-dev
mailing list