Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qminimalintegration.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
7
8#include <QtGui/private/qpixmap_raster_p.h>
9#include <QtGui/private/qguiapplication_p.h>
10#include <qpa/qplatformfontdatabase.h>
11#include <qpa/qplatformnativeinterface.h>
12#include <qpa/qplatformwindow.h>
13#include <qpa/qwindowsysteminterface.h>
14
15#if defined(Q_OS_WIN)
16# include <QtGui/private/qwindowsfontdatabase_p.h>
17# if QT_CONFIG(freetype)
18# include <QtGui/private/qwindowsfontdatabase_ft_p.h>
19# endif
20#elif defined(Q_OS_DARWIN)
21# include <QtGui/private/qcoretextfontdatabase_p.h>
22#endif
23
24#if QT_CONFIG(fontconfig)
25# include <QtGui/private/qgenericunixfontdatabase_p.h>
26#endif
27
28#if QT_CONFIG(freetype)
29#include <QtGui/private/qfontengine_ft_p.h>
30#include <QtGui/private/qfreetypefontdatabase_p.h>
31#endif
32
33#if !defined(Q_OS_WIN)
34#include <QtGui/private/qgenericunixeventdispatcher_p.h>
35#else
36#include <QtCore/private/qeventdispatcher_win_p.h>
37#endif
38
40
41using namespace Qt::StringLiterals;
42
43class QCoreTextFontEngine;
44
45static const char debugBackingStoreEnvironmentVariable[] = "QT_DEBUG_BACKINGSTORE";
46
47static inline unsigned parseOptions(const QStringList &paramList)
48{
49 unsigned options = 0;
50 for (const QString &param : paramList) {
51 if (param == "enable_fonts"_L1)
52 options |= QMinimalIntegration::EnableFonts;
53 else if (param == "freetype"_L1)
54 options |= QMinimalIntegration::FreeTypeFontDatabase;
55 else if (param == "fontconfig"_L1)
56 options |= QMinimalIntegration::FontconfigDatabase;
57 }
58 return options;
59}
60
61QMinimalIntegration::QMinimalIntegration(const QStringList &parameters)
62 : m_fontDatabase(nullptr)
64{
65 if (qEnvironmentVariableIsSet(debugBackingStoreEnvironmentVariable)
66 && qEnvironmentVariableIntValue(debugBackingStoreEnvironmentVariable) > 0) {
67 m_options |= DebugBackingStore | EnableFonts;
68 }
69
70 m_primaryScreen = new QMinimalScreen();
71
72 m_primaryScreen->mGeometry = QRect(0, 0, 240, 320);
73 m_primaryScreen->mDepth = 32;
74 m_primaryScreen->mFormat = QImage::Format_ARGB32_Premultiplied;
75
76 QWindowSystemInterface::handleScreenAdded(m_primaryScreen);
77}
78
80{
81 QWindowSystemInterface::handleScreenRemoved(m_primaryScreen);
82 delete m_fontDatabase;
83}
84
85bool QMinimalIntegration::hasCapability(QPlatformIntegration::Capability cap) const
86{
87 switch (cap) {
88 case ThreadedPixmaps: return true;
89 case MultipleWindows: return true;
90 case RhiBasedRendering: return false;
91 default: return QPlatformIntegration::hasCapability(cap);
92 }
93}
94
95// Dummy font database that does not scan the fonts directory to be
96// used for command line tools like qmlplugindump that do not create windows
97// unless DebugBackingStore is activated.
99{
100public:
101 virtual void populateFontDatabase() override {}
102};
103
105{
106 if (!m_fontDatabase && (m_options & EnableFonts)) {
107#if defined(Q_OS_WIN)
108 if (m_options & FreeTypeFontDatabase) {
109# if QT_CONFIG(freetype)
110 m_fontDatabase = new QWindowsFontDatabaseFT;
111# endif // freetype
112 } else {
113 m_fontDatabase = new QWindowsFontDatabase;
114 }
115#elif defined(Q_OS_DARWIN)
116 if (!(m_options & FontconfigDatabase)) {
117 if (m_options & FreeTypeFontDatabase) {
118# if QT_CONFIG(freetype)
119 m_fontDatabase = new QCoreTextFontDatabaseEngineFactory<QFontEngineFT>;
120# endif // freetype
121 } else {
122 m_fontDatabase = new QCoreTextFontDatabaseEngineFactory<QCoreTextFontEngine>;
123 }
124 }
125#endif
126
127 if (!m_fontDatabase) {
128#if QT_CONFIG(fontconfig)
129 m_fontDatabase = new QGenericUnixFontDatabase;
130#else
131 m_fontDatabase = QPlatformIntegration::fontDatabase();
132#endif
133 }
134 }
135 if (!m_fontDatabase)
136 m_fontDatabase = new DummyFontDatabase;
137 return m_fontDatabase;
138}
139
141{
142 Q_UNUSED(window);
143 QPlatformWindow *w = new QPlatformWindow(window);
144 w->requestActivateWindow();
145 return w;
146}
147
149{
150 return new QMinimalBackingStore(window);
151}
152
154{
155#ifdef Q_OS_WIN
156 return new QEventDispatcherWin32;
157#else
158 return createUnixEventDispatcher();
159#endif
160}
161
163{
164 if (!m_nativeInterface)
165 m_nativeInterface.reset(new QPlatformNativeInterface);
166 return m_nativeInterface.get();
167}
168
170{
171 return static_cast<QMinimalIntegration *>(QGuiApplicationPrivate::platformIntegration());
172}
173
174QT_END_NAMESPACE
virtual void populateFontDatabase() override
This function is called once at startup by Qt's internal font database.
QPlatformFontDatabase * fontDatabase() const override
Accessor for the platform integration's fontdatabase.
QAbstractEventDispatcher * createEventDispatcher() const override
Factory function for the GUI event dispatcher.
QPlatformBackingStore * createPlatformBackingStore(QWindow *window) const override
Factory function for QPlatformBackingStore.
QMinimalIntegration(const QStringList &parameters)
QPlatformNativeInterface * nativeInterface() const override
static QMinimalIntegration * instance()
bool hasCapability(QPlatformIntegration::Capability cap) const override
QPlatformWindow * createPlatformWindow(QWindow *window) const override
Factory function for QPlatformWindow.
static unsigned parseOptions(const QStringList &paramList)
static const char debugBackingStoreEnvironmentVariable[]