… | |
… | |
3 | #include "rxvt.h" |
3 | #include "rxvt.h" |
4 | |
4 | |
5 | #if HAVE_IMG |
5 | #if HAVE_IMG |
6 | |
6 | |
7 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height) |
7 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, 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(0), y(0), 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 | |
|
|
13 | rxvt_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 |
13 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap) |
21 | rxvt_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 | |
18 | rxvt_img * |
27 | rxvt_img * |
19 | rxvt_img::new_from_root (rxvt_screen *s) |
28 | rxvt_img::new_from_root (rxvt_screen *s) |
20 | { |
29 | { |
21 | Display *dpy = s->display->dpy; |
30 | Display *dpy = s->display->dpy; |
… | |
… | |
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)), |
40 | root_pm_w, |
49 | root_pm_w, |
41 | root_pm_h, |
50 | root_pm_h |
42 | root_pixmap |
|
|
43 | ); |
51 | ); |
44 | |
52 | |
45 | img->shared = true; |
53 | img->pm = root_pixmap; |
46 | |
54 | |
47 | return img; |
55 | return img; |
48 | } |
56 | } |
49 | |
57 | |
50 | rxvt_img * |
58 | rxvt_img * |
… | |
… | |
60 | s, |
68 | s, |
61 | XRenderFindStandardFormat (s->display->dpy, gdk_pixbuf_get_has_alpha (pb) ? PictStandardARGB32 : PictStandardRGB24), |
69 | XRenderFindStandardFormat (s->display->dpy, gdk_pixbuf_get_has_alpha (pb) ? PictStandardARGB32 : PictStandardRGB24), |
62 | gdk_pixbuf_get_width (pb), |
70 | gdk_pixbuf_get_width (pb), |
63 | gdk_pixbuf_get_height (pb) |
71 | gdk_pixbuf_get_height (pb) |
64 | ); |
72 | ); |
65 | |
73 | img->alloc (); |
66 | img->render_pixbuf (pb, 0, 0, img->w, img->h, 0, 0); |
74 | img->render_pixbuf (pb, 0, 0, img->w, img->h, 0, 0); |
67 | |
75 | |
68 | g_object_unref (pb); |
76 | g_object_unref (pb); |
69 | |
77 | |
70 | return img; |
78 | return img; |
71 | } |
79 | } |
72 | |
80 | |
|
|
81 | void |
|
|
82 | rxvt_img::destroy () |
|
|
83 | { |
|
|
84 | if (!refcnt || --*refcnt) |
|
|
85 | return; |
|
|
86 | |
|
|
87 | if (pm) |
|
|
88 | XFreePixmap (s->display->dpy, pm); |
|
|
89 | |
|
|
90 | delete refcnt; |
|
|
91 | } |
|
|
92 | |
73 | rxvt_img::~rxvt_img () |
93 | rxvt_img::~rxvt_img () |
74 | { |
94 | { |
75 | if (!shared) |
95 | destroy (); |
76 | XFreePixmap (s->display->dpy, pm); |
96 | } |
|
|
97 | |
|
|
98 | void |
|
|
99 | rxvt_img::alloc () |
|
|
100 | { |
|
|
101 | pm = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); |
|
|
102 | refcnt = new int (1); |
77 | } |
103 | } |
78 | |
104 | |
79 | void |
105 | void |
80 | rxvt_img::unshare () |
106 | rxvt_img::unshare () |
81 | { |
107 | { |
82 | if (!shared) |
108 | if (refcnt && *refcnt == 1) |
83 | return; |
109 | return; |
84 | |
110 | |
85 | rxvt_img *img = clone (); |
111 | Pixmap pm2 = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); |
|
|
112 | GC gc = XCreateGC (s->display->dpy, pm, 0, 0); |
|
|
113 | XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, w, h, 0, 0); |
|
|
114 | XFreeGC (s->display->dpy, gc); |
86 | |
115 | |
87 | ::swap (pm , img->pm); |
116 | destroy (); |
88 | ::swap (shared, img->shared); |
|
|
89 | |
117 | |
90 | delete img; |
118 | pm = pm2; |
|
|
119 | refcnt = new int (1); |
91 | } |
120 | } |
92 | |
121 | |
93 | void |
122 | void |
94 | rxvt_img::fill (const rxvt_color &c) |
123 | rxvt_img::fill (const rxvt_color &c) |
95 | { |
124 | { |
… | |
… | |
130 | Display *dpy = s->display->dpy; |
159 | Display *dpy = s->display->dpy; |
131 | int size = max (rh, rv) * 2 + 1; |
160 | int size = max (rh, rv) * 2 + 1; |
132 | double *kernel = (double *)malloc (size * sizeof (double)); |
161 | double *kernel = (double *)malloc (size * sizeof (double)); |
133 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
162 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
134 | rxvt_img *img = new rxvt_img (s, format, w, h); |
163 | rxvt_img *img = new rxvt_img (s, format, w, h); |
|
|
164 | img->alloc (); |
135 | |
165 | |
136 | XRenderPictureAttributes pa; |
166 | XRenderPictureAttributes pa; |
137 | |
167 | |
138 | pa.repeat = RepeatPad; |
168 | pa.repeat = RepeatPad; |
139 | Picture src = XRenderCreatePicture (dpy, pm , format, CPRepeat, &pa); |
169 | Picture src = XRenderCreatePicture (dpy, pm , format, CPRepeat, &pa); |
… | |
… | |
340 | } |
370 | } |
341 | |
371 | |
342 | rxvt_img * |
372 | rxvt_img * |
343 | rxvt_img::clone () |
373 | rxvt_img::clone () |
344 | { |
374 | { |
345 | rxvt_img *img = new rxvt_img (s, format, w, h); |
375 | return new rxvt_img (*this); |
346 | |
|
|
347 | GC gc = XCreateGC (s->display->dpy, pm, 0, 0); |
|
|
348 | XCopyArea (s->display->dpy, pm, img->pm, gc, 0, 0, w, h, 0, 0); |
|
|
349 | XFreeGC (s->display->dpy, gc); |
|
|
350 | |
|
|
351 | return img; |
|
|
352 | } |
376 | } |
353 | |
377 | |
354 | rxvt_img * |
378 | rxvt_img * |
355 | rxvt_img::sub_rect (int x, int y, int width, int height) |
379 | rxvt_img::sub_rect (int x, int y, int width, int height) |
356 | { |
380 | { |
357 | rxvt_img *img = new rxvt_img (s, format, width, height); |
381 | rxvt_img *img = new rxvt_img (s, format, width, height); |
|
|
382 | img->alloc (); |
358 | |
383 | |
359 | Display *dpy = s->display->dpy; |
384 | Display *dpy = s->display->dpy; |
360 | XRenderPictureAttributes pa; |
385 | XRenderPictureAttributes pa; |
361 | pa.repeat = repeat; |
386 | pa.repeat = repeat; |
362 | Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); |
387 | Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); |
… | |
… | |
372 | |
397 | |
373 | rxvt_img * |
398 | rxvt_img * |
374 | rxvt_img::transform (int new_width, int new_height, double matrix[9]) |
399 | rxvt_img::transform (int new_width, int new_height, double matrix[9]) |
375 | { |
400 | { |
376 | rxvt_img *img = new rxvt_img (s, format, new_width, new_height); |
401 | rxvt_img *img = new rxvt_img (s, format, new_width, new_height); |
|
|
402 | img->alloc (); |
377 | |
403 | |
378 | Display *dpy = s->display->dpy; |
404 | Display *dpy = s->display->dpy; |
379 | XRenderPictureAttributes pa; |
405 | XRenderPictureAttributes pa; |
380 | pa.repeat = repeat; |
406 | pa.repeat = repeat; |
381 | Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); |
407 | Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); |
… | |
… | |
425 | } |
451 | } |
426 | |
452 | |
427 | rxvt_img * |
453 | rxvt_img * |
428 | rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg) |
454 | rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg) |
429 | { |
455 | { |
|
|
456 | if (new_format == format) |
|
|
457 | return clone (); |
|
|
458 | |
430 | rxvt_img *img = new rxvt_img (s, new_format, w, h); |
459 | rxvt_img *img = new rxvt_img (s, new_format, w, h); |
|
|
460 | img->alloc (); |
431 | |
461 | |
432 | Display *dpy = s->display->dpy; |
462 | Display *dpy = s->display->dpy; |
433 | Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0); |
463 | Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0); |
434 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
464 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
435 | int op = PictOpSrc; |
465 | int op = PictOpSrc; |