--- rxvt-unicode/src/background.C 2010/08/29 13:24:30 1.42 +++ rxvt-unicode/src/background.C 2010/09/01 11:59:44 1.52 @@ -99,6 +99,7 @@ original_asim = NULL; #endif #ifdef BG_IMAGE_FROM_FILE + have_image = false; h_scale = v_scale = 0; h_align = v_align = 0; #endif @@ -129,9 +130,7 @@ # endif # ifdef BG_IMAGE_FROM_FILE -# ifdef HAVE_AFTERIMAGE - if (original_asim) -# endif + if (have_image) { if (h_scale != 0 || v_scale != 0 || h_align != 0 || v_align != 0) @@ -151,9 +150,7 @@ # endif # ifdef BG_IMAGE_FROM_FILE -# ifdef HAVE_AFTERIMAGE - if (original_asim) -# endif + if (have_image) { if (h_align == rootAlign || v_align == rootAlign) return true; @@ -443,20 +440,55 @@ changed++; } -//fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", -// flags, h_scale, v_scale, h_align, v_align); + //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", + // flags, h_scale, v_scale, h_align, v_align); return (changed > 0); } # ifdef HAVE_AFTERIMAGE bool -bgPixmap_t::render_asim (ASImage *background, ARGB32 background_tint) +bgPixmap_t::render_image (unsigned long background_flags) { if (target == NULL) return false; target->init_asv (); + ASImage *background = NULL; + ARGB32 background_tint = TINT_LEAVE_SAME; + +# ifdef ENABLE_TRANSPARENCY + if (background_flags) + background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100); + + if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) + { + ShadingInfo as_shade; + as_shade.shading = (shade == 0) ? 100 : shade; + + rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); + if (flags & tintSet) + tint.get (c); + as_shade.tintColor.red = c.r; + as_shade.tintColor.green = c.g; + as_shade.tintColor.blue = c.b; + + background_tint = shading2tint32 (&as_shade); + } + + if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL) + { + ASImage *tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, + (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage, + 100, ASIMAGE_QUALITY_DEFAULT); + if (tmp) + { + destroy_asimage (&background); + background = tmp; + } + } +# endif + ASImage *result = 0; int target_width = target->szHint.width; @@ -475,7 +507,7 @@ { if (h_align == rootAlign || v_align == rootAlign) { - target->get_window_origin(x, y); + target->get_window_origin (x, y); x = -x; y = -y; } @@ -612,23 +644,24 @@ } TIMING_TEST_PRINT_RESULT (asim); - if (pixmap) - { - if (result == NULL - || pmap_width != new_pmap_width - || pmap_height != new_pmap_height - || pmap_depth != target->depth) - { - XFreePixmap (target->dpy, pixmap); - pixmap = None; - } - } + bool ret = false; if (result) { XGCValues gcv; GC gc; + if (pixmap) + { + if (pmap_width != new_pmap_width + || pmap_height != new_pmap_height + || pmap_depth != target->depth) + { + XFreePixmap (target->dpy, pixmap); + pixmap = None; + } + } + /* create Pixmap */ if (pixmap == None) { @@ -637,7 +670,7 @@ pmap_height = new_pmap_height; pmap_depth = target->depth; } - /* fill with background color ( if result's not completely overlapping it)*/ + /* fill with background color (if result's not completely overlapping it) */ gcv.foreground = target->pix_colors[Color_bg]; gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); @@ -663,9 +696,14 @@ XFreeGC (target->dpy, gc); TIMING_TEST_PRINT_RESULT (asim); + + ret = true; } - return true; + if (background) + destroy_asimage (&background); + + return ret; } # endif /* HAVE_AFTERIMAGE */ @@ -676,23 +714,22 @@ if (*file) { -# ifdef HAVE_AFTERIMAGE - if (!target->asimman) - target->asimman = create_generic_imageman (target->rs[Rs_path]); - if (const char *p = strchr (file, ';')) { size_t len = p - file; - char *f = (char *)malloc (len + 1); + char *f = rxvt_temp_buf (len + 1); memcpy (f, file, len); f[len] = '\0'; - original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100); - free (f); + file = f; } - else - original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); - return original_asim; +# ifdef HAVE_AFTERIMAGE + if (!target->asimman) + target->asimman = create_generic_imageman (target->rs[Rs_path]); + original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); + if (original_asim) + have_image = true; + return have_image; # endif } @@ -722,9 +759,9 @@ int junk; int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); - if (!(geom_flags&WidthValue)) + if (!(geom_flags & WidthValue)) hr = 1; - if (!(geom_flags&HeightValue)) + if (!(geom_flags & HeightValue)) vr = hr; if (h_blurRadius != hr) @@ -744,7 +781,7 @@ else flags |= blurNeeded; - return (changed>0); + return (changed > 0); } static inline unsigned long @@ -771,9 +808,9 @@ { if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) - { - flags |= bgPixmap_t::tintNeeded; - } + { + flags |= bgPixmap_t::tintNeeded; + } } if (flags & bgPixmap_t::tintNeeded) @@ -812,8 +849,8 @@ if (new_flags != (flags & tintFlags)) { - flags = (flags&~tintFlags)|new_flags; - return true; + flags = (flags & ~tintFlags) | new_flags; + return true; } return false; @@ -908,7 +945,7 @@ attr.backing_store = Always; attr.event_mask = ExposureMask; attr.override_redirect = True; - src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0, + src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0, CopyFromParent, CopyFromParent, CopyFromParent, CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask, &attr); @@ -942,13 +979,13 @@ //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); } - if (!success) - { - XFreePixmap (dpy, tiled_root_pmap); - tiled_root_pmap = None; - } - else - result |= transpPmapTiled; + if (!success) + { + XFreePixmap (dpy, tiled_root_pmap); + tiled_root_pmap = None; + } + else + result |= transpPmapTiled; } else { @@ -1075,7 +1112,7 @@ # endif # endif } - } + } } /* server side rendering completed */ if (pixmap) @@ -1135,69 +1172,30 @@ if (background_flags == 0) return false; else if ((background_flags & transpTransformations) == (flags & transpTransformations) - && pmap_depth == target->depth) + && pmap_depth == target->depth) flags = flags & ~isInvalid; } # endif - XImage *result = NULL; -# ifdef HAVE_AFTERIMAGE - if (original_asim +# ifdef BG_IMAGE_FROM_FILE + if (have_image || (background_flags & transpTransformations) != (flags & transpTransformations)) { - target->init_asv (); - - ASImage *background = NULL; - ARGB32 as_tint = TINT_LEAVE_SAME; - if (background_flags) - background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100); - -# ifdef ENABLE_TRANSPARENCY - if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) - { - ShadingInfo as_shade; - as_shade.shading = (shade == 0) ? 100 : shade; - - rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); - if (flags & tintSet) - tint.get (c); - as_shade.tintColor.red = c.r; - as_shade.tintColor.green = c.g; - as_shade.tintColor.blue = c.b; - - as_tint = shading2tint32 (&as_shade); - } - - if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL) - { - ASImage *tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, - (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage, - 100, ASIMAGE_QUALITY_DEFAULT); - if (tmp) - { - destroy_asimage (&background); - background = tmp; - } - } -# endif - - if (render_asim (background, as_tint)) + if (render_image (background_flags)) flags = flags & ~isInvalid; - if (background) - destroy_asimage (&background); } - else if (background_flags && pmap_depth != target->depth) - result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); - -# elif !XFT /* our own client-side tinting */ +# endif - /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side. - This may need to be changed in need_client_side_rendering() logic is altered !!! */ + XImage *result = NULL; if (background_flags && (flags & isInvalid)) { result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); +# if !defined(HAVE_AFTERIMAGE) && !XFT + /* our own client-side tinting */ + /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side. + This may need to be changed in need_client_side_rendering() logic is altered !!! */ if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded)) { rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); @@ -1205,8 +1203,8 @@ tint.get (c); ShadeXImage (target, result, shade, c.r, c.g, c.b); } +# endif } -# endif /* HAVE_AFTERIMAGE */ if (result) { @@ -1248,7 +1246,7 @@ flags = flags & ~isInvalid; } - XDestroyImage (result); + XDestroyImage (result); } if (flags & isInvalid)