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.8 6.5
Change-Id: I5c0d2616ace9fbc0e077eece32d8836b40fc83dd
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit ff51ea5418d131248b07e327513b41dad1231f37)
Reviewed-by: Liang Qi <liang.qi@qt.io>
This commit is contained in:
Liang Qi 2024-12-05 12:01:36 +01:00
parent cebb2dd068
commit dcac89b5c7
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_mainThread = QThread::currentThread();
m_androidFDB = new QAndroidPlatformFontDatabase(); m_androidFDB = new QAndroidPlatformFontDatabase();
m_androidPlatformServices = new QAndroidPlatformServices();
#ifndef QT_NO_CLIPBOARD #ifndef QT_NO_CLIPBOARD
m_androidPlatformClipboard = new QAndroidPlatformClipboard(); m_androidPlatformClipboard = new QAndroidPlatformClipboard();
@ -453,7 +452,10 @@ QPlatformNativeInterface *QAndroidPlatformIntegration::nativeInterface() const
QPlatformServices *QAndroidPlatformIntegration::services() 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 QVariant QAndroidPlatformIntegration::styleHint(StyleHint hint) const

View File

@ -136,7 +136,7 @@ private:
QPlatformFontDatabase *m_androidFDB; QPlatformFontDatabase *m_androidFDB;
QAndroidPlatformNativeInterface *m_androidPlatformNativeInterface; QAndroidPlatformNativeInterface *m_androidPlatformNativeInterface;
QAndroidPlatformServices *m_androidPlatformServices; mutable QScopedPointer<QAndroidPlatformServices> m_androidPlatformServices;
// Handling the multiple screens connected. Every display is identified // Handling the multiple screens connected. Every display is identified
// with an unique (autoincremented) displayID. The values of this ID will // 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) QBsdFbIntegration::QBsdFbIntegration(const QStringList &paramList)
{ {
m_fontDb.reset(new QGenericUnixFontDatabase); m_fontDb.reset(new QGenericUnixFontDatabase);
m_services.reset(new QGenericUnixServices);
m_primaryScreen.reset(new QBsdFbScreen(paramList)); m_primaryScreen.reset(new QBsdFbScreen(paramList));
} }
@ -97,6 +96,9 @@ QPlatformFontDatabase *QBsdFbIntegration::fontDatabase() const
QPlatformServices *QBsdFbIntegration::services() const QPlatformServices *QBsdFbIntegration::services() const
{ {
if (m_services.isNull())
m_services.reset(new QGenericUnixServices);
return m_services.data(); return m_services.data();
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -109,7 +109,7 @@ private:
#endif #endif
QPlatformInputContext *m_inputContext; QPlatformInputContext *m_inputContext;
QPointingDevice *m_touchDevice; QPointingDevice *m_touchDevice;
QIOSServices *m_platformServices; mutable QIOSServices *m_platformServices = nullptr;
mutable QPlatformAccessibility *m_accessibility; mutable QPlatformAccessibility *m_accessibility;
QFactoryLoader *m_optionalPlugins; QFactoryLoader *m_optionalPlugins;
#if !defined(Q_OS_TVOS) && !defined(Q_OS_VISIONOS) #if !defined(Q_OS_TVOS) && !defined(Q_OS_VISIONOS)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -105,7 +105,7 @@ struct QWindowsIntegrationPrivate
#if QT_CONFIG(accessibility) #if QT_CONFIG(accessibility)
QWindowsUiaAccessibility m_accessibility; QWindowsUiaAccessibility m_accessibility;
#endif #endif
QWindowsServices m_services; mutable QScopedPointer<QWindowsServices> m_services;
}; };
template <typename IntType> template <typename IntType>
@ -598,7 +598,10 @@ QPlatformTheme *QWindowsIntegration::createPlatformTheme(const QString &name) co
QPlatformServices *QWindowsIntegration::services() const 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 void QWindowsIntegration::beep() const