2014-02-13 10:59:45 +00:00
|
|
|
/* GStreamer Wayland video sink
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Intel Corporation
|
|
|
|
* Copyright (C) 2011 Sreerenj Balachandran <sreerenj.balachandran@intel.com>
|
|
|
|
* Copyright (C) 2014 Collabora Ltd.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free
|
|
|
|
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2014-02-13 12:15:31 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2014-02-13 10:59:45 +00:00
|
|
|
#include "wlwindow.h"
|
2014-07-01 08:43:20 +00:00
|
|
|
#include "wlshmallocator.h"
|
|
|
|
#include "wlbuffer.h"
|
2014-02-13 10:59:45 +00:00
|
|
|
|
2014-02-13 12:28:40 +00:00
|
|
|
GST_DEBUG_CATEGORY_EXTERN (gstwayland_debug);
|
|
|
|
#define GST_CAT_DEFAULT gstwayland_debug
|
|
|
|
|
2019-03-01 08:56:24 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
CLOSED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2014-02-13 10:59:45 +00:00
|
|
|
G_DEFINE_TYPE (GstWlWindow, gst_wl_window, G_TYPE_OBJECT);
|
|
|
|
|
|
|
|
static void gst_wl_window_finalize (GObject * gobject);
|
|
|
|
|
2019-03-01 08:56:24 +00:00
|
|
|
static void
|
|
|
|
handle_xdg_toplevel_close (void *data, struct xdg_toplevel *xdg_toplevel)
|
|
|
|
{
|
|
|
|
GstWlWindow *window = data;
|
|
|
|
|
|
|
|
GST_DEBUG ("XDG toplevel got a \"close\" event.");
|
|
|
|
g_signal_emit (window, signals[CLOSED], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_xdg_toplevel_configure (void *data, struct xdg_toplevel *xdg_toplevel,
|
|
|
|
int32_t width, int32_t height, struct wl_array *states)
|
|
|
|
{
|
|
|
|
GstWlWindow *window = data;
|
|
|
|
const uint32_t *state;
|
|
|
|
|
|
|
|
GST_DEBUG ("XDG toplevel got a \"configure\" event, [ %d, %d ].",
|
|
|
|
width, height);
|
|
|
|
|
|
|
|
wl_array_for_each (state, states) {
|
|
|
|
switch (*state) {
|
|
|
|
case XDG_TOPLEVEL_STATE_FULLSCREEN:
|
|
|
|
case XDG_TOPLEVEL_STATE_MAXIMIZED:
|
|
|
|
case XDG_TOPLEVEL_STATE_RESIZING:
|
|
|
|
case XDG_TOPLEVEL_STATE_ACTIVATED:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (width <= 0 || height <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gst_wl_window_set_render_rectangle (window, 0, 0, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct xdg_toplevel_listener xdg_toplevel_listener = {
|
|
|
|
handle_xdg_toplevel_configure,
|
|
|
|
handle_xdg_toplevel_close,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_xdg_surface_configure (void *data, struct xdg_surface *xdg_surface,
|
|
|
|
uint32_t serial)
|
|
|
|
{
|
2019-03-26 02:21:09 +00:00
|
|
|
GstWlWindow *window = data;
|
2019-03-01 08:56:24 +00:00
|
|
|
xdg_surface_ack_configure (xdg_surface, serial);
|
2019-03-26 02:21:09 +00:00
|
|
|
|
|
|
|
g_mutex_lock (&window->configure_mutex);
|
|
|
|
window->configured = TRUE;
|
|
|
|
g_cond_signal (&window->configure_cond);
|
|
|
|
g_mutex_unlock (&window->configure_mutex);
|
2019-03-01 08:56:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct xdg_surface_listener xdg_surface_listener = {
|
|
|
|
handle_xdg_surface_configure,
|
|
|
|
};
|
|
|
|
|
2014-02-13 10:59:45 +00:00
|
|
|
static void
|
2019-03-01 09:17:23 +00:00
|
|
|
handle_ping (void *data, struct wl_shell_surface *wl_shell_surface,
|
2014-02-13 10:59:45 +00:00
|
|
|
uint32_t serial)
|
|
|
|
{
|
2019-03-01 09:17:23 +00:00
|
|
|
wl_shell_surface_pong (wl_shell_surface, serial);
|
2014-02-13 10:59:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-03-01 09:17:23 +00:00
|
|
|
handle_configure (void *data, struct wl_shell_surface *wl_shell_surface,
|
2014-02-13 10:59:45 +00:00
|
|
|
uint32_t edges, int32_t width, int32_t height)
|
|
|
|
{
|
2016-09-22 22:55:23 +00:00
|
|
|
GstWlWindow *window = data;
|
|
|
|
|
|
|
|
GST_DEBUG ("Windows configure: edges %x, width = %i, height %i", edges,
|
|
|
|
width, height);
|
|
|
|
|
|
|
|
if (width == 0 || height == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gst_wl_window_set_render_rectangle (window, 0, 0, width, height);
|
2014-02-13 10:59:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-03-01 09:17:23 +00:00
|
|
|
handle_popup_done (void *data, struct wl_shell_surface *wl_shell_surface)
|
2014-02-13 10:59:45 +00:00
|
|
|
{
|
2016-09-22 22:55:23 +00:00
|
|
|
GST_DEBUG ("Window popup done.");
|
2014-02-13 10:59:45 +00:00
|
|
|
}
|
|
|
|
|
2019-03-01 09:17:23 +00:00
|
|
|
static const struct wl_shell_surface_listener wl_shell_surface_listener = {
|
2014-02-13 10:59:45 +00:00
|
|
|
handle_ping,
|
|
|
|
handle_configure,
|
|
|
|
handle_popup_done
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_wl_window_class_init (GstWlWindowClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
gobject_class->finalize = gst_wl_window_finalize;
|
2019-03-01 08:56:24 +00:00
|
|
|
|
|
|
|
signals[CLOSED] = g_signal_new ("closed", G_TYPE_FROM_CLASS (gobject_class),
|
|
|
|
G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 0);
|
2014-02-13 10:59:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_wl_window_init (GstWlWindow * self)
|
|
|
|
{
|
2019-03-26 02:21:09 +00:00
|
|
|
self->configured = TRUE;
|
|
|
|
g_cond_init (&self->configure_cond);
|
|
|
|
g_mutex_init (&self->configure_mutex);
|
2014-02-13 10:59:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_wl_window_finalize (GObject * gobject)
|
|
|
|
{
|
|
|
|
GstWlWindow *self = GST_WL_WINDOW (gobject);
|
|
|
|
|
2019-03-01 09:17:23 +00:00
|
|
|
if (self->wl_shell_surface)
|
|
|
|
wl_shell_surface_destroy (self->wl_shell_surface);
|
2014-02-13 10:59:45 +00:00
|
|
|
|
2019-03-01 08:56:24 +00:00
|
|
|
if (self->xdg_toplevel)
|
|
|
|
xdg_toplevel_destroy (self->xdg_toplevel);
|
|
|
|
if (self->xdg_surface)
|
|
|
|
xdg_surface_destroy (self->xdg_surface);
|
|
|
|
|
2016-09-15 18:10:02 +00:00
|
|
|
if (self->video_viewport)
|
|
|
|
wp_viewport_destroy (self->video_viewport);
|
|
|
|
|
2018-12-03 07:18:32 +00:00
|
|
|
wl_proxy_wrapper_destroy (self->video_surface_wrapper);
|
2014-07-01 08:43:20 +00:00
|
|
|
wl_subsurface_destroy (self->video_subsurface);
|
|
|
|
wl_surface_destroy (self->video_surface);
|
2014-05-23 15:18:32 +00:00
|
|
|
|
2016-09-15 18:10:02 +00:00
|
|
|
if (self->area_subsurface)
|
2014-07-01 08:43:20 +00:00
|
|
|
wl_subsurface_destroy (self->area_subsurface);
|
2016-09-15 18:10:02 +00:00
|
|
|
|
|
|
|
if (self->area_viewport)
|
|
|
|
wp_viewport_destroy (self->area_viewport);
|
|
|
|
|
2018-12-03 07:18:32 +00:00
|
|
|
wl_proxy_wrapper_destroy (self->area_surface_wrapper);
|
2014-07-01 08:43:20 +00:00
|
|
|
wl_surface_destroy (self->area_surface);
|
2014-05-26 09:54:10 +00:00
|
|
|
|
2014-02-13 10:59:45 +00:00
|
|
|
g_clear_object (&self->display);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gst_wl_window_parent_class)->finalize (gobject);
|
|
|
|
}
|
|
|
|
|
2014-05-26 09:54:10 +00:00
|
|
|
static GstWlWindow *
|
2016-09-22 22:55:23 +00:00
|
|
|
gst_wl_window_new_internal (GstWlDisplay * display, GMutex * render_lock)
|
2014-05-26 09:54:10 +00:00
|
|
|
{
|
|
|
|
GstWlWindow *window;
|
2019-09-02 01:22:10 +00:00
|
|
|
struct wl_region *region;
|
2014-05-26 09:54:10 +00:00
|
|
|
|
|
|
|
window = g_object_new (GST_TYPE_WL_WINDOW, NULL);
|
|
|
|
window->display = g_object_ref (display);
|
2016-09-22 22:55:23 +00:00
|
|
|
window->render_lock = render_lock;
|
2019-03-26 02:21:09 +00:00
|
|
|
g_cond_init (&window->configure_cond);
|
2014-05-26 09:54:10 +00:00
|
|
|
|
2014-07-01 08:43:20 +00:00
|
|
|
window->area_surface = wl_compositor_create_surface (display->compositor);
|
|
|
|
window->video_surface = wl_compositor_create_surface (display->compositor);
|
|
|
|
|
2018-12-03 07:18:32 +00:00
|
|
|
window->area_surface_wrapper = wl_proxy_create_wrapper (window->area_surface);
|
|
|
|
window->video_surface_wrapper =
|
|
|
|
wl_proxy_create_wrapper (window->video_surface);
|
|
|
|
|
|
|
|
wl_proxy_set_queue ((struct wl_proxy *) window->area_surface_wrapper,
|
|
|
|
display->queue);
|
|
|
|
wl_proxy_set_queue ((struct wl_proxy *) window->video_surface_wrapper,
|
2014-07-01 08:43:20 +00:00
|
|
|
display->queue);
|
|
|
|
|
|
|
|
/* embed video_surface in area_surface */
|
|
|
|
window->video_subsurface =
|
|
|
|
wl_subcompositor_get_subsurface (display->subcompositor,
|
|
|
|
window->video_surface, window->area_surface);
|
|
|
|
wl_subsurface_set_desync (window->video_subsurface);
|
|
|
|
|
2016-09-15 18:10:02 +00:00
|
|
|
if (display->viewporter) {
|
|
|
|
window->area_viewport = wp_viewporter_get_viewport (display->viewporter,
|
|
|
|
window->area_surface);
|
|
|
|
window->video_viewport = wp_viewporter_get_viewport (display->viewporter,
|
|
|
|
window->video_surface);
|
|
|
|
}
|
2014-07-01 08:43:20 +00:00
|
|
|
|
2014-05-26 09:54:10 +00:00
|
|
|
/* do not accept input */
|
2019-09-02 01:22:10 +00:00
|
|
|
region = wl_compositor_create_region (display->compositor);
|
|
|
|
wl_surface_set_input_region (window->area_surface, region);
|
|
|
|
wl_region_destroy (region);
|
|
|
|
|
|
|
|
region = wl_compositor_create_region (display->compositor);
|
|
|
|
wl_surface_set_input_region (window->video_surface, region);
|
|
|
|
wl_region_destroy (region);
|
2014-05-26 09:54:10 +00:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2017-02-23 10:48:13 +00:00
|
|
|
void
|
|
|
|
gst_wl_window_ensure_fullscreen (GstWlWindow * window, gboolean fullscreen)
|
|
|
|
{
|
|
|
|
if (!window)
|
|
|
|
return;
|
|
|
|
|
2019-03-01 08:56:24 +00:00
|
|
|
if (window->display->xdg_wm_base) {
|
|
|
|
if (fullscreen)
|
|
|
|
xdg_toplevel_set_fullscreen (window->xdg_toplevel, NULL);
|
|
|
|
else
|
|
|
|
xdg_toplevel_unset_fullscreen (window->xdg_toplevel);
|
|
|
|
} else {
|
|
|
|
if (fullscreen)
|
|
|
|
wl_shell_surface_set_fullscreen (window->wl_shell_surface,
|
|
|
|
WL_SHELL_SURFACE_FULLSCREEN_METHOD_SCALE, 0, NULL);
|
|
|
|
else
|
|
|
|
wl_shell_surface_set_toplevel (window->wl_shell_surface);
|
|
|
|
}
|
2017-02-23 10:48:13 +00:00
|
|
|
}
|
|
|
|
|
2014-02-13 10:59:45 +00:00
|
|
|
GstWlWindow *
|
2016-09-22 22:55:23 +00:00
|
|
|
gst_wl_window_new_toplevel (GstWlDisplay * display, const GstVideoInfo * info,
|
2017-02-23 10:48:13 +00:00
|
|
|
gboolean fullscreen, GMutex * render_lock)
|
2014-02-13 10:59:45 +00:00
|
|
|
{
|
|
|
|
GstWlWindow *window;
|
2014-07-01 08:43:20 +00:00
|
|
|
gint width;
|
2014-02-13 10:59:45 +00:00
|
|
|
|
2016-09-22 22:55:23 +00:00
|
|
|
window = gst_wl_window_new_internal (display, render_lock);
|
2014-05-21 10:14:15 +00:00
|
|
|
|
2019-03-01 08:56:24 +00:00
|
|
|
/* Check which protocol we will use (in order of preference) */
|
|
|
|
if (display->xdg_wm_base) {
|
2019-05-24 00:24:40 +00:00
|
|
|
gint64 timeout;
|
|
|
|
|
2019-03-01 08:56:24 +00:00
|
|
|
/* First create the XDG surface */
|
|
|
|
window->xdg_surface = xdg_wm_base_get_xdg_surface (display->xdg_wm_base,
|
|
|
|
window->area_surface);
|
|
|
|
if (!window->xdg_surface) {
|
|
|
|
GST_ERROR ("Unable to get xdg_surface");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
xdg_surface_add_listener (window->xdg_surface, &xdg_surface_listener,
|
|
|
|
window);
|
|
|
|
|
|
|
|
/* Then the toplevel */
|
|
|
|
window->xdg_toplevel = xdg_surface_get_toplevel (window->xdg_surface);
|
|
|
|
if (!window->xdg_toplevel) {
|
|
|
|
GST_ERROR ("Unable to get xdg_toplevel");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
xdg_toplevel_add_listener (window->xdg_toplevel,
|
|
|
|
&xdg_toplevel_listener, window);
|
|
|
|
|
|
|
|
gst_wl_window_ensure_fullscreen (window, fullscreen);
|
2019-03-26 02:21:09 +00:00
|
|
|
|
|
|
|
/* Finally, commit the xdg_surface state as toplevel */
|
|
|
|
window->configured = FALSE;
|
|
|
|
wl_surface_commit (window->video_surface);
|
|
|
|
wl_display_flush (display->display);
|
|
|
|
|
|
|
|
g_mutex_lock (&window->configure_mutex);
|
2019-05-24 00:24:40 +00:00
|
|
|
timeout = g_get_monotonic_time () + 100 * G_TIME_SPAN_MILLISECOND;
|
|
|
|
while (!window->configured) {
|
|
|
|
if (!g_cond_wait_until (&window->configure_cond, &window->configure_mutex,
|
|
|
|
timeout)) {
|
|
|
|
GST_WARNING ("The compositor did not send configure event.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-03-26 02:21:09 +00:00
|
|
|
g_mutex_unlock (&window->configure_mutex);
|
2019-03-01 08:56:24 +00:00
|
|
|
} else if (display->wl_shell) {
|
2018-07-10 01:20:59 +00:00
|
|
|
/* go toplevel */
|
2019-03-01 09:17:23 +00:00
|
|
|
window->wl_shell_surface = wl_shell_get_shell_surface (display->wl_shell,
|
2018-07-10 01:20:59 +00:00
|
|
|
window->area_surface);
|
2019-03-01 08:56:24 +00:00
|
|
|
if (!window->wl_shell_surface) {
|
2018-07-10 01:20:59 +00:00
|
|
|
GST_ERROR ("Unable to get wl_shell_surface");
|
2019-03-01 08:56:24 +00:00
|
|
|
goto error;
|
2018-07-10 01:20:59 +00:00
|
|
|
}
|
2019-03-01 08:56:24 +00:00
|
|
|
|
|
|
|
wl_shell_surface_add_listener (window->wl_shell_surface,
|
|
|
|
&wl_shell_surface_listener, window);
|
|
|
|
gst_wl_window_ensure_fullscreen (window, fullscreen);
|
2018-07-10 01:20:59 +00:00
|
|
|
} else if (display->fullscreen_shell) {
|
|
|
|
zwp_fullscreen_shell_v1_present_surface (display->fullscreen_shell,
|
|
|
|
window->area_surface, ZWP_FULLSCREEN_SHELL_V1_PRESENT_METHOD_ZOOM,
|
|
|
|
NULL);
|
|
|
|
} else {
|
2019-03-01 08:56:24 +00:00
|
|
|
GST_ERROR ("Unable to use either wl_shell, xdg_wm_base or "
|
|
|
|
"zwp_fullscreen_shell.");
|
|
|
|
goto error;
|
2014-02-13 10:59:45 +00:00
|
|
|
}
|
|
|
|
|
2014-07-01 08:43:20 +00:00
|
|
|
/* set the initial size to be the same as the reported video size */
|
|
|
|
width =
|
|
|
|
gst_util_uint64_scale_int_round (info->width, info->par_n, info->par_d);
|
|
|
|
gst_wl_window_set_render_rectangle (window, 0, 0, width, info->height);
|
|
|
|
|
2014-02-13 10:59:45 +00:00
|
|
|
return window;
|
2019-03-01 08:56:24 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
g_object_unref (window);
|
|
|
|
return NULL;
|
2014-02-13 10:59:45 +00:00
|
|
|
}
|
|
|
|
|
2014-05-23 15:18:32 +00:00
|
|
|
GstWlWindow *
|
|
|
|
gst_wl_window_new_in_surface (GstWlDisplay * display,
|
2016-09-22 22:55:23 +00:00
|
|
|
struct wl_surface * parent, GMutex * render_lock)
|
2014-05-23 15:18:32 +00:00
|
|
|
{
|
|
|
|
GstWlWindow *window;
|
2016-09-22 22:55:23 +00:00
|
|
|
window = gst_wl_window_new_internal (display, render_lock);
|
2014-05-23 15:18:32 +00:00
|
|
|
|
2014-07-01 08:43:20 +00:00
|
|
|
/* embed in parent */
|
|
|
|
window->area_subsurface =
|
|
|
|
wl_subcompositor_get_subsurface (display->subcompositor,
|
|
|
|
window->area_surface, parent);
|
|
|
|
wl_subsurface_set_desync (window->area_subsurface);
|
2014-05-23 15:18:32 +00:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2014-02-13 10:59:45 +00:00
|
|
|
GstWlDisplay *
|
|
|
|
gst_wl_window_get_display (GstWlWindow * window)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (window != NULL, NULL);
|
|
|
|
|
|
|
|
return g_object_ref (window->display);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wl_surface *
|
|
|
|
gst_wl_window_get_wl_surface (GstWlWindow * window)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (window != NULL, NULL);
|
|
|
|
|
2018-12-03 07:18:32 +00:00
|
|
|
return window->video_surface_wrapper;
|
2014-02-13 10:59:45 +00:00
|
|
|
}
|
|
|
|
|
2014-02-28 09:48:30 +00:00
|
|
|
gboolean
|
|
|
|
gst_wl_window_is_toplevel (GstWlWindow * window)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (window != NULL, FALSE);
|
|
|
|
|
2019-04-09 18:32:36 +00:00
|
|
|
if (window->display->xdg_wm_base)
|
|
|
|
return (window->xdg_toplevel != NULL);
|
|
|
|
else
|
|
|
|
return (window->wl_shell_surface != NULL);
|
2014-02-28 09:48:30 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 11:13:56 +00:00
|
|
|
static void
|
2014-07-01 08:43:20 +00:00
|
|
|
gst_wl_window_resize_video_surface (GstWlWindow * window, gboolean commit)
|
2014-05-26 11:13:56 +00:00
|
|
|
{
|
2014-12-16 12:35:14 +00:00
|
|
|
GstVideoRectangle src = { 0, };
|
2015-11-18 11:56:06 +00:00
|
|
|
GstVideoRectangle dst = { 0, };
|
2014-12-16 12:35:14 +00:00
|
|
|
GstVideoRectangle res;
|
2014-05-26 11:13:56 +00:00
|
|
|
|
2014-07-01 08:43:20 +00:00
|
|
|
/* center the video_subsurface inside area_subsurface */
|
2014-05-26 11:13:56 +00:00
|
|
|
src.w = window->video_width;
|
|
|
|
src.h = window->video_height;
|
2015-11-18 11:56:06 +00:00
|
|
|
dst.w = window->render_rectangle.w;
|
|
|
|
dst.h = window->render_rectangle.h;
|
2016-09-15 18:10:02 +00:00
|
|
|
|
|
|
|
if (window->video_viewport) {
|
|
|
|
gst_video_sink_center_rect (src, dst, &res, TRUE);
|
|
|
|
wp_viewport_set_destination (window->video_viewport, res.w, res.h);
|
|
|
|
} else {
|
|
|
|
gst_video_sink_center_rect (src, dst, &res, FALSE);
|
|
|
|
}
|
2014-05-26 11:13:56 +00:00
|
|
|
|
2014-07-01 08:43:20 +00:00
|
|
|
wl_subsurface_set_position (window->video_subsurface, res.x, res.y);
|
2016-09-15 18:10:02 +00:00
|
|
|
|
2014-06-13 14:37:38 +00:00
|
|
|
if (commit) {
|
2018-12-03 07:18:32 +00:00
|
|
|
wl_surface_damage (window->video_surface_wrapper, 0, 0, res.w, res.h);
|
|
|
|
wl_surface_commit (window->video_surface_wrapper);
|
2014-06-13 14:37:38 +00:00
|
|
|
}
|
2014-05-26 11:13:56 +00:00
|
|
|
|
2014-07-24 14:53:53 +00:00
|
|
|
if (gst_wl_window_is_toplevel (window)) {
|
|
|
|
struct wl_region *region;
|
|
|
|
|
|
|
|
region = wl_compositor_create_region (window->display->compositor);
|
2014-12-16 12:35:14 +00:00
|
|
|
wl_region_add (region, 0, 0, window->render_rectangle.w,
|
|
|
|
window->render_rectangle.h);
|
2014-07-24 14:53:53 +00:00
|
|
|
wl_surface_set_input_region (window->area_surface, region);
|
|
|
|
wl_region_destroy (region);
|
|
|
|
}
|
|
|
|
|
2014-05-26 11:13:56 +00:00
|
|
|
/* this is saved for use in wl_surface_damage */
|
2016-09-22 19:35:44 +00:00
|
|
|
window->video_rectangle = res;
|
2014-05-26 11:13:56 +00:00
|
|
|
}
|
|
|
|
|
2017-02-02 15:47:52 +00:00
|
|
|
static void
|
|
|
|
gst_wl_window_set_opaque (GstWlWindow * window, const GstVideoInfo * info)
|
|
|
|
{
|
|
|
|
struct wl_region *region;
|
|
|
|
|
|
|
|
/* Set area opaque */
|
|
|
|
region = wl_compositor_create_region (window->display->compositor);
|
|
|
|
wl_region_add (region, 0, 0, window->render_rectangle.w,
|
|
|
|
window->render_rectangle.h);
|
|
|
|
wl_surface_set_opaque_region (window->area_surface, region);
|
|
|
|
wl_region_destroy (region);
|
|
|
|
|
|
|
|
if (!GST_VIDEO_INFO_HAS_ALPHA (info)) {
|
|
|
|
/* Set video opaque */
|
|
|
|
region = wl_compositor_create_region (window->display->compositor);
|
|
|
|
wl_region_add (region, 0, 0, window->render_rectangle.w,
|
|
|
|
window->render_rectangle.h);
|
|
|
|
wl_surface_set_opaque_region (window->video_surface, region);
|
|
|
|
wl_region_destroy (region);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-13 10:59:45 +00:00
|
|
|
void
|
2014-07-01 08:43:20 +00:00
|
|
|
gst_wl_window_render (GstWlWindow * window, GstWlBuffer * buffer,
|
|
|
|
const GstVideoInfo * info)
|
2014-02-13 10:59:45 +00:00
|
|
|
{
|
2014-07-01 08:43:20 +00:00
|
|
|
if (G_UNLIKELY (info)) {
|
|
|
|
window->video_width =
|
|
|
|
gst_util_uint64_scale_int_round (info->width, info->par_n, info->par_d);
|
|
|
|
window->video_height = info->height;
|
2014-02-13 10:59:45 +00:00
|
|
|
|
2014-07-01 08:43:20 +00:00
|
|
|
wl_subsurface_set_sync (window->video_subsurface);
|
|
|
|
gst_wl_window_resize_video_surface (window, FALSE);
|
2017-02-02 15:47:52 +00:00
|
|
|
gst_wl_window_set_opaque (window, info);
|
2014-07-01 08:43:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (G_LIKELY (buffer))
|
2018-12-03 07:18:32 +00:00
|
|
|
gst_wl_buffer_attach (buffer, window->video_surface_wrapper);
|
2014-07-01 08:43:20 +00:00
|
|
|
else
|
2018-12-03 07:18:32 +00:00
|
|
|
wl_surface_attach (window->video_surface_wrapper, NULL, 0, 0);
|
2014-07-01 08:43:20 +00:00
|
|
|
|
2018-12-03 07:18:32 +00:00
|
|
|
wl_surface_damage (window->video_surface_wrapper, 0, 0,
|
|
|
|
window->video_rectangle.w, window->video_rectangle.h);
|
|
|
|
wl_surface_commit (window->video_surface_wrapper);
|
2014-07-01 08:43:20 +00:00
|
|
|
|
|
|
|
if (G_UNLIKELY (info)) {
|
|
|
|
/* commit also the parent (area_surface) in order to change
|
|
|
|
* the position of the video_subsurface */
|
2018-12-03 07:18:32 +00:00
|
|
|
wl_surface_damage (window->area_surface_wrapper, 0, 0,
|
|
|
|
window->render_rectangle.w, window->render_rectangle.h);
|
|
|
|
wl_surface_commit (window->area_surface_wrapper);
|
2014-07-01 08:43:20 +00:00
|
|
|
wl_subsurface_set_desync (window->video_subsurface);
|
|
|
|
}
|
2014-05-26 11:13:56 +00:00
|
|
|
|
2014-07-01 08:43:20 +00:00
|
|
|
wl_display_flush (window->display->display);
|
2014-05-26 11:13:56 +00:00
|
|
|
}
|
|
|
|
|
2016-09-22 19:35:44 +00:00
|
|
|
/* Update the buffer used to draw black borders. When we have viewporter
|
|
|
|
* support, this is a scaled up 1x1 image, and without we need an black image
|
|
|
|
* the size of the rendering areay. */
|
|
|
|
static void
|
|
|
|
gst_wl_window_update_borders (GstWlWindow * window)
|
|
|
|
{
|
|
|
|
GstVideoFormat format;
|
|
|
|
GstVideoInfo info;
|
|
|
|
gint width, height;
|
|
|
|
GstBuffer *buf;
|
|
|
|
struct wl_buffer *wlbuf;
|
|
|
|
GstWlBuffer *gwlbuf;
|
2017-11-01 09:05:26 +00:00
|
|
|
GstAllocator *alloc;
|
2016-09-22 19:35:44 +00:00
|
|
|
|
|
|
|
if (window->no_border_update)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (window->display->viewporter) {
|
|
|
|
width = height = 1;
|
|
|
|
window->no_border_update = TRUE;
|
|
|
|
} else {
|
|
|
|
width = window->render_rectangle.w;
|
|
|
|
height = window->render_rectangle.h;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we want WL_SHM_FORMAT_XRGB8888 */
|
|
|
|
format = GST_VIDEO_FORMAT_BGRx;
|
|
|
|
|
|
|
|
/* draw the area_subsurface */
|
|
|
|
gst_video_info_set_format (&info, format, width, height);
|
|
|
|
|
2017-11-01 09:05:26 +00:00
|
|
|
alloc = gst_wl_shm_allocator_get ();
|
|
|
|
|
|
|
|
buf = gst_buffer_new_allocate (alloc, info.size, NULL);
|
2016-09-22 19:35:44 +00:00
|
|
|
gst_buffer_memset (buf, 0, 0, info.size);
|
|
|
|
wlbuf =
|
|
|
|
gst_wl_shm_memory_construct_wl_buffer (gst_buffer_peek_memory (buf, 0),
|
|
|
|
window->display, &info);
|
|
|
|
gwlbuf = gst_buffer_add_wl_buffer (buf, wlbuf, window->display);
|
2018-12-03 07:18:32 +00:00
|
|
|
gst_wl_buffer_attach (gwlbuf, window->area_surface_wrapper);
|
2016-09-22 19:35:44 +00:00
|
|
|
|
|
|
|
/* at this point, the GstWlBuffer keeps the buffer
|
|
|
|
* alive and will free it on wl_buffer::release */
|
|
|
|
gst_buffer_unref (buf);
|
2017-11-01 09:05:26 +00:00
|
|
|
g_object_unref (alloc);
|
2016-09-22 19:35:44 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 11:13:56 +00:00
|
|
|
void
|
|
|
|
gst_wl_window_set_render_rectangle (GstWlWindow * window, gint x, gint y,
|
|
|
|
gint w, gint h)
|
|
|
|
{
|
|
|
|
g_return_if_fail (window != NULL);
|
|
|
|
|
|
|
|
window->render_rectangle.x = x;
|
|
|
|
window->render_rectangle.y = y;
|
|
|
|
window->render_rectangle.w = w;
|
|
|
|
window->render_rectangle.h = h;
|
|
|
|
|
2014-07-01 08:43:20 +00:00
|
|
|
/* position the area inside the parent - needs a parent commit to apply */
|
|
|
|
if (window->area_subsurface)
|
|
|
|
wl_subsurface_set_position (window->area_subsurface, x, y);
|
|
|
|
|
|
|
|
/* change the size of the area */
|
2016-09-15 18:10:02 +00:00
|
|
|
if (window->area_viewport)
|
|
|
|
wp_viewport_set_destination (window->area_viewport, w, h);
|
2014-07-01 08:43:20 +00:00
|
|
|
|
2016-09-22 19:35:44 +00:00
|
|
|
gst_wl_window_update_borders (window);
|
|
|
|
|
2014-07-01 08:43:20 +00:00
|
|
|
if (window->video_width != 0) {
|
|
|
|
wl_subsurface_set_sync (window->video_subsurface);
|
|
|
|
gst_wl_window_resize_video_surface (window, TRUE);
|
|
|
|
}
|
|
|
|
|
2018-12-03 07:18:32 +00:00
|
|
|
wl_surface_damage (window->area_surface_wrapper, 0, 0, w, h);
|
|
|
|
wl_surface_commit (window->area_surface_wrapper);
|
2014-07-01 08:43:20 +00:00
|
|
|
|
2014-05-26 11:13:56 +00:00
|
|
|
if (window->video_width != 0)
|
2014-07-01 08:43:20 +00:00
|
|
|
wl_subsurface_set_desync (window->video_subsurface);
|
2014-02-13 10:59:45 +00:00
|
|
|
}
|