renderer: Add API to get a view list for a monitor

Where renderer views correspond to CRTCs, this will result in a list of
those views; otherwise (i.e. X11 CM), it'll result in a list containing
the global view.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1285
This commit is contained in:
Jonas Ådahl 2020-04-01 11:14:46 +02:00
parent 9ed463b488
commit feb444402e
3 changed files with 84 additions and 0 deletions

View File

@ -172,6 +172,75 @@ meta_renderer_real_rebuild_views (MetaRenderer *renderer)
}
}
static MetaRendererView *
meta_renderer_get_view_for_crtc (MetaRenderer *renderer,
MetaCrtc *crtc)
{
MetaRendererPrivate *priv = meta_renderer_get_instance_private (renderer);
GList *l;
for (l = priv->views; l; l = l->next)
{
MetaRendererView *view = l->data;
if (meta_renderer_view_get_crtc (view) == crtc)
return view;
}
return NULL;
}
typedef struct _CollectViewsData
{
MetaRenderer *renderer;
GList *out_views;
} CollectViewsData;
static gboolean
collect_views (MetaMonitor *monitor,
MetaMonitorMode *mode,
MetaMonitorCrtcMode *monitor_crtc_mode,
gpointer user_data,
GError **error)
{
CollectViewsData *data = user_data;
MetaCrtc *crtc;
MetaRendererView *view;
crtc = meta_output_get_assigned_crtc (monitor_crtc_mode->output);
view = meta_renderer_get_view_for_crtc (data->renderer, crtc);
if (!g_list_find (data->out_views, view))
data->out_views = g_list_prepend (data->out_views, view);
return TRUE;
}
static GList *
meta_renderer_real_get_views_for_monitor (MetaRenderer *renderer,
MetaMonitor *monitor)
{
CollectViewsData data = { 0 };
MetaMonitorMode *monitor_mode;
data.renderer = renderer;
monitor_mode = meta_monitor_get_current_mode (monitor);
meta_monitor_mode_foreach_crtc (monitor, monitor_mode,
collect_views,
&data,
NULL);
return data.out_views;
}
GList *
meta_renderer_get_views_for_monitor (MetaRenderer *renderer,
MetaMonitor *monitor)
{
return META_RENDERER_GET_CLASS (renderer)->get_views_for_monitor (renderer,
monitor);
}
void
meta_renderer_add_view (MetaRenderer *renderer,
MetaRendererView *view)
@ -278,6 +347,7 @@ meta_renderer_class_init (MetaRendererClass *klass)
object_class->finalize = meta_renderer_finalize;
klass->rebuild_views = meta_renderer_real_rebuild_views;
klass->get_views_for_monitor = meta_renderer_real_get_views_for_monitor;
obj_props[PROP_BACKEND] =
g_param_spec_object ("backend",

View File

@ -46,6 +46,8 @@ struct _MetaRendererClass
MetaOutput *output,
MetaCrtc *crtc);
void (* rebuild_views) (MetaRenderer *renderer);
GList * (* get_views_for_monitor) (MetaRenderer *renderer,
MetaMonitor *monitor);
};
MetaBackend * meta_renderer_get_backend (MetaRenderer *renderer);
@ -57,6 +59,9 @@ void meta_renderer_rebuild_views (MetaRenderer *renderer);
void meta_renderer_add_view (MetaRenderer *renderer,
MetaRendererView *view);
GList * meta_renderer_get_views_for_monitor (MetaRenderer *renderer,
MetaMonitor *monitor);
META_EXPORT_TEST
GList * meta_renderer_get_views (MetaRenderer *renderer);

View File

@ -94,6 +94,13 @@ meta_renderer_x11_cm_rebuild_views (MetaRenderer *renderer)
meta_renderer_add_view (renderer, renderer_x11_cm->screen_view);
}
static GList *
meta_renderer_x11_cm_get_views_for_monitor (MetaRenderer *renderer,
MetaMonitor *monitor)
{
return g_list_prepend (NULL, meta_renderer_get_views (renderer)->data);
}
static void
meta_renderer_x11_cm_init (MetaRendererX11Cm *renderer_x11_cm)
{
@ -105,4 +112,6 @@ meta_renderer_x11_cm_class_init (MetaRendererX11CmClass *klass)
MetaRendererClass *renderer_class = META_RENDERER_CLASS (klass);
renderer_class->rebuild_views = meta_renderer_x11_cm_rebuild_views;
renderer_class->get_views_for_monitor =
meta_renderer_x11_cm_get_views_for_monitor;
}