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.32 by root, Thu Jun 7 07:53:12 2012 UTC vs.
Revision 1.39 by root, Thu Jun 7 10:19:23 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 width, int height) 7rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height)
8: s(screen), x(0), y(0), w(width), h(height), format(format), repeat(RepeatNormal), 8: s(screen), x(x), y(y), w(width), h(height), format(format), repeat(RepeatNormal),
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)
44 return 0; 43 return 0;
45 44
46 rxvt_img *img = new rxvt_img ( 45 rxvt_img *img = new rxvt_img (
47 s, 46 s,
48 XRenderFindVisualFormat (dpy, DefaultVisual (dpy, s->display->screen)), 47 XRenderFindVisualFormat (dpy, DefaultVisual (dpy, s->display->screen)),
48 0,
49 0,
49 root_pm_w, 50 root_pm_w,
50 root_pm_h 51 root_pm_h
51 ); 52 );
52 53
53 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;
54 57
55 return img; 58 return img;
56} 59}
57 60
58rxvt_img * 61rxvt_img *
65 rxvt_fatal ("rxvt_img::new_from_file: %s\n", err->message); 68 rxvt_fatal ("rxvt_img::new_from_file: %s\n", err->message);
66 69
67 rxvt_img *img = new rxvt_img ( 70 rxvt_img *img = new rxvt_img (
68 s, 71 s,
69 XRenderFindStandardFormat (s->display->dpy, gdk_pixbuf_get_has_alpha (pb) ? PictStandardARGB32 : PictStandardRGB24), 72 XRenderFindStandardFormat (s->display->dpy, gdk_pixbuf_get_has_alpha (pb) ? PictStandardARGB32 : PictStandardRGB24),
73 0,
74 0,
70 gdk_pixbuf_get_width (pb), 75 gdk_pixbuf_get_width (pb),
71 gdk_pixbuf_get_height (pb) 76 gdk_pixbuf_get_height (pb)
72 ); 77 );
73 img->alloc (); 78 img->alloc ();
74 img->render_pixbuf (pb, 0, 0, img->w, img->h, 0, 0); 79 img->render_pixbuf (pb, 0, 0, img->w, img->h, 0, 0);
79} 84}
80 85
81void 86void
82rxvt_img::destroy () 87rxvt_img::destroy ()
83{ 88{
84 if (!refcnt || --*refcnt) 89 if (--ref->cnt)
85 return; 90 return;
86 91
87 if (pm) 92 if (pm && ref->ours)
88 XFreePixmap (s->display->dpy, pm); 93 XFreePixmap (s->display->dpy, pm);
89 94
90 delete refcnt; 95 delete ref;
91} 96}
92 97
93rxvt_img::~rxvt_img () 98rxvt_img::~rxvt_img ()
94{ 99{
95 destroy (); 100 destroy ();
97 102
98void 103void
99rxvt_img::alloc () 104rxvt_img::alloc ()
100{ 105{
101 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);
102 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;
103} 120}
104 121
105void 122void
106rxvt_img::unshare () 123rxvt_img::unshare ()
107{ 124{
108 if (refcnt && *refcnt == 1) 125 if (ref->cnt == 1 && ref->ours)
109 return; 126 return;
110 127
128 //TODO: maybe should reify instead
111 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);
112 GC gc = XCreateGC (s->display->dpy, pm, 0, 0); 130 GC gc = XCreateGC (s->display->dpy, pm, 0, 0);
113 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);
114 XFreeGC (s->display->dpy, gc); 132 XFreeGC (s->display->dpy, gc);
115 133
116 destroy (); 134 destroy ();
117 135
118 pm = pm2; 136 pm = pm2;
119 refcnt = new int (1); 137 ref = new pixref (ref->w, ref->h);
120} 138}
121 139
122void 140void
123rxvt_img::fill (const rxvt_color &c) 141rxvt_img::fill (const rxvt_color &c)
124{ 142{
158 176
159 Display *dpy = s->display->dpy; 177 Display *dpy = s->display->dpy;
160 int size = max (rh, rv) * 2 + 1; 178 int size = max (rh, rv) * 2 + 1;
161 double *kernel = (double *)malloc (size * sizeof (double)); 179 double *kernel = (double *)malloc (size * sizeof (double));
162 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 180 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
163 rxvt_img *img = new rxvt_img (s, format, w, h); 181 rxvt_img *img = new rxvt_img (s, format, x, y, w, h);
164 img->alloc (); 182 img->alloc ();
165 183
184 Picture src = src_picture ();
185
166 XRenderPictureAttributes pa; 186 XRenderPictureAttributes pa;
167
168 pa.repeat = RepeatPad; 187 pa.repeat = RepeatPad;
169 Picture src = XRenderCreatePicture (dpy, pm , format, CPRepeat, &pa);
170 Picture dst = XRenderCreatePicture (dpy, img->pm, format, CPRepeat, &pa); 188 Picture dst = XRenderCreatePicture (dpy, img->pm, format, CPRepeat, &pa);
171 189
172 Pixmap tmp_pm = XCreatePixmap (dpy, pm, w, h, format->depth); 190 Pixmap tmp_pm = XCreatePixmap (dpy, pm, w, h, format->depth);
173 Picture tmp = XRenderCreatePicture (dpy, tmp_pm , format, CPRepeat, &pa); 191 Picture tmp = XRenderCreatePicture (dpy, tmp_pm , format, CPRepeat, &pa);
174 XFreePixmap (dpy, tmp_pm); 192 XFreePixmap (dpy, tmp_pm);
374{ 392{
375 return new rxvt_img (*this); 393 return new rxvt_img (*this);
376} 394}
377 395
378rxvt_img * 396rxvt_img *
397rxvt_img::reify ()
398{
399 if (x == 0 && y == 0 && w == ref->w && h == ref->h)
400 return clone ();
401
402 rxvt_img *img = new rxvt_img (s, format, 0, 0, w, h);
403 img->alloc ();
404
405 Display *dpy = s->display->dpy;
406
407 Picture src = src_picture ();
408 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
409
410 XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h);
411
412 XRenderFreePicture (dpy, src);
413 XRenderFreePicture (dpy, dst);
414
415 return img;
416}
417
418rxvt_img *
379rxvt_img::sub_rect (int x, int y, int width, int height) 419rxvt_img::sub_rect (int x, int y, int width, int height)
380{ 420{
421 rxvt_img *img = clone ();
422
423 img->x += x;
424 img->y += y;
425
426 if (w != width || h != height)
427 {
428 img->w = width;
429 img->h = height;
430
431 rxvt_img *img2 = img->reify ();
432 delete img;
433 img = img2;
434 }
435
436 return img;
437}
438
439rxvt_img *
440rxvt_img::transform (int new_width, int new_height, double matrix[9])
441{
381 rxvt_img *img = new rxvt_img (s, format, width, height); 442 rxvt_img *img = new rxvt_img (s, format, 0, 0, new_width, new_height);
382 img->alloc (); 443 img->alloc ();
383 444
384 Display *dpy = s->display->dpy; 445 Display *dpy = s->display->dpy;
385 XRenderPictureAttributes pa; 446 Picture src = src_picture ();
386 pa.repeat = repeat;
387 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa);
388 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); 447 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
389
390 XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, width, height);
391
392 XRenderFreePicture (dpy, src);
393 XRenderFreePicture (dpy, dst);
394
395 return img;
396}
397
398rxvt_img *
399rxvt_img::transform (int new_width, int new_height, double matrix[9])
400{
401 rxvt_img *img = new rxvt_img (s, format, new_width, new_height);
402 img->alloc ();
403
404 Display *dpy = s->display->dpy;
405 XRenderPictureAttributes pa;
406 pa.repeat = repeat;
407 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa);
408 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
409 448
410 XTransform xfrm; 449 XTransform xfrm;
411 450
412 for (int i = 0; i < 3; ++i) 451 for (int i = 0; i < 3; ++i)
413 for (int j = 0; j < 3; ++j) 452 for (int j = 0; j < 3; ++j)
414 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]); 453 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]);
454
455 xfrm.matrix [0][2] += XDoubleToFixed (x);//TODO
456 xfrm.matrix [0][3] += XDoubleToFixed (y);
415 457
416 XRenderSetPictureFilter (dpy, src, "good", 0, 0); 458 XRenderSetPictureFilter (dpy, src, "good", 0, 0);
417 XRenderSetPictureTransform (dpy, src, &xfrm); 459 XRenderSetPictureTransform (dpy, src, &xfrm);
418 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height); 460 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height);
419 461
454rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg) 496rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg)
455{ 497{
456 if (new_format == format) 498 if (new_format == format)
457 return clone (); 499 return clone ();
458 500
459 rxvt_img *img = new rxvt_img (s, new_format, w, h); 501 rxvt_img *img = new rxvt_img (s, new_format, 0, 0, w, h);
460 img->alloc (); 502 img->alloc ();
461 503
462 Display *dpy = s->display->dpy; 504 Display *dpy = s->display->dpy;
463 Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0); 505 Picture src = src_picture ();
464 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); 506 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0);
465 int op = PictOpSrc; 507 int op = PictOpSrc;
466 508
467 if (format->direct.alphaMask && !new_format->direct.alphaMask) 509 if (format->direct.alphaMask && !new_format->direct.alphaMask)
468 { 510 {
487rxvt_img * 529rxvt_img *
488rxvt_img::blend (rxvt_img *img, double factor) 530rxvt_img::blend (rxvt_img *img, double factor)
489{ 531{
490 rxvt_img *img2 = clone (); 532 rxvt_img *img2 = clone ();
491 Display *dpy = s->display->dpy; 533 Display *dpy = s->display->dpy;
492 Picture src = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); 534 Picture src = img->src_picture ();
493 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); 535 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0);
494 Picture mask = create_xrender_mask (dpy, img->pm, False); 536 Picture mask = create_xrender_mask (dpy, img->pm, False);
495 537
496 XRenderColor mask_c; 538 XRenderColor mask_c;
497 539

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines