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.63 by sf-exg, Sun Oct 3 21:44:39 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;
226make_align_position (int align, int window_size, int image_size) 230make_align_position (int align, int window_size, int image_size)
227{ 231{
228 int diff = window_size - image_size; 232 int diff = window_size - image_size;
229 int smaller = min (image_size, window_size); 233 int smaller = min (image_size, window_size);
230 234
231 if (align >= 0 && align <= 50) 235 if (align >= 0 && align <= 100)
232 return diff * align / 100; 236 return diff * align / 100;
233 else if (align > 50 && align <= 100)
234 return window_size - image_size - diff * (100 - align) / 100;
235 else if (align > 100 && align <= 200 ) 237 else if (align > 100 && align <= 200 )
236 return ((align - 100) * smaller / 100) + window_size - smaller; 238 return ((align - 100) * smaller / 100) + window_size - smaller;
237 else if (align > -100 && align < 0) 239 else if (align >= -100 && align < 0)
238 return ((align + 100) * smaller / 100) - image_size; 240 return ((align + 100) * smaller / 100) - image_size;
239 return 0; 241 return 0;
240} 242}
241 243
242static inline int 244static inline int
243make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) 245make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size)
244{ 246{
245 int src_pos = 0; 247 int src_pos = 0;
246 dst_pos = 0; 248 dst_pos = pos;
247 dst_size = size; 249 dst_size = size;
248 if (pos < 0) 250 if (pos < 0)
249 { 251 {
250 src_pos = -pos; 252 src_pos = -pos;
253 dst_pos = 0;
251 dst_size += pos; 254 dst_size += pos;
252 } 255 }
253 else if (pos > 0)
254 dst_pos = pos;
255 256
256 if (dst_pos + dst_size > target_size) 257 if (dst_pos + dst_size > target_size)
257 dst_size = target_size - dst_pos; 258 dst_size = target_size - dst_pos;
258 return src_pos; 259 return src_pos;
259} 260}
461 { 462 {
462 w = h_scale * target_width / 100; 463 w = h_scale * target_width / 100;
463 h = v_scale * target_height / 100; 464 h = v_scale * target_height / 100;
464 } 465 }
465 466
467 if (!w) w = image_width;
468 if (!h) h = image_height;
469
466 if (flags & rootAlign) 470 if (flags & rootAlign)
467 { 471 {
468 target->get_window_origin (x, y); 472 target->get_window_origin (x, y);
469 x = -x; 473 x = -x;
470 y = -y; 474 y = -y;
471 } 475 }
472 else 476 else
473 { 477 {
474 x = make_align_position (h_align, target_width, w > 0 ? w : image_width); 478 x = make_align_position (h_align, target_width, w);
475 y = make_align_position (v_align, target_height, h > 0 ? h : image_height); 479 y = make_align_position (v_align, target_height, h);
476 } 480 }
477 481
478 flags &= ~sizeSensitive; 482 flags &= ~sizeSensitive;
479 if (h_scale != 0 || v_scale != 0 483 if (h_scale != 0 || v_scale != 0
480 || h_align != 0 || v_align != 0 484 || h_align != 0 || v_align != 0
481 || image_width > target_width || image_height > target_height) 485 || w > target_width || h > target_height)
482 flags |= sizeSensitive; 486 flags |= sizeSensitive;
483} 487}
484 488
485# ifdef HAVE_AFTERIMAGE 489# ifdef HAVE_AFTERIMAGE
486bool 490bool
499 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);
500 504
501 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 505 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
502 { 506 {
503 ShadingInfo as_shade; 507 ShadingInfo as_shade;
504 as_shade.shading = (shade == 0) ? 100 : shade; 508 as_shade.shading = shade;
505 509
506 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 510 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
507 if (flags & tintSet) 511 if (flags & tintSet)
508 tint.get (c); 512 tint.get (c);
509 as_shade.tintColor.red = c.r; 513 as_shade.tintColor.red = c.r;
511 as_shade.tintColor.blue = c.b; 515 as_shade.tintColor.blue = c.b;
512 516
513 background_tint = shading2tint32 (&as_shade); 517 background_tint = shading2tint32 (&as_shade);
514 } 518 }
515 519
516 if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL) 520 if (!(background_flags & transpPmapBlurred) && (flags & blurNeeded) && background != NULL)
517 { 521 {
518 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,
519 (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage, 523 (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage,
520 100, ASIMAGE_QUALITY_DEFAULT); 524 100, ASIMAGE_QUALITY_DEFAULT);
521 if (tmp) 525 if (tmp)
542 546
543 if (original_asim) 547 if (original_asim)
544 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);
545 549
546 if (!original_asim 550 if (!original_asim
551 || (!(flags & rootAlign)
547 || x >= target_width 552 && (x >= target_width
548 || y >= target_height 553 || y >= target_height
549 || (w > 0 && x + w <= 0) 554 || (x + w <= 0)
550 || (h > 0 && y + h <= 0)) 555 || (y + h <= 0))))
551 { 556 {
552 if (background) 557 if (background)
553 { 558 {
554 new_pmap_width = background->width; 559 new_pmap_width = background->width;
555 new_pmap_height = background->height; 560 new_pmap_height = background->height;
569 } 574 }
570 else 575 else
571 { 576 {
572 result = original_asim; 577 result = original_asim;
573 578
574 if ((w > 0 && w != original_asim->width) 579 if ((w != original_asim->width)
575 || (h > 0 && h != original_asim->height)) 580 || (h != original_asim->height))
576 { 581 {
577 result = scale_asimage (target->asv, original_asim, 582 result = scale_asimage (target->asv, original_asim,
578 w > 0 ? w : original_asim->width, 583 w, h,
579 h > 0 ? h : original_asim->height,
580 background ? ASA_ASImage : ASA_XImage, 584 background ? ASA_ASImage : ASA_XImage,
581 100, ASIMAGE_QUALITY_DEFAULT); 585 100, ASIMAGE_QUALITY_DEFAULT);
582 } 586 }
583 587
584 if (background == NULL) 588 if (background == NULL)
616 layers[0].clip_width = target_width; 620 layers[0].clip_width = target_width;
617 layers[0].clip_height = target_height; 621 layers[0].clip_height = target_height;
618 layers[0].tint = background_tint; 622 layers[0].tint = background_tint;
619 layers[1].im = result; 623 layers[1].im = result;
620 624
621 if (w <= 0) 625 if (h_scale == 0 || v_scale == 0)
622 { 626 {
623 /* tile horizontally */ 627 /* tile horizontally */
624 while (x > 0) x -= (int)result->width; 628 while (x > 0) x -= (int)result->width;
625 layers[1].dst_x = x; 629 layers[1].dst_x = x;
626 layers[1].clip_width = result->width+target_width; 630 layers[1].clip_width = result->width+target_width;
630 /* clip horizontally */ 634 /* clip horizontally */
631 layers[1].dst_x = x; 635 layers[1].dst_x = x;
632 layers[1].clip_width = result->width; 636 layers[1].clip_width = result->width;
633 } 637 }
634 638
635 if (h <= 0) 639 if (h_scale == 0 || v_scale == 0)
636 { 640 {
637 while (y > 0) y -= (int)result->height; 641 while (y > 0) y -= (int)result->height;
638 layers[1].dst_y = y; 642 layers[1].dst_y = y;
639 layers[1].clip_height = result->height + target_height; 643 layers[1].clip_height = result->height + target_height;
640 } 644 }
741 return false; 745 return false;
742 746
743 if (!pixbuf) 747 if (!pixbuf)
744 return false; 748 return false;
745 749
746 // TODO: add alpha blending 750#if !XFT
747 if (background_flags) 751 if (background_flags)
748 return false; 752 return false;
753#endif
749 754
750 GdkPixbuf *result; 755 GdkPixbuf *result;
751 756
752 int image_width = gdk_pixbuf_get_width (pixbuf); 757 int image_width = gdk_pixbuf_get_width (pixbuf);
753 int image_height = gdk_pixbuf_get_height (pixbuf); 758 int image_height = gdk_pixbuf_get_height (pixbuf);
762 int w = 0; 767 int w = 0;
763 int h = 0; 768 int h = 0;
764 769
765 get_image_geometry (image_width, image_height, w, h, x, y); 770 get_image_geometry (image_width, image_height, w, h, x, y);
766 771
772 if (!(flags & rootAlign)
767 if (x >= target_width 773 && (x >= target_width
768 || y >= target_height 774 || y >= target_height
769 || (w > 0 && x + w <= 0) 775 || (x + w <= 0)
770 || (h > 0 && y + h <= 0)) 776 || (y + h <= 0)))
771 return false; 777 return false;
772 778
773 result = pixbuf; 779 result = pixbuf;
774 780
775 if ((w > 0 && w != image_width) 781 if ((w != image_width)
776 || (h > 0 && h != image_height)) 782 || (h != image_height))
777 { 783 {
778 result = gdk_pixbuf_scale_simple (pixbuf, 784 result = gdk_pixbuf_scale_simple (pixbuf,
779 w > 0 ? w : image_width, 785 w, h,
780 h > 0 ? h : image_height,
781 GDK_INTERP_BILINEAR); 786 GDK_INTERP_BILINEAR);
782 } 787 }
783 788
784 bool ret = false; 789 bool ret = false;
785 790
786 if (result) 791 if (result)
787 { 792 {
788 XGCValues gcv; 793 XGCValues gcv;
789 GC gc; 794 GC gc;
795 Pixmap root_pmap;
790 796
791 image_width = gdk_pixbuf_get_width (result); 797 image_width = gdk_pixbuf_get_width (result);
792 image_height = gdk_pixbuf_get_height (result); 798 image_height = gdk_pixbuf_get_height (result);
793 799
800 if (background_flags)
801 {
802 root_pmap = pixmap;
803 pixmap = None;
804 }
805 else
806 {
794 if (h_scale == 0 || v_scale == 0) 807 if (h_scale == 0 || v_scale == 0)
795 { 808 {
796 new_pmap_width = min (image_width, target_width); 809 new_pmap_width = min (image_width, target_width);
797 new_pmap_height = min (image_height, target_height); 810 new_pmap_height = min (image_height, target_height);
811 }
798 } 812 }
799 813
800 if (pixmap) 814 if (pixmap)
801 { 815 {
802 if (pmap_width != new_pmap_width 816 if (pmap_width != new_pmap_width
858 dst_width, dst_height, 872 dst_width, dst_height,
859 XLIB_RGB_DITHER_NONE, 873 XLIB_RGB_DITHER_NONE,
860 0, 0); 874 0, 0);
861 } 875 }
862 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
863 if (result != pixbuf) 915 if (result != pixbuf)
864 g_object_unref (result); 916 g_object_unref (result);
865 917
866 XFreeGC (target->dpy, gc); 918 XFreeGC (target->dpy, gc);
867 919
889 } 941 }
890 942
891# ifdef HAVE_AFTERIMAGE 943# ifdef HAVE_AFTERIMAGE
892 if (!target->asimman) 944 if (!target->asimman)
893 target->asimman = create_generic_imageman (target->rs[Rs_path]); 945 target->asimman = create_generic_imageman (target->rs[Rs_path]);
894 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); 946 ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
947 if (image)
948 {
895 if (original_asim) 949 if (original_asim)
950 safe_asimage_destroy (original_asim);
951 original_asim = image;
896 have_image = true; 952 have_image = true;
897 return have_image; 953 return true;
954 }
898# endif 955# endif
899 956
900# ifdef HAVE_PIXBUF 957# ifdef HAVE_PIXBUF
901 pixbuf = gdk_pixbuf_new_from_file (file, NULL); 958 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL);
959 if (image)
960 {
902 if (pixbuf) 961 if (pixbuf)
962 g_object_unref (pixbuf);
963 pixbuf = image;
903 have_image = true; 964 have_image = true;
904 return have_image; 965 return true;
966 }
905# endif 967# endif
906 } 968 }
907 969
908 return false; 970 return false;
909} 971}
934 if (!(geom_flags & WidthValue)) 996 if (!(geom_flags & WidthValue))
935 hr = 1; 997 hr = 1;
936 if (!(geom_flags & HeightValue)) 998 if (!(geom_flags & HeightValue))
937 vr = hr; 999 vr = hr;
938 1000
1001 min_it (hr, 128);
1002 min_it (vr, 128);
1003
939 if (h_blurRadius != hr) 1004 if (h_blurRadius != hr)
940 { 1005 {
941 ++changed; 1006 ++changed;
942 h_blurRadius = hr; 1007 h_blurRadius = hr;
943 } 1008 }
951 if (v_blurRadius == 0 && h_blurRadius == 0) 1016 if (v_blurRadius == 0 && h_blurRadius == 0)
952 flags &= ~blurNeeded; 1017 flags &= ~blurNeeded;
953 else 1018 else
954 flags |= blurNeeded; 1019 flags |= blurNeeded;
955 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
956 return (changed > 0); 1033 return (changed > 0);
957} 1034}
958 1035
959static inline unsigned long 1036static inline unsigned long
960compute_tint_shade_flags (rxvt_color *tint, int shade) 1037compute_tint_shade_flags (rxvt_color *tint, int shade)
961{ 1038{
962 unsigned long flags = 0; 1039 unsigned long flags = 0;
963 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1040 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
964 bool has_shade = (shade > 0 && shade < 100) || (shade > 100 && shade < 200); 1041 bool has_shade = shade != 100;
965 1042
966 if (tint) 1043 if (tint)
967 { 1044 {
968 tint->get (c); 1045 tint->get (c);
969# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700) 1046# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700)
1001} 1078}
1002 1079
1003bool 1080bool
1004bgPixmap_t::set_tint (rxvt_color &new_tint) 1081bgPixmap_t::set_tint (rxvt_color &new_tint)
1005{ 1082{
1006 if (tint != new_tint) 1083 if (!(flags & tintSet) || tint != new_tint)
1007 { 1084 {
1008 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); 1085 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade);
1009 tint = new_tint; 1086 tint = new_tint;
1010 flags = (flags & ~tintFlags) | new_flags | tintSet; 1087 flags = (flags & ~tintFlags) | new_flags | tintSet;
1011 return true; 1088 return true;
1029} 1106}
1030 1107
1031bool 1108bool
1032bgPixmap_t::set_shade (const char *shade_str) 1109bgPixmap_t::set_shade (const char *shade_str)
1033{ 1110{
1034 int new_shade = (shade_str) ? atoi (shade_str) : 0; 1111 int new_shade = (shade_str) ? atoi (shade_str) : 100;
1035 1112
1036 if (new_shade < 0 && new_shade > -100) 1113 clamp_it (new_shade, -100, 200);
1114 if (new_shade < 0)
1037 new_shade = 200 - (100 + new_shade); 1115 new_shade = 200 - (100 + new_shade);
1038 else if (new_shade == 100)
1039 new_shade = 0;
1040 1116
1041 if (new_shade != shade) 1117 if (new_shade != shade)
1042 { 1118 {
1043 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);
1044 shade = new_shade; 1120 shade = new_shade;
1045 flags = (flags & (~tintFlags | tintSet)) | new_flags; 1121 flags = (flags & (~tintFlags | tintSet)) | new_flags;
1046 return true; 1122 return true;
1047 } 1123 }
1048 1124
1049 return false; 1125 return false;
1126}
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
1149bool
1150bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height)
1151{
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
1158 Display *dpy = target->dpy;
1159 XRenderPictureAttributes pa;
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;
1217 bool ret = false;
1218
1219 if (flags & tintWholesome)
1220 {
1221 XGCValues gcv;
1222 GC gc;
1223
1224 /* In this case we can tint image server-side getting significant
1225 * performance improvements, as we eliminate XImage transfer
1226 */
1227 gcv.foreground = Pixel (tint);
1228 gcv.function = GXand;
1229 gcv.fill_style = FillSolid;
1230 gc = XCreateGC (dpy, pixmap, GCFillStyle | GCForeground | GCFunction, &gcv);
1231 if (gc)
1232 {
1233 XFillRectangle (dpy, pixmap, gc, 0, 0, width, height);
1234 ret = true;
1235 XFreeGC (dpy, gc);
1236 }
1237 }
1238 else
1239 {
1240# if XFT
1241 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1242
1243 if (flags & tintSet)
1244 tint.get (c);
1245
1246 if (shade <= 100)
1247 {
1248 c.r = (c.r * shade) / 100;
1249 c.g = (c.g * shade) / 100;
1250 c.b = (c.b * shade) / 100;
1251 }
1252 else
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 }
1258
1259 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
1260 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1261 XRenderPictureAttributes pa;
1262
1263 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1264
1265 pa.repeat = True;
1266
1267 Pixmap overlay_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32);
1268 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
1269 XFreePixmap (dpy, overlay_pmap);
1270
1271 pa.component_alpha = True;
1272 Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32);
1273 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa);
1274 XFreePixmap (dpy, mask_pmap);
1275
1276 if (mask_pic && overlay_pic && back_pic)
1277 {
1278 XRenderColor mask_c;
1279
1280 memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c));
1281 mask_c.alpha = 0xffff;
1282 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1283
1284 mask_c.alpha = 0;
1285 mask_c.red = 0xffff - c.r;
1286 mask_c.green = 0xffff - c.g;
1287 mask_c.blue = 0xffff - c.b;
1288 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1289 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1290 ret = true;
1291 }
1292
1293 XRenderFreePicture (dpy, mask_pic);
1294 XRenderFreePicture (dpy, overlay_pic);
1295 XRenderFreePicture (dpy, back_pic);
1296# if DO_TIMING_TEST
1297 XSync (dpy, False);
1298# endif
1299# endif
1300 }
1301
1302 return ret;
1050} 1303}
1051 1304
1052/* make_transparency_pixmap() 1305/* make_transparency_pixmap()
1053 * Builds a pixmap sized the same as terminal window, with depth same as the root window 1306 * Builds a pixmap sized the same as terminal window, with depth same as the root window
1054 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by 1307 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by
1073 unsigned int root_pmap_width, root_pmap_height; 1326 unsigned int root_pmap_width, root_pmap_height;
1074 int window_width = target->szHint.width; 1327 int window_width = target->szHint.width;
1075 int window_height = target->szHint.height; 1328 int window_height = target->szHint.height;
1076 int sx, sy; 1329 int sx, sy;
1077 XGCValues gcv; 1330 XGCValues gcv;
1331 GC gc;
1078 1332
1079 TIMING_TEST_START (tp); 1333 TIMING_TEST_START (tp);
1080 target->get_window_origin (sx, sy); 1334 target->get_window_origin (sx, sy);
1081 1335
1082 /* 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 : */
1084 || sx >= root_width || sy >= root_height) 1338 || sx >= root_width || sy >= root_height)
1085 return 0; 1339 return 0;
1086 1340
1087 if (root_pixmap != None) 1341 if (root_pixmap != None)
1088 { 1342 {
1089 /* 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 : */
1090 int junk; 1344 int junk;
1091 unsigned int ujunk; 1345 unsigned int ujunk;
1092 /* root pixmap may be bad - allow a error */ 1346 /* root pixmap may be bad - allow a error */
1093 target->allowedxerror = -1; 1347 target->allowedxerror = -1;
1094 1348
1096 root_pixmap = None; 1350 root_pixmap = None;
1097 1351
1098 target->allowedxerror = 0; 1352 target->allowedxerror = 0;
1099 } 1353 }
1100 1354
1355 if (root_pixmap == None)
1356 return 0;
1357
1101 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);
1102 GC gc = NULL;
1103 1359
1104 if (tiled_root_pmap == None) /* something really bad happened - abort */ 1360 if (tiled_root_pmap == None) /* something really bad happened - abort */
1105 return 0; 1361 return 0;
1106 1362
1107 if (root_pixmap == None)
1108 {
1109 /* use tricks to obtain the root background image :*/
1110 /* we want to create Overrideredirect window overlapping out window
1111 with background type of Parent Relative and then grab it */
1112 XSetWindowAttributes attr;
1113 Window src;
1114 bool success = false;
1115
1116 attr.background_pixmap = ParentRelative;
1117 attr.backing_store = Always;
1118 attr.event_mask = ExposureMask;
1119 attr.override_redirect = True;
1120 src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0,
1121 CopyFromParent, CopyFromParent, CopyFromParent,
1122 CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask,
1123 &attr);
1124
1125 if (src != None)
1126 {
1127 XEvent event;
1128 int ev_count = 0;
1129 XGrabServer (dpy);
1130 XMapRaised (dpy, src);
1131 XSync (dpy, False);
1132
1133 /* XSync should get window where it's properly exposed,
1134 * but to be on the safe side - let's check for the actual event to arrive : */
1135 while (XCheckWindowEvent (dpy, src, ExposureMask, &event))
1136 ++ev_count;
1137
1138 if (ev_count > 0);
1139 {
1140 /* hooray! - we can grab the image! */
1141 gc = XCreateGC (dpy, root, 0, NULL);
1142 if (gc)
1143 {
1144 XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0);
1145 success = true;
1146 }
1147 }
1148
1149 XDestroyWindow (dpy, src);
1150 XUngrabServer (dpy);
1151 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count);
1152 }
1153
1154 if (!success)
1155 {
1156 XFreePixmap (dpy, tiled_root_pmap);
1157 tiled_root_pmap = None;
1158 }
1159 else
1160 result |= transpPmapTiled;
1161 }
1162 else
1163 {
1164 /* straightforward pixmap copy */ 1363 /* straightforward pixmap copy */
1165 gcv.tile = root_pixmap; 1364 gcv.tile = root_pixmap;
1166 gcv.fill_style = FillTiled; 1365 gcv.fill_style = FillTiled;
1167 1366
1168 while (sx < 0) sx += (int)root_width; 1367 while (sx < 0) sx += (int)root_width;
1169 while (sy < 0) sy += (int)root_height; 1368 while (sy < 0) sy += (int)root_height;
1170 1369
1171 gcv.ts_x_origin = -sx; 1370 gcv.ts_x_origin = -sx;
1172 gcv.ts_y_origin = -sy; 1371 gcv.ts_y_origin = -sy;
1173 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 1372 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
1174 1373
1175 if (gc) 1374 if (gc)
1176 { 1375 {
1177 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);
1178 result |= transpPmapTiled; 1377 result |= transpPmapTiled;
1179 } 1378 XFreeGC (dpy, gc);
1180 } 1379 }
1181 TIMING_TEST_PRINT_RESULT (tp); 1380 TIMING_TEST_PRINT_RESULT (tp);
1182 1381
1183 if (tiled_root_pmap != None) 1382 if (tiled_root_pmap != None)
1184 { 1383 {
1185 if (!need_client_side_rendering ()) 1384 if (!need_client_side_rendering ())
1186 { 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 }
1187 if ((flags & tintNeeded)) 1391 if ((flags & tintNeeded))
1188 { 1392 {
1189 if (flags & tintWholesome) 1393 if (tint_pixmap (tiled_root_pmap, DefaultVisual (dpy, target->display->screen), window_width, window_height))
1190 {
1191 /* In this case we can tint image server-side getting significant
1192 * performance improvements, as we eliminate XImage transfer
1193 */
1194 gcv.foreground = Pixel (tint);
1195 gcv.function = GXand;
1196 gcv.fill_style = FillSolid;
1197 if (gc)
1198 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcv);
1199 else
1200 gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv);
1201 if (gc)
1202 {
1203 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
1204 result |= transpPmapTinted; 1394 result |= transpPmapTinted;
1205 }
1206 }
1207 else
1208 {
1209# if XFT
1210 Picture back_pic = 0;
1211 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1212
1213 if (flags & tintSet)
1214 tint.get (c);
1215
1216 if (shade > 0 && shade < 100)
1217 {
1218 c.r = (c.r * shade) / 100;
1219 c.g = (c.g * shade) / 100;
1220 c.b = (c.b * shade) / 100;
1221 }
1222 else if (shade > 100 && shade < 200)
1223 {
1224 c.r = (c.r * (200 - shade)) / 100;
1225 c.g = (c.g * (200 - shade)) / 100;
1226 c.b = (c.b * (200 - shade)) / 100;
1227 }
1228
1229 XRenderPictFormat pf;
1230 pf.type = PictTypeDirect;
1231 pf.depth = 32;
1232 pf.direct.redMask = 0xff;
1233 pf.direct.greenMask = 0xff;
1234 pf.direct.blueMask = 0xff;
1235 pf.direct.alphaMask = 0xff;
1236
1237 XRenderPictFormat *solid_format = XRenderFindFormat (dpy,
1238 (PictFormatType|
1239 PictFormatDepth|
1240 PictFormatRedMask|
1241 PictFormatGreenMask|
1242 PictFormatBlueMask|
1243 PictFormatAlphaMask),
1244 &pf,
1245 0);
1246 XRenderPictFormat *root_format = XRenderFindVisualFormat (dpy, DefaultVisualOfScreen (ScreenOfDisplay (dpy, target->display->screen)));
1247 XRenderPictureAttributes pa ;
1248
1249 back_pic = XRenderCreatePicture (dpy, tiled_root_pmap, root_format, 0, &pa);
1250
1251 pa.repeat = True;
1252
1253 Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32);
1254 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
1255 XFreePixmap (dpy, overlay_pmap);
1256
1257 pa.component_alpha = True;
1258 Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32);
1259 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa);
1260 XFreePixmap (dpy, mask_pmap);
1261
1262 if (mask_pic && overlay_pic && back_pic)
1263 {
1264 XRenderColor mask_c;
1265
1266 memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c));
1267 mask_c.alpha = 0xffff;
1268 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1269
1270 mask_c.alpha = 0;
1271 mask_c.red = 0xffff - c.r;
1272 mask_c.green = 0xffff - c.g;
1273 mask_c.blue = 0xffff - c.b;
1274 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1275 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height);
1276 result |= transpPmapTinted;
1277 }
1278
1279 XRenderFreePicture (dpy, mask_pic);
1280 XRenderFreePicture (dpy, overlay_pic);
1281 XRenderFreePicture (dpy, back_pic);
1282# if DO_TIMING_TEST
1283 XSync (dpy, False);
1284# endif
1285# endif
1286 }
1287 } 1395 }
1288 } /* server side rendering completed */ 1396 } /* server side rendering completed */
1289 1397
1290 if (pixmap) 1398 if (pixmap)
1291 XFreePixmap (dpy, pixmap); 1399 XFreePixmap (dpy, pixmap);
1293 pixmap = tiled_root_pmap; 1401 pixmap = tiled_root_pmap;
1294 pmap_width = window_width; 1402 pmap_width = window_width;
1295 pmap_height = window_height; 1403 pmap_height = window_height;
1296 pmap_depth = root_depth; 1404 pmap_depth = root_depth;
1297 } 1405 }
1298
1299 if (gc)
1300 XFreeGC (dpy, gc);
1301 1406
1302 TIMING_TEST_PRINT_RESULT (tp); 1407 TIMING_TEST_PRINT_RESULT (tp);
1303 1408
1304 return result; 1409 return result;
1305} 1410}
1531 int i; 1636 int i;
1532 1637
1533 Visual *visual = term->visual; 1638 Visual *visual = term->visual;
1534 1639
1535 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ; 1640 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ;
1536
1537 if (shade == 0)
1538 shade = 100;
1539 1641
1540 /* for convenience */ 1642 /* for convenience */
1541 mask_r = visual->red_mask; 1643 mask_r = visual->red_mask;
1542 mask_g = visual->green_mask; 1644 mask_g = visual->green_mask;
1543 mask_b = visual->blue_mask; 1645 mask_b = visual->blue_mask;
1599 default: 1701 default:
1600 return; /* we do not support this color depth */ 1702 return; /* we do not support this color depth */
1601 } 1703 }
1602 1704
1603 /* prepare limits for color transformation (each channel is handled separately) */ 1705 /* prepare limits for color transformation (each channel is handled separately) */
1604 if (shade < 0) { 1706 if (shade > 100) {
1605 shade = -shade; 1707 shade = 200 - shade;
1606 if (shade < 0) shade = 0;
1607 if (shade > 100) shade = 100;
1608 1708
1609 lower_lim_r = 65535-rm; 1709 lower_lim_r = 65535-rm;
1610 lower_lim_g = 65535-gm; 1710 lower_lim_g = 65535-gm;
1611 lower_lim_b = 65535-bm; 1711 lower_lim_b = 65535-bm;
1612 1712
1614 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);
1615 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);
1616 1716
1617 upper_lim_r = upper_lim_g = upper_lim_b = 65535; 1717 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
1618 } else { 1718 } else {
1619 if (shade < 0) shade = 0;
1620 if (shade > 100) shade = 100;
1621 1719
1622 lower_lim_r = lower_lim_g = lower_lim_b = 0; 1720 lower_lim_r = lower_lim_g = lower_lim_b = 0;
1623 1721
1624 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100); 1722 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100);
1625 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