Add Sun mediaLib support so that hardware acceleration via mediaLib is

2007-05-16  Brian Cameron  <brian.cameron@sun.com>

        * acconfig.h, configure.in, gdk/Makefile.am, gdkprivate.h, gdkrgb.c,
          gdkdraw.c, gdk-pixbuf/gdk-pixbuf-scale.c,
          gdk-pixbuf/pixops/Makefile.am, gdk-pixbuf/pixops/pixops.[ch],
          gdk-pixbuf/pixops/timescale.c:  Add Sun mediaLib support so that
          hardware acceleration via mediaLib is enabled if mediaLib is
          detected via configure.  Enhancement request #344813.  I was given
          permission to commit in the bug report by Matthias Clasen.
        * gdk/medialib.[ch]: New files added for mediaLib support.
        * docs/reference/gdk-pixbuf/tmpl/scaling.sgml,
          docs/reference/gdk/tmpl/rgb.sgml, gdk/gdkdraw.c:  Add docs for
          mediaLib support.

svn path=/trunk/; revision=17855
This commit is contained in:
Brian Cameron 2007-05-16 01:35:51 +00:00 committed by Brian Cameron
parent 5e9e9fe4e0
commit 94dcec33c1
14 changed files with 1355 additions and 250 deletions

View File

@ -1,3 +1,17 @@
2007-05-16 Brian Cameron <brian.cameron@sun.com>
* acconfig.h, configure.in, gdk/Makefile.am, gdkprivate.h, gdkrgb.c,
gdkdraw.c, gdk-pixbuf/gdk-pixbuf-scale.c,
gdk-pixbuf/pixops/Makefile.am, gdk-pixbuf/pixops/pixops.[ch],
gdk-pixbuf/pixops/timescale.c: Add Sun mediaLib support so that
hardware acceleration via mediaLib is enabled if mediaLib is
detected via configure. Enhancement request #344813. I was given
permission to commit in the bug report by Matthias Clasen.
* gdk/medialib.[ch]: New files added for mediaLib support.
* docs/reference/gdk-pixbuf/tmpl/scaling.sgml,
docs/reference/gdk/tmpl/rgb.sgml, gdk/gdkdraw.c: Add docs for
mediaLib support.
2007-05-15 Torsten Schoenfeld <kaffeetisch@gmx.de>
* gtk/gtkprintoperation.c (pdf_end_run): Unset priv->platform_data and

View File

@ -26,6 +26,8 @@
#undef HAVE_PWD_H
#undef HAVE_SHM_H
#undef HAVE_STPCPY
#undef HAVE_SYS_SYSINFO_H
#undef HAVE_SYS_SYSTEMINFO_H
#undef HAVE_XSHM_H
#undef HAVE_SHAPE_EXT
#undef HAVE_SOLARIS_XINERAMA
@ -44,6 +46,8 @@
#undef USE_GMODULE
#undef USE_MMX
#undef USE_MEDIALIB
#undef USE_MEDIALIB25
/* Define to use XKB extension */
#undef HAVE_XKB

View File

@ -941,6 +941,32 @@ else
STATIC_LIB_DEPS="$LIBTIFF $LIBJPEG $LIBPNG"
fi
# Checks to see whether we should include mediaLib
# support.
#
AC_CHECK_HEADER(sys/systeminfo.h, AC_DEFINE(HAVE_SYS_SYSTEMINFO_H))
AC_CHECK_HEADER(sys/sysinfo.h, AC_DEFINE(HAVE_SYS_SYSINFO_H))
AC_MSG_CHECKING(for mediaLib 2.3)
use_mlib25=no
# Check for a mediaLib 2.3 function since that is what the GTK+ mediaLib
# patch requires.
AC_CHECK_LIB(mlib, mlib_ImageSetStruct, use_mlib=yes, use_mlib=no)
if test $use_mlib = yes; then
AC_DEFINE(USE_MEDIALIB)
MEDIA_LIB=-lmlib
AC_MSG_CHECKING(for mediaLib 2.5)
# Check for a mediaLib 2.5 function since that is what is needed for
# gdk_rgb_convert integration.
AC_CHECK_LIB(mlib, mlib_VideoColorRGBint_to_BGRAint, use_mlib25=yes, use_mlib25=no)
if test $use_mlib25 = yes; then
AC_DEFINE(USE_MEDIALIB25)
fi
fi
AM_CONDITIONAL(USE_MEDIALIB, test $use_mlib = yes)
AM_CONDITIONAL(USE_MEDIALIB25, test $use_mlib25 = yes)
# Checks to see if we should compile in MMX support (there will be
# a runtime test when the code is actually run to see if it should
# be used - this just checks if we can compile it.)
@ -1009,7 +1035,7 @@ fi
AC_SUBST(REBUILD_PNGS)
GDK_PIXBUF_PACKAGES="gmodule-no-export-2.0 gobject-2.0"
GDK_PIXBUF_EXTRA_LIBS="$STATIC_LIB_DEPS $MATH_LIB"
GDK_PIXBUF_EXTRA_LIBS="$STATIC_LIB_DEPS $MATH_LIB $MEDIA_LIB"
GDK_PIXBUF_EXTRA_CFLAGS=
GDK_PIXBUF_DEP_LIBS="`$PKG_CONFIG --libs $GDK_PIXBUF_PACKAGES` $GDK_PIXBUF_EXTRA_LIBS"
GDK_PIXBUF_DEP_CFLAGS="`$PKG_CONFIG --cflags gthread-2.0 $GDK_PIXBUF_PACKAGES $PNG_DEP_CFLAGS_PACKAGES` $GDK_PIXBUF_EXTRA_CFLAGS"

