--- rxvt-unicode/src/background.C 2007/12/05 08:46:27 1.17 +++ rxvt-unicode/src/background.C 2008/01/19 00:21:59 1.25 @@ -27,6 +27,7 @@ #define DO_TIMING_TEST 0 #if DO_TIMING_TEST +# include #define TIMING_TEST_START(id) \ struct timeval timing_test_##id##_stv;\ gettimeofday (&timing_test_##id##_stv, NULL); @@ -88,6 +89,8 @@ #ifdef HAVE_BG_PIXMAP bgPixmap_t::bgPixmap_t () { + // this is basically redundant as bgPixmap_t is only used in + // zero_initialised-derived structs #ifdef HAVE_AFTERIMAGE original_asim = NULL; #endif @@ -97,6 +100,8 @@ #endif flags = 0; pixmap = None; + valid_since = invalid_since = 0; + target = 0; } void @@ -121,7 +126,7 @@ # ifdef BG_IMAGE_FROM_FILE # ifdef HAVE_AFTERIMAGE - if (original_asim != NULL) + if (original_asim) # endif { if (h_scale != 0 || v_scale != 0 @@ -143,7 +148,7 @@ # ifdef BG_IMAGE_FROM_FILE # ifdef HAVE_AFTERIMAGE - if (original_asim != NULL) + if (original_asim) # endif { if (h_align == rootAlign || v_align == rootAlign) @@ -157,7 +162,7 @@ bool bgPixmap_t::need_client_side_rendering () { # ifdef HAVE_AFTERIMAGE - if (original_asim != NULL) + if (original_asim) return true; # endif # ifdef ENABLE_TRANSPARENCY @@ -257,7 +262,7 @@ unsigned int n; unsigned long new_flags = (flags & (~geometryFlags)); char *p; -# define MAXLEN_GEOM 256 /* could be longer then regular geometry string */ +# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */ if (geom == NULL) return false; @@ -274,7 +279,7 @@ char *ops; new_flags |= geometrySet; - strncpy (str, geom, n); + memcpy (str, geom, n); str[n] = '\0'; if (str[0] == ':') ops = &str[0]; @@ -436,7 +441,7 @@ flags = new_flags; changed++; } -//fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", +//fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", // flags, h_scale, v_scale, h_align, v_align); return (changed > 0); } @@ -468,13 +473,15 @@ x = -x; y = -y; } + if (h_align != rootAlign) x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); + if (v_align != rootAlign) y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); } - if (original_asim == NULL + if (!original_asim || x >= target_width || y >= target_height || (w > 0 && x + w <= 0) @@ -485,6 +492,7 @@ new_pmap_width = background->width; new_pmap_height = background->height; result = background; + if (background_tint != TINT_LEAVE_SAME) { ASImage* tmp = tile_asimage (target->asv, background, 0, 0, @@ -500,6 +508,7 @@ else { result = original_asim; + if ((w > 0 && w != original_asim->width) || (h > 0 && h != original_asim->height)) { @@ -509,10 +518,11 @@ background ? ASA_ASImage : ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); } + if (background == NULL) { /* if tiling - pixmap has to be sized exactly as the image, - but there is no need to make it bigger then the window! */ + but there is no need to make it bigger than the window! */ if (h_scale == 0) new_pmap_width = min (result->width, target_width); if (v_scale == 0) @@ -521,16 +531,17 @@ if (h_scale == 0 || v_scale == 0) { 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_height, - TINT_LEAVE_SAME, ASA_XImage, - 100, ASIMAGE_QUALITY_DEFAULT); + (h_scale > 0) ? 0 : (int)result->width - x, + (v_scale > 0) ? 0 : (int)result->height - y, + new_pmap_width, + new_pmap_height, + TINT_LEAVE_SAME, ASA_XImage, + 100, ASIMAGE_QUALITY_DEFAULT); if (tmp) { if (result != original_asim) destroy_asimage (&result); + result = tmp; } } @@ -546,6 +557,7 @@ layers[0].clip_height = target_height; layers[0].tint = background_tint; layers[1].im = result; + if (w <= 0) { /* tile horizontally */ @@ -559,6 +571,7 @@ layers[1].dst_x = x; layers[1].clip_width = result->width; } + if (h <= 0) { while (y > 0) y -= (int)result->height; @@ -570,20 +583,25 @@ layers[1].dst_y = y; layers[1].clip_height = result->height; } + if (target->rs[Rs_blendtype]) { layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]); if (layers[1].merge_scanlines == NULL) layers[1].merge_scanlines = alphablend_scanlines; } + ASImage *tmp = merge_layers (target->asv, layers, 2, target_width, target_height, ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); + if (tmp) { if (result != original_asim) destroy_asimage (&result); + result = tmp; } + free (layers); } } @@ -655,27 +673,30 @@ { char *f; - assert (file != NULL); + assert (file); - if (*file != '\0') + 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 { size_t len = f - file; f = (char *)malloc (len + 1); - strncpy (f, file, len); + memcpy (f, file, len); f[len] = '\0'; original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100); free (f); } - return (original_asim != NULL); + + return original_asim; # endif } + return false; } @@ -690,6 +711,7 @@ flags |= isTransparent; return true; } + return false; } @@ -780,6 +802,7 @@ flags = (flags & ~tintFlags) | new_flags | tintSet; return true; } + return false; } @@ -793,6 +816,7 @@ flags = (flags&~tintFlags)|new_flags; return true; } + return false; } @@ -802,7 +826,7 @@ int new_shade = (shade_str) ? atoi (shade_str) : 0; if (new_shade < 0 && new_shade > -100) - new_shade = 200 - (100 + new_shade); + new_shade = 200 - (100 + new_shade); else if (new_shade == 100) new_shade = 0; @@ -813,6 +837,7 @@ flags = (flags & (~tintFlags | tintSet)) | new_flags; return true; } + return false; } @@ -898,7 +923,7 @@ XSync (dpy, False); /* XSync should get window where it's properly exposed, - * but to be on the safe side - let's check for the actuall event to arrive : */ + * but to be on the safe side - let's check for the actual event to arrive : */ while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) ++ev_count; @@ -912,6 +937,7 @@ success = true; } } + XDestroyWindow (dpy, src); XUngrabServer (dpy); //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); @@ -985,7 +1011,7 @@ c.g = (c.g * shade) / 100; c.b = (c.b * shade) / 100; } - else if( shade > 100 && shade < 200) + else if (shade > 100 && shade < 200) { c.r = (c.r * (200 - shade)) / 100; c.g = (c.g * (200 - shade)) / 100; @@ -1041,6 +1067,7 @@ XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height); result |= transpPmapTinted; } + XRenderFreePicture (dpy, mask_pic); XRenderFreePicture (dpy, overlay_pic); XRenderFreePicture (dpy, back_pic); @@ -1072,9 +1099,7 @@ bool bgPixmap_t::set_root_pixmap () { - Pixmap new_root_pixmap = None; - - new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); + Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); if (new_root_pixmap == None) new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); @@ -1083,6 +1108,7 @@ root_pixmap = new_root_pixmap; return true; } + return false; } # endif /* ENABLE_TRANSPARENCY */ @@ -1091,7 +1117,6 @@ static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm); # endif - bool bgPixmap_t::render () { @@ -1182,9 +1207,10 @@ } # endif /* HAVE_AFTERIMAGE */ - if (result != NULL) + if (result) { GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); + if (gc) { if (/*pmap_depth != target->depth &&*/ pixmap != None) @@ -1192,30 +1218,35 @@ XFreePixmap (target->dpy, pixmap); pixmap = None; } + if (pixmap == None) { pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth); - pmap_width = result->width; + pmap_width = result->width; pmap_height = result->height; - pmap_depth = target->depth; + pmap_depth = target->depth; } + if (pmap_depth != result->depth) { /* Bad Match error will ensue ! stupid X !!!! */ - if( result->depth == 24 && pmap_depth == 32) + if (result->depth == 24 && pmap_depth == 32) result->depth = 32; - else if( result->depth == 32 && pmap_depth == 24) + else if (result->depth == 32 && pmap_depth == 24) result->depth = 24; else { /* TODO: implement image recoding */ } } + if (pmap_depth == result->depth) XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); + XFreeGC (target->dpy, gc); flags = flags & ~isInvalid; } + XDestroyImage (result); } @@ -1230,6 +1261,9 @@ apply (); + XSync (target->dpy, False); + valid_since = ev::now (); + TIMING_TEST_PRINT_RESULT (tp); return true; @@ -1251,7 +1285,7 @@ } void -bgPixmap_t::apply() +bgPixmap_t::apply () { if (target) {