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.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)
88 return true; 106 return true;
107# endif
108 return false;
109}
110
111bool bgPixmap_t::need_client_side_rendering ()
112{
113# ifdef HAVE_AFTERIMAGE
114 if (original_asim != NULL)
115 return true;
116# endif
117# ifdef ENABLE_TRANSPARENCY
118 if (flags & isTransparent)
119 {
120 if (((flags & blurNeeded) && !(flags & blurServerSide))
121 || ((flags & tintNeeded) && !(flags & tintServerSide)))
122 return true;
123 }
89# endif 124# endif
90 return false; 125 return false;
91} 126}
92 127
93# ifdef XPM_BACKGROUND 128# ifdef XPM_BACKGROUND
359 int x = 0; 394 int x = 0;
360 int y = 0; 395 int y = 0;
361 int w = h_scale * target_width / 100; 396 int w = h_scale * target_width / 100;
362 int h = v_scale * target_height / 100; 397 int h = v_scale * target_height / 100;
363 398
399 TIMING_TEST_START (asim);
400
364 if (original_asim) 401 if (original_asim)
365 { 402 {
366 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);
367 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);
368 } 405 }
472 result = tmp; 509 result = tmp;
473 } 510 }
474 free (layers); 511 free (layers);
475 } 512 }
476 } 513 }
514 TIMING_TEST_PRINT_RESULT (asim);
477 515
478 if (pixmap) 516 if (pixmap)
479 { 517 {
480 if (result == NULL 518 if (result == NULL
481 || pmap_width != new_pmap_width 519 || pmap_width != new_pmap_width
527 565
528 if (result != background && result != original_asim) 566 if (result != background && result != original_asim)
529 destroy_asimage (&result); 567 destroy_asimage (&result);
530 568
531 XFreeGC (target->dpy, gc); 569 XFreeGC (target->dpy, gc);
570 TIMING_TEST_PRINT_RESULT (asim);
532 } 571 }
533 572
534 return true; 573 return true;
535} 574}
536# endif /* HAVE_AFTERIMAGE */ 575# endif /* HAVE_AFTERIMAGE */
544 583
545 if (*file != '\0') 584 if (*file != '\0')
546 { 585 {
547# ifdef HAVE_AFTERIMAGE 586# ifdef HAVE_AFTERIMAGE
548 if (target->asimman == NULL) 587 if (target->asimman == NULL)
549 target->asimman = create_generic_imageman(target->rs[Rs_path]); 588 target->asimman = create_generic_imageman (target->rs[Rs_path]);
550 if ((f = strchr (file, ';')) == NULL) 589 if ((f = strchr (file, ';')) == NULL)
551 original_asim = get_asimage( target->asimman, file, 0xFFFFFFFF, 100 ); 590 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
552 else 591 else
553 { 592 {
554 size_t len = f - file; 593 size_t len = f - file;
555 f = (char *)malloc (len + 1); 594 f = (char *)malloc (len + 1);
556 strncpy (f, file, len); 595 strncpy (f, file, len);
557 f[len] = '\0'; 596 f[len] = '\0';
558 original_asim = get_asimage( target->asimman, f, 0xFFFFFFFF, 100 ); 597 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100);
559 free( f ); 598 free (f);
560 } 599 }
561 return (original_asim != NULL); 600 return (original_asim != NULL);
562# endif 601# endif
563 } 602 }
564 return false; 603 return false;
573 if (!(flags & isTransparent)) 612 if (!(flags & isTransparent))
574 { 613 {
575 flags |= isTransparent; 614 flags |= isTransparent;
576 return true; 615 return true;
577 } 616 }
617 return false;
578} 618}
579 619
580bool 620bool
581bgPixmap_t::set_blur_radius (const char *geom) 621bgPixmap_t::set_blur_radius (const char *geom)
582{ 622{
583 int changed = 0; 623 int changed = 0;
584 unsigned int hr, vr; 624 unsigned int hr, vr;
585 int junk; 625 int junk;
586 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); 626 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
627
587 if (!(geom_flags&WidthValue)) 628 if (!(geom_flags&WidthValue))
588 hr = 1; 629 hr = 1;
589 if (!(geom_flags&HeightValue)) 630 if (!(geom_flags&HeightValue))
590 vr = hr; 631 vr = hr;
591 632
592 if (h_blurRadius != hr) 633 if (h_blurRadius != hr)
593 { 634 {
594 ++changed; 635 ++changed;
595 h_blurRadius = hr; 636 h_blurRadius = hr;
596 } 637 }
638
597 if (v_blurRadius != vr) 639 if (v_blurRadius != vr)
598 { 640 {
599 ++changed; 641 ++changed;
600 v_blurRadius = vr; 642 v_blurRadius = vr;
601 } 643 }
644
645 if (v_blurRadius == 0 && h_blurRadius == 0)
646 flags &= ~blurNeeded;
647 else
648 flags |= blurNeeded;
649
602 return (changed>0); 650 return (changed>0);
603} 651}
604 652
605static inline unsigned long 653static inline unsigned long
606compute_tint_shade_flags (rxvt_color *tint, int shade) 654compute_tint_shade_flags (rxvt_color *tint, int shade)
607{ 655{
608 unsigned long flags = 0; 656 unsigned long flags = 0;
657 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
609 658
610 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))
611 flags |= bgPixmap_t::tintNeeded; 671 flags |= bgPixmap_t::tintNeeded;
612 else if (tint) 672 else if (tint)
613 { 673 {
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) 674 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700)
619 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) 675 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700))
620 { 676 {
621 flags |= bgPixmap_t::tintNeeded; 677 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 } 678 }
629 } 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
630 return flags; 690 return flags;
631} 691}
632 692
633bool 693bool
634bgPixmap_t::set_tint (rxvt_color &new_tint) 694bgPixmap_t::set_tint (rxvt_color &new_tint)
664 if (new_shade == 100) 724 if (new_shade == 100)
665 new_shade = 0; 725 new_shade = 0;
666 726
667 if (new_shade != shade) 727 if (new_shade != shade)
668 { 728 {
669 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);
670 shade = new_shade; 730 shade = new_shade;
671 flags = (flags & ~tintFlags) | new_flags; 731 flags = (flags & ~tintFlags) | new_flags;
672 return true; 732 return true;
673 } 733 }
674 return false; 734 return false;
675} 735}
676
677 736
678/* make_transparency_pixmap() 737/* make_transparency_pixmap()
679 * 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
680 * 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
681 * our window. 740 * our window.
682 */ 741 */
683bool 742unsigned long
684bgPixmap_t::make_transparency_pixmap () 743bgPixmap_t::make_transparency_pixmap ()
685{ 744{
745 unsigned long result = 0;
746
686 if (target == NULL) 747 if (target == NULL)
687 return false; 748 return 0;
688 749
689 /* root dimentions may change from call to call - but Display structure should 750 /* root dimentions may change from call to call - but Display structure should
690 * be always up-to-date, so let's use it : 751 * be always up-to-date, so let's use it :
691 */ 752 */
692 Window root = target->display->root; 753 Window root = target->display->root;
698 int window_width = target->szHint.width; 759 int window_width = target->szHint.width;
699 int window_height = target->szHint.height; 760 int window_height = target->szHint.height;
700 int sx, sy; 761 int sx, sy;
701 XGCValues gcv; 762 XGCValues gcv;
702 763
764 TIMING_TEST_START (tp);
703 target->get_window_origin (sx, sy); 765 target->get_window_origin (sx, sy);
704 766
705 /* 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 : */
706 if (sx + window_width <= 0 || sy + window_height <= 0 768 if (sx + window_width <= 0 || sy + window_height <= 0
707 || sx >= root_width || sy >= root_height) 769 || sx >= root_width || sy >= root_height)
708 return false; 770 return 0;
709 771
710 if (root_pixmap != None) 772 if (root_pixmap != None)
711 {/* 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 : */
712 int junk; 774 int junk;
713 unsigned int ujunk; 775 unsigned int ujunk;
714 /* root pixmap may be bad - allow a error */ 776 /* root pixmap may be bad - allow a error */
715 target->allowedxerror = -1; 777 target->allowedxerror = -1;
778
716 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))
717 root_pixmap = None; 780 root_pixmap = None;
781
718 target->allowedxerror = 0; 782 target->allowedxerror = 0;
719 } 783 }
720 784
721 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);
722 GC gc = NULL; 786 GC gc = NULL;
723 787
724 if (tiled_root_pmap == None) /* something really bad happened - abort */ 788 if (tiled_root_pmap == None) /* something really bad happened - abort */
725 return false; 789 return 0;
726 790
727 if (root_pixmap == None) 791 if (root_pixmap == None)
728 { /* use tricks to obtain the root background image :*/ 792 { /* use tricks to obtain the root background image :*/
729 /* we want to create Overrideredirect window overlapping out window 793 /* we want to create Overrideredirect window overlapping out window
730 with background type of Parent Relative and then grab it */ 794 with background type of Parent Relative and then grab it */
746 XEvent event; 810 XEvent event;
747 int ev_count = 0; 811 int ev_count = 0;
748 XGrabServer (dpy); 812 XGrabServer (dpy);
749 XMapRaised (dpy, src); 813 XMapRaised (dpy, src);
750 XSync (dpy, False); 814 XSync (dpy, False);
815
751 /* XSync should get window where it's properly exposed, 816 /* XSync should get window where it's properly exposed,
752 * 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 : */
753 while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) 818 while (XCheckWindowEvent (dpy, src, ExposureMask, &event))
754 ++ev_count; 819 ++ev_count;
820
755 if (ev_count > 0); 821 if (ev_count > 0);
756 { /* hooray! - we can grab the image! */ 822 { /* hooray! - we can grab the image! */
757 gc = XCreateGC (dpy, root, 0, NULL); 823 gc = XCreateGC (dpy, root, 0, NULL);
824 if (gc)
825 {
758 XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0); 826 XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0);
759 success = true; 827 success = true;
828 }
760 } 829 }
761 XDestroyWindow (dpy, src); 830 XDestroyWindow (dpy, src);
762 XUngrabServer (dpy); 831 XUngrabServer (dpy);
763 //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);
764 } 833 }
834
765 if (!success) 835 if (!success)
766 { 836 {
767 XFreePixmap (dpy, tiled_root_pmap); 837 XFreePixmap (dpy, tiled_root_pmap);
768 tiled_root_pmap = None; 838 tiled_root_pmap = None;
769 } 839 }
840 else
841 result |= transpPmapTiled;
770 } 842 }
771 else 843 else
772 {/* strightforward pixmap copy */ 844 {/* strightforward pixmap copy */
773 gcv.tile = root_pixmap; 845 gcv.tile = root_pixmap;
774 gcv.fill_style = FillTiled; 846 gcv.fill_style = FillTiled;
847
775 while (sx < 0) sx += (int)window_width; 848 while (sx < 0) sx += (int)window_width;
776 while (sy < 0) sy += (int)window_height; 849 while (sy < 0) sy += (int)window_height;
850
777 gcv.ts_x_origin = -sx; 851 gcv.ts_x_origin = -sx;
778 gcv.ts_y_origin = -sy; 852 gcv.ts_y_origin = -sy;
779 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 853 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
854
855 if (gc)
856 {
780 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);
858 result |= transpPmapTiled;
859 }
781 } 860 }
861 TIMING_TEST_PRINT_RESULT (tp);
782 862
783 if (tiled_root_pmap != None) 863 if (tiled_root_pmap != None)
864 {
865 if (!need_client_side_rendering ())
784 { 866 {
785 if (flags & tintNeeded) 867 if ((flags & tintNeeded))
786 { 868 {
787 if ((flags & tintServerSide) 869 if (flags & tintWholesome)
788 && h_blurRadius <= 1 && v_blurRadius <= 1
789# ifdef HAVE_AFTERIMAGE
790 && original_asim == NULL
791# endif
792 ) 870 {
793 { /* In this case we can tint image server-side getting significant 871 /* In this case we can tint image server-side getting significant
794 * performance improvements, as we eliminate XImage transfer 872 * performance improvements, as we eliminate XImage transfer
795 */ 873 */
796 gcv.foreground = Pixel (tint); 874 gcv.foreground = Pixel (tint);
797 gcv.function = GXand; 875 gcv.function = GXand;
798 gcv.fill_style = FillSolid; 876 gcv.fill_style = FillSolid;
799 if (gc) 877 if (gc)
800 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcv); 878 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcv);
801 else 879 else
802 gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv); 880 gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv);
881 if (gc)
882 {
803 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);
884 result |= transpPmapTinted;
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 }
804 } 982 }
805 } 983 } /* server side rendering completed */
984
806 if (pixmap) 985 if (pixmap)
807 XFreePixmap (dpy, pixmap); 986 XFreePixmap (dpy, pixmap);
987
808 pixmap = tiled_root_pmap; 988 pixmap = tiled_root_pmap;
809 pmap_width = window_width; 989 pmap_width = window_width;
810 pmap_height = window_height; 990 pmap_height = window_height;
811 pmap_depth = root_depth; 991 pmap_depth = root_depth;
812 } 992 }
813 993
814 if (gc) 994 if (gc)
815 XFreeGC (dpy, gc); 995 XFreeGC (dpy, gc);
996
997 TIMING_TEST_PRINT_RESULT (tp);
998
999 return result;
816} 1000}
817 1001
818bool 1002bool
819bgPixmap_t::set_root_pixmap () 1003bgPixmap_t::set_root_pixmap ()
820{ 1004{
831 } 1015 }
832 return false; 1016 return false;
833} 1017}
834# endif /* ENABLE_TRANSPARENCY */ 1018# endif /* ENABLE_TRANSPARENCY */
835 1019
1020# ifndef HAVE_AFTERIMAGE
1021static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm);
1022# endif
1023
1024
836bool 1025bool
837bgPixmap_t::render_background () 1026bgPixmap_t::render ()
838{ 1027{
839 /* TODO: temporary implementation - need to move check_parents stuff in here */ 1028 unsigned long background_flags = 0;
1029
1030 if (target == NULL)
1031 return false;
1032
1033 invalidate();
840# ifdef ENABLE_TRANSPARENCY 1034# ifdef ENABLE_TRANSPARENCY
841 if (flags & isTransparent) 1035 if (flags & isTransparent)
842 { 1036 {
843 /* we need to re-generate transparency pixmap in that case ! */ 1037 /* we need to re-generate transparency pixmap in that case ! */
844 target->check_our_parents (); 1038 background_flags = make_transparency_pixmap ();
845 return true; 1039 if (background_flags == 0)
1040 return false;
1041 else if ((background_flags & transpTransformations) == (flags & transpTransformations)
1042 && pmap_depth == target->depth)
1043 flags = flags & ~isInvalid;
846 } 1044 }
847# endif 1045# endif
1046
1047 XImage *result = NULL;
848# ifdef HAVE_AFTERIMAGE 1048# ifdef HAVE_AFTERIMAGE
849 render_asim (NULL, TINT_LEAVE_SAME); 1049 if (original_asim
850 apply_background (); 1050 || (background_flags & transpTransformations) != (flags & transpTransformations))
1051 {
1052 ASImage *background = NULL;
1053 ARGB32 as_tint = TINT_LEAVE_SAME;
1054 if (background_flags)
1055 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100);
1056
1057# ifdef ENABLE_TRANSPARENCY
1058 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
1059 {
1060 ShadingInfo as_shade;
1061 as_shade.shading = (shade == 0) ? 100 : shade;
1062
1063 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1064 if (flags & tintSet)
1065 tint.get (c);
1066 as_shade.tintColor.red = c.r;
1067 as_shade.tintColor.green = c.g;
1068 as_shade.tintColor.blue = c.b;
1069
1070 as_tint = shading2tint32 (&as_shade);
1071 }
1072 if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL)
1073 {
1074 ASImage* tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
1075 (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage,
1076 100, ASIMAGE_QUALITY_DEFAULT);
1077 if (tmp)
1078 {
1079 destroy_asimage (&background);
1080 background = tmp;
1081 }
1082 }
1083# endif
1084
1085 if (render_asim (background, as_tint))
1086 flags = flags & ~isInvalid;
1087 if (background)
1088 destroy_asimage (&background);
1089 }
1090 else if (background_flags && pmap_depth != target->depth)
1091 {
1092 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1093 }
1094# else /* our own client-side tinting */
1095 if (background_flags && (flags & isInvalid))
1096 {
1097 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1098 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded))
1099 {
1100 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1101 if (flags & tintSet)
1102 tint.get (c);
1103 ShadeXImage (target, result, shade, c.r, c.g, c.b);
1104 }
1105 }
1106# endif /* HAVE_AFTERIMAGE */
1107
1108 if (result != NULL)
1109 {
1110 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1111 if (gc)
1112 {
1113 if (/*pmap_depth != target->depth &&*/ pixmap != None)
1114 {
1115 XFreePixmap (target->dpy, pixmap);
1116 pixmap = None;
1117 }
1118 if (pixmap == None)
1119 {
1120 pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth);
1121 pmap_width = result->width;
1122 pmap_height = result->height;
1123 pmap_depth = target->depth;
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)
1137 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1138 XFreeGC (target->dpy, gc);
1139 flags = flags & ~isInvalid;
1140 }
1141 XDestroyImage (result);
1142 }
1143
1144 if (flags & isInvalid)
1145 {
1146 if (pixmap != None)
1147 {
1148 XFreePixmap (target->dpy, pixmap);
1149 pixmap = None;
1150 }
1151 }
1152
1153 apply ();
1154
851 return true; 1155 return true;
852# endif
853 return false;
854} 1156}
855 1157
856bool 1158bool
857bgPixmap_t::set_target (rxvt_term *new_target) 1159bgPixmap_t::set_target (rxvt_term *new_target)
858{ 1160{
867 } 1169 }
868 return false; 1170 return false;
869} 1171}
870 1172
871void 1173void
872bgPixmap_t::apply_background() 1174bgPixmap_t::apply()
873{ 1175{
874 if (target) 1176 if (target)
875 { 1177 {
1178 flags &= ~isVtOrigin;
876 if (pixmap != None) 1179 if (pixmap != None)
877 { /* set target's background to pixmap */ 1180 { /* set target's background to pixmap */
878# ifdef ENABLE_TRANSPARENCY 1181# ifdef ENABLE_TRANSPARENCY
879 if (flags & isTransparent) 1182 if (flags & isTransparent)
880 { 1183 {
881 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); 1184 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
882 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); 1185 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1186# if HAVE_SCROLLBARS
883 if (target->scrollBar.win) 1187 if (target->scrollBar.win)
884 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); 1188 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
1189# endif
885 } 1190 }
886 else 1191 else
887# endif 1192# endif
888 { 1193 {
1194 flags |= isVtOrigin;
889 /* force old pixmap dereference in case it was transparent before :*/ 1195 /* force old pixmap dereference in case it was transparent before :*/
890 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_bg]); 1196 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
891 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); 1197 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
892 /* do we also need to set scrollbar's background here ? */ 1198 /* do we also need to set scrollbar's background here ? */
1199# if HAVE_SCROLLBARS
1200 if (target->scrollBar.win)
1201 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1202# endif
893 } 1203 }
894 } 1204 }
895 else 1205 else
896 { /* set target background to a pixel */ 1206 { /* set target background to a pixel */
897 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_bg]); 1207 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
898 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); 1208 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
899 /* do we also need to set scrollbar's background here ? */ 1209 /* do we also need to set scrollbar's background here ? */
1210# if HAVE_SCROLLBARS
1211 if (target->scrollBar.win)
1212 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1213# endif
900 } 1214 }
1215
901 /* don't want Expose on the parent */ 1216 /* don't want Expose on the parent */
902 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, False); 1217 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, False);
903 /* do want Expose on the vt */ 1218 /* do want Expose on the vt, so we get refreshed properly */
904 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, True); 1219 XClearArea (target->dpy, target->vt, 0, 0, 0, 0, True);
905 }
906}
907#endif /* HAVE_BG_PIXMAP */
908 1220
1221# if HAVE_SCROLLBARS
1222 if (target->scrollBar.win)
1223 {
1224 target->scrollBar.setIdle ();
1225 target->scrollbar_show (0);
1226 }
1227# endif
1228 }
1229}
909 1230
910void 1231void
911rxvt_term::get_window_origin (int &x, int &y) 1232rxvt_term::get_window_origin (int &x, int &y)
912{ 1233{
913 Window cr; 1234 Window cr;
914 XTranslateCoordinates (dpy, parent[0], display->root, 0, 0, &x, &y, &cr); 1235 XTranslateCoordinates (dpy, parent[0], display->root, 0, 0, &x, &y, &cr);
1236/* fprintf( stderr, "origin is %+d%+d\n", x, y);*/
915} 1237}
916 1238
917Pixmap 1239Pixmap
918rxvt_term::get_pixmap_property (int prop_id) 1240rxvt_term::get_pixmap_property (int prop_id)
919{ 1241{
920 if (prop_id > 0 && prop_id < NUM_XA) 1242 if (prop_id > 0 && prop_id < NUM_XA)
921 if (xa[prop_id]) 1243 if (xa[prop_id])
922 { 1244 {
923 int aformat, rootdepth; 1245 int aformat;
924 unsigned long nitems, bytes_after; 1246 unsigned long nitems, bytes_after;
925 Atom atype; 1247 Atom atype;
926 unsigned char *prop = NULL; 1248 unsigned char *prop = NULL;
927 int result = XGetWindowProperty (dpy, display->root, xa[prop_id], 1249 int result = XGetWindowProperty (dpy, display->root, xa[prop_id],
928 0L, 1L, False, XA_PIXMAP, &atype, &aformat, 1250 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
933 } 1255 }
934 } 1256 }
935 return None; 1257 return None;
936} 1258}
937 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();
938 1268
939#ifdef ENABLE_TRANSPARENCY 1269 /* no chance of real time refresh if we are blurring ! */
940#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)
941/* taken from aterm-0.4.2 */ 1293/* taken from aterm-0.4.2 */
942 1294
943typedef uint32_t RUINT32T; 1295typedef uint32_t RUINT32T;
944 1296
945static void 1297static void
952 unsigned int upper_lim_r, upper_lim_g, upper_lim_b; 1304 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
953 int i; 1305 int i;
954 1306
955 Visual *visual = term->visual; 1307 Visual *visual = term->visual;
956 1308
957 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ; 1309 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ;
1310
1311 if (shade == 0)
1312 shade = 100;
958 1313
959 /* for convenience */ 1314 /* for convenience */
960 mask_r = visual->red_mask; 1315 mask_r = visual->red_mask;
961 mask_g = visual->green_mask; 1316 mask_g = visual->green_mask;
962 mask_b = visual->blue_mask; 1317 mask_b = visual->blue_mask;
1165 } 1520 }
1166 } 1521 }
1167 1522
1168 free (lookup); 1523 free (lookup);
1169} 1524}
1170#endif 1525#endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */
1171 1526
1172/* 1527#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 1528void
1185rxvt_term::check_our_parents_cb (time_watcher &w) 1529rxvt_term::check_our_parents_cb (time_watcher &w)
1186{ 1530{
1531
1187 int i, aformat, rootdepth; 1532 int i, aformat, rootdepth;
1188 unsigned long nitems, bytes_after; 1533 unsigned long nitems, bytes_after;
1189 Atom atype; 1534 Atom atype;
1190 unsigned char *prop = NULL; 1535 unsigned char *prop = NULL;
1191 Window root, oldp, *list; 1536 Window root, oldp, *list;
1195 Window cr; 1540 Window cr;
1196 unsigned int rootpixmap_w = 0, rootpixmap_h = 0; 1541 unsigned int rootpixmap_w = 0, rootpixmap_h = 0;
1197 1542
1198 if (!option (Opt_transparent)) 1543 if (!option (Opt_transparent))
1199 return; /* Don't try any more */ 1544 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 1545
1211 XGetWindowAttributes (dpy, display->root, &wrootattr); 1546 XGetWindowAttributes (dpy, display->root, &wrootattr);
1212 rootdepth = wrootattr.depth; 1547 rootdepth = wrootattr.depth;
1213 1548
1214 XGetWindowAttributes (dpy, parent[0], &wattr); 1549 XGetWindowAttributes (dpy, parent[0], &wattr);
1348 { 1683 {
1349 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);
1350 success = False; 1685 success = False;
1351 if (image != NULL) 1686 if (image != NULL)
1352 { 1687 {
1353 PRINT_BACKGROUND_OP_TIME;
1354 if (gc == NULL) 1688 if (gc == NULL)
1355 gc = XCreateGC (dpy, vt, 0UL, &gcvalue); 1689 gc = XCreateGC (dpy, vt, 0UL, &gcvalue);
1356 if (ISSET_PIXCOLOR (Color_tint) || shade != 100) 1690 if (ISSET_PIXCOLOR (Color_tint) || shade != 100)
1357 ShadeXImage (this, image, shade, c.r, c.g, c.b); 1691 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); 1692 XPutImage (dpy, bgPixmap.pixmap, gc, image, 0, 0, 0, 0, image->width, image->height);
1359 XDestroyImage (image); 1693 XDestroyImage (image);
1360 success = True; 1694 success = True;
1361 } 1695 }
1362 } 1696 }
1363#endif /* HAVE_AFTERIMAGE */ 1697#endif /* HAVE_AFTERIMAGE */
1364 PRINT_BACKGROUND_OP_TIME;
1365 1698
1366 if (gc != NULL) 1699 if (gc != NULL)
1367 XFreeGC (dpy, gc); 1700 XFreeGC (dpy, gc);
1368 1701
1369 bgPixmap.apply_background(); 1702 bgPixmap.apply();
1370 if (!success) 1703 if (!success)
1371 am_pixmap_trans = 0; 1704 am_pixmap_trans = 0;
1372 else 1705 else
1373 { 1706 {
1374 am_transparent = am_pixmap_trans = 1; 1707 am_transparent = am_pixmap_trans = 1;
1389 if (am_pixmap_trans) 1722 if (am_pixmap_trans)
1390 flush (); 1723 flush ();
1391 } 1724 }
1392 } 1725 }
1393} 1726}
1394#endif 1727#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines