From: Dan Dennedy Date: Sat, 24 Aug 2013 18:27:44 +0000 (-0700) Subject: Fix qglsl consumer for Qt 5. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=dbcde347a44ee1972ca66a606b2283fabbbe0fe7;p=mlt Fix qglsl consumer for Qt 5. --- diff --git a/src/modules/qimage/Makefile b/src/modules/qimage/Makefile index 7b9e71bf..ffe5bbf3 100644 --- a/src/modules/qimage/Makefile +++ b/src/modules/qimage/Makefile @@ -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) diff --git a/src/modules/qimage/consumer_qglsl.cpp b/src/modules/qimage/consumer_qglsl.cpp index 660bb3b5..ed6e46a4 100644 --- a/src/modules/qimage/consumer_qglsl.cpp +++ b/src/modules/qimage/consumer_qglsl.cpp @@ -21,6 +21,58 @@ #include #include #include +#include +#include + +#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) +#include +#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);