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.191 by sf-exg, Fri Dec 30 11:22:48 2011 UTC vs.
Revision 1.196 by sf-exg, Tue Jan 10 18:50:14 2012 UTC

32 32
33#ifndef FilterConvolution 33#ifndef FilterConvolution
34#define FilterConvolution "convolution" 34#define FilterConvolution "convolution"
35#endif 35#endif
36 36
37#ifndef RepeatPad
38#define RepeatPad True
39#endif
40
37#ifdef HAVE_BG_PIXMAP 41#ifdef HAVE_BG_PIXMAP
38# if XRENDER 42# if XRENDER
39static Picture 43static Picture
40create_xrender_mask (Display *dpy, Drawable drawable, Bool argb, Bool component_alpha) 44create_xrender_mask (Display *dpy, Drawable drawable, Bool argb, Bool component_alpha)
41{ 45{
392 if (tr_flags & BG_NEEDS_TINT) 396 if (tr_flags & BG_NEEDS_TINT)
393 { 397 {
394 ShadingInfo as_shade; 398 ShadingInfo as_shade;
395 as_shade.shading = shade; 399 as_shade.shading = shade;
396 400
397 rgba c; 401 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
402 if (bg_flags & BG_TINT_SET)
398 tint.get (c); 403 tint.get (c);
399 as_shade.tintColor.red = c.r; 404 as_shade.tintColor.red = c.r;
400 as_shade.tintColor.green = c.g; 405 as_shade.tintColor.green = c.g;
401 as_shade.tintColor.blue = c.b; 406 as_shade.tintColor.blue = c.b;
402 407
403 background_tint = shading2tint32 (&as_shade); 408 background_tint = shading2tint32 (&as_shade);
830 Picture mask = create_xrender_mask (dpy, vt, False, False); 835 Picture mask = create_xrender_mask (dpy, vt, False, False);
831 836
832 XRenderColor mask_c; 837 XRenderColor mask_c;
833 838
834 mask_c.alpha = 0x8000; 839 mask_c.alpha = 0x8000;
835 mask_c.red = 0; 840 mask_c.red =
836 mask_c.green = 0; 841 mask_c.green =
837 mask_c.blue = 0; 842 mask_c.blue = 0;
838 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); 843 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1);
844
839 XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height); 845 XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height);
840 846
841 XRenderFreePicture (dpy, src); 847 XRenderFreePicture (dpy, src);
842 XRenderFreePicture (dpy, dst); 848 XRenderFreePicture (dpy, dst);
843 XRenderFreePicture (dpy, mask); 849 XRenderFreePicture (dpy, mask);
955 { 961 {
956 changed = true; 962 changed = true;
957 v_blurRadius = vr; 963 v_blurRadius = vr;
958 } 964 }
959 965
960 if (v_blurRadius == 0 && h_blurRadius == 0) 966 if (h_blurRadius == 0 || v_blurRadius == 0)
961 bg_flags &= ~BG_NEEDS_BLUR; 967 bg_flags &= ~BG_NEEDS_BLUR;
962 else 968 else
963 bg_flags |= BG_NEEDS_BLUR; 969 bg_flags |= BG_NEEDS_BLUR;
964 970
965 return changed; 971 return changed;
971 rgba c; 977 rgba c;
972 bool has_shade = shade != 100; 978 bool has_shade = shade != 100;
973 979
974 bg_flags &= ~BG_TINT_FLAGS; 980 bg_flags &= ~BG_TINT_FLAGS;
975 981
982 if (bg_flags & BG_TINT_SET)
983 {
976 tint.get (c); 984 tint.get (c);
977
978 if (!has_shade 985 if (!has_shade
979 && (c.r <= 0x00ff || c.r >= 0xff00) 986 && (c.r <= 0x00ff || c.r >= 0xff00)
980 && (c.g <= 0x00ff || c.g >= 0xff00) 987 && (c.g <= 0x00ff || c.g >= 0xff00)
981 && (c.b <= 0x00ff || c.b >= 0xff00)) 988 && (c.b <= 0x00ff || c.b >= 0xff00))
982 bg_flags |= BG_TINT_BITAND; 989 bg_flags |= BG_TINT_BITAND;
990 }
983 991
984 if (has_shade 992 if (has_shade || (bg_flags & BG_TINT_SET))
985 || c.r < 0xff00
986 || c.g < 0xff00
987 || c.b < 0xff00)
988 bg_flags |= BG_NEEDS_TINT; 993 bg_flags |= BG_NEEDS_TINT;
989} 994}
990 995
991bool 996bool
992rxvt_term::bg_set_tint (rxvt_color &new_tint) 997rxvt_term::bg_set_tint (rxvt_color &new_tint)
993{ 998{
994 if (tint != new_tint) 999 if (!(bg_flags & BG_TINT_SET) || tint != new_tint)
995 { 1000 {
996 tint = new_tint; 1001 tint = new_tint;
1002 bg_flags |= BG_TINT_SET;
997 set_tint_shade_flags (); 1003 set_tint_shade_flags ();
998 return true; 1004 return true;
999 } 1005 }
1000 1006
1001 return false; 1007 return false;
1042 params[i+2] = XDoubleToFixed (kernel[i] / sum); 1048 params[i+2] = XDoubleToFixed (kernel[i] / sum);
1043} 1049}
1044#endif 1050#endif
1045 1051
1046bool 1052bool
1047rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) 1053rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height, int depth)
1048{ 1054{
1049 bool ret = false; 1055 bool ret = false;
1050#if XRENDER 1056#if XRENDER
1051 if (!(bg_flags & BG_HAS_RENDER_CONV)) 1057 if (!(bg_flags & BG_HAS_RENDER_CONV))
1052 return false; 1058 return false;
1053 1059
1054 int size = max (h_blurRadius, v_blurRadius) * 2 + 1; 1060 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
1055 double *kernel = (double *)malloc (size * sizeof (double)); 1061 double *kernel = (double *)malloc (size * sizeof (double));
1056 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 1062 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
1057 1063
1064 XRenderPictureAttributes pa;
1058 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1065 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1059 1066
1067 pa.repeat = RepeatPad;
1060 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, 0); 1068 Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa);
1069 Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth);
1061 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, 0); 1070 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa);
1071 XFreePixmap (dpy, tmp);
1062 1072
1063 if (kernel && params) 1073 if (kernel && params)
1064 { 1074 {
1065 if (h_blurRadius)
1066 {
1067 size = h_blurRadius * 2 + 1; 1075 size = h_blurRadius * 2 + 1;
1068 get_gaussian_kernel (h_blurRadius, size, kernel, params); 1076 get_gaussian_kernel (h_blurRadius, size, kernel, params);
1069 1077
1070 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); 1078 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
1071 XRenderComposite (dpy, 1079 XRenderComposite (dpy,
1072 PictOpSrc, 1080 PictOpSrc,
1073 src, 1081 src,
1074 None, 1082 None,
1075 dst, 1083 dst,
1076 0, 0, 1084 0, 0,
1077 0, 0, 1085 0, 0,
1078 0, 0, 1086 0, 0,
1079 width, height); 1087 width, height);
1080 }
1081 1088
1082 if (v_blurRadius) 1089 ::swap (src, dst);
1083 { 1090
1084 size = v_blurRadius * 2 + 1; 1091 size = v_blurRadius * 2 + 1;
1085 get_gaussian_kernel (v_blurRadius, size, kernel, params); 1092 get_gaussian_kernel (v_blurRadius, size, kernel, params);
1086 ::swap (params[0], params[1]); 1093 ::swap (params[0], params[1]);
1087 1094
1088 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); 1095 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
1089 XRenderComposite (dpy, 1096 XRenderComposite (dpy,
1090 PictOpSrc, 1097 PictOpSrc,
1091 src, 1098 src,
1092 None, 1099 None,
1093 dst, 1100 dst,
1094 0, 0, 1101 0, 0,
1095 0, 0, 1102 0, 0,
1096 0, 0, 1103 0, 0,
1097 width, height); 1104 width, height);
1098 }
1099 1105
1100 ret = true; 1106 ret = true;
1101 } 1107 }
1102 1108
1103 free (kernel); 1109 free (kernel);
1133 } 1139 }
1134 } 1140 }
1135# if XRENDER 1141# if XRENDER
1136 else if (bg_flags & BG_HAS_RENDER) 1142 else if (bg_flags & BG_HAS_RENDER)
1137 { 1143 {
1138 rgba c; 1144 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1139 1145
1146 if (bg_flags & BG_TINT_SET)
1140 tint.get (c); 1147 tint.get (c);
1141 1148
1142 if (shade <= 100) 1149 if (shade <= 100)
1143 { 1150 {
1144 c.r = c.r * shade / 100; 1151 c.r = c.r * shade / 100;
1145 c.g = c.g * shade / 100; 1152 c.g = c.g * shade / 100;
1171 mask_c.alpha = 0; 1178 mask_c.alpha = 0;
1172 mask_c.red = 0xffff - c.r; 1179 mask_c.red = 0xffff - c.r;
1173 mask_c.green = 0xffff - c.g; 1180 mask_c.green = 0xffff - c.g;
1174 mask_c.blue = 0xffff - c.b; 1181 mask_c.blue = 0xffff - c.b;
1175 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); 1182 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1183
1176 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height); 1184 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1177 1185
1178 if (shade > 100) 1186 if (shade > 100)
1179 { 1187 {
1180 mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100;
1181 mask_c.alpha = 0; 1188 mask_c.alpha = 0;
1189 mask_c.red =
1190 mask_c.green =
1191 mask_c.blue = 0xffff * (shade - 100) / 100;
1182 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); 1192 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1183 1193
1184 XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height); 1194 XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1185 } 1195 }
1186 1196
1298 1308
1299 if (!(bg_flags & BG_CLIENT_RENDER)) 1309 if (!(bg_flags & BG_CLIENT_RENDER))
1300 { 1310 {
1301 if (bg_flags & BG_NEEDS_BLUR) 1311 if (bg_flags & BG_NEEDS_BLUR)
1302 { 1312 {
1303 if (blur_pixmap (bg_pixmap, visual, window_width, window_height)) 1313 if (blur_pixmap (bg_pixmap, visual, window_width, window_height, depth))
1304 result &= ~BG_NEEDS_BLUR; 1314 result &= ~BG_NEEDS_BLUR;
1305 } 1315 }
1306 if (bg_flags & BG_NEEDS_TINT) 1316 if (bg_flags & BG_NEEDS_TINT)
1307 { 1317 {
1308 if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) 1318 if (tint_pixmap (bg_pixmap, visual, window_width, window_height))
1389 1399
1390void 1400void
1391rxvt_term::bg_init () 1401rxvt_term::bg_init ()
1392{ 1402{
1393#ifdef ENABLE_TRANSPARENCY 1403#ifdef ENABLE_TRANSPARENCY
1394 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1395 tint.set (this, c);
1396 shade = 100; 1404 shade = 100;
1397#endif 1405#endif
1398 1406
1399 bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV); 1407 bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV);
1400#if XRENDER 1408#if XRENDER
1503 break; 1511 break;
1504 default: 1512 default:
1505 return; /* we do not support this color depth */ 1513 return; /* we do not support this color depth */
1506 } 1514 }
1507 1515
1508 rgba c; 1516 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1509 1517
1518 if (bg_flags & BG_TINT_SET)
1510 tint.get (c); 1519 tint.get (c);
1511 1520
1512 /* prepare limits for color transformation (each channel is handled separately) */ 1521 /* prepare limits for color transformation (each channel is handled separately) */
1513 if (shade > 100) 1522 if (shade > 100)
1514 { 1523 {
1515 c.r = c.r * (200 - shade) / 100; 1524 c.r = c.r * (200 - shade) / 100;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines