2016-12-05 05:38:43 -05:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "tests/meta-monitor-manager-test.h"
|
|
|
|
|
2017-01-09 01:31:18 -05:00
|
|
|
#include "backends/meta-monitor-config-manager.h"
|
|
|
|
|
2016-12-05 05:38:43 -05:00
|
|
|
struct _MetaMonitorManagerTest
|
|
|
|
{
|
|
|
|
MetaMonitorManager parent;
|
2016-12-05 08:28:22 -05:00
|
|
|
|
2017-01-09 22:50:44 -05:00
|
|
|
gboolean is_lid_closed;
|
|
|
|
|
2016-12-13 07:11:48 -05:00
|
|
|
int tiled_monitor_count;
|
|
|
|
|
2016-12-05 08:28:22 -05:00
|
|
|
MetaMonitorTestSetup *test_setup;
|
2016-12-05 05:38:43 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (MetaMonitorManagerTest, meta_monitor_manager_test,
|
|
|
|
META_TYPE_MONITOR_MANAGER)
|
|
|
|
|
2016-12-05 08:28:22 -05:00
|
|
|
static MetaMonitorTestSetup *_initial_test_setup = NULL;
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_monitor_manager_test_init_test_setup (MetaMonitorTestSetup *test_setup)
|
|
|
|
{
|
|
|
|
_initial_test_setup = test_setup;
|
|
|
|
}
|
|
|
|
|
2016-12-07 04:39:53 -05:00
|
|
|
void
|
|
|
|
meta_monitor_manager_test_emulate_hotplug (MetaMonitorManagerTest *manager_test,
|
|
|
|
MetaMonitorTestSetup *test_setup)
|
|
|
|
{
|
|
|
|
MetaMonitorManager *manager = META_MONITOR_MANAGER (manager_test);
|
|
|
|
MetaMonitorTestSetup *old_test_setup;
|
|
|
|
|
|
|
|
old_test_setup = manager_test->test_setup;
|
|
|
|
manager_test->test_setup = test_setup;
|
|
|
|
|
2016-12-19 02:46:31 -05:00
|
|
|
meta_monitor_manager_read_current_state (manager);
|
2016-12-07 04:39:53 -05:00
|
|
|
meta_monitor_manager_on_hotplug (manager);
|
|
|
|
|
|
|
|
g_free (old_test_setup);
|
|
|
|
}
|
|
|
|
|
2017-01-09 22:50:44 -05:00
|
|
|
void
|
|
|
|
meta_monitor_manager_test_set_is_lid_closed (MetaMonitorManagerTest *manager_test,
|
|
|
|
gboolean is_lid_closed)
|
|
|
|
{
|
|
|
|
manager_test->is_lid_closed = is_lid_closed;
|
|
|
|
}
|
|
|
|
|
2016-12-13 07:11:48 -05:00
|
|
|
int
|
|
|
|
meta_monitor_manager_test_get_tiled_monitor_count (MetaMonitorManagerTest *manager_test)
|
|
|
|
{
|
|
|
|
return manager_test->tiled_monitor_count;
|
|
|
|
}
|
|
|
|
|
2016-12-05 05:38:43 -05:00
|
|
|
static void
|
|
|
|
meta_monitor_manager_test_read_current (MetaMonitorManager *manager)
|
|
|
|
{
|
2016-12-05 08:28:22 -05:00
|
|
|
MetaMonitorManagerTest *manager_test = META_MONITOR_MANAGER_TEST (manager);
|
2016-12-05 05:38:43 -05:00
|
|
|
|
|
|
|
manager->max_screen_width = 65535;
|
|
|
|
manager->max_screen_height = 65535;
|
|
|
|
|
2016-12-05 08:28:22 -05:00
|
|
|
g_assert (manager_test->test_setup);
|
2016-12-05 05:38:43 -05:00
|
|
|
|
2016-12-05 08:28:22 -05:00
|
|
|
manager->modes = manager_test->test_setup->modes;
|
|
|
|
manager->n_modes = manager_test->test_setup->n_modes;
|
2016-12-05 05:38:43 -05:00
|
|
|
|
2016-12-05 08:28:22 -05:00
|
|
|
manager->crtcs = manager_test->test_setup->crtcs;
|
|
|
|
manager->n_crtcs = manager_test->test_setup->n_crtcs;
|
2016-12-05 05:38:43 -05:00
|
|
|
|
2016-12-05 08:28:22 -05:00
|
|
|
manager->outputs = manager_test->test_setup->outputs;
|
|
|
|
manager->n_outputs = manager_test->test_setup->n_outputs;
|
2016-12-05 05:38:43 -05:00
|
|
|
}
|
|
|
|
|
2017-01-09 21:59:31 -05:00
|
|
|
static gboolean
|
|
|
|
meta_monitor_manager_test_is_lid_closed (MetaMonitorManager *manager)
|
|
|
|
{
|
2017-01-09 22:50:44 -05:00
|
|
|
MetaMonitorManagerTest *manager_test = META_MONITOR_MANAGER_TEST (manager);
|
|
|
|
|
|
|
|
return manager_test->is_lid_closed;
|
2017-01-09 21:59:31 -05:00
|
|
|
}
|
|
|
|
|
2017-01-06 00:27:21 -05:00
|
|
|
static void
|
|
|
|
meta_monitor_manager_test_ensure_initial_config (MetaMonitorManager *manager)
|
|
|
|
{
|
2017-01-09 01:31:18 -05:00
|
|
|
MetaMonitorsConfig *config;
|
|
|
|
|
|
|
|
config = meta_monitor_manager_ensure_configured (manager);
|
2017-01-06 00:27:21 -05:00
|
|
|
|
2017-01-09 01:31:18 -05:00
|
|
|
if (manager->config_manager)
|
|
|
|
meta_monitor_manager_update_logical_state (manager, config);
|
|
|
|
else
|
|
|
|
meta_monitor_manager_update_logical_state_derived (manager);
|
2017-01-06 00:27:21 -05:00
|
|
|
}
|
|
|
|
|
2016-12-05 05:38:43 -05:00
|
|
|
static void
|
2017-01-09 01:31:18 -05:00
|
|
|
apply_crtc_assignments (MetaMonitorManager *manager,
|
|
|
|
MetaCrtcInfo **crtcs,
|
|
|
|
unsigned int n_crtcs,
|
|
|
|
MetaOutputInfo **outputs,
|
|
|
|
unsigned int n_outputs)
|
2016-12-05 05:38:43 -05:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < n_crtcs; i++)
|
|
|
|
{
|
2016-12-07 23:15:28 -05:00
|
|
|
MetaCrtcInfo *crtc_info = crtcs[i];
|
|
|
|
MetaCrtc *crtc = crtc_info->crtc;
|
2016-12-05 05:38:43 -05:00
|
|
|
crtc->is_dirty = TRUE;
|
|
|
|
|
|
|
|
if (crtc_info->mode == NULL)
|
|
|
|
{
|
|
|
|
crtc->rect.x = 0;
|
|
|
|
crtc->rect.y = 0;
|
|
|
|
crtc->rect.width = 0;
|
|
|
|
crtc->rect.height = 0;
|
|
|
|
crtc->current_mode = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-12-09 02:49:54 -05:00
|
|
|
MetaCrtcMode *mode;
|
2016-12-05 05:38:43 -05:00
|
|
|
MetaOutput *output;
|
|
|
|
unsigned int j;
|
|
|
|
int width, height;
|
|
|
|
|
|
|
|
mode = crtc_info->mode;
|
|
|
|
|
|
|
|
if (meta_monitor_transform_is_rotated (crtc_info->transform))
|
|
|
|
{
|
|
|
|
width = mode->height;
|
|
|
|
height = mode->width;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
width = mode->width;
|
|
|
|
height = mode->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
crtc->rect.x = crtc_info->x;
|
|
|
|
crtc->rect.y = crtc_info->y;
|
|
|
|
crtc->rect.width = width;
|
|
|
|
crtc->rect.height = height;
|
|
|
|
crtc->current_mode = mode;
|
|
|
|
crtc->transform = crtc_info->transform;
|
|
|
|
|
|
|
|
for (j = 0; j < crtc_info->outputs->len; j++)
|
|
|
|
{
|
|
|
|
output = ((MetaOutput**)crtc_info->outputs->pdata)[j];
|
|
|
|
|
|
|
|
output->is_dirty = TRUE;
|
|
|
|
output->crtc = crtc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < n_outputs; i++)
|
|
|
|
{
|
|
|
|
MetaOutputInfo *output_info = outputs[i];
|
|
|
|
MetaOutput *output = output_info->output;
|
|
|
|
|
|
|
|
output->is_primary = output_info->is_primary;
|
|
|
|
output->is_presentation = output_info->is_presentation;
|
2017-01-16 22:34:23 -05:00
|
|
|
output->is_underscanning = output_info->is_underscanning;
|
2016-12-05 05:38:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable CRTCs not mentioned in the list */
|
|
|
|
for (i = 0; i < manager->n_crtcs; i++)
|
|
|
|
{
|
2016-12-07 23:15:28 -05:00
|
|
|
MetaCrtc *crtc = &manager->crtcs[i];
|
2016-12-05 05:38:43 -05:00
|
|
|
|
|
|
|
crtc->logical_monitor = NULL;
|
|
|
|
|
|
|
|
if (crtc->is_dirty)
|
|
|
|
{
|
|
|
|
crtc->is_dirty = FALSE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
crtc->rect.x = 0;
|
|
|
|
crtc->rect.y = 0;
|
|
|
|
crtc->rect.width = 0;
|
|
|
|
crtc->rect.height = 0;
|
|
|
|
crtc->current_mode = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable outputs not mentioned in the list */
|
|
|
|
for (i = 0; i < manager->n_outputs; i++)
|
|
|
|
{
|
|
|
|
MetaOutput *output = &manager->outputs[i];
|
|
|
|
|
|
|
|
if (output->is_dirty)
|
|
|
|
{
|
|
|
|
output->is_dirty = FALSE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
output->crtc = NULL;
|
|
|
|
output->is_primary = FALSE;
|
|
|
|
}
|
2017-01-09 01:31:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_screen_size (MetaMonitorManager *manager,
|
|
|
|
MetaMonitorsConfig *config)
|
|
|
|
{
|
|
|
|
GList *l;
|
|
|
|
int screen_width = 0;
|
|
|
|
int screen_height = 0;
|
|
|
|
|
|
|
|
for (l = config->logical_monitor_configs; l; l = l->next)
|
|
|
|
{
|
|
|
|
MetaLogicalMonitorConfig *logical_monitor_config = l->data;
|
|
|
|
int right_edge;
|
|
|
|
int bottom_edge;
|
|
|
|
|
|
|
|
right_edge = (logical_monitor_config->layout.width +
|
|
|
|
logical_monitor_config->layout.x);
|
|
|
|
if (right_edge > screen_width)
|
|
|
|
screen_width = right_edge;
|
|
|
|
|
|
|
|
bottom_edge = (logical_monitor_config->layout.height +
|
|
|
|
logical_monitor_config->layout.y);
|
|
|
|
if (bottom_edge > screen_height)
|
|
|
|
screen_height = bottom_edge;
|
|
|
|
}
|
2016-12-05 05:38:43 -05:00
|
|
|
|
|
|
|
manager->screen_width = screen_width;
|
|
|
|
manager->screen_height = screen_height;
|
2017-01-09 01:31:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
meta_monitor_manager_test_apply_monitors_config (MetaMonitorManager *manager,
|
|
|
|
MetaMonitorsConfig *config,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GPtrArray *crtc_infos;
|
|
|
|
GPtrArray *output_infos;
|
|
|
|
|
2017-01-20 01:50:11 -05:00
|
|
|
if (!config)
|
|
|
|
{
|
|
|
|
/* The screen is made 1x1, as clutter stage used cannot be empty. */
|
|
|
|
manager->screen_width = 1;
|
|
|
|
manager->screen_height = 1;
|
|
|
|
|
|
|
|
meta_monitor_manager_rebuild (manager, NULL);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-01-09 01:31:18 -05:00
|
|
|
if (!meta_monitor_config_manager_assign (manager, config,
|
|
|
|
&crtc_infos,
|
|
|
|
&output_infos,
|
|
|
|
error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
apply_crtc_assignments (manager,
|
|
|
|
(MetaCrtcInfo **) crtc_infos->pdata,
|
|
|
|
crtc_infos->len,
|
|
|
|
(MetaOutputInfo **) output_infos->pdata,
|
|
|
|
output_infos->len);
|
|
|
|
|
|
|
|
g_ptr_array_free (crtc_infos, TRUE);
|
|
|
|
g_ptr_array_free (output_infos, TRUE);
|
|
|
|
|
|
|
|
update_screen_size (manager, config);
|
|
|
|
meta_monitor_manager_rebuild (manager, config);
|
2016-12-05 05:38:43 -05:00
|
|
|
|
2017-01-09 01:31:18 -05:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
legacy_calculate_screen_size (MetaMonitorManager *manager)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
int width = 0, height = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < manager->n_crtcs; i++)
|
|
|
|
{
|
|
|
|
MetaCrtc *crtc = &manager->crtcs[i];
|
|
|
|
|
|
|
|
width = MAX (width, crtc->rect.x + crtc->rect.width);
|
|
|
|
height = MAX (height, crtc->rect.y + crtc->rect.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
manager->screen_width = width;
|
|
|
|
manager->screen_height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_monitor_manager_test_apply_configuration (MetaMonitorManager *manager,
|
|
|
|
MetaCrtcInfo **crtcs,
|
|
|
|
unsigned int n_crtcs,
|
|
|
|
MetaOutputInfo **outputs,
|
|
|
|
unsigned int n_outputs)
|
|
|
|
{
|
|
|
|
apply_crtc_assignments (manager, crtcs, n_crtcs, outputs, n_outputs);
|
|
|
|
legacy_calculate_screen_size (manager);
|
2016-12-05 05:38:43 -05:00
|
|
|
meta_monitor_manager_rebuild_derived (manager);
|
|
|
|
}
|
|
|
|
|
2016-12-13 07:11:48 -05:00
|
|
|
static void
|
|
|
|
meta_monitor_manager_test_tiled_monitor_added (MetaMonitorManager *manager,
|
|
|
|
MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerTest *manager_test = META_MONITOR_MANAGER_TEST (manager);
|
|
|
|
|
|
|
|
manager_test->tiled_monitor_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_monitor_manager_test_tiled_monitor_removed (MetaMonitorManager *manager,
|
|
|
|
MetaMonitor *monitor)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerTest *manager_test = META_MONITOR_MANAGER_TEST (manager);
|
|
|
|
|
|
|
|
manager_test->tiled_monitor_count--;
|
|
|
|
}
|
|
|
|
|
2017-03-08 03:05:00 -05:00
|
|
|
static gboolean
|
|
|
|
meta_monitor_manager_test_is_transform_handled (MetaMonitorManager *manager,
|
|
|
|
MetaCrtc *crtc,
|
|
|
|
MetaMonitorTransform transform)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-01-20 02:07:12 -05:00
|
|
|
static int
|
|
|
|
meta_monitor_manager_test_calculate_monitor_mode_scale (MetaMonitorManager *manager,
|
|
|
|
MetaMonitor *monitor,
|
|
|
|
MetaMonitorMode *monitor_mode)
|
|
|
|
{
|
|
|
|
MetaOutput *output;
|
|
|
|
MetaOutputTest *output_test;
|
|
|
|
|
|
|
|
output = meta_monitor_get_main_output (monitor);
|
|
|
|
output_test = output->driver_private;
|
|
|
|
|
|
|
|
return output_test->scale;
|
|
|
|
}
|
|
|
|
|
2016-12-07 04:39:53 -05:00
|
|
|
static void
|
|
|
|
meta_monitor_manager_test_dispose (GObject *object)
|
|
|
|
{
|
|
|
|
MetaMonitorManagerTest *manager_test = META_MONITOR_MANAGER_TEST (object);
|
|
|
|
|
|
|
|
g_clear_pointer (&manager_test->test_setup, g_free);
|
|
|
|
}
|
|
|
|
|
2016-12-05 05:38:43 -05:00
|
|
|
static void
|
|
|
|
meta_monitor_manager_test_init (MetaMonitorManagerTest *manager_test)
|
|
|
|
{
|
2016-12-05 08:28:22 -05:00
|
|
|
g_assert (_initial_test_setup);
|
|
|
|
|
|
|
|
manager_test->test_setup = _initial_test_setup;
|
2016-12-05 05:38:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
meta_monitor_manager_test_class_init (MetaMonitorManagerTestClass *klass)
|
|
|
|
{
|
2016-12-07 04:39:53 -05:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2016-12-05 05:38:43 -05:00
|
|
|
MetaMonitorManagerClass *manager_class = META_MONITOR_MANAGER_CLASS (klass);
|
|
|
|
|
2016-12-07 04:39:53 -05:00
|
|
|
object_class->dispose = meta_monitor_manager_test_dispose;
|
|
|
|
|
2016-12-05 05:38:43 -05:00
|
|
|
manager_class->read_current = meta_monitor_manager_test_read_current;
|
2017-01-09 21:59:31 -05:00
|
|
|
manager_class->is_lid_closed = meta_monitor_manager_test_is_lid_closed;
|
2017-01-06 00:27:21 -05:00
|
|
|
manager_class->ensure_initial_config = meta_monitor_manager_test_ensure_initial_config;
|
2017-01-09 01:31:18 -05:00
|
|
|
manager_class->apply_monitors_config = meta_monitor_manager_test_apply_monitors_config;
|
2016-12-05 05:38:43 -05:00
|
|
|
manager_class->apply_configuration = meta_monitor_manager_test_apply_configuration;
|
2016-12-13 07:11:48 -05:00
|
|
|
manager_class->tiled_monitor_added = meta_monitor_manager_test_tiled_monitor_added;
|
|
|
|
manager_class->tiled_monitor_removed = meta_monitor_manager_test_tiled_monitor_removed;
|
2017-03-08 03:05:00 -05:00
|
|
|
manager_class->is_transform_handled = meta_monitor_manager_test_is_transform_handled;
|
2017-01-20 02:07:12 -05:00
|
|
|
manager_class->calculate_monitor_mode_scale = meta_monitor_manager_test_calculate_monitor_mode_scale;
|
2016-12-05 05:38:43 -05:00
|
|
|
}
|