[mutter/gbsneto/more-screencast: 3/7] monitor-stream-src: Blit scanout when available




commit 52fde2e10e76be525fec5d92607f4a14584b249b
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Fri Aug 28 23:01:11 2020 -0300

    monitor-stream-src: Blit scanout when available
    
    When there's a direct scanout set in the stage view, we
    have to use it instead of the view's regular onscreen
    framebuffer.
    
    Use the new CoglScanout API to implement blitting to the
    stream framebuffer.
    
    https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1421

 src/backends/meta-screen-cast-monitor-stream-src.c | 32 +++++++++++++++-------
 src/backends/native/meta-drm-buffer-gbm.c          | 31 +++++++++++++++------
 2 files changed, 45 insertions(+), 18 deletions(-)
---
diff --git a/src/backends/meta-screen-cast-monitor-stream-src.c 
b/src/backends/meta-screen-cast-monitor-stream-src.c
index 78aba0a953..8ca0d4e248 100644
--- a/src/backends/meta-screen-cast-monitor-stream-src.c
+++ b/src/backends/meta-screen-cast-monitor-stream-src.c
@@ -520,6 +520,7 @@ meta_screen_cast_monitor_stream_src_record_to_framebuffer (MetaScreenCastStreamS
     {
       ClutterStageView *view = CLUTTER_STAGE_VIEW (l->data);
       CoglFramebuffer *view_framebuffer;
+      CoglScanout *scanout;
       MetaRectangle view_layout;
       int x, y;
 
@@ -528,19 +529,30 @@ meta_screen_cast_monitor_stream_src_record_to_framebuffer (MetaScreenCastStreamS
       if (!meta_rectangle_overlap (&logical_monitor_layout, &view_layout))
         continue;
 
-      view_framebuffer = clutter_stage_view_get_framebuffer (view);
-
       x = (int) roundf ((view_layout.x - logical_monitor_layout.x) * view_scale);
       y = (int) roundf ((view_layout.y - logical_monitor_layout.y) * view_scale);
 
-      if (!cogl_blit_framebuffer (view_framebuffer,
-                                  framebuffer,
-                                  0, 0,
-                                  x, y,
-                                  cogl_framebuffer_get_width (view_framebuffer),
-                                  cogl_framebuffer_get_height (view_framebuffer),
-                                  error))
-        return FALSE;
+      scanout = clutter_stage_view_peek_scanout (view);
+      if (scanout)
+        {
+          if (!cogl_scanout_blit_to_framebuffer (scanout,
+                                                 framebuffer,
+                                                 x, y,
+                                                 error))
+              return FALSE;
+        }
+      else
+        {
+          view_framebuffer = clutter_stage_view_get_framebuffer (view);
+          if (!cogl_blit_framebuffer (view_framebuffer,
+                                      framebuffer,
+                                      0, 0,
+                                      x, y,
+                                      cogl_framebuffer_get_width (view_framebuffer),
+                                      cogl_framebuffer_get_height (view_framebuffer),
+                                      error))
+            return FALSE;
+        }
     }
 
   cogl_framebuffer_finish (framebuffer);
diff --git a/src/backends/native/meta-drm-buffer-gbm.c b/src/backends/native/meta-drm-buffer-gbm.c
index f5f51fb716..9d81c3109c 100644
--- a/src/backends/native/meta-drm-buffer-gbm.c
+++ b/src/backends/native/meta-drm-buffer-gbm.c
@@ -190,14 +190,17 @@ meta_drm_buffer_gbm_blit_to_framebuffer (CoglScanout      *scanout,
   CoglEglImageFlags flags;
   CoglOffscreen *cogl_fbo = NULL;
   CoglTexture2D *cogl_tex;
-  uint64_t modifiers[1];
-  uint32_t strides[1];
-  uint32_t offsets[1];
+  uint32_t n_planes;
+  uint64_t *modifiers;
+  uint32_t *strides;
+  uint32_t *offsets;
   uint32_t width;
   uint32_t height;
   uint32_t drm_format;
+  int *fds;
   gboolean result;
   int dmabuf_fd = -1;
+  uint32_t i;
 
   if (!buffer_gbm->bo)
     {
@@ -223,16 +226,28 @@ meta_drm_buffer_gbm_blit_to_framebuffer (CoglScanout      *scanout,
 
   width = gbm_bo_get_width (buffer_gbm->bo);
   height = gbm_bo_get_height (buffer_gbm->bo);
-  strides[0] = gbm_bo_get_stride (buffer_gbm->bo);
-  offsets[0] = gbm_bo_get_offset (buffer_gbm->bo, 0);
-  modifiers[0] = gbm_bo_get_modifier (buffer_gbm->bo);
+  n_planes = gbm_bo_get_plane_count (buffer_gbm->bo);
+  fds = g_alloca (sizeof (int) * n_planes);
+  strides = g_alloca (sizeof (uint32_t) * n_planes);
+  offsets = g_alloca (sizeof (uint32_t) * n_planes);
+  modifiers = g_alloca (sizeof (uint32_t) * n_planes);
+
+  for (i = 0; i < n_planes; i++)
+    {
+      fds[i] = dmabuf_fd;
+      strides[i] = gbm_bo_get_stride_for_plane (buffer_gbm->bo, i);
+      offsets[i] = gbm_bo_get_offset (buffer_gbm->bo, i);
+      modifiers[i] = gbm_bo_get_modifier (buffer_gbm->bo);
+    }
+
+
   egl_image = meta_egl_create_dmabuf_image (egl,
                                             egl_display,
                                             width,
                                             height,
                                             drm_format,
-                                            1 /* n_planes */,
-                                            &dmabuf_fd,
+                                            n_planes,
+                                            fds,
                                             strides,
                                             offsets,
                                             modifiers,


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