From 45ec1362f8fcb5ade92f4d2d4985b1c24e78c8ba Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Mon, 20 Feb 2023 14:02:23 +0100 Subject: Convert cursor bitmap to supported format The 1-bit image formats QImage::Format_Mono and QImage::Format_MonoLSB used by cursor bitmaps don't have a corresponding wl_shm_format. Therefore, convert to a supported image format as necessary to make such bitmap cursors work on Wayland as well. Fixes: QTBUG-95434 Change-Id: I402fd870b301ddc01075251b66f2cf7cc1923133 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/client/qwaylandcursor.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/client/qwaylandcursor.cpp b/src/client/qwaylandcursor.cpp index 67a846df..ec17ed21 100644 --- a/src/client/qwaylandcursor.cpp +++ b/src/client/qwaylandcursor.cpp @@ -214,7 +214,21 @@ QWaylandCursor::QWaylandCursor(QWaylandDisplay *display) QSharedPointer QWaylandCursor::cursorBitmapBuffer(QWaylandDisplay *display, const QCursor *cursor) { Q_ASSERT(cursor->shape() == Qt::BitmapCursor); - const QImage &img = cursor->pixmap().toImage(); + QImage img = !cursor->pixmap().isNull() ? cursor->pixmap().toImage() : cursor->bitmap().toImage(); + + // convert to supported format if necessary + if (!display->shm()->formatSupported(img.format())) { + if (cursor->mask().isNull()) { + img.convertTo(QImage::Format_RGB32); + } else { + // preserve mask + img.convertTo(QImage::Format_ARGB32); + QPixmap pixmap = QPixmap::fromImage(img); + pixmap.setMask(cursor->mask()); + img = pixmap.toImage(); + } + } + QSharedPointer buffer(new QWaylandShmBuffer(display, img.size(), img.format())); memcpy(buffer->image()->bits(), img.bits(), size_t(img.sizeInBytes())); return buffer; -- cgit v1.2.1