From 7dcdb1d29c52a623d87c623a199ef29e982050ba Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Tue, 16 Feb 2016 13:58:42 +1100 Subject: [PATCH] glcontext: don't enable GL debug for messages that won't be logged This is an optimization to avoid pointless string processing. --- gst-libs/gst/gl/gstglcontext.c | 16 +++------- gst-libs/gst/gl/gstgldebug.c | 70 +++++++++++++++++++++++++++++++++++++----- 2 files changed, 67 insertions(+), 19 deletions(-) diff --git a/gst-libs/gst/gl/gstglcontext.c b/gst-libs/gst/gl/gstglcontext.c index 48a5387..88526bd 100644 --- a/gst-libs/gst/gl/gstglcontext.c +++ b/gst-libs/gst/gl/gstglcontext.c @@ -67,9 +67,7 @@ #include "eagl/gstglcontext_eagl.h" #endif -extern void GSTGLAPI _gst_gl_debug_callback (GLenum source, GLenum type, - GLuint id, GLenum severity, GLsizei length, const gchar * message, - gpointer user_data); +extern void _gst_gl_debug_enable (GstGLContext * context); static GPrivate current_context_key; @@ -186,6 +184,7 @@ _context_share_group_is_shared (struct ContextShareGroup *share) #define GST_CAT_DEFAULT gst_gl_context_debug GST_DEBUG_CATEGORY (GST_CAT_DEFAULT); +GST_DEBUG_CATEGORY_STATIC (gst_gl_debug); #define gst_gl_context_parent_class parent_class G_DEFINE_ABSTRACT_TYPE (GstGLContext, gst_gl_context, GST_TYPE_OBJECT); @@ -303,6 +302,7 @@ _init_debug (void) if (g_once_init_enter (&_init)) { GST_DEBUG_CATEGORY_INIT (gst_gl_context_debug, "glcontext", 0, "glcontext element"); + GST_DEBUG_CATEGORY_INIT (gst_gl_debug, "gldebug", 0, "OpenGL Debugging"); g_once_init_leave (&_init, 1); } } @@ -1086,7 +1086,6 @@ gst_gl_context_create_thread (GstGLContext * context) { GstGLContextClass *context_class; GstGLWindowClass *window_class; - GstGLFuncs *gl; GstGLAPI compiled_api, user_api, gl_api, display_api; gchar *api_string; gchar *compiled_api_s; @@ -1122,7 +1121,6 @@ gst_gl_context_create_thread (GstGLContext * context) } } - gl = context->gl_vtable; compiled_api = _compiled_api (); compiled_api_s = gst_gl_api_to_string (compiled_api); @@ -1210,15 +1208,9 @@ gst_gl_context_create_thread (GstGLContext * context) context->priv->alive = TRUE; - if (gl->DebugMessageCallback) { #if !defined(GST_DISABLE_GST_DEBUG) - GST_INFO_OBJECT (context, "Enabling GL context debugging"); - /* enable them all */ - gl->DebugMessageControl (GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, 0, - GL_TRUE); - gl->DebugMessageCallback (_gst_gl_debug_callback, context); + _gst_gl_debug_enable (context); #endif - } if (other_context) { GST_DEBUG_OBJECT (context, "Unreffing other_context %" GST_PTR_FORMAT, diff --git a/gst-libs/gst/gl/gstgldebug.c b/gst-libs/gst/gl/gstgldebug.c index 2d8bbca..1244025 100644 --- a/gst-libs/gst/gl/gstgldebug.c +++ b/gst-libs/gst/gl/gstgldebug.c @@ -89,6 +89,7 @@ GST_DEBUG_CATEGORY_STATIC (gst_performance); #define GST_CAT_DEFAULT gst_gl_debug GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT); GST_DEBUG_CATEGORY_STATIC (default_debug); +GST_DEBUG_CATEGORY_STATIC (gst_gl_marker_debug); static void _init_debug (void) @@ -97,8 +98,10 @@ _init_debug (void) if (g_once_init_enter (&_init)) { GST_DEBUG_CATEGORY_GET (gst_performance, "GST_PERFORMANCE"); - GST_DEBUG_CATEGORY_INIT (gst_gl_debug, "gldebug", 0, "OpenGL Debugging"); + GST_DEBUG_CATEGORY_GET (gst_gl_debug, "gldebug"); GST_DEBUG_CATEGORY_GET (default_debug, "default"); + GST_DEBUG_CATEGORY_INIT (gst_gl_marker_debug, "gldebugmarker", 0, + "OpenGL Markers"); g_once_init_leave (&_init, 1); } } @@ -238,12 +241,7 @@ _debug_type_to_string (GLenum type) } } -/* silence the compiler... */ -G_GNUC_INTERNAL void GSTGLAPI _gst_gl_debug_callback (GLenum source, - GLenum type, GLuint id, GLenum severity, GLsizei length, - const gchar * message, gpointer user_data); - -void GSTGLAPI +static void GSTGLAPI _gst_gl_debug_callback (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const gchar * message, gpointer user_data) { @@ -276,6 +274,58 @@ _gst_gl_debug_callback (GLenum source, GLenum type, GLuint id, GLenum severity, } } +G_GNUC_INTERNAL void _gst_gl_debug_enable (GstGLContext * context); + +G_GNUC_INTERNAL void +_gst_gl_debug_enable (GstGLContext * context) +{ + const GstGLFuncs *gl = context->gl_vtable; + GstDebugLevel level; + GLenum debug_types[8]; + guint i, n = 0; + + _init_debug (); + + if (!gl->DebugMessageCallback) { + GST_CAT_INFO_OBJECT (gst_gl_context_debug, context, + "No debugging support available"); + return; + } + + level = gst_debug_category_get_threshold (gst_gl_debug); + g_print ("level: %u\n", level); + + if (level < GST_LEVEL_ERROR) { + GST_CAT_INFO_OBJECT (gst_gl_context_debug, context, + "Disabling GL context debugging (gldebug category debug level < error)"); + return; + } + + GST_CAT_INFO_OBJECT (gst_gl_context_debug, context, + "Enabling GL context debugging"); + + gl->DebugMessageCallback (_gst_gl_debug_callback, context); + if (level >= GST_LEVEL_DEBUG) { + /* enable them all */ + gl->DebugMessageControl (GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, 0, + GL_TRUE); + } else { + if (level >= GST_LEVEL_FIXME) { + debug_types[n++] = GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR; + debug_types[n++] = GL_DEBUG_TYPE_PORTABILITY; + } + if (level >= GST_LEVEL_ERROR) { + debug_types[n++] = GL_DEBUG_TYPE_ERROR; + debug_types[n++] = GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR; + } + g_assert (n < G_N_ELEMENTS (debug_types)); + for (i = 0; i < n; i++) { + gl->DebugMessageControl (GL_DONT_CARE, debug_types[i], GL_DONT_CARE, + 0, 0, GL_TRUE); + } + } +} + void gst_gl_insert_debug_marker (GstGLContext * context, const gchar * format, ...) { @@ -284,6 +334,10 @@ gst_gl_insert_debug_marker (GstGLContext * context, const gchar * format, ...) gint len; va_list args; + /* are we enabled */ + if (gst_debug_category_get_threshold (gst_gl_marker_debug) < GST_LEVEL_FIXME) + return; + va_start (args, format); len = gst_info_vasprintf (&string, format, args); va_end (args); @@ -398,4 +452,6 @@ gst_gl_async_debug_store_log_msg (GstGLAsyncDebug * ad, GstDebugCategory * cat, va_end (varargs); } } +#else +G_GNUC_INTERNAL void _gst_gl_debug_enable (GstGLContext * context); #endif -- 2.7.4