--- rxvt-unicode/src/background.C 2008/02/19 10:47:03 1.30 +++ rxvt-unicode/src/background.C 2010/08/31 15:12:49 1.49 @@ -3,7 +3,7 @@ *----------------------------------------------------------------------* * * All portions of code are copyright by their respective author/s. - * Copyright (c) 2005-2006 Marc Lehmann + * Copyright (c) 2005-2008 Marc Lehmann * Copyright (c) 2007 Sasha Vasko * * This program is free software; you can redistribute it and/or modify @@ -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; @@ -261,7 +262,7 @@ unsigned int w = 0, h = 0; unsigned int n; unsigned long new_flags = (flags & (~geometryFlags)); - char *p; + const char *p; # define MAXLEN_GEOM 256 /* could be longer than regular geometry string */ if (geom == NULL) @@ -439,22 +440,61 @@ 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_asim (unsigned long background_flags) { if (target == NULL) return false; - int target_width = (int)target->szHint.width; - int target_height = (int)target->szHint.height; - int new_pmap_width = target_width, new_pmap_height = target_height; - ASImage *result = NULL; + 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; + int target_height = target->szHint.height; + int new_pmap_width = target_width; + int new_pmap_height = target_height; int x = 0; int y = 0; @@ -467,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; } @@ -493,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) @@ -531,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); @@ -548,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; @@ -630,7 +669,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); @@ -658,6 +697,9 @@ TIMING_TEST_PRINT_RESULT (asim); } + if (background) + destroy_asimage (&background); + return true; } # endif /* HAVE_AFTERIMAGE */ @@ -665,29 +707,26 @@ bool bgPixmap_t::set_file (const char *file) { - char *f; - assert (file); if (*file) { -# ifdef HAVE_AFTERIMAGE - if (target->asimman == NULL) - target->asimman = create_generic_imageman (target->rs[Rs_path]); - - if ((f = strchr (file, ';')) == NULL) - original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); - else + if (const char *p = strchr (file, ';')) { - size_t len = f - file; - f = (char *)malloc (len + 1); + size_t len = p - file; + 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; } - 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 } @@ -766,9 +805,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) @@ -807,8 +846,8 @@ if (new_flags != (flags & tintFlags)) { - flags = (flags&~tintFlags)|new_flags; - return true; + flags = (flags&~tintFlags)|new_flags; + return true; } return false; @@ -848,7 +887,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; @@ -903,7 +942,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); @@ -937,17 +976,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; @@ -1070,7 +1109,7 @@ # endif # endif } - } + } } /* server side rendering completed */ if (pixmap) @@ -1108,7 +1147,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 @@ -1121,7 +1160,7 @@ TIMING_TEST_START (tp); - invalidate(); + invalidate (); # ifdef ENABLE_TRANSPARENCY if (flags & isTransparent) { @@ -1130,67 +1169,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 || (background_flags & transpTransformations) != (flags & transpTransformations)) { - 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_asim (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); @@ -1198,8 +1200,8 @@ tint.get (c); ShadeXImage (target, result, shade, c.r, c.g, c.b); } +# endif } -# endif /* HAVE_AFTERIMAGE */ if (result) { @@ -1241,7 +1243,7 @@ flags = flags & ~isInvalid; } - XDestroyImage (result); + XDestroyImage (result); } if (flags & isInvalid) @@ -1275,6 +1277,7 @@ # endif return true; } + return false; } @@ -1324,7 +1327,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); @@ -1343,7 +1346,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;