From: Zhigang Gong Date: Wed, 3 Jul 2013 09:36:16 +0000 (+0800) Subject: CL: destroy the EGL image which is created for gl sharing when delete the mem object. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e271f10397fe2fc38986046679d6fea95449eaae;p=contrib%2Fbeignet.git CL: destroy the EGL image which is created for gl sharing when delete the mem object. Signed-off-by: Zhigang Gong --- diff --git a/src/cl_mem.c b/src/cl_mem.c index 4afc207..5465aa9 100644 --- a/src/cl_mem.c +++ b/src/cl_mem.c @@ -400,6 +400,11 @@ cl_mem_delete(cl_mem mem) return; if (LIKELY(mem->bo != NULL)) cl_buffer_unreference(mem->bo); +#ifdef HAS_EGL + if (UNLIKELY(mem->egl_image != NULL)) { + cl_mem_gl_delete(mem); + } +#endif /* Remove it from the list */ assert(mem->ctx); diff --git a/src/cl_mem.h b/src/cl_mem.h index 33ad174..c204992 100644 --- a/src/cl_mem.h +++ b/src/cl_mem.h @@ -55,6 +55,7 @@ struct _cl_mem { uint64_t magic; /* To identify it as a memory object */ volatile int ref_n; /* This object is reference counted */ cl_buffer bo; /* Data in GPU memory */ + void *egl_image; /* created from external egl image*/ size_t size; /* original request size, not alignment size, used in constant buffer */ cl_mem prev, next; /* We chain the memory buffers together */ cl_context ctx; /* Context it belongs to */ @@ -87,6 +88,9 @@ cl_mem_new_image(cl_context context, /* Unref the object and delete it if no more reference */ extern void cl_mem_delete(cl_mem); +/* Destroy egl image. */ +extern void cl_mem_gl_delete(cl_mem); + /* Add one more reference to this object */ extern void cl_mem_add_ref(cl_mem); diff --git a/src/cl_mem_gl.c b/src/cl_mem_gl.c index c2a5395..04641a5 100644 --- a/src/cl_mem_gl.c +++ b/src/cl_mem_gl.c @@ -183,6 +183,7 @@ LOCAL cl_mem cl_mem_new_gl_texture(cl_context ctx, err = CL_INVALID_GL_OBJECT; goto error; } + mem->egl_image = egl_image; mem->bo = cl_buffer_alloc_from_eglimage(ctx, (void*)egl_image, &gl_format, &w, &h, &pitch, &tiling); if (UNLIKELY(mem->bo == NULL)) { err = CL_MEM_OBJECT_ALLOCATION_FAILURE; @@ -232,3 +233,11 @@ error: goto exit; } + +LOCAL void cl_mem_gl_delete(cl_mem mem) +{ + struct cl_gl_ext_deps *egl_funcs; + EGLDisplay egl_display = (EGLDisplay)mem->ctx->props.egl_display; + egl_funcs = CL_EXTENSION_GET_FUNCS(mem->ctx, khr_gl_sharing, gl_ext_deps); + egl_funcs->eglDestroyImageKHR_func(egl_display, mem->egl_image); +}