Tizen 2.0 Release
[framework/multimedia/gstreamer-vaapi.git] / gst-libs / gst / vaapi / gstvaapidisplay_glx.c
1 /*
2  *  gstvaapidisplay_glx.c - VA/GLX display abstraction
3  *
4  *  Copyright (C) 2010-2011 Splitted-Desktop Systems
5  *  Copyright (C) 2011-2012 Intel Corporation
6  *
7  *  This library is free software; you can redistribute it and/or
8  *  modify it under the terms of the GNU Lesser General Public License
9  *  as published by the Free Software Foundation; either version 2.1
10  *  of the License, or (at your option) any later version.
11  *
12  *  This library is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  *  Lesser General Public License for more details.
16  *
17  *  You should have received a copy of the GNU Lesser General Public
18  *  License along with this library; if not, write to the Free
19  *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  *  Boston, MA 02110-1301 USA
21  */
22
23 /**
24  * SECTION:gstvaapidisplay_glx
25  * @short_description: VA/GLX display abstraction
26  */
27
28 #include "sysdeps.h"
29 #include "gstvaapicompat.h"
30 #include "gstvaapiutils.h"
31 #include "gstvaapiutils_glx.h"
32 #include "gstvaapidisplay_priv.h"
33 #include "gstvaapidisplay_x11_priv.h"
34 #include "gstvaapidisplay_glx.h"
35 #include "gstvaapidisplay_glx_priv.h"
36
37 #define DEBUG 1
38 #include "gstvaapidebug.h"
39
40 G_DEFINE_TYPE(GstVaapiDisplayGLX,
41               gst_vaapi_display_glx,
42               GST_VAAPI_TYPE_DISPLAY_X11);
43
44 static void
45 gst_vaapi_display_glx_finalize(GObject *object)
46 {
47     G_OBJECT_CLASS(gst_vaapi_display_glx_parent_class)->finalize(object);
48 }
49
50 static gboolean
51 gst_vaapi_display_glx_get_display_info(
52     GstVaapiDisplay     *display,
53     GstVaapiDisplayInfo *info
54 )
55 {
56     GstVaapiDisplayClass * const dpy_class =
57         GST_VAAPI_DISPLAY_CLASS(gst_vaapi_display_glx_parent_class);
58
59     info->va_display = vaGetDisplayGLX(GST_VAAPI_DISPLAY_XDISPLAY(display));
60     if (!info->va_display)
61         return FALSE;
62     info->display_type = GST_VAAPI_DISPLAY_TYPE_GLX;
63     return dpy_class->get_display(display, info);
64 }
65
66 static void
67 gst_vaapi_display_glx_class_init(GstVaapiDisplayGLXClass *klass)
68 {
69     GObjectClass * const object_class = G_OBJECT_CLASS(klass);
70     GstVaapiDisplayClass * const dpy_class = GST_VAAPI_DISPLAY_CLASS(klass);
71
72     object_class->finalize      = gst_vaapi_display_glx_finalize;
73     dpy_class->get_display      = gst_vaapi_display_glx_get_display_info;
74 }
75
76 static void
77 gst_vaapi_display_glx_init(GstVaapiDisplayGLX *display)
78 {
79 }
80
81 /**
82  * gst_vaapi_display_glx_new:
83  * @display_name: the X11 display name
84  *
85  * Opens an X11 #Display using @display_name and returns a newly
86  * allocated #GstVaapiDisplay object. The X11 display will be cloed
87  * when the reference count of the object reaches zero.
88  *
89  * Return value: a newly allocated #GstVaapiDisplay object
90  */
91 GstVaapiDisplay *
92 gst_vaapi_display_glx_new(const gchar *display_name)
93 {
94     return g_object_new(GST_VAAPI_TYPE_DISPLAY_GLX,
95                         "display-name", display_name,
96                         NULL);
97 }
98
99 /**
100  * gst_vaapi_display_glx_new_with_display:
101  * @x11_display: an X11 #Display
102  *
103  * Creates a #GstVaapiDisplay based on the X11 @x11_display
104  * display. The caller still owns the display and must call
105  * XCloseDisplay() when all #GstVaapiDisplay references are
106  * released. Doing so too early can yield undefined behaviour.
107  *
108  * Return value: a newly allocated #GstVaapiDisplay object
109  */
110 GstVaapiDisplay *
111 gst_vaapi_display_glx_new_with_display(Display *x11_display)
112 {
113     return g_object_new(GST_VAAPI_TYPE_DISPLAY_GLX,
114                         "x11-display", x11_display,
115                         NULL);
116 }