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"
|
|
|
|
|
|
2021-08-24 19:27:49 +00:00
|
|
|
|
#include "gdk-private.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);
|
2021-10-03 04:22:21 +00:00
|
|
|
|
EGLDisplay egl_display = gdk_display_get_egl_display (display);
|
|
|
|
|
EGLConfig egl_config = gdk_display_get_egl_config (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
|
|
|
|
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;
|
2021-07-22 15:36:29 +00:00
|
|
|
|
G_GNUC_UNUSED gint64 start_time = GDK_PROFILER_CURRENT_TIME;
|
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"));
|
|
|
|
|
|
2021-10-03 04:22:21 +00:00
|
|
|
|
ctx = eglCreateContext (egl_display,
|
|
|
|
|
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"));
|
2021-10-03 04:22:21 +00:00
|
|
|
|
ctx = eglCreateContext (egl_display,
|
|
|
|
|
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"));
|
2021-10-03 04:22:21 +00:00
|
|
|
|
ctx = eglCreateContext (egl_display,
|
|
|
|
|
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
|
|
|
|
|
2021-07-22 15:36:29 +00:00
|
|
|
|
gdk_profiler_end_mark (start_time, "realize GdkWaylandGLContext", NULL);
|
|
|
|
|
|
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));
|
|
|
|
|
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;
|
|
|
|
|
|
2021-10-05 22:48:33 +00:00
|
|
|
|
if (display->have_egl_buffer_age)
|
2016-12-04 15:33:13 +00:00
|
|
|
|
{
|
2021-10-03 19:58:57 +00:00
|
|
|
|
egl_surface = gdk_surface_get_egl_surface (surface);
|
2021-07-06 02:50:01 +00:00
|
|
|
|
gdk_gl_context_make_current (context);
|
2021-10-03 04:22:21 +00:00
|
|
|
|
eglQuerySurface (gdk_display_get_egl_display (display), egl_surface,
|
2016-12-04 15:33:13 +00:00
|
|
|
|
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);
|
|
|
|
|
|
2021-10-03 04:22:21 +00:00
|
|
|
|
return eglMakeCurrent (gdk_display_get_egl_display (display),
|
2021-07-07 02:40:34 +00:00
|
|
|
|
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);
|
|
|
|
|
EGLSurface egl_surface;
|
|
|
|
|
|
|
|
|
|
if (!surfaceless)
|
2021-10-03 19:58:57 +00:00
|
|
|
|
egl_surface = gdk_surface_get_egl_surface (gdk_gl_context_get_surface (context));
|
2021-07-07 02:40:34 +00:00
|
|
|
|
else
|
|
|
|
|
egl_surface = EGL_NO_SURFACE;
|
|
|
|
|
|
2021-10-03 04:22:21 +00:00
|
|
|
|
return eglMakeCurrent (gdk_display_get_egl_display (display),
|
2021-07-07 02:40:34 +00:00
|
|
|
|
egl_surface,
|
|
|
|
|
egl_surface,
|
|
|
|
|
context_wayland->egl_context);
|
|
|
|
|
}
|
2021-07-10 00:29:17 +00:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gdk_wayland_gl_context_begin_frame (GdkDrawContext *draw_context,
|
|
|
|
|
cairo_region_t *region)
|
|
|
|
|
{
|
2021-10-03 19:58:57 +00:00
|
|
|
|
gdk_wayland_surface_ensure_wl_egl_window (gdk_draw_context_get_surface (draw_context));
|
|
|
|
|
|
2021-07-10 00:29:17 +00:00
|
|
|
|
GDK_DRAW_CONTEXT_CLASS (gdk_wayland_gl_context_parent_class)->begin_frame (draw_context, region);
|
|
|
|
|
|
|
|
|
|
glDrawBuffers (1, (GLenum[1]) { GL_BACK });
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
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-10-03 19:58:57 +00:00
|
|
|
|
egl_surface = gdk_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");
|
2021-10-05 22:48:33 +00:00
|
|
|
|
if (display->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
|
|
|
|
}
|
2021-10-03 04:22:21 +00:00
|
|
|
|
eglSwapBuffersWithDamageEXT (gdk_display_get_egl_display (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
|
2021-10-03 04:22:21 +00:00
|
|
|
|
eglSwapBuffers (gdk_display_get_egl_display (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;
|
|
|
|
|
|
2021-07-10 00:29:17 +00:00
|
|
|
|
draw_context_class->begin_frame = gdk_wayland_gl_context_begin_frame;
|
2016-12-01 00:38:20 +00:00
|
|
|
|
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;
|
2021-09-23 23:47:03 +00:00
|
|
|
|
|
|
|
|
|
context_class->backend_type = GDK_GL_EGL;
|
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)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GDK_IS_WAYLAND_DISPLAY (display), NULL);
|
|
|
|
|
|
2021-10-03 04:22:21 +00:00
|
|
|
|
return gdk_display_get_egl_display (display);
|
2016-10-10 18:12:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
2021-10-03 04:22:21 +00:00
|
|
|
|
GdkWaylandDisplay *self = GDK_WAYLAND_DISPLAY (display);
|
|
|
|
|
|
|
|
|
|
if (!gdk_display_init_egl (display,
|
|
|
|
|
EGL_PLATFORM_WAYLAND_EXT,
|
|
|
|
|
self->wl_display,
|
|
|
|
|
TRUE,
|
|
|
|
|
error))
|
|
|
|
|
return NULL;
|
2014-10-09 09:06:48 +00:00
|
|
|
|
|
2021-10-03 04:22:21 +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);
|
2021-10-03 04:22:21 +00:00
|
|
|
|
EGLDisplay *egl_display = gdk_display_get_egl_display (display);
|
2014-10-30 10:46:09 +00:00
|
|
|
|
|
2014-10-09 09:06:48 +00:00
|
|
|
|
if (eglGetCurrentContext () == context_wayland->egl_context)
|
2021-10-03 04:22:21 +00:00
|
|
|
|
eglMakeCurrent(egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
2014-10-09 09:06:48 +00:00
|
|
|
|
|
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
|
|
|
|
|
2021-10-03 04:22:21 +00:00
|
|
|
|
eglDestroyContext (egl_display, context_wayland->egl_context);
|
2014-10-09 09:06:48 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|