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.225 by sf-exg, Wed May 30 21:20:05 2012 UTC vs.
Revision 1.230 by sf-exg, Sun Jun 3 15:50:22 2012 UTC

484 return false; 484 return false;
485 485
486 bool need_blend = bg_flags & BG_IS_VALID; 486 bool need_blend = bg_flags & BG_IS_VALID;
487 487
488 if (need_blend 488 if (need_blend
489 && !(bg_flags & BG_HAS_RENDER)) 489 && !(display->flags & DISPLAY_HAS_RENDER))
490 return false; 490 return false;
491 491
492 GdkPixbuf *result; 492 GdkPixbuf *result;
493 493
494 int image_width = gdk_pixbuf_get_width (pixbuf); 494 int image_width = gdk_pixbuf_get_width (pixbuf);
602 pixbuf_to_pixmap (result, tmp_pixmap, gc, 602 pixbuf_to_pixmap (result, tmp_pixmap, gc,
603 src_x, src_y, 603 src_x, src_y,
604 dst_x, dst_y, 604 dst_x, dst_y,
605 dst_width, dst_height, need_blend); 605 dst_width, dst_height, need_blend);
606 } 606 }
607
608 if (image.need_blur ())
609 blur_pixmap (tmp_pixmap, new_pmap_width, new_pmap_height, need_blend, image.h_blurRadius, image.v_blurRadius);
610 if (image.need_tint ())
611 tint_pixmap (tmp_pixmap, new_pmap_width, new_pmap_height, need_blend, image.tint, image.tint_set, image.shade);
607 612
608#if XRENDER 613#if XRENDER
609 if (need_blend) 614 if (need_blend)
610 { 615 {
611 XRenderPictFormat *argb_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); 616 XRenderPictFormat *argb_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
668 if (id >= 1) 673 if (id >= 1)
669 GET_R->parse_image (id, XrmQuarkToString (quarks[size-1]), (char *)value->addr); 674 GET_R->parse_image (id, XrmQuarkToString (quarks[size-1]), (char *)value->addr);
670 } 675 }
671 return False; 676 return False;
672} 677}
678# endif
673 679
674void 680void
675rxvt_term::parse_image (int id, const char *type, const char *arg) 681rxvt_term::parse_image (int id, const char *type, const char *arg)
676{ 682{
677 if (image_vec.size () < id + 1) 683 if (image_vec.size () < id + 1)
678 image_vec.resize (id + 1); 684 image_vec.resize (id + 1);
679 685
680 rxvt_image *image = &image_vec[id]; 686 rxvt_image *image = &image_vec[id];
681} 687}
682# endif
683 688
684rxvt_image::rxvt_image () 689rxvt_image::rxvt_image ()
685{ 690{
686 alpha = 0xffff; 691 alpha = 0xffff;
687 flags = 0; 692 flags = 0;
741 return ret; 746 return ret;
742} 747}
743 748
744# endif /* BG_IMAGE_FROM_FILE */ 749# endif /* BG_IMAGE_FROM_FILE */
745 750
746# ifdef ENABLE_TRANSPARENCY
747bool 751bool
748rxvt_term::bg_set_blur (const char *geom) 752image_effects::set_blur (const char *geom)
749{ 753{
750 bool changed = false; 754 bool changed = false;
751 unsigned int hr, vr; 755 unsigned int hr, vr;
752 int junk; 756 int junk;
753 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); 757 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
774 778
775 return changed; 779 return changed;
776} 780}
777 781
778bool 782bool
779rxvt_term::bg_set_tint (rxvt_color &new_tint) 783image_effects::set_tint (const rxvt_color &new_tint)
780{ 784{
781 if (!(bg_flags & BG_TINT_SET) || tint != new_tint) 785 if (!tint_set || tint != new_tint)
782 { 786 {
783 tint = new_tint; 787 tint = new_tint;
784 bg_flags |= BG_TINT_SET; 788 tint_set = true;
785
786 rgba c;
787 tint.get (c);
788 if ((c.r <= 0x00ff || c.r >= 0xff00)
789 && (c.g <= 0x00ff || c.g >= 0xff00)
790 && (c.b <= 0x00ff || c.b >= 0xff00))
791 bg_flags |= BG_TINT_BITAND;
792 else
793 bg_flags &= ~BG_TINT_BITAND;
794 789
795 return true; 790 return true;
796 } 791 }
797 792
798 return false; 793 return false;
799} 794}
800 795
801bool 796bool
802rxvt_term::bg_set_shade (const char *shade_str) 797image_effects::set_shade (const char *shade_str)
803{ 798{
804 int new_shade = atoi (shade_str); 799 int new_shade = atoi (shade_str);
805 800
806 clamp_it (new_shade, -100, 200); 801 clamp_it (new_shade, -100, 200);
807 if (new_shade < 0) 802 if (new_shade < 0)
838 params[i+2] = XDoubleToFixed (kernel[i] / sum); 833 params[i+2] = XDoubleToFixed (kernel[i] / sum);
839} 834}
840#endif 835#endif
841 836
842bool 837bool
843rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height) 838rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height, bool argb, int h_blurRadius, int v_blurRadius)
844{ 839{
845 bool ret = false; 840 bool ret = false;
846#if XRENDER 841#if XRENDER
847 if (!(bg_flags & BG_HAS_RENDER_CONV)) 842 if (!(display->flags & DISPLAY_HAS_RENDER_CONV))
848 return false; 843 return false;
849 844
850 int size = max (h_blurRadius, v_blurRadius) * 2 + 1; 845 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
851 double *kernel = (double *)malloc (size * sizeof (double)); 846 double *kernel = (double *)malloc (size * sizeof (double));
852 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 847 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
853 848
854 XRenderPictureAttributes pa; 849 XRenderPictureAttributes pa;
855 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 850 XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32)
851 : XRenderFindVisualFormat (dpy, visual);
856 852
857 pa.repeat = RepeatPad; 853 pa.repeat = RepeatPad;
858 Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); 854 Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa);
859 Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth); 855 Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth);
860 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa); 856 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa);
903#endif 899#endif
904 return ret; 900 return ret;
905} 901}
906 902
907bool 903bool
908rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height) 904rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height, bool argb, rxvt_color &tint, bool tint_set, int shade)
909{ 905{
910 bool ret = false; 906 bool ret = false;
911 907
912 if (shade == 100 && (bg_flags & BG_TINT_BITAND)) 908 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
909
910 if (tint_set)
911 tint.get (c);
912
913 if (shade == 100
914 && (c.r <= 0x00ff || c.r >= 0xff00)
915 && (c.g <= 0x00ff || c.g >= 0xff00)
916 && (c.b <= 0x00ff || c.b >= 0xff00))
913 { 917 {
914 XGCValues gcv; 918 XGCValues gcv;
915 GC gc; 919 GC gc;
916 920
917 /* In this case we can tint image server-side getting significant 921 /* In this case we can tint image server-side getting significant
927 ret = true; 931 ret = true;
928 XFreeGC (dpy, gc); 932 XFreeGC (dpy, gc);
929 } 933 }
930 } 934 }
931# if XRENDER 935# if XRENDER
932 else if (bg_flags & BG_HAS_RENDER) 936 else if (display->flags & DISPLAY_HAS_RENDER)
933 { 937 {
934 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
935
936 if (bg_flags & BG_TINT_SET)
937 tint.get (c);
938
939 if (shade <= 100) 938 if (shade <= 100)
940 { 939 {
941 c.r = c.r * shade / 100; 940 c.r = c.r * shade / 100;
942 c.g = c.g * shade / 100; 941 c.g = c.g * shade / 100;
943 c.b = c.b * shade / 100; 942 c.b = c.b * shade / 100;
947 c.r = c.r * (200 - shade) / 100; 946 c.r = c.r * (200 - shade) / 100;
948 c.g = c.g * (200 - shade) / 100; 947 c.g = c.g * (200 - shade) / 100;
949 c.b = c.b * (200 - shade) / 100; 948 c.b = c.b * (200 - shade) / 100;
950 } 949 }
951 950
952 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 951 XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32)
952 : XRenderFindVisualFormat (dpy, visual);
953 953
954 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0); 954 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0);
955 955
956 Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False); 956 Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False);
957 957
993# endif 993# endif
994 994
995 return ret; 995 return ret;
996} 996}
997 997
998# ifdef ENABLE_TRANSPARENCY
998/* 999/*
999 * Builds a pixmap of the same size as the terminal window that contains 1000 * Builds a pixmap of the same size as the terminal window that contains
1000 * the tiled portion of the root pixmap that is supposed to be covered by 1001 * the tiled portion of the root pixmap that is supposed to be covered by
1001 * our window. 1002 * our window.
1002 */ 1003 */
1003bool 1004bool
1004rxvt_term::make_transparency_pixmap () 1005rxvt_term::render_root_image ()
1005{ 1006{
1006 bool ret = false; 1007 bool ret = false;
1007 1008
1008 /* root dimensions may change from call to call - but Display structure should 1009 /* root dimensions may change from call to call - but Display structure should
1009 * be always up-to-date, so let's use it : 1010 * be always up-to-date, so let's use it :
1045 Pixmap recoded_root_pmap = root_pixmap; 1046 Pixmap recoded_root_pmap = root_pixmap;
1046 1047
1047 if (root_pixmap != None && root_depth != depth) 1048 if (root_pixmap != None && root_depth != depth)
1048 { 1049 {
1049#if XRENDER 1050#if XRENDER
1050 if (bg_flags & BG_HAS_RENDER) 1051 if (display->flags & DISPLAY_HAS_RENDER)
1051 { 1052 {
1052 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); 1053 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth);
1053 1054
1054 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); 1055 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
1055 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0); 1056 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0);
1093 1094
1094 if (gc) 1095 if (gc)
1095 { 1096 {
1096 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); 1097 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height);
1097 ret = true; 1098 ret = true;
1098 bool need_blur = h_blurRadius && v_blurRadius; 1099 bool need_blur = root_effects.need_blur ();
1099 bool need_tint = shade != 100 || (bg_flags & BG_TINT_SET); 1100 bool need_tint = root_effects.need_tint ();
1100 1101
1101 if (!(bg_flags & BG_CLIENT_RENDER))
1102 {
1103 if (need_blur) 1102 if (need_blur)
1103 {
1104 if (blur_pixmap (bg_pixmap, window_width, window_height, false,
1105 root_effects.h_blurRadius, root_effects.v_blurRadius))
1106 need_blur = false;
1107 }
1108 if (need_tint)
1109 {
1110 if (tint_pixmap (bg_pixmap, window_width, window_height, false,
1111 root_effects.tint, root_effects.tint_set, root_effects.shade))
1112 need_tint = false;
1113 }
1114 if (need_tint)
1115 {
1116 XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1117 if (ximage)
1104 { 1118 {
1105 if (blur_pixmap (bg_pixmap, window_width, window_height)) 1119 /* our own client-side tinting */
1106 need_blur = false; 1120 tint_ximage (ximage, root_effects.tint, root_effects.tint_set, root_effects.shade);
1121
1122 XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height);
1123 XDestroyImage (ximage);
1107 } 1124 }
1108 if (need_tint)
1109 {
1110 if (tint_pixmap (bg_pixmap, window_width, window_height))
1111 need_tint = false;
1112 } 1125 }
1113 if (need_tint)
1114 {
1115 XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1116 if (ximage)
1117 {
1118 /* our own client-side tinting */
1119 tint_ximage (ximage);
1120
1121 XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height);
1122 XDestroyImage (ximage);
1123 }
1124 }
1125 } /* server side rendering completed */
1126 1126
1127 XFreeGC (dpy, gc); 1127 XFreeGC (dpy, gc);
1128 } 1128 }
1129 1129
1130 if (recoded_root_pmap != root_pixmap) 1130 if (recoded_root_pmap != root_pixmap)
1150 bg_invalidate (); 1150 bg_invalidate ();
1151# ifdef ENABLE_TRANSPARENCY 1151# ifdef ENABLE_TRANSPARENCY
1152 if (bg_flags & BG_IS_TRANSPARENT) 1152 if (bg_flags & BG_IS_TRANSPARENT)
1153 { 1153 {
1154 /* we need to re-generate transparency pixmap in that case ! */ 1154 /* we need to re-generate transparency pixmap in that case ! */
1155 if (make_transparency_pixmap ()) 1155 if (render_root_image ())
1156 bg_flags |= BG_IS_VALID; 1156 bg_flags |= BG_IS_VALID;
1157 } 1157 }
1158# endif 1158# endif
1159 1159
1160# ifdef BG_IMAGE_FROM_FILE 1160# ifdef BG_IMAGE_FROM_FILE
1183} 1183}
1184 1184
1185void 1185void
1186rxvt_term::bg_init () 1186rxvt_term::bg_init ()
1187{ 1187{
1188#ifdef ENABLE_TRANSPARENCY
1189 shade = 100;
1190#endif
1191
1192 bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV);
1193#if XRENDER
1194 int major, minor;
1195 if (XRenderQueryVersion (dpy, &major, &minor))
1196 bg_flags |= BG_HAS_RENDER;
1197 XFilters *filters = XRenderQueryFilters (dpy, vt);
1198 if (filters)
1199 {
1200 for (int i = 0; i < filters->nfilter; i++)
1201 if (!strcmp (filters->filter[i], FilterConvolution))
1202 bg_flags |= BG_HAS_RENDER_CONV;
1203
1204 XFree (filters);
1205 }
1206#endif
1207
1208#ifdef BG_IMAGE_FROM_FILE 1188#ifdef BG_IMAGE_FROM_FILE
1209 if (rs[Rs_backgroundPixmap]) 1189 if (rs[Rs_backgroundPixmap])
1210 { 1190 {
1211 rxvt_image *image = new_image (); 1191 rxvt_image *image = new_image ();
1212 if (!image->set_file_geometry (rs[Rs_backgroundPixmap])) 1192 if (!image->set_file_geometry (rs[Rs_backgroundPixmap]))
1213 image_vec.pop_back (); 1193 image_vec.pop_back ();
1214 } 1194 }
1215 1195
1216# ifndef NO_RESOURCES 1196# ifndef NO_RESOURCES
1217 find_resources ("image", "Image", XrmEnumAllLevels, rxvt_define_image); 1197 find_resources ("image", "Image", XrmEnumAllLevels, rxvt_define_image);
1198# endif
1199
1218 vector<rxvt_image>::iterator bg_image = image_vec.begin (); 1200 vector<rxvt_image>::iterator bg_image = image_vec.begin ();
1219 while (bg_image != image_vec.end ()) 1201 while (bg_image != image_vec.end ())
1220 { 1202 {
1221 if (!(bg_image->flags & IM_IS_SET)) 1203 if (!(bg_image->flags & IM_IS_SET))
1222 bg_image = image_vec.erase (bg_image); 1204 bg_image = image_vec.erase (bg_image);
1226 bg_image->flags |= IM_IS_SIZE_SENSITIVE; 1208 bg_image->flags |= IM_IS_SIZE_SENSITIVE;
1227 1209
1228 bg_image++; 1210 bg_image++;
1229 } 1211 }
1230 } 1212 }
1231# endif
1232 1213
1233 if (image_vec.size () > 0 1214 if (image_vec.size () > 0
1234 && !bg_window_position_sensitive ()) 1215 && !bg_window_position_sensitive ())
1235 update_background (); 1216 update_background ();
1236#endif 1217#endif
1237} 1218}
1238 1219
1239#endif /* HAVE_BG_PIXMAP */
1240
1241#ifdef ENABLE_TRANSPARENCY
1242/* based on code from aterm-0.4.2 */ 1220/* based on code from aterm-0.4.2 */
1243 1221
1244static inline void 1222static inline void
1245fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high) 1223fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high)
1246{ 1224{
1252 lookup[i] = (tmp / 0xffff) << sh; 1230 lookup[i] = (tmp / 0xffff) << sh;
1253 } 1231 }
1254} 1232}
1255 1233
1256void 1234void
1257rxvt_term::tint_ximage (XImage *ximage) 1235rxvt_term::tint_ximage (XImage *ximage, rxvt_color &tint, bool tint_set, int shade)
1258{ 1236{
1259 unsigned int size_r, size_g, size_b; 1237 unsigned int size_r, size_g, size_b;
1260 int sh_r, sh_g, sh_b; 1238 int sh_r, sh_g, sh_b;
1261 uint32_t mask_r, mask_g, mask_b; 1239 uint32_t mask_r, mask_g, mask_b;
1262 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1240 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1287 lookup_g = lookup + size_r; 1265 lookup_g = lookup + size_r;
1288 lookup_b = lookup + size_r + size_g; 1266 lookup_b = lookup + size_r + size_g;
1289 1267
1290 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); 1268 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1291 1269
1292 if (bg_flags & BG_TINT_SET) 1270 if (tint_set)
1293 tint.get (c); 1271 tint.get (c);
1294 1272
1295 /* prepare limits for color transformation (each channel is handled separately) */ 1273 /* prepare limits for color transformation (each channel is handled separately) */
1296 if (shade > 100) 1274 if (shade > 100)
1297 { 1275 {
1347 } 1325 }
1348 } 1326 }
1349 1327
1350 free (lookup); 1328 free (lookup);
1351} 1329}
1352#endif /* ENABLE_TRANSPARENCY */ 1330
1331#endif /* HAVE_BG_PIXMAP */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines