… | |
… | |
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 | |
… | |
… | |
177 | return true; |
178 | return true; |
178 | # endif |
179 | # endif |
179 | # ifdef ENABLE_TRANSPARENCY |
180 | # ifdef ENABLE_TRANSPARENCY |
180 | if (flags & isTransparent) |
181 | if (flags & isTransparent) |
181 | { |
182 | { |
182 | # ifdef HAVE_AFTERIMAGE // can't blur without libAI anyways |
183 | # ifdef HAVE_AFTERIMAGE |
183 | if ((flags & blurNeeded) && !(flags & blurServerSide)) |
184 | if ((flags & blurNeeded) && !(flags & blurServerSide)) |
184 | return true; |
185 | return true; |
185 | # endif |
186 | # endif |
186 | if ((flags & tintNeeded) && !(flags & tintServerSide)) |
187 | if ((flags & tintNeeded) && !(flags & tintServerSide)) |
187 | return true; |
188 | return true; |
… | |
… | |
744 | return false; |
745 | return false; |
745 | |
746 | |
746 | if (!pixbuf) |
747 | if (!pixbuf) |
747 | return false; |
748 | return false; |
748 | |
749 | |
749 | // TODO: add alpha blending |
750 | #if !XFT |
750 | if (background_flags) |
751 | if (background_flags) |
751 | return false; |
752 | return false; |
|
|
753 | #endif |
752 | |
754 | |
753 | GdkPixbuf *result; |
755 | GdkPixbuf *result; |
754 | |
756 | |
755 | int image_width = gdk_pixbuf_get_width (pixbuf); |
757 | int image_width = gdk_pixbuf_get_width (pixbuf); |
756 | int image_height = gdk_pixbuf_get_height (pixbuf); |
758 | int image_height = gdk_pixbuf_get_height (pixbuf); |
… | |
… | |
788 | |
790 | |
789 | if (result) |
791 | if (result) |
790 | { |
792 | { |
791 | XGCValues gcv; |
793 | XGCValues gcv; |
792 | GC gc; |
794 | GC gc; |
|
|
795 | Pixmap root_pmap; |
793 | |
796 | |
794 | image_width = gdk_pixbuf_get_width (result); |
797 | image_width = gdk_pixbuf_get_width (result); |
795 | image_height = gdk_pixbuf_get_height (result); |
798 | image_height = gdk_pixbuf_get_height (result); |
796 | |
799 | |
|
|
800 | if (background_flags) |
|
|
801 | { |
|
|
802 | root_pmap = pixmap; |
|
|
803 | pixmap = None; |
|
|
804 | } |
|
|
805 | else |
|
|
806 | { |
797 | if (h_scale == 0 || v_scale == 0) |
807 | if (h_scale == 0 || v_scale == 0) |
798 | { |
808 | { |
799 | new_pmap_width = min (image_width, target_width); |
809 | new_pmap_width = min (image_width, target_width); |
800 | new_pmap_height = min (image_height, target_height); |
810 | new_pmap_height = min (image_height, target_height); |
|
|
811 | } |
801 | } |
812 | } |
802 | |
813 | |
803 | if (pixmap) |
814 | if (pixmap) |
804 | { |
815 | { |
805 | if (pmap_width != new_pmap_width |
816 | if (pmap_width != new_pmap_width |
… | |
… | |
860 | dst_x, dst_y, |
871 | dst_x, dst_y, |
861 | dst_width, dst_height, |
872 | dst_width, dst_height, |
862 | XLIB_RGB_DITHER_NONE, |
873 | XLIB_RGB_DITHER_NONE, |
863 | 0, 0); |
874 | 0, 0); |
864 | } |
875 | } |
|
|
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 |
865 | |
914 | |
866 | if (result != pixbuf) |
915 | if (result != pixbuf) |
867 | g_object_unref (result); |
916 | g_object_unref (result); |
868 | |
917 | |
869 | XFreeGC (target->dpy, gc); |
918 | XFreeGC (target->dpy, gc); |
… | |
… | |
937 | if (!(geom_flags & WidthValue)) |
986 | if (!(geom_flags & WidthValue)) |
938 | hr = 1; |
987 | hr = 1; |
939 | if (!(geom_flags & HeightValue)) |
988 | if (!(geom_flags & HeightValue)) |
940 | vr = hr; |
989 | vr = hr; |
941 | |
990 | |
|
|
991 | min_it (hr, 128); |
|
|
992 | min_it (vr, 128); |
|
|
993 | |
942 | if (h_blurRadius != hr) |
994 | if (h_blurRadius != hr) |
943 | { |
995 | { |
944 | ++changed; |
996 | ++changed; |
945 | h_blurRadius = hr; |
997 | h_blurRadius = hr; |
946 | } |
998 | } |
… | |
… | |
953 | |
1005 | |
954 | if (v_blurRadius == 0 && h_blurRadius == 0) |
1006 | if (v_blurRadius == 0 && h_blurRadius == 0) |
955 | flags &= ~blurNeeded; |
1007 | flags &= ~blurNeeded; |
956 | else |
1008 | else |
957 | flags |= blurNeeded; |
1009 | flags |= blurNeeded; |
|
|
1010 | |
|
|
1011 | #if XFT |
|
|
1012 | XFilters *filters = XRenderQueryFilters (target->dpy, target->display->root); |
|
|
1013 | if (filters) |
|
|
1014 | { |
|
|
1015 | for (int i = 0; i < filters->nfilter; i++) |
|
|
1016 | if (!strcmp (filters->filter[i], FilterConvolution)) |
|
|
1017 | flags |= bgPixmap_t::blurServerSide; |
|
|
1018 | |
|
|
1019 | XFree (filters); |
|
|
1020 | } |
|
|
1021 | #endif |
958 | |
1022 | |
959 | return (changed > 0); |
1023 | return (changed > 0); |
960 | } |
1024 | } |
961 | |
1025 | |
962 | static inline unsigned long |
1026 | static inline unsigned long |
… | |
… | |
1047 | flags = (flags & (~tintFlags | tintSet)) | new_flags; |
1111 | flags = (flags & (~tintFlags | tintSet)) | new_flags; |
1048 | return true; |
1112 | return true; |
1049 | } |
1113 | } |
1050 | |
1114 | |
1051 | return false; |
1115 | return false; |
|
|
1116 | } |
|
|
1117 | |
|
|
1118 | static void |
|
|
1119 | get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) |
|
|
1120 | { |
|
|
1121 | double sigma = radius / 2.0; |
|
|
1122 | double scale = sqrt (2.0 * M_PI) * sigma; |
|
|
1123 | double sum = 0.0; |
|
|
1124 | |
|
|
1125 | for (int i = 0; i < width; i++) |
|
|
1126 | { |
|
|
1127 | double x = i - width / 2; |
|
|
1128 | kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; |
|
|
1129 | sum += kernel[i]; |
|
|
1130 | } |
|
|
1131 | |
|
|
1132 | params[0] = XDoubleToFixed (width); |
|
|
1133 | params[1] = XDoubleToFixed (1); |
|
|
1134 | |
|
|
1135 | for (int i = 0; i < width; i++) |
|
|
1136 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
|
|
1137 | } |
|
|
1138 | |
|
|
1139 | bool |
|
|
1140 | bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
|
|
1141 | { |
|
|
1142 | bool ret = false; |
|
|
1143 | #if XFT |
|
|
1144 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
|
|
1145 | double *kernel = (double *)malloc (size * sizeof (double)); |
|
|
1146 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
|
|
1147 | |
|
|
1148 | Display *dpy = target->dpy; |
|
|
1149 | XRenderPictureAttributes pa; |
|
|
1150 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, target->visual); |
|
|
1151 | |
|
|
1152 | Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
|
|
1153 | Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
|
|
1154 | |
|
|
1155 | if (kernel && params && src && dst) |
|
|
1156 | { |
|
|
1157 | if (h_blurRadius) |
|
|
1158 | { |
|
|
1159 | size = h_blurRadius * 2 + 1; |
|
|
1160 | get_gaussian_kernel (h_blurRadius, size, kernel, params); |
|
|
1161 | |
|
|
1162 | XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); |
|
|
1163 | XRenderComposite (dpy, |
|
|
1164 | PictOpSrc, |
|
|
1165 | src, |
|
|
1166 | None, |
|
|
1167 | dst, |
|
|
1168 | 0, 0, |
|
|
1169 | 0, 0, |
|
|
1170 | 0, 0, |
|
|
1171 | width, height); |
|
|
1172 | } |
|
|
1173 | |
|
|
1174 | if (v_blurRadius) |
|
|
1175 | { |
|
|
1176 | size = v_blurRadius * 2 + 1; |
|
|
1177 | get_gaussian_kernel (v_blurRadius, size, kernel, params); |
|
|
1178 | swap (params[0], params[1]); |
|
|
1179 | |
|
|
1180 | XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); |
|
|
1181 | XRenderComposite (dpy, |
|
|
1182 | PictOpSrc, |
|
|
1183 | src, |
|
|
1184 | None, |
|
|
1185 | dst, |
|
|
1186 | 0, 0, |
|
|
1187 | 0, 0, |
|
|
1188 | 0, 0, |
|
|
1189 | width, height); |
|
|
1190 | } |
|
|
1191 | |
|
|
1192 | ret = true; |
|
|
1193 | } |
|
|
1194 | |
|
|
1195 | free (kernel); |
|
|
1196 | free (params); |
|
|
1197 | XRenderFreePicture (dpy, src); |
|
|
1198 | XRenderFreePicture (dpy, dst); |
|
|
1199 | #endif |
|
|
1200 | return ret; |
1052 | } |
1201 | } |
1053 | |
1202 | |
1054 | bool |
1203 | bool |
1055 | bgPixmap_t::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
1204 | bgPixmap_t::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
1056 | { |
1205 | { |
… | |
… | |
1178 | || sx >= root_width || sy >= root_height) |
1327 | || sx >= root_width || sy >= root_height) |
1179 | return 0; |
1328 | return 0; |
1180 | |
1329 | |
1181 | if (root_pixmap != None) |
1330 | if (root_pixmap != None) |
1182 | { |
1331 | { |
1183 | /* we want to validate the pixmap and get it's size at the same time : */ |
1332 | /* we want to validate the pixmap and get its size at the same time : */ |
1184 | int junk; |
1333 | int junk; |
1185 | unsigned int ujunk; |
1334 | unsigned int ujunk; |
1186 | /* root pixmap may be bad - allow a error */ |
1335 | /* root pixmap may be bad - allow a error */ |
1187 | target->allowedxerror = -1; |
1336 | target->allowedxerror = -1; |
1188 | |
1337 | |
… | |
… | |
1276 | |
1425 | |
1277 | if (tiled_root_pmap != None) |
1426 | if (tiled_root_pmap != None) |
1278 | { |
1427 | { |
1279 | if (!need_client_side_rendering ()) |
1428 | if (!need_client_side_rendering ()) |
1280 | { |
1429 | { |
|
|
1430 | if ((flags & blurNeeded)) |
|
|
1431 | { |
|
|
1432 | if (blur_pixmap (tiled_root_pmap, DefaultVisual (dpy, target->display->screen), window_width, window_height)) |
|
|
1433 | result |= transpPmapBlurred; |
|
|
1434 | } |
1281 | if ((flags & tintNeeded)) |
1435 | if ((flags & tintNeeded)) |
1282 | { |
1436 | { |
1283 | if (tint_pixmap (tiled_root_pmap, DefaultVisual (dpy, target->display->screen), window_width, window_height)) |
1437 | if (tint_pixmap (tiled_root_pmap, DefaultVisual (dpy, target->display->screen), window_width, window_height)) |
1284 | result |= transpPmapTinted; |
1438 | result |= transpPmapTinted; |
1285 | } |
1439 | } |