[843/906] memory: provide copy_into_texture

This commit is contained in:
Matthew Waters 2013-11-13 23:24:00 +11:00
parent 43d953905b
commit 4322266b97
2 changed files with 29 additions and 7 deletions

View file

@ -57,6 +57,7 @@ typedef struct
{ {
GstGLMemory *src; GstGLMemory *src;
GLuint tex_id; GLuint tex_id;
gboolean result;
} GstGLMemoryCopyParams; } GstGLMemoryCopyParams;
static void static void
@ -212,6 +213,7 @@ _gl_mem_copy_thread (GstGLContext * context, gpointer data)
copy_params = (GstGLMemoryCopyParams *) data; copy_params = (GstGLMemoryCopyParams *) data;
src = copy_params->src; src = copy_params->src;
tex_id = copy_params->tex_id;
width = src->width; width = src->width;
height = src->height; height = src->height;
v_format = src->v_format; v_format = src->v_format;
@ -225,14 +227,18 @@ _gl_mem_copy_thread (GstGLContext * context, gpointer data)
goto error; goto error;
} }
gst_gl_context_gen_texture (src->context, &tex_id, v_format, width, height); if (!tex_id)
gst_gl_context_gen_texture (src->context, &tex_id, v_format, width, height);
if (!tex_id) { if (!tex_id) {
GST_CAT_WARNING (GST_CAT_GL_MEMORY, GST_CAT_WARNING (GST_CAT_GL_MEMORY,
"Could not create GL texture with context:%p", src->context); "Could not create GL texture with context:%p", src->context);
} }
GST_CAT_DEBUG (GST_CAT_GL_MEMORY, "created texture %i", tex_id); GST_CAT_LOG (GST_CAT_GL_MEMORY, "copying memory %p, tex %u into texture %i",
src, src->tex_id, tex_id);
/* FIXME: try and avoid creating and destroying fbo's every copy... */
/* create a framebuffer object */ /* create a framebuffer object */
gl->GenFramebuffers (1, &fboId); gl->GenFramebuffers (1, &fboId);
gl->BindFramebuffer (GL_FRAMEBUFFER, fboId); gl->BindFramebuffer (GL_FRAMEBUFFER, fboId);
@ -288,12 +294,13 @@ fbo_error:
gl->DeleteFramebuffers (1, &fboId); gl->DeleteFramebuffers (1, &fboId);
copy_params->tex_id = 0; copy_params->tex_id = 0;
copy_params->result = FALSE;
return; return;
} }
error: error:
{ {
copy_params->result = FALSE;
return; return;
} }
} }
@ -320,8 +327,11 @@ _gl_mem_copy (GstGLMemory * src, gssize offset, gssize size)
_gl_mem_init (dest, src->mem.allocator, NULL, src->context, src->v_format, _gl_mem_init (dest, src->mem.allocator, NULL, src->context, src->v_format,
src->width, src->height, NULL, NULL); src->width, src->height, NULL, NULL);
if (!copy_params.tex_id) if (!copy_params.result) {
GST_CAT_WARNING (GST_CAT_GL_MEMORY, "Could not copy GL Memory"); GST_CAT_WARNING (GST_CAT_GL_MEMORY, "Could not copy GL Memory");
gst_memory_unref ((GstMemory *) dest);
return NULL;
}
dest->tex_id = copy_params.tex_id; dest->tex_id = copy_params.tex_id;
dest->data = g_malloc (src->mem.maxsize); dest->data = g_malloc (src->mem.maxsize);
@ -333,9 +343,6 @@ _gl_mem_copy (GstGLMemory * src, gssize offset, gssize size)
GST_GL_MEMORY_FLAG_SET (dest, GST_GL_MEMORY_FLAG_NEED_DOWNLOAD); GST_GL_MEMORY_FLAG_SET (dest, GST_GL_MEMORY_FLAG_NEED_DOWNLOAD);
} }
GST_CAT_DEBUG (GST_CAT_GL_MEMORY, "copied texture:%u into texture %u",
src->tex_id, dest->tex_id);
return (GstMemory *) dest; return (GstMemory *) dest;
} }
@ -384,6 +391,20 @@ _gl_mem_free (GstAllocator * allocator, GstMemory * mem)
g_slice_free (GstGLMemory, gl_mem); g_slice_free (GstGLMemory, gl_mem);
} }
gboolean
gst_gl_memory_copy_into_texture (GstGLMemory * gl_mem, guint tex_id)
{
GstGLMemoryCopyParams copy_params;
copy_params.src = gl_mem;
copy_params.tex_id = tex_id;
gst_gl_context_thread_add (gl_mem->context, _gl_mem_copy_thread,
&copy_params);
return copy_params.result;
}
/** /**
* gst_gl_memory_alloc: * gst_gl_memory_alloc:
* @context:a #GstGLContext * @context:a #GstGLContext

View file

@ -153,6 +153,7 @@ GstGLMemory * gst_gl_memory_wrapped (GstGLContext * context, GstVideoFormat form
gpointer user_data, GDestroyNotify notify); gpointer user_data, GDestroyNotify notify);
gboolean gst_is_gl_memory (GstMemory * mem); gboolean gst_is_gl_memory (GstMemory * mem);
gboolean gst_gl_memory_copy_into_texture (GstGLMemory *gl_mem, guint tex_id);
/** /**
* GstGLAllocator * GstGLAllocator