3 * Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
4 * Copyright (C) 2012 Matthew Waters <ystreet00@gmail.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library 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 GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
22 #define GLIB_DISABLE_DEPRECATION_WARNINGS
30 #include "gstglwindow_x11_glx.h"
32 #define GST_CAT_DEFAULT gst_gl_window_debug
34 #define gst_gl_window_x11_glx_parent_class parent_class
35 G_DEFINE_TYPE (GstGLWindowX11GLX, gst_gl_window_x11_glx,
36 GST_GL_TYPE_WINDOW_X11);
38 static guintptr gst_gl_window_x11_glx_get_gl_context (GstGLWindowX11 *
40 static void gst_gl_window_x11_glx_swap_buffers (GstGLWindowX11 * window_x11);
41 static gboolean gst_gl_window_x11_glx_activate (GstGLWindowX11 * window_x11,
43 static gboolean gst_gl_window_x11_glx_create_context (GstGLWindowX11 *
44 window_x11, GstGLAPI gl_api, guintptr external_gl_context, GError ** error);
45 static void gst_gl_window_x11_glx_destroy_context (GstGLWindowX11 * window_x11);
46 static gboolean gst_gl_window_x11_glx_choose_format (GstGLWindowX11 *
47 window_x11, GError ** error);
48 GstGLAPI gst_gl_window_x11_glx_get_gl_api (GstGLWindow * window);
51 gst_gl_window_x11_glx_class_init (GstGLWindowX11GLXClass * klass)
53 GstGLWindowClass *window_class = (GstGLWindowClass *) klass;
54 GstGLWindowX11Class *window_x11_class = (GstGLWindowX11Class *) klass;
56 window_x11_class->get_gl_context =
57 GST_DEBUG_FUNCPTR (gst_gl_window_x11_glx_get_gl_context);
58 window_x11_class->activate =
59 GST_DEBUG_FUNCPTR (gst_gl_window_x11_glx_activate);
60 window_x11_class->create_context =
61 GST_DEBUG_FUNCPTR (gst_gl_window_x11_glx_create_context);
62 window_x11_class->destroy_context =
63 GST_DEBUG_FUNCPTR (gst_gl_window_x11_glx_destroy_context);
64 window_x11_class->choose_format =
65 GST_DEBUG_FUNCPTR (gst_gl_window_x11_glx_choose_format);
66 window_x11_class->swap_buffers =
67 GST_DEBUG_FUNCPTR (gst_gl_window_x11_glx_swap_buffers);
69 window_class->get_gl_api =
70 GST_DEBUG_FUNCPTR (gst_gl_window_x11_glx_get_gl_api);
74 gst_gl_window_x11_glx_init (GstGLWindowX11GLX * window)
78 /* Must be called in the gl thread */
80 gst_gl_window_x11_glx_new (GstGLAPI gl_api, guintptr external_gl_context,
83 GstGLWindowX11GLX *window = g_object_new (GST_GL_TYPE_WINDOW_X11_GLX, NULL);
85 gst_gl_window_x11_open_device (GST_GL_WINDOW_X11 (window), gl_api,
86 external_gl_context, error);
92 gst_gl_window_x11_glx_create_context (GstGLWindowX11 * window_x11,
93 GstGLAPI gl_api, guintptr external_gl_context, GError ** error)
95 GstGLWindowX11GLX *window_glx;
97 window_glx = GST_GL_WINDOW_X11_GLX (window_x11);
99 window_glx->glx_context =
100 glXCreateContext (window_x11->device, window_x11->visual_info,
101 (GLXContext) external_gl_context, TRUE);
103 if (!window_glx->glx_context) {
104 g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_CREATE_CONTEXT,
105 "Failed to create opengl context (glXCreateContext failed)");
109 GST_LOG ("gl context id: %ld", (gulong) window_glx->glx_context);
118 gst_gl_window_x11_glx_destroy_context (GstGLWindowX11 * window_x11)
120 GstGLWindowX11GLX *window_glx;
122 window_glx = GST_GL_WINDOW_X11_GLX (window_x11);
124 glXDestroyContext (window_x11->device, window_glx->glx_context);
126 window_glx->glx_context = 0;
130 gst_gl_window_x11_glx_choose_format (GstGLWindowX11 * window_x11,
138 GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1,
144 if (!glXQueryExtension (window_x11->device, &error_base, &event_base)) {
145 g_set_error (error, GST_GL_WINDOW_ERROR,
146 GST_GL_WINDOW_ERROR_RESOURCE_UNAVAILABLE, "No GLX extension");
150 window_x11->visual_info = glXChooseVisual (window_x11->device,
151 window_x11->screen_num, attrib);
153 if (!window_x11->visual_info) {
154 g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_WRONG_CONFIG,
155 "Bad attributes in glXChooseVisual");
166 gst_gl_window_x11_glx_swap_buffers (GstGLWindowX11 * window_x11)
168 glXSwapBuffers (window_x11->device, window_x11->internal_win_id);
172 gst_gl_window_x11_glx_get_gl_context (GstGLWindowX11 * window_x11)
174 return (guintptr) GST_GL_WINDOW_X11_GLX (window_x11)->glx_context;
178 gst_gl_window_x11_glx_activate (GstGLWindowX11 * window_x11, gboolean activate)
183 result = glXMakeCurrent (window_x11->device, window_x11->internal_win_id,
184 GST_GL_WINDOW_X11_GLX (window_x11)->glx_context);
186 result = glXMakeCurrent (window_x11->device, None, NULL);
193 gst_gl_window_x11_glx_get_gl_api (GstGLWindow * window)
195 return GST_GL_API_OPENGL;