kms: Support non-64x64 cursors

Task-number: QTBUG-41477
Change-Id: I10a519d8560c909e87ba2f673d2da4106ce93b71
Reviewed-by: Louai Al-Khanji <louai.al-khanji@digia.com>
Reviewed-by: Jørgen Lind <jorgen.lind@digia.com>
This commit is contained in:
Laszlo Agocs 2014-09-26 12:22:09 +02:00
parent 4b128309a3
commit 3a2fdc48ad
2 changed files with 25 additions and 8 deletions

View File

@ -37,14 +37,29 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
#ifndef DRM_CAP_CURSOR_WIDTH
#define DRM_CAP_CURSOR_WIDTH 0x8
#endif
#ifndef DRM_CAP_CURSOR_HEIGHT
#define DRM_CAP_CURSOR_HEIGHT 0x9
#endif
QKmsCursor::QKmsCursor(QKmsScreen *screen) QKmsCursor::QKmsCursor(QKmsScreen *screen)
: m_screen(screen), : m_screen(screen),
m_graphicsBufferManager(screen->device()->gbmDevice()), m_graphicsBufferManager(screen->device()->gbmDevice()),
m_cursorBufferObject(gbm_bo_create(m_graphicsBufferManager, 64, 64, GBM_FORMAT_ARGB8888,
GBM_BO_USE_CURSOR_64X64|GBM_BO_USE_WRITE)),
m_cursorImage(new QPlatformCursorImage(0, 0, 0, 0, 0, 0)), m_cursorImage(new QPlatformCursorImage(0, 0, 0, 0, 0, 0)),
m_moved(false) m_moved(false),
m_cursorSize(64, 64)
{ {
uint64_t value = 0;
if (!drmGetCap(m_screen->device()->fd(), DRM_CAP_CURSOR_WIDTH, &value))
m_cursorSize.setWidth(value);
if (!drmGetCap(m_screen->device()->fd(), DRM_CAP_CURSOR_HEIGHT, &value))
m_cursorSize.setHeight(value);
m_cursorBufferObject = gbm_bo_create(m_graphicsBufferManager, m_cursorSize.width(), m_cursorSize.height(),
GBM_FORMAT_ARGB8888, GBM_BO_USE_CURSOR_64X64 | GBM_BO_USE_WRITE);
} }
QKmsCursor::~QKmsCursor() QKmsCursor::~QKmsCursor()
@ -81,16 +96,17 @@ void QKmsCursor::changeCursor(QCursor *windowCursor, QWindow *window)
windowCursor->hotSpot().y()); windowCursor->hotSpot().y());
} }
if ((m_cursorImage->image()->width() > 64) || (m_cursorImage->image()->width() > 64)) if (m_cursorImage->image()->width() > m_cursorSize.width() || m_cursorImage->image()->width() > m_cursorSize.height())
qWarning("Warning: cursor larger than 64x64; only 64x64 pixels will be shown."); qWarning("cursor larger than %dx%d, cursor truncated", m_cursorSize.width(), m_cursorSize.height());
QImage cursorImage = m_cursorImage->image()-> QImage cursorImage = m_cursorImage->image()->convertToFormat(QImage::Format_ARGB32)
convertToFormat(QImage::Format_ARGB32).copy(0, 0, 64, 64); .copy(0, 0, m_cursorSize.width(), m_cursorSize.height());
gbm_bo_write(m_cursorBufferObject, cursorImage.constBits(), cursorImage.byteCount()); gbm_bo_write(m_cursorBufferObject, cursorImage.constBits(), cursorImage.byteCount());
quint32 handle = gbm_bo_get_handle(m_cursorBufferObject).u32; quint32 handle = gbm_bo_get_handle(m_cursorBufferObject).u32;
int status = drmModeSetCursor(m_screen->device()->fd(), int status = drmModeSetCursor(m_screen->device()->fd(),
m_screen->crtcId(), handle, 64, 64); m_screen->crtcId(), handle,
m_cursorSize.width(), m_cursorSize.height());
if (status) { if (status) {
qWarning("failed to set cursor: %d", status); qWarning("failed to set cursor: %d", status);

View File

@ -58,6 +58,7 @@ private:
gbm_bo *m_cursorBufferObject; gbm_bo *m_cursorBufferObject;
QPlatformCursorImage *m_cursorImage; QPlatformCursorImage *m_cursorImage;
bool m_moved; bool m_moved;
QSize m_cursorSize;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE