… | |
… | |
4 | |
4 | |
5 | #if HAVE_IMG |
5 | #if HAVE_IMG |
6 | |
6 | |
7 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height) |
7 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int x, int y, int width, int height) |
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(RepeatNormal), |
9 | pm(0), refcnt(0) |
9 | pm(0), ref(0) |
10 | { |
10 | { |
11 | } |
11 | } |
12 | |
12 | |
13 | rxvt_img::rxvt_img (const rxvt_img &img) |
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) |
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 |
21 | rxvt_img::rxvt_img (rxvt_screen *screen, XRenderPictFormat *format, int width, int height, Pixmap pixmap) |
20 | rxvt_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 | |
60 | rxvt_img * |
61 | rxvt_img * |
… | |
… | |
83 | } |
84 | } |
84 | |
85 | |
85 | void |
86 | void |
86 | rxvt_img::destroy () |
87 | rxvt_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 | |
97 | rxvt_img::~rxvt_img () |
98 | rxvt_img::~rxvt_img () |
98 | { |
99 | { |
99 | destroy (); |
100 | destroy (); |
… | |
… | |
101 | |
102 | |
102 | void |
103 | void |
103 | rxvt_img::alloc () |
104 | rxvt_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 | |
|
|
110 | Picture |
|
|
111 | rxvt_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 | XRectangle clip = { -x, -y, min (w, ref->w), min (h, ref->h) }; |
|
|
120 | XRenderSetPictureClipRectangles (dpy, pic, 0, 0, &clip, 1); |
|
|
121 | |
|
|
122 | return pic; |
107 | } |
123 | } |
108 | |
124 | |
109 | void |
125 | void |
110 | rxvt_img::unshare () |
126 | rxvt_img::unshare () |
111 | { |
127 | { |
112 | if (refcnt && *refcnt == 1) |
128 | if (ref->cnt == 1 && ref->ours) |
113 | return; |
129 | return; |
114 | |
130 | |
|
|
131 | //TODO: maybe should reify instead |
115 | Pixmap pm2 = XCreatePixmap (s->display->dpy, s->display->root, w, h, format->depth); |
132 | 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); |
133 | GC gc = XCreateGC (s->display->dpy, pm, 0, 0); |
117 | XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, w, h, 0, 0); |
134 | XCopyArea (s->display->dpy, pm, pm2, gc, 0, 0, ref->w, ref->h, 0, 0); |
118 | XFreeGC (s->display->dpy, gc); |
135 | XFreeGC (s->display->dpy, gc); |
119 | |
136 | |
120 | destroy (); |
137 | destroy (); |
121 | |
138 | |
122 | pm = pm2; |
139 | pm = pm2; |
123 | refcnt = new int (1); |
140 | ref = new pixref (ref->w, ref->h); |
124 | } |
141 | } |
125 | |
142 | |
126 | void |
143 | void |
127 | rxvt_img::fill (const rxvt_color &c) |
144 | rxvt_img::fill (const rxvt_color &c) |
128 | { |
145 | { |
… | |
… | |
165 | double *kernel = (double *)malloc (size * sizeof (double)); |
182 | double *kernel = (double *)malloc (size * sizeof (double)); |
166 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
183 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
167 | rxvt_img *img = new rxvt_img (s, format, x, y, w, h); |
184 | rxvt_img *img = new rxvt_img (s, format, x, y, w, h); |
168 | img->alloc (); |
185 | img->alloc (); |
169 | |
186 | |
|
|
187 | Picture src = src_picture (); |
|
|
188 | |
170 | XRenderPictureAttributes pa; |
189 | XRenderPictureAttributes pa; |
171 | |
|
|
172 | pa.repeat = RepeatPad; |
190 | pa.repeat = RepeatPad; |
173 | Picture src = XRenderCreatePicture (dpy, pm , format, CPRepeat, &pa); |
|
|
174 | Picture dst = XRenderCreatePicture (dpy, img->pm, format, CPRepeat, &pa); |
191 | Picture dst = XRenderCreatePicture (dpy, img->pm, format, CPRepeat, &pa); |
175 | |
192 | |
176 | Pixmap tmp_pm = XCreatePixmap (dpy, pm, w, h, format->depth); |
193 | Pixmap tmp_pm = XCreatePixmap (dpy, pm, w, h, format->depth); |
177 | Picture tmp = XRenderCreatePicture (dpy, tmp_pm , format, CPRepeat, &pa); |
194 | Picture tmp = XRenderCreatePicture (dpy, tmp_pm , format, CPRepeat, &pa); |
178 | XFreePixmap (dpy, tmp_pm); |
195 | XFreePixmap (dpy, tmp_pm); |
… | |
… | |
387 | |
404 | |
388 | // todo, if x==0 and y==0 and w==real width we could clone |
405 | // todo, if x==0 and y==0 and w==real width we could clone |
389 | // but that involves an rtt to find pixmap width. |
406 | // but that involves an rtt to find pixmap width. |
390 | |
407 | |
391 | Display *dpy = s->display->dpy; |
408 | Display *dpy = s->display->dpy; |
392 | XRenderPictureAttributes pa; |
409 | |
393 | pa.repeat = repeat; |
410 | Picture src = src_picture (); |
394 | Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); |
|
|
395 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
411 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
396 | |
412 | |
397 | XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h); |
413 | XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h); |
398 | |
414 | |
399 | XRenderFreePicture (dpy, src); |
415 | XRenderFreePicture (dpy, src); |
400 | XRenderFreePicture (dpy, dst); |
416 | XRenderFreePicture (dpy, dst); |
… | |
… | |
404 | |
420 | |
405 | rxvt_img * |
421 | rxvt_img * |
406 | rxvt_img::sub_rect (int x, int y, int width, int height) |
422 | rxvt_img::sub_rect (int x, int y, int width, int height) |
407 | { |
423 | { |
408 | rxvt_img *img = clone (); |
424 | rxvt_img *img = clone (); |
|
|
425 | |
|
|
426 | //TODO: width > w, must reify |
409 | |
427 | |
410 | img->x += x; |
428 | img->x += x; |
411 | img->y += y; |
429 | img->y += y; |
412 | img->w = width; |
430 | img->w = width; |
413 | img->h = height; |
431 | img->h = height; |
… | |
… | |
420 | { |
438 | { |
421 | rxvt_img *img = new rxvt_img (s, format, 0, 0, new_width, new_height); |
439 | rxvt_img *img = new rxvt_img (s, format, 0, 0, new_width, new_height); |
422 | img->alloc (); |
440 | img->alloc (); |
423 | |
441 | |
424 | Display *dpy = s->display->dpy; |
442 | Display *dpy = s->display->dpy; |
425 | XRenderPictureAttributes pa; |
443 | 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); |
444 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
429 | |
445 | |
430 | XTransform xfrm; |
446 | XTransform xfrm; |
431 | |
447 | |
432 | for (int i = 0; i < 3; ++i) |
448 | for (int i = 0; i < 3; ++i) |
433 | for (int j = 0; j < 3; ++j) |
449 | for (int j = 0; j < 3; ++j) |
… | |
… | |
477 | rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg) |
493 | rxvt_img::convert_to (XRenderPictFormat *new_format, const rxvt_color &bg) |
478 | { |
494 | { |
479 | if (new_format == format) |
495 | if (new_format == format) |
480 | return clone (); |
496 | return clone (); |
481 | |
497 | |
482 | rxvt_img *img = new rxvt_img (s, new_format, x, y, w, h); |
498 | rxvt_img *img = new rxvt_img (s, new_format, 0, 0, w, h); |
483 | img->alloc (); |
499 | img->alloc (); |
484 | |
500 | |
485 | Display *dpy = s->display->dpy; |
501 | Display *dpy = s->display->dpy; |
486 | Picture src = XRenderCreatePicture (dpy, pm, format, 0, 0); |
502 | Picture src = src_picture (); |
487 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
503 | Picture dst = XRenderCreatePicture (dpy, img->pm, new_format, 0, 0); |
488 | int op = PictOpSrc; |
504 | int op = PictOpSrc; |
489 | |
505 | |
490 | if (format->direct.alphaMask && !new_format->direct.alphaMask) |
506 | if (format->direct.alphaMask && !new_format->direct.alphaMask) |
491 | { |
507 | { |
… | |
… | |
510 | rxvt_img * |
526 | rxvt_img * |
511 | rxvt_img::blend (rxvt_img *img, double factor) |
527 | rxvt_img::blend (rxvt_img *img, double factor) |
512 | { |
528 | { |
513 | rxvt_img *img2 = clone (); |
529 | rxvt_img *img2 = clone (); |
514 | Display *dpy = s->display->dpy; |
530 | Display *dpy = s->display->dpy; |
515 | Picture src = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
531 | Picture src = src_picture (); |
516 | Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); |
532 | Picture dst = XRenderCreatePicture (dpy, img2->pm, img2->format, 0, 0); |
517 | Picture mask = create_xrender_mask (dpy, img->pm, False); |
533 | Picture mask = create_xrender_mask (dpy, img->pm, False); |
518 | |
534 | |
519 | XRenderColor mask_c; |
535 | XRenderColor mask_c; |
520 | |
536 | |