mesa: refactor _mesa_get_debug_state

Move gl_debug_state allocation to a new function, debug_create.  No functional
change.

Signed-off-by: Chia-I Wu <olv@lunarg.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
This commit is contained in:
Chia-I Wu
2014-04-22 10:10:30 +08:00
parent 9339f8ac1b
commit 672b209225

View File

@@ -181,23 +181,19 @@ enum {
ENABLED = ENABLED_BIT | FOUND_BIT ENABLED = ENABLED_BIT | FOUND_BIT
}; };
/** /**
* Return debug state for the context. The debug state will be allocated * Allocate and initialize context debug state.
* and initialized upon the first call.
*/ */
struct gl_debug_state * static struct gl_debug_state *
_mesa_get_debug_state(struct gl_context *ctx) debug_create(void)
{ {
if (!ctx->Debug) { struct gl_debug_state *debug;
ctx->Debug = CALLOC_STRUCT(gl_debug_state);
if (!ctx->Debug) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "allocating debug state");
}
else {
struct gl_debug_state *debug = ctx->Debug;
int s, t, sev; int s, t, sev;
debug = CALLOC_STRUCT(gl_debug_state);
if (!debug)
return NULL;
/* Enable all the messages with severity HIGH or MEDIUM by default. */ /* Enable all the messages with severity HIGH or MEDIUM by default. */
memset(debug->Defaults[0][MESA_DEBUG_SEVERITY_HIGH], GL_TRUE, memset(debug->Defaults[0][MESA_DEBUG_SEVERITY_HIGH], GL_TRUE,
sizeof debug->Defaults[0][MESA_DEBUG_SEVERITY_HIGH]); sizeof debug->Defaults[0][MESA_DEBUG_SEVERITY_HIGH]);
@@ -217,6 +213,22 @@ _mesa_get_debug_state(struct gl_context *ctx)
} }
} }
} }
return debug;
}
/**
* Return debug state for the context. The debug state will be allocated
* and initialized upon the first call.
*/
struct gl_debug_state *
_mesa_get_debug_state(struct gl_context *ctx)
{
if (!ctx->Debug) {
ctx->Debug = debug_create();
if (!ctx->Debug) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "allocating debug state");
} }
} }