| Message ID | 20260804101949.353266-6-barnabas.pocze@ideasonboard.com |
|---|---|
| State | Superseded |
| 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> > --- > include/libcamera/internal/egl.h | 1 + > src/libcamera/egl.cpp | 21 +++++++++++++++++---- > 2 files changed, 18 insertions(+), 4 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..6b50e7bb77 100644 > --- a/src/libcamera/egl.cpp > +++ b/src/libcamera/egl.cpp > @@ -71,14 +71,13 @@ eGL::eGL(EGLDisplay display) > } > > /** > - * \brief Destroy the EGL helper > + * \brief Release all EGL resources > * > - * Destroys the EGL context and surface if they were successfully created. > + * Equivalent to calling resetEGLContext(). I would omit the implementation notice from the docstring completely, and keep only the \brief part. Either way: Reviewed-by: Milan Zamazal <mzamazal@redhat.com> > */ > eGL::~eGL() > { > - if (context_ != EGL_NO_CONTEXT) > - eglDestroyContext(display_, context_); > + resetEGLContext(); > } > > /** > @@ -436,6 +435,20 @@ 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) > + 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..6b50e7bb77 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -71,14 +71,13 @@ eGL::eGL(EGLDisplay display) } /** - * \brief Destroy the EGL helper + * \brief Release all EGL resources * - * Destroys the EGL context and surface if they were successfully created. + * Equivalent to calling resetEGLContext(). */ eGL::~eGL() { - if (context_ != EGL_NO_CONTEXT) - eglDestroyContext(display_, context_); + resetEGLContext(); } /** @@ -436,6 +435,20 @@ 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) + 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 | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-)