diff options
author | Zack Rusin <zack@ppc64.localdomain> | 2006-03-17 02:34:45 -0500 |
---|---|---|
committer | Zack Rusin <zack@ppc64.localdomain> | 2006-03-17 02:34:45 -0500 |
commit | 6382dcb9a3cb3f437b0b468d6684d5fb2753b720 (patch) | |
tree | 33c47f18c2be12303d880390eb309799d0ff5630 | |
parent | adcc63c9cf1d506293191c04a7d5b3414b4004e6 (diff) |
removing Qt dependency and adding autotools support
-rw-r--r-- | AUTHORS | 0 | ||||
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | Makefile.am | 10 | ||||
-rw-r--r-- | NEWS | 0 | ||||
-rw-r--r-- | README | 0 | ||||
-rwxr-xr-x | autogen.sh | 13 | ||||
-rw-r--r-- | configure.ac | 16 | ||||
-rw-r--r-- | images/bg1.png | bin | 0 -> 379029 bytes | |||
-rw-r--r-- | images/bg2.png | bin | 0 -> 148 bytes | |||
-rw-r--r-- | main.c (renamed from main.cpp) | 38 | ||||
-rw-r--r-- | readpng.c | 169 | ||||
-rw-r--r-- | surface.c (renamed from surface.cpp) | 24 | ||||
-rw-r--r-- | surface.h | 5 | ||||
-rw-r--r-- | testscenarios.c (renamed from testscenarios.cpp) | 11 | ||||
-rw-r--r-- | utils.c (renamed from utils.cpp) | 26 | ||||
-rw-r--r-- | utils.h | 2 | ||||
-rw-r--r-- | xrenderbenchmark.pro | 11 | ||||
-rw-r--r-- | xrenderbenchmark.qrc | 8 |
18 files changed, 257 insertions, 80 deletions
diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..6fc8b74 --- /dev/null +++ b/ChangeLog @@ -0,0 +1,4 @@ +2006-03-17 Zack Rusin <zack@kde.org> + + * Initial version + diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..dfd001e --- /dev/null +++ b/Makefile.am @@ -0,0 +1,10 @@ +bin_PROGRAMS = xrenderbenchmark + +xrenderbenchmark_CFLAGS = $(XRENDERBENCHMARK_CFLAGS) +xrenderbenchmark_LDADD = $(XRENDERBENCHMARK_LIBS) + +xrenderbenchmark_SOURCES = \ + main.c readpng.c \ + surface.c surface.h \ + testscenarios.c testscenarios.h \ + utils.c utils.h diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..e81f989 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,13 @@ +#! /bin/sh + +srcdir=`dirname $0` +test -z "$srcdir" && srcdir=. + +ORIGDIR=`pwd` +cd $srcdir + +autoreconf -v --install || exit 1 +cd $ORIGDIR || exit $? + +$srcdir/configure --enable-maintainer-mode "$@" + diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..49d69ea --- /dev/null +++ b/configure.ac @@ -0,0 +1,16 @@ +AC_PREREQ([2.57]) +AC_INIT(xrenderbenchmark,[1.0.1], [https://bugs.freedesktop.org/enter_bug.cgi?product=xorg],xrenderbenchmark) +AM_INIT_AUTOMAKE([dist-bzip2]) +AM_MAINTAINER_MODE + +AM_CONFIG_HEADER(config.h) + +AC_PROG_CC +AC_PROG_INSTALL + +# Checks for pkg-config packages +PKG_CHECK_MODULES(XRENDERBENCHMARK, libpng12 x11 xrender) +AC_SUBST(XRENDERBENCHMARK_CFLAGS) +AC_SUBST(XRENDERBENCHMARK_LIBS) + +AC_OUTPUT([Makefile]) diff --git a/images/bg1.png b/images/bg1.png Binary files differnew file mode 100644 index 0000000..7d22e75 --- /dev/null +++ b/images/bg1.png diff --git a/images/bg2.png b/images/bg2.png Binary files differnew file mode 100644 index 0000000..93a5a92 --- /dev/null +++ b/images/bg2.png @@ -1,10 +1,3 @@ -#include <QApplication> -#include <QImage> -#include <QPixmap> -#include <QX11Info> -#include <QPainter> -#include <QString> - #include <X11/Xlib.h> #include <X11/extensions/Xrender.h> @@ -80,20 +73,24 @@ test_oper(int op, XRenderSurf *src, XRenderSurf *mask, XRenderSurf *dst) static Picture createBackgroundPicture() { - // Create a background tile pixmap - static QPixmap bg(40, 40); - QPainter p(&bg); - p.fillRect(bg.rect(), QColor(90, 90, 90)); - p.fillRect(QRect(0,0,20,20), QColor(200, 200, 200)); - p.fillRect(QRect(20,20,20,20), QColor(200, 200, 200)); - p.end(); - - // Change the repeat setting for the bg pixmap so it tiles, and clear the window with it + unsigned int w, h; + char *data; + Picture back; + XRenderSurf *surf = xrender_surf_new(disp, win, PictStandardRGB24, 40, 40); + + readPng("images/bg2.png", &data, &w, &h); + xrender_surf_populate(disp, surf, w, h, data); XRenderPictureAttributes pa; - pa.repeat = true; - XRenderChangePicture(disp, bg.x11PictureHandle(), CPRepeat, &pa); + pa.repeat = 1; + XRenderChangePicture(disp, surf->pic, CPRepeat, &pa); + + back = surf->pic; + + if (surf->allocated) + XFreePixmap(disp, surf->draw); + free(surf); - return bg.x11PictureHandle(); + return back; } void @@ -143,8 +140,7 @@ main_loop(void) int main(int argc, char **argv) { - QApplication app(argc, argv); - disp = QX11Info::display(); + disp = XOpenDisplay(0); if (!disp) { fprintf(stderr, "Error: Cannot connect to display!\n"); exit(-1); diff --git a/readpng.c b/readpng.c new file mode 100644 index 0000000..bf2742d --- /dev/null +++ b/readpng.c @@ -0,0 +1,169 @@ +/* + * Copyright © 2005 Novell, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Novell, Inc. not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * Novell, Inc. makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: David Reveman <davidr@novell.com> + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <png.h> +#include <setjmp.h> + +#define FALSE 0 +#define TRUE (!FALSE) +static void +premultiplyData (png_structp png, + png_row_infop row_info, + png_bytep data) +{ + unsigned int i; + + for (i = 0; i < row_info->rowbytes; i += 4) + { + unsigned char *base = &data[i]; + unsigned char blue = base[0]; + unsigned char green = base[1]; + unsigned char red = base[2]; + unsigned char alpha = base[3]; + int p; + + red = (unsigned) red * (unsigned) alpha / 255; + green = (unsigned) green * (unsigned) alpha / 255; + blue = (unsigned) blue * (unsigned) alpha / 255; + + p = (alpha << 24) | (red << 16) | (green << 8) | (blue << 0); + memcpy (base, &p, sizeof (int)); + } +} + +int readPng(const char *filename, + char **data, + unsigned int *width, + unsigned int *height) +{ + static const int PNG_SIG_SIZE = 8; + unsigned char png_sig[PNG_SIG_SIZE]; + FILE *file; + int sig_bytes; + png_struct *png; + png_info *info; + png_uint_32 png_width, png_height; + int depth, color_type, interlace, i; + unsigned int pixel_size; + png_byte **row_pointers; + + file = fopen (filename, "r"); + if (!file) + { + fprintf(stderr, "Couldn't open file: '%s'\n", filename); + return FALSE; + } + + sig_bytes = fread (png_sig, 1, PNG_SIG_SIZE, file); + if (png_check_sig (png_sig, sig_bytes) == 0) + { + fclose (file); + return FALSE; + } + + png = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (!png) + { + fclose (file); + return FALSE; + } + + info = png_create_info_struct (png); + if (info == NULL) + { + fclose (file); + png_destroy_read_struct (&png, NULL, NULL); + return FALSE; + } + + png_init_io (png, file); + png_set_sig_bytes (png, sig_bytes); + + png_read_info (png, info); + + png_get_IHDR (png, info, + &png_width, &png_height, &depth, + &color_type, &interlace, NULL, NULL); + *width = png_width; + *height = png_height; + + /* convert palette/gray image to rgb */ + if (color_type == PNG_COLOR_TYPE_PALETTE) + png_set_palette_to_rgb (png); + + /* expand gray bit depth if needed */ + if (color_type == PNG_COLOR_TYPE_GRAY && depth < 8) + png_set_gray_1_2_4_to_8 (png); + + /* transform transparency to alpha */ + if (png_get_valid(png, info, PNG_INFO_tRNS)) + png_set_tRNS_to_alpha (png); + + if (depth == 16) + png_set_strip_16 (png); + + if (depth < 8) + png_set_packing (png); + + /* convert grayscale to RGB */ + if (color_type == PNG_COLOR_TYPE_GRAY || + color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + png_set_gray_to_rgb (png); + + if (interlace != PNG_INTERLACE_NONE) + png_set_interlace_handling (png); + + png_set_bgr (png); + png_set_filler (png, 0xff, PNG_FILLER_AFTER); + + png_set_read_user_transform_fn (png, premultiplyData); + + png_read_update_info (png, info); + + pixel_size = 4; + *data = (char *) malloc (png_width * png_height * pixel_size); + if (*data == NULL) + { + fclose (file); + return FALSE; + } + + row_pointers = (png_byte **) malloc (png_height * sizeof (char *)); + for (i=0; i < png_height; i++) + row_pointers[i] = (png_byte *) (*data + i * png_width * pixel_size); + + png_read_image (png, row_pointers); + png_read_end (png, info); + + free (row_pointers); + fclose (file); + + png_destroy_read_struct (&png, &info, NULL); + + return TRUE; +} @@ -1,5 +1,3 @@ -#include <QImage> - #include "surface.h" #include <stdlib.h> @@ -59,7 +57,8 @@ xrender_surf_free(Display *disp, XRenderSurf *rs) } void -xrender_surf_populate(Display *disp, XRenderSurf *rs, int w, int h, const QImage &img_data) +xrender_surf_populate(Display *disp, XRenderSurf *rs, int w, int h, + char *img_data) { GC gc; XGCValues gcv; @@ -73,17 +72,14 @@ xrender_surf_populate(Display *disp, XRenderSurf *rs, int w, int h, const QImage { for (x = 0; x < w; x++) { - QRgb pixel; - int a, r, g, b; - - pixel = img_data.pixel(x, y); - a = (pixel >> 24) & 0xff; - r = (pixel >> 16) & 0xff; - g = (pixel >> 8 ) & 0xff; - b = (pixel ) & 0xff; - r = (r * (a + 1)) / 256; - g = (g * (a + 1)) / 256; - b = (b * (a + 1)) / 256; + int a, r, g, b, offset; + + offset = y*w*4 + x*4; + a = img_data[offset + 0]; + r = img_data[offset + 1]; + g = img_data[offset + 2]; + b = img_data[offset + 3]; + XPutPixel(xim, x, y, (a << 24) | (r << 16) | (g << 8) | b); } } @@ -4,8 +4,6 @@ #include <X11/extensions/Xrender.h> #include <X11/Xlib.h> -class QImage; - typedef enum _SurfaceFilter { SurfaceNone, SurfaceNearest, @@ -26,8 +24,7 @@ typedef struct _XRenderSurf { XRenderSurf *xrender_surf_new(Display *disp, Drawable draw, int w, int h, int alpha); XRenderSurf *xrender_surf_adopt(Display *disp, Drawable draw, int w, int h); void xrender_surf_free(Display *disp, XRenderSurf *rs); -void xrender_surf_populate(Display *disp, XRenderSurf *rs, int w, int h, - const QImage &img_data); +void xrender_surf_populate(Display *disp, XRenderSurf *rs, int w, int h, char *img_data); void xrender_surf_prepare(Display *disp, XRenderSurf *src, int w, int h, int transformations, SurfaceFilter filter); void xrender_surf_blend(Display *disp, int op, XRenderSurf *src, XRenderSurf *mask, XRenderSurf *dst, diff --git a/testscenarios.cpp b/testscenarios.c index c744a57..25c59bf 100644 --- a/testscenarios.cpp +++ b/testscenarios.c @@ -1,4 +1,3 @@ -#include <QX11Info> #include "testscenarios.h" #include "surface.h" #include "utils.h" @@ -23,8 +22,8 @@ TestScenario * create_test_scenarios(Display *disp, Window win, int w, int h, in current->dst = xrender_surf_adopt(disp, win, w, h); current->mask = 0; current->src = xrender_surf_new(disp, win, PictStandardRGB24, 128, 128); - populate_from_file(disp, current->dst, ":/res/images/bg1.jpg"); - populate_from_file(disp, current->src, ":/res/images/kde_gear_64.png"); + populate_from_file(disp, current->dst, "images/bg1.png"); + populate_from_file(disp, current->src, "images/kde_gear_64.png"); current = &scenarios[currentNumber++]; @@ -33,7 +32,7 @@ TestScenario * create_test_scenarios(Display *disp, Window win, int w, int h, in current->dst = xrender_surf_adopt(disp, win, w, h); current->mask = 0; current->src = xrender_surf_new(disp, win,PictStandardARGB32, 128, 128); - populate_from_file(disp, current->src, ":/res/images/kde_gear_64_alpha.png"); + populate_from_file(disp, current->src, "images/kde_gear_64_alpha.png"); current = &scenarios[currentNumber++]; /*********************************/ @@ -42,7 +41,7 @@ TestScenario * create_test_scenarios(Display *disp, Window win, int w, int h, in current->mask = 0; current->src = xrender_surf_new(disp, win, PictStandardRGB24, 128, 128); - populate_from_file(disp, current->src, ":/res/images/kde_gear_64.png"); + populate_from_file(disp, current->src, "images/kde_gear_64.png"); xrender_surf_prepare(disp, current->src, current->src->w, current->src->h, 1, SurfaceNone); @@ -52,7 +51,7 @@ TestScenario * create_test_scenarios(Display *disp, Window win, int w, int h, in current->dst = xrender_surf_adopt(disp, win, w, h); current->mask = 0; current->src = xrender_surf_new(disp, win, PictStandardRGB24, 128, 128); - populate_from_file(disp, current->src, ":/res/images/kde_gear_64.png"); + populate_from_file(disp, current->src, "images/kde_gear_64.png"); xrender_surf_prepare(disp, current->src, current->src->w, current->src->h, 1, SurfaceBilinear); @@ -1,22 +1,18 @@ -#include <QX11Info> -#include <QImage> -#include <QString> #include "utils.h" +#include "surface.h" +#include "testscenarios.h" + #include <X11/Xlib.h> -#include <X11/Xutil.h> #include <X11/extensions/Xrender.h> -#include <X11/extensions/XShm.h> #include <sys/time.h> #include <time.h> #include <signal.h> +#include <unistd.h> #include <stdio.h> #include <stdlib.h> -#include "surface.h" -#include "testscenarios.h" - extern int win_w; extern int win_h; extern Display *disp; @@ -50,7 +46,7 @@ time_test(char *description, void (*func) (int op, XRenderSurf *src, XRenderSurf keep_running = 1; while (keep_running) { func(op->op, src, mask, dst); - XSync(QX11Info::display(), 0); + XSync(disp, 0); ++frame_cnt; } } @@ -58,13 +54,11 @@ time_test(char *description, void (*func) (int op, XRenderSurf *src, XRenderSurf void populate_from_file(Display *disp, XRenderSurf *rs, const char *file) { - QImage im; - int w, h; + char *img_data; + unsigned int w, h; - im.load(QString(file)); - w = im.width(); - h = im.height(); - xrender_surf_populate(disp, rs, w, h, im); + readPng(file, &img_data, &w, &h); + xrender_surf_populate(disp, rs, w, h, img_data); } @@ -75,7 +69,7 @@ setup_window(void) XClassHint *xch; att.background_pixmap = None; - att.colormap = DefaultColormap(QX11Info::display(), DefaultScreen(disp)); + att.colormap = DefaultColormap(disp, DefaultScreen(disp)); att.border_pixel = 0; att.event_mask = ButtonPressMask | @@ -23,5 +23,7 @@ void time_test(char *description, void (*func)(int op, XRenderSurf *src, XRend void populate_from_file(Display *disp, XRenderSurf *rs, const char *file); void setup_window(void); void alarmhandler(int sig); +int readPng(const char *filename, char **data, + unsigned int *width, unsigned int *height); #endif diff --git a/xrenderbenchmark.pro b/xrenderbenchmark.pro deleted file mode 100644 index 15faefb..0000000 --- a/xrenderbenchmark.pro +++ /dev/null @@ -1,11 +0,0 @@ -TEMPLATE = app -INCLUDEPATH += . - -# Input -SOURCES += surface.cpp main.cpp testscenarios.cpp utils.cpp - -RESOURCES = xrenderbenchmark.qrc - -OBJECTS_DIR = .tmp -MOC_DIR = .tmp -RESOURCES_DIR = .tmp diff --git a/xrenderbenchmark.qrc b/xrenderbenchmark.qrc deleted file mode 100644 index 1b2ccdd..0000000 --- a/xrenderbenchmark.qrc +++ /dev/null @@ -1,8 +0,0 @@ -<!DOCTYPE RCC><RCC version="1.0"> -<qresource prefix="/res"> - <file>images/bg1.jpg</file> - <file>images/qtlogo.png</file> - <file>images/kde_gear_64.png</file> - <file>images/kde_gear_64_alpha.png</file> -</qresource> -</RCC> |