mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-28 04:31:06 +00:00
[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:
parent
1cb459d4d5
commit
192bf749ea
1 changed files with 80 additions and 78 deletions
|
@ -1895,89 +1895,64 @@ void
|
||||||
gst_gl_display_glgen_texture (GstGLDisplay * display, GLuint * pTexture,
|
gst_gl_display_glgen_texture (GstGLDisplay * display, GLuint * pTexture,
|
||||||
GLint width, GLint height)
|
GLint width, GLint height)
|
||||||
{
|
{
|
||||||
if (display->isAlive) {
|
glGenTextures (1, pTexture);
|
||||||
GQueue *sub_texture_pool = NULL;
|
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, *pTexture);
|
||||||
|
|
||||||
//make a unique key from w and h
|
switch (display->upload_video_format) {
|
||||||
//the key cannot be w*h because (4*6 = 6*4 = 2*12 = 12*2)
|
case GST_VIDEO_FORMAT_RGB:
|
||||||
guint key = (gint) width;
|
case GST_VIDEO_FORMAT_BGR:
|
||||||
key <<= 16;
|
case GST_VIDEO_FORMAT_RGBx:
|
||||||
key |= (gint) height;
|
case GST_VIDEO_FORMAT_BGRx:
|
||||||
sub_texture_pool =
|
case GST_VIDEO_FORMAT_xRGB:
|
||||||
g_hash_table_lookup (display->texture_pool, GUINT_TO_POINTER (key));
|
case GST_VIDEO_FORMAT_xBGR:
|
||||||
|
case GST_VIDEO_FORMAT_RGBA:
|
||||||
//if there is a sub texture pool associated to th given key
|
case GST_VIDEO_FORMAT_BGRA:
|
||||||
if (sub_texture_pool && g_queue_get_length (sub_texture_pool) > 0) {
|
case GST_VIDEO_FORMAT_ARGB:
|
||||||
//a texture is available in the pool
|
case GST_VIDEO_FORMAT_ABGR:
|
||||||
GstGLDisplayTex *tex = g_queue_pop_head (sub_texture_pool);
|
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
|
||||||
*pTexture = tex->texture;
|
width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||||
g_free (tex);
|
break;
|
||||||
GST_LOG ("get texture id:%d from the sub texture pool: %d",
|
case GST_VIDEO_FORMAT_YUY2:
|
||||||
*pTexture, key);
|
case GST_VIDEO_FORMAT_UYVY:
|
||||||
} else {
|
switch (display->upload_colorspace_conversion) {
|
||||||
//sub texture pool does not exist yet or empty
|
case GST_GL_DISPLAY_CONVERSION_GLSL:
|
||||||
glGenTextures (1, pTexture);
|
case GST_GL_DISPLAY_CONVERSION_MATRIX:
|
||||||
glBindTexture (GL_TEXTURE_RECTANGLE_ARB, *pTexture);
|
|
||||||
|
|
||||||
switch (display->upload_video_format) {
|
|
||||||
case GST_VIDEO_FORMAT_RGB:
|
|
||||||
case GST_VIDEO_FORMAT_BGR:
|
|
||||||
case GST_VIDEO_FORMAT_RGBx:
|
|
||||||
case GST_VIDEO_FORMAT_BGRx:
|
|
||||||
case GST_VIDEO_FORMAT_xRGB:
|
|
||||||
case GST_VIDEO_FORMAT_xBGR:
|
|
||||||
case GST_VIDEO_FORMAT_RGBA:
|
|
||||||
case GST_VIDEO_FORMAT_BGRA:
|
|
||||||
case GST_VIDEO_FORMAT_ARGB:
|
|
||||||
case GST_VIDEO_FORMAT_ABGR:
|
|
||||||
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
|
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
|
||||||
width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||||
break;
|
break;
|
||||||
case GST_VIDEO_FORMAT_YUY2:
|
case GST_GL_DISPLAY_CONVERSION_MESA:
|
||||||
case GST_VIDEO_FORMAT_UYVY:
|
if (display->upload_width != display->upload_data_width ||
|
||||||
switch (display->upload_colorspace_conversion) {
|
display->upload_height != display->upload_data_height)
|
||||||
case GST_GL_DISPLAY_CONVERSION_GLSL:
|
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
|
||||||
case GST_GL_DISPLAY_CONVERSION_MATRIX:
|
width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||||
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
|
else
|
||||||
width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_YCBCR_MESA, width,
|
||||||
break;
|
height, 0, GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_MESA, NULL);
|
||||||
case GST_GL_DISPLAY_CONVERSION_MESA:
|
|
||||||
if (display->upload_width != display->upload_data_width ||
|
|
||||||
display->upload_height != display->upload_data_height)
|
|
||||||
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
|
|
||||||
width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
|
||||||
else
|
|
||||||
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_YCBCR_MESA, width,
|
|
||||||
height, 0, GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_MESA, NULL);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
g_assert_not_reached ();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case GST_VIDEO_FORMAT_I420:
|
|
||||||
case GST_VIDEO_FORMAT_YV12:
|
|
||||||
case GST_VIDEO_FORMAT_AYUV:
|
|
||||||
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
|
|
||||||
width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
g_assert_not_reached ();
|
g_assert_not_reached ();
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case GST_VIDEO_FORMAT_I420:
|
||||||
|
case GST_VIDEO_FORMAT_YV12:
|
||||||
|
case GST_VIDEO_FORMAT_AYUV:
|
||||||
|
glTexImage2D (GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA8,
|
||||||
|
width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
g_assert_not_reached ();
|
||||||
|
}
|
||||||
|
|
||||||
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER,
|
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER,
|
||||||
GL_LINEAR);
|
GL_LINEAR);
|
||||||
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER,
|
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER,
|
||||||
GL_LINEAR);
|
GL_LINEAR);
|
||||||
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S,
|
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S,
|
||||||
GL_CLAMP_TO_EDGE);
|
GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T,
|
glTexParameteri (GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T,
|
||||||
GL_CLAMP_TO_EDGE);
|
GL_CLAMP_TO_EDGE);
|
||||||
|
|
||||||
GST_LOG ("generate texture id:%d", *pTexture);
|
GST_LOG ("generated texture id:%d", *pTexture);
|
||||||
}
|
|
||||||
|
|
||||||
} else
|
|
||||||
*pTexture = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2169,11 +2144,38 @@ gst_gl_display_gen_texture (GstGLDisplay * display, GLuint * pTexture,
|
||||||
GLint width, GLint height)
|
GLint width, GLint height)
|
||||||
{
|
{
|
||||||
gst_gl_display_lock (display);
|
gst_gl_display_lock (display);
|
||||||
display->gen_texture_width = width;
|
|
||||||
display->gen_texture_height = height;
|
if (display->isAlive) {
|
||||||
gst_gl_window_send_message (display->gl_window,
|
GQueue *sub_texture_pool = NULL;
|
||||||
GST_GL_WINDOW_CB (gst_gl_display_thread_gen_texture), display);
|
|
||||||
*pTexture = display->gen_texture;
|
//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);
|
gst_gl_display_unlock (display);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue