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.129 by root, Mon Jan 3 03:05:47 2011 UTC vs.
Revision 1.140 by sf-exg, Sun Jan 23 12:28:47 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
1051 1012
1052 return false; 1013 return false;
1053} 1014}
1054 1015
1055bool 1016bool
1056bgPixmap_t::unset_tint ()
1057{
1058 unsigned long new_flags = compute_tint_shade_flags (NULL, shade);
1059
1060 if (new_flags != (flags & tintFlags))
1061 {
1062 flags = (flags & ~tintFlags) | new_flags;
1063 return true;
1064 }
1065
1066 return false;
1067}
1068
1069bool
1070bgPixmap_t::set_shade (const char *shade_str) 1017bgPixmap_t::set_shade (const char *shade_str)
1071{ 1018{
1072 int new_shade = (shade_str) ? atoi (shade_str) : 100; 1019 int new_shade = (shade_str) ? atoi (shade_str) : 100;
1073 1020
1074 clamp_it (new_shade, -100, 200); 1021 clamp_it (new_shade, -100, 200);
1077 1024
1078 if (new_shade != shade) 1025 if (new_shade != shade)
1079 { 1026 {
1080 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); 1027 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade);
1081 shade = new_shade; 1028 shade = new_shade;
1082 flags = (flags & (~tintFlags | tintSet)) | new_flags; 1029 flags = (flags & ~tintFlags) | new_flags;
1083 return true; 1030 return true;
1084 } 1031 }
1085 1032
1086 return false; 1033 return false;
1087} 1034}
1356 } 1303 }
1357 1304
1358 if (root_pixmap == None) 1305 if (root_pixmap == None)
1359 return 0; 1306 return 0;
1360 1307
1308 if (pixmap == None
1309 || pmap_width != window_width
1310 || pmap_height != window_height)
1311 {
1312 if (pixmap)
1313 XFreePixmap (target->dpy, pixmap);
1361 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 }
1362 1318
1363 if (tiled_root_pmap == None) /* something really bad happened - abort */ 1319 if (pixmap == None)
1364 return 0; 1320 return 0;
1365 1321
1366 /* straightforward pixmap copy */ 1322 /* straightforward pixmap copy */
1367 while (sx < 0) sx += (int)root_width; 1323 while (sx < 0) sx += (int)root_width;
1368 while (sy < 0) sy += (int)root_height; 1324 while (sy < 0) sy += (int)root_height;
1373 gcv.ts_y_origin = -sy; 1329 gcv.ts_y_origin = -sy;
1374 gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 1330 gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
1375 1331
1376 if (gc) 1332 if (gc)
1377 { 1333 {
1378 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); 1334 XFillRectangle (dpy, pixmap, gc, 0, 0, window_width, window_height);
1379 result |= transpPmapTiled; 1335 result |= transpPmapTiled;
1380 XFreeGC (dpy, gc); 1336 XFreeGC (dpy, gc);
1381 1337
1382 if (!need_client_side_rendering ()) 1338 if (!(flags & CLIENT_RENDER))
1383 { 1339 {
1384 if ((flags & blurNeeded) 1340 if ((flags & blurNeeded)
1385 && (flags & HAS_RENDER_CONV)) 1341 && (flags & HAS_RENDER_CONV))
1386 { 1342 {
1387 if (blur_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) 1343 if (blur_pixmap (pixmap, target->visual, window_width, window_height))
1388 result |= transpPmapBlurred; 1344 result |= transpPmapBlurred;
1389 } 1345 }
1390 if ((flags & tintNeeded) 1346 if ((flags & tintNeeded)
1391 && (flags & (tintWholesome | HAS_RENDER))) 1347 && (flags & (tintWholesome | HAS_RENDER)))
1392 { 1348 {
1393 if (tint_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) 1349 if (tint_pixmap (pixmap, target->visual, window_width, window_height))
1394 result |= transpPmapTinted; 1350 result |= transpPmapTinted;
1395 } 1351 }
1396 } /* server side rendering completed */ 1352 } /* server side rendering completed */
1397
1398 if (pixmap)
1399 XFreePixmap (dpy, pixmap);
1400
1401 pixmap = tiled_root_pmap;
1402 pmap_width = window_width;
1403 pmap_height = window_height;
1404 pmap_depth = target->depth;
1405 } 1353 }
1406 else
1407 XFreePixmap (dpy, tiled_root_pmap);
1408 1354
1409 if (recoded_root_pmap != root_pixmap) 1355 if (recoded_root_pmap != root_pixmap)
1410 XFreePixmap (dpy, recoded_root_pmap); 1356 XFreePixmap (dpy, recoded_root_pmap);
1411 1357
1412 return result; 1358 return result;
1442 /* we need to re-generate transparency pixmap in that case ! */ 1388 /* we need to re-generate transparency pixmap in that case ! */
1443 background_flags = make_transparency_pixmap (); 1389 background_flags = make_transparency_pixmap ();
1444 if (background_flags == 0) 1390 if (background_flags == 0)
1445 return false; 1391 return false;
1446 else if ((background_flags & transpTransformations) == (flags & transpTransformations)) 1392 else if ((background_flags & transpTransformations) == (flags & transpTransformations))
1447 flags &= ~isInvalid; 1393 flags |= isValid;
1448 } 1394 }
1449# endif 1395# endif
1450 1396
1451# ifdef BG_IMAGE_FROM_FILE 1397# ifdef BG_IMAGE_FROM_FILE
1452 if (have_image 1398 if (have_image
1453 || (background_flags & transpTransformations) != (flags & transpTransformations)) 1399 || (background_flags & transpTransformations) != (flags & transpTransformations))
1454 { 1400 {
1455 if (render_image (background_flags)) 1401 if (render_image (background_flags))
1456 flags &= ~isInvalid; 1402 flags |= isValid;
1457 } 1403 }
1458# endif 1404# endif
1459 1405
1460# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1406# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1461 XImage *result = NULL; 1407 XImage *result = NULL;
1462 1408
1463 if (background_flags && (flags & isInvalid)) 1409 if (background_flags && !(flags & isValid))
1464 { 1410 {
1465 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1411 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1466 } 1412 }
1467 1413
1468 if (result) 1414 if (result)
1481 if (gc) 1427 if (gc)
1482 { 1428 {
1483 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); 1429 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1484 1430
1485 XFreeGC (target->dpy, gc); 1431 XFreeGC (target->dpy, gc);
1486 flags &= ~isInvalid; 1432 flags |= isValid;
1487 } 1433 }
1488 1434
1489 XDestroyImage (result); 1435 XDestroyImage (result);
1490 } 1436 }
1491# endif 1437# endif
1492 1438
1493 if (flags & isInvalid) 1439 if (!(flags & isValid))
1494 { 1440 {
1495 if (pixmap != None) 1441 if (pixmap != None)
1496 { 1442 {
1497 XFreePixmap (target->dpy, pixmap); 1443 XFreePixmap (target->dpy, pixmap);
1498 pixmap = None; 1444 pixmap = None;
1499 } 1445 }
1500 } 1446 }
1501 1447
1502 apply (); 1448 target->scr_recolour (false);
1449 flags |= hasChanged;
1503 1450
1504 valid_since = ev::now (); 1451 valid_since = ev::now ();
1505 1452
1506 return true; 1453 return true;
1507} 1454}
1524 flags |= HAS_RENDER_CONV; 1471 flags |= HAS_RENDER_CONV;
1525 1472
1526 XFree (filters); 1473 XFree (filters);
1527 } 1474 }
1528#endif 1475#endif
1529}
1530
1531void
1532bgPixmap_t::apply ()
1533{
1534 if (target == NULL)
1535 return;
1536
1537 if (pixmap != None)
1538 {
1539 /* set target's background to pixmap */
1540# ifdef ENABLE_TRANSPARENCY
1541 if (flags & isTransparent)
1542 {
1543 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
1544 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1545
1546 if (target->scrollBar.win)
1547 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
1548 }
1549 else
1550# endif
1551 {
1552 /* force old pixmap dereference in case it was transparent before :*/
1553 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1554 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1555 /* do we also need to set scrollbar's background here ? */
1556
1557 if (target->scrollBar.win)
1558 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1559 }
1560 }
1561 else
1562 {
1563 /* set target background to a pixel */
1564 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1565 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
1566 /* do we also need to set scrollbar's background here ? */
1567 if (target->scrollBar.win)
1568 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1569 }
1570
1571 /* don't want Expose on the parent or vt. It is better to use
1572 scr_touch or we get a great deal of flicker otherwise: */
1573 XClearWindow (target->dpy, target->parent[0]);
1574
1575 if (target->scrollBar.state && target->scrollBar.win)
1576 {
1577 target->scrollBar.state = STATE_IDLE;
1578 target->scrollBar.show (0);
1579 }
1580
1581 target->want_refresh = 1;
1582 flags |= hasChanged;
1583} 1476}
1584 1477
1585#endif /* HAVE_BG_PIXMAP */ 1478#endif /* HAVE_BG_PIXMAP */
1586 1479
1587#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1480#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines