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.185 by sf-exg, Mon Dec 26 14:53:56 2011 UTC vs.
Revision 1.189 by sf-exg, Thu Dec 29 16:45:22 2011 UTC

33#ifndef FilterConvolution 33#ifndef FilterConvolution
34#define FilterConvolution "convolution" 34#define FilterConvolution "convolution"
35#endif 35#endif
36 36
37#ifdef HAVE_BG_PIXMAP 37#ifdef HAVE_BG_PIXMAP
38# if XRENDER
39static Picture
40create_xrender_mask (Display *dpy, Drawable drawable, Bool argb, Bool component_alpha)
41{
42 Pixmap pixmap = XCreatePixmap (dpy, drawable, 1, 1, argb ? 32 : 8);
43
44 XRenderPictFormat *format = XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8);
45 XRenderPictureAttributes pa;
46 pa.repeat = True;
47 pa.component_alpha = component_alpha;
48 Picture mask = XRenderCreatePicture (dpy, pixmap, format, CPRepeat | CPComponentAlpha, &pa);
49
50 XFreePixmap (dpy, pixmap);
51
52 return mask;
53}
54# endif
55
38void 56void
39rxvt_term::bg_destroy () 57rxvt_term::bg_destroy ()
40{ 58{
41#ifdef HAVE_AFTERIMAGE 59#ifdef HAVE_AFTERIMAGE
42 if (original_asim) 60 if (original_asim)
374 if (tr_flags & BG_NEEDS_TINT) 392 if (tr_flags & BG_NEEDS_TINT)
375 { 393 {
376 ShadingInfo as_shade; 394 ShadingInfo as_shade;
377 as_shade.shading = shade; 395 as_shade.shading = shade;
378 396
379 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 397 rgba c;
380 if (bg_flags & BG_TINT_SET)
381 tint.get (c); 398 tint.get (c);
382 as_shade.tintColor.red = c.r; 399 as_shade.tintColor.red = c.r;
383 as_shade.tintColor.green = c.g; 400 as_shade.tintColor.green = c.g;
384 as_shade.tintColor.blue = c.b; 401 as_shade.tintColor.blue = c.b;
385 402
386 background_tint = shading2tint32 (&as_shade); 403 background_tint = shading2tint32 (&as_shade);
810 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); 827 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa);
811 828
812 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); 829 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual);
813 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, dst_format, 0, &pa); 830 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, dst_format, 0, &pa);
814 831
815 pa.repeat = True; 832 Picture mask = create_xrender_mask (dpy, vt, False, False);
816 Pixmap mask_pmap = XCreatePixmap (dpy, vt, 1, 1, 8);
817 XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8);
818 Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa);
819 XFreePixmap (dpy, mask_pmap);
820 833
821 XRenderColor mask_c; 834 XRenderColor mask_c;
822 835
823 mask_c.alpha = 0x8000; 836 mask_c.alpha = 0x8000;
824 mask_c.red = 0; 837 mask_c.red = 0;
960 rgba c; 973 rgba c;
961 bool has_shade = shade != 100; 974 bool has_shade = shade != 100;
962 975
963 bg_flags &= ~BG_TINT_FLAGS; 976 bg_flags &= ~BG_TINT_FLAGS;
964 977
965 if (bg_flags & BG_TINT_SET)
966 {
967 tint.get (c); 978 tint.get (c);
979
968 if (!has_shade 980 if (!has_shade
969 && (c.r <= 0x00ff || c.r >= 0xff00) 981 && (c.r <= 0x00ff || c.r >= 0xff00)
970 && (c.g <= 0x00ff || c.g >= 0xff00) 982 && (c.g <= 0x00ff || c.g >= 0xff00)
971 && (c.b <= 0x00ff || c.b >= 0xff00)) 983 && (c.b <= 0x00ff || c.b >= 0xff00))
972 bg_flags |= BG_TINT_BITAND; 984 bg_flags |= BG_TINT_BITAND;
973 }
974 985
975 if (has_shade || (bg_flags & BG_TINT_SET)) 986 if (has_shade
987 || c.r < 0xff00
988 || c.g < 0xff00
989 || c.b < 0xff00)
976 bg_flags |= BG_NEEDS_TINT; 990 bg_flags |= BG_NEEDS_TINT;
977} 991}
978 992
979bool 993bool
980rxvt_term::bg_set_tint (rxvt_color &new_tint) 994rxvt_term::bg_set_tint (rxvt_color &new_tint)
981{ 995{
982 if (!(bg_flags & BG_TINT_SET) || tint != new_tint) 996 if (tint != new_tint)
983 { 997 {
984 tint = new_tint; 998 tint = new_tint;
985 bg_flags |= BG_TINT_SET;
986 set_tint_shade_flags (); 999 set_tint_shade_flags ();
987 return true; 1000 return true;
988 } 1001 }
989 1002
990 return false; 1003 return false;
991} 1004}
992 1005
993bool 1006bool
994rxvt_term::bg_set_shade (const char *shade_str) 1007rxvt_term::bg_set_shade (const char *shade_str)
995{ 1008{
996 int new_shade = (shade_str) ? atoi (shade_str) : 100; 1009 int new_shade = atoi (shade_str);
997 1010
998 clamp_it (new_shade, -100, 200); 1011 clamp_it (new_shade, -100, 200);
999 if (new_shade < 0) 1012 if (new_shade < 0)
1000 new_shade = 200 - (100 + new_shade); 1013 new_shade = 200 - (100 + new_shade);
1001 1014
1123 } 1136 }
1124 } 1137 }
1125# if XRENDER 1138# if XRENDER
1126 else if (bg_flags & BG_HAS_RENDER) 1139 else if (bg_flags & BG_HAS_RENDER)
1127 { 1140 {
1128 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); 1141 rgba c;
1129 1142
1130 if (bg_flags & BG_TINT_SET)
1131 tint.get (c); 1143 tint.get (c);
1132 1144
1133 if (shade <= 100) 1145 if (shade <= 100)
1134 { 1146 {
1135 c.r = c.r * shade / 100; 1147 c.r = c.r * shade / 100;
1136 c.g = c.g * shade / 100; 1148 c.g = c.g * shade / 100;
1141 c.r = c.r * (200 - shade) / 100; 1153 c.r = c.r * (200 - shade) / 100;
1142 c.g = c.g * (200 - shade) / 100; 1154 c.g = c.g * (200 - shade) / 100;
1143 c.b = c.b * (200 - shade) / 100; 1155 c.b = c.b * (200 - shade) / 100;
1144 } 1156 }
1145 1157
1146 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
1147 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1158 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1148 XRenderPictureAttributes pa; 1159 XRenderPictureAttributes pa;
1149 1160
1150 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1161 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1151 1162
1152 pa.repeat = True; 1163 Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False);
1153 1164
1154 Pixmap overlay_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); 1165 Picture mask_pic = create_xrender_mask (dpy, pixmap, True, True);
1155 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
1156 XFreePixmap (dpy, overlay_pmap);
1157
1158 pa.component_alpha = True;
1159 Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32);
1160 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat | CPComponentAlpha, &pa);
1161 XFreePixmap (dpy, mask_pmap);
1162 1166
1163 XRenderColor mask_c; 1167 XRenderColor mask_c;
1164 1168
1165 mask_c.alpha = 0xffff; 1169 mask_c.alpha = 0xffff;
1166 mask_c.red = 1170 mask_c.red =
1295 1299
1296 if (gc) 1300 if (gc)
1297 { 1301 {
1298 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); 1302 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height);
1299 result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS); 1303 result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS);
1300 XFreeGC (dpy, gc);
1301 1304
1302 if (!(bg_flags & BG_CLIENT_RENDER)) 1305 if (!(bg_flags & BG_CLIENT_RENDER))
1303 { 1306 {
1304 if (bg_flags & BG_NEEDS_BLUR) 1307 if (bg_flags & BG_NEEDS_BLUR)
1305 { 1308 {
1309 if (bg_flags & BG_NEEDS_TINT) 1312 if (bg_flags & BG_NEEDS_TINT)
1310 { 1313 {
1311 if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) 1314 if (tint_pixmap (bg_pixmap, visual, window_width, window_height))
1312 result &= ~BG_NEEDS_TINT; 1315 result &= ~BG_NEEDS_TINT;
1313 } 1316 }
1317# ifndef HAVE_AFTERIMAGE
1318 if (result & BG_NEEDS_TINT)
1319 {
1320 XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1321 if (ximage)
1322 {
1323 /* our own client-side tinting */
1324 tint_ximage (DefaultVisual (dpy, display->screen), ximage);
1325
1326 XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height);
1327 XDestroyImage (ximage);
1328 }
1329 }
1330# endif
1314 } /* server side rendering completed */ 1331 } /* server side rendering completed */
1332
1333 XFreeGC (dpy, gc);
1315 } 1334 }
1316 1335
1317 if (recoded_root_pmap != root_pixmap) 1336 if (recoded_root_pmap != root_pixmap)
1318 XFreePixmap (dpy, recoded_root_pmap); 1337 XFreePixmap (dpy, recoded_root_pmap);
1319 1338
1355 if (render_image (tr_flags)) 1374 if (render_image (tr_flags))
1356 bg_flags |= BG_IS_VALID; 1375 bg_flags |= BG_IS_VALID;
1357 } 1376 }
1358# endif 1377# endif
1359 1378
1360# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1361 XImage *result = NULL;
1362
1363 if (tr_flags & BG_NEEDS_TINT)
1364 {
1365 result = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1366 }
1367
1368 if (result)
1369 {
1370 /* our own client-side tinting */
1371 //if (tr_flags & BG_NEEDS_TINT)
1372 if (1)
1373 tint_ximage (DefaultVisual (dpy, display->screen), result);
1374
1375 GC gc = XCreateGC (dpy, vt, 0UL, NULL);
1376
1377 if (gc)
1378 {
1379 XPutImage (dpy, bg_pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1380
1381 XFreeGC (dpy, gc);
1382 }
1383
1384 XDestroyImage (result);
1385 }
1386# endif
1387
1388 if (!(bg_flags & BG_IS_VALID)) 1379 if (!(bg_flags & BG_IS_VALID))
1389 { 1380 {
1390 if (bg_pixmap != None) 1381 if (bg_pixmap != None)
1391 { 1382 {
1392 XFreePixmap (dpy, bg_pixmap); 1383 XFreePixmap (dpy, bg_pixmap);
1404 1395
1405void 1396void
1406rxvt_term::bg_init () 1397rxvt_term::bg_init ()
1407{ 1398{
1408#ifdef ENABLE_TRANSPARENCY 1399#ifdef ENABLE_TRANSPARENCY
1400 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1401 tint.set (this, c);
1409 shade = 100; 1402 shade = 100;
1410#endif 1403#endif
1411 1404
1412 bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV); 1405 bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV);
1413#if XRENDER 1406#if XRENDER
1516 break; 1509 break;
1517 default: 1510 default:
1518 return; /* we do not support this color depth */ 1511 return; /* we do not support this color depth */
1519 } 1512 }
1520 1513
1521 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); 1514 rgba c;
1522 1515
1523 if (bg_flags & BG_TINT_SET)
1524 tint.get (c); 1516 tint.get (c);
1525 1517
1526 /* prepare limits for color transformation (each channel is handled separately) */ 1518 /* prepare limits for color transformation (each channel is handled separately) */
1527 if (shade > 100) 1519 if (shade > 100)
1528 { 1520 {
1529 c.r = c.r * (200 - shade) / 100; 1521 c.r = c.r * (200 - shade) / 100;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines