[Mesa-dev] [Patch] Destroy context in egl_dri2 and egl_glx driver when apps call eglDestroyContext

Cooper Yuan cooperyuan at gmail.com
Sun Aug 14 00:23:27 PDT 2011


 /**
+ * Called via eglDestroyContext(), drv->API.DestroyContext().
+ */
+static EGLBoolean
+dri2_destroy_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLContext *ctx)
+{
+   struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+
+   if (_eglPutContext(ctx)) {
+      dri2_dpy->core->destroyContext(dri2_ctx->dri_context);
+      free(dri2_ctx);
+   }
+
+   return EGL_TRUE;
+}
+
+/**
  * Called via eglMakeCurrent(), drv->API.MakeCurrent().
  */
 static EGLBoolean
@@ -765,9 +782,8 @@ dri2_make_current(_EGLDriver *drv, _EGLDisplay *disp,
_EGLSurface *dsurf,
          drv->API.DestroySurface(drv, disp, old_dsurf);
       if (old_rsurf)
          drv->API.DestroySurface(drv, disp, old_rsurf);
-      /* no destroy? */
       if (old_ctx)
-         _eglPutContext(old_ctx);
+         drv->API.DestroyContext(drv, disp, old_ctx);

On Sun, Aug 14, 2011 at 12:16 PM, Chia-I Wu <olvaffe at gmail.com> wrote:

> On Fri, Aug 12, 2011 at 11:44 PM, Cooper Yuan <cooperyuan at gmail.com>
> wrote:
> > Hi, this patch calls corresponding destroyContext in egl_dri2 and egl_glx
> > driver.
> > Any comment?
> >
> > Cooper
> >
> > ---
> >  src/egl/drivers/dri2/egl_dri2.c |   17 +++++++++++++++++
> >  src/egl/drivers/glx/egl_glx.c   |   18 ++++++++++++++++++
> >  2 files changed, 35 insertions(+), 0 deletions(-)
> >
> > diff --git a/src/egl/drivers/dri2/egl_dri2.c
> > b/src/egl/drivers/dri2/egl_dri2.c
> > index 9a37ea4..2d947cd 100644
> > --- a/src/egl/drivers/dri2/egl_dri2.c
> > +++ b/src/egl/drivers/dri2/egl_dri2.c
> > @@ -726,6 +726,22 @@ dri2_create_context(_EGLDriver *drv, _EGLDisplay
> *disp,
> > _EGLConfig *conf,
> >  }
> >
> >  /**
> > + * Called via eglDestroyContext(), drv->API.DestroyContext().
> > + */
> > +static EGLBoolean
> > +dri2_destroy_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLContext
> *ctx)
> > +{
> > +   struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
> > +   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
> > +
> > +   _eglPutContext(ctx);
> You should check the return value of _eglPutContext and destroy the
> context only when it returns true.  Then in dri2_make_current, replace
> the call to _eglPutContext by a call to drv->API.DestroyContext.
>
> It should be symmetric to how surfaces are destroyed.
> > +   dri2_dpy->core->destroyContext(dri2_ctx->dri_context);
> > +   free(dri2_ctx);
> > +
> > +   return EGL_TRUE;
> > +}
> > +
> > +/**
> >   * Called via eglMakeCurrent(), drv->API.MakeCurrent().
> >   */
> >  static EGLBoolean
> > @@ -1348,6 +1364,7 @@ _EGL_MAIN(const char *args)
> >     dri2_drv->base.API.Initialize = dri2_initialize;
> >     dri2_drv->base.API.Terminate = dri2_terminate;
> >     dri2_drv->base.API.CreateContext = dri2_create_context;
> > +   dri2_drv->base.API.DestroyContext = dri2_destroy_context;
> >     dri2_drv->base.API.MakeCurrent = dri2_make_current;
> >     dri2_drv->base.API.GetProcAddress = dri2_get_proc_address;
> >     dri2_drv->base.API.WaitClient = dri2_wait_client;
> > diff --git a/src/egl/drivers/glx/egl_glx.c
> b/src/egl/drivers/glx/egl_glx.c
> > index 7cf8f4d..b21a3d7 100644
> > --- a/src/egl/drivers/glx/egl_glx.c
> > +++ b/src/egl/drivers/glx/egl_glx.c
> > @@ -713,6 +713,23 @@ GLX_eglCreateContext(_EGLDriver *drv, _EGLDisplay
> > *disp, _EGLConfig *conf,
> >     return &GLX_ctx->Base;
> >  }
> >
> > +/**
> > + * Called via eglDestroyContext(), drv->API.DestroyContext().
> > + */
> > +static EGLBoolean
> > +GLX_eglDestroyContext(_EGLDriver *drv, _EGLDisplay *disp, _EGLContext
> *ctx)
> > +{
> > +   struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
> > +   struct GLX_egl_context *GLX_ctx = GLX_egl_context(ctx);
> > +
> > +   _eglPutContext(ctx);
> > +   assert(GLX_ctx);
> > +   GLX_drv->glXDestroyContext(disp, ctx);
> > +
> > +   free(GLX_ctx);
> > +
> > +   return EGL_TRUE;
> > +}
> Ditto.
> >  /**
> >   * Destroy a surface.  The display is allowed to be uninitialized.
> > @@ -1142,6 +1159,7 @@ _EGL_MAIN(const char *args)
> >     GLX_drv->Base.API.Initialize = GLX_eglInitialize;
> >     GLX_drv->Base.API.Terminate = GLX_eglTerminate;
> >     GLX_drv->Base.API.CreateContext = GLX_eglCreateContext;
> > +   GLX_drv->Base.API.DestroyContext = GLX_eglDestroyContext;
> >     GLX_drv->Base.API.MakeCurrent = GLX_eglMakeCurrent;
> >     GLX_drv->Base.API.CreateWindowSurface = GLX_eglCreateWindowSurface;
> >     GLX_drv->Base.API.CreatePixmapSurface = GLX_eglCreatePixmapSurface;
> > --
> > 1.7.4.4
> >
> >
> >
> > _______________________________________________
> > mesa-dev mailing list
> > mesa-dev at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/mesa-dev
> >
> >
>
>
>
> --
> olv at LunarG.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20110814/47fd940a/attachment.html>


More information about the mesa-dev mailing list