… | |
… | |
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 | return pic; |
107 | } |
120 | } |
108 | |
121 | |
109 | void |
122 | void |
110 | rxvt_img::unshare () |
123 | rxvt_img::unshare () |
111 | { |
124 | { |
112 | if (refcnt && *refcnt == 1) |
125 | if (ref->cnt == 1 && ref->ours) |
113 | return; |
126 | return; |
114 | |
127 | |
|
|
128 | //TODO: maybe should reify instead |
115 | 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); |
116 | GC gc = XCreateGC (s->display->dpy, pm, 0, 0); |
130 | GC gc = XCreateGC (s->display->dpy, pm, 0, 0); |
117 | 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); |
118 | XFreeGC (s->display->dpy, gc); |
132 | XFreeGC (s->display->dpy, gc); |
119 | |
133 | |
120 | destroy (); |
134 | destroy (); |
121 | |
135 | |
122 | pm = pm2; |
136 | pm = pm2; |
123 | refcnt = new int (1); |
137 | ref = new pixref (ref->w, ref->h); |
124 | } |
138 | } |
125 | |
139 | |
126 | void |
140 | void |
127 | rxvt_img::fill (const rxvt_color &c) |
141 | rxvt_img::fill (const rxvt_color &c) |
128 | { |
142 | { |
… | |
… | |
165 | double *kernel = (double *)malloc (size * sizeof (double)); |
179 | double *kernel = (double *)malloc (size * sizeof (double)); |
166 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
180 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
167 | rxvt_img *img = new rxvt_img (s, format, x, y, w, h); |
181 | rxvt_img *img = new rxvt_img (s, format, x, y, w, h); |
168 | img->alloc (); |
182 | img->alloc (); |
169 | |
183 | |
|
|
184 | Picture src = src_picture (); |
|
|
185 | |
170 | XRenderPictureAttributes pa; |
186 | XRenderPictureAttributes pa; |
171 | |
|
|
172 | pa.repeat = RepeatPad; |
187 | pa.repeat = RepeatPad; |
173 | Picture src = XRenderCreatePicture (dpy, pm , format, CPRepeat, &pa); |
|
|
174 | Picture dst = XRenderCreatePicture (dpy, img->pm, format, CPRepeat, &pa); |
188 | Picture dst = XRenderCreatePicture (dpy, img->pm, format, CPRepeat, &pa); |
175 | |
189 | |
176 | Pixmap tmp_pm = XCreatePixmap (dpy, pm, w, h, format->depth); |
190 | Pixmap tmp_pm = XCreatePixmap (dpy, pm, w, h, format->depth); |
177 | Picture tmp = XRenderCreatePicture (dpy, tmp_pm , format, CPRepeat, &pa); |
191 | Picture tmp = XRenderCreatePicture (dpy, tmp_pm , format, CPRepeat, &pa); |
178 | XFreePixmap (dpy, tmp_pm); |
192 | XFreePixmap (dpy, tmp_pm); |
… | |
… | |
380 | } |
394 | } |
381 | |
395 | |
382 | rxvt_img * |
396 | rxvt_img * |
383 | rxvt_img::reify () |
397 | rxvt_img::reify () |
384 | { |
398 | { |
|
|
399 | if (x == 0 && y == 0 && w == ref->w && h == ref->h) |
|
|
400 | return clone (); |
|
|
401 | |
385 | rxvt_img *img = new rxvt_img (s, format, 0, 0, w, h); |
402 | rxvt_img *img = new rxvt_img (s, format, 0, 0, w, h); |
386 | img->alloc (); |
403 | img->alloc (); |
387 | |
404 | |
388 | // todo, if x==0 and y==0 and w==real width we could clone |
|
|
389 | // but that involves an rtt to find pixmap width. |
|
|
390 | |
|
|
391 | Display *dpy = s->display->dpy; |
405 | Display *dpy = s->display->dpy; |
392 | XRenderPictureAttributes pa; |
406 | |
393 | pa.repeat = repeat; |
407 | Picture src = src_picture (); |
394 | Picture src = XRenderCreatePicture (dpy, pm, format, CPRepeat, &pa); |
|
|
395 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
408 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
396 | |
409 | |
397 | XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h); |
410 | XRenderComposite (dpy, PictOpSrc, src, None, dst, x, y, 0, 0, 0, 0, w, h); |
398 | |
411 | |
399 | XRenderFreePicture (dpy, src); |
412 | XRenderFreePicture (dpy, src); |
400 | XRenderFreePicture (dpy, dst); |
413 | XRenderFreePicture (dpy, dst); |
… | |
… | |
403 | } |
416 | } |
404 | |
417 | |
405 | rxvt_img * |
418 | rxvt_img * |
406 | rxvt_img::sub_rect (int x, int y, int width, int height) |
419 | rxvt_img::sub_rect (int x, int y, int width, int height) |
407 | { |
420 | { |
|
|
421 | bool need_reify = w < width || h < height; |
|
|
422 | |
408 | rxvt_img *img = clone (); |
423 | rxvt_img *img = clone (); |
409 | |
424 | |
410 | img->x += x; |
425 | img->x += x; |
411 | img->y += y; |
426 | img->y += y; |
412 | img->w = width; |
427 | img->w = width; |
413 | img->h = height; |
428 | img->h = height; |
414 | |
429 | |
|
|
430 | if (need_reify) |
|
|
431 | img->reify (); |
|
|
432 | |
415 | return img; |
433 | return img; |
416 | } |
434 | } |
417 | |
435 | |
418 | rxvt_img * |
436 | rxvt_img * |
419 | rxvt_img::transform (int new_width, int new_height, double matrix[9]) |
437 | rxvt_img::transform (int new_width, int new_height, double matrix[9]) |
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 | |