diff --git a/src/backends/meta-screen-cast-area-stream-src.c b/src/backends/meta-screen-cast-area-stream-src.c index 6927bc177..cdcbef0bd 100644 --- a/src/backends/meta-screen-cast-area-stream-src.c +++ b/src/backends/meta-screen-cast-area-stream-src.c @@ -667,22 +667,15 @@ meta_screen_cast_area_stream_src_set_cursor_metadata (MetaScreenCastStreamSrc *s { if (cursor_sprite) { - float scale; - float cursor_scale; - float metadata_scale; - MtkMonitorTransform transform; + float view_scale; - scale = meta_screen_cast_area_stream_get_scale (area_stream); - cursor_scale = meta_cursor_sprite_get_texture_scale (cursor_sprite); - metadata_scale = scale * cursor_scale; - transform = meta_cursor_sprite_get_texture_transform (cursor_sprite); + view_scale = meta_screen_cast_area_stream_get_scale (area_stream); meta_screen_cast_stream_src_set_cursor_sprite_metadata (src, spa_meta_cursor, cursor_sprite, x, y, - transform, - metadata_scale); + view_scale); } else { diff --git a/src/backends/meta-screen-cast-monitor-stream-src.c b/src/backends/meta-screen-cast-monitor-stream-src.c index 941117fc8..46e93eb8b 100644 --- a/src/backends/meta-screen-cast-monitor-stream-src.c +++ b/src/backends/meta-screen-cast-monitor-stream-src.c @@ -852,21 +852,14 @@ meta_screen_cast_monitor_stream_src_set_cursor_metadata (MetaScreenCastStreamSrc if (cursor_sprite) { float view_scale; - float cursor_scale; - float scale; - MtkMonitorTransform transform; view_scale = get_view_scale (monitor_src); - cursor_scale = meta_cursor_sprite_get_texture_scale (cursor_sprite); - scale = view_scale * cursor_scale; - transform = meta_cursor_sprite_get_texture_transform (cursor_sprite); meta_screen_cast_stream_src_set_cursor_sprite_metadata (src, spa_meta_cursor, cursor_sprite, x, y, - scale, - transform); + view_scale); } else { diff --git a/src/backends/meta-screen-cast-stream-src.c b/src/backends/meta-screen-cast-stream-src.c index d43192b23..ccc571f27 100644 --- a/src/backends/meta-screen-cast-stream-src.c +++ b/src/backends/meta-screen-cast-stream-src.c @@ -368,7 +368,7 @@ draw_cursor_sprite_via_offscreen (MetaScreenCastStreamSrc *src, CoglTexture *cursor_texture, int bitmap_width, int bitmap_height, - MtkMonitorTransform transform, + const graphene_matrix_t *matrix, uint8_t *bitmap_data, GError **error) { @@ -385,7 +385,6 @@ draw_cursor_sprite_via_offscreen (MetaScreenCastStreamSrc *src, CoglFramebuffer *fb; CoglPipeline *pipeline; CoglColor clear_color; - graphene_matrix_t matrix; bitmap_texture = cogl_texture_2d_new_with_size (cogl_context, bitmap_width, bitmap_height); @@ -411,10 +410,7 @@ draw_cursor_sprite_via_offscreen (MetaScreenCastStreamSrc *src, COGL_PIPELINE_FILTER_LINEAR, COGL_PIPELINE_FILTER_LINEAR); - graphene_matrix_init_identity (&matrix); - mtk_monitor_transform_transform_matrix (transform, - &matrix); - cogl_pipeline_set_layer_matrix (pipeline, 0, &matrix); + cogl_pipeline_set_layer_matrix (pipeline, 0, matrix); cogl_color_init_from_4f (&clear_color, 0.0, 0.0, 0.0, 0.0); cogl_framebuffer_clear (fb, COGL_BUFFER_BIT_COLOR, &clear_color); @@ -435,22 +431,20 @@ draw_cursor_sprite_via_offscreen (MetaScreenCastStreamSrc *src, gboolean meta_screen_cast_stream_src_draw_cursor_into (MetaScreenCastStreamSrc *src, CoglTexture *cursor_texture, - float scale, - MtkMonitorTransform transform, + int width, + int height, + const graphene_matrix_t *matrix, 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 = (int) ceilf (texture_width * scale); - height = (int) ceilf (texture_height * scale); if (texture_width == width && texture_height == height && - transform == MTK_MONITOR_TRANSFORM_NORMAL) + graphene_matrix_is_identity (matrix)) { cogl_texture_get_data (cursor_texture, COGL_PIXEL_FORMAT_RGBA_8888_PRE, @@ -463,7 +457,7 @@ meta_screen_cast_stream_src_draw_cursor_into (MetaScreenCastStreamSrc *src, cursor_texture, width, height, - transform, + matrix, data, error)) return FALSE; @@ -525,15 +519,19 @@ meta_screen_cast_stream_src_set_cursor_sprite_metadata (MetaScreenCastStreamSrc MetaCursorSprite *cursor_sprite, int x, int y, - float scale, - MtkMonitorTransform transform) + float view_scale) { CoglTexture *cursor_texture; struct spa_meta_bitmap *spa_meta_bitmap; int hotspot_x, hotspot_y; int texture_width, texture_height; int bitmap_width, bitmap_height; + int dst_width, dst_height; uint8_t *bitmap_data; + float cursor_scale; + MtkMonitorTransform cursor_transform; + const graphene_rect_t *src_rect; + graphene_matrix_t matrix; GError *error = NULL; cursor_texture = meta_cursor_sprite_get_cogl_texture (cursor_sprite); @@ -557,14 +555,72 @@ meta_screen_cast_stream_src_set_cursor_sprite_metadata (MetaScreenCastStreamSrc spa_meta_bitmap->format = SPA_VIDEO_FORMAT_RGBA; spa_meta_bitmap->offset = sizeof (struct spa_meta_bitmap); - meta_cursor_sprite_get_hotspot (cursor_sprite, &hotspot_x, &hotspot_y); - spa_meta_cursor->hotspot.x = (int32_t) roundf (hotspot_x * scale); - spa_meta_cursor->hotspot.y = (int32_t) roundf (hotspot_y * scale); - texture_width = cogl_texture_get_width (cursor_texture); texture_height = cogl_texture_get_height (cursor_texture); - bitmap_width = (int) ceilf (texture_width * scale); - bitmap_height = (int) ceilf (texture_height * scale); + + meta_cursor_sprite_get_hotspot (cursor_sprite, &hotspot_x, &hotspot_y); + cursor_scale = meta_cursor_sprite_get_texture_scale (cursor_sprite); + cursor_transform = meta_cursor_sprite_get_texture_transform (cursor_sprite); + src_rect = meta_cursor_sprite_get_viewport_src_rect (cursor_sprite); + + if (meta_cursor_sprite_get_viewport_dst_size (cursor_sprite, + &dst_width, + &dst_height)) + { + float cursor_scale_x, cursor_scale_y; + float scaled_hotspot_x, scaled_hotspot_y; + + cursor_scale_x = (float) dst_width / texture_width; + cursor_scale_y = (float) dst_height / texture_height; + + scaled_hotspot_x = roundf (hotspot_x * cursor_scale_x); + scaled_hotspot_y = roundf (hotspot_y * cursor_scale_y); + + bitmap_width = (int) ceilf (dst_width * view_scale); + bitmap_height = (int) ceilf (dst_height * view_scale); + spa_meta_cursor->hotspot.x = (int32_t) ceilf (scaled_hotspot_x * view_scale); + spa_meta_cursor->hotspot.y = (int32_t) ceilf (scaled_hotspot_y * view_scale); + } + else if (src_rect) + { + float scale_x, scale_y; + + scale_x = (float) src_rect->size.width / texture_width * view_scale; + scale_y = (float) src_rect->size.height / texture_height * view_scale; + + bitmap_width = (int) ceilf (src_rect->size.width * view_scale); + bitmap_height = (int) ceilf (src_rect->size.height * view_scale); + spa_meta_cursor->hotspot.x = (int32_t) roundf (hotspot_x * scale_x); + spa_meta_cursor->hotspot.y = (int32_t) roundf (hotspot_y * scale_y); + } + else + { + float scale; + + scale = cursor_scale * view_scale; + + if (mtk_monitor_transform_is_rotated (cursor_transform)) + { + bitmap_width = (int) ceilf (texture_height * scale); + bitmap_height = (int) ceilf (texture_width * scale); + } + else + { + bitmap_width = (int) ceilf (texture_width * scale); + bitmap_height = (int) ceilf (texture_height * scale); + } + + spa_meta_cursor->hotspot.x = (int32_t) ceilf (hotspot_x * scale); + spa_meta_cursor->hotspot.y = (int32_t) ceilf (hotspot_y * scale); + } + + graphene_matrix_init_identity (&matrix); + mtk_compute_viewport_matrix (&matrix, + texture_width, + texture_height, + cursor_scale, + cursor_transform, + src_rect); spa_meta_bitmap->size.width = bitmap_width; spa_meta_bitmap->size.height = bitmap_height; @@ -576,8 +632,9 @@ meta_screen_cast_stream_src_set_cursor_sprite_metadata (MetaScreenCastStreamSrc if (!meta_screen_cast_stream_src_draw_cursor_into (src, cursor_texture, - scale, - transform, + bitmap_width, + bitmap_height, + &matrix, bitmap_data, &error)) { diff --git a/src/backends/meta-screen-cast-stream-src.h b/src/backends/meta-screen-cast-stream-src.h index dca0bc247..558a7c101 100644 --- a/src/backends/meta-screen-cast-stream-src.h +++ b/src/backends/meta-screen-cast-stream-src.h @@ -118,8 +118,9 @@ MetaScreenCastStream * meta_screen_cast_stream_src_get_stream (MetaScreenCastStr gboolean meta_screen_cast_stream_src_draw_cursor_into (MetaScreenCastStreamSrc *src, CoglTexture *cursor_texture, - float scale, - MtkMonitorTransform transform, + int width, + int height, + const graphene_matrix_t *matrix, uint8_t *data, GError **error); @@ -141,8 +142,7 @@ void meta_screen_cast_stream_src_set_cursor_sprite_metadata (MetaScreenCastStrea MetaCursorSprite *cursor_sprite, int x, int y, - float scale, - MtkMonitorTransform transform); + float view_scale); gboolean meta_screen_cast_stream_src_uses_dma_bufs (MetaScreenCastStreamSrc *src); diff --git a/src/backends/meta-screen-cast-virtual-stream-src.c b/src/backends/meta-screen-cast-virtual-stream-src.c index 5a0394001..8bd1ba1c4 100644 --- a/src/backends/meta-screen-cast-virtual-stream-src.c +++ b/src/backends/meta-screen-cast-virtual-stream-src.c @@ -563,23 +563,15 @@ meta_screen_cast_virtual_stream_src_set_cursor_metadata (MetaScreenCastStreamSrc { ClutterStageView *stage_view; float view_scale; - float cursor_scale; - float scale; - MtkMonitorTransform transform; stage_view = view_from_src (src); view_scale = clutter_stage_view_get_scale (stage_view); - cursor_scale = meta_cursor_sprite_get_texture_scale (cursor_sprite); - scale = view_scale * cursor_scale; - transform = meta_cursor_sprite_get_texture_transform (cursor_sprite); - meta_screen_cast_stream_src_set_cursor_sprite_metadata (src, spa_meta_cursor, cursor_sprite, x, y, - scale, - transform); + view_scale); } else { diff --git a/src/backends/meta-screen-cast-window-stream-src.c b/src/backends/meta-screen-cast-window-stream-src.c index a803c8d61..7140a7887 100644 --- a/src/backends/meta-screen-cast-window-stream-src.c +++ b/src/backends/meta-screen-cast-window-stream-src.c @@ -133,8 +133,11 @@ maybe_draw_cursor_sprite (MetaScreenCastWindowStreamSrc *window_src, GError *error = NULL; cairo_surface_t *stream_surface; int width, height; - float scale; - MtkMonitorTransform transform; + int texture_width, texture_height; + float scale, view_scale, cursor_scale; + MtkMonitorTransform cursor_transform; + const graphene_rect_t *src_rect; + graphene_matrix_t matrix; int hotspot_x, hotspot_y; cairo_t *cr; @@ -151,23 +154,63 @@ maybe_draw_cursor_sprite (MetaScreenCastWindowStreamSrc *window_src, if (!meta_screen_cast_window_transform_cursor_position (screen_cast_window, cursor_sprite, &cursor_position, - &scale, - &transform, - &relative_cursor_position)) + &relative_cursor_position, + &view_scale)) return; meta_cursor_sprite_get_hotspot (cursor_sprite, &hotspot_x, &hotspot_y); + cursor_scale = meta_cursor_sprite_get_texture_scale (cursor_sprite); + scale = cursor_scale * view_scale; + cursor_transform = meta_cursor_sprite_get_texture_transform (cursor_sprite); + src_rect = meta_cursor_sprite_get_viewport_src_rect (cursor_sprite); + + texture_width = cogl_texture_get_width (cursor_texture); + texture_height = cogl_texture_get_height (cursor_texture); + + if (meta_cursor_sprite_get_viewport_dst_size (cursor_sprite, + &width, + &height)) + { + width = (int) ceilf (width * view_scale); + height = (int) ceilf (height * view_scale); + } + else if (src_rect) + { + width = (int) ceilf (src_rect->size.width * view_scale); + height = (int) ceilf (src_rect->size.height * view_scale); + } + else + { + if (mtk_monitor_transform_is_rotated (cursor_transform)) + { + width = (int) ceilf (texture_height * scale); + height = (int) ceilf (texture_width * scale); + } + else + { + width = (int) ceilf (texture_width * scale); + height = (int) ceilf (texture_height * scale); + } + } + + graphene_matrix_init_identity (&matrix); + mtk_compute_viewport_matrix (&matrix, + texture_width, + texture_height, + cursor_scale, + cursor_transform, + src_rect); + - width = (int) (cogl_texture_get_width (cursor_texture) * scale); - height = (int) (cogl_texture_get_height (cursor_texture) * scale); cursor_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); cursor_surface_data = cairo_image_surface_get_data (cursor_surface); if (!meta_screen_cast_stream_src_draw_cursor_into (src, cursor_texture, - scale, - transform, + width, + height, + &matrix, cursor_surface_data, &error)) { @@ -216,11 +259,12 @@ maybe_blit_cursor_sprite (MetaScreenCastWindowStreamSrc *window_src, CoglTexture *cursor_texture; CoglPipeline *pipeline; int width, height; - float scale; - MtkMonitorTransform transform; + float scale, view_scale, cursor_scale; + MtkMonitorTransform cursor_transform; + const graphene_rect_t *src_rect; + graphene_matrix_t matrix; int hotspot_x, hotspot_y; float x, y; - graphene_matrix_t matrix; cursor_sprite = meta_cursor_renderer_get_cursor (cursor_renderer); if (!cursor_sprite) @@ -235,12 +279,15 @@ maybe_blit_cursor_sprite (MetaScreenCastWindowStreamSrc *window_src, if (!meta_screen_cast_window_transform_cursor_position (screen_cast_window, cursor_sprite, &cursor_position, - &scale, - &transform, - &relative_cursor_position)) + &relative_cursor_position, + &view_scale)) return; meta_cursor_sprite_get_hotspot (cursor_sprite, &hotspot_x, &hotspot_y); + cursor_scale = meta_cursor_sprite_get_texture_scale (cursor_sprite); + scale = cursor_scale * view_scale; + cursor_transform = meta_cursor_sprite_get_texture_transform (cursor_sprite); + src_rect = meta_cursor_sprite_get_viewport_src_rect (cursor_sprite); x = (relative_cursor_position.x - hotspot_x) * scale; y = (relative_cursor_position.y - hotspot_y) * scale; @@ -254,8 +301,12 @@ maybe_blit_cursor_sprite (MetaScreenCastWindowStreamSrc *window_src, COGL_PIPELINE_FILTER_LINEAR); graphene_matrix_init_identity (&matrix); - mtk_monitor_transform_transform_matrix (transform, - &matrix); + mtk_compute_viewport_matrix (&matrix, + width, + height, + cursor_scale, + cursor_transform, + src_rect); cogl_pipeline_set_layer_matrix (pipeline, 0, &matrix); cogl_framebuffer_draw_rectangle (framebuffer, @@ -600,8 +651,8 @@ meta_screen_cast_window_stream_src_is_cursor_metadata_valid (MetaScreenCastStrea meta_screen_cast_window_transform_cursor_position (screen_cast_window, cursor_sprite, &cursor_position, - NULL, NULL, - &relative_cursor_position)) + &relative_cursor_position, + NULL)) { int x, y; @@ -637,8 +688,7 @@ meta_screen_cast_window_stream_src_set_cursor_metadata (MetaScreenCastStreamSrc MetaScreenCastWindow *screen_cast_window = window_src->screen_cast_window; MetaCursorSprite *cursor_sprite; graphene_point_t cursor_position; - float scale; - MtkMonitorTransform transform; + float view_scale; graphene_point_t relative_cursor_position; int x, y; @@ -649,9 +699,8 @@ meta_screen_cast_window_stream_src_set_cursor_metadata (MetaScreenCastStreamSrc !meta_screen_cast_window_transform_cursor_position (screen_cast_window, cursor_sprite, &cursor_position, - &scale, - &transform, - &relative_cursor_position)) + &relative_cursor_position, + &view_scale)) { window_src->last_cursor_matadata.set = FALSE; meta_screen_cast_stream_src_unset_cursor_metadata (src, @@ -674,8 +723,7 @@ meta_screen_cast_window_stream_src_set_cursor_metadata (MetaScreenCastStreamSrc spa_meta_cursor, cursor_sprite, x, y, - scale, - transform); + view_scale); } else { diff --git a/src/backends/meta-screen-cast-window.c b/src/backends/meta-screen-cast-window.c index 94fa9222a..f4f028727 100644 --- a/src/backends/meta-screen-cast-window.c +++ b/src/backends/meta-screen-cast-window.c @@ -53,9 +53,8 @@ gboolean meta_screen_cast_window_transform_cursor_position (MetaScreenCastWindow *screen_cast_window, MetaCursorSprite *cursor_sprite, graphene_point_t *cursor_position, - float *out_cursor_scale, - MtkMonitorTransform *out_cursor_transform, - graphene_point_t *out_relative_cursor_position) + graphene_point_t *out_relative_cursor_position, + float *out_view_scale) { MetaScreenCastWindowInterface *iface = META_SCREEN_CAST_WINDOW_GET_IFACE (screen_cast_window); @@ -63,9 +62,8 @@ meta_screen_cast_window_transform_cursor_position (MetaScreenCastWindow *screen_ return iface->transform_cursor_position (screen_cast_window, cursor_sprite, cursor_position, - out_cursor_scale, - out_cursor_transform, - out_relative_cursor_position); + out_relative_cursor_position, + out_view_scale); } void diff --git a/src/backends/meta-screen-cast-window.h b/src/backends/meta-screen-cast-window.h index 180f022a8..aedc5ba80 100644 --- a/src/backends/meta-screen-cast-window.h +++ b/src/backends/meta-screen-cast-window.h @@ -46,9 +46,8 @@ struct _MetaScreenCastWindowInterface gboolean (*transform_cursor_position) (MetaScreenCastWindow *screen_cast_window, MetaCursorSprite *cursor_sprite, graphene_point_t *cursor_position, - float *out_cursor_scale, - MtkMonitorTransform *out_cursor_transform, - graphene_point_t *out_relative_cursor_position); + graphene_point_t *out_relative_cursor_position, + float *out_view_scale); void (*capture_into) (MetaScreenCastWindow *screen_cast_window, MtkRectangle *bounds, @@ -76,9 +75,8 @@ void meta_screen_cast_window_transform_relative_position (MetaScreenCastWindow * gboolean meta_screen_cast_window_transform_cursor_position (MetaScreenCastWindow *screen_cast_window, MetaCursorSprite *cursor_sprite, graphene_point_t *cursor_position, - float *out_cursor_scale, - MtkMonitorTransform *out_cursor_transform, - graphene_point_t *out_relative_cursor_position); + graphene_point_t *out_relative_cursor_position, + float *out_view_scale); void meta_screen_cast_window_capture_into (MetaScreenCastWindow *screen_cast_window, MtkRectangle *bounds, diff --git a/src/compositor/meta-window-actor.c b/src/compositor/meta-window-actor.c index fd3eb8a03..e2c23c957 100644 --- a/src/compositor/meta-window-actor.c +++ b/src/compositor/meta-window-actor.c @@ -1284,9 +1284,8 @@ static gboolean meta_window_actor_transform_cursor_position (MetaScreenCastWindow *screen_cast_window, MetaCursorSprite *cursor_sprite, graphene_point_t *cursor_position, - float *out_cursor_scale, - MtkMonitorTransform *out_cursor_transform, - graphene_point_t *out_relative_cursor_position) + graphene_point_t *out_relative_cursor_position, + float *out_view_scale) { MetaWindowActor *window_actor = META_WINDOW_ACTOR (screen_cast_window); MetaWindowActorPrivate *priv = @@ -1297,37 +1296,6 @@ meta_window_actor_transform_cursor_position (MetaScreenCastWindow *screen_cast_w if (!meta_window_has_pointer (window)) return FALSE; - if (cursor_sprite && - meta_cursor_sprite_get_cogl_texture (cursor_sprite) && - out_cursor_scale) - { - MetaDisplay *display = meta_compositor_get_display (priv->compositor); - MetaContext *context = meta_display_get_context (display); - MetaBackend *backend = meta_context_get_backend (context); - MetaLogicalMonitor *logical_monitor; - float view_scale; - float cursor_texture_scale; - - logical_monitor = meta_window_get_main_logical_monitor (window); - - if (meta_backend_is_stage_views_scaled (backend)) - view_scale = meta_logical_monitor_get_scale (logical_monitor); - else - view_scale = 1.0; - - cursor_texture_scale = meta_cursor_sprite_get_texture_scale (cursor_sprite); - - *out_cursor_scale = view_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) { MetaShapedTexture *stex = meta_surface_actor_get_texture (priv->surface); @@ -1350,6 +1318,25 @@ meta_window_actor_transform_cursor_position (MetaScreenCastWindow *screen_cast_w out_relative_cursor_position->y *= unscaled_height / height; } + if (out_view_scale) + { + MetaDisplay *display = meta_compositor_get_display (priv->compositor); + MetaContext *context = meta_display_get_context (display); + MetaBackend *backend = meta_context_get_backend (context); + + if (meta_backend_is_stage_views_scaled (backend)) + { + MetaLogicalMonitor *logical_monitor; + + logical_monitor = meta_window_get_main_logical_monitor (window); + *out_view_scale = meta_logical_monitor_get_scale (logical_monitor); + } + else + { + *out_view_scale = 1.0; + } + } + return TRUE; }