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.130 by sf-exg, Sun Jan 9 23:48:37 2011 UTC vs.
Revision 1.137 by sf-exg, Sat Jan 15 17:41:43 2011 UTC

30# include <X11/extensions/Xrender.h> 30# include <X11/extensions/Xrender.h>
31#endif 31#endif
32 32
33#ifndef FilterConvolution 33#ifndef FilterConvolution
34#define FilterConvolution "convolution" 34#define FilterConvolution "convolution"
35#endif
36
37#define DO_TIMING_TEST 0
38
39#if DO_TIMING_TEST
40# include <sys/time.h>
41#define TIMING_TEST_START(id) \
42 struct timeval timing_test_##id##_stv; \
43 gettimeofday (&timing_test_##id##_stv, NULL);
44
45#define TIMING_TEST_PRINT_RESULT(id) \
46 do { \
47 struct timeval tv; \
48 gettimeofday (&tv, NULL); \
49 tv.tv_sec -= (timing_test_##id##_stv).tv_sec; \
50 fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__, \
51 tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec); \
52 } while (0)
53
54#else
55#define TIMING_TEST_START(id) do {} while (0)
56#define TIMING_TEST_PRINT_RESULT(id) do {} while (0)
57#endif 35#endif
58 36
59/* 37/*
60 * Pixmap geometry string interpretation : 38 * Pixmap geometry string interpretation :
61 * Each geometry string contains zero or one scale/position 39 * Each geometry string contains zero or one scale/position
101#ifdef ENABLE_TRANSPARENCY 79#ifdef ENABLE_TRANSPARENCY
102 shade = 100; 80 shade = 100;
103#endif 81#endif
104 flags = 0; 82 flags = 0;
105 pixmap = None; 83 pixmap = None;
106 valid_since = invalid_since = 0; 84 valid_since = 0;
107 target = 0; 85 target = 0;
108 target_x = target_y = 0; 86 target_x = target_y = 0;
109} 87}
110 88
111void 89void
172 if (flags & rootAlign) 150 if (flags & rootAlign)
173 return true; 151 return true;
174 } 152 }
175# endif 153# endif
176 154
177 return false;
178}
179
180bool bgPixmap_t::need_client_side_rendering ()
181{
182# ifdef HAVE_AFTERIMAGE
183 if (original_asim)
184 return true;
185# endif
186 return false; 155 return false;
187} 156}
188 157
189# ifdef BG_IMAGE_FROM_FILE 158# ifdef BG_IMAGE_FROM_FILE
190static inline bool 159static inline bool
262 int x = 0, y = 0; 231 int x = 0, y = 0;
263 unsigned int w = 0, h = 0; 232 unsigned int w = 0, h = 0;
264 unsigned int n; 233 unsigned int n;
265 unsigned long new_flags = (flags & (~geometryFlags)); 234 unsigned long new_flags = (flags & (~geometryFlags));
266 const char *ops; 235 const char *ops;
267# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */
268 236
269 if (geom == NULL) 237 if (geom == NULL)
270 return false; 238 return false;
271 239
272 char str[MAXLEN_GEOM]; 240 char str[256];
273 241
274 ops = strchr (geom, ':'); 242 ops = strchr (geom, ':');
275 if (ops == NULL) 243 if (ops == NULL)
276 n = strlen (geom); 244 n = strlen (geom);
277 else 245 else
278 n = ops - geom; 246 n = ops - geom;
279 247
280 if (n >= MAXLEN_GEOM) 248 if (n >= sizeof (str))
281 return false; 249 return false;
282 250
283 memcpy (str, geom, n); 251 memcpy (str, geom, n);
284 str[n] = '\0'; 252 str[n] = '\0';
285 rxvt_strtrim (str); 253 rxvt_strtrim (str);
307 geom_flags |= WidthValue|HeightValue|XValue|YValue; 275 geom_flags |= WidthValue|HeightValue|XValue|YValue;
308 } 276 }
309 277
310 if (ops) 278 if (ops)
311 { 279 {
312 while (*ops) 280 char **arr = rxvt_strsplit (':', ops + 1);
313 {
314 while (*ops == ':' || isspace(*ops)) ++ops;
315 281
316# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof (op_str) - 1) == 0) 282 for (int i = 0; arr[i]; i++)
317 if (CHECK_GEOM_OPS ("tile")) 283 {
284 if (!strcasecmp (arr[i], "tile"))
318 { 285 {
319 w = h = noScale; 286 w = h = noScale;
320 geom_flags |= WidthValue|HeightValue; 287 geom_flags |= WidthValue|HeightValue;
321 } 288 }
322 else if (CHECK_GEOM_OPS ("propscale")) 289 else if (!strcasecmp (arr[i], "propscale"))
323 { 290 {
324 new_flags |= propScale; 291 new_flags |= propScale;
325 } 292 }
326 else if (CHECK_GEOM_OPS ("hscale")) 293 else if (!strcasecmp (arr[i], "hscale"))
327 { 294 {
328 if (w == 0) w = windowScale; 295 if (w == 0) w = windowScale;
329 296
330 h = noScale; 297 h = noScale;
331 geom_flags |= WidthValue|HeightValue; 298 geom_flags |= WidthValue|HeightValue;
332 } 299 }
333 else if (CHECK_GEOM_OPS ("vscale")) 300 else if (!strcasecmp (arr[i], "vscale"))
334 { 301 {
335 if (h == 0) h = windowScale; 302 if (h == 0) h = windowScale;
336 303
337 w = noScale; 304 w = noScale;
338 geom_flags |= WidthValue|HeightValue; 305 geom_flags |= WidthValue|HeightValue;
339 } 306 }
340 else if (CHECK_GEOM_OPS ("scale")) 307 else if (!strcasecmp (arr[i], "scale"))
341 { 308 {
342 if (h == 0) h = windowScale; 309 if (h == 0) h = windowScale;
343 if (w == 0) w = windowScale; 310 if (w == 0) w = windowScale;
344 311
345 geom_flags |= WidthValue|HeightValue; 312 geom_flags |= WidthValue|HeightValue;
346 } 313 }
347 else if (CHECK_GEOM_OPS ("auto")) 314 else if (!strcasecmp (arr[i], "auto"))
348 { 315 {
349 w = h = windowScale; 316 w = h = windowScale;
350 x = y = centerAlign; 317 x = y = centerAlign;
351 geom_flags |= WidthValue|HeightValue|XValue|YValue; 318 geom_flags |= WidthValue|HeightValue|XValue|YValue;
352 } 319 }
353 else if (CHECK_GEOM_OPS ("root")) 320 else if (!strcasecmp (arr[i], "root"))
354 { 321 {
355 new_flags |= rootAlign; 322 new_flags |= rootAlign;
356 w = h = noScale; 323 w = h = noScale;
357 geom_flags |= WidthValue|HeightValue; 324 geom_flags |= WidthValue|HeightValue;
358 } 325 }
359# undef CHECK_GEOM_OPS
360
361 while (*ops != ':' && *ops != '\0') ++ops;
362 } /* done parsing ops */ 326 } /* done parsing ops */
327
328 rxvt_free_strsplit (arr);
363 } 329 }
364 330
365 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true; 331 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true;
366 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true; 332 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true;
367 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true; 333 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true;
606 GC gc; 572 GC gc;
607 573
608 /* create Pixmap */ 574 /* create Pixmap */
609 if (pixmap == None 575 if (pixmap == None
610 || pmap_width != new_pmap_width 576 || pmap_width != new_pmap_width
611 || pmap_height != new_pmap_height 577 || pmap_height != new_pmap_height)
612 || pmap_depth != target->depth)
613 { 578 {
614 if (pixmap) 579 if (pixmap)
615 XFreePixmap (target->dpy, pixmap); 580 XFreePixmap (target->dpy, pixmap);
616 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 581 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
617 pmap_width = new_pmap_width; 582 pmap_width = new_pmap_width;
618 pmap_height = new_pmap_height; 583 pmap_height = new_pmap_height;
619 pmap_depth = target->depth;
620 } 584 }
621 /* fill with background color (if result's not completely overlapping it) */ 585 /* fill with background color (if result's not completely overlapping it) */
622 gcv.foreground = target->pix_colors[Color_bg]; 586 gcv.foreground = target->pix_colors[Color_bg];
623 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); 587 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
624 588
815 } 779 }
816 } 780 }
817 781
818 if (pixmap == None 782 if (pixmap == None
819 || pmap_width != new_pmap_width 783 || pmap_width != new_pmap_width
820 || pmap_height != new_pmap_height 784 || pmap_height != new_pmap_height)
821 || pmap_depth != target->depth)
822 { 785 {
823 if (pixmap) 786 if (pixmap)
824 XFreePixmap (target->dpy, pixmap); 787 XFreePixmap (target->dpy, pixmap);
825 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 788 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
826 pmap_width = new_pmap_width; 789 pmap_width = new_pmap_width;
827 pmap_height = new_pmap_height; 790 pmap_height = new_pmap_height;
828 pmap_depth = target->depth;
829 } 791 }
830 792
831 gcv.foreground = target->pix_colors[Color_bg]; 793 gcv.foreground = target->pix_colors[Color_bg];
832 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); 794 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
833 795
940 if (image) 902 if (image)
941 { 903 {
942 if (original_asim) 904 if (original_asim)
943 safe_asimage_destroy (original_asim); 905 safe_asimage_destroy (original_asim);
944 original_asim = image; 906 original_asim = image;
907 flags |= CLIENT_RENDER;
945 have_image = true; 908 have_image = true;
946 return true; 909 return true;
947 } 910 }
948# endif 911# endif
949 912
1021 bool has_shade = shade != 100; 984 bool has_shade = shade != 100;
1022 985
1023 if (tint) 986 if (tint)
1024 { 987 {
1025 tint->get (c); 988 tint->get (c);
1026# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x00ff || (cmp) >= 0xff00)
1027 if (!has_shade 989 if (!has_shade
1028 && IS_COMPONENT_WHOLESOME (c.r) 990 && (c.r <= 0x00ff || c.r >= 0xff00)
1029 && IS_COMPONENT_WHOLESOME (c.g) 991 && (c.g <= 0x00ff || c.g >= 0xff00)
1030 && IS_COMPONENT_WHOLESOME (c.b)) 992 && (c.b <= 0x00ff || c.b >= 0xff00))
1031 flags |= bgPixmap_t::tintWholesome; 993 flags |= bgPixmap_t::tintWholesome;
1032# undef IS_COMPONENT_WHOLESOME
1033 } 994 }
1034 995
1035 if (has_shade || tint) 996 if (has_shade || tint)
1036 flags |= bgPixmap_t::tintNeeded; 997 flags |= bgPixmap_t::tintNeeded;
1037 998
1342 } 1303 }
1343 1304
1344 if (root_pixmap == None) 1305 if (root_pixmap == None)
1345 return 0; 1306 return 0;
1346 1307
1308 if (pixmap == None
1309 || pmap_width != window_width
1310 || pmap_height != window_height)
1311 {
1312 if (pixmap)
1313 XFreePixmap (target->dpy, pixmap);
1347 Pixmap tiled_root_pmap = XCreatePixmap (dpy, target->vt, window_width, window_height, target->depth); 1314 pixmap = XCreatePixmap (target->dpy, target->vt, window_width, window_height, target->depth);
1315 pmap_width = window_width;
1316 pmap_height = window_height;
1317 }
1348 1318
1349 if (tiled_root_pmap == None) /* something really bad happened - abort */ 1319 if (pixmap == None)
1350 return 0; 1320 return 0;
1351 1321
1352 /* straightforward pixmap copy */ 1322 /* straightforward pixmap copy */
1353 while (sx < 0) sx += (int)root_width; 1323 while (sx < 0) sx += (int)root_width;
1354 while (sy < 0) sy += (int)root_height; 1324 while (sy < 0) sy += (int)root_height;
1359 gcv.ts_y_origin = -sy; 1329 gcv.ts_y_origin = -sy;
1360 gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 1330 gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
1361 1331
1362 if (gc) 1332 if (gc)
1363 { 1333 {
1364 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); 1334 XFillRectangle (dpy, pixmap, gc, 0, 0, window_width, window_height);
1365 result |= transpPmapTiled; 1335 result |= transpPmapTiled;
1366 XFreeGC (dpy, gc); 1336 XFreeGC (dpy, gc);
1367 1337
1368 if (!need_client_side_rendering ()) 1338 if (!(flags & CLIENT_RENDER))
1369 { 1339 {
1370 if ((flags & blurNeeded) 1340 if ((flags & blurNeeded)
1371 && (flags & HAS_RENDER_CONV)) 1341 && (flags & HAS_RENDER_CONV))
1372 { 1342 {
1373 if (blur_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) 1343 if (blur_pixmap (pixmap, target->visual, window_width, window_height))
1374 result |= transpPmapBlurred; 1344 result |= transpPmapBlurred;
1375 } 1345 }
1376 if ((flags & tintNeeded) 1346 if ((flags & tintNeeded)
1377 && (flags & (tintWholesome | HAS_RENDER))) 1347 && (flags & (tintWholesome | HAS_RENDER)))
1378 { 1348 {
1379 if (tint_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) 1349 if (tint_pixmap (pixmap, target->visual, window_width, window_height))
1380 result |= transpPmapTinted; 1350 result |= transpPmapTinted;
1381 } 1351 }
1382 } /* server side rendering completed */ 1352 } /* server side rendering completed */
1383
1384 if (pixmap)
1385 XFreePixmap (dpy, pixmap);
1386
1387 pixmap = tiled_root_pmap;
1388 pmap_width = window_width;
1389 pmap_height = window_height;
1390 pmap_depth = target->depth;
1391 } 1353 }
1392 else
1393 XFreePixmap (dpy, tiled_root_pmap);
1394 1354
1395 if (recoded_root_pmap != root_pixmap) 1355 if (recoded_root_pmap != root_pixmap)
1396 XFreePixmap (dpy, recoded_root_pmap); 1356 XFreePixmap (dpy, recoded_root_pmap);
1397 1357
1398 return result; 1358 return result;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines