65 GstGLDisplay *display = NULL;
66 QGuiApplication *app =
static_cast<QGuiApplication *
> (QCoreApplication::instance ());
69 g_assert (app != NULL);
71 if (g_once_init_enter (&_debug)) {
73 "Qt gl utility functions");
74 g_once_init_leave (&_debug, 1);
77 G_LOCK (display_lock);
79 display =
static_cast<GstGLDisplay *
>(g_weak_ref_get (&
qt_display));
82 GST_INFO (
"returning previously created display");
83 G_UNLOCK (display_lock);
86 gst_clear_object (&display);
91 GST_INFO (
"QGuiApplication::instance()->platformName() %s", app->platformName().toUtf8().data());
92#if GST_GL_HAVE_WINDOW_X11 && defined (HAVE_QT_X11)
93 if (QString::fromUtf8 (
"xcb") == app->platformName()) {
94 auto x11_native = app->nativeInterface<QNativeInterface::QX11Application>();
96 display = (GstGLDisplay *)
97 gst_gl_display_x11_new_with_display (x11_native->display());
101#if GST_GL_HAVE_WINDOW_WAYLAND && GST_GL_HAVE_PLATFORM_EGL && defined (HAVE_QT_WAYLAND)
102 if (QString::fromUtf8 (
"wayland") == app->platformName()
103 || QString::fromUtf8 (
"wayland-egl") == app->platformName()){
104 struct wl_display * wayland_display;
105 QPlatformNativeInterface *native =
106 QGuiApplication::platformNativeInterface();
107 wayland_display = (
struct wl_display *)
108 native->nativeResourceForWindow(
"display", NULL);
109 display = (GstGLDisplay *)
110 gst_gl_display_wayland_new_with_display (wayland_display);
113#if GST_GL_HAVE_PLATFORM_EGL && GST_GL_HAVE_WINDOW_ANDROID
114 if (QString::fromUtf8 (
"android") == app->platformName()) {
115 EGLDisplay egl_display = (EGLDisplay) gst_gl_display_egl_get_from_native (GST_GL_DISPLAY_TYPE_ANY, 0);
116 display = (GstGLDisplay *) gst_gl_display_egl_new_with_egl_display (egl_display);
118#elif GST_GL_HAVE_PLATFORM_EGL && defined (HAVE_QT_EGLFS)
119 if (QString::fromUtf8(
"eglfs") == app->platformName()) {
120#if GST_GL_HAVE_WINDOW_VIV_FB
135 fb_dev = g_getenv (
"QT_QPA_EGLFS_FB");
137 if (sscanf (fb_dev,
"/dev/fb%d", &disp_idx) != 1)
141 display = (GstGLDisplay *) gst_gl_display_viv_fb_new (disp_idx);
142#elif defined(HAVE_QT_QPA_HEADER)
143 QPlatformNativeInterface *native =
144 QGuiApplication::platformNativeInterface();
145 EGLDisplay egl_display = (EGLDisplay)
146 native->nativeResourceForWindow(
"egldisplay", NULL);
147 if (egl_display != EGL_NO_DISPLAY)
148 display = (GstGLDisplay *) gst_gl_display_egl_new_with_egl_display (egl_display);
150 EGLDisplay egl_display = (EGLDisplay) gst_gl_display_egl_get_from_native (GST_GL_DISPLAY_TYPE_ANY, 0);
151 display = (GstGLDisplay *) gst_gl_display_egl_new_with_egl_display (egl_display);
155#if GST_GL_HAVE_WINDOW_COCOA && GST_GL_HAVE_PLATFORM_CGL && defined (HAVE_QT_MAC)
156 if (QString::fromUtf8 (
"cocoa") == app->platformName())
157 display = (GstGLDisplay *) gst_gl_display_new ();
159#if GST_GL_HAVE_WINDOW_EAGL && GST_GL_HAVE_PLATFORM_EAGL && defined (HAVE_QT_IOS)
160 if (QString::fromUtf8 (
"ios") == app->platformName())
161 display = gst_gl_display_new ();
163#if GST_GL_HAVE_WINDOW_WIN32 && GST_GL_HAVE_PLATFORM_WGL && defined (HAVE_QT_WIN32)
164 if (QString::fromUtf8 (
"windows") == app->platformName())
165 display = gst_gl_display_new ();
169 display = gst_gl_display_new ();
172 G_UNLOCK (display_lock);
179 GstGLContext **wrap_glcontext, GstGLContext **context)
181 GstGLPlatform G_GNUC_UNUSED platform = (GstGLPlatform) 0;
182 GstGLAPI G_GNUC_UNUSED gl_api;
183 guintptr G_GNUC_UNUSED gl_handle;
184 GstGLContext *current;
185 GError *
error = NULL;
187 g_return_val_if_fail (display != NULL && wrap_glcontext != NULL, FALSE);
188#if GST_GL_HAVE_WINDOW_X11 && defined (HAVE_QT_X11)
189 if (GST_IS_GL_DISPLAY_X11 (display)) {
190#if GST_GL_HAVE_PLATFORM_GLX
191 platform = GST_GL_PLATFORM_GLX;
192#elif GST_GL_HAVE_PLATFORM_EGL
193 platform = GST_GL_PLATFORM_EGL;
197#if GST_GL_HAVE_WINDOW_WAYLAND && defined (HAVE_QT_WAYLAND)
198 if (GST_IS_GL_DISPLAY_WAYLAND (display)) {
199 platform = GST_GL_PLATFORM_EGL;
202#if GST_GL_HAVE_PLATFORM_EGL && defined (HAVE_QT_EGLFS)
203#if GST_GL_HAVE_WINDOW_VIV_FB
204 if (GST_IS_GL_DISPLAY_VIV_FB (display)) {
206 if (GST_IS_GL_DISPLAY_EGL (display)) {
208 platform = GST_GL_PLATFORM_EGL;
212#if GST_GL_HAVE_WINDOW_COCOA && GST_GL_HAVE_PLATFORM_CGL && defined (HAVE_QT_MAC)
213 platform = GST_GL_PLATFORM_CGL;
214#elif GST_GL_HAVE_WINDOW_EAGL && GST_GL_HAVE_PLATFORM_EAGL && defined (HAVE_QT_IOS)
215 platform = GST_GL_PLATFORM_EAGL;
216#elif GST_GL_HAVE_WINDOW_WIN32 && GST_GL_HAVE_PLATFORM_WGL && defined (HAVE_QT_WIN32)
217 platform = GST_GL_PLATFORM_WGL;
218#elif GST_GL_HAVE_WINDOW_ANDROID && GST_GL_HAVE_PLATFORM_EGL && defined (HAVE_QT_ANDROID)
219 platform = GST_GL_PLATFORM_EGL;
221 GST_ERROR (
"Unknown platform");
226 gl_api = gst_gl_context_get_current_gl_api (platform, NULL, NULL);
227 gl_handle = gst_gl_context_get_current_gl_context (platform);
230 current = gst_gl_context_get_current ();
231 if (current && current->display == display) {
233 *wrap_glcontext =
static_cast<GstGLContext *
> (gst_object_ref (current));
238 gst_gl_context_new_wrapped (display, gl_handle,
241 if (!*wrap_glcontext) {
242 GST_ERROR (
"cannot wrap qt OpenGL context");
246 gst_gl_context_activate(*wrap_glcontext, TRUE);
247 if (!gst_gl_context_fill_info (*wrap_glcontext, &
error)) {
248 GST_ERROR (
"failed to retrieve qt context info: %s",
error->message);
249 gst_gl_context_activate(*wrap_glcontext, FALSE);
250 gst_clear_object (wrap_glcontext);
254 gst_gl_display_filter_gl_api (display, gst_gl_context_get_gl_api (*wrap_glcontext));
255 gst_gl_context_activate (*wrap_glcontext, FALSE);
258#if GST_GL_HAVE_WINDOW_WIN32 && GST_GL_HAVE_PLATFORM_WGL && defined (HAVE_QT_WIN32)
259 g_return_val_if_fail (context != NULL, FALSE);
275 HDC device = wglGetCurrentDC ();
277 *context = gst_gl_context_new (display);
279 wglMakeCurrent (NULL, NULL);
280 if (!gst_gl_context_create (*context, *wrap_glcontext, &
error)) {
281 GST_ERROR (
"failed to create shared GL context: %s",
error->message);
282 gst_clear_object (wrap_glcontext);
283 gst_clear_object (context);
285 wglMakeCurrent (device, (HGLRC) gl_handle);