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)
|
|
|
|
|
2021-07-10 00:29:17 +00:00
|
|
|
static void
|
|
|
|
gdk_wayland_gl_context_begin_frame (GdkDrawContext *draw_context,
|
2021-10-06 16:25:30 +00:00
|
|
|
gboolean prefers_high_depth,
|
2021-07-10 00:29:17 +00:00
|
|
|
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-10-06 16:25:30 +00:00
|
|
|
GDK_DRAW_CONTEXT_CLASS (gdk_wayland_gl_context_parent_class)->begin_frame (draw_context, prefers_high_depth, region);
|
2021-07-10 00:29:17 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2021-10-05 22:34:10 +00:00
|
|
|
GdkSurface *surface = gdk_draw_context_get_surface (draw_context);
|
2016-12-01 00:38:20 +00:00
|
|
|
|
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
|
|
|
|
2021-10-05 22:34:10 +00:00
|
|
|
GDK_DRAW_CONTEXT_CLASS (gdk_wayland_gl_context_parent_class)->end_frame (draw_context, painted);
|
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)
|
|
|
|
{
|
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
|
|
|
|
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
|
|
|
|
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
|
|
|
}
|
|
|
|
|