ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/background.C
(Generate patch)

Comparing rxvt-unicode/src/background.C (file contents):
Revision 1.29 by root, Tue Jan 29 17:52:52 2008 UTC vs.
Revision 1.39 by sf-exg, Mon Jul 26 09:57:53 2010 UTC

1/*----------------------------------------------------------------------* 1/*----------------------------------------------------------------------*
2 * File: background.C - former xpm.C 2 * File: background.C - former xpm.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com> 6 * Copyright (c) 2005-2008 Marc Lehmann <pcg@goof.com>
7 * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> 7 * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net>
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or 11 * the Free Software Foundation; either version 2 of the License, or
27#define DO_TIMING_TEST 0 27#define DO_TIMING_TEST 0
28 28
29#if DO_TIMING_TEST 29#if DO_TIMING_TEST
30# include <sys/time.h> 30# include <sys/time.h>
31#define TIMING_TEST_START(id) \ 31#define TIMING_TEST_START(id) \
32 struct timeval timing_test_##id##_stv;\ 32 struct timeval timing_test_##id##_stv;\
33 gettimeofday (&timing_test_##id##_stv, NULL); 33 gettimeofday (&timing_test_##id##_stv, NULL);
34 34
35#define TIMING_TEST_PRINT_RESULT(id) \ 35#define TIMING_TEST_PRINT_RESULT(id) \
36 do{ struct timeval tv;gettimeofday (&tv, NULL); tv.tv_sec -= (timing_test_##id##_stv).tv_sec;\ 36 do{ struct timeval tv;gettimeofday (&tv, NULL); tv.tv_sec -= (timing_test_##id##_stv).tv_sec;\
37 fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__,\ 37 fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__,\
136# endif 136# endif
137 137
138 return false; 138 return false;
139} 139}
140 140
141bool 141bool
142bgPixmap_t::window_position_sensitive () 142bgPixmap_t::window_position_sensitive ()
143{ 143{
144# ifdef ENABLE_TRANSPARENCY 144# ifdef ENABLE_TRANSPARENCY
145 if (flags & isTransparent) 145 if (flags & isTransparent)
146 return true; 146 return true;
147# endif 147# endif
259 int geom_flags = 0, changed = 0; 259 int geom_flags = 0, changed = 0;
260 int x = 0, y = 0; 260 int x = 0, y = 0;
261 unsigned int w = 0, h = 0; 261 unsigned int w = 0, h = 0;
262 unsigned int n; 262 unsigned int n;
263 unsigned long new_flags = (flags & (~geometryFlags)); 263 unsigned long new_flags = (flags & (~geometryFlags));
264 char *p; 264 const char *p;
265# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */ 265# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */
266 266
267 if (geom == NULL) 267 if (geom == NULL)
268 return false; 268 return false;
269 269
449bgPixmap_t::render_asim (ASImage *background, ARGB32 background_tint) 449bgPixmap_t::render_asim (ASImage *background, ARGB32 background_tint)
450{ 450{
451 if (target == NULL) 451 if (target == NULL)
452 return false; 452 return false;
453 453
454 target->init_asv ();
455
456 ASImage *result = 0;
457
454 int target_width = (int)target->szHint.width; 458 int target_width = target->szHint.width;
455 int target_height = (int)target->szHint.height; 459 int target_height = target->szHint.height;
456 int new_pmap_width = target_width, new_pmap_height = target_height; 460 int new_pmap_width = target_width;
457 ASImage *result = NULL; 461 int new_pmap_height = target_height;
458 462
459 int x = 0; 463 int x = 0;
460 int y = 0; 464 int y = 0;
461 int w = h_scale * target_width / 100; 465 int w = h_scale * target_width / 100;
462 int h = v_scale * target_height / 100; 466 int h = v_scale * target_height / 100;
491 new_pmap_height = background->height; 495 new_pmap_height = background->height;
492 result = background; 496 result = background;
493 497
494 if (background_tint != TINT_LEAVE_SAME) 498 if (background_tint != TINT_LEAVE_SAME)
495 { 499 {
496 ASImage* tmp = tile_asimage (target->asv, background, 0, 0, 500 ASImage *tmp = tile_asimage (target->asv, background, 0, 0,
497 target_width, target_height, background_tint, 501 target_width, target_height, background_tint,
498 ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); 502 ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT);
499 if (tmp) 503 if (tmp)
500 result = tmp; 504 result = tmp;
501 } 505 }
529 if (h_scale == 0 || v_scale == 0) 533 if (h_scale == 0 || v_scale == 0)
530 { 534 {
531 ASImage *tmp = tile_asimage (target->asv, result, 535 ASImage *tmp = tile_asimage (target->asv, result,
532 (h_scale > 0) ? 0 : (int)result->width - x, 536 (h_scale > 0) ? 0 : (int)result->width - x,
533 (v_scale > 0) ? 0 : (int)result->height - y, 537 (v_scale > 0) ? 0 : (int)result->height - y,
534 new_pmap_width, 538 new_pmap_width,
535 new_pmap_height, 539 new_pmap_height,
536 TINT_LEAVE_SAME, ASA_XImage, 540 TINT_LEAVE_SAME, ASA_XImage,
537 100, ASIMAGE_QUALITY_DEFAULT); 541 100, ASIMAGE_QUALITY_DEFAULT);
538 if (tmp) 542 if (tmp)
539 { 543 {
663# endif /* HAVE_AFTERIMAGE */ 667# endif /* HAVE_AFTERIMAGE */
664 668
665bool 669bool
666bgPixmap_t::set_file (const char *file) 670bgPixmap_t::set_file (const char *file)
667{ 671{
668 char *f;
669
670 assert (file); 672 assert (file);
671 673
672 if (*file) 674 if (*file)
673 { 675 {
674# ifdef HAVE_AFTERIMAGE 676# ifdef HAVE_AFTERIMAGE
675 if (target->asimman == NULL) 677 if (!target->asimman)
676 target->asimman = create_generic_imageman (target->rs[Rs_path]); 678 target->asimman = create_generic_imageman (target->rs[Rs_path]);
677 679
678 if ((f = strchr (file, ';')) == NULL) 680 if (const char *p = strchr (file, ';'))
679 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
680 else
681 { 681 {
682 size_t len = f - file; 682 size_t len = p - file;
683 f = (char *)malloc (len + 1); 683 char *f = (char *)malloc (len + 1);
684 memcpy (f, file, len); 684 memcpy (f, file, len);
685 f[len] = '\0'; 685 f[len] = '\0';
686 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100); 686 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100);
687 free (f); 687 free (f);
688 } 688 }
689 else
690 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
689 691
690 return original_asim; 692 return original_asim;
691# endif 693# endif
692 } 694 }
693 695
846 unsigned long result = 0; 848 unsigned long result = 0;
847 849
848 if (target == NULL) 850 if (target == NULL)
849 return 0; 851 return 0;
850 852
851 /* root dimentions may change from call to call - but Display structure should 853 /* root dimensions may change from call to call - but Display structure should
852 * be always up-to-date, so let's use it : 854 * be always up-to-date, so let's use it :
853 */ 855 */
854 Window root = target->display->root; 856 Window root = target->display->root;
855 int screen = target->display->screen; 857 int screen = target->display->screen;
856 Display *dpy = target->dpy; 858 Display *dpy = target->dpy;
945 else 947 else
946 result |= transpPmapTiled; 948 result |= transpPmapTiled;
947 } 949 }
948 else 950 else
949 { 951 {
950 /* strightforward pixmap copy */ 952 /* straightforward pixmap copy */
951 gcv.tile = root_pixmap; 953 gcv.tile = root_pixmap;
952 gcv.fill_style = FillTiled; 954 gcv.fill_style = FillTiled;
953 955
954 while (sx < 0) sx += (int)root_width; 956 while (sx < 0) sx += (int)root_width;
955 while (sy < 0) sy += (int)root_height; 957 while (sy < 0) sy += (int)root_height;
1106 return false; 1108 return false;
1107} 1109}
1108# endif /* ENABLE_TRANSPARENCY */ 1110# endif /* ENABLE_TRANSPARENCY */
1109 1111
1110# ifndef HAVE_AFTERIMAGE 1112# ifndef HAVE_AFTERIMAGE
1111static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm); 1113static void ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm);
1112# endif 1114# endif
1113 1115
1114bool 1116bool
1115bgPixmap_t::render () 1117bgPixmap_t::render ()
1116{ 1118{
1119 if (target == NULL) 1121 if (target == NULL)
1120 return false; 1122 return false;
1121 1123
1122 TIMING_TEST_START (tp); 1124 TIMING_TEST_START (tp);
1123 1125
1124 invalidate(); 1126 invalidate ();
1125# ifdef ENABLE_TRANSPARENCY 1127# ifdef ENABLE_TRANSPARENCY
1126 if (flags & isTransparent) 1128 if (flags & isTransparent)
1127 { 1129 {
1128 /* we need to re-generate transparency pixmap in that case ! */ 1130 /* we need to re-generate transparency pixmap in that case ! */
1129 background_flags = make_transparency_pixmap (); 1131 background_flags = make_transparency_pixmap ();
1138 XImage *result = NULL; 1140 XImage *result = NULL;
1139# ifdef HAVE_AFTERIMAGE 1141# ifdef HAVE_AFTERIMAGE
1140 if (original_asim 1142 if (original_asim
1141 || (background_flags & transpTransformations) != (flags & transpTransformations)) 1143 || (background_flags & transpTransformations) != (flags & transpTransformations))
1142 { 1144 {
1145 target->init_asv ();
1146
1143 ASImage *background = NULL; 1147 ASImage *background = NULL;
1144 ARGB32 as_tint = TINT_LEAVE_SAME; 1148 ARGB32 as_tint = TINT_LEAVE_SAME;
1145 if (background_flags) 1149 if (background_flags)
1146 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100); 1150 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100);
1147 1151
1148# ifdef ENABLE_TRANSPARENCY 1152# ifdef ENABLE_TRANSPARENCY
1149 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1153 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
1150 { 1154 {
1151 ShadingInfo as_shade; 1155 ShadingInfo as_shade;
1158 as_shade.tintColor.green = c.g; 1162 as_shade.tintColor.green = c.g;
1159 as_shade.tintColor.blue = c.b; 1163 as_shade.tintColor.blue = c.b;
1160 1164
1161 as_tint = shading2tint32 (&as_shade); 1165 as_tint = shading2tint32 (&as_shade);
1162 } 1166 }
1167
1163 if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL) 1168 if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL)
1164 { 1169 {
1165 ASImage* tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, 1170 ASImage *tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
1166 (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage, 1171 (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage,
1167 100, ASIMAGE_QUALITY_DEFAULT); 1172 100, ASIMAGE_QUALITY_DEFAULT);
1168 if (tmp) 1173 if (tmp)
1169 { 1174 {
1170 destroy_asimage (&background); 1175 destroy_asimage (&background);
1174# endif 1179# endif
1175 1180
1176 if (render_asim (background, as_tint)) 1181 if (render_asim (background, as_tint))
1177 flags = flags & ~isInvalid; 1182 flags = flags & ~isInvalid;
1178 if (background) 1183 if (background)
1179 destroy_asimage (&background); 1184 destroy_asimage (&background);
1180 } 1185 }
1181 else if (background_flags && pmap_depth != target->depth) 1186 else if (background_flags && pmap_depth != target->depth)
1187 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1188
1189# elif !XFT /* our own client-side tinting */
1190
1191 /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side.
1192 This may need to be changed in need_client_side_rendering() logic is altered !!! */
1193
1194 if (background_flags && (flags & isInvalid))
1182 { 1195 {
1183 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1196 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1184 }
1185 1197
1186# elif !XFT /* our own client-side tinting */
1187
1188 /* ATTENTION: We ASSUME that XFT will let us do all the tinting neccessary server-side.
1189 This may need to be changed in need_client_side_rendering() logic is altered !!! */
1190
1191 if (background_flags && (flags & isInvalid))
1192 {
1193 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1194 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1198 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded))
1195 { 1199 {
1196 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1200 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1197 if (flags & tintSet) 1201 if (flags & tintSet)
1198 tint.get (c); 1202 tint.get (c);
1273# ifdef ENABLE_TRANSPARENCY 1277# ifdef ENABLE_TRANSPARENCY
1274 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); 1278 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen));
1275# endif 1279# endif
1276 return true; 1280 return true;
1277 } 1281 }
1282
1278 return false; 1283 return false;
1279} 1284}
1280 1285
1281void 1286void
1282bgPixmap_t::apply () 1287bgPixmap_t::apply ()
1322 1327
1323 /* don't want Expose on the parent or vt. It is better to use 1328 /* don't want Expose on the parent or vt. It is better to use
1324 scr_touch or we get a great deal of flicker otherwise: */ 1329 scr_touch or we get a great deal of flicker otherwise: */
1325 XClearWindow (target->dpy, target->parent[0]); 1330 XClearWindow (target->dpy, target->parent[0]);
1326 1331
1327 if (target->scrollBar.win) 1332 if (target->scrollBar.state && target->scrollBar.win)
1328 { 1333 {
1329 target->scrollBar.state = STATE_IDLE; 1334 target->scrollBar.state = STATE_IDLE;
1330 target->scrollbar_show (0); 1335 target->scrollBar.show (0);
1331 } 1336 }
1332 1337
1333 target->want_refresh = 1; 1338 target->want_refresh = 1;
1334 flags |= hasChanged; 1339 flags |= hasChanged;
1335 } 1340 }
1341/* taken from aterm-0.4.2 */ 1346/* taken from aterm-0.4.2 */
1342 1347
1343typedef uint32_t RUINT32T; 1348typedef uint32_t RUINT32T;
1344 1349
1345static void 1350static void
1346ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm) 1351ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm)
1347{ 1352{
1348 int sh_r, sh_g, sh_b; 1353 int sh_r, sh_g, sh_b;
1349 RUINT32T mask_r, mask_g, mask_b; 1354 RUINT32T mask_r, mask_g, mask_b;
1350 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; 1355 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
1351 unsigned int lower_lim_r, lower_lim_g, lower_lim_b; 1356 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines