From ae584145306a95e331b3ea377805848946b83341 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Wed, 16 May 2018 08:59:20 +0200 Subject: [PATCH] Client: Lazy load QWaylandCursor If nothing is trying to access QWaylandScreen::cursor() leave the platform cursor uninitialized. This in turn avoids initializing cursor themes, which may use a significant amount of shared memory depending on the cursor size, number of screens and screen DPI. Task-number: QTBUG-67796 Change-Id: Ifd062cb52c4889adcaadeb00bea928b8e84a2182 Reviewed-by: Paul Olav Tvete --- .../platforms/wayland/qwaylanddisplay.cpp | 1 - .../platforms/wayland/qwaylandscreen.cpp | 27 ++++++++----------- .../platforms/wayland/qwaylandscreen_p.h | 6 ++--- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/plugins/platforms/wayland/qwaylanddisplay.cpp b/src/plugins/platforms/wayland/qwaylanddisplay.cpp index 1c2b47da522..0199e169d73 100644 --- a/src/plugins/platforms/wayland/qwaylanddisplay.cpp +++ b/src/plugins/platforms/wayland/qwaylanddisplay.cpp @@ -238,7 +238,6 @@ void QWaylandDisplay::registry_global(uint32_t id, const QString &interface, uin mScreens.append(screen); // We need to get the output events before creating surfaces forceRoundTrip(); - screen->init(); mWaylandIntegration->screenAdded(screen); } else if (interface == QStringLiteral("wl_compositor")) { mCompositorVersion = qMin((int)version, 3); diff --git a/src/plugins/platforms/wayland/qwaylandscreen.cpp b/src/plugins/platforms/wayland/qwaylandscreen.cpp index 38d97a91dfb..37fe5f3234b 100644 --- a/src/plugins/platforms/wayland/qwaylandscreen.cpp +++ b/src/plugins/platforms/wayland/qwaylandscreen.cpp @@ -60,20 +60,6 @@ QWaylandScreen::QWaylandScreen(QWaylandDisplay *waylandDisplay, int version, uin { } -QWaylandScreen::~QWaylandScreen() -{ -#if QT_CONFIG(cursor) - delete mWaylandCursor; -#endif -} - -void QWaylandScreen::init() -{ -#if QT_CONFIG(cursor) - mWaylandCursor = new QWaylandCursor(this); -#endif -} - QWaylandDisplay * QWaylandScreen::display() const { return mWaylandDisplay; @@ -165,11 +151,20 @@ qreal QWaylandScreen::refreshRate() const } #if QT_CONFIG(cursor) + QPlatformCursor *QWaylandScreen::cursor() const { - return mWaylandCursor; + return const_cast(this)->waylandCursor(); } -#endif + +QWaylandCursor *QWaylandScreen::waylandCursor() +{ + if (!mWaylandCursor) + mWaylandCursor.reset(new QWaylandCursor(this)); + return mWaylandCursor.data(); +} + +#endif // QT_CONFIG(cursor) QWaylandScreen * QWaylandScreen::waylandScreenFromWindow(QWindow *window) { diff --git a/src/plugins/platforms/wayland/qwaylandscreen_p.h b/src/plugins/platforms/wayland/qwaylandscreen_p.h index 9df55d60340..39b72bc2443 100644 --- a/src/plugins/platforms/wayland/qwaylandscreen_p.h +++ b/src/plugins/platforms/wayland/qwaylandscreen_p.h @@ -67,9 +67,7 @@ class Q_WAYLAND_CLIENT_EXPORT QWaylandScreen : public QPlatformScreen, QtWayland { public: QWaylandScreen(QWaylandDisplay *waylandDisplay, int version, uint32_t id); - ~QWaylandScreen() override; - void init(); QWaylandDisplay *display() const; QString manufacturer() const override; @@ -95,7 +93,7 @@ public: #if QT_CONFIG(cursor) QPlatformCursor *cursor() const override; - QWaylandCursor *waylandCursor() const { return mWaylandCursor; } + QWaylandCursor *waylandCursor(); #endif uint32_t outputId() const { return m_outputId; } @@ -130,7 +128,7 @@ private: Qt::ScreenOrientation m_orientation = Qt::PrimaryOrientation; #if QT_CONFIG(cursor) - QWaylandCursor *mWaylandCursor = nullptr; + QScopedPointer mWaylandCursor; #endif };