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.54 by sf-exg, Wed Sep 1 22:49:35 2010 UTC vs.
Revision 1.67 by sf-exg, Mon Oct 4 21:56:42 2010 UTC

96 // this is basically redundant as bgPixmap_t is only used in 96 // this is basically redundant as bgPixmap_t is only used in
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 HAVE_PIXBUF
102 pixbuf = NULL;
103#endif
101#ifdef BG_IMAGE_FROM_FILE 104#ifdef BG_IMAGE_FROM_FILE
102 have_image = false; 105 have_image = false;
103 h_scale = v_scale = 0; 106 h_scale = v_scale = 0;
104 h_align = v_align = 0; 107 h_align = v_align = 0;
105#endif 108#endif
115#ifdef HAVE_AFTERIMAGE 118#ifdef HAVE_AFTERIMAGE
116 if (original_asim) 119 if (original_asim)
117 safe_asimage_destroy (original_asim); 120 safe_asimage_destroy (original_asim);
118#endif 121#endif
119 122
123#ifdef HAVE_PIXBUF
124 if (pixbuf)
125 g_object_unref (pixbuf);
126#endif
127
120 if (pixmap && target) 128 if (pixmap && target)
121 XFreePixmap (target->dpy, pixmap); 129 XFreePixmap (target->dpy, pixmap);
122} 130}
123 131
124bool 132bool
130# endif 138# endif
131 139
132# ifdef BG_IMAGE_FROM_FILE 140# ifdef BG_IMAGE_FROM_FILE
133 if (have_image) 141 if (have_image)
134 { 142 {
135 if (h_scale != 0 || v_scale != 0 143 if (flags & sizeSensitive)
136 || h_align != 0 || v_align != 0)
137 return true; 144 return true;
138 } 145 }
139# endif 146# endif
140 147
141 return false; 148 return false;
150# endif 157# endif
151 158
152# ifdef BG_IMAGE_FROM_FILE 159# ifdef BG_IMAGE_FROM_FILE
153 if (have_image) 160 if (have_image)
154 { 161 {
155 if (h_align == rootAlign || v_align == rootAlign) 162 if (flags & rootAlign)
156 return true; 163 return true;
157 } 164 }
158# endif 165# endif
159 166
160 return false; 167 return false;
200static inline bool 207static inline bool
201check_set_align_value (int geom_flags, int flag, int &align, int new_value) 208check_set_align_value (int geom_flags, int flag, int &align, int new_value)
202{ 209{
203 if (geom_flags & flag) 210 if (geom_flags & flag)
204 { 211 {
205 if (new_value != bgPixmap_t::rootAlign)
206 {
207 if (new_value < -100) 212 if (new_value < -100)
208 new_value = -100; 213 new_value = -100;
209 else if (new_value > 200) 214 else if (new_value > 200)
210 new_value = 200; 215 new_value = 200;
211 }
212 if (new_value != align) 216 if (new_value != align)
213 { 217 {
214 align = new_value; 218 align = new_value;
215 return true; 219 return true;
216 } 220 }
220 224
221static inline int 225static inline int
222make_align_position (int align, int window_size, int image_size) 226make_align_position (int align, int window_size, int image_size)
223{ 227{
224 int diff = window_size - image_size; 228 int diff = window_size - image_size;
225 int smaller = MIN (image_size,window_size); 229 int smaller = min (image_size, window_size);
226 230
227 if (align >= 0 && align <= 50) 231 if (align >= 0 && align <= 100)
228 return diff * align / 100; 232 return diff * align / 100;
229 else if (align > 50 && align <= 100)
230 return window_size - image_size - diff * (100 - align) / 100;
231 else if (align > 100 && align <= 200 ) 233 else if (align > 100 && align <= 200 )
232 return ((align - 100) * smaller / 100) + window_size - smaller; 234 return ((align - 100) * smaller / 100) + window_size - smaller;
233 else if (align > -100 && align < 0) 235 else if (align >= -100 && align < 0)
234 return ((align + 100) * smaller / 100) - image_size; 236 return ((align + 100) * smaller / 100) - image_size;
235 return 0; 237 return 0;
236} 238}
237 239
238static inline int 240static inline int
239make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) 241make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size)
240{ 242{
241 int src_pos = 0; 243 int src_pos = 0;
242 dst_pos = 0; 244 dst_pos = pos;
243 dst_size = size; 245 dst_size = size;
244 if (pos < 0 && size > target_size) 246 if (pos < 0)
245 { 247 {
246 src_pos = -pos; 248 src_pos = -pos;
249 dst_pos = 0;
247 dst_size += pos; 250 dst_size += pos;
248 } 251 }
249 else if (pos > 0)
250 dst_pos = pos;
251 252
252 if (dst_pos + dst_size > target_size) 253 if (dst_pos + dst_size > target_size)
253 dst_size = target_size - dst_pos; 254 dst_size = target_size - dst_pos;
254 return src_pos; 255 return src_pos;
255} 256}
380 w = h = noScale; 381 w = h = noScale;
381 geom_flags |= WidthValue|HeightValue; 382 geom_flags |= WidthValue|HeightValue;
382 } 383 }
383 else if (CHECK_GEOM_OPS ("propscale")) 384 else if (CHECK_GEOM_OPS ("propscale"))
384 { 385 {
385 if (w == 0 && h == 0)
386 {
387 w = windowScale;
388 geom_flags |= WidthValue;
389 }
390 new_flags |= propScale; 386 new_flags |= propScale;
391 } 387 }
392 else if (CHECK_GEOM_OPS ("hscale")) 388 else if (CHECK_GEOM_OPS ("hscale"))
393 { 389 {
394 if (w == 0) w = windowScale; 390 if (w == 0) w = windowScale;
416 x = y = centerAlign; 412 x = y = centerAlign;
417 geom_flags |= WidthValue|HeightValue|XValue|YValue; 413 geom_flags |= WidthValue|HeightValue|XValue|YValue;
418 } 414 }
419 else if (CHECK_GEOM_OPS ("root")) 415 else if (CHECK_GEOM_OPS ("root"))
420 { 416 {
417 new_flags |= rootAlign;
421 w = h = noScale; 418 w = h = noScale;
422 x = y = rootAlign;
423 geom_flags |= WidthValue|HeightValue|XValue|YValue; 419 geom_flags |= WidthValue|HeightValue;
424 } 420 }
425# undef CHECK_GEOM_OPS 421# undef CHECK_GEOM_OPS
426 422
427 while (*ops != ':' && *ops != '\0') ++ops; 423 while (*ops != ':' && *ops != '\0') ++ops;
428 } /* done parsing ops */ 424 } /* done parsing ops */
441 } 437 }
442 438
443 //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", 439 //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n",
444 // flags, h_scale, v_scale, h_align, v_align); 440 // flags, h_scale, v_scale, h_align, v_align);
445 return (changed > 0); 441 return (changed > 0);
442}
443
444void
445bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y)
446{
447 int target_width = target->szHint.width;
448 int target_height = target->szHint.height;
449
450 if (flags & propScale)
451 {
452 float scale = (float)target_width / image_width;
453 min_it (scale, (float)target_height / image_height);
454 w = image_width * scale + 0.5;
455 h = image_height * scale + 0.5;
456 }
457 else
458 {
459 w = h_scale * target_width / 100;
460 h = v_scale * target_height / 100;
461 }
462
463 if (flags & rootAlign)
464 {
465 target->get_window_origin (x, y);
466 x = -x;
467 y = -y;
468 }
469 else
470 {
471 x = make_align_position (h_align, target_width, w > 0 ? w : image_width);
472 y = make_align_position (v_align, target_height, h > 0 ? h : image_height);
473 }
474
475 flags &= ~sizeSensitive;
476 if (h_scale != 0 || v_scale != 0
477 || h_align != 0 || v_align != 0
478 || image_width > target_width || image_height > target_height)
479 flags |= sizeSensitive;
446} 480}
447 481
448# ifdef HAVE_AFTERIMAGE 482# ifdef HAVE_AFTERIMAGE
449bool 483bool
450bgPixmap_t::render_image (unsigned long background_flags) 484bgPixmap_t::render_image (unsigned long background_flags)
496 int new_pmap_width = target_width; 530 int new_pmap_width = target_width;
497 int new_pmap_height = target_height; 531 int new_pmap_height = target_height;
498 532
499 int x = 0; 533 int x = 0;
500 int y = 0; 534 int y = 0;
501 int w = h_scale * target_width / 100; 535 int w = 0;
502 int h = v_scale * target_height / 100; 536 int h = 0;
503 537
504 TIMING_TEST_START (asim); 538 TIMING_TEST_START (asim);
505 539
506 if (original_asim) 540 if (original_asim)
507 { 541 get_image_geometry (original_asim->width, original_asim->height, w, h, x, y);
508 if (h_align == rootAlign || v_align == rootAlign)
509 {
510 target->get_window_origin (x, y);
511 x = -x;
512 y = -y;
513 }
514
515 if (h_align != rootAlign)
516 x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width);
517
518 if (v_align != rootAlign)
519 y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height);
520 }
521 542
522 if (!original_asim 543 if (!original_asim
544 || (!(flags & rootAlign)
523 || x >= target_width 545 && (x >= target_width
524 || y >= target_height 546 || y >= target_height
525 || (w > 0 && x + w <= 0) 547 || (w > 0 && x + w <= 0)
526 || (h > 0 && y + h <= 0)) 548 || (h > 0 && y + h <= 0))))
527 { 549 {
528 if (background) 550 if (background)
529 { 551 {
530 new_pmap_width = background->width; 552 new_pmap_width = background->width;
531 new_pmap_height = background->height; 553 new_pmap_height = background->height;
557 100, ASIMAGE_QUALITY_DEFAULT); 579 100, ASIMAGE_QUALITY_DEFAULT);
558 } 580 }
559 581
560 if (background == NULL) 582 if (background == NULL)
561 { 583 {
562 /* if tiling - pixmap has to be sized exactly as the image,
563 but there is no need to make it bigger than the window! */
564 if (h_scale == 0)
565 new_pmap_width = min (result->width, target_width);
566 if (v_scale == 0)
567 new_pmap_height = min (result->height, target_height);
568 /* we also need to tile our image in one or both directions */
569 if (h_scale == 0 || v_scale == 0) 584 if (h_scale == 0 || v_scale == 0)
570 { 585 {
586 /* if tiling - pixmap has to be sized exactly as the image,
587 but there is no need to make it bigger than the window! */
588 new_pmap_width = min (result->width, target_width);
589 new_pmap_height = min (result->height, target_height);
590
591 /* we also need to tile our image in both directions */
571 ASImage *tmp = tile_asimage (target->asv, result, 592 ASImage *tmp = tile_asimage (target->asv, result,
572 (h_scale > 0) ? 0 : (int)result->width - x, 593 (int)result->width - x,
573 (v_scale > 0) ? 0 : (int)result->height - y, 594 (int)result->height - y,
574 new_pmap_width, 595 new_pmap_width,
575 new_pmap_height, 596 new_pmap_height,
576 TINT_LEAVE_SAME, ASA_XImage, 597 TINT_LEAVE_SAME, ASA_XImage,
577 100, ASIMAGE_QUALITY_DEFAULT); 598 100, ASIMAGE_QUALITY_DEFAULT);
578 if (tmp) 599 if (tmp)
676 697
677 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; 698 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0;
678 int dst_width = result->width, dst_height = result->height; 699 int dst_width = result->width, dst_height = result->height;
679 if (background == NULL) 700 if (background == NULL)
680 { 701 {
702 if (!(h_scale == 0 || v_scale == 0))
703 {
681 if (h_scale > 0) src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width ); 704 src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width );
682 if (v_scale > 0) src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); 705 src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height);
706 }
683 707
684 if (dst_x > 0 || dst_y > 0 708 if (dst_x > 0 || dst_y > 0
685 || dst_x + dst_width < new_pmap_width 709 || dst_x + dst_width < new_pmap_width
686 || dst_y + dst_height < new_pmap_height) 710 || dst_y + dst_height < new_pmap_height)
687 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 711 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
704 destroy_asimage (&background); 728 destroy_asimage (&background);
705 729
706 return ret; 730 return ret;
707} 731}
708# endif /* HAVE_AFTERIMAGE */ 732# endif /* HAVE_AFTERIMAGE */
733
734# ifdef HAVE_PIXBUF
735bool
736bgPixmap_t::render_image (unsigned long background_flags)
737{
738 if (target == NULL)
739 return false;
740
741 if (!pixbuf)
742 return false;
743
744 // TODO: add alpha blending
745 if (background_flags)
746 return false;
747
748 GdkPixbuf *result;
749
750 int image_width = gdk_pixbuf_get_width (pixbuf);
751 int image_height = gdk_pixbuf_get_height (pixbuf);
752
753 int target_width = target->szHint.width;
754 int target_height = target->szHint.height;
755 int new_pmap_width = target_width;
756 int new_pmap_height = target_height;
757
758 int x = 0;
759 int y = 0;
760 int w = 0;
761 int h = 0;
762
763 get_image_geometry (image_width, image_height, w, h, x, y);
764
765 if (!(flags & rootAlign)
766 && (x >= target_width
767 || y >= target_height
768 || (w > 0 && x + w <= 0)
769 || (h > 0 && y + h <= 0)))
770 return false;
771
772 result = pixbuf;
773
774 if ((w > 0 && w != image_width)
775 || (h > 0 && h != image_height))
776 {
777 result = gdk_pixbuf_scale_simple (pixbuf,
778 w > 0 ? w : image_width,
779 h > 0 ? h : image_height,
780 GDK_INTERP_BILINEAR);
781 }
782
783 bool ret = false;
784
785 if (result)
786 {
787 XGCValues gcv;
788 GC gc;
789
790 image_width = gdk_pixbuf_get_width (result);
791 image_height = gdk_pixbuf_get_height (result);
792
793 if (h_scale == 0 || v_scale == 0)
794 {
795 new_pmap_width = min (image_width, target_width);
796 new_pmap_height = min (image_height, target_height);
797 }
798
799 if (pixmap)
800 {
801 if (pmap_width != new_pmap_width
802 || pmap_height != new_pmap_height
803 || pmap_depth != target->depth)
804 {
805 XFreePixmap (target->dpy, pixmap);
806 pixmap = None;
807 }
808 }
809
810 if (pixmap == None)
811 {
812 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
813 pmap_width = new_pmap_width;
814 pmap_height = new_pmap_height;
815 pmap_depth = target->depth;
816 }
817
818 gcv.foreground = target->pix_colors[Color_bg];
819 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
820
821 if (h_scale == 0 || v_scale == 0)
822 {
823 Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth);
824 gdk_pixbuf_xlib_render_to_drawable (result, tile, gc,
825 0, 0,
826 0, 0,
827 image_width, image_height,
828 XLIB_RGB_DITHER_NONE,
829 0, 0);
830
831 gcv.tile = tile;
832 gcv.fill_style = FillTiled;
833 gcv.ts_x_origin = x;
834 gcv.ts_y_origin = y;
835 XChangeGC (target->dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
836
837 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
838 XFreePixmap (target->dpy, tile);
839 }
840 else
841 {
842 int src_x, src_y, dst_x, dst_y;
843 int dst_width, dst_height;
844
845 src_x = make_clip_rectangle (x, image_width , new_pmap_width , dst_x, dst_width );
846 src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height);
847
848 if (dst_x > 0 || dst_y > 0
849 || dst_x + dst_width < new_pmap_width
850 || dst_y + dst_height < new_pmap_height)
851 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
852
853 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
854 gdk_pixbuf_xlib_render_to_drawable (result, pixmap, gc,
855 src_x, src_y,
856 dst_x, dst_y,
857 dst_width, dst_height,
858 XLIB_RGB_DITHER_NONE,
859 0, 0);
860 }
861
862 if (result != pixbuf)
863 g_object_unref (result);
864
865 XFreeGC (target->dpy, gc);
866
867 ret = true;
868 }
869
870 return ret;
871}
872# endif /* HAVE_PIXBUF */
709 873
710bool 874bool
711bgPixmap_t::set_file (const char *file) 875bgPixmap_t::set_file (const char *file)
712{ 876{
713 assert (file); 877 assert (file);
729 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); 893 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
730 if (original_asim) 894 if (original_asim)
731 have_image = true; 895 have_image = true;
732 return have_image; 896 return have_image;
733# endif 897# endif
898
899# ifdef HAVE_PIXBUF
900 pixbuf = gdk_pixbuf_new_from_file (file, NULL);
901 if (pixbuf)
902 have_image = true;
903 return have_image;
904# endif
734 } 905 }
735 906
736 return false; 907 return false;
737} 908}
738 909
873 flags = (flags & (~tintFlags | tintSet)) | new_flags; 1044 flags = (flags & (~tintFlags | tintSet)) | new_flags;
874 return true; 1045 return true;
875 } 1046 }
876 1047
877 return false; 1048 return false;
1049}
1050
1051bool
1052bgPixmap_t::tint_pixmap (Pixmap pixmap)
1053{
1054 Window root = target->display->root;
1055 Display *dpy = target->dpy;
1056 int window_width = target->szHint.width;
1057 int window_height = target->szHint.height;
1058 bool ret = false;
1059
1060 if (flags & tintWholesome)
1061 {
1062 XGCValues gcv;
1063 GC gc;
1064
1065 /* In this case we can tint image server-side getting significant
1066 * performance improvements, as we eliminate XImage transfer
1067 */
1068 gcv.foreground = Pixel (tint);
1069 gcv.function = GXand;
1070 gcv.fill_style = FillSolid;
1071 gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv);
1072 if (gc)
1073 {
1074 XFillRectangle (dpy, pixmap, gc, 0, 0, window_width, window_height);
1075 ret = true;
1076 XFreeGC (dpy, gc);
1077 }
1078 }
1079 else
1080 {
1081# if XFT
1082 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1083
1084 if (flags & tintSet)
1085 tint.get (c);
1086
1087 if (shade > 0 && shade < 100)
1088 {
1089 c.r = (c.r * shade) / 100;
1090 c.g = (c.g * shade) / 100;
1091 c.b = (c.b * shade) / 100;
1092 }
1093 else if (shade > 100 && shade < 200)
1094 {
1095 c.r = (c.r * (200 - shade)) / 100;
1096 c.g = (c.g * (200 - shade)) / 100;
1097 c.b = (c.b * (200 - shade)) / 100;
1098 }
1099
1100 XRenderPictFormat pf;
1101 pf.type = PictTypeDirect;
1102 pf.depth = 32;
1103 pf.direct.redMask = 0xff;
1104 pf.direct.greenMask = 0xff;
1105 pf.direct.blueMask = 0xff;
1106 pf.direct.alphaMask = 0xff;
1107
1108 XRenderPictFormat *solid_format = XRenderFindFormat (dpy,
1109 (PictFormatType|
1110 PictFormatDepth|
1111 PictFormatRedMask|
1112 PictFormatGreenMask|
1113 PictFormatBlueMask|
1114 PictFormatAlphaMask),
1115 &pf,
1116 0);
1117 XRenderPictFormat *root_format = XRenderFindVisualFormat (dpy, DefaultVisualOfScreen (ScreenOfDisplay (dpy, target->display->screen)));
1118 XRenderPictureAttributes pa;
1119
1120 Picture back_pic = XRenderCreatePicture (dpy, pixmap, root_format, 0, &pa);
1121
1122 pa.repeat = True;
1123
1124 Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32);
1125 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
1126 XFreePixmap (dpy, overlay_pmap);
1127
1128 pa.component_alpha = True;
1129 Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32);
1130 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa);
1131 XFreePixmap (dpy, mask_pmap);
1132
1133 if (mask_pic && overlay_pic && back_pic)
1134 {
1135 XRenderColor mask_c;
1136
1137 memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c));
1138 mask_c.alpha = 0xffff;
1139 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1140
1141 mask_c.alpha = 0;
1142 mask_c.red = 0xffff - c.r;
1143 mask_c.green = 0xffff - c.g;
1144 mask_c.blue = 0xffff - c.b;
1145 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1146 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height);
1147 ret = true;
1148 }
1149
1150 XRenderFreePicture (dpy, mask_pic);
1151 XRenderFreePicture (dpy, overlay_pic);
1152 XRenderFreePicture (dpy, back_pic);
1153# if DO_TIMING_TEST
1154 XSync (dpy, False);
1155# endif
1156# endif
1157 }
1158
1159 return ret;
878} 1160}
879 1161
880/* make_transparency_pixmap() 1162/* make_transparency_pixmap()
881 * Builds a pixmap sized the same as terminal window, with depth same as the root window 1163 * Builds a pixmap sized the same as terminal window, with depth same as the root window
882 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by 1164 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by
1012 { 1294 {
1013 if (!need_client_side_rendering ()) 1295 if (!need_client_side_rendering ())
1014 { 1296 {
1015 if ((flags & tintNeeded)) 1297 if ((flags & tintNeeded))
1016 { 1298 {
1017 if (flags & tintWholesome) 1299 if (tint_pixmap (tiled_root_pmap))
1018 {
1019 /* In this case we can tint image server-side getting significant
1020 * performance improvements, as we eliminate XImage transfer
1021 */
1022 gcv.foreground = Pixel (tint);
1023 gcv.function = GXand;
1024 gcv.fill_style = FillSolid;
1025 if (gc)
1026 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcv);
1027 else
1028 gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv);
1029 if (gc)
1030 {
1031 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
1032 result |= transpPmapTinted; 1300 result |= transpPmapTinted;
1033 }
1034 }
1035 else
1036 {
1037# if XFT
1038 Picture back_pic = 0;
1039 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1040
1041 if (flags & tintSet)
1042 tint.get (c);
1043
1044 if (shade > 0 && shade < 100)
1045 {
1046 c.r = (c.r * shade) / 100;
1047 c.g = (c.g * shade) / 100;
1048 c.b = (c.b * shade) / 100;
1049 }
1050 else if (shade > 100 && shade < 200)
1051 {
1052 c.r = (c.r * (200 - shade)) / 100;
1053 c.g = (c.g * (200 - shade)) / 100;
1054 c.b = (c.b * (200 - shade)) / 100;
1055 }
1056
1057 XRenderPictFormat pf;
1058 pf.type = PictTypeDirect;
1059 pf.depth = 32;
1060 pf.direct.redMask = 0xff;
1061 pf.direct.greenMask = 0xff;
1062 pf.direct.blueMask = 0xff;
1063 pf.direct.alphaMask = 0xff;
1064
1065 XRenderPictFormat *solid_format = XRenderFindFormat (dpy,
1066 (PictFormatType|
1067 PictFormatDepth|
1068 PictFormatRedMask|
1069 PictFormatGreenMask|
1070 PictFormatBlueMask|
1071 PictFormatAlphaMask),
1072 &pf,
1073 0);
1074 XRenderPictFormat *root_format = XRenderFindVisualFormat (dpy, DefaultVisualOfScreen (ScreenOfDisplay (dpy, target->display->screen)));
1075 XRenderPictureAttributes pa ;
1076
1077 back_pic = XRenderCreatePicture (dpy, tiled_root_pmap, root_format, 0, &pa);
1078
1079 pa.repeat = True;
1080
1081 Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32);
1082 Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa);
1083 XFreePixmap (dpy, overlay_pmap);
1084
1085 pa.component_alpha = True;
1086 Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32);
1087 Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa);
1088 XFreePixmap (dpy, mask_pmap);
1089
1090 if (mask_pic && overlay_pic && back_pic)
1091 {
1092 XRenderColor mask_c;
1093
1094 memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c));
1095 mask_c.alpha = 0xffff;
1096 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1097
1098 mask_c.alpha = 0;
1099 mask_c.red = 0xffff - c.r;
1100 mask_c.green = 0xffff - c.g;
1101 mask_c.blue = 0xffff - c.b;
1102 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1103 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height);
1104 result |= transpPmapTinted;
1105 }
1106
1107 XRenderFreePicture (dpy, mask_pic);
1108 XRenderFreePicture (dpy, overlay_pic);
1109 XRenderFreePicture (dpy, back_pic);
1110# if DO_TIMING_TEST
1111 XSync (dpy, False);
1112# endif
1113# endif
1114 }
1115 } 1301 }
1116 } /* server side rendering completed */ 1302 } /* server side rendering completed */
1117 1303
1118 if (pixmap) 1304 if (pixmap)
1119 XFreePixmap (dpy, pixmap); 1305 XFreePixmap (dpy, pixmap);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines