libweston, backends: pass backend parameter to weston_backend functions

Passing the backend as a parameter to the weston_backend function
pointers seems more natural and will be very useful once there can be
more than one backend.

Since all backends already store a pointer to the compositor instance,
replace the compositor parameter with the backend in all functions.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
This commit is contained in:
Philipp Zabel 2023-01-13 18:21:31 +01:00
parent 0a8861e5ae
commit 6f977640e6
12 changed files with 84 additions and 69 deletions

View file

@ -610,7 +610,7 @@ struct drm_output {
};
void
drm_destroy(struct weston_compositor *ec);
drm_destroy(struct weston_backend *backend);
static inline struct drm_head *
to_drm_head(struct weston_head *base)
@ -781,7 +781,7 @@ drm_fb_get_from_paint_node(struct drm_output_state *state,
struct weston_paint_node *pnode);
extern bool
drm_can_scanout_dmabuf(struct weston_compositor *ec,
drm_can_scanout_dmabuf(struct weston_backend *backend,
struct linux_dmabuf_buffer *dmabuf);
#else
static inline struct drm_fb *
@ -791,7 +791,7 @@ drm_fb_get_from_paint_node(struct drm_output_state *state,
return NULL;
}
static inline bool
drm_can_scanout_dmabuf(struct weston_compositor *ec,
drm_can_scanout_dmabuf(struct weston_backend *backend,
struct linux_dmabuf_buffer *dmabuf)
{
return false;

View file

@ -618,9 +618,9 @@ finish_frame:
* output repaint functions until the repaint is flushed or cancelled.
*/
static void
drm_repaint_begin(struct weston_compositor *compositor)
drm_repaint_begin(struct weston_backend *backend)
{
struct drm_backend *b = to_drm_backend(compositor);
struct drm_backend *b = container_of(backend, struct drm_backend, base);
struct drm_device *device = b->drm;
struct drm_pending_state *pending_state;
@ -628,7 +628,7 @@ drm_repaint_begin(struct weston_compositor *compositor)
device->repaint_data = pending_state;
if (weston_log_scope_is_enabled(b->debug)) {
char *dbg = weston_compositor_print_scene_graph(compositor);
char *dbg = weston_compositor_print_scene_graph(b->compositor);
drm_debug(b, "[repaint] Beginning repaint; pending_state %p\n",
device->repaint_data);
drm_debug(b, "%s", dbg);
@ -646,9 +646,9 @@ drm_repaint_begin(struct weston_compositor *compositor)
* state will be freed.
*/
static int
drm_repaint_flush(struct weston_compositor *compositor)
drm_repaint_flush(struct weston_backend *backend)
{
struct drm_backend *b = to_drm_backend(compositor);
struct drm_backend *b = container_of(backend, struct drm_backend, base);
struct drm_device *device = b->drm;
struct drm_pending_state *pending_state = device->repaint_data;
int ret;
@ -670,9 +670,9 @@ drm_repaint_flush(struct weston_compositor *compositor)
* held across the repaint cycle should be discarded.
*/
static void
drm_repaint_cancel(struct weston_compositor *compositor)
drm_repaint_cancel(struct weston_backend *backend)
{
struct drm_backend *b = to_drm_backend(compositor);
struct drm_backend *b = container_of(backend, struct drm_backend, base);
struct drm_device *device = b->drm;
struct drm_pending_state *pending_state = device->repaint_data;
@ -2329,14 +2329,14 @@ drm_head_destroy(struct weston_head *base)
* Creating an output is usually followed by drm_output_attach_head()
* and drm_output_enable() to make use of it.
*
* @param compositor The compositor instance.
* @param backend The backend instance.
* @param name Name for the new output.
* @returns The output, or NULL on failure.
*/
static struct weston_output *
drm_output_create(struct weston_compositor *compositor, const char *name)
drm_output_create(struct weston_backend *backend, const char *name)
{
struct drm_backend *b = to_drm_backend(compositor);
struct drm_backend *b = container_of(backend, struct drm_backend, base);
struct drm_device *device = b->drm;
struct drm_output *output;
@ -2353,7 +2353,7 @@ drm_output_create(struct weston_compositor *compositor, const char *name)
output->gbm_bo_flags = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING;
#endif
weston_output_init(&output->base, compositor, name);
weston_output_init(&output->base, b->compositor, name);
output->base.enable = drm_output_enable;
output->base.destroy = drm_output_destroy;
@ -2693,9 +2693,10 @@ udev_drm_event(int fd, uint32_t mask, void *data)
}
void
drm_destroy(struct weston_compositor *ec)
drm_destroy(struct weston_backend *backend)
{
struct drm_backend *b = to_drm_backend(ec);
struct drm_backend *b = container_of(backend, struct drm_backend, base);
struct weston_compositor *ec = b->compositor;
struct drm_device *device = b->drm;
struct weston_head *base, *next;
struct drm_crtc *crtc, *crtc_tmp;
@ -2783,15 +2784,16 @@ session_notify(struct wl_listener *listener, void *data)
* If the device being added/removed is the KMS device, we activate/deactivate
* the compositor session.
*
* @param compositor The compositor instance.
* @param backend The DRM backend instance.
* @param devnum The device being added/removed.
* @param added Whether the device is being added (or removed)
*/
static void
drm_device_changed(struct weston_compositor *compositor,
drm_device_changed(struct weston_backend *backend,
dev_t devnum, bool added)
{
struct drm_backend *b = to_drm_backend(compositor);
struct drm_backend *b = container_of(backend, struct drm_backend, base);
struct weston_compositor *compositor = b->compositor;
struct drm_device *device = b->drm;
if (device->drm.fd < 0 || device->drm.devnum != devnum ||

View file

@ -452,11 +452,11 @@ drm_fb_unref(struct drm_fb *fb)
#ifdef BUILD_DRM_GBM
bool
drm_can_scanout_dmabuf(struct weston_compositor *ec,
drm_can_scanout_dmabuf(struct weston_backend *backend,
struct linux_dmabuf_buffer *dmabuf)
{
struct drm_backend *b = container_of(backend, struct drm_backend, base);
struct drm_fb *fb;
struct drm_backend *b = to_drm_backend(ec);
struct drm_device *device = b->drm;
bool ret = false;
uint32_t try_reason = 0x0;

View file

@ -84,7 +84,7 @@ static const uint32_t headless_formats[] = {
};
static void
headless_destroy(struct weston_compositor *ec);
headless_destroy(struct weston_backend *backend);
static inline struct headless_head *
to_headless_head(struct weston_head *base)
@ -413,8 +413,10 @@ headless_output_set_size(struct weston_output *base,
}
static struct weston_output *
headless_output_create(struct weston_compositor *compositor, const char *name)
headless_output_create(struct weston_backend *backend, const char *name)
{
struct headless_backend *b = container_of(backend, struct headless_backend, base);
struct weston_compositor *compositor = b->compositor;
struct headless_output *output;
/* name can't be NULL. */
@ -480,9 +482,10 @@ headless_head_destroy(struct weston_head *base)
}
static void
headless_destroy(struct weston_compositor *ec)
headless_destroy(struct weston_backend *backend)
{
struct headless_backend *b = to_headless_backend(ec);
struct headless_backend *b = container_of(backend, struct headless_backend, base);
struct weston_compositor *ec = b->compositor;
struct weston_head *base, *next;
weston_compositor_shutdown(ec);

View file

@ -523,8 +523,10 @@ rdp_output_destroy(struct weston_output *base)
}
static struct weston_output *
rdp_output_create(struct weston_compositor *compositor, const char *name)
rdp_output_create(struct weston_backend *backend, const char *name)
{
struct rdp_backend *b = container_of(backend, struct rdp_backend, base);
struct weston_compositor *compositor = b->compositor;
struct rdp_output *output;
output = xzalloc(sizeof *output);
@ -594,9 +596,10 @@ rdp_head_destroy(struct weston_head *base)
}
void
rdp_destroy(struct weston_compositor *ec)
rdp_destroy(struct weston_backend *backend)
{
struct rdp_backend *b = to_rdp_backend(ec);
struct rdp_backend *b = container_of(backend, struct rdp_backend, base);
struct weston_compositor *ec = b->compositor;
struct weston_head *base, *next;
struct rdp_peers_item *rdp_peer, *tmp;
int i;

View file

@ -253,7 +253,7 @@ void
rdp_head_create(struct weston_compositor *compositor, rdpMonitor *config);
void
rdp_destroy(struct weston_compositor *ec);
rdp_destroy(struct weston_backend *backend);
void
rdp_head_destroy(struct weston_head *base);

View file

@ -124,7 +124,7 @@ static void
vnc_head_destroy(struct weston_head *base);
static void
vnc_destroy(struct weston_compositor *ec);
vnc_destroy(struct weston_backend *backend);
static inline struct vnc_head *
to_vnc_head(struct weston_head *base)
@ -682,31 +682,33 @@ vnc_output_destroy(struct weston_output *base)
}
static struct weston_output *
vnc_create_output(struct weston_compositor *compositor, const char *name)
vnc_create_output(struct weston_backend *backend, const char *name)
{
struct vnc_backend *b = container_of(backend, struct vnc_backend, base);
struct vnc_output *output;
output = zalloc(sizeof *output);
if (output == NULL)
return NULL;
weston_output_init(&output->base, compositor, name);
weston_output_init(&output->base, b->compositor, name);
output->base.destroy = vnc_output_destroy;
output->base.disable = vnc_output_disable;
output->base.enable = vnc_output_enable;
output->base.attach_head = NULL;
weston_compositor_add_pending_output(&output->base, compositor);
weston_compositor_add_pending_output(&output->base, b->compositor);
return &output->base;
}
static void
vnc_destroy(struct weston_compositor *ec)
vnc_destroy(struct weston_backend *base)
{
struct weston_head *base, *next;
struct vnc_backend *backend = to_vnc_backend(ec);
struct vnc_backend *backend = container_of(base, struct vnc_backend, base);
struct weston_compositor *ec = backend->compositor;
struct weston_head *head, *next;
wl_list_remove(&backend->output_move_listener.link);
@ -718,8 +720,8 @@ vnc_destroy(struct weston_compositor *ec)
aml_unref(backend->aml);
wl_list_for_each_safe(base, next, &ec->head_list, compositor_link)
vnc_head_destroy(base);
wl_list_for_each_safe(head, next, &ec->head_list, compositor_link)
vnc_head_destroy(head);
xkb_keymap_unref(backend->xkb_keymap);

View file

@ -227,7 +227,7 @@ struct wayland_input {
struct gl_renderer_interface *gl_renderer;
static void
wayland_destroy(struct weston_compositor *ec);
wayland_destroy(struct weston_backend *backend);
static inline struct wayland_head *
to_wayland_head(struct weston_head *base)
@ -1299,8 +1299,10 @@ wayland_output_detach_head(struct weston_output *output_base,
}
static struct weston_output *
wayland_output_create(struct weston_compositor *compositor, const char *name)
wayland_output_create(struct weston_backend *backend, const char *name)
{
struct wayland_backend *b = container_of(backend, struct wayland_backend, base);
struct weston_compositor *compositor = b->compositor;
struct wayland_output *output;
char *title;
@ -2641,9 +2643,10 @@ wayland_backend_handle_event(int fd, uint32_t mask, void *data)
}
static void
wayland_destroy(struct weston_compositor *ec)
wayland_destroy(struct weston_backend *backend)
{
struct wayland_backend *b = to_wayland_backend(ec);
struct wayland_backend *b = container_of(backend, struct wayland_backend, base);
struct weston_compositor *ec = b->compositor;
struct weston_head *base, *next;
struct wayland_parent_output *output, *next_output;
struct wayland_input *input, *next_input;

View file

@ -152,7 +152,7 @@ struct window_delete_data {
struct gl_renderer_interface *gl_renderer;
static void
x11_destroy(struct weston_compositor *ec);
x11_destroy(struct weston_backend *backend);
static inline struct x11_head *
to_x11_head(struct weston_head *base)
@ -1149,8 +1149,10 @@ x11_output_set_size(struct weston_output *base, int width, int height)
}
static struct weston_output *
x11_output_create(struct weston_compositor *compositor, const char *name)
x11_output_create(struct weston_backend *backend, const char *name)
{
struct x11_backend *b = container_of(backend, struct x11_backend, base);
struct weston_compositor *compositor = b->compositor;
struct x11_output *output;
/* name can't be NULL. */
@ -1808,19 +1810,20 @@ x11_backend_get_wm_info(struct x11_backend *c)
}
static void
x11_destroy(struct weston_compositor *ec)
x11_destroy(struct weston_backend *base)
{
struct x11_backend *backend = to_x11_backend(ec);
struct weston_head *base, *next;
struct x11_backend *backend = container_of(base, struct x11_backend, base);
struct weston_compositor *ec = backend->compositor;
struct weston_head *head, *next;
wl_event_source_remove(backend->xcb_source);
x11_input_destroy(backend);
weston_compositor_shutdown(ec); /* destroys outputs, too */
wl_list_for_each_safe(base, next, &ec->head_list, compositor_link) {
if (to_x11_head(base))
x11_head_destroy(base);
wl_list_for_each_safe(head, next, &ec->head_list, compositor_link) {
if (to_x11_head(head))
x11_head_destroy(head);
}
XCloseDisplay(backend->dpy);

View file

@ -35,7 +35,7 @@
struct weston_hdr_metadata_type1;
struct weston_backend {
void (*destroy)(struct weston_compositor *compositor);
void (*destroy)(struct weston_backend *backend);
/** Begin a repaint sequence
*
@ -48,25 +48,25 @@ struct weston_backend {
* Returns an opaque pointer, which the backend may use as private
* data referring to the repaint cycle.
*/
void (*repaint_begin)(struct weston_compositor *compositor);
void (*repaint_begin)(struct weston_backend *backend);
/** Cancel a repaint sequence
*
* Cancels a repaint sequence, when an error has occurred during
* one output's repaint; see repaint_begin.
*/
void (*repaint_cancel)(struct weston_compositor *compositor);
void (*repaint_cancel)(struct weston_backend *backend);
/** Conclude a repaint sequence
*
* Called on successful completion of a repaint sequence; see
* repaint_begin.
*/
int (*repaint_flush)(struct weston_compositor *compositor);
int (*repaint_flush)(struct weston_backend *backend);
/** Allocate a new output
*
* @param compositor The compositor.
* @param backend The backend.
* @param name Name for the new output.
*
* Allocates a new output structure that embeds a weston_output,
@ -76,12 +76,11 @@ struct weston_backend {
* Must set weston_output members @c destroy, @c enable and @c disable.
*/
struct weston_output *
(*create_output)(struct weston_compositor *compositor,
const char *name);
(*create_output)(struct weston_backend *backend, const char *name);
/** Notify of device addition/removal
*
* @param compositor The compositor.
* @param backend The backend.
* @param device The device that has changed.
* @param added Where it was added (or removed)
*
@ -89,19 +88,19 @@ struct weston_backend {
* The backend can decide what to do based on whether it is a
* device that it is controlling or not.
*/
void (*device_changed)(struct weston_compositor *compositor,
void (*device_changed)(struct weston_backend *backend,
dev_t device, bool added);
/** Verifies if the dmabuf can be used directly/scanned-out by the HW.
*
* @param compositor The compositor.
* @param backend The backend.
* @param buffer The dmabuf to verify.
*
* Determines if the buffer can be imported directly by the display
* controller/HW. Back-ends can use this to check if the supplied
* buffer can be scanned-out, as to void importing it into the GPU.
*/
bool (*can_scanout_dmabuf)(struct weston_compositor *compositor,
bool (*can_scanout_dmabuf)(struct weston_backend *backend,
struct linux_dmabuf_buffer *buffer);
};

View file

@ -3203,7 +3203,7 @@ output_repaint_timer_handler(void *data)
compositor->last_repaint_start = now;
if (compositor->backend->repaint_begin)
compositor->backend->repaint_begin(compositor);
compositor->backend->repaint_begin(compositor->backend);
wl_list_for_each(output, &compositor->output_list, link) {
ret = weston_output_maybe_repaint(output, &now);
@ -3213,10 +3213,10 @@ output_repaint_timer_handler(void *data)
if (ret == 0) {
if (compositor->backend->repaint_flush)
ret = compositor->backend->repaint_flush(compositor);
ret = compositor->backend->repaint_flush(compositor->backend);
} else {
if (compositor->backend->repaint_cancel)
compositor->backend->repaint_cancel(compositor);
compositor->backend->repaint_cancel(compositor->backend);
}
if (ret != 0) {
@ -7408,7 +7408,7 @@ weston_compositor_create_output(struct weston_compositor *compositor,
return NULL;
}
output = head->backend->create_output(compositor, name);
output = head->backend->create_output(head->backend, name);
if (!output)
return NULL;
@ -8502,7 +8502,7 @@ weston_compositor_dmabuf_can_scanout(struct weston_compositor *compositor,
if (backend->can_scanout_dmabuf == NULL)
return false;
return backend->can_scanout_dmabuf(compositor, buffer);
return backend->can_scanout_dmabuf(backend, buffer);
}
WL_EXPORT void
@ -8681,7 +8681,7 @@ weston_compositor_destroy(struct weston_compositor *compositor)
weston_compositor_xkb_destroy(compositor);
if (compositor->backend)
compositor->backend->destroy(compositor);
compositor->backend->destroy(compositor->backend);
/* The backend is responsible for destroying the heads. */
assert(wl_list_empty(&compositor->head_list));

View file

@ -502,7 +502,7 @@ device_paused(struct launcher_logind *wl, DBusMessage *m)
launcher_logind_pause_device_complete(wl, major, minor);
if (wl->sync_drm && wl->compositor->backend->device_changed)
wl->compositor->backend->device_changed(wl->compositor,
wl->compositor->backend->device_changed(wl->compositor->backend,
makedev(major,minor),
false);
}
@ -529,7 +529,7 @@ device_resumed(struct launcher_logind *wl, DBusMessage *m)
* notify the compositor to wake up. */
if (wl->sync_drm && wl->compositor->backend->device_changed)
wl->compositor->backend->device_changed(wl->compositor,
wl->compositor->backend->device_changed(wl->compositor->backend,
makedev(major,minor),
true);
}