diff options
author | Johan Klokkhammer Helsing <johan.helsing@qt.io> | 2018-05-15 09:58:18 +0200 |
---|---|---|
committer | Johan Helsing <johan.helsing@qt.io> | 2018-05-28 09:10:31 +0000 |
commit | 633d4e6fd121fe128aec78bb9c137c4f2f82f1ce (patch) | |
tree | f5ac15b1f4de5357c2463cc660e9812f9ad15ca9 /src/client | |
parent | d579651f7ef737d480791a2680eb57aa0e29c260 (diff) |
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 <paul.tvete@qt.io>
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/qwaylandcursor.cpp | 22 | ||||
-rw-r--r-- | src/client/qwaylandcursor_p.h | 1 | ||||
-rw-r--r-- | src/client/qwaylanddisplay.cpp | 35 | ||||
-rw-r--r-- | src/client/qwaylanddisplay_p.h | 5 |
4 files changed, 41 insertions, 22 deletions
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 <wayland-cursor.h> +#endif #include "qwaylandhardwareintegration_p.h" #include "qwaylandinputcontext_p.h" @@ -151,9 +154,15 @@ 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<QWaylandBuffer> &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 <QtWaylandClient/private/qwaylandshm_p.h> 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<QWaylandBuffer> &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<QWaylandInputDevice *> mInputDevices; QList<Listener> mRegistryListeners; QWaylandIntegration *mWaylandIntegration = nullptr; +#if QT_CONFIG(cursor) + QMap<int, struct wl_cursor_theme*> mCursorThemesBySize; +#endif #if QT_CONFIG(wayland_datadevice) QScopedPointer<QWaylandDataDeviceManager> mDndSelectionHandler; #endif |