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.26 by root, Wed Jan 23 11:10:27 2008 UTC vs.
Revision 1.41 by sf-exg, Sat Aug 21 16:07:15 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 { \
37 struct timeval tv; \
38 gettimeofday (&tv, NULL); \
39 tv.tv_sec -= (timing_test_##id##_stv).tv_sec; \
37 fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__,\ 40 fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__, \
38 tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec);}while (0) 41 tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec); \
42 } while (0)
39 43
40#else 44#else
41#define TIMING_TEST_START(id) do{}while (0) 45#define TIMING_TEST_START(id) do {} while (0)
42#define TIMING_TEST_PRINT_RESULT(id) do{}while (0) 46#define TIMING_TEST_PRINT_RESULT(id) do {} while (0)
43#endif 47#endif
44 48
45/* 49/*
46 * Pixmap geometry string interpretation : 50 * Pixmap geometry string interpretation :
47 * Each geometry string contains zero or one scale/position 51 * Each geometry string contains zero or one scale/position
48 * adjustment and may optionally be followed by a colon and one or more 52 * adjustment and may optionally be followed by a colon and one or more
49 * colon-delimited pixmap operations. 53 * colon-delimited pixmap operations.
50 * The following table shows the valid geometry strings and their 54 * The following table shows the valid geometry strings and their
51 * affects on the background image : 55 * effects on the background image :
52 * 56 *
53 * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. 57 * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%.
54 * W and H are percentages of the terminal window size. 58 * W and H are percentages of the terminal window size.
55 * X and Y are also percentages; e.g., +50+50 centers 59 * X and Y are also percentages; e.g., +50+50 centers
56 * the image in the window. 60 * the image in the window.
136# endif 140# endif
137 141
138 return false; 142 return false;
139} 143}
140 144
141bool 145bool
142bgPixmap_t::window_position_sensitive () 146bgPixmap_t::window_position_sensitive ()
143{ 147{
144# ifdef ENABLE_TRANSPARENCY 148# ifdef ENABLE_TRANSPARENCY
145 if (flags & isTransparent) 149 if (flags & isTransparent)
146 return true; 150 return true;
147# endif 151# endif
259 int geom_flags = 0, changed = 0; 263 int geom_flags = 0, changed = 0;
260 int x = 0, y = 0; 264 int x = 0, y = 0;
261 unsigned int w = 0, h = 0; 265 unsigned int w = 0, h = 0;
262 unsigned int n; 266 unsigned int n;
263 unsigned long new_flags = (flags & (~geometryFlags)); 267 unsigned long new_flags = (flags & (~geometryFlags));
264 char *p; 268 const char *p;
265# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */ 269# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */
266 270
267 if (geom == NULL) 271 if (geom == NULL)
268 return false; 272 return false;
269 273
449bgPixmap_t::render_asim (ASImage *background, ARGB32 background_tint) 453bgPixmap_t::render_asim (ASImage *background, ARGB32 background_tint)
450{ 454{
451 if (target == NULL) 455 if (target == NULL)
452 return false; 456 return false;
453 457
458 target->init_asv ();
459
460 ASImage *result = 0;
461
454 int target_width = (int)target->szHint.width; 462 int target_width = target->szHint.width;
455 int target_height = (int)target->szHint.height; 463 int target_height = target->szHint.height;
456 int new_pmap_width = target_width, new_pmap_height = target_height; 464 int new_pmap_width = target_width;
457 ASImage *result = NULL; 465 int new_pmap_height = target_height;
458 466
459 int x = 0; 467 int x = 0;
460 int y = 0; 468 int y = 0;
461 int w = h_scale * target_width / 100; 469 int w = h_scale * target_width / 100;
462 int h = v_scale * target_height / 100; 470 int h = v_scale * target_height / 100;
491 new_pmap_height = background->height; 499 new_pmap_height = background->height;
492 result = background; 500 result = background;
493 501
494 if (background_tint != TINT_LEAVE_SAME) 502 if (background_tint != TINT_LEAVE_SAME)
495 { 503 {
496 ASImage* tmp = tile_asimage (target->asv, background, 0, 0, 504 ASImage *tmp = tile_asimage (target->asv, background, 0, 0,
497 target_width, target_height, background_tint, 505 target_width, target_height, background_tint,
498 ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); 506 ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT);
499 if (tmp) 507 if (tmp)
500 result = tmp; 508 result = tmp;
501 } 509 }
529 if (h_scale == 0 || v_scale == 0) 537 if (h_scale == 0 || v_scale == 0)
530 { 538 {
531 ASImage *tmp = tile_asimage (target->asv, result, 539 ASImage *tmp = tile_asimage (target->asv, result,
532 (h_scale > 0) ? 0 : (int)result->width - x, 540 (h_scale > 0) ? 0 : (int)result->width - x,
533 (v_scale > 0) ? 0 : (int)result->height - y, 541 (v_scale > 0) ? 0 : (int)result->height - y,
534 new_pmap_width, 542 new_pmap_width,
535 new_pmap_height, 543 new_pmap_height,
536 TINT_LEAVE_SAME, ASA_XImage, 544 TINT_LEAVE_SAME, ASA_XImage,
537 100, ASIMAGE_QUALITY_DEFAULT); 545 100, ASIMAGE_QUALITY_DEFAULT);
538 if (tmp) 546 if (tmp)
539 { 547 {
663# endif /* HAVE_AFTERIMAGE */ 671# endif /* HAVE_AFTERIMAGE */
664 672
665bool 673bool
666bgPixmap_t::set_file (const char *file) 674bgPixmap_t::set_file (const char *file)
667{ 675{
668 char *f;
669
670 assert (file); 676 assert (file);
671 677
672 if (*file) 678 if (*file)
673 { 679 {
674# ifdef HAVE_AFTERIMAGE 680# ifdef HAVE_AFTERIMAGE
675 if (target->asimman == NULL) 681 if (!target->asimman)
676 target->asimman = create_generic_imageman (target->rs[Rs_path]); 682 target->asimman = create_generic_imageman (target->rs[Rs_path]);
677 683
678 if ((f = strchr (file, ';')) == NULL) 684 if (const char *p = strchr (file, ';'))
679 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
680 else
681 { 685 {
682 size_t len = f - file; 686 size_t len = p - file;
683 f = (char *)malloc (len + 1); 687 char *f = (char *)malloc (len + 1);
684 memcpy (f, file, len); 688 memcpy (f, file, len);
685 f[len] = '\0'; 689 f[len] = '\0';
686 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100); 690 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100);
687 free (f); 691 free (f);
688 } 692 }
693 else
694 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
689 695
690 return original_asim; 696 return original_asim;
691# endif 697# endif
692 } 698 }
693 699
846 unsigned long result = 0; 852 unsigned long result = 0;
847 853
848 if (target == NULL) 854 if (target == NULL)
849 return 0; 855 return 0;
850 856
851 /* root dimentions may change from call to call - but Display structure should 857 /* root dimensions may change from call to call - but Display structure should
852 * be always up-to-date, so let's use it : 858 * be always up-to-date, so let's use it :
853 */ 859 */
854 Window root = target->display->root; 860 Window root = target->display->root;
855 int screen = target->display->screen; 861 int screen = target->display->screen;
856 Display *dpy = target->dpy; 862 Display *dpy = target->dpy;
945 else 951 else
946 result |= transpPmapTiled; 952 result |= transpPmapTiled;
947 } 953 }
948 else 954 else
949 { 955 {
950 /* strightforward pixmap copy */ 956 /* straightforward pixmap copy */
951 gcv.tile = root_pixmap; 957 gcv.tile = root_pixmap;
952 gcv.fill_style = FillTiled; 958 gcv.fill_style = FillTiled;
953 959
954 while (sx < 0) sx += (int)root_width; 960 while (sx < 0) sx += (int)root_width;
955 while (sy < 0) sy += (int)root_height; 961 while (sy < 0) sy += (int)root_height;
1106 return false; 1112 return false;
1107} 1113}
1108# endif /* ENABLE_TRANSPARENCY */ 1114# endif /* ENABLE_TRANSPARENCY */
1109 1115
1110# ifndef HAVE_AFTERIMAGE 1116# ifndef HAVE_AFTERIMAGE
1111static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm); 1117static void ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm);
1112# endif 1118# endif
1113 1119
1114bool 1120bool
1115bgPixmap_t::render () 1121bgPixmap_t::render ()
1116{ 1122{
1119 if (target == NULL) 1125 if (target == NULL)
1120 return false; 1126 return false;
1121 1127
1122 TIMING_TEST_START (tp); 1128 TIMING_TEST_START (tp);
1123 1129
1124 invalidate(); 1130 invalidate ();
1125# ifdef ENABLE_TRANSPARENCY 1131# ifdef ENABLE_TRANSPARENCY
1126 if (flags & isTransparent) 1132 if (flags & isTransparent)
1127 { 1133 {
1128 /* we need to re-generate transparency pixmap in that case ! */ 1134 /* we need to re-generate transparency pixmap in that case ! */
1129 background_flags = make_transparency_pixmap (); 1135 background_flags = make_transparency_pixmap ();
1138 XImage *result = NULL; 1144 XImage *result = NULL;
1139# ifdef HAVE_AFTERIMAGE 1145# ifdef HAVE_AFTERIMAGE
1140 if (original_asim 1146 if (original_asim
1141 || (background_flags & transpTransformations) != (flags & transpTransformations)) 1147 || (background_flags & transpTransformations) != (flags & transpTransformations))
1142 { 1148 {
1149 target->init_asv ();
1150
1143 ASImage *background = NULL; 1151 ASImage *background = NULL;
1144 ARGB32 as_tint = TINT_LEAVE_SAME; 1152 ARGB32 as_tint = TINT_LEAVE_SAME;
1145 if (background_flags) 1153 if (background_flags)
1146 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100); 1154 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100);
1147 1155
1148# ifdef ENABLE_TRANSPARENCY 1156# ifdef ENABLE_TRANSPARENCY
1149 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1157 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
1150 { 1158 {
1151 ShadingInfo as_shade; 1159 ShadingInfo as_shade;
1158 as_shade.tintColor.green = c.g; 1166 as_shade.tintColor.green = c.g;
1159 as_shade.tintColor.blue = c.b; 1167 as_shade.tintColor.blue = c.b;
1160 1168
1161 as_tint = shading2tint32 (&as_shade); 1169 as_tint = shading2tint32 (&as_shade);
1162 } 1170 }
1171
1163 if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL) 1172 if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL)
1164 { 1173 {
1165 ASImage* tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, 1174 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, 1175 (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage,
1167 100, ASIMAGE_QUALITY_DEFAULT); 1176 100, ASIMAGE_QUALITY_DEFAULT);
1168 if (tmp) 1177 if (tmp)
1169 { 1178 {
1170 destroy_asimage (&background); 1179 destroy_asimage (&background);
1174# endif 1183# endif
1175 1184
1176 if (render_asim (background, as_tint)) 1185 if (render_asim (background, as_tint))
1177 flags = flags & ~isInvalid; 1186 flags = flags & ~isInvalid;
1178 if (background) 1187 if (background)
1179 destroy_asimage (&background); 1188 destroy_asimage (&background);
1180 } 1189 }
1181 else if (background_flags && pmap_depth != target->depth) 1190 else if (background_flags && pmap_depth != target->depth)
1191 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1192
1193# elif !XFT /* our own client-side tinting */
1194
1195 /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side.
1196 This may need to be changed in need_client_side_rendering() logic is altered !!! */
1197
1198 if (background_flags && (flags & isInvalid))
1182 { 1199 {
1183 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1200 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1184 }
1185 1201
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)) 1202 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded))
1195 { 1203 {
1196 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1204 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1197 if (flags & tintSet) 1205 if (flags & tintSet)
1198 tint.get (c); 1206 tint.get (c);
1273# ifdef ENABLE_TRANSPARENCY 1281# ifdef ENABLE_TRANSPARENCY
1274 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); 1282 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen));
1275# endif 1283# endif
1276 return true; 1284 return true;
1277 } 1285 }
1286
1278 return false; 1287 return false;
1279} 1288}
1280 1289
1281void 1290void
1282bgPixmap_t::apply () 1291bgPixmap_t::apply ()
1283{ 1292{
1284 if (target) 1293 if (target)
1285 { 1294 {
1286 flags &= ~isVtOrigin; 1295 flags &= ~isVtOrigin;
1296
1287 if (pixmap != None) 1297 if (pixmap != None)
1288 { 1298 {
1289 /* set target's background to pixmap */ 1299 /* set target's background to pixmap */
1290# ifdef ENABLE_TRANSPARENCY 1300# ifdef ENABLE_TRANSPARENCY
1291 if (flags & isTransparent) 1301 if (flags & isTransparent)
1292 { 1302 {
1293 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); 1303 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
1294 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); 1304 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1295# if HAVE_SCROLLBARS 1305
1296 if (target->scrollBar.win) 1306 if (target->scrollBar.win)
1297 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); 1307 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
1298# endif
1299 } 1308 }
1300 else 1309 else
1301# endif 1310# endif
1302 { 1311 {
1303 flags |= isVtOrigin; 1312 flags |= isVtOrigin;
1304 /* force old pixmap dereference in case it was transparent before :*/ 1313 /* force old pixmap dereference in case it was transparent before :*/
1305 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1314 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1306 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); 1315 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1307 /* do we also need to set scrollbar's background here ? */ 1316 /* do we also need to set scrollbar's background here ? */
1308# if HAVE_SCROLLBARS 1317
1309 if (target->scrollBar.win) 1318 if (target->scrollBar.win)
1310 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1319 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1311# endif
1312 } 1320 }
1313 } 1321 }
1314 else 1322 else
1315 { 1323 {
1316 /* set target background to a pixel */ 1324 /* set target background to a pixel */
1317 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1325 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1318 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); 1326 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
1319 /* do we also need to set scrollbar's background here ? */ 1327 /* do we also need to set scrollbar's background here ? */
1320# if HAVE_SCROLLBARS
1321 if (target->scrollBar.win) 1328 if (target->scrollBar.win)
1322 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1329 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1323# endif
1324 } 1330 }
1331
1325 /* don't want Expose on the parent or vt. It is better to use 1332 /* don't want Expose on the parent or vt. It is better to use
1326 scr_touch or we get a great deal of flicker otherwise: */ 1333 scr_touch or we get a great deal of flicker otherwise: */
1327 XClearWindow (target->dpy, target->parent[0]); 1334 XClearWindow (target->dpy, target->parent[0]);
1328 1335
1329# if HAVE_SCROLLBARS 1336 if (target->scrollBar.state && target->scrollBar.win)
1330 if (target->scrollBar.win)
1331 { 1337 {
1332 target->scrollBar.setIdle (); 1338 target->scrollBar.state = STATE_IDLE;
1333 target->scrollbar_show (0); 1339 target->scrollBar.show (0);
1334 } 1340 }
1335# endif
1336 1341
1337 target->want_refresh = 1; 1342 target->want_refresh = 1;
1338 flags |= hasChanged; 1343 flags |= hasChanged;
1339 } 1344 }
1340} 1345}
1345/* taken from aterm-0.4.2 */ 1350/* taken from aterm-0.4.2 */
1346 1351
1347typedef uint32_t RUINT32T; 1352typedef uint32_t RUINT32T;
1348 1353
1349static void 1354static void
1350ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm) 1355ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm)
1351{ 1356{
1352 int sh_r, sh_g, sh_b; 1357 int sh_r, sh_g, sh_b;
1353 RUINT32T mask_r, mask_g, mask_b; 1358 RUINT32T mask_r, mask_g, mask_b;
1354 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; 1359 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
1355 unsigned int lower_lim_r, lower_lim_g, lower_lim_b; 1360 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines