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.113 by sf-exg, Sat Nov 6 17:51:11 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
28 32
29#define DO_TIMING_TEST 0 33#define DO_TIMING_TEST 0
30 34
31#if DO_TIMING_TEST 35#if DO_TIMING_TEST
32# include <sys/time.h> 36# include <sys/time.h>
250} 254}
251 255
252bool 256bool
253bgPixmap_t::set_geometry (const char *geom) 257bgPixmap_t::set_geometry (const char *geom)
254{ 258{
259 bool changed = false;
255 int geom_flags = 0, changed = 0; 260 int geom_flags = 0;
256 int x = 0, y = 0; 261 int x = 0, y = 0;
257 unsigned int w = 0, h = 0; 262 unsigned int w = 0, h = 0;
258 unsigned int n; 263 unsigned int n;
259 unsigned long new_flags = (flags & (~geometryFlags)); 264 unsigned long new_flags = (flags & (~geometryFlags));
260 const char *p; 265 const char *p;
416 421
417 while (*ops != ':' && *ops != '\0') ++ops; 422 while (*ops != ':' && *ops != '\0') ++ops;
418 } /* done parsing ops */ 423 } /* done parsing ops */
419 } 424 }
420 425
421 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) ++changed; 426 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; 427 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; 428 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; 429 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true;
425 } 430 }
426 431
427 if (new_flags != flags) 432 if (new_flags != flags)
428 { 433 {
429 flags = new_flags; 434 flags = new_flags;
430 changed++; 435 changed = true;
431 } 436 }
432 437
433 return (changed > 0); 438 return changed;
434} 439}
435 440
436void 441void
437bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) 442bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y)
438{ 443{
729 return false; 734 return false;
730 735
731 if (!pixbuf) 736 if (!pixbuf)
732 return false; 737 return false;
733 738
734#if !XFT
735 if (background_flags) 739 if (background_flags
740 && !(flags & HAS_RENDER))
736 return false; 741 return false;
737#endif
738 742
739 GdkPixbuf *result; 743 GdkPixbuf *result;
740 744
741 int image_width = gdk_pixbuf_get_width (pixbuf); 745 int image_width = gdk_pixbuf_get_width (pixbuf);
742 int image_height = gdk_pixbuf_get_height (pixbuf); 746 int image_height = gdk_pixbuf_get_height (pixbuf);
856 dst_width, dst_height, 860 dst_width, dst_height,
857 XLIB_RGB_DITHER_NONE, 861 XLIB_RGB_DITHER_NONE,
858 0, 0); 862 0, 0);
859 } 863 }
860 864
861#if XFT 865#if XRENDER
862 if (background_flags) 866 if (background_flags)
863 { 867 {
864 Display *dpy = target->dpy; 868 Display *dpy = target->dpy;
865 XRenderPictureAttributes pa; 869 XRenderPictureAttributes pa;
866 870
867 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, target->display->screen)); 871 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, target->visual);
868 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); 872 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa);
869 873
870 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); 874 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual);
871 Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa); 875 Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa);
872 876
909# endif /* HAVE_PIXBUF */ 913# endif /* HAVE_PIXBUF */
910 914
911bool 915bool
912bgPixmap_t::set_file (const char *file) 916bgPixmap_t::set_file (const char *file)
913{ 917{
914 assert (file); 918 if (!file || !*file)
919 return false;
915 920
916 if (*file)
917 {
918 if (const char *p = strchr (file, ';')) 921 if (const char *p = strchr (file, ';'))
919 { 922 {
920 size_t len = p - file; 923 size_t len = p - file;
921 char *f = rxvt_temp_buf<char> (len + 1); 924 char *f = rxvt_temp_buf<char> (len + 1);
922 memcpy (f, file, len); 925 memcpy (f, file, len);
923 f[len] = '\0'; 926 f[len] = '\0';
924 file = f; 927 file = f;
925 } 928 }
926 929
927# ifdef HAVE_AFTERIMAGE 930# ifdef HAVE_AFTERIMAGE
928 if (!target->asimman) 931 if (!target->asimman)
929 target->asimman = create_generic_imageman (target->rs[Rs_path]); 932 target->asimman = create_generic_imageman (target->rs[Rs_path]);
930 ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); 933 ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
931 if (image) 934 if (image)
932 { 935 {
933 if (original_asim) 936 if (original_asim)
934 safe_asimage_destroy (original_asim); 937 safe_asimage_destroy (original_asim);
935 original_asim = image; 938 original_asim = image;
936 have_image = true; 939 have_image = true;
937 return true; 940 return true;
938 } 941 }
939# endif 942# endif
940 943
941# ifdef HAVE_PIXBUF 944# ifdef HAVE_PIXBUF
942 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); 945 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL);
943 if (image) 946 if (image)
944 { 947 {
945 if (pixbuf) 948 if (pixbuf)
946 g_object_unref (pixbuf); 949 g_object_unref (pixbuf);
947 pixbuf = image; 950 pixbuf = image;
948 have_image = true; 951 have_image = true;
949 return true; 952 return true;
950 } 953 }
951# endif 954# endif
952 }
953 955
954 return false; 956 return false;
955} 957}
956 958
957# endif /* BG_IMAGE_FROM_FILE */ 959# endif /* BG_IMAGE_FROM_FILE */
970} 972}
971 973
972bool 974bool
973bgPixmap_t::set_blur_radius (const char *geom) 975bgPixmap_t::set_blur_radius (const char *geom)
974{ 976{
975 int changed = 0; 977 bool changed = false;
976 unsigned int hr, vr; 978 unsigned int hr, vr;
977 int junk; 979 int junk;
978 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); 980 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
979 981
980 if (!(geom_flags & WidthValue)) 982 if (!(geom_flags & WidthValue))
985 min_it (hr, 128); 987 min_it (hr, 128);
986 min_it (vr, 128); 988 min_it (vr, 128);
987 989
988 if (h_blurRadius != hr) 990 if (h_blurRadius != hr)
989 { 991 {
990 ++changed; 992 changed = true;
991 h_blurRadius = hr; 993 h_blurRadius = hr;
992 } 994 }
993 995
994 if (v_blurRadius != vr) 996 if (v_blurRadius != vr)
995 { 997 {
996 ++changed; 998 changed = true;
997 v_blurRadius = vr; 999 v_blurRadius = vr;
998 } 1000 }
999 1001
1000 if (v_blurRadius == 0 && h_blurRadius == 0) 1002 if (v_blurRadius == 0 && h_blurRadius == 0)
1001 flags &= ~blurNeeded; 1003 flags &= ~blurNeeded;
1002 else 1004 else
1003 flags |= blurNeeded; 1005 flags |= blurNeeded;
1004 1006
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); 1007 return changed;
1018} 1008}
1019 1009
1020static inline unsigned long 1010static inline unsigned long
1021compute_tint_shade_flags (rxvt_color *tint, int shade) 1011compute_tint_shade_flags (rxvt_color *tint, int shade)
1022{ 1012{
1044 { 1034 {
1045 flags |= bgPixmap_t::tintNeeded; 1035 flags |= bgPixmap_t::tintNeeded;
1046 } 1036 }
1047 } 1037 }
1048 1038
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; 1039 return flags;
1062} 1040}
1063 1041
1064bool 1042bool
1065bgPixmap_t::set_tint (rxvt_color &new_tint) 1043bgPixmap_t::set_tint (rxvt_color &new_tint)
1107 } 1085 }
1108 1086
1109 return false; 1087 return false;
1110} 1088}
1111 1089
1112#if XFT 1090#if XRENDER
1113static void 1091static void
1114get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) 1092get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params)
1115{ 1093{
1116 double sigma = radius / 2.0; 1094 double sigma = radius / 2.0;
1117 double scale = sqrt (2.0 * M_PI) * sigma; 1095 double scale = sqrt (2.0 * M_PI) * sigma;
1134 1112
1135bool 1113bool
1136bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) 1114bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height)
1137{ 1115{
1138 bool ret = false; 1116 bool ret = false;
1139#if XFT 1117#if XRENDER
1140 int size = max (h_blurRadius, v_blurRadius) * 2 + 1; 1118 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
1141 double *kernel = (double *)malloc (size * sizeof (double)); 1119 double *kernel = (double *)malloc (size * sizeof (double));
1142 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 1120 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
1143 1121
1144 Display *dpy = target->dpy; 1122 Display *dpy = target->dpy;
1221 XFreeGC (dpy, gc); 1199 XFreeGC (dpy, gc);
1222 } 1200 }
1223 } 1201 }
1224 else 1202 else
1225 { 1203 {
1226# if XFT 1204# if XRENDER
1227 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1205 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1228 1206
1229 if (flags & tintSet) 1207 if (flags & tintSet)
1230 tint.get (c); 1208 tint.get (c);
1231 1209
1284 1262
1285 return ret; 1263 return ret;
1286} 1264}
1287 1265
1288/* make_transparency_pixmap() 1266/* make_transparency_pixmap()
1289 * Builds a pixmap sized the same as terminal window, with depth same as the root window 1267 * 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 1268 * the tiled portion of the root pixmap that is supposed to be covered by
1291 * our window. 1269 * our window.
1292 */ 1270 */
1293unsigned long 1271unsigned long
1294bgPixmap_t::make_transparency_pixmap () 1272bgPixmap_t::make_transparency_pixmap ()
1295{ 1273{
1299 return 0; 1277 return 0;
1300 1278
1301 /* root dimensions may change from call to call - but Display structure should 1279 /* root dimensions may change from call to call - but Display structure should
1302 * be always up-to-date, so let's use it : 1280 * be always up-to-date, so let's use it :
1303 */ 1281 */
1304 Window root = target->display->root;
1305 int screen = target->display->screen; 1282 int screen = target->display->screen;
1306 Display *dpy = target->dpy; 1283 Display *dpy = target->dpy;
1284 int root_depth = DefaultDepth (dpy, screen);
1307 int root_width = DisplayWidth (dpy, screen); 1285 int root_width = DisplayWidth (dpy, screen);
1308 int root_height = DisplayHeight (dpy, screen); 1286 int root_height = DisplayHeight (dpy, screen);
1287 unsigned int root_pmap_width, root_pmap_height;
1309 int window_width = target->szHint.width; 1288 int window_width = target->szHint.width;
1310 int window_height = target->szHint.height; 1289 int window_height = target->szHint.height;
1311 int sx, sy; 1290 int sx, sy;
1312 XGCValues gcv; 1291 XGCValues gcv;
1313 GC gc; 1292 GC gc;
1317 /* check if we are outside of the visible part of the virtual screen : */ 1296 /* check if we are outside of the visible part of the virtual screen : */
1318 if (sx + window_width <= 0 || sy + window_height <= 0 1297 if (sx + window_width <= 0 || sy + window_height <= 0
1319 || sx >= root_width || sy >= root_height) 1298 || sx >= root_width || sy >= root_height)
1320 return 0; 1299 return 0;
1321 1300
1301 // validate root pixmap and get its size
1302 if (root_pixmap != None)
1303 {
1304 Window wdummy;
1305 int idummy;
1306 unsigned int udummy;
1307
1308 target->allowedxerror = -1;
1309
1310 if (!XGetGeometry (dpy, root_pixmap, &wdummy, &idummy, &idummy, &root_pmap_width, &root_pmap_height, &udummy, &udummy))
1311 root_pixmap = None;
1312
1313 target->allowedxerror = 0;
1314 }
1315
1316 Pixmap recoded_root_pmap = root_pixmap;
1317
1318 if (root_pixmap != None && root_depth != target->depth)
1319 {
1320#if XRENDER
1321 if (flags & HAS_RENDER)
1322 {
1323 XRenderPictureAttributes pa;
1324
1325 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
1326 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa);
1327
1328 recoded_root_pmap = XCreatePixmap (dpy, target->vt, root_pmap_width, root_pmap_height, target->depth);
1329 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual);
1330 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa);
1331
1332 if (src && dst)
1333 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height);
1334 else
1335 {
1336 XFreePixmap (dpy, recoded_root_pmap);
1337 root_pixmap = None;
1338 }
1339
1340 XRenderFreePicture (dpy, src);
1341 XRenderFreePicture (dpy, dst);
1342 }
1343 else
1344#endif
1345 root_pixmap = None;
1346 }
1347
1322 if (root_pixmap == None) 1348 if (root_pixmap == None)
1323 return 0; 1349 return 0;
1324 1350
1325 Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth); 1351 Pixmap tiled_root_pmap = XCreatePixmap (dpy, target->vt, window_width, window_height, target->depth);
1326 1352
1327 if (tiled_root_pmap == None) /* something really bad happened - abort */ 1353 if (tiled_root_pmap == None) /* something really bad happened - abort */
1328 return 0; 1354 return 0;
1329 1355
1330 /* straightforward pixmap copy */ 1356 /* straightforward pixmap copy */
1331 gcv.tile = root_pixmap; 1357 gcv.tile = recoded_root_pmap;
1332 gcv.fill_style = FillTiled; 1358 gcv.fill_style = FillTiled;
1333 1359
1334 while (sx < 0) sx += (int)root_width; 1360 while (sx < 0) sx += (int)root_width;
1335 while (sy < 0) sy += (int)root_height; 1361 while (sy < 0) sy += (int)root_height;
1336 1362
1337 gcv.ts_x_origin = -sx; 1363 gcv.ts_x_origin = -sx;
1338 gcv.ts_y_origin = -sy; 1364 gcv.ts_y_origin = -sy;
1339 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 1365 gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
1340 1366
1341 if (gc) 1367 if (gc)
1342 { 1368 {
1343 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); 1369 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
1344 result |= transpPmapTiled; 1370 result |= transpPmapTiled;
1347 1373
1348 if (tiled_root_pmap != None) 1374 if (tiled_root_pmap != None)
1349 { 1375 {
1350 if (!need_client_side_rendering ()) 1376 if (!need_client_side_rendering ())
1351 { 1377 {
1352 if (flags & (blurNeeded | blurServerSide)) 1378 if ((flags & blurNeeded)
1379 && (flags & HAS_RENDER_CONV))
1353 { 1380 {
1354 if (blur_pixmap (tiled_root_pmap, DefaultVisual (dpy, screen), window_width, window_height)) 1381 if (blur_pixmap (tiled_root_pmap, target->visual, window_width, window_height))
1355 result |= transpPmapBlurred; 1382 result |= transpPmapBlurred;
1356 } 1383 }
1357 if (flags & (tintNeeded | tintServerSide)) 1384 if ((flags & tintNeeded)
1385 && (flags & (tintWholesome | HAS_RENDER)))
1358 { 1386 {
1359 if (tint_pixmap (tiled_root_pmap, DefaultVisual (dpy, screen), window_width, window_height)) 1387 if (tint_pixmap (tiled_root_pmap, target->visual, window_width, window_height))
1360 result |= transpPmapTinted; 1388 result |= transpPmapTinted;
1361 } 1389 }
1362 } /* server side rendering completed */ 1390 } /* server side rendering completed */
1363 1391
1364 if (pixmap) 1392 if (pixmap)
1365 XFreePixmap (dpy, pixmap); 1393 XFreePixmap (dpy, pixmap);
1366 1394
1367 pixmap = tiled_root_pmap; 1395 pixmap = tiled_root_pmap;
1368 pmap_width = window_width; 1396 pmap_width = window_width;
1369 pmap_height = window_height; 1397 pmap_height = window_height;
1370 pmap_depth = root_depth; 1398 pmap_depth = target->depth;
1371 } 1399 }
1400
1401 if (recoded_root_pmap != root_pixmap)
1402 XFreePixmap (dpy, recoded_root_pmap);
1372 1403
1373 return result; 1404 return result;
1374} 1405}
1375 1406
1376void 1407void
1379 Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); 1410 Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID);
1380 if (new_root_pixmap == None) 1411 if (new_root_pixmap == None)
1381 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); 1412 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID);
1382 1413
1383 root_pixmap = new_root_pixmap; 1414 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} 1415}
1401# endif /* ENABLE_TRANSPARENCY */ 1416# endif /* ENABLE_TRANSPARENCY */
1402 1417
1403# ifndef HAVE_AFTERIMAGE 1418#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1404static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm); 1419static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, const rgba &c);
1405# endif 1420# endif
1406 1421
1407bool 1422bool
1408bgPixmap_t::render () 1423bgPixmap_t::render ()
1409{ 1424{
1418 { 1433 {
1419 /* we need to re-generate transparency pixmap in that case ! */ 1434 /* we need to re-generate transparency pixmap in that case ! */
1420 background_flags = make_transparency_pixmap (); 1435 background_flags = make_transparency_pixmap ();
1421 if (background_flags == 0) 1436 if (background_flags == 0)
1422 return false; 1437 return false;
1423 else if ((background_flags & transpTransformations) == (flags & transpTransformations) 1438 else if ((background_flags & transpTransformations) == (flags & transpTransformations))
1424 && pmap_depth == target->depth)
1425 flags = flags & ~isInvalid; 1439 flags = flags & ~isInvalid;
1426 } 1440 }
1427# endif 1441# endif
1428 1442
1429# ifdef BG_IMAGE_FROM_FILE 1443# ifdef BG_IMAGE_FROM_FILE
1433 if (render_image (background_flags)) 1447 if (render_image (background_flags))
1434 flags = flags & ~isInvalid; 1448 flags = flags & ~isInvalid;
1435 } 1449 }
1436# endif 1450# endif
1437 1451
1452# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1438 XImage *result = NULL; 1453 XImage *result = NULL;
1439 1454
1440 if (background_flags && (flags & isInvalid)) 1455 if (background_flags && (flags & isInvalid))
1441 { 1456 {
1442 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1457 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1443 } 1458 }
1444 1459
1445 if (result) 1460 if (result)
1446 { 1461 {
1447# if !defined(HAVE_AFTERIMAGE) && !XFT
1448 /* our own client-side tinting */ 1462 /* 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)) 1463 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
1452 { 1464 {
1453 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1465 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1454 if (flags & tintSet) 1466 if (flags & tintSet)
1455 tint.get (c); 1467 tint.get (c);
1456 ShadeXImage (DefaultVisual (target->dpy, target->display->screen), result, shade, c.r, c.g, c.b); 1468 ShadeXImage (DefaultVisual (target->dpy, target->display->screen), result, shade, c);
1457 } 1469 }
1458# endif
1459 1470
1460 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1471 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1461 1472
1462 if (gc) 1473 if (gc)
1463 { 1474 {
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); 1475 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1493 1476
1494 XFreeGC (target->dpy, gc); 1477 XFreeGC (target->dpy, gc);
1495 flags = flags & ~isInvalid; 1478 flags = flags & ~isInvalid;
1496 } 1479 }
1497 1480
1498 XDestroyImage (result); 1481 XDestroyImage (result);
1499 } 1482 }
1483# endif
1500 1484
1501 if (flags & isInvalid) 1485 if (flags & isInvalid)
1502 { 1486 {
1503 if (pixmap != None) 1487 if (pixmap != None)
1504 { 1488 {
1512 valid_since = ev::now (); 1496 valid_since = ev::now ();
1513 1497
1514 return true; 1498 return true;
1515} 1499}
1516 1500
1517bool 1501void
1518bgPixmap_t::set_target (rxvt_term *new_target) 1502bgPixmap_t::set_target (rxvt_term *new_target)
1519{ 1503{
1520 if (new_target)
1521 if (target != new_target)
1522 {
1523 target = new_target; 1504 target = new_target;
1524# ifdef ENABLE_TRANSPARENCY 1505
1525 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); 1506 flags &= ~(HAS_RENDER | HAS_RENDER_CONV);
1507#if XRENDER
1508 int major, minor;
1509 if (XRenderQueryVersion (target->dpy, &major, &minor))
1510 flags |= HAS_RENDER;
1511 XFilters *filters = XRenderQueryFilters (target->dpy, target->vt);
1512 if (filters)
1513 {
1514 for (int i = 0; i < filters->nfilter; i++)
1515 if (!strcmp (filters->filter[i], FilterConvolution))
1516 flags |= HAS_RENDER_CONV;
1517
1518 XFree (filters);
1519 }
1526# endif 1520#endif
1527 return true;
1528 }
1529
1530 return false;
1531} 1521}
1532 1522
1533void 1523void
1534bgPixmap_t::apply () 1524bgPixmap_t::apply ()
1535{ 1525{
1536 if (target) 1526 if (target == NULL)
1537 { 1527 return;
1528
1538 if (pixmap != None) 1529 if (pixmap != None)
1539 { 1530 {
1540 /* set target's background to pixmap */ 1531 /* set target's background to pixmap */
1541# ifdef ENABLE_TRANSPARENCY 1532# ifdef ENABLE_TRANSPARENCY
1542 if (flags & isTransparent) 1533 if (flags & isTransparent)
1543 { 1534 {
1544 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); 1535 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
1545 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); 1536 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1546 1537
1547 if (target->scrollBar.win) 1538 if (target->scrollBar.win)
1548 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); 1539 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
1549 } 1540 }
1550 else 1541 else
1551# endif 1542# endif
1552 { 1543 {
1553 /* force old pixmap dereference in case it was transparent before :*/ 1544 /* 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]); 1545 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1566 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); 1546 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1567 /* do we also need to set scrollbar's background here ? */ 1547 /* do we also need to set scrollbar's background here ? */
1548
1568 if (target->scrollBar.win) 1549 if (target->scrollBar.win)
1569 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1550 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1570 } 1551 }
1552 }
1553 else
1554 {
1555 /* set target background to a pixel */
1556 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1557 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
1558 /* do we also need to set scrollbar's background here ? */
1559 if (target->scrollBar.win)
1560 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1561 }
1571 1562
1572 /* don't want Expose on the parent or vt. It is better to use 1563 /* 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: */ 1564 scr_touch or we get a great deal of flicker otherwise: */
1574 XClearWindow (target->dpy, target->parent[0]); 1565 XClearWindow (target->dpy, target->parent[0]);
1575 1566
1576 if (target->scrollBar.state && target->scrollBar.win) 1567 if (target->scrollBar.state && target->scrollBar.win)
1577 { 1568 {
1578 target->scrollBar.state = STATE_IDLE; 1569 target->scrollBar.state = STATE_IDLE;
1579 target->scrollBar.show (0); 1570 target->scrollBar.show (0);
1580 } 1571 }
1581 1572
1582 target->want_refresh = 1; 1573 target->want_refresh = 1;
1583 flags |= hasChanged; 1574 flags |= hasChanged;
1584 }
1585} 1575}
1586 1576
1587#endif /* HAVE_BG_PIXMAP */ 1577#endif /* HAVE_BG_PIXMAP */
1588 1578
1589#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT 1579#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1590/* taken from aterm-0.4.2 */ 1580/* taken from aterm-0.4.2 */
1591 1581
1592static void 1582static void
1593ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm) 1583ShadeXImage(Visual *visual, XImage *srcImage, int shade, const rgba &c)
1594{ 1584{
1595 int sh_r, sh_g, sh_b; 1585 int sh_r, sh_g, sh_b;
1596 uint32_t mask_r, mask_g, mask_b; 1586 uint32_t mask_r, mask_g, mask_b;
1597 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1587 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1598 unsigned int lower_lim_r, lower_lim_g, lower_lim_b; 1588 rgba low;
1599 unsigned int upper_lim_r, upper_lim_g, upper_lim_b; 1589 rgba high;
1600 int i; 1590 int i;
1601 int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst; 1591 int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst;
1602 1592
1603 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return; 1593 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return;
1604 1594
1669 /* prepare limits for color transformation (each channel is handled separately) */ 1659 /* prepare limits for color transformation (each channel is handled separately) */
1670 if (shade > 100) 1660 if (shade > 100)
1671 { 1661 {
1672 shade = 200 - shade; 1662 shade = 200 - shade;
1673 1663
1674 lower_lim_r = 65535-rm; 1664 high.r = (65535 - c.r) * shade / 100;
1675 lower_lim_g = 65535-gm; 1665 high.g = (65535 - c.g) * shade / 100;
1676 lower_lim_b = 65535-bm; 1666 high.b = (65535 - c.b) * shade / 100;
1677 1667
1678 lower_lim_r = 65535-(unsigned int)(((uint32_t)lower_lim_r)*((uint32_t)shade)/100); 1668 low.r = 65535 - high.r;
1679 lower_lim_g = 65535-(unsigned int)(((uint32_t)lower_lim_g)*((uint32_t)shade)/100); 1669 low.g = 65535 - high.g;
1680 lower_lim_b = 65535-(unsigned int)(((uint32_t)lower_lim_b)*((uint32_t)shade)/100); 1670 low.b = 65535 - high.b;
1681
1682 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
1683 } 1671 }
1684 else 1672 else
1685 { 1673 {
1674 high.r = c.r * shade / 100;
1675 high.g = c.g * shade / 100;
1676 high.b = c.b * shade / 100;
1686 1677
1687 lower_lim_r = lower_lim_g = lower_lim_b = 0; 1678 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 } 1679 }
1693 1680
1694 /* fill our lookup tables */ 1681 /* fill our lookup tables */
1695 for (i = 0; i <= mask_r>>sh_r; i++) 1682 for (i = 0; i <= mask_r>>sh_r; i++)
1696 { 1683 {
1697 uint32_t tmp; 1684 uint32_t tmp;
1698 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_r-lower_lim_r)); 1685 tmp = i * high.r;
1699 tmp += ((uint32_t)(mask_r>>sh_r))*((uint32_t)lower_lim_r); 1686 tmp += (mask_r>>sh_r) * low.r;
1700 lookup_r[i] = (tmp/65535)<<sh_r; 1687 lookup_r[i] = (tmp/65535)<<sh_r;
1701 } 1688 }
1702 for (i = 0; i <= mask_g>>sh_g; i++) 1689 for (i = 0; i <= mask_g>>sh_g; i++)
1703 { 1690 {
1704 uint32_t tmp; 1691 uint32_t tmp;
1705 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_g-lower_lim_g)); 1692 tmp = i * high.g;
1706 tmp += ((uint32_t)(mask_g>>sh_g))*((uint32_t)lower_lim_g); 1693 tmp += (mask_g>>sh_g) * low.g;
1707 lookup_g[i] = (tmp/65535)<<sh_g; 1694 lookup_g[i] = (tmp/65535)<<sh_g;
1708 } 1695 }
1709 for (i = 0; i <= mask_b>>sh_b; i++) 1696 for (i = 0; i <= mask_b>>sh_b; i++)
1710 { 1697 {
1711 uint32_t tmp; 1698 uint32_t tmp;
1712 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_b-lower_lim_b)); 1699 tmp = i * high.b;
1713 tmp += ((uint32_t)(mask_b>>sh_b))*((uint32_t)lower_lim_b); 1700 tmp += (mask_b>>sh_b) * low.b;
1714 lookup_b[i] = (tmp/65535)<<sh_b; 1701 lookup_b[i] = (tmp/65535)<<sh_b;
1715 } 1702 }
1716 1703
1717 /* apply table to input image (replacing colors by newly calculated ones) */ 1704 /* apply table to input image (replacing colors by newly calculated ones) */
1718 if (srcImage->bits_per_pixel == 32 1705 if (srcImage->bits_per_pixel == 32

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines