]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid redundant creation of XRender pictures
authorPo Lu <luangruo@yahoo.com>
Fri, 14 Oct 2022 07:52:16 +0000 (15:52 +0800)
committerPo Lu <luangruo@yahoo.com>
Fri, 14 Oct 2022 07:56:15 +0000 (15:56 +0800)
* src/xterm.c (x_composite_image): Take arg DESTINATION.  Do not
create a picture if it is set.
(x_draw_image_foreground, x_draw_image_foreground_1): Pass
destination where appropriate.

src/xterm.c

index 27a66873484a0b2af91ea1e6ad2298e555d9e9d7..0fca9788ce54cb49b2d5125deaa8156338c913b1 100644 (file)
@@ -9603,31 +9603,49 @@ x_draw_glyph_string_box (struct glyph_string *s)
 
 
 #ifndef USE_CAIRO
+
 static void
 x_composite_image (struct glyph_string *s, Pixmap dest,
+#ifdef HAVE_XRENDER
+                  Picture destination,
+#endif
                    int srcX, int srcY, int dstX, int dstY,
                    int width, int height)
 {
-  Display *display = FRAME_X_DISPLAY (s->f);
+  Display *display;
 #ifdef HAVE_XRENDER
-  if (s->img->picture && FRAME_X_PICTURE_FORMAT (s->f))
-    {
-      Picture destination;
-      XRenderPictFormat *default_format;
-      XRenderPictureAttributes attr UNINIT;
+  XRenderPictFormat *default_format;
+  XRenderPictureAttributes attr UNINIT;
+#endif
 
-      default_format = FRAME_X_PICTURE_FORMAT (s->f);
-      destination = XRenderCreatePicture (display, dest,
-                                          default_format, 0, &attr);
+  display = FRAME_X_DISPLAY (s->f);
 
-      XRenderComposite (display, s->img->mask_picture ? PictOpOver : PictOpSrc,
-                        s->img->picture, s->img->mask_picture, destination,
-                        srcX, srcY,
-                        srcX, srcY,
-                        dstX, dstY,
-                        width, height);
+#ifdef HAVE_XRENDER
+  if (s->img->picture && FRAME_X_PICTURE_FORMAT (s->f))
+    {
+      if (destination == None)
+       {
+         /* The destination picture was not specified.  This means we
+            have to create a picture representing the */
+         default_format = FRAME_X_PICTURE_FORMAT (s->f);
+         destination = XRenderCreatePicture (display, dest,
+                                             default_format, 0, &attr);
+
+         XRenderComposite (display, (s->img->mask_picture
+                                     ? PictOpOver : PictOpSrc),
+                           s->img->picture, s->img->mask_picture,
+                           destination, srcX, srcY, srcX, srcY,
+                           dstX, dstY, width, height);
+
+         XRenderFreePicture (display, destination);
+       }
+      else
+       XRenderComposite (display, (s->img->mask_picture
+                                   ? PictOpOver : PictOpSrc),
+                         s->img->picture, s->img->mask_picture,
+                         destination, srcX, srcY, srcX, srcY,
+                         dstX, dstY, width, height);
 
-      XRenderFreePicture (display, destination);
       return;
     }
 #endif
@@ -9637,6 +9655,7 @@ x_composite_image (struct glyph_string *s, Pixmap dest,
             srcX, srcY,
             width, height, dstX, dstY);
 }
+
 #endif /* !USE_CAIRO */
 
 
@@ -9715,6 +9734,9 @@ x_draw_image_foreground (struct glyph_string *s)
          image_rect.height = s->slice.height;
          if (gui_intersect_rectangles (&clip_rect, &image_rect, &r))
             x_composite_image (s, FRAME_X_DRAWABLE (s->f),
+#ifdef HAVE_XRENDER
+                              FRAME_X_PICTURE (s->f),
+#endif
                               s->slice.x + r.x - x, s->slice.y + r.y - y,
                                r.x, r.y, r.width, r.height);
        }
@@ -9728,7 +9750,12 @@ x_draw_image_foreground (struct glyph_string *s)
          image_rect.width = s->slice.width;
          image_rect.height = s->slice.height;
          if (gui_intersect_rectangles (&clip_rect, &image_rect, &r))
-            x_composite_image (s, FRAME_X_DRAWABLE (s->f), s->slice.x + r.x - x, s->slice.y + r.y - y,
+            x_composite_image (s, FRAME_X_DRAWABLE (s->f),
+#ifdef HAVE_XRENDER
+                              FRAME_X_PICTURE (s->f),
+#endif
+                              s->slice.x + r.x - x,
+                              s->slice.y + r.y - y,
                                r.x, r.y, r.width, r.height);
 
          /* When the image has a mask, we can expect that at
@@ -9894,8 +9921,11 @@ x_draw_image_foreground_1 (struct glyph_string *s, Pixmap pixmap)
          XChangeGC (display, s->gc, mask, &xgcv);
 
          x_composite_image (s, pixmap,
-                             s->slice.x, s->slice.y,
-                             x, y, s->slice.width, s->slice.height);
+#ifdef HAVE_XRENDER
+                            None,
+#endif
+                             s->slice.x, s->slice.y, x, y,
+                            s->slice.width, s->slice.height);
          XSetClipMask (display, s->gc, None);
        }
       else