2 * gstvaapiwindow.c - VA window abstraction
4 * gstreamer-vaapi (C) 2010 Splitted-Desktop Systems
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 * SECTION:gst-vaapi-window
27 #include "gstvaapiwindow.h"
30 #include "gstvaapidebug.h"
32 G_DEFINE_TYPE(GstVaapiWindow, gst_vaapi_window, G_TYPE_OBJECT);
34 #define GST_VAAPI_WINDOW_GET_PRIVATE(obj) \
35 (G_TYPE_INSTANCE_GET_PRIVATE((obj), \
36 GST_VAAPI_TYPE_WINDOW, \
37 GstVaapiWindowPrivate))
39 struct _GstVaapiWindowPrivate {
42 gboolean is_constructed : 1;
43 guint is_fullscreen : 1;
54 gst_vaapi_window_destroy(GstVaapiWindow *window)
56 GST_VAAPI_WINDOW_GET_CLASS(window)->destroy(window);
60 gst_vaapi_window_create(GstVaapiWindow *window)
62 GstVaapiWindowPrivate * const priv = window->priv;
66 height = priv->height;
68 if (!GST_VAAPI_WINDOW_GET_CLASS(window)->create(window, &width, &height))
71 if (width != priv->width || height != priv->height) {
72 GST_DEBUG("backend resized window to %ux%u", width, height);
74 priv->height = height;
80 gst_vaapi_window_finalize(GObject *object)
82 gst_vaapi_window_destroy(GST_VAAPI_WINDOW(object));
84 G_OBJECT_CLASS(gst_vaapi_window_parent_class)->finalize(object);
88 gst_vaapi_window_set_property(
95 GstVaapiWindow * const window = GST_VAAPI_WINDOW(object);
99 gst_vaapi_window_set_width(window, g_value_get_uint(value));
102 gst_vaapi_window_set_height(window, g_value_get_uint(value));
105 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
111 gst_vaapi_window_get_property(
118 GstVaapiWindow * const window = GST_VAAPI_WINDOW(object);
122 g_value_set_uint(value, gst_vaapi_window_get_width(window));
125 g_value_set_uint(value, gst_vaapi_window_get_height(window));
128 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
134 gst_vaapi_window_constructed(GObject *object)
136 GstVaapiWindow * const window = GST_VAAPI_WINDOW(object);
137 GObjectClass *parent_class;
139 window->priv->is_constructed = gst_vaapi_window_create(window);
141 parent_class = G_OBJECT_CLASS(gst_vaapi_window_parent_class);
142 if (parent_class->constructed)
143 parent_class->constructed(object);
147 gst_vaapi_window_class_init(GstVaapiWindowClass *klass)
149 GObjectClass * const object_class = G_OBJECT_CLASS(klass);
151 g_type_class_add_private(klass, sizeof(GstVaapiWindowPrivate));
153 object_class->finalize = gst_vaapi_window_finalize;
154 object_class->set_property = gst_vaapi_window_set_property;
155 object_class->get_property = gst_vaapi_window_get_property;
156 object_class->constructed = gst_vaapi_window_constructed;
158 g_object_class_install_property
161 g_param_spec_uint("width",
167 g_object_class_install_property
170 g_param_spec_uint("height",
178 gst_vaapi_window_init(GstVaapiWindow *window)
180 GstVaapiWindowPrivate *priv = GST_VAAPI_WINDOW_GET_PRIVATE(window);
185 priv->is_constructed = FALSE;
186 priv->is_fullscreen = FALSE;
190 * gst_vaapi_window_show:
191 * @window: a #GstVaapiWindow
193 * Flags a window to be displayed. Any window that is not shown will
194 * not appear on the screen.
197 gst_vaapi_window_show(GstVaapiWindow *window)
199 g_return_if_fail(GST_VAAPI_IS_WINDOW(window));
200 g_return_if_fail(window->priv->is_constructed);
202 GST_VAAPI_WINDOW_GET_CLASS(window)->show(window);
206 * gst_vaapi_window_hide:
207 * @window: a #GstVaapiWindow
209 * Reverses the effects of gst_vaapi_window_show(), causing the window
210 * to be hidden (invisible to the user).
213 gst_vaapi_window_hide(GstVaapiWindow *window)
215 g_return_if_fail(GST_VAAPI_IS_WINDOW(window));
216 g_return_if_fail(window->priv->is_constructed);
218 GST_VAAPI_WINDOW_GET_CLASS(window)->hide(window);
222 * gst_vaapi_window_set_fullscreen:
223 * @window: a #GstVaapiWindow
224 * @fullscreen: %TRUE to request window to get fullscreen
226 * Requests to place the @window in fullscreen or unfullscreen states.
229 gst_vaapi_window_set_fullscreen(GstVaapiWindow *window, gboolean fullscreen)
231 GstVaapiWindowClass *klass;
233 g_return_if_fail(GST_VAAPI_IS_WINDOW(window));
235 klass = GST_VAAPI_WINDOW_GET_CLASS(window);
237 if (window->priv->is_fullscreen != fullscreen && klass->set_fullscreen) {
238 klass->set_fullscreen(window, fullscreen);
239 window->priv->is_fullscreen = fullscreen;
244 * gst_vaapi_window_get_width:
245 * @window: a #GstVaapiWindow
247 * Retrieves the width of a #GstVaapiWindow.
249 * Return value: the width of the @window, in pixels
252 gst_vaapi_window_get_width(GstVaapiWindow *window)
254 g_return_val_if_fail(GST_VAAPI_IS_WINDOW(window), 0);
255 g_return_val_if_fail(window->priv->is_constructed, 0);
257 return window->priv->width;
261 * gst_vaapi_window_get_height:
262 * @window: a #GstVaapiWindow
264 * Retrieves the height of a #GstVaapiWindow
266 * Return value: the height of the @window, in pixels
269 gst_vaapi_window_get_height(GstVaapiWindow *window)
271 g_return_val_if_fail(GST_VAAPI_IS_WINDOW(window), 0);
272 g_return_val_if_fail(window->priv->is_constructed, 0);
274 return window->priv->height;
278 * gst_vaapi_window_get_size:
279 * @window: a #GstVaapiWindow
280 * @pwidth: (out) (allow-none): return location for the width, or %NULL
281 * @pheight: (out) (allow-none): return location for the height, or %NULL
283 * Retrieves the dimensions of a #GstVaapiWindow.
286 gst_vaapi_window_get_size(GstVaapiWindow *window, guint *pwidth, guint *pheight)
288 g_return_if_fail(GST_VAAPI_IS_WINDOW(window));
289 g_return_if_fail(window->priv->is_constructed);
292 *pwidth = window->priv->width;
295 *pheight = window->priv->height;
299 * gst_vaapi_window_set_width:
300 * @window: a #GstVaapiWindow
301 * @width: requested new width for the window, in pixels
303 * Resizes the @window to match the specified @width.
306 gst_vaapi_window_set_width(GstVaapiWindow *window, guint width)
308 g_return_if_fail(GST_VAAPI_IS_WINDOW(window));
310 gst_vaapi_window_set_size(window, width, window->priv->height);
314 * gst_vaapi_window_set_height:
315 * @window: a #GstVaapiWindow
316 * @height: requested new height for the window, in pixels
318 * Resizes the @window to match the specified @height.
321 gst_vaapi_window_set_height(GstVaapiWindow *window, guint height)
323 g_return_if_fail(GST_VAAPI_IS_WINDOW(window));
325 gst_vaapi_window_set_size(window, window->priv->width, height);
329 * gst_vaapi_window_set_size:
330 * @window: a #GstVaapiWindow
331 * @width: requested new width for the window, in pixels
332 * @height: requested new height for the window, in pixels
334 * Resizes the @window to match the specified @width and @height.
337 gst_vaapi_window_set_size(GstVaapiWindow *window, guint width, guint height)
339 g_return_if_fail(GST_VAAPI_IS_WINDOW(window));
341 if (width == window->priv->width && height == window->priv->height)
344 window->priv->width = width;
345 window->priv->height = height;
347 if (window->priv->is_constructed)
348 GST_VAAPI_WINDOW_GET_CLASS(window)->resize(window, width, height);
352 get_surface_rect(GstVaapiSurface *surface, GstVideoRectangle *rect)
356 gst_vaapi_surface_get_size(surface, &width, &height);
364 get_window_rect(GstVaapiWindow *window, GstVideoRectangle *rect)
368 gst_vaapi_window_get_size(window, &width, &height);
376 * gst_vaapi_window_put_surface:
377 * @window: a #GstVaapiWindow
378 * @surface: a #GstVaapiSurface
379 * @src_rect: (allow-none): the sub-rectangle of the source surface to
380 * extract and process. If %NULL, the entire surface will be used.
381 * @dst_rect: (allow-none): the sub-rectangle of the destination
382 * window into which the surface is rendered. If %NULL, the entire
383 * window will be used.
384 * @flags: postprocessing flags. See #GstVaapiSurfaceRenderFlags
386 * Renders the @surface region specified by @src_rect into the @window
387 * region specified by @dst_rect. The @flags specify how de-interlacing
388 * (if needed), color space conversion, scaling and other postprocessing
389 * transformations are performed.
391 * Return value: %TRUE on success
394 gst_vaapi_window_put_surface(
395 GstVaapiWindow *window,
396 GstVaapiSurface *surface,
397 const GstVideoRectangle *src_rect,
398 const GstVideoRectangle *dst_rect,
402 GstVideoRectangle src_rect_default, dst_rect_default;
404 g_return_val_if_fail(GST_VAAPI_IS_WINDOW(window), FALSE);
405 g_return_val_if_fail(window->priv->is_constructed, FALSE);
406 g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), FALSE);
409 src_rect = &src_rect_default;
410 get_surface_rect(surface, &src_rect_default);
414 dst_rect = &dst_rect_default;
415 get_window_rect(window, &dst_rect_default);
418 return GST_VAAPI_WINDOW_GET_CLASS(window)->render(window,