… | |
… | |
391 | rxvt_img::clone () |
391 | rxvt_img::clone () |
392 | { |
392 | { |
393 | return new rxvt_img (*this); |
393 | return new rxvt_img (*this); |
394 | } |
394 | } |
395 | |
395 | |
|
|
396 | |
|
|
397 | static XRenderPictFormat * |
|
|
398 | find_alpha_format_for (Display *dpy, XRenderPictFormat *format) |
|
|
399 | { |
|
|
400 | if (format->direct.alphaMask) |
|
|
401 | return format; // already has alpha |
|
|
402 | |
|
|
403 | // try to find a suitable alpha format, one bit alpha is enough for our purposes |
|
|
404 | if (format->type == PictTypeDirect) |
|
|
405 | for (int n = 0; XRenderPictFormat *f = XRenderFindFormat (dpy, 0, 0, n); ++n) |
|
|
406 | if (f->direct.alphaMask |
|
|
407 | && f->type == PictTypeDirect |
|
|
408 | && ecb_popcount32 (f->direct.redMask ) >= ecb_popcount32 (format->direct.redMask ) |
|
|
409 | && ecb_popcount32 (f->direct.greenMask) >= ecb_popcount32 (format->direct.greenMask) |
|
|
410 | && ecb_popcount32 (f->direct.blueMask ) >= ecb_popcount32 (format->direct.blueMask )) |
|
|
411 | return f; |
|
|
412 | |
|
|
413 | // should be a very good fallback |
|
|
414 | return XRenderFindStandardFormat (dpy, PictStandardARGB32); |
|
|
415 | } |
|
|
416 | |
396 | rxvt_img * |
417 | rxvt_img * |
397 | rxvt_img::reify () |
418 | rxvt_img::reify () |
398 | { |
419 | { |
399 | if (x == 0 && y == 0 && w == ref->w && h == ref->h) |
420 | if (x == 0 && y == 0 && w == ref->w && h == ref->h) |
400 | return clone (); |
421 | return clone (); |
… | |
… | |
403 | |
424 | |
404 | bool alpha = !format->direct.alphaMask |
425 | bool alpha = !format->direct.alphaMask |
405 | && (x || y) |
426 | && (x || y) |
406 | && repeat == RepeatNone; |
427 | && repeat == RepeatNone; |
407 | |
428 | |
408 | rxvt_img *img = new rxvt_img (s, alpha ? XRenderFindStandardFormat (dpy, PictStandardARGB32) : format, 0, 0, w, h, repeat); |
429 | rxvt_img *img = new rxvt_img (s, alpha ? find_alpha_format_for (dpy, format) : format, 0, 0, w, h, repeat); |
409 | img->alloc (); |
430 | img->alloc (); |
410 | |
431 | |
411 | Picture src = src_picture (); |
432 | Picture src = src_picture (); |
412 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
433 | Picture dst = XRenderCreatePicture (dpy, img->pm, img->format, 0, 0); |
413 | |
434 | |