[333/906] add force-aspect-ratio support

This commit is contained in:
Julien Isorce 2009-04-20 00:52:41 +02:00 committed by Tim-Philipp Müller
parent d1bd71e82b
commit d43fdd3daf
2 changed files with 24 additions and 3 deletions

View file

@ -24,6 +24,7 @@
#include "config.h" #include "config.h"
#endif #endif
#include <gst/video/gstvideosink.h>
#include "gstgldisplay.h" #include "gstgldisplay.h"
/* /*
@ -125,6 +126,7 @@ gst_gl_display_init (GstGLDisplay * display, GstGLDisplayClass * klass)
display->redisplay_texture = 0; display->redisplay_texture = 0;
display->redisplay_texture_width = 0; display->redisplay_texture_width = 0;
display->redisplay_texture_height = 0; display->redisplay_texture_height = 0;
display->keep_aspect_ratio = FALSE;
#ifdef OPENGL_ES2 #ifdef OPENGL_ES2
display->redisplay_shader = NULL; display->redisplay_shader = NULL;
display->redisplay_attr_position_loc = 0; display->redisplay_attr_position_loc = 0;
@ -1747,7 +1749,24 @@ gst_gl_display_on_resize (GstGLDisplay * display, gint width, gint height)
//default reshape //default reshape
else { else {
glViewport (0, 0, width, height); if (display->keep_aspect_ratio) {
GstVideoRectangle src, dst, result;
src.x = 0;
src.y = 0;
src.w = display->redisplay_texture_width;
src.h = display->redisplay_texture_height;
dst.x = 0;
dst.y = 0;
dst.w = width;
dst.h = height;
gst_video_sink_center_rect (src, dst, &result, TRUE);
glViewport (result.x, result.y, result.w, result.h);
} else {
glViewport (0, 0, width, height);
}
#ifndef OPENGL_ES2 #ifndef OPENGL_ES2
glMatrixMode (GL_PROJECTION); glMatrixMode (GL_PROJECTION);
glLoadIdentity (); glLoadIdentity ();
@ -2091,7 +2110,7 @@ gst_gl_display_create_context (GstGLDisplay * display,
/* Called by the glimagesink element */ /* Called by the glimagesink element */
gboolean gboolean
gst_gl_display_redisplay (GstGLDisplay * display, GLuint texture, gint width, gst_gl_display_redisplay (GstGLDisplay * display, GLuint texture, gint width,
gint height) gint height, gboolean keep_aspect_ratio)
{ {
gboolean isAlive = TRUE; gboolean isAlive = TRUE;
@ -2111,6 +2130,7 @@ gst_gl_display_redisplay (GstGLDisplay * display, GLuint texture, gint width,
display->redisplay_texture_width = width; display->redisplay_texture_width = width;
display->redisplay_texture_height = height; display->redisplay_texture_height = height;
} }
display->keep_aspect_ratio = keep_aspect_ratio;
if (display->gl_window) if (display->gl_window)
gst_gl_window_draw (display->gl_window); gst_gl_window_draw (display->gl_window);
} }

View file

@ -100,6 +100,7 @@ struct _GstGLDisplay
GLuint redisplay_texture; GLuint redisplay_texture;
GLuint redisplay_texture_width; GLuint redisplay_texture_width;
GLuint redisplay_texture_height; GLuint redisplay_texture_height;
gboolean keep_aspect_ratio;
#ifdef OPENGL_ES2 #ifdef OPENGL_ES2
GstGLShader *redisplay_shader; GstGLShader *redisplay_shader;
gchar *redisplay_vertex_shader_str; gchar *redisplay_vertex_shader_str;
@ -241,7 +242,7 @@ GstGLDisplay *gst_gl_display_new (void);
void gst_gl_display_create_context (GstGLDisplay * display, void gst_gl_display_create_context (GstGLDisplay * display,
GLint width, GLint height, guint64 external_gl_context); GLint width, GLint height, guint64 external_gl_context);
gboolean gst_gl_display_redisplay (GstGLDisplay * display, GLuint texture, gboolean gst_gl_display_redisplay (GstGLDisplay * display, GLuint texture,
gint width, gint height); gint width, gint height, gboolean keep_aspect_ratio);
void gst_gl_display_thread_add (GstGLDisplay * display, void gst_gl_display_thread_add (GstGLDisplay * display,
GstGLDisplayThreadFunc func, gpointer data); GstGLDisplayThreadFunc func, gpointer data);