gldebug: implement a delayed debug system
[platform/upstream/gstreamer.git] / gst-libs / gst / gl / gstgldebug.h
1 /*
2  * GStreamer
3  * Copyright (C) 2015 Matthew Waters <matthew@centricular.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #ifndef __GST_GL_DEBUG_H__
22 #define __GST_GL_DEBUG_H__
23
24 #include <gst/gl/gl.h>
25
26 G_BEGIN_DECLS
27
28 typedef struct _GstGLAsyncDebug GstGLAsyncDebug;
29
30 typedef gchar * (*GstGLAsyncDebugLogGetMessage) (gpointer user_data);
31
32 /**
33  * GstGLAsyncDebug:
34  *
35  * #GstGLAsyncDebug an opaque structure and should only be accessed through the
36  * provided API.
37  */
38 struct _GstGLAsyncDebug
39 {
40   /* <private> */
41   guint             state_flags;
42   GstDebugCategory *cat;
43   GstDebugLevel     level;
44   const gchar      *file;
45   const gchar      *function;
46   gint              line;
47   GObject          *object;
48   gchar            *debug_msg;
49
50   /* <protected> */
51   GstGLAsyncDebugLogGetMessage callback;
52   gpointer          user_data;
53   GDestroyNotify    notify;
54 };
55
56 GstGLAsyncDebug *   gst_gl_async_debug_new                      (void);
57 void                gst_gl_async_debug_free                     (GstGLAsyncDebug * ad);
58 void                gst_gl_async_debug_init                     (GstGLAsyncDebug * ad);
59 void                gst_gl_async_debug_unset                    (GstGLAsyncDebug * ad);
60 void                gst_gl_async_debug_freeze                   (GstGLAsyncDebug * ad);
61 void                gst_gl_async_debug_thaw                     (GstGLAsyncDebug * ad);
62
63 /**
64  * GST_GL_ASYNC_CAT_LEVEL_LOG_valist:
65  * @ad: the #GstGLAsyncDebug to store the message in
66  * @cat: the #GstDebugCategory to output the message in
67  * @level: the #GstLevel
68  * @file: the file where the debug message originates from
69  * @function: the function where the debug message originates from
70  * @line: the line in @file where the debug message originates from
71  * @object: (allow-none): a #GObject to associate with the debug message
72  * @format: a printf style format string
73  * @varargs: the list of arguments for @format
74  *
75  * Stores a debug message in @ad for later output
76  */
77 #define GST_GL_ASYNC_CAT_LEVEL_LOG_valist(ad,cat,level,object,format,varargs)   \
78     gst_gl_async_debug_store_log_msg_valist (ad, cat, level, __FILE__,          \
79         GST_FUNCTION, __LINE__, object, format, varargs)
80
81 /**
82  * GST_GL_ASYNC_CAT_LEVEL_LOG:
83  * @ad: the #GstGLAsyncDebug to store the message in
84  * @cat: the #GstDebugCategory to output the message in
85  * @level: the #GstLevel
86  * @file: the file where the debug message originates from
87  * @function: the function where the debug message originates from
88  * @line: the line in @file where the debug message originates from
89  * @object: (allow-none): a #GObject to associate with the debug message
90  * @format: a printf style format string
91  * @...: the list of arguments for @format
92  *
93  * Stores a debug message in @ad for later output
94  */
95 #if G_HAVE_ISO_VARARGS
96 #define GST_GL_ASYNC_CAT_LEVEL_LOG(ad,cat,level,object,format,...)              \
97     gst_gl_async_debug_store_log_msg (ad, cat, level, __FILE__, GST_FUNCTION,   \
98         __LINE__, object, format, __VA_ARGS__)
99 #else /* G_HAVE_ISO_VARARGS */
100 #if G_HAVE_GNUC_VARARGS
101 #define GST_GL_ASYNC_CAT_LEVEL_LOG(ad,cat,level,object,format,args...)          \
102     gst_gl_async_debug_store_log_msg (ad, cat, level, __FILE__, GST_FUNCTION,   \
103         __LINE__, object, format, ##args)
104 #else /* G_HAVE_GNUC_VARARGS */
105 static inline void
106 GST_GL_ASYNC_CAT_LEVEL_LOG(GstGLAsyncDebug * ad, GstDebugCategory * cat,
107     GstDebugLevel level, GObject * object, const gchar * format, ...)
108 {
109   va_list varargs;
110
111   va_start (varargs, format);
112   GST_GL_ASYNC_CAT_LEVEL_LOG_valist (ad, cat, level, object, format, varargs);
113   va_end (varargs);
114 }
115 #endif /* G_HAVE_GNUC_VARARGS */
116 #endif /* G_HAVE_ISO_VARARGS */
117
118 #if !defined(GST_DISABLE_GST_DEBUG)
119
120 void        gst_gl_insert_debug_marker              (GstGLContext * context,
121                                                      const gchar * format, ...) G_GNUC_PRINTF (2, 3);
122 void        gst_gl_async_debug_output_log_msg       (GstGLAsyncDebug * ad);
123 void        gst_gl_async_debug_store_log_msg        (GstGLAsyncDebug * ad,
124                                                      GstDebugCategory * cat,
125                                                      GstDebugLevel level,
126                                                      const gchar * file,
127                                                      const gchar * function,
128                                                      gint line,
129                                                      GObject * object,
130                                                      const gchar * format, ...) G_GNUC_PRINTF (8, 9);
131 void        gst_gl_async_debug_store_log_msg_valist (GstGLAsyncDebug * ad,
132                                                      GstDebugCategory * cat,
133                                                      GstDebugLevel level,
134                                                      const gchar * file,
135                                                      const gchar * function,
136                                                      gint line,
137                                                      GObject * object,
138                                                      const gchar * format,
139                                                      va_list varargs) G_GNUC_PRINTF (8, 0);
140
141 #else /* GST_DISABLE_GST_DEBUG */
142
143 #define gst_gl_async_debug_output_log_msg(ad) G_STMT_START{ }G_STMT_END
144 #define gst_gl_async_debug_store_log_msg_valist(ad,cat,level,file,function,line,object,format,args) G_STMT_START{ }G_STMT_END
145
146 #if G_HAVE_ISO_VARARGS
147
148 #define gst_gl_insert_debug_marker(...) G_STMT_START{ }G_STMT_END
149 #define gst_gl_async_debug_store_log_msg(...) G_STMT_START{ }G_STMT_END
150
151 #else /* G_HAVE_ISO_VARARGS */
152 #if G_HAVE_GNUC_VARARGS
153
154 #define gst_gl_insert_debug_marker(args...) G_STMT_START{ }G_STMT_END
155 #define gst_gl_async_debug_store_log_msg(args...) G_STMT_START{ }G_STMT_END
156
157 #else /* G_HAVE_GNUC_VARARGS */
158
159 static inline void
160 gst_gl_insert_debug_marker (GstGLContext * context, const gchar * format, ...)
161 {
162 }
163
164 static inline void
165 gst_gl_async_debug_store_log_msg (GstGLAsyncDebug * ad,
166     GstDebugCategory * cat, GstDebugLevel level, const gchar * file,
167     const gchar * function, gint line, GstObject * object,
168     const gchar * format, ...)
169 {
170 }
171
172 #endif /* G_HAVE_GNUC_VARARGS */
173 #endif /* G_HAVE_ISO_VARARGS */
174 #endif /* GST_DISABLE_GST_DEBUG */
175
176 G_END_DECLS
177
178 #endif /* __GST_GL_DEBUG_H__ */