emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 103ddfe387: Display images with a mask correctly when `alpha-back


From: Po Lu
Subject: master 103ddfe387: Display images with a mask correctly when `alpha-background' is set
Date: Mon, 31 Jan 2022 23:59:05 -0500 (EST)

branch: master
commit 103ddfe387333891780b93eec652cbcf1519156c
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Display images with a mask correctly when `alpha-background' is set
    
    * src/xterm.c (x_query_frame_background_color): Return value
    adjusted for background alpha.
    (x_draw_image_glyph_string): Respect `alpha-background' when
    generating background pixmap.
---
 src/xterm.c | 49 +++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 41 insertions(+), 8 deletions(-)

diff --git a/src/xterm.c b/src/xterm.c
index 2fc336f72a..843483b594 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -2993,12 +2993,23 @@ x_query_colors (struct frame *f, XColor *colors, int 
ncolors)
   XQueryColors (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), colors, ncolors);
 }
 
-/* Store F's background color into *BGCOLOR.  */
+/* Store F's real background color into *BGCOLOR.  */
 
 static void
 x_query_frame_background_color (struct frame *f, XColor *bgcolor)
 {
-  bgcolor->pixel = FRAME_BACKGROUND_PIXEL (f);
+  unsigned long background = FRAME_BACKGROUND_PIXEL (f);
+
+  if (FRAME_DISPLAY_INFO (f)->alpha_bits)
+    {
+      background = (background & ~FRAME_DISPLAY_INFO (f)->alpha_mask);
+      background |= (((unsigned long) (f->alpha_background * 0xffff)
+                     >> (16 - FRAME_DISPLAY_INFO (f)->alpha_bits))
+                    << FRAME_DISPLAY_INFO (f)->alpha_offset);
+    }
+
+  bgcolor->pixel = background;
+
   x_query_colors (f, bgcolor, 1);
 }
 
@@ -4075,12 +4086,34 @@ x_draw_image_glyph_string (struct glyph_string *s)
          else
            {
              XGCValues xgcv;
-             XGetGCValues (display, s->gc, GCForeground | GCBackground,
-                           &xgcv);
-             XSetForeground (display, s->gc, xgcv.background);
-             XFillRectangle (display, pixmap, s->gc,
-                             0, 0, s->background_width, s->height);
-             XSetForeground (display, s->gc, xgcv.foreground);
+#if defined HAVE_XRENDER && (RENDER_MAJOR > 0 || (RENDER_MINOR >= 2))
+             if (FRAME_DISPLAY_INFO (s->f)->alpha_bits
+                 && FRAME_CHECK_XR_VERSION (s->f, 0, 2)
+                 && FRAME_X_PICTURE_FORMAT (s->f))
+               {
+                 XRenderColor xc;
+                 XRenderPictureAttributes attrs;
+                 Picture pict;
+                 memset (&attrs, 0, sizeof attrs);
+
+                 pict = XRenderCreatePicture (display, pixmap,
+                                              FRAME_X_PICTURE_FORMAT (s->f),
+                                              0, &attrs);
+                 x_xrender_color_from_gc_background (s->f, s->gc, &xc, true);
+                 XRenderFillRectangle (FRAME_X_DISPLAY (s->f), PictOpSrc, pict,
+                                       &xc, 0, 0, s->background_width, 
s->height);
+                 XRenderFreePicture (display, pict);
+               }
+             else
+#endif
+               {
+                 XGetGCValues (display, s->gc, GCForeground | GCBackground,
+                               &xgcv);
+                 XSetForeground (display, s->gc, xgcv.background);
+                 XFillRectangle (display, pixmap, s->gc,
+                                 0, 0, s->background_width, s->height);
+                 XSetForeground (display, s->gc, xgcv.foreground);
+               }
            }
        }
       else



reply via email to

[Prev in Thread] Current Thread [Next in Thread]