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.99 by sf-exg, Sat Oct 30 16:39:04 2010 UTC vs.
Revision 1.118 by sf-exg, Tue Nov 16 15:49:56 2010 UTC

23 *---------------------------------------------------------------------*/ 23 *---------------------------------------------------------------------*/
24 24
25#include <cmath> 25#include <cmath>
26#include "../config.h" /* NECESSARY */ 26#include "../config.h" /* NECESSARY */
27#include "rxvt.h" /* NECESSARY */ 27#include "rxvt.h" /* NECESSARY */
28
29#if XRENDER
30# include <X11/extensions/Xrender.h>
31#endif
32
33#ifndef FilterConvolution
34#define FilterConvolution "convolution"
35#endif
28 36
29#define DO_TIMING_TEST 0 37#define DO_TIMING_TEST 0
30 38
31#if DO_TIMING_TEST 39#if DO_TIMING_TEST
32# include <sys/time.h> 40# include <sys/time.h>
168 return true; 176 return true;
169 } 177 }
170# endif 178# endif
171 179
172 return false; 180 return false;
173}; 181}
174 182
175bool bgPixmap_t::need_client_side_rendering () 183bool bgPixmap_t::need_client_side_rendering ()
176{ 184{
177# ifdef HAVE_AFTERIMAGE 185# ifdef HAVE_AFTERIMAGE
178 if (original_asim) 186 if (original_asim)
250} 258}
251 259
252bool 260bool
253bgPixmap_t::set_geometry (const char *geom) 261bgPixmap_t::set_geometry (const char *geom)
254{ 262{
263 bool changed = false;
255 int geom_flags = 0, changed = 0; 264 int geom_flags = 0;
256 int x = 0, y = 0; 265 int x = 0, y = 0;
257 unsigned int w = 0, h = 0; 266 unsigned int w = 0, h = 0;
258 unsigned int n; 267 unsigned int n;
259 unsigned long new_flags = (flags & (~geometryFlags)); 268 unsigned long new_flags = (flags & (~geometryFlags));
260 const char *p; 269 const char *p;
416 425
417 while (*ops != ':' && *ops != '\0') ++ops; 426 while (*ops != ':' && *ops != '\0') ++ops;
418 } /* done parsing ops */ 427 } /* done parsing ops */
419 } 428 }
420 429
421 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) ++changed; 430 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true;
422 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) ++changed; 431 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true;
423 if (check_set_align_value (geom_flags, XValue, h_align, x)) ++changed; 432 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true;
424 if (check_set_align_value (geom_flags, YValue, v_align, y)) ++changed; 433 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true;
425 } 434 }
426 435
427 if (new_flags != flags) 436 if (new_flags != flags)
428 { 437 {
429 flags = new_flags; 438 flags = new_flags;
430 changed++; 439 changed = true;
431 } 440 }
432 441
433 return (changed > 0); 442 return changed;
434} 443}
435 444
436void 445void
437bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) 446bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y)
438{ 447{
661 if (result) 670 if (result)
662 { 671 {
663 XGCValues gcv; 672 XGCValues gcv;
664 GC gc; 673 GC gc;
665 674
666 if (pixmap)
667 {
668 if (pmap_width != new_pmap_width
669 || pmap_height != new_pmap_height
670 || pmap_depth != target->depth)
671 {
672 XFreePixmap (target->dpy, pixmap);
673 pixmap = None;
674 }
675 }
676
677 /* create Pixmap */ 675 /* create Pixmap */
678 if (pixmap == None) 676 if (pixmap == None
677 || pmap_width != new_pmap_width
678 || pmap_height != new_pmap_height
679 || pmap_depth != target->depth)
679 { 680 {
681 if (pixmap)
682 XFreePixmap (target->dpy, pixmap);
680 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 683 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
681 pmap_width = new_pmap_width; 684 pmap_width = new_pmap_width;
682 pmap_height = new_pmap_height; 685 pmap_height = new_pmap_height;
683 pmap_depth = target->depth; 686 pmap_depth = target->depth;
684 } 687 }
729 return false; 732 return false;
730 733
731 if (!pixbuf) 734 if (!pixbuf)
732 return false; 735 return false;
733 736
734#if !XFT
735 if (background_flags) 737 if (background_flags
738 && !(flags & HAS_RENDER))
736 return false; 739 return false;
737#endif
738 740
739 GdkPixbuf *result; 741 GdkPixbuf *result;
740 742
741 int image_width = gdk_pixbuf_get_width (pixbuf); 743 int image_width = gdk_pixbuf_get_width (pixbuf);
742 int image_height = gdk_pixbuf_get_height (pixbuf); 744 int image_height = gdk_pixbuf_get_height (pixbuf);
793 new_pmap_width = min (image_width, target_width); 795 new_pmap_width = min (image_width, target_width);
794 new_pmap_height = min (image_height, target_height); 796 new_pmap_height = min (image_height, target_height);
795 } 797 }
796 } 798 }
797 799
798 if (pixmap)
799 {
800 if (pmap_width != new_pmap_width
801 || pmap_height != new_pmap_height
802 || pmap_depth != target->depth)
803 {
804 XFreePixmap (target->dpy, pixmap);
805 pixmap = None;
806 }
807 }
808
809 if (pixmap == None) 800 if (pixmap == None
801 || pmap_width != new_pmap_width
802 || pmap_height != new_pmap_height
803 || pmap_depth != target->depth)
810 { 804 {
805 if (pixmap)
806 XFreePixmap (target->dpy, pixmap);
811 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 807 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
812 pmap_width = new_pmap_width; 808 pmap_width = new_pmap_width;
813 pmap_height = new_pmap_height; 809 pmap_height = new_pmap_height;
814 pmap_depth = target->depth; 810 pmap_depth = target->depth;
815 } 811 }
856 dst_width, dst_height, 852 dst_width, dst_height,
857 XLIB_RGB_DITHER_NONE, 853 XLIB_RGB_DITHER_NONE,
858 0, 0); 854 0, 0);
859 } 855 }
860 856
861#if XFT 857#if XRENDER
862 if (background_flags) 858 if (background_flags)
863 { 859 {
864 Display *dpy = target->dpy; 860 Display *dpy = target->dpy;
865 XRenderPictureAttributes pa; 861 XRenderPictureAttributes pa;
866 862
867 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, target->display->screen)); 863 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, target->visual);
868 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); 864 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa);
869 865
870 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); 866 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual);
871 Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa); 867 Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa);
872 868
909# endif /* HAVE_PIXBUF */ 905# endif /* HAVE_PIXBUF */
910 906
911bool 907bool
912bgPixmap_t::set_file (const char *file) 908bgPixmap_t::set_file (const char *file)
913{ 909{
914 assert (file); 910 if (!file || !*file)
911 return false;
915 912
916 if (*file)
917 {
918 if (const char *p = strchr (file, ';')) 913 if (const char *p = strchr (file, ';'))
919 { 914 {
920 size_t len = p - file; 915 size_t len = p - file;
921 char *f = rxvt_temp_buf<char> (len + 1); 916 char *f = rxvt_temp_buf<char> (len + 1);
922 memcpy (f, file, len); 917 memcpy (f, file, len);
923 f[len] = '\0'; 918 f[len] = '\0';
924 file = f; 919 file = f;
925 } 920 }
926 921
927# ifdef HAVE_AFTERIMAGE 922# ifdef HAVE_AFTERIMAGE
928 if (!target->asimman) 923 if (!target->asimman)
929 target->asimman = create_generic_imageman (target->rs[Rs_path]); 924 target->asimman = create_generic_imageman (target->rs[Rs_path]);
930 ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); 925 ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
931 if (image) 926 if (image)
932 { 927 {
933 if (original_asim) 928 if (original_asim)
934 safe_asimage_destroy (original_asim); 929 safe_asimage_destroy (original_asim);
935 original_asim = image; 930 original_asim = image;
936 have_image = true; 931 have_image = true;
937 return true; 932 return true;
938 } 933 }
939# endif 934# endif
940 935
941# ifdef HAVE_PIXBUF 936# ifdef HAVE_PIXBUF
942 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); 937 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL);
943 if (image) 938 if (image)
944 { 939 {
945 if (pixbuf) 940 if (pixbuf)
946 g_object_unref (pixbuf); 941 g_object_unref (pixbuf);
947 pixbuf = image; 942 pixbuf = image;
948 have_image = true; 943 have_image = true;
949 return true; 944 return true;
950 } 945 }
951# endif 946# endif
952 }
953 947
954 return false; 948 return false;
955} 949}
956 950
957# endif /* BG_IMAGE_FROM_FILE */ 951# endif /* BG_IMAGE_FROM_FILE */
970} 964}
971 965
972bool 966bool
973bgPixmap_t::set_blur_radius (const char *geom) 967bgPixmap_t::set_blur_radius (const char *geom)
974{ 968{
975 int changed = 0; 969 bool changed = false;
976 unsigned int hr, vr; 970 unsigned int hr, vr;
977 int junk; 971 int junk;
978 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); 972 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
979 973
980 if (!(geom_flags & WidthValue)) 974 if (!(geom_flags & WidthValue))
985 min_it (hr, 128); 979 min_it (hr, 128);
986 min_it (vr, 128); 980 min_it (vr, 128);
987 981
988 if (h_blurRadius != hr) 982 if (h_blurRadius != hr)
989 { 983 {
990 ++changed; 984 changed = true;
991 h_blurRadius = hr; 985 h_blurRadius = hr;
992 } 986 }
993 987
994 if (v_blurRadius != vr) 988 if (v_blurRadius != vr)
995 { 989 {
996 ++changed; 990 changed = true;
997 v_blurRadius = vr; 991 v_blurRadius = vr;
998 } 992 }
999 993
1000 if (v_blurRadius == 0 && h_blurRadius == 0) 994 if (v_blurRadius == 0 && h_blurRadius == 0)
1001 flags &= ~blurNeeded; 995 flags &= ~blurNeeded;
1002 else 996 else
1003 flags |= blurNeeded; 997 flags |= blurNeeded;
1004 998
1005#if XFT
1006 XFilters *filters = XRenderQueryFilters (target->dpy, target->display->root);
1007 if (filters)
1008 {
1009 for (int i = 0; i < filters->nfilter; i++)
1010 if (!strcmp (filters->filter[i], FilterConvolution))
1011 flags |= bgPixmap_t::blurServerSide;
1012
1013 XFree (filters);
1014 }
1015#endif
1016
1017 return (changed > 0); 999 return changed;
1018} 1000}
1019 1001
1020static inline unsigned long 1002static inline unsigned long
1021compute_tint_shade_flags (rxvt_color *tint, int shade) 1003compute_tint_shade_flags (rxvt_color *tint, int shade)
1022{ 1004{
1044 { 1026 {
1045 flags |= bgPixmap_t::tintNeeded; 1027 flags |= bgPixmap_t::tintNeeded;
1046 } 1028 }
1047 } 1029 }
1048 1030
1049 if (flags & bgPixmap_t::tintNeeded)
1050 {
1051 if (flags & bgPixmap_t::tintWholesome)
1052 flags |= bgPixmap_t::tintServerSide;
1053 else
1054 {
1055#if XFT
1056 flags |= bgPixmap_t::tintServerSide;
1057#endif
1058 }
1059 }
1060
1061 return flags; 1031 return flags;
1062} 1032}
1063 1033
1064bool 1034bool
1065bgPixmap_t::set_tint (rxvt_color &new_tint) 1035bgPixmap_t::set_tint (rxvt_color &new_tint)
1107 } 1077 }
1108 1078
1109 return false; 1079 return false;
1110} 1080}
1111 1081
1112#if XFT 1082#if XRENDER
1113static void 1083static void
1114get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) 1084get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params)
1115{ 1085{
1116 double sigma = radius / 2.0; 1086 double sigma = radius / 2.0;
1117 double scale = sqrt (2.0 * M_PI) * sigma; 1087 double scale = sqrt (2.0 * M_PI) * sigma;
1134 1104
1135bool 1105bool
1136bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) 1106bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height)
1137{ 1107{
1138 bool ret = false; 1108 bool ret = false;
1139#if XFT 1109#if XRENDER
1140 int size = max (h_blurRadius, v_blurRadius) * 2 + 1; 1110 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
1141 double *kernel = (double *)malloc (size * sizeof (double)); 1111 double *kernel = (double *)malloc (size * sizeof (double));
1142 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 1112 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
1143 1113
1144 Display *dpy = target->dpy; 1114 Display *dpy = target->dpy;
1221 XFreeGC (dpy, gc); 1191 XFreeGC (dpy, gc);
1222 } 1192 }
1223 } 1193 }
1224 else 1194 else
1225 { 1195 {
1226# if XFT 1196# if XRENDER
1227 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1197 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1228 1198
1229 if (flags & tintSet) 1199 if (flags & tintSet)
1230 tint.get (c); 1200 tint.get (c);
1231 1201
1261 1231
1262 if (mask_pic && overlay_pic && back_pic) 1232 if (mask_pic && overlay_pic && back_pic)
1263 { 1233 {
1264 XRenderColor mask_c; 1234 XRenderColor mask_c;
1265 1235
1266 memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c)); 1236 mask_c.red = mask_c.green = mask_c.blue = shade > 100 ? 0xffff : 0;
1267 mask_c.alpha = 0xffff; 1237 mask_c.alpha = 0xffff;
1268 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); 1238 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1269 1239
1270 mask_c.alpha = 0; 1240 mask_c.alpha = 0;
1271 mask_c.red = 0xffff - c.r; 1241 mask_c.red = 0xffff - c.r;
1284 1254
1285 return ret; 1255 return ret;
1286} 1256}
1287 1257
1288/* make_transparency_pixmap() 1258/* make_transparency_pixmap()
1289 * Builds a pixmap sized the same as terminal window, with depth same as the root window 1259 * Builds a pixmap of the same size as the terminal window that contains
1290 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by 1260 * the tiled portion of the root pixmap that is supposed to be covered by
1291 * our window. 1261 * our window.
1292 */ 1262 */
1293unsigned long 1263unsigned long
1294bgPixmap_t::make_transparency_pixmap () 1264bgPixmap_t::make_transparency_pixmap ()
1295{ 1265{
1299 return 0; 1269 return 0;
1300 1270
1301 /* root dimensions may change from call to call - but Display structure should 1271 /* root dimensions may change from call to call - but Display structure should
1302 * be always up-to-date, so let's use it : 1272 * be always up-to-date, so let's use it :
1303 */ 1273 */
1304 Window root = target->display->root;
1305 int screen = target->display->screen; 1274 int screen = target->display->screen;
1306 Display *dpy = target->dpy; 1275 Display *dpy = target->dpy;
1276 int root_depth = DefaultDepth (dpy, screen);
1307 int root_width = DisplayWidth (dpy, screen); 1277 int root_width = DisplayWidth (dpy, screen);
1308 int root_height = DisplayHeight (dpy, screen); 1278 int root_height = DisplayHeight (dpy, screen);
1279 unsigned int root_pmap_width, root_pmap_height;
1309 int window_width = target->szHint.width; 1280 int window_width = target->szHint.width;
1310 int window_height = target->szHint.height; 1281 int window_height = target->szHint.height;
1311 int sx, sy; 1282 int sx, sy;
1312 XGCValues gcv; 1283 XGCValues gcv;
1313 GC gc; 1284 GC gc;
1317 /* check if we are outside of the visible part of the virtual screen : */ 1288 /* check if we are outside of the visible part of the virtual screen : */
1318 if (sx + window_width <= 0 || sy + window_height <= 0 1289 if (sx + window_width <= 0 || sy + window_height <= 0
1319 || sx >= root_width || sy >= root_height) 1290 || sx >= root_width || sy >= root_height)
1320 return 0; 1291 return 0;
1321 1292
1293 // validate root pixmap and get its size
1294 if (root_pixmap != None)
1295 {
1296 Window wdummy;
1297 int idummy;
1298 unsigned int udummy;
1299
1300 target->allowedxerror = -1;
1301
1302 if (!XGetGeometry (dpy, root_pixmap, &wdummy, &idummy, &idummy, &root_pmap_width, &root_pmap_height, &udummy, &udummy))
1303 root_pixmap = None;
1304
1305 target->allowedxerror = 0;
1306 }
1307
1308 Pixmap recoded_root_pmap = root_pixmap;
1309
1310 if (root_pixmap != None && root_depth != target->depth)
1311 {
1312#if XRENDER
1313 if (flags & HAS_RENDER)
1314 {
1315 XRenderPictureAttributes pa;
1316
1317 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
1318 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa);
1319
1320 recoded_root_pmap = XCreatePixmap (dpy, target->vt, root_pmap_width, root_pmap_height, target->depth);
1321 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual);
1322 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa);
1323
1324 if (src && dst)
1325 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height);
1326 else
1327 {
1328 XFreePixmap (dpy, recoded_root_pmap);
1329 root_pixmap = None;
1330 }
1331
1332 XRenderFreePicture (dpy, src);
1333 XRenderFreePicture (dpy, dst);
1334 }
1335 else
1336#endif
1337 root_pixmap = None;
1338 }
1339
1322 if (root_pixmap == None) 1340 if (root_pixmap == None)
1323 return 0; 1341 return 0;
1324 1342
1325 Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth); 1343 Pixmap tiled_root_pmap = XCreatePixmap (dpy, target->vt, window_width, window_height, target->depth);
1326 1344
1327 if (tiled_root_pmap == None) /* something really bad happened - abort */ 1345 if (tiled_root_pmap == None) /* something really bad happened - abort */
1328 return 0; 1346 return 0;
1329 1347
1330 /* straightforward pixmap copy */ 1348 /* straightforward pixmap copy */
1331 gcv.tile = root_pixmap; 1349 gcv.tile = recoded_root_pmap;
1332 gcv.fill_style = FillTiled; 1350 gcv.fill_style = FillTiled;
1333 1351
1334 while (sx < 0) sx += (int)root_width; 1352 while (sx < 0) sx += (int)root_width;
1335 while (sy < 0) sy += (int)root_height; 1353 while (sy < 0) sy += (int)root_height;
1336 1354
1337 gcv.ts_x_origin = -sx; 1355 gcv.ts_x_origin = -sx;
1338 gcv.ts_y_origin = -sy; 1356 gcv.ts_y_origin = -sy;
1339 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 1357 gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
1340 1358
1341 if (gc) 1359 if (gc)
1342 { 1360 {
1343 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); 1361 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
1344 result |= transpPmapTiled; 1362 result |= transpPmapTiled;
1345 XFreeGC (dpy, gc); 1363 XFreeGC (dpy, gc);
1346 }
1347 1364
1348 if (tiled_root_pmap != None)
1349 {
1350 if (!need_client_side_rendering ()) 1365 if (!need_client_side_rendering ())
1351 { 1366 {
1352 if (flags & (blurNeeded | blurServerSide)) 1367 if ((flags & blurNeeded)
1368 && (flags & HAS_RENDER_CONV))
1353 { 1369 {
1354 if (blur_pixmap (tiled_root_pmap, DefaultVisual (dpy, screen), window_width, window_height)) 1370 if (blur_pixmap (tiled_root_pmap, target->visual, window_width, window_height))
1355 result |= transpPmapBlurred; 1371 result |= transpPmapBlurred;
1356 } 1372 }
1357 if (flags & (tintNeeded | tintServerSide)) 1373 if ((flags & tintNeeded)
1374 && (flags & (tintWholesome | HAS_RENDER)))
1358 { 1375 {
1359 if (tint_pixmap (tiled_root_pmap, DefaultVisual (dpy, screen), window_width, window_height)) 1376 if (tint_pixmap (tiled_root_pmap, target->visual, window_width, window_height))
1360 result |= transpPmapTinted; 1377 result |= transpPmapTinted;
1361 } 1378 }
1362 } /* server side rendering completed */ 1379 } /* server side rendering completed */
1363 1380
1364 if (pixmap) 1381 if (pixmap)
1365 XFreePixmap (dpy, pixmap); 1382 XFreePixmap (dpy, pixmap);
1366 1383
1367 pixmap = tiled_root_pmap; 1384 pixmap = tiled_root_pmap;
1368 pmap_width = window_width; 1385 pmap_width = window_width;
1369 pmap_height = window_height; 1386 pmap_height = window_height;
1370 pmap_depth = root_depth; 1387 pmap_depth = target->depth;
1371 } 1388 }
1389 else
1390 XFreePixmap (dpy, tiled_root_pmap);
1391
1392 if (recoded_root_pmap != root_pixmap)
1393 XFreePixmap (dpy, recoded_root_pmap);
1372 1394
1373 return result; 1395 return result;
1374} 1396}
1375 1397
1376void 1398void
1379 Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); 1401 Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID);
1380 if (new_root_pixmap == None) 1402 if (new_root_pixmap == None)
1381 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); 1403 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID);
1382 1404
1383 root_pixmap = new_root_pixmap; 1405 root_pixmap = new_root_pixmap;
1384
1385 // validate root pixmap
1386 if (root_pixmap != None)
1387 {
1388 unsigned int width, height;
1389 Window wdummy;
1390 int idummy;
1391 unsigned int udummy;
1392
1393 target->allowedxerror = -1;
1394
1395 if (!XGetGeometry (target->dpy, root_pixmap, &wdummy, &idummy, &idummy, &width, &height, &udummy, &udummy))
1396 root_pixmap = None;
1397
1398 target->allowedxerror = 0;
1399 }
1400} 1406}
1401# endif /* ENABLE_TRANSPARENCY */ 1407# endif /* ENABLE_TRANSPARENCY */
1402 1408
1403# ifndef HAVE_AFTERIMAGE 1409#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1404static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm); 1410static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, const rgba &c);
1405# endif 1411# endif
1406 1412
1407bool 1413bool
1408bgPixmap_t::render () 1414bgPixmap_t::render ()
1409{ 1415{
1418 { 1424 {
1419 /* we need to re-generate transparency pixmap in that case ! */ 1425 /* we need to re-generate transparency pixmap in that case ! */
1420 background_flags = make_transparency_pixmap (); 1426 background_flags = make_transparency_pixmap ();
1421 if (background_flags == 0) 1427 if (background_flags == 0)
1422 return false; 1428 return false;
1423 else if ((background_flags & transpTransformations) == (flags & transpTransformations) 1429 else if ((background_flags & transpTransformations) == (flags & transpTransformations))
1424 && pmap_depth == target->depth)
1425 flags = flags & ~isInvalid; 1430 flags = flags & ~isInvalid;
1426 } 1431 }
1427# endif 1432# endif
1428 1433
1429# ifdef BG_IMAGE_FROM_FILE 1434# ifdef BG_IMAGE_FROM_FILE
1433 if (render_image (background_flags)) 1438 if (render_image (background_flags))
1434 flags = flags & ~isInvalid; 1439 flags = flags & ~isInvalid;
1435 } 1440 }
1436# endif 1441# endif
1437 1442
1443# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1438 XImage *result = NULL; 1444 XImage *result = NULL;
1439 1445
1440 if (background_flags && (flags & isInvalid)) 1446 if (background_flags && (flags & isInvalid))
1441 { 1447 {
1442 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1448 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1443 } 1449 }
1444 1450
1445 if (result) 1451 if (result)
1446 { 1452 {
1447# if !defined(HAVE_AFTERIMAGE) && !XFT
1448 /* our own client-side tinting */ 1453 /* our own client-side tinting */
1449 /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side.
1450 This may need to be changed in need_client_side_rendering() logic is altered !!! */
1451 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1454 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
1452 { 1455 {
1453 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1456 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1454 if (flags & tintSet) 1457 if (flags & tintSet)
1455 tint.get (c); 1458 tint.get (c);
1456 ShadeXImage (DefaultVisual (target->dpy, target->display->screen), result, shade, c.r, c.g, c.b); 1459 ShadeXImage (DefaultVisual (target->dpy, target->display->screen), result, shade, c);
1457 } 1460 }
1458# endif
1459 1461
1460 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1462 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1461 1463
1462 if (gc) 1464 if (gc)
1463 { 1465 {
1464 if (/*pmap_depth != target->depth &&*/ pixmap != None)
1465 {
1466 XFreePixmap (target->dpy, pixmap);
1467 pixmap = None;
1468 }
1469
1470 if (pixmap == None)
1471 {
1472 pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth);
1473 pmap_width = result->width;
1474 pmap_height = result->height;
1475 pmap_depth = target->depth;
1476 }
1477
1478 if (pmap_depth != result->depth)
1479 {
1480 /* Bad Match error will ensue ! stupid X !!!! */
1481 if (result->depth == 24 && pmap_depth == 32)
1482 result->depth = 32;
1483 else if (result->depth == 32 && pmap_depth == 24)
1484 result->depth = 24;
1485 else
1486 {
1487 /* TODO: implement image recoding */
1488 }
1489 }
1490
1491 if (pmap_depth == result->depth)
1492 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); 1466 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1493 1467
1494 XFreeGC (target->dpy, gc); 1468 XFreeGC (target->dpy, gc);
1495 flags = flags & ~isInvalid; 1469 flags = flags & ~isInvalid;
1496 } 1470 }
1497 1471
1498 XDestroyImage (result); 1472 XDestroyImage (result);
1499 } 1473 }
1474# endif
1500 1475
1501 if (flags & isInvalid) 1476 if (flags & isInvalid)
1502 { 1477 {
1503 if (pixmap != None) 1478 if (pixmap != None)
1504 { 1479 {
1512 valid_since = ev::now (); 1487 valid_since = ev::now ();
1513 1488
1514 return true; 1489 return true;
1515} 1490}
1516 1491
1517bool 1492void
1518bgPixmap_t::set_target (rxvt_term *new_target) 1493bgPixmap_t::set_target (rxvt_term *new_target)
1519{ 1494{
1520 if (new_target)
1521 if (target != new_target)
1522 {
1523 target = new_target; 1495 target = new_target;
1524# ifdef ENABLE_TRANSPARENCY 1496
1525 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); 1497 flags &= ~(HAS_RENDER | HAS_RENDER_CONV);
1498#if XRENDER
1499 int major, minor;
1500 if (XRenderQueryVersion (target->dpy, &major, &minor))
1501 flags |= HAS_RENDER;
1502 XFilters *filters = XRenderQueryFilters (target->dpy, target->vt);
1503 if (filters)
1504 {
1505 for (int i = 0; i < filters->nfilter; i++)
1506 if (!strcmp (filters->filter[i], FilterConvolution))
1507 flags |= HAS_RENDER_CONV;
1508
1509 XFree (filters);
1510 }
1526# endif 1511#endif
1527 return true;
1528 }
1529
1530 return false;
1531} 1512}
1532 1513
1533void 1514void
1534bgPixmap_t::apply () 1515bgPixmap_t::apply ()
1535{ 1516{
1536 if (target) 1517 if (target == NULL)
1537 { 1518 return;
1519
1538 if (pixmap != None) 1520 if (pixmap != None)
1539 { 1521 {
1540 /* set target's background to pixmap */ 1522 /* set target's background to pixmap */
1541# ifdef ENABLE_TRANSPARENCY 1523# ifdef ENABLE_TRANSPARENCY
1542 if (flags & isTransparent) 1524 if (flags & isTransparent)
1543 { 1525 {
1544 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); 1526 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
1545 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); 1527 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1546 1528
1547 if (target->scrollBar.win) 1529 if (target->scrollBar.win)
1548 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); 1530 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
1549 } 1531 }
1550 else 1532 else
1551# endif 1533# endif
1552 { 1534 {
1553 /* force old pixmap dereference in case it was transparent before :*/ 1535 /* force old pixmap dereference in case it was transparent before :*/
1554 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1555 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1556 /* do we also need to set scrollbar's background here ? */
1557
1558 if (target->scrollBar.win)
1559 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1560 }
1561 }
1562 else
1563 {
1564 /* set target background to a pixel */
1565 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1536 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1566 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); 1537 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1567 /* do we also need to set scrollbar's background here ? */ 1538 /* do we also need to set scrollbar's background here ? */
1539
1568 if (target->scrollBar.win) 1540 if (target->scrollBar.win)
1569 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1541 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1570 } 1542 }
1543 }
1544 else
1545 {
1546 /* set target background to a pixel */
1547 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1548 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
1549 /* do we also need to set scrollbar's background here ? */
1550 if (target->scrollBar.win)
1551 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1552 }
1571 1553
1572 /* don't want Expose on the parent or vt. It is better to use 1554 /* don't want Expose on the parent or vt. It is better to use
1573 scr_touch or we get a great deal of flicker otherwise: */ 1555 scr_touch or we get a great deal of flicker otherwise: */
1574 XClearWindow (target->dpy, target->parent[0]); 1556 XClearWindow (target->dpy, target->parent[0]);
1575 1557
1576 if (target->scrollBar.state && target->scrollBar.win) 1558 if (target->scrollBar.state && target->scrollBar.win)
1577 { 1559 {
1578 target->scrollBar.state = STATE_IDLE; 1560 target->scrollBar.state = STATE_IDLE;
1579 target->scrollBar.show (0); 1561 target->scrollBar.show (0);
1580 } 1562 }
1581 1563
1582 target->want_refresh = 1; 1564 target->want_refresh = 1;
1583 flags |= hasChanged; 1565 flags |= hasChanged;
1584 }
1585} 1566}
1586 1567
1587#endif /* HAVE_BG_PIXMAP */ 1568#endif /* HAVE_BG_PIXMAP */
1588 1569
1589#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT 1570#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1590/* taken from aterm-0.4.2 */ 1571/* taken from aterm-0.4.2 */
1591 1572
1592static void 1573static void
1593ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm) 1574ShadeXImage(Visual *visual, XImage *srcImage, int shade, const rgba &c)
1594{ 1575{
1595 int sh_r, sh_g, sh_b; 1576 int sh_r, sh_g, sh_b;
1596 uint32_t mask_r, mask_g, mask_b; 1577 uint32_t mask_r, mask_g, mask_b;
1597 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1578 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1598 unsigned int lower_lim_r, lower_lim_g, lower_lim_b; 1579 rgba low;
1599 unsigned int upper_lim_r, upper_lim_g, upper_lim_b; 1580 rgba high;
1600 int i; 1581 int i;
1601 int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst; 1582 int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst;
1602 1583
1603 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return; 1584 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return;
1604 1585
1669 /* prepare limits for color transformation (each channel is handled separately) */ 1650 /* prepare limits for color transformation (each channel is handled separately) */
1670 if (shade > 100) 1651 if (shade > 100)
1671 { 1652 {
1672 shade = 200 - shade; 1653 shade = 200 - shade;
1673 1654
1674 lower_lim_r = 65535-rm; 1655 high.r = (65535 - c.r) * shade / 100;
1675 lower_lim_g = 65535-gm; 1656 high.g = (65535 - c.g) * shade / 100;
1676 lower_lim_b = 65535-bm; 1657 high.b = (65535 - c.b) * shade / 100;
1677 1658
1678 lower_lim_r = 65535-(unsigned int)(((uint32_t)lower_lim_r)*((uint32_t)shade)/100); 1659 low.r = 65535 - high.r;
1679 lower_lim_g = 65535-(unsigned int)(((uint32_t)lower_lim_g)*((uint32_t)shade)/100); 1660 low.g = 65535 - high.g;
1680 lower_lim_b = 65535-(unsigned int)(((uint32_t)lower_lim_b)*((uint32_t)shade)/100); 1661 low.b = 65535 - high.b;
1681
1682 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
1683 } 1662 }
1684 else 1663 else
1685 { 1664 {
1665 high.r = c.r * shade / 100;
1666 high.g = c.g * shade / 100;
1667 high.b = c.b * shade / 100;
1686 1668
1687 lower_lim_r = lower_lim_g = lower_lim_b = 0; 1669 low.r = low.g = low.b = 0;
1688
1689 upper_lim_r = (unsigned int)((((uint32_t)rm)*((uint32_t)shade))/100);
1690 upper_lim_g = (unsigned int)((((uint32_t)gm)*((uint32_t)shade))/100);
1691 upper_lim_b = (unsigned int)((((uint32_t)bm)*((uint32_t)shade))/100);
1692 } 1670 }
1693 1671
1694 /* fill our lookup tables */ 1672 /* fill our lookup tables */
1695 for (i = 0; i <= mask_r>>sh_r; i++) 1673 for (i = 0; i <= mask_r>>sh_r; i++)
1696 { 1674 {
1697 uint32_t tmp; 1675 uint32_t tmp;
1698 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_r-lower_lim_r)); 1676 tmp = i * high.r;
1699 tmp += ((uint32_t)(mask_r>>sh_r))*((uint32_t)lower_lim_r); 1677 tmp += (mask_r>>sh_r) * low.r;
1700 lookup_r[i] = (tmp/65535)<<sh_r; 1678 lookup_r[i] = (tmp/65535)<<sh_r;
1701 } 1679 }
1702 for (i = 0; i <= mask_g>>sh_g; i++) 1680 for (i = 0; i <= mask_g>>sh_g; i++)
1703 { 1681 {
1704 uint32_t tmp; 1682 uint32_t tmp;
1705 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_g-lower_lim_g)); 1683 tmp = i * high.g;
1706 tmp += ((uint32_t)(mask_g>>sh_g))*((uint32_t)lower_lim_g); 1684 tmp += (mask_g>>sh_g) * low.g;
1707 lookup_g[i] = (tmp/65535)<<sh_g; 1685 lookup_g[i] = (tmp/65535)<<sh_g;
1708 } 1686 }
1709 for (i = 0; i <= mask_b>>sh_b; i++) 1687 for (i = 0; i <= mask_b>>sh_b; i++)
1710 { 1688 {
1711 uint32_t tmp; 1689 uint32_t tmp;
1712 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_b-lower_lim_b)); 1690 tmp = i * high.b;
1713 tmp += ((uint32_t)(mask_b>>sh_b))*((uint32_t)lower_lim_b); 1691 tmp += (mask_b>>sh_b) * low.b;
1714 lookup_b[i] = (tmp/65535)<<sh_b; 1692 lookup_b[i] = (tmp/65535)<<sh_b;
1715 } 1693 }
1716 1694
1717 /* apply table to input image (replacing colors by newly calculated ones) */ 1695 /* apply table to input image (replacing colors by newly calculated ones) */
1718 if (srcImage->bits_per_pixel == 32 1696 if (srcImage->bits_per_pixel == 32

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines