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.167 by sf-exg, Fri Aug 19 17:42:09 2011 UTC vs.
Revision 1.194 by sf-exg, Sun Jan 1 17:43:47 2012 UTC

33#ifndef FilterConvolution 33#ifndef FilterConvolution
34#define FilterConvolution "convolution" 34#define FilterConvolution "convolution"
35#endif 35#endif
36 36
37#ifdef HAVE_BG_PIXMAP 37#ifdef HAVE_BG_PIXMAP
38# if XRENDER
39static Picture
40create_xrender_mask (Display *dpy, Drawable drawable, Bool argb, Bool component_alpha)
41{
42 Pixmap pixmap = XCreatePixmap (dpy, drawable, 1, 1, argb ? 32 : 8);
43
44 XRenderPictFormat *format = XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8);
45 XRenderPictureAttributes pa;
46 pa.repeat = True;
47 pa.component_alpha = component_alpha;
48 Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat | CPComponentAlpha, &pa);
49
50 XFreePixmap (dpy, pixmap);
51
52 return mask;
53}
54# endif
55
38void 56void
39rxvt_term::bg_destroy () 57rxvt_term::bg_destroy ()
40{ 58{
41#ifdef HAVE_AFTERIMAGE 59#ifdef HAVE_AFTERIMAGE
42 if (original_asim) 60 if (original_asim)
150 int smaller = min (image_size, window_size); 168 int smaller = min (image_size, window_size);
151 169
152 if (align >= 0 && align <= 100) 170 if (align >= 0 && align <= 100)
153 return diff * align / 100; 171 return diff * align / 100;
154 else if (align > 100 && align <= 200) 172 else if (align > 100 && align <= 200)
155 return ((align - 100) * smaller / 100) + window_size - smaller; 173 return (align - 100) * smaller / 100 + window_size - smaller;
156 else if (align >= -100 && align < 0) 174 else if (align >= -100 && align < 0)
157 return ((align + 100) * smaller / 100) - image_size; 175 return (align + 100) * smaller / 100 - image_size;
158 return 0; 176 return 0;
159} 177}
160 178
161static inline int 179static inline int
162make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) 180make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size)
181{ 199{
182 bool changed = false; 200 bool changed = false;
183 int geom_flags = 0; 201 int geom_flags = 0;
184 int x = 0, y = 0; 202 int x = 0, y = 0;
185 unsigned int w = 0, h = 0; 203 unsigned int w = 0, h = 0;
186 unsigned long new_flags = (bg_flags & (~BG_GEOMETRY_FLAGS)); 204 unsigned long new_flags = 0;
187 205
188 if (geom == NULL) 206 if (geom == NULL)
189 return false; 207 return false;
190 208
191 if (geom[0]) 209 if (geom[0])
192 { 210 {
193 char **arr = rxvt_strsplit (':', geom); 211 char **arr = rxvt_strsplit (':', geom);
194 212
195 for (int i = 0; arr[i]; i++) 213 for (int i = 0; arr[i]; i++)
196 { 214 {
197 if (!strcasecmp (arr[i], "style=tiled")) 215 if (!strcasecmp (arr[i], "style=tiled"))
198 { 216 {
199 new_flags = BG_TILE; 217 new_flags = BG_TILE;
200 w = h = noScale; 218 w = h = noScale;
201 x = y = 0; 219 x = y = 0;
202 geom_flags = WidthValue|HeightValue|XValue|YValue; 220 geom_flags = WidthValue|HeightValue|XValue|YValue;
203 } 221 }
204 else if (!strcasecmp (arr[i], "style=aspect-stretched")) 222 else if (!strcasecmp (arr[i], "style=aspect-stretched"))
205 { 223 {
206 new_flags = BG_PROP_SCALE; 224 new_flags = BG_KEEP_ASPECT;
207 w = h = windowScale; 225 w = h = windowScale;
208 x = y = centerAlign; 226 x = y = centerAlign;
209 geom_flags = WidthValue|HeightValue|XValue|YValue; 227 geom_flags = WidthValue|HeightValue|XValue|YValue;
210 } 228 }
211 else if (!strcasecmp (arr[i], "style=stretched")) 229 else if (!strcasecmp (arr[i], "style=stretched"))
227 w = h = noScale; 245 w = h = noScale;
228 geom_flags = WidthValue|HeightValue; 246 geom_flags = WidthValue|HeightValue;
229 } 247 }
230 else if (!strcasecmp (arr[i], "op=tile")) 248 else if (!strcasecmp (arr[i], "op=tile"))
231 new_flags |= BG_TILE; 249 new_flags |= BG_TILE;
232 else if (!strcasecmp (arr[i], "op=pscale")) 250 else if (!strcasecmp (arr[i], "op=keep-aspect"))
233 new_flags |= BG_PROP_SCALE; 251 new_flags |= BG_KEEP_ASPECT;
234 else if (!strcasecmp (arr[i], "op=root")) 252 else if (!strcasecmp (arr[i], "op=root-align"))
235 new_flags |= BG_ROOT_ALIGN; 253 new_flags |= BG_ROOT_ALIGN;
236 254
237 // deprecated 255 // deprecated
238 else if (!strcasecmp (arr[i], "tile")) 256 else if (!strcasecmp (arr[i], "tile"))
239 { 257 {
241 w = h = noScale; 259 w = h = noScale;
242 geom_flags |= WidthValue|HeightValue; 260 geom_flags |= WidthValue|HeightValue;
243 } 261 }
244 else if (!strcasecmp (arr[i], "propscale")) 262 else if (!strcasecmp (arr[i], "propscale"))
245 { 263 {
246 new_flags |= BG_PROP_SCALE; 264 new_flags |= BG_KEEP_ASPECT;
265 w = h = windowScale;
266 geom_flags |= WidthValue|HeightValue;
247 } 267 }
248 else if (!strcasecmp (arr[i], "hscale")) 268 else if (!strcasecmp (arr[i], "hscale"))
249 { 269 {
250 new_flags |= BG_TILE; 270 new_flags |= BG_TILE;
251 w = windowScale; 271 w = windowScale;
281 geom_flags |= XParseGeometry (arr[i], &x, &y, &w, &h); 301 geom_flags |= XParseGeometry (arr[i], &x, &y, &w, &h);
282 } /* done parsing ops */ 302 } /* done parsing ops */
283 303
284 rxvt_free_strsplit (arr); 304 rxvt_free_strsplit (arr);
285 } 305 }
306
307 new_flags |= bg_flags & ~BG_GEOMETRY_FLAGS;
286 308
287 if (!update) 309 if (!update)
288 { 310 {
289 if (!(geom_flags & XValue)) 311 if (!(geom_flags & XValue))
290 x = y = defaultAlign; 312 x = y = defaultAlign;
322 int target_height = szHint.height; 344 int target_height = szHint.height;
323 345
324 w = h_scale * target_width / 100; 346 w = h_scale * target_width / 100;
325 h = v_scale * target_height / 100; 347 h = v_scale * target_height / 100;
326 348
327 if (bg_flags & BG_PROP_SCALE) 349 if (bg_flags & BG_KEEP_ASPECT)
328 { 350 {
329 float scale = (float)w / image_width; 351 float scale = (float)w / image_width;
330 min_it (scale, (float)h / image_height); 352 min_it (scale, (float)h / image_height);
331 w = image_width * scale + 0.5; 353 w = image_width * scale + 0.5;
332 h = image_height * scale + 0.5; 354 h = image_height * scale + 0.5;
383 } 405 }
384 406
385 if ((tr_flags & BG_NEEDS_BLUR) && background != NULL) 407 if ((tr_flags & BG_NEEDS_BLUR) && background != NULL)
386 { 408 {
387 ASImage *tmp = blur_asimage_gauss (asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, 409 ASImage *tmp = blur_asimage_gauss (asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
388 (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage, 410 ASA_XImage,
389 100, ASIMAGE_QUALITY_DEFAULT); 411 100, ASIMAGE_QUALITY_DEFAULT);
390 if (tmp) 412 if (tmp)
391 { 413 {
392 destroy_asimage (&background); 414 destroy_asimage (&background);
393 background = tmp; 415 background = tmp;
412 434
413 if (!original_asim 435 if (!original_asim
414 || (!(bg_flags & BG_ROOT_ALIGN) 436 || (!(bg_flags & BG_ROOT_ALIGN)
415 && (x >= target_width 437 && (x >= target_width
416 || y >= target_height 438 || y >= target_height
417 || (x + w <= 0) 439 || x + w <= 0
418 || (y + h <= 0)))) 440 || y + h <= 0)))
419 { 441 {
420 if (background) 442 if (background)
421 { 443 {
422 new_pmap_width = background->width; 444 new_pmap_width = background->width;
423 new_pmap_height = background->height; 445 new_pmap_height = background->height;
437 } 459 }
438 else 460 else
439 { 461 {
440 result = original_asim; 462 result = original_asim;
441 463
442 if ((w != original_asim->width) 464 if (w != original_asim->width
443 || (h != original_asim->height)) 465 || h != original_asim->height)
444 { 466 {
445 result = scale_asimage (asv, original_asim, 467 result = scale_asimage (asv, original_asim,
446 w, h, 468 w, h,
447 background ? ASA_ASImage : ASA_XImage, 469 ASA_XImage,
448 100, ASIMAGE_QUALITY_DEFAULT); 470 100, ASIMAGE_QUALITY_DEFAULT);
449 } 471 }
450 472
451 if (background == NULL) 473 if (background == NULL)
452 { 474 {
702 get_image_geometry (image_width, image_height, w, h, x, y); 724 get_image_geometry (image_width, image_height, w, h, x, y);
703 725
704 if (!(bg_flags & BG_ROOT_ALIGN) 726 if (!(bg_flags & BG_ROOT_ALIGN)
705 && (x >= target_width 727 && (x >= target_width
706 || y >= target_height 728 || y >= target_height
707 || (x + w <= 0) 729 || x + w <= 0
708 || (y + h <= 0))) 730 || y + h <= 0))
709 return false; 731 return false;
710 732
711 result = pixbuf; 733 result = pixbuf;
712 734
713 if ((w != image_width) 735 if (w != image_width
714 || (h != image_height)) 736 || h != image_height)
715 { 737 {
716 result = gdk_pixbuf_scale_simple (pixbuf, 738 result = gdk_pixbuf_scale_simple (pixbuf,
717 w, h, 739 w, h,
718 GDK_INTERP_BILINEAR); 740 GDK_INTERP_BILINEAR);
719 } 741 }
798 } 820 }
799 821
800#if XRENDER 822#if XRENDER
801 if (tr_flags) 823 if (tr_flags)
802 { 824 {
803 XRenderPictureAttributes pa;
804
805 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, visual); 825 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
826
806 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); 827 Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0);
807 828
808 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual);
809 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, dst_format, 0, &pa); 829 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0);
810 830
811 pa.repeat = True; 831 Picture mask = create_xrender_mask (dpy, vt, False, False);
812 Pixmap mask_pmap = XCreatePixmap (dpy, vt, 1, 1, 8);
813 XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8);
814 Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa);
815 XFreePixmap (dpy, mask_pmap);
816 832
817 XRenderColor mask_c; 833 XRenderColor mask_c;
818 834
819 mask_c.alpha = 0x8000; 835 mask_c.alpha = 0x8000;
820 mask_c.red = 0; 836 mask_c.red =
821 mask_c.green = 0; 837 mask_c.green =
822 mask_c.blue = 0; 838 mask_c.blue = 0;
823 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); 839 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1);
840
824 XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height); 841 XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height);
825 842
826 XRenderFreePicture (dpy, src); 843 XRenderFreePicture (dpy, src);
827 XRenderFreePicture (dpy, dst); 844 XRenderFreePicture (dpy, dst);
828 XRenderFreePicture (dpy, mask); 845 XRenderFreePicture (dpy, mask);
940 { 957 {
941 changed = true; 958 changed = true;
942 v_blurRadius = vr; 959 v_blurRadius = vr;
943 } 960 }
944 961
945 if (v_blurRadius == 0 && h_blurRadius == 0) 962 if (h_blurRadius == 0 || v_blurRadius == 0)
946 bg_flags &= ~BG_NEEDS_BLUR; 963 bg_flags &= ~BG_NEEDS_BLUR;
947 else 964 else
948 bg_flags |= BG_NEEDS_BLUR; 965 bg_flags |= BG_NEEDS_BLUR;
949 966
950 return changed; 967 return changed;
951} 968}
952 969
953void 970void
954rxvt_term::set_tint_shade_flags () 971rxvt_term::set_tint_shade_flags ()
955{ 972{
956 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 973 rgba c;
957 bool has_shade = shade != 100; 974 bool has_shade = shade != 100;
958 975
959 bg_flags &= ~BG_TINT_FLAGS; 976 bg_flags &= ~BG_TINT_FLAGS;
960 977
961 if (bg_flags & BG_TINT_SET) 978 if (bg_flags & BG_TINT_SET)
987} 1004}
988 1005
989bool 1006bool
990rxvt_term::bg_set_shade (const char *shade_str) 1007rxvt_term::bg_set_shade (const char *shade_str)
991{ 1008{
992 int new_shade = (shade_str) ? atoi (shade_str) : 100; 1009 int new_shade = atoi (shade_str);
993 1010
994 clamp_it (new_shade, -100, 200); 1011 clamp_it (new_shade, -100, 200);
995 if (new_shade < 0) 1012 if (new_shade < 0)
996 new_shade = 200 - (100 + new_shade); 1013 new_shade = 200 - (100 + new_shade);
997 1014
1031bool 1048bool
1032rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) 1049rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height)
1033{ 1050{
1034 bool ret = false; 1051 bool ret = false;
1035#if XRENDER 1052#if XRENDER
1053 if (!(bg_flags & BG_HAS_RENDER_CONV))
1054 return false;
1055
1036 int size = max (h_blurRadius, v_blurRadius) * 2 + 1; 1056 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
1037 double *kernel = (double *)malloc (size * sizeof (double)); 1057 double *kernel = (double *)malloc (size * sizeof (double));
1038 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 1058 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
1039 1059
1040 XRenderPictureAttributes pa;
1041 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1060 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1042 1061
1043 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1062 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, 0);
1044 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1063 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, 0);
1045 1064
1046 if (kernel && params) 1065 if (kernel && params)
1047 { 1066 {
1048 if (h_blurRadius)
1049 {
1050 size = h_blurRadius * 2 + 1; 1067 size = h_blurRadius * 2 + 1;
1051 get_gaussian_kernel (h_blurRadius, size, kernel, params); 1068 get_gaussian_kernel (h_blurRadius, size, kernel, params);
1052 1069
1053 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); 1070 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
1054 XRenderComposite (dpy, 1071 XRenderComposite (dpy,
1055 PictOpSrc, 1072 PictOpSrc,
1056 src, 1073 src,
1057 None, 1074 None,
1058 dst, 1075 dst,
1059 0, 0, 1076 0, 0,
1060 0, 0, 1077 0, 0,
1061 0, 0, 1078 0, 0,
1062 width, height); 1079 width, height);
1063 }
1064 1080
1065 if (v_blurRadius)
1066 {
1067 size = v_blurRadius * 2 + 1; 1081 size = v_blurRadius * 2 + 1;
1068 get_gaussian_kernel (v_blurRadius, size, kernel, params); 1082 get_gaussian_kernel (v_blurRadius, size, kernel, params);
1069 ::swap (params[0], params[1]); 1083 ::swap (params[0], params[1]);
1070 1084
1071 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); 1085 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
1072 XRenderComposite (dpy, 1086 XRenderComposite (dpy,
1073 PictOpSrc, 1087 PictOpSrc,
1074 src, 1088 src,
1075 None, 1089 None,
1076 dst, 1090 dst,
1077 0, 0, 1091 0, 0,
1078 0, 0, 1092 0, 0,
1079 0, 0, 1093 0, 0,
1080 width, height); 1094 width, height);
1081 }
1082 1095
1083 ret = true; 1096 ret = true;
1084 } 1097 }
1085 1098
1086 free (kernel); 1099 free (kernel);
1113 XFillRectangle (dpy, pixmap, gc, 0, 0, width, height); 1126 XFillRectangle (dpy, pixmap, gc, 0, 0, width, height);
1114 ret = true; 1127 ret = true;
1115 XFreeGC (dpy, gc); 1128 XFreeGC (dpy, gc);
1116 } 1129 }
1117 } 1130 }
1118 else
1119 {
1120# if XRENDER 1131# if XRENDER
1132 else if (bg_flags & BG_HAS_RENDER)
1133 {
1121 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); 1134 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1122 1135
1123 if (bg_flags & BG_TINT_SET) 1136 if (bg_flags & BG_TINT_SET)
1124 tint.get (c); 1137 tint.get (c);
1125 1138
1134 c.r = c.r * (200 - shade) / 100; 1147 c.r = c.r * (200 - shade) / 100;
1135 c.g = c.g * (200 - shade) / 100; 1148 c.g = c.g * (200 - shade) / 100;
1136 c.b = c.b * (200 - shade) / 100; 1149 c.b = c.b * (200 - shade) / 100;
1137 } 1150 }
1138 1151
1139 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
1140 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1152 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1141 XRenderPictureAttributes pa;
1142 1153
1143 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1154 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0);
1144 1155
1145 pa.repeat = True; 1156 Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False);
1146 1157
1147 Pixmap overlay_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); 1158 Picture mask_pic = create_xrender_mask (dpy, pixmap, True, True);
1148 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
1149 XFreePixmap (dpy, overlay_pmap);
1150
1151 pa.component_alpha = True;
1152 Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32);
1153 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat | CPComponentAlpha, &pa);
1154 XFreePixmap (dpy, mask_pmap);
1155 1159
1156 XRenderColor mask_c; 1160 XRenderColor mask_c;
1157 1161
1158 mask_c.alpha = 0xffff; 1162 mask_c.alpha = 0xffff;
1159 mask_c.red = 1163 mask_c.red =
1164 mask_c.alpha = 0; 1168 mask_c.alpha = 0;
1165 mask_c.red = 0xffff - c.r; 1169 mask_c.red = 0xffff - c.r;
1166 mask_c.green = 0xffff - c.g; 1170 mask_c.green = 0xffff - c.g;
1167 mask_c.blue = 0xffff - c.b; 1171 mask_c.blue = 0xffff - c.b;
1168 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); 1172 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1173
1169 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height); 1174 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1170 1175
1171 if (shade > 100) 1176 if (shade > 100)
1172 { 1177 {
1173 mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100;
1174 mask_c.alpha = 0; 1178 mask_c.alpha = 0;
1179 mask_c.red =
1180 mask_c.green =
1181 mask_c.blue = 0xffff * (shade - 100) / 100;
1175 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); 1182 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1176 1183
1177 XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height); 1184 XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1178 } 1185 }
1179 1186
1180 ret = true; 1187 ret = true;
1181 1188
1182 XRenderFreePicture (dpy, mask_pic); 1189 XRenderFreePicture (dpy, mask_pic);
1183 XRenderFreePicture (dpy, overlay_pic); 1190 XRenderFreePicture (dpy, overlay_pic);
1184 XRenderFreePicture (dpy, back_pic); 1191 XRenderFreePicture (dpy, back_pic);
1192 }
1185# endif 1193# endif
1186 }
1187 1194
1188 return ret; 1195 return ret;
1189} 1196}
1190 1197
1191/* 1198/*
1242#if XRENDER 1249#if XRENDER
1243 if (bg_flags & BG_HAS_RENDER) 1250 if (bg_flags & BG_HAS_RENDER)
1244 { 1251 {
1245 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); 1252 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth);
1246 1253
1247 XRenderPictureAttributes pa;
1248
1249 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); 1254 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
1250 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); 1255 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0);
1251 1256
1252 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); 1257 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual);
1253 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); 1258 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, 0);
1254 1259
1255 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); 1260 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height);
1256 1261
1257 XRenderFreePicture (dpy, src); 1262 XRenderFreePicture (dpy, src);
1258 XRenderFreePicture (dpy, dst); 1263 XRenderFreePicture (dpy, dst);
1275 bg_pmap_width = window_width; 1280 bg_pmap_width = window_width;
1276 bg_pmap_height = window_height; 1281 bg_pmap_height = window_height;
1277 } 1282 }
1278 1283
1279 /* straightforward pixmap copy */ 1284 /* straightforward pixmap copy */
1280 while (sx < 0) sx += root_width; 1285 while (sx < 0) sx += root_pmap_width;
1281 while (sy < 0) sy += root_height; 1286 while (sy < 0) sy += root_pmap_height;
1282 1287
1283 gcv.tile = recoded_root_pmap; 1288 gcv.tile = recoded_root_pmap;
1284 gcv.fill_style = FillTiled; 1289 gcv.fill_style = FillTiled;
1285 gcv.ts_x_origin = -sx; 1290 gcv.ts_x_origin = -sx;
1286 gcv.ts_y_origin = -sy; 1291 gcv.ts_y_origin = -sy;
1288 1293
1289 if (gc) 1294 if (gc)
1290 { 1295 {
1291 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); 1296 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height);
1292 result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS); 1297 result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS);
1293 XFreeGC (dpy, gc);
1294 1298
1295 if (!(bg_flags & BG_CLIENT_RENDER)) 1299 if (!(bg_flags & BG_CLIENT_RENDER))
1296 { 1300 {
1297 if ((bg_flags & BG_NEEDS_BLUR) 1301 if (bg_flags & BG_NEEDS_BLUR)
1298 && (bg_flags & BG_HAS_RENDER_CONV))
1299 { 1302 {
1300 if (blur_pixmap (bg_pixmap, visual, window_width, window_height)) 1303 if (blur_pixmap (bg_pixmap, visual, window_width, window_height))
1301 result &= ~BG_NEEDS_BLUR; 1304 result &= ~BG_NEEDS_BLUR;
1302 } 1305 }
1303 if ((bg_flags & BG_NEEDS_TINT) 1306 if (bg_flags & BG_NEEDS_TINT)
1304 && (bg_flags & (BG_TINT_BITAND | BG_HAS_RENDER)))
1305 { 1307 {
1306 if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) 1308 if (tint_pixmap (bg_pixmap, visual, window_width, window_height))
1307 result &= ~BG_NEEDS_TINT; 1309 result &= ~BG_NEEDS_TINT;
1308 } 1310 }
1311# ifndef HAVE_AFTERIMAGE
1312 if (result & BG_NEEDS_TINT)
1313 {
1314 XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1315 if (ximage)
1316 {
1317 /* our own client-side tinting */
1318 tint_ximage (DefaultVisual (dpy, display->screen), ximage);
1319
1320 XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height);
1321 XDestroyImage (ximage);
1322 }
1323 }
1324# endif
1309 } /* server side rendering completed */ 1325 } /* server side rendering completed */
1326
1327 XFreeGC (dpy, gc);
1310 } 1328 }
1311 1329
1312 if (recoded_root_pmap != root_pixmap) 1330 if (recoded_root_pmap != root_pixmap)
1313 XFreePixmap (dpy, recoded_root_pmap); 1331 XFreePixmap (dpy, recoded_root_pmap);
1314 1332
1323 new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]); 1341 new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]);
1324 1342
1325 root_pixmap = new_root_pixmap; 1343 root_pixmap = new_root_pixmap;
1326} 1344}
1327# endif /* ENABLE_TRANSPARENCY */ 1345# endif /* ENABLE_TRANSPARENCY */
1328
1329#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1330static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c);
1331# endif
1332 1346
1333bool 1347bool
1334rxvt_term::bg_render () 1348rxvt_term::bg_render ()
1335{ 1349{
1336 unsigned long tr_flags = 0; 1350 unsigned long tr_flags = 0;
1341 { 1355 {
1342 /* we need to re-generate transparency pixmap in that case ! */ 1356 /* we need to re-generate transparency pixmap in that case ! */
1343 tr_flags = make_transparency_pixmap (); 1357 tr_flags = make_transparency_pixmap ();
1344 if (tr_flags == 0) 1358 if (tr_flags == 0)
1345 return false; 1359 return false;
1346 else if (!(tr_flags & BG_EFFECTS_FLAGS))
1347 bg_flags |= BG_IS_VALID; 1360 bg_flags |= BG_IS_VALID;
1348 } 1361 }
1349# endif 1362# endif
1350 1363
1351# ifdef BG_IMAGE_FROM_FILE 1364# ifdef BG_IMAGE_FROM_FILE
1352 if ((bg_flags & BG_IS_FROM_FILE) 1365 if ((bg_flags & BG_IS_FROM_FILE)
1353 || (tr_flags & BG_EFFECTS_FLAGS)) 1366 || (tr_flags & BG_EFFECTS_FLAGS))
1354 { 1367 {
1355 if (render_image (tr_flags)) 1368 if (render_image (tr_flags))
1356 bg_flags |= BG_IS_VALID; 1369 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_flags & BG_IS_VALID))
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 {
1373 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1374 if (bg_flags & BG_TINT_SET)
1375 tint.get (c);
1376 shade_ximage (DefaultVisual (dpy, display->screen), result, shade, c);
1377 }
1378
1379 GC gc = XCreateGC (dpy, vt, 0UL, NULL);
1380
1381 if (gc)
1382 {
1383 XPutImage (dpy, bg_pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1384
1385 XFreeGC (dpy, gc);
1386 bg_flags |= BG_IS_VALID;
1387 }
1388
1389 XDestroyImage (result);
1390 } 1370 }
1391# endif 1371# endif
1392 1372
1393 if (!(bg_flags & BG_IS_VALID)) 1373 if (!(bg_flags & BG_IS_VALID))
1394 { 1374 {
1427 bg_flags |= BG_HAS_RENDER_CONV; 1407 bg_flags |= BG_HAS_RENDER_CONV;
1428 1408
1429 XFree (filters); 1409 XFree (filters);
1430 } 1410 }
1431#endif 1411#endif
1432
1433#ifdef HAVE_AFTERIMAGE
1434 set_application_name ((char *)rs[Rs_name]);
1435 set_output_threshold (OUTPUT_LEVEL_WARNING);
1436#endif
1437
1438#ifdef HAVE_PIXBUF
1439 g_type_init ();
1440#endif
1441} 1412}
1442 1413
1443#endif /* HAVE_BG_PIXMAP */ 1414#endif /* HAVE_BG_PIXMAP */
1444 1415
1445#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1416#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1446/* taken from aterm-0.4.2 */ 1417/* based on code from aterm-0.4.2 */
1447 1418
1448static void 1419static inline void
1449shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c) 1420fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high)
1421{
1422 for (int i = 0; i <= mask >> sh; i++)
1423 {
1424 uint32_t tmp;
1425 tmp = i * high;
1426 tmp += (mask >> sh) * low;
1427 lookup[i] = (tmp / 0xffff) << sh;
1428 }
1429}
1430
1431void
1432rxvt_term::tint_ximage (Visual *visual, XImage *ximage)
1450{ 1433{
1451 int sh_r, sh_g, sh_b; 1434 int sh_r, sh_g, sh_b;
1452 uint32_t mask_r, mask_g, mask_b; 1435 uint32_t mask_r, mask_g, mask_b;
1453 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1436 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1454 rgba low; 1437 unsigned short low;
1455 rgba high;
1456 int i;
1457 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; 1438 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
1458 1439
1459 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; 1440 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return;
1460 1441
1461 /* for convenience */ 1442 /* for convenience */
1520 break; 1501 break;
1521 default: 1502 default:
1522 return; /* we do not support this color depth */ 1503 return; /* we do not support this color depth */
1523 } 1504 }
1524 1505
1506 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1507
1508 if (bg_flags & BG_TINT_SET)
1509 tint.get (c);
1510
1525 /* prepare limits for color transformation (each channel is handled separately) */ 1511 /* prepare limits for color transformation (each channel is handled separately) */
1526 if (shade > 100) 1512 if (shade > 100)
1527 { 1513 {
1528 shade = 200 - shade;
1529
1530 high.r = c.r * shade / 100;
1531 high.g = c.g * shade / 100;
1532 high.b = c.b * shade / 100;
1533
1534 low.r = 65535 * (100 - shade) / 100; 1514 c.r = c.r * (200 - shade) / 100;
1535 low.g = 65535 * (100 - shade) / 100; 1515 c.g = c.g * (200 - shade) / 100;
1536 low.b = 65535 * (100 - shade) / 100; 1516 c.b = c.b * (200 - shade) / 100;
1517
1518 low = 0xffff * (shade - 100) / 100;
1537 } 1519 }
1538 else 1520 else
1539 { 1521 {
1540 high.r = c.r * shade / 100; 1522 c.r = c.r * shade / 100;
1541 high.g = c.g * shade / 100; 1523 c.g = c.g * shade / 100;
1542 high.b = c.b * shade / 100; 1524 c.b = c.b * shade / 100;
1543 1525
1544 low.r = low.g = low.b = 0; 1526 low = 0;
1545 } 1527 }
1546 1528
1547 /* fill our lookup tables */ 1529 /* fill our lookup tables */
1548 for (i = 0; i <= mask_r>>sh_r; i++) 1530 fill_lut (lookup_r, mask_r, sh_r, low, c.r);
1549 { 1531 fill_lut (lookup_g, mask_g, sh_g, low, c.g);
1550 uint32_t tmp; 1532 fill_lut (lookup_b, mask_b, sh_b, low, c.b);
1551 tmp = i * high.r;
1552 tmp += (mask_r>>sh_r) * low.r;
1553 lookup_r[i] = (tmp/65535)<<sh_r;
1554 }
1555 for (i = 0; i <= mask_g>>sh_g; i++)
1556 {
1557 uint32_t tmp;
1558 tmp = i * high.g;
1559 tmp += (mask_g>>sh_g) * low.g;
1560 lookup_g[i] = (tmp/65535)<<sh_g;
1561 }
1562 for (i = 0; i <= mask_b>>sh_b; i++)
1563 {
1564 uint32_t tmp;
1565 tmp = i * high.b;
1566 tmp += (mask_b>>sh_b) * low.b;
1567 lookup_b[i] = (tmp/65535)<<sh_b;
1568 }
1569 1533
1570 /* apply table to input image (replacing colors by newly calculated ones) */ 1534 /* apply table to input image (replacing colors by newly calculated ones) */
1571 if (ximage->bits_per_pixel == 32 1535 if (ximage->bits_per_pixel == 32
1572 && (ximage->depth == 24 || ximage->depth == 32) 1536 && (ximage->depth == 24 || ximage->depth == 32)
1573 && ximage->byte_order == host_byte_order) 1537 && ximage->byte_order == host_byte_order)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines