#include <stdio.h>
#include "context.h"
#include "debug_output.h"
-#include "dispatch.h"
#include "enums.h"
#include "imports.h"
#include "hash.h"
#include "util/simple_list.h"
-static mtx_t DynamicIDMutex = _MTX_INITIALIZER_NP;
+static simple_mtx_t DynamicIDMutex = _SIMPLE_MTX_INITIALIZER_NP;
static GLuint NextDynamicID = 1;
const void *CallbackData;
GLboolean SyncOutput;
GLboolean DebugOutput;
+ GLboolean LogToStderr;
struct gl_debug_group *Groups[MAX_DEBUG_GROUP_STACK_DEPTH];
struct gl_debug_message GroupMessages[MAX_DEBUG_GROUP_STACK_DEPTH];
_mesa_debug_get_id(GLuint *id)
{
if (!(*id)) {
- mtx_lock(&DynamicIDMutex);
+ simple_mtx_lock(&DynamicIDMutex);
if (!(*id))
*id = NextDynamicID++;
- mtx_unlock(&DynamicIDMutex);
+ simple_mtx_unlock(&DynamicIDMutex);
}
}
debug->Groups[gstack] = NULL;
}
+/**
+ * Delete the oldest debug messages out of the log.
+ */
+static void
+debug_delete_messages(struct gl_debug_state *debug, int count)
+{
+ struct gl_debug_log *log = &debug->Log;
+
+ if (count > log->NumMessages)
+ count = log->NumMessages;
+
+ while (count--) {
+ struct gl_debug_message *msg = &log->Messages[log->NextMessage];
+
+ debug_message_clear(msg);
+
+ log->NumMessages--;
+ log->NextMessage++;
+ log->NextMessage %= MAX_DEBUG_LOGGED_MESSAGES;
+ }
+}
+
/**
* Loop through debug group stack tearing down states for
* filtering debug messages. Then free debug output state.
}
debug_clear_group(debug);
+ debug_delete_messages(debug, debug->Log.NumMessages);
free(debug);
}
GLint nextEmpty;
struct gl_debug_message *emptySlot;
+ if (debug->LogToStderr) {
+ _mesa_log("Mesa debug output: %.*s\n", len, buf);
+ }
+
assert(len < MAX_DEBUG_MESSAGE_LENGTH);
if (log->NumMessages == MAX_DEBUG_LOGGED_MESSAGES)
return (log->NumMessages) ? &log->Messages[log->NextMessage] : NULL;
}
-/**
- * Delete the oldest debug messages out of the log.
- */
-static void
-debug_delete_messages(struct gl_debug_state *debug, int count)
-{
- struct gl_debug_log *log = &debug->Log;
-
- if (count > log->NumMessages)
- count = log->NumMessages;
-
- while (count--) {
- struct gl_debug_message *msg = &log->Messages[log->NextMessage];
-
- debug_message_clear(msg);
-
- log->NumMessages--;
- log->NextMessage++;
- log->NextMessage %= MAX_DEBUG_LOGGED_MESSAGES;
- }
-}
-
static struct gl_debug_message *
debug_get_group_message(struct gl_debug_state *debug)
{
static struct gl_debug_state *
_mesa_lock_debug_state(struct gl_context *ctx)
{
- mtx_lock(&ctx->DebugMutex);
+ simple_mtx_lock(&ctx->DebugMutex);
if (!ctx->Debug) {
ctx->Debug = debug_create();
if (!ctx->Debug) {
GET_CURRENT_CONTEXT(cur);
- mtx_unlock(&ctx->DebugMutex);
+ simple_mtx_unlock(&ctx->DebugMutex);
/*
* This function may be called from other threads. When that is the
static void
_mesa_unlock_debug_state(struct gl_context *ctx)
{
- mtx_unlock(&ctx->DebugMutex);
+ simple_mtx_unlock(&ctx->DebugMutex);
}
/**
GLint
_mesa_get_debug_state_int(struct gl_context *ctx, GLenum pname)
{
- struct gl_debug_state *debug;
GLint val;
- mtx_lock(&ctx->DebugMutex);
- debug = ctx->Debug;
- if (!debug) {
- mtx_unlock(&ctx->DebugMutex);
+ struct gl_debug_state *debug = _mesa_lock_debug_state(ctx);
+ if (!debug)
return 0;
- }
switch (pname) {
case GL_DEBUG_OUTPUT:
break;
case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
val = (debug->Log.NumMessages) ?
- debug->Log.Messages[debug->Log.NextMessage].length : 0;
+ debug->Log.Messages[debug->Log.NextMessage].length + 1 : 0;
break;
case GL_DEBUG_GROUP_STACK_DEPTH:
val = debug->CurrentGroup + 1;
break;
}
- mtx_unlock(&ctx->DebugMutex);
+ _mesa_unlock_debug_state(ctx);
return val;
}
void *
_mesa_get_debug_state_ptr(struct gl_context *ctx, GLenum pname)
{
- struct gl_debug_state *debug;
void *val;
+ struct gl_debug_state *debug = _mesa_lock_debug_state(ctx);
- mtx_lock(&ctx->DebugMutex);
- debug = ctx->Debug;
- if (!debug) {
- mtx_unlock(&ctx->DebugMutex);
+ if (!debug)
return NULL;
- }
switch (pname) {
case GL_DEBUG_CALLBACK_FUNCTION_ARB:
break;
}
- mtx_unlock(&ctx->DebugMutex);
+ _mesa_unlock_debug_state(ctx);
return val;
}
}
if (ctx->Debug->Callback) {
+ /* Call the user's callback function */
GLenum gl_source = debug_source_enums[source];
GLenum gl_type = debug_type_enums[type];
GLenum gl_severity = debug_severity_enums[severity];
callback(gl_source, gl_type, id, gl_severity, len, buf, data);
}
else {
+ /* add debug message to queue */
debug_log_message(ctx->Debug, source, type, id, severity, len, buf);
_mesa_unlock_debug_state(ctx);
}
if (!validate_length(ctx, callerstr, length, buf))
return; /* GL_INVALID_VALUE */
+ /* if length not specified, string will be null terminated: */
+ if (length < 0)
+ length = strlen(buf);
+
_mesa_log_msg(ctx, gl_enum_to_debug_source(source),
gl_enum_to_debug_type(type), id,
gl_enum_to_debug_severity(severity),
length, buf);
if (type == GL_DEBUG_TYPE_MARKER && ctx->Driver.EmitStringMarker) {
- /* if length not specified, string will be null terminated: */
- if (length < 0)
- length = strlen(buf);
ctx->Driver.EmitStringMarker(ctx, buf, length);
}
}
if (!validate_length(ctx, callerstr, length, message))
return; /* GL_INVALID_VALUE */
+ if (length < 0)
+ length = strlen(message);
+
debug = _mesa_lock_debug_state(ctx);
if (!debug)
return;
void
_mesa_init_debug_output(struct gl_context *ctx)
{
- mtx_init(&ctx->DebugMutex, mtx_plain);
+ simple_mtx_init(&ctx->DebugMutex, mtx_plain);
+
+ if (MESA_DEBUG_FLAGS & DEBUG_CONTEXT) {
+ /* If the MESA_DEBUG env is set to "context", we'll turn on the
+ * GL_CONTEXT_FLAG_DEBUG_BIT context flag and log debug output
+ * messages to stderr (or whatever MESA_LOG_FILE points at).
+ */
+ struct gl_debug_state *debug = _mesa_lock_debug_state(ctx);
+ if (!debug) {
+ return;
+ }
+ debug->DebugOutput = GL_TRUE;
+ debug->LogToStderr = GL_TRUE;
+ ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_DEBUG_BIT;
+ _mesa_unlock_debug_state(ctx);
+ }
}
ctx->Debug = NULL;
}
- mtx_destroy(&ctx->DebugMutex);
+ simple_mtx_destroy(&ctx->DebugMutex);
}
void GLAPIENTRY