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.70 by sasha, Thu Aug 16 21:26:20 2007 UTC vs.
Revision 1.76 by sasha, Wed Sep 12 19:51:41 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
77# ifdef XPM_BACKGROUND 94# ifdef XPM_BACKGROUND
78# ifdef HAVE_AFTERIMAGE 95# ifdef HAVE_AFTERIMAGE
79 if (original_asim != NULL) 96 if (original_asim != NULL)
80# endif 97# endif
81 { 98 {
82 if (h_scale != 0 || v_scale != 0) 99 if (h_scale != 0 || v_scale != 0
100 || h_align != 0 || v_align != 0)
83 return true; 101 return true;
84 } 102 }
85# endif 103# endif
86# ifdef ENABLE_TRANSPARENCY 104# ifdef ENABLE_TRANSPARENCY
87 if (flags & isTransparent) 105 if (flags & isTransparent)
93bool bgPixmap_t::need_client_side_rendering () 111bool bgPixmap_t::need_client_side_rendering ()
94{ 112{
95# ifdef HAVE_AFTERIMAGE 113# ifdef HAVE_AFTERIMAGE
96 if (original_asim != NULL) 114 if (original_asim != NULL)
97 return true; 115 return true;
98#endif 116# endif
99# ifdef ENABLE_TRANSPARENCY 117# ifdef ENABLE_TRANSPARENCY
100 if (flags & isTransparent) 118 if (flags & isTransparent)
101 { 119 {
102 if ((flags & blurNeeded) 120 if (((flags & blurNeeded) && !(flags & blurServerSide))
103 || ((flags & tintNeeded) && !(flags & tintServerSide))) 121 || ((flags & tintNeeded) && !(flags & tintServerSide)))
104 return true; 122 return true;
105 } 123 }
106# endif 124# endif
107 return false; 125 return false;
376 int x = 0; 394 int x = 0;
377 int y = 0; 395 int y = 0;
378 int w = h_scale * target_width / 100; 396 int w = h_scale * target_width / 100;
379 int h = v_scale * target_height / 100; 397 int h = v_scale * target_height / 100;
380 398
399 TIMING_TEST_START (asim);
400
381 if (original_asim) 401 if (original_asim)
382 { 402 {
383 x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); 403 x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width);
384 y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); 404 y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height);
385 } 405 }
489 result = tmp; 509 result = tmp;
490 } 510 }
491 free (layers); 511 free (layers);
492 } 512 }
493 } 513 }
514 TIMING_TEST_PRINT_RESULT (asim);
494 515
495 if (pixmap) 516 if (pixmap)
496 { 517 {
497 if (result == NULL 518 if (result == NULL
498 || pmap_width != new_pmap_width 519 || pmap_width != new_pmap_width
544 565
545 if (result != background && result != original_asim) 566 if (result != background && result != original_asim)
546 destroy_asimage (&result); 567 destroy_asimage (&result);
547 568
548 XFreeGC (target->dpy, gc); 569 XFreeGC (target->dpy, gc);
570 TIMING_TEST_PRINT_RESULT (asim);
549 } 571 }
550 572
551 return true; 573 return true;
552} 574}
553# endif /* HAVE_AFTERIMAGE */ 575# endif /* HAVE_AFTERIMAGE */
561 583
562 if (*file != '\0') 584 if (*file != '\0')
563 { 585 {
564# ifdef HAVE_AFTERIMAGE 586# ifdef HAVE_AFTERIMAGE
565 if (target->asimman == NULL) 587 if (target->asimman == NULL)
566 target->asimman = create_generic_imageman(target->rs[Rs_path]); 588 target->asimman = create_generic_imageman (target->rs[Rs_path]);
567 if ((f = strchr (file, ';')) == NULL) 589 if ((f = strchr (file, ';')) == NULL)
568 original_asim = get_asimage( target->asimman, file, 0xFFFFFFFF, 100 ); 590 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
569 else 591 else
570 { 592 {
571 size_t len = f - file; 593 size_t len = f - file;
572 f = (char *)malloc (len + 1); 594 f = (char *)malloc (len + 1);
573 strncpy (f, file, len); 595 strncpy (f, file, len);
574 f[len] = '\0'; 596 f[len] = '\0';
575 original_asim = get_asimage( target->asimman, f, 0xFFFFFFFF, 100 ); 597 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100);
576 free( f ); 598 free (f);
577 } 599 }
578 return (original_asim != NULL); 600 return (original_asim != NULL);
579# endif 601# endif
580 } 602 }
581 return false; 603 return false;
590 if (!(flags & isTransparent)) 612 if (!(flags & isTransparent))
591 { 613 {
592 flags |= isTransparent; 614 flags |= isTransparent;
593 return true; 615 return true;
594 } 616 }
617 return false;
595} 618}
596 619
597bool 620bool
598bgPixmap_t::set_blur_radius (const char *geom) 621bgPixmap_t::set_blur_radius (const char *geom)
599{ 622{
600 int changed = 0; 623 int changed = 0;
601 unsigned int hr, vr; 624 unsigned int hr, vr;
602 int junk; 625 int junk;
603 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); 626 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
627
604 if (!(geom_flags&WidthValue)) 628 if (!(geom_flags&WidthValue))
605 hr = 1; 629 hr = 1;
606 if (!(geom_flags&HeightValue)) 630 if (!(geom_flags&HeightValue))
607 vr = hr; 631 vr = hr;
608 632
609 if (h_blurRadius != hr) 633 if (h_blurRadius != hr)
610 { 634 {
611 ++changed; 635 ++changed;
612 h_blurRadius = hr; 636 h_blurRadius = hr;
613 } 637 }
638
614 if (v_blurRadius != vr) 639 if (v_blurRadius != vr)
615 { 640 {
616 ++changed; 641 ++changed;
617 v_blurRadius = vr; 642 v_blurRadius = vr;
618 } 643 }
644
619 if (v_blurRadius == 0 && h_blurRadius == 0) 645 if (v_blurRadius == 0 && h_blurRadius == 0)
620 flags &= ~blurNeeded; 646 flags &= ~blurNeeded;
621 else 647 else
622 flags |= blurNeeded; 648 flags |= blurNeeded;
649
623 return (changed>0); 650 return (changed>0);
624} 651}
625 652
626static inline unsigned long 653static inline unsigned long
627compute_tint_shade_flags (rxvt_color *tint, int shade) 654compute_tint_shade_flags (rxvt_color *tint, int shade)
628{ 655{
629 unsigned long flags = 0; 656 unsigned long flags = 0;
657 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
630 658
631 if (shade > 0 && shade <100) 659 if (tint)
660 {
661 tint->get (c);
662# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700)
663 if (IS_COMPONENT_WHOLESOME (c.r)
664 && IS_COMPONENT_WHOLESOME (c.g)
665 && IS_COMPONENT_WHOLESOME (c.b))
666 flags |= bgPixmap_t::tintWholesome;
667# undef IS_COMPONENT_WHOLESOME
668 }
669
670 if ((shade > 0 && shade < 100) || (shade > 100 && shade < 200))
632 flags |= bgPixmap_t::tintNeeded; 671 flags |= bgPixmap_t::tintNeeded;
633 else if (tint) 672 else if (tint)
634 { 673 {
635 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
636 tint->get (c);
637
638 flags |= bgPixmap_t::tintNeeded;
639 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) 674 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700)
640 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) 675 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700))
641 { 676 {
642 flags |= bgPixmap_t::tintNeeded; 677 flags |= bgPixmap_t::tintNeeded;
643#define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700)
644 if (IS_COMPONENT_WHOLESOME (c.r)
645 && IS_COMPONENT_WHOLESOME (c.g)
646 && IS_COMPONENT_WHOLESOME (c.b))
647 flags |= bgPixmap_t::tintServerSide;
648#undef IS_COMPONENT_WHOLESOME
649 } 678 }
650 } 679 }
680
681 if (flags & bgPixmap_t::tintNeeded)
682 {
683 if (flags & bgPixmap_t::tintWholesome)
684 flags |= bgPixmap_t::tintServerSide;
685#if XFT
686 flags |= bgPixmap_t::tintServerSide;
687#endif
688 }
689
651 return flags; 690 return flags;
652} 691}
653 692
654bool 693bool
655bgPixmap_t::set_tint (rxvt_color &new_tint) 694bgPixmap_t::set_tint (rxvt_color &new_tint)
685 if (new_shade == 100) 724 if (new_shade == 100)
686 new_shade = 0; 725 new_shade = 0;
687 726
688 if (new_shade != shade) 727 if (new_shade != shade)
689 { 728 {
690 unsigned long new_flags = compute_tint_shade_flags (&tint, new_shade); 729 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade);
691 shade = new_shade; 730 shade = new_shade;
692 flags = (flags & ~tintFlags) | new_flags; 731 flags = (flags & ~tintFlags) | new_flags;
693 return true; 732 return true;
694 } 733 }
695 return false; 734 return false;
696} 735}
697
698 736
699/* make_transparency_pixmap() 737/* make_transparency_pixmap()
700 * Builds a pixmap sized the same as terminal window, with depth same as the root window 738 * Builds a pixmap sized the same as terminal window, with depth same as the root window
701 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by 739 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by
702 * our window. 740 * our window.
721 int window_width = target->szHint.width; 759 int window_width = target->szHint.width;
722 int window_height = target->szHint.height; 760 int window_height = target->szHint.height;
723 int sx, sy; 761 int sx, sy;
724 XGCValues gcv; 762 XGCValues gcv;
725 763
764 TIMING_TEST_START (tp);
726 target->get_window_origin (sx, sy); 765 target->get_window_origin (sx, sy);
727 766
728 /* check if we are outside of the visible part of the virtual screen : */ 767 /* check if we are outside of the visible part of the virtual screen : */
729 if (sx + window_width <= 0 || sy + window_height <= 0 768 if (sx + window_width <= 0 || sy + window_height <= 0
730 || sx >= root_width || sy >= root_height) 769 || sx >= root_width || sy >= root_height)
734 {/* we want to validate the pixmap and get it's size at the same time : */ 773 {/* we want to validate the pixmap and get it's size at the same time : */
735 int junk; 774 int junk;
736 unsigned int ujunk; 775 unsigned int ujunk;
737 /* root pixmap may be bad - allow a error */ 776 /* root pixmap may be bad - allow a error */
738 target->allowedxerror = -1; 777 target->allowedxerror = -1;
778
739 if (!XGetGeometry (dpy, root_pixmap, &root, &junk, &junk, &root_pmap_width, &root_pmap_height, &ujunk, &ujunk)) 779 if (!XGetGeometry (dpy, root_pixmap, &root, &junk, &junk, &root_pmap_width, &root_pmap_height, &ujunk, &ujunk))
740 root_pixmap = None; 780 root_pixmap = None;
781
741 target->allowedxerror = 0; 782 target->allowedxerror = 0;
742 } 783 }
743 784
744 Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth); 785 Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth);
745 GC gc = NULL; 786 GC gc = NULL;
769 XEvent event; 810 XEvent event;
770 int ev_count = 0; 811 int ev_count = 0;
771 XGrabServer (dpy); 812 XGrabServer (dpy);
772 XMapRaised (dpy, src); 813 XMapRaised (dpy, src);
773 XSync (dpy, False); 814 XSync (dpy, False);
815
774 /* XSync should get window where it's properly exposed, 816 /* XSync should get window where it's properly exposed,
775 * but to be on the safe side - let's check for the actuall event to arrive : */ 817 * but to be on the safe side - let's check for the actuall event to arrive : */
776 while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) 818 while (XCheckWindowEvent (dpy, src, ExposureMask, &event))
777 ++ev_count; 819 ++ev_count;
820
778 if (ev_count > 0); 821 if (ev_count > 0);
779 { /* hooray! - we can grab the image! */ 822 { /* hooray! - we can grab the image! */
780 gc = XCreateGC (dpy, root, 0, NULL); 823 gc = XCreateGC (dpy, root, 0, NULL);
781 if (gc) 824 if (gc)
782 { 825 {
786 } 829 }
787 XDestroyWindow (dpy, src); 830 XDestroyWindow (dpy, src);
788 XUngrabServer (dpy); 831 XUngrabServer (dpy);
789 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); 832 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count);
790 } 833 }
834
791 if (!success) 835 if (!success)
792 { 836 {
793 XFreePixmap (dpy, tiled_root_pmap); 837 XFreePixmap (dpy, tiled_root_pmap);
794 tiled_root_pmap = None; 838 tiled_root_pmap = None;
795 } 839 }
798 } 842 }
799 else 843 else
800 {/* strightforward pixmap copy */ 844 {/* strightforward pixmap copy */
801 gcv.tile = root_pixmap; 845 gcv.tile = root_pixmap;
802 gcv.fill_style = FillTiled; 846 gcv.fill_style = FillTiled;
847
803 while (sx < 0) sx += (int)window_width; 848 while (sx < 0) sx += (int)window_width;
804 while (sy < 0) sy += (int)window_height; 849 while (sy < 0) sy += (int)window_height;
850
805 gcv.ts_x_origin = -sx; 851 gcv.ts_x_origin = -sx;
806 gcv.ts_y_origin = -sy; 852 gcv.ts_y_origin = -sy;
807 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 853 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
854
808 if (gc) 855 if (gc)
809 { 856 {
810 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); 857 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
811 result |= transpPmapTiled; 858 result |= transpPmapTiled;
812 } 859 }
813 } 860 }
861 TIMING_TEST_PRINT_RESULT (tp);
814 862
815 if (tiled_root_pmap != None) 863 if (tiled_root_pmap != None)
864 {
865 if (!need_client_side_rendering ())
816 { 866 {
817 if (flags & tintNeeded) 867 if ((flags & tintNeeded))
818 { 868 {
819 if ((flags & tintServerSide) 869 if (flags & tintWholesome)
820 && h_blurRadius <= 1 && v_blurRadius <= 1
821# ifdef HAVE_AFTERIMAGE
822 && original_asim == NULL
823# endif
824 ) 870 {
825 { /* In this case we can tint image server-side getting significant 871 /* In this case we can tint image server-side getting significant
826 * performance improvements, as we eliminate XImage transfer 872 * performance improvements, as we eliminate XImage transfer
827 */ 873 */
828 gcv.foreground = Pixel (tint); 874 gcv.foreground = Pixel (tint);
829 gcv.function = GXand; 875 gcv.function = GXand;
830 gcv.fill_style = FillSolid; 876 gcv.fill_style = FillSolid;
831 if (gc) 877 if (gc)
832 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcv); 878 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcv);
833 else 879 else
834 gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv); 880 gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv);
835 if (gc) 881 if (gc)
836 { 882 {
837 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); 883 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
838 result |= transpPmapTinted; 884 result |= transpPmapTinted;
839 } 885 }
886 }
887 else
888 {
889# if XFT
890 Picture back_pic = 0;
891 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
892
893 if (flags & tintSet)
894 tint.get (c);
895
896 if (shade > 0 && shade < 100)
897 {
898 c.r = (c.r * shade) / 100;
899 c.g = (c.g * shade) / 100;
900 c.b = (c.b * shade) / 100;
901 }
902 else if( shade > 100 && shade < 200)
903 {
904 c.r = (c.r * (200 - shade)) / 100;
905 c.g = (c.g * (200 - shade)) / 100;
906 c.b = (c.b * (200 - shade)) / 100;
907 }
908
909 XRenderPictFormat pf;
910 pf.type = PictTypeDirect;
911 pf.depth = 32;
912 pf.direct.redMask = 0xff;
913 pf.direct.greenMask = 0xff;
914 pf.direct.blueMask = 0xff;
915 pf.direct.alphaMask = 0xff;
916
917 XRenderPictFormat *solid_format = XRenderFindFormat (dpy,
918 (PictFormatType|
919 PictFormatDepth|
920 PictFormatRedMask|
921 PictFormatGreenMask|
922 PictFormatBlueMask|
923 PictFormatAlphaMask),
924 &pf,
925 0);
926 XRenderPictFormat *root_format = XRenderFindVisualFormat (dpy, DefaultVisualOfScreen (ScreenOfDisplay (dpy, target->display->screen)));
927 XRenderPictureAttributes pa ;
928
929 back_pic = XRenderCreatePicture (dpy, tiled_root_pmap, root_format, 0, &pa);
930
931 pa.repeat = True;
932
933 Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32);
934 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
935 XFreePixmap (dpy, overlay_pmap);
936
937 pa.component_alpha = True;
938 Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32);
939 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa);
940 XFreePixmap (dpy, mask_pmap);
941
942 if (mask_pic && overlay_pic && back_pic)
943 {
944 XRenderColor mask_c;
945
946 memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c));
947 mask_c.alpha = 0xffff;
948 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
949 memset (&mask_c, 0x0, sizeof (mask_c));
950 mask_c.alpha = 0;
951
952 if (c.r == c.b && c.b == c.g) /* pure shading */
953 {
954 mask_c.red = mask_c.green = mask_c.blue = 0xffff - c.r;
955 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
956 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height);
957 }
958 else
959 {
960 mask_c.red = 0xffff - c.r;
961 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
962 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height);
963 mask_c.red = 0;
964 mask_c.green = 0xffff - c.g;
965 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
966 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height);
967 mask_c.green = 0;
968 mask_c.blue = 0xffff - c.b;
969 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
970 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height);
971 }
972 result |= transpPmapTinted;
973 }
974 XRenderFreePicture (dpy, mask_pic);
975 XRenderFreePicture (dpy, overlay_pic);
976 XRenderFreePicture (dpy, back_pic);
977# if DO_TIMING_TEST
978 XSync (dpy, False);
979# endif
980# endif
981 }
840 } 982 }
841 } 983 } /* server side rendering completed */
984
842 if (pixmap) 985 if (pixmap)
843 XFreePixmap (dpy, pixmap); 986 XFreePixmap (dpy, pixmap);
987
844 pixmap = tiled_root_pmap; 988 pixmap = tiled_root_pmap;
845 pmap_width = window_width; 989 pmap_width = window_width;
846 pmap_height = window_height; 990 pmap_height = window_height;
847 pmap_depth = root_depth; 991 pmap_depth = root_depth;
848 } 992 }
849 993
850 if (gc) 994 if (gc)
851 XFreeGC (dpy, gc); 995 XFreeGC (dpy, gc);
996
997 TIMING_TEST_PRINT_RESULT (tp);
852 998
853 return result; 999 return result;
854} 1000}
855 1001
856bool 1002bool
857bgPixmap_t::set_root_pixmap () 1003bgPixmap_t::set_root_pixmap ()
858{ 1004{
871} 1017}
872# endif /* ENABLE_TRANSPARENCY */ 1018# endif /* ENABLE_TRANSPARENCY */
873 1019
874# ifndef HAVE_AFTERIMAGE 1020# ifndef HAVE_AFTERIMAGE
875static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm); 1021static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm);
876#endif 1022# endif
877 1023
878 1024
879bool 1025bool
880bgPixmap_t::render () 1026bgPixmap_t::render ()
881{ 1027{
906 ASImage *background = NULL; 1052 ASImage *background = NULL;
907 ARGB32 as_tint = TINT_LEAVE_SAME; 1053 ARGB32 as_tint = TINT_LEAVE_SAME;
908 if (background_flags) 1054 if (background_flags)
909 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100); 1055 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100);
910 1056
1057# ifdef ENABLE_TRANSPARENCY
911 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1058 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
912 { 1059 {
913 ShadingInfo as_shade; 1060 ShadingInfo as_shade;
914 as_shade.shading = (shade == 0) ? 100 : shade; 1061 as_shade.shading = (shade == 0) ? 100 : shade;
915 1062
920 as_shade.tintColor.green = c.g; 1067 as_shade.tintColor.green = c.g;
921 as_shade.tintColor.blue = c.b; 1068 as_shade.tintColor.blue = c.b;
922 1069
923 as_tint = shading2tint32 (&as_shade); 1070 as_tint = shading2tint32 (&as_shade);
924 } 1071 }
925
926 if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL) 1072 if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL)
927 { 1073 {
928 ASImage* tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, 1074 ASImage* tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
929 (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage, 1075 (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage,
930 100, ASIMAGE_QUALITY_DEFAULT); 1076 100, ASIMAGE_QUALITY_DEFAULT);
932 { 1078 {
933 destroy_asimage (&background); 1079 destroy_asimage (&background);
934 background = tmp; 1080 background = tmp;
935 } 1081 }
936 } 1082 }
1083# endif
937 1084
938 if (render_asim (background, as_tint)) 1085 if (render_asim (background, as_tint))
939 flags = flags & ~isInvalid; 1086 flags = flags & ~isInvalid;
940 if (background) 1087 if (background)
941 destroy_asimage (&background); 1088 destroy_asimage (&background);
954 if (flags & tintSet) 1101 if (flags & tintSet)
955 tint.get (c); 1102 tint.get (c);
956 ShadeXImage (target, result, shade, c.r, c.g, c.b); 1103 ShadeXImage (target, result, shade, c.r, c.g, c.b);
957 } 1104 }
958 } 1105 }
959# endif 1106# endif /* HAVE_AFTERIMAGE */
1107
960 if (result != NULL) 1108 if (result != NULL)
961 { 1109 {
962 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1110 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
963 if (gc) 1111 if (gc)
964 { 1112 {
965 if (pmap_depth != target->depth && pixmap != None) 1113 if (/*pmap_depth != target->depth &&*/ pixmap != None)
966 { 1114 {
967 XFreePixmap (target->dpy, pixmap); 1115 XFreePixmap (target->dpy, pixmap);
968 pixmap = None; 1116 pixmap = None;
969 } 1117 }
970 if (pixmap == None) 1118 if (pixmap == None)
972 pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth); 1120 pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth);
973 pmap_width = result->width; 1121 pmap_width = result->width;
974 pmap_height = result->height; 1122 pmap_height = result->height;
975 pmap_depth = target->depth; 1123 pmap_depth = target->depth;
976 } 1124 }
1125 if (pmap_depth != result->depth)
1126 { /* Bad Match error will ensue ! stupid X !!!! */
1127 if( result->depth == 24 && pmap_depth == 32)
1128 result->depth = 32;
1129 else if( result->depth == 32 && pmap_depth == 24)
1130 result->depth = 24;
1131 else
1132 {
1133 /* TODO: implement image recoding */
1134 }
1135 }
1136 if (pmap_depth == result->depth)
977 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); 1137 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
978 XFreeGC (target->dpy, gc); 1138 XFreeGC (target->dpy, gc);
979 flags = flags & ~isInvalid; 1139 flags = flags & ~isInvalid;
980 } 1140 }
981 XDestroyImage (result); 1141 XDestroyImage (result);
982 } 1142 }
986 if (pixmap != None) 1146 if (pixmap != None)
987 { 1147 {
988 XFreePixmap (target->dpy, pixmap); 1148 XFreePixmap (target->dpy, pixmap);
989 pixmap = None; 1149 pixmap = None;
990 } 1150 }
991// TODO : we need to get rid of that garbadge :
992 target->am_transparent = target->am_pixmap_trans = 0;
993 } 1151 }
994 else
995 target->am_transparent = target->am_pixmap_trans = 1;
996 1152
997 apply (); 1153 apply ();
998 1154
999 return true; 1155 return true;
1000} 1156}
1017void 1173void
1018bgPixmap_t::apply() 1174bgPixmap_t::apply()
1019{ 1175{
1020 if (target) 1176 if (target)
1021 { 1177 {
1178 flags &= ~isVtOrigin;
1022 if (pixmap != None) 1179 if (pixmap != None)
1023 { /* set target's background to pixmap */ 1180 { /* set target's background to pixmap */
1024# ifdef ENABLE_TRANSPARENCY 1181# ifdef ENABLE_TRANSPARENCY
1025 if (flags & isTransparent) 1182 if (flags & isTransparent)
1026 { 1183 {
1032# endif 1189# endif
1033 } 1190 }
1034 else 1191 else
1035# endif 1192# endif
1036 { 1193 {
1194 flags |= isVtOrigin;
1037 /* force old pixmap dereference in case it was transparent before :*/ 1195 /* force old pixmap dereference in case it was transparent before :*/
1038 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1196 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1039 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); 1197 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1040 /* do we also need to set scrollbar's background here ? */ 1198 /* do we also need to set scrollbar's background here ? */
1041# if HAVE_SCROLLBARS 1199# if HAVE_SCROLLBARS
1052# if HAVE_SCROLLBARS 1210# if HAVE_SCROLLBARS
1053 if (target->scrollBar.win) 1211 if (target->scrollBar.win)
1054 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1212 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1055# endif 1213# endif
1056 } 1214 }
1215
1057 /* don't want Expose on the parent */ 1216 /* don't want Expose on the parent */
1058 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, False); 1217 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, False);
1059 /* do want Expose on the vt */ 1218 /* do want Expose on the vt, so we get refreshed properly */
1060 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, True); 1219 XClearArea (target->dpy, target->vt, 0, 0, 0, 0, True);
1220
1061#if HAVE_SCROLLBARS 1221# if HAVE_SCROLLBARS
1062 if (target->scrollBar.win) 1222 if (target->scrollBar.win)
1063 { 1223 {
1064 target->scrollBar.setIdle (); 1224 target->scrollBar.setIdle ();
1065 target->scrollbar_show (0); 1225 target->scrollbar_show (0);
1066 } 1226 }
1067#endif 1227# endif
1068 /* Is that really neccessary? we did a XClearArea to generate Expose events alreday ! */
1069 target->want_refresh = target->want_full_refresh = 1;
1070 /* TODO: why do we need a flush here ??? It causes segfault on resize ! */
1071// target->flush ();
1072 } 1228 }
1073} 1229}
1074#endif /* HAVE_BG_PIXMAP */
1075
1076 1230
1077void 1231void
1078rxvt_term::get_window_origin (int &x, int &y) 1232rxvt_term::get_window_origin (int &x, int &y)
1079{ 1233{
1080 Window cr; 1234 Window cr;
1086rxvt_term::get_pixmap_property (int prop_id) 1240rxvt_term::get_pixmap_property (int prop_id)
1087{ 1241{
1088 if (prop_id > 0 && prop_id < NUM_XA) 1242 if (prop_id > 0 && prop_id < NUM_XA)
1089 if (xa[prop_id]) 1243 if (xa[prop_id])
1090 { 1244 {
1091 int aformat, rootdepth; 1245 int aformat;
1092 unsigned long nitems, bytes_after; 1246 unsigned long nitems, bytes_after;
1093 Atom atype; 1247 Atom atype;
1094 unsigned char *prop = NULL; 1248 unsigned char *prop = NULL;
1095 int result = XGetWindowProperty (dpy, display->root, xa[prop_id], 1249 int result = XGetWindowProperty (dpy, display->root, xa[prop_id],
1096 0L, 1L, False, XA_PIXMAP, &atype, &aformat, 1250 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
1101 } 1255 }
1102 } 1256 }
1103 return None; 1257 return None;
1104} 1258}
1105 1259
1260/*
1261 * Check our parents are still who we think they are.
1262 * Do transparency updates if required
1263 */
1264int
1265rxvt_term::update_background ()
1266{
1267 bgPixmap.invalidate();
1106 1268
1107#ifdef ENABLE_TRANSPARENCY 1269 /* no chance of real time refresh if we are blurring ! */
1108#ifndef HAVE_AFTERIMAGE 1270 if (bgPixmap.invalid_since + 0.5 < NOW && !(bgPixmap.flags & bgPixmap_t::blurNeeded))
1271 bgPixmap.render();
1272 else
1273 {
1274 update_background_ev.stop ();
1275 if (!bgPixmap.need_client_side_rendering())
1276 update_background_ev.start (NOW + .05);
1277 else if (bgPixmap.flags & bgPixmap_t::blurNeeded)
1278 update_background_ev.start (NOW + .2); /* very slow !!! */
1279 else
1280 update_background_ev.start (NOW + .07);
1281 }
1282 return 0;
1283}
1284
1285void
1286rxvt_term::update_background_cb (time_watcher &w)
1287{
1288 bgPixmap.render ();
1289}
1290#endif /* HAVE_BG_PIXMAP */
1291
1292#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1109/* taken from aterm-0.4.2 */ 1293/* taken from aterm-0.4.2 */
1110 1294
1111typedef uint32_t RUINT32T; 1295typedef uint32_t RUINT32T;
1112 1296
1113static void 1297static void
1124 1308
1125 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ; 1309 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ;
1126 1310
1127 if (shade == 0) 1311 if (shade == 0)
1128 shade = 100; 1312 shade = 100;
1129 1313
1130 /* for convenience */ 1314 /* for convenience */
1131 mask_r = visual->red_mask; 1315 mask_r = visual->red_mask;
1132 mask_g = visual->green_mask; 1316 mask_g = visual->green_mask;
1133 mask_b = visual->blue_mask; 1317 mask_b = visual->blue_mask;
1134 1318
1336 } 1520 }
1337 } 1521 }
1338 1522
1339 free (lookup); 1523 free (lookup);
1340} 1524}
1341#endif 1525#endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */
1342
1343/*
1344 * Check our parents are still who we think they are.
1345 * Do transparency updates if required
1346 */
1347int
1348rxvt_term::update_background ()
1349{
1350 bgPixmap.invalidate();
1351 /* no chance of real time refresh if we are blurring ! */
1352 if (bgPixmap.invalid_since + 0.5 < NOW && !(bgPixmap.flags & bgPixmap_t::blurNeeded))
1353 bgPixmap.render();
1354 else
1355 {
1356 update_background_ev.stop ();
1357 if (!bgPixmap.need_client_side_rendering())
1358 update_background_ev.start (NOW + .05);
1359 else if (bgPixmap.flags & bgPixmap_t::blurNeeded)
1360 update_background_ev.start (NOW + .2); /* very slow !!! */
1361 else
1362 update_background_ev.start (NOW + .07);
1363 }
1364 return 0;
1365}
1366
1367void
1368rxvt_term::update_background_cb (time_watcher &w)
1369{
1370 bgPixmap.render ();
1371}
1372#endif /* HAVE_BG_PIXMAP */
1373
1374 1526
1375#if 0 /* replaced by a bgPixmap_t::render() - leve here temporarily for reference */ 1527#if 0 /* replaced by a bgPixmap_t::render() - leve here temporarily for reference */
1376void 1528void
1377rxvt_term::check_our_parents_cb (time_watcher &w) 1529rxvt_term::check_our_parents_cb (time_watcher &w)
1378{ 1530{
1388 Window cr; 1540 Window cr;
1389 unsigned int rootpixmap_w = 0, rootpixmap_h = 0; 1541 unsigned int rootpixmap_w = 0, rootpixmap_h = 0;
1390 1542
1391 if (!option (Opt_transparent)) 1543 if (!option (Opt_transparent))
1392 return; /* Don't try any more */ 1544 return; /* Don't try any more */
1393#if 0
1394 struct timeval stv;
1395 gettimeofday (&stv,NULL);
1396#define PRINT_BACKGROUND_OP_TIME do{ struct timeval tv;gettimeofday (&tv,NULL); tv.tv_sec-= stv.tv_sec;\
1397 fprintf (stderr,"%d: elapsed %ld usec\n",__LINE__,\
1398 tv.tv_sec*1000000+tv.tv_usec-stv.tv_usec );}while(0)
1399#else
1400#define PRINT_BACKGROUND_OP_TIME do{}while(0)
1401#endif
1402
1403 1545
1404 XGetWindowAttributes (dpy, display->root, &wrootattr); 1546 XGetWindowAttributes (dpy, display->root, &wrootattr);
1405 rootdepth = wrootattr.depth; 1547 rootdepth = wrootattr.depth;
1406 1548
1407 XGetWindowAttributes (dpy, parent[0], &wattr); 1549 XGetWindowAttributes (dpy, parent[0], &wattr);
1541 { 1683 {
1542 XImage *image = XGetImage (dpy, bgPixmap.pixmap, 0, 0, szHint.width, szHint.height, AllPlanes, ZPixmap); 1684 XImage *image = XGetImage (dpy, bgPixmap.pixmap, 0, 0, szHint.width, szHint.height, AllPlanes, ZPixmap);
1543 success = False; 1685 success = False;
1544 if (image != NULL) 1686 if (image != NULL)
1545 { 1687 {
1546 PRINT_BACKGROUND_OP_TIME;
1547 if (gc == NULL) 1688 if (gc == NULL)
1548 gc = XCreateGC (dpy, vt, 0UL, &gcvalue); 1689 gc = XCreateGC (dpy, vt, 0UL, &gcvalue);
1549 if (ISSET_PIXCOLOR (Color_tint) || shade != 100) 1690 if (ISSET_PIXCOLOR (Color_tint) || shade != 100)
1550 ShadeXImage (this, image, shade, c.r, c.g, c.b); 1691 ShadeXImage (this, image, shade, c.r, c.g, c.b);
1551 XPutImage (dpy, bgPixmap.pixmap, gc, image, 0, 0, 0, 0, image->width, image->height); 1692 XPutImage (dpy, bgPixmap.pixmap, gc, image, 0, 0, 0, 0, image->width, image->height);
1552 XDestroyImage (image); 1693 XDestroyImage (image);
1553 success = True; 1694 success = True;
1554 } 1695 }
1555 } 1696 }
1556#endif /* HAVE_AFTERIMAGE */ 1697#endif /* HAVE_AFTERIMAGE */
1557 PRINT_BACKGROUND_OP_TIME;
1558 1698
1559 if (gc != NULL) 1699 if (gc != NULL)
1560 XFreeGC (dpy, gc); 1700 XFreeGC (dpy, gc);
1561 1701
1562 bgPixmap.apply(); 1702 bgPixmap.apply();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines