diff options
author | Benjamin Otte <otte@redhat.com> | 2010-08-27 14:13:03 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2010-09-26 15:11:30 +0200 |
commit | 47292f28d5f6de33380152619a1f80294451ed36 (patch) | |
tree | 6d453252cb8c2e2c7e54583e8147a163046a63c8 /gdk | |
parent | 6607f2b794c6ca0555ea7cf8c597103c2115066e (diff) | |
download | gtk+-47292f28d5f6de33380152619a1f80294451ed36.tar.gz |
x11: Upload cursor image using Cairo
There's no need to write our own upload function when the cursor format
is identical to CAIRO_FORMAT_ARGB32.
Diffstat (limited to 'gdk')
-rw-r--r-- | gdk/x11/gdkcursor-x11.c | 46 |
1 files changed, 14 insertions, 32 deletions
diff --git a/gdk/x11/gdkcursor-x11.c b/gdk/x11/gdkcursor-x11.c index cf54f5cd6a..13e0c1cbb9 100644 --- a/gdk/x11/gdkcursor-x11.c +++ b/gdk/x11/gdkcursor-x11.c @@ -592,50 +592,32 @@ create_cursor_image (GdkPixbuf *pixbuf, gint x, gint y) { - guint width, height, rowstride, n_channels; - guchar *pixels, *src; + guint width, height; XcursorImage *xcimage; - XcursorPixel *dest; + cairo_surface_t *surface; + cairo_t *cr; width = gdk_pixbuf_get_width (pixbuf); height = gdk_pixbuf_get_height (pixbuf); - n_channels = gdk_pixbuf_get_n_channels (pixbuf); - rowstride = gdk_pixbuf_get_rowstride (pixbuf); - pixels = gdk_pixbuf_get_pixels (pixbuf); - xcimage = XcursorImageCreate (width, height); xcimage->xhot = x; xcimage->yhot = y; - dest = xcimage->pixels; + surface = cairo_image_surface_create_for_data ((guchar *) xcimage->pixels, + CAIRO_FORMAT_ARGB32, + width, + height, + width * 4); - if (n_channels == 3) - { - gint i, j; - - for (j = 0; j < height; j++) - { - src = pixels + j * rowstride; - for (i = 0; i < width; i++) - { - *dest = (0xff << 24) | (src[0] << 16) | (src[1] << 8) | src[2]; - } + cr = cairo_create (surface); + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); + gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0); + cairo_paint (cr); + cairo_destroy (cr); - src += n_channels; - dest++; - } - } - else - { - _gdk_x11_convert_to_format (pixels, rowstride, - (guchar *) dest, 4 * width, - GDK_X11_FORMAT_ARGB, - (G_BYTE_ORDER == G_BIG_ENDIAN) ? - GDK_MSB_FIRST : GDK_LSB_FIRST, - width, height); - } + cairo_surface_destroy (surface); return xcimage; } |