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.133 by sf-exg, Tue Jan 11 09:21:14 2011 UTC vs.
Revision 1.144 by sf-exg, Fri Jan 28 00:20:47 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
81 * scale Scale both up and down 59 * scale Scale both up and down
82 * auto Same as 100x100+50+50 60 * auto Same as 100x100+50+50
83 */ 61 */
84 62
85#ifdef HAVE_BG_PIXMAP 63#ifdef HAVE_BG_PIXMAP
86bgPixmap_t::bgPixmap_t ()
87{
88 // this is basically redundant as bgPixmap_t is only used in
89 // zero_initialised-derived structs
90#ifdef HAVE_AFTERIMAGE
91 original_asim = NULL;
92#endif
93#ifdef HAVE_PIXBUF
94 pixbuf = NULL;
95#endif
96#ifdef BG_IMAGE_FROM_FILE
97 have_image = false;
98 h_scale = v_scale = 0;
99 h_align = v_align = 0;
100#endif
101#ifdef ENABLE_TRANSPARENCY
102 shade = 100;
103#endif
104 flags = 0;
105 pixmap = None;
106 valid_since = invalid_since = 0;
107 target = 0;
108 target_x = target_y = 0;
109}
110
111void 64void
112bgPixmap_t::destroy () 65rxvt_term::bg_destroy ()
113{ 66{
114#ifdef HAVE_AFTERIMAGE 67#ifdef HAVE_AFTERIMAGE
115 if (original_asim) 68 if (original_asim)
116 safe_asimage_destroy (original_asim); 69 safe_asimage_destroy (original_asim);
117#endif 70#endif
119#ifdef HAVE_PIXBUF 72#ifdef HAVE_PIXBUF
120 if (pixbuf) 73 if (pixbuf)
121 g_object_unref (pixbuf); 74 g_object_unref (pixbuf);
122#endif 75#endif
123 76
124 if (pixmap && target) 77 if (bg_pixmap)
125 XFreePixmap (target->dpy, pixmap); 78 XFreePixmap (dpy, bg_pixmap);
126} 79}
127 80
128bool 81bool
129bgPixmap_t::set_position (int x, int y) 82rxvt_term::bg_set_position (int x, int y)
130{ 83{
131 84
132 if (target_x != x 85 if (target_x != x
133 || target_y != y) 86 || target_y != y)
134 { 87 {
138 } 91 }
139 return false; 92 return false;
140} 93}
141 94
142bool 95bool
143bgPixmap_t::window_size_sensitive () 96rxvt_term::bg_window_size_sensitive ()
144{ 97{
145# ifdef ENABLE_TRANSPARENCY 98# ifdef ENABLE_TRANSPARENCY
146 if (flags & isTransparent) 99 if (bg_flags & BG_IS_TRANSPARENT)
147 return true; 100 return true;
148# endif 101# endif
149 102
150# ifdef BG_IMAGE_FROM_FILE 103# ifdef BG_IMAGE_FROM_FILE
151 if (have_image) 104 if (bg_flags & BG_IS_FROM_FILE)
152 { 105 {
153 if (flags & sizeSensitive) 106 if (bg_flags & BG_IS_SIZE_SENSITIVE)
154 return true; 107 return true;
155 } 108 }
156# endif 109# endif
157 110
158 return false; 111 return false;
159} 112}
160 113
161bool 114bool
162bgPixmap_t::window_position_sensitive () 115rxvt_term::bg_window_position_sensitive ()
163{ 116{
164# ifdef ENABLE_TRANSPARENCY 117# ifdef ENABLE_TRANSPARENCY
165 if (flags & isTransparent) 118 if (bg_flags & BG_IS_TRANSPARENT)
166 return true; 119 return true;
167# endif 120# endif
168 121
169# ifdef BG_IMAGE_FROM_FILE 122# ifdef BG_IMAGE_FROM_FILE
170 if (have_image) 123 if (bg_flags & BG_IS_FROM_FILE)
171 { 124 {
172 if (flags & rootAlign) 125 if (bg_flags & BG_ROOT_ALIGN)
173 return true; 126 return true;
174 } 127 }
175# endif 128# endif
176 129
177 return false; 130 return false;
244 dst_size = target_size - dst_pos; 197 dst_size = target_size - dst_pos;
245 return src_pos; 198 return src_pos;
246} 199}
247 200
248bool 201bool
249bgPixmap_t::set_geometry (const char *geom, bool update) 202rxvt_term::bg_set_geometry (const char *geom, bool update)
250{ 203{
251 bool changed = false; 204 bool changed = false;
252 int geom_flags = 0; 205 int geom_flags = 0;
253 int x = 0, y = 0; 206 int x = 0, y = 0;
254 unsigned int w = 0, h = 0; 207 unsigned int w = 0, h = 0;
255 unsigned int n; 208 unsigned int n;
256 unsigned long new_flags = (flags & (~geometryFlags)); 209 unsigned long new_flags = (bg_flags & (~BG_GEOMETRY_FLAGS));
257 const char *ops; 210 const char *ops;
258 211
259 if (geom == NULL) 212 if (geom == NULL)
260 return false; 213 return false;
261 214
308 w = h = noScale; 261 w = h = noScale;
309 geom_flags |= WidthValue|HeightValue; 262 geom_flags |= WidthValue|HeightValue;
310 } 263 }
311 else if (!strcasecmp (arr[i], "propscale")) 264 else if (!strcasecmp (arr[i], "propscale"))
312 { 265 {
313 new_flags |= propScale; 266 new_flags |= BG_PROP_SCALE;
314 } 267 }
315 else if (!strcasecmp (arr[i], "hscale")) 268 else if (!strcasecmp (arr[i], "hscale"))
316 { 269 {
317 if (w == 0) w = windowScale; 270 if (w == 0) w = windowScale;
318 271
339 x = y = centerAlign; 292 x = y = centerAlign;
340 geom_flags |= WidthValue|HeightValue|XValue|YValue; 293 geom_flags |= WidthValue|HeightValue|XValue|YValue;
341 } 294 }
342 else if (!strcasecmp (arr[i], "root")) 295 else if (!strcasecmp (arr[i], "root"))
343 { 296 {
344 new_flags |= rootAlign; 297 new_flags |= BG_ROOT_ALIGN;
345 w = h = noScale; 298 w = h = noScale;
346 geom_flags |= WidthValue|HeightValue; 299 geom_flags |= WidthValue|HeightValue;
347 } 300 }
348 } /* done parsing ops */ 301 } /* done parsing ops */
349 302
353 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true; 306 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true;
354 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true; 307 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true;
355 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true; 308 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true;
356 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true; 309 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true;
357 310
358 if (new_flags != flags) 311 if (new_flags != bg_flags)
359 { 312 {
360 flags = new_flags; 313 bg_flags = new_flags;
361 changed = true; 314 changed = true;
362 } 315 }
363 316
364 return changed; 317 return changed;
365} 318}
366 319
367void 320void
368bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) 321rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y)
369{ 322{
370 int target_width = target->szHint.width; 323 int target_width = szHint.width;
371 int target_height = target->szHint.height; 324 int target_height = szHint.height;
372 325
373 if (flags & propScale) 326 if (bg_flags & BG_PROP_SCALE)
374 { 327 {
375 float scale = (float)target_width / image_width; 328 float scale = (float)target_width / image_width;
376 min_it (scale, (float)target_height / image_height); 329 min_it (scale, (float)target_height / image_height);
377 w = image_width * scale + 0.5; 330 w = image_width * scale + 0.5;
378 h = image_height * scale + 0.5; 331 h = image_height * scale + 0.5;
384 } 337 }
385 338
386 if (!w) w = image_width; 339 if (!w) w = image_width;
387 if (!h) h = image_height; 340 if (!h) h = image_height;
388 341
389 if (flags & rootAlign) 342 if (bg_flags & BG_ROOT_ALIGN)
390 { 343 {
391 x = -target_x; 344 x = -target_x;
392 y = -target_y; 345 y = -target_y;
393 } 346 }
394 else 347 else
395 { 348 {
396 x = make_align_position (h_align, target_width, w); 349 x = make_align_position (h_align, target_width, w);
397 y = make_align_position (v_align, target_height, h); 350 y = make_align_position (v_align, target_height, h);
398 } 351 }
399 352
400 flags &= ~sizeSensitive; 353 bg_flags &= ~BG_IS_SIZE_SENSITIVE;
401 if ((flags & propScale) || h_scale || v_scale 354 if ((bg_flags & BG_PROP_SCALE) || h_scale || v_scale
402 || (!(flags & rootAlign) && (h_align || v_align)) 355 || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align))
403 || w > target_width || h > target_height) 356 || w > target_width || h > target_height)
404 flags |= sizeSensitive; 357 bg_flags |= BG_IS_SIZE_SENSITIVE;
405} 358}
406 359
407# ifdef HAVE_AFTERIMAGE 360# ifdef HAVE_AFTERIMAGE
408bool 361bool
409bgPixmap_t::render_image (unsigned long background_flags) 362rxvt_term::render_image (unsigned long tr_flags)
410{ 363{
411 if (target == NULL)
412 return false;
413
414 target->init_asv (); 364 init_asv ();
415 365
416 ASImage *background = NULL; 366 ASImage *background = NULL;
417 ARGB32 background_tint = TINT_LEAVE_SAME; 367 ARGB32 background_tint = TINT_LEAVE_SAME;
418 368
419# ifdef ENABLE_TRANSPARENCY 369# ifdef ENABLE_TRANSPARENCY
420 if (background_flags) 370 if (tr_flags)
421 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100); 371 background = pixmap2ximage (asv, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, 100);
422 372
423 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 373 if (tr_flags & BG_NEEDS_TINT)
424 { 374 {
425 ShadingInfo as_shade; 375 ShadingInfo as_shade;
426 as_shade.shading = shade; 376 as_shade.shading = shade;
427 377
428 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 378 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
429 if (flags & tintSet) 379 if (bg_flags & BG_TINT_SET)
430 tint.get (c); 380 tint.get (c);
431 as_shade.tintColor.red = c.r; 381 as_shade.tintColor.red = c.r;
432 as_shade.tintColor.green = c.g; 382 as_shade.tintColor.green = c.g;
433 as_shade.tintColor.blue = c.b; 383 as_shade.tintColor.blue = c.b;
434 384
435 background_tint = shading2tint32 (&as_shade); 385 background_tint = shading2tint32 (&as_shade);
436 } 386 }
437 387
438 if (!(background_flags & transpPmapBlurred) && (flags & blurNeeded) && background != NULL) 388 if ((tr_flags & BG_NEEDS_BLUR) && background != NULL)
439 { 389 {
440 ASImage *tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, 390 ASImage *tmp = blur_asimage_gauss (asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
441 (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage, 391 (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage,
442 100, ASIMAGE_QUALITY_DEFAULT); 392 100, ASIMAGE_QUALITY_DEFAULT);
443 if (tmp) 393 if (tmp)
444 { 394 {
445 destroy_asimage (&background); 395 destroy_asimage (&background);
448 } 398 }
449# endif 399# endif
450 400
451 ASImage *result = 0; 401 ASImage *result = 0;
452 402
453 int target_width = target->szHint.width; 403 int target_width = szHint.width;
454 int target_height = target->szHint.height; 404 int target_height = szHint.height;
455 int new_pmap_width = target_width; 405 int new_pmap_width = target_width;
456 int new_pmap_height = target_height; 406 int new_pmap_height = target_height;
457 407
458 int x = 0; 408 int x = 0;
459 int y = 0; 409 int y = 0;
462 412
463 if (original_asim) 413 if (original_asim)
464 get_image_geometry (original_asim->width, original_asim->height, w, h, x, y); 414 get_image_geometry (original_asim->width, original_asim->height, w, h, x, y);
465 415
466 if (!original_asim 416 if (!original_asim
467 || (!(flags & rootAlign) 417 || (!(bg_flags & BG_ROOT_ALIGN)
468 && (x >= target_width 418 && (x >= target_width
469 || y >= target_height 419 || y >= target_height
470 || (x + w <= 0) 420 || (x + w <= 0)
471 || (y + h <= 0)))) 421 || (y + h <= 0))))
472 { 422 {
476 new_pmap_height = background->height; 426 new_pmap_height = background->height;
477 result = background; 427 result = background;
478 428
479 if (background_tint != TINT_LEAVE_SAME) 429 if (background_tint != TINT_LEAVE_SAME)
480 { 430 {
481 ASImage *tmp = tile_asimage (target->asv, background, 0, 0, 431 ASImage *tmp = tile_asimage (asv, background, 0, 0,
482 target_width, target_height, background_tint, 432 target_width, target_height, background_tint,
483 ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); 433 ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT);
484 if (tmp) 434 if (tmp)
485 result = tmp; 435 result = tmp;
486 } 436 }
493 result = original_asim; 443 result = original_asim;
494 444
495 if ((w != original_asim->width) 445 if ((w != original_asim->width)
496 || (h != original_asim->height)) 446 || (h != original_asim->height))
497 { 447 {
498 result = scale_asimage (target->asv, original_asim, 448 result = scale_asimage (asv, original_asim,
499 w, h, 449 w, h,
500 background ? ASA_ASImage : ASA_XImage, 450 background ? ASA_ASImage : ASA_XImage,
501 100, ASIMAGE_QUALITY_DEFAULT); 451 100, ASIMAGE_QUALITY_DEFAULT);
502 } 452 }
503 453
509 but there is no need to make it bigger than the window! */ 459 but there is no need to make it bigger than the window! */
510 new_pmap_width = min (result->width, target_width); 460 new_pmap_width = min (result->width, target_width);
511 new_pmap_height = min (result->height, target_height); 461 new_pmap_height = min (result->height, target_height);
512 462
513 /* we also need to tile our image in both directions */ 463 /* we also need to tile our image in both directions */
514 ASImage *tmp = tile_asimage (target->asv, result, 464 ASImage *tmp = tile_asimage (asv, result,
515 (int)result->width - x, 465 (int)result->width - x,
516 (int)result->height - y, 466 (int)result->height - y,
517 new_pmap_width, 467 new_pmap_width,
518 new_pmap_height, 468 new_pmap_height,
519 TINT_LEAVE_SAME, ASA_XImage, 469 TINT_LEAVE_SAME, ASA_XImage,
562 { 512 {
563 layers[1].dst_y = y; 513 layers[1].dst_y = y;
564 layers[1].clip_height = result->height; 514 layers[1].clip_height = result->height;
565 } 515 }
566 516
567 if (target->rs[Rs_blendtype]) 517 if (rs[Rs_blendtype])
568 { 518 {
569 layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]); 519 layers[1].merge_scanlines = blend_scanlines_name2func (rs[Rs_blendtype]);
570 if (layers[1].merge_scanlines == NULL) 520 if (layers[1].merge_scanlines == NULL)
571 layers[1].merge_scanlines = alphablend_scanlines; 521 layers[1].merge_scanlines = alphablend_scanlines;
572 } 522 }
573 523
574 ASImage *tmp = merge_layers (target->asv, layers, 2, target_width, target_height, 524 ASImage *tmp = merge_layers (asv, layers, 2, target_width, target_height,
575 ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); 525 ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT);
576 526
577 if (tmp) 527 if (tmp)
578 { 528 {
579 if (result != original_asim) 529 if (result != original_asim)
592 { 542 {
593 XGCValues gcv; 543 XGCValues gcv;
594 GC gc; 544 GC gc;
595 545
596 /* create Pixmap */ 546 /* create Pixmap */
597 if (pixmap == None 547 if (bg_pixmap == None
598 || pmap_width != new_pmap_width 548 || bg_pmap_width != new_pmap_width
599 || pmap_height != new_pmap_height 549 || bg_pmap_height != new_pmap_height)
600 || pmap_depth != target->depth)
601 { 550 {
602 if (pixmap) 551 if (bg_pixmap)
603 XFreePixmap (target->dpy, pixmap); 552 XFreePixmap (dpy, bg_pixmap);
604 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 553 bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth);
605 pmap_width = new_pmap_width; 554 bg_pmap_width = new_pmap_width;
606 pmap_height = new_pmap_height; 555 bg_pmap_height = new_pmap_height;
607 pmap_depth = target->depth;
608 } 556 }
609 /* fill with background color (if result's not completely overlapping it) */ 557 /* fill with background color (if result's not completely overlapping it) */
610 gcv.foreground = target->pix_colors[Color_bg]; 558 gcv.foreground = pix_colors[Color_bg];
611 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); 559 gc = XCreateGC (dpy, vt, GCForeground, &gcv);
612 560
613 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; 561 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0;
614 int dst_width = result->width, dst_height = result->height; 562 int dst_width = result->width, dst_height = result->height;
615 if (background == NULL) 563 if (background == NULL)
616 { 564 {
621 } 569 }
622 570
623 if (dst_x > 0 || dst_y > 0 571 if (dst_x > 0 || dst_y > 0
624 || dst_x + dst_width < new_pmap_width 572 || dst_x + dst_width < new_pmap_width
625 || dst_y + dst_height < new_pmap_height) 573 || dst_y + dst_height < new_pmap_height)
626 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 574 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
627 } 575 }
628 576
629 /* put result on pixmap */ 577 /* put result on pixmap */
630 if (dst_x < new_pmap_width && dst_y < new_pmap_height) 578 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
631 asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True); 579 asimage2drawable (asv, bg_pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True);
632 580
633 if (result != background && result != original_asim) 581 if (result != background && result != original_asim)
634 destroy_asimage (&result); 582 destroy_asimage (&result);
635 583
636 XFreeGC (target->dpy, gc); 584 XFreeGC (dpy, gc);
637 585
638 ret = true; 586 ret = true;
639 } 587 }
640 588
641 if (background) 589 if (background)
645} 593}
646# endif /* HAVE_AFTERIMAGE */ 594# endif /* HAVE_AFTERIMAGE */
647 595
648# ifdef HAVE_PIXBUF 596# ifdef HAVE_PIXBUF
649bool 597bool
650bgPixmap_t::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, 598rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc,
651 int src_x, int src_y, int dst_x, int dst_y, 599 int src_x, int src_y, int dst_x, int dst_y,
652 unsigned int width, unsigned int height) 600 unsigned int width, unsigned int height)
653{ 601{
654 XImage *ximage; 602 XImage *ximage;
655 char *data, *line; 603 char *data, *line;
656 int bytes_per_pixel; 604 int bytes_per_pixel;
657 int width_r, width_g, width_b; 605 int width_r, width_g, width_b;
658 int sh_r, sh_g, sh_b; 606 int sh_r, sh_g, sh_b;
659 int rowstride; 607 int rowstride;
660 int channels; 608 int channels;
661 unsigned char *row; 609 unsigned char *row;
662 Visual *visual = target->visual;
663 int depth = target->depth;
664 610
665 if (visual->c_class != TrueColor) 611 if (visual->c_class != TrueColor)
666 return false; 612 return false;
667 613
668 if (depth == 24 || depth == 32) 614 if (depth == 24 || depth == 32)
688 634
689 data = (char *)malloc (width * height * bytes_per_pixel); 635 data = (char *)malloc (width * height * bytes_per_pixel);
690 if (!data) 636 if (!data)
691 return false; 637 return false;
692 638
693 ximage = XCreateImage (target->dpy, visual, depth, ZPixmap, 0, data, 639 ximage = XCreateImage (dpy, visual, depth, ZPixmap, 0, data,
694 width, height, bytes_per_pixel * 8, 0); 640 width, height, bytes_per_pixel * 8, 0);
695 if (!ximage) 641 if (!ximage)
696 { 642 {
697 free (data); 643 free (data);
698 return false; 644 return false;
724 670
725 row += rowstride; 671 row += rowstride;
726 line += ximage->bytes_per_line; 672 line += ximage->bytes_per_line;
727 } 673 }
728 674
729 XPutImage (target->dpy, pixmap, gc, ximage, 0, 0, dst_x, dst_y, width, height); 675 XPutImage (dpy, pixmap, gc, ximage, 0, 0, dst_x, dst_y, width, height);
730 XDestroyImage (ximage); 676 XDestroyImage (ximage);
731 return true; 677 return true;
732} 678}
733 679
734bool 680bool
735bgPixmap_t::render_image (unsigned long background_flags) 681rxvt_term::render_image (unsigned long tr_flags)
736{ 682{
737 if (target == NULL)
738 return false;
739
740 if (!pixbuf) 683 if (!pixbuf)
741 return false; 684 return false;
742 685
743 if (background_flags 686 if (tr_flags
744 && !(flags & HAS_RENDER)) 687 && !(bg_flags & BG_HAS_RENDER))
745 return false; 688 return false;
746 689
747 GdkPixbuf *result; 690 GdkPixbuf *result;
748 691
749 int image_width = gdk_pixbuf_get_width (pixbuf); 692 int image_width = gdk_pixbuf_get_width (pixbuf);
750 int image_height = gdk_pixbuf_get_height (pixbuf); 693 int image_height = gdk_pixbuf_get_height (pixbuf);
751 694
752 int target_width = target->szHint.width; 695 int target_width = szHint.width;
753 int target_height = target->szHint.height; 696 int target_height = szHint.height;
754 int new_pmap_width = target_width; 697 int new_pmap_width = target_width;
755 int new_pmap_height = target_height; 698 int new_pmap_height = target_height;
756 699
757 int x = 0; 700 int x = 0;
758 int y = 0; 701 int y = 0;
759 int w = 0; 702 int w = 0;
760 int h = 0; 703 int h = 0;
761 704
762 get_image_geometry (image_width, image_height, w, h, x, y); 705 get_image_geometry (image_width, image_height, w, h, x, y);
763 706
764 if (!(flags & rootAlign) 707 if (!(bg_flags & BG_ROOT_ALIGN)
765 && (x >= target_width 708 && (x >= target_width
766 || y >= target_height 709 || y >= target_height
767 || (x + w <= 0) 710 || (x + w <= 0)
768 || (y + h <= 0))) 711 || (y + h <= 0)))
769 return false; 712 return false;
787 Pixmap root_pmap; 730 Pixmap root_pmap;
788 731
789 image_width = gdk_pixbuf_get_width (result); 732 image_width = gdk_pixbuf_get_width (result);
790 image_height = gdk_pixbuf_get_height (result); 733 image_height = gdk_pixbuf_get_height (result);
791 734
792 if (background_flags) 735 if (tr_flags)
793 { 736 {
794 root_pmap = pixmap; 737 root_pmap = bg_pixmap;
795 pixmap = None; 738 bg_pixmap = None;
796 } 739 }
797 else 740 else
798 { 741 {
799 if (h_scale == 0 || v_scale == 0) 742 if (h_scale == 0 || v_scale == 0)
800 { 743 {
801 new_pmap_width = min (image_width, target_width); 744 new_pmap_width = min (image_width, target_width);
802 new_pmap_height = min (image_height, target_height); 745 new_pmap_height = min (image_height, target_height);
803 } 746 }
804 } 747 }
805 748
806 if (pixmap == None 749 if (bg_pixmap == None
807 || pmap_width != new_pmap_width 750 || bg_pmap_width != new_pmap_width
808 || pmap_height != new_pmap_height 751 || bg_pmap_height != new_pmap_height)
809 || pmap_depth != target->depth)
810 { 752 {
811 if (pixmap) 753 if (bg_pixmap)
812 XFreePixmap (target->dpy, pixmap); 754 XFreePixmap (dpy, bg_pixmap);
813 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 755 bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth);
814 pmap_width = new_pmap_width; 756 bg_pmap_width = new_pmap_width;
815 pmap_height = new_pmap_height; 757 bg_pmap_height = new_pmap_height;
816 pmap_depth = target->depth;
817 } 758 }
818 759
819 gcv.foreground = target->pix_colors[Color_bg]; 760 gcv.foreground = pix_colors[Color_bg];
820 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); 761 gc = XCreateGC (dpy, vt, GCForeground, &gcv);
821 762
822 if (h_scale == 0 || v_scale == 0) 763 if (h_scale == 0 || v_scale == 0)
823 { 764 {
824 Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth); 765 Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth);
825 pixbuf_to_pixmap (result, tile, gc, 766 pixbuf_to_pixmap (result, tile, gc,
826 0, 0, 767 0, 0,
827 0, 0, 768 0, 0,
828 image_width, image_height); 769 image_width, image_height);
829 770
830 gcv.tile = tile; 771 gcv.tile = tile;
831 gcv.fill_style = FillTiled; 772 gcv.fill_style = FillTiled;
832 gcv.ts_x_origin = x; 773 gcv.ts_x_origin = x;
833 gcv.ts_y_origin = y; 774 gcv.ts_y_origin = y;
834 XChangeGC (target->dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 775 XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
835 776
836 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 777 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
837 XFreePixmap (target->dpy, tile); 778 XFreePixmap (dpy, tile);
838 } 779 }
839 else 780 else
840 { 781 {
841 int src_x, src_y, dst_x, dst_y; 782 int src_x, src_y, dst_x, dst_y;
842 int dst_width, dst_height; 783 int dst_width, dst_height;
845 src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); 786 src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height);
846 787
847 if (dst_x > 0 || dst_y > 0 788 if (dst_x > 0 || dst_y > 0
848 || dst_x + dst_width < new_pmap_width 789 || dst_x + dst_width < new_pmap_width
849 || dst_y + dst_height < new_pmap_height) 790 || dst_y + dst_height < new_pmap_height)
850 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 791 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
851 792
852 if (dst_x < new_pmap_width && dst_y < new_pmap_height) 793 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
853 pixbuf_to_pixmap (result, pixmap, gc, 794 pixbuf_to_pixmap (result, bg_pixmap, gc,
854 src_x, src_y, 795 src_x, src_y,
855 dst_x, dst_y, 796 dst_x, dst_y,
856 dst_width, dst_height); 797 dst_width, dst_height);
857 } 798 }
858 799
859#if XRENDER 800#if XRENDER
860 if (background_flags) 801 if (tr_flags)
861 { 802 {
862 Display *dpy = target->dpy;
863 XRenderPictureAttributes pa; 803 XRenderPictureAttributes pa;
864 804
865 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, target->visual); 805 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, visual);
866 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); 806 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa);
867 807
868 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); 808 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual);
869 Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa); 809 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, dst_format, 0, &pa);
870 810
871 pa.repeat = True; 811 pa.repeat = True;
872 Pixmap mask_pmap = XCreatePixmap (dpy, target->vt, 1, 1, 8); 812 Pixmap mask_pmap = XCreatePixmap (dpy, vt, 1, 1, 8);
873 XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8); 813 XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8);
874 Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa); 814 Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa);
875 XFreePixmap (dpy, mask_pmap); 815 XFreePixmap (dpy, mask_pmap);
876 816
877 if (src && dst && mask) 817 if (src && dst && mask)
895#endif 835#endif
896 836
897 if (result != pixbuf) 837 if (result != pixbuf)
898 g_object_unref (result); 838 g_object_unref (result);
899 839
900 XFreeGC (target->dpy, gc); 840 XFreeGC (dpy, gc);
901 841
902 ret = true; 842 ret = true;
903 } 843 }
904 844
905 return ret; 845 return ret;
906} 846}
907# endif /* HAVE_PIXBUF */ 847# endif /* HAVE_PIXBUF */
908 848
909bool 849bool
910bgPixmap_t::set_file (const char *file) 850rxvt_term::bg_set_file (const char *file)
911{ 851{
912 if (!file || !*file) 852 if (!file || !*file)
913 return false; 853 return false;
914 854
915 if (const char *p = strchr (file, ';')) 855 if (const char *p = strchr (file, ';'))
920 f[len] = '\0'; 860 f[len] = '\0';
921 file = f; 861 file = f;
922 } 862 }
923 863
924# ifdef HAVE_AFTERIMAGE 864# ifdef HAVE_AFTERIMAGE
925 if (!target->asimman) 865 if (!asimman)
926 target->asimman = create_generic_imageman (target->rs[Rs_path]); 866 asimman = create_generic_imageman (rs[Rs_path]);
927 ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); 867 ASImage *image = get_asimage (asimman, file, 0xFFFFFFFF, 100);
928 if (image) 868 if (image)
929 { 869 {
930 if (original_asim) 870 if (original_asim)
931 safe_asimage_destroy (original_asim); 871 safe_asimage_destroy (original_asim);
932 original_asim = image; 872 original_asim = image;
933 flags |= CLIENT_RENDER; 873 bg_flags |= BG_IS_FROM_FILE | BG_CLIENT_RENDER;
934 have_image = true;
935 return true; 874 return true;
936 } 875 }
937# endif 876# endif
938 877
939# ifdef HAVE_PIXBUF 878# ifdef HAVE_PIXBUF
941 if (image) 880 if (image)
942 { 881 {
943 if (pixbuf) 882 if (pixbuf)
944 g_object_unref (pixbuf); 883 g_object_unref (pixbuf);
945 pixbuf = image; 884 pixbuf = image;
946 have_image = true; 885 bg_flags |= BG_IS_FROM_FILE;
947 return true; 886 return true;
948 } 887 }
949# endif 888# endif
950 889
951 return false; 890 return false;
953 892
954# endif /* BG_IMAGE_FROM_FILE */ 893# endif /* BG_IMAGE_FROM_FILE */
955 894
956# ifdef ENABLE_TRANSPARENCY 895# ifdef ENABLE_TRANSPARENCY
957bool 896bool
958bgPixmap_t::set_transparent () 897rxvt_term::bg_set_transparent ()
959{ 898{
960 if (!(flags & isTransparent)) 899 if (!(bg_flags & BG_IS_TRANSPARENT))
961 { 900 {
962 flags |= isTransparent; 901 bg_flags |= BG_IS_TRANSPARENT;
963 return true; 902 return true;
964 } 903 }
965 904
966 return false; 905 return false;
967} 906}
968 907
969bool 908bool
970bgPixmap_t::set_blur_radius (const char *geom) 909rxvt_term::bg_set_blur (const char *geom)
971{ 910{
972 bool changed = false; 911 bool changed = false;
973 unsigned int hr, vr; 912 unsigned int hr, vr;
974 int junk; 913 int junk;
975 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); 914 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
993 changed = true; 932 changed = true;
994 v_blurRadius = vr; 933 v_blurRadius = vr;
995 } 934 }
996 935
997 if (v_blurRadius == 0 && h_blurRadius == 0) 936 if (v_blurRadius == 0 && h_blurRadius == 0)
998 flags &= ~blurNeeded; 937 bg_flags &= ~BG_NEEDS_BLUR;
999 else 938 else
1000 flags |= blurNeeded; 939 bg_flags |= BG_NEEDS_BLUR;
1001 940
1002 return changed; 941 return changed;
1003} 942}
1004 943
1005static inline unsigned long 944static inline unsigned long
1014 tint->get (c); 953 tint->get (c);
1015 if (!has_shade 954 if (!has_shade
1016 && (c.r <= 0x00ff || c.r >= 0xff00) 955 && (c.r <= 0x00ff || c.r >= 0xff00)
1017 && (c.g <= 0x00ff || c.g >= 0xff00) 956 && (c.g <= 0x00ff || c.g >= 0xff00)
1018 && (c.b <= 0x00ff || c.b >= 0xff00)) 957 && (c.b <= 0x00ff || c.b >= 0xff00))
1019 flags |= bgPixmap_t::tintWholesome; 958 flags |= rxvt_term::BG_TINT_BITAND;
1020 } 959 }
1021 960
1022 if (has_shade || tint) 961 if (has_shade || tint)
1023 flags |= bgPixmap_t::tintNeeded; 962 flags |= rxvt_term::BG_NEEDS_TINT;
1024 963
1025 return flags; 964 return flags;
1026} 965}
1027 966
1028bool 967bool
1029bgPixmap_t::set_tint (rxvt_color &new_tint) 968rxvt_term::bg_set_tint (rxvt_color &new_tint)
1030{ 969{
1031 if (!(flags & tintSet) || tint != new_tint) 970 if (!(bg_flags & BG_TINT_SET) || tint != new_tint)
1032 { 971 {
1033 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); 972 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade);
1034 tint = new_tint; 973 tint = new_tint;
1035 flags = (flags & ~tintFlags) | new_flags | tintSet; 974 bg_flags = (bg_flags & ~BG_TINT_FLAGS) | new_flags | BG_TINT_SET;
1036 return true; 975 return true;
1037 } 976 }
1038 977
1039 return false; 978 return false;
1040} 979}
1041 980
1042bool 981bool
1043bgPixmap_t::set_shade (const char *shade_str) 982rxvt_term::bg_set_shade (const char *shade_str)
1044{ 983{
1045 int new_shade = (shade_str) ? atoi (shade_str) : 100; 984 int new_shade = (shade_str) ? atoi (shade_str) : 100;
1046 985
1047 clamp_it (new_shade, -100, 200); 986 clamp_it (new_shade, -100, 200);
1048 if (new_shade < 0) 987 if (new_shade < 0)
1049 new_shade = 200 - (100 + new_shade); 988 new_shade = 200 - (100 + new_shade);
1050 989
1051 if (new_shade != shade) 990 if (new_shade != shade)
1052 { 991 {
1053 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); 992 unsigned long new_flags = compute_tint_shade_flags ((bg_flags & BG_TINT_SET) ? &tint : NULL, new_shade);
1054 shade = new_shade; 993 shade = new_shade;
1055 flags = (flags & (~tintFlags | tintSet)) | new_flags; 994 bg_flags = (bg_flags & ~BG_TINT_FLAGS) | new_flags;
1056 return true; 995 return true;
1057 } 996 }
1058 997
1059 return false; 998 return false;
1060} 999}
1081 params[i+2] = XDoubleToFixed (kernel[i] / sum); 1020 params[i+2] = XDoubleToFixed (kernel[i] / sum);
1082} 1021}
1083#endif 1022#endif
1084 1023
1085bool 1024bool
1086bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) 1025rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height)
1087{ 1026{
1088 bool ret = false; 1027 bool ret = false;
1089#if XRENDER 1028#if XRENDER
1090 int size = max (h_blurRadius, v_blurRadius) * 2 + 1; 1029 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
1091 double *kernel = (double *)malloc (size * sizeof (double)); 1030 double *kernel = (double *)malloc (size * sizeof (double));
1092 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 1031 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
1093 1032
1094 Display *dpy = target->dpy;
1095 XRenderPictureAttributes pa; 1033 XRenderPictureAttributes pa;
1096 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1034 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1097 1035
1098 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1036 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1099 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1037 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1119 1057
1120 if (v_blurRadius) 1058 if (v_blurRadius)
1121 { 1059 {
1122 size = v_blurRadius * 2 + 1; 1060 size = v_blurRadius * 2 + 1;
1123 get_gaussian_kernel (v_blurRadius, size, kernel, params); 1061 get_gaussian_kernel (v_blurRadius, size, kernel, params);
1124 swap (params[0], params[1]); 1062 ::swap (params[0], params[1]);
1125 1063
1126 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); 1064 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
1127 XRenderComposite (dpy, 1065 XRenderComposite (dpy,
1128 PictOpSrc, 1066 PictOpSrc,
1129 src, 1067 src,
1145#endif 1083#endif
1146 return ret; 1084 return ret;
1147} 1085}
1148 1086
1149bool 1087bool
1150bgPixmap_t::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) 1088rxvt_term::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height)
1151{ 1089{
1152 Display *dpy = target->dpy;
1153 bool ret = false; 1090 bool ret = false;
1154 1091
1155 if (flags & tintWholesome) 1092 if (bg_flags & BG_TINT_BITAND)
1156 { 1093 {
1157 XGCValues gcv; 1094 XGCValues gcv;
1158 GC gc; 1095 GC gc;
1159 1096
1160 /* In this case we can tint image server-side getting significant 1097 /* In this case we can tint image server-side getting significant
1174 else 1111 else
1175 { 1112 {
1176# if XRENDER 1113# if XRENDER
1177 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1114 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1178 1115
1179 if (flags & tintSet) 1116 if (bg_flags & BG_TINT_SET)
1180 tint.get (c); 1117 tint.get (c);
1181 1118
1182 if (shade <= 100) 1119 if (shade <= 100)
1183 { 1120 {
1184 c.r = (c.r * shade) / 100; 1121 c.r = (c.r * shade) / 100;
1249 * Builds a pixmap of the same size as the terminal window that contains 1186 * Builds a pixmap of the same size as the terminal window that contains
1250 * the tiled portion of the root pixmap that is supposed to be covered by 1187 * the tiled portion of the root pixmap that is supposed to be covered by
1251 * our window. 1188 * our window.
1252 */ 1189 */
1253unsigned long 1190unsigned long
1254bgPixmap_t::make_transparency_pixmap () 1191rxvt_term::make_transparency_pixmap ()
1255{ 1192{
1256 unsigned long result = 0; 1193 unsigned long result = 0;
1257
1258 if (target == NULL)
1259 return 0;
1260 1194
1261 /* root dimensions may change from call to call - but Display structure should 1195 /* root dimensions may change from call to call - but Display structure should
1262 * be always up-to-date, so let's use it : 1196 * be always up-to-date, so let's use it :
1263 */ 1197 */
1264 int screen = target->display->screen; 1198 int screen = display->screen;
1265 Display *dpy = target->dpy;
1266 int root_depth = DefaultDepth (dpy, screen); 1199 int root_depth = DefaultDepth (dpy, screen);
1267 int root_width = DisplayWidth (dpy, screen); 1200 int root_width = DisplayWidth (dpy, screen);
1268 int root_height = DisplayHeight (dpy, screen); 1201 int root_height = DisplayHeight (dpy, screen);
1269 unsigned int root_pmap_width, root_pmap_height; 1202 unsigned int root_pmap_width, root_pmap_height;
1270 int window_width = target->szHint.width; 1203 int window_width = szHint.width;
1271 int window_height = target->szHint.height; 1204 int window_height = szHint.height;
1272 int sx, sy; 1205 int sx, sy;
1273 XGCValues gcv; 1206 XGCValues gcv;
1274 GC gc; 1207 GC gc;
1275 1208
1276 sx = target_x; 1209 sx = target_x;
1286 { 1219 {
1287 Window wdummy; 1220 Window wdummy;
1288 int idummy; 1221 int idummy;
1289 unsigned int udummy; 1222 unsigned int udummy;
1290 1223
1291 target->allowedxerror = -1; 1224 allowedxerror = -1;
1292 1225
1293 if (!XGetGeometry (dpy, root_pixmap, &wdummy, &idummy, &idummy, &root_pmap_width, &root_pmap_height, &udummy, &udummy)) 1226 if (!XGetGeometry (dpy, root_pixmap, &wdummy, &idummy, &idummy, &root_pmap_width, &root_pmap_height, &udummy, &udummy))
1294 root_pixmap = None; 1227 root_pixmap = None;
1295 1228
1296 target->allowedxerror = 0; 1229 allowedxerror = 0;
1297 } 1230 }
1298 1231
1299 Pixmap recoded_root_pmap = root_pixmap; 1232 Pixmap recoded_root_pmap = root_pixmap;
1300 1233
1301 if (root_pixmap != None && root_depth != target->depth) 1234 if (root_pixmap != None && root_depth != depth)
1302 { 1235 {
1303#if XRENDER 1236#if XRENDER
1304 if (flags & HAS_RENDER) 1237 if (bg_flags & BG_HAS_RENDER)
1305 { 1238 {
1306 XRenderPictureAttributes pa; 1239 XRenderPictureAttributes pa;
1307 1240
1308 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); 1241 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
1309 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); 1242 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa);
1310 1243
1311 recoded_root_pmap = XCreatePixmap (dpy, target->vt, root_pmap_width, root_pmap_height, target->depth); 1244 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth);
1312 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); 1245 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual);
1313 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); 1246 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa);
1314 1247
1315 if (src && dst) 1248 if (src && dst)
1316 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); 1249 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height);
1317 else 1250 else
1329 } 1262 }
1330 1263
1331 if (root_pixmap == None) 1264 if (root_pixmap == None)
1332 return 0; 1265 return 0;
1333 1266
1267 if (bg_pixmap == None
1268 || bg_pmap_width != window_width
1269 || bg_pmap_height != window_height)
1270 {
1271 if (bg_pixmap)
1272 XFreePixmap (dpy, bg_pixmap);
1334 Pixmap tiled_root_pmap = XCreatePixmap (dpy, target->vt, window_width, window_height, target->depth); 1273 bg_pixmap = XCreatePixmap (dpy, vt, window_width, window_height, depth);
1274 bg_pmap_width = window_width;
1275 bg_pmap_height = window_height;
1276 }
1335 1277
1336 if (tiled_root_pmap == None) /* something really bad happened - abort */ 1278 if (bg_pixmap == None)
1337 return 0; 1279 return 0;
1338 1280
1339 /* straightforward pixmap copy */ 1281 /* straightforward pixmap copy */
1340 while (sx < 0) sx += (int)root_width; 1282 while (sx < 0) sx += (int)root_width;
1341 while (sy < 0) sy += (int)root_height; 1283 while (sy < 0) sy += (int)root_height;
1342 1284
1343 gcv.tile = recoded_root_pmap; 1285 gcv.tile = recoded_root_pmap;
1344 gcv.fill_style = FillTiled; 1286 gcv.fill_style = FillTiled;
1345 gcv.ts_x_origin = -sx; 1287 gcv.ts_x_origin = -sx;
1346 gcv.ts_y_origin = -sy; 1288 gcv.ts_y_origin = -sy;
1347 gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 1289 gc = XCreateGC (dpy, vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
1348 1290
1349 if (gc) 1291 if (gc)
1350 { 1292 {
1351 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); 1293 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height);
1352 result |= transpPmapTiled; 1294 result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS);
1353 XFreeGC (dpy, gc); 1295 XFreeGC (dpy, gc);
1354 1296
1355 if (!(flags & CLIENT_RENDER)) 1297 if (!(bg_flags & BG_CLIENT_RENDER))
1356 { 1298 {
1357 if ((flags & blurNeeded) 1299 if ((bg_flags & BG_NEEDS_BLUR)
1358 && (flags & HAS_RENDER_CONV)) 1300 && (bg_flags & BG_HAS_RENDER_CONV))
1359 {
1360 if (blur_pixmap (tiled_root_pmap, target->visual, window_width, window_height))
1361 result |= transpPmapBlurred;
1362 } 1301 {
1363 if ((flags & tintNeeded) 1302 if (blur_pixmap (bg_pixmap, visual, window_width, window_height))
1364 && (flags & (tintWholesome | HAS_RENDER))) 1303 result &= ~BG_NEEDS_BLUR;
1365 { 1304 }
1305 if ((bg_flags & BG_NEEDS_TINT)
1306 && (bg_flags & (BG_TINT_BITAND | BG_HAS_RENDER)))
1307 {
1366 if (tint_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) 1308 if (tint_pixmap (bg_pixmap, visual, window_width, window_height))
1367 result |= transpPmapTinted; 1309 result &= ~BG_NEEDS_TINT;
1368 } 1310 }
1369 } /* server side rendering completed */ 1311 } /* server side rendering completed */
1370
1371 if (pixmap)
1372 XFreePixmap (dpy, pixmap);
1373
1374 pixmap = tiled_root_pmap;
1375 pmap_width = window_width;
1376 pmap_height = window_height;
1377 pmap_depth = target->depth;
1378 } 1312 }
1379 else
1380 XFreePixmap (dpy, tiled_root_pmap);
1381 1313
1382 if (recoded_root_pmap != root_pixmap) 1314 if (recoded_root_pmap != root_pixmap)
1383 XFreePixmap (dpy, recoded_root_pmap); 1315 XFreePixmap (dpy, recoded_root_pmap);
1384 1316
1385 return result; 1317 return result;
1386} 1318}
1387 1319
1388void 1320void
1389bgPixmap_t::set_root_pixmap () 1321rxvt_term::bg_set_root_pixmap ()
1390{ 1322{
1391 Pixmap new_root_pixmap = target->get_pixmap_property (target->xa[XA_XROOTPMAP_ID]); 1323 Pixmap new_root_pixmap = get_pixmap_property (xa[XA_XROOTPMAP_ID]);
1392 if (new_root_pixmap == None) 1324 if (new_root_pixmap == None)
1393 new_root_pixmap = target->get_pixmap_property (target->xa[XA_ESETROOT_PMAP_ID]); 1325 new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]);
1394 1326
1395 root_pixmap = new_root_pixmap; 1327 root_pixmap = new_root_pixmap;
1396} 1328}
1397# endif /* ENABLE_TRANSPARENCY */ 1329# endif /* ENABLE_TRANSPARENCY */
1398 1330
1399#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1331#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1400static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c); 1332static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c);
1401# endif 1333# endif
1402 1334
1403bool 1335bool
1404bgPixmap_t::render () 1336rxvt_term::bg_render ()
1405{ 1337{
1406 unsigned long background_flags = 0; 1338 unsigned long tr_flags = 0;
1407 1339
1408 if (target == NULL)
1409 return false;
1410
1411 invalidate (); 1340 bg_invalidate ();
1412# ifdef ENABLE_TRANSPARENCY 1341# ifdef ENABLE_TRANSPARENCY
1413 if (flags & isTransparent) 1342 if (bg_flags & BG_IS_TRANSPARENT)
1414 { 1343 {
1415 /* we need to re-generate transparency pixmap in that case ! */ 1344 /* we need to re-generate transparency pixmap in that case ! */
1416 background_flags = make_transparency_pixmap (); 1345 tr_flags = make_transparency_pixmap ();
1417 if (background_flags == 0) 1346 if (tr_flags == 0)
1418 return false; 1347 return false;
1419 else if ((background_flags & transpTransformations) == (flags & transpTransformations)) 1348 else if (!(tr_flags & BG_EFFECTS_FLAGS))
1420 flags &= ~isInvalid; 1349 bg_flags |= BG_IS_VALID;
1421 } 1350 }
1422# endif 1351# endif
1423 1352
1424# ifdef BG_IMAGE_FROM_FILE 1353# ifdef BG_IMAGE_FROM_FILE
1425 if (have_image 1354 if ((bg_flags & BG_IS_FROM_FILE)
1426 || (background_flags & transpTransformations) != (flags & transpTransformations)) 1355 || (tr_flags & BG_EFFECTS_FLAGS))
1427 { 1356 {
1428 if (render_image (background_flags)) 1357 if (render_image (tr_flags))
1429 flags &= ~isInvalid; 1358 bg_flags |= BG_IS_VALID;
1430 } 1359 }
1431# endif 1360# endif
1432 1361
1433# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1362# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1434 XImage *result = NULL; 1363 XImage *result = NULL;
1435 1364
1436 if (background_flags && (flags & isInvalid)) 1365 if (tr_flags && !(bg_flags & BG_IS_VALID))
1437 { 1366 {
1438 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1367 result = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1439 } 1368 }
1440 1369
1441 if (result) 1370 if (result)
1442 { 1371 {
1443 /* our own client-side tinting */ 1372 /* our own client-side tinting */
1444 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1373 if (tr_flags & BG_NEEDS_TINT)
1445 { 1374 {
1446 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1375 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1447 if (flags & tintSet) 1376 if (bg_flags & BG_TINT_SET)
1448 tint.get (c); 1377 tint.get (c);
1449 shade_ximage (DefaultVisual (target->dpy, target->display->screen), result, shade, c); 1378 shade_ximage (DefaultVisual (dpy, display->screen), result, shade, c);
1450 } 1379 }
1451 1380
1452 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1381 GC gc = XCreateGC (dpy, vt, 0UL, NULL);
1453 1382
1454 if (gc) 1383 if (gc)
1455 { 1384 {
1456 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); 1385 XPutImage (dpy, bg_pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1457 1386
1458 XFreeGC (target->dpy, gc); 1387 XFreeGC (dpy, gc);
1459 flags &= ~isInvalid; 1388 bg_flags |= BG_IS_VALID;
1460 } 1389 }
1461 1390
1462 XDestroyImage (result); 1391 XDestroyImage (result);
1463 } 1392 }
1464# endif 1393# endif
1465 1394
1466 if (flags & isInvalid) 1395 if (!(bg_flags & BG_IS_VALID))
1467 { 1396 {
1468 if (pixmap != None) 1397 if (bg_pixmap != None)
1469 { 1398 {
1470 XFreePixmap (target->dpy, pixmap); 1399 XFreePixmap (dpy, bg_pixmap);
1471 pixmap = None; 1400 bg_pixmap = None;
1472 } 1401 }
1473 } 1402 }
1474 1403
1475 apply (); 1404 scr_recolour (false);
1405 bg_flags |= BG_NEEDS_REFRESH;
1476 1406
1477 valid_since = ev::now (); 1407 bg_valid_since = ev::now ();
1478 1408
1479 return true; 1409 return true;
1480} 1410}
1481 1411
1482void 1412void
1483bgPixmap_t::set_target (rxvt_term *new_target) 1413rxvt_term::bg_init ()
1484{ 1414{
1485 target = new_target; 1415#ifdef ENABLE_TRANSPARENCY
1416 shade = 100;
1417#endif
1486 1418
1487 flags &= ~(HAS_RENDER | HAS_RENDER_CONV); 1419 bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV);
1488#if XRENDER 1420#if XRENDER
1489 int major, minor; 1421 int major, minor;
1490 if (XRenderQueryVersion (target->dpy, &major, &minor)) 1422 if (XRenderQueryVersion (dpy, &major, &minor))
1491 flags |= HAS_RENDER; 1423 bg_flags |= BG_HAS_RENDER;
1492 XFilters *filters = XRenderQueryFilters (target->dpy, target->vt); 1424 XFilters *filters = XRenderQueryFilters (dpy, vt);
1493 if (filters) 1425 if (filters)
1494 { 1426 {
1495 for (int i = 0; i < filters->nfilter; i++) 1427 for (int i = 0; i < filters->nfilter; i++)
1496 if (!strcmp (filters->filter[i], FilterConvolution)) 1428 if (!strcmp (filters->filter[i], FilterConvolution))
1497 flags |= HAS_RENDER_CONV; 1429 bg_flags |= BG_HAS_RENDER_CONV;
1498 1430
1499 XFree (filters); 1431 XFree (filters);
1500 } 1432 }
1501#endif 1433#endif
1502}
1503
1504void
1505bgPixmap_t::apply ()
1506{
1507 if (target == NULL)
1508 return;
1509
1510 if (pixmap != None)
1511 {
1512 /* set target's background to pixmap */
1513# ifdef ENABLE_TRANSPARENCY
1514 if (flags & isTransparent)
1515 {
1516 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
1517 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1518
1519 if (target->scrollBar.win)
1520 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
1521 }
1522 else
1523# endif
1524 {
1525 /* force old pixmap dereference in case it was transparent before :*/
1526 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1527 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1528 /* do we also need to set scrollbar's background here ? */
1529
1530 if (target->scrollBar.win)
1531 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1532 }
1533 }
1534 else
1535 {
1536 /* set target background to a pixel */
1537 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1538 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
1539 /* do we also need to set scrollbar's background here ? */
1540 if (target->scrollBar.win)
1541 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1542 }
1543
1544 /* don't want Expose on the parent or vt. It is better to use
1545 scr_touch or we get a great deal of flicker otherwise: */
1546 XClearWindow (target->dpy, target->parent[0]);
1547
1548 if (target->scrollBar.state && target->scrollBar.win)
1549 {
1550 target->scrollBar.state = STATE_IDLE;
1551 target->scrollBar.show (0);
1552 }
1553
1554 target->want_refresh = 1;
1555 flags |= hasChanged;
1556} 1434}
1557 1435
1558#endif /* HAVE_BG_PIXMAP */ 1436#endif /* HAVE_BG_PIXMAP */
1559 1437
1560#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1438#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines