From b56142942dd0838805a574bc00d15efcef3dfc59 Mon Sep 17 00:00:00 2001
From: Jakob Bornecrantz <jakob@collabora.com>
Date: Sat, 11 Jun 2022 13:23:40 +0100
Subject: [PATCH] c/client: Tidy and reorg flow in egl create function

---
 src/xrt/compositor/client/comp_egl_client.c | 29 +++++++++++++++++----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/src/xrt/compositor/client/comp_egl_client.c b/src/xrt/compositor/client/comp_egl_client.c
index f19c5c051..dbac27ef3 100644
--- a/src/xrt/compositor/client/comp_egl_client.c
+++ b/src/xrt/compositor/client/comp_egl_client.c
@@ -269,6 +269,11 @@ xrt_gfx_provider_create_gl_egl(struct xrt_compositor_native *xcn,
 {
 	log_level = debug_get_log_option_egl_log();
 
+
+	/*
+	 * Init EGL functions
+	 */
+
 	gladLoadEGL(display, get_gl_procaddr);
 
 	if (config == EGL_NO_CONFIG_KHR && !EGL_KHR_no_config_context) {
@@ -279,6 +284,21 @@ xrt_gfx_provider_create_gl_egl(struct xrt_compositor_native *xcn,
 	// On Android this extension is 'hidden'.
 	ensure_native_fence_is_loaded(display, get_gl_procaddr);
 
+
+	/*
+	 * Get client type.
+	 */
+
+	EGLint egl_client_type;
+	if (!eglQueryContext(display, context, EGL_CONTEXT_CLIENT_TYPE, &egl_client_type)) {
+		return XRT_ERROR_OPENGL;
+	}
+
+
+	/*
+	 * Make current.
+	 */
+
 	// Save old EGL display, context and drawables.
 	struct client_egl_context old = {0};
 	save_context(&old);
@@ -296,11 +316,10 @@ xrt_gfx_provider_create_gl_egl(struct xrt_compositor_native *xcn,
 		return XRT_ERROR_OPENGL;
 	}
 
-	EGLint egl_client_type;
-	if (!eglQueryContext(display, context, EGL_CONTEXT_CLIENT_TYPE, &egl_client_type)) {
-		restore_context(&old);
-		return XRT_ERROR_OPENGL;
-	}
+
+	/*
+	 * Load GL functions.
+	 */
 
 	switch (egl_client_type) {
 	case EGL_OPENGL_API: