libweston, backends: store backend pointer in struct weston_head

Compositor code can use opaque pointer comparison to determine whether
a head belongs to a given backend. Store a backend pointer in struct
weston_head to enable the compositor to select the correct backend
specific output configuration code.

This also allows to use the backend pointer instead of the opaque
backend_id pointer to check whether a head belongs to a backend, so
replace the checks in all to_xyz_head() functions and drop backend_id.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
This commit is contained in:
Philipp Zabel 2021-03-11 13:26:45 +01:00 committed by Philipp Zabel
parent 1e901fa2b7
commit 746a03068e
9 changed files with 30 additions and 24 deletions

View File

@ -375,6 +375,7 @@ struct weston_color_characteristics {
*/
struct weston_head {
struct weston_compositor *compositor; /**< owning compositor */
struct weston_backend *backend; /**< owning backend */
struct wl_list compositor_link; /**< in weston_compositor::head_list */
struct wl_signal destroy_signal; /**< destroy callbacks */
@ -406,9 +407,6 @@ struct weston_head {
/** Current content protection status */
enum weston_hdcp_protection current_protection;
/** Opaque pointer used by backends to identify heads as theirs */
const void *backend_id;
};
/** Output properties derived from its color characteristics and profile

View File

@ -601,12 +601,12 @@ struct drm_output {
};
void
drm_head_destroy(struct weston_head *head_base);
drm_destroy(struct weston_compositor *ec);
static inline struct drm_head *
to_drm_head(struct weston_head *base)
{
if (base->backend_id != drm_head_destroy)
if (base->backend->destroy != drm_destroy)
return NULL;
return container_of(base, struct drm_head, base);
}

View File

@ -2272,7 +2272,7 @@ drm_head_create(struct drm_device *device, drmModeConnector *conn,
weston_head_init(&head->base, name);
free(name);
head->base.backend_id = drm_head_destroy;
head->base.backend = &backend->base;
ret = drm_head_update_info(head, conn);
if (ret < 0)
@ -2303,7 +2303,7 @@ err:
return -1;
}
void
static void
drm_head_destroy(struct weston_head *base)
{
struct drm_head *head = to_drm_head(base);
@ -2692,7 +2692,7 @@ udev_drm_event(int fd, uint32_t mask, void *data)
return 1;
}
static void
void
drm_destroy(struct weston_compositor *ec)
{
struct drm_backend *b = to_drm_backend(ec);

View File

@ -88,12 +88,12 @@ static const uint32_t headless_formats[] = {
};
static void
headless_head_destroy(struct weston_head *base);
headless_destroy(struct weston_compositor *ec);
static inline struct headless_head *
to_headless_head(struct weston_head *base)
{
if (base->backend_id != headless_head_destroy)
if (base->backend->destroy != headless_destroy)
return NULL;
return container_of(base, struct headless_head, base);
}
@ -505,6 +505,7 @@ static int
headless_head_create(struct weston_compositor *compositor,
const char *name)
{
struct headless_backend *backend = to_headless_backend(compositor);
struct headless_head *head;
/* name can't be NULL. */
@ -516,7 +517,7 @@ headless_head_create(struct weston_compositor *compositor,
weston_head_init(&head->base, name);
head->base.backend_id = headless_head_destroy;
head->base.backend = &backend->base;
weston_head_set_connection_status(&head->base, true);
weston_head_set_supported_eotf_mask(&head->base,

View File

@ -534,6 +534,7 @@ rdp_output_create(struct weston_compositor *compositor, const char *name)
static int
rdp_head_create(struct weston_compositor *compositor, const char *name)
{
struct rdp_backend *backend = to_rdp_backend(compositor);
struct rdp_head *head;
head = zalloc(sizeof *head);
@ -542,7 +543,7 @@ rdp_head_create(struct weston_compositor *compositor, const char *name)
weston_head_init(&head->base, name);
head->base.backend_id = rdp_head_destroy;
head->base.backend = &backend->base;
weston_head_set_connection_status(&head->base, true);
weston_compositor_add_head(compositor, &head->base);
@ -550,7 +551,7 @@ rdp_head_create(struct weston_compositor *compositor, const char *name)
return 0;
}
void
static void
rdp_head_destroy(struct weston_head *base)
{
struct rdp_head *head = to_rdp_head(base);
@ -561,7 +562,7 @@ rdp_head_destroy(struct weston_head *base)
free(head);
}
static void
void
rdp_destroy(struct weston_compositor *ec)
{
struct rdp_backend *b = to_rdp_backend(ec);

View File

@ -233,12 +233,12 @@ void
rdp_clipboard_destroy(RdpPeerContext *peerCtx);
void
rdp_head_destroy(struct weston_head *base);
rdp_destroy(struct weston_compositor *ec);
static inline struct rdp_head *
to_rdp_head(struct weston_head *base)
{
if (base->backend_id != rdp_head_destroy)
if (base->backend->destroy != rdp_destroy)
return NULL;
return container_of(base, struct rdp_head, base);
}

View File

@ -122,10 +122,13 @@ to_vnc_output(struct weston_output *base)
static void
vnc_head_destroy(struct weston_head *base);
static void
vnc_destroy(struct weston_compositor *ec);
static inline struct vnc_head *
to_vnc_head(struct weston_head *base)
{
if (base->backend_id != vnc_head_destroy)
if (base->backend->destroy != vnc_destroy)
return NULL;
return container_of(base, struct vnc_head, base);
}
@ -723,6 +726,7 @@ vnc_destroy(struct weston_compositor *ec)
static void
vnc_head_create(struct weston_compositor *compositor, const char *name)
{
struct vnc_backend *backend = to_vnc_backend(compositor);
struct vnc_head *head;
head = xzalloc(sizeof *head);
@ -731,7 +735,7 @@ vnc_head_create(struct weston_compositor *compositor, const char *name)
weston_head_set_monitor_strings(&head->base, "weston", "vnc", NULL);
weston_head_set_physical_size(&head->base, 0, 0);
head->base.backend_id = vnc_head_destroy;
head->base.backend = &backend->base;
weston_head_set_connection_status(&head->base, true);
weston_compositor_add_head(compositor, &head->base);

View File

@ -231,12 +231,12 @@ struct wayland_input {
struct gl_renderer_interface *gl_renderer;
static void
wayland_head_destroy(struct weston_head *base);
wayland_destroy(struct weston_compositor *ec);
static inline struct wayland_head *
to_wayland_head(struct weston_head *base)
{
if (base->backend_id != wayland_head_destroy)
if (base->backend->destroy != wayland_destroy)
return NULL;
return container_of(base, struct wayland_head, base);
}
@ -1417,6 +1417,7 @@ wayland_output_create(struct weston_compositor *compositor, const char *name)
static struct wayland_head *
wayland_head_create(struct weston_compositor *compositor, const char *name)
{
struct wayland_backend *backend = to_wayland_backend(compositor);
struct wayland_head *head;
assert(name);
@ -1427,7 +1428,7 @@ wayland_head_create(struct weston_compositor *compositor, const char *name)
weston_head_init(&head->base, name);
head->base.backend_id = wayland_head_destroy;
head->base.backend = &backend->base;
weston_head_set_connection_status(&head->base, true);
weston_compositor_add_head(compositor, &head->base);

View File

@ -152,12 +152,12 @@ struct window_delete_data {
struct gl_renderer_interface *gl_renderer;
static void
x11_head_destroy(struct weston_head *base);
x11_destroy(struct weston_compositor *ec);
static inline struct x11_head *
to_x11_head(struct weston_head *base)
{
if (base->backend_id != x11_head_destroy)
if (base->backend->destroy != x11_destroy)
return NULL;
return container_of(base, struct x11_head, base);
}
@ -1175,6 +1175,7 @@ x11_output_create(struct weston_compositor *compositor, const char *name)
static int
x11_head_create(struct weston_compositor *compositor, const char *name)
{
struct x11_backend *backend = to_x11_backend(compositor);
struct x11_head *head;
assert(name);
@ -1185,7 +1186,7 @@ x11_head_create(struct weston_compositor *compositor, const char *name)
weston_head_init(&head->base, name);
head->base.backend_id = x11_head_destroy;
head->base.backend = &backend->base;
weston_head_set_connection_status(&head->base, true);
weston_compositor_add_head(compositor, &head->base);