kms/device: Get driver details before constructing impl device

Eventually the type of impl device will depend on the driver details, so
get that information before constructing the impl device. This commit
doesn't introduce any new usage of the details, it just prepares for
the future.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1488>
This commit is contained in:
Jonas Ådahl 2020-09-29 16:39:12 +02:00 committed by Marge Bot
parent 84bde805fe
commit deb8f07c65
2 changed files with 60 additions and 19 deletions

View File

@ -236,6 +236,26 @@ typedef struct _CreateImplDeviceData
char *out_driver_description;
} CreateImplDeviceData;
static gboolean
get_driver_info (int fd,
char **name,
char **description)
{
drmVersion *drm_version;
drm_version = drmGetVersion (fd);
if (!drm_version)
return FALSE;
*name = g_strndup (drm_version->name,
drm_version->name_len);
*description = g_strndup (drm_version->desc,
drm_version->desc_len);
drmFreeVersion (drm_version);
return TRUE;
}
static MetaKmsImplDevice *
meta_create_kms_impl_device (MetaKmsDevice *device,
MetaKmsImpl *impl,
@ -243,6 +263,8 @@ meta_create_kms_impl_device (MetaKmsDevice *device,
GError **error)
{
int ret;
g_autofree char *driver_name = NULL;
g_autofree char *driver_description = NULL;
meta_assert_in_kms_impl (meta_kms_impl_get_kms (impl));
@ -255,10 +277,18 @@ meta_create_kms_impl_device (MetaKmsDevice *device,
return NULL;
}
if (!get_driver_info (fd, &driver_name, &driver_description))
{
driver_name = g_strdup ("unknown");
driver_description = g_strdup ("Unknown");
}
return g_initable_new (META_TYPE_KMS_IMPL_DEVICE_SIMPLE, NULL, error,
"device", device,
"impl", impl,
"fd", fd,
"driver-name", driver_name,
"driver-description", driver_description,
NULL);
}

View File

@ -45,6 +45,8 @@ enum
PROP_DEVICE,
PROP_IMPL,
PROP_FD,
PROP_DRIVER_NAME,
PROP_DRIVER_DESCRIPTION,
N_PROPS
};
@ -549,24 +551,6 @@ init_fallback_modes (MetaKmsImplDevice *impl_device)
priv->fallback_modes = g_list_reverse (modes);
}
static void
init_info (MetaKmsImplDevice *impl_device)
{
MetaKmsImplDevicePrivate *priv =
meta_kms_impl_device_get_instance_private (impl_device);
drmVersion *drm_version;
drm_version = drmGetVersion (priv->fd);
if (!drm_version)
return;
priv->driver_name = g_strndup (drm_version->name,
drm_version->name_len);
priv->driver_description = g_strndup (drm_version->desc,
drm_version->desc_len);
drmFreeVersion (drm_version);
}
void
meta_kms_impl_device_update_states (MetaKmsImplDevice *impl_device)
{
@ -693,6 +677,12 @@ meta_kms_impl_device_get_property (GObject *object,
case PROP_FD:
g_value_set_int (value, priv->fd);
break;
case PROP_DRIVER_NAME:
g_value_set_string (value, priv->driver_name);
break;
case PROP_DRIVER_DESCRIPTION:
g_value_set_string (value, priv->driver_name);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -720,6 +710,12 @@ meta_kms_impl_device_set_property (GObject *object,
case PROP_FD:
priv->fd = g_value_get_int (value);
break;
case PROP_DRIVER_NAME:
priv->driver_name = g_value_dup_string (value);
break;
case PROP_DRIVER_DESCRIPTION:
priv->driver_description = g_value_dup_string (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -769,7 +765,6 @@ meta_kms_impl_device_initable_init (GInitable *initable,
init_crtcs (impl_device, drm_resources);
init_planes (impl_device);
init_info (impl_device);
init_fallback_modes (impl_device);
@ -829,5 +824,21 @@ meta_kms_impl_device_class_init (MetaKmsImplDeviceClass *klass)
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_props[PROP_DRIVER_NAME] =
g_param_spec_string ("driver-name",
"driver-name",
"DRM device driver name",
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
obj_props[PROP_DRIVER_DESCRIPTION] =
g_param_spec_string ("driver-description",
"driver-description",
"DRM device driver description",
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPS, obj_props);
}