[RFC,v1,09/10] libcamera: egl: Make it possible to unmake the context
diff mbox series

Message ID 20260804101949.353266-10-barnabas.pocze@ideasonboard.com
State Superseded
Headers show
Series
  • libcamera: software_isp: debayer_egl: Remove some leaks
Related show

Commit Message

Barnabás Pőcze Aug. 4, 2026, 10:19 a.m. UTC
Add a parameter to `makeCurrent()` to make it possible to
remove the currently bound context.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
 include/libcamera/internal/egl.h | 2 +-
 src/libcamera/egl.cpp            | 7 ++++---
 2 files changed, 5 insertions(+), 4 deletions(-)

Comments

Milan Zamazal Aug. 5, 2026, 11:34 a.m. UTC | #1
Barnabás Pőcze <barnabas.pocze@ideasonboard.com> writes:

> Add a parameter to `makeCurrent()` to make it possible to
> remove the currently bound context.

makeCurrent(make) doesn't look like the most elegant naming, but I
happily pass naming problems to the maintainers.

Reviewed-by: Milan Zamazal <mzamazal@redhat.com>

> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
> ---
>  include/libcamera/internal/egl.h | 2 +-
>  src/libcamera/egl.cpp            | 7 ++++---
>  2 files changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h
> index e18bb91f4d..a3218af9ef 100644
> --- a/include/libcamera/internal/egl.h
> +++ b/include/libcamera/internal/egl.h
> @@ -116,7 +116,7 @@ public:
>  	void activateBindTexture(eGLImage &eglImage);
>  
>  	void pushEnv(std::vector<std::string> &shaderEnv, const char *str);
> -	void makeCurrent();
> +	void makeCurrent(bool make);
>  
>  	int compileVertexShader(GLuint &shaderId, Span<const unsigned char> shaderData,
>  				Span<const std::string> shaderEnv);
> diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp
> index 5e75c3a6d2..f351bcf52c 100644
> --- a/src/libcamera/egl.cpp
> +++ b/src/libcamera/egl.cpp
> @@ -427,7 +427,7 @@ int eGL::initEGLContext()
>  	tid_ = Thread::currentId();
>  	vtable_ = vtable;
>  
> -	makeCurrent();
> +	makeCurrent(true);
>  
>  	LOG(eGL, Info) << "EGL: GL_RENDERER: " << glGetString(GL_RENDERER);
>  	LOG(eGL, Info) << "EGL: GL_VERSION: " << glGetString(GL_VERSION);
> @@ -454,16 +454,17 @@ void eGL::resetEGLContext()
>  
>  /**
>   * \brief Make the EGL context current for the calling thread
> + * \param[in] make Whether to make/unmake the EGL context
>   *
>   * Binds the EGL context to the current thread, allowing OpenGL ES
>   * operations to be performed. Must be called from the thread that
>   * will perform rendering operations.
>   */
> -void eGL::makeCurrent()
> +void eGL::makeCurrent(bool make)
>  {
>  	ASSERT(tid_ == Thread::currentId());
>  
> -	if (eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, context_) != EGL_TRUE) {
> +	if (eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, make ? context_ : EGL_NO_CONTEXT) != EGL_TRUE) {
>  		LOG(eGL, Error) << "eglMakeCurrent fail";
>  	}
>  }

Patch
diff mbox series

diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h
index e18bb91f4d..a3218af9ef 100644
--- a/include/libcamera/internal/egl.h
+++ b/include/libcamera/internal/egl.h
@@ -116,7 +116,7 @@  public:
 	void activateBindTexture(eGLImage &eglImage);
 
 	void pushEnv(std::vector<std::string> &shaderEnv, const char *str);
-	void makeCurrent();
+	void makeCurrent(bool make);
 
 	int compileVertexShader(GLuint &shaderId, Span<const unsigned char> shaderData,
 				Span<const std::string> shaderEnv);
diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp
index 5e75c3a6d2..f351bcf52c 100644
--- a/src/libcamera/egl.cpp
+++ b/src/libcamera/egl.cpp
@@ -427,7 +427,7 @@  int eGL::initEGLContext()
 	tid_ = Thread::currentId();
 	vtable_ = vtable;
 
-	makeCurrent();
+	makeCurrent(true);
 
 	LOG(eGL, Info) << "EGL: GL_RENDERER: " << glGetString(GL_RENDERER);
 	LOG(eGL, Info) << "EGL: GL_VERSION: " << glGetString(GL_VERSION);
@@ -454,16 +454,17 @@  void eGL::resetEGLContext()
 
 /**
  * \brief Make the EGL context current for the calling thread
+ * \param[in] make Whether to make/unmake the EGL context
  *
  * Binds the EGL context to the current thread, allowing OpenGL ES
  * operations to be performed. Must be called from the thread that
  * will perform rendering operations.
  */
-void eGL::makeCurrent()
+void eGL::makeCurrent(bool make)
 {
 	ASSERT(tid_ == Thread::currentId());
 
-	if (eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, context_) != EGL_TRUE) {
+	if (eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, make ? context_ : EGL_NO_CONTEXT) != EGL_TRUE) {
 		LOG(eGL, Error) << "eglMakeCurrent fail";
 	}
 }