screen-cast-src: Add helper to draw cursor sprite into pixel buffer

It makes sure the cursor sprite is correctly scaled and positioned in
stream coordinate space.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/413
This commit is contained in:
Jonas Ådahl 2019-01-24 18:40:06 +01:00
parent 2f01418d45
commit 8c2b805d88
2 changed files with 52 additions and 23 deletions

View File

@ -222,6 +222,43 @@ draw_cursor_sprite_via_offscreen (MetaScreenCastStreamSrc *src,
return TRUE;
}
gboolean
meta_screen_cast_stream_src_draw_cursor_into (MetaScreenCastStreamSrc *src,
CoglTexture *cursor_texture,
float scale,
uint8_t *data,
GError **error)
{
int texture_width, texture_height;
int width, height;
texture_width = cogl_texture_get_width (cursor_texture);
texture_height = cogl_texture_get_height (cursor_texture);
width = texture_width * scale;
height = texture_height * scale;
if (texture_width == width &&
texture_height == height)
{
cogl_texture_get_data (cursor_texture,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
texture_width * 4,
data);
}
else
{
if (!draw_cursor_sprite_via_offscreen (src,
cursor_texture,
width,
height,
data,
error))
return FALSE;
}
return TRUE;
}
void
meta_screen_cast_stream_src_unset_cursor_metadata (MetaScreenCastStreamSrc *src,
struct spa_meta_cursor *spa_meta_cursor)
@ -289,6 +326,7 @@ meta_screen_cast_stream_src_set_cursor_sprite_metadata (MetaScreenCastStreamSrc
int texture_width, texture_height;
int bitmap_width, bitmap_height;
uint8_t *bitmap_data;
GError *error = NULL;
cursor_texture = meta_cursor_sprite_get_cogl_texture (cursor_sprite);
if (!cursor_texture)
@ -328,32 +366,17 @@ meta_screen_cast_stream_src_set_cursor_sprite_metadata (MetaScreenCastStreamSrc
spa_meta_bitmap->offset,
uint8_t);
if (texture_width == bitmap_width &&
texture_height == bitmap_height)
{
cogl_texture_get_data (cursor_texture,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
texture_width * 4,
bitmap_data);
}
else
{
GError *error = NULL;
if (!draw_cursor_sprite_via_offscreen (src,
if (!meta_screen_cast_stream_src_draw_cursor_into (src,
cursor_texture,
bitmap_width,
bitmap_height,
scale,
bitmap_data,
&error))
{
g_warning ("Failed to draw cursor via offscreen: %s",
error->message);
g_warning ("Failed to draw cursor: %s", error->message);
g_error_free (error);
spa_meta_cursor->id = 0;
}
}
}
static void
add_cursor_metadata (MetaScreenCastStreamSrc *src,

View File

@ -65,6 +65,12 @@ void meta_screen_cast_stream_src_maybe_record_frame (MetaScreenCastStreamSrc *sr
MetaScreenCastStream * meta_screen_cast_stream_src_get_stream (MetaScreenCastStreamSrc *src);
gboolean meta_screen_cast_stream_src_draw_cursor_into (MetaScreenCastStreamSrc *src,
CoglTexture *cursor_texture,
float scale,
uint8_t *data,
GError **error);
void meta_screen_cast_stream_src_unset_cursor_metadata (MetaScreenCastStreamSrc *src,
struct spa_meta_cursor *spa_meta_cursor);