ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtimg.C
(Generate patch)

Comparing rxvt-unicode/src/rxvtimg.C (file contents):
Revision 1.33 by root, Thu Jun 7 08:12:55 2012 UTC vs.
Revision 1.41 by root, Thu Jun 7 11:34:09 2012 UTC

2#include "../config.h" 2#include "../config.h"
3#include "rxvt.h" 3#include "rxvt.h"
4 4
5#if HAVE_IMG 5#if HAVE_IMG
6 6
7rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height) 7rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height, int repeat)
8: s(screen), x(x), y(y), w(width), h(height), format(format), repeat(RepeatNormal), 8: s(screen), x(x), y(y), w(width), h(height), format(format), repeat(repeat),
9 pm(0), refcnt(0) 9 pm(0), ref(0)
10{ 10{
11} 11}
12 12
13rxvt_img::rxvt_img (const rxvt_img &img) 13rxvt_img::rxvt_img (const rxvt_img &img)
14: s(img.s), x(img.x), y(img.y), w(img.w), h(img.h), format(img.format), repeat(img.repeat), pm(img.pm), refcnt(img.refcnt) 14: s(img.s), x(img.x), y(img.y), w(img.w), h(img.h), format(img.format), repeat(img.repeat), pm(img.pm), ref(img.ref)
15{ 15{
16 if (refcnt)
17 ++*refcnt; 16 ++ref->cnt;
18} 17}
19 18
20#if 0 19#if 0
21rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap) 20rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap)
22: s(screen), x(0), y(0), w(width), h(height), format(format), repeat(RepeatNormal), shared(false), pm(pixmap) 21: s(screen), x(0), y(0), w(width), h(height), format(format), repeat(RepeatNormal), shared(false), pm(pixmap)
51 root_pm_w, 50 root_pm_w,
52 root_pm_h 51 root_pm_h
53 ); 52 );
54 53
55 img->pm = root_pixmap; 54 img->pm = root_pixmap;
55 img->ref = new pixref (root_pm_w, root_pm_h);
56 img->ref->ours = false;
56 57
57 return img; 58 return img;
58} 59}
59 60
60rxvt_img * 61rxvt_img *
83} 84}
84 85
85void 86void
86rxvt_img::destroy () 87rxvt_img::destroy ()
87{ 88{
88 if (!refcnt || --*refcnt) 89 if (--ref->cnt)
89 return; 90 return;
90 91
91 if (pm) 92 if (pm && ref->ours)
92 XFreePixmap (s->display->dpy, pm); 93 XFreePixmap (s->display->dpy, pm);
93 94
94 delete refcnt; 95 delete ref;
95} 96}
96 97
97rxvt_img::~rxvt_img () 98rxvt_img::~rxvt_img ()
98{ 99{
99 destroy (); 100 destroy ();
101 102
102void 103void
103rxvt_img::alloc () 104rxvt_img::alloc ()
104{ 105{
105 pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); 106 pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth);
106 refcnt = new int (1); 107 ref = new pixref (w, h);
108}
109
110Picture
111rxvt_img::src_picture ()
112{
113 Display *dpy = s->display->dpy;
114
115 XRenderPictureAttributes pa;
116 pa.repeat = repeat;
117 Picture pic = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa);
118
119 return pic;
107} 120}
108 121
109void 122void
110rxvt_img::unshare () 123rxvt_img::unshare ()
111{ 124{
112 if (refcnt && *refcnt == 1) 125 if (ref->cnt == 1 && ref->ours)
113 return; 126 return;
114 127
128 //TODO: maybe should reify instead
115 Pixmap pm2 = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); 129 Pixmap pm2 = XCreatePixmap (s->display->dpy, s->display->root, ref->w, ref->h, format->depth);
116 GC gc = XCreateGC (s->display->dpy, pm, 0, 0); 130 GC gc = XCreateGC (s->display->dpy, pm, 0, 0);
117 XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, w, h, 0, 0); 131 XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, ref->w, ref->h, 0, 0);
118 XFreeGC (s->display->dpy, gc); 132 XFreeGC (s->display->dpy, gc);
119 133
120 destroy (); 134 destroy ();
121 135
122 pm = pm2; 136 pm = pm2;
123 refcnt = new int (1); 137 ref = new pixref (ref->w, ref->h);
124} 138}
125 139
126void 140void
127rxvt_img::fill (const rxvt_color &c) 141rxvt_img::fill (const rxvt_color &c)
128{ 142{
162 176
163 Display *dpy = s->display->dpy; 177 Display *dpy = s->display->dpy;
164 int size = max (rh, rv) * 2 + 1; 178 int size = max (rh, rv) * 2 + 1;
165 double *kernel = (double *)malloc (size * sizeof (double)); 179 double *kernel = (double *)malloc (size * sizeof (double));
166 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 180 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
167 rxvt_img *img = new rxvt_img (s, format, x, y, w, h); 181 rxvt_img *img = new rxvt_img (s, format, x, y, w, h, repeat);
168 img->alloc (); 182 img->alloc ();
169 183
184 Picture src = src_picture ();
185
170 XRenderPictureAttributes pa; 186 XRenderPictureAttributes pa;
171
172 pa.repeat = RepeatPad; 187 pa.repeat = RepeatPad;
173 Picture src = XRenderCreatePicture (dpy, pm , format, CPRepeat, &pa);
174 Picture dst = XRenderCreatePicture (dpy, img->pm, format, CPRepeat, &pa); 188 Picture dst = XRenderCreatePicture (dpy, img->pm, format, CPRepeat, &pa);
175 189
176 Pixmap tmp_pm = XCreatePixmap (dpy, pm, w, h, format->depth); 190 Pixmap tmp_pm = XCreatePixmap (dpy, pm, w, h, format->depth);
177 Picture tmp = XRenderCreatePicture (dpy, tmp_pm , format, CPRepeat, &pa); 191 Picture tmp = XRenderCreatePicture (dpy, tmp_pm , format, CPRepeat, &pa);
178 XFreePixmap (dpy, tmp_pm); 192 XFreePixmap (dpy, tmp_pm);
380} 394}
381 395
382rxvt_img * 396rxvt_img *
383rxvt_img::reify () 397rxvt_img::reify ()
384{ 398{
385 rxvt_img *img = new rxvt_img (s, format, 0, 0, w, h); 399 if (x == 0 && y == 0 && w == ref->w && h == ref->h)
400 return clone ();
401
402 Display *dpy = s->display->dpy;
403
404 bool alpha = !format->direct.alphaMask
405 && (x || y)
406 && repeat == RepeatNone;
407
408 rxvt_img *img = new rxvt_img (s, alpha ? XRenderFindStandardFormat (dpy, PictStandardARGB32) : format, 0, 0, w, h, repeat);
386 img->alloc (); 409 img->alloc ();
387 410
388 // todo, if x==0 and y==0 and w==real width we could clone 411 Picture src = src_picture ();
389 // but that involves an rtt to find pixmap width.
390
391 Display *dpy = s->display->dpy;
392 XRenderPictureAttributes pa;
393 pa.repeat = repeat;
394 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa);
395 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); 412 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
396 413
397 XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h); 414 XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h);
398 415
399 XRenderFreePicture (dpy, src); 416 XRenderFreePicture (dpy, src);
400 XRenderFreePicture (dpy, dst); 417 XRenderFreePicture (dpy, dst);
407{ 424{
408 rxvt_img *img = clone (); 425 rxvt_img *img = clone ();
409 426
410 img->x += x; 427 img->x += x;
411 img->y += y; 428 img->y += y;
429
430 if (w != width || h != height)
431 {
412 img->w = width; 432 img->w = width;
413 img->h = height; 433 img->h = height;
434
435 rxvt_img *img2 = img->reify ();
436 delete img;
437 img = img2;
438 }
414 439
415 return img; 440 return img;
416} 441}
417 442
418rxvt_img * 443rxvt_img *
419rxvt_img::transform (int new_width, int new_height, double matrix[9]) 444rxvt_img::transform (int new_width, int new_height, double matrix[9])
420{ 445{
421 rxvt_img *img = new rxvt_img (s, format, 0, 0, new_width, new_height); 446 rxvt_img *img = new rxvt_img (s, format, 0, 0, new_width, new_height, repeat);
422 img->alloc (); 447 img->alloc ();
423 448
424 Display *dpy = s->display->dpy; 449 Display *dpy = s->display->dpy;
425 XRenderPictureAttributes pa; 450 Picture src = src_picture ();
426 pa.repeat = repeat;
427 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa);
428 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); 451 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
429 452
430 XTransform xfrm; 453 XTransform xfrm;
431 454
432 for (int i = 0; i < 3; ++i) 455 for (int i = 0; i < 3; ++i)
433 for (int j = 0; j < 3; ++j) 456 for (int j = 0; j < 3; ++j)
477rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg) 500rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg)
478{ 501{
479 if (new_format == format) 502 if (new_format == format)
480 return clone (); 503 return clone ();
481 504
482 rxvt_img *img = new rxvt_img (s, new_format, x, y, w, h); 505 rxvt_img *img = new rxvt_img (s, new_format, 0, 0, w, h, repeat);
483 img->alloc (); 506 img->alloc ();
484 507
485 Display *dpy = s->display->dpy; 508 Display *dpy = s->display->dpy;
486 Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0); 509 Picture src = src_picture ();
487 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); 510 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0);
488 int op = PictOpSrc; 511 int op = PictOpSrc;
489 512
490 if (format->direct.alphaMask && !new_format->direct.alphaMask) 513 if (format->direct.alphaMask && !new_format->direct.alphaMask)
491 { 514 {
510rxvt_img * 533rxvt_img *
511rxvt_img::blend (rxvt_img *img, double factor) 534rxvt_img::blend (rxvt_img *img, double factor)
512{ 535{
513 rxvt_img *img2 = clone (); 536 rxvt_img *img2 = clone ();
514 Display *dpy = s->display->dpy; 537 Display *dpy = s->display->dpy;
515 Picture src = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); 538 Picture src = img->src_picture ();
516 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); 539 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0);
517 Picture mask = create_xrender_mask (dpy, img->pm, False); 540 Picture mask = create_xrender_mask (dpy, img->pm, False);
518 541
519 XRenderColor mask_c; 542 XRenderColor mask_c;
520 543

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines