screencast: Implement buffer-transform support

So all cursor renderers support the feature.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/344>
This commit is contained in:
Robert Mader 2022-07-02 18:50:45 +02:00
parent f804fe3a82
commit 22b9a4219a
9 changed files with 60 additions and 6 deletions

View File

@ -592,13 +592,17 @@ meta_screen_cast_area_stream_src_set_cursor_metadata (MetaScreenCastStreamSrc *s
{ {
float cursor_scale; float cursor_scale;
float metadata_scale; float metadata_scale;
MetaMonitorTransform transform;
cursor_scale = meta_cursor_sprite_get_texture_scale (cursor_sprite); cursor_scale = meta_cursor_sprite_get_texture_scale (cursor_sprite);
metadata_scale = scale * cursor_scale; metadata_scale = scale * cursor_scale;
transform = meta_cursor_sprite_get_texture_transform (cursor_sprite);
meta_screen_cast_stream_src_set_cursor_sprite_metadata (src, meta_screen_cast_stream_src_set_cursor_sprite_metadata (src,
spa_meta_cursor, spa_meta_cursor,
cursor_sprite, cursor_sprite,
x, y, x, y,
transform,
metadata_scale); metadata_scale);
} }
else else

View File

@ -687,14 +687,18 @@ meta_screen_cast_monitor_stream_src_set_cursor_metadata (MetaScreenCastStreamSrc
{ {
float cursor_scale; float cursor_scale;
float scale; float scale;
MetaMonitorTransform transform;
cursor_scale = meta_cursor_sprite_get_texture_scale (cursor_sprite); cursor_scale = meta_cursor_sprite_get_texture_scale (cursor_sprite);
scale = view_scale * cursor_scale; scale = view_scale * cursor_scale;
transform = meta_cursor_sprite_get_texture_transform (cursor_sprite);
meta_screen_cast_stream_src_set_cursor_sprite_metadata (src, meta_screen_cast_stream_src_set_cursor_sprite_metadata (src,
spa_meta_cursor, spa_meta_cursor,
cursor_sprite, cursor_sprite,
x, y, x, y,
scale); scale,
transform);
} }
else else
{ {

View File

@ -249,6 +249,7 @@ draw_cursor_sprite_via_offscreen (MetaScreenCastStreamSrc *src,
CoglTexture *cursor_texture, CoglTexture *cursor_texture,
int bitmap_width, int bitmap_width,
int bitmap_height, int bitmap_height,
MetaMonitorTransform transform,
uint8_t *bitmap_data, uint8_t *bitmap_data,
GError **error) GError **error)
{ {
@ -265,6 +266,7 @@ draw_cursor_sprite_via_offscreen (MetaScreenCastStreamSrc *src,
CoglFramebuffer *fb; CoglFramebuffer *fb;
CoglPipeline *pipeline; CoglPipeline *pipeline;
CoglColor clear_color; CoglColor clear_color;
graphene_matrix_t matrix;
bitmap_texture = cogl_texture_2d_new_with_size (cogl_context, bitmap_texture = cogl_texture_2d_new_with_size (cogl_context,
bitmap_width, bitmap_height); bitmap_width, bitmap_height);
@ -290,6 +292,12 @@ draw_cursor_sprite_via_offscreen (MetaScreenCastStreamSrc *src,
cogl_pipeline_set_layer_filters (pipeline, 0, cogl_pipeline_set_layer_filters (pipeline, 0,
COGL_PIPELINE_FILTER_LINEAR, COGL_PIPELINE_FILTER_LINEAR,
COGL_PIPELINE_FILTER_LINEAR); COGL_PIPELINE_FILTER_LINEAR);
graphene_matrix_init_identity (&matrix);
meta_monitor_transform_transform_matrix (transform,
&matrix);
cogl_pipeline_set_layer_matrix (pipeline, 0, &matrix);
cogl_color_init_from_4ub (&clear_color, 0, 0, 0, 0); cogl_color_init_from_4ub (&clear_color, 0, 0, 0, 0);
cogl_framebuffer_clear (fb, COGL_BUFFER_BIT_COLOR, &clear_color); cogl_framebuffer_clear (fb, COGL_BUFFER_BIT_COLOR, &clear_color);
cogl_framebuffer_draw_rectangle (fb, pipeline, cogl_framebuffer_draw_rectangle (fb, pipeline,
@ -310,6 +318,7 @@ gboolean
meta_screen_cast_stream_src_draw_cursor_into (MetaScreenCastStreamSrc *src, meta_screen_cast_stream_src_draw_cursor_into (MetaScreenCastStreamSrc *src,
CoglTexture *cursor_texture, CoglTexture *cursor_texture,
float scale, float scale,
MetaMonitorTransform transform,
uint8_t *data, uint8_t *data,
GError **error) GError **error)
{ {
@ -322,7 +331,8 @@ meta_screen_cast_stream_src_draw_cursor_into (MetaScreenCastStreamSrc *src,
height = texture_height * scale; height = texture_height * scale;
if (texture_width == width && if (texture_width == width &&
texture_height == height) texture_height == height &&
transform == META_MONITOR_TRANSFORM_NORMAL)
{ {
cogl_texture_get_data (cursor_texture, cogl_texture_get_data (cursor_texture,
COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_PIXEL_FORMAT_RGBA_8888_PRE,
@ -335,6 +345,7 @@ meta_screen_cast_stream_src_draw_cursor_into (MetaScreenCastStreamSrc *src,
cursor_texture, cursor_texture,
width, width,
height, height,
transform,
data, data,
error)) error))
return FALSE; return FALSE;
@ -396,7 +407,8 @@ meta_screen_cast_stream_src_set_cursor_sprite_metadata (MetaScreenCastStreamSrc
MetaCursorSprite *cursor_sprite, MetaCursorSprite *cursor_sprite,
int x, int x,
int y, int y,
float scale) float scale,
MetaMonitorTransform transform)
{ {
CoglTexture *cursor_texture; CoglTexture *cursor_texture;
struct spa_meta_bitmap *spa_meta_bitmap; struct spa_meta_bitmap *spa_meta_bitmap;
@ -447,6 +459,7 @@ meta_screen_cast_stream_src_set_cursor_sprite_metadata (MetaScreenCastStreamSrc
if (!meta_screen_cast_stream_src_draw_cursor_into (src, if (!meta_screen_cast_stream_src_draw_cursor_into (src,
cursor_texture, cursor_texture,
scale, scale,
transform,
bitmap_data, bitmap_data,
&error)) &error))
{ {

View File

@ -94,6 +94,7 @@ MetaScreenCastStream * meta_screen_cast_stream_src_get_stream (MetaScreenCastStr
gboolean meta_screen_cast_stream_src_draw_cursor_into (MetaScreenCastStreamSrc *src, gboolean meta_screen_cast_stream_src_draw_cursor_into (MetaScreenCastStreamSrc *src,
CoglTexture *cursor_texture, CoglTexture *cursor_texture,
float scale, float scale,
MetaMonitorTransform transform,
uint8_t *data, uint8_t *data,
GError **error); GError **error);
@ -115,6 +116,7 @@ void meta_screen_cast_stream_src_set_cursor_sprite_metadata (MetaScreenCastStrea
MetaCursorSprite *cursor_sprite, MetaCursorSprite *cursor_sprite,
int x, int x,
int y, int y,
float scale); float scale,
MetaMonitorTransform transform);
#endif /* META_SCREEN_CAST_STREAM_SRC_H */ #endif /* META_SCREEN_CAST_STREAM_SRC_H */

View File

@ -471,14 +471,18 @@ meta_screen_cast_virtual_stream_src_set_cursor_metadata (MetaScreenCastStreamSrc
{ {
float cursor_scale; float cursor_scale;
float scale; float scale;
MetaMonitorTransform transform;
cursor_scale = meta_cursor_sprite_get_texture_scale (cursor_sprite); cursor_scale = meta_cursor_sprite_get_texture_scale (cursor_sprite);
scale = view_scale * cursor_scale; scale = view_scale * cursor_scale;
transform = meta_cursor_sprite_get_texture_transform (cursor_sprite);
meta_screen_cast_stream_src_set_cursor_sprite_metadata (src, meta_screen_cast_stream_src_set_cursor_sprite_metadata (src,
spa_meta_cursor, spa_meta_cursor,
cursor_sprite, cursor_sprite,
x, y, x, y,
scale); scale,
transform);
} }
else else
{ {

View File

@ -130,6 +130,7 @@ maybe_draw_cursor_sprite (MetaScreenCastWindowStreamSrc *window_src,
cairo_surface_t *stream_surface; cairo_surface_t *stream_surface;
int width, height; int width, height;
float scale; float scale;
MetaMonitorTransform transform;
int hotspot_x, hotspot_y; int hotspot_x, hotspot_y;
cairo_t *cr; cairo_t *cr;
@ -147,6 +148,7 @@ maybe_draw_cursor_sprite (MetaScreenCastWindowStreamSrc *window_src,
cursor_sprite, cursor_sprite,
&cursor_position, &cursor_position,
&scale, &scale,
&transform,
&relative_cursor_position)) &relative_cursor_position))
return; return;
@ -161,6 +163,7 @@ maybe_draw_cursor_sprite (MetaScreenCastWindowStreamSrc *window_src,
if (!meta_screen_cast_stream_src_draw_cursor_into (src, if (!meta_screen_cast_stream_src_draw_cursor_into (src,
cursor_texture, cursor_texture,
scale, scale,
transform,
cursor_surface_data, cursor_surface_data,
&error)) &error))
{ {
@ -208,8 +211,10 @@ maybe_blit_cursor_sprite (MetaScreenCastWindowStreamSrc *window_src,
CoglPipeline *pipeline; CoglPipeline *pipeline;
int width, height; int width, height;
float scale; float scale;
MetaMonitorTransform transform;
int hotspot_x, hotspot_y; int hotspot_x, hotspot_y;
float x, y; float x, y;
graphene_matrix_t matrix;
cursor_sprite = meta_cursor_renderer_get_cursor (cursor_renderer); cursor_sprite = meta_cursor_renderer_get_cursor (cursor_renderer);
if (!cursor_sprite) if (!cursor_sprite)
@ -225,6 +230,7 @@ maybe_blit_cursor_sprite (MetaScreenCastWindowStreamSrc *window_src,
cursor_sprite, cursor_sprite,
&cursor_position, &cursor_position,
&scale, &scale,
&transform,
&relative_cursor_position)) &relative_cursor_position))
return; return;
@ -241,6 +247,11 @@ maybe_blit_cursor_sprite (MetaScreenCastWindowStreamSrc *window_src,
COGL_PIPELINE_FILTER_LINEAR, COGL_PIPELINE_FILTER_LINEAR,
COGL_PIPELINE_FILTER_LINEAR); COGL_PIPELINE_FILTER_LINEAR);
graphene_matrix_init_identity (&matrix);
meta_monitor_transform_transform_matrix (transform,
&matrix);
cogl_pipeline_set_layer_matrix (pipeline, 0, &matrix);
cogl_framebuffer_draw_rectangle (framebuffer, cogl_framebuffer_draw_rectangle (framebuffer,
pipeline, pipeline,
x, y, x, y,
@ -557,6 +568,7 @@ meta_screen_cast_window_stream_src_set_cursor_metadata (MetaScreenCastStreamSrc
MetaCursorSprite *cursor_sprite; MetaCursorSprite *cursor_sprite;
graphene_point_t cursor_position; graphene_point_t cursor_position;
float scale; float scale;
MetaMonitorTransform transform;
graphene_point_t relative_cursor_position; graphene_point_t relative_cursor_position;
int x, y; int x, y;
@ -568,6 +580,7 @@ meta_screen_cast_window_stream_src_set_cursor_metadata (MetaScreenCastStreamSrc
cursor_sprite, cursor_sprite,
&cursor_position, &cursor_position,
&scale, &scale,
&transform,
&relative_cursor_position)) &relative_cursor_position))
{ {
meta_screen_cast_stream_src_unset_cursor_metadata (src, meta_screen_cast_stream_src_unset_cursor_metadata (src,
@ -586,7 +599,8 @@ meta_screen_cast_window_stream_src_set_cursor_metadata (MetaScreenCastStreamSrc
spa_meta_cursor, spa_meta_cursor,
cursor_sprite, cursor_sprite,
x, y, x, y,
scale); scale,
transform);
} }
else else
{ {

View File

@ -56,6 +56,7 @@ meta_screen_cast_window_transform_cursor_position (MetaScreenCastWindow *screen_
MetaCursorSprite *cursor_sprite, MetaCursorSprite *cursor_sprite,
graphene_point_t *cursor_position, graphene_point_t *cursor_position,
float *out_cursor_scale, float *out_cursor_scale,
MetaMonitorTransform *out_cursor_transform,
graphene_point_t *out_relative_cursor_position) graphene_point_t *out_relative_cursor_position)
{ {
MetaScreenCastWindowInterface *iface = MetaScreenCastWindowInterface *iface =
@ -65,6 +66,7 @@ meta_screen_cast_window_transform_cursor_position (MetaScreenCastWindow *screen_
cursor_sprite, cursor_sprite,
cursor_position, cursor_position,
out_cursor_scale, out_cursor_scale,
out_cursor_transform,
out_relative_cursor_position); out_relative_cursor_position);
} }

View File

@ -50,6 +50,7 @@ struct _MetaScreenCastWindowInterface
MetaCursorSprite *cursor_sprite, MetaCursorSprite *cursor_sprite,
graphene_point_t *cursor_position, graphene_point_t *cursor_position,
float *out_cursor_scale, float *out_cursor_scale,
MetaMonitorTransform *out_cursor_transform,
graphene_point_t *out_relative_cursor_position); graphene_point_t *out_relative_cursor_position);
void (*capture_into) (MetaScreenCastWindow *screen_cast_window, void (*capture_into) (MetaScreenCastWindow *screen_cast_window,
@ -76,6 +77,7 @@ gboolean meta_screen_cast_window_transform_cursor_position (MetaScreenCastWindow
MetaCursorSprite *cursor_sprite, MetaCursorSprite *cursor_sprite,
graphene_point_t *cursor_position, graphene_point_t *cursor_position,
float *out_cursor_scale, float *out_cursor_scale,
MetaMonitorTransform *out_cursor_transform,
graphene_point_t *out_relative_cursor_position); graphene_point_t *out_relative_cursor_position);
void meta_screen_cast_window_capture_into (MetaScreenCastWindow *screen_cast_window, void meta_screen_cast_window_capture_into (MetaScreenCastWindow *screen_cast_window,

View File

@ -1241,6 +1241,7 @@ meta_window_actor_transform_cursor_position (MetaScreenCastWindow *screen_cast_w
MetaCursorSprite *cursor_sprite, MetaCursorSprite *cursor_sprite,
graphene_point_t *cursor_position, graphene_point_t *cursor_position,
float *out_cursor_scale, float *out_cursor_scale,
MetaMonitorTransform *out_cursor_transform,
graphene_point_t *out_relative_cursor_position) graphene_point_t *out_relative_cursor_position)
{ {
MetaWindowActor *window_actor = META_WINDOW_ACTOR (screen_cast_window); MetaWindowActor *window_actor = META_WINDOW_ACTOR (screen_cast_window);
@ -1267,6 +1268,14 @@ meta_window_actor_transform_cursor_position (MetaScreenCastWindow *screen_cast_w
*out_cursor_scale = texture_scale / cursor_texture_scale; *out_cursor_scale = texture_scale / cursor_texture_scale;
} }
if (cursor_sprite &&
meta_cursor_sprite_get_cogl_texture (cursor_sprite) &&
out_cursor_transform)
{
*out_cursor_transform =
meta_cursor_sprite_get_texture_transform (cursor_sprite);
}
if (out_relative_cursor_position) if (out_relative_cursor_position)
{ {
clutter_actor_transform_stage_point (CLUTTER_ACTOR (priv->surface), clutter_actor_transform_stage_point (CLUTTER_ACTOR (priv->surface),