| 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 | |
| 4 | #include "qminimalintegration.h" |
| 5 | #include "qminimalbackingstore.h" |
| 6 | |
| 7 | #include <QtGui/private/qpixmap_raster_p.h> |
| 8 | #include <QtGui/private/qguiapplication_p.h> |
| 9 | #include <qpa/qplatformfontdatabase.h> |
| 10 | #include <qpa/qplatformnativeinterface.h> |
| 11 | #include <qpa/qplatformwindow.h> |
| 12 | #include <qpa/qwindowsysteminterface.h> |
| 13 | |
| 14 | #if defined(Q_OS_WIN) |
| 15 | # include <QtGui/private/qwindowsfontdatabase_p.h> |
| 16 | # if QT_CONFIG(freetype) |
| 17 | # include <QtGui/private/qwindowsfontdatabase_ft_p.h> |
| 18 | # endif |
| 19 | #elif defined(Q_OS_DARWIN) |
| 20 | # include <QtGui/private/qcoretextfontdatabase_p.h> |
| 21 | #endif |
| 22 | |
| 23 | #if QT_CONFIG(fontconfig) |
| 24 | # include <QtGui/private/qgenericunixfontdatabase_p.h> |
| 25 | #endif |
| 26 | |
| 27 | #if QT_CONFIG(freetype) |
| 28 | #include <QtGui/private/qfontengine_ft_p.h> |
| 29 | #include <QtGui/private/qfreetypefontdatabase_p.h> |
| 30 | #endif |
| 31 | |
| 32 | #if !defined(Q_OS_WIN) |
| 33 | #include <QtGui/private/qgenericunixeventdispatcher_p.h> |
| 34 | #else |
| 35 | #include <QtCore/private/qeventdispatcher_win_p.h> |
| 36 | #endif |
| 37 | |
| 38 | QT_BEGIN_NAMESPACE |
| 39 | |
| 40 | using namespace Qt::StringLiterals; |
| 41 | |
| 42 | class QCoreTextFontEngine; |
| 43 | |
| 44 | static const char debugBackingStoreEnvironmentVariable[] = "QT_DEBUG_BACKINGSTORE"; |
| 45 | |
| 46 | static inline unsigned parseOptions(const QStringList ¶mList) |
| 47 | { |
| 48 | unsigned options = 0; |
| 49 | for (const QString ¶m : paramList) { |
| 50 | if (param == "enable_fonts"_L1) |
| 51 | options |= QMinimalIntegration::EnableFonts; |
| 52 | else if (param == "freetype"_L1) |
| 53 | options |= QMinimalIntegration::FreeTypeFontDatabase; |
| 54 | else if (param == "fontconfig"_L1) |
| 55 | options |= QMinimalIntegration::FontconfigDatabase; |
| 56 | } |
| 57 | return options; |
| 58 | } |
| 59 | |
| 60 | QMinimalIntegration::QMinimalIntegration(const QStringList ¶meters) |
| 61 | : m_fontDatabase(nullptr) |
| 62 | , m_options(parseOptions(paramList: parameters)) |
| 63 | { |
| 64 | if (qEnvironmentVariableIsSet(varName: debugBackingStoreEnvironmentVariable) |
| 65 | && qEnvironmentVariableIntValue(varName: debugBackingStoreEnvironmentVariable) > 0) { |
| 66 | m_options |= DebugBackingStore | EnableFonts; |
| 67 | } |
| 68 | |
| 69 | m_primaryScreen = new QMinimalScreen(); |
| 70 | |
| 71 | m_primaryScreen->mGeometry = QRect(0, 0, 240, 320); |
| 72 | m_primaryScreen->mDepth = 32; |
| 73 | m_primaryScreen->mFormat = QImage::Format_ARGB32_Premultiplied; |
| 74 | |
| 75 | QWindowSystemInterface::handleScreenAdded(screen: m_primaryScreen); |
| 76 | } |
| 77 | |
| 78 | QMinimalIntegration::~QMinimalIntegration() |
| 79 | { |
| 80 | QWindowSystemInterface::handleScreenRemoved(screen: m_primaryScreen); |
| 81 | delete m_fontDatabase; |
| 82 | } |
| 83 | |
| 84 | bool QMinimalIntegration::hasCapability(QPlatformIntegration::Capability cap) const |
| 85 | { |
| 86 | switch (cap) { |
| 87 | case ThreadedPixmaps: return true; |
| 88 | case MultipleWindows: return true; |
| 89 | case RhiBasedRendering: return false; |
| 90 | default: return QPlatformIntegration::hasCapability(cap); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | // Dummy font database that does not scan the fonts directory to be |
| 95 | // used for command line tools like qmlplugindump that do not create windows |
| 96 | // unless DebugBackingStore is activated. |
| 97 | class DummyFontDatabase : public QPlatformFontDatabase |
| 98 | { |
| 99 | public: |
| 100 | virtual void populateFontDatabase() override {} |
| 101 | }; |
| 102 | |
| 103 | QPlatformFontDatabase *QMinimalIntegration::fontDatabase() const |
| 104 | { |
| 105 | if (!m_fontDatabase && (m_options & EnableFonts)) { |
| 106 | #if defined(Q_OS_WIN) |
| 107 | if (m_options & FreeTypeFontDatabase) { |
| 108 | # if QT_CONFIG(freetype) |
| 109 | m_fontDatabase = new QWindowsFontDatabaseFT; |
| 110 | # endif // freetype |
| 111 | } else { |
| 112 | m_fontDatabase = new QWindowsFontDatabase; |
| 113 | } |
| 114 | #elif defined(Q_OS_DARWIN) |
| 115 | if (!(m_options & FontconfigDatabase)) { |
| 116 | if (m_options & FreeTypeFontDatabase) { |
| 117 | # if QT_CONFIG(freetype) |
| 118 | m_fontDatabase = new QCoreTextFontDatabaseEngineFactory<QFontEngineFT>; |
| 119 | # endif // freetype |
| 120 | } else { |
| 121 | m_fontDatabase = new QCoreTextFontDatabaseEngineFactory<QCoreTextFontEngine>; |
| 122 | } |
| 123 | } |
| 124 | #endif |
| 125 | |
| 126 | if (!m_fontDatabase) { |
| 127 | #if QT_CONFIG(fontconfig) |
| 128 | m_fontDatabase = new QGenericUnixFontDatabase; |
| 129 | #else |
| 130 | m_fontDatabase = QPlatformIntegration::fontDatabase(); |
| 131 | #endif |
| 132 | } |
| 133 | } |
| 134 | if (!m_fontDatabase) |
| 135 | m_fontDatabase = new DummyFontDatabase; |
| 136 | return m_fontDatabase; |
| 137 | } |
| 138 | |
| 139 | QPlatformWindow *QMinimalIntegration::createPlatformWindow(QWindow *window) const |
| 140 | { |
| 141 | Q_UNUSED(window); |
| 142 | QPlatformWindow *w = new QPlatformWindow(window); |
| 143 | w->requestActivateWindow(); |
| 144 | return w; |
| 145 | } |
| 146 | |
| 147 | QPlatformBackingStore *QMinimalIntegration::createPlatformBackingStore(QWindow *window) const |
| 148 | { |
| 149 | return new QMinimalBackingStore(window); |
| 150 | } |
| 151 | |
| 152 | QAbstractEventDispatcher *QMinimalIntegration::createEventDispatcher() const |
| 153 | { |
| 154 | #ifdef Q_OS_WIN |
| 155 | return new QEventDispatcherWin32; |
| 156 | #else |
| 157 | return createUnixEventDispatcher(); |
| 158 | #endif |
| 159 | } |
| 160 | |
| 161 | QPlatformNativeInterface *QMinimalIntegration::nativeInterface() const |
| 162 | { |
| 163 | if (!m_nativeInterface) |
| 164 | m_nativeInterface.reset(other: new QPlatformNativeInterface); |
| 165 | return m_nativeInterface.get(); |
| 166 | } |
| 167 | |
| 168 | QMinimalIntegration *QMinimalIntegration::instance() |
| 169 | { |
| 170 | return static_cast<QMinimalIntegration *>(QGuiApplicationPrivate::platformIntegration()); |
| 171 | } |
| 172 | |
| 173 | QT_END_NAMESPACE |
| 174 |
