drm-backend: add function drm_backend_add_connector() to create drm_head for connectors that appear

Instead of directly creating heads for the connectors in functions
drm_backend_create_heads() and drm_backend_update_connectors(),
add drm_backend_add_connector() that will handle this.

This split makes the code look better and will also make our lives
easier when we introduce writeback connectors.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
dev
Leandro Ribeiro 4 years ago committed by Pekka Paalanen
parent 99611c8788
commit 7243022b38
  1. 47
      libweston/backend-drm/drm.c

@ -2227,6 +2227,29 @@ drm_output_create(struct weston_compositor *compositor, const char *name)
return &output->base;
}
/** Given the DRM connector object of a connector, create drm_head for it.
*
* The object is then added to the DRM-backend list of heads.
*
* @param b The DRM-backend structure
* @param conn The DRM connector object
* @param drm_device udev device pointer
* @return 0 on success, -1 on failure
*/
static int
drm_backend_add_connector(struct drm_backend *b, drmModeConnector *conn,
struct udev_device *drm_device)
{
int ret;
ret = drm_head_create(b, conn, drm_device);
if (ret < 0)
weston_log("DRM: failed to create head for connector %d.\n",
conn->connector_id);
return ret;
}
static int
drm_backend_create_heads(struct drm_backend *b, struct udev_device *drm_device)
{
@ -2252,12 +2275,9 @@ drm_backend_create_heads(struct drm_backend *b, struct udev_device *drm_device)
if (!conn)
continue;
ret = drm_head_create(b, conn, drm_device);
if (ret < 0) {
weston_log("DRM: failed to create head for connector %d.\n",
connector_id);
ret = drm_backend_add_connector(b, conn, drm_device);
if (ret < 0)
drmModeFreeConnector(conn);
}
}
drmModeFreeResources(resources);
@ -2301,18 +2321,13 @@ drm_backend_update_connectors(struct drm_backend *b, struct udev_device *drm_dev
continue;
head = drm_head_find_by_connector(b, connector_id);
if (head) {
if (head)
ret = drm_head_update_info(head, conn);
if (ret < 0)
drmModeFreeConnector(conn);
} else {
ret = drm_head_create(b, conn, drm_device);
if (ret < 0) {
weston_log("DRM: failed to create head for hot-added connector %d.\n",
connector_id);
drmModeFreeConnector(conn);
}
}
else
ret = drm_backend_add_connector(b, conn, drm_device);
if (ret < 0)
drmModeFreeConnector(conn);
}
/* Remove connectors that have disappeared. */

Loading…
Cancel
Save