monitor-manager: Add portrait modes to portrait displays

If a monitor's max resolution is a portrait resolution, then assume it is
a native portrait monitor and add portrait versions of the common modes.

https://bugzilla.gnome.org/show_bug.cgi?id=782294
This commit is contained in:
Hans de Goede 2017-10-24 15:47:30 +02:00 committed by Jonas Ådahl
parent 383ac76d00
commit dd43d04d42
4 changed files with 98 additions and 20 deletions

View File

@ -51,7 +51,7 @@ common_resolutions = [
output_lines = [ output_lines = [
"/* Generated by gen-default-modes.py */\n", "/* Generated by gen-default-modes.py */\n",
"static const drmModeModeInfo meta_default_drm_mode_infos[] = {", "static const drmModeModeInfo meta_default_landscape_drm_mode_infos[] = {",
] ]
def sync_flags(hsync, vsync): def sync_flags(hsync, vsync):
@ -76,6 +76,21 @@ def drm_mode_info_from_modeline(line):
sync_flags(sline[11], sline[12]), sync_flags(sline[11], sline[12]),
sline[1]) sline[1])
def portrait_drm_mode_info_from_modeline(line):
sline = line.split()
return "{ %d, %d, %d, %d, %d, 0, %d, %d, %d, %d, 0, 0, %s, DRM_MODE_TYPE_DEFAULT, \"%dx%d_60.00\" }," % \
(int(float(sline[2]) * 1000),
int(sline[7]),
int(sline[8]),
int(sline[9]),
int(sline[10]),
int(sline[3]),
int(sline[4]),
int(sline[5]),
int(sline[6]),
sync_flags(sline[12], sline[11]),
int(sline[7]), int(sline[3]))
for resolution in common_resolutions: for resolution in common_resolutions:
cvt = os.popen("%s %s %s" % ('cvt', resolution[0], resolution[1])) cvt = os.popen("%s %s %s" % ('cvt', resolution[0], resolution[1]))
cvt.readline() # discard comment line cvt.readline() # discard comment line
@ -84,6 +99,16 @@ for resolution in common_resolutions:
cvt.close() cvt.close()
output_lines.append("};") output_lines.append("};")
output_lines.append("")
output_lines.append("static const drmModeModeInfo meta_default_portrait_drm_mode_infos[] = {")
for resolution in common_resolutions:
cvt = os.popen("%s %s %s" % ('cvt', resolution[0], resolution[1]))
cvt.readline() # discard comment line
line = cvt.readline()
output_lines.append(portrait_drm_mode_info_from_modeline(line))
cvt.close()
output_lines.append("};")
for line in output_lines: for line in output_lines:
sys.stdout.write(line + "\n") sys.stdout.write(line + "\n")
sys.stdout.flush() sys.stdout.flush()

View File

@ -1,6 +1,6 @@
/* Generated by gen-default-modes.py */ /* Generated by gen-default-modes.py */
static const drmModeModeInfo meta_default_drm_mode_infos[] = { static const drmModeModeInfo meta_default_landscape_drm_mode_infos[] = {
{ 38250, 800, 832, 912, 1024, 0, 600, 603, 607, 624, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "800x600_60.00" }, { 38250, 800, 832, 912, 1024, 0, 600, 603, 607, 624, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "800x600_60.00" },
{ 63500, 1024, 1072, 1176, 1328, 0, 768, 771, 775, 798, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "1024x768_60.00" }, { 63500, 1024, 1072, 1176, 1328, 0, 768, 771, 775, 798, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "1024x768_60.00" },
{ 81750, 1152, 1216, 1336, 1520, 0, 864, 867, 871, 897, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "1152x864_60.00" }, { 81750, 1152, 1216, 1336, 1520, 0, 864, 867, 871, 897, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "1152x864_60.00" },
@ -27,3 +27,31 @@ static const drmModeModeInfo meta_default_drm_mode_infos[] = {
{ 813000, 4096, 4440, 4888, 5680, 0, 2304, 2307, 2312, 2386, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "4096x2304_60.00" }, { 813000, 4096, 4440, 4888, 5680, 0, 2304, 2307, 2312, 2386, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "4096x2304_60.00" },
{ 1276500, 5120, 5560, 6128, 7136, 0, 2880, 2883, 2888, 2982, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "5120x2880_60.00" }, { 1276500, 5120, 5560, 6128, 7136, 0, 2880, 2883, 2888, 2982, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "5120x2880_60.00" },
}; };
static const drmModeModeInfo meta_default_portrait_drm_mode_infos[] = {
{ 38250, 600, 603, 607, 624, 0, 800, 832, 912, 1024, 0, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, DRM_MODE_TYPE_DEFAULT, "600x800_60.00" },
{ 63500, 768, 771, 775, 798, 0, 1024, 1072, 1176, 1328, 0, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, DRM_MODE_TYPE_DEFAULT, "768x1024_60.00" },
{ 81750, 864, 867, 871, 897, 0, 1152, 1216, 1336, 1520, 0, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, DRM_MODE_TYPE_DEFAULT, "864x1152_60.00" },
{ 101250, 960, 963, 967, 996, 0, 1280, 1360, 1488, 1696, 0, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, DRM_MODE_TYPE_DEFAULT, "960x1280_60.00" },
{ 121750, 1050, 1053, 1057, 1089, 0, 1400, 1488, 1632, 1864, 0, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, DRM_MODE_TYPE_DEFAULT, "1050x1400_60.00" },
{ 129000, 1080, 1083, 1087, 1120, 0, 1440, 1528, 1680, 1920, 0, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, DRM_MODE_TYPE_DEFAULT, "1080x1440_60.00" },
{ 161000, 1200, 1203, 1207, 1245, 0, 1600, 1712, 1880, 2160, 0, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, DRM_MODE_TYPE_DEFAULT, "1200x1600_60.00" },
{ 233500, 1440, 1443, 1447, 1493, 0, 1920, 2064, 2264, 2608, 0, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, DRM_MODE_TYPE_DEFAULT, "1440x1920_60.00" },
{ 267250, 1536, 1539, 1543, 1592, 0, 2048, 2208, 2424, 2800, 0, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, DRM_MODE_TYPE_DEFAULT, "1536x2048_60.00" },
{ 83500, 800, 803, 809, 831, 0, 1280, 1352, 1480, 1680, 0, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, DRM_MODE_TYPE_DEFAULT, "800x1280_60.00" },
{ 106500, 900, 903, 909, 934, 0, 1440, 1528, 1672, 1904, 0, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, DRM_MODE_TYPE_DEFAULT, "900x1440_60.00" },
{ 146250, 1050, 1053, 1059, 1089, 0, 1680, 1784, 1960, 2240, 0, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, DRM_MODE_TYPE_DEFAULT, "1050x1680_60.00" },
{ 193250, 1200, 1203, 1209, 1245, 0, 1920, 2056, 2256, 2592, 0, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, DRM_MODE_TYPE_DEFAULT, "1200x1920_60.00" },
{ 348500, 1600, 1603, 1609, 1658, 0, 2560, 2760, 3032, 3504, 0, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, DRM_MODE_TYPE_DEFAULT, "1600x2560_60.00" },
{ 74500, 720, 723, 728, 748, 0, 1280, 1344, 1472, 1664, 0, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, DRM_MODE_TYPE_DEFAULT, "720x1280_60.00" },
{ 85250, 768, 771, 781, 798, 0, 1368, 1440, 1576, 1784, 0, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, DRM_MODE_TYPE_DEFAULT, "768x1368_60.00" },
{ 118250, 900, 903, 908, 934, 0, 1600, 1696, 1856, 2112, 0, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, DRM_MODE_TYPE_DEFAULT, "900x1600_60.00" },
{ 173000, 1080, 1083, 1088, 1120, 0, 1920, 2048, 2248, 2576, 0, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, DRM_MODE_TYPE_DEFAULT, "1080x1920_60.00" },
{ 197000, 1152, 1155, 1160, 1195, 0, 2048, 2184, 2400, 2752, 0, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, DRM_MODE_TYPE_DEFAULT, "1152x2048_60.00" },
{ 312250, 1440, 1443, 1448, 1493, 0, 2560, 2752, 3024, 3488, 0, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, DRM_MODE_TYPE_DEFAULT, "1440x2560_60.00" },
{ 396250, 1620, 1623, 1628, 1679, 0, 2880, 3096, 3408, 3936, 0, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, DRM_MODE_TYPE_DEFAULT, "1620x2880_60.00" },
{ 492000, 1800, 1803, 1808, 1865, 0, 3200, 3456, 3800, 4400, 0, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, DRM_MODE_TYPE_DEFAULT, "1800x3200_60.00" },
{ 712750, 2160, 2163, 2168, 2237, 0, 3840, 4160, 4576, 5312, 0, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, DRM_MODE_TYPE_DEFAULT, "2160x3840_60.00" },
{ 813000, 2304, 2307, 2312, 2386, 0, 4096, 4440, 4888, 5680, 0, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, DRM_MODE_TYPE_DEFAULT, "2304x4096_60.00" },
{ 1276500, 2880, 2883, 2888, 2982, 0, 5120, 5560, 6128, 7136, 0, 0, DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC, DRM_MODE_TYPE_DEFAULT, "2880x5120_60.00" },
};

View File

@ -601,11 +601,21 @@ init_modes (MetaGpuKms *gpu_kms,
g_hash_table_destroy (modes_table); g_hash_table_destroy (modes_table);
for (i = 0; i < G_N_ELEMENTS (meta_default_drm_mode_infos); i++) for (i = 0; i < G_N_ELEMENTS (meta_default_landscape_drm_mode_infos); i++)
{ {
MetaCrtcMode *mode; MetaCrtcMode *mode;
mode = create_mode (&meta_default_drm_mode_infos[i], (long) mode_id); mode = create_mode (&meta_default_landscape_drm_mode_infos[i], mode_id);
modes = g_list_append (modes, mode);
mode_id++;
}
for (i = 0; i < G_N_ELEMENTS (meta_default_portrait_drm_mode_infos); i++)
{
MetaCrtcMode *mode;
mode = create_mode (&meta_default_portrait_drm_mode_infos[i], mode_id);
modes = g_list_append (modes, mode); modes = g_list_append (modes, mode);
mode_id++; mode_id++;

View File

@ -357,7 +357,10 @@ static void
add_common_modes (MetaOutput *output, add_common_modes (MetaOutput *output,
MetaGpuKms *gpu_kms) MetaGpuKms *gpu_kms)
{ {
const drmModeModeInfo *drm_mode;
MetaCrtcMode *crtc_mode;
GPtrArray *array; GPtrArray *array;
float refresh_rate;
unsigned i; unsigned i;
unsigned max_hdisplay = 0; unsigned max_hdisplay = 0;
unsigned max_vdisplay = 0; unsigned max_vdisplay = 0;
@ -365,9 +368,6 @@ add_common_modes (MetaOutput *output,
for (i = 0; i < output->n_modes; i++) for (i = 0; i < output->n_modes; i++)
{ {
const drmModeModeInfo *drm_mode;
float refresh_rate;
drm_mode = output->modes[i]->driver_private; drm_mode = output->modes[i]->driver_private;
refresh_rate = meta_calculate_drm_mode_refresh_rate (drm_mode); refresh_rate = meta_calculate_drm_mode_refresh_rate (drm_mode);
max_hdisplay = MAX (max_hdisplay, drm_mode->hdisplay); max_hdisplay = MAX (max_hdisplay, drm_mode->hdisplay);
@ -379,22 +379,37 @@ add_common_modes (MetaOutput *output,
max_refresh_rate *= (1 + SYNC_TOLERANCE); max_refresh_rate *= (1 + SYNC_TOLERANCE);
array = g_ptr_array_new (); array = g_ptr_array_new ();
for (i = 0; i < G_N_ELEMENTS (meta_default_drm_mode_infos); i++) if (max_hdisplay > max_vdisplay)
{ {
const drmModeModeInfo *drm_mode; for (i = 0; i < G_N_ELEMENTS (meta_default_landscape_drm_mode_infos); i++)
float refresh_rate; {
MetaCrtcMode *crtc_mode; drm_mode = &meta_default_landscape_drm_mode_infos[i];
refresh_rate = meta_calculate_drm_mode_refresh_rate (drm_mode);
if (drm_mode->hdisplay > max_hdisplay ||
drm_mode->vdisplay > max_vdisplay ||
refresh_rate > max_refresh_rate)
continue;
drm_mode = &meta_default_drm_mode_infos[i]; crtc_mode = meta_gpu_kms_get_mode_from_drm_mode (gpu_kms,
refresh_rate = meta_calculate_drm_mode_refresh_rate (drm_mode); drm_mode);
if (drm_mode->hdisplay > max_hdisplay || g_ptr_array_add (array, crtc_mode);
drm_mode->vdisplay > max_vdisplay || }
refresh_rate > max_refresh_rate) }
continue; else
{
for (i = 0; i < G_N_ELEMENTS (meta_default_portrait_drm_mode_infos); i++)
{
drm_mode = &meta_default_portrait_drm_mode_infos[i];
refresh_rate = meta_calculate_drm_mode_refresh_rate (drm_mode);
if (drm_mode->hdisplay > max_hdisplay ||
drm_mode->vdisplay > max_vdisplay ||
refresh_rate > max_refresh_rate)
continue;
crtc_mode = meta_gpu_kms_get_mode_from_drm_mode (gpu_kms, crtc_mode = meta_gpu_kms_get_mode_from_drm_mode (gpu_kms,
drm_mode); drm_mode);
g_ptr_array_add (array, crtc_mode); g_ptr_array_add (array, crtc_mode);
}
} }
output->modes = g_renew (MetaCrtcMode *, output->modes, output->modes = g_renew (MetaCrtcMode *, output->modes,