[mutter] cogl/renderer: Add API to bind the right EGL API



commit 5e45dc15b6c9ac5a109a4521637afa406da580ca
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Tue Apr 13 15:39:55 2021 +0200

    cogl/renderer: Add API to bind the right EGL API
    
    We need to call eglBindAPI() with GLES before we setup the secondary
    GPU blit. We've been lucky not really needing this, as it has been
    GLES default, which is what the secondary blit uses, in order to not
    depend on the default, or if we want to create the secondary blit
    objects after initializing cogl, we must make sure to bind the right API
    at the right time.
    
    As we need to bind the GLES API when setting up the secondary blit, we
    need to make sure that cogl gets the right API bound when that's done,
    so Cogl can continue working. For this, add a "bind_api()" method on the
    CoglRenderer object, that will know what API is correct to bind.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1828>

 cogl/cogl/cogl-renderer.c              |  8 ++++++++
 cogl/cogl/cogl-renderer.h              |  6 ++++++
 cogl/cogl/winsys/cogl-winsys-egl.c     | 17 ++++++++++++-----
 cogl/cogl/winsys/cogl-winsys-glx.c     |  6 ++++++
 cogl/cogl/winsys/cogl-winsys-private.h |  3 +++
 5 files changed, 35 insertions(+), 5 deletions(-)
---
diff --git a/cogl/cogl/cogl-renderer.c b/cogl/cogl/cogl-renderer.c
index 199dd175e9..d815757a0c 100644
--- a/cogl/cogl/cogl-renderer.c
+++ b/cogl/cogl/cogl-renderer.c
@@ -774,3 +774,11 @@ cogl_renderer_create_dma_buf (CoglRenderer  *renderer,
 
   return NULL;
 }
+
+void
+cogl_renderer_bind_api (CoglRenderer *renderer)
+{
+  const CoglWinsysVtable *winsys = _cogl_renderer_get_winsys (renderer);
+
+  winsys->renderer_bind_api (renderer);
+}
diff --git a/cogl/cogl/cogl-renderer.h b/cogl/cogl/cogl-renderer.h
index b8eb6e5450..70910c07b4 100644
--- a/cogl/cogl/cogl-renderer.h
+++ b/cogl/cogl/cogl-renderer.h
@@ -419,6 +419,12 @@ cogl_renderer_create_dma_buf (CoglRenderer  *renderer,
                               int            height,
                               GError       **error);
 
+/**
+ * cogl_renderer_bind_api: (skip)
+ */
+COGL_EXPORT void
+cogl_renderer_bind_api (CoglRenderer *renderer);
+
 G_END_DECLS
 
 #endif /* __COGL_RENDERER_H__ */
diff --git a/cogl/cogl/winsys/cogl-winsys-egl.c b/cogl/cogl/winsys/cogl-winsys-egl.c
index 85409433d3..8ea1008b51 100644
--- a/cogl/cogl/winsys/cogl-winsys-egl.c
+++ b/cogl/cogl/winsys/cogl-winsys-egl.c
@@ -134,6 +134,16 @@ _cogl_winsys_renderer_disconnect (CoglRenderer *renderer)
   g_assert_not_reached ();
 }
 
+static void
+_cogl_winsys_renderer_bind_api (CoglRenderer *renderer)
+{
+  if (renderer->driver == COGL_DRIVER_GL ||
+      renderer->driver == COGL_DRIVER_GL3)
+    eglBindAPI (EGL_OPENGL_API);
+  else if (renderer->driver == COGL_DRIVER_GLES2)
+    eglBindAPI (EGL_OPENGL_ES_API);
+}
+
 /* Updates all the function pointers */
 static void
 check_egl_extensions (CoglRenderer *renderer)
@@ -364,11 +374,7 @@ try_create_context (CoglDisplay *display,
 
   g_return_val_if_fail (egl_display->egl_context == NULL, TRUE);
 
-  if (renderer->driver == COGL_DRIVER_GL ||
-      renderer->driver == COGL_DRIVER_GL3)
-    eglBindAPI (EGL_OPENGL_API);
-  else if (renderer->driver == COGL_DRIVER_GLES2)
-    eglBindAPI (EGL_OPENGL_ES_API);
+  cogl_renderer_bind_api (renderer);
 
   cogl_display_egl_determine_attributes (display,
                                          &display->onscreen_template->config,
@@ -620,6 +626,7 @@ static CoglWinsysVtable _cogl_winsys_vtable =
     .renderer_get_proc_address = _cogl_winsys_renderer_get_proc_address,
     .renderer_connect = _cogl_winsys_renderer_connect,
     .renderer_disconnect = _cogl_winsys_renderer_disconnect,
+    .renderer_bind_api = _cogl_winsys_renderer_bind_api,
     .display_setup = _cogl_winsys_display_setup,
     .display_destroy = _cogl_winsys_display_destroy,
     .context_init = _cogl_winsys_context_init,
diff --git a/cogl/cogl/winsys/cogl-winsys-glx.c b/cogl/cogl/winsys/cogl-winsys-glx.c
index a8453dd48e..f3738e07c0 100644
--- a/cogl/cogl/winsys/cogl-winsys-glx.c
+++ b/cogl/cogl/winsys/cogl-winsys-glx.c
@@ -297,6 +297,11 @@ _cogl_winsys_renderer_outputs_changed (CoglRenderer *renderer)
   update_all_outputs (renderer);
 }
 
+static void
+_cogl_winsys_renderer_bind_api (CoglRenderer *renderer)
+{
+}
+
 static gboolean
 resolve_core_glx_functions (CoglRenderer *renderer,
                             GError **error)
@@ -1419,6 +1424,7 @@ static CoglWinsysVtable _cogl_winsys_vtable =
     .renderer_connect = _cogl_winsys_renderer_connect,
     .renderer_disconnect = _cogl_winsys_renderer_disconnect,
     .renderer_outputs_changed = _cogl_winsys_renderer_outputs_changed,
+    .renderer_bind_api = _cogl_winsys_renderer_bind_api,
     .display_setup = _cogl_winsys_display_setup,
     .display_destroy = _cogl_winsys_display_destroy,
     .context_init = _cogl_winsys_context_init,
diff --git a/cogl/cogl/winsys/cogl-winsys-private.h b/cogl/cogl/winsys/cogl-winsys-private.h
index 29bea6aa4a..b323a704d4 100644
--- a/cogl/cogl/winsys/cogl-winsys-private.h
+++ b/cogl/cogl/winsys/cogl-winsys-private.h
@@ -97,6 +97,9 @@ typedef struct _CoglWinsysVtable
                               int            height,
                               GError       **error);
 
+  void
+  (*renderer_bind_api) (CoglRenderer *renderer);
+
   gboolean
   (*context_init) (CoglContext *context, GError **error);
 


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