gl: Require EGL_KHR_surfaceless_context with egl
authorBenjamin Otte <otte@redhat.com>
Wed, 7 Jul 2021 01:00:09 +0000 (03:00 +0200)
committerBenjamin Otte <otte@redhat.com>
Thu, 22 Jul 2021 14:27:31 +0000 (16:27 +0200)
The code to create and manage a fake egl surface to bind to is
complex and completely untested because everyone seems to support this
extension.

nvidia and Mesa do support it and according to Mesa devs, adding support
in a new driver is rather simple and Mesa drivers gain that feature
automatically, so all future drivers shoould have it.

gdk/wayland/gdkdisplay-wayland.h
gdk/wayland/gdkglcontext-wayland.c
gdk/wayland/gdkprivate-wayland.h
gdk/wayland/gdksurface-wayland.c
gdk/x11/gdkdisplay-x11.h
gdk/x11/gdkglcontext-egl.c

index d431405570908201c4a2698efa903f8a531f4947..66e8020b283a2909ff1d5779ecbdddab4bcdf1af 100644 (file)
@@ -159,7 +159,6 @@ struct _GdkWaylandDisplay
 
   guint have_egl_buffer_age : 1;
   guint have_egl_swap_buffers_with_damage : 1;
-  guint have_egl_surfaceless_context : 1;
 };
 
 struct _GdkWaylandDisplayClass
index 2e83d501f189bd97cc5de4dc1613cd0e017b0540..de60ebc820f407ae4ad88b75687e419f2aca7bf4 100644 (file)
@@ -469,6 +469,15 @@ gdk_wayland_display_init_gl (GdkDisplay  *display,
       return NULL;
     }
 
+  if (!epoxy_has_egl_extension (dpy, "EGL_KHR_surfaceless_context"))
+    {
+      eglTerminate (dpy);
+      g_set_error_literal (error, GDK_GL_ERROR,
+                           GDK_GL_ERROR_UNSUPPORTED_PROFILE,
+                           _("Surfaceless contexts are not supported on this EGL implementation"));
+      return NULL;
+    }
+
   display_wayland->egl_config = get_eglconfig (dpy);
   if (!display_wayland->egl_config)
     {
@@ -489,9 +498,6 @@ gdk_wayland_display_init_gl (GdkDisplay  *display,
   display_wayland->have_egl_swap_buffers_with_damage =
     epoxy_has_egl_extension (dpy, "EGL_EXT_swap_buffers_with_damage");
 
-  display_wayland->have_egl_surfaceless_context =
-    epoxy_has_egl_extension (dpy, "EGL_KHR_surfaceless_context");
-
   GDK_DISPLAY_NOTE (display, OPENGL,
             g_message ("EGL API version %d.%d found\n"
                        " - Vendor: %s\n"
@@ -572,13 +578,7 @@ gdk_wayland_display_make_gl_context_current (GdkDisplay   *display,
   if (gdk_draw_context_is_in_frame (GDK_DRAW_CONTEXT (context)))
     egl_surface = gdk_wayland_surface_get_egl_surface (surface);
   else
-    {
-      if (display_wayland->have_egl_surfaceless_context)
-        egl_surface = EGL_NO_SURFACE;
-      else
-        egl_surface = gdk_wayland_surface_get_dummy_egl_surface (surface,
-                                                                 display_wayland->egl_config);
-    }
+    egl_surface = EGL_NO_SURFACE;
 
   if (!eglMakeCurrent (display_wayland->egl_display, egl_surface,
                        egl_surface, context_wayland->egl_context))
index 2177cef90d65882c59f947ab392da6aa1dfaa501..09f41606f35db93ceebf1bd1c1988d19ede58f47 100644 (file)
@@ -182,9 +182,6 @@ cairo_surface_t * _gdk_wayland_display_create_shm_surface (GdkWaylandDisplay *di
 struct wl_buffer *_gdk_wayland_shm_surface_get_wl_buffer (cairo_surface_t *surface);
 gboolean _gdk_wayland_is_shm_surface (cairo_surface_t *surface);
 
-EGLSurface gdk_wayland_surface_get_dummy_egl_surface (GdkSurface *surface,
-                                                     EGLConfig config);
-
 struct gtk_surface1 * gdk_wayland_surface_get_gtk_surface (GdkSurface *surface);
 
 void gdk_wayland_seat_set_global_cursor (GdkSeat   *seat,
index 124b8103945b9e5fdb4ad1e558c331e146974c97..404b10b226ed43b2bdbcab7c98df207afa2ad908 100644 (file)
@@ -103,7 +103,6 @@ struct _GdkWaylandSurface
 
     struct gtk_surface1  *gtk_surface;
     struct wl_egl_window *egl_window;
-    struct wl_egl_window *dummy_egl_window;
     struct zxdg_exported_v1 *xdg_exported;
     struct org_kde_kwin_server_decoration *server_decoration;
   } display_server;
@@ -111,7 +110,6 @@ struct _GdkWaylandSurface
   struct wl_event_queue *event_queue;
 
   EGLSurface egl_surface;
-  EGLSurface dummy_egl_surface;
 
   uint32_t reposition_token;
   uint32_t received_reposition_token;
@@ -2901,18 +2899,6 @@ gdk_wayland_surface_hide_surface (GdkSurface *surface)
 
   if (impl->display_server.wl_surface)
     {
-      if (impl->dummy_egl_surface)
-        {
-          eglDestroySurface (display_wayland->egl_display, impl->dummy_egl_surface);
-          impl->dummy_egl_surface = NULL;
-        }
-
-      if (impl->display_server.dummy_egl_window)
-        {
-          wl_egl_window_destroy (impl->display_server.dummy_egl_window);
-          impl->display_server.dummy_egl_window = NULL;
-        }
-
       if (impl->egl_surface)
         {
           eglDestroySurface (display_wayland->egl_display, impl->egl_surface);
@@ -4325,29 +4311,6 @@ gdk_wayland_surface_get_egl_surface (GdkSurface *surface)
   return impl->egl_surface;
 }
 
-EGLSurface
-gdk_wayland_surface_get_dummy_egl_surface (GdkSurface *surface,
-                                           EGLConfig   config)
-{
-  GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (gdk_surface_get_display (surface));
-  GdkWaylandSurface *impl;
-
-  g_return_val_if_fail (GDK_IS_WAYLAND_SURFACE (surface), NULL);
-
-  impl = GDK_WAYLAND_SURFACE (surface);
-
-  if (impl->dummy_egl_surface == NULL)
-    {
-      impl->display_server.dummy_egl_window =
-        wl_egl_window_create (impl->display_server.wl_surface, 1, 1);
-
-      impl->dummy_egl_surface =
-        eglCreateWindowSurface (display->egl_display, config, impl->display_server.dummy_egl_window, NULL);
-    }
-
-  return impl->dummy_egl_surface;
-}
-
 struct gtk_surface1 *
 gdk_wayland_surface_get_gtk_surface (GdkSurface *surface)
 {
index 0bdc4488f01c1f1e50214f193a0dd7eaf3fd0493..2a7356f752b2a6342597f44ebe50cbd6733f414d 100644 (file)
@@ -164,7 +164,6 @@ struct _GdkX11Display
   guint has_egl_khr_create_context : 1;
   guint has_egl_buffer_age : 1;
   guint has_egl_swap_buffers_with_damage : 1;
-  guint has_egl_surfaceless_context : 1;
 };
 
 struct _GdkX11DisplayClass
index 280df54b7b0ea4c7976f348cb0b35dc511120721..632209a43fb35ef7b765298f0278847dcf25569b 100644 (file)
@@ -631,6 +631,16 @@ gdk_x11_display_init_egl (GdkX11Display  *self,
       return FALSE;
     }
 
+  if (!epoxy_has_egl_extension (self->egl_display, "EGL_KHR_surfaceless_context"))
+    {
+      eglTerminate (dpy);
+      self->egl_display = NULL;
+      g_set_error_literal (error, GDK_GL_ERROR,
+                           GDK_GL_ERROR_UNSUPPORTED_PROFILE,
+                           _("Surfaceless contexts are not supported on this EGL implementation"));
+      return FALSE;
+    }
+
   if (!gdk_x11_display_create_egl_config (self, force, out_visual, out_depth, error))
     {
       eglTerminate (self->egl_display);
@@ -646,8 +656,6 @@ gdk_x11_display_init_egl (GdkX11Display  *self,
     epoxy_has_egl_extension (self->egl_display, "EGL_EXT_buffer_age");
   self->has_egl_swap_buffers_with_damage =
     epoxy_has_egl_extension (self->egl_display, "EGL_EXT_swap_buffers_with_damage");
-  self->has_egl_surfaceless_context =
-    epoxy_has_egl_extension (self->egl_display, "EGL_KHR_surfaceless_context");
 
   GDK_DISPLAY_NOTE (display, OPENGL,
                     g_message ("EGL found\n"
@@ -657,15 +665,13 @@ gdk_x11_display_init_egl (GdkX11Display  *self,
                                " - Checked extensions:\n"
                                "\t* EGL_KHR_create_context: %s\n"
                                "\t* EGL_EXT_buffer_age: %s\n"
-                               "\t* EGL_EXT_swap_buffers_with_damage: %s\n"
-                               "\t* EGL_KHR_surfaceless_context: %s\n",
+                               "\t* EGL_EXT_swap_buffers_with_damage: %s\n",
                                eglQueryString (self->egl_display, EGL_VERSION),
                                eglQueryString (self->egl_display, EGL_VENDOR),
                                eglQueryString (self->egl_display, EGL_CLIENT_APIS),
                                self->has_egl_khr_create_context ? "yes" : "no",
                                self->has_egl_buffer_age ? "yes" : "no",
-                               self->has_egl_swap_buffers_with_damage ? "yes" : "no",
-                               self->has_egl_surfaceless_context ? "yes" : "no"));
+                               self->has_egl_swap_buffers_with_damage ? "yes" : "no"));
 
   return TRUE;
 }
@@ -711,12 +717,7 @@ gdk_x11_gl_context_egl_make_current (GdkDisplay   *display,
   if (gdk_draw_context_is_in_frame (GDK_DRAW_CONTEXT (context)))
     egl_surface = gdk_x11_surface_get_egl_surface (surface);
   else
-    {
-      if (display_x11->has_egl_surfaceless_context)
-        egl_surface = EGL_NO_SURFACE;
-      else
-        egl_surface = gdk_x11_surface_get_egl_surface (display_x11->leader_gdk_surface);
-    }
+    egl_surface = EGL_NO_SURFACE;
 
   GDK_DISPLAY_NOTE (display, OPENGL,
                     g_message ("Making EGL context %p current to surface %p",