mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2025-10-29 05:40:12 -04:00
backend: replace get_buffer_caps hook with a struct field
Do the same as wlr_renderer: the supported buffer capabilities are static for the lifetime of the backend.
This commit is contained in:
parent
9fdffba170
commit
b908d865b1
14 changed files with 44 additions and 87 deletions
|
|
@ -12,7 +12,6 @@
|
|||
#include <wlr/config.h>
|
||||
#include <wlr/render/wlr_renderer.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "backend/backend.h"
|
||||
#include "backend/multi.h"
|
||||
#include "types/wlr_output.h"
|
||||
#include "util/env.h"
|
||||
|
|
@ -120,14 +119,6 @@ int wlr_backend_get_drm_fd(struct wlr_backend *backend) {
|
|||
return backend->impl->get_drm_fd(backend);
|
||||
}
|
||||
|
||||
uint32_t backend_get_buffer_caps(struct wlr_backend *backend) {
|
||||
if (!backend->impl->get_buffer_caps) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return backend->impl->get_buffer_caps(backend);
|
||||
}
|
||||
|
||||
static size_t parse_outputs_env(const char *name) {
|
||||
const char *outputs_str = getenv(name);
|
||||
if (outputs_str == NULL) {
|
||||
|
|
|
|||
|
|
@ -76,10 +76,6 @@ static int backend_get_drm_fd(struct wlr_backend *backend) {
|
|||
return drm->fd;
|
||||
}
|
||||
|
||||
static uint32_t backend_get_buffer_caps(struct wlr_backend *backend) {
|
||||
return WLR_BUFFER_CAP_DMABUF;
|
||||
}
|
||||
|
||||
static bool backend_test(struct wlr_backend *backend,
|
||||
const struct wlr_backend_output_state *states, size_t states_len) {
|
||||
struct wlr_drm_backend *drm = get_drm_backend_from_backend(backend);
|
||||
|
|
@ -96,7 +92,6 @@ static const struct wlr_backend_impl backend_impl = {
|
|||
.start = backend_start,
|
||||
.destroy = backend_destroy,
|
||||
.get_drm_fd = backend_get_drm_fd,
|
||||
.get_buffer_caps = backend_get_buffer_caps,
|
||||
.test = backend_test,
|
||||
.commit = backend_commit,
|
||||
};
|
||||
|
|
@ -238,6 +233,8 @@ struct wlr_backend *wlr_drm_backend_create(struct wlr_session *session,
|
|||
}
|
||||
wlr_backend_init(&drm->backend, &backend_impl);
|
||||
|
||||
drm->backend.buffer_caps = WLR_BUFFER_CAP_DMABUF;
|
||||
|
||||
drm->session = session;
|
||||
wl_list_init(&drm->fbs);
|
||||
wl_list_init(&drm->connectors);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
#include "backend/drm/drm.h"
|
||||
#include "backend/drm/fb.h"
|
||||
#include "backend/drm/renderer.h"
|
||||
#include "backend/backend.h"
|
||||
#include "render/drm_format_set.h"
|
||||
#include "render/pixel_format.h"
|
||||
#include "render/wlr_renderer.h"
|
||||
|
|
|
|||
|
|
@ -45,16 +45,9 @@ static void backend_destroy(struct wlr_backend *wlr_backend) {
|
|||
free(backend);
|
||||
}
|
||||
|
||||
static uint32_t get_buffer_caps(struct wlr_backend *wlr_backend) {
|
||||
return WLR_BUFFER_CAP_DATA_PTR
|
||||
| WLR_BUFFER_CAP_DMABUF
|
||||
| WLR_BUFFER_CAP_SHM;
|
||||
}
|
||||
|
||||
static const struct wlr_backend_impl backend_impl = {
|
||||
.start = backend_start,
|
||||
.destroy = backend_destroy,
|
||||
.get_buffer_caps = get_buffer_caps,
|
||||
};
|
||||
|
||||
static void handle_event_loop_destroy(struct wl_listener *listener, void *data) {
|
||||
|
|
@ -74,6 +67,9 @@ struct wlr_backend *wlr_headless_backend_create(struct wl_event_loop *loop) {
|
|||
|
||||
wlr_backend_init(&backend->backend, &backend_impl);
|
||||
|
||||
backend->backend.buffer_caps =
|
||||
WLR_BUFFER_CAP_DATA_PTR | WLR_BUFFER_CAP_DMABUF | WLR_BUFFER_CAP_SHM;
|
||||
|
||||
backend->event_loop = loop;
|
||||
wl_list_init(&backend->outputs);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
#include <wlr/types/wlr_buffer.h>
|
||||
#include <wlr/types/wlr_output.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "backend/backend.h"
|
||||
#include "backend/multi.h"
|
||||
|
||||
struct subbackend_state {
|
||||
|
|
@ -76,28 +75,6 @@ static int multi_backend_get_drm_fd(struct wlr_backend *backend) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
static uint32_t multi_backend_get_buffer_caps(struct wlr_backend *backend) {
|
||||
struct wlr_multi_backend *multi = multi_backend_from_backend(backend);
|
||||
|
||||
if (wl_list_empty(&multi->backends)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t caps = WLR_BUFFER_CAP_DATA_PTR | WLR_BUFFER_CAP_DMABUF
|
||||
| WLR_BUFFER_CAP_SHM;
|
||||
|
||||
struct subbackend_state *sub;
|
||||
wl_list_for_each(sub, &multi->backends, link) {
|
||||
uint32_t backend_caps = backend_get_buffer_caps(sub->backend);
|
||||
if (backend_caps != 0) {
|
||||
// only count backend capable of presenting a buffer
|
||||
caps = caps & backend_caps;
|
||||
}
|
||||
}
|
||||
|
||||
return caps;
|
||||
}
|
||||
|
||||
static int compare_output_state_backend(const void *data_a, const void *data_b) {
|
||||
const struct wlr_backend_output_state *a = data_a;
|
||||
const struct wlr_backend_output_state *b = data_b;
|
||||
|
|
@ -164,7 +141,6 @@ static const struct wlr_backend_impl backend_impl = {
|
|||
.start = multi_backend_start,
|
||||
.destroy = multi_backend_destroy,
|
||||
.get_drm_fd = multi_backend_get_drm_fd,
|
||||
.get_buffer_caps = multi_backend_get_buffer_caps,
|
||||
.test = multi_backend_test,
|
||||
.commit = multi_backend_commit,
|
||||
};
|
||||
|
|
@ -228,16 +204,30 @@ static struct subbackend_state *multi_backend_get_subbackend(struct wlr_multi_ba
|
|||
}
|
||||
|
||||
static void multi_backend_refresh_features(struct wlr_multi_backend *multi) {
|
||||
multi->backend.buffer_caps = 0;
|
||||
multi->backend.features.timeline = true;
|
||||
|
||||
bool has_buffer_cap = false;
|
||||
uint32_t buffer_caps_intersection =
|
||||
WLR_BUFFER_CAP_DATA_PTR | WLR_BUFFER_CAP_DMABUF | WLR_BUFFER_CAP_SHM;
|
||||
struct subbackend_state *sub = NULL;
|
||||
wl_list_for_each(sub, &multi->backends, link) {
|
||||
// Only take into account backends capable of presenting a buffer
|
||||
if (sub->backend->buffer_caps != 0) {
|
||||
has_buffer_cap = true;
|
||||
buffer_caps_intersection &= sub->backend->buffer_caps;
|
||||
}
|
||||
|
||||
// timeline is only applicable to backends that support DMABUFs
|
||||
if (backend_get_buffer_caps(sub->backend) & WLR_BUFFER_CAP_DMABUF) {
|
||||
if (sub->backend->buffer_caps & WLR_BUFFER_CAP_DMABUF) {
|
||||
multi->backend.features.timeline = multi->backend.features.timeline &&
|
||||
sub->backend->features.timeline;
|
||||
}
|
||||
}
|
||||
|
||||
if (has_buffer_cap) {
|
||||
multi->backend.buffer_caps = buffer_caps_intersection;
|
||||
}
|
||||
}
|
||||
|
||||
bool wlr_multi_backend_add(struct wlr_backend *_multi,
|
||||
|
|
|
|||
|
|
@ -566,17 +566,10 @@ static int backend_get_drm_fd(struct wlr_backend *backend) {
|
|||
return wl->drm_fd;
|
||||
}
|
||||
|
||||
static uint32_t get_buffer_caps(struct wlr_backend *backend) {
|
||||
struct wlr_wl_backend *wl = get_wl_backend_from_backend(backend);
|
||||
return (wl->zwp_linux_dmabuf_v1 ? WLR_BUFFER_CAP_DMABUF : 0)
|
||||
| (wl->shm ? WLR_BUFFER_CAP_SHM : 0);
|
||||
}
|
||||
|
||||
static const struct wlr_backend_impl backend_impl = {
|
||||
.start = backend_start,
|
||||
.destroy = backend_destroy,
|
||||
.get_drm_fd = backend_get_drm_fd,
|
||||
.get_buffer_caps = get_buffer_caps,
|
||||
};
|
||||
|
||||
bool wlr_backend_is_wl(struct wlr_backend *b) {
|
||||
|
|
@ -672,6 +665,13 @@ struct wlr_backend *wlr_wl_backend_create(struct wl_event_loop *loop,
|
|||
zwp_linux_dmabuf_feedback_v1_destroy(linux_dmabuf_feedback_v1);
|
||||
}
|
||||
|
||||
if (wl->zwp_linux_dmabuf_v1) {
|
||||
wl->backend.buffer_caps |= WLR_BUFFER_CAP_DMABUF;
|
||||
}
|
||||
if (wl->shm) {
|
||||
wl->backend.buffer_caps |= WLR_BUFFER_CAP_SHM;
|
||||
}
|
||||
|
||||
int fd = wl_display_get_fd(wl->remote_display);
|
||||
wl->remote_display_src = wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE,
|
||||
dispatch_events, wl);
|
||||
|
|
|
|||
|
|
@ -212,17 +212,10 @@ static int backend_get_drm_fd(struct wlr_backend *backend) {
|
|||
return x11->drm_fd;
|
||||
}
|
||||
|
||||
static uint32_t get_buffer_caps(struct wlr_backend *backend) {
|
||||
struct wlr_x11_backend *x11 = get_x11_backend_from_backend(backend);
|
||||
return (x11->have_dri3 ? WLR_BUFFER_CAP_DMABUF : 0)
|
||||
| (x11->have_shm ? WLR_BUFFER_CAP_SHM : 0);
|
||||
}
|
||||
|
||||
static const struct wlr_backend_impl backend_impl = {
|
||||
.start = backend_start,
|
||||
.destroy = backend_destroy,
|
||||
.get_drm_fd = backend_get_drm_fd,
|
||||
.get_buffer_caps = get_buffer_caps,
|
||||
};
|
||||
|
||||
bool wlr_backend_is_x11(struct wlr_backend *backend) {
|
||||
|
|
@ -573,6 +566,13 @@ struct wlr_backend *wlr_x11_backend_create(struct wl_event_loop *loop,
|
|||
}
|
||||
free(xi_reply);
|
||||
|
||||
if (x11->have_dri3) {
|
||||
x11->backend.buffer_caps |= WLR_BUFFER_CAP_DMABUF;
|
||||
}
|
||||
if (x11->have_shm) {
|
||||
x11->backend.buffer_caps |= WLR_BUFFER_CAP_SHM;
|
||||
}
|
||||
|
||||
int fd = xcb_get_file_descriptor(x11->xcb);
|
||||
uint32_t events = WL_EVENT_READABLE | WL_EVENT_ERROR | WL_EVENT_HANGUP;
|
||||
x11->event_source = wl_event_loop_add_fd(loop, fd, events, x11_event, x11);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue