Use a singleton for the plugin.
authorGunnar Sletta <gunnar.sletta@nokia.com>
Wed, 8 Feb 2012 07:06:17 +0000 (08:06 +0100)
committerQt by Nokia <qt-info@nokia.com>
Wed, 8 Feb 2012 15:06:52 +0000 (16:06 +0100)
The factory is created from the QQuickCanvas constructor
before any alternative threads are started and doesn't need
this kind of protected. In addition this caused problems on
shutdown if multiple custom contexts where created.

Change-Id: Ifdd9bde0c65aa7c399722aea33af78087a2465b4
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
src/quick/scenegraph/qsgcontextplugin.cpp

index 2a2268d..026afb2 100644 (file)
@@ -79,14 +79,14 @@ struct QSGAdaptionPluginData
     QString deviceName;
 };
 
-QThreadStorage<QSGAdaptionPluginData> qsg_plugin_data;
-
+Q_GLOBAL_STATIC(QSGAdaptionPluginData, qsg_adaptation_data)
 
 QSGAdaptionPluginData *contextFactory()
 {
-    QSGAdaptionPluginData &plugin = qsg_plugin_data.localData();
-    if (!plugin.tried) {
-        plugin.tried = true;
+    QSGAdaptionPluginData *plugin = qsg_adaptation_data();
+    if (!plugin->tried) {
+
+        plugin->tried = true;
         const QStringList args = QGuiApplication::arguments();
         QString device;
         for (int index = 0; index < args.count(); ++index) {
@@ -100,8 +100,8 @@ QSGAdaptionPluginData *contextFactory()
 
 #if !defined (QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
         if (!device.isEmpty()) {
-            plugin.factory = qobject_cast<QSGContextFactoryInterface*>(loader()->instance(device));
-            plugin.deviceName = device;
+            plugin->factory = qobject_cast<QSGContextFactoryInterface*>(loader()->instance(device));
+            plugin->deviceName = device;
         }
 #ifndef QT_NO_DEBUG
         if (!device.isEmpty()) {
@@ -114,7 +114,7 @@ QSGAdaptionPluginData *contextFactory()
 
 #endif // QT_NO_LIBRARY || QT_NO_SETTINGS
     }
-    return &plugin;
+    return plugin;
 }