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

Comparing rxvt-unicode/src/background.C (file contents):
Revision 1.66 by sf-exg, Mon Oct 4 20:46:20 2010 UTC vs.
Revision 1.82 by sf-exg, Thu Oct 14 16:01:28 2010 UTC

19 * You should have received a copy of the GNU General Public License 19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software 20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *---------------------------------------------------------------------*/ 22 *---------------------------------------------------------------------*/
23 23
24#include <cmath>
24#include "../config.h" /* NECESSARY */ 25#include "../config.h" /* NECESSARY */
25#include "rxvt.h" /* NECESSARY */ 26#include "rxvt.h" /* NECESSARY */
26 27
27#define DO_TIMING_TEST 0 28#define DO_TIMING_TEST 0
28 29
104#ifdef BG_IMAGE_FROM_FILE 105#ifdef BG_IMAGE_FROM_FILE
105 have_image = false; 106 have_image = false;
106 h_scale = v_scale = 0; 107 h_scale = v_scale = 0;
107 h_align = v_align = 0; 108 h_align = v_align = 0;
108#endif 109#endif
110#ifdef ENABLE_TRANSPARENCY
111 shade = 100;
112#endif
109 flags = 0; 113 flags = 0;
110 pixmap = None; 114 pixmap = None;
111 valid_since = invalid_since = 0; 115 valid_since = invalid_since = 0;
112 target = 0; 116 target = 0;
113} 117}
174 return true; 178 return true;
175# endif 179# endif
176# ifdef ENABLE_TRANSPARENCY 180# ifdef ENABLE_TRANSPARENCY
177 if (flags & isTransparent) 181 if (flags & isTransparent)
178 { 182 {
179# ifdef HAVE_AFTERIMAGE // can't blur without libAI anyways 183# ifdef HAVE_AFTERIMAGE
180 if ((flags & blurNeeded) && !(flags & blurServerSide)) 184 if ((flags & blurNeeded) && !(flags & blurServerSide))
181 return true; 185 return true;
182# endif 186# endif
183 if ((flags & tintNeeded) && !(flags & tintServerSide)) 187 if ((flags & tintNeeded) && !(flags & tintServerSide))
184 return true; 188 return true;
458 { 462 {
459 w = h_scale * target_width / 100; 463 w = h_scale * target_width / 100;
460 h = v_scale * target_height / 100; 464 h = v_scale * target_height / 100;
461 } 465 }
462 466
467 if (!w) w = image_width;
468 if (!h) h = image_height;
469
463 if (flags & rootAlign) 470 if (flags & rootAlign)
464 { 471 {
465 target->get_window_origin (x, y); 472 target->get_window_origin (x, y);
466 x = -x; 473 x = -x;
467 y = -y; 474 y = -y;
468 } 475 }
469 else 476 else
470 { 477 {
471 x = make_align_position (h_align, target_width, w > 0 ? w : image_width); 478 x = make_align_position (h_align, target_width, w);
472 y = make_align_position (v_align, target_height, h > 0 ? h : image_height); 479 y = make_align_position (v_align, target_height, h);
473 } 480 }
474 481
475 flags &= ~sizeSensitive; 482 flags &= ~sizeSensitive;
476 if (h_scale != 0 || v_scale != 0 483 if (h_scale != 0 || v_scale != 0
477 || h_align != 0 || v_align != 0 484 || h_align != 0 || v_align != 0
478 || image_width > target_width || image_height > target_height) 485 || w > target_width || h > target_height)
479 flags |= sizeSensitive; 486 flags |= sizeSensitive;
480} 487}
481 488
482# ifdef HAVE_AFTERIMAGE 489# ifdef HAVE_AFTERIMAGE
483bool 490bool
496 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100); 503 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100);
497 504
498 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 505 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
499 { 506 {
500 ShadingInfo as_shade; 507 ShadingInfo as_shade;
501 as_shade.shading = (shade == 0) ? 100 : shade; 508 as_shade.shading = shade;
502 509
503 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 510 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
504 if (flags & tintSet) 511 if (flags & tintSet)
505 tint.get (c); 512 tint.get (c);
506 as_shade.tintColor.red = c.r; 513 as_shade.tintColor.red = c.r;
508 as_shade.tintColor.blue = c.b; 515 as_shade.tintColor.blue = c.b;
509 516
510 background_tint = shading2tint32 (&as_shade); 517 background_tint = shading2tint32 (&as_shade);
511 } 518 }
512 519
513 if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL) 520 if (!(background_flags & transpPmapBlurred) && (flags & blurNeeded) && background != NULL)
514 { 521 {
515 ASImage *tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, 522 ASImage *tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
516 (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage, 523 (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage,
517 100, ASIMAGE_QUALITY_DEFAULT); 524 100, ASIMAGE_QUALITY_DEFAULT);
518 if (tmp) 525 if (tmp)
539 546
540 if (original_asim) 547 if (original_asim)
541 get_image_geometry (original_asim->width, original_asim->height, w, h, x, y); 548 get_image_geometry (original_asim->width, original_asim->height, w, h, x, y);
542 549
543 if (!original_asim 550 if (!original_asim
551 || (!(flags & rootAlign)
544 || x >= target_width 552 && (x >= target_width
545 || y >= target_height 553 || y >= target_height
546 || (w > 0 && x + w <= 0) 554 || (x + w <= 0)
547 || (h > 0 && y + h <= 0)) 555 || (y + h <= 0))))
548 { 556 {
549 if (background) 557 if (background)
550 { 558 {
551 new_pmap_width = background->width; 559 new_pmap_width = background->width;
552 new_pmap_height = background->height; 560 new_pmap_height = background->height;
566 } 574 }
567 else 575 else
568 { 576 {
569 result = original_asim; 577 result = original_asim;
570 578
571 if ((w > 0 && w != original_asim->width) 579 if ((w != original_asim->width)
572 || (h > 0 && h != original_asim->height)) 580 || (h != original_asim->height))
573 { 581 {
574 result = scale_asimage (target->asv, original_asim, 582 result = scale_asimage (target->asv, original_asim,
575 w > 0 ? w : original_asim->width, 583 w, h,
576 h > 0 ? h : original_asim->height,
577 background ? ASA_ASImage : ASA_XImage, 584 background ? ASA_ASImage : ASA_XImage,
578 100, ASIMAGE_QUALITY_DEFAULT); 585 100, ASIMAGE_QUALITY_DEFAULT);
579 } 586 }
580 587
581 if (background == NULL) 588 if (background == NULL)
613 layers[0].clip_width = target_width; 620 layers[0].clip_width = target_width;
614 layers[0].clip_height = target_height; 621 layers[0].clip_height = target_height;
615 layers[0].tint = background_tint; 622 layers[0].tint = background_tint;
616 layers[1].im = result; 623 layers[1].im = result;
617 624
618 if (w <= 0) 625 if (h_scale == 0 || v_scale == 0)
619 { 626 {
620 /* tile horizontally */ 627 /* tile horizontally */
621 while (x > 0) x -= (int)result->width; 628 while (x > 0) x -= (int)result->width;
622 layers[1].dst_x = x; 629 layers[1].dst_x = x;
623 layers[1].clip_width = result->width+target_width; 630 layers[1].clip_width = result->width+target_width;
627 /* clip horizontally */ 634 /* clip horizontally */
628 layers[1].dst_x = x; 635 layers[1].dst_x = x;
629 layers[1].clip_width = result->width; 636 layers[1].clip_width = result->width;
630 } 637 }
631 638
632 if (h <= 0) 639 if (h_scale == 0 || v_scale == 0)
633 { 640 {
634 while (y > 0) y -= (int)result->height; 641 while (y > 0) y -= (int)result->height;
635 layers[1].dst_y = y; 642 layers[1].dst_y = y;
636 layers[1].clip_height = result->height + target_height; 643 layers[1].clip_height = result->height + target_height;
637 } 644 }
738 return false; 745 return false;
739 746
740 if (!pixbuf) 747 if (!pixbuf)
741 return false; 748 return false;
742 749
743 // TODO: add alpha blending 750#if !XFT
744 if (background_flags) 751 if (background_flags)
745 return false; 752 return false;
753#endif
746 754
747 GdkPixbuf *result; 755 GdkPixbuf *result;
748 756
749 int image_width = gdk_pixbuf_get_width (pixbuf); 757 int image_width = gdk_pixbuf_get_width (pixbuf);
750 int image_height = gdk_pixbuf_get_height (pixbuf); 758 int image_height = gdk_pixbuf_get_height (pixbuf);
759 int w = 0; 767 int w = 0;
760 int h = 0; 768 int h = 0;
761 769
762 get_image_geometry (image_width, image_height, w, h, x, y); 770 get_image_geometry (image_width, image_height, w, h, x, y);
763 771
772 if (!(flags & rootAlign)
764 if (x >= target_width 773 && (x >= target_width
765 || y >= target_height 774 || y >= target_height
766 || (w > 0 && x + w <= 0) 775 || (x + w <= 0)
767 || (h > 0 && y + h <= 0)) 776 || (y + h <= 0)))
768 return false; 777 return false;
769 778
770 result = pixbuf; 779 result = pixbuf;
771 780
772 if ((w > 0 && w != image_width) 781 if ((w != image_width)
773 || (h > 0 && h != image_height)) 782 || (h != image_height))
774 { 783 {
775 result = gdk_pixbuf_scale_simple (pixbuf, 784 result = gdk_pixbuf_scale_simple (pixbuf,
776 w > 0 ? w : image_width, 785 w, h,
777 h > 0 ? h : image_height,
778 GDK_INTERP_BILINEAR); 786 GDK_INTERP_BILINEAR);
779 } 787 }
780 788
781 bool ret = false; 789 bool ret = false;
782 790
783 if (result) 791 if (result)
784 { 792 {
785 XGCValues gcv; 793 XGCValues gcv;
786 GC gc; 794 GC gc;
795 Pixmap root_pmap;
787 796
788 image_width = gdk_pixbuf_get_width (result); 797 image_width = gdk_pixbuf_get_width (result);
789 image_height = gdk_pixbuf_get_height (result); 798 image_height = gdk_pixbuf_get_height (result);
790 799
800 if (background_flags)
801 {
802 root_pmap = pixmap;
803 pixmap = None;
804 }
805 else
806 {
791 if (h_scale == 0 || v_scale == 0) 807 if (h_scale == 0 || v_scale == 0)
792 { 808 {
793 new_pmap_width = min (image_width, target_width); 809 new_pmap_width = min (image_width, target_width);
794 new_pmap_height = min (image_height, target_height); 810 new_pmap_height = min (image_height, target_height);
811 }
795 } 812 }
796 813
797 if (pixmap) 814 if (pixmap)
798 { 815 {
799 if (pmap_width != new_pmap_width 816 if (pmap_width != new_pmap_width
855 dst_width, dst_height, 872 dst_width, dst_height,
856 XLIB_RGB_DITHER_NONE, 873 XLIB_RGB_DITHER_NONE,
857 0, 0); 874 0, 0);
858 } 875 }
859 876
877#if XFT
878 if (background_flags)
879 {
880 Display *dpy = target->dpy;
881 XRenderPictureAttributes pa;
882
883 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, target->display->screen));
884 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa);
885
886 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual);
887 Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa);
888
889 pa.repeat = True;
890 Pixmap mask_pmap = XCreatePixmap (dpy, target->vt, 1, 1, 8);
891 XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8);
892 Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa);
893 XFreePixmap (dpy, mask_pmap);
894
895 if (src && dst && mask)
896 {
897 XRenderColor mask_c;
898
899 mask_c.alpha = 0x8000;
900 mask_c.red = 0;
901 mask_c.green = 0;
902 mask_c.blue = 0;
903 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1);
904 XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height);
905 }
906
907 XRenderFreePicture (dpy, src);
908 XRenderFreePicture (dpy, dst);
909 XRenderFreePicture (dpy, mask);
910
911 XFreePixmap (dpy, root_pmap);
912 }
913#endif
914
860 if (result != pixbuf) 915 if (result != pixbuf)
861 g_object_unref (result); 916 g_object_unref (result);
862 917
863 XFreeGC (target->dpy, gc); 918 XFreeGC (target->dpy, gc);
864 919
886 } 941 }
887 942
888# ifdef HAVE_AFTERIMAGE 943# ifdef HAVE_AFTERIMAGE
889 if (!target->asimman) 944 if (!target->asimman)
890 target->asimman = create_generic_imageman (target->rs[Rs_path]); 945 target->asimman = create_generic_imageman (target->rs[Rs_path]);
891 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); 946 ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
947 if (image)
948 {
892 if (original_asim) 949 if (original_asim)
950 safe_asimage_destroy (original_asim);
951 original_asim = image;
893 have_image = true; 952 have_image = true;
894 return have_image; 953 return true;
954 }
895# endif 955# endif
896 956
897# ifdef HAVE_PIXBUF 957# ifdef HAVE_PIXBUF
898 pixbuf = gdk_pixbuf_new_from_file (file, NULL); 958 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL);
959 if (image)
960 {
899 if (pixbuf) 961 if (pixbuf)
962 g_object_unref (pixbuf);
963 pixbuf = image;
900 have_image = true; 964 have_image = true;
901 return have_image; 965 return true;
966 }
902# endif 967# endif
903 } 968 }
904 969
905 return false; 970 return false;
906} 971}
931 if (!(geom_flags & WidthValue)) 996 if (!(geom_flags & WidthValue))
932 hr = 1; 997 hr = 1;
933 if (!(geom_flags & HeightValue)) 998 if (!(geom_flags & HeightValue))
934 vr = hr; 999 vr = hr;
935 1000
1001 min_it (hr, 128);
1002 min_it (vr, 128);
1003
936 if (h_blurRadius != hr) 1004 if (h_blurRadius != hr)
937 { 1005 {
938 ++changed; 1006 ++changed;
939 h_blurRadius = hr; 1007 h_blurRadius = hr;
940 } 1008 }
948 if (v_blurRadius == 0 && h_blurRadius == 0) 1016 if (v_blurRadius == 0 && h_blurRadius == 0)
949 flags &= ~blurNeeded; 1017 flags &= ~blurNeeded;
950 else 1018 else
951 flags |= blurNeeded; 1019 flags |= blurNeeded;
952 1020
1021#if XFT
1022 XFilters *filters = XRenderQueryFilters (target->dpy, target->display->root);
1023 if (filters)
1024 {
1025 for (int i = 0; i < filters->nfilter; i++)
1026 if (!strcmp (filters->filter[i], FilterConvolution))
1027 flags |= bgPixmap_t::blurServerSide;
1028
1029 XFree (filters);
1030 }
1031#endif
1032
953 return (changed > 0); 1033 return (changed > 0);
954} 1034}
955 1035
956static inline unsigned long 1036static inline unsigned long
957compute_tint_shade_flags (rxvt_color *tint, int shade) 1037compute_tint_shade_flags (rxvt_color *tint, int shade)
958{ 1038{
959 unsigned long flags = 0; 1039 unsigned long flags = 0;
960 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1040 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
961 bool has_shade = (shade > 0 && shade < 100) || (shade > 100 && shade < 200); 1041 bool has_shade = shade != 100;
962 1042
963 if (tint) 1043 if (tint)
964 { 1044 {
965 tint->get (c); 1045 tint->get (c);
966# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700) 1046# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700)
998} 1078}
999 1079
1000bool 1080bool
1001bgPixmap_t::set_tint (rxvt_color &new_tint) 1081bgPixmap_t::set_tint (rxvt_color &new_tint)
1002{ 1082{
1003 if (tint != new_tint) 1083 if (!(flags & tintSet) || tint != new_tint)
1004 { 1084 {
1005 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); 1085 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade);
1006 tint = new_tint; 1086 tint = new_tint;
1007 flags = (flags & ~tintFlags) | new_flags | tintSet; 1087 flags = (flags & ~tintFlags) | new_flags | tintSet;
1008 return true; 1088 return true;
1026} 1106}
1027 1107
1028bool 1108bool
1029bgPixmap_t::set_shade (const char *shade_str) 1109bgPixmap_t::set_shade (const char *shade_str)
1030{ 1110{
1031 int new_shade = (shade_str) ? atoi (shade_str) : 0; 1111 int new_shade = (shade_str) ? atoi (shade_str) : 100;
1032 1112
1033 if (new_shade < 0 && new_shade > -100) 1113 clamp_it (new_shade, -100, 200);
1114 if (new_shade < 0)
1034 new_shade = 200 - (100 + new_shade); 1115 new_shade = 200 - (100 + new_shade);
1035 else if (new_shade == 100)
1036 new_shade = 0;
1037 1116
1038 if (new_shade != shade) 1117 if (new_shade != shade)
1039 { 1118 {
1040 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); 1119 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade);
1041 shade = new_shade; 1120 shade = new_shade;
1044 } 1123 }
1045 1124
1046 return false; 1125 return false;
1047} 1126}
1048 1127
1128static void
1129get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params)
1130{
1131 double sigma = radius / 2.0;
1132 double scale = sqrt (2.0 * M_PI) * sigma;
1133 double sum = 0.0;
1134
1135 for (int i = 0; i < width; i++)
1136 {
1137 double x = i - width / 2;
1138 kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale;
1139 sum += kernel[i];
1140 }
1141
1142 params[0] = XDoubleToFixed (width);
1143 params[1] = XDoubleToFixed (1);
1144
1145 for (int i = 0; i < width; i++)
1146 params[i+2] = XDoubleToFixed (kernel[i] / sum);
1147}
1148
1049bool 1149bool
1050bgPixmap_t::tint_pixmap (Pixmap pixmap) 1150bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height)
1051{ 1151{
1052 Window root = target->display->root; 1152 bool ret = false;
1153#if XFT
1154 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
1155 double *kernel = (double *)malloc (size * sizeof (double));
1156 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
1157
1053 Display *dpy = target->dpy; 1158 Display *dpy = target->dpy;
1054 int window_width = target->szHint.width; 1159 XRenderPictureAttributes pa;
1055 int window_height = target->szHint.height; 1160 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, target->visual);
1161
1162 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1163 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1164
1165 if (kernel && params && src && dst)
1166 {
1167 if (h_blurRadius)
1168 {
1169 size = h_blurRadius * 2 + 1;
1170 get_gaussian_kernel (h_blurRadius, size, kernel, params);
1171
1172 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
1173 XRenderComposite (dpy,
1174 PictOpSrc,
1175 src,
1176 None,
1177 dst,
1178 0, 0,
1179 0, 0,
1180 0, 0,
1181 width, height);
1182 }
1183
1184 if (v_blurRadius)
1185 {
1186 size = v_blurRadius * 2 + 1;
1187 get_gaussian_kernel (v_blurRadius, size, kernel, params);
1188 swap (params[0], params[1]);
1189
1190 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
1191 XRenderComposite (dpy,
1192 PictOpSrc,
1193 src,
1194 None,
1195 dst,
1196 0, 0,
1197 0, 0,
1198 0, 0,
1199 width, height);
1200 }
1201
1202 ret = true;
1203 }
1204
1205 free (kernel);
1206 free (params);
1207 XRenderFreePicture (dpy, src);
1208 XRenderFreePicture (dpy, dst);
1209#endif
1210 return ret;
1211}
1212
1213bool
1214bgPixmap_t::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height)
1215{
1216 Display *dpy = target->dpy;
1056 bool ret = false; 1217 bool ret = false;
1057 1218
1058 if (flags & tintWholesome) 1219 if (flags & tintWholesome)
1059 { 1220 {
1060 XGCValues gcv; 1221 XGCValues gcv;
1064 * performance improvements, as we eliminate XImage transfer 1225 * performance improvements, as we eliminate XImage transfer
1065 */ 1226 */
1066 gcv.foreground = Pixel (tint); 1227 gcv.foreground = Pixel (tint);
1067 gcv.function = GXand; 1228 gcv.function = GXand;
1068 gcv.fill_style = FillSolid; 1229 gcv.fill_style = FillSolid;
1069 gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv); 1230 gc = XCreateGC (dpy, pixmap, GCFillStyle | GCForeground | GCFunction, &gcv);
1070 if (gc) 1231 if (gc)
1071 { 1232 {
1072 XFillRectangle (dpy, pixmap, gc, 0, 0, window_width, window_height); 1233 XFillRectangle (dpy, pixmap, gc, 0, 0, width, height);
1073 ret = true; 1234 ret = true;
1074 XFreeGC (dpy, gc); 1235 XFreeGC (dpy, gc);
1075 } 1236 }
1076 } 1237 }
1077 else 1238 else
1080 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1241 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1081 1242
1082 if (flags & tintSet) 1243 if (flags & tintSet)
1083 tint.get (c); 1244 tint.get (c);
1084 1245
1085 if (shade > 0 && shade < 100) 1246 if (shade <= 100)
1086 { 1247 {
1087 c.r = (c.r * shade) / 100; 1248 c.r = (c.r * shade) / 100;
1088 c.g = (c.g * shade) / 100; 1249 c.g = (c.g * shade) / 100;
1089 c.b = (c.b * shade) / 100; 1250 c.b = (c.b * shade) / 100;
1090 } 1251 }
1091 else if (shade > 100 && shade < 200) 1252 else
1092 {
1093 c.r = (c.r * (200 - shade)) / 100;
1094 c.g = (c.g * (200 - shade)) / 100;
1095 c.b = (c.b * (200 - shade)) / 100;
1096 } 1253 {
1254 c.r = ((0xffff - c.r) * (200 - shade)) / 100;
1255 c.g = ((0xffff - c.g) * (200 - shade)) / 100;
1256 c.b = ((0xffff - c.b) * (200 - shade)) / 100;
1257 }
1097 1258
1098 XRenderPictFormat pf; 1259 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
1099 pf.type = PictTypeDirect;
1100 pf.depth = 32;
1101 pf.direct.redMask = 0xff;
1102 pf.direct.greenMask = 0xff;
1103 pf.direct.blueMask = 0xff;
1104 pf.direct.alphaMask = 0xff;
1105
1106 XRenderPictFormat *solid_format = XRenderFindFormat (dpy, 1260 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1107 (PictFormatType|
1108 PictFormatDepth|
1109 PictFormatRedMask|
1110 PictFormatGreenMask|
1111 PictFormatBlueMask|
1112 PictFormatAlphaMask),
1113 &pf,
1114 0);
1115 XRenderPictFormat *root_format = XRenderFindVisualFormat (dpy, DefaultVisualOfScreen (ScreenOfDisplay (dpy, target->display->screen)));
1116 XRenderPictureAttributes pa; 1261 XRenderPictureAttributes pa;
1117 1262
1118 Picture back_pic = XRenderCreatePicture (dpy, pixmap, root_format, 0, &pa); 1263 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1119 1264
1120 pa.repeat = True; 1265 pa.repeat = True;
1121 1266
1122 Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32); 1267 Pixmap overlay_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32);
1123 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); 1268 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
1124 XFreePixmap (dpy, overlay_pmap); 1269 XFreePixmap (dpy, overlay_pmap);
1125 1270
1126 pa.component_alpha = True; 1271 pa.component_alpha = True;
1127 Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32); 1272 Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32);
1128 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa); 1273 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa);
1129 XFreePixmap (dpy, mask_pmap); 1274 XFreePixmap (dpy, mask_pmap);
1130 1275
1131 if (mask_pic && overlay_pic && back_pic) 1276 if (mask_pic && overlay_pic && back_pic)
1132 { 1277 {
1139 mask_c.alpha = 0; 1284 mask_c.alpha = 0;
1140 mask_c.red = 0xffff - c.r; 1285 mask_c.red = 0xffff - c.r;
1141 mask_c.green = 0xffff - c.g; 1286 mask_c.green = 0xffff - c.g;
1142 mask_c.blue = 0xffff - c.b; 1287 mask_c.blue = 0xffff - c.b;
1143 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); 1288 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1144 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height); 1289 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1145 ret = true; 1290 ret = true;
1146 } 1291 }
1147 1292
1148 XRenderFreePicture (dpy, mask_pic); 1293 XRenderFreePicture (dpy, mask_pic);
1149 XRenderFreePicture (dpy, overlay_pic); 1294 XRenderFreePicture (dpy, overlay_pic);
1181 unsigned int root_pmap_width, root_pmap_height; 1326 unsigned int root_pmap_width, root_pmap_height;
1182 int window_width = target->szHint.width; 1327 int window_width = target->szHint.width;
1183 int window_height = target->szHint.height; 1328 int window_height = target->szHint.height;
1184 int sx, sy; 1329 int sx, sy;
1185 XGCValues gcv; 1330 XGCValues gcv;
1331 GC gc;
1186 1332
1187 TIMING_TEST_START (tp); 1333 TIMING_TEST_START (tp);
1188 target->get_window_origin (sx, sy); 1334 target->get_window_origin (sx, sy);
1189 1335
1190 /* check if we are outside of the visible part of the virtual screen : */ 1336 /* check if we are outside of the visible part of the virtual screen : */
1192 || sx >= root_width || sy >= root_height) 1338 || sx >= root_width || sy >= root_height)
1193 return 0; 1339 return 0;
1194 1340
1195 if (root_pixmap != None) 1341 if (root_pixmap != None)
1196 { 1342 {
1197 /* we want to validate the pixmap and get it's size at the same time : */ 1343 /* we want to validate the pixmap and get its size at the same time : */
1198 int junk; 1344 int junk;
1199 unsigned int ujunk; 1345 unsigned int ujunk;
1200 /* root pixmap may be bad - allow a error */ 1346 /* root pixmap may be bad - allow a error */
1201 target->allowedxerror = -1; 1347 target->allowedxerror = -1;
1202 1348
1204 root_pixmap = None; 1350 root_pixmap = None;
1205 1351
1206 target->allowedxerror = 0; 1352 target->allowedxerror = 0;
1207 } 1353 }
1208 1354
1355 if (root_pixmap == None)
1356 return 0;
1357
1209 Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth); 1358 Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth);
1210 GC gc = NULL;
1211 1359
1212 if (tiled_root_pmap == None) /* something really bad happened - abort */ 1360 if (tiled_root_pmap == None) /* something really bad happened - abort */
1213 return 0; 1361 return 0;
1214 1362
1215 if (root_pixmap == None)
1216 {
1217 /* use tricks to obtain the root background image :*/
1218 /* we want to create Overrideredirect window overlapping out window
1219 with background type of Parent Relative and then grab it */
1220 XSetWindowAttributes attr;
1221 Window src;
1222 bool success = false;
1223
1224 attr.background_pixmap = ParentRelative;
1225 attr.backing_store = Always;
1226 attr.event_mask = ExposureMask;
1227 attr.override_redirect = True;
1228 src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0,
1229 CopyFromParent, CopyFromParent, CopyFromParent,
1230 CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask,
1231 &attr);
1232
1233 if (src != None)
1234 {
1235 XEvent event;
1236 int ev_count = 0;
1237 XGrabServer (dpy);
1238 XMapRaised (dpy, src);
1239 XSync (dpy, False);
1240
1241 /* XSync should get window where it's properly exposed,
1242 * but to be on the safe side - let's check for the actual event to arrive : */
1243 while (XCheckWindowEvent (dpy, src, ExposureMask, &event))
1244 ++ev_count;
1245
1246 if (ev_count > 0);
1247 {
1248 /* hooray! - we can grab the image! */
1249 gc = XCreateGC (dpy, root, 0, NULL);
1250 if (gc)
1251 {
1252 XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0);
1253 success = true;
1254 }
1255 }
1256
1257 XDestroyWindow (dpy, src);
1258 XUngrabServer (dpy);
1259 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count);
1260 }
1261
1262 if (!success)
1263 {
1264 XFreePixmap (dpy, tiled_root_pmap);
1265 tiled_root_pmap = None;
1266 }
1267 else
1268 result |= transpPmapTiled;
1269 }
1270 else
1271 {
1272 /* straightforward pixmap copy */ 1363 /* straightforward pixmap copy */
1273 gcv.tile = root_pixmap; 1364 gcv.tile = root_pixmap;
1274 gcv.fill_style = FillTiled; 1365 gcv.fill_style = FillTiled;
1275 1366
1276 while (sx < 0) sx += (int)root_width; 1367 while (sx < 0) sx += (int)root_width;
1277 while (sy < 0) sy += (int)root_height; 1368 while (sy < 0) sy += (int)root_height;
1278 1369
1279 gcv.ts_x_origin = -sx; 1370 gcv.ts_x_origin = -sx;
1280 gcv.ts_y_origin = -sy; 1371 gcv.ts_y_origin = -sy;
1281 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 1372 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
1282 1373
1283 if (gc) 1374 if (gc)
1284 { 1375 {
1285 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); 1376 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
1286 result |= transpPmapTiled; 1377 result |= transpPmapTiled;
1287 } 1378 XFreeGC (dpy, gc);
1288 } 1379 }
1289 TIMING_TEST_PRINT_RESULT (tp); 1380 TIMING_TEST_PRINT_RESULT (tp);
1290 1381
1291 if (tiled_root_pmap != None) 1382 if (tiled_root_pmap != None)
1292 { 1383 {
1293 if (!need_client_side_rendering ()) 1384 if (!need_client_side_rendering ())
1294 { 1385 {
1386 if ((flags & blurNeeded))
1387 {
1388 if (blur_pixmap (tiled_root_pmap, DefaultVisual (dpy, target->display->screen), window_width, window_height))
1389 result |= transpPmapBlurred;
1390 }
1295 if ((flags & tintNeeded)) 1391 if ((flags & tintNeeded))
1296 { 1392 {
1297 if (tint_pixmap (tiled_root_pmap)) 1393 if (tint_pixmap (tiled_root_pmap, DefaultVisual (dpy, target->display->screen), window_width, window_height))
1298 result |= transpPmapTinted; 1394 result |= transpPmapTinted;
1299 } 1395 }
1300 } /* server side rendering completed */ 1396 } /* server side rendering completed */
1301 1397
1302 if (pixmap) 1398 if (pixmap)
1305 pixmap = tiled_root_pmap; 1401 pixmap = tiled_root_pmap;
1306 pmap_width = window_width; 1402 pmap_width = window_width;
1307 pmap_height = window_height; 1403 pmap_height = window_height;
1308 pmap_depth = root_depth; 1404 pmap_depth = root_depth;
1309 } 1405 }
1310
1311 if (gc)
1312 XFreeGC (dpy, gc);
1313 1406
1314 TIMING_TEST_PRINT_RESULT (tp); 1407 TIMING_TEST_PRINT_RESULT (tp);
1315 1408
1316 return result; 1409 return result;
1317} 1410}
1543 int i; 1636 int i;
1544 1637
1545 Visual *visual = term->visual; 1638 Visual *visual = term->visual;
1546 1639
1547 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ; 1640 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ;
1548
1549 if (shade == 0)
1550 shade = 100;
1551 1641
1552 /* for convenience */ 1642 /* for convenience */
1553 mask_r = visual->red_mask; 1643 mask_r = visual->red_mask;
1554 mask_g = visual->green_mask; 1644 mask_g = visual->green_mask;
1555 mask_b = visual->blue_mask; 1645 mask_b = visual->blue_mask;
1611 default: 1701 default:
1612 return; /* we do not support this color depth */ 1702 return; /* we do not support this color depth */
1613 } 1703 }
1614 1704
1615 /* prepare limits for color transformation (each channel is handled separately) */ 1705 /* prepare limits for color transformation (each channel is handled separately) */
1616 if (shade < 0) { 1706 if (shade > 100) {
1617 shade = -shade; 1707 shade = 200 - shade;
1618 if (shade < 0) shade = 0;
1619 if (shade > 100) shade = 100;
1620 1708
1621 lower_lim_r = 65535-rm; 1709 lower_lim_r = 65535-rm;
1622 lower_lim_g = 65535-gm; 1710 lower_lim_g = 65535-gm;
1623 lower_lim_b = 65535-bm; 1711 lower_lim_b = 65535-bm;
1624 1712
1626 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100); 1714 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100);
1627 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100); 1715 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100);
1628 1716
1629 upper_lim_r = upper_lim_g = upper_lim_b = 65535; 1717 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
1630 } else { 1718 } else {
1631 if (shade < 0) shade = 0;
1632 if (shade > 100) shade = 100;
1633 1719
1634 lower_lim_r = lower_lim_g = lower_lim_b = 0; 1720 lower_lim_r = lower_lim_g = lower_lim_b = 0;
1635 1721
1636 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100); 1722 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100);
1637 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100); 1723 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines