gdk: Get rid of paint contexts

... or more exactly: Only use paint contexts with
gdk_cairo_draw_from_gl().

Instead of paint contexts being the only contexts who call swapBuffer(),
any context can be used for this, when it's used with
begin_frame()/end_frame().

This removes 2 features:

1. We no longer need a big sharing hierarchy. All contexts are now
   shared with gdk_display_get_gl_context().
2. There is no longer a difference between attached and non-attached
   contexts. All contexts work the same way.
This commit is contained in:
Benjamin Otte 2021-07-06 04:50:01 +02:00
parent a27434a8a7
commit 505436340b
13 changed files with 21 additions and 115 deletions

View File

@ -357,17 +357,9 @@ gdk_gl_context_real_begin_frame (GdkDrawContext *draw_context,
{
GdkGLContext *context = GDK_GL_CONTEXT (draw_context);
GdkSurface *surface;
GdkGLContext *shared;
cairo_region_t *damage;
int ww, wh;
shared = gdk_gl_context_get_shared_context (context);
if (shared)
{
GDK_DRAW_CONTEXT_GET_CLASS (GDK_DRAW_CONTEXT (shared))->begin_frame (GDK_DRAW_CONTEXT (shared), region);
return;
}
damage = GDK_GL_CONTEXT_GET_CLASS (context)->get_damage (context);
if (context->old_updated_area[1])
@ -397,15 +389,6 @@ static void
gdk_gl_context_real_end_frame (GdkDrawContext *draw_context,
cairo_region_t *painted)
{
GdkGLContext *context = GDK_GL_CONTEXT (draw_context);
GdkGLContext *shared;
shared = gdk_gl_context_get_shared_context (context);
if (shared)
{
GDK_DRAW_CONTEXT_GET_CLASS (GDK_DRAW_CONTEXT (shared))->end_frame (GDK_DRAW_CONTEXT (shared), painted);
return;
}
}
static void

View File

@ -1078,15 +1078,8 @@ gdk_surface_get_paint_gl_context (GdkSurface *surface,
{
GdkSurfaceClass *class = GDK_SURFACE_GET_CLASS (surface);
if (class->create_gl_context == NULL)
{
g_set_error_literal (error, GDK_GL_ERROR, GDK_GL_ERROR_NOT_AVAILABLE,
_("The current backend does not support OpenGL"));
return NULL;
}
surface->gl_paint_context =
class->create_gl_context (surface, TRUE, NULL, &internal_error);
class->create_gl_context (surface, &internal_error);
}
if (internal_error != NULL)
@ -1125,18 +1118,13 @@ GdkGLContext *
gdk_surface_create_gl_context (GdkSurface *surface,
GError **error)
{
GdkGLContext *paint_context;
g_return_val_if_fail (GDK_IS_SURFACE (surface), NULL);
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
paint_context = gdk_surface_get_paint_gl_context (surface, error);
if (paint_context == NULL)
if (!gdk_display_prepare_gl (surface->display, error))
return NULL;
return GDK_SURFACE_GET_CLASS (surface)->create_gl_context (surface,
FALSE,
paint_context,
error);
}

View File

@ -161,8 +161,6 @@ struct _GdkSurfaceClass
void (* set_opaque_region) (GdkSurface *surface,
cairo_region_t *region);
GdkGLContext *(*create_gl_context) (GdkSurface *surface,
gboolean attached,
GdkGLContext *share,
GError **error);
void (* request_layout) (GdkSurface *surface);
gboolean (* compute_size) (GdkSurface *surface);

View File

@ -310,9 +310,7 @@ gdk_macos_gl_context_begin_frame (GdkDrawContext *context,
* want to replace our damage region for the next frame (to avoid
* doing it multiple times).
*/
if (!self->is_attached &&
gdk_gl_context_get_shared_context (GDK_GL_CONTEXT (context)))
ensure_gl_view (self);
ensure_gl_view (self);
if (self->needs_resize)
{

View File

@ -211,14 +211,8 @@ gdk_wayland_gl_context_get_damage (GdkGLContext *context)
if (display_wayland->have_egl_buffer_age)
{
GdkGLContext *shared;
shared = gdk_gl_context_get_shared_context (context);
if (shared == NULL)
shared = context;
egl_surface = gdk_wayland_surface_get_egl_surface (surface);
gdk_gl_context_make_current (shared);
gdk_gl_context_make_current (context);
eglQuerySurface (display_wayland->egl_display, egl_surface,
EGL_BUFFER_AGE_EXT, &buffer_age);
@ -262,8 +256,6 @@ gdk_wayland_gl_context_end_frame (GdkDrawContext *draw_context,
EGLSurface egl_surface;
GDK_DRAW_CONTEXT_CLASS (gdk_wayland_gl_context_parent_class)->end_frame (draw_context, painted);
if (gdk_gl_context_get_shared_context (context))
return;
gdk_gl_context_make_current (context);
@ -521,19 +513,14 @@ gdk_wayland_display_init_gl (GdkDisplay *display,
GdkGLContext *
gdk_wayland_surface_create_gl_context (GdkSurface *surface,
gboolean attached,
GdkGLContext *share,
GError **error)
{
GdkWaylandGLContext *context;
context = g_object_new (GDK_TYPE_WAYLAND_GL_CONTEXT,
"surface", surface,
"shared-context", share,
NULL);
context->is_attached = attached;
return GDK_GL_CONTEXT (context);
}
@ -582,7 +569,7 @@ gdk_wayland_display_make_gl_context_current (GdkDisplay *display,
context_wayland = GDK_WAYLAND_GL_CONTEXT (context);
surface = gdk_gl_context_get_surface (context);
if (context_wayland->is_attached || gdk_draw_context_is_in_frame (GDK_DRAW_CONTEXT (context)))
if (gdk_draw_context_is_in_frame (GDK_DRAW_CONTEXT (context)))
egl_surface = gdk_wayland_surface_get_egl_surface (surface);
else
{

View File

@ -36,7 +36,6 @@ struct _GdkWaylandGLContext
GdkGLContext parent_instance;
EGLContext egl_context;
gboolean is_attached;
};
struct _GdkWaylandGLContextClass
@ -47,8 +46,6 @@ struct _GdkWaylandGLContextClass
GdkGLContext * gdk_wayland_display_init_gl (GdkDisplay *display,
GError **error);
GdkGLContext * gdk_wayland_surface_create_gl_context (GdkSurface *surface,
gboolean attach,
GdkGLContext *share,
GError **error);
gboolean gdk_wayland_display_make_gl_context_current (GdkDisplay *display,
GdkGLContext *context);

View File

@ -125,8 +125,6 @@ gdk_win32_gl_context_end_frame (GdkDrawContext *draw_context,
cairo_rectangle_int_t whole_window;
GDK_DRAW_CONTEXT_CLASS (gdk_win32_gl_context_parent_class)->end_frame (draw_context, painted);
if (gdk_gl_context_get_shared_context (context))
return;
gdk_gl_context_make_current (context);
whole_window = (GdkRectangle) { 0, 0, gdk_surface_get_width (surface), gdk_surface_get_height (surface) };
@ -1070,8 +1068,6 @@ gdk_win32_gl_context_init (GdkWin32GLContext *self)
GdkGLContext *
_gdk_win32_surface_create_gl_context (GdkSurface *surface,
gboolean attached,
GdkGLContext *share,
GError **error)
{
GdkDisplay *display = gdk_surface_get_display (surface);
@ -1107,11 +1103,9 @@ _gdk_win32_surface_create_gl_context (GdkSurface *surface,
context = g_object_new (GDK_TYPE_WIN32_GL_CONTEXT,
"surface", surface,
"shared-context", share,
NULL);
context->gl_hdc = impl->hdc;
context->is_attached = attached;
#ifdef GDK_WIN32_ENABLE_EGL
if (display_win32->have_egl)
@ -1157,7 +1151,8 @@ _gdk_win32_display_make_gl_context_current (GdkDisplay *display,
return FALSE;
}
if (context_win32->is_attached && display_win32->hasWglEXTSwapControl)
if (gdk_draw_context_is_in_frame (GDK_DRAW_CONTEXT (context)) &&
display_win32->hasWglEXTSwapControl)
{
surface = gdk_gl_context_get_surface (context);
@ -1187,7 +1182,7 @@ _gdk_win32_display_make_gl_context_current (GdkDisplay *display,
surface = gdk_gl_context_get_surface (context);
if (context_win32->is_attached)
if (gdk_draw_context_is_in_frame (GDK_DRAW_CONTEXT (context)))
egl_surface = _gdk_win32_surface_get_egl_surface (surface, context_win32->egl_config, FALSE);
else
{

View File

@ -45,7 +45,6 @@ struct _GdkWin32GLContext
guint need_alpha_bits : 1;
/* other items */
guint is_attached : 1;
guint do_frame_sync : 1;
#ifdef GDK_WIN32_ENABLE_EGL
@ -62,9 +61,7 @@ struct _GdkWin32GLContextClass
GdkGLContext *
_gdk_win32_surface_create_gl_context (GdkSurface *window,
gboolean attached,
GdkGLContext *share,
GError **error);
GError **error);
gboolean
_gdk_win32_display_make_gl_context_current (GdkDisplay *display,

View File

@ -2889,7 +2889,7 @@ gdk_x11_display_init_gl (GdkDisplay *display,
if (!have_gl)
return NULL;
return gdk_x11_surface_create_gl_context (display_x11->leader_gdk_surface, FALSE, NULL, error);
return gdk_x11_surface_create_gl_context (display_x11->leader_gdk_surface, error);
}
static void

View File

@ -321,8 +321,6 @@ gdk_x11_gl_context_egl_end_frame (GdkDrawContext *draw_context,
EGLSurface egl_surface;
GDK_DRAW_CONTEXT_CLASS (gdk_x11_gl_context_egl_parent_class)->end_frame (draw_context, painted);
if (gdk_gl_context_get_shared_context (context) != NULL)
return;
gdk_gl_context_make_current (context);
@ -371,16 +369,11 @@ gdk_x11_gl_context_egl_get_damage (GdkGLContext *context)
if (display_x11->has_egl_buffer_age)
{
GdkSurface *surface = gdk_draw_context_get_surface (GDK_DRAW_CONTEXT (context));
GdkGLContext *shared = gdk_gl_context_get_shared_context (context);
EGLSurface egl_surface;
int buffer_age = 0;
shared = gdk_gl_context_get_shared_context (context);
if (shared == NULL)
shared = context;
egl_surface = gdk_x11_surface_get_egl_surface (surface);
gdk_gl_context_make_current (shared);
gdk_gl_context_make_current (context);
eglQuerySurface (display_x11->egl_display,
egl_surface,
@ -679,15 +672,12 @@ gdk_x11_display_init_egl (GdkX11Display *self,
GdkX11GLContext *
gdk_x11_gl_context_egl_new (GdkSurface *surface,
gboolean attached,
GdkGLContext *share,
GError **error)
{
GdkX11GLContextEGL *context;
context = g_object_new (GDK_TYPE_X11_GL_CONTEXT_EGL,
"surface", surface,
"shared-context", share,
NULL);
return GDK_X11_GL_CONTEXT (context);
@ -718,7 +708,7 @@ gdk_x11_gl_context_egl_make_current (GdkDisplay *display,
surface = gdk_gl_context_get_surface (context);
if (context_x11->is_attached || gdk_draw_context_is_in_frame (GDK_DRAW_CONTEXT (context)))
if (gdk_draw_context_is_in_frame (GDK_DRAW_CONTEXT (context)))
egl_surface = gdk_x11_surface_get_egl_surface (surface);
else
{
@ -739,7 +729,7 @@ gdk_x11_gl_context_egl_make_current (GdkDisplay *display,
return FALSE;
}
if (context_x11->is_attached)
if (gdk_draw_context_is_in_frame (GDK_DRAW_CONTEXT (context)))
{
gboolean do_frame_sync = FALSE;

View File

@ -131,11 +131,10 @@ maybe_wait_for_vblank (GdkDisplay *display,
static GLXDrawable
gdk_x11_gl_context_glx_get_drawable (GdkX11GLContextGLX *self)
{
GdkX11GLContext *context_x11 = GDK_X11_GL_CONTEXT (self);
GdkDrawContext *draw_context = GDK_DRAW_CONTEXT (self);
GdkSurface *surface;
if (context_x11->is_attached || gdk_draw_context_is_in_frame (draw_context))
if (gdk_draw_context_is_in_frame (draw_context))
surface = gdk_draw_context_get_surface (draw_context);
else
surface = GDK_X11_DISPLAY (gdk_draw_context_get_display (draw_context))->leader_gdk_surface;
@ -158,8 +157,6 @@ gdk_x11_gl_context_glx_end_frame (GdkDrawContext *draw_context,
GLXDrawable drawable;
GDK_DRAW_CONTEXT_CLASS (gdk_x11_gl_context_glx_parent_class)->end_frame (draw_context, painted);
if (gdk_gl_context_get_shared_context (context) != NULL)
return;
gdk_gl_context_make_current (context);
@ -242,17 +239,10 @@ gdk_x11_gl_context_glx_get_damage (GdkGLContext *context)
if (display_x11->has_glx_buffer_age)
{
GdkGLContext *shared;
GdkX11GLContextGLX *shared_glx;
GdkX11GLContextGLX *self = GDK_X11_GL_CONTEXT_GLX (context);
shared = gdk_gl_context_get_shared_context (context);
if (shared == NULL)
shared = context;
shared_glx = GDK_X11_GL_CONTEXT_GLX (shared);
gdk_gl_context_make_current (shared);
glXQueryDrawable (dpy, gdk_x11_gl_context_glx_get_drawable (shared_glx),
gdk_gl_context_make_current (context);
glXQueryDrawable (dpy, gdk_x11_gl_context_glx_get_drawable (self),
GLX_BACK_BUFFER_AGE_EXT, &buffer_age);
switch (buffer_age)
@ -412,12 +402,8 @@ on_gl_surface_xevent (GdkGLContext *context,
GdkX11Display *display_x11)
{
GdkX11GLContextGLX *context_glx = GDK_X11_GL_CONTEXT_GLX (context);
GdkX11GLContext *context_x11 = GDK_X11_GL_CONTEXT (context);
XDamageNotifyEvent *damage_xevent;
if (!context_x11->is_attached)
return FALSE;
if (xevent->type != (display_x11->damage_event_base + XDamageNotify))
return FALSE;
@ -844,15 +830,12 @@ gdk_x11_display_create_glx_config (GdkX11Display *self,
GdkX11GLContext *
gdk_x11_gl_context_glx_new (GdkSurface *surface,
gboolean attached,
GdkGLContext *share,
GError **error)
{
GdkX11GLContextGLX *context;
return g_object_new (GDK_TYPE_X11_GL_CONTEXT_GLX,
"surface", surface,
"shared-context", share,
NULL);
return GDK_X11_GL_CONTEXT (context);
@ -896,7 +879,8 @@ gdk_x11_gl_context_glx_make_current (GdkDisplay *display,
return FALSE;
}
if (context_x11->is_attached && GDK_X11_DISPLAY (display)->has_glx_swap_interval)
if (gdk_draw_context_is_in_frame (GDK_DRAW_CONTEXT (context)) &&
GDK_X11_DISPLAY (display)->has_glx_swap_interval)
{
/* If the WM is compositing there is no particular need to delay
* the swap when drawing on the offscreen, rendering to the screen

View File

@ -55,8 +55,6 @@ gdk_x11_gl_context_init (GdkX11GLContext *self)
GdkGLContext *
gdk_x11_surface_create_gl_context (GdkSurface *surface,
gboolean attached,
GdkGLContext *share,
GError **error)
{
GdkX11GLContext *context = NULL;
@ -67,9 +65,9 @@ gdk_x11_surface_create_gl_context (GdkSurface *surface,
display_x11 = GDK_X11_DISPLAY (display);
if (display_x11->egl_display)
context = gdk_x11_gl_context_egl_new (surface, attached, share, error);
context = gdk_x11_gl_context_egl_new (surface, error);
else if (display_x11->glx_config != NULL)
context = gdk_x11_gl_context_glx_new (surface, attached, share, error);
context = gdk_x11_gl_context_glx_new (surface, error);
else
{
g_assert (display_x11->gl_error);
@ -81,8 +79,6 @@ gdk_x11_surface_create_gl_context (GdkSurface *surface,
if (context == NULL)
return NULL;
context->is_attached = attached;
return GDK_GL_CONTEXT (context);
}

View File

@ -49,7 +49,6 @@ struct _GdkX11GLContext
GdkGLContext parent_instance;
guint do_frame_sync : 1;
guint is_attached : 1;
};
struct _GdkX11GLContextClass
@ -65,8 +64,6 @@ gboolean gdk_x11_display_init_gl_backend (GdkX11Display *
GError **error);
GdkGLContext * gdk_x11_surface_create_gl_context (GdkSurface *window,
gboolean attached,
GdkGLContext *share,
GError **error);
gboolean gdk_x11_display_make_gl_context_current (GdkDisplay *display,
GdkGLContext *context);
@ -86,8 +83,6 @@ void gdk_x11_surface_destroy_glx_drawable (GdkX11Surface *
GType gdk_x11_gl_context_glx_get_type (void) G_GNUC_CONST;
GdkX11GLContext * gdk_x11_gl_context_glx_new (GdkSurface *surface,
gboolean attached,
GdkGLContext *share,
GError **error);
gboolean gdk_x11_gl_context_glx_make_current (GdkDisplay *display,
GdkGLContext *context);
@ -109,8 +104,6 @@ void gdk_x11_surface_destroy_egl_surface (GdkX11Surface *
GType gdk_x11_gl_context_egl_get_type (void) G_GNUC_CONST;
GdkX11GLContext * gdk_x11_gl_context_egl_new (GdkSurface *surface,
gboolean attached,
GdkGLContext *share,
GError **error);
gboolean gdk_x11_gl_context_egl_make_current (GdkDisplay *display,
GdkGLContext *context);