<div> /**</div><div>+ * Called via eglDestroyContext(), drv-&gt;API.DestroyContext().</div><div>+ */</div><div>+static EGLBoolean</div><div>+dri2_destroy_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLContext *ctx)</div><div>

+{</div><div>+   struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);</div><div>+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);</div><div>+</div><div>+   if (_eglPutContext(ctx)) {</div><div>+      dri2_dpy-&gt;core-&gt;destroyContext(dri2_ctx-&gt;dri_context);</div>

<div>+      free(dri2_ctx);</div><div>+   }</div><div>+</div><div>+   return EGL_TRUE;</div><div>+}</div><div>+</div><div>+/**</div><div>  * Called via eglMakeCurrent(), drv-&gt;API.MakeCurrent().</div><div>  */</div><div>

 static EGLBoolean</div><div>@@ -765,9 +782,8 @@ dri2_make_current(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf,</div><div>          drv-&gt;API.DestroySurface(drv, disp, old_dsurf);</div><div>       if (old_rsurf)</div>

<div>          drv-&gt;API.DestroySurface(drv, disp, old_rsurf);</div><div>-      /* no destroy? */</div><div>       if (old_ctx)</div><div>-         _eglPutContext(old_ctx);</div><div>+         drv-&gt;API.DestroyContext(drv, disp, old_ctx);</div>

<div> </div><div class="gmail_quote">On Sun, Aug 14, 2011 at 12:16 PM, Chia-I Wu <span dir="ltr">&lt;<a href="mailto:olvaffe@gmail.com">olvaffe@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

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