logical-monitor: Don't duplicate output list

Just use the monitor list and the output lists of each monitor.

https://bugzilla.gnome.org/show_bug.cgi?id=777732
This commit is contained in:
Jonas Ådahl 2016-12-13 21:44:16 +08:00
parent 310064601c
commit ff633f295e
5 changed files with 82 additions and 45 deletions

View File

@ -36,7 +36,6 @@ meta_logical_monitor_new (MetaMonitor *monitor,
GList *outputs;
GList *l;
gboolean is_presentation;
int i;
g_assert (meta_monitor_is_active (monitor));
@ -59,20 +58,15 @@ meta_logical_monitor_new (MetaMonitor *monitor,
is_presentation = TRUE;
outputs = meta_monitor_get_outputs (monitor);
for (l = outputs, i = 0; l; l = l->next, i++)
for (l = outputs; l; l = l->next)
{
MetaOutput *output = l->data;
output->crtc->logical_monitor = logical_monitor;
if (i <= META_MAX_OUTPUTS_PER_MONITOR)
logical_monitor->outputs[i] = output;
else
g_warning ("Couldn't add all outputs to monitor");
is_presentation = is_presentation && output->is_presentation;
}
logical_monitor->n_outputs = MIN (i, META_MAX_OUTPUTS_PER_MONITOR);
logical_monitor->is_presentation = is_presentation;
logical_monitor->monitors = g_list_append (logical_monitor->monitors,
@ -85,30 +79,29 @@ void
meta_logical_monitor_add_monitor (MetaLogicalMonitor *logical_monitor,
MetaMonitor *monitor)
{
GList *outputs;
GList *l;
gboolean is_presentation;
int i;
is_presentation = logical_monitor->is_presentation;
logical_monitor->monitors = g_list_append (logical_monitor->monitors,
monitor);
outputs = meta_monitor_get_outputs (monitor);
for (l = outputs, i = logical_monitor->n_outputs; l; l = l->next, i++)
for (l = logical_monitor->monitors; l; l = l->next)
{
MetaOutput *output = l->data;
MetaMonitor *monitor = l->data;
GList *outputs;
GList *l_output;
output->crtc->logical_monitor = logical_monitor;
outputs = meta_monitor_get_outputs (monitor);
for (l_output = outputs; l_output; l_output = l_output->next)
{
MetaOutput *output = l_output->data;
if (i <= META_MAX_OUTPUTS_PER_MONITOR)
logical_monitor->outputs[i] = output;
else
g_warning ("Couldn't add all outputs to monitor");
is_presentation = is_presentation && output->is_presentation;
is_presentation = is_presentation && output->is_presentation;
output->crtc->logical_monitor = logical_monitor;
}
}
logical_monitor->n_outputs = MIN (i, META_MAX_OUTPUTS_PER_MONITOR);
logical_monitor->is_presentation = is_presentation;
}
@ -124,6 +117,12 @@ meta_logical_monitor_make_primary (MetaLogicalMonitor *logical_monitor)
logical_monitor->is_primary = TRUE;
}
GList *
meta_logical_monitor_get_monitors (MetaLogicalMonitor *logical_monitor)
{
return logical_monitor->monitors;
}
static void
meta_logical_monitor_init (MetaLogicalMonitor *logical_monitor)
{

View File

@ -55,9 +55,6 @@ struct _MetaLogicalMonitor
*/
glong winsys_id;
int n_outputs;
MetaOutput *outputs[META_MAX_OUTPUTS_PER_MONITOR];
GList *monitors;
};
@ -78,4 +75,6 @@ gboolean meta_logical_monitor_is_primary (MetaLogicalMonitor *logical_monitor);
void meta_logical_monitor_make_primary (MetaLogicalMonitor *logical_monitor);
GList * meta_logical_monitor_get_monitors (MetaLogicalMonitor *logical_monitor);
#endif /* META_LOGICAL_MONITOR_H */

View File

@ -968,20 +968,14 @@ meta_renderer_native_create_surface_egl_device (MetaRendererNative *renderer_nat
CoglRenderer *cogl_renderer = cogl_display->renderer;
CoglRendererEGL *egl_renderer = cogl_renderer->winsys;
EGLDisplay egl_display = egl_renderer->edpy;
MetaMonitor *monitor;
MetaOutput *output;
EGLConfig egl_config;
EGLStreamKHR egl_stream;
EGLSurface egl_surface;
EGLint num_layers;
EGLOutputLayerEXT output_layer;
EGLAttrib output_attribs[] = {
/*
* An "logical_monitor" may have multiple outputs/crtcs in case its tiled,
* but as far as I can tell, EGL only allows you to pass one crtc_id, so
* lets pass the first one.
*/
EGL_DRM_CRTC_EXT, logical_monitor->outputs[0]->crtc->crtc_id,
EGL_NONE,
};
EGLAttrib output_attribs[3];
EGLint stream_attribs[] = {
EGL_STREAM_FIFO_LENGTH_KHR, 1,
EGL_CONSUMER_AUTO_ACQUIRE_EXT, EGL_FALSE,
@ -997,6 +991,18 @@ meta_renderer_native_create_surface_egl_device (MetaRendererNative *renderer_nat
if (egl_stream == EGL_NO_STREAM_KHR)
return FALSE;
monitor = meta_logical_monitor_get_monitors (logical_monitor)->data;
output = meta_monitor_get_main_output (monitor);
/*
* An "logical_monitor" may have multiple outputs/crtcs in case its tiled,
* but as far as I can tell, EGL only allows you to pass one crtc_id, so
* lets pass the first one.
*/
output_attribs[0] = EGL_DRM_CRTC_EXT;
output_attribs[1] = output->crtc->crtc_id;
output_attribs[2] = EGL_NONE;
if (!meta_egl_get_output_layers (egl, egl_display,
output_attribs,
&output_layer, 1, &num_layers,
@ -1394,11 +1400,14 @@ meta_renderer_native_get_logical_monitor_transform (MetaRenderer *renderer
meta_backend_get_monitor_manager (backend);
MetaMonitorManagerKms *monitor_manager_kms =
META_MONITOR_MANAGER_KMS (monitor_manager);
MetaMonitor *monitor;
MetaOutput *output;
g_assert (logical_monitor->n_outputs > 0);
monitor = meta_logical_monitor_get_monitors (logical_monitor)->data;
output = meta_monitor_get_main_output (monitor);
return meta_monitor_manager_kms_get_view_transform (monitor_manager_kms,
logical_monitor->outputs[0]->crtc);
output->crtc);
}
static CoglOnscreen *

View File

@ -305,7 +305,8 @@ check_monitor_configuration (MonitorTestCase *test_case)
MetaLogicalMonitor *logical_monitor = l->data;
MonitorTestCaseLogicalMonitor *test_logical_monitor =
&test_case->expect.logical_monitors[i];
int j;
GList *monitors;
GList *l_monitor;
g_assert (logical_monitor->rect.x == test_logical_monitor->layout.x);
g_assert (logical_monitor->rect.y == test_logical_monitor->layout.y);
@ -315,11 +316,20 @@ check_monitor_configuration (MonitorTestCase *test_case)
test_logical_monitor->layout.height);
g_assert (logical_monitor->scale == test_logical_monitor->scale);
for (j = 0; j < logical_monitor->n_outputs; j++)
monitors = meta_logical_monitor_get_monitors (logical_monitor);
for (l_monitor = monitors; l_monitor; l_monitor = l_monitor->next)
{
MetaOutput *output = logical_monitor->outputs[j];
MetaMonitor *monitor = l_monitor->data;
GList *outputs;
GList *l_output;
g_assert (output->crtc->logical_monitor == logical_monitor);
outputs = meta_monitor_get_outputs (monitor);
for (l_output = outputs; l_output; l_output = l_output->next)
{
MetaOutput *output = l_output->data;
g_assert (output->crtc->logical_monitor == logical_monitor);
}
}
}
g_assert (n_logical_monitors == i);

View File

@ -54,6 +54,17 @@ output_resource_destroy (struct wl_resource *res)
wayland_output->resources = g_list_remove (wayland_output->resources, res);
}
static MetaOutput *
pick_main_output (MetaLogicalMonitor *logical_monitor)
{
GList *monitors;
MetaMonitor *monitor;
monitors = meta_logical_monitor_get_monitors (logical_monitor);
monitor = g_list_first (monitors)->data;
return meta_monitor_get_main_output (monitor);
}
static void
send_output_events (struct wl_resource *resource,
MetaWaylandOutput *wayland_output,
@ -61,11 +72,17 @@ send_output_events (struct wl_resource *resource,
gboolean need_all_events)
{
int version = wl_resource_get_version (resource);
MetaOutput *output = logical_monitor->outputs[0];
MetaOutput *output;
guint mode_flags = WL_OUTPUT_MODE_CURRENT;
MetaLogicalMonitor *old_logical_monitor = wayland_output->logical_monitor;
guint old_mode_flags = wayland_output->mode_flags;
gint old_scale = wayland_output->scale;
MetaLogicalMonitor *old_logical_monitor;
guint old_mode_flags;
gint old_scale;
old_logical_monitor = wayland_output->logical_monitor;
old_mode_flags = wayland_output->mode_flags;
old_scale = wayland_output->scale;
output = pick_main_output (logical_monitor);
gboolean need_done = FALSE;
@ -131,7 +148,7 @@ bind_output (struct wl_client *client,
MetaWaylandOutput *wayland_output = data;
MetaLogicalMonitor *logical_monitor = wayland_output->logical_monitor;
struct wl_resource *resource;
MetaOutput *output = logical_monitor->outputs[0];
MetaOutput *output;
resource = wl_resource_create (client, &wl_output_interface, version, id);
wayland_output->resources = g_list_prepend (wayland_output->resources, resource);
@ -139,6 +156,7 @@ bind_output (struct wl_client *client,
wl_resource_set_user_data (resource, wayland_output);
wl_resource_set_destructor (resource, output_resource_destroy);
output = pick_main_output (logical_monitor);
meta_verbose ("Binding monitor %p/%s (%u, %u, %u, %u) x %f\n",
logical_monitor, output->name,
logical_monitor->rect.x, logical_monitor->rect.y,
@ -161,10 +179,12 @@ static void
meta_wayland_output_set_logical_monitor (MetaWaylandOutput *wayland_output,
MetaLogicalMonitor *logical_monitor)
{
MetaOutput *output = logical_monitor->outputs[0];
MetaOutput *output;
wayland_output->logical_monitor = logical_monitor;
wayland_output->mode_flags = WL_OUTPUT_MODE_CURRENT;
output = pick_main_output (logical_monitor);
if (output->crtc->current_mode == output->preferred_mode)
wayland_output->mode_flags |= WL_OUTPUT_MODE_PREFERRED;
wayland_output->scale = output->scale;