… | |
… | |
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; |
… | |
… | |
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) |
… | |
… | |
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); |
… | |
… | |
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 | |
959 | static inline unsigned long |
1036 | static inline unsigned long |
960 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
1037 | compute_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 | |
1003 | bool |
1080 | bool |
1004 | bgPixmap_t::set_tint (rxvt_color &new_tint) |
1081 | bgPixmap_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 | |
1031 | bool |
1108 | bool |
1032 | bgPixmap_t::set_shade (const char *shade_str) |
1109 | bgPixmap_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; |
… | |
… | |
1047 | } |
1123 | } |
1048 | |
1124 | |
1049 | return false; |
1125 | return false; |
1050 | } |
1126 | } |
1051 | |
1127 | |
|
|
1128 | static void |
|
|
1129 | get_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 | |
1052 | bool |
1149 | bool |
1053 | bgPixmap_t::tint_pixmap (Pixmap pixmap) |
1150 | bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
1054 | { |
1151 | { |
1055 | 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 | |
1056 | Display *dpy = target->dpy; |
1158 | Display *dpy = target->dpy; |
1057 | int window_width = target->szHint.width; |
1159 | XRenderPictureAttributes pa; |
1058 | 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 | |
|
|
1213 | bool |
|
|
1214 | bgPixmap_t::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
|
|
1215 | { |
|
|
1216 | Display *dpy = target->dpy; |
1059 | bool ret = false; |
1217 | bool ret = false; |
1060 | |
1218 | |
1061 | if (flags & tintWholesome) |
1219 | if (flags & tintWholesome) |
1062 | { |
1220 | { |
1063 | XGCValues gcv; |
1221 | XGCValues gcv; |
… | |
… | |
1067 | * performance improvements, as we eliminate XImage transfer |
1225 | * performance improvements, as we eliminate XImage transfer |
1068 | */ |
1226 | */ |
1069 | gcv.foreground = Pixel (tint); |
1227 | gcv.foreground = Pixel (tint); |
1070 | gcv.function = GXand; |
1228 | gcv.function = GXand; |
1071 | gcv.fill_style = FillSolid; |
1229 | gcv.fill_style = FillSolid; |
1072 | gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv); |
1230 | gc = XCreateGC (dpy, pixmap, GCFillStyle | GCForeground | GCFunction, &gcv); |
1073 | if (gc) |
1231 | if (gc) |
1074 | { |
1232 | { |
1075 | XFillRectangle (dpy, pixmap, gc, 0, 0, window_width, window_height); |
1233 | XFillRectangle (dpy, pixmap, gc, 0, 0, width, height); |
1076 | ret = true; |
1234 | ret = true; |
1077 | XFreeGC (dpy, gc); |
1235 | XFreeGC (dpy, gc); |
1078 | } |
1236 | } |
1079 | } |
1237 | } |
1080 | else |
1238 | else |
… | |
… | |
1083 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1241 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1084 | |
1242 | |
1085 | if (flags & tintSet) |
1243 | if (flags & tintSet) |
1086 | tint.get (c); |
1244 | tint.get (c); |
1087 | |
1245 | |
1088 | if (shade > 0 && shade < 100) |
1246 | if (shade <= 100) |
1089 | { |
1247 | { |
1090 | c.r = (c.r * shade) / 100; |
1248 | c.r = (c.r * shade) / 100; |
1091 | c.g = (c.g * shade) / 100; |
1249 | c.g = (c.g * shade) / 100; |
1092 | c.b = (c.b * shade) / 100; |
1250 | c.b = (c.b * shade) / 100; |
1093 | } |
1251 | } |
1094 | else if (shade > 100 && shade < 200) |
1252 | else |
1095 | { |
|
|
1096 | c.r = (c.r * (200 - shade)) / 100; |
|
|
1097 | c.g = (c.g * (200 - shade)) / 100; |
|
|
1098 | c.b = (c.b * (200 - shade)) / 100; |
|
|
1099 | } |
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 | } |
1100 | |
1258 | |
1101 | XRenderPictFormat pf; |
1259 | XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
1102 | pf.type = PictTypeDirect; |
|
|
1103 | pf.depth = 32; |
|
|
1104 | pf.direct.redMask = 0xff; |
|
|
1105 | pf.direct.greenMask = 0xff; |
|
|
1106 | pf.direct.blueMask = 0xff; |
|
|
1107 | pf.direct.alphaMask = 0xff; |
|
|
1108 | |
|
|
1109 | XRenderPictFormat *solid_format = XRenderFindFormat (dpy, |
1260 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1110 | (PictFormatType| |
|
|
1111 | PictFormatDepth| |
|
|
1112 | PictFormatRedMask| |
|
|
1113 | PictFormatGreenMask| |
|
|
1114 | PictFormatBlueMask| |
|
|
1115 | PictFormatAlphaMask), |
|
|
1116 | &pf, |
|
|
1117 | 0); |
|
|
1118 | XRenderPictFormat *root_format = XRenderFindVisualFormat (dpy, DefaultVisualOfScreen (ScreenOfDisplay (dpy, target->display->screen))); |
|
|
1119 | XRenderPictureAttributes pa; |
1261 | XRenderPictureAttributes pa; |
1120 | |
1262 | |
1121 | Picture back_pic = XRenderCreatePicture (dpy, pixmap, root_format, 0, &pa); |
1263 | Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1122 | |
1264 | |
1123 | pa.repeat = True; |
1265 | pa.repeat = True; |
1124 | |
1266 | |
1125 | Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32); |
1267 | Pixmap overlay_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); |
1126 | Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); |
1268 | Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); |
1127 | XFreePixmap (dpy, overlay_pmap); |
1269 | XFreePixmap (dpy, overlay_pmap); |
1128 | |
1270 | |
1129 | pa.component_alpha = True; |
1271 | pa.component_alpha = True; |
1130 | Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32); |
1272 | Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); |
1131 | 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); |
1132 | XFreePixmap (dpy, mask_pmap); |
1274 | XFreePixmap (dpy, mask_pmap); |
1133 | |
1275 | |
1134 | if (mask_pic && overlay_pic && back_pic) |
1276 | if (mask_pic && overlay_pic && back_pic) |
1135 | { |
1277 | { |
… | |
… | |
1142 | mask_c.alpha = 0; |
1284 | mask_c.alpha = 0; |
1143 | mask_c.red = 0xffff - c.r; |
1285 | mask_c.red = 0xffff - c.r; |
1144 | mask_c.green = 0xffff - c.g; |
1286 | mask_c.green = 0xffff - c.g; |
1145 | mask_c.blue = 0xffff - c.b; |
1287 | mask_c.blue = 0xffff - c.b; |
1146 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
1288 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
1147 | 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); |
1148 | ret = true; |
1290 | ret = true; |
1149 | } |
1291 | } |
1150 | |
1292 | |
1151 | XRenderFreePicture (dpy, mask_pic); |
1293 | XRenderFreePicture (dpy, mask_pic); |
1152 | XRenderFreePicture (dpy, overlay_pic); |
1294 | XRenderFreePicture (dpy, overlay_pic); |
… | |
… | |
1184 | unsigned int root_pmap_width, root_pmap_height; |
1326 | unsigned int root_pmap_width, root_pmap_height; |
1185 | int window_width = target->szHint.width; |
1327 | int window_width = target->szHint.width; |
1186 | int window_height = target->szHint.height; |
1328 | int window_height = target->szHint.height; |
1187 | int sx, sy; |
1329 | int sx, sy; |
1188 | XGCValues gcv; |
1330 | XGCValues gcv; |
|
|
1331 | GC gc; |
1189 | |
1332 | |
1190 | TIMING_TEST_START (tp); |
1333 | TIMING_TEST_START (tp); |
1191 | target->get_window_origin (sx, sy); |
1334 | target->get_window_origin (sx, sy); |
1192 | |
1335 | |
1193 | /* 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 : */ |
… | |
… | |
1195 | || sx >= root_width || sy >= root_height) |
1338 | || sx >= root_width || sy >= root_height) |
1196 | return 0; |
1339 | return 0; |
1197 | |
1340 | |
1198 | if (root_pixmap != None) |
1341 | if (root_pixmap != None) |
1199 | { |
1342 | { |
1200 | /* 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 : */ |
1201 | int junk; |
1344 | int junk; |
1202 | unsigned int ujunk; |
1345 | unsigned int ujunk; |
1203 | /* root pixmap may be bad - allow a error */ |
1346 | /* root pixmap may be bad - allow a error */ |
1204 | target->allowedxerror = -1; |
1347 | target->allowedxerror = -1; |
1205 | |
1348 | |
… | |
… | |
1207 | root_pixmap = None; |
1350 | root_pixmap = None; |
1208 | |
1351 | |
1209 | target->allowedxerror = 0; |
1352 | target->allowedxerror = 0; |
1210 | } |
1353 | } |
1211 | |
1354 | |
|
|
1355 | if (root_pixmap == None) |
|
|
1356 | return 0; |
|
|
1357 | |
1212 | 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); |
1213 | GC gc = NULL; |
|
|
1214 | |
1359 | |
1215 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
1360 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
1216 | return 0; |
1361 | return 0; |
1217 | |
1362 | |
1218 | if (root_pixmap == None) |
|
|
1219 | { |
|
|
1220 | /* use tricks to obtain the root background image :*/ |
|
|
1221 | /* we want to create Overrideredirect window overlapping out window |
|
|
1222 | with background type of Parent Relative and then grab it */ |
|
|
1223 | XSetWindowAttributes attr; |
|
|
1224 | Window src; |
|
|
1225 | bool success = false; |
|
|
1226 | |
|
|
1227 | attr.background_pixmap = ParentRelative; |
|
|
1228 | attr.backing_store = Always; |
|
|
1229 | attr.event_mask = ExposureMask; |
|
|
1230 | attr.override_redirect = True; |
|
|
1231 | src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0, |
|
|
1232 | CopyFromParent, CopyFromParent, CopyFromParent, |
|
|
1233 | CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask, |
|
|
1234 | &attr); |
|
|
1235 | |
|
|
1236 | if (src != None) |
|
|
1237 | { |
|
|
1238 | XEvent event; |
|
|
1239 | int ev_count = 0; |
|
|
1240 | XGrabServer (dpy); |
|
|
1241 | XMapRaised (dpy, src); |
|
|
1242 | XSync (dpy, False); |
|
|
1243 | |
|
|
1244 | /* XSync should get window where it's properly exposed, |
|
|
1245 | * but to be on the safe side - let's check for the actual event to arrive : */ |
|
|
1246 | while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) |
|
|
1247 | ++ev_count; |
|
|
1248 | |
|
|
1249 | if (ev_count > 0); |
|
|
1250 | { |
|
|
1251 | /* hooray! - we can grab the image! */ |
|
|
1252 | gc = XCreateGC (dpy, root, 0, NULL); |
|
|
1253 | if (gc) |
|
|
1254 | { |
|
|
1255 | XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0); |
|
|
1256 | success = true; |
|
|
1257 | } |
|
|
1258 | } |
|
|
1259 | |
|
|
1260 | XDestroyWindow (dpy, src); |
|
|
1261 | XUngrabServer (dpy); |
|
|
1262 | //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); |
|
|
1263 | } |
|
|
1264 | |
|
|
1265 | if (!success) |
|
|
1266 | { |
|
|
1267 | XFreePixmap (dpy, tiled_root_pmap); |
|
|
1268 | tiled_root_pmap = None; |
|
|
1269 | } |
|
|
1270 | else |
|
|
1271 | result |= transpPmapTiled; |
|
|
1272 | } |
|
|
1273 | else |
|
|
1274 | { |
|
|
1275 | /* straightforward pixmap copy */ |
1363 | /* straightforward pixmap copy */ |
1276 | gcv.tile = root_pixmap; |
1364 | gcv.tile = root_pixmap; |
1277 | gcv.fill_style = FillTiled; |
1365 | gcv.fill_style = FillTiled; |
1278 | |
1366 | |
1279 | while (sx < 0) sx += (int)root_width; |
1367 | while (sx < 0) sx += (int)root_width; |
1280 | while (sy < 0) sy += (int)root_height; |
1368 | while (sy < 0) sy += (int)root_height; |
1281 | |
1369 | |
1282 | gcv.ts_x_origin = -sx; |
1370 | gcv.ts_x_origin = -sx; |
1283 | gcv.ts_y_origin = -sy; |
1371 | gcv.ts_y_origin = -sy; |
1284 | gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
1372 | gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
1285 | |
1373 | |
1286 | if (gc) |
1374 | if (gc) |
1287 | { |
1375 | { |
1288 | 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); |
1289 | result |= transpPmapTiled; |
1377 | result |= transpPmapTiled; |
1290 | } |
1378 | XFreeGC (dpy, gc); |
1291 | } |
1379 | } |
1292 | TIMING_TEST_PRINT_RESULT (tp); |
1380 | TIMING_TEST_PRINT_RESULT (tp); |
1293 | |
1381 | |
1294 | if (tiled_root_pmap != None) |
1382 | if (tiled_root_pmap != None) |
1295 | { |
1383 | { |
1296 | if (!need_client_side_rendering ()) |
1384 | if (!need_client_side_rendering ()) |
1297 | { |
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 | } |
1298 | if ((flags & tintNeeded)) |
1391 | if ((flags & tintNeeded)) |
1299 | { |
1392 | { |
1300 | if (tint_pixmap (tiled_root_pmap)) |
1393 | if (tint_pixmap (tiled_root_pmap, DefaultVisual (dpy, target->display->screen), window_width, window_height)) |
1301 | result |= transpPmapTinted; |
1394 | result |= transpPmapTinted; |
1302 | } |
1395 | } |
1303 | } /* server side rendering completed */ |
1396 | } /* server side rendering completed */ |
1304 | |
1397 | |
1305 | if (pixmap) |
1398 | if (pixmap) |
… | |
… | |
1308 | pixmap = tiled_root_pmap; |
1401 | pixmap = tiled_root_pmap; |
1309 | pmap_width = window_width; |
1402 | pmap_width = window_width; |
1310 | pmap_height = window_height; |
1403 | pmap_height = window_height; |
1311 | pmap_depth = root_depth; |
1404 | pmap_depth = root_depth; |
1312 | } |
1405 | } |
1313 | |
|
|
1314 | if (gc) |
|
|
1315 | XFreeGC (dpy, gc); |
|
|
1316 | |
1406 | |
1317 | TIMING_TEST_PRINT_RESULT (tp); |
1407 | TIMING_TEST_PRINT_RESULT (tp); |
1318 | |
1408 | |
1319 | return result; |
1409 | return result; |
1320 | } |
1410 | } |
… | |
… | |
1546 | int i; |
1636 | int i; |
1547 | |
1637 | |
1548 | Visual *visual = term->visual; |
1638 | Visual *visual = term->visual; |
1549 | |
1639 | |
1550 | if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ; |
1640 | if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ; |
1551 | |
|
|
1552 | if (shade == 0) |
|
|
1553 | shade = 100; |
|
|
1554 | |
1641 | |
1555 | /* for convenience */ |
1642 | /* for convenience */ |
1556 | mask_r = visual->red_mask; |
1643 | mask_r = visual->red_mask; |
1557 | mask_g = visual->green_mask; |
1644 | mask_g = visual->green_mask; |
1558 | mask_b = visual->blue_mask; |
1645 | mask_b = visual->blue_mask; |
… | |
… | |
1614 | default: |
1701 | default: |
1615 | return; /* we do not support this color depth */ |
1702 | return; /* we do not support this color depth */ |
1616 | } |
1703 | } |
1617 | |
1704 | |
1618 | /* prepare limits for color transformation (each channel is handled separately) */ |
1705 | /* prepare limits for color transformation (each channel is handled separately) */ |
1619 | if (shade < 0) { |
1706 | if (shade > 100) { |
1620 | shade = -shade; |
1707 | shade = 200 - shade; |
1621 | if (shade < 0) shade = 0; |
|
|
1622 | if (shade > 100) shade = 100; |
|
|
1623 | |
1708 | |
1624 | lower_lim_r = 65535-rm; |
1709 | lower_lim_r = 65535-rm; |
1625 | lower_lim_g = 65535-gm; |
1710 | lower_lim_g = 65535-gm; |
1626 | lower_lim_b = 65535-bm; |
1711 | lower_lim_b = 65535-bm; |
1627 | |
1712 | |
… | |
… | |
1629 | 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); |
1630 | 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); |
1631 | |
1716 | |
1632 | upper_lim_r = upper_lim_g = upper_lim_b = 65535; |
1717 | upper_lim_r = upper_lim_g = upper_lim_b = 65535; |
1633 | } else { |
1718 | } else { |
1634 | if (shade < 0) shade = 0; |
|
|
1635 | if (shade > 100) shade = 100; |
|
|
1636 | |
1719 | |
1637 | lower_lim_r = lower_lim_g = lower_lim_b = 0; |
1720 | lower_lim_r = lower_lim_g = lower_lim_b = 0; |
1638 | |
1721 | |
1639 | upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100); |
1722 | upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100); |
1640 | upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100); |
1723 | upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100); |