--- rxvt-unicode/src/rxvtimg.C 2012/06/07 11:34:09 1.41 +++ rxvt-unicode/src/rxvtimg.C 2012/06/07 18:07:42 1.46 @@ -393,6 +393,27 @@ return new rxvt_img (*this); } + +static XRenderPictFormat * +find_alpha_format_for (Display *dpy, XRenderPictFormat *format) +{ + if (format->direct.alphaMask) + return format; // already has alpha + + // try to find a suitable alpha format, one bit alpha is enough for our purposes + if (format->type == PictTypeDirect) + for (int n = 0; XRenderPictFormat *f = XRenderFindFormat (dpy, 0, 0, n); ++n) + if (f->direct.alphaMask + && f->type == PictTypeDirect + && ecb_popcount32 (f->direct.redMask ) >= ecb_popcount32 (format->direct.redMask ) + && ecb_popcount32 (f->direct.greenMask) >= ecb_popcount32 (format->direct.greenMask) + && ecb_popcount32 (f->direct.blueMask ) >= ecb_popcount32 (format->direct.blueMask )) + return f; + + // should be a very good fallback + return XRenderFindStandardFormat (dpy, PictStandardARGB32); +} + rxvt_img * rxvt_img::reify () { @@ -405,14 +426,21 @@ && (x || y) && repeat == RepeatNone; - rxvt_img *img = new rxvt_img (s, alpha ? XRenderFindStandardFormat (dpy, PictStandardARGB32) : format, 0, 0, w, h, repeat); + rxvt_img *img = new rxvt_img (s, alpha ? find_alpha_format_for (dpy, format) : format, 0, 0, w, h, repeat); img->alloc (); Picture src = src_picture (); Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); - XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h); - + if (alpha) + { + XRenderColor rc = { 0, 0, 0, 0 }; + XRenderFillRectangle (dpy, PictOpSrc, dst, &rc, 0, 0, w, h);//TODO: split into four fillrectangles + XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, -x, -y, ref->w, ref->h); + } + else + XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h); + XRenderFreePicture (dpy, src); XRenderFreePicture (dpy, dst); @@ -456,8 +484,10 @@ for (int j = 0; j < 3; ++j) xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]); - xfrm.matrix [0][2] += XDoubleToFixed (x);//TODO - xfrm.matrix [0][3] += XDoubleToFixed (y); +#if 0 + xfrm.matrix [0][2] -= XDoubleToFixed (x);//TODO + xfrm.matrix [1][2] -= XDoubleToFixed (y); +#endif XRenderSetPictureFilter (dpy, src, "good", 0, 0); XRenderSetPictureTransform (dpy, src, &xfrm); @@ -472,13 +502,24 @@ rxvt_img * rxvt_img::scale (int new_width, int new_height) { + if (w == new_width && h == new_height) + return clone (); + double matrix[9] = { w / (double)new_width, 0, 0, 0, h / (double)new_height, 0, 0, 0, 1 }; - return transform (new_width, new_height, matrix); + int old_repeat_mode = repeat; + repeat = RepeatPad; // not right, but xrender can't proeprly scale it seems + + rxvt_img *img = transform (new_width, new_height, matrix); + + repeat = old_repeat_mode; + img->repeat = repeat; + + return img; } rxvt_img * @@ -497,12 +538,12 @@ } rxvt_img * -rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg) +rxvt_img::convert_format (XRenderPictFormat *new_format, const rxvt_color &bg) { if (new_format == format) return clone (); - rxvt_img *img = new rxvt_img (s, new_format, 0, 0, w, h, repeat); + rxvt_img *img = new rxvt_img (s, new_format, x, y, w, h, repeat); img->alloc (); Display *dpy = s->display->dpy;