stage: Use Cairo to dump the pick buffer

Do not use GdkPixbuf just for getting image data down into a PNG; Cairo
is perfectly capable of doing the same, at least just for debugging
purposes.

https://bugzilla.gnome.org/show_bug.cgi?id=647875
This commit is contained in:
Emmanuele Bassi 2011-04-12 17:01:51 +01:00
parent 3a071a4787
commit 00f2a39ac5

View File

@ -53,10 +53,13 @@
#include "config.h" #include "config.h"
#endif #endif
#include <cairo/cairo.h>
#include "clutter-stage.h" #include "clutter-stage.h"
#include "clutter-actor-private.h" #include "clutter-actor-private.h"
#include "clutter-backend-private.h" #include "clutter-backend-private.h"
#include "clutter-cairo-texture.h"
#include "clutter-color.h" #include "clutter-color.h"
#include "clutter-container.h" #include "clutter-container.h"
#include "clutter-debug.h" #include "clutter-debug.h"
@ -1166,15 +1169,6 @@ _clutter_stage_has_full_redraw_queued (ClutterStage *stage)
return FALSE; return FALSE;
} }
#ifdef USE_GDKPIXBUF
static void
pixbuf_free (guchar *pixels,
gpointer data)
{
g_free (pixels);
}
#endif
static void static void
read_pixels_to_file (char *filename_stem, read_pixels_to_file (char *filename_stem,
int x, int x,
@ -1182,55 +1176,30 @@ read_pixels_to_file (char *filename_stem,
int width, int width,
int height) int height)
{ {
#ifdef USE_GDKPIXBUF
GLubyte *data; GLubyte *data;
GdkPixbuf *pixbuf; cairo_surface_t *surface;
static int read_count = 0; static int read_count = 0;
char *filename = g_strdup_printf ("%s-%05d.png",
filename_stem,
read_count);
data = g_malloc (4 * width * height); data = g_malloc (4 * width * height);
cogl_read_pixels (x, y, width, height, cogl_read_pixels (x, y, width, height,
COGL_READ_PIXELS_COLOR_BUFFER, COGL_READ_PIXELS_COLOR_BUFFER,
COGL_PIXEL_FORMAT_RGB_888, CLUTTER_CAIRO_FORMAT_ARGB32,
data); data);
pixbuf = gdk_pixbuf_new_from_data (data,
GDK_COLORSPACE_RGB,
FALSE, /* has alpha */
8, /* bits per sample */
width, /* width */
height, /* height */
width * 3, /* rowstride */
pixbuf_free, /* callback to free data */
NULL); /* callback data */
if (pixbuf)
{
char *filename = g_strdup_printf ("%s-%05d.png",
filename_stem,
read_count);
GError *error = NULL;
if (!gdk_pixbuf_save (pixbuf, filename, "png", &error, NULL)) surface = cairo_image_surface_create_for_data (data, CAIRO_FORMAT_RGB24,
{ width, height,
g_warning ("Failed to save pick buffer to file %s: %s", width * 4);
filename, error->message);
g_error_free (error);
}
g_free (filename); cairo_surface_write_to_png (surface, filename);
g_object_unref (pixbuf); cairo_surface_destroy (surface);
read_count++;
}
#else /* !USE_GDKPIXBUF */
{
static gboolean seen = FALSE;
if (!seen) g_free (data);
{ g_free (filename);
g_warning ("dumping buffers to an image isn't supported on platforms "
"without gdk pixbuf support\n"); read_count++;
seen = TRUE;
}
}
#endif /* USE_GDKPIXBUF */
} }
ClutterActor * ClutterActor *