1 | /**************************************************************************** |
---|---|
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the plugins 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 https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://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 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #include "qminimalintegration.h" |
41 | #include "qminimalbackingstore.h" |
42 | |
43 | #include <QtGui/private/qpixmap_raster_p.h> |
44 | #include <QtGui/private/qguiapplication_p.h> |
45 | #include <qpa/qplatformwindow.h> |
46 | #include <qpa/qwindowsysteminterface.h> |
47 | |
48 | #include <QtFontDatabaseSupport/private/qfreetypefontdatabase_p.h> |
49 | #if defined(Q_OS_WINRT) |
50 | # include <QtFontDatabaseSupport/private/qwinrtfontdatabase_p.h> |
51 | #elif defined(Q_OS_WIN) |
52 | # include <QtFontDatabaseSupport/private/qwindowsfontdatabase_p.h> |
53 | # if QT_CONFIG(freetype) |
54 | # include <QtFontDatabaseSupport/private/qwindowsfontdatabase_ft_p.h> |
55 | # endif |
56 | #elif defined(Q_OS_DARWIN) |
57 | # include <QtFontDatabaseSupport/private/qcoretextfontdatabase_p.h> |
58 | #endif |
59 | |
60 | #if QT_CONFIG(fontconfig) |
61 | # include <QtFontDatabaseSupport/private/qgenericunixfontdatabase_p.h> |
62 | # include <qpa/qplatformfontdatabase.h> |
63 | #endif |
64 | |
65 | #if QT_CONFIG(freetype) |
66 | #include <QtFontDatabaseSupport/private/qfontengine_ft_p.h> |
67 | #endif |
68 | |
69 | #if !defined(Q_OS_WIN) |
70 | #include <QtEventDispatcherSupport/private/qgenericunixeventdispatcher_p.h> |
71 | #elif defined(Q_OS_WINRT) |
72 | #include <QtCore/private/qeventdispatcher_winrt_p.h> |
73 | #else |
74 | #include <QtCore/private/qeventdispatcher_win_p.h> |
75 | #endif |
76 | |
77 | QT_BEGIN_NAMESPACE |
78 | |
79 | class QCoreTextFontEngine; |
80 | |
81 | static const char debugBackingStoreEnvironmentVariable[] = "QT_DEBUG_BACKINGSTORE"; |
82 | |
83 | static inline unsigned parseOptions(const QStringList ¶mList) |
84 | { |
85 | unsigned options = 0; |
86 | for (const QString ¶m : paramList) { |
87 | if (param == QLatin1String("enable_fonts")) |
88 | options |= QMinimalIntegration::EnableFonts; |
89 | else if (param == QLatin1String("freetype")) |
90 | options |= QMinimalIntegration::FreeTypeFontDatabase; |
91 | else if (param == QLatin1String("fontconfig")) |
92 | options |= QMinimalIntegration::FontconfigDatabase; |
93 | } |
94 | return options; |
95 | } |
96 | |
97 | QMinimalIntegration::QMinimalIntegration(const QStringList ¶meters) |
98 | : m_fontDatabase(0) |
99 | , m_options(parseOptions(paramList: parameters)) |
100 | { |
101 | if (qEnvironmentVariableIsSet(varName: debugBackingStoreEnvironmentVariable) |
102 | && qEnvironmentVariableIntValue(varName: debugBackingStoreEnvironmentVariable) > 0) { |
103 | m_options |= DebugBackingStore | EnableFonts; |
104 | } |
105 | |
106 | m_primaryScreen = new QMinimalScreen(); |
107 | |
108 | m_primaryScreen->mGeometry = QRect(0, 0, 240, 320); |
109 | m_primaryScreen->mDepth = 32; |
110 | m_primaryScreen->mFormat = QImage::Format_ARGB32_Premultiplied; |
111 | |
112 | QWindowSystemInterface::handleScreenAdded(screen: m_primaryScreen); |
113 | } |
114 | |
115 | QMinimalIntegration::~QMinimalIntegration() |
116 | { |
117 | QWindowSystemInterface::handleScreenRemoved(screen: m_primaryScreen); |
118 | delete m_fontDatabase; |
119 | } |
120 | |
121 | bool QMinimalIntegration::hasCapability(QPlatformIntegration::Capability cap) const |
122 | { |
123 | switch (cap) { |
124 | case ThreadedPixmaps: return true; |
125 | case MultipleWindows: return true; |
126 | default: return QPlatformIntegration::hasCapability(cap); |
127 | } |
128 | } |
129 | |
130 | // Dummy font database that does not scan the fonts directory to be |
131 | // used for command line tools like qmlplugindump that do not create windows |
132 | // unless DebugBackingStore is activated. |
133 | class DummyFontDatabase : public QPlatformFontDatabase |
134 | { |
135 | public: |
136 | virtual void populateFontDatabase() override {} |
137 | }; |
138 | |
139 | QPlatformFontDatabase *QMinimalIntegration::fontDatabase() const |
140 | { |
141 | if (!m_fontDatabase && (m_options & EnableFonts)) { |
142 | #if defined(Q_OS_WINRT) |
143 | m_fontDatabase = new QWinRTFontDatabase; |
144 | #elif defined(Q_OS_WIN) |
145 | if (m_options & FreeTypeFontDatabase) { |
146 | # if QT_CONFIG(freetype) |
147 | m_fontDatabase = new QWindowsFontDatabaseFT; |
148 | # endif // freetype |
149 | } else { |
150 | m_fontDatabase = new QWindowsFontDatabase; |
151 | } |
152 | #elif defined(Q_OS_DARWIN) |
153 | if (!(m_options & FontconfigDatabase)) { |
154 | if (m_options & FreeTypeFontDatabase) { |
155 | # if QT_CONFIG(freetype) |
156 | m_fontDatabase = new QCoreTextFontDatabaseEngineFactory<QFontEngineFT>; |
157 | # endif // freetype |
158 | } else { |
159 | m_fontDatabase = new QCoreTextFontDatabaseEngineFactory<QCoreTextFontEngine>; |
160 | } |
161 | } |
162 | #endif |
163 | |
164 | if (!m_fontDatabase) { |
165 | #if QT_CONFIG(fontconfig) |
166 | m_fontDatabase = new QGenericUnixFontDatabase; |
167 | #else |
168 | m_fontDatabase = QPlatformIntegration::fontDatabase(); |
169 | #endif |
170 | } |
171 | } |
172 | if (!m_fontDatabase) |
173 | m_fontDatabase = new DummyFontDatabase; |
174 | return m_fontDatabase; |
175 | } |
176 | |
177 | QPlatformWindow *QMinimalIntegration::createPlatformWindow(QWindow *window) const |
178 | { |
179 | Q_UNUSED(window); |
180 | QPlatformWindow *w = new QPlatformWindow(window); |
181 | w->requestActivateWindow(); |
182 | return w; |
183 | } |
184 | |
185 | QPlatformBackingStore *QMinimalIntegration::createPlatformBackingStore(QWindow *window) const |
186 | { |
187 | return new QMinimalBackingStore(window); |
188 | } |
189 | |
190 | QAbstractEventDispatcher *QMinimalIntegration::createEventDispatcher() const |
191 | { |
192 | #ifdef Q_OS_WIN |
193 | #ifndef Q_OS_WINRT |
194 | return new QEventDispatcherWin32; |
195 | #else // !Q_OS_WINRT |
196 | return new QEventDispatcherWinRT; |
197 | #endif // Q_OS_WINRT |
198 | #else |
199 | return createUnixEventDispatcher(); |
200 | #endif |
201 | } |
202 | |
203 | QMinimalIntegration *QMinimalIntegration::instance() |
204 | { |
205 | return static_cast<QMinimalIntegration *>(QGuiApplicationPrivate::platformIntegration()); |
206 | } |
207 | |
208 | QT_END_NAMESPACE |
209 |