From f26c6ad5be1e7adbfe347d4f9e1510392475a5b8 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 22 Mar 2022 10:07:12 +0200 Subject: [PATCH] plugins/screencast: Fix a glitch in cursor bitmap In 52bc46069e6a96c03166c961266cbf2c86b3a92c, some code was shuffled around to improve code readability. However, it was overlooked that spa_meta_bitmap->offset is initialized too late, after QImage dest is constructed. That's the reason why the left edge of the cursor is wrapped around horizontally. This change fixes the cursor glitch by ensuring that spa_meta_bitmap->offset is initialized to proper value before getting pointer to bitmap data. While on this, this change also moves spa_meta_bitmap initialization code around to make spa_meta_bitmap setup look less like a bowl of spaghetti, i.e. spa_meta_bitmap is initialized first, and QImage dest is created with spa_meta_bitmap's values. --- src/plugins/screencast/screencaststream.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/plugins/screencast/screencaststream.cpp b/src/plugins/screencast/screencaststream.cpp index aae80c24bc..e90103cad1 100644 --- a/src/plugins/screencast/screencaststream.cpp +++ b/src/plugins/screencast/screencaststream.cpp @@ -641,9 +641,18 @@ void ScreenCastStream::sendCursorData(Cursor *cursor, spa_meta_cursor *spa_meta_ struct spa_meta_bitmap *spa_meta_bitmap = SPA_MEMBER (spa_meta_cursor, spa_meta_cursor->bitmap_offset, struct spa_meta_bitmap); + spa_meta_bitmap->format = SPA_VIDEO_FORMAT_RGBA; + spa_meta_bitmap->offset = sizeof(struct spa_meta_bitmap); + spa_meta_bitmap->size.width = std::min(m_cursor.bitmapSize.width(), image.width()); + spa_meta_bitmap->size.height = std::min(m_cursor.bitmapSize.height(), image.height()); + spa_meta_bitmap->stride = spa_meta_bitmap->size.width * 4; uint8_t *bitmap_data = SPA_MEMBER (spa_meta_bitmap, spa_meta_bitmap->offset, uint8_t); - QImage dest(bitmap_data, std::min(m_cursor.bitmapSize.width(), image.width()), std::min(m_cursor.bitmapSize.height(), image.height()), QImage::Format_RGBA8888_Premultiplied); + QImage dest(bitmap_data, + spa_meta_bitmap->size.width, + spa_meta_bitmap->size.height, + spa_meta_bitmap->stride, + QImage::Format_RGBA8888_Premultiplied); dest.setDevicePixelRatio(m_cursor.scale); dest.fill(Qt::transparent); @@ -651,12 +660,6 @@ void ScreenCastStream::sendCursorData(Cursor *cursor, spa_meta_cursor *spa_meta_ QPainter painter(&dest); painter.drawImage(QPoint(), image); } - - spa_meta_bitmap->format = SPA_VIDEO_FORMAT_RGBA; - spa_meta_bitmap->offset = sizeof (struct spa_meta_bitmap); - spa_meta_bitmap->size.width = dest.width(); - spa_meta_bitmap->size.height = dest.height(); - spa_meta_bitmap->stride = dest.bytesPerLine(); } void ScreenCastStream::setCursorMode(KWaylandServer::ScreencastV1Interface::CursorMode mode, qreal scale, const QRect &viewport)