View File

@ -23,6 +23,15 @@ Scaling pixbufs and scaling and compositing pixbufs
new pixbuf.
</para>
<para>
Scaling and compositing functions take advantage of MMX hardware
acceleration on systems where MMX is supported. If gdk-pixbuf is built
with the Sun mediaLib library, these functions are instead accelerated
using mediaLib, which provides hardware acceleration on Intel, AMD,
and Sparc chipsets. If desired, mediaLib support can be turned off by
setting the GDK_DISABLE_MEDIALIB environment variable.
</para>
<para>
The following example demonstrates handling an expose event by
rendering the appropriate area of a source image (which is scaled

View File

@ -34,6 +34,13 @@ created in grayscale and direct color modes, and the visual is changed
in cases where a "better" visual than the default is available.
</para>
<para>
If GDK is built with the Sun mediaLib library, the GdkRGB functions are
accelerated using mediaLib, which provides hardware acceleration on Intel,
AMD, and Sparc chipsets. If desired, mediaLib support can be turned off
by setting the GDK_DISABLE_MEDIALIB environment variable.
</para>
<example>
<title>A simple example program using GdkRGB</title>
<programlisting>

View File

@ -73,14 +73,12 @@ gdk_pixbuf_scale (const GdkPixbuf *src,
offset_x = floor (offset_x + 0.5);
offset_y = floor (offset_y + 0.5);
_pixops_scale (dest->pixels + dest_y * dest->rowstride + dest_x * dest->n_channels,
dest_x - offset_x, dest_y - offset_y,
dest_x + dest_width - offset_x, dest_y + dest_height - offset_y,
dest->rowstride, dest->n_channels, dest->has_alpha,
src->pixels, src->width, src->height,
src->rowstride, src->n_channels, src->has_alpha,
scale_x, scale_y, (PixopsInterpType)interp_type);
_pixops_scale (dest->pixels, dest->width, dest->height, dest->rowstride,
dest->n_channels, dest->has_alpha, src->pixels, src->width,
src->height, src->rowstride, src->n_channels, src->has_alpha,
dest_x, dest_y, dest_width, dest_height, offset_x, offset_y,
scale_x, scale_y, (PixopsInterpType)interp_type);
}
/**
@ -136,13 +134,13 @@ gdk_pixbuf_composite (const GdkPixbuf *src,
offset_x = floor (offset_x + 0.5);
offset_y = floor (offset_y + 0.5);
_pixops_composite (dest->pixels + dest_y * dest->rowstride + dest_x * dest->n_channels,
dest_x - offset_x, dest_y - offset_y,
dest_x + dest_width - offset_x, dest_y + dest_height - offset_y,
dest->rowstride, dest->n_channels, dest->has_alpha,
src->pixels, src->width, src->height,
src->rowstride, src->n_channels, src->has_alpha,
scale_x, scale_y, (PixopsInterpType)interp_type, overall_alpha);
_pixops_composite (dest->pixels, dest->width, dest->height, dest->rowstride,
dest->n_channels, dest->has_alpha, src->pixels,
src->width, src->height, src->rowstride, src->n_channels,
src->has_alpha, dest_x, dest_y, dest_width, dest_height,
offset_x, offset_y, scale_x, scale_y,
(PixopsInterpType)interp_type, overall_alpha);
}
/**
@ -204,14 +202,14 @@ gdk_pixbuf_composite_color (const GdkPixbuf *src,
offset_x = floor (offset_x + 0.5);
offset_y = floor (offset_y + 0.5);
_pixops_composite_color (dest->pixels + dest_y * dest->rowstride + dest_x * dest->n_channels,
dest_x - offset_x, dest_y - offset_y,
dest_x + dest_width - offset_x, dest_y + dest_height - offset_y,
_pixops_composite_color (dest->pixels, dest_width, dest_height,
dest->rowstride, dest->n_channels, dest->has_alpha,
src->pixels, src->width, src->height,
src->rowstride, src->n_channels, src->has_alpha,
scale_x, scale_y, (PixopsInterpType)interp_type, overall_alpha, check_x, check_y,
check_size, color1, color2);
dest_x, dest_y, dest_width, dest_height, offset_x,
offset_y, scale_x, scale_y,
(PixopsInterpType)interp_type, overall_alpha,
check_x, check_y, check_size, color1, color2);
}
/**

View File

@ -9,7 +9,7 @@ INCLUDES = \
noinst_PROGRAMS = timescale
timescale_SOURCES = timescale.c
timescale_LDADD = libpixops.la $(GLIB_LIBS) -lm
timescale_LDADD = libpixops.la $(GLIB_LIBS) $(GDK_PIXBUF_EXTRA_LIBS)
if USE_MMX
mmx_sources = \

File diff suppressed because it is too large Load Diff

View File

@ -21,8 +21,6 @@
#include <glib.h>
/* Interpolation modes; must match GdkInterpType */
typedef enum {
PIXOPS_INTERP_NEAREST,
@ -36,24 +34,28 @@ typedef enum {
* render_x, render_y, render_width, render_height in the new
* coordinate system into dest_buf starting at 0, 0
*/
void _pixops_composite (guchar *dest_buf,
int render_x0,
int render_y0,
int render_x1,
int render_y1,
int dest_rowstride,
int dest_channels,
int dest_has_alpha,
const guchar *src_buf,
int src_width,
int src_height,
int src_rowstride,
int src_channels,
int src_has_alpha,
double scale_x,
double scale_y,
PixopsInterpType interp_type,
int overall_alpha);
void _pixops_composite (guchar *dest_buf,
int dest_width,
int dest_height,
int dest_rowstride,
int dest_channels,
int dest_has_alpha,
const guchar *src_buf,
int src_width,
int src_height,
int src_rowstride,
int src_channels,
int src_has_alpha,
int dest_x,
int dest_y,
int dest_region_width,
int dest_region_height,
double offset_x,
double offset_y,
double scale_x,
double scale_y,
PixopsInterpType interp_type,
int overall_alpha);
/* Scale src_buf from src_width / src_height by factors scale_x, scale_y
* and composite the portion corresponding to
@ -61,53 +63,58 @@ void _pixops_composite (guchar *dest_buf,
* coordinate system against a checkboard with checks of size check_size
* of the colors color1 and color2 into dest_buf starting at 0, 0
*/
void _pixops_composite_color (guchar *dest_buf,
int render_x0,
int render_y0,
int render_x1,
int render_y1,
int dest_rowstride,
int dest_channels,
int dest_has_alpha,
const guchar *src_buf,
int src_width,
int src_height,
int src_rowstride,
int src_channels,
int src_has_alpha,
double scale_x,
double scale_y,
PixopsInterpType interp_type,
int overall_alpha,
int check_x,
int check_y,
int check_size,
guint32 color1,
guint32 color2);
void _pixops_composite_color (guchar *dest_buf,
int dest_width,
int dest_height,
int dest_rowstride,
int dest_channels,
int dest_has_alpha,
const guchar *src_buf,
int src_width,
int src_height,
int src_rowstride,
int src_channels,
int src_has_alpha,
int dest_x,
int dest_y,
int dest_region_width,
int dest_region_height,
double offset_x,
double offset_y,
double scale_x,
double scale_y,
PixopsInterpType interp_type,
int overall_alpha,
int check_x,
int check_y,
int check_size,
guint32 color1,
guint32 color2);
/* Scale src_buf from src_width / src_height by factors scale_x, scale_y
* and composite the portion corresponding to
* render_x, render_y, render_width, render_height in the new
* coordinate system into dest_buf starting at 0, 0
*/
void _pixops_scale (guchar *dest_buf,
int render_x0,
int render_y0,
int render_x1,
int render_y1,
int dest_rowstride,
int dest_channels,
int dest_has_alpha,
const guchar *src_buf,
int src_width,
int src_height,
int src_rowstride,
int src_channels,
int src_has_alpha,
double scale_x,
double scale_y,
PixopsInterpType interp_type);
void _pixops_scale (guchar *dest_buf,
int dest_width,
int dest_height,
int dest_rowstride,
int dest_channels,
int dest_has_alpha,
const guchar *src_buf,
int src_width,
int src_height,
int src_rowstride,
int src_channels,
int src_has_alpha,
int dest_x,
int dest_y,
int dest_region_width,
int dest_region_height,
double offset_x,
double offset_y,
double scale_x,
double scale_y,
PixopsInterpType interp_type);
#endif

View File

@ -201,9 +201,13 @@ int main (int argc, char **argv)
start_timing ();
for (i = 0; i < ITERS; i++)
{
_pixops_scale (dest_buf, 0, 0, dest_width, dest_height, dest_rowstride, dest_channels, dest_has_alpha,
src_buf, src_width, src_height, src_rowstride, src_channels, src_has_alpha,
(double)dest_width / src_width, (double)dest_height / src_height,
_pixops_scale (dest_buf, dest_width, dest_height,
dest_rowstride, dest_channels,
dest_has_alpha, src_buf, src_width,
src_height, src_rowstride, src_channels,
src_has_alpha, 0, 0, 0, 0, 0, 0,
(double)dest_width / src_width,
(double)dest_height / src_height,
filter_level);
}
scale_times[src_index][dest_index][filter_level] =
@ -213,21 +217,32 @@ int main (int argc, char **argv)
start_timing ();
for (i = 0; i < ITERS; i++)
{
_pixops_composite (dest_buf, 0, 0, dest_width, dest_height, dest_rowstride, dest_channels, dest_has_alpha,
src_buf, src_width, src_height, src_rowstride, src_channels, src_has_alpha,
(double)dest_width / src_width, (double)dest_height / src_height,
_pixops_composite (dest_buf, dest_width, dest_height,
dest_rowstride, dest_channels,
dest_has_alpha, src_buf, src_width,
src_height, src_rowstride, src_channels,
src_has_alpha, 0, 0, 0, 0, 0, 0,
(double)dest_width / src_width,
(double)dest_height / src_height,
filter_level, 255);
}
composite_times[src_index][dest_index][filter_level] =
stop_timing (" composite\t\t", ITERS, dest_height * dest_width);
stop_timing (" composite\t\t", ITERS,
dest_height * dest_width);
start_timing ();
for (i = 0; i < ITERS; i++)
{
_pixops_composite_color (dest_buf, 0, 0, dest_width, dest_height, dest_rowstride, dest_channels, dest_has_alpha,
src_buf, src_width, src_height, src_rowstride, src_channels, src_has_alpha,
(double)dest_width / src_width, (double)dest_height / src_height,
filter_level, 255, 0, 0, 16, 0xaaaaaa, 0x555555);
_pixops_composite_color (dest_buf, dest_width, dest_height,
dest_rowstride, dest_channels,
dest_has_alpha, src_buf, src_width,
src_height, src_rowstride,
src_channels, src_has_alpha, 0, 0,
0, 0, 0, 0,
(double)dest_width / src_width,
(double)dest_height / src_height,
filter_level, 255, 0, 0, 16,
0xaaaaaa, 0x555555);
}
composite_color_times[src_index][dest_index][filter_level] =
stop_timing (" composite color\t", ITERS, dest_height * dest_width);

View File

@ -45,6 +45,15 @@ LDADD = \
$(no_undefined) \
$(LIBTOOL_EXPORT_OPTIONS)
if USE_MEDIALIB
medialib_sources = \
gdkmedialib.c
medialib_h_sources = \
gdkmedialib.h
else
medialib_sources =
medialib_h_sources =
endif
#
# setup source file variables
@ -84,11 +93,13 @@ gdk_public_h_sources = \
gdk_headers = \
$(gdk_public_h_sources) \
$(medialib_h_sources) \
gdkenumtypes.h \
gdkprivate.h \
gdkalias.h
gdk_c_sources = \
$(medialib_sources) \
gdk.c \
gdkcairo.c \
gdkcolor.c \

View File

@ -730,7 +730,13 @@ gdk_draw_image (GdkDrawable *drawable,
*
* The clip mask of @gc is ignored, but clip rectangles and clip regions work
* fine.
*
*
* If GDK is built with the Sun mediaLib library, the gdk_draw_pixbuf
* function is accelerated using mediaLib, which provides hardware
* acceleration on Intel, AMD, and Sparc chipsets. If desired, mediaLib
* support can be turned off by setting the GDK_DISABLE_MEDIALIB environment
* variable.
*
* Since: 2.2
**/
void
@ -1361,6 +1367,44 @@ composite_0888 (guchar *src_buf,
}
}
#ifdef USE_MEDIALIB
static void
composite_0888_medialib (guchar *src_buf,
gint src_rowstride,
guchar *dest_buf,
gint dest_rowstride,
GdkByteOrder dest_byte_order,
gint width,
gint height)
{
guchar *src = src_buf;
guchar *dest = dest_buf;
mlib_image img_src, img_dst;
mlib_ImageSetStruct (&img_dst,
MLIB_BYTE,
4,
width,
height,
dest_rowstride,
dest_buf);
mlib_ImageSetStruct (&img_src,
MLIB_BYTE,
4,
width,
height,
src_rowstride,
src_buf);
if (dest_byte_order == GDK_LSB_FIRST)
mlib_ImageBlendRGBA2BGRA (&img_dst, &img_src);
else
mlib_ImageBlendRGBA2ARGB (&img_dst, &img_src);
}
#endif
static void
composite_565 (guchar *src_buf,
gint src_rowstride,
@ -1558,7 +1602,16 @@ gdk_drawable_real_draw_pixbuf (GdkDrawable *drawable,
visual->red_mask == 0xff0000 &&
visual->green_mask == 0x00ff00 &&
visual->blue_mask == 0x0000ff)
composite_func = composite_0888;
{
#ifdef USE_MEDIALIB
if (_gdk_use_medialib ())
composite_func = composite_0888_medialib;
else
composite_func = composite_0888;
#else
composite_func = composite_0888;
#endif
}
}
/* We can't use our composite func if we are required to dither

View File

@ -35,6 +35,9 @@
#include <gdk/gdkregion.h>
#include <gdk/gdkvisual.h>
#include <gdk/gdkwindow.h>
#ifdef USE_MEDIALIB
#include <gdk/gdkmedialib.h>
#endif
G_BEGIN_DECLS

View File

@ -2158,6 +2158,29 @@ gdk_rgb_convert_0888 (GdkRgbInfo *image_info, GdkImage *image,
}
}
#ifdef USE_MEDIALIB25
/* convert 24-bit packed to 32-bit unpacked */
static void
gdk_rgb_convert_0888_medialib (GdkRgbInfo *image_info, GdkImage *image,
gint x0, gint y0, gint width, gint height,
guchar *buf, int rowstride,
gint x_align, gint y_align, GdkRgbCmap *cmap)
{
int y, w;
guchar *obuf, *p;
gint bpl;
guchar *bptr, *bp2;
bptr = buf;
bpl = image->bpl;
obuf = ((guchar *)image->mem) + y0 * bpl + x0 * 4;
mlib_VideoColorRGBint_to_BGRAint (obuf, bptr, NULL, 0xff,
width, height, bpl,
rowstride, 0);
}
#endif
static void
gdk_rgb_convert_0888_br (GdkRgbInfo *image_info, GdkImage *image,
gint x0, gint y0, gint width, gint height,
@ -3131,7 +3154,17 @@ gdk_rgb_select_conv (GdkRgbInfo *image_info)
(depth == 24 || depth == 32) &&
vtype == GDK_VISUAL_TRUE_COLOR &&
(mask_rgb && byte_order == GDK_LSB_FIRST))
conv = gdk_rgb_convert_0888;
{
#ifdef USE_MEDIALIB25
if (_gdk_use_medialib ())
conv = gdk_rgb_convert_0888_medialib;
else
conv = gdk_rgb_convert_0888;
#else
conv = gdk_rgb_convert_0888;
#endif
}
#if G_BYTE_ORDER == G_BIG_ENDIAN
else if (bpp == 32 && depth == 24 && vtype == GDK_VISUAL_TRUE_COLOR &&
(mask_bgr && byte_order == GDK_MSB_FIRST))
@ -3148,7 +3181,16 @@ gdk_rgb_select_conv (GdkRgbInfo *image_info)
conv = gdk_rgb_convert_8880_br;
else if (bpp == 32 && depth == 32 && vtype == GDK_VISUAL_TRUE_COLOR &&
(mask_rgb && byte_order == GDK_LSB_FIRST))
conv = gdk_rgb_convert_0888;
{
#ifdef USE_MEDIALIB25
if (_gdk_use_medialib ())
conv = gdk_rgb_convert_0888_medialib;
else
conv = gdk_rgb_convert_0888;
#else
conv = gdk_rgb_convert_0888;
#endif
}
#endif
else if (vtype == GDK_VISUAL_TRUE_COLOR && byte_order == GDK_LSB_FIRST)
{