[333/906] add force-aspect-ratio support
authorJulien Isorce <julien.isorce@gmail.com>
Sun, 19 Apr 2009 22:52:41 +0000 (00:52 +0200)
committerTim-Philipp Müller <tim@centricular.com>
Sat, 9 Dec 2017 19:31:21 +0000 (19:31 +0000)
gst-libs/gst/gl/gstgldisplay.c
gst-libs/gst/gl/gstgldisplay.h

index f339f0c..9c3cce9 100644 (file)
@@ -24,6 +24,7 @@
 #include "config.h"
 #endif
 
+#include <gst/video/gstvideosink.h>
 #include "gstgldisplay.h"
 
 /*
@@ -125,6 +126,7 @@ gst_gl_display_init (GstGLDisplay * display, GstGLDisplayClass * klass)
   display->redisplay_texture = 0;
   display->redisplay_texture_width = 0;
   display->redisplay_texture_height = 0;
+  display->keep_aspect_ratio = FALSE;
 #ifdef OPENGL_ES2
   display->redisplay_shader = NULL;
   display->redisplay_attr_position_loc = 0;
@@ -1747,7 +1749,24 @@ gst_gl_display_on_resize (GstGLDisplay * display, gint width, gint height)
 
   //default reshape
   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
     glMatrixMode (GL_PROJECTION);
     glLoadIdentity ();
@@ -2091,7 +2110,7 @@ gst_gl_display_create_context (GstGLDisplay * display,
 /* Called by the glimagesink element */
 gboolean
 gst_gl_display_redisplay (GstGLDisplay * display, GLuint texture, gint width,
-    gint height)
+    gint height, gboolean keep_aspect_ratio)
 {
   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_height = height;
     }
+    display->keep_aspect_ratio = keep_aspect_ratio;
     if (display->gl_window)
       gst_gl_window_draw (display->gl_window);
   }
index 25370b5..74a72e6 100644 (file)
@@ -100,6 +100,7 @@ struct _GstGLDisplay
   GLuint redisplay_texture;
   GLuint redisplay_texture_width;
   GLuint redisplay_texture_height;
+  gboolean keep_aspect_ratio;
 #ifdef OPENGL_ES2
   GstGLShader *redisplay_shader;
   gchar *redisplay_vertex_shader_str;
@@ -241,7 +242,7 @@ GstGLDisplay *gst_gl_display_new (void);
 void gst_gl_display_create_context (GstGLDisplay * display,
     GLint width, GLint height, guint64 external_gl_context);
 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,
     GstGLDisplayThreadFunc func, gpointer data);