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.79 by sf-exg, Wed Oct 13 23:01:40 2010 UTC vs.
Revision 1.80 by sf-exg, Wed Oct 13 23:04:57 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
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;
985 if (!(geom_flags & WidthValue)) 986 if (!(geom_flags & WidthValue))
986 hr = 1; 987 hr = 1;
987 if (!(geom_flags & HeightValue)) 988 if (!(geom_flags & HeightValue))
988 vr = hr; 989 vr = hr;
989 990
991 min_it (hr, 128);
992 min_it (vr, 128);
993
990 if (h_blurRadius != hr) 994 if (h_blurRadius != hr)
991 { 995 {
992 ++changed; 996 ++changed;
993 h_blurRadius = hr; 997 h_blurRadius = hr;
994 } 998 }
1001 1005
1002 if (v_blurRadius == 0 && h_blurRadius == 0) 1006 if (v_blurRadius == 0 && h_blurRadius == 0)
1003 flags &= ~blurNeeded; 1007 flags &= ~blurNeeded;
1004 else 1008 else
1005 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
1006 1022
1007 return (changed > 0); 1023 return (changed > 0);
1008} 1024}
1009 1025
1010static inline unsigned long 1026static inline unsigned long
1095 flags = (flags & (~tintFlags | tintSet)) | new_flags; 1111 flags = (flags & (~tintFlags | tintSet)) | new_flags;
1096 return true; 1112 return true;
1097 } 1113 }
1098 1114
1099 return false; 1115 return false;
1116}
1117
1118static void
1119get_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
1139bool
1140bgPixmap_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;
1100} 1201}
1101 1202
1102bool 1203bool
1103bgPixmap_t::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) 1204bgPixmap_t::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height)
1104{ 1205{
1324 1425
1325 if (tiled_root_pmap != None) 1426 if (tiled_root_pmap != None)
1326 { 1427 {
1327 if (!need_client_side_rendering ()) 1428 if (!need_client_side_rendering ())
1328 { 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 }
1329 if ((flags & tintNeeded)) 1435 if ((flags & tintNeeded))
1330 { 1436 {
1331 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))
1332 result |= transpPmapTinted; 1438 result |= transpPmapTinted;
1333 } 1439 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines