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.132 by sf-exg, Mon Jan 10 20:46:20 2011 UTC vs.
Revision 1.139 by sf-exg, Sat Jan 22 15:41:19 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
253 int x = 0, y = 0; 231 int x = 0, y = 0;
254 unsigned int w = 0, h = 0; 232 unsigned int w = 0, h = 0;
255 unsigned int n; 233 unsigned int n;
256 unsigned long new_flags = (flags & (~geometryFlags)); 234 unsigned long new_flags = (flags & (~geometryFlags));
257 const char *ops; 235 const char *ops;
258# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */
259 236
260 if (geom == NULL) 237 if (geom == NULL)
261 return false; 238 return false;
262 239
263 char str[MAXLEN_GEOM]; 240 char str[256];
264 241
265 ops = strchr (geom, ':'); 242 ops = strchr (geom, ':');
266 if (ops == NULL) 243 if (ops == NULL)
267 n = strlen (geom); 244 n = strlen (geom);
268 else 245 else
269 n = ops - geom; 246 n = ops - geom;
270 247
271 if (n >= MAXLEN_GEOM) 248 if (n >= sizeof (str))
272 return false; 249 return false;
273 250
274 memcpy (str, geom, n); 251 memcpy (str, geom, n);
275 str[n] = '\0'; 252 str[n] = '\0';
276 rxvt_strtrim (str); 253 rxvt_strtrim (str);
302 { 279 {
303 char **arr = rxvt_strsplit (':', ops + 1); 280 char **arr = rxvt_strsplit (':', ops + 1);
304 281
305 for (int i = 0; arr[i]; i++) 282 for (int i = 0; arr[i]; i++)
306 { 283 {
307# define CHECK_GEOM_OPS(op_str) (strcasecmp (arr[i], (op_str)) == 0) 284 if (!strcasecmp (arr[i], "tile"))
308 if (CHECK_GEOM_OPS ("tile"))
309 { 285 {
310 w = h = noScale; 286 w = h = noScale;
311 geom_flags |= WidthValue|HeightValue; 287 geom_flags |= WidthValue|HeightValue;
312 } 288 }
313 else if (CHECK_GEOM_OPS ("propscale")) 289 else if (!strcasecmp (arr[i], "propscale"))
314 { 290 {
315 new_flags |= propScale; 291 new_flags |= propScale;
316 } 292 }
317 else if (CHECK_GEOM_OPS ("hscale")) 293 else if (!strcasecmp (arr[i], "hscale"))
318 { 294 {
319 if (w == 0) w = windowScale; 295 if (w == 0) w = windowScale;
320 296
321 h = noScale; 297 h = noScale;
322 geom_flags |= WidthValue|HeightValue; 298 geom_flags |= WidthValue|HeightValue;
323 } 299 }
324 else if (CHECK_GEOM_OPS ("vscale")) 300 else if (!strcasecmp (arr[i], "vscale"))
325 { 301 {
326 if (h == 0) h = windowScale; 302 if (h == 0) h = windowScale;
327 303
328 w = noScale; 304 w = noScale;
329 geom_flags |= WidthValue|HeightValue; 305 geom_flags |= WidthValue|HeightValue;
330 } 306 }
331 else if (CHECK_GEOM_OPS ("scale")) 307 else if (!strcasecmp (arr[i], "scale"))
332 { 308 {
333 if (h == 0) h = windowScale; 309 if (h == 0) h = windowScale;
334 if (w == 0) w = windowScale; 310 if (w == 0) w = windowScale;
335 311
336 geom_flags |= WidthValue|HeightValue; 312 geom_flags |= WidthValue|HeightValue;
337 } 313 }
338 else if (CHECK_GEOM_OPS ("auto")) 314 else if (!strcasecmp (arr[i], "auto"))
339 { 315 {
340 w = h = windowScale; 316 w = h = windowScale;
341 x = y = centerAlign; 317 x = y = centerAlign;
342 geom_flags |= WidthValue|HeightValue|XValue|YValue; 318 geom_flags |= WidthValue|HeightValue|XValue|YValue;
343 } 319 }
344 else if (CHECK_GEOM_OPS ("root")) 320 else if (!strcasecmp (arr[i], "root"))
345 { 321 {
346 new_flags |= rootAlign; 322 new_flags |= rootAlign;
347 w = h = noScale; 323 w = h = noScale;
348 geom_flags |= WidthValue|HeightValue; 324 geom_flags |= WidthValue|HeightValue;
349 } 325 }
350# undef CHECK_GEOM_OPS
351 } /* done parsing ops */ 326 } /* done parsing ops */
352 327
353 rxvt_free_strsplit (arr); 328 rxvt_free_strsplit (arr);
354 } 329 }
355 330
597 GC gc; 572 GC gc;
598 573
599 /* create Pixmap */ 574 /* create Pixmap */
600 if (pixmap == None 575 if (pixmap == None
601 || pmap_width != new_pmap_width 576 || pmap_width != new_pmap_width
602 || pmap_height != new_pmap_height 577 || pmap_height != new_pmap_height)
603 || pmap_depth != target->depth)
604 { 578 {
605 if (pixmap) 579 if (pixmap)
606 XFreePixmap (target->dpy, pixmap); 580 XFreePixmap (target->dpy, pixmap);
607 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);
608 pmap_width = new_pmap_width; 582 pmap_width = new_pmap_width;
609 pmap_height = new_pmap_height; 583 pmap_height = new_pmap_height;
610 pmap_depth = target->depth;
611 } 584 }
612 /* fill with background color (if result's not completely overlapping it) */ 585 /* fill with background color (if result's not completely overlapping it) */
613 gcv.foreground = target->pix_colors[Color_bg]; 586 gcv.foreground = target->pix_colors[Color_bg];
614 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); 587 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
615 588
806 } 779 }
807 } 780 }
808 781
809 if (pixmap == None 782 if (pixmap == None
810 || pmap_width != new_pmap_width 783 || pmap_width != new_pmap_width
811 || pmap_height != new_pmap_height 784 || pmap_height != new_pmap_height)
812 || pmap_depth != target->depth)
813 { 785 {
814 if (pixmap) 786 if (pixmap)
815 XFreePixmap (target->dpy, pixmap); 787 XFreePixmap (target->dpy, pixmap);
816 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);
817 pmap_width = new_pmap_width; 789 pmap_width = new_pmap_width;
818 pmap_height = new_pmap_height; 790 pmap_height = new_pmap_height;
819 pmap_depth = target->depth;
820 } 791 }
821 792
822 gcv.foreground = target->pix_colors[Color_bg]; 793 gcv.foreground = target->pix_colors[Color_bg];
823 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); 794 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
824 795
1013 bool has_shade = shade != 100; 984 bool has_shade = shade != 100;
1014 985
1015 if (tint) 986 if (tint)
1016 { 987 {
1017 tint->get (c); 988 tint->get (c);
1018# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x00ff || (cmp) >= 0xff00)
1019 if (!has_shade 989 if (!has_shade
1020 && IS_COMPONENT_WHOLESOME (c.r) 990 && (c.r <= 0x00ff || c.r >= 0xff00)
1021 && IS_COMPONENT_WHOLESOME (c.g) 991 && (c.g <= 0x00ff || c.g >= 0xff00)
1022 && IS_COMPONENT_WHOLESOME (c.b)) 992 && (c.b <= 0x00ff || c.b >= 0xff00))
1023 flags |= bgPixmap_t::tintWholesome; 993 flags |= bgPixmap_t::tintWholesome;
1024# undef IS_COMPONENT_WHOLESOME
1025 } 994 }
1026 995
1027 if (has_shade || tint) 996 if (has_shade || tint)
1028 flags |= bgPixmap_t::tintNeeded; 997 flags |= bgPixmap_t::tintNeeded;
1029 998
1055 1024
1056 if (new_shade != shade) 1025 if (new_shade != shade)
1057 { 1026 {
1058 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);
1059 shade = new_shade; 1028 shade = new_shade;
1060 flags = (flags & (~tintFlags | tintSet)) | new_flags; 1029 flags = (flags & ~tintFlags) | new_flags;
1061 return true; 1030 return true;
1062 } 1031 }
1063 1032
1064 return false; 1033 return false;
1065} 1034}
1334 } 1303 }
1335 1304
1336 if (root_pixmap == None) 1305 if (root_pixmap == None)
1337 return 0; 1306 return 0;
1338 1307
1308 if (pixmap == None
1309 || pmap_width != window_width
1310 || pmap_height != window_height)
1311 {
1312 if (pixmap)
1313 XFreePixmap (target->dpy, pixmap);
1339 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 }
1340 1318
1341 if (tiled_root_pmap == None) /* something really bad happened - abort */ 1319 if (pixmap == None)
1342 return 0; 1320 return 0;
1343 1321
1344 /* straightforward pixmap copy */ 1322 /* straightforward pixmap copy */
1345 while (sx < 0) sx += (int)root_width; 1323 while (sx < 0) sx += (int)root_width;
1346 while (sy < 0) sy += (int)root_height; 1324 while (sy < 0) sy += (int)root_height;
1351 gcv.ts_y_origin = -sy; 1329 gcv.ts_y_origin = -sy;
1352 gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 1330 gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
1353 1331
1354 if (gc) 1332 if (gc)
1355 { 1333 {
1356 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); 1334 XFillRectangle (dpy, pixmap, gc, 0, 0, window_width, window_height);
1357 result |= transpPmapTiled; 1335 result |= transpPmapTiled;
1358 XFreeGC (dpy, gc); 1336 XFreeGC (dpy, gc);
1359 1337
1360 if (!(flags & CLIENT_RENDER)) 1338 if (!(flags & CLIENT_RENDER))
1361 { 1339 {
1362 if ((flags & blurNeeded) 1340 if ((flags & blurNeeded)
1363 && (flags & HAS_RENDER_CONV)) 1341 && (flags & HAS_RENDER_CONV))
1364 { 1342 {
1365 if (blur_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) 1343 if (blur_pixmap (pixmap, target->visual, window_width, window_height))
1366 result |= transpPmapBlurred; 1344 result |= transpPmapBlurred;
1367 } 1345 }
1368 if ((flags & tintNeeded) 1346 if ((flags & tintNeeded)
1369 && (flags & (tintWholesome | HAS_RENDER))) 1347 && (flags & (tintWholesome | HAS_RENDER)))
1370 { 1348 {
1371 if (tint_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) 1349 if (tint_pixmap (pixmap, target->visual, window_width, window_height))
1372 result |= transpPmapTinted; 1350 result |= transpPmapTinted;
1373 } 1351 }
1374 } /* server side rendering completed */ 1352 } /* server side rendering completed */
1375
1376 if (pixmap)
1377 XFreePixmap (dpy, pixmap);
1378
1379 pixmap = tiled_root_pmap;
1380 pmap_width = window_width;
1381 pmap_height = window_height;
1382 pmap_depth = target->depth;
1383 } 1353 }
1384 else
1385 XFreePixmap (dpy, tiled_root_pmap);
1386 1354
1387 if (recoded_root_pmap != root_pixmap) 1355 if (recoded_root_pmap != root_pixmap)
1388 XFreePixmap (dpy, recoded_root_pmap); 1356 XFreePixmap (dpy, recoded_root_pmap);
1389 1357
1390 return result; 1358 return result;
1475 XFreePixmap (target->dpy, pixmap); 1443 XFreePixmap (target->dpy, pixmap);
1476 pixmap = None; 1444 pixmap = None;
1477 } 1445 }
1478 } 1446 }
1479 1447
1480 apply (); 1448 target->scr_recolour (false);
1449 flags |= hasChanged;
1481 1450
1482 valid_since = ev::now (); 1451 valid_since = ev::now ();
1483 1452
1484 return true; 1453 return true;
1485} 1454}
1502 flags |= HAS_RENDER_CONV; 1471 flags |= HAS_RENDER_CONV;
1503 1472
1504 XFree (filters); 1473 XFree (filters);
1505 } 1474 }
1506#endif 1475#endif
1507}
1508
1509void
1510bgPixmap_t::apply ()
1511{
1512 if (target == NULL)
1513 return;
1514
1515 if (pixmap != None)
1516 {
1517 /* set target's background to pixmap */
1518# ifdef ENABLE_TRANSPARENCY
1519 if (flags & isTransparent)
1520 {
1521 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
1522 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1523
1524 if (target->scrollBar.win)
1525 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
1526 }
1527 else
1528# endif
1529 {
1530 /* force old pixmap dereference in case it was transparent before :*/
1531 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1532 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1533 /* do we also need to set scrollbar's background here ? */
1534
1535 if (target->scrollBar.win)
1536 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1537 }
1538 }
1539 else
1540 {
1541 /* set target background to a pixel */
1542 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1543 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
1544 /* do we also need to set scrollbar's background here ? */
1545 if (target->scrollBar.win)
1546 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1547 }
1548
1549 /* don't want Expose on the parent or vt. It is better to use
1550 scr_touch or we get a great deal of flicker otherwise: */
1551 XClearWindow (target->dpy, target->parent[0]);
1552
1553 if (target->scrollBar.state && target->scrollBar.win)
1554 {
1555 target->scrollBar.state = STATE_IDLE;
1556 target->scrollBar.show (0);
1557 }
1558
1559 target->want_refresh = 1;
1560 flags |= hasChanged;
1561} 1476}
1562 1477
1563#endif /* HAVE_BG_PIXMAP */ 1478#endif /* HAVE_BG_PIXMAP */
1564 1479
1565#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