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.145 by sf-exg, Fri Jan 28 00:21:10 2011 UTC vs.
Revision 1.160 by sf-exg, Thu Aug 11 08:37:17 2011 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-2008 Marc Lehmann <pcg@goof.com> 6 * Copyright (c) 2005-2008 Marc Lehmann <schmorp@schmorp.de>
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 * Copyright (c) 2010 Emanuele Giaquinta <e.giaquinta@glauco.it>
9 * 9 *
10 * 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
11 * 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
46 * W and H are percentages of the terminal window size. 46 * W and H are percentages of the terminal window size.
47 * X and Y are also percentages; e.g., +50+50 centers 47 * X and Y are also percentages; e.g., +50+50 centers
48 * the image in the window. 48 * the image in the window.
49 * 49 *
50 * Pixmap Operations : (should be prepended by a colon) 50 * Pixmap Operations : (should be prepended by a colon)
51 * tile Tile image. Scaling/position modifiers above will affect
52 * the tile size and origin.
53 * propscale When scaling, scale proportionally. That is, maintain the
54 * proper aspect ratio for the image. Any portion of the
55 * background not covered by the image is filled with the
56 * current background color.
57 * hscale Scale horizontally, tile vertically ?
58 * vscale Tile horizontally, scale vertically ?
59 * scale Scale both up and down
60 * auto Same as 100x100+50+50
61 */ 51 */
62 52
63#ifdef HAVE_BG_PIXMAP 53#ifdef HAVE_BG_PIXMAP
64void 54void
65rxvt_term::bg_destroy () 55rxvt_term::bg_destroy ()
258 { 248 {
259 char **arr = rxvt_strsplit (':', ops + 1); 249 char **arr = rxvt_strsplit (':', ops + 1);
260 250
261 for (int i = 0; arr[i]; i++) 251 for (int i = 0; arr[i]; i++)
262 { 252 {
253 if (!strcasecmp (arr[i], "style=tiled"))
254 {
255 new_flags = BG_TILE;
256 w = h = noScale;
257 x = y = 0;
258 geom_flags = WidthValue|HeightValue|XValue|YValue;
259 }
260 else if (!strcasecmp (arr[i], "style=aspect-stretched"))
261 {
262 new_flags = BG_PROP_SCALE;
263 x = y = centerAlign;
264 geom_flags = XValue|YValue;
265 }
266 else if (!strcasecmp (arr[i], "style=stretched"))
267 {
268 new_flags = 0;
269 w = h = windowScale;
270 geom_flags = WidthValue|HeightValue;
271 }
272 else if (!strcasecmp (arr[i], "style=centered"))
273 {
274 new_flags = 0;
275 w = h = noScale;
276 x = y = centerAlign;
277 geom_flags = WidthValue|HeightValue|XValue|YValue;
278 }
279 else if (!strcasecmp (arr[i], "style=root-tiled"))
280 {
281 new_flags = BG_TILE|BG_ROOT_ALIGN;
282 w = h = noScale;
283 geom_flags = WidthValue|HeightValue;
284 }
285 else if (!strcasecmp (arr[i], "op=tile"))
286 new_flags |= BG_TILE;
287 else if (!strcasecmp (arr[i], "op=pscale"))
288 new_flags |= BG_PROP_SCALE;
289 else if (!strcasecmp (arr[i], "op=root"))
290 new_flags |= BG_ROOT_ALIGN;
291
292 // deprecated
263 if (!strcasecmp (arr[i], "tile")) 293 else if (!strcasecmp (arr[i], "tile"))
264 { 294 {
295 new_flags |= BG_TILE;
265 w = h = noScale; 296 w = h = noScale;
266 geom_flags |= WidthValue|HeightValue; 297 geom_flags |= WidthValue|HeightValue;
267 } 298 }
268 else if (!strcasecmp (arr[i], "propscale")) 299 else if (!strcasecmp (arr[i], "propscale"))
269 { 300 {
270 new_flags |= BG_PROP_SCALE; 301 new_flags |= BG_PROP_SCALE;
271 } 302 }
272 else if (!strcasecmp (arr[i], "hscale"))
273 {
274 if (w == 0) w = windowScale;
275
276 h = noScale;
277 geom_flags |= WidthValue|HeightValue;
278 }
279 else if (!strcasecmp (arr[i], "vscale"))
280 {
281 if (h == 0) h = windowScale;
282
283 w = noScale;
284 geom_flags |= WidthValue|HeightValue;
285 }
286 else if (!strcasecmp (arr[i], "scale")) 303 else if (!strcasecmp (arr[i], "scale"))
287 { 304 {
288 if (h == 0) h = windowScale; 305 if (h == 0) h = windowScale;
289 if (w == 0) w = windowScale; 306 if (w == 0) w = windowScale;
290 307
291 geom_flags |= WidthValue|HeightValue; 308 geom_flags |= WidthValue|HeightValue;
292 } 309 }
293 else if (!strcasecmp (arr[i], "auto"))
294 {
295 w = h = windowScale;
296 x = y = centerAlign;
297 geom_flags |= WidthValue|HeightValue|XValue|YValue;
298 }
299 else if (!strcasecmp (arr[i], "root")) 310 else if (!strcasecmp (arr[i], "root"))
300 { 311 {
301 new_flags |= BG_ROOT_ALIGN; 312 new_flags |= BG_TILE|BG_ROOT_ALIGN;
302 w = h = noScale; 313 w = h = noScale;
303 geom_flags |= WidthValue|HeightValue; 314 geom_flags |= WidthValue|HeightValue;
304 } 315 }
305 } /* done parsing ops */ 316 } /* done parsing ops */
306 317
353 x = make_align_position (h_align, target_width, w); 364 x = make_align_position (h_align, target_width, w);
354 y = make_align_position (v_align, target_height, h); 365 y = make_align_position (v_align, target_height, h);
355 } 366 }
356 367
357 bg_flags &= ~BG_IS_SIZE_SENSITIVE; 368 bg_flags &= ~BG_IS_SIZE_SENSITIVE;
369 if (!(bg_flags & BG_TILE)
358 if ((bg_flags & BG_PROP_SCALE) || h_scale || v_scale 370 || (bg_flags & BG_PROP_SCALE) || h_scale || v_scale
359 || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align)) 371 || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align))
360 || w > target_width || h > target_height) 372 || w > target_width || h > target_height)
361 bg_flags |= BG_IS_SIZE_SENSITIVE; 373 bg_flags |= BG_IS_SIZE_SENSITIVE;
362} 374}
363 375
455 100, ASIMAGE_QUALITY_DEFAULT); 467 100, ASIMAGE_QUALITY_DEFAULT);
456 } 468 }
457 469
458 if (background == NULL) 470 if (background == NULL)
459 { 471 {
460 if (h_scale == 0 || v_scale == 0) 472 if (bg_flags & BG_TILE)
461 { 473 {
462 /* if tiling - pixmap has to be sized exactly as the image, 474 /* if tiling - pixmap has to be sized exactly as the image,
463 but there is no need to make it bigger than the window! */ 475 but there is no need to make it bigger than the window! */
464 new_pmap_width = min (result->width, target_width); 476 new_pmap_width = min (result->width, target_width);
465 new_pmap_height = min (result->height, target_height); 477 new_pmap_height = min (result->height, target_height);
490 layers[0].clip_width = target_width; 502 layers[0].clip_width = target_width;
491 layers[0].clip_height = target_height; 503 layers[0].clip_height = target_height;
492 layers[0].tint = background_tint; 504 layers[0].tint = background_tint;
493 layers[1].im = result; 505 layers[1].im = result;
494 506
495 if (h_scale == 0 || v_scale == 0) 507 if (bg_flags & BG_TILE)
496 { 508 {
497 /* tile horizontally */ 509 /* tile horizontally */
498 while (x > 0) x -= (int)result->width; 510 while (x > 0) x -= (int)result->width;
499 layers[1].dst_x = x; 511 layers[1].dst_x = x;
500 layers[1].clip_width = result->width+target_width; 512 layers[1].clip_width = result->width+target_width;
504 /* clip horizontally */ 516 /* clip horizontally */
505 layers[1].dst_x = x; 517 layers[1].dst_x = x;
506 layers[1].clip_width = result->width; 518 layers[1].clip_width = result->width;
507 } 519 }
508 520
509 if (h_scale == 0 || v_scale == 0) 521 if (bg_flags & BG_TILE)
510 { 522 {
511 while (y > 0) y -= (int)result->height; 523 while (y > 0) y -= (int)result->height;
512 layers[1].dst_y = y; 524 layers[1].dst_y = y;
513 layers[1].clip_height = result->height + target_height; 525 layers[1].clip_height = result->height + target_height;
514 } 526 }
564 576
565 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; 577 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0;
566 int dst_width = result->width, dst_height = result->height; 578 int dst_width = result->width, dst_height = result->height;
567 if (background == NULL) 579 if (background == NULL)
568 { 580 {
569 if (!(h_scale == 0 || v_scale == 0)) 581 if (!(bg_flags & BG_TILE))
570 { 582 {
571 src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width ); 583 src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width );
572 src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); 584 src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height);
573 } 585 }
574 586
620 else if (depth == 15 || depth == 16) 632 else if (depth == 15 || depth == 16)
621 bytes_per_pixel = 2; 633 bytes_per_pixel = 2;
622 else 634 else
623 return false; 635 return false;
624 636
625 width_r = rxvt_popcount (visual->red_mask); 637 width_r = ecb_popcount32 (visual->red_mask);
626 width_g = rxvt_popcount (visual->green_mask); 638 width_g = ecb_popcount32 (visual->green_mask);
627 width_b = rxvt_popcount (visual->blue_mask); 639 width_b = ecb_popcount32 (visual->blue_mask);
628 640
629 if (width_r > 8 || width_g > 8 || width_b > 8) 641 if (width_r > 8 || width_g > 8 || width_b > 8)
630 return false; 642 return false;
631 643
632 sh_r = rxvt_ctz (visual->red_mask); 644 sh_r = ecb_ctz32 (visual->red_mask);
633 sh_g = rxvt_ctz (visual->green_mask); 645 sh_g = ecb_ctz32 (visual->green_mask);
634 sh_b = rxvt_ctz (visual->blue_mask); 646 sh_b = ecb_ctz32 (visual->blue_mask);
635 647
636 if (width > INT_MAX / height / bytes_per_pixel) 648 if (width > INT_MAX / height / bytes_per_pixel)
637 return false; 649 return false;
638 650
639 data = (char *)malloc (width * height * bytes_per_pixel); 651 data = (char *)malloc (width * height * bytes_per_pixel);
646 { 658 {
647 free (data); 659 free (data);
648 return false; 660 return false;
649 } 661 }
650 662
651 ximage->byte_order = byteorder::big_endian () ? MSBFirst : LSBFirst; 663 ximage->byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
652 664
653 rowstride = gdk_pixbuf_get_rowstride (pixbuf); 665 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
654 channels = gdk_pixbuf_get_n_channels (pixbuf); 666 channels = gdk_pixbuf_get_n_channels (pixbuf);
655 row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; 667 row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels;
656 line = data; 668 line = data;
723 result = gdk_pixbuf_scale_simple (pixbuf, 735 result = gdk_pixbuf_scale_simple (pixbuf,
724 w, h, 736 w, h,
725 GDK_INTERP_BILINEAR); 737 GDK_INTERP_BILINEAR);
726 } 738 }
727 739
740 if (!result)
741 return false;
742
728 bool ret = false; 743 bool ret = false;
729 744
730 if (result)
731 {
732 XGCValues gcv; 745 XGCValues gcv;
733 GC gc; 746 GC gc;
734 Pixmap root_pmap; 747 Pixmap root_pmap;
735 748
736 image_width = gdk_pixbuf_get_width (result); 749 image_width = gdk_pixbuf_get_width (result);
737 image_height = gdk_pixbuf_get_height (result); 750 image_height = gdk_pixbuf_get_height (result);
738 751
739 if (tr_flags) 752 if (tr_flags)
740 { 753 {
741 root_pmap = bg_pixmap; 754 root_pmap = bg_pixmap;
742 bg_pixmap = None; 755 bg_pixmap = None;
756 }
757 else
758 {
759 if (bg_flags & BG_TILE)
743 } 760 {
744 else
745 {
746 if (h_scale == 0 || v_scale == 0)
747 {
748 new_pmap_width = min (image_width, target_width); 761 new_pmap_width = min (image_width, target_width);
749 new_pmap_height = min (image_height, target_height); 762 new_pmap_height = min (image_height, target_height);
750 } 763 }
751 } 764 }
752 765
753 if (bg_pixmap == None 766 if (bg_pixmap == None
754 || bg_pmap_width != new_pmap_width 767 || bg_pmap_width != new_pmap_width
755 || bg_pmap_height != new_pmap_height) 768 || bg_pmap_height != new_pmap_height)
756 { 769 {
757 if (bg_pixmap) 770 if (bg_pixmap)
758 XFreePixmap (dpy, bg_pixmap); 771 XFreePixmap (dpy, bg_pixmap);
759 bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); 772 bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth);
760 bg_pmap_width = new_pmap_width; 773 bg_pmap_width = new_pmap_width;
761 bg_pmap_height = new_pmap_height; 774 bg_pmap_height = new_pmap_height;
762 } 775 }
763 776
764 gcv.foreground = pix_colors[Color_bg]; 777 gcv.foreground = pix_colors[Color_bg];
765 gc = XCreateGC (dpy, vt, GCForeground, &gcv); 778 gc = XCreateGC (dpy, vt, GCForeground, &gcv);
766 779
767 if (h_scale == 0 || v_scale == 0) 780 if (gc)
781 {
782 if (bg_flags & BG_TILE)
768 { 783 {
769 Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); 784 Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth);
770 pixbuf_to_pixmap (result, tile, gc, 785 pixbuf_to_pixmap (result, tile, gc,
771 0, 0, 786 0, 0,
772 0, 0, 787 0, 0,
816 Pixmap mask_pmap = XCreatePixmap (dpy, vt, 1, 1, 8); 831 Pixmap mask_pmap = XCreatePixmap (dpy, vt, 1, 1, 8);
817 XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8); 832 XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8);
818 Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa); 833 Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa);
819 XFreePixmap (dpy, mask_pmap); 834 XFreePixmap (dpy, mask_pmap);
820 835
821 if (src && dst && mask)
822 {
823 XRenderColor mask_c; 836 XRenderColor mask_c;
824 837
825 mask_c.alpha = 0x8000; 838 mask_c.alpha = 0x8000;
826 mask_c.red = 0; 839 mask_c.red = 0;
827 mask_c.green = 0; 840 mask_c.green = 0;
828 mask_c.blue = 0; 841 mask_c.blue = 0;
829 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); 842 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1);
830 XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height); 843 XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height);
831 }
832 844
833 XRenderFreePicture (dpy, src); 845 XRenderFreePicture (dpy, src);
834 XRenderFreePicture (dpy, dst); 846 XRenderFreePicture (dpy, dst);
835 XRenderFreePicture (dpy, mask); 847 XRenderFreePicture (dpy, mask);
836
837 XFreePixmap (dpy, root_pmap);
838 } 848 }
839#endif 849#endif
840 850
841 if (result != pixbuf)
842 g_object_unref (result);
843
844 XFreeGC (dpy, gc); 851 XFreeGC (dpy, gc);
845 852
846 ret = true; 853 ret = true;
847 } 854 }
855
856 if (result != pixbuf)
857 g_object_unref (result);
858
859 if (tr_flags)
860 XFreePixmap (dpy, root_pmap);
848 861
849 return ret; 862 return ret;
850} 863}
851# endif /* HAVE_PIXBUF */ 864# endif /* HAVE_PIXBUF */
852 865
943 bg_flags |= BG_NEEDS_BLUR; 956 bg_flags |= BG_NEEDS_BLUR;
944 957
945 return changed; 958 return changed;
946} 959}
947 960
948static inline unsigned long 961void
949compute_tint_shade_flags (rxvt_color *tint, int shade) 962rxvt_term::set_tint_shade_flags ()
950{ 963{
951 unsigned long flags = 0;
952 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 964 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
953 bool has_shade = shade != 100; 965 bool has_shade = shade != 100;
954 966
955 if (tint) 967 bg_flags &= ~BG_TINT_FLAGS;
968
969 if (bg_flags & BG_TINT_SET)
956 { 970 {
957 tint->get (c); 971 tint.get (c);
958 if (!has_shade 972 if (!has_shade
959 && (c.r <= 0x00ff || c.r >= 0xff00) 973 && (c.r <= 0x00ff || c.r >= 0xff00)
960 && (c.g <= 0x00ff || c.g >= 0xff00) 974 && (c.g <= 0x00ff || c.g >= 0xff00)
961 && (c.b <= 0x00ff || c.b >= 0xff00)) 975 && (c.b <= 0x00ff || c.b >= 0xff00))
962 flags |= rxvt_term::BG_TINT_BITAND; 976 bg_flags |= BG_TINT_BITAND;
963 } 977 }
964 978
965 if (has_shade || tint) 979 if (has_shade || (bg_flags & BG_TINT_SET))
966 flags |= rxvt_term::BG_NEEDS_TINT; 980 bg_flags |= BG_NEEDS_TINT;
967
968 return flags;
969} 981}
970 982
971bool 983bool
972rxvt_term::bg_set_tint (rxvt_color &new_tint) 984rxvt_term::bg_set_tint (rxvt_color &new_tint)
973{ 985{
974 if (!(bg_flags & BG_TINT_SET) || tint != new_tint) 986 if (!(bg_flags & BG_TINT_SET) || tint != new_tint)
975 { 987 {
976 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade);
977 tint = new_tint; 988 tint = new_tint;
978 bg_flags = (bg_flags & ~BG_TINT_FLAGS) | new_flags | BG_TINT_SET; 989 bg_flags |= BG_TINT_SET;
990 set_tint_shade_flags ();
979 return true; 991 return true;
980 } 992 }
981 993
982 return false; 994 return false;
983} 995}
991 if (new_shade < 0) 1003 if (new_shade < 0)
992 new_shade = 200 - (100 + new_shade); 1004 new_shade = 200 - (100 + new_shade);
993 1005
994 if (new_shade != shade) 1006 if (new_shade != shade)
995 { 1007 {
996 unsigned long new_flags = compute_tint_shade_flags ((bg_flags & BG_TINT_SET) ? &tint : NULL, new_shade);
997 shade = new_shade; 1008 shade = new_shade;
998 bg_flags = (bg_flags & ~BG_TINT_FLAGS) | new_flags; 1009 set_tint_shade_flags ();
999 return true; 1010 return true;
1000 } 1011 }
1001 1012
1002 return false; 1013 return false;
1003} 1014}
1038 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1049 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1039 1050
1040 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1051 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1041 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1052 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1042 1053
1043 if (kernel && params && src && dst) 1054 if (kernel && params)
1044 { 1055 {
1045 if (h_blurRadius) 1056 if (h_blurRadius)
1046 { 1057 {
1047 size = h_blurRadius * 2 + 1; 1058 size = h_blurRadius * 2 + 1;
1048 get_gaussian_kernel (h_blurRadius, size, kernel, params); 1059 get_gaussian_kernel (h_blurRadius, size, kernel, params);
1113 } 1124 }
1114 } 1125 }
1115 else 1126 else
1116 { 1127 {
1117# if XRENDER 1128# if XRENDER
1118 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1129 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1119 1130
1120 if (bg_flags & BG_TINT_SET) 1131 if (bg_flags & BG_TINT_SET)
1121 tint.get (c); 1132 tint.get (c);
1122 1133
1123 if (shade <= 100) 1134 if (shade <= 100)
1124 { 1135 {
1125 c.r = (c.r * shade) / 100; 1136 c.r = c.r * shade / 100;
1126 c.g = (c.g * shade) / 100; 1137 c.g = c.g * shade / 100;
1127 c.b = (c.b * shade) / 100; 1138 c.b = c.b * shade / 100;
1128 } 1139 }
1129 else 1140 else
1130 { 1141 {
1131 c.r = (c.r * (200 - shade)) / 100; 1142 c.r = c.r * (200 - shade) / 100;
1132 c.g = (c.g * (200 - shade)) / 100; 1143 c.g = c.g * (200 - shade) / 100;
1133 c.b = (c.b * (200 - shade)) / 100; 1144 c.b = c.b * (200 - shade) / 100;
1134 } 1145 }
1135 1146
1136 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); 1147 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
1137 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1148 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1138 XRenderPictureAttributes pa; 1149 XRenderPictureAttributes pa;
1145 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); 1156 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
1146 XFreePixmap (dpy, overlay_pmap); 1157 XFreePixmap (dpy, overlay_pmap);
1147 1158
1148 pa.component_alpha = True; 1159 pa.component_alpha = True;
1149 Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); 1160 Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32);
1150 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa); 1161 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat | CPComponentAlpha, &pa);
1151 XFreePixmap (dpy, mask_pmap); 1162 XFreePixmap (dpy, mask_pmap);
1152 1163
1153 if (mask_pic && overlay_pic && back_pic)
1154 {
1155 XRenderColor mask_c; 1164 XRenderColor mask_c;
1156 1165
1157 mask_c.red = mask_c.green = mask_c.blue = 0;
1158 mask_c.alpha = 0xffff; 1166 mask_c.alpha = 0xffff;
1167 mask_c.red =
1168 mask_c.green =
1169 mask_c.blue = 0;
1170 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1171
1172 mask_c.alpha = 0;
1173 mask_c.red = 0xffff - c.r;
1174 mask_c.green = 0xffff - c.g;
1175 mask_c.blue = 0xffff - c.b;
1176 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1177 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1178
1179 if (shade > 100)
1180 {
1181 mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100;
1182 mask_c.alpha = 0;
1159 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); 1183 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1160 1184
1161 mask_c.alpha = 0;
1162 mask_c.red = 0xffff - c.r;
1163 mask_c.green = 0xffff - c.g;
1164 mask_c.blue = 0xffff - c.b;
1165 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1166 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1167
1168 if (shade > 100)
1169 {
1170 mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100;
1171 mask_c.alpha = 0;
1172 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1173
1174 XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height); 1185 XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1175 } 1186 }
1176 1187
1177 ret = true; 1188 ret = true;
1178 }
1179 1189
1180 XRenderFreePicture (dpy, mask_pic); 1190 XRenderFreePicture (dpy, mask_pic);
1181 XRenderFreePicture (dpy, overlay_pic); 1191 XRenderFreePicture (dpy, overlay_pic);
1182 XRenderFreePicture (dpy, back_pic); 1192 XRenderFreePicture (dpy, back_pic);
1183# endif 1193# endif
1184 } 1194 }
1185 1195
1186 return ret; 1196 return ret;
1187} 1197}
1188 1198
1189/* make_transparency_pixmap() 1199/*
1190 * Builds a pixmap of the same size as the terminal window that contains 1200 * Builds a pixmap of the same size as the terminal window that contains
1191 * the tiled portion of the root pixmap that is supposed to be covered by 1201 * the tiled portion of the root pixmap that is supposed to be covered by
1192 * our window. 1202 * our window.
1193 */ 1203 */
1194unsigned long 1204unsigned long
1238 if (root_pixmap != None && root_depth != depth) 1248 if (root_pixmap != None && root_depth != depth)
1239 { 1249 {
1240#if XRENDER 1250#if XRENDER
1241 if (bg_flags & BG_HAS_RENDER) 1251 if (bg_flags & BG_HAS_RENDER)
1242 { 1252 {
1253 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth);
1254
1243 XRenderPictureAttributes pa; 1255 XRenderPictureAttributes pa;
1244 1256
1245 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); 1257 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
1246 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); 1258 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa);
1247 1259
1248 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth);
1249 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); 1260 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual);
1250 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); 1261 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa);
1251 1262
1252 if (src && dst)
1253 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); 1263 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height);
1254 else
1255 {
1256 XFreePixmap (dpy, recoded_root_pmap);
1257 root_pixmap = None;
1258 }
1259 1264
1260 XRenderFreePicture (dpy, src); 1265 XRenderFreePicture (dpy, src);
1261 XRenderFreePicture (dpy, dst); 1266 XRenderFreePicture (dpy, dst);
1262 } 1267 }
1263 else 1268 else
1264#endif 1269#endif
1265 root_pixmap = None; 1270 recoded_root_pmap = None;
1266 } 1271 }
1267 1272
1268 if (root_pixmap == None) 1273 if (recoded_root_pmap == None)
1269 return 0; 1274 return 0;
1270 1275
1271 if (bg_pixmap == None 1276 if (bg_pixmap == None
1272 || bg_pmap_width != window_width 1277 || bg_pmap_width != window_width
1273 || bg_pmap_height != window_height) 1278 || bg_pmap_height != window_height)
1277 bg_pixmap = XCreatePixmap (dpy, vt, window_width, window_height, depth); 1282 bg_pixmap = XCreatePixmap (dpy, vt, window_width, window_height, depth);
1278 bg_pmap_width = window_width; 1283 bg_pmap_width = window_width;
1279 bg_pmap_height = window_height; 1284 bg_pmap_height = window_height;
1280 } 1285 }
1281 1286
1282 if (bg_pixmap == None)
1283 return 0;
1284
1285 /* straightforward pixmap copy */ 1287 /* straightforward pixmap copy */
1286 while (sx < 0) sx += (int)root_width; 1288 while (sx < 0) sx += root_width;
1287 while (sy < 0) sy += (int)root_height; 1289 while (sy < 0) sy += root_height;
1288 1290
1289 gcv.tile = recoded_root_pmap; 1291 gcv.tile = recoded_root_pmap;
1290 gcv.fill_style = FillTiled; 1292 gcv.fill_style = FillTiled;
1291 gcv.ts_x_origin = -sx; 1293 gcv.ts_x_origin = -sx;
1292 gcv.ts_y_origin = -sy; 1294 gcv.ts_y_origin = -sy;
1449 uint32_t mask_r, mask_g, mask_b; 1451 uint32_t mask_r, mask_g, mask_b;
1450 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1452 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1451 rgba low; 1453 rgba low;
1452 rgba high; 1454 rgba high;
1453 int i; 1455 int i;
1454 int host_byte_order = byteorder::big_endian () ? MSBFirst : LSBFirst; 1456 int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst;
1455 1457
1456 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; 1458 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return;
1457 1459
1458 /* for convenience */ 1460 /* for convenience */
1459 mask_r = visual->red_mask; 1461 mask_r = visual->red_mask;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines