… | |
… | |
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 |
|
|
42 | # if XRENDER |
|
|
43 | static Picture |
|
|
44 | create_xrender_mask (Display *dpy, Drawable drawable, Bool argb, Bool component_alpha) |
|
|
45 | { |
|
|
46 | Pixmap pixmap = XCreatePixmap (dpy, drawable, 1, 1, argb ? 32 : 8); |
|
|
47 | |
|
|
48 | XRenderPictFormat *format = XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8); |
|
|
49 | XRenderPictureAttributes pa; |
|
|
50 | pa.repeat = True; |
|
|
51 | pa.component_alpha = component_alpha; |
|
|
52 | Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat | CPComponentAlpha, &pa); |
|
|
53 | |
|
|
54 | XFreePixmap (dpy, pixmap); |
|
|
55 | |
|
|
56 | return mask; |
|
|
57 | } |
|
|
58 | # endif |
|
|
59 | |
38 | void |
60 | void |
39 | rxvt_term::bg_destroy () |
61 | rxvt_term::bg_destroy () |
40 | { |
62 | { |
41 | #ifdef HAVE_AFTERIMAGE |
63 | #ifdef HAVE_AFTERIMAGE |
42 | if (original_asim) |
64 | if (original_asim) |
… | |
… | |
181 | { |
203 | { |
182 | bool changed = false; |
204 | bool changed = false; |
183 | int geom_flags = 0; |
205 | int geom_flags = 0; |
184 | int x = 0, y = 0; |
206 | int x = 0, y = 0; |
185 | unsigned int w = 0, h = 0; |
207 | unsigned int w = 0, h = 0; |
186 | unsigned long new_flags = bg_flags & ~BG_GEOMETRY_FLAGS; |
208 | unsigned long new_flags = 0; |
187 | |
209 | |
188 | if (geom == NULL) |
210 | if (geom == NULL) |
189 | return false; |
211 | return false; |
190 | |
212 | |
191 | if (geom[0]) |
213 | if (geom[0]) |
… | |
… | |
201 | x = y = 0; |
223 | x = y = 0; |
202 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
224 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
203 | } |
225 | } |
204 | else if (!strcasecmp (arr[i], "style=aspect-stretched")) |
226 | else if (!strcasecmp (arr[i], "style=aspect-stretched")) |
205 | { |
227 | { |
206 | new_flags = BG_PROP_SCALE; |
228 | new_flags = BG_KEEP_ASPECT; |
207 | w = h = windowScale; |
229 | w = h = windowScale; |
208 | x = y = centerAlign; |
230 | x = y = centerAlign; |
209 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
231 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
210 | } |
232 | } |
211 | else if (!strcasecmp (arr[i], "style=stretched")) |
233 | else if (!strcasecmp (arr[i], "style=stretched")) |
… | |
… | |
227 | w = h = noScale; |
249 | w = h = noScale; |
228 | geom_flags = WidthValue|HeightValue; |
250 | geom_flags = WidthValue|HeightValue; |
229 | } |
251 | } |
230 | else if (!strcasecmp (arr[i], "op=tile")) |
252 | else if (!strcasecmp (arr[i], "op=tile")) |
231 | new_flags |= BG_TILE; |
253 | new_flags |= BG_TILE; |
232 | else if (!strcasecmp (arr[i], "op=pscale")) |
254 | else if (!strcasecmp (arr[i], "op=keep-aspect")) |
233 | new_flags |= BG_PROP_SCALE; |
255 | new_flags |= BG_KEEP_ASPECT; |
234 | else if (!strcasecmp (arr[i], "op=root")) |
256 | else if (!strcasecmp (arr[i], "op=root-align")) |
235 | new_flags |= BG_ROOT_ALIGN; |
257 | new_flags |= BG_ROOT_ALIGN; |
236 | |
258 | |
237 | // deprecated |
259 | // deprecated |
238 | else if (!strcasecmp (arr[i], "tile")) |
260 | else if (!strcasecmp (arr[i], "tile")) |
239 | { |
261 | { |
… | |
… | |
241 | w = h = noScale; |
263 | w = h = noScale; |
242 | geom_flags |= WidthValue|HeightValue; |
264 | geom_flags |= WidthValue|HeightValue; |
243 | } |
265 | } |
244 | else if (!strcasecmp (arr[i], "propscale")) |
266 | else if (!strcasecmp (arr[i], "propscale")) |
245 | { |
267 | { |
246 | new_flags |= BG_PROP_SCALE; |
268 | new_flags |= BG_KEEP_ASPECT; |
|
|
269 | w = h = windowScale; |
|
|
270 | geom_flags |= WidthValue|HeightValue; |
247 | } |
271 | } |
248 | else if (!strcasecmp (arr[i], "hscale")) |
272 | else if (!strcasecmp (arr[i], "hscale")) |
249 | { |
273 | { |
250 | new_flags |= BG_TILE; |
274 | new_flags |= BG_TILE; |
251 | w = windowScale; |
275 | w = windowScale; |
… | |
… | |
281 | geom_flags |= XParseGeometry (arr[i], &x, &y, &w, &h); |
305 | geom_flags |= XParseGeometry (arr[i], &x, &y, &w, &h); |
282 | } /* done parsing ops */ |
306 | } /* done parsing ops */ |
283 | |
307 | |
284 | rxvt_free_strsplit (arr); |
308 | rxvt_free_strsplit (arr); |
285 | } |
309 | } |
|
|
310 | |
|
|
311 | new_flags |= bg_flags & ~BG_GEOMETRY_FLAGS; |
286 | |
312 | |
287 | if (!update) |
313 | if (!update) |
288 | { |
314 | { |
289 | if (!(geom_flags & XValue)) |
315 | if (!(geom_flags & XValue)) |
290 | x = y = defaultAlign; |
316 | x = y = defaultAlign; |
… | |
… | |
299 | w = h; |
325 | w = h; |
300 | |
326 | |
301 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
327 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
302 | } |
328 | } |
303 | |
329 | |
304 | if (check_set_scale_value (geom_flags, WidthValue, h_scale, w) |
330 | if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true; |
305 | || check_set_scale_value (geom_flags, HeightValue, v_scale, h) |
331 | if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true; |
306 | || check_set_align_value (geom_flags, XValue, h_align, x) |
332 | if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true; |
307 | || check_set_align_value (geom_flags, YValue, v_align, y)) |
333 | if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true; |
308 | changed = true; |
|
|
309 | |
334 | |
310 | if (new_flags != bg_flags) |
335 | if (new_flags != bg_flags) |
311 | { |
336 | { |
312 | bg_flags = new_flags; |
337 | bg_flags = new_flags; |
313 | changed = true; |
338 | changed = true; |
… | |
… | |
323 | int target_height = szHint.height; |
348 | int target_height = szHint.height; |
324 | |
349 | |
325 | w = h_scale * target_width / 100; |
350 | w = h_scale * target_width / 100; |
326 | h = v_scale * target_height / 100; |
351 | h = v_scale * target_height / 100; |
327 | |
352 | |
328 | if (bg_flags & BG_PROP_SCALE) |
353 | if (bg_flags & BG_KEEP_ASPECT) |
329 | { |
354 | { |
330 | float scale = (float)w / image_width; |
355 | float scale = (float)w / image_width; |
331 | min_it (scale, (float)h / image_height); |
356 | min_it (scale, (float)h / image_height); |
332 | w = image_width * scale + 0.5; |
357 | w = image_width * scale + 0.5; |
333 | h = image_height * scale + 0.5; |
358 | h = image_height * scale + 0.5; |
… | |
… | |
799 | } |
824 | } |
800 | |
825 | |
801 | #if XRENDER |
826 | #if XRENDER |
802 | if (tr_flags) |
827 | if (tr_flags) |
803 | { |
828 | { |
804 | XRenderPictureAttributes pa; |
|
|
805 | |
|
|
806 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, visual); |
829 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
|
|
830 | |
807 | Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); |
831 | Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0); |
808 | |
832 | |
809 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); |
|
|
810 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, dst_format, 0, &pa); |
833 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); |
811 | |
834 | |
812 | pa.repeat = True; |
835 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
813 | Pixmap mask_pmap = XCreatePixmap (dpy, vt, 1, 1, 8); |
|
|
814 | XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8); |
|
|
815 | Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa); |
|
|
816 | XFreePixmap (dpy, mask_pmap); |
|
|
817 | |
836 | |
818 | XRenderColor mask_c; |
837 | XRenderColor mask_c; |
819 | |
838 | |
820 | mask_c.alpha = 0x8000; |
839 | mask_c.alpha = 0x8000; |
821 | mask_c.red = 0; |
840 | mask_c.red = |
822 | mask_c.green = 0; |
841 | mask_c.green = |
823 | mask_c.blue = 0; |
842 | mask_c.blue = 0; |
824 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
843 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
|
|
844 | |
825 | 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); |
826 | |
846 | |
827 | XRenderFreePicture (dpy, src); |
847 | XRenderFreePicture (dpy, src); |
828 | XRenderFreePicture (dpy, dst); |
848 | XRenderFreePicture (dpy, dst); |
829 | XRenderFreePicture (dpy, mask); |
849 | XRenderFreePicture (dpy, mask); |
… | |
… | |
941 | { |
961 | { |
942 | changed = true; |
962 | changed = true; |
943 | v_blurRadius = vr; |
963 | v_blurRadius = vr; |
944 | } |
964 | } |
945 | |
965 | |
946 | if (v_blurRadius == 0 && h_blurRadius == 0) |
966 | if (h_blurRadius == 0 || v_blurRadius == 0) |
947 | bg_flags &= ~BG_NEEDS_BLUR; |
967 | bg_flags &= ~BG_NEEDS_BLUR; |
948 | else |
968 | else |
949 | bg_flags |= BG_NEEDS_BLUR; |
969 | bg_flags |= BG_NEEDS_BLUR; |
950 | |
970 | |
951 | return changed; |
971 | return changed; |
952 | } |
972 | } |
953 | |
973 | |
954 | void |
974 | void |
955 | rxvt_term::set_tint_shade_flags () |
975 | rxvt_term::set_tint_shade_flags () |
956 | { |
976 | { |
957 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
977 | rgba c; |
958 | bool has_shade = shade != 100; |
978 | bool has_shade = shade != 100; |
959 | |
979 | |
960 | bg_flags &= ~BG_TINT_FLAGS; |
980 | bg_flags &= ~BG_TINT_FLAGS; |
961 | |
981 | |
962 | if (bg_flags & BG_TINT_SET) |
982 | if (bg_flags & BG_TINT_SET) |
… | |
… | |
988 | } |
1008 | } |
989 | |
1009 | |
990 | bool |
1010 | bool |
991 | rxvt_term::bg_set_shade (const char *shade_str) |
1011 | rxvt_term::bg_set_shade (const char *shade_str) |
992 | { |
1012 | { |
993 | int new_shade = (shade_str) ? atoi (shade_str) : 100; |
1013 | int new_shade = atoi (shade_str); |
994 | |
1014 | |
995 | clamp_it (new_shade, -100, 200); |
1015 | clamp_it (new_shade, -100, 200); |
996 | if (new_shade < 0) |
1016 | if (new_shade < 0) |
997 | new_shade = 200 - (100 + new_shade); |
1017 | new_shade = 200 - (100 + new_shade); |
998 | |
1018 | |
… | |
… | |
1028 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
1048 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
1029 | } |
1049 | } |
1030 | #endif |
1050 | #endif |
1031 | |
1051 | |
1032 | bool |
1052 | bool |
1033 | rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
1053 | rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height, int depth) |
1034 | { |
1054 | { |
1035 | bool ret = false; |
1055 | bool ret = false; |
1036 | #if XRENDER |
1056 | #if XRENDER |
|
|
1057 | if (!(bg_flags & BG_HAS_RENDER_CONV)) |
|
|
1058 | return false; |
|
|
1059 | |
1037 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
1060 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
1038 | double *kernel = (double *)malloc (size * sizeof (double)); |
1061 | double *kernel = (double *)malloc (size * sizeof (double)); |
1039 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
1062 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
1040 | |
1063 | |
1041 | XRenderPictureAttributes pa; |
1064 | XRenderPictureAttributes pa; |
1042 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1065 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1043 | |
1066 | |
|
|
1067 | pa.repeat = RepeatPad; |
1044 | 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); |
1045 | Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1070 | Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa); |
|
|
1071 | XFreePixmap (dpy, tmp); |
1046 | |
1072 | |
1047 | if (kernel && params) |
1073 | if (kernel && params) |
1048 | { |
1074 | { |
1049 | if (h_blurRadius) |
|
|
1050 | { |
|
|
1051 | size = h_blurRadius * 2 + 1; |
1075 | size = h_blurRadius * 2 + 1; |
1052 | get_gaussian_kernel (h_blurRadius, size, kernel, params); |
1076 | get_gaussian_kernel (h_blurRadius, size, kernel, params); |
1053 | |
1077 | |
1054 | XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); |
1078 | XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); |
1055 | XRenderComposite (dpy, |
1079 | XRenderComposite (dpy, |
1056 | PictOpSrc, |
1080 | PictOpSrc, |
1057 | src, |
1081 | src, |
1058 | None, |
1082 | None, |
1059 | dst, |
1083 | dst, |
1060 | 0, 0, |
1084 | 0, 0, |
1061 | 0, 0, |
1085 | 0, 0, |
1062 | 0, 0, |
1086 | 0, 0, |
1063 | width, height); |
1087 | width, height); |
1064 | } |
|
|
1065 | |
1088 | |
1066 | if (v_blurRadius) |
1089 | ::swap (src, dst); |
1067 | { |
1090 | |
1068 | size = v_blurRadius * 2 + 1; |
1091 | size = v_blurRadius * 2 + 1; |
1069 | get_gaussian_kernel (v_blurRadius, size, kernel, params); |
1092 | get_gaussian_kernel (v_blurRadius, size, kernel, params); |
1070 | ::swap (params[0], params[1]); |
1093 | ::swap (params[0], params[1]); |
1071 | |
1094 | |
1072 | XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); |
1095 | XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); |
1073 | XRenderComposite (dpy, |
1096 | XRenderComposite (dpy, |
1074 | PictOpSrc, |
1097 | PictOpSrc, |
1075 | src, |
1098 | src, |
1076 | None, |
1099 | None, |
1077 | dst, |
1100 | dst, |
1078 | 0, 0, |
1101 | 0, 0, |
1079 | 0, 0, |
1102 | 0, 0, |
1080 | 0, 0, |
1103 | 0, 0, |
1081 | width, height); |
1104 | width, height); |
1082 | } |
|
|
1083 | |
1105 | |
1084 | ret = true; |
1106 | ret = true; |
1085 | } |
1107 | } |
1086 | |
1108 | |
1087 | free (kernel); |
1109 | free (kernel); |
… | |
… | |
1114 | XFillRectangle (dpy, pixmap, gc, 0, 0, width, height); |
1136 | XFillRectangle (dpy, pixmap, gc, 0, 0, width, height); |
1115 | ret = true; |
1137 | ret = true; |
1116 | XFreeGC (dpy, gc); |
1138 | XFreeGC (dpy, gc); |
1117 | } |
1139 | } |
1118 | } |
1140 | } |
1119 | else |
|
|
1120 | { |
|
|
1121 | # if XRENDER |
1141 | # if XRENDER |
|
|
1142 | else if (bg_flags & BG_HAS_RENDER) |
|
|
1143 | { |
1122 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
1144 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
1123 | |
1145 | |
1124 | if (bg_flags & BG_TINT_SET) |
1146 | if (bg_flags & BG_TINT_SET) |
1125 | tint.get (c); |
1147 | tint.get (c); |
1126 | |
1148 | |
… | |
… | |
1135 | c.r = c.r * (200 - shade) / 100; |
1157 | c.r = c.r * (200 - shade) / 100; |
1136 | c.g = c.g * (200 - shade) / 100; |
1158 | c.g = c.g * (200 - shade) / 100; |
1137 | c.b = c.b * (200 - shade) / 100; |
1159 | c.b = c.b * (200 - shade) / 100; |
1138 | } |
1160 | } |
1139 | |
1161 | |
1140 | XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
|
|
1141 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1162 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1142 | XRenderPictureAttributes pa; |
|
|
1143 | |
1163 | |
1144 | Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1164 | Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0); |
1145 | |
1165 | |
1146 | pa.repeat = True; |
1166 | Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False); |
1147 | |
1167 | |
1148 | Pixmap overlay_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); |
1168 | Picture mask_pic = create_xrender_mask (dpy, pixmap, True, True); |
1149 | Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); |
|
|
1150 | XFreePixmap (dpy, overlay_pmap); |
|
|
1151 | |
|
|
1152 | pa.component_alpha = True; |
|
|
1153 | Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); |
|
|
1154 | Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat | CPComponentAlpha, &pa); |
|
|
1155 | XFreePixmap (dpy, mask_pmap); |
|
|
1156 | |
1169 | |
1157 | XRenderColor mask_c; |
1170 | XRenderColor mask_c; |
1158 | |
1171 | |
1159 | mask_c.alpha = 0xffff; |
1172 | mask_c.alpha = 0xffff; |
1160 | mask_c.red = |
1173 | mask_c.red = |
… | |
… | |
1165 | mask_c.alpha = 0; |
1178 | mask_c.alpha = 0; |
1166 | mask_c.red = 0xffff - c.r; |
1179 | mask_c.red = 0xffff - c.r; |
1167 | mask_c.green = 0xffff - c.g; |
1180 | mask_c.green = 0xffff - c.g; |
1168 | mask_c.blue = 0xffff - c.b; |
1181 | mask_c.blue = 0xffff - c.b; |
1169 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
1182 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
|
|
1183 | |
1170 | 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); |
1171 | |
1185 | |
1172 | if (shade > 100) |
1186 | if (shade > 100) |
1173 | { |
1187 | { |
1174 | mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100; |
|
|
1175 | 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; |
1176 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
1192 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
1177 | |
1193 | |
1178 | 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); |
1179 | } |
1195 | } |
1180 | |
1196 | |
1181 | ret = true; |
1197 | ret = true; |
1182 | |
1198 | |
1183 | XRenderFreePicture (dpy, mask_pic); |
1199 | XRenderFreePicture (dpy, mask_pic); |
1184 | XRenderFreePicture (dpy, overlay_pic); |
1200 | XRenderFreePicture (dpy, overlay_pic); |
1185 | XRenderFreePicture (dpy, back_pic); |
1201 | XRenderFreePicture (dpy, back_pic); |
|
|
1202 | } |
1186 | # endif |
1203 | # endif |
1187 | } |
|
|
1188 | |
1204 | |
1189 | return ret; |
1205 | return ret; |
1190 | } |
1206 | } |
1191 | |
1207 | |
1192 | /* |
1208 | /* |
… | |
… | |
1243 | #if XRENDER |
1259 | #if XRENDER |
1244 | if (bg_flags & BG_HAS_RENDER) |
1260 | if (bg_flags & BG_HAS_RENDER) |
1245 | { |
1261 | { |
1246 | 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); |
1247 | |
1263 | |
1248 | XRenderPictureAttributes pa; |
|
|
1249 | |
|
|
1250 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
1264 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
1251 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); |
1265 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0); |
1252 | |
1266 | |
1253 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); |
1267 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); |
1254 | Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); |
1268 | Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, 0); |
1255 | |
1269 | |
1256 | 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); |
1257 | |
1271 | |
1258 | XRenderFreePicture (dpy, src); |
1272 | XRenderFreePicture (dpy, src); |
1259 | XRenderFreePicture (dpy, dst); |
1273 | XRenderFreePicture (dpy, dst); |
… | |
… | |
1276 | bg_pmap_width = window_width; |
1290 | bg_pmap_width = window_width; |
1277 | bg_pmap_height = window_height; |
1291 | bg_pmap_height = window_height; |
1278 | } |
1292 | } |
1279 | |
1293 | |
1280 | /* straightforward pixmap copy */ |
1294 | /* straightforward pixmap copy */ |
1281 | while (sx < 0) sx += root_width; |
1295 | while (sx < 0) sx += root_pmap_width; |
1282 | while (sy < 0) sy += root_height; |
1296 | while (sy < 0) sy += root_pmap_height; |
1283 | |
1297 | |
1284 | gcv.tile = recoded_root_pmap; |
1298 | gcv.tile = recoded_root_pmap; |
1285 | gcv.fill_style = FillTiled; |
1299 | gcv.fill_style = FillTiled; |
1286 | gcv.ts_x_origin = -sx; |
1300 | gcv.ts_x_origin = -sx; |
1287 | gcv.ts_y_origin = -sy; |
1301 | gcv.ts_y_origin = -sy; |
… | |
… | |
1289 | |
1303 | |
1290 | if (gc) |
1304 | if (gc) |
1291 | { |
1305 | { |
1292 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1306 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1293 | result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS); |
1307 | result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS); |
1294 | XFreeGC (dpy, gc); |
|
|
1295 | |
1308 | |
1296 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1309 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1297 | { |
1310 | { |
1298 | if ((bg_flags & BG_NEEDS_BLUR) |
1311 | if (bg_flags & BG_NEEDS_BLUR) |
1299 | && (bg_flags & BG_HAS_RENDER_CONV)) |
|
|
1300 | { |
1312 | { |
1301 | if (blur_pixmap (bg_pixmap, visual, window_width, window_height)) |
1313 | if (blur_pixmap (bg_pixmap, visual, window_width, window_height, depth)) |
1302 | result &= ~BG_NEEDS_BLUR; |
1314 | result &= ~BG_NEEDS_BLUR; |
1303 | } |
1315 | } |
1304 | if ((bg_flags & BG_NEEDS_TINT) |
1316 | if (bg_flags & BG_NEEDS_TINT) |
1305 | && (bg_flags & (BG_TINT_BITAND | BG_HAS_RENDER))) |
|
|
1306 | { |
1317 | { |
1307 | if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) |
1318 | if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) |
1308 | result &= ~BG_NEEDS_TINT; |
1319 | result &= ~BG_NEEDS_TINT; |
1309 | } |
1320 | } |
|
|
1321 | # ifndef HAVE_AFTERIMAGE |
|
|
1322 | if (result & BG_NEEDS_TINT) |
|
|
1323 | { |
|
|
1324 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
|
|
1325 | if (ximage) |
|
|
1326 | { |
|
|
1327 | /* our own client-side tinting */ |
|
|
1328 | tint_ximage (DefaultVisual (dpy, display->screen), ximage); |
|
|
1329 | |
|
|
1330 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
|
|
1331 | XDestroyImage (ximage); |
|
|
1332 | } |
|
|
1333 | } |
|
|
1334 | # endif |
1310 | } /* server side rendering completed */ |
1335 | } /* server side rendering completed */ |
|
|
1336 | |
|
|
1337 | XFreeGC (dpy, gc); |
1311 | } |
1338 | } |
1312 | |
1339 | |
1313 | if (recoded_root_pmap != root_pixmap) |
1340 | if (recoded_root_pmap != root_pixmap) |
1314 | XFreePixmap (dpy, recoded_root_pmap); |
1341 | XFreePixmap (dpy, recoded_root_pmap); |
1315 | |
1342 | |
… | |
… | |
1324 | new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]); |
1351 | new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]); |
1325 | |
1352 | |
1326 | root_pixmap = new_root_pixmap; |
1353 | root_pixmap = new_root_pixmap; |
1327 | } |
1354 | } |
1328 | # endif /* ENABLE_TRANSPARENCY */ |
1355 | # endif /* ENABLE_TRANSPARENCY */ |
1329 | |
|
|
1330 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
|
|
1331 | static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c); |
|
|
1332 | # endif |
|
|
1333 | |
1356 | |
1334 | bool |
1357 | bool |
1335 | rxvt_term::bg_render () |
1358 | rxvt_term::bg_render () |
1336 | { |
1359 | { |
1337 | unsigned long tr_flags = 0; |
1360 | unsigned long tr_flags = 0; |
… | |
… | |
1352 | if ((bg_flags & BG_IS_FROM_FILE) |
1375 | if ((bg_flags & BG_IS_FROM_FILE) |
1353 | || (tr_flags & BG_EFFECTS_FLAGS)) |
1376 | || (tr_flags & BG_EFFECTS_FLAGS)) |
1354 | { |
1377 | { |
1355 | if (render_image (tr_flags)) |
1378 | if (render_image (tr_flags)) |
1356 | bg_flags |= BG_IS_VALID; |
1379 | bg_flags |= BG_IS_VALID; |
1357 | } |
|
|
1358 | # endif |
|
|
1359 | |
|
|
1360 | # if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
|
|
1361 | XImage *result = NULL; |
|
|
1362 | |
|
|
1363 | if (tr_flags & BG_NEEDS_TINT) |
|
|
1364 | { |
|
|
1365 | result = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
|
|
1366 | } |
|
|
1367 | |
|
|
1368 | if (result) |
|
|
1369 | { |
|
|
1370 | /* our own client-side tinting */ |
|
|
1371 | //if (tr_flags & BG_NEEDS_TINT) |
|
|
1372 | if (1) |
|
|
1373 | { |
|
|
1374 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
|
|
1375 | if (bg_flags & BG_TINT_SET) |
|
|
1376 | tint.get (c); |
|
|
1377 | shade_ximage (DefaultVisual (dpy, display->screen), result, shade, c); |
|
|
1378 | } |
|
|
1379 | |
|
|
1380 | GC gc = XCreateGC (dpy, vt, 0UL, NULL); |
|
|
1381 | |
|
|
1382 | if (gc) |
|
|
1383 | { |
|
|
1384 | XPutImage (dpy, bg_pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); |
|
|
1385 | |
|
|
1386 | XFreeGC (dpy, gc); |
|
|
1387 | } |
|
|
1388 | |
|
|
1389 | XDestroyImage (result); |
|
|
1390 | } |
1380 | } |
1391 | # endif |
1381 | # endif |
1392 | |
1382 | |
1393 | if (!(bg_flags & BG_IS_VALID)) |
1383 | if (!(bg_flags & BG_IS_VALID)) |
1394 | { |
1384 | { |
… | |
… | |
1434 | #endif /* HAVE_BG_PIXMAP */ |
1424 | #endif /* HAVE_BG_PIXMAP */ |
1435 | |
1425 | |
1436 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1426 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1437 | /* based on code from aterm-0.4.2 */ |
1427 | /* based on code from aterm-0.4.2 */ |
1438 | |
1428 | |
1439 | static void |
1429 | static inline void |
1440 | shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c) |
1430 | fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high) |
|
|
1431 | { |
|
|
1432 | for (int i = 0; i <= mask >> sh; i++) |
|
|
1433 | { |
|
|
1434 | uint32_t tmp; |
|
|
1435 | tmp = i * high; |
|
|
1436 | tmp += (mask >> sh) * low; |
|
|
1437 | lookup[i] = (tmp / 0xffff) << sh; |
|
|
1438 | } |
|
|
1439 | } |
|
|
1440 | |
|
|
1441 | void |
|
|
1442 | rxvt_term::tint_ximage (Visual *visual, XImage *ximage) |
1441 | { |
1443 | { |
1442 | int sh_r, sh_g, sh_b; |
1444 | int sh_r, sh_g, sh_b; |
1443 | uint32_t mask_r, mask_g, mask_b; |
1445 | uint32_t mask_r, mask_g, mask_b; |
1444 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1446 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1445 | rgba low; |
1447 | unsigned short low; |
1446 | rgba high; |
|
|
1447 | int i; |
|
|
1448 | int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
1448 | int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
1449 | |
1449 | |
1450 | if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; |
1450 | if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; |
1451 | |
1451 | |
1452 | /* for convenience */ |
1452 | /* for convenience */ |
… | |
… | |
1511 | break; |
1511 | break; |
1512 | default: |
1512 | default: |
1513 | return; /* we do not support this color depth */ |
1513 | return; /* we do not support this color depth */ |
1514 | } |
1514 | } |
1515 | |
1515 | |
|
|
1516 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
|
|
1517 | |
|
|
1518 | if (bg_flags & BG_TINT_SET) |
|
|
1519 | tint.get (c); |
|
|
1520 | |
1516 | /* prepare limits for color transformation (each channel is handled separately) */ |
1521 | /* prepare limits for color transformation (each channel is handled separately) */ |
1517 | if (shade > 100) |
1522 | if (shade > 100) |
1518 | { |
1523 | { |
1519 | shade = 200 - shade; |
|
|
1520 | |
|
|
1521 | high.r = c.r * shade / 100; |
|
|
1522 | high.g = c.g * shade / 100; |
|
|
1523 | high.b = c.b * shade / 100; |
|
|
1524 | |
|
|
1525 | low.r = 65535 * (100 - shade) / 100; |
1524 | c.r = c.r * (200 - shade) / 100; |
1526 | low.g = 65535 * (100 - shade) / 100; |
1525 | c.g = c.g * (200 - shade) / 100; |
1527 | low.b = 65535 * (100 - shade) / 100; |
1526 | c.b = c.b * (200 - shade) / 100; |
|
|
1527 | |
|
|
1528 | low = 0xffff * (shade - 100) / 100; |
1528 | } |
1529 | } |
1529 | else |
1530 | else |
1530 | { |
1531 | { |
1531 | high.r = c.r * shade / 100; |
1532 | c.r = c.r * shade / 100; |
1532 | high.g = c.g * shade / 100; |
1533 | c.g = c.g * shade / 100; |
1533 | high.b = c.b * shade / 100; |
1534 | c.b = c.b * shade / 100; |
1534 | |
1535 | |
1535 | low.r = low.g = low.b = 0; |
1536 | low = 0; |
1536 | } |
1537 | } |
1537 | |
1538 | |
1538 | /* fill our lookup tables */ |
1539 | /* fill our lookup tables */ |
1539 | for (i = 0; i <= mask_r>>sh_r; i++) |
1540 | fill_lut (lookup_r, mask_r, sh_r, low, c.r); |
1540 | { |
1541 | fill_lut (lookup_g, mask_g, sh_g, low, c.g); |
1541 | uint32_t tmp; |
1542 | fill_lut (lookup_b, mask_b, sh_b, low, c.b); |
1542 | tmp = i * high.r; |
|
|
1543 | tmp += (mask_r>>sh_r) * low.r; |
|
|
1544 | lookup_r[i] = (tmp/65535)<<sh_r; |
|
|
1545 | } |
|
|
1546 | for (i = 0; i <= mask_g>>sh_g; i++) |
|
|
1547 | { |
|
|
1548 | uint32_t tmp; |
|
|
1549 | tmp = i * high.g; |
|
|
1550 | tmp += (mask_g>>sh_g) * low.g; |
|
|
1551 | lookup_g[i] = (tmp/65535)<<sh_g; |
|
|
1552 | } |
|
|
1553 | for (i = 0; i <= mask_b>>sh_b; i++) |
|
|
1554 | { |
|
|
1555 | uint32_t tmp; |
|
|
1556 | tmp = i * high.b; |
|
|
1557 | tmp += (mask_b>>sh_b) * low.b; |
|
|
1558 | lookup_b[i] = (tmp/65535)<<sh_b; |
|
|
1559 | } |
|
|
1560 | |
1543 | |
1561 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1544 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1562 | if (ximage->bits_per_pixel == 32 |
1545 | if (ximage->bits_per_pixel == 32 |
1563 | && (ximage->depth == 24 || ximage->depth == 32) |
1546 | && (ximage->depth == 24 || ximage->depth == 32) |
1564 | && ximage->byte_order == host_byte_order) |
1547 | && ximage->byte_order == host_byte_order) |