From 83e4733f4b8d4dc1386b163553121ce942ecabfe Mon Sep 17 00:00:00 2001 From: Hyunil Date: Mon, 31 Oct 2016 21:03:58 +0900 Subject: [PATCH] Waylandsink : resolve ROI concept different between wayland-sever and MSL API Change-Id: I67152f382063b6a011aa12c4d30798fcac435869 Signed-off-by: Hyunil (cherry picked from commit 6da53b2612daa5b70a917956eb486d93cf000e85) --- ext/wayland/wlwindow.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++-- ext/wayland/wlwindow.h | 4 ++ 2 files changed, 114 insertions(+), 4 deletions(-) diff --git a/ext/wayland/wlwindow.c b/ext/wayland/wlwindow.c index bdbb6a5..1e6fa86 100644 --- a/ext/wayland/wlwindow.c +++ b/ext/wayland/wlwindow.c @@ -33,6 +33,15 @@ enum { + ROTATE_0, + ROTATE_90, + ROTATE_180, + ROTATE_270, +}; + + +enum +{ ROTATE_0_FLIP_NONE, ROTATE_0_FLIP_HORIZONTAL, ROTATE_0_FLIP_VERTICAL, @@ -84,6 +93,31 @@ static const struct wl_shell_surface_listener shell_surface_listener = { }; static void +parent_size (void *data, struct tizen_viewport *tizen_viewport, uint32_t width, + uint32_t height) +{ + GstWlWindow *self = data; + FUNCTION; + g_return_if_fail (self != NULL); + self->parent_win.w = width; + self->parent_win.h = height; + GST_LOG ("parent size is (w)%d x (h)%d", self->parent_win.w, + self->parent_win.h); +} + +static void +destination_changed (void *data, struct tizen_viewport *tizen_viewport, + uint32_t transform, int32_t x, int32_t y, uint32_t width, uint32_t height) +{ +} + +static const struct tizen_viewport_listener viewport_listener = { + destination_changed, + parent_size, +}; + + +static void gst_wl_window_class_init (GstWlWindowClass * klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); @@ -95,8 +129,11 @@ static void gst_wl_window_init (GstWlWindow * self) { g_return_if_fail (self != NULL); - self->buffer_width = self->buffer_height = self->buffer_x = self->buffer_y = - 0; + self->buffer_width = self->buffer_height = 0; + self->buffer_x = self->buffer_y = 0; + self->parent_win.x = self->parent_win.y = 0; + self->parent_win.w = self->parent_win.h = 0; + self->roi.x = self->roi.y = self->roi.w = self->roi.h = 0; } static void @@ -294,6 +331,16 @@ gst_wl_window_new_internal (GstWlDisplay * display) GST_INFO ("tizen_area_viewport(tizen_viewport)@%p = tizen_video_get_viewport(tizen_video@%p, area_surface(wl_surface)@%p)", window->tizen_area_viewport, display->tizen_video, window->area_surface); + + /* query parent size */ + if (window->tizen_area_viewport) { + tizen_viewport_query_parent_size (window->tizen_area_viewport); + tizen_viewport_add_listener (window->tizen_area_viewport, + &viewport_listener, window); + /* to execute query(tizen_viewport_query_parent_size) immediately */ + wl_display_roundtrip (display->display); + } + window->tizen_video_viewport = tizen_video_get_viewport (display->tizen_video, window->video_surface); GST_INFO @@ -925,6 +972,44 @@ gst_wl_window_render (GstWlWindow * window, GstWlBuffer * buffer, #endif } +static void +gst_wl_window_calculate_wl_roi_rectangle (GstWlWindow * window) +{ + FUNCTION; + g_return_if_fail (window != NULL); + + switch (window->rotate_angle.value) { + case ROTATE_0: + window->wl_roi.x = window->roi.x; + window->wl_roi.y = window->roi.y; + window->wl_roi.w = window->roi.w; + window->wl_roi.h = window->roi.h; + break; + case ROTATE_90: + window->wl_roi.x = window->roi.y; + window->wl_roi.y = window->parent_win.h - (window->roi.w + window->roi.x); + window->wl_roi.w = window->roi.h; + window->wl_roi.h = window->roi.w; + break; + case ROTATE_180: + window->wl_roi.x = window->parent_win.w - (window->roi.w + window->roi.x); + window->wl_roi.y = window->parent_win.h - (window->roi.h + window->roi.y); + window->wl_roi.w = window->roi.w; + window->wl_roi.h = window->roi.h; + break; + case ROTATE_270: + window->wl_roi.x = window->parent_win.w - (window->roi.h + window->roi.y); + window->wl_roi.y = window->roi.x; + window->wl_roi.w = window->roi.h; + window->wl_roi.h = window->roi.w; + break; + default: + break; + } + GST_DEBUG ("wl roi : x(%d) y(%d) w(%d) h(%d)", window->wl_roi.x, + window->wl_roi.y, window->wl_roi.w, window->wl_roi.h); +} + void gst_wl_window_set_render_rectangle (GstWlWindow * window, gint x, gint y, gint w, gint h) @@ -938,14 +1023,30 @@ gst_wl_window_set_render_rectangle (GstWlWindow * window, gint x, gint y, ("must be set display-geometry-method to DISP_GEO_METHOD_CUSTOM_ROI before setting render rectangle()"); return; } + if (window->parent_win.w <= 0 || window->parent_win.h <= 0) { + GST_ERROR ("Error : get parent win size"); + } + if (w <= 0 || h <= 0) { + GST_ERROR ("Error : wrong roi size w(%d), h(%d)", w, h); + } + + window->roi.x = x; + window->roi.y = y; + window->roi.w = w; + window->roi.h = h; + window->wl_roi.x = window->wl_roi.y = window->wl_roi.w = window->wl_roi.h = 0; + /* calculate wl roi area */ + gst_wl_window_calculate_wl_roi_rectangle (window); /* position the area inside the parent - needs a parent commit to apply */ /* use tizen view port */ if (window->tizen_area_viewport) { GST_INFO ("tizen_viewport_set_destination (tizen_area_viewport(tizen_viewport)@%p, x@%d, y@%d, w@%d, h@%d)", - window->tizen_area_viewport, x, y, w, h); - tizen_viewport_set_destination (window->tizen_area_viewport, x, y, w, h); + window->tizen_area_viewport, window->wl_roi.x, window->wl_roi.y, + window->wl_roi.w, window->wl_roi.h); + tizen_viewport_set_destination (window->tizen_area_viewport, + window->wl_roi.x, window->wl_roi.y, window->wl_roi.w, window->wl_roi.h); } if (window->video_width != 0) { @@ -1000,6 +1101,11 @@ gst_wl_window_set_rotate_angle (GstWlWindow * window, guint rotate_angle) window->rotate_angle.value = rotate_angle; GST_LOG ("rotate_angle value is (%d)", window->rotate_angle.value); window->rotate_angle.changed = TRUE; + /* if set ROI */ + if (window->disp_geo_method.value == DISP_GEO_METHOD_CUSTOM_ROI + && window->roi.w > 0 && window->roi.h > 0) + gst_wl_window_set_render_rectangle (window, window->roi.x, window->roi.y, + window->roi.w, window->roi.h); } void diff --git a/ext/wayland/wlwindow.h b/ext/wayland/wlwindow.h index 55142f4..7df131c 100644 --- a/ext/wayland/wlwindow.h +++ b/ext/wayland/wlwindow.h @@ -92,6 +92,10 @@ struct _GstWlWindow WinGeometryRange mode_scale; WinGeometryRange mode_align; #endif + /* parent window size*/ + GstVideoRectangle parent_win; + GstVideoRectangle roi; + GstVideoRectangle wl_roi; #endif /* the size and position of the area_(sub)surface */ -- 2.7.4