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.217 by sf-exg, Sun May 20 16:34:42 2012 UTC vs.
Revision 1.234 by sf-exg, Thu Jun 7 09:21:18 2012 UTC

58# endif 58# endif
59 59
60void 60void
61rxvt_term::bg_destroy () 61rxvt_term::bg_destroy ()
62{ 62{
63# if BG_IMAGE_FROM_FILE
64 fimage.destroy ();
65# endif
66
63 if (bg_pixmap) 67 if (bg_pixmap)
64 XFreePixmap (dpy, bg_pixmap); 68 XFreePixmap (dpy, bg_pixmap);
65} 69}
66 70
67bool 71bool
79} 83}
80 84
81bool 85bool
82rxvt_term::bg_window_size_sensitive () 86rxvt_term::bg_window_size_sensitive ()
83{ 87{
84# ifdef ENABLE_TRANSPARENCY 88# if ENABLE_TRANSPARENCY
85 if (bg_flags & BG_IS_TRANSPARENT) 89 if (bg_flags & BG_IS_TRANSPARENT)
86 return true; 90 return true;
87# endif 91# endif
88 92
89# ifdef BG_IMAGE_FROM_FILE 93# if BG_IMAGE_FROM_FILE
90 if (bg_image.flags & IM_IS_SET) 94 if (fimage.flags & IM_IS_SET)
91 { 95 {
92 if ((bg_image.flags & IM_IS_SIZE_SENSITIVE) 96 if ((fimage.flags & IM_IS_SIZE_SENSITIVE)
93 || bg_image.width () > szHint.width 97 || fimage.width () > szHint.width
94 || bg_image.height () > szHint.height) 98 || fimage.height () > szHint.height)
95 return true; 99 return true;
96 } 100 }
97# endif 101# endif
98 102
99 return false; 103 return false;
100} 104}
101 105
102bool 106bool
103rxvt_term::bg_window_position_sensitive () 107rxvt_term::bg_window_position_sensitive ()
104{ 108{
105# ifdef ENABLE_TRANSPARENCY 109# if ENABLE_TRANSPARENCY
106 if (bg_flags & BG_IS_TRANSPARENT) 110 if (bg_flags & BG_IS_TRANSPARENT)
107 return true; 111 return true;
108# endif 112# endif
109 113
110# ifdef BG_IMAGE_FROM_FILE 114# if BG_IMAGE_FROM_FILE
111 if (bg_image.flags & IM_IS_SET) 115 if (fimage.flags & IM_IS_SET)
112 { 116 {
113 if (bg_image.flags & IM_ROOT_ALIGN) 117 if (fimage.flags & IM_ROOT_ALIGN)
114 return true; 118 return true;
115 } 119 }
116# endif 120# endif
117 121
118 return false; 122 return false;
119} 123}
120 124
121# ifdef BG_IMAGE_FROM_FILE 125# if BG_IMAGE_FROM_FILE
122static inline int 126static inline int
123make_align_position (int align, int window_size, int image_size) 127make_align_position (int align, int window_size, int image_size)
124{ 128{
125 if (align >= 0 && align <= 100) 129 if (align >= 0 && align <= 100)
126 return lerp (0, window_size - image_size, align); 130 return lerp (0, window_size - image_size, align);
145 149
146 min_it (dst_size, target_size - dst_pos); 150 min_it (dst_size, target_size - dst_pos);
147 return src_pos; 151 return src_pos;
148} 152}
149 153
154static void
155parse_style (const char *style, int &x, int &y, unsigned int &w, unsigned int &h, uint8_t &flags)
156{
157 if (!strcasecmp (style, "tiled"))
158 {
159 flags = IM_TILE;
160 w = h = noScale;
161 x = y = 0;
162 }
163 else if (!strcasecmp (style, "aspect-stretched"))
164 {
165 flags = IM_KEEP_ASPECT;
166 w = h = windowScale;
167 x = y = centerAlign;
168 }
169 else if (!strcasecmp (style, "stretched"))
170 {
171 flags = 0;
172 w = h = windowScale;
173 x = y = centerAlign;
174 }
175 else if (!strcasecmp (style, "centered"))
176 {
177 flags = 0;
178 w = h = noScale;
179 x = y = centerAlign;
180 }
181 else if (!strcasecmp (style, "root-tiled"))
182 {
183 flags = IM_TILE|IM_ROOT_ALIGN;
184 w = h = noScale;
185 x = y = 0;
186 }
187}
188
150bool 189bool
151rxvt_image::set_geometry (const char *geom, bool update) 190rxvt_image::set_geometry (const char *geom, bool update)
152{ 191{
153 bool changed = false; 192 bool changed = false;
154 int geom_flags = 0; 193 int geom_flags = 0;
155 int x = h_align; 194 int x = h_align;
156 int y = v_align; 195 int y = v_align;
157 unsigned int w = h_scale; 196 unsigned int w = h_scale;
158 unsigned int h = v_scale; 197 unsigned int h = v_scale;
159 unsigned long new_flags = 0; 198 uint8_t new_flags = 0;
160 199
161 if (geom == NULL) 200 if (geom == NULL)
162 return false; 201 return false;
163 202
164 if (geom[0]) 203 if (geom[0])
165 { 204 {
166 char **arr = rxvt_strsplit (':', geom); 205 char **arr = rxvt_strsplit (':', geom);
167 206
168 for (int i = 0; arr[i]; i++) 207 for (int i = 0; arr[i]; i++)
169 { 208 {
170 if (!strcasecmp (arr[i], "style=tiled")) 209 if (!strncasecmp (arr[i], "style=", 6))
171 { 210 {
172 new_flags = IM_TILE; 211 parse_style (arr[i] + 6, x, y, w, h, new_flags);
173 w = h = noScale;
174 x = y = 0;
175 geom_flags = WidthValue|HeightValue|XValue|YValue; 212 geom_flags = WidthValue|HeightValue|XValue|YValue;
176 }
177 else if (!strcasecmp (arr[i], "style=aspect-stretched"))
178 {
179 new_flags = IM_KEEP_ASPECT;
180 w = h = windowScale;
181 x = y = centerAlign;
182 geom_flags = WidthValue|HeightValue|XValue|YValue;
183 }
184 else if (!strcasecmp (arr[i], "style=stretched"))
185 {
186 new_flags = 0;
187 w = h = windowScale;
188 geom_flags = WidthValue|HeightValue;
189 }
190 else if (!strcasecmp (arr[i], "style=centered"))
191 {
192 new_flags = 0;
193 w = h = noScale;
194 x = y = centerAlign;
195 geom_flags = WidthValue|HeightValue|XValue|YValue;
196 }
197 else if (!strcasecmp (arr[i], "style=root-tiled"))
198 {
199 new_flags = IM_TILE|IM_ROOT_ALIGN;
200 w = h = noScale;
201 geom_flags = WidthValue|HeightValue;
202 } 213 }
203 else if (!strcasecmp (arr[i], "op=tile")) 214 else if (!strcasecmp (arr[i], "op=tile"))
204 new_flags |= IM_TILE; 215 new_flags |= IM_TILE;
205 else if (!strcasecmp (arr[i], "op=keep-aspect")) 216 else if (!strcasecmp (arr[i], "op=keep-aspect"))
206 new_flags |= IM_KEEP_ASPECT; 217 new_flags |= IM_KEEP_ASPECT;
291 h_align = x; 302 h_align = x;
292 v_align = y; 303 v_align = y;
293 changed = true; 304 changed = true;
294 } 305 }
295 306
296 if (!(flags & IM_TILE) 307 if (is_size_sensitive ())
297 || h_scale || v_scale
298 || (!(flags & IM_ROOT_ALIGN) && (h_align || v_align)))
299 flags |= IM_IS_SIZE_SENSITIVE; 308 flags |= IM_IS_SIZE_SENSITIVE;
300 else 309 else
301 flags &= ~IM_IS_SIZE_SENSITIVE; 310 flags &= ~IM_IS_SIZE_SENSITIVE;
302 311
303 return changed; 312 return changed;
337 x = make_align_position (image.h_align, target_width, w); 346 x = make_align_position (image.h_align, target_width, w);
338 y = make_align_position (image.v_align, target_height, h); 347 y = make_align_position (image.v_align, target_height, h);
339 } 348 }
340} 349}
341 350
342# ifdef HAVE_PIXBUF 351# if HAVE_PIXBUF
343bool 352bool
344rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, 353rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc,
345 int src_x, int src_y, int dst_x, int dst_y, 354 int src_x, int src_y, int dst_x, int dst_y,
346 unsigned int width, unsigned int height) 355 unsigned int width, unsigned int height, bool argb)
347{ 356{
348 XImage *ximage; 357 XImage *ximage;
349 char *line; 358 char *line;
350 int width_r, width_g, width_b, width_a; 359 int width_r, width_g, width_b, width_a;
351 int sh_r, sh_g, sh_b, sh_a; 360 int sh_r, sh_g, sh_b, sh_a;
352 uint32_t alpha_mask; 361 uint32_t red_mask, green_mask, blue_mask, alpha_mask;
353 int rowstride; 362 int rowstride;
354 int channels; 363 int channels;
355 unsigned char *row; 364 unsigned char *row;
356 365
357 if (visual->c_class != TrueColor) 366 if (visual->c_class != TrueColor)
358 return false; 367 return false;
359 368
369 if (argb)
370 {
371 red_mask = 0xff << 16;
372 green_mask = 0xff << 8;
373 blue_mask = 0xff;
374 alpha_mask = 0xff << 24;
375 }
376 else
377 {
378 red_mask = visual->red_mask;
379 green_mask = visual->green_mask;
380 blue_mask = visual->blue_mask;
360#if XRENDER 381#if XRENDER
361 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 382 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
362 if (format) 383 if (format)
363 alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha; 384 alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha;
364 else 385 else
365#endif 386#endif
366 alpha_mask = 0; 387 alpha_mask = 0;
388 }
367 389
368 width_r = ecb_popcount32 (visual->red_mask); 390 width_r = ecb_popcount32 (red_mask);
369 width_g = ecb_popcount32 (visual->green_mask); 391 width_g = ecb_popcount32 (green_mask);
370 width_b = ecb_popcount32 (visual->blue_mask); 392 width_b = ecb_popcount32 (blue_mask);
371 width_a = ecb_popcount32 (alpha_mask); 393 width_a = ecb_popcount32 (alpha_mask);
372 394
373 if (width_r > 8 || width_g > 8 || width_b > 8 || width_a > 8) 395 if (width_r > 8 || width_g > 8 || width_b > 8 || width_a > 8)
374 return false; 396 return false;
375 397
376 sh_r = ecb_ctz32 (visual->red_mask); 398 sh_r = ecb_ctz32 (red_mask);
377 sh_g = ecb_ctz32 (visual->green_mask); 399 sh_g = ecb_ctz32 (green_mask);
378 sh_b = ecb_ctz32 (visual->blue_mask); 400 sh_b = ecb_ctz32 (blue_mask);
379 sh_a = ecb_ctz32 (alpha_mask); 401 sh_a = ecb_ctz32 (alpha_mask);
380 402
381 if (width > 32767 || height > 32767) 403 if (width > 32767 || height > 32767)
382 return false; 404 return false;
383 405
384 ximage = XCreateImage (dpy, visual, depth, ZPixmap, 0, 0, 406 ximage = XCreateImage (dpy, visual, argb ? 32 : depth, ZPixmap, 0, 0,
385 width, height, 32, 0); 407 width, height, 32, 0);
386 if (!ximage) 408 if (!ximage)
387 return false; 409 return false;
388 410
389 if (height > INT_MAX / ximage->bytes_per_line 411 if (height > INT_MAX / ximage->bytes_per_line
461 return false; 483 return false;
462 484
463 bool need_blend = bg_flags & BG_IS_VALID; 485 bool need_blend = bg_flags & BG_IS_VALID;
464 486
465 if (need_blend 487 if (need_blend
466 && !(bg_flags & BG_HAS_RENDER)) 488 && !(display->flags & DISPLAY_HAS_RENDER))
467 return false; 489 return false;
468 490
469 GdkPixbuf *result; 491 GdkPixbuf *result;
470 492
471 int image_width = gdk_pixbuf_get_width (pixbuf); 493 int image_width = gdk_pixbuf_get_width (pixbuf);
511 533
512 image_width = gdk_pixbuf_get_width (result); 534 image_width = gdk_pixbuf_get_width (result);
513 image_height = gdk_pixbuf_get_height (result); 535 image_height = gdk_pixbuf_get_height (result);
514 536
515 if (need_blend) 537 if (need_blend)
516 { 538 tmp_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, 32);
517 tmp_pixmap = bg_pixmap;
518 bg_pixmap = None;
519 }
520 else 539 else
521 { 540 {
522 if (image.flags & IM_TILE) 541 if (image.flags & IM_TILE)
523 { 542 {
524 new_pmap_width = min (image_width, target_width); 543 new_pmap_width = min (image_width, target_width);
525 new_pmap_height = min (image_height, target_height); 544 new_pmap_height = min (image_height, target_height);
526 } 545 }
527 }
528 546
529 if (bg_pixmap == None 547 if (bg_pixmap == None
530 || bg_pmap_width != new_pmap_width 548 || bg_pmap_width != new_pmap_width
531 || bg_pmap_height != new_pmap_height) 549 || bg_pmap_height != new_pmap_height)
532 { 550 {
533 if (bg_pixmap) 551 if (bg_pixmap)
534 XFreePixmap (dpy, bg_pixmap); 552 XFreePixmap (dpy, bg_pixmap);
535 bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); 553 bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth);
536 bg_pmap_width = new_pmap_width; 554 bg_pmap_width = new_pmap_width;
537 bg_pmap_height = new_pmap_height; 555 bg_pmap_height = new_pmap_height;
556 }
557
558 tmp_pixmap = bg_pixmap;
538 } 559 }
539 560
540 gcv.foreground = pix_colors[Color_bg]; 561 gcv.foreground = pix_colors[Color_bg];
541 gc = XCreateGC (dpy, vt, GCForeground, &gcv); 562 gc = XCreateGC (dpy, tmp_pixmap, GCForeground, &gcv);
542 563
543 if (gc) 564 if (gc)
544 { 565 {
545 if (image.flags & IM_TILE) 566 if (image.flags & IM_TILE)
546 { 567 {
547 Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); 568 Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, need_blend ? 32 : depth);
548 pixbuf_to_pixmap (result, tile, gc, 569 pixbuf_to_pixmap (result, tile, gc,
549 0, 0, 570 0, 0,
550 0, 0, 571 0, 0,
551 image_width, image_height); 572 image_width, image_height, need_blend);
552 573
553 gcv.tile = tile; 574 gcv.tile = tile;
554 gcv.fill_style = FillTiled; 575 gcv.fill_style = FillTiled;
555 gcv.ts_x_origin = x; 576 gcv.ts_x_origin = x;
556 gcv.ts_y_origin = y; 577 gcv.ts_y_origin = y;
557 XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 578 XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
558 579
559 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 580 XFillRectangle (dpy, tmp_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
560 XFreePixmap (dpy, tile); 581 XFreePixmap (dpy, tile);
561 } 582 }
562 else 583 else
563 { 584 {
564 int src_x, src_y, dst_x, dst_y; 585 int src_x, src_y, dst_x, dst_y;
568 src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); 589 src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height);
569 590
570 if (dst_x > 0 || dst_y > 0 591 if (dst_x > 0 || dst_y > 0
571 || dst_x + dst_width < new_pmap_width 592 || dst_x + dst_width < new_pmap_width
572 || dst_y + dst_height < new_pmap_height) 593 || dst_y + dst_height < new_pmap_height)
573 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 594 XFillRectangle (dpy, tmp_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
574 595
575 if (dst_x < new_pmap_width && dst_y < new_pmap_height) 596 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
576 pixbuf_to_pixmap (result, bg_pixmap, gc, 597 pixbuf_to_pixmap (result, tmp_pixmap, gc,
577 src_x, src_y, 598 src_x, src_y,
578 dst_x, dst_y, 599 dst_x, dst_y,
579 dst_width, dst_height); 600 dst_width, dst_height, need_blend);
580 } 601 }
602
603 if (image.need_blur ())
604 blur_pixmap (tmp_pixmap, new_pmap_width, new_pmap_height, need_blend, image.h_blurRadius, image.v_blurRadius);
605 if (image.need_tint ())
606 tint_pixmap (tmp_pixmap, new_pmap_width, new_pmap_height, need_blend, image.tint, image.tint_set, image.shade);
581 607
582#if XRENDER 608#if XRENDER
583 if (need_blend) 609 if (need_blend)
584 { 610 {
611 XRenderPictFormat *argb_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
585 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 612 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
586 613
587 Picture src = XRenderCreatePicture (dpy, tmp_pixmap, format, 0, 0); 614 Picture src = XRenderCreatePicture (dpy, tmp_pixmap, argb_format, 0, 0);
588 615
589 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); 616 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0);
590 617
591 Picture mask = create_xrender_mask (dpy, vt, False, False); 618 Picture mask = create_xrender_mask (dpy, vt, False, False);
592 619
593 XRenderColor mask_c; 620 XRenderColor mask_c;
594 621
595 mask_c.alpha = 0x8000; 622 mask_c.alpha = image.alpha;
596 mask_c.red = 623 mask_c.red =
597 mask_c.green = 624 mask_c.green =
598 mask_c.blue = 0; 625 mask_c.blue = 0;
599 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); 626 XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1);
600 627
619 646
620 return ret; 647 return ret;
621} 648}
622# endif /* HAVE_PIXBUF */ 649# endif /* HAVE_PIXBUF */
623 650
651rxvt_image::rxvt_image ()
652{
653 alpha = 0xffff;
654 flags = 0;
655 h_scale =
656 v_scale = defaultScale;
657 h_align =
658 v_align = defaultAlign;
659
660# if HAVE_PIXBUF
661 pixbuf = 0;
662# endif
663}
664
624bool 665bool
625rxvt_image::set_file (const char *file) 666rxvt_image::set_file_geometry (const char *file)
626{ 667{
627 if (!file || !*file) 668 if (!file || !*file)
628 return false; 669 return false;
629 670
630 bool ret = false;
631 const char *p = strchr (file, ';'); 671 const char *p = strchr (file, ';');
632 672
633 if (p) 673 if (p)
634 { 674 {
635 size_t len = p - file; 675 size_t len = p - file;
637 memcpy (f, file, len); 677 memcpy (f, file, len);
638 f[len] = '\0'; 678 f[len] = '\0';
639 file = f; 679 file = f;
640 } 680 }
641 681
682 bool ret = set_file (file);
683 alpha = 0x8000;
684 if (ret)
685 set_geometry (p ? p + 1 : "");
686 return ret;
687}
688
689bool
690rxvt_image::set_file (const char *file)
691{
692 bool ret = false;
693
642# ifdef HAVE_PIXBUF 694# if HAVE_PIXBUF
643 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); 695 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL);
644 if (image) 696 if (image)
645 { 697 {
646 if (pixbuf) 698 if (pixbuf)
647 g_object_unref (pixbuf); 699 g_object_unref (pixbuf);
649 ret = true; 701 ret = true;
650 } 702 }
651# endif 703# endif
652 704
653 if (ret) 705 if (ret)
654 { 706 flags |= IM_IS_SET;
655 flags = IM_IS_SET | IM_IS_SIZE_SENSITIVE;
656 h_scale = v_scale = defaultScale;
657 h_align = v_align = defaultAlign;
658
659 if (p)
660 set_geometry (p + 1);
661 }
662 707
663 return ret; 708 return ret;
664} 709}
665 710
666# endif /* BG_IMAGE_FROM_FILE */ 711# endif /* BG_IMAGE_FROM_FILE */
667 712
668# ifdef ENABLE_TRANSPARENCY
669bool 713bool
670rxvt_term::bg_set_blur (const char *geom) 714image_effects::set_blur (const char *geom)
671{ 715{
672 bool changed = false; 716 bool changed = false;
673 unsigned int hr, vr; 717 unsigned int hr, vr;
674 int junk; 718 int junk;
675 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); 719 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
696 740
697 return changed; 741 return changed;
698} 742}
699 743
700bool 744bool
701rxvt_term::bg_set_tint (rxvt_color &new_tint) 745image_effects::set_tint (const rxvt_color &new_tint)
702{ 746{
703 if (!(bg_flags & BG_TINT_SET) || tint != new_tint) 747 if (!tint_set || tint != new_tint)
704 { 748 {
705 tint = new_tint; 749 tint = new_tint;
706 bg_flags |= BG_TINT_SET; 750 tint_set = true;
707
708 rgba c;
709 tint.get (c);
710 if ((c.r <= 0x00ff || c.r >= 0xff00)
711 && (c.g <= 0x00ff || c.g >= 0xff00)
712 && (c.b <= 0x00ff || c.b >= 0xff00))
713 bg_flags |= BG_TINT_BITAND;
714 else
715 bg_flags &= ~BG_TINT_BITAND;
716 751
717 return true; 752 return true;
718 } 753 }
719 754
720 return false; 755 return false;
721} 756}
722 757
723bool 758bool
724rxvt_term::bg_set_shade (const char *shade_str) 759image_effects::set_shade (const char *shade_str)
725{ 760{
726 int new_shade = atoi (shade_str); 761 int new_shade = atoi (shade_str);
727 762
728 clamp_it (new_shade, -100, 200); 763 clamp_it (new_shade, -100, 200);
729 if (new_shade < 0) 764 if (new_shade < 0)
760 params[i+2] = XDoubleToFixed (kernel[i] / sum); 795 params[i+2] = XDoubleToFixed (kernel[i] / sum);
761} 796}
762#endif 797#endif
763 798
764bool 799bool
765rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height) 800rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height, bool argb, int h_blurRadius, int v_blurRadius)
766{ 801{
767 bool ret = false; 802 bool ret = false;
768#if XRENDER 803#if XRENDER
769 if (!(bg_flags & BG_HAS_RENDER_CONV)) 804 if (!(display->flags & DISPLAY_HAS_RENDER_CONV))
770 return false; 805 return false;
771 806
772 int size = max (h_blurRadius, v_blurRadius) * 2 + 1; 807 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
773 double *kernel = (double *)malloc (size * sizeof (double)); 808 double *kernel = (double *)malloc (size * sizeof (double));
774 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 809 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
775 810
776 XRenderPictureAttributes pa; 811 XRenderPictureAttributes pa;
777 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 812 XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32)
813 : XRenderFindVisualFormat (dpy, visual);
778 814
779 pa.repeat = RepeatPad; 815 pa.repeat = RepeatPad;
780 Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); 816 Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa);
781 Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth); 817 Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth);
782 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa); 818 Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa);
825#endif 861#endif
826 return ret; 862 return ret;
827} 863}
828 864
829bool 865bool
830rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height) 866rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height, bool argb, rxvt_color &tint, bool tint_set, int shade)
831{ 867{
832 bool ret = false; 868 bool ret = false;
833 869
834 if (shade == 100 && (bg_flags & BG_TINT_BITAND)) 870 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
871
872 if (tint_set)
873 tint.get (c);
874
875 if (shade == 100
876 && (c.r <= 0x00ff || c.r >= 0xff00)
877 && (c.g <= 0x00ff || c.g >= 0xff00)
878 && (c.b <= 0x00ff || c.b >= 0xff00))
835 { 879 {
836 XGCValues gcv; 880 XGCValues gcv;
837 GC gc; 881 GC gc;
838 882
839 /* In this case we can tint image server-side getting significant 883 /* In this case we can tint image server-side getting significant
849 ret = true; 893 ret = true;
850 XFreeGC (dpy, gc); 894 XFreeGC (dpy, gc);
851 } 895 }
852 } 896 }
853# if XRENDER 897# if XRENDER
854 else if (bg_flags & BG_HAS_RENDER) 898 else if (display->flags & DISPLAY_HAS_RENDER)
855 { 899 {
856 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
857
858 if (bg_flags & BG_TINT_SET)
859 tint.get (c);
860
861 if (shade <= 100) 900 if (shade <= 100)
862 { 901 {
863 c.r = c.r * shade / 100; 902 c.r = c.r * shade / 100;
864 c.g = c.g * shade / 100; 903 c.g = c.g * shade / 100;
865 c.b = c.b * shade / 100; 904 c.b = c.b * shade / 100;
869 c.r = c.r * (200 - shade) / 100; 908 c.r = c.r * (200 - shade) / 100;
870 c.g = c.g * (200 - shade) / 100; 909 c.g = c.g * (200 - shade) / 100;
871 c.b = c.b * (200 - shade) / 100; 910 c.b = c.b * (200 - shade) / 100;
872 } 911 }
873 912
874 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 913 XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32)
914 : XRenderFindVisualFormat (dpy, visual);
875 915
876 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0); 916 Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0);
877 917
878 Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False); 918 Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False);
879 919
915# endif 955# endif
916 956
917 return ret; 957 return ret;
918} 958}
919 959
960# if ENABLE_TRANSPARENCY
920/* 961/*
921 * Builds a pixmap of the same size as the terminal window that contains 962 * Builds a pixmap of the same size as the terminal window that contains
922 * the tiled portion of the root pixmap that is supposed to be covered by 963 * the tiled portion of the root pixmap that is supposed to be covered by
923 * our window. 964 * our window.
924 */ 965 */
925bool 966bool
926rxvt_term::make_transparency_pixmap () 967rxvt_term::render_root_image ()
927{ 968{
928 bool ret = false; 969 bool ret = false;
929 970
930 /* root dimensions may change from call to call - but Display structure should 971 /* root dimensions may change from call to call - but Display structure should
931 * be always up-to-date, so let's use it : 972 * be always up-to-date, so let's use it :
967 Pixmap recoded_root_pmap = root_pixmap; 1008 Pixmap recoded_root_pmap = root_pixmap;
968 1009
969 if (root_pixmap != None && root_depth != depth) 1010 if (root_pixmap != None && root_depth != depth)
970 { 1011 {
971#if XRENDER 1012#if XRENDER
972 if (bg_flags & BG_HAS_RENDER) 1013 if (display->flags & DISPLAY_HAS_RENDER)
973 { 1014 {
974 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); 1015 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth);
975 1016
976 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); 1017 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
977 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0); 1018 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0);
1015 1056
1016 if (gc) 1057 if (gc)
1017 { 1058 {
1018 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); 1059 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height);
1019 ret = true; 1060 ret = true;
1020 bool need_blur = h_blurRadius && v_blurRadius; 1061 bool need_blur = root_effects.need_blur ();
1021 bool need_tint = shade != 100 || (bg_flags & BG_TINT_SET); 1062 bool need_tint = root_effects.need_tint ();
1022 1063
1023 if (!(bg_flags & BG_CLIENT_RENDER))
1024 {
1025 if (need_blur) 1064 if (need_blur)
1065 {
1066 if (blur_pixmap (bg_pixmap, window_width, window_height, false,
1067 root_effects.h_blurRadius, root_effects.v_blurRadius))
1068 need_blur = false;
1069 }
1070 if (need_tint)
1071 {
1072 if (tint_pixmap (bg_pixmap, window_width, window_height, false,
1073 root_effects.tint, root_effects.tint_set, root_effects.shade))
1074 need_tint = false;
1075 }
1076 if (need_tint)
1077 {
1078 XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1079 if (ximage)
1026 { 1080 {
1027 if (blur_pixmap (bg_pixmap, window_width, window_height)) 1081 /* our own client-side tinting */
1028 need_blur = false; 1082 tint_ximage (ximage, root_effects.tint, root_effects.tint_set, root_effects.shade);
1083
1084 XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height);
1085 XDestroyImage (ximage);
1029 } 1086 }
1030 if (need_tint)
1031 {
1032 if (tint_pixmap (bg_pixmap, window_width, window_height))
1033 need_tint = false;
1034 } 1087 }
1035 if (need_tint)
1036 {
1037 XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1038 if (ximage)
1039 {
1040 /* our own client-side tinting */
1041 tint_ximage (ximage);
1042
1043 XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height);
1044 XDestroyImage (ximage);
1045 }
1046 }
1047 } /* server side rendering completed */
1048 1088
1049 XFreeGC (dpy, gc); 1089 XFreeGC (dpy, gc);
1050 } 1090 }
1051 1091
1052 if (recoded_root_pmap != root_pixmap) 1092 if (recoded_root_pmap != root_pixmap)
1056} 1096}
1057 1097
1058void 1098void
1059rxvt_term::bg_set_root_pixmap () 1099rxvt_term::bg_set_root_pixmap ()
1060{ 1100{
1061 Pixmap new_root_pixmap = get_pixmap_property (xa[XA_XROOTPMAP_ID]); 1101 Pixmap new_root_pixmap = display->get_pixmap_property (xa[XA_XROOTPMAP_ID]);
1062 if (new_root_pixmap == None) 1102 if (new_root_pixmap == None)
1063 new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]); 1103 new_root_pixmap = display->get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]);
1064 1104
1065 root_pixmap = new_root_pixmap; 1105 root_pixmap = new_root_pixmap;
1066} 1106}
1067# endif /* ENABLE_TRANSPARENCY */ 1107# endif /* ENABLE_TRANSPARENCY */
1068 1108
1069bool 1109void
1070rxvt_term::bg_render () 1110rxvt_term::bg_render ()
1071{ 1111{
1072 bg_invalidate (); 1112 bg_invalidate ();
1073# ifdef ENABLE_TRANSPARENCY 1113# if ENABLE_TRANSPARENCY
1074 if (bg_flags & BG_IS_TRANSPARENT) 1114 if (bg_flags & BG_IS_TRANSPARENT)
1075 { 1115 {
1076 /* we need to re-generate transparency pixmap in that case ! */ 1116 /* we need to re-generate transparency pixmap in that case ! */
1077 if (make_transparency_pixmap ()) 1117 if (render_root_image ())
1078 bg_flags |= BG_IS_VALID; 1118 bg_flags |= BG_IS_VALID;
1079 } 1119 }
1080# endif 1120# endif
1081 1121
1082# ifdef BG_IMAGE_FROM_FILE 1122# if BG_IMAGE_FROM_FILE
1083 if (bg_image.flags & IM_IS_SET) 1123 if (fimage.flags & IM_IS_SET)
1084 { 1124 {
1085 if (render_image (bg_image)) 1125 if (render_image (fimage))
1086 bg_flags |= BG_IS_VALID; 1126 bg_flags |= BG_IS_VALID;
1087 } 1127 }
1088# endif 1128# endif
1089 1129
1090 if (!(bg_flags & BG_IS_VALID)) 1130 if (!(bg_flags & BG_IS_VALID))
1098 1138
1099 scr_recolour (false); 1139 scr_recolour (false);
1100 bg_flags |= BG_NEEDS_REFRESH; 1140 bg_flags |= BG_NEEDS_REFRESH;
1101 1141
1102 bg_valid_since = ev::now (); 1142 bg_valid_since = ev::now ();
1103
1104 return true;
1105} 1143}
1106 1144
1107void 1145void
1108rxvt_term::bg_init () 1146rxvt_term::bg_init ()
1109{ 1147{
1110#ifdef ENABLE_TRANSPARENCY 1148#if BG_IMAGE_FROM_FILE
1111 shade = 100; 1149 if (rs[Rs_backgroundPixmap])
1150 {
1151 if (fimage.set_file_geometry (rs[Rs_backgroundPixmap])
1152 && !bg_window_position_sensitive ())
1153 update_background ();
1154 }
1112#endif 1155#endif
1113
1114 bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV);
1115#if XRENDER
1116 int major, minor;
1117 if (XRenderQueryVersion (dpy, &major, &minor))
1118 bg_flags |= BG_HAS_RENDER;
1119 XFilters *filters = XRenderQueryFilters (dpy, vt);
1120 if (filters)
1121 {
1122 for (int i = 0; i < filters->nfilter; i++)
1123 if (!strcmp (filters->filter[i], FilterConvolution))
1124 bg_flags |= BG_HAS_RENDER_CONV;
1125
1126 XFree (filters);
1127 }
1128#endif
1129} 1156}
1130 1157
1131#endif /* HAVE_BG_PIXMAP */
1132
1133#ifdef ENABLE_TRANSPARENCY
1134/* based on code from aterm-0.4.2 */ 1158/* based on code from aterm-0.4.2 */
1135 1159
1136static inline void 1160static inline void
1137fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high) 1161fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high)
1138{ 1162{
1144 lookup[i] = (tmp / 0xffff) << sh; 1168 lookup[i] = (tmp / 0xffff) << sh;
1145 } 1169 }
1146} 1170}
1147 1171
1148void 1172void
1149rxvt_term::tint_ximage (XImage *ximage) 1173rxvt_term::tint_ximage (XImage *ximage, rxvt_color &tint, bool tint_set, int shade)
1150{ 1174{
1151 unsigned int size_r, size_g, size_b; 1175 unsigned int size_r, size_g, size_b;
1152 int sh_r, sh_g, sh_b; 1176 int sh_r, sh_g, sh_b;
1153 uint32_t mask_r, mask_g, mask_b; 1177 uint32_t mask_r, mask_g, mask_b;
1154 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1178 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1179 lookup_g = lookup + size_r; 1203 lookup_g = lookup + size_r;
1180 lookup_b = lookup + size_r + size_g; 1204 lookup_b = lookup + size_r + size_g;
1181 1205
1182 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); 1206 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
1183 1207
1184 if (bg_flags & BG_TINT_SET) 1208 if (tint_set)
1185 tint.get (c); 1209 tint.get (c);
1186 1210
1187 /* prepare limits for color transformation (each channel is handled separately) */ 1211 /* prepare limits for color transformation (each channel is handled separately) */
1188 if (shade > 100) 1212 if (shade > 100)
1189 { 1213 {
1239 } 1263 }
1240 } 1264 }
1241 1265
1242 free (lookup); 1266 free (lookup);
1243} 1267}
1244#endif /* ENABLE_TRANSPARENCY */ 1268
1269#endif /* HAVE_BG_PIXMAP */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines