| Message ID | 20260810105942.1098192-6-barnabas.pocze@ideasonboard.com |
|---|---|
| State | New |
| Headers | show |
| Series |
|
| Related | show |
Barnabás Pőcze <barnabas.pocze@ideasonboard.com> writes: > Add a function that undoes the effects of `initEGLContext()`. > > Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> Reviewed-by: Milan Zamazal <mzamazal@redhat.com> > --- > include/libcamera/internal/egl.h | 1 + > src/libcamera/egl.cpp | 25 ++++++++++++++++++++----- > 2 files changed, 21 insertions(+), 5 deletions(-) > > diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h > index fb77225ac4..e18bb91f4d 100644 > --- a/include/libcamera/internal/egl.h > +++ b/include/libcamera/internal/egl.h > @@ -103,6 +103,7 @@ public: > ~eGL(); > > int initEGLContext(); > + void resetEGLContext(); > static EGLDisplay probeDisplay(); > > int createInputDMABufTexture2D(eGLImage &eglImage, int fd); > diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp > index 3de5fab816..237791bca1 100644 > --- a/src/libcamera/egl.cpp > +++ b/src/libcamera/egl.cpp > @@ -71,14 +71,11 @@ eGL::eGL(EGLDisplay display) > } > > /** > - * \brief Destroy the EGL helper > - * > - * Destroys the EGL context and surface if they were successfully created. > + * \brief Release all EGL resources > */ > eGL::~eGL() > { > - if (context_ != EGL_NO_CONTEXT) > - eglDestroyContext(display_, context_); > + resetEGLContext(); > } > > /** > @@ -436,6 +433,24 @@ fail: > return -ENODEV; > } > > +/** > + * \brief Destroy the EGL context > + * > + * This function destroys the EGL context created by initEGLContext(). > + */ > +void eGL::resetEGLContext() > +{ > + if (context_ != EGL_NO_CONTEXT) { > + if (tid_ == Thread::currentId()) > + eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); > + > + eglDestroyContext(display_, std::exchange(context_, EGL_NO_CONTEXT)); > + } > + > + tid_ = -1; > + vtable_ = {}; > +} > + > /** > * \brief Make the EGL context current for the calling thread > *
diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index fb77225ac4..e18bb91f4d 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -103,6 +103,7 @@ public: ~eGL(); int initEGLContext(); + void resetEGLContext(); static EGLDisplay probeDisplay(); int createInputDMABufTexture2D(eGLImage &eglImage, int fd); diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index 3de5fab816..237791bca1 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -71,14 +71,11 @@ eGL::eGL(EGLDisplay display) } /** - * \brief Destroy the EGL helper - * - * Destroys the EGL context and surface if they were successfully created. + * \brief Release all EGL resources */ eGL::~eGL() { - if (context_ != EGL_NO_CONTEXT) - eglDestroyContext(display_, context_); + resetEGLContext(); } /** @@ -436,6 +433,24 @@ fail: return -ENODEV; } +/** + * \brief Destroy the EGL context + * + * This function destroys the EGL context created by initEGLContext(). + */ +void eGL::resetEGLContext() +{ + if (context_ != EGL_NO_CONTEXT) { + if (tid_ == Thread::currentId()) + eglMakeCurrent(display_, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + + eglDestroyContext(display_, std::exchange(context_, EGL_NO_CONTEXT)); + } + + tid_ = -1; + vtable_ = {}; +} + /** * \brief Make the EGL context current for the calling thread *
Add a function that undoes the effects of `initEGLContext()`. Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com> --- include/libcamera/internal/egl.h | 1 + src/libcamera/egl.cpp | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-)