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.150 by sf-exg, Sun May 8 21:00:45 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
943 bg_flags |= BG_NEEDS_BLUR; 943 bg_flags |= BG_NEEDS_BLUR;
944 944
945 return changed; 945 return changed;
946} 946}
947 947
948static inline unsigned long 948void
949compute_tint_shade_flags (rxvt_color *tint, int shade) 949rxvt_term::set_tint_shade_flags ()
950{ 950{
951 unsigned long flags = 0;
952 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 951 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
953 bool has_shade = shade != 100; 952 bool has_shade = shade != 100;
954 953
955 if (tint) 954 bg_flags &= ~BG_TINT_FLAGS;
955
956 if (bg_flags & BG_TINT_SET)
956 { 957 {
957 tint->get (c); 958 tint.get (c);
958 if (!has_shade 959 if (!has_shade
959 && (c.r <= 0x00ff || c.r >= 0xff00) 960 && (c.r <= 0x00ff || c.r >= 0xff00)
960 && (c.g <= 0x00ff || c.g >= 0xff00) 961 && (c.g <= 0x00ff || c.g >= 0xff00)
961 && (c.b <= 0x00ff || c.b >= 0xff00)) 962 && (c.b <= 0x00ff || c.b >= 0xff00))
962 flags |= rxvt_term::BG_TINT_BITAND; 963 bg_flags |= BG_TINT_BITAND;
963 } 964 }
964 965
965 if (has_shade || tint) 966 if (has_shade || (bg_flags & BG_TINT_SET))
966 flags |= rxvt_term::BG_NEEDS_TINT; 967 bg_flags |= BG_NEEDS_TINT;
967
968 return flags;
969} 968}
970 969
971bool 970bool
972rxvt_term::bg_set_tint (rxvt_color &new_tint) 971rxvt_term::bg_set_tint (rxvt_color &new_tint)
973{ 972{
974 if (!(bg_flags & BG_TINT_SET) || tint != new_tint) 973 if (!(bg_flags & BG_TINT_SET) || tint != new_tint)
975 { 974 {
976 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade);
977 tint = new_tint; 975 tint = new_tint;
978 bg_flags = (bg_flags & ~BG_TINT_FLAGS) | new_flags | BG_TINT_SET; 976 bg_flags |= BG_TINT_SET;
977 set_tint_shade_flags ();
979 return true; 978 return true;
980 } 979 }
981 980
982 return false; 981 return false;
983} 982}
991 if (new_shade < 0) 990 if (new_shade < 0)
992 new_shade = 200 - (100 + new_shade); 991 new_shade = 200 - (100 + new_shade);
993 992
994 if (new_shade != shade) 993 if (new_shade != shade)
995 { 994 {
996 unsigned long new_flags = compute_tint_shade_flags ((bg_flags & BG_TINT_SET) ? &tint : NULL, new_shade);
997 shade = new_shade; 995 shade = new_shade;
998 bg_flags = (bg_flags & ~BG_TINT_FLAGS) | new_flags; 996 set_tint_shade_flags ();
999 return true; 997 return true;
1000 } 998 }
1001 999
1002 return false; 1000 return false;
1003} 1001}
1113 } 1111 }
1114 } 1112 }
1115 else 1113 else
1116 { 1114 {
1117# if XRENDER 1115# if XRENDER
1118 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1116 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1119 1117
1120 if (bg_flags & BG_TINT_SET) 1118 if (bg_flags & BG_TINT_SET)
1121 tint.get (c); 1119 tint.get (c);
1122 1120
1123 if (shade <= 100) 1121 if (shade <= 100)
1124 { 1122 {
1125 c.r = (c.r * shade) / 100; 1123 c.r = c.r * shade / 100;
1126 c.g = (c.g * shade) / 100; 1124 c.g = c.g * shade / 100;
1127 c.b = (c.b * shade) / 100; 1125 c.b = c.b * shade / 100;
1128 } 1126 }
1129 else 1127 else
1130 { 1128 {
1131 c.r = (c.r * (200 - shade)) / 100; 1129 c.r = c.r * (200 - shade) / 100;
1132 c.g = (c.g * (200 - shade)) / 100; 1130 c.g = c.g * (200 - shade) / 100;
1133 c.b = (c.b * (200 - shade)) / 100; 1131 c.b = c.b * (200 - shade) / 100;
1134 } 1132 }
1135 1133
1136 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); 1134 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
1137 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1135 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1138 XRenderPictureAttributes pa; 1136 XRenderPictureAttributes pa;
1145 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); 1143 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
1146 XFreePixmap (dpy, overlay_pmap); 1144 XFreePixmap (dpy, overlay_pmap);
1147 1145
1148 pa.component_alpha = True; 1146 pa.component_alpha = True;
1149 Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); 1147 Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32);
1150 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa); 1148 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat | CPComponentAlpha, &pa);
1151 XFreePixmap (dpy, mask_pmap); 1149 XFreePixmap (dpy, mask_pmap);
1152 1150
1153 if (mask_pic && overlay_pic && back_pic) 1151 if (mask_pic && overlay_pic && back_pic)
1154 { 1152 {
1155 XRenderColor mask_c; 1153 XRenderColor mask_c;
1156 1154
1157 mask_c.red = mask_c.green = mask_c.blue = 0;
1158 mask_c.alpha = 0xffff; 1155 mask_c.alpha = 0xffff;
1156 mask_c.red =
1157 mask_c.green =
1158 mask_c.blue = 0;
1159 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); 1159 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1160 1160
1161 mask_c.alpha = 0; 1161 mask_c.alpha = 0;
1162 mask_c.red = 0xffff - c.r; 1162 mask_c.red = 0xffff - c.r;
1163 mask_c.green = 0xffff - c.g; 1163 mask_c.green = 0xffff - c.g;
1164 mask_c.blue = 0xffff - c.b; 1164 mask_c.blue = 0xffff - c.b;
1165 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); 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); 1166 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1167 1167
1168 if (shade > 100) 1168 if (shade > 100)
1169 { 1169 {
1184 } 1184 }
1185 1185
1186 return ret; 1186 return ret;
1187} 1187}
1188 1188
1189/* make_transparency_pixmap() 1189/*
1190 * Builds a pixmap of the same size as the terminal window that contains 1190 * 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 1191 * the tiled portion of the root pixmap that is supposed to be covered by
1192 * our window. 1192 * our window.
1193 */ 1193 */
1194unsigned long 1194unsigned long
1277 bg_pixmap = XCreatePixmap (dpy, vt, window_width, window_height, depth); 1277 bg_pixmap = XCreatePixmap (dpy, vt, window_width, window_height, depth);
1278 bg_pmap_width = window_width; 1278 bg_pmap_width = window_width;
1279 bg_pmap_height = window_height; 1279 bg_pmap_height = window_height;
1280 } 1280 }
1281 1281
1282 if (bg_pixmap == None) 1282 if (bg_pixmap != None)
1283 return 0; 1283 {
1284
1285 /* straightforward pixmap copy */ 1284 /* straightforward pixmap copy */
1286 while (sx < 0) sx += (int)root_width; 1285 while (sx < 0) sx += (int)root_width;
1287 while (sy < 0) sy += (int)root_height; 1286 while (sy < 0) sy += (int)root_height;
1288 1287
1289 gcv.tile = recoded_root_pmap; 1288 gcv.tile = recoded_root_pmap;
1290 gcv.fill_style = FillTiled; 1289 gcv.fill_style = FillTiled;
1291 gcv.ts_x_origin = -sx; 1290 gcv.ts_x_origin = -sx;
1292 gcv.ts_y_origin = -sy; 1291 gcv.ts_y_origin = -sy;
1293 gc = XCreateGC (dpy, vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 1292 gc = XCreateGC (dpy, vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
1294 1293
1295 if (gc) 1294 if (gc)
1296 { 1295 {
1297 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); 1296 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height);
1298 result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS); 1297 result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS);
1299 XFreeGC (dpy, gc); 1298 XFreeGC (dpy, gc);
1300 1299
1301 if (!(bg_flags & BG_CLIENT_RENDER)) 1300 if (!(bg_flags & BG_CLIENT_RENDER))
1302 { 1301 {
1303 if ((bg_flags & BG_NEEDS_BLUR) 1302 if ((bg_flags & BG_NEEDS_BLUR)
1304 && (bg_flags & BG_HAS_RENDER_CONV)) 1303 && (bg_flags & BG_HAS_RENDER_CONV))
1305 { 1304 {
1306 if (blur_pixmap (bg_pixmap, visual, window_width, window_height)) 1305 if (blur_pixmap (bg_pixmap, visual, window_width, window_height))
1307 result &= ~BG_NEEDS_BLUR; 1306 result &= ~BG_NEEDS_BLUR;
1308 } 1307 }
1309 if ((bg_flags & BG_NEEDS_TINT) 1308 if ((bg_flags & BG_NEEDS_TINT)
1310 && (bg_flags & (BG_TINT_BITAND | BG_HAS_RENDER))) 1309 && (bg_flags & (BG_TINT_BITAND | BG_HAS_RENDER)))
1311 { 1310 {
1312 if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) 1311 if (tint_pixmap (bg_pixmap, visual, window_width, window_height))
1313 result &= ~BG_NEEDS_TINT; 1312 result &= ~BG_NEEDS_TINT;
1314 } 1313 }
1315 } /* server side rendering completed */ 1314 } /* server side rendering completed */
1315 }
1316 } 1316 }
1317 1317
1318 if (recoded_root_pmap != root_pixmap) 1318 if (recoded_root_pmap != root_pixmap)
1319 XFreePixmap (dpy, recoded_root_pmap); 1319 XFreePixmap (dpy, recoded_root_pmap);
1320 1320

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines