1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qscreendriverfactory_qws.h"
43 
44 #include "qscreen_qws.h"
45 #include "qapplication.h"
46 #include "qscreenlinuxfb_qws.h"
47 #include "qscreentransformed_qws.h"
48 #include "qscreenvfb_qws.h"
49 #include "qscreenmulti_qws_p.h"
50 #include "qscreenqnx_qws.h"
51 #include "qscreenintegrityfb_qws.h"
52 #include <stdlib.h>
53 #include "private/qfactoryloader_p.h"
54 #include "qscreendriverplugin_qws.h"
55 #ifndef QT_NO_QWS_DIRECTFB
56 #include "qdirectfbscreen.h"
57 #endif
58 #ifndef QT_NO_QWS_VNC
59 #include "qscreenvnc_qws.h"
60 #endif
61 
62 QT_BEGIN_NAMESPACE
63 
64 #if !defined(Q_OS_WIN32) || defined(QT_MAKEDLL)
65 #ifndef QT_NO_LIBRARY
66 
67 Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
68     (QScreenDriverFactoryInterface_iid,
69      QLatin1String("/gfxdrivers"), Qt::CaseInsensitive))
70 
71 #endif //QT_NO_LIBRARY
72 #endif //QT_MAKEDLL
73 
74 /*!
75     \class QScreenDriverFactory
76     \ingroup qws
77 
78     \brief The QScreenDriverFactory class creates screen drivers in
79     Qt for Embedded Linux.
80 
81     Note that this class is only available in \l{Qt for Embedded Linux}.
82 
83     QScreenDriverFactory is used to detect and instantiate the
84     available screen drivers, allowing \l{Qt for Embedded Linux} to load the
85     preferred driver into the server application at runtime.  The
86     create() function returns a QScreen object representing the screen
87     driver identified by a given key. The valid keys (i.e. the
88     supported drivers) can be retrieved using the keys() function.
89 
90 
91     \l{Qt for Embedded Linux} provides several built-in screen drivers. In
92     addition, custom screen drivers can be added using Qt's plugin
93     mechanism, i.e. by subclassing the QScreen class and creating a
94     screen driver plugin (QScreenDriverPlugin). See the
95     \l{Qt for Embedded Linux Display Management}{display management}
96     documentation for details.
97 
98     \sa QScreen, QScreenDriverPlugin
99 */
100 
101 /*!
102     Creates the screen driver specified by the given \a key, using the
103     display specified by the given \a displayId.
104 
105     Note that the keys are case-insensitive.
106 
107     \sa keys()
108 */
create(const QString & key,int displayId)109 QScreen *QScreenDriverFactory::create(const QString& key, int displayId)
110 {
111     QString driver = key.toLower();
112 #if defined(Q_OS_QNX) && !defined(QT_NO_QWS_QNX)
113     if (driver == QLatin1String("qnx") || driver.isEmpty())
114         return new QQnxScreen(displayId);
115 #endif
116 #if defined(Q_OS_INTEGRITY) && !defined(QT_NO_QWS_INTEGRITY)
117     if (driver == QLatin1String("integrityfb") || driver.isEmpty())
118         return new QIntfbScreen(displayId);
119 #endif
120 #ifndef QT_NO_QWS_QVFB
121     if (driver == QLatin1String("qvfb") || driver.isEmpty())
122         return new QVFbScreen(displayId);
123 #endif
124 #ifndef QT_NO_QWS_LINUXFB
125     if (driver == QLatin1String("linuxfb") || driver.isEmpty())
126         return new QLinuxFbScreen(displayId);
127 #endif
128 #ifndef QT_NO_QWS_DIRECTFB
129     if (driver == QLatin1String("directfb") || driver.isEmpty())
130         return new QDirectFBScreen(displayId);
131 #endif
132 #ifndef QT_NO_QWS_TRANSFORMED
133     if (driver == QLatin1String("transformed"))
134         return new QTransformedScreen(displayId);
135 #endif
136 #ifndef QT_NO_QWS_VNC
137     if (driver == QLatin1String("vnc"))
138         return new QVNCScreen(displayId);
139 #endif
140 #ifndef QT_NO_QWS_MULTISCREEN
141     if (driver == QLatin1String("multi"))
142         return new QMultiScreen(displayId);
143 #endif
144 #if !defined(Q_OS_WIN32) || defined(QT_MAKEDLL)
145 #ifndef QT_NO_LIBRARY
146 
147     if (QScreenDriverFactoryInterface *factory = qobject_cast<QScreenDriverFactoryInterface*>(loader()->instance(key)))
148         return factory->create(driver, displayId);
149 
150 #endif
151 #endif
152     return 0;
153 }
154 
155 /*!
156     Returns the list of valid keys, i.e. the available screen drivers.
157 
158     \sa create()
159 */
keys()160 QStringList QScreenDriverFactory::keys()
161 {
162     QStringList list;
163 
164 #if defined(Q_OS_QNX) && !defined(QT_NO_QWS_QNX)
165     list << QLatin1String("QNX");
166 #endif
167 #if defined(Q_OS_INTEGRITY) && !defined(QT_NO_QWS_INTEGRITY)
168     list << QLatin1String("INTEGRITYFB");
169 #endif
170 #ifndef QT_NO_QWS_QVFB
171     list << QLatin1String("QVFb");
172 #endif
173 #ifndef QT_NO_QWS_LINUXFB
174     list << QLatin1String("LinuxFb");
175 #endif
176 #ifndef QT_NO_QWS_TRANSFORMED
177     list << QLatin1String("Transformed");
178 #endif
179 #ifndef QT_NO_QWS_VNC
180     list << QLatin1String("VNC");
181 #endif
182 #ifndef QT_NO_QWS_MULTISCREEN
183     list << QLatin1String("Multi");
184 #endif
185 
186 #if !defined(Q_OS_WIN32) || defined(QT_MAKEDLL)
187 #ifndef QT_NO_LIBRARY
188     QStringList plugins = loader()->keys();
189     for (int i = 0; i < plugins.size(); ++i) {
190 # ifdef QT_NO_QWS_QVFB
191         // give QVFb top priority for autodetection
192         if (plugins.at(i) == QLatin1String("QVFb"))
193             list.prepend(plugins.at(i));
194         else
195 # endif
196         if (!list.contains(plugins.at(i)))
197             list += plugins.at(i);
198     }
199 #endif //QT_NO_LIBRARY
200 #endif //QT_MAKEDLL
201     return list;
202 }
203 
204 QT_END_NAMESPACE
205