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.58 by sf-exg, Fri Sep 3 22:57:31 2010 UTC vs.
Revision 1.79 by sf-exg, Wed Oct 13 23:01:40 2010 UTC

104#ifdef BG_IMAGE_FROM_FILE 104#ifdef BG_IMAGE_FROM_FILE
105 have_image = false; 105 have_image = false;
106 h_scale = v_scale = 0; 106 h_scale = v_scale = 0;
107 h_align = v_align = 0; 107 h_align = v_align = 0;
108#endif 108#endif
109#ifdef ENABLE_TRANSPARENCY
110 shade = 100;
111#endif
109 flags = 0; 112 flags = 0;
110 pixmap = None; 113 pixmap = None;
111 valid_since = invalid_since = 0; 114 valid_since = invalid_since = 0;
112 target = 0; 115 target = 0;
113} 116}
138# endif 141# endif
139 142
140# ifdef BG_IMAGE_FROM_FILE 143# ifdef BG_IMAGE_FROM_FILE
141 if (have_image) 144 if (have_image)
142 { 145 {
143 if (h_scale != 0 || v_scale != 0 146 if (flags & sizeSensitive)
144 || h_align != 0 || v_align != 0)
145 return true; 147 return true;
146 } 148 }
147# endif 149# endif
148 150
149 return false; 151 return false;
158# endif 160# endif
159 161
160# ifdef BG_IMAGE_FROM_FILE 162# ifdef BG_IMAGE_FROM_FILE
161 if (have_image) 163 if (have_image)
162 { 164 {
163 if (h_align == rootAlign || v_align == rootAlign) 165 if (flags & rootAlign)
164 return true; 166 return true;
165 } 167 }
166# endif 168# endif
167 169
168 return false; 170 return false;
208static inline bool 210static inline bool
209check_set_align_value (int geom_flags, int flag, int &align, int new_value) 211check_set_align_value (int geom_flags, int flag, int &align, int new_value)
210{ 212{
211 if (geom_flags & flag) 213 if (geom_flags & flag)
212 { 214 {
213 if (new_value != bgPixmap_t::rootAlign)
214 {
215 if (new_value < -100) 215 if (new_value < -100)
216 new_value = -100; 216 new_value = -100;
217 else if (new_value > 200) 217 else if (new_value > 200)
218 new_value = 200; 218 new_value = 200;
219 }
220 if (new_value != align) 219 if (new_value != align)
221 { 220 {
222 align = new_value; 221 align = new_value;
223 return true; 222 return true;
224 } 223 }
230make_align_position (int align, int window_size, int image_size) 229make_align_position (int align, int window_size, int image_size)
231{ 230{
232 int diff = window_size - image_size; 231 int diff = window_size - image_size;
233 int smaller = min (image_size, window_size); 232 int smaller = min (image_size, window_size);
234 233
235 if (align >= 0 && align <= 50) 234 if (align >= 0 && align <= 100)
236 return diff * align / 100; 235 return diff * align / 100;
237 else if (align > 50 && align <= 100)
238 return window_size - image_size - diff * (100 - align) / 100;
239 else if (align > 100 && align <= 200 ) 236 else if (align > 100 && align <= 200 )
240 return ((align - 100) * smaller / 100) + window_size - smaller; 237 return ((align - 100) * smaller / 100) + window_size - smaller;
241 else if (align > -100 && align < 0) 238 else if (align >= -100 && align < 0)
242 return ((align + 100) * smaller / 100) - image_size; 239 return ((align + 100) * smaller / 100) - image_size;
243 return 0; 240 return 0;
244} 241}
245 242
246static inline int 243static inline int
247make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) 244make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size)
248{ 245{
249 int src_pos = 0; 246 int src_pos = 0;
250 dst_pos = 0; 247 dst_pos = pos;
251 dst_size = size; 248 dst_size = size;
252 if (pos < 0 && size > target_size) 249 if (pos < 0)
253 { 250 {
254 src_pos = -pos; 251 src_pos = -pos;
252 dst_pos = 0;
255 dst_size += pos; 253 dst_size += pos;
256 } 254 }
257 else if (pos > 0)
258 dst_pos = pos;
259 255
260 if (dst_pos + dst_size > target_size) 256 if (dst_pos + dst_size > target_size)
261 dst_size = target_size - dst_pos; 257 dst_size = target_size - dst_pos;
262 return src_pos; 258 return src_pos;
263} 259}
388 w = h = noScale; 384 w = h = noScale;
389 geom_flags |= WidthValue|HeightValue; 385 geom_flags |= WidthValue|HeightValue;
390 } 386 }
391 else if (CHECK_GEOM_OPS ("propscale")) 387 else if (CHECK_GEOM_OPS ("propscale"))
392 { 388 {
393 if (w == 0 && h == 0)
394 {
395 w = windowScale;
396 geom_flags |= WidthValue;
397 }
398 new_flags |= propScale; 389 new_flags |= propScale;
399 } 390 }
400 else if (CHECK_GEOM_OPS ("hscale")) 391 else if (CHECK_GEOM_OPS ("hscale"))
401 { 392 {
402 if (w == 0) w = windowScale; 393 if (w == 0) w = windowScale;
424 x = y = centerAlign; 415 x = y = centerAlign;
425 geom_flags |= WidthValue|HeightValue|XValue|YValue; 416 geom_flags |= WidthValue|HeightValue|XValue|YValue;
426 } 417 }
427 else if (CHECK_GEOM_OPS ("root")) 418 else if (CHECK_GEOM_OPS ("root"))
428 { 419 {
420 new_flags |= rootAlign;
429 w = h = noScale; 421 w = h = noScale;
430 x = y = rootAlign;
431 geom_flags |= WidthValue|HeightValue|XValue|YValue; 422 geom_flags |= WidthValue|HeightValue;
432 } 423 }
433# undef CHECK_GEOM_OPS 424# undef CHECK_GEOM_OPS
434 425
435 while (*ops != ':' && *ops != '\0') ++ops; 426 while (*ops != ':' && *ops != '\0') ++ops;
436 } /* done parsing ops */ 427 } /* done parsing ops */
451 //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", 442 //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n",
452 // flags, h_scale, v_scale, h_align, v_align); 443 // flags, h_scale, v_scale, h_align, v_align);
453 return (changed > 0); 444 return (changed > 0);
454} 445}
455 446
447void
448bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y)
449{
450 int target_width = target->szHint.width;
451 int target_height = target->szHint.height;
452
453 if (flags & propScale)
454 {
455 float scale = (float)target_width / image_width;
456 min_it (scale, (float)target_height / image_height);
457 w = image_width * scale + 0.5;
458 h = image_height * scale + 0.5;
459 }
460 else
461 {
462 w = h_scale * target_width / 100;
463 h = v_scale * target_height / 100;
464 }
465
466 if (!w) w = image_width;
467 if (!h) h = image_height;
468
469 if (flags & rootAlign)
470 {
471 target->get_window_origin (x, y);
472 x = -x;
473 y = -y;
474 }
475 else
476 {
477 x = make_align_position (h_align, target_width, w);
478 y = make_align_position (v_align, target_height, h);
479 }
480
481 flags &= ~sizeSensitive;
482 if (h_scale != 0 || v_scale != 0
483 || h_align != 0 || v_align != 0
484 || w > target_width || h > target_height)
485 flags |= sizeSensitive;
486}
487
456# ifdef HAVE_AFTERIMAGE 488# ifdef HAVE_AFTERIMAGE
457bool 489bool
458bgPixmap_t::render_image (unsigned long background_flags) 490bgPixmap_t::render_image (unsigned long background_flags)
459{ 491{
460 if (target == NULL) 492 if (target == NULL)
470 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100); 502 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100);
471 503
472 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 504 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
473 { 505 {
474 ShadingInfo as_shade; 506 ShadingInfo as_shade;
475 as_shade.shading = (shade == 0) ? 100 : shade; 507 as_shade.shading = shade;
476 508
477 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 509 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
478 if (flags & tintSet) 510 if (flags & tintSet)
479 tint.get (c); 511 tint.get (c);
480 as_shade.tintColor.red = c.r; 512 as_shade.tintColor.red = c.r;
482 as_shade.tintColor.blue = c.b; 514 as_shade.tintColor.blue = c.b;
483 515
484 background_tint = shading2tint32 (&as_shade); 516 background_tint = shading2tint32 (&as_shade);
485 } 517 }
486 518
487 if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL) 519 if (!(background_flags & transpPmapBlurred) && (flags & blurNeeded) && background != NULL)
488 { 520 {
489 ASImage *tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, 521 ASImage *tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
490 (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage, 522 (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage,
491 100, ASIMAGE_QUALITY_DEFAULT); 523 100, ASIMAGE_QUALITY_DEFAULT);
492 if (tmp) 524 if (tmp)
504 int new_pmap_width = target_width; 536 int new_pmap_width = target_width;
505 int new_pmap_height = target_height; 537 int new_pmap_height = target_height;
506 538
507 int x = 0; 539 int x = 0;
508 int y = 0; 540 int y = 0;
509 int w = h_scale * target_width / 100; 541 int w = 0;
510 int h = v_scale * target_height / 100; 542 int h = 0;
511 543
512 TIMING_TEST_START (asim); 544 TIMING_TEST_START (asim);
513 545
514 if (original_asim) 546 if (original_asim)
515 { 547 get_image_geometry (original_asim->width, original_asim->height, w, h, x, y);
516 if (h_align == rootAlign || v_align == rootAlign)
517 {
518 target->get_window_origin (x, y);
519 x = -x;
520 y = -y;
521 }
522
523 if (h_align != rootAlign)
524 x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width);
525
526 if (v_align != rootAlign)
527 y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height);
528 }
529 548
530 if (!original_asim 549 if (!original_asim
550 || (!(flags & rootAlign)
531 || x >= target_width 551 && (x >= target_width
532 || y >= target_height 552 || y >= target_height
533 || (w > 0 && x + w <= 0) 553 || (x + w <= 0)
534 || (h > 0 && y + h <= 0)) 554 || (y + h <= 0))))
535 { 555 {
536 if (background) 556 if (background)
537 { 557 {
538 new_pmap_width = background->width; 558 new_pmap_width = background->width;
539 new_pmap_height = background->height; 559 new_pmap_height = background->height;
553 } 573 }
554 else 574 else
555 { 575 {
556 result = original_asim; 576 result = original_asim;
557 577
558 if ((w > 0 && w != original_asim->width) 578 if ((w != original_asim->width)
559 || (h > 0 && h != original_asim->height)) 579 || (h != original_asim->height))
560 { 580 {
561 result = scale_asimage (target->asv, original_asim, 581 result = scale_asimage (target->asv, original_asim,
562 w > 0 ? w : original_asim->width, 582 w, h,
563 h > 0 ? h : original_asim->height,
564 background ? ASA_ASImage : ASA_XImage, 583 background ? ASA_ASImage : ASA_XImage,
565 100, ASIMAGE_QUALITY_DEFAULT); 584 100, ASIMAGE_QUALITY_DEFAULT);
566 } 585 }
567 586
568 if (background == NULL) 587 if (background == NULL)
600 layers[0].clip_width = target_width; 619 layers[0].clip_width = target_width;
601 layers[0].clip_height = target_height; 620 layers[0].clip_height = target_height;
602 layers[0].tint = background_tint; 621 layers[0].tint = background_tint;
603 layers[1].im = result; 622 layers[1].im = result;
604 623
605 if (w <= 0) 624 if (h_scale == 0 || v_scale == 0)
606 { 625 {
607 /* tile horizontally */ 626 /* tile horizontally */
608 while (x > 0) x -= (int)result->width; 627 while (x > 0) x -= (int)result->width;
609 layers[1].dst_x = x; 628 layers[1].dst_x = x;
610 layers[1].clip_width = result->width+target_width; 629 layers[1].clip_width = result->width+target_width;
614 /* clip horizontally */ 633 /* clip horizontally */
615 layers[1].dst_x = x; 634 layers[1].dst_x = x;
616 layers[1].clip_width = result->width; 635 layers[1].clip_width = result->width;
617 } 636 }
618 637
619 if (h <= 0) 638 if (h_scale == 0 || v_scale == 0)
620 { 639 {
621 while (y > 0) y -= (int)result->height; 640 while (y > 0) y -= (int)result->height;
622 layers[1].dst_y = y; 641 layers[1].dst_y = y;
623 layers[1].clip_height = result->height + target_height; 642 layers[1].clip_height = result->height + target_height;
624 } 643 }
725 return false; 744 return false;
726 745
727 if (!pixbuf) 746 if (!pixbuf)
728 return false; 747 return false;
729 748
730 // TODO: add alpha blending 749#if !XFT
731 if (background_flags) 750 if (background_flags)
732 return false; 751 return false;
752#endif
733 753
734 GdkPixbuf *result; 754 GdkPixbuf *result;
735 755
736 int image_width = gdk_pixbuf_get_width (pixbuf); 756 int image_width = gdk_pixbuf_get_width (pixbuf);
737 int image_height = gdk_pixbuf_get_height (pixbuf); 757 int image_height = gdk_pixbuf_get_height (pixbuf);
741 int new_pmap_width = target_width; 761 int new_pmap_width = target_width;
742 int new_pmap_height = target_height; 762 int new_pmap_height = target_height;
743 763
744 int x = 0; 764 int x = 0;
745 int y = 0; 765 int y = 0;
746 int w = h_scale * target_width / 100; 766 int w = 0;
747 int h = v_scale * target_height / 100; 767 int h = 0;
748 768
749 if (h_align == rootAlign || v_align == rootAlign) 769 get_image_geometry (image_width, image_height, w, h, x, y);
750 {
751 target->get_window_origin (x, y);
752 x = -x;
753 y = -y;
754 }
755 770
756 if (h_align != rootAlign) 771 if (!(flags & rootAlign)
757 x = make_align_position (h_align, target_width, w > 0 ? w : image_width);
758
759 if (v_align != rootAlign)
760 y = make_align_position (v_align, target_height, h > 0 ? h : image_height);
761
762 if (x >= target_width 772 && (x >= target_width
763 || y >= target_height 773 || y >= target_height
764 || (w > 0 && x + w <= 0) 774 || (x + w <= 0)
765 || (h > 0 && y + h <= 0)) 775 || (y + h <= 0)))
766 return false; 776 return false;
767 777
768 result = pixbuf; 778 result = pixbuf;
769 779
770 if ((w > 0 && w != image_width) 780 if ((w != image_width)
771 || (h > 0 && h != image_height)) 781 || (h != image_height))
772 { 782 {
773 result = gdk_pixbuf_scale_simple (pixbuf, 783 result = gdk_pixbuf_scale_simple (pixbuf,
774 w > 0 ? w : image_width, 784 w, h,
775 h > 0 ? h : image_height,
776 GDK_INTERP_BILINEAR); 785 GDK_INTERP_BILINEAR);
777 } 786 }
778 787
779 bool ret = false; 788 bool ret = false;
780 789
781 if (result) 790 if (result)
782 { 791 {
783 XGCValues gcv; 792 XGCValues gcv;
784 GC gc; 793 GC gc;
794 Pixmap root_pmap;
785 795
786 image_width = gdk_pixbuf_get_width (result); 796 image_width = gdk_pixbuf_get_width (result);
787 image_height = gdk_pixbuf_get_height (result); 797 image_height = gdk_pixbuf_get_height (result);
788 798
799 if (background_flags)
800 {
801 root_pmap = pixmap;
802 pixmap = None;
803 }
804 else
805 {
789 if (h_scale == 0 || v_scale == 0) 806 if (h_scale == 0 || v_scale == 0)
790 { 807 {
791 new_pmap_width = min (image_width, target_width); 808 new_pmap_width = min (image_width, target_width);
792 new_pmap_height = min (image_height, target_height); 809 new_pmap_height = min (image_height, target_height);
810 }
793 } 811 }
794 812
795 if (pixmap) 813 if (pixmap)
796 { 814 {
797 if (pmap_width != new_pmap_width 815 if (pmap_width != new_pmap_width
852 dst_x, dst_y, 870 dst_x, dst_y,
853 dst_width, dst_height, 871 dst_width, dst_height,
854 XLIB_RGB_DITHER_NONE, 872 XLIB_RGB_DITHER_NONE,
855 0, 0); 873 0, 0);
856 } 874 }
875
876#if XFT
877 if (background_flags)
878 {
879 Display *dpy = target->dpy;
880 XRenderPictureAttributes pa;
881
882 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, target->display->screen));
883 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa);
884
885 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual);
886 Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa);
887
888 pa.repeat = True;
889 Pixmap mask_pmap = XCreatePixmap (dpy, target->vt, 1, 1, 8);
890 XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8);
891 Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa);
892 XFreePixmap (dpy, mask_pmap);
893
894 if (src && dst && mask)
895 {
896 XRenderColor mask_c;
897
898 mask_c.alpha = 0x8000;
899 mask_c.red = 0;
900 mask_c.green = 0;
901 mask_c.blue = 0;
902 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1);
903 XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height);
904 }
905
906 XRenderFreePicture (dpy, src);
907 XRenderFreePicture (dpy, dst);
908 XRenderFreePicture (dpy, mask);
909
910 XFreePixmap (dpy, root_pmap);
911 }
912#endif
857 913
858 if (result != pixbuf) 914 if (result != pixbuf)
859 g_object_unref (result); 915 g_object_unref (result);
860 916
861 XFreeGC (target->dpy, gc); 917 XFreeGC (target->dpy, gc);
954static inline unsigned long 1010static inline unsigned long
955compute_tint_shade_flags (rxvt_color *tint, int shade) 1011compute_tint_shade_flags (rxvt_color *tint, int shade)
956{ 1012{
957 unsigned long flags = 0; 1013 unsigned long flags = 0;
958 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1014 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
959 bool has_shade = (shade > 0 && shade < 100) || (shade > 100 && shade < 200); 1015 bool has_shade = shade != 100;
960 1016
961 if (tint) 1017 if (tint)
962 { 1018 {
963 tint->get (c); 1019 tint->get (c);
964# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700) 1020# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700)
996} 1052}
997 1053
998bool 1054bool
999bgPixmap_t::set_tint (rxvt_color &new_tint) 1055bgPixmap_t::set_tint (rxvt_color &new_tint)
1000{ 1056{
1001 if (tint != new_tint) 1057 if (!(flags & tintSet) || tint != new_tint)
1002 { 1058 {
1003 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); 1059 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade);
1004 tint = new_tint; 1060 tint = new_tint;
1005 flags = (flags & ~tintFlags) | new_flags | tintSet; 1061 flags = (flags & ~tintFlags) | new_flags | tintSet;
1006 return true; 1062 return true;
1024} 1080}
1025 1081
1026bool 1082bool
1027bgPixmap_t::set_shade (const char *shade_str) 1083bgPixmap_t::set_shade (const char *shade_str)
1028{ 1084{
1029 int new_shade = (shade_str) ? atoi (shade_str) : 0; 1085 int new_shade = (shade_str) ? atoi (shade_str) : 100;
1030 1086
1031 if (new_shade < 0 && new_shade > -100) 1087 clamp_it (new_shade, -100, 200);
1088 if (new_shade < 0)
1032 new_shade = 200 - (100 + new_shade); 1089 new_shade = 200 - (100 + new_shade);
1033 else if (new_shade == 100)
1034 new_shade = 0;
1035 1090
1036 if (new_shade != shade) 1091 if (new_shade != shade)
1037 { 1092 {
1038 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); 1093 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade);
1039 shade = new_shade; 1094 shade = new_shade;
1040 flags = (flags & (~tintFlags | tintSet)) | new_flags; 1095 flags = (flags & (~tintFlags | tintSet)) | new_flags;
1041 return true; 1096 return true;
1042 } 1097 }
1043 1098
1044 return false; 1099 return false;
1100}
1101
1102bool
1103bgPixmap_t::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height)
1104{
1105 Display *dpy = target->dpy;
1106 bool ret = false;
1107
1108 if (flags & tintWholesome)
1109 {
1110 XGCValues gcv;
1111 GC gc;
1112
1113 /* In this case we can tint image server-side getting significant
1114 * performance improvements, as we eliminate XImage transfer
1115 */
1116 gcv.foreground = Pixel (tint);
1117 gcv.function = GXand;
1118 gcv.fill_style = FillSolid;
1119 gc = XCreateGC (dpy, pixmap, GCFillStyle | GCForeground | GCFunction, &gcv);
1120 if (gc)
1121 {
1122 XFillRectangle (dpy, pixmap, gc, 0, 0, width, height);
1123 ret = true;
1124 XFreeGC (dpy, gc);
1125 }
1126 }
1127 else
1128 {
1129# if XFT
1130 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1131
1132 if (flags & tintSet)
1133 tint.get (c);
1134
1135 if (shade <= 100)
1136 {
1137 c.r = (c.r * shade) / 100;
1138 c.g = (c.g * shade) / 100;
1139 c.b = (c.b * shade) / 100;
1140 }
1141 else
1142 {
1143 c.r = ((0xffff - c.r) * (200 - shade)) / 100;
1144 c.g = ((0xffff - c.g) * (200 - shade)) / 100;
1145 c.b = ((0xffff - c.b) * (200 - shade)) / 100;
1146 }
1147
1148 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
1149 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1150 XRenderPictureAttributes pa;
1151
1152 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1153
1154 pa.repeat = True;
1155
1156 Pixmap overlay_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32);
1157 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
1158 XFreePixmap (dpy, overlay_pmap);
1159
1160 pa.component_alpha = True;
1161 Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32);
1162 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa);
1163 XFreePixmap (dpy, mask_pmap);
1164
1165 if (mask_pic && overlay_pic && back_pic)
1166 {
1167 XRenderColor mask_c;
1168
1169 memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c));
1170 mask_c.alpha = 0xffff;
1171 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1172
1173 mask_c.alpha = 0;
1174 mask_c.red = 0xffff - c.r;
1175 mask_c.green = 0xffff - c.g;
1176 mask_c.blue = 0xffff - c.b;
1177 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1178 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1179 ret = true;
1180 }
1181
1182 XRenderFreePicture (dpy, mask_pic);
1183 XRenderFreePicture (dpy, overlay_pic);
1184 XRenderFreePicture (dpy, back_pic);
1185# if DO_TIMING_TEST
1186 XSync (dpy, False);
1187# endif
1188# endif
1189 }
1190
1191 return ret;
1045} 1192}
1046 1193
1047/* make_transparency_pixmap() 1194/* make_transparency_pixmap()
1048 * Builds a pixmap sized the same as terminal window, with depth same as the root window 1195 * Builds a pixmap sized the same as terminal window, with depth same as the root window
1049 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by 1196 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by
1079 || sx >= root_width || sy >= root_height) 1226 || sx >= root_width || sy >= root_height)
1080 return 0; 1227 return 0;
1081 1228
1082 if (root_pixmap != None) 1229 if (root_pixmap != None)
1083 { 1230 {
1084 /* we want to validate the pixmap and get it's size at the same time : */ 1231 /* we want to validate the pixmap and get its size at the same time : */
1085 int junk; 1232 int junk;
1086 unsigned int ujunk; 1233 unsigned int ujunk;
1087 /* root pixmap may be bad - allow a error */ 1234 /* root pixmap may be bad - allow a error */
1088 target->allowedxerror = -1; 1235 target->allowedxerror = -1;
1089 1236
1179 { 1326 {
1180 if (!need_client_side_rendering ()) 1327 if (!need_client_side_rendering ())
1181 { 1328 {
1182 if ((flags & tintNeeded)) 1329 if ((flags & tintNeeded))
1183 { 1330 {
1184 if (flags & tintWholesome) 1331 if (tint_pixmap (tiled_root_pmap, DefaultVisual (dpy, target->display->screen), window_width, window_height))
1185 {
1186 /* In this case we can tint image server-side getting significant
1187 * performance improvements, as we eliminate XImage transfer
1188 */
1189 gcv.foreground = Pixel (tint);
1190 gcv.function = GXand;
1191 gcv.fill_style = FillSolid;
1192 if (gc)
1193 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcv);
1194 else
1195 gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv);
1196 if (gc)
1197 {
1198 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
1199 result |= transpPmapTinted; 1332 result |= transpPmapTinted;
1200 }
1201 }
1202 else
1203 {
1204# if XFT
1205 Picture back_pic = 0;
1206 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1207
1208 if (flags & tintSet)
1209 tint.get (c);
1210
1211 if (shade > 0 && shade < 100)
1212 {
1213 c.r = (c.r * shade) / 100;
1214 c.g = (c.g * shade) / 100;
1215 c.b = (c.b * shade) / 100;
1216 }
1217 else if (shade > 100 && shade < 200)
1218 {
1219 c.r = (c.r * (200 - shade)) / 100;
1220 c.g = (c.g * (200 - shade)) / 100;
1221 c.b = (c.b * (200 - shade)) / 100;
1222 }
1223
1224 XRenderPictFormat pf;
1225 pf.type = PictTypeDirect;
1226 pf.depth = 32;
1227 pf.direct.redMask = 0xff;
1228 pf.direct.greenMask = 0xff;
1229 pf.direct.blueMask = 0xff;
1230 pf.direct.alphaMask = 0xff;
1231
1232 XRenderPictFormat *solid_format = XRenderFindFormat (dpy,
1233 (PictFormatType|
1234 PictFormatDepth|
1235 PictFormatRedMask|
1236 PictFormatGreenMask|
1237 PictFormatBlueMask|
1238 PictFormatAlphaMask),
1239 &pf,
1240 0);
1241 XRenderPictFormat *root_format = XRenderFindVisualFormat (dpy, DefaultVisualOfScreen (ScreenOfDisplay (dpy, target->display->screen)));
1242 XRenderPictureAttributes pa ;
1243
1244 back_pic = XRenderCreatePicture (dpy, tiled_root_pmap, root_format, 0, &pa);
1245
1246 pa.repeat = True;
1247
1248 Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32);
1249 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
1250 XFreePixmap (dpy, overlay_pmap);
1251
1252 pa.component_alpha = True;
1253 Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32);
1254 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa);
1255 XFreePixmap (dpy, mask_pmap);
1256
1257 if (mask_pic && overlay_pic && back_pic)
1258 {
1259 XRenderColor mask_c;
1260
1261 memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c));
1262 mask_c.alpha = 0xffff;
1263 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1264
1265 mask_c.alpha = 0;
1266 mask_c.red = 0xffff - c.r;
1267 mask_c.green = 0xffff - c.g;
1268 mask_c.blue = 0xffff - c.b;
1269 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1270 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height);
1271 result |= transpPmapTinted;
1272 }
1273
1274 XRenderFreePicture (dpy, mask_pic);
1275 XRenderFreePicture (dpy, overlay_pic);
1276 XRenderFreePicture (dpy, back_pic);
1277# if DO_TIMING_TEST
1278 XSync (dpy, False);
1279# endif
1280# endif
1281 }
1282 } 1333 }
1283 } /* server side rendering completed */ 1334 } /* server side rendering completed */
1284 1335
1285 if (pixmap) 1336 if (pixmap)
1286 XFreePixmap (dpy, pixmap); 1337 XFreePixmap (dpy, pixmap);
1526 int i; 1577 int i;
1527 1578
1528 Visual *visual = term->visual; 1579 Visual *visual = term->visual;
1529 1580
1530 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ; 1581 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ;
1531
1532 if (shade == 0)
1533 shade = 100;
1534 1582
1535 /* for convenience */ 1583 /* for convenience */
1536 mask_r = visual->red_mask; 1584 mask_r = visual->red_mask;
1537 mask_g = visual->green_mask; 1585 mask_g = visual->green_mask;
1538 mask_b = visual->blue_mask; 1586 mask_b = visual->blue_mask;
1594 default: 1642 default:
1595 return; /* we do not support this color depth */ 1643 return; /* we do not support this color depth */
1596 } 1644 }
1597 1645
1598 /* prepare limits for color transformation (each channel is handled separately) */ 1646 /* prepare limits for color transformation (each channel is handled separately) */
1599 if (shade < 0) { 1647 if (shade > 100) {
1600 shade = -shade; 1648 shade = 200 - shade;
1601 if (shade < 0) shade = 0;
1602 if (shade > 100) shade = 100;
1603 1649
1604 lower_lim_r = 65535-rm; 1650 lower_lim_r = 65535-rm;
1605 lower_lim_g = 65535-gm; 1651 lower_lim_g = 65535-gm;
1606 lower_lim_b = 65535-bm; 1652 lower_lim_b = 65535-bm;
1607 1653
1609 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100); 1655 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100);
1610 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100); 1656 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100);
1611 1657
1612 upper_lim_r = upper_lim_g = upper_lim_b = 65535; 1658 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
1613 } else { 1659 } else {
1614 if (shade < 0) shade = 0;
1615 if (shade > 100) shade = 100;
1616 1660
1617 lower_lim_r = lower_lim_g = lower_lim_b = 0; 1661 lower_lim_r = lower_lim_g = lower_lim_b = 0;
1618 1662
1619 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100); 1663 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100);
1620 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100); 1664 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines