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.82 by sf-exg, Thu Oct 14 16:01:28 2010 UTC vs.
Revision 1.123 by sf-exg, Tue Nov 23 08:37:37 2010 UTC

3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 2005-2008 Marc Lehmann <pcg@goof.com> 6 * Copyright (c) 2005-2008 Marc Lehmann <pcg@goof.com>
7 * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> 7 * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net>
8 * Copyright (c) 2010 Emanuele Giaquinta <e.giaquinta@glauco.it>
8 * 9 *
9 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or 12 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version. 13 * (at your option) any later version.
23 24
24#include <cmath> 25#include <cmath>
25#include "../config.h" /* NECESSARY */ 26#include "../config.h" /* NECESSARY */
26#include "rxvt.h" /* NECESSARY */ 27#include "rxvt.h" /* NECESSARY */
27 28
29#if XRENDER
30# include <X11/extensions/Xrender.h>
31#endif
32
33#ifndef FilterConvolution
34#define FilterConvolution "convolution"
35#endif
36
28#define DO_TIMING_TEST 0 37#define DO_TIMING_TEST 0
29 38
30#if DO_TIMING_TEST 39#if DO_TIMING_TEST
31# include <sys/time.h> 40# include <sys/time.h>
32#define TIMING_TEST_START(id) \ 41#define TIMING_TEST_START(id) \
57 * 66 *
58 * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. 67 * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%.
59 * W and H are percentages of the terminal window size. 68 * W and H are percentages of the terminal window size.
60 * X and Y are also percentages; e.g., +50+50 centers 69 * X and Y are also percentages; e.g., +50+50 centers
61 * the image in the window. 70 * the image in the window.
62 * WxH+X Assumes Y == X
63 * WxH Assumes Y == X == 50 (centers the image)
64 * W+X+Y Assumes H == W
65 * W+X Assumes H == W and Y == X
66 * W Assumes H == W and Y == X == 50
67 *
68 * Adjusting position only :
69 * =+X+Y Set position to X% by Y% (absolute).
70 * =+X Set position to X% by X%.
71 * +X+Y Adjust position horizontally X% and vertically Y%
72 * from current position (relative).
73 * +X Adjust position horizontally X% and vertically X%
74 * from current position.
75 *
76 * Adjusting scale only :
77 * Wx0 Multiply horizontal scaling factor by W%
78 * 0xH Multiply vertical scaling factor by H%
79 * 0x0 No scaling (show image at normal size).
80 * 71 *
81 * Pixmap Operations : (should be prepended by a colon) 72 * Pixmap Operations : (should be prepended by a colon)
82 * tile Tile image. Scaling/position modifiers above will affect 73 * tile Tile image. Scaling/position modifiers above will affect
83 * the tile size and origin. 74 * the tile size and origin.
84 * propscale When scaling, scale proportionally. That is, maintain the 75 * propscale When scaling, scale proportionally. That is, maintain the
112#endif 103#endif
113 flags = 0; 104 flags = 0;
114 pixmap = None; 105 pixmap = None;
115 valid_since = invalid_since = 0; 106 valid_since = invalid_since = 0;
116 target = 0; 107 target = 0;
108 target_x = target_y = 0;
117} 109}
118 110
119void 111void
120bgPixmap_t::destroy () 112bgPixmap_t::destroy ()
121{ 113{
132 if (pixmap && target) 124 if (pixmap && target)
133 XFreePixmap (target->dpy, pixmap); 125 XFreePixmap (target->dpy, pixmap);
134} 126}
135 127
136bool 128bool
129bgPixmap_t::set_position (int x, int y)
130{
131
132 if (target_x != x
133 || target_y != y)
134 {
135 target_x = x;
136 target_y = y;
137 return true;
138 }
139 return false;
140}
141
142bool
137bgPixmap_t::window_size_sensitive () 143bgPixmap_t::window_size_sensitive ()
138{ 144{
139# ifdef ENABLE_TRANSPARENCY 145# ifdef ENABLE_TRANSPARENCY
140 if (flags & isTransparent) 146 if (flags & isTransparent)
141 return true; 147 return true;
167 return true; 173 return true;
168 } 174 }
169# endif 175# endif
170 176
171 return false; 177 return false;
172}; 178}
173 179
174bool bgPixmap_t::need_client_side_rendering () 180bool bgPixmap_t::need_client_side_rendering ()
175{ 181{
176# ifdef HAVE_AFTERIMAGE 182# ifdef HAVE_AFTERIMAGE
177 if (original_asim) 183 if (original_asim)
178 return true; 184 return true;
179# endif
180# ifdef ENABLE_TRANSPARENCY
181 if (flags & isTransparent)
182 {
183# ifdef HAVE_AFTERIMAGE
184 if ((flags & blurNeeded) && !(flags & blurServerSide))
185 return true;
186# endif
187 if ((flags & tintNeeded) && !(flags & tintServerSide))
188 return true;
189 }
190# endif 185# endif
191 return false; 186 return false;
192} 187}
193 188
194# ifdef BG_IMAGE_FROM_FILE 189# ifdef BG_IMAGE_FROM_FILE
232 int diff = window_size - image_size; 227 int diff = window_size - image_size;
233 int smaller = min (image_size, window_size); 228 int smaller = min (image_size, window_size);
234 229
235 if (align >= 0 && align <= 100) 230 if (align >= 0 && align <= 100)
236 return diff * align / 100; 231 return diff * align / 100;
237 else if (align > 100 && align <= 200 ) 232 else if (align > 100 && align <= 200)
238 return ((align - 100) * smaller / 100) + window_size - smaller; 233 return ((align - 100) * smaller / 100) + window_size - smaller;
239 else if (align >= -100 && align < 0) 234 else if (align >= -100 && align < 0)
240 return ((align + 100) * smaller / 100) - image_size; 235 return ((align + 100) * smaller / 100) - image_size;
241 return 0; 236 return 0;
242} 237}
258 dst_size = target_size - dst_pos; 253 dst_size = target_size - dst_pos;
259 return src_pos; 254 return src_pos;
260} 255}
261 256
262bool 257bool
263bgPixmap_t::set_geometry (const char *geom) 258bgPixmap_t::set_geometry (const char *geom, bool update)
264{ 259{
260 bool changed = false;
265 int geom_flags = 0, changed = 0; 261 int geom_flags = 0;
266 int x = 0, y = 0; 262 int x = 0, y = 0;
267 unsigned int w = 0, h = 0; 263 unsigned int w = 0, h = 0;
268 unsigned int n; 264 unsigned int n;
269 unsigned long new_flags = (flags & (~geometryFlags)); 265 unsigned long new_flags = (flags & (~geometryFlags));
270 const char *p; 266 const char *ops;
271# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */ 267# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */
272 268
273 if (geom == NULL) 269 if (geom == NULL)
274 return false; 270 return false;
275 271
276 char str[MAXLEN_GEOM]; 272 char str[MAXLEN_GEOM];
277 273
278 while (isspace(*geom)) ++geom;
279 if ((p = strchr (geom, ';')) == NULL)
280 p = strchr (geom, '\0'); 274 ops = strchr (geom, ':');
281 275 if (ops == NULL)
276 n = strlen (geom);
277 else
282 n = (p - geom); 278 n = ops - geom;
279
283 if (n < MAXLEN_GEOM) 280 if (n >= MAXLEN_GEOM)
284 { 281 return false;
285 char *ops;
286 new_flags |= geometrySet;
287 282
288 memcpy (str, geom, n); 283 memcpy (str, geom, n);
289 str[n] = '\0'; 284 str[n] = '\0';
290 if (str[0] == ':') 285 rxvt_strtrim (str);
291 ops = &str[0];
292 else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0]))
293 ops = &str[0];
294 else
295 {
296 char *tmp;
297 ops = strchr (str, ':');
298 if (ops != NULL)
299 {
300 for (tmp = ops-1; tmp >= str && isspace(*tmp); --tmp);
301 *(++tmp) = '\0';
302 if (ops == tmp) ++ops;
303 }
304 }
305 286
306 if (ops > str || ops == NULL) 287 if (str[0])
307 { 288 {
308 /* we have geometry string - let's handle it prior to applying ops */ 289 /* we have geometry string - let's handle it prior to applying ops */
309 geom_flags = XParseGeometry (str, &x, &y, &w, &h); 290 geom_flags = XParseGeometry (str, &x, &y, &w, &h);
310
311 if ((geom_flags & XValue) && !(geom_flags & YValue))
312 {
313 y = x;
314 geom_flags |= YValue;
315 }
316
317 if (flags & geometrySet)
318 {
319 /* new geometry is an adjustment to the old one ! */
320 if ((geom_flags & WidthValue) && (geom_flags & HeightValue))
321 {
322 if (w == 0 && h != 0)
323 {
324 w = h_scale;
325 h = (v_scale * h) / 100;
326 }
327 else if (h == 0 && w != 0)
328 {
329 w = (h_scale * w) / 100;
330 h = v_scale;
331 }
332 }
333 if (geom_flags & XValue)
334 {
335 if (str[0] != '=')
336 {
337 y += v_align;
338 x += h_align;
339 }
340 }
341 }
342 else /* setting up geometry from scratch */
343 {
344 if (!(geom_flags & XValue))
345 {
346 /* use default geometry - centered */
347 x = y = defaultAlign;
348 }
349 else if (!(geom_flags & YValue))
350 y = x;
351
352 if ((geom_flags & (WidthValue|HeightValue)) == 0)
353 {
354 /* use default geometry - scaled */
355 w = h = defaultScale;
356 }
357 else if (geom_flags & WidthValue)
358 {
359 if (!(geom_flags & HeightValue))
360 h = w;
361 }
362 else
363 w = h;
364 }
365 } /* done parsing geometry string */ 291 } /* done parsing geometry string */
366 else if (!(flags & geometrySet)) 292
367 { 293 if (!update)
368 /* default geometry - scaled and centered */ 294 {
295 if (!(geom_flags & XValue))
369 x = y = defaultAlign; 296 x = y = defaultAlign;
297 else if (!(geom_flags & YValue))
298 y = x;
299
300 if (!(geom_flags & (WidthValue|HeightValue)))
370 w = h = defaultScale; 301 w = h = defaultScale;
371 } 302 else if (!(geom_flags & HeightValue))
303 h = w;
304 else if (!(geom_flags & WidthValue))
305 w = h;
372 306
373 if (!(flags & geometrySet))
374 geom_flags |= WidthValue|HeightValue|XValue|YValue; 307 geom_flags |= WidthValue|HeightValue|XValue|YValue;
308 }
375 309
376 if (ops) 310 if (ops)
377 { 311 {
378 while (*ops) 312 while (*ops)
379 { 313 {
380 while (*ops == ':' || isspace(*ops)) ++ops; 314 while (*ops == ':' || isspace(*ops)) ++ops;
381 315
382# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof (op_str) - 1) == 0) 316# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof (op_str) - 1) == 0)
383 if (CHECK_GEOM_OPS ("tile")) 317 if (CHECK_GEOM_OPS ("tile"))
384 { 318 {
385 w = h = noScale; 319 w = h = noScale;
386 geom_flags |= WidthValue|HeightValue; 320 geom_flags |= WidthValue|HeightValue;
387 } 321 }
388 else if (CHECK_GEOM_OPS ("propscale")) 322 else if (CHECK_GEOM_OPS ("propscale"))
389 { 323 {
390 new_flags |= propScale; 324 new_flags |= propScale;
391 } 325 }
392 else if (CHECK_GEOM_OPS ("hscale")) 326 else if (CHECK_GEOM_OPS ("hscale"))
393 { 327 {
394 if (w == 0) w = windowScale; 328 if (w == 0) w = windowScale;
395 329
396 h = noScale; 330 h = noScale;
397 geom_flags |= WidthValue|HeightValue; 331 geom_flags |= WidthValue|HeightValue;
398 } 332 }
399 else if (CHECK_GEOM_OPS ("vscale")) 333 else if (CHECK_GEOM_OPS ("vscale"))
400 { 334 {
401 if (h == 0) h = windowScale; 335 if (h == 0) h = windowScale;
402 336
403 w = noScale; 337 w = noScale;
404 geom_flags |= WidthValue|HeightValue; 338 geom_flags |= WidthValue|HeightValue;
405 } 339 }
406 else if (CHECK_GEOM_OPS ("scale")) 340 else if (CHECK_GEOM_OPS ("scale"))
407 { 341 {
408 if (h == 0) h = windowScale; 342 if (h == 0) h = windowScale;
409 if (w == 0) w = windowScale; 343 if (w == 0) w = windowScale;
410 344
411 geom_flags |= WidthValue|HeightValue; 345 geom_flags |= WidthValue|HeightValue;
412 } 346 }
413 else if (CHECK_GEOM_OPS ("auto")) 347 else if (CHECK_GEOM_OPS ("auto"))
414 { 348 {
415 w = h = windowScale; 349 w = h = windowScale;
416 x = y = centerAlign; 350 x = y = centerAlign;
417 geom_flags |= WidthValue|HeightValue|XValue|YValue; 351 geom_flags |= WidthValue|HeightValue|XValue|YValue;
418 } 352 }
419 else if (CHECK_GEOM_OPS ("root")) 353 else if (CHECK_GEOM_OPS ("root"))
420 { 354 {
421 new_flags |= rootAlign; 355 new_flags |= rootAlign;
422 w = h = noScale; 356 w = h = noScale;
423 geom_flags |= WidthValue|HeightValue; 357 geom_flags |= WidthValue|HeightValue;
424 } 358 }
425# undef CHECK_GEOM_OPS 359# undef CHECK_GEOM_OPS
426 360
427 while (*ops != ':' && *ops != '\0') ++ops; 361 while (*ops != ':' && *ops != '\0') ++ops;
428 } /* done parsing ops */ 362 } /* done parsing ops */
429 } 363 }
430 364
431 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) ++changed; 365 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true;
432 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) ++changed; 366 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true;
433 if (check_set_align_value (geom_flags, XValue, h_align, x)) ++changed; 367 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true;
434 if (check_set_align_value (geom_flags, YValue, v_align, y)) ++changed; 368 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true;
435 }
436 369
437 if (new_flags != flags) 370 if (new_flags != flags)
438 { 371 {
439 flags = new_flags; 372 flags = new_flags;
440 changed++; 373 changed = true;
441 } 374 }
442 375
443 //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n",
444 // flags, h_scale, v_scale, h_align, v_align);
445 return (changed > 0); 376 return changed;
446} 377}
447 378
448void 379void
449bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) 380bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y)
450{ 381{
467 if (!w) w = image_width; 398 if (!w) w = image_width;
468 if (!h) h = image_height; 399 if (!h) h = image_height;
469 400
470 if (flags & rootAlign) 401 if (flags & rootAlign)
471 { 402 {
472 target->get_window_origin (x, y);
473 x = -x; 403 x = -target_x;
474 y = -y; 404 y = -target_y;
475 } 405 }
476 else 406 else
477 { 407 {
478 x = make_align_position (h_align, target_width, w); 408 x = make_align_position (h_align, target_width, w);
479 y = make_align_position (v_align, target_height, h); 409 y = make_align_position (v_align, target_height, h);
480 } 410 }
481 411
482 flags &= ~sizeSensitive; 412 flags &= ~sizeSensitive;
483 if (h_scale != 0 || v_scale != 0 413 if ((flags & propScale) || h_scale || v_scale
484 || h_align != 0 || v_align != 0 414 || (!(flags & rootAlign) && (h_align || v_align))
485 || w > target_width || h > target_height) 415 || w > target_width || h > target_height)
486 flags |= sizeSensitive; 416 flags |= sizeSensitive;
487} 417}
488 418
489# ifdef HAVE_AFTERIMAGE 419# ifdef HAVE_AFTERIMAGE
539 469
540 int x = 0; 470 int x = 0;
541 int y = 0; 471 int y = 0;
542 int w = 0; 472 int w = 0;
543 int h = 0; 473 int h = 0;
544
545 TIMING_TEST_START (asim);
546 474
547 if (original_asim) 475 if (original_asim)
548 get_image_geometry (original_asim->width, original_asim->height, w, h, x, y); 476 get_image_geometry (original_asim->width, original_asim->height, w, h, x, y);
549 477
550 if (!original_asim 478 if (!original_asim
667 } 595 }
668 596
669 free (layers); 597 free (layers);
670 } 598 }
671 } 599 }
672 TIMING_TEST_PRINT_RESULT (asim);
673 600
674 bool ret = false; 601 bool ret = false;
675 602
676 if (result) 603 if (result)
677 { 604 {
678 XGCValues gcv; 605 XGCValues gcv;
679 GC gc; 606 GC gc;
680 607
681 if (pixmap)
682 {
683 if (pmap_width != new_pmap_width
684 || pmap_height != new_pmap_height
685 || pmap_depth != target->depth)
686 {
687 XFreePixmap (target->dpy, pixmap);
688 pixmap = None;
689 }
690 }
691
692 /* create Pixmap */ 608 /* create Pixmap */
693 if (pixmap == None) 609 if (pixmap == None
610 || pmap_width != new_pmap_width
611 || pmap_height != new_pmap_height
612 || pmap_depth != target->depth)
694 { 613 {
614 if (pixmap)
615 XFreePixmap (target->dpy, pixmap);
695 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 616 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
696 pmap_width = new_pmap_width; 617 pmap_width = new_pmap_width;
697 pmap_height = new_pmap_height; 618 pmap_height = new_pmap_height;
698 pmap_depth = target->depth; 619 pmap_depth = target->depth;
699 } 620 }
723 644
724 if (result != background && result != original_asim) 645 if (result != background && result != original_asim)
725 destroy_asimage (&result); 646 destroy_asimage (&result);
726 647
727 XFreeGC (target->dpy, gc); 648 XFreeGC (target->dpy, gc);
728 TIMING_TEST_PRINT_RESULT (asim);
729 649
730 ret = true; 650 ret = true;
731 } 651 }
732 652
733 if (background) 653 if (background)
745 return false; 665 return false;
746 666
747 if (!pixbuf) 667 if (!pixbuf)
748 return false; 668 return false;
749 669
750#if !XFT
751 if (background_flags) 670 if (background_flags
671 && !(flags & HAS_RENDER))
752 return false; 672 return false;
753#endif
754 673
755 GdkPixbuf *result; 674 GdkPixbuf *result;
756 675
757 int image_width = gdk_pixbuf_get_width (pixbuf); 676 int image_width = gdk_pixbuf_get_width (pixbuf);
758 int image_height = gdk_pixbuf_get_height (pixbuf); 677 int image_height = gdk_pixbuf_get_height (pixbuf);
809 new_pmap_width = min (image_width, target_width); 728 new_pmap_width = min (image_width, target_width);
810 new_pmap_height = min (image_height, target_height); 729 new_pmap_height = min (image_height, target_height);
811 } 730 }
812 } 731 }
813 732
814 if (pixmap)
815 {
816 if (pmap_width != new_pmap_width
817 || pmap_height != new_pmap_height
818 || pmap_depth != target->depth)
819 {
820 XFreePixmap (target->dpy, pixmap);
821 pixmap = None;
822 }
823 }
824
825 if (pixmap == None) 733 if (pixmap == None
734 || pmap_width != new_pmap_width
735 || pmap_height != new_pmap_height
736 || pmap_depth != target->depth)
826 { 737 {
738 if (pixmap)
739 XFreePixmap (target->dpy, pixmap);
827 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 740 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
828 pmap_width = new_pmap_width; 741 pmap_width = new_pmap_width;
829 pmap_height = new_pmap_height; 742 pmap_height = new_pmap_height;
830 pmap_depth = target->depth; 743 pmap_depth = target->depth;
831 } 744 }
872 dst_width, dst_height, 785 dst_width, dst_height,
873 XLIB_RGB_DITHER_NONE, 786 XLIB_RGB_DITHER_NONE,
874 0, 0); 787 0, 0);
875 } 788 }
876 789
877#if XFT 790#if XRENDER
878 if (background_flags) 791 if (background_flags)
879 { 792 {
880 Display *dpy = target->dpy; 793 Display *dpy = target->dpy;
881 XRenderPictureAttributes pa; 794 XRenderPictureAttributes pa;
882 795
883 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, target->display->screen)); 796 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, target->visual);
884 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); 797 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa);
885 798
886 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); 799 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual);
887 Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa); 800 Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa);
888 801
925# endif /* HAVE_PIXBUF */ 838# endif /* HAVE_PIXBUF */
926 839
927bool 840bool
928bgPixmap_t::set_file (const char *file) 841bgPixmap_t::set_file (const char *file)
929{ 842{
930 assert (file); 843 if (!file || !*file)
844 return false;
931 845
932 if (*file)
933 {
934 if (const char *p = strchr (file, ';')) 846 if (const char *p = strchr (file, ';'))
935 { 847 {
936 size_t len = p - file; 848 size_t len = p - file;
937 char *f = rxvt_temp_buf<char> (len + 1); 849 char *f = rxvt_temp_buf<char> (len + 1);
938 memcpy (f, file, len); 850 memcpy (f, file, len);
939 f[len] = '\0'; 851 f[len] = '\0';
940 file = f; 852 file = f;
941 } 853 }
942 854
943# ifdef HAVE_AFTERIMAGE 855# ifdef HAVE_AFTERIMAGE
944 if (!target->asimman) 856 if (!target->asimman)
945 target->asimman = create_generic_imageman (target->rs[Rs_path]); 857 target->asimman = create_generic_imageman (target->rs[Rs_path]);
946 ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); 858 ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
947 if (image) 859 if (image)
948 { 860 {
949 if (original_asim) 861 if (original_asim)
950 safe_asimage_destroy (original_asim); 862 safe_asimage_destroy (original_asim);
951 original_asim = image; 863 original_asim = image;
952 have_image = true; 864 have_image = true;
953 return true; 865 return true;
954 } 866 }
955# endif 867# endif
956 868
957# ifdef HAVE_PIXBUF 869# ifdef HAVE_PIXBUF
958 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); 870 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL);
959 if (image) 871 if (image)
960 { 872 {
961 if (pixbuf) 873 if (pixbuf)
962 g_object_unref (pixbuf); 874 g_object_unref (pixbuf);
963 pixbuf = image; 875 pixbuf = image;
964 have_image = true; 876 have_image = true;
965 return true; 877 return true;
966 } 878 }
967# endif 879# endif
968 }
969 880
970 return false; 881 return false;
971} 882}
972 883
973# endif /* BG_IMAGE_FROM_FILE */ 884# endif /* BG_IMAGE_FROM_FILE */
986} 897}
987 898
988bool 899bool
989bgPixmap_t::set_blur_radius (const char *geom) 900bgPixmap_t::set_blur_radius (const char *geom)
990{ 901{
991 int changed = 0; 902 bool changed = false;
992 unsigned int hr, vr; 903 unsigned int hr, vr;
993 int junk; 904 int junk;
994 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); 905 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
995 906
996 if (!(geom_flags & WidthValue)) 907 if (!(geom_flags & WidthValue))
1001 min_it (hr, 128); 912 min_it (hr, 128);
1002 min_it (vr, 128); 913 min_it (vr, 128);
1003 914
1004 if (h_blurRadius != hr) 915 if (h_blurRadius != hr)
1005 { 916 {
1006 ++changed; 917 changed = true;
1007 h_blurRadius = hr; 918 h_blurRadius = hr;
1008 } 919 }
1009 920
1010 if (v_blurRadius != vr) 921 if (v_blurRadius != vr)
1011 { 922 {
1012 ++changed; 923 changed = true;
1013 v_blurRadius = vr; 924 v_blurRadius = vr;
1014 } 925 }
1015 926
1016 if (v_blurRadius == 0 && h_blurRadius == 0) 927 if (v_blurRadius == 0 && h_blurRadius == 0)
1017 flags &= ~blurNeeded; 928 flags &= ~blurNeeded;
1018 else 929 else
1019 flags |= blurNeeded; 930 flags |= blurNeeded;
1020 931
1021#if XFT
1022 XFilters *filters = XRenderQueryFilters (target->dpy, target->display->root);
1023 if (filters)
1024 {
1025 for (int i = 0; i < filters->nfilter; i++)
1026 if (!strcmp (filters->filter[i], FilterConvolution))
1027 flags |= bgPixmap_t::blurServerSide;
1028
1029 XFree (filters);
1030 }
1031#endif
1032
1033 return (changed > 0); 932 return changed;
1034} 933}
1035 934
1036static inline unsigned long 935static inline unsigned long
1037compute_tint_shade_flags (rxvt_color *tint, int shade) 936compute_tint_shade_flags (rxvt_color *tint, int shade)
1038{ 937{
1042 941
1043 if (tint) 942 if (tint)
1044 { 943 {
1045 tint->get (c); 944 tint->get (c);
1046# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700) 945# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700)
946 if (!has_shade
1047 if (!has_shade && IS_COMPONENT_WHOLESOME (c.r) 947 && IS_COMPONENT_WHOLESOME (c.r)
1048 && IS_COMPONENT_WHOLESOME (c.g) 948 && IS_COMPONENT_WHOLESOME (c.g)
1049 && IS_COMPONENT_WHOLESOME (c.b)) 949 && IS_COMPONENT_WHOLESOME (c.b))
1050 flags |= bgPixmap_t::tintWholesome; 950 flags |= bgPixmap_t::tintWholesome;
1051# undef IS_COMPONENT_WHOLESOME 951# undef IS_COMPONENT_WHOLESOME
1052 } 952 }
1053 953
1054 if (has_shade) 954 if (has_shade || tint)
1055 flags |= bgPixmap_t::tintNeeded; 955 flags |= bgPixmap_t::tintNeeded;
1056 else if (tint)
1057 {
1058 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700)
1059 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700))
1060 {
1061 flags |= bgPixmap_t::tintNeeded;
1062 }
1063 }
1064
1065 if (flags & bgPixmap_t::tintNeeded)
1066 {
1067 if (flags & bgPixmap_t::tintWholesome)
1068 flags |= bgPixmap_t::tintServerSide;
1069 else
1070 {
1071#if XFT
1072 flags |= bgPixmap_t::tintServerSide;
1073#endif
1074 }
1075 }
1076 956
1077 return flags; 957 return flags;
1078} 958}
1079 959
1080bool 960bool
1123 } 1003 }
1124 1004
1125 return false; 1005 return false;
1126} 1006}
1127 1007
1008#if XRENDER
1128static void 1009static void
1129get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) 1010get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params)
1130{ 1011{
1131 double sigma = radius / 2.0; 1012 double sigma = radius / 2.0;
1132 double scale = sqrt (2.0 * M_PI) * sigma; 1013 double scale = sqrt (2.0 * M_PI) * sigma;
1133 double sum = 0.0; 1014 double sum = 0.0;
1134 1015
1135 for (int i = 0; i < width; i++) 1016 for (int i = 0; i < width; i++)
1136 { 1017 {
1137 double x = i - width / 2; 1018 double x = i - width / 2;
1138 kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; 1019 kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale;
1139 sum += kernel[i]; 1020 sum += kernel[i];
1140 } 1021 }
1141 1022
1142 params[0] = XDoubleToFixed (width); 1023 params[0] = XDoubleToFixed (width);
1143 params[1] = XDoubleToFixed (1); 1024 params[1] = XDoubleToFixed (1);
1144 1025
1145 for (int i = 0; i < width; i++) 1026 for (int i = 0; i < width; i++)
1146 params[i+2] = XDoubleToFixed (kernel[i] / sum); 1027 params[i+2] = XDoubleToFixed (kernel[i] / sum);
1147} 1028}
1029#endif
1148 1030
1149bool 1031bool
1150bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) 1032bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height)
1151{ 1033{
1152 bool ret = false; 1034 bool ret = false;
1153#if XFT 1035#if XRENDER
1154 int size = max (h_blurRadius, v_blurRadius) * 2 + 1; 1036 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
1155 double *kernel = (double *)malloc (size * sizeof (double)); 1037 double *kernel = (double *)malloc (size * sizeof (double));
1156 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 1038 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
1157 1039
1158 Display *dpy = target->dpy; 1040 Display *dpy = target->dpy;
1159 XRenderPictureAttributes pa; 1041 XRenderPictureAttributes pa;
1160 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, target->visual); 1042 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1161 1043
1162 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1044 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1163 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1045 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1164 1046
1165 if (kernel && params && src && dst) 1047 if (kernel && params && src && dst)
1235 XFreeGC (dpy, gc); 1117 XFreeGC (dpy, gc);
1236 } 1118 }
1237 } 1119 }
1238 else 1120 else
1239 { 1121 {
1240# if XFT 1122# if XRENDER
1241 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1123 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1242 1124
1243 if (flags & tintSet) 1125 if (flags & tintSet)
1244 tint.get (c); 1126 tint.get (c);
1245 1127
1275 1157
1276 if (mask_pic && overlay_pic && back_pic) 1158 if (mask_pic && overlay_pic && back_pic)
1277 { 1159 {
1278 XRenderColor mask_c; 1160 XRenderColor mask_c;
1279 1161
1280 memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c)); 1162 mask_c.red = mask_c.green = mask_c.blue = shade > 100 ? 0xffff : 0;
1281 mask_c.alpha = 0xffff; 1163 mask_c.alpha = 0xffff;
1282 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); 1164 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1283 1165
1284 mask_c.alpha = 0; 1166 mask_c.alpha = 0;
1285 mask_c.red = 0xffff - c.r; 1167 mask_c.red = 0xffff - c.r;
1291 } 1173 }
1292 1174
1293 XRenderFreePicture (dpy, mask_pic); 1175 XRenderFreePicture (dpy, mask_pic);
1294 XRenderFreePicture (dpy, overlay_pic); 1176 XRenderFreePicture (dpy, overlay_pic);
1295 XRenderFreePicture (dpy, back_pic); 1177 XRenderFreePicture (dpy, back_pic);
1296# if DO_TIMING_TEST
1297 XSync (dpy, False);
1298# endif
1299# endif 1178# endif
1300 } 1179 }
1301 1180
1302 return ret; 1181 return ret;
1303} 1182}
1304 1183
1305/* make_transparency_pixmap() 1184/* make_transparency_pixmap()
1306 * Builds a pixmap sized the same as terminal window, with depth same as the root window 1185 * Builds a pixmap of the same size as the terminal window that contains
1307 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by 1186 * the tiled portion of the root pixmap that is supposed to be covered by
1308 * our window. 1187 * our window.
1309 */ 1188 */
1310unsigned long 1189unsigned long
1311bgPixmap_t::make_transparency_pixmap () 1190bgPixmap_t::make_transparency_pixmap ()
1312{ 1191{
1316 return 0; 1195 return 0;
1317 1196
1318 /* root dimensions may change from call to call - but Display structure should 1197 /* root dimensions may change from call to call - but Display structure should
1319 * be always up-to-date, so let's use it : 1198 * be always up-to-date, so let's use it :
1320 */ 1199 */
1321 Window root = target->display->root;
1322 int screen = target->display->screen; 1200 int screen = target->display->screen;
1323 Display *dpy = target->dpy; 1201 Display *dpy = target->dpy;
1202 int root_depth = DefaultDepth (dpy, screen);
1324 int root_width = DisplayWidth (dpy, screen); 1203 int root_width = DisplayWidth (dpy, screen);
1325 int root_height = DisplayHeight (dpy, screen); 1204 int root_height = DisplayHeight (dpy, screen);
1326 unsigned int root_pmap_width, root_pmap_height; 1205 unsigned int root_pmap_width, root_pmap_height;
1327 int window_width = target->szHint.width; 1206 int window_width = target->szHint.width;
1328 int window_height = target->szHint.height; 1207 int window_height = target->szHint.height;
1329 int sx, sy; 1208 int sx, sy;
1330 XGCValues gcv; 1209 XGCValues gcv;
1331 GC gc; 1210 GC gc;
1332 1211
1333 TIMING_TEST_START (tp); 1212 sx = target_x;
1334 target->get_window_origin (sx, sy); 1213 sy = target_y;
1335 1214
1336 /* check if we are outside of the visible part of the virtual screen : */ 1215 /* check if we are outside of the visible part of the virtual screen : */
1337 if (sx + window_width <= 0 || sy + window_height <= 0 1216 if (sx + window_width <= 0 || sy + window_height <= 0
1338 || sx >= root_width || sy >= root_height) 1217 || sx >= root_width || sy >= root_height)
1339 return 0; 1218 return 0;
1340 1219
1220 // validate root pixmap and get its size
1341 if (root_pixmap != None) 1221 if (root_pixmap != None)
1342 { 1222 {
1343 /* we want to validate the pixmap and get its size at the same time : */ 1223 Window wdummy;
1344 int junk; 1224 int idummy;
1345 unsigned int ujunk; 1225 unsigned int udummy;
1346 /* root pixmap may be bad - allow a error */ 1226
1347 target->allowedxerror = -1; 1227 target->allowedxerror = -1;
1348 1228
1349 if (!XGetGeometry (dpy, root_pixmap, &root, &junk, &junk, &root_pmap_width, &root_pmap_height, &ujunk, &ujunk)) 1229 if (!XGetGeometry (dpy, root_pixmap, &wdummy, &idummy, &idummy, &root_pmap_width, &root_pmap_height, &udummy, &udummy))
1350 root_pixmap = None; 1230 root_pixmap = None;
1351 1231
1352 target->allowedxerror = 0; 1232 target->allowedxerror = 0;
1233 }
1234
1235 Pixmap recoded_root_pmap = root_pixmap;
1236
1237 if (root_pixmap != None && root_depth != target->depth)
1238 {
1239#if XRENDER
1240 if (flags & HAS_RENDER)
1241 {
1242 XRenderPictureAttributes pa;
1243
1244 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
1245 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa);
1246
1247 recoded_root_pmap = XCreatePixmap (dpy, target->vt, root_pmap_width, root_pmap_height, target->depth);
1248 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual);
1249 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa);
1250
1251 if (src && dst)
1252 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height);
1253 else
1254 {
1255 XFreePixmap (dpy, recoded_root_pmap);
1256 root_pixmap = None;
1257 }
1258
1259 XRenderFreePicture (dpy, src);
1260 XRenderFreePicture (dpy, dst);
1261 }
1262 else
1263#endif
1264 root_pixmap = None;
1353 } 1265 }
1354 1266
1355 if (root_pixmap == None) 1267 if (root_pixmap == None)
1356 return 0; 1268 return 0;
1357 1269
1358 Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth); 1270 Pixmap tiled_root_pmap = XCreatePixmap (dpy, target->vt, window_width, window_height, target->depth);
1359 1271
1360 if (tiled_root_pmap == None) /* something really bad happened - abort */ 1272 if (tiled_root_pmap == None) /* something really bad happened - abort */
1361 return 0; 1273 return 0;
1362 1274
1363 /* straightforward pixmap copy */ 1275 /* straightforward pixmap copy */
1364 gcv.tile = root_pixmap;
1365 gcv.fill_style = FillTiled;
1366
1367 while (sx < 0) sx += (int)root_width; 1276 while (sx < 0) sx += (int)root_width;
1368 while (sy < 0) sy += (int)root_height; 1277 while (sy < 0) sy += (int)root_height;
1369 1278
1279 gcv.tile = recoded_root_pmap;
1280 gcv.fill_style = FillTiled;
1370 gcv.ts_x_origin = -sx; 1281 gcv.ts_x_origin = -sx;
1371 gcv.ts_y_origin = -sy; 1282 gcv.ts_y_origin = -sy;
1372 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 1283 gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
1373 1284
1374 if (gc) 1285 if (gc)
1375 { 1286 {
1376 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); 1287 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
1377 result |= transpPmapTiled; 1288 result |= transpPmapTiled;
1378 XFreeGC (dpy, gc); 1289 XFreeGC (dpy, gc);
1379 }
1380 TIMING_TEST_PRINT_RESULT (tp);
1381 1290
1382 if (tiled_root_pmap != None)
1383 {
1384 if (!need_client_side_rendering ()) 1291 if (!need_client_side_rendering ())
1385 { 1292 {
1386 if ((flags & blurNeeded)) 1293 if ((flags & blurNeeded)
1294 && (flags & HAS_RENDER_CONV))
1387 { 1295 {
1388 if (blur_pixmap (tiled_root_pmap, DefaultVisual (dpy, target->display->screen), window_width, window_height)) 1296 if (blur_pixmap (tiled_root_pmap, target->visual, window_width, window_height))
1389 result |= transpPmapBlurred; 1297 result |= transpPmapBlurred;
1390 } 1298 }
1391 if ((flags & tintNeeded)) 1299 if ((flags & tintNeeded)
1300 && (flags & (tintWholesome | HAS_RENDER)))
1392 { 1301 {
1393 if (tint_pixmap (tiled_root_pmap, DefaultVisual (dpy, target->display->screen), window_width, window_height)) 1302 if (tint_pixmap (tiled_root_pmap, target->visual, window_width, window_height))
1394 result |= transpPmapTinted; 1303 result |= transpPmapTinted;
1395 } 1304 }
1396 } /* server side rendering completed */ 1305 } /* server side rendering completed */
1397 1306
1398 if (pixmap) 1307 if (pixmap)
1399 XFreePixmap (dpy, pixmap); 1308 XFreePixmap (dpy, pixmap);
1400 1309
1401 pixmap = tiled_root_pmap; 1310 pixmap = tiled_root_pmap;
1402 pmap_width = window_width; 1311 pmap_width = window_width;
1403 pmap_height = window_height; 1312 pmap_height = window_height;
1404 pmap_depth = root_depth; 1313 pmap_depth = target->depth;
1405 } 1314 }
1315 else
1316 XFreePixmap (dpy, tiled_root_pmap);
1406 1317
1407 TIMING_TEST_PRINT_RESULT (tp); 1318 if (recoded_root_pmap != root_pixmap)
1319 XFreePixmap (dpy, recoded_root_pmap);
1408 1320
1409 return result; 1321 return result;
1410} 1322}
1411 1323
1412bool 1324void
1413bgPixmap_t::set_root_pixmap () 1325bgPixmap_t::set_root_pixmap ()
1414{ 1326{
1415 Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); 1327 Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID);
1416 if (new_root_pixmap == None) 1328 if (new_root_pixmap == None)
1417 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); 1329 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID);
1418 1330
1419 if (new_root_pixmap != root_pixmap)
1420 {
1421 root_pixmap = new_root_pixmap; 1331 root_pixmap = new_root_pixmap;
1422 return true;
1423 }
1424
1425 return false;
1426} 1332}
1427# endif /* ENABLE_TRANSPARENCY */ 1333# endif /* ENABLE_TRANSPARENCY */
1428 1334
1429# ifndef HAVE_AFTERIMAGE 1335#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1430static void ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm); 1336static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, const rgba &c);
1431# endif 1337# endif
1432 1338
1433bool 1339bool
1434bgPixmap_t::render () 1340bgPixmap_t::render ()
1435{ 1341{
1436 unsigned long background_flags = 0; 1342 unsigned long background_flags = 0;
1437 1343
1438 if (target == NULL) 1344 if (target == NULL)
1439 return false; 1345 return false;
1440
1441 TIMING_TEST_START (tp);
1442 1346
1443 invalidate (); 1347 invalidate ();
1444# ifdef ENABLE_TRANSPARENCY 1348# ifdef ENABLE_TRANSPARENCY
1445 if (flags & isTransparent) 1349 if (flags & isTransparent)
1446 { 1350 {
1447 /* we need to re-generate transparency pixmap in that case ! */ 1351 /* we need to re-generate transparency pixmap in that case ! */
1448 background_flags = make_transparency_pixmap (); 1352 background_flags = make_transparency_pixmap ();
1449 if (background_flags == 0) 1353 if (background_flags == 0)
1450 return false; 1354 return false;
1451 else if ((background_flags & transpTransformations) == (flags & transpTransformations) 1355 else if ((background_flags & transpTransformations) == (flags & transpTransformations))
1452 && pmap_depth == target->depth)
1453 flags = flags & ~isInvalid; 1356 flags &= ~isInvalid;
1454 } 1357 }
1455# endif 1358# endif
1456 1359
1457# ifdef BG_IMAGE_FROM_FILE 1360# ifdef BG_IMAGE_FROM_FILE
1458 if (have_image 1361 if (have_image
1459 || (background_flags & transpTransformations) != (flags & transpTransformations)) 1362 || (background_flags & transpTransformations) != (flags & transpTransformations))
1460 { 1363 {
1461 if (render_image (background_flags)) 1364 if (render_image (background_flags))
1462 flags = flags & ~isInvalid; 1365 flags &= ~isInvalid;
1463 } 1366 }
1464# endif 1367# endif
1465 1368
1369# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1466 XImage *result = NULL; 1370 XImage *result = NULL;
1467 1371
1468 if (background_flags && (flags & isInvalid)) 1372 if (background_flags && (flags & isInvalid))
1469 { 1373 {
1470 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1374 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1471 } 1375 }
1472 1376
1473 if (result) 1377 if (result)
1474 { 1378 {
1475# if !defined(HAVE_AFTERIMAGE) && !XFT
1476 /* our own client-side tinting */ 1379 /* our own client-side tinting */
1477 /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side.
1478 This may need to be changed in need_client_side_rendering() logic is altered !!! */
1479 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1380 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
1480 { 1381 {
1481 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1382 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1482 if (flags & tintSet) 1383 if (flags & tintSet)
1483 tint.get (c); 1384 tint.get (c);
1484 ShadeXImage (target, result, shade, c.r, c.g, c.b); 1385 ShadeXImage (DefaultVisual (target->dpy, target->display->screen), result, shade, c);
1485 } 1386 }
1486# endif
1487 1387
1488 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1388 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1489 1389
1490 if (gc) 1390 if (gc)
1491 { 1391 {
1492 if (/*pmap_depth != target->depth &&*/ pixmap != None)
1493 {
1494 XFreePixmap (target->dpy, pixmap);
1495 pixmap = None;
1496 }
1497
1498 if (pixmap == None)
1499 {
1500 pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth);
1501 pmap_width = result->width;
1502 pmap_height = result->height;
1503 pmap_depth = target->depth;
1504 }
1505
1506 if (pmap_depth != result->depth)
1507 {
1508 /* Bad Match error will ensue ! stupid X !!!! */
1509 if (result->depth == 24 && pmap_depth == 32)
1510 result->depth = 32;
1511 else if (result->depth == 32 && pmap_depth == 24)
1512 result->depth = 24;
1513 else
1514 {
1515 /* TODO: implement image recoding */
1516 }
1517 }
1518
1519 if (pmap_depth == result->depth)
1520 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); 1392 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1521 1393
1522 XFreeGC (target->dpy, gc); 1394 XFreeGC (target->dpy, gc);
1523 flags = flags & ~isInvalid; 1395 flags &= ~isInvalid;
1524 } 1396 }
1525 1397
1526 XDestroyImage (result); 1398 XDestroyImage (result);
1527 } 1399 }
1400# endif
1528 1401
1529 if (flags & isInvalid) 1402 if (flags & isInvalid)
1530 { 1403 {
1531 if (pixmap != None) 1404 if (pixmap != None)
1532 { 1405 {
1535 } 1408 }
1536 } 1409 }
1537 1410
1538 apply (); 1411 apply ();
1539 1412
1540 XSync (target->dpy, False);
1541 valid_since = ev::now (); 1413 valid_since = ev::now ();
1542 1414
1543 TIMING_TEST_PRINT_RESULT (tp);
1544
1545 return true; 1415 return true;
1546} 1416}
1547 1417
1548bool 1418void
1549bgPixmap_t::set_target (rxvt_term *new_target) 1419bgPixmap_t::set_target (rxvt_term *new_target)
1550{ 1420{
1551 if (new_target)
1552 if (target != new_target)
1553 {
1554 target = new_target; 1421 target = new_target;
1555# ifdef ENABLE_TRANSPARENCY 1422
1556 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); 1423 flags &= ~(HAS_RENDER | HAS_RENDER_CONV);
1424#if XRENDER
1425 int major, minor;
1426 if (XRenderQueryVersion (target->dpy, &major, &minor))
1427 flags |= HAS_RENDER;
1428 XFilters *filters = XRenderQueryFilters (target->dpy, target->vt);
1429 if (filters)
1430 {
1431 for (int i = 0; i < filters->nfilter; i++)
1432 if (!strcmp (filters->filter[i], FilterConvolution))
1433 flags |= HAS_RENDER_CONV;
1434
1435 XFree (filters);
1436 }
1557# endif 1437#endif
1558 return true;
1559 }
1560
1561 return false;
1562} 1438}
1563 1439
1564void 1440void
1565bgPixmap_t::apply () 1441bgPixmap_t::apply ()
1566{ 1442{
1567 if (target) 1443 if (target == NULL)
1568 { 1444 return;
1569 flags &= ~isVtOrigin;
1570 1445
1571 if (pixmap != None) 1446 if (pixmap != None)
1572 { 1447 {
1573 /* set target's background to pixmap */ 1448 /* set target's background to pixmap */
1574# ifdef ENABLE_TRANSPARENCY 1449# ifdef ENABLE_TRANSPARENCY
1575 if (flags & isTransparent) 1450 if (flags & isTransparent)
1576 { 1451 {
1577 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); 1452 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
1578 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); 1453 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1579 1454
1580 if (target->scrollBar.win) 1455 if (target->scrollBar.win)
1581 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); 1456 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
1582 } 1457 }
1583 else 1458 else
1584# endif 1459# endif
1585 { 1460 {
1586 flags |= isVtOrigin;
1587 /* force old pixmap dereference in case it was transparent before :*/ 1461 /* force old pixmap dereference in case it was transparent before :*/
1588 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1589 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1590 /* do we also need to set scrollbar's background here ? */
1591
1592 if (target->scrollBar.win)
1593 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1594 }
1595 }
1596 else
1597 {
1598 /* set target background to a pixel */
1599 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1462 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1600 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); 1463 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1601 /* do we also need to set scrollbar's background here ? */ 1464 /* do we also need to set scrollbar's background here ? */
1465
1602 if (target->scrollBar.win) 1466 if (target->scrollBar.win)
1603 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1467 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1604 } 1468 }
1469 }
1470 else
1471 {
1472 /* set target background to a pixel */
1473 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1474 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
1475 /* do we also need to set scrollbar's background here ? */
1476 if (target->scrollBar.win)
1477 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1478 }
1605 1479
1606 /* don't want Expose on the parent or vt. It is better to use 1480 /* don't want Expose on the parent or vt. It is better to use
1607 scr_touch or we get a great deal of flicker otherwise: */ 1481 scr_touch or we get a great deal of flicker otherwise: */
1608 XClearWindow (target->dpy, target->parent[0]); 1482 XClearWindow (target->dpy, target->parent[0]);
1609 1483
1610 if (target->scrollBar.state && target->scrollBar.win) 1484 if (target->scrollBar.state && target->scrollBar.win)
1611 { 1485 {
1612 target->scrollBar.state = STATE_IDLE; 1486 target->scrollBar.state = STATE_IDLE;
1613 target->scrollBar.show (0); 1487 target->scrollBar.show (0);
1614 } 1488 }
1615 1489
1616 target->want_refresh = 1; 1490 target->want_refresh = 1;
1617 flags |= hasChanged; 1491 flags |= hasChanged;
1618 }
1619} 1492}
1620 1493
1621#endif /* HAVE_BG_PIXMAP */ 1494#endif /* HAVE_BG_PIXMAP */
1622 1495
1623#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT 1496#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1624/* taken from aterm-0.4.2 */ 1497/* taken from aterm-0.4.2 */
1625 1498
1626typedef uint32_t RUINT32T;
1627
1628static void 1499static void
1629ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm) 1500ShadeXImage(Visual *visual, XImage *srcImage, int shade, const rgba &c)
1630{ 1501{
1631 int sh_r, sh_g, sh_b; 1502 int sh_r, sh_g, sh_b;
1632 RUINT32T mask_r, mask_g, mask_b; 1503 uint32_t mask_r, mask_g, mask_b;
1633 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; 1504 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1634 unsigned int lower_lim_r, lower_lim_g, lower_lim_b; 1505 rgba low;
1635 unsigned int upper_lim_r, upper_lim_g, upper_lim_b; 1506 rgba high;
1636 int i; 1507 int i;
1508 int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst;
1637 1509
1638 Visual *visual = term->visual;
1639
1640 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ; 1510 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return;
1641 1511
1642 /* for convenience */ 1512 /* for convenience */
1643 mask_r = visual->red_mask; 1513 mask_r = visual->red_mask;
1644 mask_g = visual->green_mask; 1514 mask_g = visual->green_mask;
1645 mask_b = visual->blue_mask; 1515 mask_b = visual->blue_mask;
1646 1516
1647 /* boring lookup table pre-initialization */ 1517 /* boring lookup table pre-initialization */
1648 switch (srcImage->bits_per_pixel) { 1518 switch (srcImage->depth)
1519 {
1649 case 15: 1520 case 15:
1650 if ((mask_r != 0x7c00) || 1521 if ((mask_r != 0x7c00) ||
1651 (mask_g != 0x03e0) || 1522 (mask_g != 0x03e0) ||
1652 (mask_b != 0x001f)) 1523 (mask_b != 0x001f))
1653 return; 1524 return;
1654 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32)); 1525 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+32+32));
1655 lookup_r = lookup; 1526 lookup_r = lookup;
1656 lookup_g = lookup+32; 1527 lookup_g = lookup+32;
1657 lookup_b = lookup+32+32; 1528 lookup_b = lookup+32+32;
1658 sh_r = 10; 1529 sh_r = 10;
1659 sh_g = 5; 1530 sh_g = 5;
1660 sh_b = 0; 1531 sh_b = 0;
1661 break; 1532 break;
1662 case 16: 1533 case 16:
1663 if ((mask_r != 0xf800) || 1534 if ((mask_r != 0xf800) ||
1664 (mask_g != 0x07e0) || 1535 (mask_g != 0x07e0) ||
1665 (mask_b != 0x001f)) 1536 (mask_b != 0x001f))
1666 return; 1537 return;
1667 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32)); 1538 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+64+32));
1668 lookup_r = lookup; 1539 lookup_r = lookup;
1669 lookup_g = lookup+32; 1540 lookup_g = lookup+32;
1670 lookup_b = lookup+32+64; 1541 lookup_b = lookup+32+64;
1671 sh_r = 11; 1542 sh_r = 11;
1672 sh_g = 5; 1543 sh_g = 5;
1673 sh_b = 0; 1544 sh_b = 0;
1674 break; 1545 break;
1675 case 24: 1546 case 24:
1676 if ((mask_r != 0xff0000) || 1547 if ((mask_r != 0xff0000) ||
1677 (mask_g != 0x00ff00) || 1548 (mask_g != 0x00ff00) ||
1678 (mask_b != 0x0000ff)) 1549 (mask_b != 0x0000ff))
1679 return; 1550 return;
1680 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256)); 1551 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(256+256+256));
1681 lookup_r = lookup; 1552 lookup_r = lookup;
1682 lookup_g = lookup+256; 1553 lookup_g = lookup+256;
1683 lookup_b = lookup+256+256; 1554 lookup_b = lookup+256+256;
1684 sh_r = 16; 1555 sh_r = 16;
1685 sh_g = 8; 1556 sh_g = 8;
1686 sh_b = 0; 1557 sh_b = 0;
1687 break; 1558 break;
1688 case 32: 1559 case 32:
1689 if ((mask_r != 0xff0000) || 1560 if ((mask_r != 0xff0000) ||
1690 (mask_g != 0x00ff00) || 1561 (mask_g != 0x00ff00) ||
1691 (mask_b != 0x0000ff)) 1562 (mask_b != 0x0000ff))
1692 return; 1563 return;
1693 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256)); 1564 lookup = (uint32_t *) malloc (sizeof (uint32_t)*(256+256+256));
1694 lookup_r = lookup; 1565 lookup_r = lookup;
1695 lookup_g = lookup+256; 1566 lookup_g = lookup+256;
1696 lookup_b = lookup+256+256; 1567 lookup_b = lookup+256+256;
1697 sh_r = 16; 1568 sh_r = 16;
1698 sh_g = 8; 1569 sh_g = 8;
1699 sh_b = 0; 1570 sh_b = 0;
1700 break; 1571 break;
1701 default: 1572 default:
1702 return; /* we do not support this color depth */ 1573 return; /* we do not support this color depth */
1703 } 1574 }
1704 1575
1705 /* prepare limits for color transformation (each channel is handled separately) */ 1576 /* prepare limits for color transformation (each channel is handled separately) */
1706 if (shade > 100) { 1577 if (shade > 100)
1578 {
1707 shade = 200 - shade; 1579 shade = 200 - shade;
1708 1580
1709 lower_lim_r = 65535-rm; 1581 high.r = (65535 - c.r) * shade / 100;
1710 lower_lim_g = 65535-gm; 1582 high.g = (65535 - c.g) * shade / 100;
1711 lower_lim_b = 65535-bm; 1583 high.b = (65535 - c.b) * shade / 100;
1712 1584
1713 lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100); 1585 low.r = 65535 - high.r;
1714 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100); 1586 low.g = 65535 - high.g;
1715 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100); 1587 low.b = 65535 - high.b;
1716
1717 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
1718 } else {
1719
1720 lower_lim_r = lower_lim_g = lower_lim_b = 0;
1721
1722 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100);
1723 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100);
1724 upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100);
1725 } 1588 }
1726 1589 else
1727 /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */
1728 if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 ))
1729 { 1590 {
1730 unsigned int tmp; 1591 high.r = c.r * shade / 100;
1592 high.g = c.g * shade / 100;
1593 high.b = c.b * shade / 100;
1731 1594
1732 tmp = lower_lim_r; 1595 low.r = low.g = low.b = 0;
1733 lower_lim_r = lower_lim_b;
1734 lower_lim_b = tmp;
1735
1736 tmp = upper_lim_r;
1737 upper_lim_r = upper_lim_b;
1738 upper_lim_b = tmp;
1739 } 1596 }
1740 1597
1741 /* fill our lookup tables */ 1598 /* fill our lookup tables */
1742 for (i = 0; i <= mask_r>>sh_r; i++) 1599 for (i = 0; i <= mask_r>>sh_r; i++)
1743 { 1600 {
1744 RUINT32T tmp; 1601 uint32_t tmp;
1745 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r)); 1602 tmp = i * high.r;
1746 tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r); 1603 tmp += (mask_r>>sh_r) * low.r;
1747 lookup_r[i] = (tmp/65535)<<sh_r; 1604 lookup_r[i] = (tmp/65535)<<sh_r;
1748 } 1605 }
1749 for (i = 0; i <= mask_g>>sh_g; i++) 1606 for (i = 0; i <= mask_g>>sh_g; i++)
1750 { 1607 {
1751 RUINT32T tmp; 1608 uint32_t tmp;
1752 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g)); 1609 tmp = i * high.g;
1753 tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g); 1610 tmp += (mask_g>>sh_g) * low.g;
1754 lookup_g[i] = (tmp/65535)<<sh_g; 1611 lookup_g[i] = (tmp/65535)<<sh_g;
1755 } 1612 }
1756 for (i = 0; i <= mask_b>>sh_b; i++) 1613 for (i = 0; i <= mask_b>>sh_b; i++)
1757 { 1614 {
1758 RUINT32T tmp; 1615 uint32_t tmp;
1759 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b)); 1616 tmp = i * high.b;
1760 tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b); 1617 tmp += (mask_b>>sh_b) * low.b;
1761 lookup_b[i] = (tmp/65535)<<sh_b; 1618 lookup_b[i] = (tmp/65535)<<sh_b;
1762 } 1619 }
1763 1620
1764 /* apply table to input image (replacing colors by newly calculated ones) */ 1621 /* apply table to input image (replacing colors by newly calculated ones) */
1765 switch (srcImage->bits_per_pixel) 1622 if (srcImage->bits_per_pixel == 32
1623 && (srcImage->depth == 24 || srcImage->depth == 32)
1624 && srcImage->byte_order == host_byte_order)
1766 { 1625 {
1767 case 15:
1768 {
1769 unsigned short *p1, *pf, *p, *pl; 1626 uint32_t *p1, *pf, *p, *pl;
1770 p1 = (unsigned short *) srcImage->data; 1627 p1 = (uint32_t *) srcImage->data;
1771 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); 1628 pf = (uint32_t *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
1629
1772 while (p1 < pf) 1630 while (p1 < pf)
1773 { 1631 {
1774 p = p1; 1632 p = p1;
1775 pl = p1 + srcImage->width; 1633 pl = p1 + srcImage->width;
1776 for (; p < pl; p++) 1634 for (; p < pl; p++)
1777 { 1635 {
1778 *p = lookup_r[(*p & 0x7c00)>>10] |
1779 lookup_g[(*p & 0x03e0)>> 5] |
1780 lookup_b[(*p & 0x001f)];
1781 }
1782 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
1783 }
1784 break;
1785 }
1786 case 16:
1787 {
1788 unsigned short *p1, *pf, *p, *pl;
1789 p1 = (unsigned short *) srcImage->data;
1790 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
1791 while (p1 < pf)
1792 {
1793 p = p1;
1794 pl = p1 + srcImage->width;
1795 for (; p < pl; p++)
1796 {
1797 *p = lookup_r[(*p & 0xf800)>>11] |
1798 lookup_g[(*p & 0x07e0)>> 5] |
1799 lookup_b[(*p & 0x001f)];
1800 }
1801 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
1802 }
1803 break;
1804 }
1805 case 24:
1806 {
1807 unsigned char *p1, *pf, *p, *pl;
1808 p1 = (unsigned char *) srcImage->data;
1809 pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
1810 while (p1 < pf)
1811 {
1812 p = p1;
1813 pl = p1 + srcImage->width * 3;
1814 for (; p < pl; p += 3)
1815 {
1816 p[0] = lookup_r[(p[0] & 0xff0000)>>16];
1817 p[1] = lookup_r[(p[1] & 0x00ff00)>> 8];
1818 p[2] = lookup_r[(p[2] & 0x0000ff)];
1819 }
1820 p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line);
1821 }
1822 break;
1823 }
1824 case 32:
1825 {
1826 RUINT32T *p1, *pf, *p, *pl;
1827 p1 = (RUINT32T *) srcImage->data;
1828 pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
1829
1830 while (p1 < pf)
1831 {
1832 p = p1;
1833 pl = p1 + srcImage->width;
1834 for (; p < pl; p++)
1835 {
1836 *p = lookup_r[(*p & 0xff0000)>>16] | 1636 *p = lookup_r[(*p & 0xff0000) >> 16] |
1837 lookup_g[(*p & 0x00ff00)>> 8] | 1637 lookup_g[(*p & 0x00ff00) >> 8] |
1838 lookup_b[(*p & 0x0000ff)] | 1638 lookup_b[(*p & 0x0000ff)] |
1839 (*p & ~0xffffff); 1639 (*p & 0xff000000);
1640 }
1641 p1 = (uint32_t *) ((char *) p1 + srcImage->bytes_per_line);
1642 }
1643 }
1644 else
1645 {
1646 for (int y = 0; y < srcImage->height; y++)
1647 for (int x = 0; x < srcImage->width; x++)
1648 {
1649 unsigned long pixel = XGetPixel (srcImage, x, y);
1650 pixel = lookup_r[(pixel & mask_r) >> sh_r] |
1651 lookup_g[(pixel & mask_g) >> sh_g] |
1652 lookup_b[(pixel & mask_b) >> sh_b];
1653 XPutPixel (srcImage, x, y, pixel);
1840 } 1654 }
1841 p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line);
1842 } 1655 }
1843 break;
1844 }
1845 }
1846 1656
1847 free (lookup); 1657 free (lookup);
1848} 1658}
1849#endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */ 1659#endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines