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.189 by sf-exg, Thu Dec 29 16:45:22 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);
819 } 824 }
820 825
821#if XRENDER 826#if XRENDER
822 if (tr_flags) 827 if (tr_flags)
823 { 828 {
824 XRenderPictureAttributes pa;
825
826 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, visual); 829 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
830
827 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); 831 Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0);
828 832
829 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual);
830 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, dst_format, 0, &pa); 833 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0);
831 834
832 Picture mask = create_xrender_mask (dpy, vt, False, False); 835 Picture mask = create_xrender_mask (dpy, vt, False, False);
833 836
834 XRenderColor mask_c; 837 XRenderColor mask_c;
835 838
836 mask_c.alpha = 0x8000; 839 mask_c.alpha = 0x8000;
837 mask_c.red = 0; 840 mask_c.red =
838 mask_c.green = 0; 841 mask_c.green =
839 mask_c.blue = 0; 842 mask_c.blue = 0;
840 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); 843 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1);
844
841 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);
842 846
843 XRenderFreePicture (dpy, src); 847 XRenderFreePicture (dpy, src);
844 XRenderFreePicture (dpy, dst); 848 XRenderFreePicture (dpy, dst);
845 XRenderFreePicture (dpy, mask); 849 XRenderFreePicture (dpy, mask);
957 { 961 {
958 changed = true; 962 changed = true;
959 v_blurRadius = vr; 963 v_blurRadius = vr;
960 } 964 }
961 965
962 if (v_blurRadius == 0 && h_blurRadius == 0) 966 if (h_blurRadius == 0 || v_blurRadius == 0)
963 bg_flags &= ~BG_NEEDS_BLUR; 967 bg_flags &= ~BG_NEEDS_BLUR;
964 else 968 else
965 bg_flags |= BG_NEEDS_BLUR; 969 bg_flags |= BG_NEEDS_BLUR;
966 970
967 return changed; 971 return changed;
973 rgba c; 977 rgba c;
974 bool has_shade = shade != 100; 978 bool has_shade = shade != 100;
975 979
976 bg_flags &= ~BG_TINT_FLAGS; 980 bg_flags &= ~BG_TINT_FLAGS;
977 981
982 if (bg_flags & BG_TINT_SET)
983 {
978 tint.get (c); 984 tint.get (c);
979
980 if (!has_shade 985 if (!has_shade
981 && (c.r <= 0x00ff || c.r >= 0xff00) 986 && (c.r <= 0x00ff || c.r >= 0xff00)
982 && (c.g <= 0x00ff || c.g >= 0xff00) 987 && (c.g <= 0x00ff || c.g >= 0xff00)
983 && (c.b <= 0x00ff || c.b >= 0xff00)) 988 && (c.b <= 0x00ff || c.b >= 0xff00))
984 bg_flags |= BG_TINT_BITAND; 989 bg_flags |= BG_TINT_BITAND;
990 }
985 991
986 if (has_shade 992 if (has_shade || (bg_flags & BG_TINT_SET))
987 || c.r < 0xff00
988 || c.g < 0xff00
989 || c.b < 0xff00)
990 bg_flags |= BG_NEEDS_TINT; 993 bg_flags |= BG_NEEDS_TINT;
991} 994}
992 995
993bool 996bool
994rxvt_term::bg_set_tint (rxvt_color &new_tint) 997rxvt_term::bg_set_tint (rxvt_color &new_tint)
995{ 998{
996 if (tint != new_tint) 999 if (!(bg_flags & BG_TINT_SET) || tint != new_tint)
997 { 1000 {
998 tint = new_tint; 1001 tint = new_tint;
1002 bg_flags |= BG_TINT_SET;
999 set_tint_shade_flags (); 1003 set_tint_shade_flags ();
1000 return true; 1004 return true;
1001 } 1005 }
1002 1006
1003 return false; 1007 return false;
1044 params[i+2] = XDoubleToFixed (kernel[i] / sum); 1048 params[i+2] = XDoubleToFixed (kernel[i] / sum);
1045} 1049}
1046#endif 1050#endif
1047 1051
1048bool 1052bool
1049rxvt_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)
1050{ 1054{
1051 bool ret = false; 1055 bool ret = false;
1052#if XRENDER 1056#if XRENDER
1053 if (!(bg_flags & BG_HAS_RENDER_CONV)) 1057 if (!(bg_flags & BG_HAS_RENDER_CONV))
1054 return false; 1058 return false;
1058 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 1062 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
1059 1063
1060 XRenderPictureAttributes pa; 1064 XRenderPictureAttributes pa;
1061 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1065 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1062 1066
1067 pa.repeat = RepeatPad;
1063 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1068 Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa);
1069 Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth);
1064 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1070 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa);
1071 XFreePixmap (dpy, tmp);
1065 1072
1066 if (kernel && params) 1073 if (kernel && params)
1067 { 1074 {
1068 if (h_blurRadius)
1069 {
1070 size = h_blurRadius * 2 + 1; 1075 size = h_blurRadius * 2 + 1;
1071 get_gaussian_kernel (h_blurRadius, size, kernel, params); 1076 get_gaussian_kernel (h_blurRadius, size, kernel, params);
1072 1077
1073 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); 1078 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
1074 XRenderComposite (dpy, 1079 XRenderComposite (dpy,
1075 PictOpSrc, 1080 PictOpSrc,
1076 src, 1081 src,
1077 None, 1082 None,
1078 dst, 1083 dst,
1079 0, 0, 1084 0, 0,
1080 0, 0, 1085 0, 0,
1081 0, 0, 1086 0, 0,
1082 width, height); 1087 width, height);
1083 }
1084 1088
1085 if (v_blurRadius) 1089 ::swap (src, dst);
1086 { 1090
1087 size = v_blurRadius * 2 + 1; 1091 size = v_blurRadius * 2 + 1;
1088 get_gaussian_kernel (v_blurRadius, size, kernel, params); 1092 get_gaussian_kernel (v_blurRadius, size, kernel, params);
1089 ::swap (params[0], params[1]); 1093 ::swap (params[0], params[1]);
1090 1094
1091 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); 1095 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
1092 XRenderComposite (dpy, 1096 XRenderComposite (dpy,
1093 PictOpSrc, 1097 PictOpSrc,
1094 src, 1098 src,
1095 None, 1099 None,
1096 dst, 1100 dst,
1097 0, 0, 1101 0, 0,
1098 0, 0, 1102 0, 0,
1099 0, 0, 1103 0, 0,
1100 width, height); 1104 width, height);
1101 }
1102 1105
1103 ret = true; 1106 ret = true;
1104 } 1107 }
1105 1108
1106 free (kernel); 1109 free (kernel);
1136 } 1139 }
1137 } 1140 }
1138# if XRENDER 1141# if XRENDER
1139 else if (bg_flags & BG_HAS_RENDER) 1142 else if (bg_flags & BG_HAS_RENDER)
1140 { 1143 {
1141 rgba c; 1144 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1142 1145
1146 if (bg_flags & BG_TINT_SET)
1143 tint.get (c); 1147 tint.get (c);
1144 1148
1145 if (shade <= 100) 1149 if (shade <= 100)
1146 { 1150 {
1147 c.r = c.r * shade / 100; 1151 c.r = c.r * shade / 100;
1148 c.g = c.g * shade / 100; 1152 c.g = c.g * shade / 100;
1154 c.g = c.g * (200 - shade) / 100; 1158 c.g = c.g * (200 - shade) / 100;
1155 c.b = c.b * (200 - shade) / 100; 1159 c.b = c.b * (200 - shade) / 100;
1156 } 1160 }
1157 1161
1158 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1162 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1159 XRenderPictureAttributes pa;
1160 1163
1161 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1164 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0);
1162 1165
1163 Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False); 1166 Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False);
1164 1167
1165 Picture mask_pic = create_xrender_mask (dpy, pixmap, True, True); 1168 Picture mask_pic = create_xrender_mask (dpy, pixmap, True, True);
1166 1169
1175 mask_c.alpha = 0; 1178 mask_c.alpha = 0;
1176 mask_c.red = 0xffff - c.r; 1179 mask_c.red = 0xffff - c.r;
1177 mask_c.green = 0xffff - c.g; 1180 mask_c.green = 0xffff - c.g;
1178 mask_c.blue = 0xffff - c.b; 1181 mask_c.blue = 0xffff - c.b;
1179 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); 1182 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1183
1180 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);
1181 1185
1182 if (shade > 100) 1186 if (shade > 100)
1183 { 1187 {
1184 mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100;
1185 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;
1186 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); 1192 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1187 1193
1188 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);
1189 } 1195 }
1190 1196
1253#if XRENDER 1259#if XRENDER
1254 if (bg_flags & BG_HAS_RENDER) 1260 if (bg_flags & BG_HAS_RENDER)
1255 { 1261 {
1256 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); 1262 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth);
1257 1263
1258 XRenderPictureAttributes pa;
1259
1260 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); 1264 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
1261 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); 1265 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0);
1262 1266
1263 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); 1267 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual);
1264 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); 1268 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, 0);
1265 1269
1266 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); 1270 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height);
1267 1271
1268 XRenderFreePicture (dpy, src); 1272 XRenderFreePicture (dpy, src);
1269 XRenderFreePicture (dpy, dst); 1273 XRenderFreePicture (dpy, dst);
1304 1308
1305 if (!(bg_flags & BG_CLIENT_RENDER)) 1309 if (!(bg_flags & BG_CLIENT_RENDER))
1306 { 1310 {
1307 if (bg_flags & BG_NEEDS_BLUR) 1311 if (bg_flags & BG_NEEDS_BLUR)
1308 { 1312 {
1309 if (blur_pixmap (bg_pixmap, visual, window_width, window_height)) 1313 if (blur_pixmap (bg_pixmap, visual, window_width, window_height, depth))
1310 result &= ~BG_NEEDS_BLUR; 1314 result &= ~BG_NEEDS_BLUR;
1311 } 1315 }
1312 if (bg_flags & BG_NEEDS_TINT) 1316 if (bg_flags & BG_NEEDS_TINT)
1313 { 1317 {
1314 if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) 1318 if (tint_pixmap (bg_pixmap, visual, window_width, window_height))
1395 1399
1396void 1400void
1397rxvt_term::bg_init () 1401rxvt_term::bg_init ()
1398{ 1402{
1399#ifdef ENABLE_TRANSPARENCY 1403#ifdef ENABLE_TRANSPARENCY
1400 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1401 tint.set (this, c);
1402 shade = 100; 1404 shade = 100;
1403#endif 1405#endif
1404 1406
1405 bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV); 1407 bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV);
1406#if XRENDER 1408#if XRENDER
1509 break; 1511 break;
1510 default: 1512 default:
1511 return; /* we do not support this color depth */ 1513 return; /* we do not support this color depth */
1512 } 1514 }
1513 1515
1514 rgba c; 1516 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1515 1517
1518 if (bg_flags & BG_TINT_SET)
1516 tint.get (c); 1519 tint.get (c);
1517 1520
1518 /* prepare limits for color transformation (each channel is handled separately) */ 1521 /* prepare limits for color transformation (each channel is handled separately) */
1519 if (shade > 100) 1522 if (shade > 100)
1520 { 1523 {
1521 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