[mutter/gbsneto/window-screencast-fixes: 6/9] window-stream-src: Implement cursor blitting



commit ea34915df3e99443df1e036e089db5ca4fadddda
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Tue Mar 17 18:22:29 2020 -0300

    window-stream-src: Implement cursor blitting
    
    A regression compared to the old code, we're not drawing the cursor
    when on EMBEDDED mode.
    
    Blit the cursor to the screencast framebuffer when on EMBEDDED mode.
    
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/1129

 src/backends/meta-screen-cast-window-stream-src.c | 81 +++++++++++++++++++++--
 1 file changed, 77 insertions(+), 4 deletions(-)
---
diff --git a/src/backends/meta-screen-cast-window-stream-src.c 
b/src/backends/meta-screen-cast-window-stream-src.c
index bba19f5be..401f6e283 100644
--- a/src/backends/meta-screen-cast-window-stream-src.c
+++ b/src/backends/meta-screen-cast-window-stream-src.c
@@ -178,6 +178,65 @@ maybe_draw_cursor_sprite (MetaScreenCastWindowStreamSrc *window_src,
   cairo_surface_destroy (cursor_surface);
 }
 
+static void
+maybe_blit_cursor_sprite (MetaScreenCastWindowStreamSrc *window_src,
+                          CoglFramebuffer               *framebuffer,
+                          MetaRectangle                 *stream_rect)
+{
+  MetaBackend *backend = get_backend (window_src);
+  CoglContext *cogl_context =
+    clutter_backend_get_cogl_context (clutter_get_default_backend ());
+  MetaCursorRenderer *cursor_renderer =
+    meta_backend_get_cursor_renderer (backend);
+  MetaScreenCastWindow *screen_cast_window;
+  MetaCursorSprite *cursor_sprite;
+  graphene_point_t relative_cursor_position;
+  graphene_point_t cursor_position;
+  CoglTexture *cursor_texture;
+  CoglPipeline *pipeline;
+  int width, height;
+  float scale;
+  int hotspot_x, hotspot_y;
+  float x, y;
+
+  cursor_sprite = meta_cursor_renderer_get_cursor (cursor_renderer);
+  if (!cursor_sprite)
+    return;
+
+  cursor_texture = meta_cursor_sprite_get_cogl_texture (cursor_sprite);
+  if (!cursor_texture)
+    return;
+
+  screen_cast_window = window_src->screen_cast_window;
+  cursor_position = meta_cursor_renderer_get_position (cursor_renderer);
+  if (!meta_screen_cast_window_transform_cursor_position (screen_cast_window,
+                                                          cursor_sprite,
+                                                          &cursor_position,
+                                                          &scale,
+                                                          &relative_cursor_position))
+    return;
+
+  meta_cursor_sprite_get_hotspot (cursor_sprite, &hotspot_x, &hotspot_y);
+
+  x = (relative_cursor_position.x - hotspot_x) * scale;
+  y = (relative_cursor_position.y - hotspot_y) * scale;
+  width = cogl_texture_get_width (cursor_texture);
+  height = cogl_texture_get_height (cursor_texture);
+
+  pipeline = cogl_pipeline_new (cogl_context);
+  cogl_pipeline_set_layer_texture (pipeline, 0, cursor_texture);
+  cogl_pipeline_set_layer_filters (pipeline, 0,
+                                   COGL_PIPELINE_FILTER_LINEAR,
+                                   COGL_PIPELINE_FILTER_LINEAR);
+
+  cogl_framebuffer_draw_rectangle (framebuffer,
+                                   pipeline,
+                                   x, y,
+                                   x + width, y + height);
+
+  cogl_object_unref (pipeline);
+}
+
 static gboolean
 capture_into (MetaScreenCastWindowStreamSrc *window_src,
               uint8_t                       *data)
@@ -409,6 +468,7 @@ meta_screen_cast_window_stream_src_blit_to_framebuffer (MetaScreenCastStreamSrc
 {
   MetaScreenCastWindowStreamSrc *window_src =
     META_SCREEN_CAST_WINDOW_STREAM_SRC (src);
+  MetaScreenCastStream *stream;
   MetaRectangle stream_rect;
 
   stream_rect.x = 0;
@@ -416,10 +476,23 @@ meta_screen_cast_window_stream_src_blit_to_framebuffer (MetaScreenCastStreamSrc
   stream_rect.width = get_stream_width (window_src);
   stream_rect.height = get_stream_height (window_src);
 
-  return
-    meta_screen_cast_window_blit_to_framebuffer (window_src->screen_cast_window,
-                                                 &stream_rect,
-                                                 framebuffer);
+  if (!meta_screen_cast_window_blit_to_framebuffer (window_src->screen_cast_window,
+                                                     &stream_rect,
+                                                     framebuffer))
+    return FALSE;
+
+  stream = meta_screen_cast_stream_src_get_stream (src);
+  switch (meta_screen_cast_stream_get_cursor_mode (stream))
+    {
+    case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED:
+      maybe_blit_cursor_sprite (window_src, framebuffer, &stream_rect);
+      break;
+    case META_SCREEN_CAST_CURSOR_MODE_METADATA:
+    case META_SCREEN_CAST_CURSOR_MODE_HIDDEN:
+      break;
+    }
+
+  return TRUE;
 }
 
 static void


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