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
This commit is contained in:
Nicolas Dufresne 2015-07-21 23:48:25 -04:00 committed by Tim-Philipp Müller
parent 8abd2bbe35
commit 1812c19291
5 changed files with 13 additions and 39 deletions

View file

@ -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,

View file

@ -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,

View file

@ -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);

View file

@ -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);
}

View file

@ -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);