From 96eb21da3597c3be76502108e229a24b9c232973 Mon Sep 17 00:00:00 2001 From: Jan Grulich Date: Wed, 5 Jan 2022 11:39:29 +0100 Subject: [PATCH] PipeWire fb: process cursor metadata even for empty buffer It is possible to have zero data in the buffer, but have the buffer to carry metadata about the mouse cursor. In that case we should try to process the cursor metadata before we discard the buffer for not having any data. --- framebuffers/pipewire/pw_framebuffer.cpp | 46 ++++++++++++------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/framebuffers/pipewire/pw_framebuffer.cpp b/framebuffers/pipewire/pw_framebuffer.cpp index 2b93d52d..9e2ffa4b 100644 --- a/framebuffers/pipewire/pw_framebuffer.cpp +++ b/framebuffers/pipewire/pw_framebuffer.cpp @@ -676,8 +676,30 @@ void PWFrameBuffer::Private::handleFrame(pw_buffer *pwBuffer) auto spaBuffer = pwBuffer->buffer; uint8_t *src = nullptr; + // process cursor + { + struct spa_meta_cursor *cursor = static_cast(spa_buffer_find_meta_data (spaBuffer, SPA_META_Cursor, sizeof (*cursor))); + if (spa_meta_cursor_is_valid (cursor)) { + struct spa_meta_bitmap *bitmap = nullptr; + + if (cursor->bitmap_offset) + bitmap = SPA_MEMBER (cursor, cursor->bitmap_offset, struct spa_meta_bitmap); + + if (bitmap && bitmap->size.width > 0 && bitmap->size.height > 0) { + const uint8_t *bitmap_data; + + bitmap_data = SPA_MEMBER (bitmap, bitmap->offset, uint8_t); + cursorHotspot = { cursor->hotspot.x, cursor->hotspot.y }; + cursorTexture = QImage(bitmap_data, bitmap->size.width, bitmap->size.height, bitmap->stride, spaToQImageFormat(bitmap->format)); + } + + cursorPosition = QPoint{ cursor->position.x, cursor->position.y }; + } + } + if (spaBuffer->datas[0].chunk->size == 0) { - qCDebug(KRFB_FB_PIPEWIRE) << "discarding null buffer"; + qCDebug(KRFB_FB_PIPEWIRE) << "Got empty buffer. The buffer possibly carried only " + "information about the mouse cursor."; return; } @@ -780,28 +802,6 @@ void PWFrameBuffer::Private::handleFrame(pw_buffer *pwBuffer) } #endif /* HAVE_DMA_BUF */ - - // process cursor - { - struct spa_meta_cursor *cursor = static_cast(spa_buffer_find_meta_data (spaBuffer, SPA_META_Cursor, sizeof (*cursor))); - if (spa_meta_cursor_is_valid (cursor)) { - struct spa_meta_bitmap *bitmap = nullptr; - - if (cursor->bitmap_offset) - bitmap = SPA_MEMBER (cursor, cursor->bitmap_offset, struct spa_meta_bitmap); - - if (bitmap && bitmap->size.width > 0 && bitmap->size.height > 0) { - const uint8_t *bitmap_data; - - bitmap_data = SPA_MEMBER (bitmap, bitmap->offset, uint8_t); - cursorHotspot = { cursor->hotspot.x, cursor->hotspot.y }; - cursorTexture = QImage(bitmap_data, bitmap->size.width, bitmap->size.height, bitmap->stride, spaToQImageFormat(bitmap->format)); - } - - cursorPosition = QPoint{ cursor->position.x, cursor->position.y }; - } - } - struct spa_meta_region* videoMetadata = static_cast(spa_buffer_find_meta_data( spaBuffer, SPA_META_VideoCrop, sizeof(*videoMetadata)));