--- rxvt-unicode/src/background.C 2011/11/23 16:53:53 1.174 +++ rxvt-unicode/src/background.C 2012/01/10 18:50:14 1.196 @@ -34,7 +34,29 @@ #define FilterConvolution "convolution" #endif +#ifndef RepeatPad +#define RepeatPad True +#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 +205,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; @@ -203,7 +225,7 @@ } else if (!strcasecmp (arr[i], "style=aspect-stretched")) { - new_flags = BG_PROP_SCALE; + new_flags = BG_KEEP_ASPECT; w = h = windowScale; x = y = centerAlign; geom_flags = WidthValue|HeightValue|XValue|YValue; @@ -229,9 +251,9 @@ } else if (!strcasecmp (arr[i], "op=tile")) new_flags |= BG_TILE; - else if (!strcasecmp (arr[i], "op=pscale")) - new_flags |= BG_PROP_SCALE; - else if (!strcasecmp (arr[i], "op=root")) + else if (!strcasecmp (arr[i], "op=keep-aspect")) + new_flags |= BG_KEEP_ASPECT; + else if (!strcasecmp (arr[i], "op=root-align")) new_flags |= BG_ROOT_ALIGN; // deprecated @@ -243,7 +265,9 @@ } else if (!strcasecmp (arr[i], "propscale")) { - new_flags |= BG_PROP_SCALE; + new_flags |= BG_KEEP_ASPECT; + w = h = windowScale; + geom_flags |= WidthValue|HeightValue; } else if (!strcasecmp (arr[i], "hscale")) { @@ -284,6 +308,8 @@ rxvt_free_strsplit (arr); } + new_flags |= bg_flags & ~BG_GEOMETRY_FLAGS; + if (!update) { if (!(geom_flags & XValue)) @@ -301,11 +327,10 @@ geom_flags |= WidthValue|HeightValue|XValue|YValue; } - if (check_set_scale_value (geom_flags, WidthValue, h_scale, w) - || check_set_scale_value (geom_flags, HeightValue, v_scale, h) - || check_set_align_value (geom_flags, XValue, h_align, x) - || check_set_align_value (geom_flags, YValue, v_align, y)) - changed = true; + if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true; + if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true; + if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true; + if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true; if (new_flags != bg_flags) { @@ -325,7 +350,7 @@ w = h_scale * target_width / 100; h = v_scale * target_height / 100; - if (bg_flags & BG_PROP_SCALE) + if (bg_flags & BG_KEEP_ASPECT) { float scale = (float)w / image_width; min_it (scale, (float)h / image_height); @@ -801,27 +826,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); @@ -943,7 +963,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; @@ -954,7 +974,7 @@ void rxvt_term::set_tint_shade_flags () { - rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); + rgba c; bool has_shade = shade != 100; bg_flags &= ~BG_TINT_FLAGS; @@ -990,7 +1010,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) @@ -1030,10 +1050,13 @@ #endif bool -rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) +rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height, int depth) { bool ret = false; #if XRENDER + if (!(bg_flags & BG_HAS_RENDER_CONV)) + return false; + int size = max (h_blurRadius, v_blurRadius) * 2 + 1; double *kernel = (double *)malloc (size * sizeof (double)); XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); @@ -1041,45 +1064,44 @@ XRenderPictureAttributes pa; XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); - Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); - Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); + pa.repeat = RepeatPad; + Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); + Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth); + Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa); + XFreePixmap (dpy, tmp); if (kernel && params) { - if (h_blurRadius) - { - 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); - } + size = h_blurRadius * 2 + 1; + get_gaussian_kernel (h_blurRadius, size, kernel, params); - 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); + + ::swap (src, dst); + + 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; } @@ -1116,9 +1138,9 @@ XFreeGC (dpy, gc); } } - else - { # if XRENDER + else if (bg_flags & BG_HAS_RENDER) + { rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); if (bg_flags & BG_TINT_SET) @@ -1137,22 +1159,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; @@ -1167,12 +1180,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); @@ -1183,8 +1199,8 @@ XRenderFreePicture (dpy, mask_pic); XRenderFreePicture (dpy, overlay_pic); XRenderFreePicture (dpy, back_pic); -# endif } +# endif return ret; } @@ -1245,13 +1261,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); @@ -1278,8 +1292,8 @@ } /* straightforward pixmap copy */ - while (sx < 0) sx += root_width; - while (sy < 0) sy += root_height; + while (sx < 0) sx += root_pmap_width; + while (sy < 0) sy += root_pmap_height; gcv.tile = recoded_root_pmap; gcv.fill_style = FillTiled; @@ -1291,23 +1305,36 @@ { 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)) { - if ((bg_flags & BG_NEEDS_BLUR) - && (bg_flags & BG_HAS_RENDER_CONV)) + if (bg_flags & BG_NEEDS_BLUR) { - if (blur_pixmap (bg_pixmap, visual, window_width, window_height)) + if (blur_pixmap (bg_pixmap, visual, window_width, window_height, depth)) result &= ~BG_NEEDS_BLUR; } - if ((bg_flags & BG_NEEDS_TINT) - && (bg_flags & (BG_TINT_BITAND | BG_HAS_RENDER))) + if (bg_flags & BG_NEEDS_TINT) { 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) @@ -1327,10 +1354,6 @@ } # endif /* ENABLE_TRANSPARENCY */ -#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) -static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c); -# endif - bool rxvt_term::bg_render () { @@ -1357,39 +1380,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) - { - rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); - if (bg_flags & BG_TINT_SET) - tint.get (c); - shade_ximage (DefaultVisual (dpy, display->screen), result, shade, c); - } - - 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) @@ -1436,15 +1426,25 @@ #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) /* based on code from aterm-0.4.2 */ -static void -shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c) +static inline void +fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high) +{ + for (int i = 0; i <= mask >> sh; i++) + { + uint32_t tmp; + tmp = i * high; + tmp += (mask >> sh) * low; + lookup[i] = (tmp / 0xffff) << sh; + } +} + +void +rxvt_term::tint_ximage (Visual *visual, XImage *ximage) { int sh_r, sh_g, sh_b; uint32_t mask_r, mask_g, mask_b; uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; - rgba low; - rgba high; - int i; + unsigned short low; int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; @@ -1513,50 +1513,33 @@ return; /* we do not support this color depth */ } + rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); + + if (bg_flags & BG_TINT_SET) + tint.get (c); + /* prepare limits for color transformation (each channel is handled separately) */ if (shade > 100) { - shade = 200 - shade; + c.r = c.r * (200 - shade) / 100; + c.g = c.g * (200 - shade) / 100; + c.b = c.b * (200 - shade) / 100; - high.r = c.r * shade / 100; - high.g = c.g * shade / 100; - high.b = c.b * shade / 100; - - low.r = 65535 * (100 - shade) / 100; - low.g = 65535 * (100 - shade) / 100; - low.b = 65535 * (100 - shade) / 100; + low = 0xffff * (shade - 100) / 100; } else { - high.r = c.r * shade / 100; - high.g = c.g * shade / 100; - high.b = c.b * shade / 100; + c.r = c.r * shade / 100; + c.g = c.g * shade / 100; + c.b = c.b * shade / 100; - low.r = low.g = low.b = 0; + low = 0; } /* fill our lookup tables */ - for (i = 0; i <= mask_r>>sh_r; i++) - { - uint32_t tmp; - tmp = i * high.r; - tmp += (mask_r>>sh_r) * low.r; - lookup_r[i] = (tmp/65535)<>sh_g; i++) - { - uint32_t tmp; - tmp = i * high.g; - tmp += (mask_g>>sh_g) * low.g; - lookup_g[i] = (tmp/65535)<>sh_b; i++) - { - uint32_t tmp; - tmp = i * high.b; - tmp += (mask_b>>sh_b) * low.b; - lookup_b[i] = (tmp/65535)<bits_per_pixel == 32