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.27 by ayin, Sun Jan 27 22:48:33 2008 UTC vs.
Revision 1.79 by sf-exg, Wed Oct 13 23:01:40 2010 UTC

1/*----------------------------------------------------------------------* 1/*----------------------------------------------------------------------*
2 * File: background.C - former xpm.C 2 * File: background.C - former xpm.C
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-2006 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 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * 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 10 * 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 11 * the Free Software Foundation; either version 2 of the License, or
27#define DO_TIMING_TEST 0 27#define DO_TIMING_TEST 0
28 28
29#if DO_TIMING_TEST 29#if DO_TIMING_TEST
30# include <sys/time.h> 30# include <sys/time.h>
31#define TIMING_TEST_START(id) \ 31#define TIMING_TEST_START(id) \
32 struct timeval timing_test_##id##_stv;\ 32 struct timeval timing_test_##id##_stv; \
33 gettimeofday (&timing_test_##id##_stv, NULL); 33 gettimeofday (&timing_test_##id##_stv, NULL);
34 34
35#define TIMING_TEST_PRINT_RESULT(id) \ 35#define TIMING_TEST_PRINT_RESULT(id) \
36 do{ struct timeval tv;gettimeofday (&tv, NULL); tv.tv_sec -= (timing_test_##id##_stv).tv_sec;\ 36 do { \
37 struct timeval tv; \
38 gettimeofday (&tv, NULL); \
39 tv.tv_sec -= (timing_test_##id##_stv).tv_sec; \
37 fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__,\ 40 fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__, \
38 tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec);}while (0) 41 tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec); \
42 } while (0)
39 43
40#else 44#else
41#define TIMING_TEST_START(id) do{}while (0) 45#define TIMING_TEST_START(id) do {} while (0)
42#define TIMING_TEST_PRINT_RESULT(id) do{}while (0) 46#define TIMING_TEST_PRINT_RESULT(id) do {} while (0)
43#endif 47#endif
44 48
45/* 49/*
46 * Pixmap geometry string interpretation : 50 * Pixmap geometry string interpretation :
47 * Each geometry string contains zero or one scale/position 51 * Each geometry string contains zero or one scale/position
48 * adjustment and may optionally be followed by a colon and one or more 52 * adjustment and may optionally be followed by a colon and one or more
49 * colon-delimited pixmap operations. 53 * colon-delimited pixmap operations.
50 * The following table shows the valid geometry strings and their 54 * The following table shows the valid geometry strings and their
51 * affects on the background image : 55 * effects on the background image :
52 * 56 *
53 * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. 57 * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%.
54 * W and H are percentages of the terminal window size. 58 * W and H are percentages of the terminal window size.
55 * X and Y are also percentages; e.g., +50+50 centers 59 * X and Y are also percentages; e.g., +50+50 centers
56 * the image in the window. 60 * the image in the window.
57 * WxH+X Assumes Y == X 61 * WxH+X Assumes Y == X
58 * WxH Assumes Y == X == 50 (centers the image) 62 * WxH Assumes Y == X == 50 (centers the image)
59 * W+X+Y Assumes H == W 63 * W+X+Y Assumes H == W
60 * W+X Assumes H == W and Y == X 64 * W+X Assumes H == W and Y == X
61 * W Assumes H == W and Y == X == 50 65 * W Assumes H == W and Y == X == 50
62 * 66 *
63 * Adjusting position only : 67 * Adjusting position only :
64 * =+X+Y Set position to X% by Y% (absolute). 68 * =+X+Y Set position to X% by Y% (absolute).
65 * =+X Set position to X% by X%. 69 * =+X Set position to X% by X%.
66 * +X+Y Adjust position horizontally X% and vertically Y% 70 * +X+Y Adjust position horizontally X% and vertically Y%
67 * from current position (relative). 71 * from current position (relative).
68 * +X Adjust position horizontally X% and vertically X% 72 * +X Adjust position horizontally X% and vertically X%
69 * from current position. 73 * from current position.
70 * 74 *
71 * Adjusting scale only : 75 * Adjusting scale only :
72 * Wx0 Multiply horizontal scaling factor by W% 76 * Wx0 Multiply horizontal scaling factor by W%
73 * 0xH Multiply vertical scaling factor by H% 77 * 0xH Multiply vertical scaling factor by H%
74 * 0x0 No scaling (show image at normal size). 78 * 0x0 No scaling (show image at normal size).
75 * 79 *
76 * Pixmap Operations : (should be prepended by a colon) 80 * Pixmap Operations : (should be prepended by a colon)
77 * tile Tile image. Scaling/position modifiers above will affect 81 * tile Tile image. Scaling/position modifiers above will affect
78 * the tile size and origin. 82 * the tile size and origin.
79 * propscale When scaling, scale proportionally. That is, maintain the 83 * propscale When scaling, scale proportionally. That is, maintain the
80 * proper aspect ratio for the image. Any portion of the 84 * proper aspect ratio for the image. Any portion of the
81 * background not covered by the image is filled with the 85 * background not covered by the image is filled with the
82 * current background color. 86 * current background color.
83 * hscale Scale horizontally, tile vertically ? 87 * hscale Scale horizontally, tile vertically ?
84 * vscale Tile horizontally, scale vertically ? 88 * vscale Tile horizontally, scale vertically ?
92 // this is basically redundant as bgPixmap_t is only used in 96 // this is basically redundant as bgPixmap_t is only used in
93 // zero_initialised-derived structs 97 // zero_initialised-derived structs
94#ifdef HAVE_AFTERIMAGE 98#ifdef HAVE_AFTERIMAGE
95 original_asim = NULL; 99 original_asim = NULL;
96#endif 100#endif
101#ifdef HAVE_PIXBUF
102 pixbuf = NULL;
103#endif
97#ifdef BG_IMAGE_FROM_FILE 104#ifdef BG_IMAGE_FROM_FILE
105 have_image = false;
98 h_scale = v_scale = 0; 106 h_scale = v_scale = 0;
99 h_align = v_align = 0; 107 h_align = v_align = 0;
108#endif
109#ifdef ENABLE_TRANSPARENCY
110 shade = 100;
100#endif 111#endif
101 flags = 0; 112 flags = 0;
102 pixmap = None; 113 pixmap = None;
103 valid_since = invalid_since = 0; 114 valid_since = invalid_since = 0;
104 target = 0; 115 target = 0;
110#ifdef HAVE_AFTERIMAGE 121#ifdef HAVE_AFTERIMAGE
111 if (original_asim) 122 if (original_asim)
112 safe_asimage_destroy (original_asim); 123 safe_asimage_destroy (original_asim);
113#endif 124#endif
114 125
126#ifdef HAVE_PIXBUF
127 if (pixbuf)
128 g_object_unref (pixbuf);
129#endif
130
115 if (pixmap && target) 131 if (pixmap && target)
116 XFreePixmap (target->dpy, pixmap); 132 XFreePixmap (target->dpy, pixmap);
117} 133}
118 134
119bool 135bool
123 if (flags & isTransparent) 139 if (flags & isTransparent)
124 return true; 140 return true;
125# endif 141# endif
126 142
127# ifdef BG_IMAGE_FROM_FILE 143# ifdef BG_IMAGE_FROM_FILE
128# ifdef HAVE_AFTERIMAGE 144 if (have_image)
129 if (original_asim)
130# endif
131 { 145 {
132 if (h_scale != 0 || v_scale != 0 146 if (flags & sizeSensitive)
133 || h_align != 0 || v_align != 0)
134 return true; 147 return true;
135 } 148 }
136# endif 149# endif
137 150
138 return false; 151 return false;
139} 152}
140 153
141bool 154bool
142bgPixmap_t::window_position_sensitive () 155bgPixmap_t::window_position_sensitive ()
143{ 156{
144# ifdef ENABLE_TRANSPARENCY 157# ifdef ENABLE_TRANSPARENCY
145 if (flags & isTransparent) 158 if (flags & isTransparent)
146 return true; 159 return true;
147# endif 160# endif
148 161
149# ifdef BG_IMAGE_FROM_FILE 162# ifdef BG_IMAGE_FROM_FILE
150# ifdef HAVE_AFTERIMAGE 163 if (have_image)
151 if (original_asim)
152# endif
153 { 164 {
154 if (h_align == rootAlign || v_align == rootAlign) 165 if (flags & rootAlign)
155 return true; 166 return true;
156 } 167 }
157# endif 168# endif
158 169
159 return false; 170 return false;
199static inline bool 210static inline bool
200check_set_align_value (int geom_flags, int flag, int &align, int new_value) 211check_set_align_value (int geom_flags, int flag, int &align, int new_value)
201{ 212{
202 if (geom_flags & flag) 213 if (geom_flags & flag)
203 { 214 {
204 if (new_value != bgPixmap_t::rootAlign)
205 {
206 if (new_value < -100) 215 if (new_value < -100)
207 new_value = -100; 216 new_value = -100;
208 else if (new_value > 200) 217 else if (new_value > 200)
209 new_value = 200; 218 new_value = 200;
210 }
211 if (new_value != align) 219 if (new_value != align)
212 { 220 {
213 align = new_value; 221 align = new_value;
214 return true; 222 return true;
215 } 223 }
219 227
220static inline int 228static inline int
221make_align_position (int align, int window_size, int image_size) 229make_align_position (int align, int window_size, int image_size)
222{ 230{
223 int diff = window_size - image_size; 231 int diff = window_size - image_size;
224 int smaller = MIN (image_size,window_size); 232 int smaller = min (image_size, window_size);
225 233
226 if (align >= 0 && align <= 50) 234 if (align >= 0 && align <= 100)
227 return diff * align / 100; 235 return diff * align / 100;
228 else if (align > 50 && align <= 100)
229 return window_size - image_size - diff * (100 - align) / 100;
230 else if (align > 100 && align <= 200 ) 236 else if (align > 100 && align <= 200 )
231 return ((align - 100) * smaller / 100) + window_size - smaller; 237 return ((align - 100) * smaller / 100) + window_size - smaller;
232 else if (align > -100 && align < 0) 238 else if (align >= -100 && align < 0)
233 return ((align + 100) * smaller / 100) - image_size; 239 return ((align + 100) * smaller / 100) - image_size;
234 return 0; 240 return 0;
235} 241}
236 242
237static inline int 243static inline int
238make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) 244make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size)
239{ 245{
240 int src_pos = 0; 246 int src_pos = 0;
241 dst_pos = 0; 247 dst_pos = pos;
242 dst_size = size; 248 dst_size = size;
243 if (pos < 0 && size > target_size) 249 if (pos < 0)
244 { 250 {
245 src_pos = -pos; 251 src_pos = -pos;
252 dst_pos = 0;
246 dst_size += pos; 253 dst_size += pos;
247 } 254 }
248 else if (pos > 0)
249 dst_pos = pos;
250 255
251 if (dst_pos + dst_size > target_size) 256 if (dst_pos + dst_size > target_size)
252 dst_size = target_size - dst_pos; 257 dst_size = target_size - dst_pos;
253 return src_pos; 258 return src_pos;
254} 259}
259 int geom_flags = 0, changed = 0; 264 int geom_flags = 0, changed = 0;
260 int x = 0, y = 0; 265 int x = 0, y = 0;
261 unsigned int w = 0, h = 0; 266 unsigned int w = 0, h = 0;
262 unsigned int n; 267 unsigned int n;
263 unsigned long new_flags = (flags & (~geometryFlags)); 268 unsigned long new_flags = (flags & (~geometryFlags));
264 char *p; 269 const char *p;
265# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */ 270# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */
266 271
267 if (geom == NULL) 272 if (geom == NULL)
268 return false; 273 return false;
269 274
379 w = h = noScale; 384 w = h = noScale;
380 geom_flags |= WidthValue|HeightValue; 385 geom_flags |= WidthValue|HeightValue;
381 } 386 }
382 else if (CHECK_GEOM_OPS ("propscale")) 387 else if (CHECK_GEOM_OPS ("propscale"))
383 { 388 {
384 if (w == 0 && h == 0)
385 {
386 w = windowScale;
387 geom_flags |= WidthValue;
388 }
389 new_flags |= propScale; 389 new_flags |= propScale;
390 } 390 }
391 else if (CHECK_GEOM_OPS ("hscale")) 391 else if (CHECK_GEOM_OPS ("hscale"))
392 { 392 {
393 if (w == 0) w = windowScale; 393 if (w == 0) w = windowScale;
415 x = y = centerAlign; 415 x = y = centerAlign;
416 geom_flags |= WidthValue|HeightValue|XValue|YValue; 416 geom_flags |= WidthValue|HeightValue|XValue|YValue;
417 } 417 }
418 else if (CHECK_GEOM_OPS ("root")) 418 else if (CHECK_GEOM_OPS ("root"))
419 { 419 {
420 new_flags |= rootAlign;
420 w = h = noScale; 421 w = h = noScale;
421 x = y = rootAlign;
422 geom_flags |= WidthValue|HeightValue|XValue|YValue; 422 geom_flags |= WidthValue|HeightValue;
423 } 423 }
424# undef CHECK_GEOM_OPS 424# undef CHECK_GEOM_OPS
425 425
426 while (*ops != ':' && *ops != '\0') ++ops; 426 while (*ops != ':' && *ops != '\0') ++ops;
427 } /* done parsing ops */ 427 } /* done parsing ops */
437 { 437 {
438 flags = new_flags; 438 flags = new_flags;
439 changed++; 439 changed++;
440 } 440 }
441 441
442//fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", 442 //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n",
443// flags, h_scale, v_scale, h_align, v_align); 443 // flags, h_scale, v_scale, h_align, v_align);
444 return (changed > 0); 444 return (changed > 0);
445}
446
447void
448bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y)
449{
450 int target_width = target->szHint.width;
451 int target_height = target->szHint.height;
452
453 if (flags & propScale)
454 {
455 float scale = (float)target_width / image_width;
456 min_it (scale, (float)target_height / image_height);
457 w = image_width * scale + 0.5;
458 h = image_height * scale + 0.5;
459 }
460 else
461 {
462 w = h_scale * target_width / 100;
463 h = v_scale * target_height / 100;
464 }
465
466 if (!w) w = image_width;
467 if (!h) h = image_height;
468
469 if (flags & rootAlign)
470 {
471 target->get_window_origin (x, y);
472 x = -x;
473 y = -y;
474 }
475 else
476 {
477 x = make_align_position (h_align, target_width, w);
478 y = make_align_position (v_align, target_height, h);
479 }
480
481 flags &= ~sizeSensitive;
482 if (h_scale != 0 || v_scale != 0
483 || h_align != 0 || v_align != 0
484 || w > target_width || h > target_height)
485 flags |= sizeSensitive;
445} 486}
446 487
447# ifdef HAVE_AFTERIMAGE 488# ifdef HAVE_AFTERIMAGE
448bool 489bool
449bgPixmap_t::render_asim (ASImage *background, ARGB32 background_tint) 490bgPixmap_t::render_image (unsigned long background_flags)
450{ 491{
451 if (target == NULL) 492 if (target == NULL)
452 return false; 493 return false;
453 494
495 target->init_asv ();
496
497 ASImage *background = NULL;
498 ARGB32 background_tint = TINT_LEAVE_SAME;
499
500# ifdef ENABLE_TRANSPARENCY
501 if (background_flags)
502 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100);
503
504 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
505 {
506 ShadingInfo as_shade;
507 as_shade.shading = shade;
508
509 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
510 if (flags & tintSet)
511 tint.get (c);
512 as_shade.tintColor.red = c.r;
513 as_shade.tintColor.green = c.g;
514 as_shade.tintColor.blue = c.b;
515
516 background_tint = shading2tint32 (&as_shade);
517 }
518
519 if (!(background_flags & transpPmapBlurred) && (flags & blurNeeded) && background != NULL)
520 {
521 ASImage *tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
522 (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage,
523 100, ASIMAGE_QUALITY_DEFAULT);
524 if (tmp)
525 {
526 destroy_asimage (&background);
527 background = tmp;
528 }
529 }
530# endif
531
532 ASImage *result = 0;
533
454 int target_width = (int)target->szHint.width; 534 int target_width = target->szHint.width;
455 int target_height = (int)target->szHint.height; 535 int target_height = target->szHint.height;
456 int new_pmap_width = target_width, new_pmap_height = target_height; 536 int new_pmap_width = target_width;
457 ASImage *result = NULL; 537 int new_pmap_height = target_height;
458 538
459 int x = 0; 539 int x = 0;
460 int y = 0; 540 int y = 0;
461 int w = h_scale * target_width / 100; 541 int w = 0;
462 int h = v_scale * target_height / 100; 542 int h = 0;
463 543
464 TIMING_TEST_START (asim); 544 TIMING_TEST_START (asim);
465 545
466 if (original_asim) 546 if (original_asim)
467 { 547 get_image_geometry (original_asim->width, original_asim->height, w, h, x, y);
468 if (h_align == rootAlign || v_align == rootAlign)
469 {
470 target->get_window_origin(x, y);
471 x = -x;
472 y = -y;
473 }
474
475 if (h_align != rootAlign)
476 x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width);
477
478 if (v_align != rootAlign)
479 y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height);
480 }
481 548
482 if (!original_asim 549 if (!original_asim
550 || (!(flags & rootAlign)
483 || x >= target_width 551 && (x >= target_width
484 || y >= target_height 552 || y >= target_height
485 || (w > 0 && x + w <= 0) 553 || (x + w <= 0)
486 || (h > 0 && y + h <= 0)) 554 || (y + h <= 0))))
487 { 555 {
488 if (background) 556 if (background)
489 { 557 {
490 new_pmap_width = background->width; 558 new_pmap_width = background->width;
491 new_pmap_height = background->height; 559 new_pmap_height = background->height;
492 result = background; 560 result = background;
493 561
494 if (background_tint != TINT_LEAVE_SAME) 562 if (background_tint != TINT_LEAVE_SAME)
495 { 563 {
496 ASImage* tmp = tile_asimage (target->asv, background, 0, 0, 564 ASImage *tmp = tile_asimage (target->asv, background, 0, 0,
497 target_width, target_height, background_tint, 565 target_width, target_height, background_tint,
498 ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); 566 ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT);
499 if (tmp) 567 if (tmp)
500 result = tmp; 568 result = tmp;
501 } 569 }
505 } 573 }
506 else 574 else
507 { 575 {
508 result = original_asim; 576 result = original_asim;
509 577
510 if ((w > 0 && w != original_asim->width) 578 if ((w != original_asim->width)
511 || (h > 0 && h != original_asim->height)) 579 || (h != original_asim->height))
512 { 580 {
513 result = scale_asimage (target->asv, original_asim, 581 result = scale_asimage (target->asv, original_asim,
514 w > 0 ? w : original_asim->width, 582 w, h,
515 h > 0 ? h : original_asim->height,
516 background ? ASA_ASImage : ASA_XImage, 583 background ? ASA_ASImage : ASA_XImage,
517 100, ASIMAGE_QUALITY_DEFAULT); 584 100, ASIMAGE_QUALITY_DEFAULT);
518 } 585 }
519 586
520 if (background == NULL) 587 if (background == NULL)
521 { 588 {
522 /* if tiling - pixmap has to be sized exactly as the image,
523 but there is no need to make it bigger than the window! */
524 if (h_scale == 0)
525 new_pmap_width = min (result->width, target_width);
526 if (v_scale == 0)
527 new_pmap_height = min (result->height, target_height);
528 /* we also need to tile our image in one or both directions */
529 if (h_scale == 0 || v_scale == 0) 589 if (h_scale == 0 || v_scale == 0)
530 { 590 {
591 /* if tiling - pixmap has to be sized exactly as the image,
592 but there is no need to make it bigger than the window! */
593 new_pmap_width = min (result->width, target_width);
594 new_pmap_height = min (result->height, target_height);
595
596 /* we also need to tile our image in both directions */
531 ASImage *tmp = tile_asimage (target->asv, result, 597 ASImage *tmp = tile_asimage (target->asv, result,
532 (h_scale > 0) ? 0 : (int)result->width - x, 598 (int)result->width - x,
533 (v_scale > 0) ? 0 : (int)result->height - y, 599 (int)result->height - y,
534 new_pmap_width, 600 new_pmap_width,
535 new_pmap_height, 601 new_pmap_height,
536 TINT_LEAVE_SAME, ASA_XImage, 602 TINT_LEAVE_SAME, ASA_XImage,
537 100, ASIMAGE_QUALITY_DEFAULT); 603 100, ASIMAGE_QUALITY_DEFAULT);
538 if (tmp) 604 if (tmp)
539 { 605 {
546 } 612 }
547 else 613 else
548 { 614 {
549 /* if blending background and image - pixmap has to be sized same as target window */ 615 /* if blending background and image - pixmap has to be sized same as target window */
550 ASImageLayer *layers = create_image_layers (2); 616 ASImageLayer *layers = create_image_layers (2);
551 ASImage *merged_im = NULL;
552 617
553 layers[0].im = background; 618 layers[0].im = background;
554 layers[0].clip_width = target_width; 619 layers[0].clip_width = target_width;
555 layers[0].clip_height = target_height; 620 layers[0].clip_height = target_height;
556 layers[0].tint = background_tint; 621 layers[0].tint = background_tint;
557 layers[1].im = result; 622 layers[1].im = result;
558 623
559 if (w <= 0) 624 if (h_scale == 0 || v_scale == 0)
560 { 625 {
561 /* tile horizontally */ 626 /* tile horizontally */
562 while (x > 0) x -= (int)result->width; 627 while (x > 0) x -= (int)result->width;
563 layers[1].dst_x = x; 628 layers[1].dst_x = x;
564 layers[1].clip_width = result->width+target_width; 629 layers[1].clip_width = result->width+target_width;
568 /* clip horizontally */ 633 /* clip horizontally */
569 layers[1].dst_x = x; 634 layers[1].dst_x = x;
570 layers[1].clip_width = result->width; 635 layers[1].clip_width = result->width;
571 } 636 }
572 637
573 if (h <= 0) 638 if (h_scale == 0 || v_scale == 0)
574 { 639 {
575 while (y > 0) y -= (int)result->height; 640 while (y > 0) y -= (int)result->height;
576 layers[1].dst_y = y; 641 layers[1].dst_y = y;
577 layers[1].clip_height = result->height + target_height; 642 layers[1].clip_height = result->height + target_height;
578 } 643 }
603 free (layers); 668 free (layers);
604 } 669 }
605 } 670 }
606 TIMING_TEST_PRINT_RESULT (asim); 671 TIMING_TEST_PRINT_RESULT (asim);
607 672
608 if (pixmap) 673 bool ret = false;
609 {
610 if (result == NULL
611 || pmap_width != new_pmap_width
612 || pmap_height != new_pmap_height
613 || pmap_depth != target->depth)
614 {
615 XFreePixmap (target->dpy, pixmap);
616 pixmap = None;
617 }
618 }
619 674
620 if (result) 675 if (result)
621 { 676 {
622 XGCValues gcv; 677 XGCValues gcv;
623 GC gc; 678 GC gc;
679
680 if (pixmap)
681 {
682 if (pmap_width != new_pmap_width
683 || pmap_height != new_pmap_height
684 || pmap_depth != target->depth)
685 {
686 XFreePixmap (target->dpy, pixmap);
687 pixmap = None;
688 }
689 }
624 690
625 /* create Pixmap */ 691 /* create Pixmap */
626 if (pixmap == None) 692 if (pixmap == None)
627 { 693 {
628 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 694 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
629 pmap_width = new_pmap_width; 695 pmap_width = new_pmap_width;
630 pmap_height = new_pmap_height; 696 pmap_height = new_pmap_height;
631 pmap_depth = target->depth; 697 pmap_depth = target->depth;
632 } 698 }
633 /* fill with background color ( if result's not completely overlapping it)*/ 699 /* fill with background color (if result's not completely overlapping it) */
634 gcv.foreground = target->pix_colors[Color_bg]; 700 gcv.foreground = target->pix_colors[Color_bg];
635 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); 701 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
636 702
637 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; 703 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0;
638 int dst_width = result->width, dst_height = result->height; 704 int dst_width = result->width, dst_height = result->height;
639 if (background == NULL) 705 if (background == NULL)
640 { 706 {
707 if (!(h_scale == 0 || v_scale == 0))
708 {
641 if (h_scale > 0) src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width ); 709 src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width );
642 if (v_scale > 0) src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); 710 src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height);
711 }
643 712
644 if (dst_x > 0 || dst_y > 0 713 if (dst_x > 0 || dst_y > 0
645 || dst_x + dst_width < new_pmap_width 714 || dst_x + dst_width < new_pmap_width
646 || dst_y + dst_height < new_pmap_height) 715 || dst_y + dst_height < new_pmap_height)
647 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 716 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
654 if (result != background && result != original_asim) 723 if (result != background && result != original_asim)
655 destroy_asimage (&result); 724 destroy_asimage (&result);
656 725
657 XFreeGC (target->dpy, gc); 726 XFreeGC (target->dpy, gc);
658 TIMING_TEST_PRINT_RESULT (asim); 727 TIMING_TEST_PRINT_RESULT (asim);
659 }
660 728
729 ret = true;
730 }
731
732 if (background)
733 destroy_asimage (&background);
734
661 return true; 735 return ret;
662} 736}
663# endif /* HAVE_AFTERIMAGE */ 737# endif /* HAVE_AFTERIMAGE */
738
739# ifdef HAVE_PIXBUF
740bool
741bgPixmap_t::render_image (unsigned long background_flags)
742{
743 if (target == NULL)
744 return false;
745
746 if (!pixbuf)
747 return false;
748
749#if !XFT
750 if (background_flags)
751 return false;
752#endif
753
754 GdkPixbuf *result;
755
756 int image_width = gdk_pixbuf_get_width (pixbuf);
757 int image_height = gdk_pixbuf_get_height (pixbuf);
758
759 int target_width = target->szHint.width;
760 int target_height = target->szHint.height;
761 int new_pmap_width = target_width;
762 int new_pmap_height = target_height;
763
764 int x = 0;
765 int y = 0;
766 int w = 0;
767 int h = 0;
768
769 get_image_geometry (image_width, image_height, w, h, x, y);
770
771 if (!(flags & rootAlign)
772 && (x >= target_width
773 || y >= target_height
774 || (x + w <= 0)
775 || (y + h <= 0)))
776 return false;
777
778 result = pixbuf;
779
780 if ((w != image_width)
781 || (h != image_height))
782 {
783 result = gdk_pixbuf_scale_simple (pixbuf,
784 w, h,
785 GDK_INTERP_BILINEAR);
786 }
787
788 bool ret = false;
789
790 if (result)
791 {
792 XGCValues gcv;
793 GC gc;
794 Pixmap root_pmap;
795
796 image_width = gdk_pixbuf_get_width (result);
797 image_height = gdk_pixbuf_get_height (result);
798
799 if (background_flags)
800 {
801 root_pmap = pixmap;
802 pixmap = None;
803 }
804 else
805 {
806 if (h_scale == 0 || v_scale == 0)
807 {
808 new_pmap_width = min (image_width, target_width);
809 new_pmap_height = min (image_height, target_height);
810 }
811 }
812
813 if (pixmap)
814 {
815 if (pmap_width != new_pmap_width
816 || pmap_height != new_pmap_height
817 || pmap_depth != target->depth)
818 {
819 XFreePixmap (target->dpy, pixmap);
820 pixmap = None;
821 }
822 }
823
824 if (pixmap == None)
825 {
826 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
827 pmap_width = new_pmap_width;
828 pmap_height = new_pmap_height;
829 pmap_depth = target->depth;
830 }
831
832 gcv.foreground = target->pix_colors[Color_bg];
833 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
834
835 if (h_scale == 0 || v_scale == 0)
836 {
837 Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth);
838 gdk_pixbuf_xlib_render_to_drawable (result, tile, gc,
839 0, 0,
840 0, 0,
841 image_width, image_height,
842 XLIB_RGB_DITHER_NONE,
843 0, 0);
844
845 gcv.tile = tile;
846 gcv.fill_style = FillTiled;
847 gcv.ts_x_origin = x;
848 gcv.ts_y_origin = y;
849 XChangeGC (target->dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
850
851 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
852 XFreePixmap (target->dpy, tile);
853 }
854 else
855 {
856 int src_x, src_y, dst_x, dst_y;
857 int dst_width, dst_height;
858
859 src_x = make_clip_rectangle (x, image_width , new_pmap_width , dst_x, dst_width );
860 src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height);
861
862 if (dst_x > 0 || dst_y > 0
863 || dst_x + dst_width < new_pmap_width
864 || dst_y + dst_height < new_pmap_height)
865 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
866
867 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
868 gdk_pixbuf_xlib_render_to_drawable (result, pixmap, gc,
869 src_x, src_y,
870 dst_x, dst_y,
871 dst_width, dst_height,
872 XLIB_RGB_DITHER_NONE,
873 0, 0);
874 }
875
876#if XFT
877 if (background_flags)
878 {
879 Display *dpy = target->dpy;
880 XRenderPictureAttributes pa;
881
882 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, target->display->screen));
883 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa);
884
885 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual);
886 Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa);
887
888 pa.repeat = True;
889 Pixmap mask_pmap = XCreatePixmap (dpy, target->vt, 1, 1, 8);
890 XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8);
891 Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa);
892 XFreePixmap (dpy, mask_pmap);
893
894 if (src && dst && mask)
895 {
896 XRenderColor mask_c;
897
898 mask_c.alpha = 0x8000;
899 mask_c.red = 0;
900 mask_c.green = 0;
901 mask_c.blue = 0;
902 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1);
903 XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height);
904 }
905
906 XRenderFreePicture (dpy, src);
907 XRenderFreePicture (dpy, dst);
908 XRenderFreePicture (dpy, mask);
909
910 XFreePixmap (dpy, root_pmap);
911 }
912#endif
913
914 if (result != pixbuf)
915 g_object_unref (result);
916
917 XFreeGC (target->dpy, gc);
918
919 ret = true;
920 }
921
922 return ret;
923}
924# endif /* HAVE_PIXBUF */
664 925
665bool 926bool
666bgPixmap_t::set_file (const char *file) 927bgPixmap_t::set_file (const char *file)
667{ 928{
668 char *f;
669
670 assert (file); 929 assert (file);
671 930
672 if (*file) 931 if (*file)
673 { 932 {
674# ifdef HAVE_AFTERIMAGE 933 if (const char *p = strchr (file, ';'))
675 if (target->asimman == NULL)
676 target->asimman = create_generic_imageman (target->rs[Rs_path]);
677
678 if ((f = strchr (file, ';')) == NULL)
679 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
680 else
681 { 934 {
682 size_t len = f - file; 935 size_t len = p - file;
683 f = (char *)malloc (len + 1); 936 char *f = rxvt_temp_buf<char> (len + 1);
684 memcpy (f, file, len); 937 memcpy (f, file, len);
685 f[len] = '\0'; 938 f[len] = '\0';
939 file = f;
940 }
941
942# ifdef HAVE_AFTERIMAGE
943 if (!target->asimman)
944 target->asimman = create_generic_imageman (target->rs[Rs_path]);
686 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100); 945 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
687 free (f); 946 if (original_asim)
688 } 947 have_image = true;
948 return have_image;
949# endif
689 950
690 return original_asim; 951# ifdef HAVE_PIXBUF
952 pixbuf = gdk_pixbuf_new_from_file (file, NULL);
953 if (pixbuf)
954 have_image = true;
955 return have_image;
691# endif 956# endif
692 } 957 }
693 958
694 return false; 959 return false;
695} 960}
715 int changed = 0; 980 int changed = 0;
716 unsigned int hr, vr; 981 unsigned int hr, vr;
717 int junk; 982 int junk;
718 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); 983 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
719 984
720 if (!(geom_flags&WidthValue)) 985 if (!(geom_flags & WidthValue))
721 hr = 1; 986 hr = 1;
722 if (!(geom_flags&HeightValue)) 987 if (!(geom_flags & HeightValue))
723 vr = hr; 988 vr = hr;
724 989
725 if (h_blurRadius != hr) 990 if (h_blurRadius != hr)
726 { 991 {
727 ++changed; 992 ++changed;
737 if (v_blurRadius == 0 && h_blurRadius == 0) 1002 if (v_blurRadius == 0 && h_blurRadius == 0)
738 flags &= ~blurNeeded; 1003 flags &= ~blurNeeded;
739 else 1004 else
740 flags |= blurNeeded; 1005 flags |= blurNeeded;
741 1006
742 return (changed>0); 1007 return (changed > 0);
743} 1008}
744 1009
745static inline unsigned long 1010static inline unsigned long
746compute_tint_shade_flags (rxvt_color *tint, int shade) 1011compute_tint_shade_flags (rxvt_color *tint, int shade)
747{ 1012{
748 unsigned long flags = 0; 1013 unsigned long flags = 0;
749 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1014 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
750 bool has_shade = (shade > 0 && shade < 100) || (shade > 100 && shade < 200); 1015 bool has_shade = shade != 100;
751 1016
752 if (tint) 1017 if (tint)
753 { 1018 {
754 tint->get (c); 1019 tint->get (c);
755# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700) 1020# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700)
764 flags |= bgPixmap_t::tintNeeded; 1029 flags |= bgPixmap_t::tintNeeded;
765 else if (tint) 1030 else if (tint)
766 { 1031 {
767 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) 1032 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700)
768 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) 1033 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700))
769 { 1034 {
770 flags |= bgPixmap_t::tintNeeded; 1035 flags |= bgPixmap_t::tintNeeded;
771 } 1036 }
772 } 1037 }
773 1038
774 if (flags & bgPixmap_t::tintNeeded) 1039 if (flags & bgPixmap_t::tintNeeded)
775 { 1040 {
776 if (flags & bgPixmap_t::tintWholesome) 1041 if (flags & bgPixmap_t::tintWholesome)
787} 1052}
788 1053
789bool 1054bool
790bgPixmap_t::set_tint (rxvt_color &new_tint) 1055bgPixmap_t::set_tint (rxvt_color &new_tint)
791{ 1056{
792 if (tint != new_tint) 1057 if (!(flags & tintSet) || tint != new_tint)
793 { 1058 {
794 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); 1059 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade);
795 tint = new_tint; 1060 tint = new_tint;
796 flags = (flags & ~tintFlags) | new_flags | tintSet; 1061 flags = (flags & ~tintFlags) | new_flags | tintSet;
797 return true; 1062 return true;
805{ 1070{
806 unsigned long new_flags = compute_tint_shade_flags (NULL, shade); 1071 unsigned long new_flags = compute_tint_shade_flags (NULL, shade);
807 1072
808 if (new_flags != (flags & tintFlags)) 1073 if (new_flags != (flags & tintFlags))
809 { 1074 {
810 flags = (flags&~tintFlags)|new_flags; 1075 flags = (flags & ~tintFlags) | new_flags;
811 return true; 1076 return true;
812 } 1077 }
813 1078
814 return false; 1079 return false;
815} 1080}
816 1081
817bool 1082bool
818bgPixmap_t::set_shade (const char *shade_str) 1083bgPixmap_t::set_shade (const char *shade_str)
819{ 1084{
820 int new_shade = (shade_str) ? atoi (shade_str) : 0; 1085 int new_shade = (shade_str) ? atoi (shade_str) : 100;
821 1086
822 if (new_shade < 0 && new_shade > -100) 1087 clamp_it (new_shade, -100, 200);
1088 if (new_shade < 0)
823 new_shade = 200 - (100 + new_shade); 1089 new_shade = 200 - (100 + new_shade);
824 else if (new_shade == 100)
825 new_shade = 0;
826 1090
827 if (new_shade != shade) 1091 if (new_shade != shade)
828 { 1092 {
829 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); 1093 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade);
830 shade = new_shade; 1094 shade = new_shade;
831 flags = (flags & (~tintFlags | tintSet)) | new_flags; 1095 flags = (flags & (~tintFlags | tintSet)) | new_flags;
832 return true; 1096 return true;
833 } 1097 }
834 1098
835 return false; 1099 return false;
1100}
1101
1102bool
1103bgPixmap_t::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height)
1104{
1105 Display *dpy = target->dpy;
1106 bool ret = false;
1107
1108 if (flags & tintWholesome)
1109 {
1110 XGCValues gcv;
1111 GC gc;
1112
1113 /* In this case we can tint image server-side getting significant
1114 * performance improvements, as we eliminate XImage transfer
1115 */
1116 gcv.foreground = Pixel (tint);
1117 gcv.function = GXand;
1118 gcv.fill_style = FillSolid;
1119 gc = XCreateGC (dpy, pixmap, GCFillStyle | GCForeground | GCFunction, &gcv);
1120 if (gc)
1121 {
1122 XFillRectangle (dpy, pixmap, gc, 0, 0, width, height);
1123 ret = true;
1124 XFreeGC (dpy, gc);
1125 }
1126 }
1127 else
1128 {
1129# if XFT
1130 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1131
1132 if (flags & tintSet)
1133 tint.get (c);
1134
1135 if (shade <= 100)
1136 {
1137 c.r = (c.r * shade) / 100;
1138 c.g = (c.g * shade) / 100;
1139 c.b = (c.b * shade) / 100;
1140 }
1141 else
1142 {
1143 c.r = ((0xffff - c.r) * (200 - shade)) / 100;
1144 c.g = ((0xffff - c.g) * (200 - shade)) / 100;
1145 c.b = ((0xffff - c.b) * (200 - shade)) / 100;
1146 }
1147
1148 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
1149 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1150 XRenderPictureAttributes pa;
1151
1152 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1153
1154 pa.repeat = True;
1155
1156 Pixmap overlay_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32);
1157 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
1158 XFreePixmap (dpy, overlay_pmap);
1159
1160 pa.component_alpha = True;
1161 Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32);
1162 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa);
1163 XFreePixmap (dpy, mask_pmap);
1164
1165 if (mask_pic && overlay_pic && back_pic)
1166 {
1167 XRenderColor mask_c;
1168
1169 memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c));
1170 mask_c.alpha = 0xffff;
1171 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1172
1173 mask_c.alpha = 0;
1174 mask_c.red = 0xffff - c.r;
1175 mask_c.green = 0xffff - c.g;
1176 mask_c.blue = 0xffff - c.b;
1177 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1178 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1179 ret = true;
1180 }
1181
1182 XRenderFreePicture (dpy, mask_pic);
1183 XRenderFreePicture (dpy, overlay_pic);
1184 XRenderFreePicture (dpy, back_pic);
1185# if DO_TIMING_TEST
1186 XSync (dpy, False);
1187# endif
1188# endif
1189 }
1190
1191 return ret;
836} 1192}
837 1193
838/* make_transparency_pixmap() 1194/* make_transparency_pixmap()
839 * Builds a pixmap sized the same as terminal window, with depth same as the root window 1195 * Builds a pixmap sized the same as terminal window, with depth same as the root window
840 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by 1196 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by
846 unsigned long result = 0; 1202 unsigned long result = 0;
847 1203
848 if (target == NULL) 1204 if (target == NULL)
849 return 0; 1205 return 0;
850 1206
851 /* root dimentions may change from call to call - but Display structure should 1207 /* root dimensions may change from call to call - but Display structure should
852 * be always up-to-date, so let's use it : 1208 * be always up-to-date, so let's use it :
853 */ 1209 */
854 Window root = target->display->root; 1210 Window root = target->display->root;
855 int screen = target->display->screen; 1211 int screen = target->display->screen;
856 Display *dpy = target->dpy; 1212 Display *dpy = target->dpy;
870 || sx >= root_width || sy >= root_height) 1226 || sx >= root_width || sy >= root_height)
871 return 0; 1227 return 0;
872 1228
873 if (root_pixmap != None) 1229 if (root_pixmap != None)
874 { 1230 {
875 /* we want to validate the pixmap and get it's size at the same time : */ 1231 /* we want to validate the pixmap and get its size at the same time : */
876 int junk; 1232 int junk;
877 unsigned int ujunk; 1233 unsigned int ujunk;
878 /* root pixmap may be bad - allow a error */ 1234 /* root pixmap may be bad - allow a error */
879 target->allowedxerror = -1; 1235 target->allowedxerror = -1;
880 1236
901 1257
902 attr.background_pixmap = ParentRelative; 1258 attr.background_pixmap = ParentRelative;
903 attr.backing_store = Always; 1259 attr.backing_store = Always;
904 attr.event_mask = ExposureMask; 1260 attr.event_mask = ExposureMask;
905 attr.override_redirect = True; 1261 attr.override_redirect = True;
906 src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0, 1262 src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0,
907 CopyFromParent, CopyFromParent, CopyFromParent, 1263 CopyFromParent, CopyFromParent, CopyFromParent,
908 CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask, 1264 CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask,
909 &attr); 1265 &attr);
910 1266
911 if (src != None) 1267 if (src != None)
935 XDestroyWindow (dpy, src); 1291 XDestroyWindow (dpy, src);
936 XUngrabServer (dpy); 1292 XUngrabServer (dpy);
937 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); 1293 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count);
938 } 1294 }
939 1295
940 if (!success) 1296 if (!success)
941 { 1297 {
942 XFreePixmap (dpy, tiled_root_pmap); 1298 XFreePixmap (dpy, tiled_root_pmap);
943 tiled_root_pmap = None; 1299 tiled_root_pmap = None;
944 } 1300 }
945 else 1301 else
946 result |= transpPmapTiled; 1302 result |= transpPmapTiled;
947 } 1303 }
948 else 1304 else
949 { 1305 {
950 /* strightforward pixmap copy */ 1306 /* straightforward pixmap copy */
951 gcv.tile = root_pixmap; 1307 gcv.tile = root_pixmap;
952 gcv.fill_style = FillTiled; 1308 gcv.fill_style = FillTiled;
953 1309
954 while (sx < 0) sx += (int)root_width; 1310 while (sx < 0) sx += (int)root_width;
955 while (sy < 0) sy += (int)root_height; 1311 while (sy < 0) sy += (int)root_height;
970 { 1326 {
971 if (!need_client_side_rendering ()) 1327 if (!need_client_side_rendering ())
972 { 1328 {
973 if ((flags & tintNeeded)) 1329 if ((flags & tintNeeded))
974 { 1330 {
975 if (flags & tintWholesome) 1331 if (tint_pixmap (tiled_root_pmap, DefaultVisual (dpy, target->display->screen), window_width, window_height))
976 {
977 /* In this case we can tint image server-side getting significant
978 * performance improvements, as we eliminate XImage transfer
979 */
980 gcv.foreground = Pixel (tint);
981 gcv.function = GXand;
982 gcv.fill_style = FillSolid;
983 if (gc)
984 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcv);
985 else
986 gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv);
987 if (gc)
988 {
989 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
990 result |= transpPmapTinted; 1332 result |= transpPmapTinted;
991 }
992 }
993 else
994 {
995# if XFT
996 Picture back_pic = 0;
997 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
998
999 if (flags & tintSet)
1000 tint.get (c);
1001
1002 if (shade > 0 && shade < 100)
1003 {
1004 c.r = (c.r * shade) / 100;
1005 c.g = (c.g * shade) / 100;
1006 c.b = (c.b * shade) / 100;
1007 }
1008 else if (shade > 100 && shade < 200)
1009 {
1010 c.r = (c.r * (200 - shade)) / 100;
1011 c.g = (c.g * (200 - shade)) / 100;
1012 c.b = (c.b * (200 - shade)) / 100;
1013 }
1014
1015 XRenderPictFormat pf;
1016 pf.type = PictTypeDirect;
1017 pf.depth = 32;
1018 pf.direct.redMask = 0xff;
1019 pf.direct.greenMask = 0xff;
1020 pf.direct.blueMask = 0xff;
1021 pf.direct.alphaMask = 0xff;
1022
1023 XRenderPictFormat *solid_format = XRenderFindFormat (dpy,
1024 (PictFormatType|
1025 PictFormatDepth|
1026 PictFormatRedMask|
1027 PictFormatGreenMask|
1028 PictFormatBlueMask|
1029 PictFormatAlphaMask),
1030 &pf,
1031 0);
1032 XRenderPictFormat *root_format = XRenderFindVisualFormat (dpy, DefaultVisualOfScreen (ScreenOfDisplay (dpy, target->display->screen)));
1033 XRenderPictureAttributes pa ;
1034
1035 back_pic = XRenderCreatePicture (dpy, tiled_root_pmap, root_format, 0, &pa);
1036
1037 pa.repeat = True;
1038
1039 Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32);
1040 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
1041 XFreePixmap (dpy, overlay_pmap);
1042
1043 pa.component_alpha = True;
1044 Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32);
1045 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa);
1046 XFreePixmap (dpy, mask_pmap);
1047
1048 if (mask_pic && overlay_pic && back_pic)
1049 {
1050 XRenderColor mask_c;
1051
1052 memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c));
1053 mask_c.alpha = 0xffff;
1054 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1055
1056 mask_c.alpha = 0;
1057 mask_c.red = 0xffff - c.r;
1058 mask_c.green = 0xffff - c.g;
1059 mask_c.blue = 0xffff - c.b;
1060 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1061 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height);
1062 result |= transpPmapTinted;
1063 }
1064
1065 XRenderFreePicture (dpy, mask_pic);
1066 XRenderFreePicture (dpy, overlay_pic);
1067 XRenderFreePicture (dpy, back_pic);
1068# if DO_TIMING_TEST
1069 XSync (dpy, False);
1070# endif
1071# endif
1072 }
1073 } 1333 }
1074 } /* server side rendering completed */ 1334 } /* server side rendering completed */
1075 1335
1076 if (pixmap) 1336 if (pixmap)
1077 XFreePixmap (dpy, pixmap); 1337 XFreePixmap (dpy, pixmap);
1078 1338
1106 return false; 1366 return false;
1107} 1367}
1108# endif /* ENABLE_TRANSPARENCY */ 1368# endif /* ENABLE_TRANSPARENCY */
1109 1369
1110# ifndef HAVE_AFTERIMAGE 1370# ifndef HAVE_AFTERIMAGE
1111static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm); 1371static void ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm);
1112# endif 1372# endif
1113 1373
1114bool 1374bool
1115bgPixmap_t::render () 1375bgPixmap_t::render ()
1116{ 1376{
1119 if (target == NULL) 1379 if (target == NULL)
1120 return false; 1380 return false;
1121 1381
1122 TIMING_TEST_START (tp); 1382 TIMING_TEST_START (tp);
1123 1383
1124 invalidate(); 1384 invalidate ();
1125# ifdef ENABLE_TRANSPARENCY 1385# ifdef ENABLE_TRANSPARENCY
1126 if (flags & isTransparent) 1386 if (flags & isTransparent)
1127 { 1387 {
1128 /* we need to re-generate transparency pixmap in that case ! */ 1388 /* we need to re-generate transparency pixmap in that case ! */
1129 background_flags = make_transparency_pixmap (); 1389 background_flags = make_transparency_pixmap ();
1130 if (background_flags == 0) 1390 if (background_flags == 0)
1131 return false; 1391 return false;
1132 else if ((background_flags & transpTransformations) == (flags & transpTransformations) 1392 else if ((background_flags & transpTransformations) == (flags & transpTransformations)
1133 && pmap_depth == target->depth) 1393 && pmap_depth == target->depth)
1134 flags = flags & ~isInvalid; 1394 flags = flags & ~isInvalid;
1135 } 1395 }
1136# endif 1396# endif
1137 1397
1398# ifdef BG_IMAGE_FROM_FILE
1399 if (have_image
1400 || (background_flags & transpTransformations) != (flags & transpTransformations))
1401 {
1402 if (render_image (background_flags))
1403 flags = flags & ~isInvalid;
1404 }
1405# endif
1406
1138 XImage *result = NULL; 1407 XImage *result = NULL;
1139# ifdef HAVE_AFTERIMAGE 1408
1140 if (original_asim 1409 if (background_flags && (flags & isInvalid))
1141 || (background_flags & transpTransformations) != (flags & transpTransformations)) 1410 {
1411 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1142 { 1412 }
1143 ASImage *background = NULL;
1144 ARGB32 as_tint = TINT_LEAVE_SAME;
1145 if (background_flags)
1146 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100);
1147 1413
1148# ifdef ENABLE_TRANSPARENCY 1414 if (result)
1415 {
1416# if !defined(HAVE_AFTERIMAGE) && !XFT
1417 /* our own client-side tinting */
1418 /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side.
1419 This may need to be changed in need_client_side_rendering() logic is altered !!! */
1149 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1420 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
1150 {
1151 ShadingInfo as_shade;
1152 as_shade.shading = (shade == 0) ? 100 : shade;
1153
1154 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1155 if (flags & tintSet)
1156 tint.get (c);
1157 as_shade.tintColor.red = c.r;
1158 as_shade.tintColor.green = c.g;
1159 as_shade.tintColor.blue = c.b;
1160
1161 as_tint = shading2tint32 (&as_shade);
1162 }
1163 if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL)
1164 {
1165 ASImage* tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
1166 (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage,
1167 100, ASIMAGE_QUALITY_DEFAULT);
1168 if (tmp)
1169 {
1170 destroy_asimage (&background);
1171 background = tmp;
1172 }
1173 }
1174# endif
1175
1176 if (render_asim (background, as_tint))
1177 flags = flags & ~isInvalid;
1178 if (background)
1179 destroy_asimage (&background);
1180 }
1181 else if (background_flags && pmap_depth != target->depth)
1182 {
1183 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1184 }
1185
1186# elif !XFT /* our own client-side tinting */
1187
1188 /* ATTENTION: We ASSUME that XFT will let us do all the tinting neccessary server-side.
1189 This may need to be changed in need_client_side_rendering() logic is altered !!! */
1190
1191 if (background_flags && (flags & isInvalid))
1192 {
1193 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1194 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded))
1195 { 1421 {
1196 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1422 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1197 if (flags & tintSet) 1423 if (flags & tintSet)
1198 tint.get (c); 1424 tint.get (c);
1199 ShadeXImage (target, result, shade, c.r, c.g, c.b); 1425 ShadeXImage (target, result, shade, c.r, c.g, c.b);
1200 } 1426 }
1201 } 1427# endif
1202# endif /* HAVE_AFTERIMAGE */
1203 1428
1204 if (result)
1205 {
1206 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1429 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1207 1430
1208 if (gc) 1431 if (gc)
1209 { 1432 {
1210 if (/*pmap_depth != target->depth &&*/ pixmap != None) 1433 if (/*pmap_depth != target->depth &&*/ pixmap != None)
1239 1462
1240 XFreeGC (target->dpy, gc); 1463 XFreeGC (target->dpy, gc);
1241 flags = flags & ~isInvalid; 1464 flags = flags & ~isInvalid;
1242 } 1465 }
1243 1466
1244 XDestroyImage (result); 1467 XDestroyImage (result);
1245 } 1468 }
1246 1469
1247 if (flags & isInvalid) 1470 if (flags & isInvalid)
1248 { 1471 {
1249 if (pixmap != None) 1472 if (pixmap != None)
1273# ifdef ENABLE_TRANSPARENCY 1496# ifdef ENABLE_TRANSPARENCY
1274 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); 1497 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen));
1275# endif 1498# endif
1276 return true; 1499 return true;
1277 } 1500 }
1501
1278 return false; 1502 return false;
1279} 1503}
1280 1504
1281void 1505void
1282bgPixmap_t::apply () 1506bgPixmap_t::apply ()
1283{ 1507{
1284 if (target) 1508 if (target)
1285 { 1509 {
1286 flags &= ~isVtOrigin; 1510 flags &= ~isVtOrigin;
1511
1287 if (pixmap != None) 1512 if (pixmap != None)
1288 { 1513 {
1289 /* set target's background to pixmap */ 1514 /* set target's background to pixmap */
1290# ifdef ENABLE_TRANSPARENCY 1515# ifdef ENABLE_TRANSPARENCY
1291 if (flags & isTransparent) 1516 if (flags & isTransparent)
1292 { 1517 {
1293 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); 1518 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
1294 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); 1519 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1520
1295 if (target->scrollBar.win) 1521 if (target->scrollBar.win)
1296 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); 1522 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
1297 } 1523 }
1298 else 1524 else
1299# endif 1525# endif
1301 flags |= isVtOrigin; 1527 flags |= isVtOrigin;
1302 /* force old pixmap dereference in case it was transparent before :*/ 1528 /* force old pixmap dereference in case it was transparent before :*/
1303 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1529 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1304 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); 1530 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1305 /* do we also need to set scrollbar's background here ? */ 1531 /* do we also need to set scrollbar's background here ? */
1532
1306 if (target->scrollBar.win) 1533 if (target->scrollBar.win)
1307 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1534 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1308 } 1535 }
1309 } 1536 }
1310 else 1537 else
1311 { 1538 {
1312 /* set target background to a pixel */ 1539 /* set target background to a pixel */
1313 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1540 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1314 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); 1541 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
1315 /* do we also need to set scrollbar's background here ? */ 1542 /* do we also need to set scrollbar's background here ? */
1316 if (target->scrollBar.win) 1543 if (target->scrollBar.win)
1317 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1544 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1318 } 1545 }
1546
1319 /* don't want Expose on the parent or vt. It is better to use 1547 /* don't want Expose on the parent or vt. It is better to use
1320 scr_touch or we get a great deal of flicker otherwise: */ 1548 scr_touch or we get a great deal of flicker otherwise: */
1321 XClearWindow (target->dpy, target->parent[0]); 1549 XClearWindow (target->dpy, target->parent[0]);
1322 1550
1323 if (target->scrollBar.win) 1551 if (target->scrollBar.state && target->scrollBar.win)
1324 { 1552 {
1325 target->scrollBar.setIdle (); 1553 target->scrollBar.state = STATE_IDLE;
1326 target->scrollbar_show (0); 1554 target->scrollBar.show (0);
1327 } 1555 }
1328 1556
1329 target->want_refresh = 1; 1557 target->want_refresh = 1;
1330 flags |= hasChanged; 1558 flags |= hasChanged;
1331 } 1559 }
1337/* taken from aterm-0.4.2 */ 1565/* taken from aterm-0.4.2 */
1338 1566
1339typedef uint32_t RUINT32T; 1567typedef uint32_t RUINT32T;
1340 1568
1341static void 1569static void
1342ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm) 1570ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm)
1343{ 1571{
1344 int sh_r, sh_g, sh_b; 1572 int sh_r, sh_g, sh_b;
1345 RUINT32T mask_r, mask_g, mask_b; 1573 RUINT32T mask_r, mask_g, mask_b;
1346 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; 1574 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
1347 unsigned int lower_lim_r, lower_lim_g, lower_lim_b; 1575 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
1349 int i; 1577 int i;
1350 1578
1351 Visual *visual = term->visual; 1579 Visual *visual = term->visual;
1352 1580
1353 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ; 1581 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ;
1354
1355 if (shade == 0)
1356 shade = 100;
1357 1582
1358 /* for convenience */ 1583 /* for convenience */
1359 mask_r = visual->red_mask; 1584 mask_r = visual->red_mask;
1360 mask_g = visual->green_mask; 1585 mask_g = visual->green_mask;
1361 mask_b = visual->blue_mask; 1586 mask_b = visual->blue_mask;
1417 default: 1642 default:
1418 return; /* we do not support this color depth */ 1643 return; /* we do not support this color depth */
1419 } 1644 }
1420 1645
1421 /* prepare limits for color transformation (each channel is handled separately) */ 1646 /* prepare limits for color transformation (each channel is handled separately) */
1422 if (shade < 0) { 1647 if (shade > 100) {
1423 shade = -shade; 1648 shade = 200 - shade;
1424 if (shade < 0) shade = 0;
1425 if (shade > 100) shade = 100;
1426 1649
1427 lower_lim_r = 65535-rm; 1650 lower_lim_r = 65535-rm;
1428 lower_lim_g = 65535-gm; 1651 lower_lim_g = 65535-gm;
1429 lower_lim_b = 65535-bm; 1652 lower_lim_b = 65535-bm;
1430 1653
1432 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100); 1655 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100);
1433 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100); 1656 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100);
1434 1657
1435 upper_lim_r = upper_lim_g = upper_lim_b = 65535; 1658 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
1436 } else { 1659 } else {
1437 if (shade < 0) shade = 0;
1438 if (shade > 100) shade = 100;
1439 1660
1440 lower_lim_r = lower_lim_g = lower_lim_b = 0; 1661 lower_lim_r = lower_lim_g = lower_lim_b = 0;
1441 1662
1442 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100); 1663 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100);
1443 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100); 1664 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines