2009-04-27 14:48:12 +00:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
|
|
|
* An object oriented GL/GLES Abstraction/Utility Layer
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Intel Corporation.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2010-03-01 12:56:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
2009-04-27 14:48:12 +00:00
|
|
|
*/
|
|
|
|
|
2009-02-23 12:47:02 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2010-02-17 14:38:11 +00:00
|
|
|
#include <stdlib.h>
|
2009-02-23 12:47:02 +00:00
|
|
|
#include <glib/gi18n-lib.h>
|
|
|
|
|
2011-06-14 21:33:44 +00:00
|
|
|
#include "cogl.h"
|
|
|
|
#include "cogl-private.h"
|
2009-02-23 12:47:02 +00:00
|
|
|
#include "cogl-debug.h"
|
|
|
|
|
2010-12-03 12:01:18 +00:00
|
|
|
/* XXX: If you add a debug option, please also add an option
|
|
|
|
* definition to cogl-debug-options.h. This will enable us - for
|
|
|
|
* example - to emit a "help" description for the option.
|
2010-02-17 14:38:11 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* NB: Only these options get enabled if COGL_DEBUG=all is
|
|
|
|
* used since they don't affect the behaviour of Cogl they
|
|
|
|
* simply print out verbose information */
|
|
|
|
static const GDebugKey cogl_log_debug_keys[] = {
|
|
|
|
{ "handle", COGL_DEBUG_HANDLE },
|
|
|
|
{ "slicing", COGL_DEBUG_SLICING },
|
|
|
|
{ "atlas", COGL_DEBUG_ATLAS },
|
|
|
|
{ "blend-strings", COGL_DEBUG_BLEND_STRINGS },
|
|
|
|
{ "journal", COGL_DEBUG_JOURNAL },
|
|
|
|
{ "batching", COGL_DEBUG_BATCHING },
|
|
|
|
{ "matrices", COGL_DEBUG_MATRICES },
|
2009-02-28 16:03:11 +00:00
|
|
|
{ "draw", COGL_DEBUG_DRAW },
|
2010-02-17 18:45:08 +00:00
|
|
|
{ "opengl", COGL_DEBUG_OPENGL },
|
2009-04-17 14:10:55 +00:00
|
|
|
{ "pango", COGL_DEBUG_PANGO },
|
2010-05-26 16:14:53 +00:00
|
|
|
{ "show-source", COGL_DEBUG_SHOW_SOURCE},
|
2010-05-25 17:56:14 +00:00
|
|
|
{ "offscreen", COGL_DEBUG_OFFSCREEN },
|
2010-07-15 12:02:23 +00:00
|
|
|
{ "texture-pixmap", COGL_DEBUG_TEXTURE_PIXMAP },
|
2011-01-24 16:36:56 +00:00
|
|
|
{ "bitmap", COGL_DEBUG_BITMAP },
|
2012-02-07 16:53:12 +00:00
|
|
|
{ "clipping", COGL_DEBUG_CLIPPING },
|
|
|
|
{ "winsys", COGL_DEBUG_WINSYS }
|
2010-02-17 14:38:11 +00:00
|
|
|
};
|
|
|
|
static const int n_cogl_log_debug_keys =
|
|
|
|
G_N_ELEMENTS (cogl_log_debug_keys);
|
|
|
|
|
|
|
|
static const GDebugKey cogl_behavioural_debug_keys[] = {
|
2009-05-19 15:00:18 +00:00
|
|
|
{ "rectangles", COGL_DEBUG_RECTANGLES },
|
2009-06-05 12:50:00 +00:00
|
|
|
{ "disable-batching", COGL_DEBUG_DISABLE_BATCHING },
|
2009-06-17 00:59:28 +00:00
|
|
|
{ "disable-vbos", COGL_DEBUG_DISABLE_VBOS },
|
2010-07-06 00:30:25 +00:00
|
|
|
{ "disable-pbos", COGL_DEBUG_DISABLE_PBOS },
|
2009-10-26 11:01:33 +00:00
|
|
|
{ "disable-software-transform", COGL_DEBUG_DISABLE_SOFTWARE_TRANSFORM },
|
2010-01-21 15:34:19 +00:00
|
|
|
{ "dump-atlas-image", COGL_DEBUG_DUMP_ATLAS_IMAGE },
|
2010-04-26 09:01:43 +00:00
|
|
|
{ "disable-atlas", COGL_DEBUG_DISABLE_ATLAS },
|
2011-03-30 15:39:38 +00:00
|
|
|
{ "disable-shared-atlas", COGL_DEBUG_DISABLE_SHARED_ATLAS },
|
2010-04-26 09:01:43 +00:00
|
|
|
{ "disable-texturing", COGL_DEBUG_DISABLE_TEXTURING},
|
|
|
|
{ "disable-arbfp", COGL_DEBUG_DISABLE_ARBFP},
|
2010-11-24 17:29:00 +00:00
|
|
|
{ "disable-fixed", COGL_DEBUG_DISABLE_FIXED},
|
2010-04-08 11:21:04 +00:00
|
|
|
{ "disable-glsl", COGL_DEBUG_DISABLE_GLSL},
|
2010-11-05 14:55:46 +00:00
|
|
|
{ "disable-blending", COGL_DEBUG_DISABLE_BLENDING},
|
2010-11-16 13:06:08 +00:00
|
|
|
{ "disable-npot-textures", COGL_DEBUG_DISABLE_NPOT_TEXTURES},
|
2010-11-10 14:02:31 +00:00
|
|
|
{ "wireframe", COGL_DEBUG_WIREFRAME},
|
2010-12-03 12:01:18 +00:00
|
|
|
{ "disable-software-clip", COGL_DEBUG_DISABLE_SOFTWARE_CLIP},
|
2011-01-20 14:41:51 +00:00
|
|
|
{ "disable-program-caches", COGL_DEBUG_DISABLE_PROGRAM_CACHES},
|
|
|
|
{ "disable-fast-read-pixel", COGL_DEBUG_DISABLE_FAST_READ_PIXEL}
|
2009-02-23 12:47:02 +00:00
|
|
|
};
|
2010-02-17 14:38:11 +00:00
|
|
|
static const int n_cogl_behavioural_debug_keys =
|
|
|
|
G_N_ELEMENTS (cogl_behavioural_debug_keys);
|
2009-02-23 12:47:02 +00:00
|
|
|
|
2011-10-31 14:19:10 +00:00
|
|
|
unsigned long _cogl_debug_flags[COGL_DEBUG_N_LONGS];
|
2011-06-10 17:44:09 +00:00
|
|
|
GHashTable *_cogl_debug_instances;
|
2009-02-23 12:47:02 +00:00
|
|
|
|
2011-01-24 14:28:00 +00:00
|
|
|
static void
|
|
|
|
_cogl_parse_debug_string_for_keys (const char *value,
|
|
|
|
gboolean enable,
|
|
|
|
const GDebugKey *keys,
|
|
|
|
unsigned int nkeys)
|
|
|
|
{
|
2011-10-31 14:19:10 +00:00
|
|
|
int long_num, key_num;
|
2011-01-24 14:28:00 +00:00
|
|
|
|
|
|
|
/* g_parse_debug_string expects the value field in GDebugKey to be a
|
2011-10-31 14:19:10 +00:00
|
|
|
mask in a guint but the flags is stored in an array of multiple
|
|
|
|
longs so we need to build a separate array for each possible
|
|
|
|
guint */
|
2011-01-24 14:28:00 +00:00
|
|
|
|
2011-10-31 14:19:10 +00:00
|
|
|
for (long_num = 0; long_num < COGL_DEBUG_N_LONGS; long_num++)
|
2011-01-24 14:28:00 +00:00
|
|
|
{
|
2011-10-31 14:19:10 +00:00
|
|
|
int int_num;
|
|
|
|
|
|
|
|
for (int_num = 0;
|
|
|
|
int_num < sizeof (unsigned long) / sizeof (unsigned int);
|
|
|
|
int_num++)
|
2011-01-24 14:28:00 +00:00
|
|
|
{
|
2011-10-31 14:19:10 +00:00
|
|
|
GDebugKey keys_for_int[sizeof (unsigned int) * 8];
|
|
|
|
int nkeys_for_int = 0;
|
|
|
|
|
|
|
|
for (key_num = 0; key_num < nkeys; key_num++)
|
|
|
|
{
|
|
|
|
int long_index = COGL_FLAGS_GET_INDEX (keys[key_num].value);
|
|
|
|
int int_index = (keys[key_num].value %
|
|
|
|
(sizeof (unsigned long) * 8) /
|
|
|
|
(sizeof (unsigned int) * 8));
|
|
|
|
|
|
|
|
if (long_index == long_num && int_index == int_num)
|
|
|
|
{
|
|
|
|
keys_for_int[nkeys_for_int] = keys[key_num];
|
|
|
|
keys_for_int[nkeys_for_int].value =
|
|
|
|
COGL_FLAGS_GET_MASK (keys[key_num].value) >>
|
|
|
|
(int_num * sizeof (unsigned int) * 8);
|
|
|
|
nkeys_for_int++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nkeys_for_int > 0)
|
|
|
|
{
|
|
|
|
unsigned long mask =
|
|
|
|
((unsigned long) g_parse_debug_string (value,
|
|
|
|
keys_for_int,
|
|
|
|
nkeys_for_int)) <<
|
|
|
|
(int_num * sizeof (unsigned int) * 8);
|
|
|
|
|
|
|
|
if (enable)
|
|
|
|
_cogl_debug_flags[long_num] |= mask;
|
|
|
|
else
|
|
|
|
_cogl_debug_flags[long_num] &= ~mask;
|
|
|
|
}
|
2011-01-24 14:28:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-03 17:15:54 +00:00
|
|
|
void
|
2010-02-17 14:38:11 +00:00
|
|
|
_cogl_parse_debug_string (const char *value,
|
2011-01-24 14:28:00 +00:00
|
|
|
gboolean enable,
|
2010-02-17 14:38:11 +00:00
|
|
|
gboolean ignore_help)
|
|
|
|
{
|
|
|
|
if (ignore_help && strcmp (value, "help") == 0)
|
2011-01-24 14:28:00 +00:00
|
|
|
return;
|
2010-02-17 14:38:11 +00:00
|
|
|
|
|
|
|
/* We don't want to let g_parse_debug_string handle "all" because
|
|
|
|
* literally enabling all the debug options wouldn't be useful to
|
|
|
|
* anyone; instead the all option enables all non behavioural
|
|
|
|
* options.
|
|
|
|
*/
|
|
|
|
if (strcmp (value, "all") == 0 ||
|
|
|
|
strcmp (value, "verbose") == 0)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < n_cogl_log_debug_keys; i++)
|
2011-01-24 14:28:00 +00:00
|
|
|
if (enable)
|
|
|
|
COGL_DEBUG_SET_FLAG (cogl_log_debug_keys[i].value);
|
|
|
|
else
|
|
|
|
COGL_DEBUG_CLEAR_FLAG (cogl_log_debug_keys[i].value);
|
2010-02-17 14:38:11 +00:00
|
|
|
}
|
2011-12-09 17:17:51 +00:00
|
|
|
else if (g_ascii_strcasecmp (value, "help") == 0)
|
2010-02-17 14:38:11 +00:00
|
|
|
{
|
2011-09-10 08:52:48 +00:00
|
|
|
g_printerr ("\n\n%28s\n", _("Supported debug values:"));
|
2010-06-21 14:36:46 +00:00
|
|
|
#define OPT(MASK_NAME, GROUP, NAME, NAME_FORMATTED, DESCRIPTION) \
|
2011-09-10 08:52:48 +00:00
|
|
|
g_printerr ("%28s %s\n", NAME ":", g_dgettext (GETTEXT_PACKAGE, \
|
|
|
|
DESCRIPTION));
|
2010-06-21 14:36:46 +00:00
|
|
|
#include "cogl-debug-options.h"
|
2011-09-10 08:52:48 +00:00
|
|
|
g_printerr ("\n%28s\n", _("Special debug values:"));
|
2010-06-21 14:36:46 +00:00
|
|
|
OPT (IGNORED, "ignored", "all", "ignored", \
|
2011-09-10 08:52:48 +00:00
|
|
|
N_("Enables all non-behavioural debug options"));
|
2010-06-21 14:36:46 +00:00
|
|
|
OPT (IGNORED, "ignored", "verbose", "ignored", \
|
2011-09-10 08:52:48 +00:00
|
|
|
N_("Enables all non-behavioural debug options"));
|
2010-02-17 14:38:11 +00:00
|
|
|
#undef OPT
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-24 14:28:00 +00:00
|
|
|
_cogl_parse_debug_string_for_keys (value,
|
|
|
|
enable,
|
|
|
|
cogl_log_debug_keys,
|
|
|
|
n_cogl_log_debug_keys);
|
|
|
|
_cogl_parse_debug_string_for_keys (value,
|
|
|
|
enable,
|
|
|
|
cogl_behavioural_debug_keys,
|
|
|
|
n_cogl_behavioural_debug_keys);
|
2010-02-17 14:38:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-14 21:33:44 +00:00
|
|
|
#ifdef COGL_ENABLE_DEBUG
|
2009-02-23 12:47:02 +00:00
|
|
|
static gboolean
|
|
|
|
cogl_arg_debug_cb (const char *key,
|
|
|
|
const char *value,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2011-01-24 14:28:00 +00:00
|
|
|
_cogl_parse_debug_string (value,
|
|
|
|
TRUE /* enable the flags */,
|
|
|
|
FALSE /* don't ignore help */);
|
2009-02-23 12:47:02 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
cogl_arg_no_debug_cb (const char *key,
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-10 01:57:32 +00:00
|
|
|
const char *value,
|
|
|
|
gpointer user_data)
|
2009-02-23 12:47:02 +00:00
|
|
|
{
|
2011-01-24 14:28:00 +00:00
|
|
|
_cogl_parse_debug_string (value,
|
|
|
|
FALSE, /* disable the flags */
|
|
|
|
TRUE /* ignore help */);
|
2009-02-23 12:47:02 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2010-02-17 14:38:11 +00:00
|
|
|
#endif /* COGL_ENABLE_DEBUG */
|
2009-02-23 12:47:02 +00:00
|
|
|
|
|
|
|
static GOptionEntry cogl_args[] = {
|
2010-03-02 02:07:40 +00:00
|
|
|
#ifdef COGL_ENABLE_DEBUG
|
2009-02-23 12:47:02 +00:00
|
|
|
{ "cogl-debug", 0, 0, G_OPTION_ARG_CALLBACK, cogl_arg_debug_cb,
|
2010-10-05 07:03:19 +00:00
|
|
|
N_("Cogl debugging flags to set"), "FLAGS" },
|
2009-02-23 12:47:02 +00:00
|
|
|
{ "cogl-no-debug", 0, 0, G_OPTION_ARG_CALLBACK, cogl_arg_no_debug_cb,
|
2010-10-05 07:03:19 +00:00
|
|
|
N_("Cogl debugging flags to unset"), "FLAGS" },
|
2010-03-02 02:07:40 +00:00
|
|
|
#endif /* COGL_ENABLE_DEBUG */
|
2009-02-23 12:47:02 +00:00
|
|
|
{ NULL, },
|
|
|
|
};
|
|
|
|
|
2011-06-14 21:33:44 +00:00
|
|
|
void
|
|
|
|
_cogl_debug_check_environment (void)
|
2009-02-23 12:47:02 +00:00
|
|
|
{
|
|
|
|
const char *env_string;
|
|
|
|
|
|
|
|
env_string = g_getenv ("COGL_DEBUG");
|
|
|
|
if (env_string != NULL)
|
|
|
|
{
|
2011-01-24 14:28:00 +00:00
|
|
|
_cogl_parse_debug_string (env_string,
|
|
|
|
TRUE /* enable the flags */,
|
|
|
|
FALSE /* don't ignore help */);
|
2009-02-23 12:47:02 +00:00
|
|
|
env_string = NULL;
|
|
|
|
}
|
2011-08-03 17:15:54 +00:00
|
|
|
|
|
|
|
env_string = g_getenv ("COGL_NO_DEBUG");
|
|
|
|
if (env_string != NULL)
|
|
|
|
{
|
|
|
|
_cogl_parse_debug_string (env_string,
|
|
|
|
FALSE /* disable the flags */,
|
|
|
|
FALSE /* don't ignore help */);
|
|
|
|
env_string = NULL;
|
|
|
|
}
|
2011-06-14 21:33:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
pre_parse_hook (GOptionContext *context,
|
|
|
|
GOptionGroup *group,
|
|
|
|
gpointer data,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
_cogl_init ();
|
2009-02-23 12:47:02 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-06-14 21:33:44 +00:00
|
|
|
/* XXX: GOption based library initialization is not reliable because the
|
|
|
|
* GOption API has no way to represent dependencies between libraries.
|
|
|
|
*/
|
2009-02-23 12:47:02 +00:00
|
|
|
GOptionGroup *
|
|
|
|
cogl_get_option_group (void)
|
|
|
|
{
|
|
|
|
GOptionGroup *group;
|
|
|
|
|
|
|
|
group = g_option_group_new ("cogl",
|
2010-10-05 07:03:19 +00:00
|
|
|
_("Cogl Options"),
|
|
|
|
_("Show Cogl options"),
|
2009-02-23 12:47:02 +00:00
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
g_option_group_set_parse_hooks (group, pre_parse_hook, NULL);
|
|
|
|
g_option_group_add_entries (group, cogl_args);
|
|
|
|
g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
|
|
|
|
|
|
|
|
return group;
|
|
|
|
}
|