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.31 by sf-exg, Thu Jun 7 06:08:09 2012 UTC vs.
Revision 1.33 by root, Thu Jun 7 08:12:55 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), shared(false) 8: s(screen), x(x), y(y), w(width), h(height), format(format), repeat(RepeatNormal),
9 pm(0), refcnt(0)
9{ 10{
10 pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth);
11} 11}
12 12
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)
15{
16 if (refcnt)
17 ++*refcnt;
18}
19
20#if 0
13rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap) 21rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap)
14: s(screen), x(0), y(0), w(width), h(height), format(format), repeat(RepeatNormal), shared(false), pm(pixmap) 22: s(screen), x(0), y(0), w(width), h(height), format(format), repeat(RepeatNormal), shared(false), pm(pixmap)
15{ 23{
16} 24}
25#endif
17 26
18rxvt_img * 27rxvt_img *
19rxvt_img::new_from_root (rxvt_screen *s) 28rxvt_img::new_from_root (rxvt_screen *s)
20{ 29{
21 Display *dpy = s->display->dpy; 30 Display *dpy = s->display->dpy;
35 return 0; 44 return 0;
36 45
37 rxvt_img *img = new rxvt_img ( 46 rxvt_img *img = new rxvt_img (
38 s, 47 s,
39 XRenderFindVisualFormat (dpy, DefaultVisual (dpy, s->display->screen)), 48 XRenderFindVisualFormat (dpy, DefaultVisual (dpy, s->display->screen)),
49 0,
50 0,
40 root_pm_w, 51 root_pm_w,
41 root_pm_h, 52 root_pm_h
42 root_pixmap
43 ); 53 );
44 54
45 img->shared = true; 55 img->pm = root_pixmap;
46 56
47 return img; 57 return img;
48} 58}
49 59
50rxvt_img * 60rxvt_img *
57 rxvt_fatal ("rxvt_img::new_from_file: %s\n", err->message); 67 rxvt_fatal ("rxvt_img::new_from_file: %s\n", err->message);
58 68
59 rxvt_img *img = new rxvt_img ( 69 rxvt_img *img = new rxvt_img (
60 s, 70 s,
61 XRenderFindStandardFormat (s->display->dpy, gdk_pixbuf_get_has_alpha (pb) ? PictStandardARGB32 : PictStandardRGB24), 71 XRenderFindStandardFormat (s->display->dpy, gdk_pixbuf_get_has_alpha (pb) ? PictStandardARGB32 : PictStandardRGB24),
72 0,
73 0,
62 gdk_pixbuf_get_width (pb), 74 gdk_pixbuf_get_width (pb),
63 gdk_pixbuf_get_height (pb) 75 gdk_pixbuf_get_height (pb)
64 ); 76 );
65 77 img->alloc ();
66 img->render_pixbuf (pb, 0, 0, img->w, img->h, 0, 0); 78 img->render_pixbuf (pb, 0, 0, img->w, img->h, 0, 0);
67 79
68 g_object_unref (pb); 80 g_object_unref (pb);
69 81
70 return img; 82 return img;
71} 83}
72 84
85void
86rxvt_img::destroy ()
87{
88 if (!refcnt || --*refcnt)
89 return;
90
91 if (pm)
92 XFreePixmap (s->display->dpy, pm);
93
94 delete refcnt;
95}
96
73rxvt_img::~rxvt_img () 97rxvt_img::~rxvt_img ()
74{ 98{
75 if (!shared) 99 destroy ();
76 XFreePixmap (s->display->dpy, pm); 100}
101
102void
103rxvt_img::alloc ()
104{
105 pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth);
106 refcnt = new int (1);
77} 107}
78 108
79void 109void
80rxvt_img::unshare () 110rxvt_img::unshare ()
81{ 111{
82 if (!shared) 112 if (refcnt && *refcnt == 1)
83 return; 113 return;
84 114
85 rxvt_img *img = clone (); 115 Pixmap pm2 = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth);
116 GC gc = XCreateGC (s->display->dpy, pm, 0, 0);
117 XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, w, h, 0, 0);
118 XFreeGC (s->display->dpy, gc);
86 119
87 ::swap (pm , img->pm); 120 destroy ();
88 ::swap (shared, img->shared);
89 121
90 delete img; 122 pm = pm2;
123 refcnt = new int (1);
91} 124}
92 125
93void 126void
94rxvt_img::fill (const rxvt_color &c) 127rxvt_img::fill (const rxvt_color &c)
95{ 128{
129 162
130 Display *dpy = s->display->dpy; 163 Display *dpy = s->display->dpy;
131 int size = max (rh, rv) * 2 + 1; 164 int size = max (rh, rv) * 2 + 1;
132 double *kernel = (double *)malloc (size * sizeof (double)); 165 double *kernel = (double *)malloc (size * sizeof (double));
133 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 166 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
134 rxvt_img *img = new rxvt_img (s, format, w, h); 167 rxvt_img *img = new rxvt_img (s, format, x, y, w, h);
168 img->alloc ();
135 169
136 XRenderPictureAttributes pa; 170 XRenderPictureAttributes pa;
137 171
138 pa.repeat = RepeatPad; 172 pa.repeat = RepeatPad;
139 Picture src = XRenderCreatePicture (dpy, pm , format, CPRepeat, &pa); 173 Picture src = XRenderCreatePicture (dpy, pm , format, CPRepeat, &pa);
340} 374}
341 375
342rxvt_img * 376rxvt_img *
343rxvt_img::clone () 377rxvt_img::clone ()
344{ 378{
379 return new rxvt_img (*this);
380}
381
382rxvt_img *
383rxvt_img::reify ()
384{
345 rxvt_img *img = new rxvt_img (s, format, w, h); 385 rxvt_img *img = new rxvt_img (s, format, 0, 0, w, h);
386 img->alloc ();
346 387
347 GC gc = XCreateGC (s->display->dpy, pm, 0, 0); 388 // todo, if x==0 and y==0 and w==real width we could clone
348 XCopyArea (s->display->dpy, pm, img->pm, gc, 0, 0, w, h, 0, 0); 389 // but that involves an rtt to find pixmap width.
349 XFreeGC (s->display->dpy, gc);
350
351 return img;
352}
353
354rxvt_img *
355rxvt_img::sub_rect (int x, int y, int width, int height)
356{
357 rxvt_img *img = new rxvt_img (s, format, width, height);
358 390
359 Display *dpy = s->display->dpy; 391 Display *dpy = s->display->dpy;
360 XRenderPictureAttributes pa; 392 XRenderPictureAttributes pa;
361 pa.repeat = repeat; 393 pa.repeat = repeat;
362 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); 394 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa);
363 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); 395 Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0);
364 396
365 XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, width, height); 397 XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h);
366 398
367 XRenderFreePicture (dpy, src);
368 XRenderFreePicture (dpy, dst); 399 XRenderFreePicture (dpy, src);
400 XRenderFreePicture (dpy, dst);
401
402 return img;
403}
404
405rxvt_img *
406rxvt_img::sub_rect (int x, int y, int width, int height)
407{
408 rxvt_img *img = clone ();
409
410 img->x += x;
411 img->y += y;
412 img->w = width;
413 img->h = height;
369 414
370 return img; 415 return img;
371} 416}
372 417
373rxvt_img * 418rxvt_img *
374rxvt_img::transform (int new_width, int new_height, double matrix[9]) 419rxvt_img::transform (int new_width, int new_height, double matrix[9])
375{ 420{
376 rxvt_img *img = new rxvt_img (s, format, new_width, new_height); 421 rxvt_img *img = new rxvt_img (s, format, 0, 0, new_width, new_height);
422 img->alloc ();
377 423
378 Display *dpy = s->display->dpy; 424 Display *dpy = s->display->dpy;
379 XRenderPictureAttributes pa; 425 XRenderPictureAttributes pa;
380 pa.repeat = repeat; 426 pa.repeat = repeat;
381 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); 427 Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa);
384 XTransform xfrm; 430 XTransform xfrm;
385 431
386 for (int i = 0; i < 3; ++i) 432 for (int i = 0; i < 3; ++i)
387 for (int j = 0; j < 3; ++j) 433 for (int j = 0; j < 3; ++j)
388 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]); 434 xfrm.matrix [i][j] = XDoubleToFixed (matrix [i * 3 + j]);
435
436 xfrm.matrix [0][2] += XDoubleToFixed (x);//TODO
437 xfrm.matrix [0][3] += XDoubleToFixed (y);
389 438
390 XRenderSetPictureFilter (dpy, src, "good", 0, 0); 439 XRenderSetPictureFilter (dpy, src, "good", 0, 0);
391 XRenderSetPictureTransform (dpy, src, &xfrm); 440 XRenderSetPictureTransform (dpy, src, &xfrm);
392 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height); 441 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, new_width, new_height);
393 442
425} 474}
426 475
427rxvt_img * 476rxvt_img *
428rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg) 477rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg)
429{ 478{
479 if (new_format == format)
480 return clone ();
481
430 rxvt_img *img = new rxvt_img (s, new_format, w, h); 482 rxvt_img *img = new rxvt_img (s, new_format, x, y, w, h);
483 img->alloc ();
431 484
432 Display *dpy = s->display->dpy; 485 Display *dpy = s->display->dpy;
433 Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0); 486 Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0);
434 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); 487 Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0);
435 int op = PictOpSrc; 488 int op = PictOpSrc;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines