crtc: Move configured state to separate struct

To make it more reliable to distinguish between values that are read
from the backend implementation (which is likely to be irrelevant for
anything but the backend implementation), split out those values (e.g.
layout).

This changes the meaning of what was MetaCrtc::rect, to a
MetaCrtcConfig::layout which is the layout the CRTC has in the global
coordinate space.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/1042
This commit is contained in:
Jonas Ådahl
2020-01-14 22:34:44 +01:00
parent a11f9bd513
commit fe42d56db3
20 changed files with 370 additions and 350 deletions

View File

@ -140,38 +140,17 @@ apply_crtc_assignments (MetaMonitorManager *manager,
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;
meta_crtc_unset_config (crtc);
}
else
{
MetaCrtcMode *mode;
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;
meta_crtc_set_config (crtc,
&crtc_info->layout,
crtc_info->mode,
crtc_info->transform);
for (j = 0; j < crtc_info->outputs->len; j++)
{
@ -206,11 +185,7 @@ apply_crtc_assignments (MetaMonitorManager *manager,
continue;
}
crtc->rect.x = 0;
crtc->rect.y = 0;
crtc->rect.width = 0;
crtc->rect.height = 0;
crtc->current_mode = NULL;
meta_crtc_unset_config (crtc);
}
/* Disable outputs not mentioned in the list */

View File

@ -175,8 +175,8 @@ typedef struct _MonitorTestCaseCrtcExpect
{
MetaMonitorTransform transform;
int current_mode;
int x;
int y;
float x;
float y;
} MonitorTestCaseCrtcExpect;
typedef struct _MonitorTestCaseExpect
@ -313,6 +313,7 @@ static MonitorTestCase initial_test_case = {
},
{
.current_mode = 0,
.x = 1024,
}
},
.n_crtcs = 2,
@ -509,10 +510,15 @@ check_current_monitor_mode (MetaMonitor *monitor,
}
else
{
MetaCrtcConfig *crtc_config;
MetaLogicalMonitor *logical_monitor;
g_assert_nonnull (crtc);
g_assert (monitor_crtc_mode->crtc_mode == crtc->current_mode);
crtc_config = crtc->config;
g_assert_nonnull (crtc_config);
g_assert (monitor_crtc_mode->crtc_mode == crtc_config->mode);
logical_monitor = crtc->logical_monitor;
g_assert_nonnull (logical_monitor);
@ -623,42 +629,6 @@ check_logical_monitor (MonitorTestCase *test_case,
g_assert_nonnull (primary_output);
}
static void
get_compensated_crtc_position (MetaCrtc *crtc,
int *x,
int *y)
{
MetaLogicalMonitor *logical_monitor;
MetaBackend *backend = meta_get_backend ();
MetaRenderer *renderer = meta_backend_get_renderer (backend);
GList *views;
GList *l;
logical_monitor = crtc->logical_monitor;
g_assert_nonnull (logical_monitor);
views = meta_renderer_get_views (renderer);
for (l = views; 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_equal (&view_layout,
&logical_monitor->rect))
{
*x = crtc->rect.x - view_layout.x;
*y = crtc->rect.y - view_layout.y;
return;
}
}
*x = crtc->rect.x;
*y = crtc->rect.y;
}
static void
check_monitor_configuration (MonitorTestCase *test_case)
{
@ -853,50 +823,37 @@ check_monitor_configuration (MonitorTestCase *test_case)
for (l = crtcs, i = 0; l; l = l->next, i++)
{
MetaCrtc *crtc = l->data;
MetaCrtcConfig *crtc_config = crtc->config;
if (test_case->expect.crtcs[i].current_mode == -1)
{
g_assert_null (crtc->current_mode);
g_assert_null (crtc_config);
}
else
{
MetaLogicalMonitor *logical_monitor = crtc->logical_monitor;
MetaCrtcMode *expected_current_mode;
int crtc_x, crtc_y;
g_assert_nonnull (crtc_config);
expected_current_mode =
g_list_nth_data (meta_gpu_get_modes (gpu),
test_case->expect.crtcs[i].current_mode);
g_assert (crtc->current_mode == expected_current_mode);
g_assert (crtc_config->mode == expected_current_mode);
g_assert_cmpuint (crtc->transform,
g_assert_cmpuint (crtc_config->transform,
==,
test_case->expect.crtcs[i].transform);
if (meta_is_stage_views_enabled ())
{
get_compensated_crtc_position (crtc, &crtc_x, &crtc_y);
logical_monitor = crtc->logical_monitor;
g_assert_nonnull (logical_monitor);
g_assert_cmpint (crtc_x, ==, test_case->expect.crtcs[i].x);
g_assert_cmpint (crtc_y, ==, test_case->expect.crtcs[i].y);
}
else
{
int expect_crtc_x;
int expect_crtc_y;
g_assert_cmpuint (logical_monitor->transform,
==,
crtc->transform);
expect_crtc_x = (test_case->expect.crtcs[i].x +
logical_monitor->rect.x);
expect_crtc_y = (test_case->expect.crtcs[i].y +
logical_monitor->rect.y);
g_assert_cmpint (crtc->rect.x, ==, expect_crtc_x);
g_assert_cmpint (crtc->rect.y, ==, expect_crtc_y);
}
g_assert_cmpfloat_with_epsilon (crtc_config->layout.origin.x,
test_case->expect.crtcs[i].x,
FLT_EPSILON);
g_assert_cmpfloat_with_epsilon (crtc_config->layout.origin.y,
test_case->expect.crtcs[i].y,
FLT_EPSILON);
}
}
@ -945,19 +902,9 @@ create_monitor_test_setup (MonitorTestCase *test_case,
for (i = 0; i < test_case->setup.n_crtcs; i++)
{
MetaCrtc *crtc;
int current_mode_index;
MetaCrtcMode *current_mode;
current_mode_index = test_case->setup.crtcs[i].current_mode;
if (current_mode_index == -1)
current_mode = NULL;
else
current_mode = g_list_nth_data (test_setup->modes, current_mode_index);
crtc = g_object_new (META_TYPE_CRTC, NULL);
crtc->crtc_id = i + 1;
crtc->current_mode = current_mode;
crtc->transform = META_MONITOR_TRANSFORM_NORMAL;
crtc->all_transforms = ALL_TRANSFORMS;
test_setup->crtcs = g_list_append (test_setup->crtcs, crtc);
@ -1258,6 +1205,7 @@ meta_test_monitor_one_off_linear_config (void)
},
{
.current_mode = 0,
.x = 1024,
}
},
.n_crtcs = 2,
@ -1966,6 +1914,7 @@ meta_test_monitor_hidpi_linear_config (void)
},
{
.current_mode = 1,
.x = 640,
}
},
.n_crtcs = 2,
@ -2118,6 +2067,8 @@ meta_test_monitor_suggested_config (void)
.crtcs = {
{
.current_mode = 0,
.x = 1024,
.y = 758,
},
{
.current_mode = 1,
@ -2386,6 +2337,7 @@ meta_test_monitor_lid_switch_config (void)
},
{
.current_mode = 0,
.x = 1024,
}
},
.n_crtcs = 2,
@ -2417,6 +2369,7 @@ meta_test_monitor_lid_switch_config (void)
test_case.expect.screen_width = 1024;
test_case.expect.monitors[0].current_mode = -1;
test_case.expect.crtcs[0].current_mode = -1;
test_case.expect.crtcs[1].x = 0;
check_monitor_configuration (&test_case);
@ -2436,6 +2389,7 @@ meta_test_monitor_lid_switch_config (void)
test_case.expect.crtcs[0].current_mode = 0;
test_case.expect.crtcs[1].current_mode = 0;
test_case.expect.crtcs[1].x = 1024;
check_monitor_configuration (&test_case);
}
@ -2584,7 +2538,9 @@ meta_test_monitor_lid_opened_config (void)
test_case.expect.screen_width = 1024 * 2;
test_case.expect.monitors[0].current_mode = 0;
test_case.expect.crtcs[0].current_mode = 0;
test_case.expect.crtcs[0].x = 1024;
test_case.expect.crtcs[1].current_mode = 0;
test_case.expect.crtcs[1].x = 0;
check_monitor_configuration (&test_case);
}
@ -2831,6 +2787,7 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void)
test_case.expect.n_monitors = 2;
test_case.expect.n_logical_monitors = 2;
test_case.expect.crtcs[1].current_mode = 0;
test_case.expect.crtcs[1].x = 1024;
test_case.expect.screen_width = 1024 * 2;
test_setup = create_monitor_test_setup (&test_case,
@ -2844,6 +2801,7 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void)
test_case.expect.logical_monitors[0].monitors[0] = 1,
test_case.expect.n_logical_monitors = 1;
test_case.expect.crtcs[0].current_mode = -1;
test_case.expect.crtcs[1].x = 0;
test_case.expect.screen_width = 1024;
test_setup = create_monitor_test_setup (&test_case,
@ -2867,6 +2825,7 @@ meta_test_monitor_lid_closed_with_hotplugged_external (void)
test_case.expect.logical_monitors[1].monitors[0] = 1,
test_case.expect.n_logical_monitors = 2;
test_case.expect.crtcs[0].current_mode = 0;
test_case.expect.crtcs[1].x = 1024;
test_case.expect.screen_width = 1024 * 2;
test_setup = create_monitor_test_setup (&test_case,
@ -3301,6 +3260,7 @@ meta_test_monitor_custom_vertical_config (void)
},
{
.current_mode = 1,
.y = 768,
}
},
.n_crtcs = 2,
@ -3440,6 +3400,7 @@ meta_test_monitor_custom_primary_config (void)
},
{
.current_mode = 1,
.x = 1024,
}
},
.n_crtcs = 2,
@ -3952,7 +3913,7 @@ meta_test_monitor_custom_tiled_config (void)
},
{
.current_mode = 0,
.x = 400,
.x = 200,
.y = 0
}
},
@ -4555,6 +4516,7 @@ meta_test_monitor_custom_first_rotated_config (void)
},
{
.current_mode = 0,
.x = 768,
}
},
.n_crtcs = 2,
@ -4685,10 +4647,12 @@ meta_test_monitor_custom_second_rotated_config (void)
.crtcs = {
{
.current_mode = 0,
.y = 256,
},
{
.current_mode = 0,
.transform = META_MONITOR_TRANSFORM_90
.transform = META_MONITOR_TRANSFORM_90,
.x = 1024,
}
},
.n_crtcs = 2,
@ -4859,16 +4823,18 @@ meta_test_monitor_custom_second_rotated_tiled_config (void)
.crtcs = {
{
.current_mode = 0,
.y = 256,
},
{
.current_mode = 1,
.transform = META_MONITOR_TRANSFORM_90,
.x = 0,
.x = 1024,
.y = 400,
},
{
.current_mode = 1,
.transform = META_MONITOR_TRANSFORM_90
.transform = META_MONITOR_TRANSFORM_90,
.x = 1024,
}
},
.n_crtcs = 3,
@ -5008,10 +4974,12 @@ meta_test_monitor_custom_second_rotated_nonnative_config (void)
.crtcs = {
{
.current_mode = 0,
.y = 256,
},
{
.current_mode = 0,
.transform = META_MONITOR_TRANSFORM_NORMAL
.transform = META_MONITOR_TRANSFORM_NORMAL,
.x = 1024,
}
},
.n_crtcs = 2,
@ -5423,6 +5391,7 @@ meta_test_monitor_custom_lid_switch_config (void)
test_case.expect.n_outputs = 2;
test_case.expect.crtcs[0].transform = META_MONITOR_TRANSFORM_NORMAL;
test_case.expect.crtcs[1].current_mode = 0;
test_case.expect.crtcs[1].x = 1024;
test_case.expect.crtcs[1].transform = META_MONITOR_TRANSFORM_270;
test_case.expect.logical_monitors[0].layout =
(MetaRectangle) { .width = 1024, .height = 768 };
@ -5440,6 +5409,7 @@ meta_test_monitor_custom_lid_switch_config (void)
test_case.expect.crtcs[0].current_mode = -1;
test_case.expect.crtcs[1].transform = META_MONITOR_TRANSFORM_90;
test_case.expect.crtcs[1].x = 0;
test_case.expect.monitors[0].current_mode = -1;
test_case.expect.logical_monitors[0].layout =
(MetaRectangle) { .width = 768, .height = 1024 };
@ -5460,6 +5430,7 @@ meta_test_monitor_custom_lid_switch_config (void)
test_case.expect.crtcs[0].transform = META_MONITOR_TRANSFORM_NORMAL;
test_case.expect.crtcs[1].current_mode = 0;
test_case.expect.crtcs[1].transform = META_MONITOR_TRANSFORM_270;
test_case.expect.crtcs[1].x = 1024;
test_case.expect.monitors[0].current_mode = 0;
test_case.expect.logical_monitors[0].layout =
(MetaRectangle) { .width = 1024, .height = 768 };