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 <QtGui/private/qfreetypefontdatabase_p.h> |
49 | #if defined(Q_OS_WIN) |
50 | # include <QtGui/private/qwindowsfontdatabase_p.h> |
51 | # if QT_CONFIG(freetype) |
52 | # include <QtGui/private/qwindowsfontdatabase_ft_p.h> |
53 | # endif |
54 | #elif defined(Q_OS_DARWIN) |
55 | # include <QtGui/private/qcoretextfontdatabase_p.h> |
56 | #endif |
57 | |
58 | #if QT_CONFIG(fontconfig) |
59 | # include <QtGui/private/qgenericunixfontdatabase_p.h> |
60 | # include <qpa/qplatformfontdatabase.h> |
61 | #endif |
62 | |
63 | #if QT_CONFIG(freetype) |
64 | #include <QtGui/private/qfontengine_ft_p.h> |
65 | #endif |
66 | |
67 | #if !defined(Q_OS_WIN) |
68 | #include <QtGui/private/qgenericunixeventdispatcher_p.h> |
69 | #else |
70 | #include <QtCore/private/qeventdispatcher_win_p.h> |
71 | #endif |
72 | |
73 | QT_BEGIN_NAMESPACE |
74 | |
75 | class QCoreTextFontEngine; |
76 | |
77 | static const char debugBackingStoreEnvironmentVariable[] = "QT_DEBUG_BACKINGSTORE"; |
78 | |
79 | static inline unsigned parseOptions(const QStringList ¶mList) |
80 | { |
81 | unsigned options = 0; |
82 | for (const QString ¶m : paramList) { |
83 | if (param == QLatin1String("enable_fonts")) |
84 | options |= QMinimalIntegration::EnableFonts; |
85 | else if (param == QLatin1String("freetype")) |
86 | options |= QMinimalIntegration::FreeTypeFontDatabase; |
87 | else if (param == QLatin1String("fontconfig")) |
88 | options |= QMinimalIntegration::FontconfigDatabase; |
89 | } |
90 | return options; |
91 | } |
92 | |
93 | QMinimalIntegration::QMinimalIntegration(const QStringList ¶meters) |
94 | : m_fontDatabase(0) |
95 | , m_options(parseOptions(parameters)) |
96 | { |
97 | if (qEnvironmentVariableIsSet(debugBackingStoreEnvironmentVariable) |
98 | && qEnvironmentVariableIntValue(debugBackingStoreEnvironmentVariable) > 0) { |
99 | m_options |= DebugBackingStore | EnableFonts; |
100 | } |
101 | |
102 | m_primaryScreen = new QMinimalScreen(); |
103 | |
104 | m_primaryScreen->mGeometry = QRect(0, 0, 240, 320); |
105 | m_primaryScreen->mDepth = 32; |
106 | m_primaryScreen->mFormat = QImage::Format_ARGB32_Premultiplied; |
107 | |
108 | QWindowSystemInterface::handleScreenAdded(m_primaryScreen); |
109 | } |
110 | |
111 | QMinimalIntegration::~QMinimalIntegration() |
112 | { |
113 | QWindowSystemInterface::handleScreenRemoved(m_primaryScreen); |
114 | delete m_fontDatabase; |
115 | } |
116 | |
117 | bool QMinimalIntegration::hasCapability(QPlatformIntegration::Capability cap) const |
118 | { |
119 | switch (cap) { |
120 | case ThreadedPixmaps: return true; |
121 | case MultipleWindows: return true; |
122 | default: return QPlatformIntegration::hasCapability(cap); |
123 | } |
124 | } |
125 | |
126 | // Dummy font database that does not scan the fonts directory to be |
127 | // used for command line tools like qmlplugindump that do not create windows |
128 | // unless DebugBackingStore is activated. |
129 | class DummyFontDatabase : public QPlatformFontDatabase |
130 | { |
131 | public: |
132 | virtual void populateFontDatabase() override {} |
133 | }; |
134 | |
135 | QPlatformFontDatabase *QMinimalIntegration::fontDatabase() const |
136 | { |
137 | if (!m_fontDatabase && (m_options & EnableFonts)) { |
138 | #if defined(Q_OS_WIN) |
139 | if (m_options & FreeTypeFontDatabase) { |
140 | # if QT_CONFIG(freetype) |
141 | m_fontDatabase = new QWindowsFontDatabaseFT; |
142 | # endif // freetype |
143 | } else { |
144 | m_fontDatabase = new QWindowsFontDatabase; |
145 | } |
146 | #elif defined(Q_OS_DARWIN) |
147 | if (!(m_options & FontconfigDatabase)) { |
148 | if (m_options & FreeTypeFontDatabase) { |
149 | # if QT_CONFIG(freetype) |
150 | m_fontDatabase = new QCoreTextFontDatabaseEngineFactory<QFontEngineFT>; |
151 | # endif // freetype |
152 | } else { |
153 | m_fontDatabase = new QCoreTextFontDatabaseEngineFactory<QCoreTextFontEngine>; |
154 | } |
155 | } |
156 | #endif |
157 | |
158 | if (!m_fontDatabase) { |
159 | #if QT_CONFIG(fontconfig) |
160 | m_fontDatabase = new QGenericUnixFontDatabase; |
161 | #else |
162 | m_fontDatabase = QPlatformIntegration::fontDatabase(); |
163 | #endif |
164 | } |
165 | } |
166 | if (!m_fontDatabase) |
167 | m_fontDatabase = new DummyFontDatabase; |
168 | return m_fontDatabase; |
169 | } |
170 | |
171 | QPlatformWindow *QMinimalIntegration::createPlatformWindow(QWindow *window) const |
172 | { |
173 | Q_UNUSED(window); |
174 | QPlatformWindow *w = new QPlatformWindow(window); |
175 | w->requestActivateWindow(); |
176 | return w; |
177 | } |
178 | |
179 | QPlatformBackingStore *QMinimalIntegration::createPlatformBackingStore(QWindow *window) const |
180 | { |
181 | return new QMinimalBackingStore(window); |
182 | } |
183 | |
184 | QAbstractEventDispatcher *QMinimalIntegration::createEventDispatcher() const |
185 | { |
186 | #ifdef Q_OS_WIN |
187 | return new QEventDispatcherWin32; |
188 | #else |
189 | return createUnixEventDispatcher(); |
190 | #endif |
191 | } |
192 | |
193 | QMinimalIntegration *QMinimalIntegration::instance() |
194 | { |
195 | return static_cast<QMinimalIntegration *>(QGuiApplicationPrivate::platformIntegration()); |
196 | } |
197 | |
198 | QT_END_NAMESPACE |
199 |