Commit e4280ea1 authored by Emmanuele Bassi's avatar Emmanuele Bassi

gdk/x11: Add conditional support for EGL-X11

On certain platforms we need to use EGL X11 and OpenGL ES if we want to
get through to the hardware accelerate GL driver, and avoid the software
rasterizer inside Mesa.

Since this is a per-platform decision that cannot be resolved at run
time, we need to add a configure-time option that switches from GLX to
the X11 native support for EGL.
parent 7c394e82
......@@ -320,6 +320,10 @@ AC_ARG_ENABLE(xdamage,
[AS_HELP_STRING([--enable-xdamage],
[support X Damage extension [default=maybe]])],,
[enable_xdamage="maybe"])
AC_ARG_ENABLE(egl-x11,
[AS_HELP_STRING([--enable-egl-x11],
[Use EGL and XLib instead of GLX [default=no]])],,
[enable_egl_x11=no])
AC_ARG_ENABLE(x11-backend,
[AS_HELP_STRING([--enable-x11-backend],
......@@ -1279,6 +1283,20 @@ if test "x$enable_x11_backend" = xyes; then
fi
fi
# Checks whether to use EGL-X11 or GLX
if test x"$enable_egl_x11" != xno; then
if $PKG_CONFIG --exists egl ; then
AC_DEFINE(HAVE_EGL_X11, 1, [Use EGL-X11 instead of GLX])
X_PACKAGES="$X_PACKAGES egl"
elif test x"$enable_egl_x11" = xyes; then
AC_MSG_ERROR([EGL-X11 support requested but egl not found])
fi
fi
AM_CONDITIONAL(USE_EGL_X11, test "x$enable_egl_x11" != xno)
if $have_base_x_pc ; then
GDK_EXTRA_LIBS="$x_extra_libs"
else
......
......@@ -40,7 +40,6 @@ libgdk_x11_la_SOURCES = \
gdkeventtranslator.c \
gdkeventtranslator.h \
gdkgeometry-x11.c \
gdkglcontext-x11.c \
gdkglcontext-x11.h \
gdkkeys-x11.c \
gdkmain-x11.c \
......@@ -61,6 +60,12 @@ libgdk_x11_la_SOURCES = \
xsettings-client.h \
xsettings-client.c
if USE_EGL_X11
libgdk_x11_la_SOURCES += gdkglcontext-x11-eglx.c
else
libgdk_x11_la_SOURCES += gdkglcontext-x11.c
endif
libgdkinclude_HEADERS = \
gdkx.h
......
......@@ -137,18 +137,19 @@ struct _GdkX11Display
guint server_time_is_monotonic_time : 1;
guint have_glx : 1;
/* GLX extensions we check */
guint has_glx_swap_interval : 1;
guint has_glx_create_context : 1;
guint has_glx_texture_from_pixmap : 1;
guint has_glx_video_sync : 1;
guint has_glx_buffer_age : 1;
guint has_glx_sync_control : 1;
guint has_glx_multisample : 1;
guint has_glx_visual_rating : 1;
guint has_glx_create_es2_context : 1;
guint supports_gl : 1;
/* Platform-specific GL extensions we check */
guint has_swap_interval : 1;
guint has_create_context : 1;
guint has_texture_from_pixmap : 1;
guint has_video_sync : 1;
guint has_buffer_age : 1;
guint has_sync_control : 1;
guint has_multisample : 1;
guint has_visual_rating : 1;
guint has_create_es2_context : 1;
guint has_swap_buffers_with_damage : 1;
};
struct _GdkX11DisplayClass
......
This diff is collapsed.
......@@ -39,17 +39,38 @@
#include <cairo/cairo-xlib.h>
#include <epoxy/gl.h>
#include <epoxy/glx.h>
struct _GdkX11GLContext
{
GdkGLContext parent_instance;
GLXContext glx_context;
GLXFBConfig glx_config;
GLXDrawable drawable;
guint is_attached : 1;
guint is_direct : 1;
guint do_frame_sync : 1;
guint do_blit_swap : 1;
};
struct _GdkX11GLContextClass
{
GdkGLContextClass parent_class;
};
G_DEFINE_TYPE (GdkX11GLContext, gdk_x11_gl_context, GDK_TYPE_GL_CONTEXT)
typedef struct {
GdkDisplay *display;
GLXDrawable glx_drawable;
GLXWindow dummy_glx;
Window dummy_xwin;
GLXWindow dummy_glx;
guint32 last_frame_counter;
} DrawableInfo;
......@@ -100,7 +121,7 @@ maybe_wait_for_vblank (GdkDisplay *display,
GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
Display *dpy = gdk_x11_display_get_xdisplay (display);
if (display_x11->has_glx_sync_control)
if (display_x11->has_sync_control)
{
gint64 ust, msc, sbc;
......@@ -109,7 +130,7 @@ maybe_wait_for_vblank (GdkDisplay *display,
0, 2, (msc + 1) % 2,
&ust, &msc, &sbc);
}
else if (display_x11->has_glx_video_sync)
else if (display_x11->has_video_sync)
{
guint32 current_count;
......@@ -140,7 +161,7 @@ gdk_x11_window_invalidate_for_new_frame (GdkWindow *window,
context_x11->do_blit_swap = FALSE;
if (display_x11->has_glx_buffer_age)
if (display_x11->has_buffer_age)
{
gdk_gl_context_make_current (window->gl_paint_context);
glXQueryDrawable(dpy, context_x11->drawable,
......@@ -248,13 +269,13 @@ gdk_x11_gl_context_end_frame (GdkGLContext *context,
if (context_x11->do_frame_sync)
{
guint32 end_frame_counter = 0;
gboolean has_counter = display_x11->has_glx_video_sync;
gboolean can_wait = display_x11->has_glx_video_sync || display_x11->has_glx_sync_control;
gboolean has_counter = display_x11->has_video_sync;
gboolean can_wait = display_x11->has_video_sync || display_x11->has_sync_control;
if (display_x11->has_glx_video_sync)
if (display_x11->has_video_sync)
glXGetVideoSyncSGI (&end_frame_counter);
if (context_x11->do_frame_sync && !display_x11->has_glx_swap_interval)
if (context_x11->do_frame_sync && !display_x11->has_swap_interval)
{
glFinish ();
......@@ -284,7 +305,7 @@ gdk_x11_gl_context_end_frame (GdkGLContext *context,
else
glXSwapBuffers (dpy, drawable);
if (context_x11->do_frame_sync && info != NULL && display_x11->has_glx_video_sync)
if (context_x11->do_frame_sync && info != NULL && display_x11->has_video_sync)
glXGetVideoSyncSGI (&info->last_frame_counter);
}
......@@ -439,7 +460,7 @@ gdk_x11_gl_context_texture_from_surface (GdkGLContext *paint_context,
GdkX11Display *display_x11;
display_x11 = GDK_X11_DISPLAY (gdk_gl_context_get_display (paint_context));
if (!display_x11->has_glx_texture_from_pixmap)
if (!display_x11->has_texture_from_pixmap)
return FALSE;
if (cairo_surface_get_type (surface) != CAIRO_SURFACE_TYPE_XLIB)
......@@ -640,12 +661,12 @@ gdk_x11_gl_context_realize (GdkGLContext *context,
compat_bit = gdk_gl_context_get_forward_compatible (context);
/* If there is no glXCreateContextAttribsARB() then we default to legacy */
legacy_bit = !display_x11->has_glx_create_context ||
legacy_bit = !display_x11->has_create_context ||
(_gdk_gl_flags & GDK_GL_LEGACY) != 0;
es_bit = ((_gdk_gl_flags & GDK_GL_GLES) != 0 ||
(share != NULL && gdk_gl_context_get_use_es (share))) &&
(display_x11->has_glx_create_context && display_x11->has_glx_create_es2_context);
(display_x11->has_create_context && display_x11->has_create_es2_context);
/* We cannot share legacy contexts with core profile ones, so the
* shared context is the one that decides if we're going to create
......@@ -672,7 +693,7 @@ gdk_x11_gl_context_realize (GdkGLContext *context,
* a compatibility profile; if we don't, then we have to fall back to the
* old GLX 1.3 API.
*/
if (legacy_bit && !GDK_X11_DISPLAY (display)->has_glx_create_context)
if (legacy_bit && !GDK_X11_DISPLAY (display)->has_create_context)
{
GDK_NOTE (OPENGL, g_message ("Creating legacy GL context on request"));
context_x11->glx_context = create_legacy_context (display, context_x11->glx_config, share);
......@@ -848,7 +869,7 @@ gdk_x11_screen_init_gl (GdkScreen *screen)
int error_base, event_base;
int screen_num;
if (display_x11->have_glx)
if (display_x11->supports_gl)
return TRUE;
if (_gdk_gl_flags & GDK_GL_DISABLE)
......@@ -861,29 +882,29 @@ gdk_x11_screen_init_gl (GdkScreen *screen)
screen_num = GDK_X11_SCREEN (screen)->screen_num;
display_x11->have_glx = TRUE;
display_x11->supports_gl = TRUE;
display_x11->glx_version = epoxy_glx_version (dpy, screen_num);
display_x11->glx_error_base = error_base;
display_x11->glx_event_base = event_base;
display_x11->has_glx_create_context =
display_x11->has_create_context =
epoxy_has_glx_extension (dpy, screen_num, "GLX_ARB_create_context_profile");
display_x11->has_glx_create_es2_context =
display_x11->has_create_es2_context =
epoxy_has_glx_extension (dpy, screen_num, "GLX_EXT_create_context_es2_profile");
display_x11->has_glx_swap_interval =
display_x11->has_swap_interval =
epoxy_has_glx_extension (dpy, screen_num, "GLX_SGI_swap_control");
display_x11->has_glx_texture_from_pixmap =
display_x11->has_texture_from_pixmap =
epoxy_has_glx_extension (dpy, screen_num, "GLX_EXT_texture_from_pixmap");
display_x11->has_glx_video_sync =
display_x11->has_video_sync =
epoxy_has_glx_extension (dpy, screen_num, "GLX_SGI_video_sync");
display_x11->has_glx_buffer_age =
display_x11->has_buffer_age =
epoxy_has_glx_extension (dpy, screen_num, "GLX_EXT_buffer_age");
display_x11->has_glx_sync_control =
display_x11->has_sync_control =
epoxy_has_glx_extension (dpy, screen_num, "GLX_OML_sync_control");
display_x11->has_glx_multisample =
display_x11->has_multisample =
epoxy_has_glx_extension (dpy, screen_num, "GLX_ARB_multisample");
display_x11->has_glx_visual_rating =
display_x11->has_visual_rating =
epoxy_has_glx_extension (dpy, screen_num, "GLX_EXT_visual_rating");
GDK_NOTE (OPENGL,
......@@ -900,13 +921,13 @@ gdk_x11_screen_init_gl (GdkScreen *screen)
display_x11->glx_version / 10,
display_x11->glx_version % 10,
glXGetClientString (dpy, GLX_VENDOR),
display_x11->has_glx_create_context ? "yes" : "no",
display_x11->has_glx_create_es2_context ? "yes" : "no",
display_x11->has_glx_swap_interval ? "yes" : "no",
display_x11->has_glx_texture_from_pixmap ? "yes" : "no",
display_x11->has_glx_video_sync ? "yes" : "no",
display_x11->has_glx_buffer_age ? "yes" : "no",
display_x11->has_glx_sync_control ? "yes" : "no"));
display_x11->has_create_context ? "yes" : "no",
display_x11->has_create_es2_context ? "yes" : "no",
display_x11->has_swap_interval ? "yes" : "no",
display_x11->has_texture_from_pixmap ? "yes" : "no",
display_x11->has_video_sync ? "yes" : "no",
display_x11->has_buffer_age ? "yes" : "no",
display_x11->has_sync_control ? "yes" : "no"));
return TRUE;
}
......@@ -1232,10 +1253,10 @@ _gdk_x11_screen_update_visuals_for_gl (GdkScreen *screen)
glXGetConfig (dpy, &visual_list[0], GLX_DEPTH_SIZE, &gl_info[i].depth_size);
glXGetConfig (dpy, &visual_list[0], GLX_STENCIL_SIZE, &gl_info[i].stencil_size);
if (display_x11->has_glx_multisample)
if (display_x11->has_multisample)
glXGetConfig(dpy, &visual_list[0], GLX_SAMPLE_BUFFERS_ARB, &gl_info[i].num_multisample);
if (display_x11->has_glx_visual_rating)
if (display_x11->has_visual_rating)
glXGetConfig(dpy, &visual_list[0], GLX_VISUAL_CAVEAT_EXT, &gl_info[i].visual_caveat);
else
gl_info[i].visual_caveat = GLX_NONE_EXT;
......@@ -1327,7 +1348,7 @@ gdk_x11_display_make_gl_context_current (GdkDisplay *display,
return FALSE;
}
if (context_x11->is_attached && GDK_X11_DISPLAY (display)->has_glx_swap_interval)
if (context_x11->is_attached && GDK_X11_DISPLAY (display)->has_swap_interval)
{
window = gdk_gl_context_get_window (context);
......
......@@ -24,9 +24,6 @@
#include <X11/X.h>
#include <X11/Xlib.h>
#include <epoxy/gl.h>
#include <epoxy/glx.h>
#include "gdkglcontextprivate.h"
#include "gdkdisplayprivate.h"
#include "gdkvisual.h"
......@@ -36,27 +33,6 @@
G_BEGIN_DECLS
struct _GdkX11GLContext
{
GdkGLContext parent_instance;
GLXContext glx_context;
GLXFBConfig glx_config;
GLXDrawable drawable;
guint is_attached : 1;
guint is_direct : 1;
guint do_frame_sync : 1;
guint do_blit_swap : 1;
};
struct _GdkX11GLContextClass
{
GdkGLContextClass parent_class;
};
gboolean gdk_x11_screen_init_gl (GdkScreen *screen);
GdkGLContext * gdk_x11_window_create_gl_context (GdkWindow *window,
gboolean attached,
GdkGLContext *share,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment