backends/native: Update PropTable on hotplug and remove parse callback

Updating the PropTable has the side effect that the parse callback now
also gets called on hotplug but it is used to initialize data. The parse
callbacks are moved to the read_state functions which are aware if this
is an initializing call or just an update.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2379>
This commit is contained in:
Sebastian Wick 2022-04-20 22:43:13 +02:00 committed by Marge Bot
parent 1e06b346cb
commit 981524c268
5 changed files with 89 additions and 149 deletions

View File

@ -675,6 +675,13 @@ meta_kms_connector_read_state (MetaKmsConnector *connector,
current_state = g_steal_pointer (&connector->current_state); current_state = g_steal_pointer (&connector->current_state);
changes = META_KMS_UPDATE_CHANGE_NONE; changes = META_KMS_UPDATE_CHANGE_NONE;
meta_kms_impl_device_update_prop_table (impl_device,
drm_connector->props,
drm_connector->prop_values,
drm_connector->count_props,
connector->prop_table.props,
META_KMS_CONNECTOR_N_PROPS);
if (!drm_connector) if (!drm_connector)
{ {
if (current_state) if (current_state)
@ -1048,14 +1055,6 @@ init_properties (MetaKmsConnector *connector,
}, },
} }
}; };
meta_kms_impl_device_init_prop_table (impl_device,
drm_connector->props,
drm_connector->prop_values,
drm_connector->count_props,
connector->prop_table.props,
META_KMS_CONNECTOR_N_PROPS,
NULL);
} }
static char * static char *

View File

