[Mesa-dev] [PATCH 01/18] mesa: refactor _mesa_get_debug_state

Chia-I Wu olvaffe at gmail.com
Fri Apr 25 03:41:54 PDT 2014


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

Signed-off-by: Chia-I Wu <olv at lunarg.com>
---
 src/mesa/main/errors.c | 62 ++++++++++++++++++++++++++++++--------------------
 1 file changed, 37 insertions(+), 25 deletions(-)

diff --git a/src/mesa/main/errors.c b/src/mesa/main/errors.c
index d80fda0..66d3146 100644
--- a/src/mesa/main/errors.c
+++ b/src/mesa/main/errors.c
@@ -181,6 +181,42 @@ enum {
    ENABLED = ENABLED_BIT | FOUND_BIT
 };
 
+/**
+ * Allocate and initialize context debug state.
+ */
+static struct gl_debug_state *
+debug_create(void)
+{
+   struct gl_debug_state *debug;
+   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. */
+   memset(debug->Defaults[0][MESA_DEBUG_SEVERITY_HIGH], GL_TRUE,
+         sizeof debug->Defaults[0][MESA_DEBUG_SEVERITY_HIGH]);
+   memset(debug->Defaults[0][MESA_DEBUG_SEVERITY_MEDIUM], GL_TRUE,
+         sizeof debug->Defaults[0][MESA_DEBUG_SEVERITY_MEDIUM]);
+   memset(debug->Defaults[0][MESA_DEBUG_SEVERITY_LOW], GL_FALSE,
+         sizeof debug->Defaults[0][MESA_DEBUG_SEVERITY_LOW]);
+
+   /* Initialize state for filtering known debug messages. */
+   for (s = 0; s < MESA_DEBUG_SOURCE_COUNT; s++) {
+      for (t = 0; t < MESA_DEBUG_TYPE_COUNT; t++) {
+         debug->Namespaces[0][s][t].IDs = _mesa_NewHashTable();
+         assert(debug->Namespaces[0][s][t].IDs);
+
+         for (sev = 0; sev < MESA_DEBUG_SEVERITY_COUNT; sev++) {
+            make_empty_list(&debug->Namespaces[0][s][t].Severity[sev]);
+         }
+      }
+   }
+
+   return debug;
+}
+
 
 /**
  * Return debug state for the context.  The debug state will be allocated
@@ -190,34 +226,10 @@ struct gl_debug_state *
 _mesa_get_debug_state(struct gl_context *ctx)
 {
    if (!ctx->Debug) {
-      ctx->Debug = CALLOC_STRUCT(gl_debug_state);
+      ctx->Debug = debug_create();
       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;
-
-         /* Enable all the messages with severity HIGH or MEDIUM by default. */
-         memset(debug->Defaults[0][MESA_DEBUG_SEVERITY_HIGH], GL_TRUE,
-                sizeof debug->Defaults[0][MESA_DEBUG_SEVERITY_HIGH]);
-         memset(debug->Defaults[0][MESA_DEBUG_SEVERITY_MEDIUM], GL_TRUE,
-                sizeof debug->Defaults[0][MESA_DEBUG_SEVERITY_MEDIUM]);
-         memset(debug->Defaults[0][MESA_DEBUG_SEVERITY_LOW], GL_FALSE,
-                sizeof debug->Defaults[0][MESA_DEBUG_SEVERITY_LOW]);
-
-         /* Initialize state for filtering known debug messages. */
-         for (s = 0; s < MESA_DEBUG_SOURCE_COUNT; s++) {
-            for (t = 0; t < MESA_DEBUG_TYPE_COUNT; t++) {
-               debug->Namespaces[0][s][t].IDs = _mesa_NewHashTable();
-               assert(debug->Namespaces[0][s][t].IDs);
-
-               for (sev = 0; sev < MESA_DEBUG_SEVERITY_COUNT; sev++) {
-                  make_empty_list(&debug->Namespaces[0][s][t].Severity[sev]);
-               }
-            }
-         }
-      }
    }
 
    return ctx->Debug;
-- 
1.8.5.3



More information about the mesa-dev mailing list