From 1812c1929179ca76a4ab1de0020bfea892f300d7 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Tue, 21 Jul 2015 23:48:25 -0400 Subject: [PATCH] composition-overlay: Positions are relative to texture The coordinate are relative to the texture dimension and not the window dimension now. There is no need to pass the window dimension or to update the overlay if the dimension changes. https://bugzilla.gnome.org/show_bug.cgi?id=745107 --- ext/gl/gstglimagesink.c | 2 +- gst-libs/gst/gl/gstglcompositionoverlay.c | 33 ++++++----------------- gst-libs/gst/gl/gstglcompositionoverlay.h | 2 +- gst-libs/gst/gl/gstgloverlaycompositor.c | 13 ++------- gst-libs/gst/gl/gstgloverlaycompositor.h | 2 +- 5 files changed, 13 insertions(+), 39 deletions(-) diff --git a/ext/gl/gstglimagesink.c b/ext/gl/gstglimagesink.c index adb56d08d2..1a8c934569 100644 --- a/ext/gl/gstglimagesink.c +++ b/ext/gl/gstglimagesink.c @@ -1287,7 +1287,7 @@ prepare_next_buffer (GstGLImageSink * glimage_sink) } gst_gl_overlay_compositor_upload_overlays (glimage_sink->overlay_compositor, - next_buffer, glimage_sink->window_width, glimage_sink->window_height); + next_buffer); /* in_buffer invalid now */ if (!gst_video_frame_map (&gl_frame, info, next_buffer, diff --git a/gst-libs/gst/gl/gstglcompositionoverlay.c b/gst-libs/gst/gl/gstglcompositionoverlay.c index e1268cb3fb..181db4aa57 100644 --- a/gst-libs/gst/gl/gstglcompositionoverlay.c +++ b/gst-libs/gst/gl/gstglcompositionoverlay.c @@ -42,7 +42,7 @@ G_DEFINE_TYPE_WITH_CODE (GstGLCompositionOverlay, gst_gl_composition_overlay, static void gst_gl_composition_overlay_finalize (GObject * object); static void gst_gl_composition_overlay_add_transformation (GstGLCompositionOverlay * - overlay, GstBuffer * video_buffer, guint window_width, guint window_height); + overlay, GstBuffer * video_buffer); static void gst_gl_composition_overlay_class_init (GstGLCompositionOverlayClass * klass) @@ -204,7 +204,7 @@ gst_gl_composition_overlay_init_vertex_buffer (GstGLContext * context, static void gst_gl_composition_overlay_add_transformation (GstGLCompositionOverlay * - overlay, GstBuffer * video_buffer, guint window_width, guint window_height) + overlay, GstBuffer * video_buffer) { gint comp_x, comp_y; guint comp_width, comp_height; @@ -213,19 +213,13 @@ gst_gl_composition_overlay_add_transformation (GstGLCompositionOverlay * float rel_x, rel_y, rel_w, rel_h; - gfloat window_aspect = 1.0; - gfloat video_aspect = 1.0; - meta = gst_buffer_get_video_meta (video_buffer); gst_video_overlay_rectangle_get_render_rectangle (overlay->rectangle, &comp_x, &comp_y, &comp_width, &comp_height); - width = window_width; - height = window_height; - - window_aspect = (float) width / (float) height; - video_aspect = (float) meta->width / (float) meta->height; + width = meta->width; + height = meta->height; /* calculate relative position */ rel_x = (float) comp_x / (float) width; @@ -234,15 +228,6 @@ gst_gl_composition_overlay_add_transformation (GstGLCompositionOverlay * rel_w = (float) comp_width / (float) width; rel_h = (float) comp_height / (float) height; - /* transform to window aspect ratio */ - if (window_aspect <= video_aspect) { - rel_y *= video_aspect / window_aspect; - rel_h *= video_aspect / window_aspect; - } else { - rel_x *= window_aspect / video_aspect; - rel_w *= window_aspect / video_aspect; - } - /* transform from [0,1] to [-1,1], invert y axis */ rel_x = rel_x * 2.0 - 1.0; rel_y = (1.0 - rel_y) * 2.0 - 1.0; @@ -274,14 +259,13 @@ gst_gl_composition_overlay_add_transformation (GstGLCompositionOverlay * gst_gl_composition_overlay_init_vertex_buffer, overlay); GST_DEBUG - ("overlay position: (%d,%d) size: %dx%d video size: %dx%d, sink window %dx%d", - comp_x, comp_y, comp_width, comp_height, meta->width, meta->height, - window_width, window_height); + ("overlay position: (%d,%d) size: %dx%d video size: %dx%d", + comp_x, comp_y, comp_width, comp_height, meta->width, meta->height); } void gst_gl_composition_overlay_upload (GstGLCompositionOverlay * overlay, - GstBuffer * buf, guint window_width, guint window_height) + GstBuffer * buf) { GstMapInfo info; GstVideoMeta *vmeta; @@ -306,8 +290,7 @@ gst_gl_composition_overlay_upload (GstGLCompositionOverlay * overlay, meta = gst_buffer_get_video_meta (comp_buffer); - gst_gl_composition_overlay_add_transformation (overlay, buf, window_width, - window_height); + gst_gl_composition_overlay_add_transformation (overlay, buf); gst_video_info_init (&text_info); gst_video_info_set_format (&text_info, meta->format, meta->width, diff --git a/gst-libs/gst/gl/gstglcompositionoverlay.h b/gst-libs/gst/gl/gstglcompositionoverlay.h index a7a7ccb10f..005ef2f6e2 100644 --- a/gst-libs/gst/gl/gstglcompositionoverlay.h +++ b/gst-libs/gst/gl/gstglcompositionoverlay.h @@ -74,7 +74,7 @@ GstGLCompositionOverlay *gst_gl_composition_overlay_new (GstGLContext * context, GLint texcoord_attrib); void gst_gl_composition_overlay_upload (GstGLCompositionOverlay * overlay, - GstBuffer * buf, guint window_width, guint window_height); + GstBuffer * buf); void gst_gl_composition_overlay_draw (GstGLCompositionOverlay * overlay, GstGLShader * shader); diff --git a/gst-libs/gst/gl/gstgloverlaycompositor.c b/gst-libs/gst/gl/gstgloverlaycompositor.c index 9b164abb3d..dfafdb2db8 100644 --- a/gst-libs/gst/gl/gstgloverlaycompositor.c +++ b/gst-libs/gst/gl/gstgloverlaycompositor.c @@ -153,18 +153,10 @@ gst_gl_overlay_compositor_free_overlays (GstGLOverlayCompositor * compositor) void gst_gl_overlay_compositor_upload_overlays (GstGLOverlayCompositor * compositor, - GstBuffer * buf, guint window_width, guint window_height) + GstBuffer * buf) { GstVideoOverlayCompositionMeta *composition_meta; - if (compositor->last_window_width != window_width || - compositor->last_window_height != window_height) { - gst_gl_overlay_compositor_free_overlays (compositor); - compositor->last_window_width = window_width; - compositor->last_window_height = window_height; - GST_DEBUG ("window size changed, freeing overlays"); - } - composition_meta = gst_buffer_get_video_overlay_composition_meta (buf); if (composition_meta) { GstVideoOverlayComposition *composition = NULL; @@ -186,8 +178,7 @@ gst_gl_overlay_compositor_upload_overlays (GstGLOverlayCompositor * compositor, gst_gl_composition_overlay_new (compositor->context, rectangle, compositor->position_attrib, compositor->texcoord_attrib); - gst_gl_composition_overlay_upload (overlay, buf, window_width, - window_height); + gst_gl_composition_overlay_upload (overlay, buf); compositor->overlays = g_list_append (compositor->overlays, overlay); } diff --git a/gst-libs/gst/gl/gstgloverlaycompositor.h b/gst-libs/gst/gl/gstgloverlaycompositor.h index cd8ae858de..d35a5c0d0f 100644 --- a/gst-libs/gst/gl/gstgloverlaycompositor.h +++ b/gst-libs/gst/gl/gstgloverlaycompositor.h @@ -69,7 +69,7 @@ GstGLOverlayCompositor *gst_gl_overlay_compositor_new (GstGLContext * context); void gst_gl_overlay_compositor_free_overlays (GstGLOverlayCompositor * compositor); void gst_gl_overlay_compositor_upload_overlays (GstGLOverlayCompositor * compositor, - GstBuffer * buf, guint window_width, guint window_height); + GstBuffer * buf); void gst_gl_overlay_compositor_draw_overlays (GstGLOverlayCompositor * compositor);