[cogl] Rework the debug messages

COGL has a debug message system like Clutter's own. In parallel,
it also uses a coupld of #defines. Spread around there are also
calls to printf() instead to the more correct g_log* wrappers.

This commit tries to unify and clean up the macros and the
debug message handling inside COGL to be more consistent.
This commit is contained in:
Emmanuele Bassi 2009-05-19 14:44:29 +01:00
parent e73a3899e5
commit cf4a49061a
6 changed files with 131 additions and 151 deletions

View File

@ -46,65 +46,59 @@ typedef struct _CoglHandleObject
/* Helper macro to encapsulate the common code for COGL reference
counted handles */
#if COGL_DEBUG
#ifdef COGL_HANDLE_DEBUG
#define _COGL_HANDLE_DEBUG_NEW(type_name, obj) \
printf ("COGL " G_STRINGIFY (type_name) " NEW %p %i\n", \
g_debug ("COGL " G_STRINGIFY (type_name) " NEW %p %i\n", \
(obj), (obj)->ref_count)
#define _COGL_HANDLE_DEBUG_REF(type_name, handle) \
do { \
CoglHandleObject *obj = (CoglHandleObject *)handle; \
printf ("COGL %s REF %p %i\n", \
g_quark_to_string ((obj)->klass->type), \
(obj), (obj)->ref_count); \
} while (0)
#define _COGL_HANDLE_DEBUG_REF(type_name, handle) G_STMT_START { \
CoglHandleObject *__obj = (CoglHandleObject *)handle; \
g_debug ("COGL %s REF %p %i\n", \
g_quark_to_string ((__obj)->klass->type), \
(__obj), (__obj)->ref_count); } G_STMT_END
#define _COGL_HANDLE_DEBUG_UNREF(type_name, handle) \
do { \
CoglHandleObject *obj = (CoglHandleObject *)handle; \
printf ("COGL %s UNREF %p %i\n", \
g_quark_to_string ((obj)->klass->type), \
(obj), (obj)->ref_count - 1); \
} while (0)
#define _COGL_HANDLE_DEBUG_UNREF(type_name, handle) G_STMT_START { \
CoglHandleObject *__obj = (CoglHandleObject *)handle; \
g_debug ("COGL %s UNREF %p %i\n", \
g_quark_to_string ((__obj)->klass->type), \
(__obj), (__obj)->ref_count - 1); } G_STMT_END
#define COGL_HANDLE_DEBUG_FREE(obj) \
printf ("COGL %s FREE %p\n", \
g_quark_to_string ((obj)->klass->type), (obj)) \
#define COGL_HANDLE_DEBUG_FREE(obj) \
g_debug ("COGL %s FREE %p\n", g_quark_to_string ((obj)->klass->type), (obj))
#else /* COGL_DEBUG */
#else /* !COGL_HANDLE_DEBUG */
#define _COGL_HANDLE_DEBUG_NEW(type_name, obj)
#define _COGL_HANDLE_DEBUG_REF(type_name, obj)
#define _COGL_HANDLE_DEBUG_UNREF(type_name, obj)
#define COGL_HANDLE_DEBUG_FREE(obj)
#endif /* COGL_DEBUG */
#endif /* COGL_HANDLE_DEBUG */
#define COGL_HANDLE_DEFINE(TypeName, type_name) \
\
static CoglHandleClass _cogl_##type_name##_class; \
static CoglHandleClass _cogl_##type_name##_class; \
\
static GQuark \
_cogl_##type_name##_get_type (void) \
{ \
static GQuark type = 0; \
if (!type) \
type = g_quark_from_static_string ("Cogl"#TypeName); \
return type; \
} \
static GQuark \
_cogl_##type_name##_get_type (void) \
{ \
static GQuark type = 0; \
if (!type) \
type = g_quark_from_static_string ("Cogl"#TypeName); \
return type; \
} \
\
static CoglHandle \
_cogl_##type_name##_handle_new (Cogl##TypeName *new_obj) \
{ \
CoglHandleObject *obj = &new_obj->_parent; \
obj->ref_count = 1; \
static CoglHandle \
_cogl_##type_name##_handle_new (Cogl##TypeName *new_obj) \
{ \
CoglHandleObject *obj = &new_obj->_parent; \
obj->ref_count = 1; \
\
obj->klass = &_cogl_##type_name##_class; \
if (!obj->klass->type) \
{ \
obj->klass->type = \
_cogl_##type_name##_get_type (); \
obj->klass = &_cogl_##type_name##_class; \
if (!obj->klass->type) \
{ \
obj->klass->type = _cogl_##type_name##_get_type (); \
obj->klass->virt_free = _cogl_##type_name##_free; \
} \
\
@ -112,51 +106,50 @@ typedef struct _CoglHandleObject
return (CoglHandle) new_obj; \
} \
\
Cogl##TypeName * \
_cogl_##type_name##_pointer_from_handle (CoglHandle handle) \
{ \
return (Cogl##TypeName *) handle; \
} \
Cogl##TypeName * \
_cogl_##type_name##_pointer_from_handle (CoglHandle handle) \
{ \
return (Cogl##TypeName *) handle; \
} \
\
gboolean \
cogl_is_##type_name (CoglHandle handle) \
{ \
CoglHandleObject *obj = (CoglHandleObject *)handle; \
gboolean \
cogl_is_##type_name (CoglHandle handle) \
{ \
CoglHandleObject *obj = (CoglHandleObject *)handle; \
\
if (handle == COGL_INVALID_HANDLE) \
return FALSE; \
if (handle == COGL_INVALID_HANDLE) \
return FALSE; \
\
return (obj->klass->type == \
_cogl_##type_name##_get_type ()); \
} \
return (obj->klass->type == _cogl_##type_name##_get_type ()); \
} \
\
CoglHandle G_GNUC_DEPRECATED \
cogl_##type_name##_ref (CoglHandle handle) \
{ \
if (!cogl_is_##type_name (handle)) \
return COGL_INVALID_HANDLE; \
CoglHandle G_GNUC_DEPRECATED \
cogl_##type_name##_ref (CoglHandle handle) \
{ \
if (!cogl_is_##type_name (handle)) \
return COGL_INVALID_HANDLE; \
\
_COGL_HANDLE_DEBUG_REF (TypeName, handle); \
_COGL_HANDLE_DEBUG_REF (TypeName, handle); \
\
cogl_handle_ref (handle); \
cogl_handle_ref (handle); \
\
return handle; \
} \
return handle; \
} \
\
void G_GNUC_DEPRECATED \
cogl_##type_name##_unref (CoglHandle handle) \
{ \
if (!cogl_is_##type_name (handle)) \
{ \
g_warning (G_STRINGIFY (cogl_##type_name##_unref) \
": Ignoring unref of Cogl handle " \
"due to type missmatch"); \
return; \
} \
void G_GNUC_DEPRECATED \
cogl_##type_name##_unref (CoglHandle handle) \
{ \
if (!cogl_is_##type_name (handle)) \
{ \
g_warning (G_STRINGIFY (cogl_##type_name##_unref) \
": Ignoring unref of Cogl handle " \
"due to type mismatch"); \
return; \
} \
\
_COGL_HANDLE_DEBUG_UNREF (TypeName, handle); \
_COGL_HANDLE_DEBUG_UNREF (TypeName, handle); \
\
cogl_handle_unref (handle); \
}
cogl_handle_unref (handle); \
}
#endif /* __COGL_HANDLE_H */

View File

@ -49,29 +49,28 @@ typedef struct _CoglBoxedValue
} CoglBoxedValue;
#endif
#define COGL_DEBUG 0
/* XXX - set to 1 to enable checks on every GL call */
#define COGL_GL_DEBUG 0
#if COGL_DEBUG
#include <stdio.h>
#if COGL_GL_DEBUG
const gchar *cogl_gl_error_to_string (GLenum error_code);
#define GE(x...) G_STMT_START { \
GLenum __err; \
(x); \
while ((err = glGetError ()) != GL_NO_ERROR) \
{ \
g_warning ("%s: GL error (%d): %s\n", \
G_STRLOC, \
cogl_gl_error_to_string (err));\
} } G_STMT_END
#define GE(x...) G_STMT_START { \
GLenum __err; \
(x); \
while ((__err = glGetError ()) != GL_NO_ERROR) \
{ \
g_warning ("%s: GL error (%d): %s\n", \
G_STRLOC, \
cogl_gl_error_to_string (__err)); \
} } G_STMT_END
#else /* COGL_DEBUG */
#else /* !COGL_GL_DEBUG */
#define GE(x) (x)
#endif /* COGL_DEBUG */
#endif /* COGL_GL_DEBUG */
#define COGL_ENABLE_BLEND (1<<1)
#define COGL_ENABLE_ALPHA_TEST (1<<2)
@ -79,16 +78,10 @@ const gchar *cogl_gl_error_to_string (GLenum error_code);
#define COGL_ENABLE_COLOR_ARRAY (1<<4)
#define COGL_ENABLE_BACKFACE_CULLING (1<<5)
void
_cogl_features_init (void);
void _cogl_features_init (void);
gint _cogl_get_format_bpp (CoglPixelFormat format);
gint
_cogl_get_format_bpp (CoglPixelFormat format);
void
cogl_enable (gulong flags);
gulong
cogl_get_enable ();
void cogl_enable (gulong flags);
gulong cogl_get_enable (void);
#endif /* __COGL_INTERNAL_H */

View File

@ -372,9 +372,7 @@ _cogl_texture_sliced_quad (CoglTexture *tex,
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
#if COGL_DEBUG
printf("=== Drawing Tex Quad (Sliced Mode) ===\n");
#endif
COGL_NOTE (DRAW, "Drawing Tex Quad (Sliced Mode)");
/* We can't use hardware repeat so we need to set clamp to edge
otherwise it might pull in edge pixels from the other side */
@ -485,17 +483,21 @@ _cogl_texture_sliced_quad (CoglTexture *tex,
slice_tx2 /= iter_x.span->size;
}
#if COGL_DEBUG
printf("~~~~~ slice (%d,%d)\n", iter_x.index, iter_y.index);
printf("qx1: %f\n", (slice_qx1));
printf("qy1: %f\n", (slice_qy1));
printf("qx2: %f\n", (slice_qx2));
printf("qy2: %f\n", (slice_qy2));
printf("tx1: %f\n", (slice_tx1));
printf("ty1: %f\n", (slice_ty1));
printf("tx2: %f\n", (slice_tx2));
printf("ty2: %f\n", (slice_ty2));
#endif
COGL_NOTE (DRAW,
"~~~~~ slice (%d, %d)\n"
"qx1: %f\t"
"qy1: %f\n"
"qx2: %f\t"
"qy2: %f\n"
"tx1: %f\t"
"ty1: %f\n"
"tx2: %f\t"
"ty2: %f\n",
iter_x.index, iter_y.index,
slice_qx1, slice_qy1,
slice_qx2, slice_qy2,
slice_tx1, slice_ty1,
slice_tx2, slice_ty2);
/* Pick and bind opengl texture object */
gl_handle = g_array_index (tex->slice_gl_handles, GLuint,

View File

@ -38,6 +38,7 @@
typedef CoglFuncPtr (*GLXGetProcAddressProc) (const guint8 *procName);
#endif
#include "cogl-debug.h"
#include "cogl-internal.h"
#include "cogl-util.h"
#include "cogl-context.h"
@ -46,7 +47,7 @@ typedef CoglFuncPtr (*GLXGetProcAddressProc) (const guint8 *procName);
#include "cogl-gles2-wrapper.h"
#endif
#ifdef COGL_DEBUG
#ifdef COGL_GL_DEBUG
/* GL error to string conversion */
static const struct {
GLuint error_code;
@ -78,18 +79,16 @@ cogl_gl_error_to_string (GLenum error_code)
return gl_errors[i].error_string;
}
return "Unknown error";
return "Unknown GL error";
}
#endif /* COGL_DEBUG */
#endif /* COGL_GL_DEBUG */
void
cogl_clear (const CoglColor *color, gulong buffers)
{
GLbitfield gl_buffers = 0;
#if COGL_DEBUG
fprintf(stderr, "\n ============== Paint Start ================ \n");
#endif
COGL_NOTE (DRAW, "Clear begin");
cogl_clip_ensure ();
@ -101,20 +100,29 @@ cogl_clear (const CoglColor *color, gulong buffers)
0.0) );
gl_buffers |= GL_COLOR_BUFFER_BIT;
}
if (buffers & COGL_BUFFER_BIT_DEPTH)
gl_buffers |= GL_DEPTH_BUFFER_BIT;
if (buffers & COGL_BUFFER_BIT_STENCIL)
gl_buffers |= GL_STENCIL_BUFFER_BIT;
if (!gl_buffers)
{
static gboolean shown = FALSE;
if (!shown)
g_warning ("You should specify at least one auxiliary buffer when calling cogl_clear");
{
g_warning ("You should specify at least one auxiliary buffer "
"when calling cogl_clear");
}
return;
}
glClear (gl_buffers);
COGL_NOTE (DRAW, "Clear end");
}
static inline gboolean
@ -563,24 +571,31 @@ cogl_get_viewport (float v[4])
}
void
cogl_get_bitmasks (gint *red, gint *green, gint *blue, gint *alpha)
cogl_get_bitmasks (gint *red,
gint *green,
gint *blue,
gint *alpha)
{
GLint value;
if (red)
{
GE( glGetIntegerv(GL_RED_BITS, &value) );
*red = value;
}
if (green)
{
GE( glGetIntegerv(GL_GREEN_BITS, &value) );
*green = value;
}
if (blue)
{
GE( glGetIntegerv(GL_BLUE_BITS, &value) );
*blue = value;
}
if (alpha)
{
GE( glGetIntegerv(GL_ALPHA_BITS, &value ) );

View File

@ -44,17 +44,6 @@
#include <stdlib.h>
#include <math.h>
/*
#define COGL_DEBUG 1
#define GE(x) \
{ \
glGetError(); x; \
GLuint err = glGetError(); \
if (err != 0) \
printf("err: 0x%x\n", err); \
} */
#ifdef HAVE_COGL_GL
#define glDrawRangeElements ctx->pf_glDrawRangeElements
@ -943,12 +932,11 @@ _cogl_texture_slices_create (CoglTexture *tex)
{
x_span = &g_array_index (tex->slice_x_spans, CoglTexSliceSpan, x);
#if COGL_DEBUG
printf ("CREATE SLICE (%d,%d)\n", x,y);
printf ("size: (%d x %d)\n",
x_span->size - x_span->waste,
y_span->size - y_span->waste);
#endif
COGL_NOTE (TEXTURE, "CREATE SLICE (%d,%d)\tsize (%d,%d)",
x, y,
x_span->size - x_span->waste,
y_span->size - y_span->waste);
/* Setup texture parameters */
GE( glBindTexture (tex->gl_target,
gl_handles[y * n_x_slices + x]) );

View File

@ -40,17 +40,6 @@
#include <stdlib.h>
#include <math.h>
/*
#define COGL_DEBUG 1
#define GE(x) \
{ \
glGetError(); x; \
GLuint err = glGetError(); \
if (err != 0) \
printf("err: 0x%x\n", err); \
} */
extern void _cogl_journal_flush (void);
static void _cogl_texture_free (CoglTexture *tex);