[gtk/wip/otte/gleanup] x11: Store the EGL surface in the GdkSurfaceX11



commit 50a685eec655d8595b61cd572c15f77b6277096d
Author: Benjamin Otte <otte redhat com>
Date:   Thu Jun 10 23:10:22 2021 +0200

    x11: Store the EGL surface in the GdkSurfaceX11
    
    Avoids having to use private data, though the benefit is somewhat
    limited as we still have to put the destructor in the egl code and can't
    just put it in gdk_surface_x11_finalize().

 gdk/x11/gdkglcontext-egl.c | 37 ++++++++++++++++++++++---------------
 gdk/x11/gdkglcontext-x11.h |  1 +
 gdk/x11/gdksurface-x11.c   |  2 ++
 gdk/x11/gdksurface-x11.h   |  1 +
 4 files changed, 26 insertions(+), 15 deletions(-)
---
diff --git a/gdk/x11/gdkglcontext-egl.c b/gdk/x11/gdkglcontext-egl.c
index 3dc86cd9ed..a28d67e1d9 100644
--- a/gdk/x11/gdkglcontext-egl.c
+++ b/gdk/x11/gdkglcontext-egl.c
@@ -139,6 +139,20 @@ gdk_x11_display_get_egl_display (GdkDisplay *display)
   return self->egl_display;
 }
 
+void
+gdk_x11_surface_destroy_egl_surface (GdkX11Surface *self)
+{
+  GdkX11Display *display_x11;
+
+  if (self->egl_surface == NULL)
+    return;
+
+  display_x11 = GDK_X11_DISPLAY (gdk_surface_get_display (GDK_SURFACE (self)));
+
+  eglDestroySurface (display_x11->egl_display, self->egl_surface);
+  self->egl_surface = NULL;
+}
+
 static XVisualInfo *
 get_visual_info_for_egl_config (GdkDisplay *display,
                                 EGLConfig   egl_config)
@@ -239,27 +253,20 @@ gdk_x11_display_get_egl_dummy_surface (GdkDisplay *display,
 static EGLSurface
 gdk_x11_surface_get_egl_surface (GdkSurface *surface)
 {
-  GdkDisplay *display = gdk_surface_get_display (surface);
+  GdkX11Surface *self = GDK_X11_SURFACE (surface);
+  GdkDisplay *display = gdk_surface_get_display (GDK_SURFACE (self));
   GdkX11Display *display_x11 = GDK_X11_DISPLAY (display);
-  DrawableInfo *info;
 
-  info = g_object_get_data (G_OBJECT (surface), "-gdk-x11-egl-drawable");
-  if (info != NULL)
-    return info->egl_surface;
+  if (self->egl_surface)
+    return self->egl_surface;
 
-  info = g_new0 (DrawableInfo, 1);
-  info->egl_display = display_x11->egl_display;
-  info->egl_config = display_x11->egl_config;
-  info->egl_surface =
-    eglCreateWindowSurface (info->egl_display, info->egl_config,
+  self->egl_surface =
+    eglCreateWindowSurface (display_x11->egl_display, 
+                            display_x11->egl_config,
                             (EGLNativeWindowType) gdk_x11_surface_get_xid (surface),
                             NULL);
 
-  g_object_set_data_full (G_OBJECT (surface), "-gdk-x11-egl-drawable",
-                          info,
-                          drawable_info_free);
-
-  return info->egl_surface;
+  return self->egl_surface;
 }
 
 static void
diff --git a/gdk/x11/gdkglcontext-x11.h b/gdk/x11/gdkglcontext-x11.h
index 97583133f2..ca296a2c97 100644
--- a/gdk/x11/gdkglcontext-x11.h
+++ b/gdk/x11/gdkglcontext-x11.h
@@ -93,6 +93,7 @@ gboolean                gdk_x11_gl_context_glx_make_current     (GdkDisplay    *
 typedef struct _GdkX11GLContextEGL      GdkX11GLContextEGL;
 
 gboolean                gdk_x11_display_init_egl                (GdkX11Display *display_x11);
+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,
diff --git a/gdk/x11/gdksurface-x11.c b/gdk/x11/gdksurface-x11.c
index add72799f6..0fb8b38451 100644
--- a/gdk/x11/gdksurface-x11.c
+++ b/gdk/x11/gdksurface-x11.c
@@ -757,6 +757,8 @@ gdk_x11_surface_finalize (GObject *object)
 
   _gdk_x11_surface_grab_check_destroy (GDK_SURFACE (impl));
 
+  gdk_x11_surface_destroy_egl_surface (impl);
+
   if (!GDK_SURFACE_DESTROYED (impl))
     {
       GdkDisplay *display = GDK_SURFACE_DISPLAY (GDK_SURFACE (impl));
diff --git a/gdk/x11/gdksurface-x11.h b/gdk/x11/gdksurface-x11.h
index 89f4b12845..cb8f92307f 100644
--- a/gdk/x11/gdksurface-x11.h
+++ b/gdk/x11/gdksurface-x11.h
@@ -87,6 +87,7 @@ struct _GdkX11Surface
   guint compute_size_source_id;
 
   cairo_surface_t *cairo_surface;
+  /* EGLSurface */ gpointer egl_surface;
 
   int abs_x;
   int abs_y;


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