[v3,6/8] libcamera: software_isp: debayer_egl: Remove EGL context switch
diff mbox series

Message ID 20260811130042.213139-7-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • libcamera: software_isp: debayer_egl: Remove some leaks
Related show

Commit Message

Barnabás Pőcze Aug. 11, 2026, 1 p.m. UTC
`eGL::initEGLContext()`, which is called from the worker thread already
includes a call to `eGL::makeCurrent()`, so calling it for each
`process()` is not necessary, so skip it.

Instead call `eGL::assertThread()` in `process()` to ensure that
the thread is correct.

And lastly, make `eGL::makeCurrent()` a private function as now there
are no external calleras.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>

asd
---
 include/libcamera/internal/egl.h           | 3 ++-
 src/libcamera/software_isp/debayer_egl.cpp | 4 +---
 2 files changed, 3 insertions(+), 4 deletions(-)

Comments

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

> `eGL::initEGLContext()`, which is called from the worker thread already
> includes a call to `eGL::makeCurrent()`, so calling it for each
> `process()` is not necessary, so skip it.
>
> Instead call `eGL::assertThread()` in `process()` to ensure that
> the thread is correct.
>
> And lastly, make `eGL::makeCurrent()` a private function as now there
> are no external calleras.

callers

> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>

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

> asd

?

> ---
>  include/libcamera/internal/egl.h           | 3 ++-
>  src/libcamera/software_isp/debayer_egl.cpp | 4 +---
>  2 files changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h
> index 13df65e6b2..608d53151c 100644
> --- a/include/libcamera/internal/egl.h
> +++ b/include/libcamera/internal/egl.h
> @@ -116,7 +116,6 @@ public:
>  	void activateBindTexture(eGLImage &eglImage);
>  
>  	void pushEnv(std::vector<std::string> &shaderEnv, const char *str);
> -	void makeCurrent();
>  
>  	int compileVertexShader(GLuint &shaderId, Span<const unsigned char> shaderData,
>  				Span<const std::string> shaderEnv);
> @@ -145,6 +144,8 @@ private:
>  
>  	int createDMABufTexture2D(eGLImage &eglImage, int fd, bool output);
>  
> +	void makeCurrent();
> +
>  	struct VTable {
>  		PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
>  		PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
> diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp
> index ede3be2352..7b2b367305 100644
> --- a/src/libcamera/software_isp/debayer_egl.cpp
> +++ b/src/libcamera/software_isp/debayer_egl.cpp
> @@ -578,9 +578,6 @@ int DebayerEGL::debayerGPU(FrameBuffer *input, FrameBuffer *output, const Debaye
>  	eGLImage *eglImageIn;
>  	eGLImage *eglImageOut;
>  
> -	/* eGL context switch */
> -	egl_.makeCurrent();
> -
>  	eglImageIn = getCachedInputFrameBuffer(input, inMapped, inDmaSyncer);
>  	if (!eglImageIn)
>  		return -ENOMEM;
> @@ -608,6 +605,7 @@ int DebayerEGL::debayerGPU(FrameBuffer *input, FrameBuffer *output, const Debaye
>  
>  void DebayerEGL::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, const DebayerParams &params)
>  {
> +	egl_.assertThread();
>  	bench_.startFrame();
>  
>  	/* Copy metadata from the input buffer */
Jacopo Mondi Aug. 11, 2026, 4 p.m. UTC | #2
Hi Barnabás

On Tue, Aug 11, 2026 at 03:00:40PM +0200, Barnabás Pőcze wrote:
> `eGL::initEGLContext()`, which is called from the worker thread already
> includes a call to `eGL::makeCurrent()`, so calling it for each
> `process()` is not necessary, so skip it.
>
> Instead call `eGL::assertThread()` in `process()` to ensure that
> the thread is correct.
>
> And lastly, make `eGL::makeCurrent()` a private function as now there
> are no external calleras.
>
> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
>
> asd

With Milan's comments addressed
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>

> ---
>  include/libcamera/internal/egl.h           | 3 ++-
>  src/libcamera/software_isp/debayer_egl.cpp | 4 +---
>  2 files changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h
> index 13df65e6b2..608d53151c 100644
> --- a/include/libcamera/internal/egl.h
> +++ b/include/libcamera/internal/egl.h
> @@ -116,7 +116,6 @@ public:
>  	void activateBindTexture(eGLImage &eglImage);
>
>  	void pushEnv(std::vector<std::string> &shaderEnv, const char *str);
> -	void makeCurrent();
>
>  	int compileVertexShader(GLuint &shaderId, Span<const unsigned char> shaderData,
>  				Span<const std::string> shaderEnv);
> @@ -145,6 +144,8 @@ private:
>
>  	int createDMABufTexture2D(eGLImage &eglImage, int fd, bool output);
>
> +	void makeCurrent();
> +
>  	struct VTable {
>  		PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
>  		PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
> diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp
> index ede3be2352..7b2b367305 100644
> --- a/src/libcamera/software_isp/debayer_egl.cpp
> +++ b/src/libcamera/software_isp/debayer_egl.cpp
> @@ -578,9 +578,6 @@ int DebayerEGL::debayerGPU(FrameBuffer *input, FrameBuffer *output, const Debaye
>  	eGLImage *eglImageIn;
>  	eGLImage *eglImageOut;
>
> -	/* eGL context switch */
> -	egl_.makeCurrent();
> -
>  	eglImageIn = getCachedInputFrameBuffer(input, inMapped, inDmaSyncer);
>  	if (!eglImageIn)
>  		return -ENOMEM;
> @@ -608,6 +605,7 @@ int DebayerEGL::debayerGPU(FrameBuffer *input, FrameBuffer *output, const Debaye
>
>  void DebayerEGL::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, const DebayerParams &params)
>  {
> +	egl_.assertThread();
>  	bench_.startFrame();
>
>  	/* Copy metadata from the input buffer */
> --
> 2.55.0
>

Patch
diff mbox series

diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h
index 13df65e6b2..608d53151c 100644
--- a/include/libcamera/internal/egl.h
+++ b/include/libcamera/internal/egl.h
@@ -116,7 +116,6 @@  public:
 	void activateBindTexture(eGLImage &eglImage);
 
 	void pushEnv(std::vector<std::string> &shaderEnv, const char *str);
-	void makeCurrent();
 
 	int compileVertexShader(GLuint &shaderId, Span<const unsigned char> shaderData,
 				Span<const std::string> shaderEnv);
@@ -145,6 +144,8 @@  private:
 
 	int createDMABufTexture2D(eGLImage &eglImage, int fd, bool output);
 
+	void makeCurrent();
+
 	struct VTable {
 		PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES;
 		PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR;
diff --git a/src/libcamera/software_isp/debayer_egl.cpp b/src/libcamera/software_isp/debayer_egl.cpp
index ede3be2352..7b2b367305 100644
--- a/src/libcamera/software_isp/debayer_egl.cpp
+++ b/src/libcamera/software_isp/debayer_egl.cpp
@@ -578,9 +578,6 @@  int DebayerEGL::debayerGPU(FrameBuffer *input, FrameBuffer *output, const Debaye
 	eGLImage *eglImageIn;
 	eGLImage *eglImageOut;
 
-	/* eGL context switch */
-	egl_.makeCurrent();
-
 	eglImageIn = getCachedInputFrameBuffer(input, inMapped, inDmaSyncer);
 	if (!eglImageIn)
 		return -ENOMEM;
@@ -608,6 +605,7 @@  int DebayerEGL::debayerGPU(FrameBuffer *input, FrameBuffer *output, const Debaye
 
 void DebayerEGL::process(uint32_t frame, FrameBuffer *input, FrameBuffer *output, const DebayerParams &params)
 {
+	egl_.assertThread();
 	bench_.startFrame();
 
 	/* Copy metadata from the input buffer */