summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/xcb/qxcbcursor.cpp
diff options
context:
space:
mode:
authorGatis Paeglis <gatis.paeglis@qt.io>2018-03-23 14:24:23 +0100
committerGatis Paeglis <gatis.paeglis@qt.io>2018-04-14 17:03:01 +0000
commit7286d9d8dd1f8543007218a91d5c6767a7a7b152 (patch)
treeb08eb56bb766044ddee999469a66a774dfaa132b /src/plugins/platforms/xcb/qxcbcursor.cpp
parentcba414a26b58b867d0c46ac214606e29e4bbdd94 (diff)
xcb: fix bitmap cursor loading performance regression
... introduced by 422838685c31d9b57133a8711bfd5db92095d96d. Instead of completely droping caching for bitmap cursors we can do the same what is done in libXcursor - have a fixed size cache, with oldest entries eventually being replaced with new bitmaps. This fixes the original issue, where the hash was growing indefinitely until running out of file descriptors and won't have the performance penalty as in 422838685c31d9b57133a8711bfd5db92095d96d. Task-number: QTBUG-66897 Change-Id: I14f80b46f97fd0e2c920e17a31ffbc0441cd9d22 Reviewed-by: Uli Schlachter <psychon@znc.in> Reviewed-by: Robin Burchell <robin.burchell@crimson.no> Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'src/plugins/platforms/xcb/qxcbcursor.cpp')
-rw-r--r--src/plugins/platforms/xcb/qxcbcursor.cpp42
1 files changed, 23 insertions, 19 deletions
diff --git a/src/plugins/platforms/xcb/qxcbcursor.cpp b/src/plugins/platforms/xcb/qxcbcursor.cpp
index 34b7d0d236..70138abede 100644
--- a/src/plugins/platforms/xcb/qxcbcursor.cpp
+++ b/src/plugins/platforms/xcb/qxcbcursor.cpp
@@ -301,6 +301,9 @@ QXcbCursorCacheKey::QXcbCursorCacheKey(const QCursor &c)
QXcbCursor::QXcbCursor(QXcbConnection *conn, QXcbScreen *screen)
: QXcbObject(conn), m_screen(screen), m_gtkCursorThemeInitialized(false)
{
+ // see NUM_BITMAPS in libXcursor/src/xcursorint.h
+ m_bitmapCache.setMaxCost(8);
+
if (cursorCount++)
return;
@@ -351,37 +354,38 @@ QXcbCursor::~QXcbCursor()
}
#ifndef QT_NO_CURSOR
-void QXcbCursor::changeCursor(QCursor *cursor, QWindow *widget)
+void QXcbCursor::changeCursor(QCursor *cursor, QWindow *window)
{
- QXcbWindow *w = 0;
- if (widget && widget->handle())
- w = static_cast<QXcbWindow *>(widget->handle());
- else
- // No X11 cursor control when there is no widget under the cursor
+ if (!window || !window->handle())
return;
xcb_cursor_t c = XCB_CURSOR_NONE;
- bool isBitmapCursor = false;
-
if (cursor) {
+ const QXcbCursorCacheKey key(*cursor);
const Qt::CursorShape shape = cursor->shape();
- isBitmapCursor = shape == Qt::BitmapCursor;
- if (!isBitmapCursor) {
- const QXcbCursorCacheKey key(*cursor);
- CursorHash::iterator it = m_cursorHash.find(key);
- if (it == m_cursorHash.end()) {
- it = m_cursorHash.insert(key, createFontCursor(shape));
+ if (shape == Qt::BitmapCursor) {
+ auto *bitmap = m_bitmapCache.object(key);
+ if (bitmap) {
+ c = bitmap->cursor;
+ } else {
+ c = createBitmapCursor(cursor);
+ m_bitmapCache.insert(key, new CachedCursor(xcb_connection(), c));
}
- c = it.value();
} else {
- // Do not cache bitmap cursors, as otherwise they have unclear
- // lifetime (we effectively leak xcb_cursor_t).
- c = createBitmapCursor(cursor);
+ auto it = m_cursorHash.find(key);
+ if (it == m_cursorHash.end()) {
+ c = createFontCursor(shape);
+ m_cursorHash.insert(key, c);
+ } else {
+ c = it.value();
+ }
}
}
- w->setCursor(c, isBitmapCursor);
+ auto *w = static_cast<QXcbWindow *>(window->handle());
+ xcb_change_window_attributes(xcb_connection(), w->xcb_window(), XCB_CW_CURSOR, &c);
+ xcb_flush(xcb_connection());
}
static int cursorIdForShape(int cshape)