[PATCH] Add test for a rendering bug in libreoffice.
Eric Anholt
eric at anholt.net
Tue Apr 22 15:32:22 PDT 2014
After changing the get/putimage code in glamor, we found a render
regression that was surprisingly not caught by rendercheck.
---
Makefile.am | 1 +
main.c | 1 +
rendercheck.h | 4 ++
t_libreoffice_xrgb.c | 155 +++++++++++++++++++++++++++++++++++++++++++++++++++
tests.c | 10 ++++
5 files changed, 171 insertions(+)
create mode 100644 t_libreoffice_xrgb.c
diff --git a/Makefile.am b/Makefile.am
index 36d38e4..852d174 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -14,6 +14,7 @@ rendercheck_SOURCES = \
t_fill.c \
t_gradient.c \
t_gtk_argb_xbgr.c \
+ t_libreoffice_xrgb.c \
t_repeat.c \
t_srccoords.c \
t_tsrccoords.c \
diff --git a/main.c b/main.c
index ee02423..a7035b9 100644
--- a/main.c
+++ b/main.c
@@ -122,6 +122,7 @@ struct {
{TEST_TRIANGLES, "triangles"},
{TEST_BUG7366, "bug7366"},
{TEST_GTK_ARGB_XBGR, "gtk_argb_xbgr"},
+ {TEST_LIBREOFFICE_XRGB, "libreoffice_xrgb"},
{0, NULL}
};
diff --git a/rendercheck.h b/rendercheck.h
index c8ad9d6..c745e93 100644
--- a/rendercheck.h
+++ b/rendercheck.h
@@ -82,6 +82,7 @@ struct op_info {
#define TEST_TRIANGLES 0x0800
#define TEST_BUG7366 0x1000
#define TEST_GTK_ARGB_XBGR 0x2000
+#define TEST_LIBREOFFICE_XRGB 0x4000
extern int pixmap_move_iter;
extern int win_width, win_height;
@@ -223,3 +224,6 @@ bug7366_test(Display *dpy);
Bool
gtk_argb_xbgr_test(Display *dpy);
+
+Bool
+libreoffice_xrgb_test(Display *dpy);
diff --git a/t_libreoffice_xrgb.c b/t_libreoffice_xrgb.c
new file mode 100644
index 0000000..09888f6
--- /dev/null
+++ b/t_libreoffice_xrgb.c
@@ -0,0 +1,155 @@
+/* Copyright © 2014 Keith Packard <keithp at keithp.com>
+ * Copyright © 2014 Intel Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/** @file t_libreoffice_xrgb.c
+ *
+ * Test Render's XRGB behavior when the pixmap is initialized with PutImage.
+ * Catches a bug in glamor where the Render acceleration was relying on the
+ * high bits of the pixmap having been set to 0xff, which is certainly not
+ * guaranteed. The rest of rendercheck didn't catch the bug, because it uses
+ * XRenderFillRectangle() to initialize the common XRGB pictures, and
+ * apparently that was setting the unused bits to 1 at the time.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <strings.h>
+#include "rendercheck.h"
+
+#define WIDTH 1
+#define HEIGHT 1
+
+#define PIXEL_ARGB 0xff886644
+#define PIXEL_XRGB 0x11886644
+
+Bool
+libreoffice_xrgb_test(Display *dpy)
+{
+ int x, y;
+ Pixmap src_pix, dst_pix;
+ Picture src_pict, dst_pict;
+ XRenderPictFormat templ;
+ XRenderPictFormat *pic_xrgb_format;
+ XRenderPictFormat *pic_argb_format;
+ XRenderPictFormat *pic_rgb_format;
+ GC gc;
+ XImage *image;
+
+ templ.type = PictTypeDirect;
+ templ.depth = 32;
+ templ.direct.alphaMask = 0;
+ templ.direct.red = 16;
+ templ.direct.green = 8;
+ templ.direct.blue = 0;
+
+ pic_xrgb_format = XRenderFindFormat(dpy,
+ PictFormatType |
+ PictFormatDepth |
+ PictFormatAlphaMask |
+ PictFormatRed |
+ PictFormatGreen |
+ PictFormatBlue,
+ &templ, 0);
+
+ templ.type = PictTypeDirect;
+ templ.depth = 32;
+ templ.direct.alpha = 24;
+ templ.direct.red = 16;
+ templ.direct.green = 8;
+ templ.direct.blue = 0;
+
+ pic_argb_format = XRenderFindFormat(dpy,
+ PictFormatType |
+ PictFormatDepth |
+ PictFormatAlpha |
+ PictFormatRed |
+ PictFormatGreen |
+ PictFormatBlue,
+ &templ, 0);
+
+ templ.type = PictTypeDirect;
+ templ.depth = 24;
+ templ.direct.red = 16;
+ templ.direct.green = 8;
+ templ.direct.blue = 0;
+
+ pic_rgb_format = XRenderFindFormat(dpy,
+ PictFormatType |
+ PictFormatDepth |
+ PictFormatRed |
+ PictFormatGreen |
+ PictFormatBlue,
+ &templ, 0);
+
+ if (!pic_argb_format || !pic_xrgb_format || !pic_rgb_format) {
+ printf("Couldn't find xRGB and ARGB formats\n");
+ return FALSE;
+ }
+
+ src_pix = XCreatePixmap(dpy, RootWindow(dpy, DefaultScreen(dpy)),
+ WIDTH, HEIGHT, 32);
+
+ dst_pix = XCreatePixmap(dpy, RootWindow(dpy, DefaultScreen(dpy)),
+ WIDTH, HEIGHT, 32);
+
+ src_pict = XRenderCreatePicture(dpy, src_pix, pic_xrgb_format, 0,
+ NULL);
+ dst_pict = XRenderCreatePicture(dpy, dst_pix, pic_argb_format, 0,
+ NULL);
+
+ image = XCreateImage(dpy,
+ NULL,
+ 32,
+ ZPixmap,
+ 0,
+ NULL,
+ WIDTH, HEIGHT, 32, 0);
+
+ image->data = malloc(HEIGHT * image->bytes_per_line);
+
+ for (y = 0; y < HEIGHT; y++)
+ for (x = 0; x < WIDTH; x++)
+ XPutPixel(image, x, y, PIXEL_XRGB);
+
+ gc = XCreateGC(dpy, src_pix, 0, NULL);
+
+ XPutImage(dpy, src_pix, gc, image, 0, 0, 0, 0, WIDTH, HEIGHT);
+
+ XDestroyImage(image);
+
+ XRenderComposite(dpy, PictOpOver, src_pict, None, dst_pict,
+ 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT);
+
+ image = XGetImage(dpy, dst_pix, 0, 0, WIDTH, HEIGHT, 0xffffffff,
+ ZPixmap);
+ for (y = 0; y < HEIGHT; y++) {
+ for (x = 0; x < WIDTH; x++) {
+ unsigned long pixel = XGetPixel(image, x, y);
+ if (pixel != PIXEL_ARGB) {
+ printf("fail: pixel value is %08lx, "
+ "should be %08x\n",
+ pixel, PIXEL_ARGB);
+ return FALSE;
+ }
+ }
+ }
+ XDestroyImage(image);
+
+ return TRUE;
+}
diff --git a/tests.c b/tests.c
index 8271d4c..fbb87e2 100644
--- a/tests.c
+++ b/tests.c
@@ -742,6 +742,16 @@ do { \
success_mask |= TEST_GTK_ARGB_XBGR;
}
+ if (enabled_tests & TEST_LIBREOFFICE_XRGB) {
+ Bool ok, group_ok = TRUE;
+
+ ok = libreoffice_xrgb_test(dpy);
+ RECORD_RESULTS();
+
+ if (group_ok)
+ success_mask |= TEST_LIBREOFFICE_XRGB;
+ }
+
free(test_ops);
free(test_src);
free(test_mask);
--
1.9.2
More information about the xorg-devel
mailing list