Commit 633a4d8f authored by Andrew Voznytsa's avatar Andrew Voznytsa

Fix HDC for wglMakeCurrent() calls - enables multiple qmlglsink instances on Windows

parent 18e09de0
Pipeline #121695 failed with stages
in 66 minutes and 31 seconds
......@@ -174,7 +174,7 @@ gst_qt_get_gl_display ()
gboolean
gst_qt_get_gl_wrapcontext (GstGLDisplay * display,
GstGLContext **wrap_glcontext, GstGLContext **context)
GstGLContext **wrap_glcontext, GstGLContext **context, void * wgl_device)
{
GstGLPlatform platform = (GstGLPlatform) 0;
GstGLAPI gl_api;
......@@ -256,13 +256,11 @@ gst_qt_get_gl_wrapcontext (GstGLDisplay * display,
return FALSE;
} else {
gst_gl_display_filter_gl_api (display, gst_gl_context_get_gl_api (*wrap_glcontext));
#if GST_GL_HAVE_WINDOW_WIN32 && GST_GL_HAVE_PLATFORM_WGL && defined (HAVE_QT_WIN32)
#if GST_GL_HAVE_WINDOW_WIN32 && GST_GL_HAVE_PLATFORM_WGL && defined (HAVE_QT_WIN32)
g_return_val_if_fail (context != NULL, FALSE);
g_return_val_if_fail (wgl_device != NULL, FALSE);
G_STMT_START {
GstGLWindow *window;
HDC device;
/* If there's no wglCreateContextAttribsARB() support, then we would fallback to
* wglShareLists() which will fail with ERROR_BUSY (0xaa) if either of the GL
* contexts are current in any other thread.
......@@ -275,21 +273,19 @@ gst_qt_get_gl_wrapcontext (GstGLDisplay * display,
* unconditionally.
*/
*context = gst_gl_context_new (display);
window = gst_gl_context_get_window (*context);
device = (HDC) gst_gl_window_get_display (window);
wglMakeCurrent (device, 0);
gst_object_unref (window);
wglMakeCurrent ((HDC) wgl_device, 0);
if (!gst_gl_context_create (*context, *wrap_glcontext, &error)) {
GST_ERROR ("failed to create shared GL context: %s", error->message);
gst_object_unref (*context);
*context = NULL;
gst_object_unref (*wrap_glcontext);
*wrap_glcontext = NULL;
wglMakeCurrent (device, (HGLRC) gl_handle);
wglMakeCurrent ((HDC) wgl_device, (HGLRC) gl_handle);
return FALSE;
}
wglMakeCurrent (device, (HGLRC) gl_handle);
wglMakeCurrent ((HDC) wgl_device, (HGLRC) gl_handle);
} G_STMT_END;
#endif
gst_gl_context_activate (*wrap_glcontext, FALSE);
......
......@@ -30,7 +30,7 @@ G_BEGIN_DECLS
GstGLDisplay * gst_qt_get_gl_display ();
gboolean gst_qt_get_gl_wrapcontext (GstGLDisplay * display,
GstGLContext **wrap_glcontext, GstGLContext **context);
GstGLContext **wrap_glcontext, GstGLContext **context, void * wgl_device);
QVariant qt_opengl_native_context_from_gst_gl_context (GstGLContext * context);
......
......@@ -35,6 +35,10 @@
#include <QtQuick/QQuickWindow>
#include <QtQuick/QSGSimpleTextureNode>
#ifdef HAVE_QT_QPA_HEADER
#include <qpa/qplatformnativeinterface.h>
#endif
/**
* SECTION:gtkgstglwidget
* @short_description: a #GtkGLArea that renders GStreamer video #GstBuffers
......@@ -285,6 +289,13 @@ QtGLVideoItemInterface::setBuffer (GstBuffer * buffer)
void
QtGLVideoItem::onSceneGraphInitialized ()
{
void* wgl_device = nullptr;
#if GST_GL_HAVE_WINDOW_WIN32 && GST_GL_HAVE_PLATFORM_WGL && defined (HAVE_QT_WIN32) && defined (HAVE_QT_QPA_HEADER)
HWND hWnd = nullptr;
QWindow* window = this->window();
#endif
GST_DEBUG ("%p scene graph initialization with Qt GL context %p", this,
this->window()->openglContext ());
......@@ -297,8 +308,29 @@ QtGLVideoItem::onSceneGraphInitialized ()
return;
}
#if GST_GL_HAVE_WINDOW_WIN32 && GST_GL_HAVE_PLATFORM_WGL && defined (HAVE_QT_WIN32) && defined (HAVE_QT_QPA_HEADER)
if (window && window->handle()) {
QPlatformNativeInterface* pni = QGuiApplication::platformNativeInterface();
hWnd = static_cast<HWND>(pni->nativeResourceForWindow(QByteArrayLiteral("handle"), window));
if (hWnd != nullptr) {
wgl_device = GetWindowDC(hWnd);
}
}
#endif
m_openGlContextInitialized = gst_qt_get_gl_wrapcontext (this->priv->display,
&this->priv->other_context, &this->priv->context);
&this->priv->other_context, &this->priv->context, wgl_device);
#if GST_GL_HAVE_WINDOW_WIN32 && GST_GL_HAVE_PLATFORM_WGL && defined (HAVE_QT_WIN32) && defined (HAVE_QT_QPA_HEADER)
if (wgl_device != nullptr) {
ReleaseDC(hWnd, static_cast<HDC>(wgl_device));
wgl_device = nullptr;
}
hWnd = nullptr;
window = nullptr;
#endif
GST_DEBUG ("%p created wrapped GL context %" GST_PTR_FORMAT, this,
this->priv->other_context);
......
......@@ -2,7 +2,7 @@ TEMPLATE = lib
TARGET = gstqmlgl
QT += qml quick gui
QT += qml quick gui-private
QT_CONFIG -= no-pkg-config
CONFIG += link_pkgconfig debug
......@@ -18,10 +18,10 @@ android {
}
android:DEFINES += HAVE_QT_ANDROID
win32:DEFINES += HAVE_QT_WIN32
win32:DEFINES += HAVE_QT_WIN32 HAVE_QT_QPA_HEADER
macx:DEFINES += HAVE_QT_MAC
versionAtLeast(QT_VERSION, "5.5"):win32-msvc: LIBS += opengl32.lib
versionAtLeast(QT_VERSION, "5.5"):win32-msvc: LIBS += opengl32.lib user32.lib
SOURCES += \
gstplugin.cc \
......
......@@ -36,6 +36,10 @@
#include <QtQuick/QQuickWindow>
#include <QOpenGLFramebufferObject>
#ifdef HAVE_QT_QPA_HEADER
#include <qpa/qplatformnativeinterface.h>
#endif
/* compatibility definitions... */
#ifndef GL_READ_FRAMEBUFFER
#define GL_READ_FRAMEBUFFER 0x8CA8
......@@ -289,11 +293,35 @@ QtGLWindow::aboutToQuit()
void
QtGLWindow::onSceneGraphInitialized()
{
void* wgl_device = nullptr;
#if GST_GL_HAVE_WINDOW_WIN32 && GST_GL_HAVE_PLATFORM_WGL && defined (HAVE_QT_WIN32) && defined (HAVE_QT_QPA_HEADER)
HWND hWnd = nullptr;
#endif
GST_DEBUG ("scene graph initialization with Qt GL context %p",
this->source->openglContext ());
#if GST_GL_HAVE_WINDOW_WIN32 && GST_GL_HAVE_PLATFORM_WGL && defined (HAVE_QT_WIN32) && defined (HAVE_QT_QPA_HEADER)
if (handle()) {
QPlatformNativeInterface* pni = QGuiApplication::platformNativeInterface();
hWnd = static_cast<HWND>(pni->nativeResourceForWindow(QByteArrayLiteral("handle"), this));
if (hWnd != nullptr) {
wgl_device = GetWindowDC(hWnd);
}
}
#endif
this->priv->initted = gst_qt_get_gl_wrapcontext (this->priv->display,
&this->priv->other_context, NULL);
&this->priv->other_context, NULL, wgl_device);
#if GST_GL_HAVE_WINDOW_WIN32 && GST_GL_HAVE_PLATFORM_WGL && defined (HAVE_QT_WIN32) && defined (HAVE_QT_QPA_HEADER)
if (wgl_device != nullptr) {
ReleaseDC(hWnd, static_cast<HDC>(wgl_device));
wgl_device = nullptr;
}
#endif
if (this->priv->initted && this->priv->other_context) {
const GstGLFuncs *gl;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment