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.65 by sasha, Fri Aug 10 22:10:36 2007 UTC vs.
Revision 1.72 by sasha, Thu Aug 23 20:53:36 2007 UTC

23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *---------------------------------------------------------------------*/ 24 *---------------------------------------------------------------------*/
25 25
26#include "../config.h" /* NECESSARY */ 26#include "../config.h" /* NECESSARY */
27#include "rxvt.h" /* NECESSARY */ 27#include "rxvt.h" /* NECESSARY */
28
29#define DO_TIMING_TEST 0
30
31#if DO_TIMING_TEST
32#define TIMING_TEST_START(id) \
33 struct timeval timing_test_##id##_stv;\
34 gettimeofday (&timing_test_##id##_stv, NULL);
35
36#define TIMING_TEST_PRINT_RESULT(id) \
37 do{ struct timeval tv;gettimeofday (&tv, NULL); tv.tv_sec -= (timing_test_##id##_stv).tv_sec;\
38 fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__,\
39 tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec);}while (0)
40
41#else
42#define TIMING_TEST_START(id) do{}while (0)
43#define TIMING_TEST_PRINT_RESULT(id) do{}while (0)
44#endif
28 45
29/* 46/*
30 * Pixmap geometry string interpretation : 47 * Pixmap geometry string interpretation :
31 * Each geometry string contains zero or one scale/position 48 * Each geometry string contains zero or one scale/position
32 * adjustment and may optionally be followed by a colon and one or more 49 * adjustment and may optionally be followed by a colon and one or more
88 return true; 105 return true;
89# endif 106# endif
90 return false; 107 return false;
91} 108}
92 109
110bool bgPixmap_t::need_client_side_rendering ()
111{
112# ifdef HAVE_AFTERIMAGE
113 if (original_asim != NULL)
114 return true;
115# endif
116# ifdef ENABLE_TRANSPARENCY
117 if (flags & isTransparent)
118 {
119 if ((flags & blurNeeded)
120 || ((flags & tintNeeded) && !(flags & tintServerSide)))
121 return true;
122 }
123# endif
124 return false;
125}
126
93# ifdef XPM_BACKGROUND 127# ifdef XPM_BACKGROUND
94static inline bool 128static inline bool
95check_set_scale_value (int geom_flags, int flag, unsigned int &scale, unsigned int new_value) 129check_set_scale_value (int geom_flags, int flag, unsigned int &scale, unsigned int new_value)
96{ 130{
97 if (geom_flags & flag) 131 if (geom_flags & flag)
359 int x = 0; 393 int x = 0;
360 int y = 0; 394 int y = 0;
361 int w = h_scale * target_width / 100; 395 int w = h_scale * target_width / 100;
362 int h = v_scale * target_height / 100; 396 int h = v_scale * target_height / 100;
363 397
398 TIMING_TEST_START (asim);
399
364 if (original_asim) 400 if (original_asim)
365 { 401 {
366 x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); 402 x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width);
367 y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); 403 y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height);
368 } 404 }
472 result = tmp; 508 result = tmp;
473 } 509 }
474 free (layers); 510 free (layers);
475 } 511 }
476 } 512 }
513 TIMING_TEST_PRINT_RESULT (asim);
477 514
478 if (pixmap) 515 if (pixmap)
479 { 516 {
480 if (result == NULL 517 if (result == NULL
481 || pmap_width != new_pmap_width 518 || pmap_width != new_pmap_width
527 564
528 if (result != background && result != original_asim) 565 if (result != background && result != original_asim)
529 destroy_asimage (&result); 566 destroy_asimage (&result);
530 567
531 XFreeGC (target->dpy, gc); 568 XFreeGC (target->dpy, gc);
569 TIMING_TEST_PRINT_RESULT (asim);
532 } 570 }
533 571
534 return true; 572 return true;
535} 573}
536# endif /* HAVE_AFTERIMAGE */ 574# endif /* HAVE_AFTERIMAGE */
597 if (v_blurRadius != vr) 635 if (v_blurRadius != vr)
598 { 636 {
599 ++changed; 637 ++changed;
600 v_blurRadius = vr; 638 v_blurRadius = vr;
601 } 639 }
640 if (v_blurRadius == 0 && h_blurRadius == 0)
641 flags &= ~blurNeeded;
642 else
643 flags |= blurNeeded;
602 return (changed>0); 644 return (changed>0);
603} 645}
604 646
605static inline unsigned long 647static inline unsigned long
606compute_tint_shade_flags (rxvt_color *tint, int shade) 648compute_tint_shade_flags (rxvt_color *tint, int shade)
607{ 649{
608 unsigned long flags = 0; 650 unsigned long flags = 0;
651 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
609 652
610 if (shade > 0 && shade <100) 653 if (tint)
654 {
655 tint->get (c);
656# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700)
657 if (IS_COMPONENT_WHOLESOME (c.r)
658 && IS_COMPONENT_WHOLESOME (c.g)
659 && IS_COMPONENT_WHOLESOME (c.b))
660 flags |= bgPixmap_t::tintWholesome;
661# undef IS_COMPONENT_WHOLESOME
662 }
663
664 if ((shade > 0 && shade < 100) || (shade > 100 && shade < 200))
611 flags |= bgPixmap_t::tintNeeded; 665 flags |= bgPixmap_t::tintNeeded;
612 else if (tint) 666 else if (tint)
613 { 667 {
614 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
615 tint->get (c);
616
617 flags |= bgPixmap_t::tintNeeded;
618 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) 668 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700)
619 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) 669 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700))
620 { 670 {
621 flags |= bgPixmap_t::tintNeeded; 671 flags |= bgPixmap_t::tintNeeded;
622#define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700)
623 if (IS_COMPONENT_WHOLESOME (c.r)
624 && IS_COMPONENT_WHOLESOME (c.g)
625 && IS_COMPONENT_WHOLESOME (c.b))
626 flags |= bgPixmap_t::tintServerSide;
627#undef IS_COMPONENT_WHOLESOME
628 } 672 }
629 } 673 }
674
675 if (flags & bgPixmap_t::tintNeeded)
676 {
677 if (flags & bgPixmap_t::tintWholesome)
678 flags |= bgPixmap_t::tintServerSide;
679#if XFT
680 /* TODO: add logic for XRENDER tinting */
681 flags |= bgPixmap_t::tintServerSide;
682#endif
683 }
684
630 return flags; 685 return flags;
631} 686}
632 687
633bool 688bool
634bgPixmap_t::set_tint (rxvt_color &new_tint) 689bgPixmap_t::set_tint (rxvt_color &new_tint)
664 if (new_shade == 100) 719 if (new_shade == 100)
665 new_shade = 0; 720 new_shade = 0;
666 721
667 if (new_shade != shade) 722 if (new_shade != shade)
668 { 723 {
669 unsigned long new_flags = compute_tint_shade_flags (&tint, new_shade); 724 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade);
670 shade = new_shade; 725 shade = new_shade;
671 flags = (flags & ~tintFlags) | new_flags; 726 flags = (flags & ~tintFlags) | new_flags;
672 return true; 727 return true;
673 } 728 }
674 return false; 729 return false;
678/* make_transparency_pixmap() 733/* make_transparency_pixmap()
679 * Builds a pixmap sized the same as terminal window, with depth same as the root window 734 * Builds a pixmap sized the same as terminal window, with depth same as the root window
680 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by 735 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by
681 * our window. 736 * our window.
682 */ 737 */
683bool 738unsigned long
684bgPixmap_t::make_transparency_pixmap () 739bgPixmap_t::make_transparency_pixmap ()
685{ 740{
741 unsigned long result = 0;
742
686 if (target == NULL) 743 if (target == NULL)
687 return false; 744 return 0;
688 745
689 /* root dimentions may change from call to call - but Display structure should 746 /* root dimentions may change from call to call - but Display structure should
690 * be always up-to-date, so let's use it : 747 * be always up-to-date, so let's use it :
691 */ 748 */
692 Window root = target->display->root; 749 Window root = target->display->root;
698 int window_width = target->szHint.width; 755 int window_width = target->szHint.width;
699 int window_height = target->szHint.height; 756 int window_height = target->szHint.height;
700 int sx, sy; 757 int sx, sy;
701 XGCValues gcv; 758 XGCValues gcv;
702 759
760 TIMING_TEST_START (tp);
703 target->get_window_origin (sx, sy); 761 target->get_window_origin (sx, sy);
704 762
705 /* check if we are outside of the visible part of the virtual screen : */ 763 /* check if we are outside of the visible part of the virtual screen : */
706 if (sx + window_width <= 0 || sy + window_height <= 0 764 if (sx + window_width <= 0 || sy + window_height <= 0
707 || sx >= root_width || sy >= root_height) 765 || sx >= root_width || sy >= root_height)
708 return false; 766 return 0;
709 767
710 if (root_pixmap != None) 768 if (root_pixmap != None)
711 {/* we want to validate the pixmap and get it's size at the same time : */ 769 {/* we want to validate the pixmap and get it's size at the same time : */
712 int junk; 770 int junk;
713 unsigned int ujunk; 771 unsigned int ujunk;
720 778
721 Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth); 779 Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth);
722 GC gc = NULL; 780 GC gc = NULL;
723 781
724 if (tiled_root_pmap == None) /* something really bad happened - abort */ 782 if (tiled_root_pmap == None) /* something really bad happened - abort */
725 return false; 783 return 0;
726 784
727 if (root_pixmap == None) 785 if (root_pixmap == None)
728 { /* use tricks to obtain the root background image :*/ 786 { /* use tricks to obtain the root background image :*/
729 /* we want to create Overrideredirect window overlapping out window 787 /* we want to create Overrideredirect window overlapping out window
730 with background type of Parent Relative and then grab it */ 788 with background type of Parent Relative and then grab it */
753 while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) 811 while (XCheckWindowEvent (dpy, src, ExposureMask, &event))
754 ++ev_count; 812 ++ev_count;
755 if (ev_count > 0); 813 if (ev_count > 0);
756 { /* hooray! - we can grab the image! */ 814 { /* hooray! - we can grab the image! */
757 gc = XCreateGC (dpy, root, 0, NULL); 815 gc = XCreateGC (dpy, root, 0, NULL);
816 if (gc)
817 {
758 XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0); 818 XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0);
759 success = true; 819 success = true;
820 }
760 } 821 }
761 XDestroyWindow (dpy, src); 822 XDestroyWindow (dpy, src);
762 XUngrabServer (dpy); 823 XUngrabServer (dpy);
763 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); 824 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count);
764 } 825 }
765 if (!success) 826 if (!success)
766 { 827 {
767 XFreePixmap (dpy, tiled_root_pmap); 828 XFreePixmap (dpy, tiled_root_pmap);
768 tiled_root_pmap = None; 829 tiled_root_pmap = None;
769 } 830 }
831 else
832 result |= transpPmapTiled;
770 } 833 }
771 else 834 else
772 {/* strightforward pixmap copy */ 835 {/* strightforward pixmap copy */
773 gcv.tile = root_pixmap; 836 gcv.tile = root_pixmap;
774 gcv.fill_style = FillTiled; 837 gcv.fill_style = FillTiled;
775 while (sx < 0) sx += (int)window_width; 838 while (sx < 0) sx += (int)window_width;
776 while (sy < 0) sy += (int)window_height; 839 while (sy < 0) sy += (int)window_height;
777 gcv.ts_x_origin = -sx; 840 gcv.ts_x_origin = -sx;
778 gcv.ts_y_origin = -sy; 841 gcv.ts_y_origin = -sy;
779 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 842 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
843 if (gc)
844 {
780 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); 845 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
846 result |= transpPmapTiled;
847 }
781 } 848 }
849 TIMING_TEST_PRINT_RESULT (tp);
782 850
783 if (tiled_root_pmap != None) 851 if (tiled_root_pmap != None)
852 {
853 if ((flags & tintNeeded) && !need_client_side_rendering ())
784 { 854 {
785 if (flags & tintNeeded) 855 if (flags & tintWholesome)
786 { 856 {
787 if ((flags & tintServerSide)
788 && h_blurRadius <= 1 && v_blurRadius <= 1
789# ifdef HAVE_AFTERIMAGE
790 && original_asim == NULL
791# endif
792 )
793 { /* In this case we can tint image server-side getting significant 857 /* In this case we can tint image server-side getting significant
794 * performance improvements, as we eliminate XImage transfer 858 * performance improvements, as we eliminate XImage transfer
795 */ 859 */
796 gcv.foreground = Pixel (tint); 860 gcv.foreground = Pixel (tint);
797 gcv.function = GXand; 861 gcv.function = GXand;
798 gcv.fill_style = FillSolid; 862 gcv.fill_style = FillSolid;
799 if (gc) 863 if (gc)
800 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcv); 864 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcv);
801 else 865 else
802 gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv); 866 gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv);
867 if (gc)
868 {
803 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); 869 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
870 result |= transpPmapTinted;
804 } 871 }
805 } 872 }
873 else
874 {
875#if XFT /* TODO : implement proper detection of XRENDER, as XFT may be present without XRENDER ! */
876 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
877 if (flags & tintSet)
878 tint.get (c);
879 if (shade > 0 && shade < 100)
880 {
881 c.r = (c.r * shade) / 100;
882 c.g = (c.g * shade) / 100;
883 c.b = (c.b * shade) / 100;
884 }
885 else if( shade > 100 && shade < 200)
886 {
887 c.r = (c.r * (200 - shade)) / 100;
888 c.g = (c.g * (200 - shade)) / 100;
889 c.b = (c.b * (200 - shade)) / 100;
890 }
891
892 XRenderPictFormat pf;
893 pf.type = PictTypeDirect;
894 pf.depth = 32;
895 pf.direct.redMask = 0xff;
896 pf.direct.greenMask = 0xff;
897 pf.direct.blueMask = 0xff;
898 pf.direct.alphaMask = 0xff;
899
900 XRenderPictFormat *solid_format = XRenderFindFormat (dpy,
901 (PictFormatType|
902 PictFormatDepth|
903 PictFormatRedMask|
904 PictFormatGreenMask|
905 PictFormatBlueMask|
906 PictFormatAlphaMask),
907 &pf,
908 0);
909 XRenderPictFormat *root_format = XRenderFindVisualFormat (dpy, DefaultVisualOfScreen (ScreenOfDisplay (dpy, target->display->screen)));
910 XRenderPictureAttributes pa ;
911
912 Picture back_pic = XRenderCreatePicture (dpy, tiled_root_pmap, root_format, 0, &pa);
913
914 pa.repeat = True;
915
916 Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32);
917 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
918 XFreePixmap (dpy, overlay_pmap);
919
920 pa.component_alpha = True;
921 Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32);
922 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa);
923 XFreePixmap (dpy, mask_pmap);
924
925 if (mask_pic && overlay_pic && back_pic)
926 {
927 XRenderColor mask_c;
928
929 memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof(mask_c));
930 mask_c.alpha = 0xffff;
931 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
932 memset (&mask_c, 0x0, sizeof(mask_c));
933 mask_c.alpha = 0;
934 if (c.r == c.b && c.b == c.g) /* pure shading */
935 {
936 mask_c.red = mask_c.green = mask_c.blue = 0xffff-c.r;
937 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
938 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height);
939 }
940 else
941 {
942 mask_c.red = 0xffff-c.r;
943 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
944 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height);
945 mask_c.red = 0;
946 mask_c.green = 0xffff-c.g;
947 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
948 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height);
949 mask_c.green = 0;
950 mask_c.blue = 0xffff-c.b;
951 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
952 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height);
953 }
954 result |= transpPmapTinted;
955 }
956 XRenderFreePicture (dpy, mask_pic);
957 XRenderFreePicture (dpy, overlay_pic);
958 XRenderFreePicture (dpy, back_pic);
959#endif
960 }
961 }
806 if (pixmap) 962 if (pixmap)
807 XFreePixmap (dpy, pixmap); 963 XFreePixmap (dpy, pixmap);
808 pixmap = tiled_root_pmap; 964 pixmap = tiled_root_pmap;
809 pmap_width = window_width; 965 pmap_width = window_width;
810 pmap_height = window_height; 966 pmap_height = window_height;
811 pmap_depth = root_depth; 967 pmap_depth = root_depth;
812 } 968 }
813 969
814 if (gc) 970 if (gc)
815 XFreeGC (dpy, gc); 971 XFreeGC (dpy, gc);
972
973 TIMING_TEST_PRINT_RESULT (tp);
974
975 return result;
816} 976}
817 977
818bool 978bool
819bgPixmap_t::set_root_pixmap () 979bgPixmap_t::set_root_pixmap ()
820{ 980{
831 } 991 }
832 return false; 992 return false;
833} 993}
834# endif /* ENABLE_TRANSPARENCY */ 994# endif /* ENABLE_TRANSPARENCY */
835 995
996# ifndef HAVE_AFTERIMAGE
997static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm);
998# endif
999
1000
836bool 1001bool
837bgPixmap_t::render_background () 1002bgPixmap_t::render ()
838{ 1003{
839 /* TODO: temporary implementation - need to move check_parents stuff in here */ 1004 unsigned long background_flags = 0;
1005
1006 if (target == NULL)
1007 return false;
1008
1009 invalidate();
840# ifdef ENABLE_TRANSPARENCY 1010# ifdef ENABLE_TRANSPARENCY
841 if (flags & isTransparent) 1011 if (flags & isTransparent)
842 { 1012 {
843 /* we need to re-generate transparency pixmap in that case ! */ 1013 /* we need to re-generate transparency pixmap in that case ! */
844 target->check_our_parents (); 1014 background_flags = make_transparency_pixmap ();
845 return true; 1015 if (background_flags == 0)
1016 return false;
1017 else if ((background_flags & transpTransformations) == (flags & transpTransformations)
1018 && pmap_depth == target->depth)
1019 flags = flags & ~isInvalid;
846 } 1020 }
847# endif 1021# endif
1022
1023 XImage *result = NULL;
848# ifdef HAVE_AFTERIMAGE 1024# ifdef HAVE_AFTERIMAGE
849 render_asim (NULL, TINT_LEAVE_SAME); 1025 if (original_asim
850 apply_background (); 1026 || (background_flags & transpTransformations) != (flags & transpTransformations))
1027 {
1028 ASImage *background = NULL;
1029 ARGB32 as_tint = TINT_LEAVE_SAME;
1030 if (background_flags)
1031 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100);
1032
1033# ifdef ENABLE_TRANSPARENCY
1034 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
1035 {
1036 ShadingInfo as_shade;
1037 as_shade.shading = (shade == 0) ? 100 : shade;
1038
1039 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1040 if (flags & tintSet)
1041 tint.get (c);
1042 as_shade.tintColor.red = c.r;
1043 as_shade.tintColor.green = c.g;
1044 as_shade.tintColor.blue = c.b;
1045
1046 as_tint = shading2tint32 (&as_shade);
1047 }
1048 if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL)
1049 {
1050 ASImage* tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
1051 (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage,
1052 100, ASIMAGE_QUALITY_DEFAULT);
1053 if (tmp)
1054 {
1055 destroy_asimage (&background);
1056 background = tmp;
1057 }
1058 }
1059# endif
1060
1061 if (render_asim (background, as_tint))
1062 flags = flags & ~isInvalid;
1063 if (background)
1064 destroy_asimage (&background);
1065 }
1066 else if (background_flags && pmap_depth != target->depth)
1067 {
1068 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1069 }
1070# else /* our own client-side tinting */
1071 if (background_flags && (flags & isInvalid))
1072 {
1073 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1074 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded))
1075 {
1076 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1077 if (flags & tintSet)
1078 tint.get (c);
1079 ShadeXImage (target, result, shade, c.r, c.g, c.b);
1080 }
1081 }
1082# endif /* HAVE_AFTERIMAGE */
1083 if (result != NULL)
1084 {
1085 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1086 if (gc)
1087 {
1088 if (/*pmap_depth != target->depth &&*/ pixmap != None)
1089 {
1090 XFreePixmap (target->dpy, pixmap);
1091 pixmap = None;
1092 }
1093 if (pixmap == None)
1094 {
1095 pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth);
1096 pmap_width = result->width;
1097 pmap_height = result->height;
1098 pmap_depth = target->depth;
1099 }
1100 if (pmap_depth != result->depth)
1101 { /* Bad Match error will ensue ! stupid X !!!! */
1102 if( result->depth == 24 && pmap_depth == 32)
1103 result->depth = 32;
1104 else if( result->depth == 32 && pmap_depth == 24)
1105 result->depth = 24;
1106 else
1107 {
1108 /* TODO: implement image recoding */
1109 }
1110 }
1111 if (pmap_depth == result->depth)
1112 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1113 XFreeGC (target->dpy, gc);
1114 flags = flags & ~isInvalid;
1115 }
1116 XDestroyImage (result);
1117 }
1118
1119 if (flags & isInvalid)
1120 {
1121 if (pixmap != None)
1122 {
1123 XFreePixmap (target->dpy, pixmap);
1124 pixmap = None;
1125 }
1126 }
1127
1128 apply ();
1129
851 return true; 1130 return true;
852# endif
853 return false;
854} 1131}
855 1132
856bool 1133bool
857bgPixmap_t::set_target (rxvt_term *new_target) 1134bgPixmap_t::set_target (rxvt_term *new_target)
858{ 1135{
867 } 1144 }
868 return false; 1145 return false;
869} 1146}
870 1147
871void 1148void
872bgPixmap_t::apply_background() 1149bgPixmap_t::apply()
873{ 1150{
874 if (target) 1151 if (target)
875 { 1152 {
876 if (pixmap != None) 1153 if (pixmap != None)
877 { /* set target's background to pixmap */ 1154 { /* set target's background to pixmap */
878# ifdef ENABLE_TRANSPARENCY 1155# ifdef ENABLE_TRANSPARENCY
879 if (flags & isTransparent) 1156 if (flags & isTransparent)
880 { 1157 {
881 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); 1158 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
882 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); 1159 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1160# if HAVE_SCROLLBARS
883 if (target->scrollBar.win) 1161 if (target->scrollBar.win)
884 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); 1162 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
1163# endif
885 } 1164 }
886 else 1165 else
887# endif 1166# endif
888 { 1167 {
889 /* force old pixmap dereference in case it was transparent before :*/ 1168 /* force old pixmap dereference in case it was transparent before :*/
890 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_bg]); 1169 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
891 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); 1170 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
892 /* do we also need to set scrollbar's background here ? */ 1171 /* do we also need to set scrollbar's background here ? */
1172# if HAVE_SCROLLBARS
1173 if (target->scrollBar.win)
1174 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1175# endif
893 } 1176 }
894 } 1177 }
895 else 1178 else
896 { /* set target background to a pixel */ 1179 { /* set target background to a pixel */
897 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_bg]); 1180 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
898 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); 1181 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
899 /* do we also need to set scrollbar's background here ? */ 1182 /* do we also need to set scrollbar's background here ? */
1183# if HAVE_SCROLLBARS
1184 if (target->scrollBar.win)
1185 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1186# endif
900 } 1187 }
901 /* don't want Expose on the parent */ 1188 /* don't want Expose on the parent */
902 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, False); 1189 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, False);
903 /* do want Expose on the vt */ 1190 /* do want Expose on the vt */
904 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, True); 1191 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, True);
1192# if HAVE_SCROLLBARS
1193 if (target->scrollBar.win)
1194 {
1195 target->scrollBar.setIdle ();
1196 target->scrollbar_show (0);
1197 }
1198# endif
1199 /* Is that really neccessary? we did a XClearArea to generate Expose events alreday ! */
1200 target->want_refresh = 1;
1201# ifdef ENABLE_TRANSPARENCY
1202 target->want_full_refresh = 1;
1203# endif
1204 /* TODO: why do we need a flush here ??? It causes segfault on resize ! */
1205// target->flush ();
905 } 1206 }
906} 1207}
907#endif /* HAVE_BG_PIXMAP */
908
909 1208
910void 1209void
911rxvt_term::get_window_origin (int &x, int &y) 1210rxvt_term::get_window_origin (int &x, int &y)
912{ 1211{
913 Window cr; 1212 Window cr;
914 XTranslateCoordinates (dpy, parent[0], display->root, 0, 0, &x, &y, &cr); 1213 XTranslateCoordinates (dpy, parent[0], display->root, 0, 0, &x, &y, &cr);
1214/* fprintf( stderr, "origin is %+d%+d\n", x, y);*/
915} 1215}
916 1216
917Pixmap 1217Pixmap
918rxvt_term::get_pixmap_property (int prop_id) 1218rxvt_term::get_pixmap_property (int prop_id)
919{ 1219{
933 } 1233 }
934 } 1234 }
935 return None; 1235 return None;
936} 1236}
937 1237
1238/*
1239 * Check our parents are still who we think they are.
1240 * Do transparency updates if required
1241 */
1242int
1243rxvt_term::update_background ()
1244{
1245 bgPixmap.invalidate();
1246 /* no chance of real time refresh if we are blurring ! */
1247 if (bgPixmap.invalid_since + 0.5 < NOW && !(bgPixmap.flags & bgPixmap_t::blurNeeded))
1248 bgPixmap.render();
1249 else
1250 {
1251 update_background_ev.stop ();
1252 if (!bgPixmap.need_client_side_rendering())
1253 update_background_ev.start (NOW + .05);
1254 else if (bgPixmap.flags & bgPixmap_t::blurNeeded)
1255 update_background_ev.start (NOW + .2); /* very slow !!! */
1256 else
1257 update_background_ev.start (NOW + .07);
1258 }
1259 return 0;
1260}
938 1261
939#ifdef ENABLE_TRANSPARENCY 1262void
940#ifndef HAVE_AFTERIMAGE 1263rxvt_term::update_background_cb (time_watcher &w)
1264{
1265 bgPixmap.render ();
1266}
1267#endif /* HAVE_BG_PIXMAP */
1268
1269#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
941/* taken from aterm-0.4.2 */ 1270/* taken from aterm-0.4.2 */
942 1271
943typedef uint32_t RUINT32T; 1272typedef uint32_t RUINT32T;
944 1273
945static void 1274static void
952 unsigned int upper_lim_r, upper_lim_g, upper_lim_b; 1281 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
953 int i; 1282 int i;
954 1283
955 Visual *visual = term->visual; 1284 Visual *visual = term->visual;
956 1285
957 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ; 1286 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ;
1287
1288 if (shade == 0)
1289 shade = 100;
958 1290
959 /* for convenience */ 1291 /* for convenience */
960 mask_r = visual->red_mask; 1292 mask_r = visual->red_mask;
961 mask_g = visual->green_mask; 1293 mask_g = visual->green_mask;
962 mask_b = visual->blue_mask; 1294 mask_b = visual->blue_mask;
1165 } 1497 }
1166 } 1498 }
1167 1499
1168 free (lookup); 1500 free (lookup);
1169} 1501}
1170#endif 1502#endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */
1171 1503
1172/* 1504#if 0 /* replaced by a bgPixmap_t::render() - leve here temporarily for reference */
1173 * Check our parents are still who we think they are.
1174 * Do transparency updates if required
1175 */
1176int
1177rxvt_term::check_our_parents ()
1178{
1179 check_our_parents_ev.stop ();
1180 check_our_parents_ev.start (NOW + .1);
1181 return 0;
1182}
1183
1184void 1505void
1185rxvt_term::check_our_parents_cb (time_watcher &w) 1506rxvt_term::check_our_parents_cb (time_watcher &w)
1186{ 1507{
1508
1187 int i, aformat, rootdepth; 1509 int i, aformat, rootdepth;
1188 unsigned long nitems, bytes_after; 1510 unsigned long nitems, bytes_after;
1189 Atom atype; 1511 Atom atype;
1190 unsigned char *prop = NULL; 1512 unsigned char *prop = NULL;
1191 Window root, oldp, *list; 1513 Window root, oldp, *list;
1195 Window cr; 1517 Window cr;
1196 unsigned int rootpixmap_w = 0, rootpixmap_h = 0; 1518 unsigned int rootpixmap_w = 0, rootpixmap_h = 0;
1197 1519
1198 if (!option (Opt_transparent)) 1520 if (!option (Opt_transparent))
1199 return; /* Don't try any more */ 1521 return; /* Don't try any more */
1200#if 0
1201 struct timeval stv;
1202 gettimeofday (&stv,NULL);
1203#define PRINT_BACKGROUND_OP_TIME do{ struct timeval tv;gettimeofday (&tv,NULL); tv.tv_sec-= stv.tv_sec;\
1204 fprintf (stderr,"%d: elapsed %ld usec\n",__LINE__,\
1205 tv.tv_sec*1000000+tv.tv_usec-stv.tv_usec );}while(0)
1206#else
1207#define PRINT_BACKGROUND_OP_TIME do{}while(0)
1208#endif
1209
1210 1522
1211 XGetWindowAttributes (dpy, display->root, &wrootattr); 1523 XGetWindowAttributes (dpy, display->root, &wrootattr);
1212 rootdepth = wrootattr.depth; 1524 rootdepth = wrootattr.depth;
1213 1525
1214 XGetWindowAttributes (dpy, parent[0], &wattr); 1526 XGetWindowAttributes (dpy, parent[0], &wattr);
1348 { 1660 {
1349 XImage *image = XGetImage (dpy, bgPixmap.pixmap, 0, 0, szHint.width, szHint.height, AllPlanes, ZPixmap); 1661 XImage *image = XGetImage (dpy, bgPixmap.pixmap, 0, 0, szHint.width, szHint.height, AllPlanes, ZPixmap);
1350 success = False; 1662 success = False;
1351 if (image != NULL) 1663 if (image != NULL)
1352 { 1664 {
1353 PRINT_BACKGROUND_OP_TIME;
1354 if (gc == NULL) 1665 if (gc == NULL)
1355 gc = XCreateGC (dpy, vt, 0UL, &gcvalue); 1666 gc = XCreateGC (dpy, vt, 0UL, &gcvalue);
1356 if (ISSET_PIXCOLOR (Color_tint) || shade != 100) 1667 if (ISSET_PIXCOLOR (Color_tint) || shade != 100)
1357 ShadeXImage (this, image, shade, c.r, c.g, c.b); 1668 ShadeXImage (this, image, shade, c.r, c.g, c.b);
1358 XPutImage (dpy, bgPixmap.pixmap, gc, image, 0, 0, 0, 0, image->width, image->height); 1669 XPutImage (dpy, bgPixmap.pixmap, gc, image, 0, 0, 0, 0, image->width, image->height);
1359 XDestroyImage (image); 1670 XDestroyImage (image);
1360 success = True; 1671 success = True;
1361 } 1672 }
1362 } 1673 }
1363#endif /* HAVE_AFTERIMAGE */ 1674#endif /* HAVE_AFTERIMAGE */
1364 PRINT_BACKGROUND_OP_TIME;
1365 1675
1366 if (gc != NULL) 1676 if (gc != NULL)
1367 XFreeGC (dpy, gc); 1677 XFreeGC (dpy, gc);
1368 1678
1369 bgPixmap.apply_background(); 1679 bgPixmap.apply();
1370 if (!success) 1680 if (!success)
1371 am_pixmap_trans = 0; 1681 am_pixmap_trans = 0;
1372 else 1682 else
1373 { 1683 {
1374 am_transparent = am_pixmap_trans = 1; 1684 am_transparent = am_pixmap_trans = 1;
1389 if (am_pixmap_trans) 1699 if (am_pixmap_trans)
1390 flush (); 1700 flush ();
1391 } 1701 }
1392 } 1702 }
1393} 1703}
1394#endif 1704#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines