From 633d4e6fd121fe128aec78bb9c137c4f2f82f1ce Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Tue, 15 May 2018 09:58:18 +0200 Subject: Client: Only load cursor theme once Now cursor themes load once per device pixel ratio, and not once per screen. Task-number: QTBUG-67796 Change-Id: I4c253e65a791d69e7d510c4228989390a4343110 Reviewed-by: Paul Olav Tvete --- src/client/qwaylandcursor.cpp | 22 +--------------------- src/client/qwaylandcursor_p.h | 1 - src/client/qwaylanddisplay.cpp | 35 +++++++++++++++++++++++++++++++++++ src/client/qwaylanddisplay_p.h | 5 +++++ 4 files changed, 41 insertions(+), 22 deletions(-) (limited to 'src/client') diff --git a/src/client/qwaylandcursor.cpp b/src/client/qwaylandcursor.cpp index a356950c3..3d2cbd761 100644 --- a/src/client/qwaylandcursor.cpp +++ b/src/client/qwaylandcursor.cpp @@ -55,31 +55,11 @@ namespace QtWaylandClient { QWaylandCursor::QWaylandCursor(QWaylandScreen *screen) : mDisplay(screen->display()) + , mCursorTheme(mDisplay->loadCursorTheme(screen->devicePixelRatio())) { - //TODO: Make wl_cursor_theme_load arguments configurable here - QByteArray cursorTheme = qgetenv("XCURSOR_THEME"); - if (cursorTheme.isEmpty()) - cursorTheme = QByteArray("default"); - int cursorSize = qEnvironmentVariableIntValue("XCURSOR_SIZE"); - if (cursorSize <= 0) - cursorSize = 32; - - // wl_surface.set_buffer_scale is not supported on earlier versions - if (mDisplay->compositorVersion() >= 3) - cursorSize *= screen->devicePixelRatio(); - - mCursorTheme = wl_cursor_theme_load(cursorTheme, cursorSize, mDisplay->shm()->object()); - if (!mCursorTheme) - qDebug() << "Could not load theme" << cursorTheme; initCursorMap(); } -QWaylandCursor::~QWaylandCursor() -{ - if (mCursorTheme) - wl_cursor_theme_destroy(mCursorTheme); -} - struct wl_cursor_image *QWaylandCursor::cursorImage(Qt::CursorShape newShape) { struct wl_cursor *waylandCursor = nullptr; diff --git a/src/client/qwaylandcursor_p.h b/src/client/qwaylandcursor_p.h index b3df93160..532e46c19 100644 --- a/src/client/qwaylandcursor_p.h +++ b/src/client/qwaylandcursor_p.h @@ -73,7 +73,6 @@ class Q_WAYLAND_CLIENT_EXPORT QWaylandCursor : public QPlatformCursor { public: QWaylandCursor(QWaylandScreen *screen); - ~QWaylandCursor() override; void changeCursor(QCursor *cursor, QWindow *window) override; void pointerEvent(const QMouseEvent &event) override; diff --git a/src/client/qwaylanddisplay.cpp b/src/client/qwaylanddisplay.cpp index 9cbb3524d..6a6370bf9 100644 --- a/src/client/qwaylanddisplay.cpp +++ b/src/client/qwaylanddisplay.cpp @@ -50,6 +50,9 @@ #if QT_CONFIG(wayland_datadevice) #include "qwaylanddatadevicemanager_p.h" #endif +#if QT_CONFIG(cursor) +#include +#endif #include "qwaylandhardwareintegration_p.h" #include "qwaylandinputcontext_p.h" @@ -151,8 +154,14 @@ QWaylandDisplay::~QWaylandDisplay(void) mWaylandIntegration->destroyScreen(screen); } mScreens.clear(); + #if QT_CONFIG(wayland_datadevice) delete mDndSelectionHandler.take(); +#endif +#if QT_CONFIG(cursor) + for (auto *cursorTheme : mCursorThemesBySize) + wl_cursor_theme_destroy(cursorTheme); + mCursorThemesBySize.clear(); #endif if (mDisplay) wl_display_disconnect(mDisplay); @@ -472,6 +481,7 @@ QWaylandInputDevice *QWaylandDisplay::defaultInputDevice() const } #if QT_CONFIG(cursor) + void QWaylandDisplay::setCursor(struct wl_buffer *buffer, struct wl_cursor_image *image, qreal dpr) { /* Qt doesn't tell us which input device we should set the cursor @@ -491,6 +501,31 @@ void QWaylandDisplay::setCursor(const QSharedPointer &buffer, co inputDevice->setCursor(buffer, hotSpot, dpr); } } + +struct ::wl_cursor_theme *QWaylandDisplay::loadCursorTheme(qreal devicePixelRatio) +{ + QByteArray themeName = qgetenv("XCURSOR_THEME"); + if (themeName.isEmpty()) + themeName = QByteArray("default"); + + int cursorSize = qEnvironmentVariableIntValue("XCURSOR_SIZE"); + if (cursorSize <= 0) + cursorSize = 32; + if (compositorVersion() >= 3) // set_buffer_scale is not supported on earlier versions + cursorSize *= devicePixelRatio; + + if (auto *theme = mCursorThemesBySize.value(cursorSize, nullptr)) + return theme; + + struct ::wl_cursor_theme *theme = wl_cursor_theme_load(themeName, cursorSize, shm()->object()); + + if (!theme) + qCWarning(lcQpaWayland) << "Could not load cursor theme" << themeName; + + mCursorThemesBySize[cursorSize] = theme; + return theme; +} + #endif // QT_CONFIG(cursor) } diff --git a/src/client/qwaylanddisplay_p.h b/src/client/qwaylanddisplay_p.h index d39e561f6..521119fe8 100644 --- a/src/client/qwaylanddisplay_p.h +++ b/src/client/qwaylanddisplay_p.h @@ -66,6 +66,7 @@ #include struct wl_cursor_image; +struct wl_cursor_theme; QT_BEGIN_NAMESPACE @@ -123,6 +124,7 @@ public: #if QT_CONFIG(cursor) void setCursor(struct wl_buffer *buffer, struct wl_cursor_image *image, qreal dpr); void setCursor(const QSharedPointer &buffer, const QPoint &hotSpot, qreal dpr); + struct ::wl_cursor_theme *loadCursorTheme(qreal devicePixelRatio); #endif struct wl_display *wl_display() const { return mDisplay; } struct ::wl_registry *wl_registry() { return object(); } @@ -199,6 +201,9 @@ private: QList mInputDevices; QList mRegistryListeners; QWaylandIntegration *mWaylandIntegration = nullptr; +#if QT_CONFIG(cursor) + QMap mCursorThemesBySize; +#endif #if QT_CONFIG(wayland_datadevice) QScopedPointer mDndSelectionHandler; #endif -- cgit v1.2.3