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"
|
|
|
|
#include "gdkdisplay-wayland.h"
|
|
|
|
|
|
|
|
#include "gdkwaylanddisplay.h"
|
|
|
|
#include "gdkwaylandglcontext.h"
|
|
|
|
#include "gdkwaylandwindow.h"
|
|
|
|
#include "gdkprivate-wayland.h"
|
|
|
|
|
|
|
|
#include "gdkinternals.h"
|
|
|
|
|
|
|
|
#include "gdkintl.h"
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GdkWaylandGLContext, gdk_wayland_gl_context, GDK_TYPE_GL_CONTEXT)
|
|
|
|
|
2014-10-30 10:46:09 +00:00
|
|
|
static void gdk_x11_gl_context_dispose (GObject *gobject);
|
|
|
|
|
2014-10-09 09:06:48 +00:00
|
|
|
void
|
|
|
|
gdk_wayland_window_invalidate_for_new_frame (GdkWindow *window,
|
|
|
|
cairo_region_t *update_area)
|
|
|
|
{
|
|
|
|
cairo_rectangle_int_t window_rect;
|
|
|
|
GdkDisplay *display = gdk_window_get_display (window);
|
|
|
|
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
|
|
|
|
GdkWaylandGLContext *context_wayland;
|
|
|
|
int buffer_age;
|
|
|
|
gboolean invalidate_all;
|
|
|
|
EGLSurface egl_surface;
|
|
|
|
|
|
|
|
/* Minimal update is ok if we're not drawing with gl */
|
|
|
|
if (window->gl_paint_context == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
context_wayland = GDK_WAYLAND_GL_CONTEXT (window->gl_paint_context);
|
|
|
|
buffer_age = 0;
|
|
|
|
|
|
|
|
egl_surface = gdk_wayland_window_get_egl_surface (window->impl_window,
|
|
|
|
context_wayland->egl_config);
|
|
|
|
|
2014-10-09 15:24:21 +00:00
|
|
|
if (display_wayland->have_egl_buffer_age)
|
|
|
|
{
|
|
|
|
gdk_gl_context_make_current (window->gl_paint_context);
|
|
|
|
eglQuerySurface (display_wayland->egl_display, egl_surface,
|
|
|
|
EGL_BUFFER_AGE_EXT, &buffer_age);
|
|
|
|
}
|
2014-10-09 09:06:48 +00:00
|
|
|
|
|
|
|
invalidate_all = FALSE;
|
|
|
|
if (buffer_age == 0 || buffer_age >= 4)
|
|
|
|
invalidate_all = TRUE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (buffer_age >= 2)
|
|
|
|
{
|
|
|
|
if (window->old_updated_area[0])
|
|
|
|
cairo_region_union (update_area, window->old_updated_area[0]);
|
|
|
|
else
|
|
|
|
invalidate_all = TRUE;
|
|
|
|
}
|
|
|
|
if (buffer_age >= 3)
|
|
|
|
{
|
|
|
|
if (window->old_updated_area[1])
|
|
|
|
cairo_region_union (update_area, window->old_updated_area[1]);
|
|
|
|
else
|
|
|
|
invalidate_all = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (invalidate_all)
|
|
|
|
{
|
|
|
|
window_rect.x = 0;
|
|
|
|
window_rect.y = 0;
|
|
|
|
window_rect.width = gdk_window_get_width (window);
|
|
|
|
window_rect.height = gdk_window_get_height (window);
|
|
|
|
|
|
|
|
/* If nothing else is known, repaint everything so that the back
|
2015-02-28 03:28:28 +00:00
|
|
|
* buffer is fully up-to-date for the swapbuffer
|
|
|
|
*/
|
2014-10-09 09:06:48 +00:00
|
|
|
cairo_region_union_rectangle (update_area, &window_rect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
GdkGLContext *share = gdk_gl_context_get_shared_context (context);
|
|
|
|
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);
|
2015-10-07 14:26:53 +00:00
|
|
|
legacy_bit = (_gdk_gl_flags & GDK_GL_LEGACY) != 0 ||
|
|
|
|
(share != NULL && gdk_gl_context_is_legacy (share));
|
2016-04-22 11:45:32 +00:00
|
|
|
use_es = (_gdk_gl_flags & GDK_GL_GLES) != 0 ||
|
|
|
|
(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
|
|
|
|
2016-04-22 17:50:50 +00:00
|
|
|
GDK_NOTE (OPENGL, g_message ("Creating EGL context version %d.%d (debug:%s, forward:%s, legacy:%s, es:%s)",
|
|
|
|
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,
|
|
|
|
context_wayland->egl_config,
|
|
|
|
share != NULL ? GDK_WAYLAND_GL_CONTEXT (share)->egl_context
|
|
|
|
: EGL_NO_CONTEXT,
|
|
|
|
context_attribs);
|
2015-10-07 14:26:53 +00:00
|
|
|
|
|
|
|
/* If context creation failed without the legacy bit, let's try again with it */
|
|
|
|
if (ctx == NULL && !legacy_bit)
|
|
|
|
{
|
|
|
|
/* Ensure that re-ordering does not break the offsets */
|
|
|
|
g_assert (context_attribs[0] == EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR);
|
|
|
|
context_attribs[1] = EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR;
|
|
|
|
context_attribs[3] = 3;
|
|
|
|
context_attribs[5] = 0;
|
|
|
|
|
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
|
|
|
|
2016-04-22 17:50:50 +00:00
|
|
|
GDK_NOTE (OPENGL, g_message ("eglCreateContext failed, switching to legacy"));
|
2015-10-07 14:26:53 +00:00
|
|
|
ctx = eglCreateContext (display_wayland->egl_display,
|
|
|
|
context_wayland->egl_config,
|
|
|
|
share != NULL ? GDK_WAYLAND_GL_CONTEXT (share)->egl_context
|
|
|
|
: EGL_NO_CONTEXT,
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-02-29 02:28:01 +00:00
|
|
|
GDK_NOTE (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;
|
|
|
|
}
|
|
|
|
|
2014-10-09 09:06:48 +00:00
|
|
|
static void
|
2015-02-28 03:28:28 +00:00
|
|
|
gdk_wayland_gl_context_end_frame (GdkGLContext *context,
|
2014-10-27 15:33:37 +00:00
|
|
|
cairo_region_t *painted,
|
|
|
|
cairo_region_t *damage)
|
2014-10-09 09:06:48 +00:00
|
|
|
{
|
|
|
|
GdkWindow *window = gdk_gl_context_get_window (context);
|
|
|
|
GdkDisplay *display = gdk_window_get_display (window);
|
|
|
|
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
|
|
|
|
GdkWaylandGLContext *context_wayland = GDK_WAYLAND_GL_CONTEXT (context);
|
|
|
|
EGLSurface egl_surface;
|
|
|
|
|
2014-10-09 15:24:21 +00:00
|
|
|
gdk_gl_context_make_current (context);
|
2014-10-09 09:06:48 +00:00
|
|
|
|
|
|
|
egl_surface = gdk_wayland_window_get_egl_surface (window->impl_window,
|
|
|
|
context_wayland->egl_config);
|
|
|
|
|
|
|
|
if (display_wayland->have_egl_swap_buffers_with_damage)
|
|
|
|
{
|
|
|
|
int i, j, n_rects = cairo_region_num_rectangles (damage);
|
|
|
|
EGLint *rects = g_new (EGLint, n_rects * 4);
|
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
int window_height = gdk_window_get_height (window);
|
|
|
|
|
|
|
|
for (i = 0, j = 0; i < n_rects; i++)
|
|
|
|
{
|
|
|
|
cairo_region_get_rectangle (damage, i, &rect);
|
|
|
|
rects[j++] = rect.x;
|
|
|
|
rects[j++] = window_height - rect.height - rect.y;
|
|
|
|
rects[j++] = rect.width;
|
|
|
|
rects[j++] = rect.height;
|
|
|
|
}
|
|
|
|
eglSwapBuffersWithDamageEXT (display_wayland->egl_display, egl_surface, rects, n_rects);
|
|
|
|
g_free (rects);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
eglSwapBuffers (display_wayland->egl_display, egl_surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
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
|
|
|
|
2014-10-30 10:46:09 +00:00
|
|
|
gobject_class->dispose = gdk_x11_gl_context_dispose;
|
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;
|
|
|
|
context_class->end_frame = gdk_wayland_gl_context_end_frame;
|
2014-10-09 09:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_wayland_gl_context_init (GdkWaylandGLContext *self)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-10-10 18:12:40 +00:00
|
|
|
static EGLDisplay
|
|
|
|
gdk_wayland_get_display (GdkWaylandDisplay *display_wayland)
|
|
|
|
{
|
|
|
|
EGLDisplay dpy = NULL;
|
|
|
|
|
|
|
|
if (epoxy_has_egl_extension (NULL, "EGL_KHR_platform_base"))
|
|
|
|
{
|
|
|
|
PFNEGLGETPLATFORMDISPLAYPROC getPlatformDisplay =
|
|
|
|
(void *) eglGetProcAddress ("eglGetPlatformDisplay");
|
|
|
|
|
|
|
|
if (getPlatformDisplay)
|
|
|
|
dpy = getPlatformDisplay (EGL_PLATFORM_WAYLAND_EXT,
|
|
|
|
display_wayland->wl_display,
|
|
|
|
NULL);
|
|
|
|
if (dpy)
|
|
|
|
return dpy;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (epoxy_has_egl_extension (NULL, "EGL_EXT_platform_base"))
|
|
|
|
{
|
|
|
|
PFNEGLGETPLATFORMDISPLAYEXTPROC getPlatformDisplay =
|
|
|
|
(void *) eglGetProcAddress ("eglGetPlatformDisplayEXT");
|
|
|
|
|
|
|
|
if (getPlatformDisplay)
|
|
|
|
dpy = getPlatformDisplay (EGL_PLATFORM_WAYLAND_EXT,
|
|
|
|
display_wayland->wl_display,
|
|
|
|
NULL);
|
|
|
|
if (dpy)
|
|
|
|
return dpy;
|
|
|
|
}
|
|
|
|
|
|
|
|
return eglGetDisplay ((EGLNativeDisplayType) display_wayland->wl_display);
|
|
|
|
}
|
|
|
|
|
2014-10-09 09:06:48 +00:00
|
|
|
gboolean
|
|
|
|
gdk_wayland_display_init_gl (GdkDisplay *display)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
if (display_wayland->have_egl)
|
|
|
|
return TRUE;
|
|
|
|
|
2016-10-10 18:12:40 +00:00
|
|
|
dpy = gdk_wayland_get_display (display_wayland);
|
|
|
|
|
2014-10-09 09:06:48 +00:00
|
|
|
if (dpy == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!eglInitialize (dpy, &major, &minor))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!eglBindAPI (EGL_OPENGL_API))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
display_wayland->egl_display = dpy;
|
|
|
|
display_wayland->egl_major_version = major;
|
|
|
|
display_wayland->egl_minor_version = minor;
|
|
|
|
|
|
|
|
display_wayland->have_egl = TRUE;
|
|
|
|
|
|
|
|
display_wayland->have_egl_khr_create_context =
|
|
|
|
epoxy_has_egl_extension (dpy, "EGL_KHR_create_context");
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
2014-10-09 14:09:05 +00:00
|
|
|
display_wayland->have_egl_surfaceless_context =
|
|
|
|
epoxy_has_egl_extension (dpy, "EGL_KHR_surfaceless_context");
|
|
|
|
|
2014-10-09 09:06:48 +00:00
|
|
|
GDK_NOTE (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
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_EGL_ATTRS 30
|
|
|
|
|
|
|
|
static gboolean
|
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
|
|
|
find_eglconfig_for_window (GdkWindow *window,
|
|
|
|
EGLConfig *egl_config_out,
|
|
|
|
GError **error)
|
2014-10-09 09:06:48 +00:00
|
|
|
{
|
|
|
|
GdkDisplay *display = gdk_window_get_display (window);
|
|
|
|
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
|
|
|
|
EGLint attrs[MAX_EGL_ATTRS];
|
|
|
|
EGLint count;
|
|
|
|
EGLConfig *configs;
|
|
|
|
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;
|
2014-10-28 17:29:02 +00:00
|
|
|
attrs[i++] = 1;
|
2014-10-09 09:06:48 +00:00
|
|
|
attrs[i++] = EGL_GREEN_SIZE;
|
2014-10-28 17:29:02 +00:00
|
|
|
attrs[i++] = 1;
|
2014-10-09 09:06:48 +00:00
|
|
|
attrs[i++] = EGL_BLUE_SIZE;
|
2014-10-28 17:29:02 +00:00
|
|
|
attrs[i++] = 1;
|
2016-10-27 21:27:49 +00:00
|
|
|
attrs[i++] = EGL_ALPHA_SIZE;
|
|
|
|
attrs[i++] = 1;
|
2014-10-09 09:06:48 +00:00
|
|
|
|
|
|
|
attrs[i++] = EGL_NONE;
|
|
|
|
g_assert (i < MAX_EGL_ATTRS);
|
|
|
|
|
|
|
|
if (!eglChooseConfig (display_wayland->egl_display, attrs, NULL, 0, &count) || count < 1)
|
|
|
|
{
|
|
|
|
g_set_error_literal (error, GDK_GL_ERROR,
|
|
|
|
GDK_GL_ERROR_UNSUPPORTED_FORMAT,
|
|
|
|
_("No available configurations for the given pixel format"));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
configs = g_new (EGLConfig, count);
|
|
|
|
|
|
|
|
if (!eglChooseConfig (display_wayland->egl_display, attrs, configs, count, &count) || count < 1)
|
|
|
|
{
|
|
|
|
g_set_error_literal (error, GDK_GL_ERROR,
|
|
|
|
GDK_GL_ERROR_UNSUPPORTED_FORMAT,
|
|
|
|
_("No available configurations for the given pixel format"));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pick first valid configuration i guess? */
|
|
|
|
|
|
|
|
if (egl_config_out != NULL)
|
|
|
|
*egl_config_out = configs[0];
|
|
|
|
|
|
|
|
g_free (configs);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GdkGLContext *
|
|
|
|
gdk_wayland_window_create_gl_context (GdkWindow *window,
|
2014-10-09 14:09:05 +00:00
|
|
|
gboolean attached,
|
2014-10-09 09:06:48 +00:00
|
|
|
GdkGLContext *share,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GdkDisplay *display = gdk_window_get_display (window);
|
|
|
|
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
|
|
|
|
GdkWaylandGLContext *context;
|
|
|
|
EGLConfig config;
|
|
|
|
|
|
|
|
if (!gdk_wayland_display_init_gl (display))
|
|
|
|
{
|
|
|
|
g_set_error_literal (error, GDK_GL_ERROR,
|
|
|
|
GDK_GL_ERROR_NOT_AVAILABLE,
|
|
|
|
_("No GL implementation is available"));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-02-12 12:34:28 +00:00
|
|
|
if (!display_wayland->have_egl_khr_create_context)
|
2014-10-09 09:06:48 +00:00
|
|
|
{
|
|
|
|
g_set_error_literal (error, GDK_GL_ERROR,
|
|
|
|
GDK_GL_ERROR_UNSUPPORTED_PROFILE,
|
2015-02-12 17:30:42 +00:00
|
|
|
_("Core GL is not available on EGL implementation"));
|
2014-10-09 09:06:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!find_eglconfig_for_window (window, &config, error))
|
|
|
|
return NULL;
|
|
|
|
|
2014-10-22 03:39:05 +00:00
|
|
|
context = g_object_new (GDK_TYPE_WAYLAND_GL_CONTEXT,
|
2014-11-03 12:20:55 +00:00
|
|
|
"display", display,
|
2014-10-09 09:06:48 +00:00
|
|
|
"window", window,
|
2014-10-30 11:04:23 +00:00
|
|
|
"shared-context", share,
|
2014-10-09 09:06:48 +00:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
context->egl_config = config;
|
2014-10-09 14:09:05 +00:00
|
|
|
context->is_attached = attached;
|
2014-10-09 09:06:48 +00:00
|
|
|
|
|
|
|
return GDK_GL_CONTEXT (context);
|
|
|
|
}
|
|
|
|
|
2014-10-30 10:46:09 +00:00
|
|
|
static void
|
|
|
|
gdk_x11_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);
|
|
|
|
GdkWindow *window = gdk_gl_context_get_window (context);
|
|
|
|
GdkDisplay *display = gdk_window_get_display (window);
|
|
|
|
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);
|
|
|
|
|
2016-02-29 02:28:01 +00:00
|
|
|
GDK_NOTE (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
|
|
|
}
|
|
|
|
|
2014-10-30 10:46:09 +00:00
|
|
|
gboolean
|
2014-10-09 09:06:48 +00:00
|
|
|
gdk_wayland_display_make_gl_context_current (GdkDisplay *display,
|
|
|
|
GdkGLContext *context)
|
|
|
|
{
|
|
|
|
GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
|
|
|
|
GdkWaylandGLContext *context_wayland;
|
|
|
|
GdkWindow *window;
|
|
|
|
EGLSurface egl_surface;
|
|
|
|
|
|
|
|
if (context == NULL)
|
|
|
|
{
|
|
|
|
eglMakeCurrent(display_wayland->egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
|
|
|
|
EGL_NO_CONTEXT);
|
2014-10-30 10:46:09 +00:00
|
|
|
return TRUE;
|
2014-10-09 09:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
context_wayland = GDK_WAYLAND_GL_CONTEXT (context);
|
|
|
|
window = gdk_gl_context_get_window (context);
|
|
|
|
|
2014-10-09 14:09:05 +00:00
|
|
|
if (context_wayland->is_attached)
|
|
|
|
egl_surface = gdk_wayland_window_get_egl_surface (window->impl_window, context_wayland->egl_config);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (display_wayland->have_egl_surfaceless_context)
|
|
|
|
egl_surface = EGL_NO_SURFACE;
|
|
|
|
else
|
|
|
|
egl_surface = gdk_wayland_window_get_dummy_egl_surface (window->impl_window,
|
|
|
|
context_wayland->egl_config);
|
|
|
|
}
|
2014-10-09 09:06:48 +00:00
|
|
|
|
2014-10-09 15:24:21 +00:00
|
|
|
if (!eglMakeCurrent (display_wayland->egl_display, egl_surface,
|
2014-10-30 10:46:09 +00:00
|
|
|
egl_surface, context_wayland->egl_context))
|
|
|
|
{
|
|
|
|
g_warning ("eglMakeCurrent failed");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2014-10-09 09:06:48 +00:00
|
|
|
}
|