[debug] Guard the use of gdk_pixbuf for pick debugging by #ifdef USE_GDKPIXBUF

gdk is an optional clutter dependency, so the pick buffer debugging option
needs some guards so we don't break, for example, the OSX builds.  This also
adds a comment for the bit fiddling done on the pick colors used to ensure
the pick colors are more distinguished while debugging.  (we swap the
nibbles of each color component so that pick buffers don't just look black.)
This commit is contained in:
Robert Bragg 2009-10-05 16:46:24 +01:00
parent f7c0264245
commit dd8e4dcd62

View File

@ -38,7 +38,9 @@
#include <glib/gi18n-lib.h> #include <glib/gi18n-lib.h>
#include <locale.h> #include <locale.h>
#ifdef USE_GDKPIXBUF
#include <gdk-pixbuf/gdk-pixbuf.h> #include <gdk-pixbuf/gdk-pixbuf.h>
#endif
#include "clutter-event.h" #include "clutter-event.h"
#include "clutter-backend.h" #include "clutter-backend.h"
@ -340,6 +342,11 @@ _clutter_id_to_color (guint id, ClutterColor *col)
col->blue = blue; col->blue = blue;
col->alpha = 0xff; col->alpha = 0xff;
/* XXX: We rotate the nibbles of the colors here so that there is a
* visible variation between colors of sequential actor identifiers;
* otherwise pick buffers dumped to an image will pretty much just look
* black.
*/
if (G_UNLIKELY (clutter_debug_flags & CLUTTER_DEBUG_DUMP_PICK_BUFFERS)) if (G_UNLIKELY (clutter_debug_flags & CLUTTER_DEBUG_DUMP_PICK_BUFFERS))
{ {
col->red = (col->red << 4) | (col->red >> 4); col->red = (col->red << 4) | (col->red >> 4);
@ -363,6 +370,12 @@ _clutter_pixel_to_id (guchar pixel[4])
if (G_UNLIKELY (clutter_debug_flags & CLUTTER_DEBUG_DUMP_PICK_BUFFERS)) if (G_UNLIKELY (clutter_debug_flags & CLUTTER_DEBUG_DUMP_PICK_BUFFERS))
{ {
guchar tmp; guchar tmp;
/* XXX: In _clutter_id_to_color we rotated the nibbles of the colors so
* that there is a visible variation between colors of sequential actor
* identifiers (otherwise pick buffers dumped to an image will pretty
* much just look black.) Here we reverse that rotation.
*/
tmp = ((pixel[0] << 4) | (pixel[0] >> 4)); tmp = ((pixel[0] << 4) | (pixel[0] >> 4));
red = tmp >> (8 - ctx->fb_r_mask); red = tmp >> (8 - ctx->fb_r_mask);
tmp = ((pixel[1] << 4) | (pixel[1] >> 4)); tmp = ((pixel[1] << 4) | (pixel[1] >> 4));
@ -389,11 +402,13 @@ _clutter_pixel_to_id (guchar pixel[4])
return id; return id;
} }
#ifdef USE_GDKPIXBUF
static void static void
pixbuf_free (guchar *pixels, gpointer data) pixbuf_free (guchar *pixels, gpointer data)
{ {
g_free (pixels); g_free (pixels);
} }
#endif
static void static void
read_pixels_to_file (char *filename_stem, read_pixels_to_file (char *filename_stem,
@ -402,6 +417,7 @@ read_pixels_to_file (char *filename_stem,
int width, int width,
int height) int height)
{ {
#ifdef USE_GDKPIXBUF
GLubyte *data; GLubyte *data;
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
static int read_count = 0; static int read_count = 0;
@ -439,6 +455,15 @@ read_pixels_to_file (char *filename_stem,
g_object_unref (flipped); g_object_unref (flipped);
read_count++; read_count++;
} }
#else
static gboolean seen = FALSE;
if (!seen)
{
g_warning ("dumping buffers to an image isn't supported on platforms "
"without gdk pixbuf support\n");
seen = TRUE;
}
#endif
} }
ClutterActor * ClutterActor *