eglglessink: Only draw black borders if the default swap behaviour of the surface is to destroy the buffer

This commit is contained in:
Sebastian Dröge 2012-10-18 10:20:26 +02:00
parent a025c80b4c
commit 147edd1fc2
2 changed files with 109 additions and 92 deletions

View file

@ -1117,6 +1117,7 @@ gst_eglglessink_init_egl_surface (GstEglGlesSink * eglglessink)
EGLint display_par;
const gchar *texnames[3] = { NULL, };
gchar *tmp_prog = NULL;
EGLint swap_behavior;
GST_DEBUG_OBJECT (eglglessink, "Enter EGL surface setup");
@ -1131,6 +1132,16 @@ gst_eglglessink_init_egl_surface (GstEglGlesSink * eglglessink)
goto HANDLE_EGL_ERROR_LOCKED;
}
eglglessink->eglglesctx.buffer_preserved = FALSE;
if (eglQuerySurface (eglglessink->eglglesctx.display,
eglglessink->eglglesctx.surface, EGL_SWAP_BEHAVIOR, &swap_behavior)) {
GST_DEBUG_OBJECT (eglglessink, "Buffer swap behavior %x", swap_behavior);
eglglessink->eglglesctx.buffer_preserved =
swap_behavior == EGL_BUFFER_PRESERVED;
} else {
GST_DEBUG_OBJECT (eglglessink, "Can't query buffer swap behavior");
}
if (!gst_eglglessink_context_make_current (eglglessink, TRUE))
goto HANDLE_EGL_ERROR_LOCKED;
@ -1368,6 +1379,7 @@ gst_eglglessink_init_egl_surface (GstEglGlesSink * eglglessink)
if (got_gl_error ("glEnableVertexAttribArray"))
goto HANDLE_ERROR;
if (!eglglessink->eglglesctx.buffer_preserved) {
/* Build shader program for black borders */
eglglessink->eglglesctx.vertshader[1] = glCreateShader (GL_VERTEX_SHADER);
GST_DEBUG_OBJECT (eglglessink, "Sending %s to handle %d", vert_COPY_prog,
@ -1446,11 +1458,13 @@ gst_eglglessink_init_egl_surface (GstEglGlesSink * eglglessink)
}
eglglessink->eglglesctx.position_loc[1] =
glGetAttribLocation (eglglessink->eglglesctx.glslprogram[1], "position");
glGetAttribLocation (eglglessink->eglglesctx.glslprogram[1],
"position");
glEnableVertexAttribArray (eglglessink->eglglesctx.position_loc[1]);
if (got_gl_error ("glEnableVertexAttribArray"))
goto HANDLE_ERROR;
}
glUseProgram (eglglessink->eglglesctx.glslprogram[0]);
@ -1891,6 +1905,7 @@ gst_eglglessink_render_and_display (GstEglGlesSink * eglglessink,
}
}
if (!eglglessink->eglglesctx.buffer_preserved) {
/* Draw black borders */
GST_DEBUG_OBJECT (eglglessink, "Drawing black border 1");
glUseProgram (eglglessink->eglglesctx.glslprogram[1]);
@ -1914,6 +1929,7 @@ gst_eglglessink_render_and_display (GstEglGlesSink * eglglessink,
glDrawElements (GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, 0);
if (got_gl_error ("glDrawElements"))
goto HANDLE_ERROR;
}
/* Draw video frame */
GST_DEBUG_OBJECT (eglglessink, "Drawing video frame");

View file

@ -122,6 +122,7 @@ struct _GstEglGlesRenderContext
EGLDisplay display;
EGLNativeWindowType window, used_window;
EGLSurface surface;
gboolean buffer_preserved;
GLuint fragshader[2], vertshader[2], glslprogram[2];
GLuint texture[3];
EGLint surface_width;