[mutter] screencast: Implement buffer-transform support



commit 22b9a4219ad96ecf5596705515e69a7ed4538853
Author: Robert Mader <robert mader posteo de>
Date:   Sat Jul 2 18:50:45 2022 +0200

    screencast: Implement buffer-transform support
    
    So all cursor renderers support the feature.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/344>

 src/backends/meta-screen-cast-area-stream-src.c    |  4 ++++
 src/backends/meta-screen-cast-monitor-stream-src.c |  6 +++++-
 src/backends/meta-screen-cast-stream-src.c         | 17 +++++++++++++++--
 src/backends/meta-screen-cast-stream-src.h         |  4 +++-
 src/backends/meta-screen-cast-virtual-stream-src.c |  6 +++++-
 src/backends/meta-screen-cast-window-stream-src.c  | 16 +++++++++++++++-
 src/backends/meta-screen-cast-window.c             |  2 ++
 src/backends/meta-screen-cast-window.h             |  2 ++
 src/compositor/meta-window-actor.c                 |  9 +++++++++
 9 files changed, 60 insertions(+), 6 deletions(-)
---
diff --git a/src/backends/meta-screen-cast-area-stream-src.c b/src/backends/meta-screen-cast-area-stream-src.c
index fe376db05e..d9f0a0e154 100644
--- a/src/backends/meta-screen-cast-area-stream-src.c
+++ b/src/backends/meta-screen-cast-area-stream-src.c
@@ -592,13 +592,17 @@ meta_screen_cast_area_stream_src_set_cursor_metadata (MetaScreenCastStreamSrc *s
         {
           float cursor_scale;
           float metadata_scale;
+          MetaMonitorTransform transform;
 
           cursor_scale = meta_cursor_sprite_get_texture_scale (cursor_sprite);
           metadata_scale = 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,
+                                                                  transform,
                                                                   metadata_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 3c449e0225..a7bd35f851 100644
--- a/src/backends/meta-screen-cast-monitor-stream-src.c
+++ b/src/backends/meta-screen-cast-monitor-stream-src.c
@@ -687,14 +687,18 @@ meta_screen_cast_monitor_stream_src_set_cursor_metadata (MetaScreenCastStreamSrc
         {
           float cursor_scale;
           float scale;
+          MetaMonitorTransform transform;
 
           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);
+                                                                  scale,
+                                                                  transform);
         }
       else
         {
diff --git a/src/backends/meta-screen-cast-stream-src.c b/src/backends/meta-screen-cast-stream-src.c
index 5f91b66028..7914d02d20 100644
--- a/src/backends/meta-screen-cast-stream-src.c
+++ b/src/backends/meta-screen-cast-stream-src.c
@@ -249,6 +249,7 @@ draw_cursor_sprite_via_offscreen (MetaScreenCastStreamSrc  *src,
                                   CoglTexture              *cursor_texture,
                                   int                       bitmap_width,
                                   int                       bitmap_height,
+                                  MetaMonitorTransform      transform,
                                   uint8_t                  *bitmap_data,
                                   GError                  **error)
 {
@@ -265,6 +266,7 @@ 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);
@@ -290,6 +292,12 @@ draw_cursor_sprite_via_offscreen (MetaScreenCastStreamSrc  *src,
   cogl_pipeline_set_layer_filters (pipeline, 0,
                                    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_framebuffer_clear (fb, COGL_BUFFER_BIT_COLOR, &clear_color);
   cogl_framebuffer_draw_rectangle (fb, pipeline,
@@ -310,6 +318,7 @@ gboolean
 meta_screen_cast_stream_src_draw_cursor_into (MetaScreenCastStreamSrc  *src,
                                               CoglTexture              *cursor_texture,
                                               float                     scale,
+                                              MetaMonitorTransform      transform,
                                               uint8_t                  *data,
                                               GError                  **error)
 {
@@ -322,7 +331,8 @@ meta_screen_cast_stream_src_draw_cursor_into (MetaScreenCastStreamSrc  *src,
   height = texture_height * scale;
 
   if (texture_width == width &&
-      texture_height == height)
+      texture_height == height &&
+      transform == META_MONITOR_TRANSFORM_NORMAL)
     {
       cogl_texture_get_data (cursor_texture,
                              COGL_PIXEL_FORMAT_RGBA_8888_PRE,
@@ -335,6 +345,7 @@ meta_screen_cast_stream_src_draw_cursor_into (MetaScreenCastStreamSrc  *src,
                                              cursor_texture,
                                              width,
                                              height,
+                                             transform,
                                              data,
                                              error))
         return FALSE;
@@ -396,7 +407,8 @@ meta_screen_cast_stream_src_set_cursor_sprite_metadata (MetaScreenCastStreamSrc
                                                         MetaCursorSprite        *cursor_sprite,
                                                         int                      x,
                                                         int                      y,
-                                                        float                    scale)
+                                                        float                    scale,
+                                                        MetaMonitorTransform     transform)
 {
   CoglTexture *cursor_texture;
   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,
                                                      cursor_texture,
                                                      scale,
+                                                     transform,
                                                      bitmap_data,
                                                      &error))
     {
diff --git a/src/backends/meta-screen-cast-stream-src.h b/src/backends/meta-screen-cast-stream-src.h
index 2eafa57242..03b05c1442 100644
--- a/src/backends/meta-screen-cast-stream-src.h
+++ b/src/backends/meta-screen-cast-stream-src.h
@@ -94,6 +94,7 @@ 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,
+                                                       MetaMonitorTransform      transform,
                                                        uint8_t                  *data,
                                                        GError                  **error);
 
@@ -115,6 +116,7 @@ void meta_screen_cast_stream_src_set_cursor_sprite_metadata (MetaScreenCastStrea
                                                              MetaCursorSprite        *cursor_sprite,
                                                              int                      x,
                                                              int                      y,
-                                                             float                    scale);
+                                                             float                    scale,
+                                                             MetaMonitorTransform     transform);
 
 #endif /* META_SCREEN_CAST_STREAM_SRC_H */
diff --git a/src/backends/meta-screen-cast-virtual-stream-src.c 
b/src/backends/meta-screen-cast-virtual-stream-src.c
index 56f9bfaa2a..ee0dd44721 100644
--- a/src/backends/meta-screen-cast-virtual-stream-src.c
+++ b/src/backends/meta-screen-cast-virtual-stream-src.c
@@ -471,14 +471,18 @@ meta_screen_cast_virtual_stream_src_set_cursor_metadata (MetaScreenCastStreamSrc
         {
           float cursor_scale;
           float scale;
+          MetaMonitorTransform transform;
 
           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);
+                                                                  scale,
+                                                                  transform);
         }
       else
         {
diff --git a/src/backends/meta-screen-cast-window-stream-src.c 
b/src/backends/meta-screen-cast-window-stream-src.c
index b353a76df7..d90d65ac69 100644
--- a/src/backends/meta-screen-cast-window-stream-src.c
+++ b/src/backends/meta-screen-cast-window-stream-src.c
@@ -130,6 +130,7 @@ maybe_draw_cursor_sprite (MetaScreenCastWindowStreamSrc *window_src,
   cairo_surface_t *stream_surface;
   int width, height;
   float scale;
+  MetaMonitorTransform transform;
   int hotspot_x, hotspot_y;
   cairo_t *cr;
 
@@ -147,6 +148,7 @@ maybe_draw_cursor_sprite (MetaScreenCastWindowStreamSrc *window_src,
                                                           cursor_sprite,
                                                           &cursor_position,
                                                           &scale,
+                                                          &transform,
                                                           &relative_cursor_position))
     return;
 
@@ -161,6 +163,7 @@ maybe_draw_cursor_sprite (MetaScreenCastWindowStreamSrc *window_src,
   if (!meta_screen_cast_stream_src_draw_cursor_into (src,
                                                      cursor_texture,
                                                      scale,
+                                                     transform,
                                                      cursor_surface_data,
                                                      &error))
     {
@@ -208,8 +211,10 @@ maybe_blit_cursor_sprite (MetaScreenCastWindowStreamSrc *window_src,
   CoglPipeline *pipeline;
   int width, height;
   float scale;
+  MetaMonitorTransform transform;
   int hotspot_x, hotspot_y;
   float x, y;
+  graphene_matrix_t matrix;
 
   cursor_sprite = meta_cursor_renderer_get_cursor (cursor_renderer);
   if (!cursor_sprite)
@@ -225,6 +230,7 @@ maybe_blit_cursor_sprite (MetaScreenCastWindowStreamSrc *window_src,
                                                           cursor_sprite,
                                                           &cursor_position,
                                                           &scale,
+                                                          &transform,
                                                           &relative_cursor_position))
     return;
 
@@ -241,6 +247,11 @@ maybe_blit_cursor_sprite (MetaScreenCastWindowStreamSrc *window_src,
                                    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,
                                    pipeline,
                                    x, y,
@@ -557,6 +568,7 @@ meta_screen_cast_window_stream_src_set_cursor_metadata (MetaScreenCastStreamSrc
   MetaCursorSprite *cursor_sprite;
   graphene_point_t cursor_position;
   float scale;
+  MetaMonitorTransform transform;
   graphene_point_t relative_cursor_position;
   int x, y;
 
@@ -568,6 +580,7 @@ meta_screen_cast_window_stream_src_set_cursor_metadata (MetaScreenCastStreamSrc
                                                           cursor_sprite,
                                                           &cursor_position,
                                                           &scale,
+                                                          &transform,
                                                           &relative_cursor_position))
     {
       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,
                                                                   cursor_sprite,
                                                                   x, y,
-                                                                  scale);
+                                                                  scale,
+                                                                  transform);
         }
       else
         {
diff --git a/src/backends/meta-screen-cast-window.c b/src/backends/meta-screen-cast-window.c
index ab3e4ebe31..b9c0df867e 100644
--- a/src/backends/meta-screen-cast-window.c
+++ b/src/backends/meta-screen-cast-window.c
@@ -56,6 +56,7 @@ meta_screen_cast_window_transform_cursor_position (MetaScreenCastWindow *screen_
                                                    MetaCursorSprite     *cursor_sprite,
                                                    graphene_point_t     *cursor_position,
                                                    float                *out_cursor_scale,
+                                                   MetaMonitorTransform *out_cursor_transform,
                                                    graphene_point_t     *out_relative_cursor_position)
 {
   MetaScreenCastWindowInterface *iface =
@@ -65,6 +66,7 @@ meta_screen_cast_window_transform_cursor_position (MetaScreenCastWindow *screen_
                                            cursor_sprite,
                                            cursor_position,
                                            out_cursor_scale,
+                                           out_cursor_transform,
                                            out_relative_cursor_position);
 }
 
diff --git a/src/backends/meta-screen-cast-window.h b/src/backends/meta-screen-cast-window.h
index e149646ede..d170d92ae7 100644
--- a/src/backends/meta-screen-cast-window.h
+++ b/src/backends/meta-screen-cast-window.h
@@ -50,6 +50,7 @@ struct _MetaScreenCastWindowInterface
                                          MetaCursorSprite     *cursor_sprite,
                                          graphene_point_t     *cursor_position,
                                          float                *out_cursor_scale,
+                                         MetaMonitorTransform *out_cursor_transform,
                                          graphene_point_t     *out_relative_cursor_position);
 
   void (*capture_into) (MetaScreenCastWindow *screen_cast_window,
@@ -76,6 +77,7 @@ gboolean meta_screen_cast_window_transform_cursor_position (MetaScreenCastWindow
                                                             MetaCursorSprite     *cursor_sprite,
                                                             graphene_point_t     *cursor_position,
                                                             float                *out_cursor_scale,
+                                                            MetaMonitorTransform *out_cursor_transform,
                                                             graphene_point_t     
*out_relative_cursor_position);
 
 void meta_screen_cast_window_capture_into (MetaScreenCastWindow *screen_cast_window,
diff --git a/src/compositor/meta-window-actor.c b/src/compositor/meta-window-actor.c
index 9fd9f758c6..85e439a0ea 100644
--- a/src/compositor/meta-window-actor.c
+++ b/src/compositor/meta-window-actor.c
@@ -1241,6 +1241,7 @@ meta_window_actor_transform_cursor_position (MetaScreenCastWindow *screen_cast_w
                                              MetaCursorSprite     *cursor_sprite,
                                              graphene_point_t     *cursor_position,
                                              float                *out_cursor_scale,
+                                             MetaMonitorTransform *out_cursor_transform,
                                              graphene_point_t     *out_relative_cursor_position)
 {
   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;
     }
 
+  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)
     {
       clutter_actor_transform_stage_point (CLUTTER_ACTOR (priv->surface),


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]