[gtk/wip/otte/gleanup: 44/53] gdk: Get rid of paint contexts
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/gleanup: 44/53] gdk: Get rid of paint contexts
- Date: Tue, 13 Jul 2021 03:35:06 +0000 (UTC)
commit fe6943547919adb772f2d7843d6e46c7f2beb2c1
Author: Benjamin Otte <otte redhat com>
Date: Tue Jul 6 04:50:01 2021 +0200
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.
gdk/gdkglcontext.c | 17 -----------------
gdk/gdksurface.c | 16 ++--------------
gdk/gdksurfaceprivate.h | 2 --
gdk/macos/gdkmacosglcontext.c | 4 +---
gdk/wayland/gdkglcontext-wayland.c | 17 ++---------------
gdk/wayland/gdkglcontext-wayland.h | 3 ---
gdk/win32/gdkglcontext-win32.c | 13 ++++---------
gdk/win32/gdkglcontext-win32.h | 5 +----
gdk/x11/gdkdisplay-x11.c | 2 +-
gdk/x11/gdkglcontext-egl.c | 16 +++-------------
gdk/x11/gdkglcontext-glx.c | 28 ++++++----------------------
gdk/x11/gdkglcontext-x11.c | 8 ++------
gdk/x11/gdkglcontext-x11.h | 7 -------
13 files changed, 22 insertions(+), 116 deletions(-)
---
diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c
index 5fd43a4c0f..c962ae903f 100644
--- a/gdk/gdkglcontext.c
+++ b/gdk/gdkglcontext.c
@@ -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
diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c
index 274ad99345..f56b0e8c17 100644
--- a/gdk/gdksurface.c
+++ b/gdk/gdksurface.c
@@ -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);
}
diff --git a/gdk/gdksurfaceprivate.h b/gdk/gdksurfaceprivate.h
index c29827c34e..cf7a0f73b6 100644
--- a/gdk/gdksurfaceprivate.h
+++ b/gdk/gdksurfaceprivate.h
@@ -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);
diff --git a/gdk/macos/gdkmacosglcontext.c b/gdk/macos/gdkmacosglcontext.c
index 66f767c19d..58d688e890 100644
--- a/gdk/macos/gdkmacosglcontext.c
+++ b/gdk/macos/gdkmacosglcontext.c
@@ -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)
{
diff --git a/gdk/wayland/gdkglcontext-wayland.c b/gdk/wayland/gdkglcontext-wayland.c
index 6044a9a907..2e83d501f1 100644
--- a/gdk/wayland/gdkglcontext-wayland.c
+++ b/gdk/wayland/gdkglcontext-wayland.c
@@ -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
{
diff --git a/gdk/wayland/gdkglcontext-wayland.h b/gdk/wayland/gdkglcontext-wayland.h
index d939a4ad39..98a2a7b62e 100644
--- a/gdk/wayland/gdkglcontext-wayland.h
+++ b/gdk/wayland/gdkglcontext-wayland.h
@@ -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);
diff --git a/gdk/win32/gdkglcontext-win32.c b/gdk/win32/gdkglcontext-win32.c
index 66adbb858e..a992634bdd 100644
--- a/gdk/win32/gdkglcontext-win32.c
+++ b/gdk/win32/gdkglcontext-win32.c
@@ -129,8 +129,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) };
@@ -1074,9 +1072,7 @@ gdk_win32_gl_context_init (GdkWin32GLContext *self)
GdkGLContext *
_gdk_win32_surface_create_gl_context (GdkSurface *surface,
- gboolean attached,
- GdkGLContext *share,
- GError **error)
+ GError **error)
{
GdkDisplay *display = gdk_surface_get_display (surface);
GdkWin32Display *display_win32 = GDK_WIN32_DISPLAY (display);
@@ -1125,11 +1121,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 = hdc;
- context->is_attached = attached;
#ifdef GDK_WIN32_ENABLE_EGL
if (display_win32->have_egl)
@@ -1175,7 +1169,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);
@@ -1205,7 +1200,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
{
diff --git a/gdk/win32/gdkglcontext-win32.h b/gdk/win32/gdkglcontext-win32.h
index 3249d4c6db..c000b8143b 100644
--- a/gdk/win32/gdkglcontext-win32.h
+++ b/gdk/win32/gdkglcontext-win32.h
@@ -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,
diff --git a/gdk/x11/gdkdisplay-x11.c b/gdk/x11/gdkdisplay-x11.c
index 0b838c25dd..bb76c96275 100644
--- a/gdk/x11/gdkdisplay-x11.c
+++ b/gdk/x11/gdkdisplay-x11.c
@@ -2911,7 +2911,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
diff --git a/gdk/x11/gdkglcontext-egl.c b/gdk/x11/gdkglcontext-egl.c
index 1ce44b168b..280df54b7b 100644
--- a/gdk/x11/gdkglcontext-egl.c
+++ b/gdk/x11/gdkglcontext-egl.c
@@ -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;
diff --git a/gdk/x11/gdkglcontext-glx.c b/gdk/x11/gdkglcontext-glx.c
index cc68137aab..763091af7c 100644
--- a/gdk/x11/gdkglcontext-glx.c
+++ b/gdk/x11/gdkglcontext-glx.c
@@ -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;
-
- shared = gdk_gl_context_get_shared_context (context);
- if (shared == NULL)
- shared = context;
-
- shared_glx = GDK_X11_GL_CONTEXT_GLX (shared);
+ GdkX11GLContextGLX *self = GDK_X11_GL_CONTEXT_GLX (context);
- 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;
@@ -843,15 +829,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);
@@ -895,7 +878,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
diff --git a/gdk/x11/gdkglcontext-x11.c b/gdk/x11/gdkglcontext-x11.c
index 3585367596..4ecbf47a7d 100644
--- a/gdk/x11/gdkglcontext-x11.c
+++ b/gdk/x11/gdkglcontext-x11.c
@@ -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);
}
diff --git a/gdk/x11/gdkglcontext-x11.h b/gdk/x11/gdkglcontext-x11.h
index e62a4795d7..680fd91fb7 100644
--- a/gdk/x11/gdkglcontext-x11.h
+++ b/gdk/x11/gdkglcontext-x11.h
@@ -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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]