mirror of
https://github.com/brl/mutter.git
synced 2024-11-24 17:10:40 -05:00
monitor-manager-kms: Add common modes
Some output devices only advertise their preferred mode even though they're able to display others too. This means we can include some common modes in each output's supported list. This is particularly important for mirroring, since we can only mirror outputs which are using the same resolution. https://bugzilla.gnome.org/show_bug.cgi?id=744544
This commit is contained in:
parent
5cae628f37
commit
9a076076c0
@ -376,6 +376,8 @@ AC_CHECK_DECL([GL_EXT_x11_sync_object],
|
||||
[AC_MSG_ERROR([GL_EXT_x11_sync_object definition not found, please update your GL headers])],
|
||||
[#include <GL/glx.h>])
|
||||
|
||||
AC_PATH_PROG([CVT],[cvt],[])
|
||||
|
||||
#### Warnings (last since -Werror can disturb other tests)
|
||||
|
||||
# Stay command-line compatible with the gnome-common configure option. Here
|
||||
|
@ -363,6 +363,7 @@ libmutter_la_SOURCES += \
|
||||
backends/native/meta-clutter-backend-native.h \
|
||||
backends/native/meta-cursor-renderer-native.c \
|
||||
backends/native/meta-cursor-renderer-native.h \
|
||||
backends/native/meta-default-modes.h \
|
||||
backends/native/meta-idle-monitor-native.c \
|
||||
backends/native/meta-idle-monitor-native.h \
|
||||
backends/native/meta-input-settings-native.c \
|
||||
@ -508,6 +509,7 @@ EXTRA_DIST += \
|
||||
org.freedesktop.login1.xml \
|
||||
org.gnome.Mutter.DisplayConfig.xml \
|
||||
org.gnome.Mutter.IdleMonitor.xml \
|
||||
backends/native/gen-default-modes.py \
|
||||
$(NULL)
|
||||
|
||||
BUILT_SOURCES = \
|
||||
@ -565,6 +567,12 @@ $(dbus_login1_built_sources) : Makefile.am org.freedesktop.login1.xml
|
||||
--c-generate-autocleanup all \
|
||||
$(srcdir)/org.freedesktop.login1.xml
|
||||
|
||||
backends/native/meta-default-modes.h: backends/native/gen-default-modes.py Makefile.am
|
||||
@if test -n "$(CVT)"; then \
|
||||
if $(AM_V_P); then PS4= set -x; else echo " GEN $@"; fi; \
|
||||
python $< > $@; \
|
||||
fi
|
||||
|
||||
.SECONDEXPANSION:
|
||||
|
||||
define protostability
|
||||
|
89
src/backends/native/gen-default-modes.py
Normal file
89
src/backends/native/gen-default-modes.py
Normal file
@ -0,0 +1,89 @@
|
||||
# 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, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
# 02111-1307, USA.
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
common_resolutions = [
|
||||
# 4:3
|
||||
(800, 600),
|
||||
(1024, 768),
|
||||
(1152, 864),
|
||||
(1280, 960),
|
||||
(1400, 1050),
|
||||
(1440, 1080),
|
||||
(1600, 1200),
|
||||
(1920, 1440),
|
||||
(2048, 1536),
|
||||
# 16:10
|
||||
(1280, 800),
|
||||
(1440, 900),
|
||||
(1680, 1050),
|
||||
(1920, 1200),
|
||||
(2560, 1600),
|
||||
# 16:9
|
||||
(1280, 720),
|
||||
(1366, 768),
|
||||
(1600, 900),
|
||||
(1920, 1080),
|
||||
(2048, 1152),
|
||||
(2560, 1440),
|
||||
(2880, 1620),
|
||||
(3200, 1800),
|
||||
(3840, 2160),
|
||||
(4096, 2304),
|
||||
(5120, 2880),
|
||||
]
|
||||
|
||||
output_lines = [
|
||||
"/* Generated by gen-default-modes.py */\n",
|
||||
"const drmModeModeInfo meta_default_drm_mode_infos[] = {",
|
||||
]
|
||||
|
||||
def sync_flags(hsync, vsync):
|
||||
flags = "DRM_MODE_FLAG_"
|
||||
flags += "NHSYNC" if hsync[0] is '-' else "PHSYNC"
|
||||
flags += " | DRM_MODE_FLAG_"
|
||||
flags += "NVSYNC" if vsync[0] is '-' else "PVSYNC"
|
||||
return flags
|
||||
|
||||
def 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, %s }," % \
|
||||
(int(float(sline[2]) * 1000),
|
||||
int(sline[3]),
|
||||
int(sline[4]),
|
||||
int(sline[5]),
|
||||
int(sline[6]),
|
||||
int(sline[7]),
|
||||
int(sline[8]),
|
||||
int(sline[9]),
|
||||
int(sline[10]),
|
||||
sync_flags(sline[11], sline[12]),
|
||||
sline[1])
|
||||
|
||||
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(drm_mode_info_from_modeline(line))
|
||||
cvt.close()
|
||||
output_lines.append("};")
|
||||
|
||||
for line in output_lines:
|
||||
sys.stdout.write(line + "\n")
|
||||
sys.stdout.flush()
|
29
src/backends/native/meta-default-modes.h
Normal file
29
src/backends/native/meta-default-modes.h
Normal file
@ -0,0 +1,29 @@
|
||||
/* Generated by gen-default-modes.py */
|
||||
|
||||
const drmModeModeInfo meta_default_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" },
|
||||
{ 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" },
|
||||
{ 101250, 1280, 1360, 1488, 1696, 0, 960, 963, 967, 996, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "1280x960_60.00" },
|
||||
{ 121750, 1400, 1488, 1632, 1864, 0, 1050, 1053, 1057, 1089, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "1400x1050_60.00" },
|
||||
{ 129000, 1440, 1528, 1680, 1920, 0, 1080, 1083, 1087, 1120, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "1440x1080_60.00" },
|
||||
{ 161000, 1600, 1712, 1880, 2160, 0, 1200, 1203, 1207, 1245, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "1600x1200_60.00" },
|
||||
{ 233500, 1920, 2064, 2264, 2608, 0, 1440, 1443, 1447, 1493, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "1920x1440_60.00" },
|
||||
{ 267250, 2048, 2208, 2424, 2800, 0, 1536, 1539, 1543, 1592, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "2048x1536_60.00" },
|
||||
{ 83500, 1280, 1352, 1480, 1680, 0, 800, 803, 809, 831, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "1280x800_60.00" },
|
||||
{ 106500, 1440, 1528, 1672, 1904, 0, 900, 903, 909, 934, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "1440x900_60.00" },
|
||||
{ 146250, 1680, 1784, 1960, 2240, 0, 1050, 1053, 1059, 1089, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "1680x1050_60.00" },
|
||||
{ 193250, 1920, 2056, 2256, 2592, 0, 1200, 1203, 1209, 1245, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "1920x1200_60.00" },
|
||||
{ 348500, 2560, 2760, 3032, 3504, 0, 1600, 1603, 1609, 1658, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "2560x1600_60.00" },
|
||||
{ 74500, 1280, 1344, 1472, 1664, 0, 720, 723, 728, 748, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "1280x720_60.00" },
|
||||
{ 85250, 1368, 1440, 1576, 1784, 0, 768, 771, 781, 798, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "1368x768_60.00" },
|
||||
{ 118250, 1600, 1696, 1856, 2112, 0, 900, 903, 908, 934, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "1600x900_60.00" },
|
||||
{ 173000, 1920, 2048, 2248, 2576, 0, 1080, 1083, 1088, 1120, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "1920x1080_60.00" },
|
||||
{ 197000, 2048, 2184, 2400, 2752, 0, 1152, 1155, 1160, 1195, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "2048x1152_60.00" },
|
||||
{ 312250, 2560, 2752, 3024, 3488, 0, 1440, 1443, 1448, 1493, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "2560x1440_60.00" },
|
||||
{ 396250, 2880, 3096, 3408, 3936, 0, 1620, 1623, 1628, 1679, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "2880x1620_60.00" },
|
||||
{ 492000, 3200, 3456, 3800, 4400, 0, 1800, 1803, 1808, 1865, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "3200x1800_60.00" },
|
||||
{ 712750, 3840, 4160, 4576, 5312, 0, 2160, 2163, 2168, 2237, 0, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC, DRM_MODE_TYPE_DEFAULT, "3840x2160_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" },
|
||||
};
|
@ -45,8 +45,11 @@
|
||||
|
||||
#include <gudev/gudev.h>
|
||||
|
||||
#include "meta-default-modes.h"
|
||||
|
||||
#define ALL_TRANSFORMS (META_MONITOR_TRANSFORM_FLIPPED_270 + 1)
|
||||
#define ALL_TRANSFORMS_MASK ((1 << ALL_TRANSFORMS) - 1)
|
||||
#define SYNC_TOLERANCE 0.01 /* 1 percent */
|
||||
|
||||
typedef struct {
|
||||
drmModeConnector *connector;
|
||||
@ -69,6 +72,8 @@ typedef struct {
|
||||
int suggested_x;
|
||||
int suggested_y;
|
||||
uint32_t hotplug_mode_update;
|
||||
|
||||
gboolean has_scaling;
|
||||
} MetaOutputKms;
|
||||
|
||||
typedef struct {
|
||||
@ -267,7 +272,9 @@ find_connector_properties (MetaMonitorManagerKms *manager_kms,
|
||||
else if ((prop->flags & DRM_MODE_PROP_RANGE) &&
|
||||
strcmp (prop->name, "hotplug_mode_update") == 0)
|
||||
output_kms->hotplug_mode_update = output_kms->connector->prop_values[i];
|
||||
|
||||
else if (strcmp (prop->name, "scaling mode") == 0)
|
||||
output_kms->has_scaling = TRUE;
|
||||
|
||||
drmModeFreeProperty (prop);
|
||||
}
|
||||
}
|
||||
@ -389,33 +396,63 @@ find_meta_mode (MetaMonitorManager *manager,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static float
|
||||
drm_mode_vrefresh (const drmModeModeInfo *mode)
|
||||
{
|
||||
float refresh = 0.0;
|
||||
|
||||
if (mode->vrefresh > 0.0)
|
||||
return mode->vrefresh;
|
||||
|
||||
if (mode->htotal > 0 && mode->vtotal > 0)
|
||||
{
|
||||
/* Calculate refresh rate in milliHz first for extra precision. */
|
||||
refresh = (mode->clock * 1000000LL) / mode->htotal;
|
||||
refresh += (mode->vtotal / 2);
|
||||
refresh /= mode->vtotal;
|
||||
if (mode->flags & DRM_MODE_FLAG_INTERLACE)
|
||||
refresh *= 2;
|
||||
if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
|
||||
refresh /= 2;
|
||||
if (mode->vscan > 1)
|
||||
refresh /= mode->vscan;
|
||||
refresh /= 1000.0;
|
||||
}
|
||||
return refresh;
|
||||
}
|
||||
|
||||
static void
|
||||
init_mode (MetaMonitorMode *mode,
|
||||
drmModeModeInfo *drm_mode,
|
||||
long mode_id)
|
||||
init_mode (MetaMonitorMode *mode,
|
||||
const drmModeModeInfo *drm_mode,
|
||||
long mode_id)
|
||||
{
|
||||
mode->mode_id = mode_id;
|
||||
mode->name = g_strndup (drm_mode->name, DRM_DISPLAY_MODE_LEN);
|
||||
mode->width = drm_mode->hdisplay;
|
||||
mode->height = drm_mode->vdisplay;
|
||||
mode->flags = drm_mode->flags;
|
||||
|
||||
/* Calculate refresh rate in milliHz first for extra precision. */
|
||||
mode->refresh_rate = (drm_mode->clock * 1000000LL) / drm_mode->htotal;
|
||||
mode->refresh_rate += (drm_mode->vtotal / 2);
|
||||
mode->refresh_rate /= drm_mode->vtotal;
|
||||
if (drm_mode->flags & DRM_MODE_FLAG_INTERLACE)
|
||||
mode->refresh_rate *= 2;
|
||||
if (drm_mode->flags & DRM_MODE_FLAG_DBLSCAN)
|
||||
mode->refresh_rate /= 2;
|
||||
if (drm_mode->vscan > 1)
|
||||
mode->refresh_rate /= drm_mode->vscan;
|
||||
mode->refresh_rate /= 1000.0;
|
||||
|
||||
mode->refresh_rate = drm_mode_vrefresh (drm_mode);
|
||||
mode->driver_private = g_slice_dup (drmModeModeInfo, drm_mode);
|
||||
mode->driver_notify = (GDestroyNotify)meta_monitor_mode_destroy_notify;
|
||||
}
|
||||
|
||||
static int
|
||||
compare_modes (const void *one,
|
||||
const void *two)
|
||||
{
|
||||
MetaMonitorMode *a = *(MetaMonitorMode **) one;
|
||||
MetaMonitorMode *b = *(MetaMonitorMode **) two;
|
||||
|
||||
if (a->width != b->width)
|
||||
return a->width > b->width ? -1 : 1;
|
||||
if (a->height != b->height)
|
||||
return a->height > b->height ? -1 : 1;
|
||||
if (a->refresh_rate != b->refresh_rate)
|
||||
return a->refresh_rate > b->refresh_rate ? -1 : 1;
|
||||
|
||||
return g_strcmp0 (b->name, a->name);
|
||||
}
|
||||
|
||||
static MetaOutput *
|
||||
find_output_by_id (MetaOutput *outputs,
|
||||
unsigned n_outputs,
|
||||
@ -628,6 +665,47 @@ init_crtc_rotations (MetaMonitorManager *manager,
|
||||
drmModeFreePlaneResources (planes);
|
||||
}
|
||||
|
||||
static void
|
||||
add_common_modes (MetaMonitorManager *manager,
|
||||
MetaOutput *output)
|
||||
{
|
||||
const drmModeModeInfo *mode;
|
||||
GPtrArray *array;
|
||||
unsigned i;
|
||||
unsigned max_hdisplay = 0;
|
||||
unsigned max_vdisplay = 0;
|
||||
float max_vrefresh = 0.0;
|
||||
|
||||
for (i = 0; i < output->n_modes; i++)
|
||||
{
|
||||
mode = output->modes[i]->driver_private;
|
||||
max_hdisplay = MAX (max_hdisplay, mode->hdisplay);
|
||||
max_vdisplay = MAX (max_vdisplay, mode->vdisplay);
|
||||
max_vrefresh = MAX (max_vrefresh, drm_mode_vrefresh (mode));
|
||||
}
|
||||
|
||||
max_vrefresh = MAX (max_vrefresh, 60.0);
|
||||
max_vrefresh *= (1 + SYNC_TOLERANCE);
|
||||
|
||||
array = g_ptr_array_new ();
|
||||
for (i = 0; i < G_N_ELEMENTS (meta_default_drm_mode_infos); i++)
|
||||
{
|
||||
mode = &meta_default_drm_mode_infos[i];
|
||||
if (mode->hdisplay > max_hdisplay ||
|
||||
mode->vdisplay > max_vdisplay ||
|
||||
drm_mode_vrefresh (mode) > max_vrefresh)
|
||||
continue;
|
||||
|
||||
g_ptr_array_add (array, find_meta_mode (manager, mode));
|
||||
}
|
||||
|
||||
output->modes = g_renew (MetaMonitorMode *, output->modes, output->n_modes + array->len);
|
||||
memcpy (output->modes + output->n_modes, array->pdata, array->len * sizeof (MetaMonitorMode *));
|
||||
output->n_modes += array->len;
|
||||
|
||||
g_ptr_array_free (array, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
init_crtc (MetaCRTC *crtc,
|
||||
MetaMonitorManager *manager,
|
||||
@ -719,6 +797,17 @@ init_output (MetaOutput *output,
|
||||
output->preferred_mode = output->modes[0];
|
||||
|
||||
output_kms->connector = connector;
|
||||
find_connector_properties (manager_kms, output_kms);
|
||||
|
||||
/* FIXME: MSC feature bit? */
|
||||
/* Presume that if the output supports scaling, then we have
|
||||
* a panel fitter capable of adjusting any mode to suit.
|
||||
*/
|
||||
if (output_kms->has_scaling)
|
||||
add_common_modes (manager, output);
|
||||
|
||||
qsort (output->modes, output->n_modes, sizeof (MetaMonitorMode *), compare_modes);
|
||||
|
||||
output_kms->n_encoders = connector->count_encoders;
|
||||
output_kms->encoders = g_new0 (drmModeEncoderPtr, output_kms->n_encoders);
|
||||
|
||||
@ -782,7 +871,6 @@ init_output (MetaOutput *output,
|
||||
output->is_presentation = FALSE;
|
||||
}
|
||||
|
||||
find_connector_properties (manager_kms, output_kms);
|
||||
output->suggested_x = output_kms->suggested_x;
|
||||
output->suggested_y = output_kms->suggested_y;
|
||||
output->hotplug_mode_update = output_kms->hotplug_mode_update;
|
||||
@ -951,7 +1039,7 @@ init_modes (MetaMonitorManager *manager,
|
||||
}
|
||||
}
|
||||
|
||||
manager->n_modes = g_hash_table_size (modes);
|
||||
manager->n_modes = g_hash_table_size (modes) + G_N_ELEMENTS (meta_default_drm_mode_infos);
|
||||
manager->modes = g_new0 (MetaMonitorMode, manager->n_modes);
|
||||
|
||||
g_hash_table_iter_init (&iter, modes);
|
||||
@ -967,6 +1055,16 @@ init_modes (MetaMonitorManager *manager,
|
||||
}
|
||||
|
||||
g_hash_table_destroy (modes);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (meta_default_drm_mode_infos); i++)
|
||||
{
|
||||
MetaMonitorMode *mode;
|
||||
|
||||
mode = &manager->modes[mode_id];
|
||||
init_mode (mode, &meta_default_drm_mode_infos[i], (long) mode_id);
|
||||
|
||||
mode_id++;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user