From 485dffa6d5bd2a7e0758362b8fc19096bc0ac45e Mon Sep 17 00:00:00 2001 From: Gwang Yoon Hwang Date: Thu, 5 May 2016 15:53:57 +0900 Subject: [PATCH] gl/dispmanx: Implements set_render_rectangle to adjust the position of window We cannot set the x, y coordinate of the video frame at the dispmanx at this point. We need to teach dispmanx backend to understand about set_render_rectangle API to draw a video with other UI. This patch keeps the current behavior which places video frame at the center of the display if there is no set_render_rectangle call to the dispmanx window. https://bugzilla.gnome.org/show_bug.cgi?id=766018 --- .../gl/dispmanx/gstglwindow_dispmanx_egl.c | 43 ++++++++++++++++--- .../gl/dispmanx/gstglwindow_dispmanx_egl.h | 1 + 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/gst-libs/gst/gl/dispmanx/gstglwindow_dispmanx_egl.c b/gst-libs/gst/gl/dispmanx/gstglwindow_dispmanx_egl.c index f4a5ae0de9..d06424c6b6 100644 --- a/gst-libs/gst/gl/dispmanx/gstglwindow_dispmanx_egl.c +++ b/gst-libs/gst/gl/dispmanx/gstglwindow_dispmanx_egl.c @@ -57,7 +57,8 @@ static void gst_gl_window_dispmanx_egl_close (GstGLWindow * window); static gboolean gst_gl_window_dispmanx_egl_open (GstGLWindow * window, GError ** error); static guintptr gst_gl_window_dispmanx_egl_get_display (GstGLWindow * window); - +static gboolean gst_gl_window_dispmanx_egl_set_render_rectangle (GstGLWindow * + window, gint x, gint y, gint width, gint height); static void window_resize (GstGLWindowDispmanxEGL * window_egl, guint width, guint height, gboolean visible); @@ -78,6 +79,8 @@ gst_gl_window_dispmanx_egl_class_init (GstGLWindowDispmanxEGLClass * klass) GST_DEBUG_FUNCPTR (gst_gl_window_dispmanx_egl_get_display); window_class->set_preferred_size = GST_DEBUG_FUNCPTR (gst_gl_window_dispmanx_egl_set_preferred_size); + window_class->set_render_rectangle = + GST_DEBUG_FUNCPTR (gst_gl_window_dispmanx_egl_set_render_rectangle); } static void @@ -92,6 +95,10 @@ gst_gl_window_dispmanx_egl_init (GstGLWindowDispmanxEGL * window_egl) window_egl->native.element = 0; window_egl->native.width = 0; window_egl->native.height = 0; + window_egl->render_rect.x = 0; + window_egl->render_rect.y = 0; + window_egl->render_rect.w = 0; + window_egl->render_rect.h = 0; } /* Must be called in the gl thread */ @@ -194,20 +201,27 @@ window_resize (GstGLWindowDispmanxEGL * window_egl, guint width, guint height, if (window_egl->display) { VC_RECT_T dst_rect; VC_RECT_T src_rect; - GstVideoRectangle src, dst, res; + GstVideoRectangle src, res; DISPMANX_UPDATE_HANDLE_T dispman_update; uint32_t opacity = visible ? 255 : 0; VC_DISPMANX_ALPHA_T alpha = { DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS, opacity, 0 }; - /* Center width*height frame inside dp_width*dp_height */ src.w = width; src.h = height; src.x = src.y = 0; - dst.w = window_egl->dp_width; - dst.h = window_egl->dp_height; - dst.x = dst.y = 0; - gst_video_sink_center_rect (src, dst, &res, FALSE); + + /* If there is no render rectangle, center the width*height frame + * inside dp_width*dp_height */ + if (window_egl->render_rect.w <= 0 || window_egl->render_rect.h <= 0) { + GstVideoRectangle dst; + dst.w = window_egl->dp_width; + dst.h = window_egl->dp_height; + dst.x = dst.y = 0; + gst_video_sink_center_rect (src, dst, &res, FALSE); + } else { + gst_video_sink_center_rect (src, window_egl->render_rect, &res, FALSE); + } dst_rect.x = res.x; dst_rect.y = res.y; @@ -243,6 +257,21 @@ window_resize (GstGLWindowDispmanxEGL * window_egl, guint width, guint height, window_egl->native.height = height; } +static gboolean +gst_gl_window_dispmanx_egl_set_render_rectangle (GstGLWindow * window, + gint x, gint y, gint width, gint height) +{ + GstGLWindowDispmanxEGL *window_egl = GST_GL_WINDOW_DISPMANX_EGL (window); + window_egl->render_rect.x = x; + window_egl->render_rect.y = x; + window_egl->render_rect.w = width; + window_egl->render_rect.h = height; + + window_resize (window_egl, window_egl->render_rect.w, + window_egl->render_rect.h, TRUE); + return TRUE; +} + static void gst_gl_window_dispmanx_egl_show (GstGLWindow * window) { diff --git a/gst-libs/gst/gl/dispmanx/gstglwindow_dispmanx_egl.h b/gst-libs/gst/gl/dispmanx/gstglwindow_dispmanx_egl.h index 3130a6c346..f0663e22cd 100644 --- a/gst-libs/gst/gl/dispmanx/gstglwindow_dispmanx_egl.h +++ b/gst-libs/gst/gl/dispmanx/gstglwindow_dispmanx_egl.h @@ -67,6 +67,7 @@ struct _GstGLWindowDispmanxEGL { gint preferred_width; gint preferred_height; + GstVideoRectangle render_rect; gboolean visible;