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.43 by sf-exg, Sun Aug 29 13:40:42 2010 UTC vs.
Revision 1.52 by sf-exg, Wed Sep 1 11:59:44 2010 UTC

97 // zero_initialised-derived structs 97 // zero_initialised-derived structs
98#ifdef HAVE_AFTERIMAGE 98#ifdef HAVE_AFTERIMAGE
99 original_asim = NULL; 99 original_asim = NULL;
100#endif 100#endif
101#ifdef BG_IMAGE_FROM_FILE 101#ifdef BG_IMAGE_FROM_FILE
102 have_image = false;
102 h_scale = v_scale = 0; 103 h_scale = v_scale = 0;
103 h_align = v_align = 0; 104 h_align = v_align = 0;
104#endif 105#endif
105 flags = 0; 106 flags = 0;
106 pixmap = None; 107 pixmap = None;
127 if (flags & isTransparent) 128 if (flags & isTransparent)
128 return true; 129 return true;
129# endif 130# endif
130 131
131# ifdef BG_IMAGE_FROM_FILE 132# ifdef BG_IMAGE_FROM_FILE
132# ifdef HAVE_AFTERIMAGE 133 if (have_image)
133 if (original_asim)
134# endif
135 { 134 {
136 if (h_scale != 0 || v_scale != 0 135 if (h_scale != 0 || v_scale != 0
137 || h_align != 0 || v_align != 0) 136 || h_align != 0 || v_align != 0)
138 return true; 137 return true;
139 } 138 }
149 if (flags & isTransparent) 148 if (flags & isTransparent)
150 return true; 149 return true;
151# endif 150# endif
152 151
153# ifdef BG_IMAGE_FROM_FILE 152# ifdef BG_IMAGE_FROM_FILE
154# ifdef HAVE_AFTERIMAGE 153 if (have_image)
155 if (original_asim)
156# endif
157 { 154 {
158 if (h_align == rootAlign || v_align == rootAlign) 155 if (h_align == rootAlign || v_align == rootAlign)
159 return true; 156 return true;
160 } 157 }
161# endif 158# endif
441 { 438 {
442 flags = new_flags; 439 flags = new_flags;
443 changed++; 440 changed++;
444 } 441 }
445 442
446//fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", 443 //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n",
447// flags, h_scale, v_scale, h_align, v_align); 444 // flags, h_scale, v_scale, h_align, v_align);
448 return (changed > 0); 445 return (changed > 0);
449} 446}
450 447
451# ifdef HAVE_AFTERIMAGE 448# ifdef HAVE_AFTERIMAGE
452bool 449bool
453bgPixmap_t::render_asim (ASImage *background, ARGB32 background_tint) 450bgPixmap_t::render_image (unsigned long background_flags)
454{ 451{
455 if (target == NULL) 452 if (target == NULL)
456 return false; 453 return false;
457 454
458 target->init_asv (); 455 target->init_asv ();
456
457 ASImage *background = NULL;
458 ARGB32 background_tint = TINT_LEAVE_SAME;
459
460# ifdef ENABLE_TRANSPARENCY
461 if (background_flags)
462 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100);
463
464 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
465 {
466 ShadingInfo as_shade;
467 as_shade.shading = (shade == 0) ? 100 : shade;
468
469 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
470 if (flags & tintSet)
471 tint.get (c);
472 as_shade.tintColor.red = c.r;
473 as_shade.tintColor.green = c.g;
474 as_shade.tintColor.blue = c.b;
475
476 background_tint = shading2tint32 (&as_shade);
477 }
478
479 if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL)
480 {
481 ASImage *tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
482 (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage,
483 100, ASIMAGE_QUALITY_DEFAULT);
484 if (tmp)
485 {
486 destroy_asimage (&background);
487 background = tmp;
488 }
489 }
490# endif
459 491
460 ASImage *result = 0; 492 ASImage *result = 0;
461 493
462 int target_width = target->szHint.width; 494 int target_width = target->szHint.width;
463 int target_height = target->szHint.height; 495 int target_height = target->szHint.height;
473 505
474 if (original_asim) 506 if (original_asim)
475 { 507 {
476 if (h_align == rootAlign || v_align == rootAlign) 508 if (h_align == rootAlign || v_align == rootAlign)
477 { 509 {
478 target->get_window_origin(x, y); 510 target->get_window_origin (x, y);
479 x = -x; 511 x = -x;
480 y = -y; 512 y = -y;
481 } 513 }
482 514
483 if (h_align != rootAlign) 515 if (h_align != rootAlign)
610 free (layers); 642 free (layers);
611 } 643 }
612 } 644 }
613 TIMING_TEST_PRINT_RESULT (asim); 645 TIMING_TEST_PRINT_RESULT (asim);
614 646
615 if (pixmap) 647 bool ret = false;
616 {
617 if (result == NULL
618 || pmap_width != new_pmap_width
619 || pmap_height != new_pmap_height
620 || pmap_depth != target->depth)
621 {
622 XFreePixmap (target->dpy, pixmap);
623 pixmap = None;
624 }
625 }
626 648
627 if (result) 649 if (result)
628 { 650 {
629 XGCValues gcv; 651 XGCValues gcv;
630 GC gc; 652 GC gc;
653
654 if (pixmap)
655 {
656 if (pmap_width != new_pmap_width
657 || pmap_height != new_pmap_height
658 || pmap_depth != target->depth)
659 {
660 XFreePixmap (target->dpy, pixmap);
661 pixmap = None;
662 }
663 }
631 664
632 /* create Pixmap */ 665 /* create Pixmap */
633 if (pixmap == None) 666 if (pixmap == None)
634 { 667 {
635 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 668 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
636 pmap_width = new_pmap_width; 669 pmap_width = new_pmap_width;
637 pmap_height = new_pmap_height; 670 pmap_height = new_pmap_height;
638 pmap_depth = target->depth; 671 pmap_depth = target->depth;
639 } 672 }
640 /* fill with background color ( if result's not completely overlapping it)*/ 673 /* fill with background color (if result's not completely overlapping it) */
641 gcv.foreground = target->pix_colors[Color_bg]; 674 gcv.foreground = target->pix_colors[Color_bg];
642 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); 675 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
643 676
644 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; 677 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0;
645 int dst_width = result->width, dst_height = result->height; 678 int dst_width = result->width, dst_height = result->height;
661 if (result != background && result != original_asim) 694 if (result != background && result != original_asim)
662 destroy_asimage (&result); 695 destroy_asimage (&result);
663 696
664 XFreeGC (target->dpy, gc); 697 XFreeGC (target->dpy, gc);
665 TIMING_TEST_PRINT_RESULT (asim); 698 TIMING_TEST_PRINT_RESULT (asim);
666 }
667 699
700 ret = true;
701 }
702
703 if (background)
704 destroy_asimage (&background);
705
668 return true; 706 return ret;
669} 707}
670# endif /* HAVE_AFTERIMAGE */ 708# endif /* HAVE_AFTERIMAGE */
671 709
672bool 710bool
673bgPixmap_t::set_file (const char *file) 711bgPixmap_t::set_file (const char *file)
674{ 712{
675 assert (file); 713 assert (file);
676 714
677 if (*file) 715 if (*file)
678 { 716 {
679# ifdef HAVE_AFTERIMAGE
680 if (!target->asimman)
681 target->asimman = create_generic_imageman (target->rs[Rs_path]);
682
683 if (const char *p = strchr (file, ';')) 717 if (const char *p = strchr (file, ';'))
684 { 718 {
685 size_t len = p - file; 719 size_t len = p - file;
686 char *f = rxvt_temp_buf<char> (len + 1); 720 char *f = rxvt_temp_buf<char> (len + 1);
687 memcpy (f, file, len); 721 memcpy (f, file, len);
688 f[len] = '\0'; 722 f[len] = '\0';
689 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100); 723 file = f;
690 } 724 }
691 else 725
726# ifdef HAVE_AFTERIMAGE
727 if (!target->asimman)
728 target->asimman = create_generic_imageman (target->rs[Rs_path]);
692 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); 729 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
693 730 if (original_asim)
694 return original_asim; 731 have_image = true;
732 return have_image;
695# endif 733# endif
696 } 734 }
697 735
698 return false; 736 return false;
699} 737}
719 int changed = 0; 757 int changed = 0;
720 unsigned int hr, vr; 758 unsigned int hr, vr;
721 int junk; 759 int junk;
722 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); 760 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
723 761
724 if (!(geom_flags&WidthValue)) 762 if (!(geom_flags & WidthValue))
725 hr = 1; 763 hr = 1;
726 if (!(geom_flags&HeightValue)) 764 if (!(geom_flags & HeightValue))
727 vr = hr; 765 vr = hr;
728 766
729 if (h_blurRadius != hr) 767 if (h_blurRadius != hr)
730 { 768 {
731 ++changed; 769 ++changed;
741 if (v_blurRadius == 0 && h_blurRadius == 0) 779 if (v_blurRadius == 0 && h_blurRadius == 0)
742 flags &= ~blurNeeded; 780 flags &= ~blurNeeded;
743 else 781 else
744 flags |= blurNeeded; 782 flags |= blurNeeded;
745 783
746 return (changed>0); 784 return (changed > 0);
747} 785}
748 786
749static inline unsigned long 787static inline unsigned long
750compute_tint_shade_flags (rxvt_color *tint, int shade) 788compute_tint_shade_flags (rxvt_color *tint, int shade)
751{ 789{
768 flags |= bgPixmap_t::tintNeeded; 806 flags |= bgPixmap_t::tintNeeded;
769 else if (tint) 807 else if (tint)
770 { 808 {
771 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) 809 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700)
772 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) 810 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700))
773 { 811 {
774 flags |= bgPixmap_t::tintNeeded; 812 flags |= bgPixmap_t::tintNeeded;
775 } 813 }
776 } 814 }
777 815
778 if (flags & bgPixmap_t::tintNeeded) 816 if (flags & bgPixmap_t::tintNeeded)
779 { 817 {
780 if (flags & bgPixmap_t::tintWholesome) 818 if (flags & bgPixmap_t::tintWholesome)
809{ 847{
810 unsigned long new_flags = compute_tint_shade_flags (NULL, shade); 848 unsigned long new_flags = compute_tint_shade_flags (NULL, shade);
811 849
812 if (new_flags != (flags & tintFlags)) 850 if (new_flags != (flags & tintFlags))
813 { 851 {
814 flags = (flags&~tintFlags)|new_flags; 852 flags = (flags & ~tintFlags) | new_flags;
815 return true; 853 return true;
816 } 854 }
817 855
818 return false; 856 return false;
819} 857}
820 858
905 943
906 attr.background_pixmap = ParentRelative; 944 attr.background_pixmap = ParentRelative;
907 attr.backing_store = Always; 945 attr.backing_store = Always;
908 attr.event_mask = ExposureMask; 946 attr.event_mask = ExposureMask;
909 attr.override_redirect = True; 947 attr.override_redirect = True;
910 src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0, 948 src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0,
911 CopyFromParent, CopyFromParent, CopyFromParent, 949 CopyFromParent, CopyFromParent, CopyFromParent,
912 CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask, 950 CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask,
913 &attr); 951 &attr);
914 952
915 if (src != None) 953 if (src != None)
939 XDestroyWindow (dpy, src); 977 XDestroyWindow (dpy, src);
940 XUngrabServer (dpy); 978 XUngrabServer (dpy);
941 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); 979 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count);
942 } 980 }
943 981
944 if (!success) 982 if (!success)
945 { 983 {
946 XFreePixmap (dpy, tiled_root_pmap); 984 XFreePixmap (dpy, tiled_root_pmap);
947 tiled_root_pmap = None; 985 tiled_root_pmap = None;
948 } 986 }
949 else 987 else
950 result |= transpPmapTiled; 988 result |= transpPmapTiled;
951 } 989 }
952 else 990 else
953 { 991 {
954 /* straightforward pixmap copy */ 992 /* straightforward pixmap copy */
955 gcv.tile = root_pixmap; 993 gcv.tile = root_pixmap;
1072# if DO_TIMING_TEST 1110# if DO_TIMING_TEST
1073 XSync (dpy, False); 1111 XSync (dpy, False);
1074# endif 1112# endif
1075# endif 1113# endif
1076 } 1114 }
1077 } 1115 }
1078 } /* server side rendering completed */ 1116 } /* server side rendering completed */
1079 1117
1080 if (pixmap) 1118 if (pixmap)
1081 XFreePixmap (dpy, pixmap); 1119 XFreePixmap (dpy, pixmap);
1082 1120
1132 /* we need to re-generate transparency pixmap in that case ! */ 1170 /* we need to re-generate transparency pixmap in that case ! */
1133 background_flags = make_transparency_pixmap (); 1171 background_flags = make_transparency_pixmap ();
1134 if (background_flags == 0) 1172 if (background_flags == 0)
1135 return false; 1173 return false;
1136 else if ((background_flags & transpTransformations) == (flags & transpTransformations) 1174 else if ((background_flags & transpTransformations) == (flags & transpTransformations)
1137 && pmap_depth == target->depth) 1175 && pmap_depth == target->depth)
1138 flags = flags & ~isInvalid; 1176 flags = flags & ~isInvalid;
1139 } 1177 }
1140# endif 1178# endif
1141 1179
1180# ifdef BG_IMAGE_FROM_FILE
1181 if (have_image
1182 || (background_flags & transpTransformations) != (flags & transpTransformations))
1183 {
1184 if (render_image (background_flags))
1185 flags = flags & ~isInvalid;
1186 }
1187# endif
1188
1142 XImage *result = NULL; 1189 XImage *result = NULL;
1143# ifdef HAVE_AFTERIMAGE
1144 if (original_asim
1145 || (background_flags & transpTransformations) != (flags & transpTransformations))
1146 {
1147 target->init_asv ();
1148
1149 ASImage *background = NULL;
1150 ARGB32 as_tint = TINT_LEAVE_SAME;
1151 if (background_flags)
1152 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100);
1153
1154# ifdef ENABLE_TRANSPARENCY
1155 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
1156 {
1157 ShadingInfo as_shade;
1158 as_shade.shading = (shade == 0) ? 100 : shade;
1159
1160 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1161 if (flags & tintSet)
1162 tint.get (c);
1163 as_shade.tintColor.red = c.r;
1164 as_shade.tintColor.green = c.g;
1165 as_shade.tintColor.blue = c.b;
1166
1167 as_tint = shading2tint32 (&as_shade);
1168 }
1169
1170 if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL)
1171 {
1172 ASImage *tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
1173 (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage,
1174 100, ASIMAGE_QUALITY_DEFAULT);
1175 if (tmp)
1176 {
1177 destroy_asimage (&background);
1178 background = tmp;
1179 }
1180 }
1181# endif
1182
1183 if (render_asim (background, as_tint))
1184 flags = flags & ~isInvalid;
1185 if (background)
1186 destroy_asimage (&background);
1187 }
1188 else if (background_flags && pmap_depth != target->depth)
1189 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1190
1191# elif !XFT /* our own client-side tinting */
1192
1193 /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side.
1194 This may need to be changed in need_client_side_rendering() logic is altered !!! */
1195 1190
1196 if (background_flags && (flags & isInvalid)) 1191 if (background_flags && (flags & isInvalid))
1197 { 1192 {
1198 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1193 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1199 1194
1195# if !defined(HAVE_AFTERIMAGE) && !XFT
1196 /* our own client-side tinting */
1197 /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side.
1198 This may need to be changed in need_client_side_rendering() logic is altered !!! */
1200 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1199 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded))
1201 { 1200 {
1202 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1201 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1203 if (flags & tintSet) 1202 if (flags & tintSet)
1204 tint.get (c); 1203 tint.get (c);
1205 ShadeXImage (target, result, shade, c.r, c.g, c.b); 1204 ShadeXImage (target, result, shade, c.r, c.g, c.b);
1206 } 1205 }
1206# endif
1207 } 1207 }
1208# endif /* HAVE_AFTERIMAGE */
1209 1208
1210 if (result) 1209 if (result)
1211 { 1210 {
1212 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1211 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1213 1212
1245 1244
1246 XFreeGC (target->dpy, gc); 1245 XFreeGC (target->dpy, gc);
1247 flags = flags & ~isInvalid; 1246 flags = flags & ~isInvalid;
1248 } 1247 }
1249 1248
1250 XDestroyImage (result); 1249 XDestroyImage (result);
1251 } 1250 }
1252 1251
1253 if (flags & isInvalid) 1252 if (flags & isInvalid)
1254 { 1253 {
1255 if (pixmap != None) 1254 if (pixmap != None)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines