1
0
Fork 0

tests: Add tests for monitor_calculate_mode_scale

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2653>
This commit is contained in:
Adrian Vovk 2023-01-30 14:34:21 -05:00 committed by Jonas Ådahl
parent 2f1dd049bf
commit a6217c720e
4 changed files with 229 additions and 47 deletions

View file

@ -40,6 +40,8 @@ struct _MetaMonitorManagerTest
int tiled_monitor_count;
MetaLogicalMonitorLayoutMode layout_mode;
MetaMonitorTestSetup *test_setup;
};
@ -314,30 +316,8 @@ meta_monitor_manager_test_is_transform_handled (MetaMonitorManager *manager,
return manager_test->handles_transforms;
}
static float
meta_monitor_manager_test_calculate_monitor_mode_scale (MetaMonitorManager *manager,
MetaLogicalMonitorLayoutMode layout_mode,
MetaMonitor *monitor,
MetaMonitorMode *monitor_mode)
{
MetaOutput *output;
MetaOutputTest *output_test;
output = meta_monitor_get_main_output (monitor);
output_test = META_OUTPUT_TEST (output);
if (output_test)
return output_test->scale;
else
return 1;
}
static float *
meta_monitor_manager_test_calculate_supported_scales (MetaMonitorManager *manager,
MetaLogicalMonitorLayoutMode layout_mode,
MetaMonitor *monitor,
MetaMonitorMode *monitor_mode,
int *n_supported_scales)
static MetaMonitorScalesConstraint
get_monitor_scale_constraints_from_layout_mode (MetaLogicalMonitorLayoutMode layout_mode)
{
MetaMonitorScalesConstraint constraints =
META_MONITOR_SCALES_CONSTRAINT_NONE;
@ -351,32 +331,52 @@ meta_monitor_manager_test_calculate_supported_scales (MetaMonitorManager
break;
}
return constraints;
}
static float
meta_monitor_manager_test_calculate_monitor_mode_scale (MetaMonitorManager *manager,
MetaLogicalMonitorLayoutMode layout_mode,
MetaMonitor *monitor,
MetaMonitorMode *monitor_mode)
{
MetaOutput *output;
MetaOutputTest *output_test;
MetaMonitorScalesConstraint constraints;
output = meta_monitor_get_main_output (monitor);
output_test = META_OUTPUT_TEST (output);
if (!output_test)
return 1;
if (output_test->scale != -1)
return output_test->scale;
constraints = get_monitor_scale_constraints_from_layout_mode (layout_mode);
return meta_monitor_calculate_mode_scale (monitor, monitor_mode, constraints);
}
static float *
meta_monitor_manager_test_calculate_supported_scales (MetaMonitorManager *manager,
MetaLogicalMonitorLayoutMode layout_mode,
MetaMonitor *monitor,
MetaMonitorMode *monitor_mode,
int *n_supported_scales)
{
MetaMonitorScalesConstraint constraints =
get_monitor_scale_constraints_from_layout_mode (layout_mode);
return meta_monitor_calculate_supported_scales (monitor, monitor_mode,
constraints,
n_supported_scales);
}
static gboolean
is_monitor_framebuffer_scaled (MetaMonitorManager *manager)
{
MetaBackend *backend = meta_monitor_manager_get_backend (manager);
MetaSettings *settings = meta_backend_get_settings (backend);
return meta_settings_is_experimental_feature_enabled (
settings,
META_EXPERIMENTAL_FEATURE_SCALE_MONITOR_FRAMEBUFFER);
}
static MetaMonitorManagerCapability
meta_monitor_manager_test_get_capabilities (MetaMonitorManager *manager)
{
MetaMonitorManagerCapability capabilities =
META_MONITOR_MANAGER_CAPABILITY_NONE;
if (is_monitor_framebuffer_scaled (manager))
capabilities |= META_MONITOR_MANAGER_CAPABILITY_LAYOUT_MODE;
return capabilities;
return META_MONITOR_MANAGER_CAPABILITY_LAYOUT_MODE;
}
static gboolean
@ -387,13 +387,19 @@ meta_monitor_manager_test_get_max_screen_size (MetaMonitorManager *manager,
return FALSE;
}
void
meta_monitor_manager_test_set_layout_mode (MetaMonitorManagerTest *manager_test,
MetaLogicalMonitorLayoutMode layout_mode)
{
manager_test->layout_mode = layout_mode;
}
static MetaLogicalMonitorLayoutMode
meta_monitor_manager_test_get_default_layout_mode (MetaMonitorManager *manager)
{
if (is_monitor_framebuffer_scaled (manager))
return META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL;
else
return META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL;
MetaMonitorManagerTest *manager_test = META_MONITOR_MANAGER_TEST (manager);
return manager_test->layout_mode;
}
static void
@ -425,6 +431,7 @@ static void
meta_monitor_manager_test_init (MetaMonitorManagerTest *manager_test)
{
manager_test->handles_transforms = TRUE;
manager_test->layout_mode = META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL;
}
static void

View file

@ -90,4 +90,8 @@ int meta_monitor_manager_test_get_tiled_monitor_count (MetaMonitorManagerTest *m
META_EXPORT
void meta_crtc_test_disable_gamma_lut (MetaCrtcTest *crtc_test);
META_EXPORT
void meta_monitor_manager_test_set_layout_mode (MetaMonitorManagerTest *manager_test,
MetaLogicalMonitorLayoutMode layout_mode);
#endif /* META_MONITOR_MANAGER_TEST_H */

View file

@ -727,7 +727,7 @@ meta_create_monitor_test_setup (MetaBackend *backend,
}
scale = setup->outputs[i].scale;
if (scale < 1)
if (scale < 1 && scale != -1)
scale = 1;
is_laptop_panel = setup->outputs[i].is_laptop_panel;

View file

@ -9202,6 +9202,175 @@ meta_test_monitor_supported_fractional_scales (void)
META_MONITOR_SCALES_CONSTRAINT_NONE));
}
static void
meta_test_monitor_calculate_mode_scale (void)
{
static MonitorTestCaseSetup base_test_case_setup = {
.modes = {
{
.refresh_rate = 60.0
}
},
.n_modes = 1,
.outputs = {
{
.crtc = 0,
.modes = { 0 },
.n_modes = 1,
.preferred_mode = 0,
.possible_crtcs = { 0 },
.n_possible_crtcs = 1,
.scale = -1,
}
},
.n_outputs = 1,
.crtcs = {
{
.current_mode = 0
}
},
.n_crtcs = 1
};
static struct {
const char *name;
int width, height;
int width_mm, height_mm;
float exp, exp_nofrac;
} cases[] = {
{
.name = "Librem 5",
.width = 720,
.height = 1440,
.width_mm = 65, /* 2:1, 5.7" */
.height_mm = 129,
/* Librem 5, when scaled, doesn't have enough logical area to
fit a full desktop-sized GNOME UI. Thus, Mutter rules out
scale factors above 1.75. */
.exp = 1.5,
.exp_nofrac = 1.0,
},
{
.name = "OnePlus 6",
.width = 1080,
.height = 2280,
.width_mm = 68, /* 19:9, 6.28" */
.height_mm = 144,
.exp = 3.0,
.exp_nofrac = 3.0,
},
{
.name = "Google Pixel 6a",
.width = 1080,
.height = 2400,
.width_mm = 64, /* 20:9, 6.1" */
.height_mm = 142,
.exp = 2.75,
.exp_nofrac = 3.0,
},
{
.name = "13\" MacBook Retina",
.width = 2560,
.height = 1600,
.width_mm = 286, /* 16:10, 13.3" */
.height_mm = 179,
.exp = 1.75,
.exp_nofrac = 2.0,
},
{
.name = "Surface Laptop Studio",
.width = 2400,
.height = 1600,
.width_mm = 303, /* 3:2 @ 14.34" */
.height_mm = 202,
.exp = 1.5,
.exp_nofrac = 2.0,
},
{
.name = "Generic 23\" 1080p",
.width = 1920,
.height = 1080,
.width_mm = 509,
.height_mm = 286,
.exp = 1.0,
.exp_nofrac = 1.0,
},
{
.name = "Generic 23\" 4K",
.width = 3840,
.height = 2160,
.width_mm = 509,
.height_mm = 286,
.exp = 1.75,
.exp_nofrac = 2.0,
},
{
.name = "Generic 27\" 4K",
.width = 3840,
.height = 2160,
.width_mm = 598,
.height_mm = 336,
.exp = 1.5,
.exp_nofrac = 2.0,
},
{
.name = "Generic 32\" 4K",
.width = 3840,
.height = 2160,
.width_mm = 708,
.height_mm = 398,
.exp = 1.25,
.exp_nofrac = 1.0,
},
};
static const int n_cases = 1;
MetaMonitorManager *manager;
MetaMonitorManagerTest *manager_test;
manager = meta_backend_get_monitor_manager (test_backend);
manager_test = META_MONITOR_MANAGER_TEST (manager);
for (int i = 0; i < n_cases; i++)
{
MonitorTestCaseSetup test_case_setup = base_test_case_setup;
MetaMonitorTestSetup *test_setup;
MetaLogicalMonitor *logical_monitor;
g_autofree char *serial1 = NULL;
g_autofree char *serial2 = NULL;
serial1 = g_strdup_printf ("0x120001%x", i * 2);
test_case_setup.modes[0].width = cases[i].width;
test_case_setup.modes[0].height = cases[i].height;
test_case_setup.outputs[0].width_mm = cases[i].width_mm;
test_case_setup.outputs[0].height_mm = cases[i].height_mm;
test_case_setup.outputs[0].serial = serial1;
test_setup = meta_create_monitor_test_setup (test_backend, &test_case_setup,
MONITOR_TEST_FLAG_NO_STORED);
g_debug ("Checking default non-fractional scale for %s", cases[i].name);
meta_monitor_manager_test_set_layout_mode (manager_test,
META_LOGICAL_MONITOR_LAYOUT_MODE_PHYSICAL);
emulate_hotplug (test_setup);
/* Crashes right here because manager->logical_monitors is NULL */
logical_monitor = manager->logical_monitors->data;
g_assert_cmpfloat_with_epsilon (logical_monitor->scale, cases[i].exp_nofrac, 0.01);
g_debug ("Checking default fractional scale for %s", cases[i].name);
meta_monitor_manager_test_set_layout_mode (manager_test,
META_LOGICAL_MONITOR_LAYOUT_MODE_LOGICAL);
serial2 = g_strdup_printf ("0x120001%x", i * 2 + 1);
test_case_setup.outputs[0].serial = serial2;
test_setup = meta_create_monitor_test_setup (test_backend, &test_case_setup,
MONITOR_TEST_FLAG_NO_STORED);
emulate_hotplug (test_setup);
logical_monitor = manager->logical_monitors->data;
g_assert_cmpfloat_with_epsilon (logical_monitor->scale, cases[i].exp,
FLT_EPSILON);
}
}
static void
meta_test_monitor_policy_system_only (void)
{
@ -9507,6 +9676,8 @@ init_monitor_tests (void)
meta_test_monitor_supported_integer_scales);
add_monitor_test ("/backends/monitor/suppported_scales/fractional",
meta_test_monitor_supported_fractional_scales);
add_monitor_test ("/backends/monitor/default_scale",
meta_test_monitor_calculate_mode_scale);
add_monitor_test ("/backends/monitor/policy/system-only",
meta_test_monitor_policy_system_only);