mirror of
https://github.com/brl/mutter.git
synced 2024-11-22 08:00:42 -05:00
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:
parent
2f01418d45
commit
8c2b805d88
@ -222,6 +222,43 @@ draw_cursor_sprite_via_offscreen (MetaScreenCastStreamSrc *src,
|
|||||||
return TRUE;
|
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
|
void
|
||||||
meta_screen_cast_stream_src_unset_cursor_metadata (MetaScreenCastStreamSrc *src,
|
meta_screen_cast_stream_src_unset_cursor_metadata (MetaScreenCastStreamSrc *src,
|
||||||
struct spa_meta_cursor *spa_meta_cursor)
|
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 texture_width, texture_height;
|
||||||
int bitmap_width, bitmap_height;
|
int bitmap_width, bitmap_height;
|
||||||
uint8_t *bitmap_data;
|
uint8_t *bitmap_data;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
cursor_texture = meta_cursor_sprite_get_cogl_texture (cursor_sprite);
|
cursor_texture = meta_cursor_sprite_get_cogl_texture (cursor_sprite);
|
||||||
if (!cursor_texture)
|
if (!cursor_texture)
|
||||||
@ -328,32 +366,17 @@ meta_screen_cast_stream_src_set_cursor_sprite_metadata (MetaScreenCastStreamSrc
|
|||||||
spa_meta_bitmap->offset,
|
spa_meta_bitmap->offset,
|
||||||
uint8_t);
|
uint8_t);
|
||||||
|
|
||||||
if (texture_width == bitmap_width &&
|
if (!meta_screen_cast_stream_src_draw_cursor_into (src,
|
||||||
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,
|
|
||||||
cursor_texture,
|
cursor_texture,
|
||||||
bitmap_width,
|
scale,
|
||||||
bitmap_height,
|
|
||||||
bitmap_data,
|
bitmap_data,
|
||||||
&error))
|
&error))
|
||||||
{
|
{
|
||||||
g_warning ("Failed to draw cursor via offscreen: %s",
|
g_warning ("Failed to draw cursor: %s", error->message);
|
||||||
error->message);
|
|
||||||
g_error_free (error);
|
g_error_free (error);
|
||||||
spa_meta_cursor->id = 0;
|
spa_meta_cursor->id = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
add_cursor_metadata (MetaScreenCastStreamSrc *src,
|
add_cursor_metadata (MetaScreenCastStreamSrc *src,
|
||||||
|
@ -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);
|
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,
|
void meta_screen_cast_stream_src_unset_cursor_metadata (MetaScreenCastStreamSrc *src,
|
||||||
struct spa_meta_cursor *spa_meta_cursor);
|
struct spa_meta_cursor *spa_meta_cursor);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user