Coverage Report

Created: 2026-03-12 07:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qtbase/src/plugins/platforms/minimal/qminimalintegration.cpp
Line
Count
Source
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
5
#include "qminimalintegration.h"
6
#include "qminimalbackingstore.h"
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/qwindowsdirectwritefontdatabase_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
39
QT_BEGIN_NAMESPACE
40
41
using namespace Qt::StringLiterals;
42
43
class QCoreTextFontEngine;
44
45
static const char debugBackingStoreEnvironmentVariable[] = "QT_DEBUG_BACKINGSTORE";
46
47
static inline unsigned parseOptions(const QStringList &paramList)
48
148k
{
49
148k
    unsigned options = 0;
50
148k
    for (const QString &param : paramList) {
51
0
        if (param == "enable_fonts"_L1)
52
0
            options |= QMinimalIntegration::EnableFonts;
53
0
        else if (param == "freetype"_L1)
54
0
            options |= QMinimalIntegration::FreeTypeFontDatabase;
55
0
        else if (param == "fontconfig"_L1)
56
0
            options |= QMinimalIntegration::FontconfigDatabase;
57
0
    }
58
148k
    return options;
59
148k
}
60
61
QMinimalIntegration::QMinimalIntegration(const QStringList &parameters)
62
148k
    : m_fontDatabase(nullptr)
63
148k
    , m_options(parseOptions(parameters))
64
148k
{
65
148k
    if (qEnvironmentVariableIsSet(debugBackingStoreEnvironmentVariable)
66
0
        && qEnvironmentVariableIntValue(debugBackingStoreEnvironmentVariable) > 0) {
67
0
        m_options |= DebugBackingStore | EnableFonts;
68
0
    }
69
70
148k
    m_primaryScreen = new QMinimalScreen();
71
72
148k
    m_primaryScreen->mGeometry = QRect(0, 0, 240, 320);
73
148k
    m_primaryScreen->mDepth = 32;
74
148k
    m_primaryScreen->mFormat = QImage::Format_ARGB32_Premultiplied;
75
76
148k
    QWindowSystemInterface::handleScreenAdded(m_primaryScreen);
77
148k
}
78
79
QMinimalIntegration::~QMinimalIntegration()
80
148k
{
81
148k
    QWindowSystemInterface::handleScreenRemoved(m_primaryScreen);
82
148k
    delete m_fontDatabase;
83
148k
}
84
85
bool QMinimalIntegration::hasCapability(QPlatformIntegration::Capability cap) const
86
0
{
87
0
    switch (cap) {
88
0
    case ThreadedPixmaps: return true;
89
0
    case MultipleWindows: return true;
90
0
    case RhiBasedRendering: return false;
91
0
    default: return QPlatformIntegration::hasCapability(cap);
92
0
    }
93
0
}
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.
98
class DummyFontDatabase : public QPlatformFontDatabase
99
{
100
public:
101
10.5k
    virtual void populateFontDatabase() override {}
102
};
103
104
QPlatformFontDatabase *QMinimalIntegration::fontDatabase() const
105
180k
{
106
180k
    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 QWindowsDirectWriteFontDatabase;
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
0
        if (!m_fontDatabase) {
128
0
#if QT_CONFIG(fontconfig)
129
0
            m_fontDatabase = new QGenericUnixFontDatabase;
130
#else
131
            m_fontDatabase = QPlatformIntegration::fontDatabase();
132
#endif
133
0
        }
134
0
    }
135
180k
    if (!m_fontDatabase)
136
13.6k
        m_fontDatabase = new DummyFontDatabase;
137
180k
    return m_fontDatabase;
138
180k
}
139
140
QPlatformWindow *QMinimalIntegration::createPlatformWindow(QWindow *window) const
141
0
{
142
0
    Q_UNUSED(window);
143
0
    QPlatformWindow *w = new QPlatformWindow(window);
144
0
    w->requestActivateWindow();
145
0
    return w;
146
0
}
147
148
QPlatformBackingStore *QMinimalIntegration::createPlatformBackingStore(QWindow *window) const
149
0
{
150
0
    return new QMinimalBackingStore(window);
151
0
}
152
153
QAbstractEventDispatcher *QMinimalIntegration::createEventDispatcher() const
154
148k
{
155
#ifdef Q_OS_WIN
156
    return new QEventDispatcherWin32;
157
#else
158
148k
    return createUnixEventDispatcher();
159
148k
#endif
160
148k
}
161
162
QPlatformNativeInterface *QMinimalIntegration::nativeInterface() const
163
0
{
164
0
    if (!m_nativeInterface)
165
0
        m_nativeInterface.reset(new QPlatformNativeInterface);
166
0
    return m_nativeInterface.get();
167
0
}
168
169
QMinimalIntegration *QMinimalIntegration::instance()
170
0
{
171
0
    return static_cast<QMinimalIntegration *>(QGuiApplicationPrivate::platformIntegration());
172
0
}
173
174
QT_END_NAMESPACE