[gtk/wip/otte/gleanup: 47/53] gdk: Move GL context construction to GdkGLContext




commit b873a34e0fec277074d820dc0a47aea903428ac1
Author: Benjamin Otte <otte redhat com>
Date:   Fri Jul 9 02:50:32 2021 +0200

    gdk: Move GL context construction to GdkGLContext
    
    Now that we have the display's context to hook into, we can use it to
    construct other GL contexts and don't need a GdkSurface vfunc anymore.
    
    This has the added benefit that backends can have different GdkGLContext
    classes on the display and get new GLContexts generated from them, so
    we get multiple GL backend support per GDK backend for free.
    
    I originally wanted to make this a vfunc on GdkGLContextClass, but
    it turns out all the abckends would just call g_object_new() anyway.

 gdk/gdkglcontext.c                    | 15 +++++++++++++++
 gdk/gdkglcontextprivate.h             |  2 ++
 gdk/gdksurface.c                      | 25 ++++++-------------------
 gdk/gdksurfaceprivate.h               |  2 --
 gdk/macos/gdkmacosdisplay.c           |  4 +++-
 gdk/macos/gdkmacosglcontext-private.h |  5 -----
 gdk/macos/gdkmacosglcontext.c         | 23 -----------------------
 gdk/macos/gdkmacossurface.c           | 16 ----------------
 gdk/wayland/gdkglcontext-wayland.c    | 13 -------------
 gdk/wayland/gdkglcontext-wayland.h    |  2 --
 gdk/wayland/gdksurface-wayland.c      |  1 -
 gdk/win32/gdkglcontext-win32.c        |  2 ++
 gdk/win32/gdkglcontext-win32.h        |  4 ----
 gdk/win32/gdksurface-win32.c          |  1 -
 gdk/x11/gdkdisplay-x11.c              |  7 ++++++-
 gdk/x11/gdkglcontext-egl.c            | 13 -------------
 gdk/x11/gdkglcontext-glx.c            | 13 -------------
 gdk/x11/gdkglcontext-x11.c            | 29 -----------------------------
 gdk/x11/gdkglcontext-x11.h            |  7 -------
 gdk/x11/gdksurface-x11.c              |  1 -
 20 files changed, 34 insertions(+), 151 deletions(-)
---
diff --git a/gdk/gdkglcontext.c b/gdk/gdkglcontext.c
index 06a9de118e..5c0193c0ec 100644
--- a/gdk/gdkglcontext.c
+++ b/gdk/gdkglcontext.c
@@ -451,6 +451,21 @@ gdk_gl_context_init (GdkGLContext *self)
   priv->use_es = -1;
 }
 
