Skip to content

Commit

Permalink
linux-pipewire: Clear cursor texture on empty bitmap
Browse files Browse the repository at this point in the history
If we receive an empty cursor bitmap - one without valid size - we
should hide the cursor. Do so by clearing the texture.

This fixes visible cursors when recording various games with Wayland
compositors.

Closes #4895
  • Loading branch information
rmader committed Mar 14, 2023
1 parent b31344d commit a0c59bb
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions plugins/linux-pipewire/pipewire.c
Original file line number Diff line number Diff line change
Expand Up @@ -719,27 +719,33 @@ static void on_process_cb(void *user_data)
bitmap = SPA_MEMBER(cursor, cursor->bitmap_offset,
struct spa_meta_bitmap);

if (bitmap && bitmap->size.width > 0 &&
bitmap->size.height > 0 &&
lookup_format_info_from_spa_format(
bitmap->format, NULL, &gs_format, &swap_red_blue)) {
const uint8_t *bitmap_data;

bitmap_data =
SPA_MEMBER(bitmap, bitmap->offset, uint8_t);
obs_pw->cursor.hotspot_x = cursor->hotspot.x;
obs_pw->cursor.hotspot_y = cursor->hotspot.y;
obs_pw->cursor.width = bitmap->size.width;
obs_pw->cursor.height = bitmap->size.height;

if (bitmap) {
g_clear_pointer(&obs_pw->cursor.texture,
gs_texture_destroy);
obs_pw->cursor.texture = gs_texture_create(
obs_pw->cursor.width, obs_pw->cursor.height,
gs_format, 1, &bitmap_data, GS_DYNAMIC);

if (swap_red_blue)
swap_texture_red_blue(obs_pw->cursor.texture);
if (bitmap->size.width > 0 && bitmap->size.height > 0 &&
lookup_format_info_from_spa_format(
bitmap->format, NULL, &gs_format,
&swap_red_blue)) {
const uint8_t *bitmap_data;

bitmap_data = SPA_MEMBER(bitmap, bitmap->offset,
uint8_t);
obs_pw->cursor.hotspot_x = cursor->hotspot.x;
obs_pw->cursor.hotspot_y = cursor->hotspot.y;
obs_pw->cursor.width = bitmap->size.width;
obs_pw->cursor.height = bitmap->size.height;

obs_pw->cursor.texture = gs_texture_create(
obs_pw->cursor.width,
obs_pw->cursor.height, gs_format, 1,
&bitmap_data, GS_DYNAMIC);

if (swap_red_blue) {
swap_texture_red_blue(
obs_pw->cursor.texture);
}
}
}

obs_pw->cursor.x = cursor->position.x;
Expand Down

0 comments on commit a0c59bb

Please sign in to comment.