2014-10-09 09:06:48 +00:00
|
|
|
|
/* GDK - The GIMP Drawing Kit
|
|
|
|
|
*
|
|
|
|
|
* gdkglcontext-wayland.c: Wayland specific OpenGL wrappers
|
|
|
|
|
*
|
|
|
|
|
* Copyright © 2014 Emmanuele Bassi
|
|
|
|
|
* Copyright © 2014 Alexander Larsson
|
|
|
|
|
*
|
|
|
|
|
* 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-wayland.h"
|
2021-07-04 18:55:53 +00:00
|
|
|
|
|
2014-10-09 09:06:48 +00:00
|
|
|
|
#include "gdkdisplay-wayland.h"
|
2021-07-04 18:55:53 +00:00
|
|
|
|
#include "gdksurface-wayland.h"
|
2014-10-09 09:06:48 +00:00
|
|
|
|
|
|
|
|
|
#include "gdkwaylanddisplay.h"
|
|
|
|
|
#include "gdkwaylandglcontext.h"
|
2018-03-20 10:46:11 +00:00
|
|
|
|
#include "gdkwaylandsurface.h"
|
2014-10-09 09:06:48 +00:00
|
|
|
|
#include "gdkprivate-wayland.h"
|
|
|
|
|
|
|
|
|
|
#include "gdkinternals.h"
|
2019-04-22 01:14:46 +00:00
|
|
|
|
#include "gdksurfaceprivate.h"
|
2020-01-22 19:51:40 +00:00
|
|
|
|
#include "gdkprofilerprivate.h"
|
2014-10-09 09:06:48 +00:00
|
|
|
|
|
|
|
|
|
#include "gdkintl.h"
|
|
|
|
|
|
2021-02-21 15:40:24 +00:00
|
|
|
|
/**
|
|
|
|
|
* GdkWaylandGLContext:
|
|
|
|
|
*
|
|
|
|
|
* The Wayland implementation of `GdkGLContext`.
|
|
|
|
|
*/
|
|
|
|
|
|
2014-10-09 09:06:48 +00:00
|
|
|
|
G_DEFINE_TYPE (GdkWaylandGLContext, gdk_wayland_gl_context, GDK_TYPE_GL_CONTEXT)
|
|
|
|
|
|
2016-12-01 00:38:20 +00:00
|
|
|
|
static void gdk_wayland_gl_context_dispose (GObject *gobject);
|
2014-10-30 10:46:09 +00:00
|
|
|
|
|
2015-02-09 15:56:18 +00:00
|
|
|
|
#define N_EGL_ATTRS 16
|
|
|
|
|
|
GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.
We have a couple of requirements in terms of API:
• avoid, if at all possible, the "C arrays of integers with
attribute, value pairs", which are hard to write and hard
to bind in non-C languages.
• allow failing in a recoverable way.
• do not make the GL context creation API a mess of arguments.
Looking at prior art, it seems that a common pattern is to split the
construction phase in two:
• a first phase that creates a GL context wrapper object and
does preliminary checks on the environment.
• a second phase that creates the backend-specific GL object.
We adopted a similar pattern:
• gdk_window_create_gl_context() creates a GdkGLContext
• gdk_gl_context_realize() creates the underlying resources
Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.
https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-01-27 21:23:23 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
gdk_wayland_gl_context_realize (GdkGLContext *context,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
GdkWaylandGLContext *context_wayland = GDK_WAYLAND_GL_CONTEXT (context);
|
|
|
|
|
GdkDisplay *display = gdk_gl_context_get_display (context);
|
2021-07-04 23:57:03 +00:00
|
|
|
|
GdkGLContext *share = gdk_display_get_gl_context (display);
|
GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.
We have a couple of requirements in terms of API:
• avoid, if at all possible, the "C arrays of integers with
attribute, value pairs", which are hard to write and hard
to bind in non-C languages.
• allow failing in a recoverable way.
• do not make the GL context creation API a mess of arguments.
Looking at prior art, it seems that a common pattern is to split the
construction phase in two:
• a first phase that creates a GL context wrapper object and
does preliminary checks on the environment.
• a second phase that creates the backend-specific GL object.
We adopted a similar pattern:
• gdk_window_create_gl_context() creates a GdkGLContext
• gdk_gl_context_realize() creates the underlying resources
Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.
https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-01-27 21:23:23 +00:00
|
|
|
|
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
|
|
|
|
|
EGLContext ctx;
|
2015-02-09 15:56:18 +00:00
|
|
|
|
EGLint context_attribs[N_EGL_ATTRS];
|
|
|
|
|
int major, minor, flags;
|
2016-04-18 09:13:05 +00:00
|
|
|
|
gboolean debug_bit, forward_bit, legacy_bit, use_es;
|
2015-02-09 15:56:18 +00:00
|
|
|
|
int i = 0;
|
GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.
We have a couple of requirements in terms of API:
• avoid, if at all possible, the "C arrays of integers with
attribute, value pairs", which are hard to write and hard
to bind in non-C languages.
• allow failing in a recoverable way.
• do not make the GL context creation API a mess of arguments.
Looking at prior art, it seems that a common pattern is to split the
construction phase in two:
• a first phase that creates a GL context wrapper object and
does preliminary checks on the environment.
• a second phase that creates the backend-specific GL object.
We adopted a similar pattern:
• gdk_window_create_gl_context() creates a GdkGLContext
• gdk_gl_context_realize() creates the underlying resources
Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.
https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-01-27 21:23:23 +00:00
|
|
|
|
|
2015-02-09 15:56:18 +00:00
|
|
|
|
gdk_gl_context_get_required_version (context, &major, &minor);
|
|
|
|
|
debug_bit = gdk_gl_context_get_debug_enabled (context);
|
|
|
|
|
forward_bit = gdk_gl_context_get_forward_compatible (context);
|
2018-01-12 00:48:27 +00:00
|
|
|
|
legacy_bit = GDK_DISPLAY_DEBUG_CHECK (display, GL_LEGACY) ||
|
2015-10-07 14:26:53 +00:00
|
|
|
|
(share != NULL && gdk_gl_context_is_legacy (share));
|
2018-01-12 00:48:27 +00:00
|
|
|
|
use_es = GDK_DISPLAY_DEBUG_CHECK (display, GL_GLES) ||
|
2016-04-22 11:45:32 +00:00
|
|
|
|
(share != NULL && gdk_gl_context_get_use_es (share));
|
2015-02-09 15:56:18 +00:00
|
|
|
|
|
|
|
|
|
flags = 0;
|
|
|
|
|
|
|
|
|
|
if (debug_bit)
|
|
|
|
|
flags |= EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR;
|
|
|
|
|
if (forward_bit)
|
|
|
|
|
flags |= EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR;
|
|
|
|
|
|
2016-04-18 09:13:05 +00:00
|
|
|
|
if (!use_es)
|
|
|
|
|
{
|
2016-04-23 09:13:39 +00:00
|
|
|
|
eglBindAPI (EGL_OPENGL_API);
|
|
|
|
|
|
2016-04-18 09:13:05 +00:00
|
|
|
|
/* We want a core profile, unless in legacy mode */
|
|
|
|
|
context_attribs[i++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
|
|
|
|
|
context_attribs[i++] = legacy_bit
|
|
|
|
|
? EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR
|
|
|
|
|
: EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR;
|
|
|
|
|
|
|
|
|
|
/* Specify the version */
|
|
|
|
|
context_attribs[i++] = EGL_CONTEXT_MAJOR_VERSION_KHR;
|
|
|
|
|
context_attribs[i++] = legacy_bit ? 3 : major;
|
|
|
|
|
context_attribs[i++] = EGL_CONTEXT_MINOR_VERSION_KHR;
|
|
|
|
|
context_attribs[i++] = legacy_bit ? 0 : minor;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-04-23 09:13:39 +00:00
|
|
|
|
eglBindAPI (EGL_OPENGL_ES_API);
|
|
|
|
|
|
2016-04-18 09:13:05 +00:00
|
|
|
|
context_attribs[i++] = EGL_CONTEXT_CLIENT_VERSION;
|
|
|
|
|
if (major == 3)
|
|
|
|
|
context_attribs[i++] = 3;
|
|
|
|
|
else
|
|
|
|
|
context_attribs[i++] = 2;
|
|
|
|
|
}
|
2015-02-09 15:56:18 +00:00
|
|
|
|
|
|
|
|
|
/* Specify the flags */
|
|
|
|
|
context_attribs[i++] = EGL_CONTEXT_FLAGS_KHR;
|
|
|
|
|
context_attribs[i++] = flags;
|
|
|
|
|
|
GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.
We have a couple of requirements in terms of API:
• avoid, if at all possible, the "C arrays of integers with
attribute, value pairs", which are hard to write and hard
to bind in non-C languages.
• allow failing in a recoverable way.
• do not make the GL context creation API a mess of arguments.
Looking at prior art, it seems that a common pattern is to split the
construction phase in two:
• a first phase that creates a GL context wrapper object and
does preliminary checks on the environment.
• a second phase that creates the backend-specific GL object.
We adopted a similar pattern:
• gdk_window_create_gl_context() creates a GdkGLContext
• gdk_gl_context_realize() creates the underlying resources
Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.
https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-01-27 21:23:23 +00:00
|
|
|
|
context_attribs[i++] = EGL_NONE;
|
2015-02-09 15:56:18 +00:00
|
|
|
|
g_assert (i < N_EGL_ATTRS);
|
GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.
We have a couple of requirements in terms of API:
• avoid, if at all possible, the "C arrays of integers with
attribute, value pairs", which are hard to write and hard
to bind in non-C languages.
• allow failing in a recoverable way.
• do not make the GL context creation API a mess of arguments.
Looking at prior art, it seems that a common pattern is to split the
construction phase in two:
• a first phase that creates a GL context wrapper object and
does preliminary checks on the environment.
• a second phase that creates the backend-specific GL object.
We adopted a similar pattern:
• gdk_window_create_gl_context() creates a GdkGLContext
• gdk_gl_context_realize() creates the underlying resources
Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.
https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-01-27 21:23:23 +00:00
|
|
|
|
|
2018-01-12 00:48:27 +00:00
|
|
|
|
GDK_DISPLAY_NOTE (display, OPENGL,
|
|
|
|
|
g_message ("Creating EGL context version %d.%d (debug:%s, forward:%s, legacy:%s, es:%s)",
|
2016-04-22 17:50:50 +00:00
|
|
|
|
major, minor,
|
|
|
|
|
debug_bit ? "yes" : "no",
|
|
|
|
|
forward_bit ? "yes" : "no",
|
|
|
|
|
legacy_bit ? "yes" : "no",
|
|
|
|
|
use_es ? "yes" : "no"));
|
|
|
|
|
|
GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.
We have a couple of requirements in terms of API:
• avoid, if at all possible, the "C arrays of integers with
attribute, value pairs", which are hard to write and hard
to bind in non-C languages.
• allow failing in a recoverable way.
• do not make the GL context creation API a mess of arguments.
Looking at prior art, it seems that a common pattern is to split the
construction phase in two:
• a first phase that creates a GL context wrapper object and
does preliminary checks on the environment.
• a second phase that creates the backend-specific GL object.
We adopted a similar pattern:
• gdk_window_create_gl_context() creates a GdkGLContext
• gdk_gl_context_realize() creates the underlying resources
Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.
https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-01-27 21:23:23 +00:00
|
|
|
|
ctx = eglCreateContext (display_wayland->egl_display,
|
2021-07-04 17:48:11 +00:00
|
|
|
|
display_wayland->egl_config,
|
GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.
We have a couple of requirements in terms of API:
• avoid, if at all possible, the "C arrays of integers with
attribute, value pairs", which are hard to write and hard
to bind in non-C languages.
• allow failing in a recoverable way.
• do not make the GL context creation API a mess of arguments.
Looking at prior art, it seems that a common pattern is to split the
construction phase in two:
• a first phase that creates a GL context wrapper object and
does preliminary checks on the environment.
• a second phase that creates the backend-specific GL object.
We adopted a similar pattern:
• gdk_window_create_gl_context() creates a GdkGLContext
• gdk_gl_context_realize() creates the underlying resources
Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.
https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-01-27 21:23:23 +00:00
|
|
|
|
share != NULL ? GDK_WAYLAND_GL_CONTEXT (share)->egl_context
|
2021-07-04 23:57:03 +00:00
|
|
|
|
: EGL_NO_CONTEXT,
|
GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.
We have a couple of requirements in terms of API:
• avoid, if at all possible, the "C arrays of integers with
attribute, value pairs", which are hard to write and hard
to bind in non-C languages.
• allow failing in a recoverable way.
• do not make the GL context creation API a mess of arguments.
Looking at prior art, it seems that a common pattern is to split the
construction phase in two:
• a first phase that creates a GL context wrapper object and
does preliminary checks on the environment.
• a second phase that creates the backend-specific GL object.
We adopted a similar pattern:
• gdk_window_create_gl_context() creates a GdkGLContext
• gdk_gl_context_realize() creates the underlying resources
Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.
https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-01-27 21:23:23 +00:00
|
|
|
|
context_attribs);
|
2015-10-07 14:26:53 +00:00
|
|
|
|
|
2021-03-21 20:02:08 +00:00
|
|
|
|
/* If context creation failed without the ES bit, let's try again with it */
|
|
|
|
|
if (ctx == NULL)
|
|
|
|
|
{
|
|
|
|
|
i = 0;
|
|
|
|
|
context_attribs[i++] = EGL_CONTEXT_MAJOR_VERSION;
|
|
|
|
|
context_attribs[i++] = 2;
|
|
|
|
|
context_attribs[i++] = EGL_CONTEXT_MINOR_VERSION;
|
|
|
|
|
context_attribs[i++] = 0;
|
|
|
|
|
context_attribs[i++] = EGL_CONTEXT_FLAGS_KHR;
|
|
|
|
|
context_attribs[i++] = flags & ~EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR;
|
|
|
|
|
context_attribs[i++] = EGL_NONE;
|
|
|
|
|
g_assert (i < N_EGL_ATTRS);
|
|
|
|
|
|
|
|
|
|
eglBindAPI (EGL_OPENGL_ES_API);
|
|
|
|
|
|
|
|
|
|
legacy_bit = FALSE;
|
|
|
|
|
use_es = TRUE;
|
|
|
|
|
|
|
|
|
|
GDK_DISPLAY_NOTE (display, OPENGL,
|
|
|
|
|
g_message ("eglCreateContext failed, switching to OpenGL ES"));
|
|
|
|
|
ctx = eglCreateContext (display_wayland->egl_display,
|
2021-07-04 17:48:11 +00:00
|
|
|
|
display_wayland->egl_config,
|
2021-03-21 20:02:08 +00:00
|
|
|
|
share != NULL ? GDK_WAYLAND_GL_CONTEXT (share)->egl_context
|
2021-07-04 23:57:03 +00:00
|
|
|
|
: EGL_NO_CONTEXT,
|
2021-03-21 20:02:08 +00:00
|
|
|
|
context_attribs);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-07 14:26:53 +00:00
|
|
|
|
/* If context creation failed without the legacy bit, let's try again with it */
|
2021-03-21 20:02:08 +00:00
|
|
|
|
if (ctx == NULL)
|
2015-10-07 14:26:53 +00:00
|
|
|
|
{
|
2021-03-21 20:02:08 +00:00
|
|
|
|
i = 0;
|
|
|
|
|
context_attribs[i++] = EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR;
|
|
|
|
|
context_attribs[i++] = EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR;
|
|
|
|
|
context_attribs[i++] = EGL_CONTEXT_MAJOR_VERSION;
|
|
|
|
|
context_attribs[i++] = 3;
|
|
|
|
|
context_attribs[i++] = EGL_CONTEXT_MINOR_VERSION;
|
|
|
|
|
context_attribs[i++] = 0;
|
|
|
|
|
context_attribs[i++] = EGL_CONTEXT_FLAGS_KHR;
|
|
|
|
|
context_attribs[i++] = flags & ~EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR;
|
|
|
|
|
context_attribs[i++] = EGL_NONE;
|
|
|
|
|
g_assert (i < N_EGL_ATTRS);
|
2015-10-07 14:26:53 +00:00
|
|
|
|
|
2016-04-23 09:13:39 +00:00
|
|
|
|
eglBindAPI (EGL_OPENGL_API);
|
|
|
|
|
|
2015-10-07 14:26:53 +00:00
|
|
|
|
legacy_bit = TRUE;
|
2016-04-22 17:50:50 +00:00
|
|
|
|
use_es = FALSE;
|
2015-10-07 14:26:53 +00:00
|
|
|
|
|
2018-01-12 00:48:27 +00:00
|
|
|
|
GDK_DISPLAY_NOTE (display, OPENGL,
|
|
|
|
|
g_message ("eglCreateContext failed, switching to legacy"));
|
2015-10-07 14:26:53 +00:00
|
|
|
|
ctx = eglCreateContext (display_wayland->egl_display,
|
2021-07-04 17:48:11 +00:00
|
|
|
|
display_wayland->egl_config,
|
2015-10-07 14:26:53 +00:00
|
|
|
|
share != NULL ? GDK_WAYLAND_GL_CONTEXT (share)->egl_context
|
2021-07-04 23:57:03 +00:00
|
|
|
|
: EGL_NO_CONTEXT,
|
2015-10-07 14:26:53 +00:00
|
|
|
|
context_attribs);
|
|
|
|
|
}
|
|
|
|
|
|
GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.
We have a couple of requirements in terms of API:
• avoid, if at all possible, the "C arrays of integers with
attribute, value pairs", which are hard to write and hard
to bind in non-C languages.
• allow failing in a recoverable way.
• do not make the GL context creation API a mess of arguments.
Looking at prior art, it seems that a common pattern is to split the
construction phase in two:
• a first phase that creates a GL context wrapper object and
does preliminary checks on the environment.
• a second phase that creates the backend-specific GL object.
We adopted a similar pattern:
• gdk_window_create_gl_context() creates a GdkGLContext
• gdk_gl_context_realize() creates the underlying resources
Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.
https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-01-27 21:23:23 +00:00
|
|
|
|
if (ctx == NULL)
|
|
|
|
|
{
|
|
|
|
|
g_set_error_literal (error, GDK_GL_ERROR,
|
|
|
|
|
GDK_GL_ERROR_NOT_AVAILABLE,
|
|
|
|
|
_("Unable to create a GL context"));
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-12 00:48:27 +00:00
|
|
|
|
GDK_DISPLAY_NOTE (display, OPENGL, g_message ("Created EGL context[%p]", ctx));
|
GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.
We have a couple of requirements in terms of API:
• avoid, if at all possible, the "C arrays of integers with
attribute, value pairs", which are hard to write and hard
to bind in non-C languages.
• allow failing in a recoverable way.
• do not make the GL context creation API a mess of arguments.
Looking at prior art, it seems that a common pattern is to split the
construction phase in two:
• a first phase that creates a GL context wrapper object and
does preliminary checks on the environment.
• a second phase that creates the backend-specific GL object.
We adopted a similar pattern:
• gdk_window_create_gl_context() creates a GdkGLContext
• gdk_gl_context_realize() creates the underlying resources
Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.
https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-01-27 21:23:23 +00:00
|
|
|
|
|
|
|
|
|
context_wayland->egl_context = ctx;
|
|
|
|
|
|
2015-10-07 14:26:53 +00:00
|
|
|
|
gdk_gl_context_set_is_legacy (context, legacy_bit);
|
2016-04-22 11:45:32 +00:00
|
|
|
|
gdk_gl_context_set_use_es (context, use_es);
|
2015-10-07 14:26:53 +00:00
|
|
|
|
|
GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.
We have a couple of requirements in terms of API:
• avoid, if at all possible, the "C arrays of integers with
attribute, value pairs", which are hard to write and hard
to bind in non-C languages.
• allow failing in a recoverable way.
• do not make the GL context creation API a mess of arguments.
Looking at prior art, it seems that a common pattern is to split the
construction phase in two:
• a first phase that creates a GL context wrapper object and
does preliminary checks on the environment.
• a second phase that creates the backend-specific GL object.
We adopted a similar pattern:
• gdk_window_create_gl_context() creates a GdkGLContext
• gdk_gl_context_realize() creates the underlying resources
Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.
https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-01-27 21:23:23 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-04 15:33:13 +00:00
|
|
|
|
static cairo_region_t *
|
|
|
|
|
gdk_wayland_gl_context_get_damage (GdkGLContext *context)
|
|
|
|
|
{
|
|
|
|
|
GdkDisplay *display = gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context));
|
|
|
|
|
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
|
|
|
|
|
EGLSurface egl_surface;
|
2018-03-20 14:14:10 +00:00
|
|
|
|
GdkSurface *surface = gdk_draw_context_get_surface (GDK_DRAW_CONTEXT (context));
|
2016-12-04 15:33:13 +00:00
|
|
|
|
int buffer_age = 0;
|
|
|
|
|
|
|
|
|
|
if (display_wayland->have_egl_buffer_age)
|
|
|
|
|
{
|
2021-07-04 18:55:53 +00:00
|
|
|
|
egl_surface = gdk_wayland_surface_get_egl_surface (surface);
|
2021-07-06 02:50:01 +00:00
|
|
|
|
gdk_gl_context_make_current (context);
|
2016-12-04 15:33:13 +00:00
|
|
|
|
eglQuerySurface (display_wayland->egl_display, egl_surface,
|
|
|
|
|
EGL_BUFFER_AGE_EXT, &buffer_age);
|
|
|
|
|
|
2018-11-30 12:14:00 +00:00
|
|
|
|
switch (buffer_age)
|
2016-12-04 15:33:13 +00:00
|
|
|
|
{
|
2018-11-30 12:14:00 +00:00
|
|
|
|
case 1:
|
|
|
|
|
return cairo_region_create ();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
|
if (context->old_updated_area[0])
|
|
|
|
|
return cairo_region_copy (context->old_updated_area[0]);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
|
if (context->old_updated_area[0] &&
|
|
|
|
|
context->old_updated_area[1])
|
|
|
|
|
{
|
|
|
|
|
cairo_region_t *damage = cairo_region_copy (context->old_updated_area[0]);
|
|
|
|
|
cairo_region_union (damage, context->old_updated_area[1]);
|
|
|
|
|
return damage;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
;
|
2016-12-04 15:33:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return GDK_GL_CONTEXT_CLASS (gdk_wayland_gl_context_parent_class)->get_damage (context);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-07 02:40:34 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
gdk_wayland_gl_context_clear_current (GdkGLContext *context)
|
|
|
|
|
{
|
|
|
|
|
GdkDisplay *display = gdk_gl_context_get_display (context);
|
|
|
|
|
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
|
|
|
|
|
|
|
|
|
|
return eglMakeCurrent (display_wayland->egl_display,
|
|
|
|
|
EGL_NO_SURFACE,
|
|
|
|
|
EGL_NO_SURFACE,
|
|
|
|
|
EGL_NO_CONTEXT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gdk_wayland_gl_context_make_current (GdkGLContext *context,
|
|
|
|
|
gboolean surfaceless)
|
|
|
|
|
{
|
|
|
|
|
GdkWaylandGLContext *context_wayland = GDK_WAYLAND_GL_CONTEXT (context);
|
|
|
|
|
GdkDisplay *display = gdk_gl_context_get_display (context);
|
|
|
|
|
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
|
|
|
|
|
EGLSurface egl_surface;
|
|
|
|
|
|
|
|
|
|
if (!surfaceless)
|
|
|
|
|
egl_surface = gdk_wayland_surface_get_egl_surface (gdk_gl_context_get_surface (context));
|
|
|
|
|
else
|
|
|
|
|
egl_surface = EGL_NO_SURFACE;
|
|
|
|
|
|
|
|
|
|
return eglMakeCurrent (display_wayland->egl_display,
|
|
|
|
|
egl_surface,
|
|
|
|
|
egl_surface,
|
|
|
|
|
context_wayland->egl_context);
|
|
|
|
|
}
|
2014-10-09 09:06:48 +00:00
|
|
|
|
static void
|
2016-12-01 00:38:20 +00:00
|
|
|
|
gdk_wayland_gl_context_end_frame (GdkDrawContext *draw_context,
|
2018-04-23 21:26:14 +00:00
|
|
|
|
cairo_region_t *painted)
|
2014-10-09 09:06:48 +00:00
|
|
|
|
{
|
2016-12-01 00:38:20 +00:00
|
|
|
|
GdkGLContext *context = GDK_GL_CONTEXT (draw_context);
|
2018-03-20 14:14:10 +00:00
|
|
|
|
GdkSurface *surface = gdk_gl_context_get_surface (context);
|
|
|
|
|
GdkDisplay *display = gdk_surface_get_display (surface);
|
2014-10-09 09:06:48 +00:00
|
|
|
|
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
|
|
|
|
|
EGLSurface egl_surface;
|
|
|
|
|
|
2018-04-23 21:26:14 +00:00
|
|
|
|
GDK_DRAW_CONTEXT_CLASS (gdk_wayland_gl_context_parent_class)->end_frame (draw_context, painted);
|
2016-12-01 00:38:20 +00:00
|
|
|
|
|
|
|
|
|
gdk_gl_context_make_current (context);
|
2014-10-09 09:06:48 +00:00
|
|
|
|
|
2021-07-04 18:55:53 +00:00
|
|
|
|
egl_surface = gdk_wayland_surface_get_egl_surface (surface);
|
2018-03-21 06:01:58 +00:00
|
|
|
|
gdk_wayland_surface_sync (surface);
|
2018-04-10 13:10:56 +00:00
|
|
|
|
gdk_wayland_surface_request_frame (surface);
|
2018-03-21 06:01:58 +00:00
|
|
|
|
|
2020-08-19 22:49:34 +00:00
|
|
|
|
gdk_profiler_add_mark (GDK_PROFILER_CURRENT_TIME, 0, "wayland", "swap buffers");
|
2018-04-23 21:26:14 +00:00
|
|
|
|
if (display_wayland->have_egl_swap_buffers_with_damage)
|
2014-10-09 09:06:48 +00:00
|
|
|
|
{
|
2020-12-24 08:27:31 +00:00
|
|
|
|
EGLint stack_rects[4 * 4]; /* 4 rects */
|
|
|
|
|
EGLint *heap_rects = NULL;
|
2018-04-23 21:26:14 +00:00
|
|
|
|
int i, j, n_rects = cairo_region_num_rectangles (painted);
|
2018-03-20 14:14:10 +00:00
|
|
|
|
int surface_height = gdk_surface_get_height (surface);
|
2019-12-03 15:32:59 +00:00
|
|
|
|
int scale = gdk_surface_get_scale_factor (surface);
|
2020-12-24 08:27:31 +00:00
|
|
|
|
EGLint *rects;
|
|
|
|
|
|
|
|
|
|
if (n_rects < G_N_ELEMENTS (stack_rects) / 4)
|
|
|
|
|
rects = (EGLint *)&stack_rects;
|
|
|
|
|
else
|
|
|
|
|
heap_rects = rects = g_new (EGLint, n_rects * 4);
|
2014-10-09 09:06:48 +00:00
|
|
|
|
|
|
|
|
|
for (i = 0, j = 0; i < n_rects; i++)
|
|
|
|
|
{
|
2020-12-24 08:27:31 +00:00
|
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
|
|
2018-04-23 21:26:14 +00:00
|
|
|
|
cairo_region_get_rectangle (painted, i, &rect);
|
2019-12-03 15:32:59 +00:00
|
|
|
|
rects[j++] = rect.x * scale;
|
|
|
|
|
rects[j++] = (surface_height - rect.height - rect.y) * scale;
|
|
|
|
|
rects[j++] = rect.width * scale;
|
|
|
|
|
rects[j++] = rect.height * scale;
|
2014-10-09 09:06:48 +00:00
|
|
|
|
}
|
|
|
|
|
eglSwapBuffersWithDamageEXT (display_wayland->egl_display, egl_surface, rects, n_rects);
|
2020-12-24 08:27:31 +00:00
|
|
|
|
g_free (heap_rects);
|
2014-10-09 09:06:48 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
eglSwapBuffers (display_wayland->egl_display, egl_surface);
|
2020-09-17 16:20:08 +00:00
|
|
|
|
|
|
|
|
|
gdk_wayland_surface_notify_committed (surface);
|
2014-10-09 09:06:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gdk_wayland_gl_context_class_init (GdkWaylandGLContextClass *klass)
|
|
|
|
|
{
|
2014-10-30 10:46:09 +00:00
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
2016-12-01 00:38:20 +00:00
|
|
|
|
GdkDrawContextClass *draw_context_class = GDK_DRAW_CONTEXT_CLASS (klass);
|
GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.
We have a couple of requirements in terms of API:
• avoid, if at all possible, the "C arrays of integers with
attribute, value pairs", which are hard to write and hard
to bind in non-C languages.
• allow failing in a recoverable way.
• do not make the GL context creation API a mess of arguments.
Looking at prior art, it seems that a common pattern is to split the
construction phase in two:
• a first phase that creates a GL context wrapper object and
does preliminary checks on the environment.
• a second phase that creates the backend-specific GL object.
We adopted a similar pattern:
• gdk_window_create_gl_context() creates a GdkGLContext
• gdk_gl_context_realize() creates the underlying resources
Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.
https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-01-27 21:23:23 +00:00
|
|
|
|
GdkGLContextClass *context_class = GDK_GL_CONTEXT_CLASS (klass);
|
2014-10-09 09:06:48 +00:00
|
|
|
|
|
2016-12-01 00:38:20 +00:00
|
|
|
|
gobject_class->dispose = gdk_wayland_gl_context_dispose;
|
|
|
|
|
|
|
|
|
|
draw_context_class->end_frame = gdk_wayland_gl_context_end_frame;
|
GL: Split GL context creation in two phases
One of the major requests by OpenGL users has been the ability to
specify settings when creating a GL context, like the version to use
or whether the debug support should be enabled.
We have a couple of requirements in terms of API:
• avoid, if at all possible, the "C arrays of integers with
attribute, value pairs", which are hard to write and hard
to bind in non-C languages.
• allow failing in a recoverable way.
• do not make the GL context creation API a mess of arguments.
Looking at prior art, it seems that a common pattern is to split the
construction phase in two:
• a first phase that creates a GL context wrapper object and
does preliminary checks on the environment.
• a second phase that creates the backend-specific GL object.
We adopted a similar pattern:
• gdk_window_create_gl_context() creates a GdkGLContext
• gdk_gl_context_realize() creates the underlying resources
Calling gdk_gl_context_make_current() also realizes the context, so
simple GL users do not need to care. Advanced users will want to
call gdk_window_create_gl_context(), set up the optional requirements,
and then call gdk_gl_context_realize(). If either of these two steps
fails, it's possible to recover by changing the requirements, or simply
creating a new GdkGLContext instance.
https://bugzilla.gnome.org/show_bug.cgi?id=741946
2015-01-27 21:23:23 +00:00
|
|
|
|
|
|
|
|
|
context_class->realize = gdk_wayland_gl_context_realize;
|
2021-07-07 02:40:34 +00:00
|
|
|
|
context_class->make_current = gdk_wayland_gl_context_make_current;
|
|
|
|
|
context_class->clear_current = gdk_wayland_gl_context_clear_current;
|
2016-12-04 15:33:13 +00:00
|
|
|
|
context_class->get_damage = gdk_wayland_gl_context_get_damage;
|
2014-10-09 09:06:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gdk_wayland_gl_context_init (GdkWaylandGLContext *self)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-11 11:26:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* gdk_wayland_display_get_egl_display:
|
|
|
|
|
* @display: (type GdkWaylandDisplay): a Wayland display
|
|
|
|
|
*
|
|
|
|
|
* Retrieves the EGL display connection object for the given GDK display.
|
|
|
|
|
*
|
|
|
|
|
* Returns: (nullable): the EGL display
|
2021-07-07 16:18:28 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 4.4
|
2021-05-11 11:26:55 +00:00
|
|
|
|
*/
|
|
|
|
|
gpointer
|
|
|
|
|
gdk_wayland_display_get_egl_display (GdkDisplay *display)
|
|
|
|
|
{
|
|
|
|
|
GdkWaylandDisplay *display_wayland;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_WAYLAND_DISPLAY (display), NULL);
|
|
|
|
|
|
2021-07-04 23:57:03 +00:00
|
|
|
|
if (!gdk_display_prepare_gl (display, NULL))
|
2021-05-11 11:26:55 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
display_wayland = GDK_WAYLAND_DISPLAY (display);
|
|
|
|
|
|
|
|
|
|
return display_wayland->egl_display;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-10 18:12:40 +00:00
|
|
|
|
static EGLDisplay
|
2021-05-11 11:26:55 +00:00
|
|
|
|
get_egl_display (GdkWaylandDisplay *display_wayland)
|
2016-10-10 18:12:40 +00:00
|
|
|
|
{
|
|
|
|
|
EGLDisplay dpy = NULL;
|
|
|
|
|
|
|
|
|
|
if (epoxy_has_egl_extension (NULL, "EGL_KHR_platform_base"))
|
|
|
|
|
{
|
|
|
|
|
PFNEGLGETPLATFORMDISPLAYPROC getPlatformDisplay =
|
2020-12-25 09:17:25 +00:00
|
|
|
|
(void *) eglGetProcAddress ("eglGetPlatformDisplay");
|
2016-10-10 18:12:40 +00:00
|
|
|
|
|
2021-05-11 11:26:55 +00:00
|
|
|
|
if (getPlatformDisplay != NULL)
|
2020-12-25 09:17:25 +00:00
|
|
|
|
dpy = getPlatformDisplay (EGL_PLATFORM_WAYLAND_EXT,
|
|
|
|
|
display_wayland->wl_display,
|
|
|
|
|
NULL);
|
2021-05-11 11:26:55 +00:00
|
|
|
|
if (dpy != NULL)
|
|
|
|
|
goto out;
|
2016-10-10 18:12:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (epoxy_has_egl_extension (NULL, "EGL_EXT_platform_base"))
|
|
|
|
|
{
|
|
|
|
|
PFNEGLGETPLATFORMDISPLAYEXTPROC getPlatformDisplay =
|
2020-12-25 09:17:25 +00:00
|
|
|
|
(void *) eglGetProcAddress ("eglGetPlatformDisplayEXT");
|
2016-10-10 18:12:40 +00:00
|
|
|
|
|
2021-05-11 11:26:55 +00:00
|
|
|
|
if (getPlatformDisplay != NULL)
|
2020-12-25 09:17:25 +00:00
|
|
|
|
dpy = getPlatformDisplay (EGL_PLATFORM_WAYLAND_EXT,
|
|
|
|
|
display_wayland->wl_display,
|
|
|
|
|
NULL);
|
2021-05-11 11:26:55 +00:00
|
|
|
|
if (dpy != NULL)
|
|
|
|
|
goto out;
|
2016-10-10 18:12:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-11 11:26:55 +00:00
|
|
|
|
dpy = eglGetDisplay ((EGLNativeDisplayType) display_wayland->wl_display);
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
return dpy;
|
2016-10-10 18:12:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-04 17:48:11 +00:00
|
|
|
|
#define MAX_EGL_ATTRS 30
|
|
|
|
|
|
|
|
|
|
static EGLConfig
|
|
|
|
|
get_eglconfig (EGLDisplay dpy)
|
|
|
|
|
{
|
|
|
|
|
EGLint attrs[MAX_EGL_ATTRS];
|
|
|
|
|
EGLint count;
|
|
|
|
|
EGLConfig config;
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
|
attrs[i++] = EGL_SURFACE_TYPE;
|
|
|
|
|
attrs[i++] = EGL_WINDOW_BIT;
|
|
|
|
|
|
|
|
|
|
attrs[i++] = EGL_COLOR_BUFFER_TYPE;
|
|
|
|
|
attrs[i++] = EGL_RGB_BUFFER;
|
|
|
|
|
|
|
|
|
|
attrs[i++] = EGL_RED_SIZE;
|
|
|
|
|
attrs[i++] = 8;
|
|
|
|
|
attrs[i++] = EGL_GREEN_SIZE;
|
|
|
|
|
attrs[i++] = 8;
|
|
|
|
|
attrs[i++] = EGL_BLUE_SIZE;
|
|
|
|
|
attrs[i++] = 8;
|
|
|
|
|
attrs[i++] = EGL_ALPHA_SIZE;
|
|
|
|
|
attrs[i++] = 8;
|
|
|
|
|
|
|
|
|
|
attrs[i++] = EGL_NONE;
|
|
|
|
|
g_assert (i < MAX_EGL_ATTRS);
|
|
|
|
|
|
|
|
|
|
/* Pick first valid configuration i guess? */
|
|
|
|
|
if (!eglChooseConfig (dpy, attrs, &config, 1, &count) || count < 1)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
return config;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#undef MAX_EGL_ATTRS
|
|
|
|
|
|
2021-07-04 23:57:03 +00:00
|
|
|
|
GdkGLContext *
|
2021-07-04 17:48:11 +00:00
|
|
|
|
gdk_wayland_display_init_gl (GdkDisplay *display,
|
|
|
|
|
GError **error)
|
2014-10-09 09:06:48 +00:00
|
|
|
|
{
|
|
|
|
|
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
|
|
|
|
|
EGLint major, minor;
|
2016-10-10 18:10:38 +00:00
|
|
|
|
EGLDisplay dpy;
|
2014-10-09 09:06:48 +00:00
|
|
|
|
|
2021-05-11 11:26:55 +00:00
|
|
|
|
dpy = get_egl_display (display_wayland);
|
2014-10-09 09:06:48 +00:00
|
|
|
|
if (dpy == NULL)
|
2021-07-04 17:48:11 +00:00
|
|
|
|
{
|
|
|
|
|
g_set_error_literal (error, GDK_GL_ERROR,
|
|
|
|
|
GDK_GL_ERROR_NOT_AVAILABLE,
|
|
|
|
|
_("Failed to create EGL display"));
|
2021-07-04 23:57:03 +00:00
|
|
|
|
return NULL;
|
2021-07-04 17:48:11 +00:00
|
|
|
|
}
|
2014-10-09 09:06:48 +00:00
|
|
|
|
|
|
|
|
|
if (!eglInitialize (dpy, &major, &minor))
|
2021-07-04 17:48:11 +00:00
|
|
|
|
{
|
|
|
|
|
g_set_error_literal (error, GDK_GL_ERROR,
|
|
|
|
|
GDK_GL_ERROR_NOT_AVAILABLE,
|
|
|
|
|
_("Could not initialize EGL display"));
|
2021-07-04 23:57:03 +00:00
|
|
|
|
return NULL;
|
2021-07-04 17:48:11 +00:00
|
|
|
|
}
|
2021-07-05 01:04:08 +00:00
|
|
|
|
if (major < GDK_EGL_MIN_VERSION_MAJOR ||
|
|
|
|
|
(major == GDK_EGL_MIN_VERSION_MAJOR && minor < GDK_EGL_MIN_VERSION_MINOR))
|
|
|
|
|
{
|
|
|
|
|
eglTerminate (dpy);
|
|
|
|
|
g_set_error (error, GDK_GL_ERROR,
|
|
|
|
|
GDK_GL_ERROR_NOT_AVAILABLE,
|
|
|
|
|
_("EGL version %d.%d is too old. GTK requires %d.%d"),
|
|
|
|
|
major, minor, GDK_EGL_MIN_VERSION_MAJOR, GDK_EGL_MIN_VERSION_MINOR);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2014-10-09 09:06:48 +00:00
|
|
|
|
|
|
|
|
|
if (!eglBindAPI (EGL_OPENGL_API))
|
2021-07-04 17:48:11 +00:00
|
|
|
|
{
|
|
|
|
|
eglTerminate (dpy);
|
|
|
|
|
g_set_error_literal (error, GDK_GL_ERROR,
|
|
|
|
|
GDK_GL_ERROR_NOT_AVAILABLE,
|
|
|
|
|
_("No GL implementation is available"));
|
2021-07-04 23:57:03 +00:00
|
|
|
|
return NULL;
|
2021-07-04 17:48:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!epoxy_has_egl_extension (dpy, "EGL_KHR_create_context"))
|
|
|
|
|
{
|
|
|
|
|
eglTerminate (dpy);
|
|
|
|
|
g_set_error_literal (error, GDK_GL_ERROR,
|
|
|
|
|
GDK_GL_ERROR_UNSUPPORTED_PROFILE,
|
|
|
|
|
_("Core GL is not available on EGL implementation"));
|
2021-07-04 23:57:03 +00:00
|
|
|
|
return NULL;
|
2021-07-04 17:48:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-07 01:00:09 +00:00
|
|
|
|
if (!epoxy_has_egl_extension (dpy, "EGL_KHR_surfaceless_context"))
|
|
|
|
|
{
|
|
|
|
|
eglTerminate (dpy);
|
|
|
|
|
g_set_error_literal (error, GDK_GL_ERROR,
|
|
|
|
|
GDK_GL_ERROR_UNSUPPORTED_PROFILE,
|
|
|
|
|
_("Surfaceless contexts are not supported on this EGL implementation"));
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-04 17:48:11 +00:00
|
|
|
|
display_wayland->egl_config = get_eglconfig (dpy);
|
|
|
|
|
if (!display_wayland->egl_config)
|
|
|
|
|
{
|
|
|
|
|
eglTerminate (dpy);
|
|
|
|
|
g_set_error_literal (error, GDK_GL_ERROR,
|
|
|
|
|
GDK_GL_ERROR_UNSUPPORTED_FORMAT,
|
|
|
|
|
_("No available configurations for the given pixel format"));
|
2021-07-04 23:57:03 +00:00
|
|
|
|
return NULL;
|
2021-07-04 17:48:11 +00:00
|
|
|
|
}
|
2014-10-09 09:06:48 +00:00
|
|
|
|
|
|
|
|
|
display_wayland->egl_display = dpy;
|
|
|
|
|
display_wayland->egl_major_version = major;
|
|
|
|
|
display_wayland->egl_minor_version = minor;
|
|
|
|
|
|
|
|
|
|
display_wayland->have_egl_buffer_age =
|
|
|
|
|
epoxy_has_egl_extension (dpy, "EGL_EXT_buffer_age");
|
|
|
|
|
|
|
|
|
|
display_wayland->have_egl_swap_buffers_with_damage =
|
|
|
|
|
epoxy_has_egl_extension (dpy, "EGL_EXT_swap_buffers_with_damage");
|
|
|
|
|
|
2018-01-12 00:48:27 +00:00
|
|
|
|
GDK_DISPLAY_NOTE (display, OPENGL,
|
2016-02-29 02:28:01 +00:00
|
|
|
|
g_message ("EGL API version %d.%d found\n"
|
|
|
|
|
" - Vendor: %s\n"
|
|
|
|
|
" - Version: %s\n"
|
|
|
|
|
" - Client APIs: %s\n"
|
|
|
|
|
" - Extensions:\n"
|
|
|
|
|
"\t%s",
|
|
|
|
|
display_wayland->egl_major_version,
|
|
|
|
|
display_wayland->egl_minor_version,
|
|
|
|
|
eglQueryString (dpy, EGL_VENDOR),
|
|
|
|
|
eglQueryString (dpy, EGL_VERSION),
|
|
|
|
|
eglQueryString (dpy, EGL_CLIENT_APIS),
|
|
|
|
|
eglQueryString (dpy, EGL_EXTENSIONS)));
|
2014-10-09 09:06:48 +00:00
|
|
|
|
|
2021-07-04 23:57:03 +00:00
|
|
|
|
return g_object_new (GDK_TYPE_WAYLAND_GL_CONTEXT,
|
|
|
|
|
"display", display,
|
|
|
|
|
NULL);
|
2014-10-09 09:06:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-30 10:46:09 +00:00
|
|
|
|
static void
|
2016-12-01 00:38:20 +00:00
|
|
|
|
gdk_wayland_gl_context_dispose (GObject *gobject)
|
2014-10-09 09:06:48 +00:00
|
|
|
|
{
|
2014-10-30 10:46:09 +00:00
|
|
|
|
GdkWaylandGLContext *context_wayland = GDK_WAYLAND_GL_CONTEXT (gobject);
|
2014-10-09 09:06:48 +00:00
|
|
|
|
|
|
|
|
|
if (context_wayland->egl_context != NULL)
|
|
|
|
|
{
|
2014-10-30 10:46:09 +00:00
|
|
|
|
GdkGLContext *context = GDK_GL_CONTEXT (gobject);
|
2018-03-20 14:14:10 +00:00
|
|
|
|
GdkSurface *surface = gdk_gl_context_get_surface (context);
|
|
|
|
|
GdkDisplay *display = gdk_surface_get_display (surface);
|
2014-10-30 10:46:09 +00:00
|
|
|
|
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
|
|
|
|
|
|
2014-10-09 09:06:48 +00:00
|
|
|
|
if (eglGetCurrentContext () == context_wayland->egl_context)
|
|
|
|
|
eglMakeCurrent(display_wayland->egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
|
|
|
|
|
EGL_NO_CONTEXT);
|
|
|
|
|
|
2018-01-12 00:48:27 +00:00
|
|
|
|
GDK_DISPLAY_NOTE (display, OPENGL, g_message ("Destroying EGL context"));
|
2014-10-09 09:06:48 +00:00
|
|
|
|
|
|
|
|
|
eglDestroyContext (display_wayland->egl_display,
|
|
|
|
|
context_wayland->egl_context);
|
|
|
|
|
context_wayland->egl_context = NULL;
|
|
|
|
|
}
|
2014-10-30 10:46:09 +00:00
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gdk_wayland_gl_context_parent_class)->dispose (gobject);
|
2014-10-09 09:06:48 +00:00
|
|
|
|
}
|
|
|
|
|
|