From: Po Lu Date: Wed, 19 Jan 2022 09:39:04 +0000 (+0800) Subject: Use Cairo XCB surfaces when XCB is available X-Git-Tag: emacs-29.0.90~2951 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=de614ec9508d6ba34abf9db28f5d086b8710e361;p=emacs.git Use Cairo XCB surfaces when XCB is available This lets us get at goodies such as shm support, which aren't available with the xlib surface. (bug#52120) * configure.ac: Test for cairo-xcb if cairo is available on X. * src/xterm.c (USE_CAIRO_XCB_SURFACE): New define. (x_begin_cr_clip): Create XCB surfaces if available. (x_try_cr_xlib_drawable): (x_scroll_run): Handle XCB surfaces. (x_term_init): Find XCB visualtype structure. * src/xterm.h (struct x_display_info): New field `xcb_visual'. * src/xwidget.c (x_draw_xwidget_glyph_string): Fix integer overflow. --- diff --git a/configure.ac b/configure.ac index 955f0918fd4..4b5316f4de1 100644 --- a/configure.ac +++ b/configure.ac @@ -3433,6 +3433,13 @@ if test "${HAVE_X11}" = "yes"; then CAIRO_MODULE="cairo >= $CAIRO_REQUIRED" EMACS_CHECK_MODULES(CAIRO, $CAIRO_MODULE) if test $HAVE_CAIRO = yes; then + CAIRO_XCB_MODULE="cairo-xcb >= $CAIRO_REQUIRED" + EMACS_CHECK_MODULES(CAIRO_XCB, $CAIRO_XCB_MODULE) + if test $HAVE_CAIRO_XCB = yes; then + CAIRO_CFLAGS="$CAIRO_CFLAGS $CAIRO_XCB_CFLAGS" + CAIRO_LIBS="$CAIRO_LIBS $CAIRO_XCB_LIBS" + AC_DEFINE(USE_CAIRO_XCB, 1, [Define to 1 if cairo XCB surfaces are available.]) + fi AC_DEFINE(USE_CAIRO, 1, [Define to 1 if using cairo.]) CFLAGS="$CFLAGS $CAIRO_CFLAGS" LIBS="$LIBS $CAIRO_LIBS" diff --git a/src/xterm.c b/src/xterm.c index 54d10e01c30..d3619f5b5e6 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -99,6 +99,10 @@ along with GNU Emacs. If not, see . */ #include "xterm.h" #include +#ifdef USE_XCB +#include +#endif + /* If we have Xfixes extension, use it for pointer blanking. */ #ifdef HAVE_XFIXES #include @@ -206,6 +210,10 @@ along with GNU Emacs. If not, see . */ #include #endif +#if defined USE_XCB && defined USE_CAIRO_XCB +#define USE_CAIRO_XCB_SURFACE +#endif + /* Default to using XIM if available. */ #ifdef USE_XIM bool use_xim = true; @@ -777,11 +785,19 @@ x_begin_cr_clip (struct frame *f, GC gc) { int width = FRAME_CR_SURFACE_DESIRED_WIDTH (f); int height = FRAME_CR_SURFACE_DESIRED_HEIGHT (f); - cairo_surface_t *surface - = cairo_xlib_surface_create (FRAME_X_DISPLAY (f), - FRAME_X_RAW_DRAWABLE (f), - FRAME_X_VISUAL (f), - width, height); + cairo_surface_t *surface; +#ifdef USE_CAIRO_XCB_SURFACE + if (FRAME_DISPLAY_INFO (f)->xcb_visual) + surface = cairo_xcb_surface_create (FRAME_DISPLAY_INFO (f)->xcb_connection, + (xcb_drawable_t) FRAME_X_RAW_DRAWABLE (f), + FRAME_DISPLAY_INFO (f)->xcb_visual, + width, height); + else +#endif + surface = cairo_xlib_surface_create (FRAME_X_DISPLAY (f), + FRAME_X_RAW_DRAWABLE (f), + FRAME_X_VISUAL (f), + width, height); cr = FRAME_CR_CONTEXT (f) = cairo_create (surface); cairo_surface_destroy (surface); @@ -850,6 +866,9 @@ x_try_cr_xlib_drawable (struct frame *f, GC gc) switch (cairo_surface_get_type (surface)) { case CAIRO_SURFACE_TYPE_XLIB: +#ifdef USE_CAIRO_XCB_SURFACE + case CAIRO_SURFACE_TYPE_XCB: +#endif cairo_surface_flush (surface); return true; @@ -4921,6 +4940,18 @@ x_scroll_run (struct window *w, struct run *run) x, to_y); cairo_surface_mark_dirty_rectangle (surface, x, to_y, width, height); } +#ifdef USE_CAIRO_XCB_SURFACE + else if (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_XCB) + { + cairo_surface_flush (surface); + xcb_copy_area (FRAME_DISPLAY_INFO (f)->xcb_connection, + (xcb_drawable_t) FRAME_X_DRAWABLE (f), + (xcb_drawable_t) FRAME_X_DRAWABLE (f), + (xcb_gcontext_t) XGContextFromGC (f->output_data.x->normal_gc), + x, from_y, x, to_y, width, height); + cairo_surface_mark_dirty_rectangle (surface, x, to_y, width, height); + } +#endif else { cairo_surface_t *s @@ -15258,6 +15289,40 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name) dpyinfo->supports_xdbe = true; #endif +#ifdef USE_XCB + xcb_screen_t *xcb_screen = NULL; + xcb_screen_iterator_t iter; + xcb_visualid_t wanted = { XVisualIDFromVisual (dpyinfo->visual) }; + xcb_depth_iterator_t depth_iter; + xcb_visualtype_iterator_t visual_iter; + + int screen = DefaultScreen (dpyinfo->display); + + iter = xcb_setup_roots_iterator (xcb_get_setup (dpyinfo->xcb_connection)); + for (; iter.rem; --screen, xcb_screen_next (&iter)) + { + if (!screen) + xcb_screen = iter.data; + } + + if (xcb_screen) + { + depth_iter = xcb_screen_allowed_depths_iterator (xcb_screen); + for (; depth_iter.rem; xcb_depth_next (&depth_iter)) + { + visual_iter = xcb_depth_visuals_iterator (depth_iter.data); + for (; visual_iter.rem; xcb_visualtype_next (&visual_iter)) + { + if (wanted == visual_iter.data->visual_id) + { + dpyinfo->xcb_visual = visual_iter.data; + break; + } + } + } + } +#endif + #ifdef HAVE_XINPUT2 dpyinfo->supports_xi2 = false; int rc; diff --git a/src/xterm.h b/src/xterm.h index 696f9db3d0a..a8eb6ee547a 100644 --- a/src/xterm.h +++ b/src/xterm.h @@ -78,6 +78,9 @@ typedef GtkWidget *xt_or_gtk_widget; #ifdef CAIRO_HAS_SVG_SURFACE #include #endif +#ifdef USE_CAIRO_XCB +#include +#endif #endif #ifdef HAVE_X_I18N @@ -512,6 +515,7 @@ struct x_display_info #ifdef USE_XCB xcb_connection_t *xcb_connection; + xcb_visualtype_t *xcb_visual; #endif #ifdef HAVE_XDBE diff --git a/src/xwidget.c b/src/xwidget.c index fce0aafb099..69e9d5b64be 100644 --- a/src/xwidget.c +++ b/src/xwidget.c @@ -1855,7 +1855,7 @@ webkit_js_to_lisp (JSCValue *value) const gint32 dlen = jsc_value_to_int32 (len); Lisp_Object obj; - if (! (0 <= dlen && dlen < G_MAXINT32 + 1)) + if (! (0 <= dlen && dlen < G_MAXINT32)) memory_full (SIZE_MAX); ptrdiff_t n = dlen;