wayland: add public API for creating & using the display handle GstContext
[platform/upstream/gstreamer.git] / gst-libs / gst / wayland / wayland.c
1 /*
2  * GStreamer Wayland Library
3  * Copyright (C) 2014 Collabora Ltd.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <gst/wayland/wayland.h>
26 #include <gst/video/videooverlay.h>
27
28 gboolean
29 gst_is_wayland_display_handle_need_context_message (GstMessage * msg)
30 {
31   const gchar *type = NULL;
32
33   g_return_val_if_fail (GST_IS_MESSAGE (msg), FALSE);
34
35   if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_NEED_CONTEXT &&
36       gst_message_parse_context_type (msg, &type)) {
37     return !g_strcmp0 (type, GST_WAYLAND_DISPLAY_HANDLE_CONTEXT_TYPE);
38   }
39
40   return FALSE;
41 }
42
43 GstContext *
44 gst_wayland_display_handle_context_new (struct wl_display * display)
45 {
46   GstContext *context =
47       gst_context_new (GST_WAYLAND_DISPLAY_HANDLE_CONTEXT_TYPE, TRUE);
48   gst_structure_set (gst_context_writable_structure (context),
49       "handle", G_TYPE_POINTER, display, NULL);
50   return context;
51 }
52
53 struct wl_display *
54 gst_wayland_display_handle_context_get_handle (GstContext * context)
55 {
56   const GstStructure *s;
57   struct wl_display *display;
58
59   g_return_val_if_fail (GST_IS_CONTEXT (context), NULL);
60
61   s = gst_context_get_structure (context);
62   gst_structure_get (s, "handle", G_TYPE_POINTER, &display, NULL);
63   return display;
64 }
65
66
67 G_DEFINE_INTERFACE (GstWaylandVideo, gst_wayland_video, GST_TYPE_VIDEO_OVERLAY);
68
69 static void
70 gst_wayland_video_default_init (GstWaylandVideoInterface * klass)
71 {
72   (void) klass;
73 }
74
75 /**
76  * gst_wayland_video_set_surface_size:
77  *
78  * This tells the video sink to change the size of its drawing
79  * surface. The caller must call gst_wayland_video_pause_rendering
80  * before calling this method and gst_wayland_video_resume_rendering
81  * later, on the next redraw request.
82  */
83 void
84 gst_wayland_video_set_surface_size (GstWaylandVideo * video, gint w, gint h)
85 {
86   GstWaylandVideoInterface *iface;
87
88   g_return_if_fail (video != NULL);
89   g_return_if_fail (GST_IS_WAYLAND_VIDEO (video));
90
91   iface = GST_WAYLAND_VIDEO_GET_INTERFACE (video);
92
93   if (iface->set_surface_size) {
94     iface->set_surface_size (video, w, h);
95   }
96 }
97
98 /**
99  * gst_wayland_video_pause_rendering:
100  *
101  * This tells the video sink to stop rendering on the surface,
102  * dropping frames in the meanwhile. This should be called
103  * before resizing a stack of subsurfaces, one of which is
104  * the surface of the video sink.
105  */
106 void
107 gst_wayland_video_pause_rendering (GstWaylandVideo * video)
108 {
109   GstWaylandVideoInterface *iface;
110
111   g_return_if_fail (video != NULL);
112   g_return_if_fail (GST_IS_WAYLAND_VIDEO (video));
113
114   iface = GST_WAYLAND_VIDEO_GET_INTERFACE (video);
115
116   if (iface->pause_rendering) {
117     iface->pause_rendering (video);
118   }
119 }
120
121 /**
122  * gst_wayland_video_resume_rendering:
123  *
124  * Resumes surface rendering that was previously paused
125  * with gst_wayland_video_pause_rendering. This function will
126  * block until there is a new wl_buffer commited on the surface
127  * inside the element, either with a new frame (if the element
128  * is PLAYING) or with an old frame (if the element is PAUSED).
129  */
130 void
131 gst_wayland_video_resume_rendering (GstWaylandVideo * video)
132 {
133   GstWaylandVideoInterface *iface;
134
135   g_return_if_fail (video != NULL);
136   g_return_if_fail (GST_IS_WAYLAND_VIDEO (video));
137
138   iface = GST_WAYLAND_VIDEO_GET_INTERFACE (video);
139
140   if (iface->resume_rendering) {
141     iface->resume_rendering (video);
142   }
143 }