ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/xpm.C
(Generate patch)

Comparing rxvt-unicode/src/xpm.C (file contents):
Revision 1.66 by sasha, Mon Aug 13 22:41:34 2007 UTC vs.
Revision 1.71 by sasha, Fri Aug 17 22:01:33 2007 UTC

84 } 84 }
85# endif 85# endif
86# ifdef ENABLE_TRANSPARENCY 86# ifdef ENABLE_TRANSPARENCY
87 if (flags & isTransparent) 87 if (flags & isTransparent)
88 return true; 88 return true;
89# endif
90 return false;
91}
92
93bool bgPixmap_t::need_client_side_rendering ()
94{
95# ifdef HAVE_AFTERIMAGE
96 if (original_asim != NULL)
97 return true;
98# endif
99# ifdef ENABLE_TRANSPARENCY
100 if (flags & isTransparent)
101 {
102 if ((flags & blurNeeded)
103 || ((flags & tintNeeded) && !(flags & tintServerSide)))
104 return true;
105 }
89# endif 106# endif
90 return false; 107 return false;
91} 108}
92 109
93# ifdef XPM_BACKGROUND 110# ifdef XPM_BACKGROUND
597 if (v_blurRadius != vr) 614 if (v_blurRadius != vr)
598 { 615 {
599 ++changed; 616 ++changed;
600 v_blurRadius = vr; 617 v_blurRadius = vr;
601 } 618 }
619 if (v_blurRadius == 0 && h_blurRadius == 0)
620 flags &= ~blurNeeded;
621 else
622 flags |= blurNeeded;
602 return (changed>0); 623 return (changed>0);
603} 624}
604 625
605static inline unsigned long 626static inline unsigned long
606compute_tint_shade_flags (rxvt_color *tint, int shade) 627compute_tint_shade_flags (rxvt_color *tint, int shade)
612 else if (tint) 633 else if (tint)
613 { 634 {
614 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 635 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
615 tint->get (c); 636 tint->get (c);
616 637
617 flags |= bgPixmap_t::tintNeeded;
618 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) 638 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700)
619 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) 639 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700))
620 { 640 {
621 flags |= bgPixmap_t::tintNeeded; 641 flags |= bgPixmap_t::tintNeeded;
622#define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700) 642# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700)
623 if (IS_COMPONENT_WHOLESOME (c.r) 643 if (IS_COMPONENT_WHOLESOME (c.r)
624 && IS_COMPONENT_WHOLESOME (c.g) 644 && IS_COMPONENT_WHOLESOME (c.g)
625 && IS_COMPONENT_WHOLESOME (c.b)) 645 && IS_COMPONENT_WHOLESOME (c.b))
626 flags |= bgPixmap_t::tintServerSide; 646 flags |= bgPixmap_t::tintServerSide;
627#undef IS_COMPONENT_WHOLESOME 647# undef IS_COMPONENT_WHOLESOME
628 } 648 }
629 } 649 }
630 return flags; 650 return flags;
631} 651}
632 652
791 } 811 }
792 } 812 }
793 813
794 if (tiled_root_pmap != None) 814 if (tiled_root_pmap != None)
795 { 815 {
796 if (flags & tintNeeded) 816 if (flags & tintNeeded && !need_client_side_rendering ())
797 { 817 {
798 if ((flags & tintServerSide)
799 && h_blurRadius <= 1 && v_blurRadius <= 1
800# ifdef HAVE_AFTERIMAGE
801 && original_asim == NULL
802# endif
803 )
804 { /* In this case we can tint image server-side getting significant 818 /* In this case we can tint image server-side getting significant
805 * performance improvements, as we eliminate XImage transfer 819 * performance improvements, as we eliminate XImage transfer
806 */ 820 */
807 gcv.foreground = Pixel (tint); 821 gcv.foreground = Pixel (tint);
808 gcv.function = GXand; 822 gcv.function = GXand;
809 gcv.fill_style = FillSolid; 823 gcv.fill_style = FillSolid;
810 if (gc) 824 if (gc)
811 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcv); 825 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcv);
812 else 826 else
813 gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv); 827 gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv);
814 if (gc) 828 if (gc)
815 { 829 {
816 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); 830 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
817 result |= transpPmapTinted; 831 result |= transpPmapTinted;
818 }
819 } 832 }
820 } 833 }
821 if (pixmap) 834 if (pixmap)
822 XFreePixmap (dpy, pixmap); 835 XFreePixmap (dpy, pixmap);
823 pixmap = tiled_root_pmap; 836 pixmap = tiled_root_pmap;
848 } 861 }
849 return false; 862 return false;
850} 863}
851# endif /* ENABLE_TRANSPARENCY */ 864# endif /* ENABLE_TRANSPARENCY */
852 865
866# ifndef HAVE_AFTERIMAGE
867static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm);
868# endif
869
870
853bool 871bool
854bgPixmap_t::render () 872bgPixmap_t::render ()
855{ 873{
856 unsigned long background_flags = 0; 874 unsigned long background_flags = 0;
857 875
864 { 882 {
865 /* we need to re-generate transparency pixmap in that case ! */ 883 /* we need to re-generate transparency pixmap in that case ! */
866 background_flags = make_transparency_pixmap (); 884 background_flags = make_transparency_pixmap ();
867 if (background_flags == 0) 885 if (background_flags == 0)
868 return false; 886 return false;
887 else if ((background_flags & transpTransformations) == (flags & transpTransformations)
888 && pmap_depth == target->depth)
889 flags = flags & ~isInvalid;
869 } 890 }
870# endif 891# endif
871 892
872 XImage *result = NULL; 893 XImage *result = NULL;
873# ifdef HAVE_AFTERIMAGE 894# ifdef HAVE_AFTERIMAGE
877 ASImage *background = NULL; 898 ASImage *background = NULL;
878 ARGB32 as_tint = TINT_LEAVE_SAME; 899 ARGB32 as_tint = TINT_LEAVE_SAME;
879 if (background_flags) 900 if (background_flags)
880 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100); 901 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100);
881 902
903# ifdef ENABLE_TRANSPARENCY
882 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 904 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
883 { 905 {
884 ShadingInfo as_shade; 906 ShadingInfo as_shade;
885 as_shade.shading = (shade == 0) ? 100 : shade; 907 as_shade.shading = (shade == 0) ? 100 : shade;
886 908
887 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 909 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
910 if (flags & tintSet)
888 tint.get (c); 911 tint.get (c);
889 as_shade.tintColor.red = c.r; 912 as_shade.tintColor.red = c.r;
890 as_shade.tintColor.green = c.g; 913 as_shade.tintColor.green = c.g;
891 as_shade.tintColor.blue = c.b; 914 as_shade.tintColor.blue = c.b;
892 915
893 as_tint = shading2tint32 (&as_shade); 916 as_tint = shading2tint32 (&as_shade);
894 } 917 }
918 if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL)
919 {
920 ASImage* tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
921 (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage,
922 100, ASIMAGE_QUALITY_DEFAULT);
923 if (tmp)
924 {
925 destroy_asimage (&background);
926 background = tmp;
927 }
928 }
929# endif
930
895 if (render_asim (background, as_tint)) 931 if (render_asim (background, as_tint))
896 flags = flags & ~isInvalid; 932 flags = flags & ~isInvalid;
897 if (background) 933 if (background)
898 destroy_asimage (&background); 934 destroy_asimage (&background);
899 } 935 }
900 else if (background_flags && pmap_depth != target->depth) 936 else if (background_flags && pmap_depth != target->depth)
901 { 937 {
902 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 938 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
903 } 939 }
904# else /* our own client-side tinting */ 940# else /* our own client-side tinting */
905 if (background_flags && 941 if (background_flags && (flags & isInvalid))
906 (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) || pmap_depth != target->depth)
907 { 942 {
908 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 943 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
909 success = False;
910 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded)) 944 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded))
911 { 945 {
912 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 946 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
947 if (flags & tintSet)
913 tint.get (c); 948 tint.get (c);
914 ShadeXImage (this, result, shade, c.r, c.g, c.b); 949 ShadeXImage (target, result, shade, c.r, c.g, c.b);
915 } 950 }
916 } 951 }
917# endif 952# endif /* HAVE_AFTERIMAGE */
918 if (result != NULL) 953 if (result != NULL)
919 { 954 {
920 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 955 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
921 if (gc) 956 if (gc)
922 { 957 {
923 if (pmap_depth != target->depth && pixmap != None) 958 if (/*pmap_depth != target->depth &&*/ pixmap != None)
924 { 959 {
925 XFreePixmap (target->dpy, pixmap); 960 XFreePixmap (target->dpy, pixmap);
926 pixmap = None; 961 pixmap = None;
927 } 962 }
928 if (pixmap == None) 963 if (pixmap == None)
930 pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth); 965 pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth);
931 pmap_width = result->width; 966 pmap_width = result->width;
932 pmap_height = result->height; 967 pmap_height = result->height;
933 pmap_depth = target->depth; 968 pmap_depth = target->depth;
934 } 969 }
970 if (pmap_depth != result->depth)
971 { /* Bad Match error will ensue ! stupid X !!!! */
972 if( result->depth == 24 && pmap_depth == 32)
973 result->depth = 32;
974 else if( result->depth == 32 && pmap_depth == 24)
975 result->depth = 24;
976 else
977 {
978 /* TODO: implement image recoding */
979 }
980 }
981 if (pmap_depth == result->depth)
935 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); 982 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
936 XFreeGC (target->dpy, gc); 983 XFreeGC (target->dpy, gc);
937 flags = flags & ~isInvalid; 984 flags = flags & ~isInvalid;
938 } 985 }
939 XDestroyImage (result); 986 XDestroyImage (result);
940 } 987 }
944 if (pixmap != None) 991 if (pixmap != None)
945 { 992 {
946 XFreePixmap (target->dpy, pixmap); 993 XFreePixmap (target->dpy, pixmap);
947 pixmap = None; 994 pixmap = None;
948 } 995 }
949// TODO : we need to get rid of that garbadge :
950 target->am_transparent = target->am_pixmap_trans = 0;
951 } 996 }
952 else
953 target->am_transparent = target->am_pixmap_trans = 1;
954 997
955 apply (); 998 apply ();
956 999
957 return true; 1000 return true;
958} 1001}
1014 } 1057 }
1015 /* don't want Expose on the parent */ 1058 /* don't want Expose on the parent */
1016 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, False); 1059 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, False);
1017 /* do want Expose on the vt */ 1060 /* do want Expose on the vt */
1018 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, True); 1061 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, True);
1019#if HAVE_SCROLLBARS 1062# if HAVE_SCROLLBARS
1020 if (target->scrollBar.win) 1063 if (target->scrollBar.win)
1021 { 1064 {
1022 target->scrollBar.setIdle (); 1065 target->scrollBar.setIdle ();
1023 target->scrollbar_show (0); 1066 target->scrollbar_show (0);
1024 } 1067 }
1025#endif 1068# endif
1069 /* Is that really neccessary? we did a XClearArea to generate Expose events alreday ! */
1070 target->want_refresh = 1;
1071# ifdef ENABLE_TRANSPARENCY
1026 target->want_refresh = target->want_full_refresh = 1; 1072 target->want_full_refresh = 1;
1073# endif
1074 /* TODO: why do we need a flush here ??? It causes segfault on resize ! */
1027 target->flush (); 1075// target->flush ();
1028 } 1076 }
1029} 1077}
1030#endif /* HAVE_BG_PIXMAP */
1031
1032 1078
1033void 1079void
1034rxvt_term::get_window_origin (int &x, int &y) 1080rxvt_term::get_window_origin (int &x, int &y)
1035{ 1081{
1036 Window cr; 1082 Window cr;
1037 XTranslateCoordinates (dpy, parent[0], display->root, 0, 0, &x, &y, &cr); 1083 XTranslateCoordinates (dpy, parent[0], display->root, 0, 0, &x, &y, &cr);
1084/* fprintf( stderr, "origin is %+d%+d\n", x, y);*/
1038} 1085}
1039 1086
1040Pixmap 1087Pixmap
1041rxvt_term::get_pixmap_property (int prop_id) 1088rxvt_term::get_pixmap_property (int prop_id)
1042{ 1089{
1056 } 1103 }
1057 } 1104 }
1058 return None; 1105 return None;
1059} 1106}
1060 1107
1108/*
1109 * Check our parents are still who we think they are.
1110 * Do transparency updates if required
1111 */
1112int
1113rxvt_term::update_background ()
1114{
1115 bgPixmap.invalidate();
1116 /* no chance of real time refresh if we are blurring ! */
1117 if (bgPixmap.invalid_since + 0.5 < NOW && !(bgPixmap.flags & bgPixmap_t::blurNeeded))
1118 bgPixmap.render();
1119 else
1120 {
1121 update_background_ev.stop ();
1122 if (!bgPixmap.need_client_side_rendering())
1123 update_background_ev.start (NOW + .05);
1124 else if (bgPixmap.flags & bgPixmap_t::blurNeeded)
1125 update_background_ev.start (NOW + .2); /* very slow !!! */
1126 else
1127 update_background_ev.start (NOW + .07);
1128 }
1129 return 0;
1130}
1061 1131
1062#ifdef ENABLE_TRANSPARENCY 1132void
1063#ifndef HAVE_AFTERIMAGE 1133rxvt_term::update_background_cb (time_watcher &w)
1134{
1135 bgPixmap.render ();
1136}
1137#endif /* HAVE_BG_PIXMAP */
1138
1139#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1064/* taken from aterm-0.4.2 */ 1140/* taken from aterm-0.4.2 */
1065 1141
1066typedef uint32_t RUINT32T; 1142typedef uint32_t RUINT32T;
1067 1143
1068static void 1144static void
1075 unsigned int upper_lim_r, upper_lim_g, upper_lim_b; 1151 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
1076 int i; 1152 int i;
1077 1153
1078 Visual *visual = term->visual; 1154 Visual *visual = term->visual;
1079 1155
1080 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ; 1156 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ;
1081 1157
1158 if (shade == 0)
1159 shade = 100;
1160
1082 /* for convenience */ 1161 /* for convenience */
1083 mask_r = visual->red_mask; 1162 mask_r = visual->red_mask;
1084 mask_g = visual->green_mask; 1163 mask_g = visual->green_mask;
1085 mask_b = visual->blue_mask; 1164 mask_b = visual->blue_mask;
1086 1165
1288 } 1367 }
1289 } 1368 }
1290 1369
1291 free (lookup); 1370 free (lookup);
1292} 1371}
1293#endif 1372#endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */
1294 1373
1295/* 1374#if 0 /* replaced by a bgPixmap_t::render() - leve here temporarily for reference */
1296 * Check our parents are still who we think they are.
1297 * Do transparency updates if required
1298 */
1299int
1300rxvt_term::check_our_parents ()
1301{
1302 check_our_parents_ev.stop ();
1303 check_our_parents_ev.start (NOW + .1);
1304 return 0;
1305}
1306
1307void 1375void
1308rxvt_term::check_our_parents_cb (time_watcher &w) 1376rxvt_term::check_our_parents_cb (time_watcher &w)
1309{ 1377{
1310#if 0 /* replaced by a bgPixmap_t::render() - leve here temporarily for reference */
1311 1378
1312 int i, aformat, rootdepth; 1379 int i, aformat, rootdepth;
1313 unsigned long nitems, bytes_after; 1380 unsigned long nitems, bytes_after;
1314 Atom atype; 1381 Atom atype;
1315 unsigned char *prop = NULL; 1382 unsigned char *prop = NULL;
1513 want_refresh = want_full_refresh = 1; 1580 want_refresh = want_full_refresh = 1;
1514 if (am_pixmap_trans) 1581 if (am_pixmap_trans)
1515 flush (); 1582 flush ();
1516 } 1583 }
1517 } 1584 }
1585}
1518#endif 1586#endif
1519}
1520#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines