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>
This commit is contained in:
Jonas Ådahl 2021-04-13 15:39:55 +02:00
parent 173d895d53
commit 5e45dc15b6
5 changed files with 35 additions and 5 deletions

View File

@ -774,3 +774,11 @@ cogl_renderer_create_dma_buf (CoglRenderer *renderer,
return NULL; return NULL;
} }
void
cogl_renderer_bind_api (CoglRenderer *renderer)
{
const CoglWinsysVtable *winsys = _cogl_renderer_get_winsys (renderer);
winsys->renderer_bind_api (renderer);
}

View File

@ -419,6 +419,12 @@ cogl_renderer_create_dma_buf (CoglRenderer *renderer,
int height, int height,
GError **error); GError **error);
/**
* cogl_renderer_bind_api: (skip)
*/
COGL_EXPORT void
cogl_renderer_bind_api (CoglRenderer *renderer);
G_END_DECLS G_END_DECLS
#endif /* __COGL_RENDERER_H__ */ #endif /* __COGL_RENDERER_H__ */

View File

@ -134,6 +134,16 @@ _cogl_winsys_renderer_disconnect (CoglRenderer *renderer)
g_assert_not_reached (); 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 */ /* Updates all the function pointers */
static void static void
check_egl_extensions (CoglRenderer *renderer) 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); g_return_val_if_fail (egl_display->egl_context == NULL, TRUE);
if (renderer->driver == COGL_DRIVER_GL || cogl_renderer_bind_api (renderer);
renderer->driver == COGL_DRIVER_GL3)
eglBindAPI (EGL_OPENGL_API);
else if (renderer->driver == COGL_DRIVER_GLES2)
eglBindAPI (EGL_OPENGL_ES_API);
cogl_display_egl_determine_attributes (display, cogl_display_egl_determine_attributes (display,
&display->onscreen_template->config, &display->onscreen_template->config,
@ -620,6 +626,7 @@ static CoglWinsysVtable _cogl_winsys_vtable =
.renderer_get_proc_address = _cogl_winsys_renderer_get_proc_address, .renderer_get_proc_address = _cogl_winsys_renderer_get_proc_address,
.renderer_connect = _cogl_winsys_renderer_connect, .renderer_connect = _cogl_winsys_renderer_connect,
.renderer_disconnect = _cogl_winsys_renderer_disconnect, .renderer_disconnect = _cogl_winsys_renderer_disconnect,
.renderer_bind_api = _cogl_winsys_renderer_bind_api,
.display_setup = _cogl_winsys_display_setup, .display_setup = _cogl_winsys_display_setup,
.display_destroy = _cogl_winsys_display_destroy, .display_destroy = _cogl_winsys_display_destroy,
.context_init = _cogl_winsys_context_init, .context_init = _cogl_winsys_context_init,

View File

@ -297,6 +297,11 @@ _cogl_winsys_renderer_outputs_changed (CoglRenderer *renderer)
update_all_outputs (renderer); update_all_outputs (renderer);
} }
static void
_cogl_winsys_renderer_bind_api (CoglRenderer *renderer)
{
}
static gboolean static gboolean
resolve_core_glx_functions (CoglRenderer *renderer, resolve_core_glx_functions (CoglRenderer *renderer,
GError **error) GError **error)
@ -1419,6 +1424,7 @@ static CoglWinsysVtable _cogl_winsys_vtable =
.renderer_connect = _cogl_winsys_renderer_connect, .renderer_connect = _cogl_winsys_renderer_connect,
.renderer_disconnect = _cogl_winsys_renderer_disconnect, .renderer_disconnect = _cogl_winsys_renderer_disconnect,
.renderer_outputs_changed = _cogl_winsys_renderer_outputs_changed, .renderer_outputs_changed = _cogl_winsys_renderer_outputs_changed,
.renderer_bind_api = _cogl_winsys_renderer_bind_api,
.display_setup = _cogl_winsys_display_setup, .display_setup = _cogl_winsys_display_setup,
.display_destroy = _cogl_winsys_display_destroy, .display_destroy = _cogl_winsys_display_destroy,
.context_init = _cogl_winsys_context_init, .context_init = _cogl_winsys_context_init,

View File

@ -97,6 +97,9 @@ typedef struct _CoglWinsysVtable
int height, int height,
GError **error); GError **error);
void
(*renderer_bind_api) (CoglRenderer *renderer);
gboolean gboolean
(*context_init) (CoglContext *context, GError **error); (*context_init) (CoglContext *context, GError **error);