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>
This commit is contained in:
Johan Klokkhammer Helsing 2018-05-15 09:58:18 +02:00 committed by Johan Helsing
parent f9da2c645c
commit 60146a92b8
4 changed files with 41 additions and 22 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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,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<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)
}

View File

@ -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