kms/connector: Make property ID fetching more declarative

Instead of relatively verbosely going through the DRM properties finding
the properties we care about and saving their ID's, add a more
declarative way to fetch property metadata. This'll allow for fetching
more property IDs with relatively less code, which will be useful for
the atomic backend.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1488>
This commit is contained in:
Jonas Ådahl 2020-07-13 21:42:04 +02:00 committed by Marge Bot
parent 309651df6b
commit df89e8ce4b
3 changed files with 157 additions and 40 deletions

View File

@ -30,6 +30,20 @@
#include "backends/native/meta-kms-mode-private.h"
#include "backends/native/meta-kms-update-private.h"
typedef enum _MetaKmsConnectorProp
{
META_KMS_CONNECTOR_PROP_DPMS = 0,
META_KMS_CONNECTOR_PROP_UNDERSCAN,
META_KMS_CONNECTOR_PROP_UNDERSCAN_HBORDER,
META_KMS_CONNECTOR_PROP_UNDERSCAN_VBORDER,
META_KMS_CONNECTOR_N_PROPS
} MetaKmsConnectorProp;
typedef struct _MetaKmsConnectorPropTable
{
MetaKmsProp props[META_KMS_CONNECTOR_N_PROPS];
} MetaKmsConnectorPropTable;
struct _MetaKmsConnector
{
GObject parent;
@ -43,10 +57,8 @@ struct _MetaKmsConnector
MetaKmsConnectorState *current_state;
uint32_t dpms_prop_id;
uint32_t underscan_prop_id;
uint32_t underscan_hborder_prop_id;
uint32_t underscan_vborder_prop_id;
MetaKmsConnectorPropTable prop_table;
uint32_t edid_blob_id;
uint32_t tile_blob_id;
};
@ -64,9 +76,12 @@ meta_kms_connector_update_set_dpms_state (MetaKmsConnector *connector,
MetaKmsUpdate *update,
uint64_t state)
{
uint32_t prop_id;
prop_id = connector->prop_table.props[META_KMS_CONNECTOR_PROP_DPMS].prop_id;
meta_kms_update_set_connector_property (update,
connector,
connector->dpms_prop_id,
prop_id,
state);
}
@ -76,17 +91,29 @@ meta_kms_connector_set_underscanning (MetaKmsConnector *connector,
uint64_t hborder,
uint64_t vborder)
{
MetaKmsProp *props = connector->prop_table.props;
uint32_t underscan_prop_id;
uint32_t underscan_hborder_prop_id;
uint32_t underscan_vborder_prop_id;
underscan_prop_id =
props[META_KMS_CONNECTOR_PROP_UNDERSCAN].prop_id;
underscan_hborder_prop_id =
props[META_KMS_CONNECTOR_PROP_UNDERSCAN_HBORDER].prop_id;
underscan_vborder_prop_id =
props[META_KMS_CONNECTOR_PROP_UNDERSCAN_VBORDER].prop_id;
meta_kms_update_set_connector_property (update,
connector,
connector->underscan_prop_id,
underscan_prop_id,
1);
meta_kms_update_set_connector_property (update,
connector,
connector->underscan_hborder_prop_id,
underscan_hborder_prop_id,
hborder);
meta_kms_update_set_connector_property (update,
connector,
connector->underscan_vborder_prop_id,
underscan_vborder_prop_id,
vborder);
}
@ -94,9 +121,13 @@ void
meta_kms_connector_unset_underscanning (MetaKmsConnector *connector,
MetaKmsUpdate *update)
{
MetaKmsProp *props = connector->prop_table.props;
uint32_t underscan_prop_id;
underscan_prop_id = props[META_KMS_CONNECTOR_PROP_UNDERSCAN].prop_id;
meta_kms_update_set_connector_property (update,
connector,
connector->underscan_prop_id,
underscan_prop_id,
0);
}
@ -144,7 +175,12 @@ meta_kms_connector_get_current_state (MetaKmsConnector *connector)
gboolean
meta_kms_connector_is_underscanning_supported (MetaKmsConnector *connector)
{
return connector->underscan_prop_id != 0;
uint32_t underscan_prop_id;
underscan_prop_id =
connector->prop_table.props[META_KMS_CONNECTOR_PROP_UNDERSCAN].prop_id;
return underscan_prop_id != 0;
}
static void
@ -543,38 +579,42 @@ meta_kms_connector_predict_state (MetaKmsConnector *connector,
}
static void
find_property_ids (MetaKmsConnector *connector,
MetaKmsImplDevice *impl_device,
drmModeConnector *drm_connector)
init_properties (MetaKmsConnector *connector,
MetaKmsImplDevice *impl_device,
drmModeConnector *drm_connector)
{
int fd;
int i;
MetaKmsConnectorPropTable *prop_table = &connector->prop_table;
fd = meta_kms_impl_device_get_fd (impl_device);
for (i = 0; i < drm_connector->count_props; i++)
{
drmModePropertyPtr prop;
prop = drmModeGetProperty (fd, drm_connector->props[i]);
if (!prop)
continue;
if ((prop->flags & DRM_MODE_PROP_ENUM) &&
strcmp (prop->name, "DPMS") == 0)
connector->dpms_prop_id = prop->prop_id;
else if ((prop->flags & DRM_MODE_PROP_ENUM) &&
strcmp (prop->name, "underscan") == 0)
connector->underscan_prop_id = prop->prop_id;
else if ((prop->flags & DRM_MODE_PROP_RANGE) &&
strcmp (prop->name, "underscan hborder") == 0)
connector->underscan_hborder_prop_id = prop->prop_id;
else if ((prop->flags & DRM_MODE_PROP_RANGE) &&
strcmp (prop->name, "underscan vborder") == 0)
connector->underscan_vborder_prop_id = prop->prop_id;
drmModeFreeProperty (prop);
*prop_table = (MetaKmsConnectorPropTable) {
.props = {
[META_KMS_CONNECTOR_PROP_DPMS] =
{
.name = "DPMS",
.type = DRM_MODE_PROP_ENUM,
},
[META_KMS_CONNECTOR_PROP_UNDERSCAN] =
{
.name = "underscan",
.type = DRM_MODE_PROP_ENUM,
},
[META_KMS_CONNECTOR_PROP_UNDERSCAN_HBORDER] =
{
.name = "underscan hborder",
.type = DRM_MODE_PROP_RANGE,
},
[META_KMS_CONNECTOR_PROP_UNDERSCAN_VBORDER] =
{
.name = "underscan vborder",
.type = DRM_MODE_PROP_RANGE,
},
}
};
meta_kms_impl_device_init_prop_table (impl_device,
drm_connector->props,
drm_connector->count_props,
connector->prop_table.props,
META_KMS_CONNECTOR_N_PROPS);
}
static char *
@ -633,7 +673,7 @@ meta_kms_connector_new (MetaKmsImplDevice *impl_device,
connector->type_id = drm_connector->connector_type_id;
connector->name = make_connector_name (drm_connector);
find_property_ids (connector, impl_device, drm_connector);
init_properties (connector, impl_device, drm_connector);
meta_kms_connector_read_state (connector, impl_device,
drm_connector,

View File

@ -337,6 +337,69 @@ meta_kms_impl_device_add_fake_plane (MetaKmsImplDevice *impl_device,
return plane;
}
static MetaKmsProp *
find_prop (MetaKmsProp *props,
int n_props,
const char *name)
{
int i;
for (i = 0; i < n_props; i++)
{
MetaKmsProp *prop = &props[i];
g_warn_if_fail (prop->name);
if (g_strcmp0 (prop->name, name) == 0)
return prop;
}
return NULL;
}
void
meta_kms_impl_device_init_prop_table (MetaKmsImplDevice *impl_device,
uint32_t *drm_props,
int n_drm_props,
MetaKmsProp *props,
int n_props)
{
int fd;
uint32_t i;
fd = meta_kms_impl_device_get_fd (impl_device);
for (i = 0; i < n_drm_props; i++)
{
drmModePropertyRes *drm_prop;
MetaKmsProp *prop;
drm_prop = drmModeGetProperty (fd, drm_props[i]);
if (!drm_prop)
continue;
prop = find_prop (props, n_props, drm_prop->name);
if (!prop)
{
drmModeFreeProperty (drm_prop);
continue;
}
if (!(drm_prop->flags & prop->type))
{
g_warning ("DRM property '%s' (%u) had unexpected flags (0x%x), "
"ignoring",
drm_prop->name, drm_props[i], drm_prop->flags);
drmModeFreeProperty (drm_prop);
continue;
}
prop->prop_id = drm_props[i];
drmModeFreeProperty (drm_prop);
}
}
static void
init_planes (MetaKmsImplDevice *impl_device)
{

View File

@ -35,6 +35,14 @@ typedef struct _MetaKmsDeviceCaps
uint64_t cursor_height;
} MetaKmsDeviceCaps;
typedef struct _MetaKmsProp
{
const char *name;
uint32_t type;
uint32_t prop_id;
} MetaKmsProp;
#define META_TYPE_KMS_IMPL_DEVICE (meta_kms_impl_device_get_type ())
G_DECLARE_FINAL_TYPE (MetaKmsImplDevice, meta_kms_impl_device,
META, KMS_IMPL_DEVICE,
@ -77,6 +85,12 @@ MetaKmsPlane * meta_kms_impl_device_add_fake_plane (MetaKmsImplDevice *impl_devi
MetaKmsPlaneType plane_type,
MetaKmsCrtc *crtc);
void meta_kms_impl_device_init_prop_table (MetaKmsImplDevice *impl_device,
uint32_t *drm_props,
int n_drm_props,
MetaKmsProp *props,
int n_props);
int meta_kms_impl_device_close (MetaKmsImplDevice *impl_device);
MetaKmsImplDevice * meta_kms_impl_device_new (MetaKmsDevice *device,