@ -156,24 +156,6 @@ meta_kms_crtc_state_changes (MetaKmsCrtcState *state,
return META_KMS_UPDATE_CHANGE_NONE; return META_KMS_UPDATE_CHANGE_NONE;
} }
static int
find_prop_idx (MetaKmsProp *prop,
uint32_t *drm_props,
int n_drm_props)
{
int i;
g_return_val_if_fail (prop->prop_id > 0, -1);
for (i = 0; i < n_drm_props; i++)
{
if (drm_props[i] == prop->prop_id)
return i;
}
return -1;
}
static void static void
clear_gamma_state (MetaKmsCrtcState *crtc_state) clear_gamma_state (MetaKmsCrtcState *crtc_state)
{ {
@ -192,7 +174,13 @@ meta_kms_crtc_read_state (MetaKmsCrtc *crtc,
MetaKmsCrtcState crtc_state = {0}; MetaKmsCrtcState crtc_state = {0};
MetaKmsUpdateChanges changes = META_KMS_UPDATE_CHANGE_NONE; MetaKmsUpdateChanges changes = META_KMS_UPDATE_CHANGE_NONE;
MetaKmsProp *active_prop; MetaKmsProp *active_prop;
int active_idx;
meta_kms_impl_device_update_prop_table (impl_device,
drm_props->props,
drm_props->prop_values,
drm_props->count_props,
crtc->prop_table.props,
META_KMS_CRTC_N_PROPS);
crtc_state.rect = (MetaRectangle) { crtc_state.rect = (MetaRectangle) {
.x = drm_crtc->x, .x = drm_crtc->x,
@ -205,17 +193,11 @@ meta_kms_crtc_read_state (MetaKmsCrtc *crtc,
crtc_state.drm_mode = drm_crtc->mode; crtc_state.drm_mode = drm_crtc->mode;
active_prop = &crtc->prop_table.props[META_KMS_CRTC_PROP_ACTIVE]; active_prop = &crtc->prop_table.props[META_KMS_CRTC_PROP_ACTIVE];
if (active_prop->prop_id) if (active_prop->prop_id)
{ crtc_state.is_active = !!active_prop->value;
active_idx = find_prop_idx (active_prop,
drm_props->props,
drm_props->count_props);
crtc_state.is_active = !!drm_props->prop_values[active_idx];
}
else else
{ crtc_state.is_active = drm_crtc->mode_valid;
crtc_state.is_active = drm_crtc->mode_valid;
}
read_gamma_state (crtc, &crtc_state, impl_device, drm_crtc); read_gamma_state (crtc, &crtc_state, impl_device, drm_crtc);
@ -350,27 +332,12 @@ meta_kms_crtc_predict_state (MetaKmsCrtc *crtc,
} }
} }
static void
parse_active (MetaKmsImplDevice *impl_device,
MetaKmsProp *prop,
drmModePropertyPtr drm_prop,
uint64_t drm_prop_value,
gpointer user_data)
{
MetaKmsCrtc *crtc = user_data;
crtc->current_state.is_active = !!drm_prop_value;
}
static void static void
init_properties (MetaKmsCrtc *crtc, init_properties (MetaKmsCrtc *crtc,
MetaKmsImplDevice *impl_device, MetaKmsImplDevice *impl_device,
drmModeCrtc *drm_crtc) drmModeCrtc *drm_crtc)
{ {
MetaKmsCrtcPropTable *prop_table = &crtc->prop_table; MetaKmsCrtcPropTable *prop_table = &crtc->prop_table;
int fd;
drmModeObjectProperties *drm_props;
int i;
*prop_table = (MetaKmsCrtcPropTable) { *prop_table = (MetaKmsCrtcPropTable) {
.props = { .props = {
@ -383,7 +350,6 @@ init_properties (MetaKmsCrtc *crtc,
{ {
.name = "ACTIVE", .name = "ACTIVE",
.type = DRM_MODE_PROP_RANGE, .type = DRM_MODE_PROP_RANGE,
.parse = parse_active,
}, },
[META_KMS_CRTC_PROP_GAMMA_LUT] = [META_KMS_CRTC_PROP_GAMMA_LUT] =
{ {
@ -392,32 +358,6 @@ init_properties (MetaKmsCrtc *crtc,
}, },
} }
}; };
fd = meta_kms_impl_device_get_fd (impl_device);
drm_props = drmModeObjectGetProperties (fd,
drm_crtc->crtc_id,
DRM_MODE_OBJECT_CRTC);
meta_kms_impl_device_init_prop_table (impl_device,
drm_props->props,
drm_props->prop_values,
drm_props->count_props,
crtc->prop_table.props,
META_KMS_CRTC_N_PROPS,
crtc);
drmModeFreeObjectProperties (drm_props);
for (i = 0; i < META_KMS_CRTC_N_PROPS; i++)
{
meta_topic (META_DEBUG_KMS,
"%s (%s) CRTC %u property '%s' is %s",
meta_kms_impl_device_get_path (impl_device),
meta_kms_impl_device_get_driver_name (impl_device),
drm_crtc->crtc_id,
prop_table->props[i].name,
prop_table->props[i].prop_id ? "supported" : "unsupported");
}
} }
MetaKmsCrtc * MetaKmsCrtc *

View File

@ -623,13 +623,12 @@ find_prop (MetaKmsProp *props,
} }
void void
meta_kms_impl_device_init_prop_table (MetaKmsImplDevice *impl_device, meta_kms_impl_device_update_prop_table (MetaKmsImplDevice *impl_device,
uint32_t *drm_props, uint32_t *drm_props,
uint64_t *drm_prop_values, uint64_t *drm_prop_values,
int n_drm_props, int n_drm_props,
MetaKmsProp *props, MetaKmsProp *props,
int n_props, int n_props)
gpointer user_data)
{ {
int fd; int fd;
uint32_t i, j; uint32_t i, j;
@ -691,13 +690,6 @@ meta_kms_impl_device_init_prop_table (MetaKmsImplDevice *impl_device,
update_prop_value (prop, prop_value); update_prop_value (prop, prop_value);
if (prop->parse)
{
prop->parse (impl_device, prop,
drm_prop, prop_value,
user_data);
}
drmModeFreeProperty (drm_prop); drmModeFreeProperty (drm_prop);
} }
} }

View File

@ -66,12 +66,6 @@ struct _MetaKmsProp
uint32_t prop_id; uint32_t prop_id;
uint64_t value; uint64_t value;
void (* parse) (MetaKmsImplDevice *impl_device,
MetaKmsProp *prop,
drmModePropertyPtr drm_prop,
uint64_t value,
gpointer user_data);
}; };
#define META_TYPE_KMS_IMPL_DEVICE (meta_kms_impl_device_get_type ()) #define META_TYPE_KMS_IMPL_DEVICE (meta_kms_impl_device_get_type ())
@ -164,13 +158,12 @@ MetaKmsPlane * meta_kms_impl_device_add_fake_plane (MetaKmsImplDevice *impl_devi
MetaKmsPlaneType plane_type, MetaKmsPlaneType plane_type,
MetaKmsCrtc *crtc); MetaKmsCrtc *crtc);
void meta_kms_impl_device_init_prop_table (MetaKmsImplDevice *impl_device, void meta_kms_impl_device_update_prop_table (MetaKmsImplDevice *impl_device,
uint32_t *drm_props, uint32_t *drm_props,
uint64_t *drm_props_values, uint64_t *drm_props_values,
int n_drm_props, int n_drm_props,
MetaKmsProp *props, MetaKmsProp *props,
int n_props, int n_props);
gpointer user_data);
void meta_kms_impl_device_reload_prop_values (MetaKmsImplDevice *impl_device, void meta_kms_impl_device_reload_prop_values (MetaKmsImplDevice *impl_device,
uint32_t *drm_props, uint32_t *drm_props,

View File

@ -190,33 +190,40 @@ meta_kms_plane_is_usable_with (MetaKmsPlane *plane,
} }
static void static void
parse_rotations (MetaKmsImplDevice *impl_device, update_rotations (MetaKmsPlane *plane)
MetaKmsProp *prop,
drmModePropertyPtr drm_prop,
uint64_t drm_prop_value,
gpointer user_data)
{ {
MetaKmsPlane *plane = user_data; MetaKmsProp *prop;
int i; MetaKmsPlaneRotation rotation;
for (i = 0; i < drm_prop->count_enums; i++) prop = &plane->prop_table.props[META_KMS_PLANE_PROP_ROTATION];
rotation = prop->value;
if (rotation & META_KMS_PLANE_ROTATION_ROTATE_0)
{ {
MetaMonitorTransform transform = -1; plane->all_hw_transforms |= 1 << META_MONITOR_TRANSFORM_NORMAL;
plane->rotation_map[META_MONITOR_TRANSFORM_NORMAL] =
1 << prop->enum_values[META_KMS_PLANE_ROTATION_BIT_ROTATE_0].value;
}
if (strcmp (drm_prop->enums[i].name, "rotate-0") == 0) if (rotation & META_KMS_PLANE_ROTATION_ROTATE_90)
transform = META_MONITOR_TRANSFORM_NORMAL; {
else if (strcmp (drm_prop->enums[i].name, "rotate-90") == 0) plane->all_hw_transforms |= 1 << META_MONITOR_TRANSFORM_90;
transform = META_MONITOR_TRANSFORM_90; plane->rotation_map[META_MONITOR_TRANSFORM_90] =
else if (strcmp (drm_prop->enums[i].name, "rotate-180") == 0) 1 << prop->enum_values[META_KMS_PLANE_ROTATION_BIT_ROTATE_90].value;
transform = META_MONITOR_TRANSFORM_180; }
else if (strcmp (drm_prop->enums[i].name, "rotate-270") == 0)
transform = META_MONITOR_TRANSFORM_270;
if (transform != -1) if (rotation & META_KMS_PLANE_ROTATION_ROTATE_180)
{ {
plane->all_hw_transforms |= 1 << transform; plane->all_hw_transforms |= 1 << META_MONITOR_TRANSFORM_180;
plane->rotation_map[transform] = 1 << drm_prop->enums[i].value; plane->rotation_map[META_MONITOR_TRANSFORM_180] =
} 1 << prop->enum_values[META_KMS_PLANE_ROTATION_BIT_ROTATE_180].value;
}
if (rotation & META_KMS_PLANE_ROTATION_ROTATE_270)
{
plane->all_hw_transforms |= 1 << META_MONITOR_TRANSFORM_270;
plane->rotation_map[META_MONITOR_TRANSFORM_270] =
1 << prop->enum_values[META_KMS_PLANE_ROTATION_BIT_ROTATE_270].value;
} }
} }
@ -243,13 +250,9 @@ free_modifier_array (GArray *array)
} }
static void static void
parse_formats (MetaKmsImplDevice *impl_device, update_formats (MetaKmsPlane *plane,
MetaKmsProp *prop, MetaKmsImplDevice *impl_device)
drmModePropertyPtr drm_prop,
uint64_t drm_prop_value,
gpointer user_data)
{ {
MetaKmsPlane *plane = user_data;
uint64_t blob_id; uint64_t blob_id;
int fd; int fd;
drmModePropertyBlobPtr blob; drmModePropertyBlobPtr blob;
@ -257,10 +260,12 @@ parse_formats (MetaKmsImplDevice *impl_device,
uint32_t *formats; uint32_t *formats;
struct drm_format_modifier *drm_modifiers; struct drm_format_modifier *drm_modifiers;
unsigned int fmt_i, mod_i; unsigned int fmt_i, mod_i;
MetaKmsProp *in_formats;
g_return_if_fail (g_hash_table_size (plane->formats_modifiers) == 0); g_return_if_fail (g_hash_table_size (plane->formats_modifiers) == 0);
blob_id = drm_prop_value; in_formats = &plane->prop_table.props[META_KMS_PLANE_PROP_IN_FORMATS];
blob_id = in_formats->value;
if (blob_id == 0) if (blob_id == 0)
return; return;
@ -345,10 +350,8 @@ static const uint32_t drm_default_formats[] =
}; };
static void static void
init_legacy_formats (MetaKmsPlane *plane, update_legacy_formats (MetaKmsPlane *plane,
MetaKmsImplDevice *impl_device, drmModePlane *drm_plane)
drmModePlane *drm_plane,
drmModeObjectProperties *drm_plane_props)
{ {
if (g_hash_table_size (plane->formats_modifiers) == 0) if (g_hash_table_size (plane->formats_modifiers) == 0)
{ {
@ -366,6 +369,28 @@ init_legacy_formats (MetaKmsPlane *plane,
} }
} }
static MetaKmsUpdateChanges
meta_kms_plane_read_state (MetaKmsPlane *plane,
MetaKmsImplDevice *impl_device,
drmModePlane *drm_plane,
drmModeObjectProperties *drm_plane_props)
{
MetaKmsUpdateChanges changes = META_KMS_UPDATE_CHANGE_NONE;
meta_kms_impl_device_update_prop_table (impl_device,
drm_plane_props->props,
drm_plane_props->prop_values,
drm_plane_props->count_props,
plane->prop_table.props,
META_KMS_PLANE_N_PROPS);
update_formats (plane, impl_device);
update_rotations (plane);
update_legacy_formats (plane, drm_plane);
return changes;
}
static void static void
init_properties (MetaKmsPlane *plane, init_properties (MetaKmsPlane *plane,
MetaKmsImplDevice *impl_device, MetaKmsImplDevice *impl_device,
@ -388,13 +413,11 @@ init_properties (MetaKmsPlane *plane,
.enum_values = prop_table->rotation_bitmask, .enum_values = prop_table->rotation_bitmask,
.num_enum_values = META_KMS_PLANE_ROTATION_BIT_N_PROPS, .num_enum_values = META_KMS_PLANE_ROTATION_BIT_N_PROPS,
.default_value = META_KMS_PLANE_ROTATION_UNKNOWN, .default_value = META_KMS_PLANE_ROTATION_UNKNOWN,
.parse = parse_rotations,
}, },
[META_KMS_PLANE_PROP_IN_FORMATS] = [META_KMS_PLANE_PROP_IN_FORMATS] =
{ {
.name = "IN_FORMATS", .name = "IN_FORMATS",
.type = DRM_MODE_PROP_BLOB, .type = DRM_MODE_PROP_BLOB,
.parse = parse_formats,
}, },
[META_KMS_PLANE_PROP_SRC_X] = [META_KMS_PLANE_PROP_SRC_X] =
{ {
@ -489,14 +512,6 @@ init_properties (MetaKmsPlane *plane,
}, },
}, },
}; };
meta_kms_impl_device_init_prop_table (impl_device,
drm_plane_props->props,
drm_plane_props->prop_values,
drm_plane_props->count_props,
plane->prop_table.props,
META_KMS_PLANE_N_PROPS,
plane);
} }
MetaKmsPlane * MetaKmsPlane *
@ -514,7 +529,8 @@ meta_kms_plane_new (MetaKmsPlaneType type,
plane->device = meta_kms_impl_device_get_device (impl_device); plane->device = meta_kms_impl_device_get_device (impl_device);
init_properties (plane, impl_device, drm_plane, drm_plane_props); init_properties (plane, impl_device, drm_plane, drm_plane_props);
init_legacy_formats (plane, impl_device, drm_plane, drm_plane_props);
meta_kms_plane_read_state (plane, impl_device, drm_plane, drm_plane_props);
return plane; return plane;
} }