qpa: lazily populate the services object except xcb

In order to optimize the footprint of QPA plugins, we avoid to
create QPlatformServices object in QPlatformIntegration constructor.
It benefits embedded platforms and others.

Task-number: QTBUG-130884
Pick-to: 6.9 6.8 6.5
Change-Id: I5c0d2616ace9fbc0e077eece32d8836b40fc83dd
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Liang Qi 2024-12-05 12:01:36 +01:00
parent 967d9b8cf2
commit ff51ea5418
25 changed files with 57 additions and 34 deletions

View File

@ -216,7 +216,6 @@ QAndroidPlatformIntegration::QAndroidPlatformIntegration(const QStringList &para
m_mainThread = QThread::currentThread();
m_androidFDB = new QAndroidPlatformFontDatabase();
m_androidPlatformServices = new QAndroidPlatformServices();
#ifndef QT_NO_CLIPBOARD
m_androidPlatformClipboard = new QAndroidPlatformClipboard();
@ -453,7 +452,10 @@ QPlatformNativeInterface *QAndroidPlatformIntegration::nativeInterface() const
QPlatformServices *QAndroidPlatformIntegration::services() const
{
return m_androidPlatformServices;
if (m_androidPlatformServices.isNull())
m_androidPlatformServices.reset(new QAndroidPlatformServices);
return m_androidPlatformServices.data();
}
QVariant QAndroidPlatformIntegration::styleHint(StyleHint hint) const

View File

@ -136,7 +136,7 @@ private:
QPlatformFontDatabase *m_androidFDB;
QAndroidPlatformNativeInterface *m_androidPlatformNativeInterface;
QAndroidPlatformServices *m_androidPlatformServices;
mutable QScopedPointer<QAndroidPlatformServices> m_androidPlatformServices;
// Handling the multiple screens connected. Every display is identified
// with an unique (autoincremented) displayID. The values of this ID will

View File

@ -30,7 +30,6 @@ using namespace Qt::StringLiterals;
QBsdFbIntegration::QBsdFbIntegration(const QStringList &paramList)
{
m_fontDb.reset(new QGenericUnixFontDatabase);
m_services.reset(new QGenericUnixServices);
m_primaryScreen.reset(new QBsdFbScreen(paramList));
}
@ -97,6 +96,9 @@ QPlatformFontDatabase *QBsdFbIntegration::fontDatabase() const
QPlatformServices *QBsdFbIntegration::services() const
{
if (m_services.isNull())
m_services.reset(new QGenericUnixServices);
return m_services.data();
}

View File

@ -41,7 +41,7 @@ private:
QScopedPointer<QBsdFbScreen> m_primaryScreen;
QScopedPointer<QPlatformInputContext> m_inputContext;
QScopedPointer<QPlatformFontDatabase> m_fontDb;
QScopedPointer<QPlatformServices> m_services;
mutable QScopedPointer<QPlatformServices> m_services;
QScopedPointer<QFbVtHandler> m_vtHandler;
QScopedPointer<QPlatformNativeInterface> m_nativeInterface;
};

View File

@ -111,7 +111,7 @@ private:
#endif
QScopedPointer<QCocoaDrag> mCocoaDrag;
QScopedPointer<QCocoaNativeInterface> mNativeInterface;
QScopedPointer<QCocoaServices> mServices;
mutable QScopedPointer<QCocoaServices> mServices;
QScopedPointer<QAppleKeyMapper> mKeyboardMapper;
#if QT_CONFIG(vulkan)

View File

@ -109,7 +109,6 @@ QCocoaIntegration::QCocoaIntegration(const QStringList &paramList)
#endif
, mCocoaDrag(new QCocoaDrag)
, mNativeInterface(new QCocoaNativeInterface)
, mServices(new QCocoaServices)
, mKeyboardMapper(new QAppleKeyMapper)
{
logVersionInformation();
@ -394,6 +393,9 @@ QPlatformTheme *QCocoaIntegration::createPlatformTheme(const QString &name) cons
QCocoaServices *QCocoaIntegration::services() const
{
if (mServices.isNull())
mServices.reset(new QCocoaServices);
return mServices.data();
}

View File

@ -26,7 +26,6 @@ QT_BEGIN_NAMESPACE
QDirectFbIntegration::QDirectFbIntegration()
: m_fontDb(new QGenericUnixFontDatabase())
, m_services(new QGenericUnixServices)
{
}
@ -125,6 +124,9 @@ QPlatformFontDatabase *QDirectFbIntegration::fontDatabase() const
QPlatformServices *QDirectFbIntegration::services() const
{
if (m_services.isNull())
m_services.reset(new QGenericUnixServices);
return m_services.data();
}

View File

@ -47,7 +47,7 @@ protected:
QScopedPointer<QDirectFbInput> m_input;
QScopedPointer<QThread> m_inputRunner;
QScopedPointer<QPlatformFontDatabase> m_fontDb;
QScopedPointer<QPlatformServices> m_services;
mutable QScopedPointer<QPlatformServices> m_services;
QPlatformInputContext *m_inputContext;
};

View File

@ -77,7 +77,6 @@ QEglFSIntegration::QEglFSIntegration()
: m_display(EGL_NO_DISPLAY),
m_inputContext(nullptr),
m_fontDb(new QGenericUnixFontDatabase),
m_services(new QGenericUnixServices),
m_disableInputHandlers(false)
{
m_disableInputHandlers = qEnvironmentVariableIntValue("QT_QPA_EGLFS_DISABLE_INPUT");
@ -132,6 +131,9 @@ QAbstractEventDispatcher *QEglFSIntegration::createEventDispatcher() const
QPlatformServices *QEglFSIntegration::services() const
{
if (m_services.isNull())
m_services.reset(new QGenericUnixServices);
return m_services.data();
}

View File

@ -108,7 +108,7 @@ private:
EGLDisplay m_display;
QPlatformInputContext *m_inputContext;
QScopedPointer<QPlatformFontDatabase> m_fontDb;
QScopedPointer<QPlatformServices> m_services;
mutable QScopedPointer<QPlatformServices> m_services;
QScopedPointer<QFbVtHandler> m_vtHandler;
QPointer<QWindow> m_pointerWindow;
bool m_disableInputHandlers;

View File

@ -45,8 +45,6 @@ QHaikuIntegration::QHaikuIntegration(const QStringList &parameters)
m_screen = new QHaikuScreen;
m_services = new QHaikuServices;
// notify system about available screen
QWindowSystemInterface::handleScreenAdded(m_screen);
}
@ -78,6 +76,9 @@ QPlatformFontDatabase *QHaikuIntegration::fontDatabase() const
QPlatformServices *QHaikuIntegration::services() const
{
if (!m_services)
m_services = new QHaikuServices;
return m_services;
}

View File

@ -34,7 +34,7 @@ public:
private:
QHaikuClipboard *m_clipboard;
QHaikuScreen *m_screen;
QHaikuServices *m_services;
mutable QHaikuServices *m_services = nullptr;
};
QT_END_NAMESPACE

View File

@ -20,8 +20,7 @@
QT_BEGIN_NAMESPACE
QIntegrityFbIntegration::QIntegrityFbIntegration(const QStringList &paramList)
: m_fontDb(new QGenericUnixFontDatabase),
m_services(new QGenericUnixServices)
: m_fontDb(new QGenericUnixFontDatabase)
{
m_primaryScreen = new QIntegrityFbScreen(paramList);
}
@ -84,6 +83,9 @@ QPlatformFontDatabase *QIntegrityFbIntegration::fontDatabase() const
QPlatformServices *QIntegrityFbIntegration::services() const
{
if (m_services.isNull())
m_services.reset(new QGenericUnixServices);
return m_services.data();
}

View File

@ -40,7 +40,7 @@ private:
QIntegrityFbScreen *m_primaryScreen;
QPlatformInputContext *m_inputContext;
QScopedPointer<QPlatformFontDatabase> m_fontDb;
QScopedPointer<QPlatformServices> m_services;
mutable QScopedPointer<QPlatformServices> m_services;
QScopedPointer<QPlatformNativeInterface> m_nativeInterface;
};

View File

@ -115,7 +115,7 @@ private:
#if QT_CONFIG(tabletevent)
QPointingDevice *m_pencilDevice = nullptr;
#endif
QIOSServices *m_platformServices;
mutable QIOSServices *m_platformServices = nullptr;
mutable QPlatformAccessibility *m_accessibility;
QFactoryLoader *m_optionalPlugins;
#if !defined(Q_OS_TVOS) && !defined(Q_OS_VISIONOS)

View File

@ -59,7 +59,6 @@ QIOSIntegration::QIOSIntegration()
, m_clipboard(new QIOSClipboard)
#endif
, m_inputContext(0)
, m_platformServices(new QIOSServices)
, m_accessibility(0)
, m_optionalPlugins(new QFactoryLoader(QIosOptionalPluginInterface_iid, "/platforms/darwin"_L1))
{
@ -238,6 +237,9 @@ QPlatformInputContext *QIOSIntegration::inputContext() const
QPlatformServices *QIOSIntegration::services() const
{
if (!m_platformServices)
m_platformServices = new QIOSServices;
return m_platformServices;
}

View File

@ -41,7 +41,6 @@ using namespace Qt::StringLiterals;
QLinuxFbIntegration::QLinuxFbIntegration(const QStringList &paramList)
: m_primaryScreen(nullptr),
m_fontDb(new QGenericUnixFontDatabase),
m_services(new QGenericUnixServices),
m_kbdMgr(nullptr)
{
#if QT_CONFIG(kms)
@ -111,6 +110,9 @@ QPlatformFontDatabase *QLinuxFbIntegration::fontDatabase() const
QPlatformServices *QLinuxFbIntegration::services() const
{
if (m_services.isNull())
m_services.reset(new QGenericUnixServices);
return m_services.data();
}

View File

@ -53,7 +53,7 @@ private:
QFbScreen *m_primaryScreen;
QPlatformInputContext *m_inputContext;
QScopedPointer<QPlatformFontDatabase> m_fontDb;
QScopedPointer<QPlatformServices> m_services;
mutable QScopedPointer<QPlatformServices> m_services;
QScopedPointer<QFbVtHandler> m_vtHandler;
QEvdevKeyboardManager *m_kbdMgr;

View File

@ -74,7 +74,6 @@ QOffscreenIntegration::QOffscreenIntegration(const QStringList& paramList)
#if QT_CONFIG(draganddrop)
m_drag.reset(new QOffscreenDrag);
#endif
m_services.reset(new QPlatformServices);
QJsonObject config = resolveConfigFileConfiguration(paramList).value_or(defaultConfiguration());
setConfiguration(config);
@ -417,6 +416,9 @@ QPlatformDrag *QOffscreenIntegration::drag() const
QPlatformServices *QOffscreenIntegration::services() const
{
if (m_services.isNull())
m_services.reset(new QPlatformServices);
return m_services.data();
}

View File

@ -55,7 +55,7 @@ protected:
QScopedPointer<QPlatformDrag> m_drag;
#endif
QScopedPointer<QPlatformInputContext> m_inputContext;
QScopedPointer<QPlatformServices> m_services;
mutable QScopedPointer<QPlatformServices> m_services;
mutable QScopedPointer<QPlatformNativeInterface> m_nativeInterface;
QList<QOffscreenScreen *> m_screens;
bool m_windowFrameMarginsEnabled = true;

View File

@ -124,7 +124,6 @@ QQnxIntegration::QQnxIntegration(const QStringList &paramList)
, m_buttonsNotifier(new QQnxButtonEventNotifier())
#endif
, m_qpaInputContext(0)
, m_services(0)
, m_fontDatabase(new QGenericUnixFontDatabase())
, m_eventDispatcher(createUnixEventDispatcher())
, m_nativeInterface(new QQnxNativeInterface(this))
@ -190,10 +189,6 @@ QQnxIntegration::QQnxIntegration(const QStringList &paramList)
m_navigator = new QQnxNavigatorPps();
#endif
// Create services handling class
if (m_navigator)
m_services = new QQnxServices(m_navigator);
createDisplays();
if (m_virtualKeyboard) {
@ -473,6 +468,10 @@ QVariant QQnxIntegration::styleHint(QPlatformIntegration::StyleHint hint) const
QPlatformServices * QQnxIntegration::services() const
{
// Create services handling class
if (m_navigator && !m_services)
m_services = new QQnxServices(m_navigator);
return m_services;
}

View File

@ -128,7 +128,7 @@ private:
QQnxButtonEventNotifier *m_buttonsNotifier;
#endif
QPlatformInputContext *m_qpaInputContext;
QQnxServices *m_services;
mutable QQnxServices *m_services = nullptr;
QPlatformFontDatabase *m_fontDatabase;
mutable QAbstractEventDispatcher *m_eventDispatcher;
QQnxNativeInterface *m_nativeInterface;

View File

@ -25,8 +25,7 @@ QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
QVncIntegration::QVncIntegration(const QStringList &paramList)
: m_fontDb(new QGenericUnixFontDatabase),
m_services(new QGenericUnixServices)
: m_fontDb(new QGenericUnixFontDatabase)
{
QRegularExpression portRx("port=(\\d+)"_L1);
quint16 port = 5900;
@ -105,6 +104,9 @@ QPlatformFontDatabase *QVncIntegration::fontDatabase() const
QPlatformServices *QVncIntegration::services() const
{
if (m_services.isNull())
m_services.reset(new QGenericUnixServices);
return m_services.data();
}

View File

@ -40,7 +40,7 @@ private:
QVncScreen *m_primaryScreen;
QPlatformInputContext *m_inputContext;
QScopedPointer<QPlatformFontDatabase> m_fontDb;
QScopedPointer<QPlatformServices> m_services;
mutable QScopedPointer<QPlatformServices> m_services;
QScopedPointer<QPlatformNativeInterface> m_nativeInterface;
};

View File

@ -105,7 +105,7 @@ struct QWindowsIntegrationPrivate
#if QT_CONFIG(accessibility)
QWindowsUiaAccessibility m_accessibility;
#endif
QWindowsServices m_services;
mutable QScopedPointer<QWindowsServices> m_services;
};
template <typename IntType>
@ -598,7 +598,10 @@ QPlatformTheme *QWindowsIntegration::createPlatformTheme(const QString &name) co
QPlatformServices *QWindowsIntegration::services() const
{
return &d->m_services;
if (d->m_services.isNull())
d->m_services.reset(new QWindowsServices);
return d->m_services.data();
}
void QWindowsIntegration::beep() const