+/* Must have called gdk_display_prepare_gl() before */
+GdkGLContext *
+gdk_gl_context_new_for_surface (GdkSurface *surface)
+{
+  GdkDisplay *display = gdk_surface_get_display (surface);
+  GdkGLContext *shared = gdk_display_get_gl_context (display);
+
+  /* assert gdk_display_prepare_gl() had been called */
+  g_assert (shared);
+
+  return g_object_new (G_OBJECT_TYPE (shared),
+                       "surface", surface,
+                       NULL);
+}
+
 GdkGLContextPaintData *
 gdk_gl_context_get_paint_data (GdkGLContext *context)
 {
diff --git a/gdk/gdkglcontextprivate.h b/gdk/gdkglcontextprivate.h
index bbc7397d0a..e762c59075 100644
--- a/gdk/gdkglcontextprivate.h
+++ b/gdk/gdkglcontextprivate.h
@@ -87,6 +87,8 @@ typedef struct {
   guint use_es : 1;
 } GdkGLContextPaintData;
 
+GdkGLContext *          gdk_gl_context_new_for_surface          (GdkSurface      *surface);
+
 void                    gdk_gl_context_set_is_legacy            (GdkGLContext    *context,
                                                                  gboolean         is_legacy);
 
diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c
index f56b0e8c17..3f2b5189ff 100644
--- a/gdk/gdksurface.c
+++ b/gdk/gdksurface.c
@@ -1069,31 +1069,19 @@ GdkGLContext *
 gdk_surface_get_paint_gl_context (GdkSurface  *surface,
                                   GError     **error)
 {
-  GError *internal_error = NULL;
-
   if (!gdk_display_prepare_gl (surface->display, error))
     return NULL;
 
   if (surface->gl_paint_context == NULL)
     {
-      GdkSurfaceClass *class = GDK_SURFACE_GET_CLASS (surface);
-
-      surface->gl_paint_context =
-        class->create_gl_context (surface, &internal_error);
-    }
-
-  if (internal_error != NULL)
-    {
-      g_propagate_error (error, internal_error);
-      g_clear_object (&(surface->gl_paint_context));
-      return NULL;
+      surface->gl_paint_context = gdk_surface_create_gl_context (surface, error);
+      if (surface->gl_paint_context == NULL)
+        return NULL;
     }
 
-  gdk_gl_context_realize (surface->gl_paint_context, &internal_error);
-  if (internal_error != NULL)
+  if (!gdk_gl_context_realize (surface->gl_paint_context, error))
     {
-      g_propagate_error (error, internal_error);
-      g_clear_object (&(surface->gl_paint_context));
+      g_clear_object (&surface->gl_paint_context);
       return NULL;
     }
 
@@ -1124,8 +1112,7 @@ gdk_surface_create_gl_context (GdkSurface   *surface,
   if (!gdk_display_prepare_gl (surface->display, error))
     return NULL;
 
-  return GDK_SURFACE_GET_CLASS (surface)->create_gl_context (surface,
-                                                             error);
+  return gdk_gl_context_new_for_surface (surface);
 }
 
 /**
diff --git a/gdk/gdksurfaceprivate.h b/gdk/gdksurfaceprivate.h
index cf7a0f73b6..3ab692e19c 100644
--- a/gdk/gdksurfaceprivate.h
+++ b/gdk/gdksurfaceprivate.h
@@ -160,8 +160,6 @@ struct _GdkSurfaceClass
 
   void         (* set_opaque_region)      (GdkSurface      *surface,
                                            cairo_region_t *region);
-  GdkGLContext *(*create_gl_context)      (GdkSurface      *surface,
-                                           GError        **error);
   void         (* request_layout)         (GdkSurface     *surface);
   gboolean     (* compute_size)           (GdkSurface     *surface);
 };
diff --git a/gdk/macos/gdkmacosdisplay.c b/gdk/macos/gdkmacosdisplay.c
index 93afcce196..450ad2434d 100644
--- a/gdk/macos/gdkmacosdisplay.c
+++ b/gdk/macos/gdkmacosdisplay.c
@@ -641,7 +641,9 @@ static GdkGLContext *
 gdk_macos_display_init_gl (GdkDisplay  *display,
                            GError     **error)
 {
-  return _gdk_macos_gl_context_new (display, NULL, FALSE, NULL, error);
+  return g_object_new (GDK_TYPE_MACOS_GL_CONTEXT,
+                       "display", display,
+                       NULL);
 }
 
 static void
diff --git a/gdk/macos/gdkmacosglcontext-private.h b/gdk/macos/gdkmacosglcontext-private.h
index a09a2da905..533888cd2c 100644
--- a/gdk/macos/gdkmacosglcontext-private.h
+++ b/gdk/macos/gdkmacosglcontext-private.h
@@ -57,11 +57,6 @@ struct _GdkMacosGLContextClass
   GdkGLContextClass parent_class;
 };
 
-GdkGLContext *_gdk_macos_gl_context_new          (GdkMacosDisplay    *display,
-                                                  GdkMacosSurface    *surface,
-                                                  gboolean            attached,
-                                                  GdkGLContext       *share,
-                                                  GError            **error);
 
 G_END_DECLS
 
diff --git a/gdk/macos/gdkmacosglcontext.c b/gdk/macos/gdkmacosglcontext.c
index 9b23fe929a..8e79f7688f 100644
--- a/gdk/macos/gdkmacosglcontext.c
+++ b/gdk/macos/gdkmacosglcontext.c
@@ -522,27 +522,4 @@ gdk_macos_gl_context_init (GdkMacosGLContext *self)
 {
 }
 
-GdkGLContext *
-_gdk_macos_gl_context_new (GdkMacosDisplay  *display,
-                           GdkMacosSurface  *surface,
-                           gboolean          attached,
-                           GdkGLContext     *share,
-                           GError          **error)
-{
-  GdkMacosGLContext *context;
-
-  g_return_val_if_fail (GDK_IS_MACOS_SURFACE (surface), NULL);
-  g_return_val_if_fail (!share || GDK_IS_MACOS_GL_CONTEXT (share), NULL);
-
-  context = g_object_new (GDK_TYPE_MACOS_GL_CONTEXT,
-                          "display", display,
-                          "surface", surface,
-                          "shared-context", share,
-                          NULL);
-
-  context->is_attached = !!attached;
-
-  return GDK_GL_CONTEXT (context);
-}
-
 G_GNUC_END_IGNORE_DEPRECATIONS
diff --git a/gdk/macos/gdkmacossurface.c b/gdk/macos/gdkmacossurface.c
index aa8df2f35e..88be1f513d 100644
--- a/gdk/macos/gdkmacossurface.c
+++ b/gdk/macos/gdkmacossurface.c
@@ -358,21 +358,6 @@ gdk_macos_surface_drag_begin (GdkSurface         *surface,
   return GDK_DRAG (g_steal_pointer (&drag));
 }
 
-static GdkGLContext *
-gdk_macos_surface_create_gl_context (GdkSurface    *surface,
-                                     gboolean       attached,
-                                     GdkGLContext  *share,
-                                     GError       **error)
-{
-  GdkMacosSurface *self = (GdkMacosSurface *)surface;
-
-  g_assert (GDK_IS_MACOS_SURFACE (self));
-  g_assert (!share || GDK_IS_GL_CONTEXT (share));
-
-  return _gdk_macos_gl_context_new ((GdkMacosDisplay *) gdk_surface_get_display (surface),
-                                    self, attached, share, error);
-}
-
 static void
 gdk_macos_surface_destroy (GdkSurface *surface,
                            gboolean    foreign_destroy)
@@ -496,7 +481,6 @@ gdk_macos_surface_class_init (GdkMacosSurfaceClass *klass)
   object_class->get_property = gdk_macos_surface_get_property;
   object_class->set_property = gdk_macos_surface_set_property;
 
-  surface_class->create_gl_context = gdk_macos_surface_create_gl_context;
   surface_class->destroy = gdk_macos_surface_destroy;
   surface_class->drag_begin = gdk_macos_surface_drag_begin;
   surface_class->get_device_state = gdk_macos_surface_get_device_state;
diff --git a/gdk/wayland/gdkglcontext-wayland.c b/gdk/wayland/gdkglcontext-wayland.c
index 2a2e03300d..558c9cfed0 100644
--- a/gdk/wayland/gdkglcontext-wayland.c
+++ b/gdk/wayland/gdkglcontext-wayland.c
@@ -550,19 +550,6 @@ gdk_wayland_display_init_gl (GdkDisplay  *display,
                        NULL);
 }
 
-GdkGLContext *
-gdk_wayland_surface_create_gl_context (GdkSurface    *surface,
-                                       GError       **error)
-{
-  GdkWaylandGLContext *context;
-
-  context = g_object_new (GDK_TYPE_WAYLAND_GL_CONTEXT,
-                          "surface", surface,
-                          NULL);
-
-  return GDK_GL_CONTEXT (context);
-}
-
 static void
 gdk_wayland_gl_context_dispose (GObject *gobject)
 {
diff --git a/gdk/wayland/gdkglcontext-wayland.h b/gdk/wayland/gdkglcontext-wayland.h
index add5807849..0a60a467be 100644
--- a/gdk/wayland/gdkglcontext-wayland.h
+++ b/gdk/wayland/gdkglcontext-wayland.h
@@ -45,8 +45,6 @@ struct _GdkWaylandGLContextClass
 
 GdkGLContext *  gdk_wayland_display_init_gl                         (GdkDisplay        *display,
                                                                      GError           **error);
-GdkGLContext *  gdk_wayland_surface_create_gl_context               (GdkSurface        *surface,
-                                                                     GError           **error);
 
 G_END_DECLS
 
diff --git a/gdk/wayland/gdksurface-wayland.c b/gdk/wayland/gdksurface-wayland.c
index 404b10b226..5689241c7d 100644
--- a/gdk/wayland/gdksurface-wayland.c
+++ b/gdk/wayland/gdksurface-wayland.c
@@ -4224,7 +4224,6 @@ gdk_wayland_surface_class_init (GdkWaylandSurfaceClass *klass)
   impl_class->drag_begin = _gdk_wayland_surface_drag_begin;
   impl_class->get_scale_factor = gdk_wayland_surface_get_scale_factor;
   impl_class->set_opaque_region = gdk_wayland_surface_set_opaque_region;
-  impl_class->create_gl_context = gdk_wayland_surface_create_gl_context;
   impl_class->request_layout = gdk_wayland_surface_request_layout;
   impl_class->compute_size = gdk_wayland_surface_compute_size;
 }
diff --git a/gdk/win32/gdkglcontext-win32.c b/gdk/win32/gdkglcontext-win32.c
index 6a5e725e01..368b99d6a4 100644
--- a/gdk/win32/gdkglcontext-win32.c
+++ b/gdk/win32/gdkglcontext-win32.c
@@ -1159,6 +1159,7 @@ gdk_win32_gl_context_init (GdkWin32GLContext *self)
 {
 }
 
+#if 0
 GdkGLContext *
 _gdk_win32_surface_create_gl_context (GdkSurface *surface,
                                       GError **error)
@@ -1221,6 +1222,7 @@ _gdk_win32_surface_create_gl_context (GdkSurface *surface,
 
   return GDK_GL_CONTEXT (context);
 }
+#endif
 
 /**
  * gdk_win32_display_get_wgl_version:
diff --git a/gdk/win32/gdkglcontext-win32.h b/gdk/win32/gdkglcontext-win32.h
index 5a66334fca..b13fb04913 100644
--- a/gdk/win32/gdkglcontext-win32.h
+++ b/gdk/win32/gdkglcontext-win32.h
@@ -59,10 +59,6 @@ struct _GdkWin32GLContextClass
   GdkGLContextClass parent_class;
 };
 
-GdkGLContext *
-_gdk_win32_surface_create_gl_context (GdkSurface *window,
-                                      GError **error);
-
 void
 _gdk_win32_surface_invalidate_egl_framebuffer (GdkSurface *surface);
 
diff --git a/gdk/win32/gdksurface-win32.c b/gdk/win32/gdksurface-win32.c
index bca73c6edb..7e86a96725 100644
--- a/gdk/win32/gdksurface-win32.c
+++ b/gdk/win32/gdksurface-win32.c
@@ -4623,7 +4623,6 @@ gdk_win32_surface_class_init (GdkWin32SurfaceClass *klass)
 
   impl_class->destroy_notify = gdk_win32_surface_destroy_notify;
   impl_class->drag_begin = _gdk_win32_surface_drag_begin;
-  impl_class->create_gl_context = _gdk_win32_surface_create_gl_context;
   impl_class->get_scale_factor = _gdk_win32_surface_get_scale_factor;
   impl_class->request_layout = _gdk_win32_surface_request_layout;
   impl_class->compute_size = _gdk_win32_surface_compute_size;
diff --git a/gdk/x11/gdkdisplay-x11.c b/gdk/x11/gdkdisplay-x11.c
index 12b9beb5e7..647e6a6845 100644
--- a/gdk/x11/gdkdisplay-x11.c
+++ b/gdk/x11/gdkdisplay-x11.c
@@ -2911,7 +2911,12 @@ gdk_x11_display_init_gl (GdkDisplay  *display,
   if (!have_gl)
     return NULL;
 
-  return gdk_x11_surface_create_gl_context (display_x11->leader_gdk_surface, error);
+  if (display_x11->egl_display)
+    return g_object_new (GDK_TYPE_X11_GL_CONTEXT_EGL, "surface", display_x11->leader_gdk_surface, NULL);
+  else if (display_x11->glx_config != NULL)
+    return g_object_new (GDK_TYPE_X11_GL_CONTEXT_GLX, "surface", display_x11->leader_gdk_surface, NULL);
+  else
+    g_return_val_if_reached (NULL);
 }
 
 static void
diff --git a/gdk/x11/gdkglcontext-egl.c b/gdk/x11/gdkglcontext-egl.c
index 2248adaf2c..b5a571303c 100644
--- a/gdk/x11/gdkglcontext-egl.c
+++ b/gdk/x11/gdkglcontext-egl.c
@@ -742,19 +742,6 @@ gdk_x11_display_init_egl (GdkX11Display  *self,
   return TRUE;
 }
 
-GdkX11GLContext *
-gdk_x11_gl_context_egl_new (GdkSurface    *surface,
-                            GError       **error)
-{
-  GdkX11GLContextEGL *context;
-
-  context = g_object_new (GDK_TYPE_X11_GL_CONTEXT_EGL,
-                          "surface", surface,
-                          NULL);
-
-  return GDK_X11_GL_CONTEXT (context);
-}
-
 /**
  * gdk_x11_display_get_egl_version:
  * @display: (type GdkX11Display): a `GdkDisplay`
diff --git a/gdk/x11/gdkglcontext-glx.c b/gdk/x11/gdkglcontext-glx.c
index 37850edde7..1c2338e392 100644
--- a/gdk/x11/gdkglcontext-glx.c
+++ b/gdk/x11/gdkglcontext-glx.c
@@ -889,19 +889,6 @@ gdk_x11_display_create_glx_config (GdkX11Display  *self,
 
 #undef MAX_GLX_ATTRS
 
-GdkX11GLContext *
-gdk_x11_gl_context_glx_new (GdkSurface    *surface,
-                            GError       **error)
-{
-  GdkX11GLContextGLX *context;
-
-  return g_object_new (GDK_TYPE_X11_GL_CONTEXT_GLX,
-                       "surface", surface,
-                       NULL);
-
-  return GDK_X11_GL_CONTEXT (context);
-}
-
 /**
  * gdk_x11_display_get_glx_version:
  * @display: (type GdkX11Display): a `GdkDisplay`
diff --git a/gdk/x11/gdkglcontext-x11.c b/gdk/x11/gdkglcontext-x11.c
index 88453663e8..98210b5ef1 100644
--- a/gdk/x11/gdkglcontext-x11.c
+++ b/gdk/x11/gdkglcontext-x11.c
@@ -53,35 +53,6 @@ gdk_x11_gl_context_init (GdkX11GLContext *self)
   self->do_frame_sync = TRUE;
 }
 
-GdkGLContext *
-gdk_x11_surface_create_gl_context (GdkSurface    *surface,
-                                   GError       **error)
-{
-  GdkX11GLContext *context = NULL;
-  GdkX11Display *display_x11;
-  GdkDisplay *display;
-
-  display = gdk_surface_get_display (surface);
-  display_x11 = GDK_X11_DISPLAY (display);
-
-  if (display_x11->egl_display)
-    context = gdk_x11_gl_context_egl_new (surface, error);
-  else if (display_x11->glx_config != NULL)
-    context = gdk_x11_gl_context_glx_new (surface, error);
-  else
-    {
-      g_assert (display_x11->gl_error);
-      if (error)
-        *error = g_error_copy (display_x11->gl_error);
-      return NULL;
-    }
-
-  if (context == NULL)
-    return NULL;
-
-  return GDK_GL_CONTEXT (context);
-}
-
 gboolean
 gdk_x11_display_init_gl_backend (GdkX11Display  *self,
                                  Visual        **out_visual,
diff --git a/gdk/x11/gdkglcontext-x11.h b/gdk/x11/gdkglcontext-x11.h
index 70cee907ab..d1b6c8e106 100644
--- a/gdk/x11/gdkglcontext-x11.h
+++ b/gdk/x11/gdkglcontext-x11.h
@@ -63,9 +63,6 @@ gboolean                gdk_x11_display_init_gl_backend         (GdkX11Display *
                                                                  int           *out_depth,
                                                                  GError       **error);
 
-GdkGLContext *          gdk_x11_surface_create_gl_context       (GdkSurface    *window,
-                                                                 GError       **error);
-
 /* GLX */
 #define GDK_TYPE_X11_GL_CONTEXT_GLX     (gdk_x11_gl_context_glx_get_type())
 #define GDK_X11_GL_CONTEXT_GLX(obj)     (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDK_TYPE_X11_GL_CONTEXT_GLX, 
GdkX11GLContextGLX))
@@ -80,8 +77,6 @@ gboolean                gdk_x11_display_init_glx                (GdkX11Display *
 void                    gdk_x11_surface_destroy_glx_drawable    (GdkX11Surface *self);
 
 GType                   gdk_x11_gl_context_glx_get_type         (void) G_GNUC_CONST;
-GdkX11GLContext *       gdk_x11_gl_context_glx_new              (GdkSurface    *surface,
-                                                                 GError       **error);
 
 
 /* EGL */
@@ -99,8 +94,6 @@ gboolean                gdk_x11_display_init_egl                (GdkX11Display *
 void                    gdk_x11_surface_destroy_egl_surface     (GdkX11Surface *self);
 
 GType                   gdk_x11_gl_context_egl_get_type         (void) G_GNUC_CONST;
-GdkX11GLContext *       gdk_x11_gl_context_egl_new              (GdkSurface    *surface,
-                                                                 GError       **error);
 
 G_END_DECLS
 
diff --git a/gdk/x11/gdksurface-x11.c b/gdk/x11/gdksurface-x11.c
index 7467e04228..1339e2c2b9 100644
--- a/gdk/x11/gdksurface-x11.c
+++ b/gdk/x11/gdksurface-x11.c
@@ -4818,7 +4818,6 @@ gdk_x11_surface_class_init (GdkX11SurfaceClass *klass)
   impl_class->drag_begin = _gdk_x11_surface_drag_begin;
   impl_class->get_scale_factor = gdk_x11_surface_get_scale_factor;
   impl_class->set_opaque_region = gdk_x11_surface_set_opaque_region;
-  impl_class->create_gl_context = gdk_x11_surface_create_gl_context;
   impl_class->request_layout = gdk_x11_surface_request_layout;
   impl_class->compute_size = gdk_x11_surface_compute_size;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]