1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qsgcontextplugin_p.h"
43 #include <QtQuick/private/qsgcontext_p.h>
44 #include <QtGui/qguiapplication.h>
45 #include <QtCore/private/qfactoryloader_p.h>
46 #include <QtCore/qlibraryinfo.h>
50 QSGContextPlugin::QSGContextPlugin(QObject *parent)
55 QSGContextPlugin::~QSGContextPlugin()
60 Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
61 (QSGContextFactoryInterface_iid, QLatin1String("/scenegraph")))
64 struct QSGAdaptionPluginData
66 QSGAdaptionPluginData()
72 ~QSGAdaptionPluginData()
77 QSGContextFactoryInterface *factory;
81 Q_GLOBAL_STATIC(QSGAdaptionPluginData, qsg_adaptation_data)
83 QSGAdaptionPluginData *contextFactory()
85 QSGAdaptionPluginData *plugin = qsg_adaptation_data();
89 const QStringList args = QGuiApplication::arguments();
91 for (int index = 0; index < args.count(); ++index) {
92 if (args.at(index).startsWith(QLatin1String("--device="))) {
93 device = args.at(index).mid(9);
98 device = QString::fromLocal8Bit(qgetenv("QMLSCENE_DEVICE"));
100 #ifndef QT_NO_LIBRARY
101 if (!device.isEmpty()) {
102 const int index = loader()->indexOf(device);
104 plugin->factory = qobject_cast<QSGContextFactoryInterface*>(loader()->instance(index));
105 plugin->deviceName = device;
107 if (!plugin->factory) {
108 qWarning("Could not create scene graph context for device '%s'"
109 " - check that plugins are installed correctly in %s",
111 qPrintable(QLibraryInfo::location(QLibraryInfo::PluginsPath)));
116 #endif // QT_NO_LIBRARY
124 \fn QSGContext *QSGContext::createDefaultContext()
126 Creates a default scene graph context for the current hardware.
127 This may load a device-specific plugin.
129 QSGContext *QSGContext::createDefaultContext()
131 QSGAdaptionPluginData *plugin = contextFactory();
133 return plugin->factory->create(plugin->deviceName);
134 return new QSGContext();
140 \fn QQuickTextureFactory *createTextureFactoryFromImage(const QImage &image)
142 Calls into the scene graph adaptation if available and creates a texture
143 factory. The primary purpose of this function is to reimplement hardware
144 specific asynchronous texture frameskip-less uploads that can happen on
145 the image providers thread.
148 QQuickTextureFactory *QSGContext::createTextureFactoryFromImage(const QImage &image)
150 QSGAdaptionPluginData *plugin = contextFactory();
152 return plugin->factory->createTextureFactoryFromImage(image);
158 \fn QQuickWindowManager *createWindowManager()
160 Calls into the scene graph adaptation if available and creates a hardware
161 specific window manager.
164 QQuickWindowManager *QSGContext::createWindowManager()
166 QSGAdaptionPluginData *plugin = contextFactory();
168 return plugin->factory->createWindowManager();