--- rxvt-unicode/src/background.C 2011/12/30 11:22:48 1.191 +++ rxvt-unicode/src/background.C 2012/01/17 19:51:30 1.199 @@ -34,6 +34,10 @@ #define FilterConvolution "convolution" #endif +#ifndef RepeatPad +#define RepeatPad True +#endif + #ifdef HAVE_BG_PIXMAP # if XRENDER static Picture @@ -127,40 +131,6 @@ } # ifdef BG_IMAGE_FROM_FILE -static inline bool -check_set_scale_value (int geom_flags, int flag, unsigned int &scale, unsigned int new_value) -{ - if (geom_flags & flag) - { - if (new_value > 1000) - new_value = 1000; - if (new_value != scale) - { - scale = new_value; - return true; - } - } - return false; -} - -static inline bool -check_set_align_value (int geom_flags, int flag, int &align, int new_value) -{ - if (geom_flags & flag) - { - if (new_value < -100) - new_value = -100; - else if (new_value > 200) - new_value = 200; - if (new_value != align) - { - align = new_value; - return true; - } - } - return false; -} - static inline int make_align_position (int align, int window_size, int image_size) { @@ -189,8 +159,7 @@ dst_size += pos; } - if (dst_pos + dst_size > target_size) - dst_size = target_size - dst_pos; + min_it (dst_size, target_size - dst_pos); return src_pos; } @@ -199,8 +168,10 @@ { bool changed = false; int geom_flags = 0; - int x = 0, y = 0; - unsigned int w = 0, h = 0; + int x = h_align; + int y = v_align; + unsigned int w = h_scale; + unsigned int h = v_scale; unsigned long new_flags = 0; if (geom == NULL) @@ -319,18 +290,24 @@ h = w; else if (!(geom_flags & WidthValue)) w = h; - - geom_flags |= WidthValue|HeightValue|XValue|YValue; } - 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) + min_it (w, 1000); + min_it (h, 1000); + clamp_it (x, -100, 200); + clamp_it (y, -100, 200); + + if (bg_flags != new_flags + || h_scale != w + || v_scale != h + || h_align != x + || v_align != y) { bg_flags = new_flags; + h_scale = w; + v_scale = h; + h_align = x; + v_align = y; changed = true; } @@ -394,8 +371,9 @@ ShadingInfo as_shade; as_shade.shading = shade; - rgba c; - tint.get (c); + rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); + if (bg_flags & BG_TINT_SET) + tint.get (c); as_shade.tintColor.red = c.r; as_shade.tintColor.green = c.g; as_shade.tintColor.blue = c.b; @@ -832,10 +810,11 @@ 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); @@ -957,7 +936,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; @@ -973,27 +952,27 @@ bg_flags &= ~BG_TINT_FLAGS; - tint.get (c); + 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; + } - 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) + if (has_shade || (bg_flags & BG_TINT_SET)) bg_flags |= BG_NEEDS_TINT; } bool rxvt_term::bg_set_tint (rxvt_color &new_tint) { - if (tint != new_tint) + if (!(bg_flags & BG_TINT_SET) || tint != new_tint) { tint = new_tint; + bg_flags |= BG_TINT_SET; set_tint_shade_flags (); return true; } @@ -1044,7 +1023,7 @@ #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 @@ -1055,47 +1034,47 @@ 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, 0); - Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, 0); + 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); + 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); + + ::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; } @@ -1135,9 +1114,10 @@ # if XRENDER else if (bg_flags & BG_HAS_RENDER) { - rgba c; + rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); - tint.get (c); + if (bg_flags & BG_TINT_SET) + tint.get (c); if (shade <= 100) { @@ -1173,12 +1153,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); @@ -1300,7 +1283,7 @@ { 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) @@ -1355,9 +1338,8 @@ { /* we need to re-generate transparency pixmap in that case ! */ tr_flags = make_transparency_pixmap (); - if (tr_flags == 0) - return false; - bg_flags |= BG_IS_VALID; + if (tr_flags) + bg_flags |= BG_IS_VALID; } # endif @@ -1391,8 +1373,6 @@ 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 @@ -1505,9 +1485,10 @@ return; /* we do not support this color depth */ } - rgba c; + rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); - tint.get (c); + if (bg_flags & BG_TINT_SET) + tint.get (c); /* prepare limits for color transformation (each channel is handled separately) */ if (shade > 100)