--- rxvt-unicode/src/background.C 2009/04/26 01:59:53 1.34 +++ rxvt-unicode/src/background.C 2010/09/01 11:59:44 1.52 @@ -29,17 +29,21 @@ #if DO_TIMING_TEST # include #define TIMING_TEST_START(id) \ - struct timeval timing_test_##id##_stv;\ + struct timeval timing_test_##id##_stv; \ gettimeofday (&timing_test_##id##_stv, NULL); #define TIMING_TEST_PRINT_RESULT(id) \ - do{ struct timeval tv;gettimeofday (&tv, NULL); tv.tv_sec -= (timing_test_##id##_stv).tv_sec;\ - fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__,\ - tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec);}while (0) + do { \ + struct timeval tv; \ + gettimeofday (&tv, NULL); \ + tv.tv_sec -= (timing_test_##id##_stv).tv_sec; \ + fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__, \ + tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec); \ + } while (0) #else -#define TIMING_TEST_START(id) do{}while (0) -#define TIMING_TEST_PRINT_RESULT(id) do{}while (0) +#define TIMING_TEST_START(id) do {} while (0) +#define TIMING_TEST_PRINT_RESULT(id) do {} while (0) #endif /* @@ -48,7 +52,7 @@ * adjustment and may optionally be followed by a colon and one or more * colon-delimited pixmap operations. * The following table shows the valid geometry strings and their - * affects on the background image : + * effects on the background image : * * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. * W and H are percentages of the terminal window size. @@ -95,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 @@ -125,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) @@ -138,8 +141,8 @@ return false; } -bool -bgPixmap_t::window_position_sensitive () +bool +bgPixmap_t::window_position_sensitive () { # ifdef ENABLE_TRANSPARENCY if (flags & isTransparent) @@ -147,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; @@ -439,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; @@ -471,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; } @@ -497,7 +533,7 @@ if (background_tint != TINT_LEAVE_SAME) { - ASImage* tmp = tile_asimage (target->asv, background, 0, 0, + ASImage *tmp = tile_asimage (target->asv, background, 0, 0, target_width, target_height, background_tint, ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); if (tmp) @@ -535,7 +571,7 @@ ASImage *tmp = tile_asimage (target->asv, result, (h_scale > 0) ? 0 : (int)result->width - x, (v_scale > 0) ? 0 : (int)result->height - y, - new_pmap_width, + new_pmap_width, new_pmap_height, TINT_LEAVE_SAME, ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); @@ -552,7 +588,6 @@ { /* if blending background and image - pixmap has to be sized same as target window */ ASImageLayer *layers = create_image_layers (2); - ASImage *merged_im = NULL; layers[0].im = background; layers[0].clip_width = target_width; @@ -609,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) { @@ -634,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); @@ -660,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 */ @@ -673,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 } @@ -719,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) @@ -741,7 +781,7 @@ else flags |= blurNeeded; - return (changed>0); + return (changed > 0); } static inline unsigned long @@ -768,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) @@ -809,8 +849,8 @@ if (new_flags != (flags & tintFlags)) { - flags = (flags&~tintFlags)|new_flags; - return true; + flags = (flags & ~tintFlags) | new_flags; + return true; } return false; @@ -850,7 +890,7 @@ if (target == NULL) return 0; - /* root dimentions may change from call to call - but Display structure should + /* root dimensions may change from call to call - but Display structure should * be always up-to-date, so let's use it : */ Window root = target->display->root; @@ -905,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); @@ -939,17 +979,17 @@ //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 { - /* strightforward pixmap copy */ + /* straightforward pixmap copy */ gcv.tile = root_pixmap; gcv.fill_style = FillTiled; @@ -1072,7 +1112,7 @@ # endif # endif } - } + } } /* server side rendering completed */ if (pixmap) @@ -1110,7 +1150,7 @@ # endif /* ENABLE_TRANSPARENCY */ # ifndef HAVE_AFTERIMAGE -static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm); +static void ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm); # endif bool @@ -1132,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 neccessary 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); @@ -1202,8 +1203,8 @@ tint.get (c); ShadeXImage (target, result, shade, c.r, c.g, c.b); } +# endif } -# endif /* HAVE_AFTERIMAGE */ if (result) { @@ -1245,7 +1246,7 @@ flags = flags & ~isInvalid; } - XDestroyImage (result); + XDestroyImage (result); } if (flags & isInvalid) @@ -1329,7 +1330,7 @@ scr_touch or we get a great deal of flicker otherwise: */ XClearWindow (target->dpy, target->parent[0]); - if (target->scrollBar.win) + if (target->scrollBar.state && target->scrollBar.win) { target->scrollBar.state = STATE_IDLE; target->scrollBar.show (0); @@ -1348,7 +1349,7 @@ typedef uint32_t RUINT32T; static void -ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm) +ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm) { int sh_r, sh_g, sh_b; RUINT32T mask_r, mask_g, mask_b;