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.3 by sasha, Wed Sep 12 22:12:54 2007 UTC vs.
Revision 1.12 by ayin, Thu Nov 15 11:36:15 2007 UTC

1/*----------------------------------------------------------------------* 1/*----------------------------------------------------------------------*
2 * File: background.C - former xmp.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) 1997 Carsten Haitzler <raster@zip.com.au> 6 * Copyright (c) 1997 Carsten Haitzler <raster@zip.com.au>
7 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> 7 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de>
31 31
32#if DO_TIMING_TEST 32#if DO_TIMING_TEST
33#define TIMING_TEST_START(id) \ 33#define TIMING_TEST_START(id) \
34 struct timeval timing_test_##id##_stv;\ 34 struct timeval timing_test_##id##_stv;\
35 gettimeofday (&timing_test_##id##_stv, NULL); 35 gettimeofday (&timing_test_##id##_stv, NULL);
36 36
37#define TIMING_TEST_PRINT_RESULT(id) \ 37#define TIMING_TEST_PRINT_RESULT(id) \
38 do{ struct timeval tv;gettimeofday (&tv, NULL); tv.tv_sec -= (timing_test_##id##_stv).tv_sec;\ 38 do{ struct timeval tv;gettimeofday (&tv, NULL); tv.tv_sec -= (timing_test_##id##_stv).tv_sec;\
39 fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__,\ 39 fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__,\
40 tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec);}while (0) 40 tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec);}while (0)
41 41
100#endif 100#endif
101 flags = 0; 101 flags = 0;
102 pixmap = None; 102 pixmap = None;
103} 103}
104 104
105bgPixmap_t::~bgPixmap_t()
106{
107#ifdef HAVE_AFTERIMAGE
108 if (original_asim)
109 safe_asimage_destroy (original_asim);
110#endif
111 if (pixmap && target)
112 XFreePixmap (target->dpy, pixmap);
113}
105 114
106bool 115bool
107bgPixmap_t::window_size_sensitive () 116bgPixmap_t::window_size_sensitive ()
108{ 117{
109# ifdef BG_IMAGE_FROM_FILE 118# ifdef BG_IMAGE_FROM_FILE
130 return true; 139 return true;
131# endif 140# endif
132# ifdef ENABLE_TRANSPARENCY 141# ifdef ENABLE_TRANSPARENCY
133 if (flags & isTransparent) 142 if (flags & isTransparent)
134 { 143 {
144# ifdef HAVE_AFTERIMAGE // can't blur without libAI anyways
135 if (((flags & blurNeeded) && !(flags & blurServerSide)) 145 if ((flags & blurNeeded) && !(flags & blurServerSide))
146 return true;
147# endif
136 || ((flags & tintNeeded) && !(flags & tintServerSide))) 148 if ((flags & tintNeeded) && !(flags & tintServerSide))
137 return true; 149 return true;
138 } 150 }
139# endif 151# endif
140 return false; 152 return false;
141} 153}
142 154
315 else if (!(flags & geometrySet)) 327 else if (!(flags & geometrySet))
316 { /* default geometry - scaled and centered */ 328 { /* default geometry - scaled and centered */
317 x = y = defaultAlign; 329 x = y = defaultAlign;
318 w = h = defaultScale; 330 w = h = defaultScale;
319 } 331 }
320 332
321 if (!(flags & geometrySet)) 333 if (!(flags & geometrySet))
322 geom_flags |= WidthValue|HeightValue|XValue|YValue; 334 geom_flags |= WidthValue|HeightValue|XValue|YValue;
323 335
324 if (ops) 336 if (ops)
325 { 337 {
446 { 458 {
447 result = original_asim; 459 result = original_asim;
448 if ((w > 0 && w != original_asim->width) 460 if ((w > 0 && w != original_asim->width)
449 || (h > 0 && h != original_asim->height)) 461 || (h > 0 && h != original_asim->height))
450 { 462 {
451 result = scale_asimage (target->asv, original_asim, 463 result = scale_asimage (target->asv, original_asim,
452 w > 0 ? w : original_asim->width, 464 w > 0 ? w : original_asim->width,
453 h > 0 ? h : original_asim->height, 465 h > 0 ? h : original_asim->height,
454 background ? ASA_ASImage : ASA_XImage, 466 background ? ASA_ASImage : ASA_XImage,
455 100, ASIMAGE_QUALITY_DEFAULT); 467 100, ASIMAGE_QUALITY_DEFAULT);
456 } 468 }
457 if (background == NULL) 469 if (background == NULL)
462 new_pmap_height = result->height; 474 new_pmap_height = result->height;
463 /* we also need to tile our image in one or both directions */ 475 /* we also need to tile our image in one or both directions */
464 if (h_scale == 0 || v_scale == 0) 476 if (h_scale == 0 || v_scale == 0)
465 { 477 {
466 ASImage *tmp = tile_asimage (target->asv, result, 478 ASImage *tmp = tile_asimage (target->asv, result,
467 (h_scale > 0) ? 0 : (int)result->width - x, 479 (h_scale > 0) ? 0 : (int)result->width - x,
468 (v_scale > 0) ? 0 : (int)result->height - y, 480 (v_scale > 0) ? 0 : (int)result->height - y,
469 result->width, result->height, 481 result->width, result->height,
470 TINT_LEAVE_SAME, ASA_XImage, 482 TINT_LEAVE_SAME, ASA_XImage,
471 100, ASIMAGE_QUALITY_DEFAULT); 483 100, ASIMAGE_QUALITY_DEFAULT);
472 if (tmp) 484 if (tmp)
473 { 485 {
575 } 587 }
576 588
577 /* put result on pixmap */ 589 /* put result on pixmap */
578 if (dst_x < new_pmap_width && dst_y < new_pmap_height) 590 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
579 asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True); 591 asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True);
580 592
581 if (result != background && result != original_asim) 593 if (result != background && result != original_asim)
582 destroy_asimage (&result); 594 destroy_asimage (&result);
583 595
584 XFreeGC (target->dpy, gc); 596 XFreeGC (target->dpy, gc);
585 TIMING_TEST_PRINT_RESULT (asim); 597 TIMING_TEST_PRINT_RESULT (asim);
611 f[len] = '\0'; 623 f[len] = '\0';
612 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100); 624 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100);
613 free (f); 625 free (f);
614 } 626 }
615 return (original_asim != NULL); 627 return (original_asim != NULL);
616# endif 628# endif
617 } 629 }
618 return false; 630 return false;
619} 631}
620 632
621# endif /* BG_IMAGE_FROM_FILE */ 633# endif /* BG_IMAGE_FROM_FILE */
622 634
623# ifdef ENABLE_TRANSPARENCY 635# ifdef ENABLE_TRANSPARENCY
624bool 636bool
625bgPixmap_t::set_transparent () 637bgPixmap_t::set_transparent ()
626{ 638{
627 if (!(flags & isTransparent)) 639 if (!(flags & isTransparent))
628 { 640 {
629 flags |= isTransparent; 641 flags |= isTransparent;
654 if (v_blurRadius != vr) 666 if (v_blurRadius != vr)
655 { 667 {
656 ++changed; 668 ++changed;
657 v_blurRadius = vr; 669 v_blurRadius = vr;
658 } 670 }
659 671
660 if (v_blurRadius == 0 && h_blurRadius == 0) 672 if (v_blurRadius == 0 && h_blurRadius == 0)
661 flags &= ~blurNeeded; 673 flags &= ~blurNeeded;
662 else 674 else
663 flags |= blurNeeded; 675 flags |= blurNeeded;
664 676
691 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) 703 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700))
692 { 704 {
693 flags |= bgPixmap_t::tintNeeded; 705 flags |= bgPixmap_t::tintNeeded;
694 } 706 }
695 } 707 }
696 708
697 if (flags & bgPixmap_t::tintNeeded) 709 if (flags & bgPixmap_t::tintNeeded)
698 { 710 {
699 if (flags & bgPixmap_t::tintWholesome) 711 if (flags & bgPixmap_t::tintWholesome)
700 flags |= bgPixmap_t::tintServerSide; 712 flags |= bgPixmap_t::tintServerSide;
701 else 713 else
738bool 750bool
739bgPixmap_t::set_shade (const char *shade_str) 751bgPixmap_t::set_shade (const char *shade_str)
740{ 752{
741 int new_shade = (shade_str) ? atoi (shade_str) : 0; 753 int new_shade = (shade_str) ? atoi (shade_str) : 0;
742 754
755 if (new_shade < 0 && new_shade > -100)
756 new_shade = 200 - (100 + new_shade);
743 if (new_shade == 100) 757 else if (new_shade == 100)
744 new_shade = 0; 758 new_shade = 0;
745 759
746 if (new_shade != shade) 760 if (new_shade != shade)
747 { 761 {
748 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); 762 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade);
751 return true; 765 return true;
752 } 766 }
753 return false; 767 return false;
754} 768}
755 769
756/* make_transparency_pixmap() 770/* make_transparency_pixmap()
757 * Builds a pixmap sized the same as terminal window, with depth same as the root window 771 * Builds a pixmap sized the same as terminal window, with depth same as the root window
758 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by 772 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by
759 * our window. 773 * our window.
760 */ 774 */
761unsigned long 775unsigned long
762bgPixmap_t::make_transparency_pixmap () 776bgPixmap_t::make_transparency_pixmap ()
763{ 777{
862 else 876 else
863 {/* strightforward pixmap copy */ 877 {/* strightforward pixmap copy */
864 gcv.tile = root_pixmap; 878 gcv.tile = root_pixmap;
865 gcv.fill_style = FillTiled; 879 gcv.fill_style = FillTiled;
866 880
867 while (sx < 0) sx += (int)window_width; 881 while (sx < 0) sx += (int)root_width;
868 while (sy < 0) sy += (int)window_height; 882 while (sy < 0) sy += (int)root_height;
869 883
870 gcv.ts_x_origin = -sx; 884 gcv.ts_x_origin = -sx;
871 gcv.ts_y_origin = -sy; 885 gcv.ts_y_origin = -sy;
872 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 886 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
873 887
879 } 893 }
880 TIMING_TEST_PRINT_RESULT (tp); 894 TIMING_TEST_PRINT_RESULT (tp);
881 895
882 if (tiled_root_pmap != None) 896 if (tiled_root_pmap != None)
883 { 897 {
884 if (!need_client_side_rendering ()) 898 if (!need_client_side_rendering ())
885 { 899 {
886 if ((flags & tintNeeded)) 900 if ((flags & tintNeeded))
887 { 901 {
888 if (flags & tintWholesome) 902 if (flags & tintWholesome)
889 { 903 {
890 /* In this case we can tint image server-side getting significant 904 /* In this case we can tint image server-side getting significant
891 * performance improvements, as we eliminate XImage transfer 905 * performance improvements, as we eliminate XImage transfer
932 pf.direct.greenMask = 0xff; 946 pf.direct.greenMask = 0xff;
933 pf.direct.blueMask = 0xff; 947 pf.direct.blueMask = 0xff;
934 pf.direct.alphaMask = 0xff; 948 pf.direct.alphaMask = 0xff;
935 949
936 XRenderPictFormat *solid_format = XRenderFindFormat (dpy, 950 XRenderPictFormat *solid_format = XRenderFindFormat (dpy,
937 (PictFormatType| 951 (PictFormatType|
938 PictFormatDepth| 952 PictFormatDepth|
939 PictFormatRedMask| 953 PictFormatRedMask|
940 PictFormatGreenMask| 954 PictFormatGreenMask|
941 PictFormatBlueMask| 955 PictFormatBlueMask|
942 PictFormatAlphaMask), 956 PictFormatAlphaMask),
943 &pf, 957 &pf,
944 0); 958 0);
945 XRenderPictFormat *root_format = XRenderFindVisualFormat (dpy, DefaultVisualOfScreen (ScreenOfDisplay (dpy, target->display->screen))); 959 XRenderPictFormat *root_format = XRenderFindVisualFormat (dpy, DefaultVisualOfScreen (ScreenOfDisplay (dpy, target->display->screen)));
946 XRenderPictureAttributes pa ; 960 XRenderPictureAttributes pa ;
947 961
948 back_pic = XRenderCreatePicture (dpy, tiled_root_pmap, root_format, 0, &pa); 962 back_pic = XRenderCreatePicture (dpy, tiled_root_pmap, root_format, 0, &pa);
949 963
951 965
952 Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32); 966 Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32);
953 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); 967 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
954 XFreePixmap (dpy, overlay_pmap); 968 XFreePixmap (dpy, overlay_pmap);
955 969
956 pa.component_alpha = True; 970 pa.component_alpha = True;
957 Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32); 971 Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32);
958 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa); 972 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa);
959 XFreePixmap (dpy, mask_pmap); 973 XFreePixmap (dpy, mask_pmap);
960 974
961 if (mask_pic && overlay_pic && back_pic) 975 if (mask_pic && overlay_pic && back_pic)
977 XRenderFreePicture (dpy, mask_pic); 991 XRenderFreePicture (dpy, mask_pic);
978 XRenderFreePicture (dpy, overlay_pic); 992 XRenderFreePicture (dpy, overlay_pic);
979 XRenderFreePicture (dpy, back_pic); 993 XRenderFreePicture (dpy, back_pic);
980# if DO_TIMING_TEST 994# if DO_TIMING_TEST
981 XSync (dpy, False); 995 XSync (dpy, False);
982# endif 996# endif
983# endif 997# endif
984 } 998 }
985 } 999 }
986 } /* server side rendering completed */ 1000 } /* server side rendering completed */
987 1001
991 pixmap = tiled_root_pmap; 1005 pixmap = tiled_root_pmap;
992 pmap_width = window_width; 1006 pmap_width = window_width;
993 pmap_height = window_height; 1007 pmap_height = window_height;
994 pmap_depth = root_depth; 1008 pmap_depth = root_depth;
995 } 1009 }
996 1010
997 if (gc) 1011 if (gc)
998 XFreeGC (dpy, gc); 1012 XFreeGC (dpy, gc);
999 1013
1000 TIMING_TEST_PRINT_RESULT (tp); 1014 TIMING_TEST_PRINT_RESULT (tp);
1001 1015
1002 return result; 1016 return result;
1003} 1017}
1004 1018
1005bool 1019bool
1006bgPixmap_t::set_root_pixmap () 1020bgPixmap_t::set_root_pixmap ()
1007{ 1021{
1008 Pixmap new_root_pixmap = None; 1022 Pixmap new_root_pixmap = None;
1009 1023
1010 new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); 1024 new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID);
1011 if (new_root_pixmap == None) 1025 if (new_root_pixmap == None)
1012 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); 1026 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID);
1013 1027
1014 if (new_root_pixmap != root_pixmap) 1028 if (new_root_pixmap != root_pixmap)
1094 } 1108 }
1095 else if (background_flags && pmap_depth != target->depth) 1109 else if (background_flags && pmap_depth != target->depth)
1096 { 1110 {
1097 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1111 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1098 } 1112 }
1113
1099# else /* our own client-side tinting */ 1114# elif !XFT /* our own client-side tinting */
1115
1116 /* ATTENTION: We ASSUME that XFT will let us do all the tinting neccessary server-side.
1117 This may need to be changed in need_client_side_rendering() logic is altered !!! */
1118
1100 if (background_flags && (flags & isInvalid)) 1119 if (background_flags && (flags & isInvalid))
1101 { 1120 {
1102 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1121 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1103 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1122 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded))
1104 { 1123 {
1157 1176
1158 apply (); 1177 apply ();
1159 1178
1160 TIMING_TEST_PRINT_RESULT (tp); 1179 TIMING_TEST_PRINT_RESULT (tp);
1161 1180
1162 return true; 1181 return true;
1163} 1182}
1164 1183
1165bool 1184bool
1166bgPixmap_t::set_target (rxvt_term *new_target) 1185bgPixmap_t::set_target (rxvt_term *new_target)
1167{ 1186{
1168 if (new_target) 1187 if (new_target)
1169 if (target != new_target) 1188 if (target != new_target)
1170 { 1189 {
1217# if HAVE_SCROLLBARS 1236# if HAVE_SCROLLBARS
1218 if (target->scrollBar.win) 1237 if (target->scrollBar.win)
1219 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1238 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1220# endif 1239# endif
1221 } 1240 }
1222 1241 /* don't want Expose on the parent or vt. It is better to use
1223 /* don't want Expose on the parent */ 1242 scr_touch or we get a great deal of flicker otherwise: */
1224 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, False); 1243 XClearWindow (target->dpy, target->parent[0]);
1225 /* do want Expose on the vt, so we get refreshed properly */
1226 XClearArea (target->dpy, target->vt, 0, 0, 0, 0, True);
1227 1244
1228# if HAVE_SCROLLBARS 1245# if HAVE_SCROLLBARS
1229 if (target->scrollBar.win) 1246 if (target->scrollBar.win)
1230 { 1247 {
1231 target->scrollBar.setIdle (); 1248 target->scrollBar.setIdle ();
1232 target->scrollbar_show (0); 1249 target->scrollbar_show (0);
1233 } 1250 }
1234# endif 1251# endif
1235 }
1236}
1237 1252
1253 target->want_refresh = 1;
1254 flags |= hasChanged;
1255 }
1256}
1257
1238#endif /* HAVE_BG_PIXMAP */ 1258#endif /* HAVE_BG_PIXMAP */
1239 1259
1240#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1260#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT
1241/* taken from aterm-0.4.2 */ 1261/* taken from aterm-0.4.2 */
1242 1262
1243typedef uint32_t RUINT32T; 1263typedef uint32_t RUINT32T;
1244 1264
1245static void 1265static void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines