mirror of
https://github.com/brl/mutter.git
synced 2024-12-23 19:42:05 +00:00
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>
This commit is contained in:
parent
41bf0181b9
commit
70d9a7b4bf
@ -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))
|
||||
{
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user