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. 43
      libweston/backend-drm/drm.c

@ -2227,6 +2227,29 @@ drm_output_create(struct weston_compositor *compositor, const char *name)
return &output->base; 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 static int
drm_backend_create_heads(struct drm_backend *b, struct udev_device *drm_device) drm_backend_create_heads(struct drm_backend *b, struct udev_device *drm_device)
{ {
@ -2252,13 +2275,10 @@ drm_backend_create_heads(struct drm_backend *b, struct udev_device *drm_device)
if (!conn) if (!conn)
continue; continue;
ret = drm_head_create(b, conn, drm_device); ret = drm_backend_add_connector(b, conn, drm_device);
if (ret < 0) { if (ret < 0)
weston_log("DRM: failed to create head for connector %d.\n",
connector_id);
drmModeFreeConnector(conn); drmModeFreeConnector(conn);
} }
}
drmModeFreeResources(resources); drmModeFreeResources(resources);
@ -2301,18 +2321,13 @@ drm_backend_update_connectors(struct drm_backend *b, struct udev_device *drm_dev
continue; continue;
head = drm_head_find_by_connector(b, connector_id); head = drm_head_find_by_connector(b, connector_id);
if (head) { if (head)
ret = drm_head_update_info(head, conn); ret = drm_head_update_info(head, conn);
else
ret = drm_backend_add_connector(b, conn, drm_device);
if (ret < 0) if (ret < 0)
drmModeFreeConnector(conn); 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);
}
}
} }
/* Remove connectors that have disappeared. */ /* Remove connectors that have disappeared. */

Loading…
Cancel
Save