2020-03-04 15:42:52 -05:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 Red Hat Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
* 02111-1307, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "backends/meta-screen-cast-area-stream-src.h"
|
|
|
|
|
|
|
|
#include <spa/buffer/meta.h>
|
|
|
|
|
|
|
|
#include "backends/meta-backend-private.h"
|
|
|
|
#include "backends/meta-cursor-tracker-private.h"
|
2022-03-11 03:39:07 -05:00
|
|
|
#include "backends/meta-dbus-session-manager.h"
|
2020-03-04 15:42:52 -05:00
|
|
|
#include "backends/meta-screen-cast-area-stream.h"
|
|
|
|
#include "backends/meta-screen-cast-session.h"
|
|
|
|
#include "backends/meta-stage-private.h"
|
|
|
|
#include "clutter/clutter.h"
|
|
|
|
#include "clutter/clutter-mutter.h"
|
|
|
|
#include "core/boxes-private.h"
|
|
|
|
|
|
|
|
struct _MetaScreenCastAreaStreamSrc
|
|
|
|
{
|
|
|
|
MetaScreenCastStreamSrc parent;
|
|
|
|
|
|
|
|
gboolean cursor_bitmap_invalid;
|
|
|
|
gboolean hw_cursor_inhibited;
|
|
|
|
|
|
|
|
GList *watches;
|
|
|
|
|
2020-07-13 08:09:44 -04:00
|
|
|
gulong position_invalidated_handler_id;
|
2020-03-04 15:42:52 -05:00
|
|
|
gulong cursor_changed_handler_id;
|
2022-04-29 10:05:50 -04:00
|
|
|
gulong prepare_frame_handler_id;
|
2020-03-04 15:42:52 -05:00
|
|
|
|
|
|
|
guint maybe_record_idle_id;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
hw_cursor_inhibitor_iface_init (MetaHwCursorInhibitorInterface *iface);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (MetaScreenCastAreaStreamSrc,
|
|
|
|
meta_screen_cast_area_stream_src,
|
|
|
|
META_TYPE_SCREEN_CAST_STREAM_SRC,
|
|
|
|
G_IMPLEMENT_INTERFACE (META_TYPE_HW_CURSOR_INHIBITOR,
|
|
|
|
hw_cursor_inhibitor_iface_init))
|
|
|
|
|
|
|
|
static ClutterStage *
|
|
|
|
get_stage (MetaScreenCastAreaStreamSrc *area_src)
|
|
|
|
{
|
|
|
|
MetaScreenCastStreamSrc *src;
|
|
|
|
MetaScreenCastStream *stream;
|
|
|
|
MetaScreenCastAreaStream *area_stream;
|
|
|
|
|
|
|
|
src = META_SCREEN_CAST_STREAM_SRC (area_src);
|
|
|
|
stream = meta_screen_cast_stream_src_get_stream (src);
|
|
|
|
area_stream = META_SCREEN_CAST_AREA_STREAM (stream);
|
|
|
|
|
|
|
|
return meta_screen_cast_area_stream_get_stage (area_stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
static MetaBackend *
|
|
|
|
get_backend (MetaScreenCastAreaStreamSrc *area_src)
|
|
|
|
{
|
|
|
|
MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (area_src);
|
|
|
|
MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
|
|
|
|
MetaScreenCastSession *session = meta_screen_cast_stream_get_session (stream);
|
|
|
|
MetaScreenCast *screen_cast =
|
|
|
|
meta_screen_cast_session_get_screen_cast (session);
|
|
|
|
|
|
|
|
return meta_screen_cast_get_backend (screen_cast);
|
|
|
|
}
|
|
|
|
|
2021-02-01 04:41:57 -05:00
|
|
|
static gboolean
|
2020-03-04 15:42:52 -05:00
|
|
|
meta_screen_cast_area_stream_src_get_specs (MetaScreenCastStreamSrc *src,
|
|
|
|
int *width,
|
|
|
|
int *height,
|
|
|
|
float *frame_rate)
|
|
|
|
{
|
|
|
|
MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
|
|
|
|
MetaScreenCastAreaStream *area_stream = META_SCREEN_CAST_AREA_STREAM (stream);
|
|
|
|
MetaRectangle *area;
|
|
|
|
float scale;
|
|
|
|
|
|
|
|
area = meta_screen_cast_area_stream_get_area (area_stream);
|
|
|
|
scale = meta_screen_cast_area_stream_get_scale (area_stream);
|
|
|
|
|
|
|
|
*width = (int) roundf (area->width * scale);
|
|
|
|
*height = (int) roundf (area->height * scale);
|
|
|
|
*frame_rate = 60.0;
|
2021-02-01 04:41:57 -05:00
|
|
|
|
|
|
|
return TRUE;
|
2020-03-04 15:42:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
is_cursor_in_stream (MetaScreenCastAreaStreamSrc *area_src)
|
|
|
|
{
|
|
|
|
MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (area_src);
|
|
|
|
MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
|
|
|
|
MetaScreenCastAreaStream *area_stream = META_SCREEN_CAST_AREA_STREAM (stream);
|
|
|
|
MetaBackend *backend = get_backend (area_src);
|
|
|
|
MetaCursorRenderer *cursor_renderer =
|
|
|
|
meta_backend_get_cursor_renderer (backend);
|
|
|
|
MetaRectangle *area;
|
|
|
|
graphene_rect_t area_rect;
|
|
|
|
MetaCursorSprite *cursor_sprite;
|
|
|
|
|
|
|
|
area = meta_screen_cast_area_stream_get_area (area_stream);
|
|
|
|
area_rect = meta_rectangle_to_graphene_rect (area);
|
|
|
|
|
|
|
|
cursor_sprite = meta_cursor_renderer_get_cursor (cursor_renderer);
|
|
|
|
if (cursor_sprite)
|
|
|
|
{
|
|
|
|
graphene_rect_t cursor_rect;
|
|
|
|
|
|
|
|
cursor_rect = meta_cursor_renderer_calculate_rect (cursor_renderer,
|
|
|
|
cursor_sprite);
|
|
|
|
return graphene_rect_intersection (&cursor_rect, &area_rect, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-13 06:28:46 -04:00
|
|
|
MetaCursorTracker *cursor_tracker =
|
|
|
|
meta_backend_get_cursor_tracker (backend);
|
2020-03-04 15:42:52 -05:00
|
|
|
graphene_point_t cursor_position;
|
|
|
|
|
2020-07-13 06:28:46 -04:00
|
|
|
meta_cursor_tracker_get_pointer (cursor_tracker, &cursor_position, NULL);
|
2020-03-04 15:42:52 -05:00
|
|
|
return graphene_rect_contains_point (&area_rect, &cursor_position);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-01 05:06:13 -04:00
|
|
|
static gboolean
|
|
|
|
is_redraw_queued (MetaScreenCastAreaStreamSrc *area_src)
|
|
|
|
{
|
|
|
|
ClutterStage *stage = get_stage (area_src);
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
for (l = clutter_stage_peek_stage_views (stage); l; l = l->next)
|
|
|
|
{
|
|
|
|
ClutterStageView *view = l->data;
|
|
|
|
|
|
|
|
if (clutter_stage_is_redraw_queued_on_view (stage, view))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-03-04 15:42:52 -05:00
|
|
|
static void
|
|
|
|
sync_cursor_state (MetaScreenCastAreaStreamSrc *area_src)
|
|
|
|
{
|
|
|
|
MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (area_src);
|
2020-07-03 10:48:52 -04:00
|
|
|
MetaScreenCastRecordFlag flags;
|
2020-03-04 15:42:52 -05:00
|
|
|
|
2020-04-01 05:06:13 -04:00
|
|
|
if (is_redraw_queued (area_src))
|
2020-03-04 15:42:52 -05:00
|
|
|
return;
|
|
|
|
|
2020-07-03 10:52:43 -04:00
|
|
|
flags = META_SCREEN_CAST_RECORD_FLAG_CURSOR_ONLY;
|
2020-07-03 10:48:52 -04:00
|
|
|
meta_screen_cast_stream_src_maybe_record_frame (src, flags);
|
2020-03-04 15:42:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-07-13 08:09:44 -04:00
|
|
|
pointer_position_invalidated (MetaCursorTracker *cursor_tracker,
|
|
|
|
MetaScreenCastAreaStreamSrc *area_src)
|
2020-03-04 15:42:52 -05:00
|
|
|
{
|
2022-04-29 10:05:50 -04:00
|
|
|
ClutterStage *stage = get_stage (area_src);
|
|
|
|
|
|
|
|
clutter_stage_schedule_update (stage);
|
2020-03-04 15:42:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cursor_changed (MetaCursorTracker *cursor_tracker,
|
|
|
|
MetaScreenCastAreaStreamSrc *area_src)
|
|
|
|
{
|
|
|
|
area_src->cursor_bitmap_invalid = TRUE;
|
|
|
|
sync_cursor_state (area_src);
|
|
|
|
}
|
|
|
|
|
2022-04-29 10:05:50 -04:00
|
|
|
static void
|
|
|
|
on_prepare_frame (ClutterStage *stage,
|
|
|
|
ClutterStageView *stage_view,
|
2022-10-13 11:50:34 -04:00
|
|
|
ClutterFrame *frame,
|
2022-04-29 10:05:50 -04:00
|
|
|
MetaScreenCastAreaStreamSrc *area_src)
|
|
|
|
{
|
|
|
|
sync_cursor_state (area_src);
|
|
|
|
}
|
|
|
|
|
2020-03-04 15:42:52 -05:00
|
|
|
static void
|
|
|
|
inhibit_hw_cursor (MetaScreenCastAreaStreamSrc *area_src)
|
|
|
|
{
|
|
|
|
MetaHwCursorInhibitor *inhibitor;
|
2020-07-13 11:45:41 -04:00
|
|
|
MetaBackend *backend;
|
2020-03-04 15:42:52 -05:00
|
|
|
|
|
|
|
g_return_if_fail (!area_src->hw_cursor_inhibited);
|
|
|
|
|
2020-07-13 11:45:41 -04:00
|
|
|
backend = get_backend (area_src);
|
2020-03-04 15:42:52 -05:00
|
|
|
inhibitor = META_HW_CURSOR_INHIBITOR (area_src);
|
2020-07-13 11:45:41 -04:00
|
|
|
meta_backend_add_hw_cursor_inhibitor (backend, inhibitor);
|
2020-03-04 15:42:52 -05:00
|
|
|
|
|
|
|
area_src->hw_cursor_inhibited = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
uninhibit_hw_cursor (MetaScreenCastAreaStreamSrc *area_src)
|
|
|
|
{
|
|
|
|
MetaHwCursorInhibitor *inhibitor;
|
2020-07-13 11:45:41 -04:00
|
|
|
MetaBackend *backend;
|
2020-03-04 15:42:52 -05:00
|
|
|
|
|
|
|
g_return_if_fail (area_src->hw_cursor_inhibited);
|
|
|
|
|
2020-07-13 11:45:41 -04:00
|
|
|
backend = get_backend (area_src);
|
2020-03-04 15:42:52 -05:00
|
|
|
inhibitor = META_HW_CURSOR_INHIBITOR (area_src);
|
2020-07-13 11:45:41 -04:00
|
|
|
meta_backend_remove_hw_cursor_inhibitor (backend, inhibitor);
|
2020-03-04 15:42:52 -05:00
|
|
|
|
|
|
|
area_src->hw_cursor_inhibited = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
maybe_record_frame_on_idle (gpointer user_data)
|
|
|
|
{
|
|
|
|
MetaScreenCastAreaStreamSrc *area_src =
|
|
|
|
META_SCREEN_CAST_AREA_STREAM_SRC (user_data);
|
|
|
|
MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (area_src);
|
2020-07-03 10:48:52 -04:00
|
|
|
MetaScreenCastRecordFlag flags;
|
2020-03-04 15:42:52 -05:00
|
|
|
|
|
|
|
area_src->maybe_record_idle_id = 0;
|
|
|
|
|
2020-07-03 10:48:52 -04:00
|
|
|
flags = META_SCREEN_CAST_RECORD_FLAG_NONE;
|
|
|
|
meta_screen_cast_stream_src_maybe_record_frame (src, flags);
|
2020-03-04 15:42:52 -05:00
|
|
|
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
2021-06-25 06:54:46 -04:00
|
|
|
static void
|
|
|
|
before_stage_painted (MetaStage *stage,
|
|
|
|
ClutterStageView *view,
|
|
|
|
ClutterPaintContext *paint_context,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
MetaScreenCastAreaStreamSrc *area_src =
|
|
|
|
META_SCREEN_CAST_AREA_STREAM_SRC (user_data);
|
|
|
|
MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (area_src);
|
|
|
|
|
|
|
|
if (area_src->maybe_record_idle_id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!clutter_stage_view_peek_scanout (view))
|
|
|
|
return;
|
|
|
|
|
|
|
|
area_src->maybe_record_idle_id = g_idle_add (maybe_record_frame_on_idle, src);
|
|
|
|
}
|
|
|
|
|
2020-03-04 15:42:52 -05:00
|
|
|
static void
|
|
|
|
stage_painted (MetaStage *stage,
|
|
|
|
ClutterStageView *view,
|
|
|
|
ClutterPaintContext *paint_context,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
MetaScreenCastAreaStreamSrc *area_src =
|
|
|
|
META_SCREEN_CAST_AREA_STREAM_SRC (user_data);
|
|
|
|
MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (area_src);
|
|
|
|
MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
|
|
|
|
MetaScreenCastAreaStream *area_stream = META_SCREEN_CAST_AREA_STREAM (stream);
|
|
|
|
const cairo_region_t *redraw_clip;
|
|
|
|
MetaRectangle *area;
|
|
|
|
|
|
|
|
if (area_src->maybe_record_idle_id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
area = meta_screen_cast_area_stream_get_area (area_stream);
|
|
|
|
redraw_clip = clutter_paint_context_get_redraw_clip (paint_context);
|
|
|
|
|
|
|
|
if (redraw_clip)
|
|
|
|
{
|
|
|
|
switch (cairo_region_contains_rectangle (redraw_clip, area))
|
|
|
|
{
|
|
|
|
case CAIRO_REGION_OVERLAP_IN:
|
|
|
|
case CAIRO_REGION_OVERLAP_PART:
|
|
|
|
break;
|
|
|
|
case CAIRO_REGION_OVERLAP_OUT:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
area_src->maybe_record_idle_id = g_idle_add (maybe_record_frame_on_idle, src);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-06-25 06:53:13 -04:00
|
|
|
add_view_painted_watches (MetaScreenCastAreaStreamSrc *area_src)
|
2020-03-04 15:42:52 -05:00
|
|
|
{
|
|
|
|
MetaScreenCastStreamSrc *src = META_SCREEN_CAST_STREAM_SRC (area_src);
|
|
|
|
MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
|
|
|
|
MetaScreenCastAreaStream *area_stream = META_SCREEN_CAST_AREA_STREAM (stream);
|
|
|
|
MetaBackend *backend = get_backend (area_src);
|
|
|
|
MetaRenderer *renderer = meta_backend_get_renderer (backend);
|
|
|
|
ClutterStage *stage;
|
|
|
|
MetaStage *meta_stage;
|
|
|
|
MetaRectangle *area;
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
stage = get_stage (area_src);
|
|
|
|
meta_stage = META_STAGE (stage);
|
|
|
|
area = meta_screen_cast_area_stream_get_area (area_stream);
|
|
|
|
|
|
|
|
for (l = meta_renderer_get_views (renderer); l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaRendererView *view = l->data;
|
|
|
|
MetaRectangle view_layout;
|
|
|
|
|
|
|
|
clutter_stage_view_get_layout (CLUTTER_STAGE_VIEW (view), &view_layout);
|
|
|
|
if (meta_rectangle_overlap (area, &view_layout))
|
|
|
|
{
|
|
|
|
MetaStageWatch *watch;
|
|
|
|
|
2021-06-25 06:54:46 -04:00
|
|
|
watch = meta_stage_watch_view (meta_stage,
|
|
|
|
CLUTTER_STAGE_VIEW (view),
|
|
|
|
META_STAGE_WATCH_BEFORE_PAINT,
|
|
|
|
before_stage_painted,
|
|
|
|
area_src);
|
|
|
|
|
|
|
|
area_src->watches = g_list_prepend (area_src->watches, watch);
|
|
|
|
|
2020-03-04 15:42:52 -05:00
|
|
|
watch = meta_stage_watch_view (meta_stage,
|
|
|
|
CLUTTER_STAGE_VIEW (view),
|
2021-06-25 06:53:13 -04:00
|
|
|
META_STAGE_WATCH_AFTER_ACTOR_PAINT,
|
2020-03-04 15:42:52 -05:00
|
|
|
stage_painted,
|
|
|
|
area_src);
|
|
|
|
|
|
|
|
area_src->watches = g_list_prepend (area_src->watches, watch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-28 17:21:12 -05:00
|
|
|
static void
|
|
|
|
on_monitors_changed (MetaMonitorManager *monitor_manager,
|
|
|
|
MetaScreenCastAreaStreamSrc *area_src)
|
|
|
|
{
|
|
|
|
MetaStage *stage = META_STAGE (get_stage (area_src));
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
for (l = area_src->watches; l; l = l->next)
|
|
|
|
meta_stage_remove_watch (stage, l->data);
|
|
|
|
g_clear_pointer (&area_src->watches, g_list_free);
|
|
|
|
|
2021-06-25 06:53:13 -04:00
|
|
|
add_view_painted_watches (area_src);
|
2021-01-28 17:21:12 -05:00
|
|
|
}
|
|
|
|
|
2020-03-04 15:42:52 -05:00
|
|
|
static void
|
|
|
|
meta_screen_cast_area_stream_src_enable (MetaScreenCastStreamSrc *src)
|
|
|
|
{
|
|
|
|
MetaScreenCastAreaStreamSrc *area_src =
|
|
|
|
META_SCREEN_CAST_AREA_STREAM_SRC (src);
|
|
|
|
MetaBackend *backend = get_backend (area_src);
|
2021-01-28 17:21:12 -05:00
|
|
|
MetaMonitorManager *monitor_manager =
|
|
|
|
meta_backend_get_monitor_manager (backend);
|
2020-03-04 15:42:52 -05:00
|
|
|
MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
|
|
|
|
ClutterStage *stage;
|
|
|
|
MetaScreenCastStream *stream;
|
|
|
|
|
|
|
|
stream = meta_screen_cast_stream_src_get_stream (src);
|
|
|
|
stage = get_stage (area_src);
|
|
|
|
|
|
|
|
switch (meta_screen_cast_stream_get_cursor_mode (stream))
|
|
|
|
{
|
|
|
|
case META_SCREEN_CAST_CURSOR_MODE_METADATA:
|
2020-07-13 08:09:44 -04:00
|
|
|
area_src->position_invalidated_handler_id =
|
|
|
|
g_signal_connect_after (cursor_tracker, "position-invalidated",
|
|
|
|
G_CALLBACK (pointer_position_invalidated),
|
2020-03-04 15:42:52 -05:00
|
|
|
area_src);
|
|
|
|
area_src->cursor_changed_handler_id =
|
|
|
|
g_signal_connect_after (cursor_tracker, "cursor-changed",
|
|
|
|
G_CALLBACK (cursor_changed),
|
|
|
|
area_src);
|
2022-04-29 10:05:50 -04:00
|
|
|
area_src->prepare_frame_handler_id =
|
|
|
|
g_signal_connect_after (stage, "prepare-frame",
|
|
|
|
G_CALLBACK (on_prepare_frame),
|
|
|
|
area_src);
|
2020-07-29 05:43:44 -04:00
|
|
|
meta_cursor_tracker_track_position (cursor_tracker);
|
2020-03-04 15:42:52 -05:00
|
|
|
G_GNUC_FALLTHROUGH;
|
|
|
|
case META_SCREEN_CAST_CURSOR_MODE_HIDDEN:
|
2021-06-25 06:53:13 -04:00
|
|
|
add_view_painted_watches (area_src);
|
2020-03-04 15:42:52 -05:00
|
|
|
break;
|
|
|
|
case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED:
|
|
|
|
inhibit_hw_cursor (area_src);
|
2020-07-29 05:43:44 -04:00
|
|
|
meta_cursor_tracker_track_position (cursor_tracker);
|
2021-06-25 06:53:13 -04:00
|
|
|
add_view_painted_watches (area_src);
|
2020-03-04 15:42:52 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-01-28 17:21:12 -05:00
|
|
|
g_signal_connect_object (monitor_manager, "monitors-changed-internal",
|
|
|
|
G_CALLBACK (on_monitors_changed),
|
|
|
|
area_src, 0);
|
|
|
|
|
2020-03-04 15:42:52 -05:00
|
|
|
clutter_actor_queue_redraw (CLUTTER_ACTOR (stage));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_screen_cast_area_stream_src_disable (MetaScreenCastStreamSrc *src)
|
|
|
|
{
|
|
|
|
MetaScreenCastAreaStreamSrc *area_src =
|
|
|
|
META_SCREEN_CAST_AREA_STREAM_SRC (src);
|
2020-07-29 05:43:44 -04:00
|
|
|
MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
|
2020-03-04 15:42:52 -05:00
|
|
|
MetaBackend *backend = get_backend (area_src);
|
|
|
|
MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend);
|
|
|
|
ClutterStage *stage;
|
|
|
|
MetaStage *meta_stage;
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
stage = get_stage (area_src);
|
|
|
|
meta_stage = META_STAGE (stage);
|
|
|
|
|
|
|
|
for (l = area_src->watches; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaStageWatch *watch = l->data;
|
|
|
|
|
|
|
|
meta_stage_remove_watch (meta_stage, watch);
|
|
|
|
}
|
|
|
|
g_clear_pointer (&area_src->watches, g_list_free);
|
|
|
|
|
|
|
|
if (area_src->hw_cursor_inhibited)
|
|
|
|
uninhibit_hw_cursor (area_src);
|
|
|
|
|
2020-07-13 08:09:44 -04:00
|
|
|
g_clear_signal_handler (&area_src->position_invalidated_handler_id,
|
2020-03-04 15:42:52 -05:00
|
|
|
cursor_tracker);
|
|
|
|
g_clear_signal_handler (&area_src->cursor_changed_handler_id,
|
|
|
|
cursor_tracker);
|
2022-04-29 10:05:50 -04:00
|
|
|
g_clear_signal_handler (&area_src->prepare_frame_handler_id,
|
|
|
|
stage);
|
2020-03-04 15:42:52 -05:00
|
|
|
|
|
|
|
g_clear_handle_id (&area_src->maybe_record_idle_id, g_source_remove);
|
2020-07-29 05:43:44 -04:00
|
|
|
|
|
|
|
switch (meta_screen_cast_stream_get_cursor_mode (stream))
|
|
|
|
{
|
|
|
|
case META_SCREEN_CAST_CURSOR_MODE_METADATA:
|
|
|
|
case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED:
|
|
|
|
meta_cursor_tracker_untrack_position (cursor_tracker);
|
|
|
|
break;
|
|
|
|
case META_SCREEN_CAST_CURSOR_MODE_HIDDEN:
|
|
|
|
break;
|
|
|
|
}
|
2020-03-04 15:42:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2020-07-03 10:57:01 -04:00
|
|
|
meta_screen_cast_area_stream_src_record_to_buffer (MetaScreenCastStreamSrc *src,
|
2021-02-01 03:17:15 -05:00
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int stride,
|
2020-07-03 10:57:01 -04:00
|
|
|
uint8_t *data,
|
|
|
|
GError **error)
|
2020-03-04 15:42:52 -05:00
|
|
|
{
|
|
|
|
MetaScreenCastAreaStreamSrc *area_src =
|
|
|
|
META_SCREEN_CAST_AREA_STREAM_SRC (src);
|
|
|
|
MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
|
|
|
|
MetaScreenCastAreaStream *area_stream = META_SCREEN_CAST_AREA_STREAM (stream);
|
|
|
|
ClutterStage *stage;
|
|
|
|
MetaRectangle *area;
|
|
|
|
float scale;
|
2020-09-30 11:40:10 -04:00
|
|
|
ClutterPaintFlag paint_flags = CLUTTER_PAINT_FLAG_CLEAR;
|
2020-03-04 15:42:52 -05:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
switch (meta_screen_cast_stream_get_cursor_mode (stream))
|
|
|
|
{
|
|
|
|
case META_SCREEN_CAST_CURSOR_MODE_METADATA:
|
|
|
|
case META_SCREEN_CAST_CURSOR_MODE_HIDDEN:
|
|
|
|
paint_flags |= CLUTTER_PAINT_FLAG_NO_CURSORS;
|
|
|
|
break;
|
|
|
|
case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED:
|
2020-07-29 05:43:44 -04:00
|
|
|
paint_flags |= CLUTTER_PAINT_FLAG_FORCE_CURSORS;
|
2020-03-04 15:42:52 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!clutter_stage_paint_to_buffer (stage, area, scale,
|
|
|
|
data,
|
|
|
|
stride,
|
|
|
|
CLUTTER_CAIRO_FORMAT_ARGB32,
|
|
|
|
paint_flags,
|
2020-07-03 10:57:01 -04:00
|
|
|
error))
|
|
|
|
return FALSE;
|
2020-03-04 15:42:52 -05:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2020-07-03 10:57:01 -04:00
|
|
|
meta_screen_cast_area_stream_src_record_to_framebuffer (MetaScreenCastStreamSrc *src,
|
|
|
|
CoglFramebuffer *framebuffer,
|
|
|
|
GError **error)
|
2020-03-04 15:42:52 -05:00
|
|
|
{
|
|
|
|
MetaScreenCastAreaStreamSrc *area_src =
|
|
|
|
META_SCREEN_CAST_AREA_STREAM_SRC (src);
|
|
|
|
MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
|
|
|
|
MetaScreenCastAreaStream *area_stream = META_SCREEN_CAST_AREA_STREAM (stream);
|
|
|
|
MetaBackend *backend = get_backend (area_src);
|
|
|
|
ClutterStage *stage;
|
|
|
|
MetaRectangle *area;
|
|
|
|
float scale;
|
2020-09-30 11:40:10 -04:00
|
|
|
ClutterPaintFlag paint_flags = CLUTTER_PAINT_FLAG_CLEAR;
|
2020-03-04 15:42:52 -05:00
|
|
|
|
|
|
|
stage = CLUTTER_STAGE (meta_backend_get_stage (backend));
|
|
|
|
area = meta_screen_cast_area_stream_get_area (area_stream);
|
|
|
|
scale = meta_screen_cast_area_stream_get_scale (area_stream);
|
|
|
|
|
|
|
|
switch (meta_screen_cast_stream_get_cursor_mode (stream))
|
|
|
|
{
|
|
|
|
case META_SCREEN_CAST_CURSOR_MODE_METADATA:
|
|
|
|
case META_SCREEN_CAST_CURSOR_MODE_HIDDEN:
|
|
|
|
paint_flags |= CLUTTER_PAINT_FLAG_NO_CURSORS;
|
|
|
|
break;
|
|
|
|
case META_SCREEN_CAST_CURSOR_MODE_EMBEDDED:
|
2020-07-29 05:43:44 -04:00
|
|
|
paint_flags |= CLUTTER_PAINT_FLAG_FORCE_CURSORS;
|
2020-03-04 15:42:52 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
clutter_stage_paint_to_framebuffer (stage, framebuffer,
|
|
|
|
area, scale,
|
|
|
|
paint_flags);
|
|
|
|
|
2021-01-27 06:50:46 -05:00
|
|
|
cogl_framebuffer_flush (framebuffer);
|
2020-03-04 15:42:52 -05:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-07-03 17:57:31 -04:00
|
|
|
static void
|
|
|
|
meta_screen_cast_area_stream_record_follow_up (MetaScreenCastStreamSrc *src)
|
|
|
|
{
|
|
|
|
MetaScreenCastAreaStreamSrc *area_src =
|
|
|
|
META_SCREEN_CAST_AREA_STREAM_SRC (src);
|
|
|
|
MetaScreenCastRecordFlag flags;
|
|
|
|
|
|
|
|
g_clear_handle_id (&area_src->maybe_record_idle_id, g_source_remove);
|
|
|
|
|
|
|
|
flags = META_SCREEN_CAST_RECORD_FLAG_NONE;
|
|
|
|
meta_screen_cast_stream_src_maybe_record_frame (src, flags);
|
|
|
|
}
|
|
|
|
|
2020-03-04 15:42:52 -05:00
|
|
|
static void
|
|
|
|
meta_screen_cast_area_stream_src_set_cursor_metadata (MetaScreenCastStreamSrc *src,
|
|
|
|
struct spa_meta_cursor *spa_meta_cursor)
|
|
|
|
{
|
|
|
|
MetaScreenCastAreaStreamSrc *area_src =
|
|
|
|
META_SCREEN_CAST_AREA_STREAM_SRC (src);
|
|
|
|
MetaScreenCastStream *stream = meta_screen_cast_stream_src_get_stream (src);
|
|
|
|
MetaScreenCastAreaStream *area_stream = META_SCREEN_CAST_AREA_STREAM (stream);
|
|
|
|
MetaBackend *backend = get_backend (area_src);
|
|
|
|
MetaCursorRenderer *cursor_renderer =
|
|
|
|
meta_backend_get_cursor_renderer (backend);
|
2020-09-01 09:25:02 -04:00
|
|
|
MetaCursorTracker *cursor_tracker =
|
|
|
|
meta_backend_get_cursor_tracker (backend);
|
2020-03-04 15:42:52 -05:00
|
|
|
MetaCursorSprite *cursor_sprite;
|
|
|
|
MetaRectangle *area;
|
|
|
|
float scale;
|
|
|
|
graphene_point_t cursor_position;
|
|
|
|
int x, y;
|
|
|
|
|
|
|
|
cursor_sprite = meta_cursor_renderer_get_cursor (cursor_renderer);
|
|
|
|
|
2020-09-01 09:25:02 -04:00
|
|
|
if (!meta_cursor_tracker_get_pointer_visible (cursor_tracker) ||
|
|
|
|
!is_cursor_in_stream (area_src))
|
2020-03-04 15:42:52 -05:00
|
|
|
{
|
|
|
|
meta_screen_cast_stream_src_unset_cursor_metadata (src,
|
|
|
|
spa_meta_cursor);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
area = meta_screen_cast_area_stream_get_area (area_stream);
|
|
|
|
scale = meta_screen_cast_area_stream_get_scale (area_stream);
|
|
|
|
|
2020-07-13 06:28:46 -04:00
|
|
|
meta_cursor_tracker_get_pointer (cursor_tracker, &cursor_position, NULL);
|
2020-03-04 15:42:52 -05:00
|
|
|
cursor_position.x -= area->x;
|
|
|
|
cursor_position.y -= area->y;
|
|
|
|
cursor_position.x *= scale;
|
|
|
|
cursor_position.y *= scale;
|
|
|
|
|
|
|
|
x = (int) roundf (cursor_position.x);
|
|
|
|
y = (int) roundf (cursor_position.y);
|
|
|
|
|
|
|
|
if (area_src->cursor_bitmap_invalid)
|
|
|
|
{
|
|
|
|
if (cursor_sprite)
|
|
|
|
{
|
|
|
|
float cursor_scale;
|
|
|
|
float metadata_scale;
|
2022-07-02 12:50:45 -04:00
|
|
|
MetaMonitorTransform transform;
|
2020-03-04 15:42:52 -05:00
|
|
|
|
|
|
|
cursor_scale = meta_cursor_sprite_get_texture_scale (cursor_sprite);
|
|
|
|
metadata_scale = scale * cursor_scale;
|
2022-07-02 12:50:45 -04:00
|
|
|
transform = meta_cursor_sprite_get_texture_transform (cursor_sprite);
|
|
|
|
|
2020-03-04 15:42:52 -05:00
|
|
|
meta_screen_cast_stream_src_set_cursor_sprite_metadata (src,
|
|
|
|
spa_meta_cursor,
|
|
|
|
cursor_sprite,
|
|
|
|
x, y,
|
2022-07-02 12:50:45 -04:00
|
|
|
transform,
|
2020-03-04 15:42:52 -05:00
|
|
|
metadata_scale);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
meta_screen_cast_stream_src_set_empty_cursor_sprite_metadata (src,
|
|
|
|
spa_meta_cursor,
|
|
|
|
x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
area_src->cursor_bitmap_invalid = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
meta_screen_cast_stream_src_set_cursor_position_metadata (src,
|
|
|
|
spa_meta_cursor,
|
|
|
|
x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2020-07-13 11:29:51 -04:00
|
|
|
meta_screen_cast_area_stream_src_is_cursor_inhibited (MetaHwCursorInhibitor *inhibitor)
|
2020-03-04 15:42:52 -05:00
|
|
|
{
|
|
|
|
MetaScreenCastAreaStreamSrc *area_src =
|
|
|
|
META_SCREEN_CAST_AREA_STREAM_SRC (inhibitor);
|
|
|
|
|
|
|
|
return is_cursor_in_stream (area_src);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
hw_cursor_inhibitor_iface_init (MetaHwCursorInhibitorInterface *iface)
|
|
|
|
{
|
2020-07-13 11:29:51 -04:00
|
|
|
iface->is_cursor_inhibited =
|
|
|
|
meta_screen_cast_area_stream_src_is_cursor_inhibited;
|
2020-03-04 15:42:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
MetaScreenCastAreaStreamSrc *
|
|
|
|
meta_screen_cast_area_stream_src_new (MetaScreenCastAreaStream *area_stream,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
return g_initable_new (META_TYPE_SCREEN_CAST_AREA_STREAM_SRC, NULL, error,
|
|
|
|
"stream", area_stream,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_screen_cast_area_stream_src_init (MetaScreenCastAreaStreamSrc *area_src)
|
|
|
|
{
|
|
|
|
area_src->cursor_bitmap_invalid = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_screen_cast_area_stream_src_class_init (MetaScreenCastAreaStreamSrcClass *klass)
|
|
|
|
{
|
|
|
|
MetaScreenCastStreamSrcClass *src_class =
|
|
|
|
META_SCREEN_CAST_STREAM_SRC_CLASS (klass);
|
|
|
|
|
|
|
|
src_class->get_specs = meta_screen_cast_area_stream_src_get_specs;
|
|
|
|
src_class->enable = meta_screen_cast_area_stream_src_enable;
|
|
|
|
src_class->disable = meta_screen_cast_area_stream_src_disable;
|
2020-07-03 10:42:45 -04:00
|
|
|
src_class->record_to_buffer =
|
|
|
|
meta_screen_cast_area_stream_src_record_to_buffer;
|
|
|
|
src_class->record_to_framebuffer =
|
|
|
|
meta_screen_cast_area_stream_src_record_to_framebuffer;
|
2020-07-03 17:57:31 -04:00
|
|
|
src_class->record_follow_up =
|
|
|
|
meta_screen_cast_area_stream_record_follow_up;
|
2020-03-04 15:42:52 -05:00
|
|
|
src_class->set_cursor_metadata =
|
|
|
|
meta_screen_cast_area_stream_src_set_cursor_metadata;
|
|
|
|
}
|