[mutter] screen-cast/src: Pass dimension and stride when needed
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] screen-cast/src: Pass dimension and stride when needed
- Date: Tue, 2 Feb 2021 10:46:49 +0000 (UTC)
commit 70d9a7b4bf10d9d121b925f564a58b1d1c1510c3
Author: Jonas Ã…dahl <jadahl gmail com>
Date: Mon Feb 1 09:17:15 2021 +0100
screen-cast/src: Pass dimension and stride when needed
Instead of getters, pass the width, height and stride around when
relevant. This also removes the redudant "stream_size" and
"stream_height" variables from the src struct, as they are already part
of the video format.
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1697>
src/backends/meta-screen-cast-area-stream-src.c | 5 +-
src/backends/meta-screen-cast-monitor-stream-src.c | 13 ++--
src/backends/meta-screen-cast-stream-src.c | 69 ++++++++--------------
src/backends/meta-screen-cast-stream-src.h | 9 +--
src/backends/meta-screen-cast-window-stream-src.c | 20 ++++---
5 files changed, 52 insertions(+), 64 deletions(-)
---
diff --git a/src/backends/meta-screen-cast-area-stream-src.c b/src/backends/meta-screen-cast-area-stream-src.c
index 7f88d80d11..281f6f2e90 100644
--- a/src/backends/meta-screen-cast-area-stream-src.c
+++ b/src/backends/meta-screen-cast-area-stream-src.c
@@ -411,6 +411,9 @@ meta_screen_cast_area_stream_src_disable (MetaScreenCastStreamSrc *src)
static gboolean
meta_screen_cast_area_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src,
+ int width,
+ int height,
+ int stride,
uint8_t *data,
GError **error)
{
@@ -421,13 +424,11 @@ meta_screen_cast_area_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src
ClutterStage *stage;
MetaRectangle *area;
float scale;
- int stride;
ClutterPaintFlag paint_flags = CLUTTER_PAINT_FLAG_CLEAR;
stage = get_stage (area_src);
area = meta_screen_cast_area_stream_get_area (area_stream);
scale = meta_screen_cast_area_stream_get_scale (area_stream);
- stride = meta_screen_cast_stream_src_get_stride (src);
switch (meta_screen_cast_stream_get_cursor_mode (stream))
{
diff --git a/src/backends/meta-screen-cast-monitor-stream-src.c
b/src/backends/meta-screen-cast-monitor-stream-src.c
index 2fa7ebdef2..3011d0d193 100644
--- a/src/backends/meta-screen-cast-monitor-stream-src.c
+++ b/src/backends/meta-screen-cast-monitor-stream-src.c
@@ -450,9 +450,11 @@ meta_screen_cast_monitor_stream_src_disable (MetaScreenCastStreamSrc *src)
static void
maybe_paint_cursor_sprite (MetaScreenCastMonitorStreamSrc *monitor_src,
+ int width,
+ int height,
+ int stride,
uint8_t *data)
{
- MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (monitor_src);
MetaBackend *backend = get_backend (monitor_src);
MetaCursorRenderer *cursor_renderer =
meta_backend_get_cursor_renderer (backend);
@@ -463,7 +465,6 @@ maybe_paint_cursor_sprite (MetaScreenCastMonitorStreamSrc *monitor_src,
uint8_t *sprite_data;
cairo_surface_t *sprite_surface;
graphene_rect_t sprite_rect;
- int width, height, stride;
cairo_surface_t *surface;
cairo_t *cr;
@@ -496,9 +497,6 @@ maybe_paint_cursor_sprite (MetaScreenCastMonitorStreamSrc *monitor_src,
sprite_stride);
cairo_surface_set_device_scale (sprite_surface, sprite_scale, sprite_scale);
- stride = meta_screen_cast_stream_src_get_stride (src);
- width = meta_screen_cast_stream_src_get_width (src);
- height = meta_screen_cast_stream_src_get_height (src);
surface = cairo_image_surface_create_for_data (data,
CAIRO_FORMAT_ARGB32,
width, height, stride);
@@ -516,6 +514,9 @@ maybe_paint_cursor_sprite (MetaScreenCastMonitorStreamSrc *monitor_src,
static gboolean
meta_screen_cast_monitor_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src,
+ int width,
+ int height,
+ int stride,
uint8_t *data,
GError **error)
{
@@ -534,7 +535,7 @@ meta_screen_cast_monitor_stream_src_record_to_buffer (MetaScreenCastStreamSrc *
switch (meta_screen_cast_stream_get_cursor_mode (stream))
{
case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED:
- maybe_paint_cursor_sprite (monitor_src, data);
+ maybe_paint_cursor_sprite (monitor_src, width, height, stride, data);
break;
case META_SCREEN_CAST_CURSOR_MODE_METADATA:
case META_SCREEN_CAST_CURSOR_MODE_HIDDEN:
diff --git a/src/backends/meta-screen-cast-stream-src.c b/src/backends/meta-screen-cast-stream-src.c
index cc08bccdbe..0682d7330a 100644
--- a/src/backends/meta-screen-cast-stream-src.c
+++ b/src/backends/meta-screen-cast-stream-src.c
@@ -95,9 +95,6 @@ typedef struct _MetaScreenCastStreamSrcPrivate
guint follow_up_frame_source_id;
GHashTable *dmabuf_handles;
-
- int stream_width;
- int stream_height;
} MetaScreenCastStreamSrcPrivate;
static void
@@ -137,13 +134,16 @@ meta_screen_cast_stream_src_get_videocrop (MetaScreenCastStreamSrc *src,
static gboolean
meta_screen_cast_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src,
+ int width,
+ int height,
+ int stride,
uint8_t *data,
GError **error)
{
MetaScreenCastStreamSrcClass *klass =
META_SCREEN_CAST_STREAM_SRC_GET_CLASS (src);
- return klass->record_to_buffer (src, data, error);
+ return klass->record_to_buffer (src, width, height, stride, data, error);
}
static gboolean
@@ -432,7 +432,16 @@ do_record_frame (MetaScreenCastStreamSrc *src,
if (spa_buffer->datas[0].data ||
spa_buffer->datas[0].type == SPA_DATA_MemFd)
{
- return meta_screen_cast_stream_src_record_to_buffer (src, data, error);
+ int width = priv->video_format.size.width;
+ int height = priv->video_format.size.height;
+ int stride = priv->video_stride;
+
+ return meta_screen_cast_stream_src_record_to_buffer (src,
+ width,
+ height,
+ stride,
+ data,
+ error);
}
else if (spa_buffer->datas[0].type == SPA_DATA_DmaBuf)
{
@@ -567,8 +576,10 @@ meta_screen_cast_stream_src_maybe_record_frame (MetaScreenCastStreamSrc *src,
{
spa_meta_video_crop->region.position.x = 0;
spa_meta_video_crop->region.position.y = 0;
- spa_meta_video_crop->region.size.width = priv->stream_width;
- spa_meta_video_crop->region.size.height = priv->stream_height;
+ spa_meta_video_crop->region.size.width =
+ priv->video_format.size.width;
+ spa_meta_video_crop->region.size.height =
+ priv->video_format.size.height;
}
}
}
@@ -735,9 +746,10 @@ on_stream_add_buffer (void *data,
spa_data[0].mapoffset = 0;
spa_data[0].maxsize = stride * priv->video_format.size.height;
- dmabuf_handle = meta_screen_cast_create_dma_buf_handle (screen_cast,
- priv->stream_width,
- priv->stream_height);
+ dmabuf_handle =
+ meta_screen_cast_create_dma_buf_handle (screen_cast,
+ priv->video_format.size.width,
+ priv->video_format.size.height);
if (dmabuf_handle)
{
@@ -831,6 +843,8 @@ create_pipewire_stream (MetaScreenCastStreamSrc *src,
uint8_t buffer[1024];
struct spa_pod_builder pod_builder =
SPA_POD_BUILDER_INIT (buffer, sizeof (buffer));
+ int width;
+ int height;
float frame_rate;
MetaFraction frame_rate_fraction;
struct spa_fraction max_framerate;
@@ -851,10 +865,7 @@ create_pipewire_stream (MetaScreenCastStreamSrc *src,
return NULL;
}
- meta_screen_cast_stream_src_get_specs (src,
- &priv->stream_width,
- &priv->stream_height,
- &frame_rate);
+ meta_screen_cast_stream_src_get_specs (src, &width, &height, &frame_rate);
frame_rate_fraction = meta_fraction_from_double (frame_rate);
min_framerate = SPA_FRACTION (1, 1);
@@ -867,8 +878,7 @@ create_pipewire_stream (MetaScreenCastStreamSrc *src,
SPA_FORMAT_mediaType, SPA_POD_Id (SPA_MEDIA_TYPE_video),
SPA_FORMAT_mediaSubtype, SPA_POD_Id (SPA_MEDIA_SUBTYPE_raw),
SPA_FORMAT_VIDEO_format, SPA_POD_Id (SPA_VIDEO_FORMAT_BGRx),
- SPA_FORMAT_VIDEO_size, SPA_POD_Rectangle (&SPA_RECTANGLE (priv->stream_width,
- priv->stream_height)),
+ SPA_FORMAT_VIDEO_size, SPA_POD_Rectangle (&SPA_RECTANGLE (width, height)),
SPA_FORMAT_VIDEO_framerate, SPA_POD_Fraction (&SPA_FRACTION (0, 1)),
SPA_FORMAT_VIDEO_maxFramerate, SPA_POD_CHOICE_RANGE_Fraction (&max_framerate,
&min_framerate,
@@ -1045,33 +1055,6 @@ meta_screen_cast_stream_src_init_initable_iface (GInitableIface *iface)
iface->init = meta_screen_cast_stream_src_initable_init;
}
-int
-meta_screen_cast_stream_src_get_stride (MetaScreenCastStreamSrc *src)
-{
- MetaScreenCastStreamSrcPrivate *priv =
- meta_screen_cast_stream_src_get_instance_private (src);
-
- return priv->video_stride;
-}
-
-int
-meta_screen_cast_stream_src_get_width (MetaScreenCastStreamSrc *src)
-{
- MetaScreenCastStreamSrcPrivate *priv =
- meta_screen_cast_stream_src_get_instance_private (src);
-
- return priv->stream_width;
-}
-
-int
-meta_screen_cast_stream_src_get_height (MetaScreenCastStreamSrc *src)
-{
- MetaScreenCastStreamSrcPrivate *priv =
- meta_screen_cast_stream_src_get_instance_private (src);
-
- return priv->stream_height;
-}
-
MetaScreenCastStream *
meta_screen_cast_stream_src_get_stream (MetaScreenCastStreamSrc *src)
{
diff --git a/src/backends/meta-screen-cast-stream-src.h b/src/backends/meta-screen-cast-stream-src.h
index a2f681793f..3eaebf62c5 100644
--- a/src/backends/meta-screen-cast-stream-src.h
+++ b/src/backends/meta-screen-cast-stream-src.h
@@ -60,6 +60,9 @@ struct _MetaScreenCastStreamSrcClass
void (* enable) (MetaScreenCastStreamSrc *src);
void (* disable) (MetaScreenCastStreamSrc *src);
gboolean (* record_to_buffer) (MetaScreenCastStreamSrc *src,
+ int width,
+ int height,
+ int stride,
uint8_t *data,
GError **error);
gboolean (* record_to_framebuffer) (MetaScreenCastStreamSrc *src,
@@ -78,12 +81,6 @@ void meta_screen_cast_stream_src_maybe_record_frame (MetaScreenCastStreamSrc *s
gboolean meta_screen_cast_stream_src_pending_follow_up_frame (MetaScreenCastStreamSrc *src);
-int meta_screen_cast_stream_src_get_stride (MetaScreenCastStreamSrc *src);
-
-int meta_screen_cast_stream_src_get_width (MetaScreenCastStreamSrc *src);
-
-int meta_screen_cast_stream_src_get_height (MetaScreenCastStreamSrc *src);
-
MetaScreenCastStream * meta_screen_cast_stream_src_get_stream (MetaScreenCastStreamSrc *src);
gboolean meta_screen_cast_stream_src_draw_cursor_into (MetaScreenCastStreamSrc *src,
diff --git a/src/backends/meta-screen-cast-window-stream-src.c
b/src/backends/meta-screen-cast-window-stream-src.c
index 76f53d1600..3fe8120f2f 100644
--- a/src/backends/meta-screen-cast-window-stream-src.c
+++ b/src/backends/meta-screen-cast-window-stream-src.c
@@ -244,16 +244,19 @@ maybe_blit_cursor_sprite (MetaScreenCastWindowStreamSrc *window_src,
static gboolean
capture_into (MetaScreenCastWindowStreamSrc *window_src,
+ int width,
+ int height,
+ int stride,
uint8_t *data)
{
MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (window_src);
MetaRectangle stream_rect;
MetaScreenCastStream *stream;
- stream_rect.x = 0;
- stream_rect.y = 0;
- stream_rect.width = get_stream_width (window_src);
- stream_rect.height = get_stream_height (window_src);
+ stream_rect = (MetaRectangle) {
+ .width = width,
+ .height = height,
+ };
meta_screen_cast_window_capture_into (window_src->screen_cast_window,
&stream_rect, data);
@@ -449,13 +452,16 @@ meta_screen_cast_window_stream_src_disable (MetaScreenCastStreamSrc *src)
static gboolean
meta_screen_cast_window_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src,
+ int width,
+ int height,
+ int stride,
uint8_t *data,
GError **error)
{
MetaScreenCastWindowStreamSrc *window_src =
META_SCREEN_CAST_WINDOW_STREAM_SRC (src);
- capture_into (window_src, data);
+ capture_into (window_src, width, height, stride, data);
return TRUE;
}
@@ -472,8 +478,8 @@ meta_screen_cast_window_stream_src_record_to_framebuffer (MetaScreenCastStreamSr
stream_rect.x = 0;
stream_rect.y = 0;
- stream_rect.width = get_stream_width (window_src);
- stream_rect.height = get_stream_height (window_src);
+ stream_rect.width = cogl_framebuffer_get_width (framebuffer);
+ stream_rect.height = cogl_framebuffer_get_height (framebuffer);
if (!meta_screen_cast_window_blit_to_framebuffer (window_src->screen_cast_window,
&stream_rect,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]