When sourcing a picture that has no alpha values, make sure any
texture fetches wire the alpha value to one. This ensures that bits
beyond the depth of the pixmap, or bits other than the RGB values
aren't used.
Here's the actual patch:From 30ef8c0ec2808aa89a392ea8e744e12cec1bec37 Mon Sep 17 00:00:00 2001 From: Keith Packard <[email protected]> Date: Tue, 22 Apr 2014 14:52:51 -0700 Subject: [PATCH] glamor: Wire alpha to 1 for pictures without alpha bits When sourcing a picture that has no alpha values, make sure any texture fetches wire the alpha value to one. This ensures that bits beyond the depth of the pixmap, or bits other than the RGB values aren't used. Signed-off-by: Keith Packard <[email protected]> --- glamor/glamor_render.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/glamor/glamor_render.c b/glamor/glamor_render.c index 2f3d950..af0b6b8 100644 --- a/glamor/glamor_render.c +++ b/glamor/glamor_render.c @@ -880,7 +880,10 @@ glamor_composite_choose_shader(CARD8 op, goto fail; } else { - key.source = SHADER_SOURCE_TEXTURE_ALPHA; + if (PICT_FORMAT_A(source->format)) + key.source = SHADER_SOURCE_TEXTURE_ALPHA; + else + key.source = SHADER_SOURCE_TEXTURE; } if (mask) { -- 1.9.2
And here's a test case:
/* cc -o render-invert render-invert.c `pkg-config --cflags --libs xrender x11` * * Copyright © 2014 Keith Packard <[email protected]> * * 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; version 2 of the License. * * 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., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ /* Test mixing Render with core Invert operation */ #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <strings.h> #include <X11/Xos.h> #include <X11/Xlib.h> #include <X11/Xutil.h> #include <X11/Xatom.h> #include <X11/extensions/Xrender.h> #define WIDTH 1 #define HEIGHT 1 #define PIXEL_ARGB 0xff446688 #define PIXEL_RGB 0x11446688 int main(int argc, char **argv) { int x, y; Pixmap pix_32; Pixmap pix_24; Picture pic_24; Picture pic_32_argb; XRenderPictFormat templ; XRenderPictFormat *pic_argb_format; XRenderPictFormat *pic_rgb_format; GC gc_24; XImage *image_24, *image_32; Display *dpy; dpy = XOpenDisplay(NULL); if (!dpy) { printf ("Cannot open display\n"); exit(1); } 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); pix_24 = XCreatePixmap(dpy, RootWindow(dpy, DefaultScreen(dpy)), WIDTH, HEIGHT, 24); pic_24 = XRenderCreatePicture(dpy, pix_24, pic_rgb_format, 0, NULL); image_24 = XCreateImage(dpy, NULL, 24, ZPixmap, 0, NULL, WIDTH, HEIGHT, 32, 0); image_24->data = malloc (HEIGHT * image_24->bytes_per_line); for (y = 0; y < HEIGHT; y++) for (x = 0; x < WIDTH; x++) XPutPixel(image_24, x, y, ~PIXEL_RGB); gc_24 = XCreateGC(dpy, pix_24, 0, NULL); XPutImage(dpy, pix_24, gc_24, image_24, 0, 0, 0, 0, WIDTH, HEIGHT); XSetFunction(dpy, gc_24, GXinvert); XFillRectangle(dpy, pix_24, gc_24, 0, 0, WIDTH, HEIGHT); pix_32 = XCreatePixmap(dpy, RootWindow(dpy, DefaultScreen(dpy)), WIDTH, HEIGHT, 32); pic_32_argb = XRenderCreatePicture(dpy, pix_32, pic_argb_format, 0, NULL); XRenderComposite(dpy, PictOpOver, pic_24, None, pic_32_argb, 0, 0, 0, 0, 0, 0, WIDTH, HEIGHT); image_32 = XGetImage(dpy, pix_32, 0, 0, WIDTH, HEIGHT, 0xffffffff, ZPixmap); for (y = 0; y < HEIGHT; y++) { for (x = 0; x < WIDTH; x++) { unsigned long pixel = XGetPixel(image_32, x, y); if (pixel != PIXEL_ARGB) { printf ("fail: pixel error is %08lx should be %08x\n", pixel, PIXEL_ARGB); exit(1); } } } printf ("pass\n"); exit(0); }
-- [email protected]
pgpCrYp6oPNBv.pgp
Description: PGP signature
_______________________________________________ [email protected]: X.Org development Archives: http://lists.x.org/archives/xorg-devel Info: http://lists.x.org/mailman/listinfo/xorg-devel
