[4/6] libcamera: egl: Separate proc address search into its own function
diff mbox series

Message ID 20261126110422.362455-5-remy.alipoursafari@collabora.com
State New
Headers show
Series
  • benchmark: Add GPU benchmarking to SoftISP eGL
Related show

Commit Message

Remy Alipoursafari Nov. 26, 2026, 11:03 a.m. UTC
Separates searching for proc addresses using eglGetProcAddress into its
own function so that future searches can be more easily added.

Signed-off-by: Remy Alipoursafari <remy.alipoursafari@collabora.com>
Reviewed-by: Robert Mader <robert.mader@collabora.com>
---
 include/libcamera/internal/egl.h |  2 ++
 src/libcamera/egl.cpp            | 41 +++++++++++++++++++-------------
 2 files changed, 26 insertions(+), 17 deletions(-)

Patch
diff mbox series

diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h
index 10a9a3c5..6a146405 100644
--- a/include/libcamera/internal/egl.h
+++ b/include/libcamera/internal/egl.h
@@ -165,5 +165,7 @@  private:
 		PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
 		PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR;
 	} vtable_ = {};
+
+	void locateProcAddresses(VTable *vtable);
 };
 } //namespace libcamera
diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp
index f88fb7c4..df0bba8e 100644
--- a/src/libcamera/egl.cpp
+++ b/src/libcamera/egl.cpp
@@ -414,23 +414,7 @@  int eGL::initEGLContext()
 	eglExtensions_ = eglQueryString(display_, EGL_EXTENSIONS);
 	LOG(eGL, Info) << "EGL: EGL_EXTENSIONS: " << eglExtensions_;
 
-	vtable.eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)eglGetProcAddress("eglCreateImageKHR");
-	if (!vtable.eglCreateImageKHR) {
-		LOG(eGL, Error) << "eglCreateImageKHR not found";
-		goto fail;
-	}
-
-	vtable.eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)eglGetProcAddress("eglDestroyImageKHR");
-	if (!vtable.eglDestroyImageKHR) {
-		LOG(eGL, Error) << "eglDestroyImageKHR not found";
-		goto fail;
-	}
-
-	vtable.glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES");
-	if (!vtable.glEGLImageTargetTexture2DOES) {
-		LOG(eGL, Error) << "glEGLImageTargetTexture2DOES not found";
-		goto fail;
-	}
+	locateProcAddresses(&vtable);
 
 	if (eglChooseConfig(display_, configAttribs, &config, 1, &numConfigs) != EGL_TRUE) {
 		LOG(eGL, Error) << "eglChooseConfig fail";
@@ -586,6 +570,29 @@  void eGL::makeCurrent()
 	}
 }
 
+/**
+ * \brief Gets the addresses for EGL extension functions
+ * \param[in,out] vtable VTable to store the function addresses
+ *
+ * Locates the relevant runtime function addresses needed to fill the VTable.
+ * This does not fail when a function pointer is not found, nor does it validate
+ * the functions are available for the GL context, so it is also expected to
+ * also check the extension availability.
+ */
+void eGL::locateProcAddresses(VTable *vtable)
+{
+#define GET_PROC_ADDRESS(location, name, type) ({        \
+	location = (type)eglGetProcAddress(name);        \
+	if (!location) {                                 \
+		LOG(eGL, Debug) << name << " not found"; \
+	}                                                \
+})
+
+	GET_PROC_ADDRESS(vtable->eglCreateImageKHR, "eglCreateImageKHR", PFNEGLCREATEIMAGEKHRPROC);
+	GET_PROC_ADDRESS(vtable->eglDestroyImageKHR, "eglDestroyImageKHR", PFNEGLDESTROYIMAGEKHRPROC);
+	GET_PROC_ADDRESS(vtable->glEGLImageTargetTexture2DOES, "glEGLImageTargetTexture2DOES", PFNGLEGLIMAGETARGETTEXTURE2DOESPROC);
+}
+
 /**
  * \brief Add a preprocessor definition to shader environment
  * \param[in,out] shaderEnv Vector of shader environment strings