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.222 by sf-exg, Sat May 26 08:10:25 2012 UTC vs.
Revision 1.227 by sf-exg, Thu May 31 14:02:17 2012 UTC

303 h_align = x; 303 h_align = x;
304 v_align = y; 304 v_align = y;
305 changed = true; 305 changed = true;
306 } 306 }
307 307
308 if (!(flags & IM_TILE) 308 if (is_size_sensitive ())
309 || h_scale || v_scale
310 || (!(flags & IM_ROOT_ALIGN) && (h_align || v_align)))
311 flags |= IM_IS_SIZE_SENSITIVE; 309 flags |= IM_IS_SIZE_SENSITIVE;
312 else 310 else
313 flags &= ~IM_IS_SIZE_SENSITIVE; 311 flags &= ~IM_IS_SIZE_SENSITIVE;
314 312
315 return changed; 313 return changed;
605 src_x, src_y, 603 src_x, src_y,
606 dst_x, dst_y, 604 dst_x, dst_y,
607 dst_width, dst_height, need_blend); 605 dst_width, dst_height, need_blend);
608 } 606 }
609 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);
612
610#if XRENDER 613#if XRENDER
611 if (need_blend) 614 if (need_blend)
612 { 615 {
613 XRenderPictFormat *argb_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); 616 XRenderPictFormat *argb_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
614 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 617 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
619 622
620 Picture mask = create_xrender_mask (dpy, vt, False, False); 623 Picture mask = create_xrender_mask (dpy, vt, False, False);
621 624
622 XRenderColor mask_c; 625 XRenderColor mask_c;
623 626
624 mask_c.alpha = gdk_pixbuf_get_has_alpha (image.pixbuf) ? 0xffff : image.alpha; 627 mask_c.alpha = image.alpha;
625 mask_c.red = 628 mask_c.red =
626 mask_c.green = 629 mask_c.green =
627 mask_c.blue = 0; 630 mask_c.blue = 0;
628 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); 631 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1);
629 632
683} 686}
684# endif 687# endif
685 688
686rxvt_image::rxvt_image () 689rxvt_image::rxvt_image ()
687{ 690{
688 alpha = 691 alpha = 0xffff;
689 flags = 692 flags = 0;
690 h_scale = 693 h_scale =
691 v_scale = 694 v_scale = defaultScale;
692 h_align = 695 h_align =
693 v_align = 0; 696 v_align = defaultAlign;
694 697
695# ifdef HAVE_PIXBUF 698# ifdef HAVE_PIXBUF
696 pixbuf = 0; 699 pixbuf = 0;
697# endif 700# endif
698} 701}
714 file = f; 717 file = f;
715 } 718 }
716 719
717 bool ret = set_file (file); 720 bool ret = set_file (file);
718 alpha = 0x8000; 721 alpha = 0x8000;
719 if (ret && p) 722 if (ret)
720 set_geometry (p + 1); 723 set_geometry (p ? p + 1 : "");
721 return ret; 724 return ret;
722} 725}
723 726
724bool 727bool
725rxvt_image::set_file (const char *file) 728rxvt_image::set_file (const char *file)
736 ret = true; 739 ret = true;
737 } 740 }
738# endif 741# endif
739 742
740 if (ret) 743 if (ret)
741 { 744 flags |= IM_IS_SET;
742 alpha = 0xffff;
743 flags = IM_IS_SET | IM_IS_SIZE_SENSITIVE;
744 h_scale = v_scale = defaultScale;
745 h_align = v_align = defaultAlign;
746 }
747 745
748 return ret; 746 return ret;
749} 747}
750 748
751# endif /* BG_IMAGE_FROM_FILE */ 749# endif /* BG_IMAGE_FROM_FILE */
752 750
753# ifdef ENABLE_TRANSPARENCY
754bool 751bool
755rxvt_term::bg_set_blur (const char *geom) 752image_effects::set_blur (const char *geom)
756{ 753{
757 bool changed = false; 754 bool changed = false;
758 unsigned int hr, vr; 755 unsigned int hr, vr;
759 int junk; 756 int junk;
760 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); 757 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
781 778
782 return changed; 779 return changed;
783} 780}
784 781
785bool 782bool
786rxvt_term::bg_set_tint (rxvt_color &new_tint) 783image_effects::set_tint (const rxvt_color &new_tint)
787{ 784{
788 if (!(bg_flags & BG_TINT_SET) || tint != new_tint) 785 if (!tint_set || tint != new_tint)
789 { 786 {
790 tint = new_tint; 787 tint = new_tint;
791 bg_flags |= BG_TINT_SET; 788 tint_set = true;
792
793 rgba c;
794 tint.get (c);
795 if ((c.r <= 0x00ff || c.r >= 0xff00)
796 && (c.g <= 0x00ff || c.g >= 0xff00)
797 && (c.b <= 0x00ff || c.b >= 0xff00))
798 bg_flags |= BG_TINT_BITAND;
799 else
800 bg_flags &= ~BG_TINT_BITAND;
801 789
802 return true; 790 return true;
803 } 791 }
804 792
805 return false; 793 return false;
806} 794}
807 795
808bool 796bool
809rxvt_term::bg_set_shade (const char *shade_str) 797image_effects::set_shade (const char *shade_str)
810{ 798{
811 int new_shade = atoi (shade_str); 799 int new_shade = atoi (shade_str);
812 800
813 clamp_it (new_shade, -100, 200); 801 clamp_it (new_shade, -100, 200);
814 if (new_shade < 0) 802 if (new_shade < 0)
845 params[i+2] = XDoubleToFixed (kernel[i] / sum); 833 params[i+2] = XDoubleToFixed (kernel[i] / sum);
846} 834}
847#endif 835#endif
848 836
849bool 837bool
850rxvt_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)
851{ 839{
852 bool ret = false; 840 bool ret = false;
853#if XRENDER 841#if XRENDER
854 if (!(bg_flags & BG_HAS_RENDER_CONV)) 842 if (!(bg_flags & BG_HAS_RENDER_CONV))
855 return false; 843 return false;
857 int size = max (h_blurRadius, v_blurRadius) * 2 + 1; 845 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
858 double *kernel = (double *)malloc (size * sizeof (double)); 846 double *kernel = (double *)malloc (size * sizeof (double));
859 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 847 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
860 848
861 XRenderPictureAttributes pa; 849 XRenderPictureAttributes pa;
862 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 850 XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32)
851 : XRenderFindVisualFormat (dpy, visual);
863 852
864 pa.repeat = RepeatPad; 853 pa.repeat = RepeatPad;
865 Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); 854 Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa);
866 Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth); 855 Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth);
867 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa); 856 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa);
910#endif 899#endif
911 return ret; 900 return ret;
912} 901}
913 902
914bool 903bool
915rxvt_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)
916{ 905{
917 bool ret = false; 906 bool ret = false;
918 907
919 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))
920 { 917 {
921 XGCValues gcv; 918 XGCValues gcv;
922 GC gc; 919 GC gc;
923 920
924 /* In this case we can tint image server-side getting significant 921 /* In this case we can tint image server-side getting significant
936 } 933 }
937 } 934 }
938# if XRENDER 935# if XRENDER
939 else if (bg_flags & BG_HAS_RENDER) 936 else if (bg_flags & BG_HAS_RENDER)
940 { 937 {
941 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
942
943 if (bg_flags & BG_TINT_SET)
944 tint.get (c);
945
946 if (shade <= 100) 938 if (shade <= 100)
947 { 939 {
948 c.r = c.r * shade / 100; 940 c.r = c.r * shade / 100;
949 c.g = c.g * shade / 100; 941 c.g = c.g * shade / 100;
950 c.b = c.b * shade / 100; 942 c.b = c.b * shade / 100;
954 c.r = c.r * (200 - shade) / 100; 946 c.r = c.r * (200 - shade) / 100;
955 c.g = c.g * (200 - shade) / 100; 947 c.g = c.g * (200 - shade) / 100;
956 c.b = c.b * (200 - shade) / 100; 948 c.b = c.b * (200 - shade) / 100;
957 } 949 }
958 950
959 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 951 XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32)
952 : XRenderFindVisualFormat (dpy, visual);
960 953
961 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0); 954 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0);
962 955
963 Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False); 956 Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False);
964 957
1000# endif 993# endif
1001 994
1002 return ret; 995 return ret;
1003} 996}
1004 997
998# ifdef ENABLE_TRANSPARENCY
1005/* 999/*
1006 * 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
1007 * 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
1008 * our window. 1002 * our window.
1009 */ 1003 */
1100 1094
1101 if (gc) 1095 if (gc)
1102 { 1096 {
1103 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); 1097 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height);
1104 ret = true; 1098 ret = true;
1105 bool need_blur = h_blurRadius && v_blurRadius; 1099 bool need_blur = root_effects.need_blur ();
1106 bool need_tint = shade != 100 || (bg_flags & BG_TINT_SET); 1100 bool need_tint = root_effects.need_tint ();
1107 1101
1108 if (!(bg_flags & BG_CLIENT_RENDER))
1109 {
1110 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)
1111 { 1118 {
1112 if (blur_pixmap (bg_pixmap, window_width, window_height)) 1119 /* our own client-side tinting */
1113 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);
1114 } 1124 }
1115 if (need_tint)
1116 {
1117 if (tint_pixmap (bg_pixmap, window_width, window_height))
1118 need_tint = false;
1119 } 1125 }
1120 if (need_tint)
1121 {
1122 XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1123 if (ximage)
1124 {
1125 /* our own client-side tinting */
1126 tint_ximage (ximage);
1127
1128 XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height);
1129 XDestroyImage (ximage);
1130 }
1131 }
1132 } /* server side rendering completed */
1133 1126
1134 XFreeGC (dpy, gc); 1127 XFreeGC (dpy, gc);
1135 } 1128 }
1136 1129
1137 if (recoded_root_pmap != root_pixmap) 1130 if (recoded_root_pmap != root_pixmap)
1190} 1183}
1191 1184
1192void 1185void
1193rxvt_term::bg_init () 1186rxvt_term::bg_init ()
1194{ 1187{
1195#ifdef ENABLE_TRANSPARENCY
1196 shade = 100;
1197#endif
1198
1199 bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV); 1188 bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV);
1200#if XRENDER 1189#if XRENDER
1201 int major, minor; 1190 int major, minor;
1202 if (XRenderQueryVersion (dpy, &major, &minor)) 1191 if (XRenderQueryVersion (dpy, &major, &minor))
1203 bg_flags |= BG_HAS_RENDER; 1192 bg_flags |= BG_HAS_RENDER;
1226 while (bg_image != image_vec.end ()) 1215 while (bg_image != image_vec.end ())
1227 { 1216 {
1228 if (!(bg_image->flags & IM_IS_SET)) 1217 if (!(bg_image->flags & IM_IS_SET))
1229 bg_image = image_vec.erase (bg_image); 1218 bg_image = image_vec.erase (bg_image);
1230 else 1219 else
1220 {
1221 if (bg_image->is_size_sensitive ())
1222 bg_image->flags |= IM_IS_SIZE_SENSITIVE;
1223
1231 bg_image++; 1224 bg_image++;
1225 }
1232 } 1226 }
1233# endif 1227# endif
1234 1228
1235 if (image_vec.size () > 0 1229 if (image_vec.size () > 0
1236 && !bg_window_position_sensitive ()) 1230 && !bg_window_position_sensitive ())
1237 update_background (); 1231 update_background ();
1238#endif 1232#endif
1239} 1233}
1240 1234
1241#endif /* HAVE_BG_PIXMAP */
1242
1243#ifdef ENABLE_TRANSPARENCY
1244/* based on code from aterm-0.4.2 */ 1235/* based on code from aterm-0.4.2 */
1245 1236
1246static inline void 1237static inline void
1247fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high) 1238fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high)
1248{ 1239{
1254 lookup[i] = (tmp / 0xffff) << sh; 1245 lookup[i] = (tmp / 0xffff) << sh;
1255 } 1246 }
1256} 1247}
1257 1248
1258void 1249void
1259rxvt_term::tint_ximage (XImage *ximage) 1250rxvt_term::tint_ximage (XImage *ximage, rxvt_color &tint, bool tint_set, int shade)
1260{ 1251{
1261 unsigned int size_r, size_g, size_b; 1252 unsigned int size_r, size_g, size_b;
1262 int sh_r, sh_g, sh_b; 1253 int sh_r, sh_g, sh_b;
1263 uint32_t mask_r, mask_g, mask_b; 1254 uint32_t mask_r, mask_g, mask_b;
1264 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1255 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1289 lookup_g = lookup + size_r; 1280 lookup_g = lookup + size_r;
1290 lookup_b = lookup + size_r + size_g; 1281 lookup_b = lookup + size_r + size_g;
1291 1282
1292 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); 1283 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1293 1284
1294 if (bg_flags & BG_TINT_SET) 1285 if (tint_set)
1295 tint.get (c); 1286 tint.get (c);
1296 1287
1297 /* prepare limits for color transformation (each channel is handled separately) */ 1288 /* prepare limits for color transformation (each channel is handled separately) */
1298 if (shade > 100) 1289 if (shade > 100)
1299 { 1290 {
1349 } 1340 }
1350 } 1341 }
1351 1342
1352 free (lookup); 1343 free (lookup);
1353} 1344}
1354#endif /* ENABLE_TRANSPARENCY */ 1345
1346#endif /* HAVE_BG_PIXMAP */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines