--- rxvt-unicode/src/background.C 2011/01/28 00:08:57 1.143 +++ rxvt-unicode/src/background.C 2011/05/08 21:03:03 1.152 @@ -3,7 +3,7 @@ *----------------------------------------------------------------------* * * All portions of code are copyright by their respective author/s. - * Copyright (c) 2005-2008 Marc Lehmann + * Copyright (c) 2005-2008 Marc Lehmann * Copyright (c) 2007 Sasha Vasko * Copyright (c) 2010 Emanuele Giaquinta * @@ -67,6 +67,10 @@ #ifdef HAVE_AFTERIMAGE if (original_asim) safe_asimage_destroy (original_asim); + if (asv) + destroy_asvisual (asv, 0); + if (asimman) + destroy_image_manager (asimman, 0); #endif #ifdef HAVE_PIXBUF @@ -101,7 +105,7 @@ # endif # ifdef BG_IMAGE_FROM_FILE - if (have_image) + if (bg_flags & BG_IS_FROM_FILE) { if (bg_flags & BG_IS_SIZE_SENSITIVE) return true; @@ -120,7 +124,7 @@ # endif # ifdef BG_IMAGE_FROM_FILE - if (have_image) + if (bg_flags & BG_IS_FROM_FILE) { if (bg_flags & BG_ROOT_ALIGN) return true; @@ -721,126 +725,137 @@ GDK_INTERP_BILINEAR); } + if (!result) + return false; + bool ret = false; - if (result) - { - XGCValues gcv; - GC gc; - Pixmap root_pmap; + XGCValues gcv; + GC gc; + Pixmap root_pmap; - image_width = gdk_pixbuf_get_width (result); - image_height = gdk_pixbuf_get_height (result); + image_width = gdk_pixbuf_get_width (result); + image_height = gdk_pixbuf_get_height (result); - if (tr_flags) - { - root_pmap = bg_pixmap; - bg_pixmap = None; - } - else + if (tr_flags) + { + root_pmap = bg_pixmap; + bg_pixmap = None; + } + else + { + if (h_scale == 0 || v_scale == 0) { - if (h_scale == 0 || v_scale == 0) - { - new_pmap_width = min (image_width, target_width); - new_pmap_height = min (image_height, target_height); - } + new_pmap_width = min (image_width, target_width); + new_pmap_height = min (image_height, target_height); } + } - if (bg_pixmap == None - || bg_pmap_width != new_pmap_width - || bg_pmap_height != new_pmap_height) - { - if (bg_pixmap) - XFreePixmap (dpy, bg_pixmap); - bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); - bg_pmap_width = new_pmap_width; - bg_pmap_height = new_pmap_height; - } + if (bg_pixmap == None + || bg_pmap_width != new_pmap_width + || bg_pmap_height != new_pmap_height) + { + if (bg_pixmap) + XFreePixmap (dpy, bg_pixmap); + bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); + bg_pmap_width = new_pmap_width; + bg_pmap_height = new_pmap_height; + } + if (bg_pixmap != None) + { gcv.foreground = pix_colors[Color_bg]; gc = XCreateGC (dpy, vt, GCForeground, &gcv); - if (h_scale == 0 || v_scale == 0) + if (gc) { - Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); - pixbuf_to_pixmap (result, tile, gc, - 0, 0, - 0, 0, - image_width, image_height); - - gcv.tile = tile; - gcv.fill_style = FillTiled; - gcv.ts_x_origin = x; - gcv.ts_y_origin = y; - XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); + if (h_scale == 0 || v_scale == 0) + { + Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); - XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); - XFreePixmap (dpy, tile); - } - else - { - int src_x, src_y, dst_x, dst_y; - int dst_width, dst_height; + if (tile != None) + { + pixbuf_to_pixmap (result, tile, gc, + 0, 0, + 0, 0, + image_width, image_height); + + gcv.tile = tile; + gcv.fill_style = FillTiled; + gcv.ts_x_origin = x; + gcv.ts_y_origin = y; + XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); - src_x = make_clip_rectangle (x, image_width , new_pmap_width , dst_x, dst_width ); - src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); + XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); + XFreePixmap (dpy, tile); + } + } + else + { + int src_x, src_y, dst_x, dst_y; + int dst_width, dst_height; - if (dst_x > 0 || dst_y > 0 - || dst_x + dst_width < new_pmap_width - || dst_y + dst_height < new_pmap_height) - XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); + src_x = make_clip_rectangle (x, image_width , new_pmap_width , dst_x, dst_width ); + src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); - if (dst_x < new_pmap_width && dst_y < new_pmap_height) - pixbuf_to_pixmap (result, bg_pixmap, gc, - src_x, src_y, - dst_x, dst_y, - dst_width, dst_height); - } + if (dst_x > 0 || dst_y > 0 + || dst_x + dst_width < new_pmap_width + || dst_y + dst_height < new_pmap_height) + XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); + + if (dst_x < new_pmap_width && dst_y < new_pmap_height) + pixbuf_to_pixmap (result, bg_pixmap, gc, + src_x, src_y, + dst_x, dst_y, + dst_width, dst_height); + } #if XRENDER - if (tr_flags) - { - XRenderPictureAttributes pa; + if (tr_flags) + { + XRenderPictureAttributes pa; - XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, visual); - Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); + XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, visual); + Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); - XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); - Picture dst = XRenderCreatePicture (dpy, bg_pixmap, dst_format, 0, &pa); + XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); + Picture dst = XRenderCreatePicture (dpy, bg_pixmap, dst_format, 0, &pa); - 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); + 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); - if (src && dst && mask) - { - XRenderColor mask_c; + if (src && dst && mask) + { + XRenderColor mask_c; - mask_c.alpha = 0x8000; - mask_c.red = 0; - mask_c.green = 0; - 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); + mask_c.alpha = 0x8000; + mask_c.red = 0; + mask_c.green = 0; + 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); + XRenderFreePicture (dpy, dst); + XRenderFreePicture (dpy, mask); } +#endif - XRenderFreePicture (dpy, src); - XRenderFreePicture (dpy, dst); - XRenderFreePicture (dpy, mask); + XFreeGC (dpy, gc); - XFreePixmap (dpy, root_pmap); + ret = true; } -#endif - - if (result != pixbuf) - g_object_unref (result); + } - XFreeGC (dpy, gc); + if (result != pixbuf) + g_object_unref (result); - ret = true; - } + if (tr_flags) + XFreePixmap (dpy, root_pmap); return ret; } @@ -870,8 +885,7 @@ if (original_asim) safe_asimage_destroy (original_asim); original_asim = image; - bg_flags |= BG_CLIENT_RENDER; - have_image = true; + bg_flags |= BG_IS_FROM_FILE | BG_CLIENT_RENDER; return true; } # endif @@ -883,7 +897,7 @@ if (pixbuf) g_object_unref (pixbuf); pixbuf = image; - have_image = true; + bg_flags |= BG_IS_FROM_FILE; return true; } # endif @@ -942,27 +956,26 @@ return changed; } -static inline unsigned long -compute_tint_shade_flags (rxvt_color *tint, int shade) +void +rxvt_term::set_tint_shade_flags () { - unsigned long flags = 0; rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); bool has_shade = shade != 100; - if (tint) + bg_flags &= ~BG_TINT_FLAGS; + + if (bg_flags & BG_TINT_SET) { - tint->get (c); + tint.get (c); if (!has_shade && (c.r <= 0x00ff || c.r >= 0xff00) && (c.g <= 0x00ff || c.g >= 0xff00) && (c.b <= 0x00ff || c.b >= 0xff00)) - flags |= rxvt_term::BG_TINT_BITAND; + bg_flags |= BG_TINT_BITAND; } - if (has_shade || tint) - flags |= rxvt_term::BG_NEEDS_TINT; - - return flags; + if (has_shade || (bg_flags & BG_TINT_SET)) + bg_flags |= BG_NEEDS_TINT; } bool @@ -970,9 +983,9 @@ { if (!(bg_flags & BG_TINT_SET) || tint != new_tint) { - unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); tint = new_tint; - bg_flags = (bg_flags & ~BG_TINT_FLAGS) | new_flags | BG_TINT_SET; + bg_flags |= BG_TINT_SET; + set_tint_shade_flags (); return true; } @@ -990,9 +1003,8 @@ if (new_shade != shade) { - unsigned long new_flags = compute_tint_shade_flags ((bg_flags & BG_TINT_SET) ? &tint : NULL, new_shade); shade = new_shade; - bg_flags = (bg_flags & ~BG_TINT_FLAGS) | new_flags; + set_tint_shade_flags (); return true; } @@ -1112,22 +1124,22 @@ else { # if XRENDER - rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); + rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); if (bg_flags & BG_TINT_SET) tint.get (c); if (shade <= 100) { - c.r = (c.r * shade) / 100; - c.g = (c.g * shade) / 100; - c.b = (c.b * shade) / 100; + c.r = c.r * shade / 100; + c.g = c.g * shade / 100; + c.b = c.b * shade / 100; } else { - c.r = (c.r * (200 - shade)) / 100; - c.g = (c.g * (200 - shade)) / 100; - c.b = (c.b * (200 - shade)) / 100; + c.r = c.r * (200 - shade) / 100; + c.g = c.g * (200 - shade) / 100; + c.b = c.b * (200 - shade) / 100; } XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); @@ -1144,21 +1156,23 @@ 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); + Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat | CPComponentAlpha, &pa); XFreePixmap (dpy, mask_pmap); if (mask_pic && overlay_pic && back_pic) { XRenderColor mask_c; - mask_c.red = mask_c.green = mask_c.blue = 0; mask_c.alpha = 0xffff; + mask_c.red = + mask_c.green = + mask_c.blue = 0; XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); mask_c.alpha = 0; - mask_c.red = 0xffff - c.r; + mask_c.red = 0xffff - c.r; mask_c.green = 0xffff - c.g; - mask_c.blue = 0xffff - c.b; + 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); @@ -1183,7 +1197,7 @@ return ret; } -/* make_transparency_pixmap() +/* * Builds a pixmap of the same size as the terminal window that contains * the tiled portion of the root pixmap that is supposed to be covered by * our window. @@ -1237,32 +1251,36 @@ #if XRENDER if (bg_flags & BG_HAS_RENDER) { - XRenderPictureAttributes pa; - - XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); - Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); - recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); - XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); - Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); - if (src && dst) - XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); - else + if (recoded_root_pmap != None) { - XFreePixmap (dpy, recoded_root_pmap); - root_pixmap = None; - } + XRenderPictureAttributes pa; + + XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); + Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); + + XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); + Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); - XRenderFreePicture (dpy, src); - XRenderFreePicture (dpy, dst); + if (src && dst) + XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); + else + { + XFreePixmap (dpy, recoded_root_pmap); + recoded_root_pmap = None; + } + + XRenderFreePicture (dpy, src); + XRenderFreePicture (dpy, dst); + } } else #endif - root_pixmap = None; + recoded_root_pmap = None; } - if (root_pixmap == None) + if (recoded_root_pmap == None) return 0; if (bg_pixmap == None @@ -1276,40 +1294,40 @@ bg_pmap_height = window_height; } - if (bg_pixmap == None) - return 0; - - /* straightforward pixmap copy */ - while (sx < 0) sx += (int)root_width; - while (sy < 0) sy += (int)root_height; - - gcv.tile = recoded_root_pmap; - gcv.fill_style = FillTiled; - gcv.ts_x_origin = -sx; - gcv.ts_y_origin = -sy; - gc = XCreateGC (dpy, vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); - - if (gc) + if (bg_pixmap != None) { - XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); - result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS); - XFreeGC (dpy, gc); + /* straightforward pixmap copy */ + while (sx < 0) sx += (int)root_width; + while (sy < 0) sy += (int)root_height; + + gcv.tile = recoded_root_pmap; + gcv.fill_style = FillTiled; + gcv.ts_x_origin = -sx; + gcv.ts_y_origin = -sy; + gc = XCreateGC (dpy, vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); - if (!(bg_flags & BG_CLIENT_RENDER)) + if (gc) { - if ((bg_flags & BG_NEEDS_BLUR) - && (bg_flags & BG_HAS_RENDER_CONV)) - { - if (blur_pixmap (bg_pixmap, visual, window_width, window_height)) - result &= ~BG_NEEDS_BLUR; - } - if ((bg_flags & BG_NEEDS_TINT) - && (bg_flags & (BG_TINT_BITAND | BG_HAS_RENDER))) + 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 (tint_pixmap (bg_pixmap, visual, window_width, window_height)) - result &= ~BG_NEEDS_TINT; - } - } /* server side rendering completed */ + if ((bg_flags & BG_NEEDS_BLUR) + && (bg_flags & BG_HAS_RENDER_CONV)) + { + if (blur_pixmap (bg_pixmap, visual, window_width, window_height)) + result &= ~BG_NEEDS_BLUR; + } + if ((bg_flags & BG_NEEDS_TINT) + && (bg_flags & (BG_TINT_BITAND | BG_HAS_RENDER))) + { + if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) + result &= ~BG_NEEDS_TINT; + } + } /* server side rendering completed */ + } } if (recoded_root_pmap != root_pixmap) @@ -1352,7 +1370,7 @@ # endif # ifdef BG_IMAGE_FROM_FILE - if (have_image + if ((bg_flags & BG_IS_FROM_FILE) || (tr_flags & BG_EFFECTS_FLAGS)) { if (render_image (tr_flags))