2014-10-09 08:45:44 +00:00
|
|
|
/* GDK - The GIMP Drawing Kit
|
|
|
|
*
|
|
|
|
* gdkglcontext-x11.c: X11 specific OpenGL wrappers
|
|
|
|
*
|
|
|
|
* Copyright © 2014 Emmanuele Bassi
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gdkglcontext-x11.h"
|
|
|
|
#include "gdkdisplay-x11.h"
|
2016-10-27 21:27:49 +00:00
|
|
|
#include "gdkprivate-x11.h"
|
2014-10-09 08:45:44 +00:00
|
|
|
#include "gdkscreen-x11.h"
|
|
|
|
|
|
|
|
#include "gdkx11display.h"
|
|
|
|
#include "gdkx11glcontext.h"
|
|
|
|
#include "gdkx11screen.h"
|
2018-03-20 10:46:11 +00:00
|
|
|
#include "gdkx11surface.h"
|
2014-10-29 12:33:08 +00:00
|
|
|
#include "gdkx11property.h"
|
|
|
|
#include <X11/Xatom.h>
|
2014-10-09 08:45:44 +00:00
|
|
|
|
|
|
|
#include "gdkinternals.h"
|
|
|
|
|
|
|
|
#include "gdkintl.h"
|
|
|
|
|
2021-03-16 08:51:40 +00:00
|
|
|
#include <cairo-xlib.h>
|
2014-10-09 08:45:44 +00:00
|
|
|
|
2014-10-22 18:37:58 +00:00
|
|
|
#include <epoxy/glx.h>
|
2014-10-09 08:45:44 +00:00
|
|
|
|
2021-05-10 14:07:08 +00:00
|
|
|
G_DEFINE_ABSTRACT_TYPE (GdkX11GLContext, gdk_x11_gl_context, GDK_TYPE_GL_CONTEXT)
|
2015-10-06 17:59:35 +00:00
|
|
|
|
2014-10-09 08:45:44 +00:00
|
|
|
static void
|
|
|
|
gdk_x11_gl_context_class_init (GdkX11GLContextClass *klass)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_x11_gl_context_init (GdkX11GLContext *self)
|
|
|
|
{
|
2014-11-05 11:02:18 +00:00
|
|
|
self->do_frame_sync = TRUE;
|
2014-10-09 08:45:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GdkGLContext *
|
2018-03-20 14:14:10 +00:00
|
|
|
gdk_x11_surface_create_gl_context (GdkSurface *surface,
|
2021-05-10 14:07:08 +00:00
|
|
|
gboolean attached,
|
|
|
|
GdkGLContext *share,
|
|
|
|
GError **error)
|
2014-10-09 08:45:44 +00:00
|
|
|
{
|
2021-05-10 17:11:05 +00:00
|
|
|
GdkX11GLContext *context = NULL;
|
2021-05-10 14:07:08 +00:00
|
|
|
GdkX11Display *display_x11;
|
|
|
|
GdkDisplay *display;
|
2014-10-09 08:45:44 +00:00
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
display = gdk_surface_get_display (surface);
|
2021-06-06 15:07:05 +00:00
|
|
|
display_x11 = GDK_X11_DISPLAY (display);
|
2014-10-09 14:09:05 +00:00
|
|
|
|
2021-06-07 12:30:29 +00:00
|
|
|
if (display_x11->egl_display)
|
2021-06-06 15:07:05 +00:00
|
|
|
context = gdk_x11_gl_context_egl_new (surface, attached, share, error);
|
2021-06-29 20:10:48 +00:00
|
|
|
else if (display_x11->glx_config != NULL)
|
2021-06-06 15:07:05 +00:00
|
|
|
context = gdk_x11_gl_context_glx_new (surface, attached, share, error);
|
|
|
|
else
|
2014-10-09 08:45:44 +00:00
|
|
|
{
|
2021-07-02 01:21:14 +00:00
|
|
|
g_assert (display_x11->gl_error);
|
|
|
|
if (error)
|
|
|
|
*error = g_error_copy (display_x11->gl_error);
|
2014-10-09 08:45:44 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-05-10 14:07:08 +00:00
|
|
|
if (context == NULL)
|
|
|
|
return NULL;
|
2014-10-09 08:45:44 +00:00
|
|
|
|
2014-10-09 14:09:05 +00:00
|
|
|
context->is_attached = attached;
|
2014-10-09 08:45:44 +00:00
|
|
|
|
|
|
|
return GDK_GL_CONTEXT (context);
|
|
|
|
}
|
|
|
|
|
2014-10-30 10:46:09 +00:00
|
|
|
gboolean
|
2014-10-09 08:45:44 +00:00
|
|
|
gdk_x11_display_make_gl_context_current (GdkDisplay *display,
|
|
|
|
GdkGLContext *context)
|
|
|
|
{
|
2021-05-10 14:07:08 +00:00
|
|
|
GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
|
2014-10-09 08:45:44 +00:00
|
|
|
|
2021-06-07 12:30:29 +00:00
|
|
|
if (display_x11->egl_display)
|
2021-05-10 17:11:05 +00:00
|
|
|
return gdk_x11_gl_context_egl_make_current (display, context);
|
2021-06-29 20:10:48 +00:00
|
|
|
else if (display_x11->glx_config)
|
2021-05-10 14:07:08 +00:00
|
|
|
return gdk_x11_gl_context_glx_make_current (display, context);
|
2021-05-10 17:11:05 +00:00
|
|
|
else
|
|
|
|
g_assert_not_reached ();
|
2014-10-09 08:45:44 +00:00
|
|
|
|
2021-05-10 14:07:08 +00:00
|
|
|
return FALSE;
|
2014-10-09 08:45:44 +00:00
|
|
|
}
|
2021-06-12 09:07:24 +00:00
|
|
|
|
2021-06-13 15:34:55 +00:00
|
|
|
gboolean
|
2021-07-04 23:57:03 +00:00
|
|
|
gdk_x11_display_init_gl_backend (GdkX11Display *self,
|
|
|
|
Visual **out_visual,
|
|
|
|
int *out_depth,
|
|
|
|
GError **error)
|
2021-06-12 09:07:24 +00:00
|
|
|
{
|
|
|
|
GdkDisplay *display G_GNUC_UNUSED = GDK_DISPLAY (self);
|
|
|
|
|
|
|
|
if (GDK_DISPLAY_DEBUG_CHECK (display, GL_DISABLE))
|
2021-07-02 01:21:14 +00:00
|
|
|
{
|
|
|
|
g_set_error_literal (error, GDK_GL_ERROR,
|
|
|
|
GDK_GL_ERROR_NOT_AVAILABLE,
|
|
|
|
_("GL support disabled via GDK_DEBUG=gl-disable"));
|
|
|
|
return FALSE;
|
|
|
|
}
|
2021-06-12 09:07:24 +00:00
|
|
|
|
2021-07-02 01:37:32 +00:00
|
|
|
if (GDK_DISPLAY_DEBUG_CHECK (display, GL_EGL))
|
|
|
|
return gdk_x11_display_init_egl (self, TRUE, out_visual, out_depth, error);
|
|
|
|
if (GDK_DISPLAY_DEBUG_CHECK (display, GL_GLX))
|
|
|
|
return gdk_x11_display_init_glx (self, out_visual, out_depth, error);
|
|
|
|
|
|
|
|
/* No env vars set, do the regular GL initialization.
|
|
|
|
*
|
|
|
|
* We try EGL first, but are very picky about what we accept.
|
|
|
|
* If that fails, we try to go with GLX instead.
|
|
|
|
* And if that also fails, we try EGL again, but this time accept anything.
|
|
|
|
*
|
|
|
|
* The idea here is that EGL is the preferred method going forward, but GLX is
|
|
|
|
* the tried and tested method that we know works. So if we detect issues with
|
|
|
|
* EGL, we want to avoid using it in favor of GLX.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (gdk_x11_display_init_egl (self, FALSE, out_visual, out_depth, error))
|
|
|
|
return TRUE;
|
|
|
|
g_clear_error (error);
|
|
|
|
|
|
|
|
if (gdk_x11_display_init_glx (self, out_visual, out_depth, error))
|
|
|
|
return TRUE;
|
|
|
|
g_clear_error (error);
|
|
|
|
|
|
|
|
return gdk_x11_display_init_egl (self, TRUE, out_visual, out_depth, error);
|
2021-06-12 09:07:24 +00:00
|
|
|
}
|
|
|
|
|