`gdk_x11_gl_context_texture_from_surface` is not fit for purpose, slower than "software fallback"
Description
Of all the GDK backends (in gtk3), only the X11 backend has a dedicated implementation of texture_from_surface
. That means that in gdk_gl_texture_from_surface
, only it runs a dedicated code-path, and all the other backends take the software fallback instead:
void
gdk_gl_texture_from_surface (cairo_surface_t *surface,
cairo_region_t *region)
{
// ...
paint_context = gdk_gl_context_get_current ();
if ((_gdk_gl_flags & GDK_GL_SOFTWARE_DRAW_SURFACE) == 0 &&
paint_context &&
GDK_GL_CONTEXT_GET_CLASS (paint_context)->texture_from_surface &&
// Run dedicated code-path if it exists:
GDK_GL_CONTEXT_GET_CLASS (paint_context)->texture_from_surface (paint_context, surface, region))
return;
/* Software fallback */
use_texture_rectangle = gdk_gl_context_use_texture_rectangle (paint_context);
// ...
The bug is that the dedicated X11 code path is much, much slower than the "software fallback".
Here is a condensed version of the X11 code path. I have snipped most of it out except for three important lines:
static gboolean
gdk_x11_gl_context_texture_from_surface (GdkGLContext *paint_context,
cairo_surface_t *surface,
cairo_region_t *region)
{
// ...
glx_pixmap = glx_pixmap_get (surface, target); // 1
if (glx_pixmap == NULL)
return FALSE;
// ...
/* Ensure all the X stuff are synced before we read it back via texture-from-pixmap */
glXWaitX(); // 2
// ...
glXBindTexImageEXT (glx_pixmap->display, glx_pixmap->drawable, // 3
GLX_FRONT_LEFT_EXT, NULL);
// ...
}
I benchmarked the three lines while running Inkscape in OpenGL mode under an empty workload. Here are the results (raw data available on request):
All of these functions are taking way too long compared to the software fallback, probably due to X11 round trips. For example on wayland, the software fallback is used, and is orders of magnitude faster. Combined, these delays are detrimental to the performance of Inkscape on X11, and any other OpenGL-using GTK app that happens to touch this code path.
Version info
GTK version: 1:3.24.31-3 (Arch Linux packages)