From d12c9702a4428cdf83e6d0dc37b0b9e69fb19f80 Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Fri, 4 Jan 2002 05:58:01 +0000 Subject: Private function to tell if we have RENDER extension. Thu Jan 3 22:18:15 2002 Owen Taylor * gdk/x11/gdkdrawable-x11.c gdk/x11/gdkprivate-x11.h (_gdk_x11_have_render): Private function to tell if we have RENDER extension. * gdk/x11/gdkgc-x11.c (_gdk_x11_gc_get_fg_picture): Return None if we don't have RENDER extension. * gdk/x11/gdkpango-x11.c (gdk_pango_context_get): Don't use Xft unless we have render extension. * gdk/x11/gdkdrawable-x11.c (gdk_x11_drawable_get_picture): Handle missing render extension. * gdk/gdkdraw.c gdk/gdkdrawable.h gdk/gdkpixmap.c gdk/gdkwindow.c gdk/gdkinternals.h: Add a private copy_to_image() virtual function to the GdkDrawable vtable that extends get_image() to allow copying onto existing images. Make the default implementation of get_image() use this so that backends don't have to implement both. Add private wrapper _gdk_drawable_copy_to_image(). * gdk/x11/gdkimage-x11.c gdk/x11/gdkprivate-x11.c gdk/x11/gdkdrawable-x11.c (_gdk_x11_copy_to_image): Implement copy_to_image() semantics, speed up by using ShmPixmaps and XCopyArea when possible, XFlush() after ungrabbing the server, generally redo the logic once again. * gdk/gdkinternals.h gdk/x11/gdkimage-x11.c _gdk_windowing_bits_per_depth(): Function to convert from depth to bits-per-pixel. (We assume only one bpp per depth - X requires this.) * gdk/gdkinternals.h gdk/gdkrgb.c gdk/gdkimage.c: Move the GdkRGB scratch image code into a generic _gdk_image_get_scratch() chunk of code that we can use other places we need scratch images. * gdk/gdkimage.c gdk/x11/gdkimage.c gdk/gdkinternals.h: Add _gdk_image_new_for_depth() as the backend to _gdk_image_new() to allowing creating images with a depth and no visual. * gdk/gdkpixbuf-drawable.c: Fix so that getting parts of images not at 0,0 actually works. * gdk/gdkdrawable.h gdk/gdkinternals.h gdk/gdkdraw.c gdk/gdkwindow.c gdk/gdkpixmap.c gdk/gdkpixbuf-render.c: - Add a new GdkDrawableClass vfunc _draw_pixbuf, and _gdk_draw_pixbuf() [ will be made public later ], to allow backends to accelerate drawing pixbufs. - Move the implementation of gdk_pixbuf_render_to_drawable_alpha() to be the default implementation. - Update docs for gdk_pixbuf_render_to_drawable_alpha(). - Optimize the default implementation by using _gdk_image_copy_to_pixmap() and scratch shared images, and special casing the compositing. * gdk/x11/gdkdrawable-x11.c: Accelerate _gdk_draw_pixbuf() with alpha using the RENDER extension. * gdk/gdkpixbuf-drawable.c (gdk_pixbuf_get_from_drawable): Optimize by _gdk_image_copy_to_pixmap() and scratch images. * tests/testrgb.c: Add test for speed of alpha composition, reduce the number of iterations since alpha composition can be a bit slow. * gdk/x11/gdkimage-x11.c gdk/gdkprivate-x11.h (_gdk_x11_image_get_shm_pixmap): Private function to get a ShmPixmap for an image, if possible. --- gdk/gdkpixbuf-drawable.c | 87 ++++++++++++++++++++++++++++-------------------- 1 file changed, 51 insertions(+), 36 deletions(-) (limited to 'gdk/gdkpixbuf-drawable.c') diff --git a/gdk/gdkpixbuf-drawable.c b/gdk/gdkpixbuf-drawable.c index f4a99cab70..bfb0d941d1 100644 --- a/gdk/gdkpixbuf-drawable.c +++ b/gdk/gdkpixbuf-drawable.c @@ -72,7 +72,7 @@ bitmap1 (GdkImage *image, int bpl; register guint8 data; guint8 *o; - guint8 *srow = image->mem, *orow = pixels; + guint8 *srow = image->mem + y1 * image->bpl, *orow = pixels; d (printf ("bitmap, no alpha\n")); @@ -128,7 +128,7 @@ bitmap1a (GdkImage *image, int bpl; register guint8 data; guint8 *o; - guint8 *srow = image->mem, *orow = pixels; + guint8 *srow = image->mem + y1 * image->bpl, *orow = pixels; d (printf ("bitmap, with alpha\n")); @@ -183,7 +183,7 @@ rgb1 (GdkImage *image, int bpl; register guint8 data; guint8 *o; - guint8 *srow = image->mem, *orow = pixels; + guint8 *srow = image->mem + y1 * image->bpl, *orow = pixels; d (printf ("1 bits/pixel\n")); @@ -231,7 +231,7 @@ rgb1a (GdkImage *image, int bpl; register guint8 data; guint8 *o; - guint8 *srow = image->mem, *orow = pixels; + guint8 *srow = image->mem + y1 * image->bpl, *orow = pixels; d (printf ("1 bits/pixel\n")); @@ -279,7 +279,7 @@ rgb8 (GdkImage *image, int bpl; guint32 mask; register guint32 data; - guint8 *srow = image->mem, *orow = pixels; + guint8 *srow = image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; register guint8 *s; register guint8 *o; @@ -326,7 +326,7 @@ rgb8a (GdkImage *image, guint32 remap[256]; register guint8 *s; /* read 2 pixels at once */ register guint32 *o; - guint8 *srow = image->mem, *orow = pixels; + guint8 *srow = image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; bpl = image->bpl; @@ -387,7 +387,7 @@ rgb565lsb (GdkImage *image, register guint8 *s; /* read 2 pixels at once */ #endif register guint16 *o; - guint8 *srow = image->mem, *orow = pixels; + guint8 *srow = image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; bpl = image->bpl; @@ -490,7 +490,7 @@ rgb565msb (GdkImage *image, register guint32 *s; /* read 2 pixels at once */ #endif register guint16 *o; - guint8 *srow = image->mem, *orow = pixels; + guint8 *srow = image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; bpl = image->bpl; @@ -596,7 +596,7 @@ rgb565alsb (GdkImage *image, #endif register guint32 *o; - guint8 *srow = image->mem, *orow = pixels; + guint8 *srow = image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; bpl = image->bpl; @@ -659,7 +659,7 @@ rgb565amsb (GdkImage *image, #endif register guint32 *o; - guint8 *srow = image->mem, *orow = pixels; + guint8 *srow = image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; bpl = image->bpl; @@ -717,7 +717,7 @@ rgb555lsb (GdkImage *image, register guint8 *s; /* read 2 pixels at once */ #endif register guint16 *o; - guint8 *srow = image->mem, *orow = pixels; + guint8 *srow = image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; bpl = image->bpl; @@ -821,7 +821,7 @@ rgb555msb (GdkImage *image, register guint32 *s; /* read 2 pixels at once */ #endif register guint16 *o; - guint8 *srow = image->mem, *orow = pixels; + guint8 *srow = image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; bpl = image->bpl; @@ -922,7 +922,7 @@ rgb555alsb (GdkImage *image, #endif register guint32 *o; - guint8 *srow = image->mem, *orow = pixels; + guint8 *srow = image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; bpl = image->bpl; @@ -985,7 +985,7 @@ rgb555amsb (GdkImage *image, #endif register guint32 *o; - guint8 *srow = image->mem, *orow = pixels; + guint8 *srow = image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; bpl = image->bpl; @@ -1039,7 +1039,7 @@ rgb888alsb (GdkImage *image, guint8 *s; /* for byte order swapping */ guint8 *o; - guint8 *srow = image->mem, *orow = pixels; + guint8 *srow = image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; bpl = image->bpl; @@ -1076,7 +1076,7 @@ rgb888lsb (GdkImage *image, int xx, yy; int bpl; - guint8 *srow = image->mem, *orow = pixels; + guint8 *srow = image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; guint8 *o, *s; bpl = image->bpl; @@ -1112,7 +1112,7 @@ rgb888amsb (GdkImage *image, int xx, yy; int bpl; - guint8 *srow = image->mem, *orow = pixels; + guint8 *srow = image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; #ifdef LITTLE guint32 *o; guint32 *s; @@ -1166,7 +1166,7 @@ rgb888msb (GdkImage *image, int xx, yy; int bpl; - guint8 *srow = image->mem, *orow = pixels; + guint8 *srow = image->mem + y1 * image->bpl + x1 * image->bpp, *orow = pixels; guint8 *s; guint8 *o; @@ -1207,8 +1207,7 @@ convert_real_slow (GdkImage *image, { int xx, yy; int bpl; - guint8 *srow = image->mem, *orow = pixels; - guint8 *s; + guint8 *orow = pixels; guint8 *o; guint32 pixel; GdkVisual *v; @@ -1225,7 +1224,6 @@ convert_real_slow (GdkImage *image, for (yy = y1; yy < y2; yy++) { - s = srow; o = orow; for (xx = x1; xx < x2; xx++) { @@ -1268,7 +1266,6 @@ convert_real_slow (GdkImage *image, if (alpha) *o++ = 0xff; } - srow += bpl; orow += rowstride; } } @@ -1481,6 +1478,7 @@ gdk_pixbuf_get_from_drawable (GdkPixbuf *dest, int src_width, src_height; GdkImage *image; int depth; + int x0, y0; /* General sanity checks */ @@ -1503,6 +1501,14 @@ gdk_pixbuf_get_from_drawable (GdkPixbuf *dest, g_return_val_if_fail (dest->bits_per_sample == 8, NULL); } + /* Create the pixbuf if needed */ + if (!dest) + { + dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height); + if (dest == NULL) + return NULL; + } + if (cmap == NULL) cmap = gdk_drawable_get_colormap (src); @@ -1536,19 +1542,28 @@ gdk_pixbuf_get_from_drawable (GdkPixbuf *dest, g_return_val_if_fail (dest_x + width <= dest->width, NULL); g_return_val_if_fail (dest_y + height <= dest->height, NULL); } - - /* Get Image in ZPixmap format (packed bits). */ - image = gdk_image_get (src, src_x, src_y, width, height); - - if (image == NULL) - return NULL; - - dest = gdk_pixbuf_get_from_image (dest, image, cmap, - 0, 0, dest_x, dest_y, - width, height); - - gdk_image_destroy (image); + for (y0 = 0; y0 < height; y0 += GDK_SCRATCH_IMAGE_HEIGHT) + { + gint height1 = MIN (height - y0, GDK_SCRATCH_IMAGE_HEIGHT); + for (x0 = 0; x0 < width; x0 += GDK_SCRATCH_IMAGE_WIDTH) + { + gint xs0, ys0; + + gint width1 = MIN (width - x0, GDK_SCRATCH_IMAGE_WIDTH); + + image = _gdk_image_get_scratch (width1, height1, depth, &xs0, &ys0); + + _gdk_drawable_copy_to_image (src, image, + src_x + x0, src_y + y0, + xs0, ys0, width1, height1); + + gdk_pixbuf_get_from_image (dest, image, cmap, + xs0, ys0, dest_x + x0, dest_y + y0, + width1, height1); + } + } + return dest; } @@ -1638,8 +1653,8 @@ gdk_pixbuf_get_from_image (GdkPixbuf *dest, rowstride, alpha, src_x, src_y, - src_x + width, - src_y + height, + width, + height, cmap); return dest; -- cgit v1.2.1