[377/906] gldisplay: avoid to request gl thread when generating a texture

Thanks to the texture pool the gl textures are re-used.
When re-using one, no opengl code is executed so do not need
to request gl thread.
This commit is contained in:
Julien Isorce 2009-09-19 14:16:25 +02:00 committed by Tim-Philipp Müller
parent fa9177d037
commit fa41020ee4

View file

@ -1895,27 +1895,6 @@ void
gst_gl_display_glgen_texture (GstGLDisplay * display, GLuint * pTexture,
GLint width, GLint height)
{
if (display->isAlive) {
GQueue *sub_texture_pool = NULL;
//make a unique key from w and h
//the key cannot be w*h because (4*6 = 6*4 = 2*12 = 12*2)
guint key = (gint) width;
key <<= 16;
key |= (gint) height;
sub_texture_pool =
g_hash_table_lookup (display->texture_pool, GUINT_TO_POINTER (key));
//if there is a sub texture pool associated to th given key
if (sub_texture_pool && g_queue_get_length (sub_texture_pool) > 0) {
//a texture is available in the pool
GstGLDisplayTex *tex = g_queue_pop_head (sub_texture_pool);
*pTexture = tex->texture;
g_free (tex);
GST_LOG ("get texture id:%d from the sub texture pool: %d",
*pTexture, key);
} else {
//sub texture pool does not exist yet or empty
glGenTextures (1, pTexture);
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, *pTexture);
@ -1973,11 +1952,7 @@ gst_gl_display_glgen_texture (GstGLDisplay * display, GLuint * pTexture,
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T,
GL_CLAMP_TO_EDGE);
GST_LOG ("generate texture id:%d", *pTexture);
}
} else
*pTexture = 0;
GST_LOG ("generated texture id:%d", *pTexture);
}
@ -2169,11 +2144,38 @@ gst_gl_display_gen_texture (GstGLDisplay * display, GLuint * pTexture,
GLint width, GLint height)
{
gst_gl_display_lock (display);
if (display->isAlive) {
GQueue *sub_texture_pool = NULL;
//make a unique key from w and h
//the key cannot be w*h because (4*6 = 6*4 = 2*12 = 12*2)
guint key = (gint) width;
key <<= 16;
key |= (gint) height;
sub_texture_pool =
g_hash_table_lookup (display->texture_pool, GUINT_TO_POINTER (key));
//if there is a sub texture pool associated to the given key
if (sub_texture_pool && g_queue_get_length (sub_texture_pool) > 0) {
//a texture is available in the pool
GstGLDisplayTex *tex = g_queue_pop_head (sub_texture_pool);
*pTexture = tex->texture;
g_free (tex);
GST_LOG ("get texture id:%d from the sub texture pool: %d",
*pTexture, key);
} else {
//only in this case we want to ask a texture from the gl thread
display->gen_texture_width = width;
display->gen_texture_height = height;
gst_gl_window_send_message (display->gl_window,
GST_GL_WINDOW_CB (gst_gl_display_thread_gen_texture), display);
*pTexture = display->gen_texture;
}
} else
*pTexture = 0;
gst_gl_display_unlock (display);
}