]> git.sesse.net Git - mlt/commitdiff
Fix qglsl consumer for Qt 5.
authorDan Dennedy <dan@dennedy.org>
Sat, 24 Aug 2013 18:27:44 +0000 (11:27 -0700)
committerDan Dennedy <dan@dennedy.org>
Sat, 24 Aug 2013 18:27:44 +0000 (11:27 -0700)
src/modules/qimage/Makefile
src/modules/qimage/consumer_qglsl.cpp

index 7b9e71bfb826a513006288f4873976fc6b9a4276..ffe5bbf31d395f31efc27afbc2c853caf159d63d 100644 (file)
@@ -17,6 +17,12 @@ ifdef GPL3
        CFLAGS += -DGPL3
 endif
 
+ifneq ($(targetos), Darwin)
+ifneq ($(targetos), MinGW)
+    LDFLAGS += -lX11
+endif
+endif
+
 CXXFLAGS += $(CFLAGS) $(QTCXXFLAGS) $(EXIFCXXFLAGS) $(KDECXXFLAGS) -Wno-deprecated
 
 LDFLAGS += $(QTLIBS) $(EXIFLIBS) $(KDELIBS)
index 660bb3b51a07f350261f4c10947233ef972dac9b..ed6e46a40b74bc05f8faf6af64d341fe66751f76 100644 (file)
 #include <QApplication>
 #include <QLocale>
 #include <QGLWidget>
+#include <QMutex>
+#include <QWaitCondition>
+
+#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
+#include <X11/Xlib.h>
+#endif
+
+class GLWidget : public QGLWidget
+{
+private:
+       QGLWidget *renderContext;
+       bool isInitialized;
+       QMutex mutex;
+       QWaitCondition condition;
+
+public:
+       GLWidget()
+               : QGLWidget(0, 0, Qt::SplashScreen)
+               , renderContext(0)
+               , isInitialized(false)
+       {
+               resize(0, 0);
+               show();
+       }
+
+       ~GLWidget()
+       {
+               delete renderContext;
+       }
+
+       bool createRenderContext()
+       {
+               if (!isInitialized) {
+                       mutex.lock();
+                       condition.wait(&mutex);
+                       mutex.unlock();
+               }
+               if (!renderContext) {
+                       renderContext = new QGLWidget(0, this, Qt::SplashScreen);
+                       renderContext->resize(0, 0);
+                       renderContext->makeCurrent();
+               }
+               return renderContext->isValid();
+       }
+
+protected:
+       void initializeGL()
+       {
+               condition.wakeAll();
+               isInitialized = true;
+       }
+};
 
 static void onThreadStarted(mlt_properties owner, mlt_consumer consumer)
 {
@@ -28,45 +80,25 @@ static void onThreadStarted(mlt_properties owner, mlt_consumer consumer)
        mlt_properties properties = MLT_CONSUMER_PROPERTIES(consumer);
        mlt_filter filter = (mlt_filter) mlt_properties_get_data(properties, "glslManager", NULL);
        mlt_properties filter_properties = MLT_FILTER_PROPERTIES(filter);
-       QApplication* app = qApp;
 
        mlt_log_debug(service, "%s\n", __FUNCTION__);
-#ifdef linux
-       if ( getenv("DISPLAY") == 0 ) {
-               mlt_log_error(service, "The qglsl consumer requires a X11 environment.\nPlease either run melt from an X session or use a fake X server like xvfb:\nxvfb-run -a melt (...)\n" );
-       } else
-#endif
-       if (!app) {
-               int argc = 1;
-               char* argv[1];
-               argv[0] = (char*) "MLT qglsl consumer";
-               app = new QApplication(argc, argv);
-               const char *localename = mlt_properties_get_lcnumeric(properties);
-               QLocale::setDefault(QLocale(localename));
-       }
-       QGLWidget* renderContext = new QGLWidget;
-       renderContext->resize(0, 0);
-       renderContext->show();
-       mlt_events_fire(filter_properties, "init glsl", NULL);
-       if (!mlt_properties_get_int(filter_properties, "glsl_supported")) {
-               mlt_log_fatal(service,
-                       "OpenGL Shading Language rendering is not supported on this machine.\n" );
-               mlt_events_fire(properties, "consumer-fatal-error", NULL);
-       }
-       else {
-               mlt_properties_set_data(properties, "qglslRenderContext", renderContext, 0, NULL, NULL);
+       GLWidget *widget = (GLWidget*) mlt_properties_get_data(properties, "GLWidget", NULL);
+       if (widget->createRenderContext()) {
+               mlt_events_fire(filter_properties, "init glsl", NULL);
+               if (!mlt_properties_get_int(filter_properties, "glsl_supported")) {
+                       mlt_log_fatal(service,
+                               "OpenGL Shading Language rendering is not supported on this machine.\n" );
+                       mlt_events_fire(properties, "consumer-fatal-error", NULL);
+               }
        }
 }
 
 static void onCleanup(mlt_properties owner, mlt_consumer consumer)
 {
-       QGLWidget* renderContext = (QGLWidget*) mlt_properties_get_data(
-               MLT_CONSUMER_PROPERTIES(consumer), "qglslRenderContext", NULL);
-       if (renderContext)
-               renderContext->makeCurrent();
-       delete renderContext;
-       mlt_properties_set_data(MLT_CONSUMER_PROPERTIES(consumer),
-               "qglslRenderContext", NULL, 0, NULL, NULL);
+       GLWidget* widget = (GLWidget*) mlt_properties_get_data( MLT_CONSUMER_PROPERTIES(consumer), "GLWidget", NULL);
+       delete widget;
+       mlt_properties_set_data(MLT_CONSUMER_PROPERTIES(consumer), "GLWidget", NULL, 0, NULL, NULL);
+       qApp->processEvents();
 }
 
 extern "C" {
@@ -77,11 +109,29 @@ mlt_consumer consumer_qglsl_init( mlt_profile profile, mlt_service_type type, co
        if (consumer) {
                mlt_filter filter = mlt_factory_filter(profile, "glsl.manager", 0);
                if (filter) {
+#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
+                       XInitThreads();
+#endif
                        mlt_properties properties = MLT_CONSUMER_PROPERTIES(consumer);
                        mlt_properties_set_data(properties, "glslManager", filter, 0, (mlt_destructor) mlt_filter_close, NULL);
                        mlt_events_register( properties, "consumer-cleanup", NULL );
                        mlt_events_listen(properties, consumer, "consumer-thread-started", (mlt_listener) onThreadStarted);
                        mlt_events_listen(properties, consumer, "consumer-cleanup", (mlt_listener) onCleanup);
+#ifdef linux
+                       if ( getenv("DISPLAY") == 0 ) {
+                               mlt_log_error(MLT_CONSUMER_SERVICE(consumer), "The qglsl consumer requires a X11 environment.\nPlease either run melt from an X session or use a fake X server like xvfb:\nxvfb-run -a melt (...)\n" );
+                       } else
+#endif
+                       if (!qApp) {
+                               int argc = 1;
+                               char* argv[1];
+                               argv[0] = (char*) "MLT qglsl consumer";
+                               new QApplication(argc, argv);
+                               const char *localename = mlt_properties_get_lcnumeric(properties);
+                               QLocale::setDefault(QLocale(localename));
+                       }
+                       mlt_properties_set_data(properties, "GLWidget", new GLWidget, 0, NULL, NULL);
+                       qApp->processEvents();
                        return consumer;
                }
                mlt_consumer_close(consumer);