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.120 by sf-exg, Thu Nov 18 17:29:25 2010 UTC vs.
Revision 1.136 by sf-exg, Fri Jan 14 17:06:04 2011 UTC

30# include <X11/extensions/Xrender.h> 30# include <X11/extensions/Xrender.h>
31#endif 31#endif
32 32
33#ifndef FilterConvolution 33#ifndef FilterConvolution
34#define FilterConvolution "convolution" 34#define FilterConvolution "convolution"
35#endif
36
37#define DO_TIMING_TEST 0
38
39#if DO_TIMING_TEST
40# include <sys/time.h>
41#define TIMING_TEST_START(id) \
42 struct timeval timing_test_##id##_stv; \
43 gettimeofday (&timing_test_##id##_stv, NULL);
44
45#define TIMING_TEST_PRINT_RESULT(id) \
46 do { \
47 struct timeval tv; \
48 gettimeofday (&tv, NULL); \
49 tv.tv_sec -= (timing_test_##id##_stv).tv_sec; \
50 fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__, \
51 tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec); \
52 } while (0)
53
54#else
55#define TIMING_TEST_START(id) do {} while (0)
56#define TIMING_TEST_PRINT_RESULT(id) do {} while (0)
57#endif 35#endif
58 36
59/* 37/*
60 * Pixmap geometry string interpretation : 38 * Pixmap geometry string interpretation :
61 * Each geometry string contains zero or one scale/position 39 * Each geometry string contains zero or one scale/position
103#endif 81#endif
104 flags = 0; 82 flags = 0;
105 pixmap = None; 83 pixmap = None;
106 valid_since = invalid_since = 0; 84 valid_since = invalid_since = 0;
107 target = 0; 85 target = 0;
86 target_x = target_y = 0;
108} 87}
109 88
110void 89void
111bgPixmap_t::destroy () 90bgPixmap_t::destroy ()
112{ 91{
123 if (pixmap && target) 102 if (pixmap && target)
124 XFreePixmap (target->dpy, pixmap); 103 XFreePixmap (target->dpy, pixmap);
125} 104}
126 105
127bool 106bool
107bgPixmap_t::set_position (int x, int y)
108{
109
110 if (target_x != x
111 || target_y != y)
112 {
113 target_x = x;
114 target_y = y;
115 return true;
116 }
117 return false;
118}
119
120bool
128bgPixmap_t::window_size_sensitive () 121bgPixmap_t::window_size_sensitive ()
129{ 122{
130# ifdef ENABLE_TRANSPARENCY 123# ifdef ENABLE_TRANSPARENCY
131 if (flags & isTransparent) 124 if (flags & isTransparent)
132 return true; 125 return true;
157 if (flags & rootAlign) 150 if (flags & rootAlign)
158 return true; 151 return true;
159 } 152 }
160# endif 153# endif
161 154
162 return false;
163}
164
165bool bgPixmap_t::need_client_side_rendering ()
166{
167# ifdef HAVE_AFTERIMAGE
168 if (original_asim)
169 return true;
170# endif
171 return false; 155 return false;
172} 156}
173 157
174# ifdef BG_IMAGE_FROM_FILE 158# ifdef BG_IMAGE_FROM_FILE
175static inline bool 159static inline bool
247 int x = 0, y = 0; 231 int x = 0, y = 0;
248 unsigned int w = 0, h = 0; 232 unsigned int w = 0, h = 0;
249 unsigned int n; 233 unsigned int n;
250 unsigned long new_flags = (flags & (~geometryFlags)); 234 unsigned long new_flags = (flags & (~geometryFlags));
251 const char *ops; 235 const char *ops;
252# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */
253 236
254 if (geom == NULL) 237 if (geom == NULL)
255 return false; 238 return false;
256 239
257 char str[MAXLEN_GEOM]; 240 char str[256];
258 241
259 ops = strchr (geom, ':'); 242 ops = strchr (geom, ':');
260 if (ops == NULL) 243 if (ops == NULL)
261 n = strlen (geom); 244 n = strlen (geom);
262 else 245 else
263 n = ops - geom; 246 n = ops - geom;
264 247
265 if (n < MAXLEN_GEOM) 248 if (n >= sizeof (str))
266 { 249 return false;
250
267 memcpy (str, geom, n); 251 memcpy (str, geom, n);
268 str[n] = '\0'; 252 str[n] = '\0';
269 rxvt_strtrim (str); 253 rxvt_strtrim (str);
270 254
271 if (str[0]) 255 if (str[0])
272 { 256 {
273 /* we have geometry string - let's handle it prior to applying ops */ 257 /* we have geometry string - let's handle it prior to applying ops */
274 geom_flags = XParseGeometry (str, &x, &y, &w, &h); 258 geom_flags = XParseGeometry (str, &x, &y, &w, &h);
275 } /* done parsing geometry string */ 259 } /* done parsing geometry string */
276 260
277 if (!update) 261 if (!update)
278 { 262 {
279 if (!(geom_flags & XValue)) 263 if (!(geom_flags & XValue))
280 x = y = defaultAlign; 264 x = y = defaultAlign;
281 else if (!(geom_flags & YValue)) 265 else if (!(geom_flags & YValue))
282 y = x; 266 y = x;
283 267
284 if (!(geom_flags & (WidthValue|HeightValue))) 268 if (!(geom_flags & (WidthValue|HeightValue)))
285 w = h = defaultScale; 269 w = h = defaultScale;
286 else if (!(geom_flags & HeightValue)) 270 else if (!(geom_flags & HeightValue))
287 h = w; 271 h = w;
288 else if (!(geom_flags & WidthValue)) 272 else if (!(geom_flags & WidthValue))
289 w = h; 273 w = h;
290 274
291 geom_flags |= WidthValue|HeightValue|XValue|YValue; 275 geom_flags |= WidthValue|HeightValue|XValue|YValue;
276 }
277
278 if (ops)
279 {
280 char **arr = rxvt_strsplit (':', ops + 1);
281
282 for (int i = 0; arr[i]; i++)
292 } 283 {
293 284 if (!strcasecmp (arr[i], "tile"))
294 if (ops)
295 {
296 while (*ops)
297 {
298 while (*ops == ':' || isspace(*ops)) ++ops;
299
300# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof (op_str) - 1) == 0)
301 if (CHECK_GEOM_OPS ("tile"))
302 { 285 {
303 w = h = noScale; 286 w = h = noScale;
304 geom_flags |= WidthValue|HeightValue; 287 geom_flags |= WidthValue|HeightValue;
305 } 288 }
306 else if (CHECK_GEOM_OPS ("propscale")) 289 else if (!strcasecmp (arr[i], "propscale"))
307 { 290 {
308 new_flags |= propScale; 291 new_flags |= propScale;
309 } 292 }
310 else if (CHECK_GEOM_OPS ("hscale")) 293 else if (!strcasecmp (arr[i], "hscale"))
311 { 294 {
312 if (w == 0) w = windowScale; 295 if (w == 0) w = windowScale;
313 296
314 h = noScale; 297 h = noScale;
315 geom_flags |= WidthValue|HeightValue; 298 geom_flags |= WidthValue|HeightValue;
316 } 299 }
317 else if (CHECK_GEOM_OPS ("vscale")) 300 else if (!strcasecmp (arr[i], "vscale"))
318 { 301 {
319 if (h == 0) h = windowScale; 302 if (h == 0) h = windowScale;
320 303
321 w = noScale; 304 w = noScale;
322 geom_flags |= WidthValue|HeightValue; 305 geom_flags |= WidthValue|HeightValue;
323 } 306 }
324 else if (CHECK_GEOM_OPS ("scale")) 307 else if (!strcasecmp (arr[i], "scale"))
325 { 308 {
326 if (h == 0) h = windowScale; 309 if (h == 0) h = windowScale;
327 if (w == 0) w = windowScale; 310 if (w == 0) w = windowScale;
328 311
329 geom_flags |= WidthValue|HeightValue; 312 geom_flags |= WidthValue|HeightValue;
330 } 313 }
331 else if (CHECK_GEOM_OPS ("auto")) 314 else if (!strcasecmp (arr[i], "auto"))
332 { 315 {
333 w = h = windowScale; 316 w = h = windowScale;
334 x = y = centerAlign; 317 x = y = centerAlign;
335 geom_flags |= WidthValue|HeightValue|XValue|YValue; 318 geom_flags |= WidthValue|HeightValue|XValue|YValue;
336 } 319 }
337 else if (CHECK_GEOM_OPS ("root")) 320 else if (!strcasecmp (arr[i], "root"))
338 { 321 {
339 new_flags |= rootAlign; 322 new_flags |= rootAlign;
340 w = h = noScale; 323 w = h = noScale;
341 geom_flags |= WidthValue|HeightValue; 324 geom_flags |= WidthValue|HeightValue;
342 } 325 }
343# undef CHECK_GEOM_OPS
344
345 while (*ops != ':' && *ops != '\0') ++ops;
346 } /* done parsing ops */ 326 } /* done parsing ops */
347 }
348 327
328 rxvt_free_strsplit (arr);
329 }
330
349 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true; 331 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true;
350 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true; 332 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true;
351 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true; 333 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true;
352 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true; 334 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true;
353 }
354 335
355 if (new_flags != flags) 336 if (new_flags != flags)
356 { 337 {
357 flags = new_flags; 338 flags = new_flags;
358 changed = true; 339 changed = true;
383 if (!w) w = image_width; 364 if (!w) w = image_width;
384 if (!h) h = image_height; 365 if (!h) h = image_height;
385 366
386 if (flags & rootAlign) 367 if (flags & rootAlign)
387 { 368 {
388 target->get_window_origin (x, y);
389 x = -x; 369 x = -target_x;
390 y = -y; 370 y = -target_y;
391 } 371 }
392 else 372 else
393 { 373 {
394 x = make_align_position (h_align, target_width, w); 374 x = make_align_position (h_align, target_width, w);
395 y = make_align_position (v_align, target_height, h); 375 y = make_align_position (v_align, target_height, h);
592 GC gc; 572 GC gc;
593 573
594 /* create Pixmap */ 574 /* create Pixmap */
595 if (pixmap == None 575 if (pixmap == None
596 || pmap_width != new_pmap_width 576 || pmap_width != new_pmap_width
597 || pmap_height != new_pmap_height 577 || pmap_height != new_pmap_height)
598 || pmap_depth != target->depth)
599 { 578 {
600 if (pixmap) 579 if (pixmap)
601 XFreePixmap (target->dpy, pixmap); 580 XFreePixmap (target->dpy, pixmap);
602 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 581 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
603 pmap_width = new_pmap_width; 582 pmap_width = new_pmap_width;
604 pmap_height = new_pmap_height; 583 pmap_height = new_pmap_height;
605 pmap_depth = target->depth;
606 } 584 }
607 /* fill with background color (if result's not completely overlapping it) */ 585 /* fill with background color (if result's not completely overlapping it) */
608 gcv.foreground = target->pix_colors[Color_bg]; 586 gcv.foreground = target->pix_colors[Color_bg];
609 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); 587 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
610 588
642 return ret; 620 return ret;
643} 621}
644# endif /* HAVE_AFTERIMAGE */ 622# endif /* HAVE_AFTERIMAGE */
645 623
646# ifdef HAVE_PIXBUF 624# ifdef HAVE_PIXBUF
625bool
626bgPixmap_t::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc,
627 int src_x, int src_y, int dst_x, int dst_y,
628 unsigned int width, unsigned int height)
629{
630 XImage *ximage;
631 char *data, *line;
632 int bytes_per_pixel;
633 int width_r, width_g, width_b;
634 int sh_r, sh_g, sh_b;
635 int rowstride;
636 int channels;
637 unsigned char *row;
638 Visual *visual = target->visual;
639 int depth = target->depth;
640
641 if (visual->c_class != TrueColor)
642 return false;
643
644 if (depth == 24 || depth == 32)
645 bytes_per_pixel = 4;
646 else if (depth == 15 || depth == 16)
647 bytes_per_pixel = 2;
648 else
649 return false;
650
651 width_r = rxvt_popcount (visual->red_mask);
652 width_g = rxvt_popcount (visual->green_mask);
653 width_b = rxvt_popcount (visual->blue_mask);
654
655 if (width_r > 8 || width_g > 8 || width_b > 8)
656 return false;
657
658 sh_r = rxvt_ctz (visual->red_mask);
659 sh_g = rxvt_ctz (visual->green_mask);
660 sh_b = rxvt_ctz (visual->blue_mask);
661
662 if (width > INT_MAX / height / bytes_per_pixel)
663 return false;
664
665 data = (char *)malloc (width * height * bytes_per_pixel);
666 if (!data)
667 return false;
668
669 ximage = XCreateImage (target->dpy, visual, depth, ZPixmap, 0, data,
670 width, height, bytes_per_pixel * 8, 0);
671 if (!ximage)
672 {
673 free (data);
674 return false;
675 }
676
677 ximage->byte_order = byteorder::big_endian () ? MSBFirst : LSBFirst;
678
679 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
680 channels = gdk_pixbuf_get_n_channels (pixbuf);
681 row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels;
682 line = data;
683
684 for (int y = 0; y < height; y++)
685 {
686 for (int x = 0; x < width; x++)
687 {
688 unsigned char *pixel = row + x * channels;
689 uint32_t value;
690
691 value = ((pixel[0] >> (8 - width_r)) << sh_r)
692 | ((pixel[1] >> (8 - width_g)) << sh_g)
693 | ((pixel[2] >> (8 - width_b)) << sh_b);
694
695 if (bytes_per_pixel == 4)
696 ((uint32_t *)line)[x] = value;
697 else
698 ((uint16_t *)line)[x] = value;
699 }
700
701 row += rowstride;
702 line += ximage->bytes_per_line;
703 }
704
705 XPutImage (target->dpy, pixmap, gc, ximage, 0, 0, dst_x, dst_y, width, height);
706 XDestroyImage (ximage);
707 return true;
708}
709
647bool 710bool
648bgPixmap_t::render_image (unsigned long background_flags) 711bgPixmap_t::render_image (unsigned long background_flags)
649{ 712{
650 if (target == NULL) 713 if (target == NULL)
651 return false; 714 return false;
716 } 779 }
717 } 780 }
718 781
719 if (pixmap == None 782 if (pixmap == None
720 || pmap_width != new_pmap_width 783 || pmap_width != new_pmap_width
721 || pmap_height != new_pmap_height 784 || pmap_height != new_pmap_height)
722 || pmap_depth != target->depth)
723 { 785 {
724 if (pixmap) 786 if (pixmap)
725 XFreePixmap (target->dpy, pixmap); 787 XFreePixmap (target->dpy, pixmap);
726 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 788 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
727 pmap_width = new_pmap_width; 789 pmap_width = new_pmap_width;
728 pmap_height = new_pmap_height; 790 pmap_height = new_pmap_height;
729 pmap_depth = target->depth;
730 } 791 }
731 792
732 gcv.foreground = target->pix_colors[Color_bg]; 793 gcv.foreground = target->pix_colors[Color_bg];
733 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); 794 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
734 795
735 if (h_scale == 0 || v_scale == 0) 796 if (h_scale == 0 || v_scale == 0)
736 { 797 {
737 Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth); 798 Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth);
738 gdk_pixbuf_xlib_render_to_drawable (result, tile, gc, 799 pixbuf_to_pixmap (result, tile, gc,
739 0, 0, 800 0, 0,
740 0, 0, 801 0, 0,
741 image_width, image_height, 802 image_width, image_height);
742 XLIB_RGB_DITHER_NONE,
743 0, 0);
744 803
745 gcv.tile = tile; 804 gcv.tile = tile;
746 gcv.fill_style = FillTiled; 805 gcv.fill_style = FillTiled;
747 gcv.ts_x_origin = x; 806 gcv.ts_x_origin = x;
748 gcv.ts_y_origin = y; 807 gcv.ts_y_origin = y;
763 || dst_x + dst_width < new_pmap_width 822 || dst_x + dst_width < new_pmap_width
764 || dst_y + dst_height < new_pmap_height) 823 || dst_y + dst_height < new_pmap_height)
765 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 824 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
766 825
767 if (dst_x < new_pmap_width && dst_y < new_pmap_height) 826 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
768 gdk_pixbuf_xlib_render_to_drawable (result, pixmap, gc, 827 pixbuf_to_pixmap (result, pixmap, gc,
769 src_x, src_y, 828 src_x, src_y,
770 dst_x, dst_y, 829 dst_x, dst_y,
771 dst_width, dst_height, 830 dst_width, dst_height);
772 XLIB_RGB_DITHER_NONE,
773 0, 0);
774 } 831 }
775 832
776#if XRENDER 833#if XRENDER
777 if (background_flags) 834 if (background_flags)
778 { 835 {
845 if (image) 902 if (image)
846 { 903 {
847 if (original_asim) 904 if (original_asim)
848 safe_asimage_destroy (original_asim); 905 safe_asimage_destroy (original_asim);
849 original_asim = image; 906 original_asim = image;
907 flags |= CLIENT_RENDER;
850 have_image = true; 908 have_image = true;
851 return true; 909 return true;
852 } 910 }
853# endif 911# endif
854 912
926 bool has_shade = shade != 100; 984 bool has_shade = shade != 100;
927 985
928 if (tint) 986 if (tint)
929 { 987 {
930 tint->get (c); 988 tint->get (c);
931# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700) 989 if (!has_shade
932 if (!has_shade && IS_COMPONENT_WHOLESOME (c.r) 990 && (c.r <= 0x00ff || c.r >= 0xff00)
933 && IS_COMPONENT_WHOLESOME (c.g) 991 && (c.g <= 0x00ff || c.g >= 0xff00)
934 && IS_COMPONENT_WHOLESOME (c.b)) 992 && (c.b <= 0x00ff || c.b >= 0xff00))
935 flags |= bgPixmap_t::tintWholesome; 993 flags |= bgPixmap_t::tintWholesome;
936# undef IS_COMPONENT_WHOLESOME
937 } 994 }
938 995
939 if (has_shade) 996 if (has_shade || tint)
940 flags |= bgPixmap_t::tintNeeded; 997 flags |= bgPixmap_t::tintNeeded;
941 else if (tint)
942 {
943 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700)
944 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700))
945 {
946 flags |= bgPixmap_t::tintNeeded;
947 }
948 }
949 998
950 return flags; 999 return flags;
951} 1000}
952 1001
953bool 1002bool
956 if (!(flags & tintSet) || tint != new_tint) 1005 if (!(flags & tintSet) || tint != new_tint)
957 { 1006 {
958 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); 1007 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade);
959 tint = new_tint; 1008 tint = new_tint;
960 flags = (flags & ~tintFlags) | new_flags | tintSet; 1009 flags = (flags & ~tintFlags) | new_flags | tintSet;
961 return true;
962 }
963
964 return false;
965}
966
967bool
968bgPixmap_t::unset_tint ()
969{
970 unsigned long new_flags = compute_tint_shade_flags (NULL, shade);
971
972 if (new_flags != (flags & tintFlags))
973 {
974 flags = (flags & ~tintFlags) | new_flags;
975 return true; 1010 return true;
976 } 1011 }
977 1012
978 return false; 1013 return false;
979} 1014}
1124 c.g = (c.g * shade) / 100; 1159 c.g = (c.g * shade) / 100;
1125 c.b = (c.b * shade) / 100; 1160 c.b = (c.b * shade) / 100;
1126 } 1161 }
1127 else 1162 else
1128 { 1163 {
1129 c.r = ((0xffff - c.r) * (200 - shade)) / 100; 1164 c.r = (c.r * (200 - shade)) / 100;
1130 c.g = ((0xffff - c.g) * (200 - shade)) / 100; 1165 c.g = (c.g * (200 - shade)) / 100;
1131 c.b = ((0xffff - c.b) * (200 - shade)) / 100; 1166 c.b = (c.b * (200 - shade)) / 100;
1132 } 1167 }
1133 1168
1134 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); 1169 XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
1135 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1170 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1136 XRenderPictureAttributes pa; 1171 XRenderPictureAttributes pa;
1150 1185
1151 if (mask_pic && overlay_pic && back_pic) 1186 if (mask_pic && overlay_pic && back_pic)
1152 { 1187 {
1153 XRenderColor mask_c; 1188 XRenderColor mask_c;
1154 1189
1155 mask_c.red = mask_c.green = mask_c.blue = shade > 100 ? 0xffff : 0; 1190 mask_c.red = mask_c.green = mask_c.blue = 0;
1156 mask_c.alpha = 0xffff; 1191 mask_c.alpha = 0xffff;
1157 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); 1192 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1158 1193
1159 mask_c.alpha = 0; 1194 mask_c.alpha = 0;
1160 mask_c.red = 0xffff - c.r; 1195 mask_c.red = 0xffff - c.r;
1161 mask_c.green = 0xffff - c.g; 1196 mask_c.green = 0xffff - c.g;
1162 mask_c.blue = 0xffff - c.b; 1197 mask_c.blue = 0xffff - c.b;
1163 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); 1198 XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1);
1164 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height); 1199 XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1200
1201 if (shade > 100)
1202 {
1203 mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100;
1204 mask_c.alpha = 0;
1205 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1206
1207 XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height);
1208 }
1209
1165 ret = true; 1210 ret = true;
1166 } 1211 }
1167 1212
1168 XRenderFreePicture (dpy, mask_pic); 1213 XRenderFreePicture (dpy, mask_pic);
1169 XRenderFreePicture (dpy, overlay_pic); 1214 XRenderFreePicture (dpy, overlay_pic);
1200 int window_height = target->szHint.height; 1245 int window_height = target->szHint.height;
1201 int sx, sy; 1246 int sx, sy;
1202 XGCValues gcv; 1247 XGCValues gcv;
1203 GC gc; 1248 GC gc;
1204 1249
1205 target->get_window_origin (sx, sy); 1250 sx = target_x;
1251 sy = target_y;
1206 1252
1207 /* check if we are outside of the visible part of the virtual screen : */ 1253 /* check if we are outside of the visible part of the virtual screen : */
1208 if (sx + window_width <= 0 || sy + window_height <= 0 1254 if (sx + window_width <= 0 || sy + window_height <= 0
1209 || sx >= root_width || sy >= root_height) 1255 || sx >= root_width || sy >= root_height)
1210 return 0; 1256 return 0;
1257 } 1303 }
1258 1304
1259 if (root_pixmap == None) 1305 if (root_pixmap == None)
1260 return 0; 1306 return 0;
1261 1307
1308 if (pixmap == None
1309 || pmap_width != window_width
1310 || pmap_height != window_height)
1311 {
1312 if (pixmap)
1313 XFreePixmap (target->dpy, pixmap);
1262 Pixmap tiled_root_pmap = XCreatePixmap (dpy, target->vt, window_width, window_height, target->depth); 1314 pixmap = XCreatePixmap (target->dpy, target->vt, window_width, window_height, target->depth);
1315 pmap_width = window_width;
1316 pmap_height = window_height;
1317 }
1263 1318
1264 if (tiled_root_pmap == None) /* something really bad happened - abort */ 1319 if (pixmap == None)
1265 return 0; 1320 return 0;
1266 1321
1267 /* straightforward pixmap copy */ 1322 /* straightforward pixmap copy */
1323 while (sx < 0) sx += (int)root_width;
1324 while (sy < 0) sy += (int)root_height;
1325
1268 gcv.tile = recoded_root_pmap; 1326 gcv.tile = recoded_root_pmap;
1269 gcv.fill_style = FillTiled; 1327 gcv.fill_style = FillTiled;
1270
1271 while (sx < 0) sx += (int)root_width;
1272 while (sy < 0) sy += (int)root_height;
1273
1274 gcv.ts_x_origin = -sx; 1328 gcv.ts_x_origin = -sx;
1275 gcv.ts_y_origin = -sy; 1329 gcv.ts_y_origin = -sy;
1276 gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 1330 gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
1277 1331
1278 if (gc) 1332 if (gc)
1279 { 1333 {
1280 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); 1334 XFillRectangle (dpy, pixmap, gc, 0, 0, window_width, window_height);
1281 result |= transpPmapTiled; 1335 result |= transpPmapTiled;
1282 XFreeGC (dpy, gc); 1336 XFreeGC (dpy, gc);
1283 1337
1284 if (!need_client_side_rendering ()) 1338 if (!(flags & CLIENT_RENDER))
1285 { 1339 {
1286 if ((flags & blurNeeded) 1340 if ((flags & blurNeeded)
1287 && (flags & HAS_RENDER_CONV)) 1341 && (flags & HAS_RENDER_CONV))
1288 { 1342 {
1289 if (blur_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) 1343 if (blur_pixmap (pixmap, target->visual, window_width, window_height))
1290 result |= transpPmapBlurred; 1344 result |= transpPmapBlurred;
1291 } 1345 }
1292 if ((flags & tintNeeded) 1346 if ((flags & tintNeeded)
1293 && (flags & (tintWholesome | HAS_RENDER))) 1347 && (flags & (tintWholesome | HAS_RENDER)))
1294 { 1348 {
1295 if (tint_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) 1349 if (tint_pixmap (pixmap, target->visual, window_width, window_height))
1296 result |= transpPmapTinted; 1350 result |= transpPmapTinted;
1297 } 1351 }
1298 } /* server side rendering completed */ 1352 } /* server side rendering completed */
1299
1300 if (pixmap)
1301 XFreePixmap (dpy, pixmap);
1302
1303 pixmap = tiled_root_pmap;
1304 pmap_width = window_width;
1305 pmap_height = window_height;
1306 pmap_depth = target->depth;
1307 } 1353 }
1308 else
1309 XFreePixmap (dpy, tiled_root_pmap);
1310 1354
1311 if (recoded_root_pmap != root_pixmap) 1355 if (recoded_root_pmap != root_pixmap)
1312 XFreePixmap (dpy, recoded_root_pmap); 1356 XFreePixmap (dpy, recoded_root_pmap);
1313 1357
1314 return result; 1358 return result;
1315} 1359}
1316 1360
1317void 1361void
1318bgPixmap_t::set_root_pixmap () 1362bgPixmap_t::set_root_pixmap ()
1319{ 1363{
1320 Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); 1364 Pixmap new_root_pixmap = target->get_pixmap_property (target->xa[XA_XROOTPMAP_ID]);
1321 if (new_root_pixmap == None) 1365 if (new_root_pixmap == None)
1322 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); 1366 new_root_pixmap = target->get_pixmap_property (target->xa[XA_ESETROOT_PMAP_ID]);
1323 1367
1324 root_pixmap = new_root_pixmap; 1368 root_pixmap = new_root_pixmap;
1325} 1369}
1326# endif /* ENABLE_TRANSPARENCY */ 1370# endif /* ENABLE_TRANSPARENCY */
1327 1371
1328#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1372#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1329static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, const rgba &c); 1373static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c);
1330# endif 1374# endif
1331 1375
1332bool 1376bool
1333bgPixmap_t::render () 1377bgPixmap_t::render ()
1334{ 1378{
1344 /* we need to re-generate transparency pixmap in that case ! */ 1388 /* we need to re-generate transparency pixmap in that case ! */
1345 background_flags = make_transparency_pixmap (); 1389 background_flags = make_transparency_pixmap ();
1346 if (background_flags == 0) 1390 if (background_flags == 0)
1347 return false; 1391 return false;
1348 else if ((background_flags & transpTransformations) == (flags & transpTransformations)) 1392 else if ((background_flags & transpTransformations) == (flags & transpTransformations))
1349 flags = flags & ~isInvalid; 1393 flags &= ~isInvalid;
1350 } 1394 }
1351# endif 1395# endif
1352 1396
1353# ifdef BG_IMAGE_FROM_FILE 1397# ifdef BG_IMAGE_FROM_FILE
1354 if (have_image 1398 if (have_image
1355 || (background_flags & transpTransformations) != (flags & transpTransformations)) 1399 || (background_flags & transpTransformations) != (flags & transpTransformations))
1356 { 1400 {
1357 if (render_image (background_flags)) 1401 if (render_image (background_flags))
1358 flags = flags & ~isInvalid; 1402 flags &= ~isInvalid;
1359 } 1403 }
1360# endif 1404# endif
1361 1405
1362# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1406# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1363 XImage *result = NULL; 1407 XImage *result = NULL;
1373 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1417 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
1374 { 1418 {
1375 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1419 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1376 if (flags & tintSet) 1420 if (flags & tintSet)
1377 tint.get (c); 1421 tint.get (c);
1378 ShadeXImage (DefaultVisual (target->dpy, target->display->screen), result, shade, c); 1422 shade_ximage (DefaultVisual (target->dpy, target->display->screen), result, shade, c);
1379 } 1423 }
1380 1424
1381 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1425 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1382 1426
1383 if (gc) 1427 if (gc)
1384 { 1428 {
1385 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); 1429 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1386 1430
1387 XFreeGC (target->dpy, gc); 1431 XFreeGC (target->dpy, gc);
1388 flags = flags & ~isInvalid; 1432 flags &= ~isInvalid;
1389 } 1433 }
1390 1434
1391 XDestroyImage (result); 1435 XDestroyImage (result);
1392 } 1436 }
1393# endif 1437# endif
1488 1532
1489#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1533#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1490/* taken from aterm-0.4.2 */ 1534/* taken from aterm-0.4.2 */
1491 1535
1492static void 1536static void
1493ShadeXImage(Visual *visual, XImage *srcImage, int shade, const rgba &c) 1537shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c)
1494{ 1538{
1495 int sh_r, sh_g, sh_b; 1539 int sh_r, sh_g, sh_b;
1496 uint32_t mask_r, mask_g, mask_b; 1540 uint32_t mask_r, mask_g, mask_b;
1497 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1541 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1498 rgba low; 1542 rgba low;
1499 rgba high; 1543 rgba high;
1500 int i; 1544 int i;
1501 int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst; 1545 int host_byte_order = byteorder::big_endian () ? MSBFirst : LSBFirst;
1502 1546
1503 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return; 1547 if (visual->c_class != TrueColor || ximage->format != ZPixmap) return;
1504 1548
1505 /* for convenience */ 1549 /* for convenience */
1506 mask_r = visual->red_mask; 1550 mask_r = visual->red_mask;
1507 mask_g = visual->green_mask; 1551 mask_g = visual->green_mask;
1508 mask_b = visual->blue_mask; 1552 mask_b = visual->blue_mask;
1509 1553
1510 /* boring lookup table pre-initialization */ 1554 /* boring lookup table pre-initialization */
1511 switch (srcImage->depth) 1555 switch (ximage->depth)
1512 { 1556 {
1513 case 15: 1557 case 15:
1514 if ((mask_r != 0x7c00) || 1558 if ((mask_r != 0x7c00) ||
1515 (mask_g != 0x03e0) || 1559 (mask_g != 0x03e0) ||
1516 (mask_b != 0x001f)) 1560 (mask_b != 0x001f))
1569 /* prepare limits for color transformation (each channel is handled separately) */ 1613 /* prepare limits for color transformation (each channel is handled separately) */
1570 if (shade > 100) 1614 if (shade > 100)
1571 { 1615 {
1572 shade = 200 - shade; 1616 shade = 200 - shade;
1573 1617
1574 high.r = (65535 - c.r) * shade / 100; 1618 high.r = c.r * shade / 100;
1575 high.g = (65535 - c.g) * shade / 100; 1619 high.g = c.g * shade / 100;
1576 high.b = (65535 - c.b) * shade / 100; 1620 high.b = c.b * shade / 100;
1577 1621
1578 low.r = 65535 - high.r; 1622 low.r = 65535 * (100 - shade) / 100;
1579 low.g = 65535 - high.g; 1623 low.g = 65535 * (100 - shade) / 100;
1580 low.b = 65535 - high.b; 1624 low.b = 65535 * (100 - shade) / 100;
1581 } 1625 }
1582 else 1626 else
1583 { 1627 {
1584 high.r = c.r * shade / 100; 1628 high.r = c.r * shade / 100;
1585 high.g = c.g * shade / 100; 1629 high.g = c.g * shade / 100;
1610 tmp += (mask_b>>sh_b) * low.b; 1654 tmp += (mask_b>>sh_b) * low.b;
1611 lookup_b[i] = (tmp/65535)<<sh_b; 1655 lookup_b[i] = (tmp/65535)<<sh_b;
1612 } 1656 }
1613 1657
1614 /* apply table to input image (replacing colors by newly calculated ones) */ 1658 /* apply table to input image (replacing colors by newly calculated ones) */
1615 if (srcImage->bits_per_pixel == 32 1659 if (ximage->bits_per_pixel == 32
1616 && (srcImage->depth == 24 || srcImage->depth == 32) 1660 && (ximage->depth == 24 || ximage->depth == 32)
1617 && srcImage->byte_order == host_byte_order) 1661 && ximage->byte_order == host_byte_order)
1618 { 1662 {
1619 uint32_t *p1, *pf, *p, *pl; 1663 uint32_t *p1, *pf, *p, *pl;
1620 p1 = (uint32_t *) srcImage->data; 1664 p1 = (uint32_t *) ximage->data;
1621 pf = (uint32_t *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); 1665 pf = (uint32_t *) (ximage->data + ximage->height * ximage->bytes_per_line);
1622 1666
1623 while (p1 < pf) 1667 while (p1 < pf)
1624 { 1668 {
1625 p = p1; 1669 p = p1;
1626 pl = p1 + srcImage->width; 1670 pl = p1 + ximage->width;
1627 for (; p < pl; p++) 1671 for (; p < pl; p++)
1628 { 1672 {
1629 *p = lookup_r[(*p & 0xff0000) >> 16] | 1673 *p = lookup_r[(*p & 0xff0000) >> 16] |
1630 lookup_g[(*p & 0x00ff00) >> 8] | 1674 lookup_g[(*p & 0x00ff00) >> 8] |
1631 lookup_b[(*p & 0x0000ff)] | 1675 lookup_b[(*p & 0x0000ff)] |
1632 (*p & 0xff000000); 1676 (*p & 0xff000000);
1633 } 1677 }
1634 p1 = (uint32_t *) ((char *) p1 + srcImage->bytes_per_line); 1678 p1 = (uint32_t *) ((char *) p1 + ximage->bytes_per_line);
1635 } 1679 }
1636 } 1680 }
1637 else 1681 else
1638 { 1682 {
1639 for (int y = 0; y < srcImage->height; y++) 1683 for (int y = 0; y < ximage->height; y++)
1640 for (int x = 0; x < srcImage->width; x++) 1684 for (int x = 0; x < ximage->width; x++)
1641 { 1685 {
1642 unsigned long pixel = XGetPixel (srcImage, x, y); 1686 unsigned long pixel = XGetPixel (ximage, x, y);
1643 pixel = lookup_r[(pixel & mask_r) >> sh_r] | 1687 pixel = lookup_r[(pixel & mask_r) >> sh_r] |
1644 lookup_g[(pixel & mask_g) >> sh_g] | 1688 lookup_g[(pixel & mask_g) >> sh_g] |
1645 lookup_b[(pixel & mask_b) >> sh_b]; 1689 lookup_b[(pixel & mask_b) >> sh_b];
1646 XPutPixel (srcImage, x, y, pixel); 1690 XPutPixel (ximage, x, y, pixel);
1647 } 1691 }
1648 } 1692 }
1649 1693
1650 free (lookup); 1694 free (lookup);
1651} 1695}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines