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.40 by root, Thu Jun 7 11:27:08 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 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);
409 img->alloc ();
410
411 Picture src = src_picture ();
412 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
413
414 XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h);
415
416 XRenderFreePicture (dpy, src);
417 XRenderFreePicture (dpy, dst);
418
419 return img;
420}
421
422rxvt_img *
379rxvt_img::sub_rect (int x, int y, int width, int height) 423rxvt_img::sub_rect (int x, int y, int width, int height)
380{ 424{
425 rxvt_img *img = clone ();
426
427 img->x += x;
428 img->y += y;
429
430 if (w != width || h != height)
431 {
432 img->w = width;
433 img->h = height;
434
435 rxvt_img *img2 = img->reify ();
436 delete img;
437 img = img2;
438 }
439
440 return img;
441}
442
443rxvt_img *
444rxvt_img::transform (int new_width, int new_height, double matrix[9])
445{
381 rxvt_img *img = new rxvt_img (s, format, width, height); 446 rxvt_img *img = new rxvt_img (s, format, 0, 0, new_width, new_height);
382 img->alloc (); 447 img->alloc ();
383 448
384 Display *dpy = s->display->dpy; 449 Display *dpy = s->display->dpy;
385 XRenderPictureAttributes pa; 450 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); 451 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 452
410 XTransform xfrm; 453 XTransform xfrm;
411 454
412 for (int i = 0; i < 3; ++i) 455 for (int i = 0; i < 3; ++i)
413 for (int j = 0; j < 3; ++j) 456 for (int j = 0; j < 3; ++j)
414 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]); 457 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]);
458
459 xfrm.matrix [0][2] += XDoubleToFixed (x);//TODO
460 xfrm.matrix [0][3] += XDoubleToFixed (y);
415 461
416 XRenderSetPictureFilter (dpy, src, "good", 0, 0); 462 XRenderSetPictureFilter (dpy, src, "good", 0, 0);
417 XRenderSetPictureTransform (dpy, src, &xfrm); 463 XRenderSetPictureTransform (dpy, src, &xfrm);
418 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height); 464 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height);
419 465
454rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg) 500rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg)
455{ 501{
456 if (new_format == format) 502 if (new_format == format)
457 return clone (); 503 return clone ();
458 504
459 rxvt_img *img = new rxvt_img (s, new_format, w, h); 505 rxvt_img *img = new rxvt_img (s, new_format, 0, 0, w, h);
460 img->alloc (); 506 img->alloc ();
461 507
462 Display *dpy = s->display->dpy; 508 Display *dpy = s->display->dpy;
463 Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0); 509 Picture src = src_picture ();
464 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); 510 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0);
465 int op = PictOpSrc; 511 int op = PictOpSrc;
466 512
467 if (format->direct.alphaMask && !new_format->direct.alphaMask) 513 if (format->direct.alphaMask && !new_format->direct.alphaMask)
468 { 514 {
487rxvt_img * 533rxvt_img *
488rxvt_img::blend (rxvt_img *img, double factor) 534rxvt_img::blend (rxvt_img *img, double factor)
489{ 535{
490 rxvt_img *img2 = clone (); 536 rxvt_img *img2 = clone ();
491 Display *dpy = s->display->dpy; 537 Display *dpy = s->display->dpy;
492 Picture src = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); 538 Picture src = img->src_picture ();
493 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); 539 Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0);
494 Picture mask = create_xrender_mask (dpy, img->pm, False); 540 Picture mask = create_xrender_mask (dpy, img->pm, False);
495 541
496 XRenderColor mask_c; 542 XRenderColor mask_c;
497 543

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines