--- rxvt-unicode/src/background.C 2011/12/25 17:07:00 1.184 +++ rxvt-unicode/src/background.C 2012/01/01 14:31:29 1.193 @@ -35,6 +35,24 @@ #endif #ifdef HAVE_BG_PIXMAP +# if XRENDER +static Picture +create_xrender_mask (Display *dpy, Drawable drawable, Bool argb, Bool component_alpha) +{ + Pixmap pixmap = XCreatePixmap (dpy, drawable, 1, 1, argb ? 32 : 8); + + XRenderPictFormat *format = XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8); + XRenderPictureAttributes pa; + pa.repeat = True; + pa.component_alpha = component_alpha; + Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat | CPComponentAlpha, &pa); + + XFreePixmap (dpy, pixmap); + + return mask; +} +# endif + void rxvt_term::bg_destroy () { @@ -183,7 +201,7 @@ int geom_flags = 0; int x = 0, y = 0; unsigned int w = 0, h = 0; - unsigned long new_flags = bg_flags & ~BG_GEOMETRY_FLAGS; + unsigned long new_flags = 0; if (geom == NULL) return false; @@ -286,6 +304,8 @@ rxvt_free_strsplit (arr); } + new_flags |= bg_flags & ~BG_GEOMETRY_FLAGS; + if (!update) { if (!(geom_flags & XValue)) @@ -374,9 +394,8 @@ ShadingInfo as_shade; as_shade.shading = shade; - rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); - if (bg_flags & BG_TINT_SET) - tint.get (c); + rgba c; + tint.get (c); as_shade.tintColor.red = c.r; as_shade.tintColor.green = c.g; as_shade.tintColor.blue = c.b; @@ -802,27 +821,22 @@ #if XRENDER if (tr_flags) { - XRenderPictureAttributes pa; + XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); - XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, visual); - Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); + Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0); - XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); - Picture dst = XRenderCreatePicture (dpy, bg_pixmap, dst_format, 0, &pa); + Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); - pa.repeat = True; - Pixmap mask_pmap = XCreatePixmap (dpy, vt, 1, 1, 8); - XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8); - Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa); - XFreePixmap (dpy, mask_pmap); + Picture mask = create_xrender_mask (dpy, vt, False, False); XRenderColor mask_c; mask_c.alpha = 0x8000; - mask_c.red = 0; - mask_c.green = 0; - mask_c.blue = 0; + mask_c.red = + mask_c.green = + mask_c.blue = 0; XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); + XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height); XRenderFreePicture (dpy, src); @@ -944,7 +958,7 @@ v_blurRadius = vr; } - if (v_blurRadius == 0 && h_blurRadius == 0) + if (h_blurRadius == 0 || v_blurRadius == 0) bg_flags &= ~BG_NEEDS_BLUR; else bg_flags |= BG_NEEDS_BLUR; @@ -960,27 +974,27 @@ bg_flags &= ~BG_TINT_FLAGS; - if (bg_flags & BG_TINT_SET) - { - tint.get (c); - if (!has_shade - && (c.r <= 0x00ff || c.r >= 0xff00) - && (c.g <= 0x00ff || c.g >= 0xff00) - && (c.b <= 0x00ff || c.b >= 0xff00)) - bg_flags |= BG_TINT_BITAND; - } + tint.get (c); - if (has_shade || (bg_flags & BG_TINT_SET)) + if (!has_shade + && (c.r <= 0x00ff || c.r >= 0xff00) + && (c.g <= 0x00ff || c.g >= 0xff00) + && (c.b <= 0x00ff || c.b >= 0xff00)) + bg_flags |= BG_TINT_BITAND; + + if (has_shade + || c.r < 0xff00 + || c.g < 0xff00 + || c.b < 0xff00) bg_flags |= BG_NEEDS_TINT; } bool rxvt_term::bg_set_tint (rxvt_color &new_tint) { - if (!(bg_flags & BG_TINT_SET) || tint != new_tint) + if (tint != new_tint) { tint = new_tint; - bg_flags |= BG_TINT_SET; set_tint_shade_flags (); return true; } @@ -991,7 +1005,7 @@ bool rxvt_term::bg_set_shade (const char *shade_str) { - int new_shade = (shade_str) ? atoi (shade_str) : 100; + int new_shade = atoi (shade_str); clamp_it (new_shade, -100, 200); if (new_shade < 0) @@ -1042,48 +1056,41 @@ double *kernel = (double *)malloc (size * sizeof (double)); XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); - XRenderPictureAttributes pa; XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); - Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); - Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); + Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, 0); + Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, 0); if (kernel && params) { - if (h_blurRadius) - { - size = h_blurRadius * 2 + 1; - get_gaussian_kernel (h_blurRadius, size, kernel, params); + size = h_blurRadius * 2 + 1; + get_gaussian_kernel (h_blurRadius, size, kernel, params); - XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); - XRenderComposite (dpy, - PictOpSrc, - src, - None, - dst, - 0, 0, - 0, 0, - 0, 0, - width, height); - } - - if (v_blurRadius) - { - size = v_blurRadius * 2 + 1; - get_gaussian_kernel (v_blurRadius, size, kernel, params); - ::swap (params[0], params[1]); - - XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); - XRenderComposite (dpy, - PictOpSrc, - src, - None, - dst, - 0, 0, - 0, 0, - 0, 0, - width, height); - } + XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); + XRenderComposite (dpy, + PictOpSrc, + src, + None, + dst, + 0, 0, + 0, 0, + 0, 0, + width, height); + + size = v_blurRadius * 2 + 1; + get_gaussian_kernel (v_blurRadius, size, kernel, params); + ::swap (params[0], params[1]); + + XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); + XRenderComposite (dpy, + PictOpSrc, + src, + None, + dst, + 0, 0, + 0, 0, + 0, 0, + width, height); ret = true; } @@ -1123,10 +1130,9 @@ # if XRENDER else if (bg_flags & BG_HAS_RENDER) { - rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); + rgba c; - if (bg_flags & BG_TINT_SET) - tint.get (c); + tint.get (c); if (shade <= 100) { @@ -1141,22 +1147,13 @@ c.b = c.b * (200 - shade) / 100; } - XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); - XRenderPictureAttributes pa; - Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); + Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0); - pa.repeat = True; + Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False); - Pixmap overlay_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); - Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); - XFreePixmap (dpy, overlay_pmap); - - pa.component_alpha = True; - Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); - Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat | CPComponentAlpha, &pa); - XFreePixmap (dpy, mask_pmap); + Picture mask_pic = create_xrender_mask (dpy, pixmap, True, True); XRenderColor mask_c; @@ -1171,12 +1168,15 @@ mask_c.green = 0xffff - c.g; mask_c.blue = 0xffff - c.b; XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); + XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height); if (shade > 100) { - mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100; mask_c.alpha = 0; + mask_c.red = + mask_c.green = + mask_c.blue = 0xffff * (shade - 100) / 100; XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height); @@ -1249,13 +1249,11 @@ { recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); - XRenderPictureAttributes pa; - XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); - Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); + Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0); XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); - Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); + Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, 0); XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); @@ -1295,7 +1293,6 @@ { XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS); - XFreeGC (dpy, gc); if (!(bg_flags & BG_CLIENT_RENDER)) { @@ -1309,7 +1306,23 @@ if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) result &= ~BG_NEEDS_TINT; } +# ifndef HAVE_AFTERIMAGE + if (result & BG_NEEDS_TINT) + { + XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); + if (ximage) + { + /* our own client-side tinting */ + tint_ximage (DefaultVisual (dpy, display->screen), ximage); + + XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); + XDestroyImage (ximage); + } + } +# endif } /* server side rendering completed */ + + XFreeGC (dpy, gc); } if (recoded_root_pmap != root_pixmap) @@ -1355,34 +1368,6 @@ } # endif -# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) - XImage *result = NULL; - - if (tr_flags & BG_NEEDS_TINT) - { - result = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); - } - - if (result) - { - /* our own client-side tinting */ - //if (tr_flags & BG_NEEDS_TINT) - if (1) - tint_ximage (DefaultVisual (dpy, display->screen), result); - - GC gc = XCreateGC (dpy, vt, 0UL, NULL); - - if (gc) - { - XPutImage (dpy, bg_pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); - - XFreeGC (dpy, gc); - } - - XDestroyImage (result); - } -# endif - if (!(bg_flags & BG_IS_VALID)) { if (bg_pixmap != None) @@ -1404,6 +1389,8 @@ rxvt_term::bg_init () { #ifdef ENABLE_TRANSPARENCY + rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); + tint.set (this, c); shade = 100; #endif @@ -1516,10 +1503,9 @@ return; /* we do not support this color depth */ } - rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); + rgba c; - if (bg_flags & BG_TINT_SET) - tint.get (c); + tint.get (c); /* prepare limits for color transformation (each channel is handled separately) */ if (shade > 100)