mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2024-11-25 08:32:30 +00:00
Refactor wlr_backend_state out of DRM backend
This commit is contained in:
parent
c95a108d2f
commit
234b2104e4
@ -16,32 +16,34 @@
|
||||
#include "backend/udev.h"
|
||||
#include "backend/drm.h"
|
||||
|
||||
static bool wlr_drm_backend_init(struct wlr_backend_state *drm) {
|
||||
wlr_drm_scan_connectors(drm);
|
||||
static bool wlr_drm_backend_init(struct wlr_backend *_backend) {
|
||||
struct wlr_drm_backend *backend = (struct wlr_drm_backend *)_backend;
|
||||
wlr_drm_scan_connectors(backend);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void wlr_drm_backend_destroy(struct wlr_backend_state *drm) {
|
||||
if (!drm) {
|
||||
static void wlr_drm_backend_destroy(struct wlr_backend *_backend) {
|
||||
if (!_backend) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i = 0; drm->outputs && i < drm->outputs->length; ++i) {
|
||||
struct wlr_output_state *output = drm->outputs->items[i];
|
||||
struct wlr_drm_backend *backend = (struct wlr_drm_backend *)_backend;
|
||||
for (size_t i = 0; backend->outputs && i < backend->outputs->length; ++i) {
|
||||
struct wlr_output_state *output = backend->outputs->items[i];
|
||||
wlr_output_destroy(output->base);
|
||||
}
|
||||
|
||||
wlr_udev_signal_remove(drm->udev, &drm->drm_invalidated);
|
||||
wlr_drm_renderer_free(&drm->renderer);
|
||||
wlr_drm_resources_free(drm);
|
||||
wlr_session_close_file(drm->session, drm->fd);
|
||||
wl_event_source_remove(drm->drm_event);
|
||||
list_free(drm->outputs);
|
||||
free(drm);
|
||||
wlr_udev_signal_remove(backend->udev, &backend->drm_invalidated);
|
||||
wlr_drm_renderer_free(&backend->renderer);
|
||||
wlr_drm_resources_free(backend);
|
||||
wlr_session_close_file(backend->session, backend->fd);
|
||||
wl_event_source_remove(backend->drm_event);
|
||||
list_free(backend->outputs);
|
||||
free(backend);
|
||||
}
|
||||
|
||||
static struct wlr_egl *wlr_drm_backend_get_egl(struct wlr_backend_state *drm) {
|
||||
return &drm->renderer.egl;
|
||||
static struct wlr_egl *wlr_drm_backend_get_egl(struct wlr_backend *_backend) {
|
||||
struct wlr_drm_backend *backend = (struct wlr_drm_backend *)_backend;
|
||||
return &backend->renderer.egl;
|
||||
}
|
||||
|
||||
static struct wlr_backend_impl backend_impl = {
|
||||
@ -51,14 +53,15 @@ static struct wlr_backend_impl backend_impl = {
|
||||
};
|
||||
|
||||
static void session_signal(struct wl_listener *listener, void *data) {
|
||||
struct wlr_backend_state *drm = wl_container_of(listener, drm, session_signal);
|
||||
struct wlr_drm_backend *backend =
|
||||
wl_container_of(listener, backend, session_signal);
|
||||
struct wlr_session *session = data;
|
||||
|
||||
if (session->active) {
|
||||
wlr_log(L_INFO, "DRM fd resumed");
|
||||
|
||||
for (size_t i = 0; i < drm->outputs->length; ++i) {
|
||||
struct wlr_output_state *output = drm->outputs->items[i];
|
||||
for (size_t i = 0; i < backend->outputs->length; ++i) {
|
||||
struct wlr_output_state *output = backend->outputs->items[i];
|
||||
wlr_drm_output_start_renderer(output);
|
||||
|
||||
if (!output->crtc) {
|
||||
@ -67,7 +70,7 @@ static void session_signal(struct wl_listener *listener, void *data) {
|
||||
|
||||
struct wlr_drm_plane *plane = output->crtc->cursor;
|
||||
|
||||
drm->iface->crtc_set_cursor(drm, output->crtc,
|
||||
backend->iface->crtc_set_cursor(backend, output->crtc,
|
||||
plane ? plane->cursor_bo : NULL);
|
||||
}
|
||||
} else {
|
||||
@ -76,16 +79,16 @@ static void session_signal(struct wl_listener *listener, void *data) {
|
||||
}
|
||||
|
||||
static void drm_invalidated(struct wl_listener *listener, void *data) {
|
||||
struct wlr_backend_state *drm = wl_container_of(listener, drm, drm_invalidated);
|
||||
struct wlr_drm_backend *backend =
|
||||
wl_container_of(listener, backend, drm_invalidated);
|
||||
struct wlr_udev *udev = data;
|
||||
|
||||
(void)udev;
|
||||
|
||||
char *name = drmGetDeviceNameFromFd2(drm->fd);
|
||||
char *name = drmGetDeviceNameFromFd2(backend->fd);
|
||||
wlr_log(L_DEBUG, "%s invalidated", name);
|
||||
free(name);
|
||||
|
||||
wlr_drm_scan_connectors(drm);
|
||||
wlr_drm_scan_connectors(backend);
|
||||
}
|
||||
|
||||
struct wlr_backend *wlr_drm_backend_create(struct wl_display *display,
|
||||
@ -98,77 +101,70 @@ struct wlr_backend *wlr_drm_backend_create(struct wl_display *display,
|
||||
free(name);
|
||||
drmFreeVersion(version);
|
||||
|
||||
struct wlr_backend_state *drm = calloc(1, sizeof(*drm));
|
||||
if (!drm) {
|
||||
wlr_log_errno(L_ERROR, "Allocation failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct wlr_backend *backend = wlr_backend_create(&backend_impl, drm);
|
||||
struct wlr_drm_backend *backend = calloc(1, sizeof(struct wlr_drm_backend));
|
||||
if (!backend) {
|
||||
wlr_log_errno(L_ERROR, "Allocation failed");
|
||||
return NULL;
|
||||
}
|
||||
wlr_backend_create(&backend->backend, &backend_impl);
|
||||
|
||||
drm->base = backend;
|
||||
drm->session = session;
|
||||
drm->udev = udev;
|
||||
drm->outputs = list_create();
|
||||
if (!drm->outputs) {
|
||||
backend->session = session;
|
||||
backend->udev = udev;
|
||||
backend->outputs = list_create();
|
||||
if (!backend->outputs) {
|
||||
wlr_log(L_ERROR, "Failed to allocate list");
|
||||
goto error_backend;
|
||||
}
|
||||
|
||||
drm->fd = gpu_fd;
|
||||
backend->fd = gpu_fd;
|
||||
|
||||
struct stat st;
|
||||
if (fstat(drm->fd, &st) < 0) {
|
||||
if (fstat(backend->fd, &st) < 0) {
|
||||
wlr_log_errno(L_ERROR, "Stat failed");
|
||||
}
|
||||
drm->dev = st.st_rdev;
|
||||
backend->dev = st.st_rdev;
|
||||
|
||||
drm->drm_invalidated.notify = drm_invalidated;
|
||||
wlr_udev_signal_add(udev, drm->dev, &drm->drm_invalidated);
|
||||
backend->drm_invalidated.notify = drm_invalidated;
|
||||
wlr_udev_signal_add(udev, backend->dev, &backend->drm_invalidated);
|
||||
|
||||
drm->display = display;
|
||||
backend->display = display;
|
||||
struct wl_event_loop *event_loop = wl_display_get_event_loop(display);
|
||||
|
||||
drm->drm_event = wl_event_loop_add_fd(event_loop, drm->fd,
|
||||
backend->drm_event = wl_event_loop_add_fd(event_loop, backend->fd,
|
||||
WL_EVENT_READABLE, wlr_drm_event, NULL);
|
||||
if (!drm->drm_event) {
|
||||
if (!backend->drm_event) {
|
||||
wlr_log(L_ERROR, "Failed to create DRM event source");
|
||||
goto error_fd;
|
||||
}
|
||||
|
||||
drm->session_signal.notify = session_signal;
|
||||
wl_signal_add(&session->session_signal, &drm->session_signal);
|
||||
backend->session_signal.notify = session_signal;
|
||||
wl_signal_add(&session->session_signal, &backend->session_signal);
|
||||
|
||||
if (!wlr_drm_check_features(drm)) {
|
||||
if (!wlr_drm_check_features(backend)) {
|
||||
goto error_event;
|
||||
}
|
||||
|
||||
if (!wlr_drm_resources_init(drm)) {
|
||||
if (!wlr_drm_resources_init(backend)) {
|
||||
goto error_event;
|
||||
}
|
||||
|
||||
if (!wlr_drm_renderer_init(&drm->renderer, drm->fd)) {
|
||||
if (!wlr_drm_renderer_init(&backend->renderer, backend->fd)) {
|
||||
wlr_log(L_ERROR, "Failed to initialize renderer");
|
||||
goto error_event;
|
||||
}
|
||||
|
||||
if (!wlr_egl_bind_display(&drm->renderer.egl, display)) {
|
||||
if (!wlr_egl_bind_display(&backend->renderer.egl, display)) {
|
||||
wlr_log(L_INFO, "Failed to bind egl/wl display: %s", egl_error());
|
||||
}
|
||||
|
||||
return backend;
|
||||
return &backend->backend;
|
||||
|
||||
error_event:
|
||||
wl_event_source_remove(drm->drm_event);
|
||||
wl_event_source_remove(backend->drm_event);
|
||||
error_fd:
|
||||
wlr_session_close_file(drm->session, drm->fd);
|
||||
list_free(drm->outputs);
|
||||
wlr_session_close_file(backend->session, backend->fd);
|
||||
list_free(backend->outputs);
|
||||
error_backend:
|
||||
free(drm);
|
||||
free(backend);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -87,14 +87,16 @@ static void set_plane_props(struct atomic *atom, struct wlr_drm_plane *plane,
|
||||
}
|
||||
}
|
||||
|
||||
static bool atomic_crtc_pageflip(struct wlr_backend_state *drm, struct wlr_output_state *output,
|
||||
struct wlr_drm_crtc *crtc, uint32_t fb_id, drmModeModeInfo *mode) {
|
||||
static bool atomic_crtc_pageflip(struct wlr_drm_backend *backend,
|
||||
struct wlr_output_state *output,
|
||||
struct wlr_drm_crtc *crtc,
|
||||
uint32_t fb_id, drmModeModeInfo *mode) {
|
||||
if (mode) {
|
||||
if (crtc->mode_id) {
|
||||
drmModeDestroyPropertyBlob(drm->fd, crtc->mode_id);
|
||||
drmModeDestroyPropertyBlob(backend->fd, crtc->mode_id);
|
||||
}
|
||||
|
||||
if (drmModeCreatePropertyBlob(drm->fd, mode, sizeof(*mode), &crtc->mode_id)) {
|
||||
if (drmModeCreatePropertyBlob(backend->fd, mode, sizeof(*mode), &crtc->mode_id)) {
|
||||
wlr_log_errno(L_ERROR, "Unable to create property blob");
|
||||
return false;
|
||||
}
|
||||
@ -107,24 +109,25 @@ static bool atomic_crtc_pageflip(struct wlr_backend_state *drm, struct wlr_outpu
|
||||
atomic_add(&atom, crtc->id, crtc->props.mode_id, crtc->mode_id);
|
||||
atomic_add(&atom, crtc->id, crtc->props.active, 1);
|
||||
set_plane_props(&atom, crtc->primary, crtc->id, fb_id, true);
|
||||
return atomic_commit(drm->fd, &atom, output, mode ? DRM_MODE_ATOMIC_ALLOW_MODESET : 0);
|
||||
return atomic_commit(backend->fd, &atom,
|
||||
output, mode ? DRM_MODE_ATOMIC_ALLOW_MODESET : 0);
|
||||
}
|
||||
|
||||
static void atomic_conn_enable(struct wlr_backend_state *drm, struct wlr_output_state *output,
|
||||
bool enable) {
|
||||
static void atomic_conn_enable(struct wlr_drm_backend *backend,
|
||||
struct wlr_output_state *output, bool enable) {
|
||||
struct wlr_drm_crtc *crtc = output->crtc;
|
||||
struct atomic atom;
|
||||
|
||||
atomic_begin(crtc, &atom);
|
||||
atomic_add(&atom, crtc->id, crtc->props.active, enable);
|
||||
atomic_end(drm->fd, &atom);
|
||||
atomic_end(backend->fd, &atom);
|
||||
}
|
||||
|
||||
bool legacy_crtc_set_cursor(struct wlr_backend_state *drm, struct wlr_drm_crtc *crtc,
|
||||
struct gbm_bo *bo);
|
||||
bool legacy_crtc_set_cursor(struct wlr_drm_backend *backend,
|
||||
struct wlr_drm_crtc *crtc, struct gbm_bo *bo);
|
||||
|
||||
static bool atomic_crtc_set_cursor(struct wlr_backend_state *drm, struct wlr_drm_crtc *crtc,
|
||||
struct gbm_bo *bo) {
|
||||
static bool atomic_crtc_set_cursor(struct wlr_drm_backend *backend,
|
||||
struct wlr_drm_crtc *crtc, struct gbm_bo *bo) {
|
||||
if (!crtc || !crtc->cursor) {
|
||||
return true;
|
||||
}
|
||||
@ -132,7 +135,7 @@ static bool atomic_crtc_set_cursor(struct wlr_backend_state *drm, struct wlr_drm
|
||||
struct wlr_drm_plane *plane = crtc->cursor;
|
||||
// We can't use atomic operations on fake planes
|
||||
if (plane->id == 0) {
|
||||
return legacy_crtc_set_cursor(drm, crtc, bo);
|
||||
return legacy_crtc_set_cursor(backend, crtc, bo);
|
||||
}
|
||||
|
||||
struct atomic atom;
|
||||
@ -146,18 +149,18 @@ static bool atomic_crtc_set_cursor(struct wlr_backend_state *drm, struct wlr_drm
|
||||
atomic_add(&atom, plane->id, plane->props.crtc_id, 0);
|
||||
}
|
||||
|
||||
return atomic_end(drm->fd, &atom);
|
||||
return atomic_end(backend->fd, &atom);
|
||||
}
|
||||
|
||||
bool legacy_crtc_move_cursor(struct wlr_backend_state *drm, struct wlr_drm_crtc *crtc,
|
||||
int x, int y);
|
||||
bool legacy_crtc_move_cursor(struct wlr_drm_backend *backend,
|
||||
struct wlr_drm_crtc *crtc, int x, int y);
|
||||
|
||||
static bool atomic_crtc_move_cursor(struct wlr_backend_state *drm, struct wlr_drm_crtc *crtc,
|
||||
int x, int y) {
|
||||
static bool atomic_crtc_move_cursor(struct wlr_drm_backend *backend,
|
||||
struct wlr_drm_crtc *crtc, int x, int y) {
|
||||
struct wlr_drm_plane *plane = crtc->cursor;
|
||||
// We can't use atomic operations on fake planes
|
||||
if (plane->id == 0) {
|
||||
return legacy_crtc_move_cursor(drm, crtc, x, y);
|
||||
return legacy_crtc_move_cursor(backend, crtc, x, y);
|
||||
}
|
||||
|
||||
struct atomic atom;
|
||||
@ -165,7 +168,7 @@ static bool atomic_crtc_move_cursor(struct wlr_backend_state *drm, struct wlr_dr
|
||||
atomic_begin(crtc, &atom);
|
||||
atomic_add(&atom, plane->id, plane->props.crtc_x, x);
|
||||
atomic_add(&atom, plane->id, plane->props.crtc_y, y);
|
||||
return atomic_end(drm->fd, &atom);
|
||||
return atomic_end(backend->fd, &atom);
|
||||
}
|
||||
|
||||
const struct wlr_drm_interface atomic_iface = {
|
||||
|
@ -5,38 +5,39 @@
|
||||
#include "backend/drm.h"
|
||||
#include "backend/drm-util.h"
|
||||
|
||||
static bool legacy_crtc_pageflip(struct wlr_backend_state *drm, struct wlr_output_state *output,
|
||||
struct wlr_drm_crtc *crtc, uint32_t fb_id, drmModeModeInfo *mode) {
|
||||
static bool legacy_crtc_pageflip(struct wlr_drm_backend *backend,
|
||||
struct wlr_output_state *output, struct wlr_drm_crtc *crtc,
|
||||
uint32_t fb_id, drmModeModeInfo *mode) {
|
||||
if (mode) {
|
||||
drmModeSetCrtc(drm->fd, crtc->id, fb_id, 0, 0,
|
||||
drmModeSetCrtc(backend->fd, crtc->id, fb_id, 0, 0,
|
||||
&output->connector, 1, mode);
|
||||
}
|
||||
|
||||
drmModePageFlip(drm->fd, crtc->id, fb_id, DRM_MODE_PAGE_FLIP_EVENT, output);
|
||||
drmModePageFlip(backend->fd, crtc->id, fb_id, DRM_MODE_PAGE_FLIP_EVENT, output);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void legacy_conn_enable(struct wlr_backend_state *drm, struct wlr_output_state *output,
|
||||
bool enable) {
|
||||
drmModeConnectorSetProperty(drm->fd, output->connector, output->props.dpms,
|
||||
static void legacy_conn_enable(struct wlr_drm_backend *backend,
|
||||
struct wlr_output_state *output, bool enable) {
|
||||
drmModeConnectorSetProperty(backend->fd, output->connector, output->props.dpms,
|
||||
enable ? DRM_MODE_DPMS_ON : DRM_MODE_DPMS_OFF);
|
||||
}
|
||||
|
||||
bool legacy_crtc_set_cursor(struct wlr_backend_state *drm, struct wlr_drm_crtc *crtc,
|
||||
struct gbm_bo *bo) {
|
||||
bool legacy_crtc_set_cursor(struct wlr_drm_backend *backend,
|
||||
struct wlr_drm_crtc *crtc, struct gbm_bo *bo) {
|
||||
if (!crtc || !crtc->cursor) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!bo) {
|
||||
drmModeSetCursor(drm->fd, crtc->id, 0, 0, 0);
|
||||
drmModeSetCursor(backend->fd, crtc->id, 0, 0, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
struct wlr_drm_plane *plane = crtc->cursor;
|
||||
|
||||
if (drmModeSetCursor(drm->fd, crtc->id, gbm_bo_get_handle(bo).u32,
|
||||
if (drmModeSetCursor(backend->fd, crtc->id, gbm_bo_get_handle(bo).u32,
|
||||
plane->width, plane->height)) {
|
||||
wlr_log_errno(L_ERROR, "Failed to set hardware cursor");
|
||||
return false;
|
||||
@ -45,9 +46,9 @@ bool legacy_crtc_set_cursor(struct wlr_backend_state *drm, struct wlr_drm_crtc *
|
||||
return true;
|
||||
}
|
||||
|
||||
bool legacy_crtc_move_cursor(struct wlr_backend_state *drm, struct wlr_drm_crtc *crtc,
|
||||
int x, int y) {
|
||||
return !drmModeMoveCursor(drm->fd, crtc->id, x, y);
|
||||
bool legacy_crtc_move_cursor(struct wlr_drm_backend *backend,
|
||||
struct wlr_drm_crtc *crtc, int x, int y) {
|
||||
return !drmModeMoveCursor(backend->fd, crtc->id, x, y);
|
||||
}
|
||||
|
||||
const struct wlr_drm_interface legacy_iface = {
|
||||
|
@ -22,21 +22,21 @@
|
||||
#include "backend/drm.h"
|
||||
#include "backend/drm-util.h"
|
||||
|
||||
bool wlr_drm_check_features(struct wlr_backend_state *drm) {
|
||||
bool wlr_drm_check_features(struct wlr_drm_backend *backend) {
|
||||
extern const struct wlr_drm_interface legacy_iface;
|
||||
extern const struct wlr_drm_interface atomic_iface;
|
||||
|
||||
if (drmSetClientCap(drm->fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1)) {
|
||||
if (drmSetClientCap(backend->fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1)) {
|
||||
wlr_log(L_ERROR, "DRM universal planes unsupported");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (drmSetClientCap(drm->fd, DRM_CLIENT_CAP_ATOMIC, 1)) {
|
||||
if (drmSetClientCap(backend->fd, DRM_CLIENT_CAP_ATOMIC, 1)) {
|
||||
wlr_log(L_DEBUG, "Atomic modesetting unsupported, using legacy DRM interface");
|
||||
drm->iface = &legacy_iface;
|
||||
backend->iface = &legacy_iface;
|
||||
} else {
|
||||
wlr_log(L_DEBUG, "Using atomic DRM interface");
|
||||
drm->iface = &atomic_iface;
|
||||
backend->iface = &atomic_iface;
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -49,8 +49,8 @@ static int cmp_plane(const void *arg1, const void *arg2) {
|
||||
return (int)a->type - (int)b->type;
|
||||
}
|
||||
|
||||
static bool init_planes(struct wlr_backend_state *drm) {
|
||||
drmModePlaneRes *plane_res = drmModeGetPlaneResources(drm->fd);
|
||||
static bool init_planes(struct wlr_drm_backend *backend) {
|
||||
drmModePlaneRes *plane_res = drmModeGetPlaneResources(backend->fd);
|
||||
if (!plane_res) {
|
||||
wlr_log_errno(L_ERROR, "Failed to get DRM plane resources");
|
||||
return false;
|
||||
@ -63,17 +63,17 @@ static bool init_planes(struct wlr_backend_state *drm) {
|
||||
return true;
|
||||
}
|
||||
|
||||
drm->num_planes = plane_res->count_planes;
|
||||
drm->planes = calloc(drm->num_planes, sizeof(*drm->planes));
|
||||
if (!drm->planes) {
|
||||
backend->num_planes = plane_res->count_planes;
|
||||
backend->planes = calloc(backend->num_planes, sizeof(*backend->planes));
|
||||
if (!backend->planes) {
|
||||
wlr_log_errno(L_ERROR, "Allocation failed");
|
||||
goto error_res;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < drm->num_planes; ++i) {
|
||||
struct wlr_drm_plane *p = &drm->planes[i];
|
||||
for (size_t i = 0; i < backend->num_planes; ++i) {
|
||||
struct wlr_drm_plane *p = &backend->planes[i];
|
||||
|
||||
drmModePlane *plane = drmModeGetPlane(drm->fd, plane_res->planes[i]);
|
||||
drmModePlane *plane = drmModeGetPlane(backend->fd, plane_res->planes[i]);
|
||||
if (!plane) {
|
||||
wlr_log_errno(L_ERROR, "Failed to get DRM plane");
|
||||
goto error_planes;
|
||||
@ -83,39 +83,44 @@ static bool init_planes(struct wlr_backend_state *drm) {
|
||||
p->possible_crtcs = plane->possible_crtcs;
|
||||
uint64_t type;
|
||||
|
||||
if (!wlr_drm_get_plane_props(drm->fd, p->id, &p->props) ||
|
||||
!wlr_drm_get_prop(drm->fd, p->id, p->props.type, &type)) {
|
||||
if (!wlr_drm_get_plane_props(backend->fd, p->id, &p->props) ||
|
||||
!wlr_drm_get_prop(backend->fd, p->id, p->props.type, &type)) {
|
||||
drmModeFreePlane(plane);
|
||||
goto error_planes;
|
||||
}
|
||||
|
||||
p->type = type;
|
||||
drm->num_type_planes[type]++;
|
||||
backend->num_type_planes[type]++;
|
||||
|
||||
drmModeFreePlane(plane);
|
||||
}
|
||||
|
||||
wlr_log(L_INFO, "(%zu overlay, %zu primary, %zu cursor)",
|
||||
drm->num_overlay_planes, drm->num_primary_planes, drm->num_cursor_planes);
|
||||
backend->num_overlay_planes,
|
||||
backend->num_primary_planes,
|
||||
backend->num_cursor_planes);
|
||||
|
||||
qsort(drm->planes, drm->num_planes, sizeof(*drm->planes), cmp_plane);
|
||||
qsort(backend->planes, backend->num_planes,
|
||||
sizeof(*backend->planes), cmp_plane);
|
||||
|
||||
drm->overlay_planes = drm->planes;
|
||||
drm->primary_planes = drm->overlay_planes + drm->num_overlay_planes;
|
||||
drm->cursor_planes = drm->primary_planes + drm->num_primary_planes;
|
||||
backend->overlay_planes = backend->planes;
|
||||
backend->primary_planes = backend->overlay_planes
|
||||
+ backend->num_overlay_planes;
|
||||
backend->cursor_planes = backend->primary_planes
|
||||
+ backend->num_primary_planes;
|
||||
|
||||
drmModeFreePlaneResources(plane_res);
|
||||
return true;
|
||||
|
||||
error_planes:
|
||||
free(drm->planes);
|
||||
free(backend->planes);
|
||||
error_res:
|
||||
drmModeFreePlaneResources(plane_res);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool wlr_drm_resources_init(struct wlr_backend_state *drm) {
|
||||
drmModeRes *res = drmModeGetResources(drm->fd);
|
||||
bool wlr_drm_resources_init(struct wlr_drm_backend *backend) {
|
||||
drmModeRes *res = drmModeGetResources(backend->fd);
|
||||
if (!res) {
|
||||
wlr_log_errno(L_ERROR, "Failed to get DRM resources");
|
||||
return false;
|
||||
@ -123,20 +128,20 @@ bool wlr_drm_resources_init(struct wlr_backend_state *drm) {
|
||||
|
||||
wlr_log(L_INFO, "Found %d DRM CRTCs", res->count_crtcs);
|
||||
|
||||
drm->num_crtcs = res->count_crtcs;
|
||||
drm->crtcs = calloc(drm->num_crtcs, sizeof(drm->crtcs[0]));
|
||||
if (!drm->crtcs) {
|
||||
backend->num_crtcs = res->count_crtcs;
|
||||
backend->crtcs = calloc(backend->num_crtcs, sizeof(backend->crtcs[0]));
|
||||
if (!backend->crtcs) {
|
||||
wlr_log_errno(L_ERROR, "Allocation failed");
|
||||
goto error_res;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < drm->num_crtcs; ++i) {
|
||||
struct wlr_drm_crtc *crtc = &drm->crtcs[i];
|
||||
for (size_t i = 0; i < backend->num_crtcs; ++i) {
|
||||
struct wlr_drm_crtc *crtc = &backend->crtcs[i];
|
||||
crtc->id = res->crtcs[i];
|
||||
wlr_drm_get_crtc_props(drm->fd, crtc->id, &crtc->props);
|
||||
wlr_drm_get_crtc_props(backend->fd, crtc->id, &crtc->props);
|
||||
}
|
||||
|
||||
if (!init_planes(drm)) {
|
||||
if (!init_planes(backend)) {
|
||||
goto error_crtcs;
|
||||
}
|
||||
|
||||
@ -145,28 +150,25 @@ bool wlr_drm_resources_init(struct wlr_backend_state *drm) {
|
||||
return true;
|
||||
|
||||
error_crtcs:
|
||||
free(drm->crtcs);
|
||||
free(backend->crtcs);
|
||||
error_res:
|
||||
drmModeFreeResources(res);
|
||||
return false;
|
||||
}
|
||||
|
||||
void wlr_drm_resources_free(struct wlr_backend_state *drm) {
|
||||
if (!drm) {
|
||||
void wlr_drm_resources_free(struct wlr_drm_backend *backend) {
|
||||
if (!backend) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < drm->num_crtcs; ++i) {
|
||||
struct wlr_drm_crtc *crtc = &drm->crtcs[i];
|
||||
|
||||
for (size_t i = 0; i < backend->num_crtcs; ++i) {
|
||||
struct wlr_drm_crtc *crtc = &backend->crtcs[i];
|
||||
drmModeAtomicFree(crtc->atomic);
|
||||
if (crtc->mode_id) {
|
||||
drmModeDestroyPropertyBlob(drm->fd, crtc->mode_id);
|
||||
drmModeDestroyPropertyBlob(backend->fd, crtc->mode_id);
|
||||
}
|
||||
}
|
||||
|
||||
free(drm->crtcs);
|
||||
free(drm->planes);
|
||||
free(backend->crtcs);
|
||||
free(backend->planes);
|
||||
}
|
||||
|
||||
bool wlr_drm_renderer_init(struct wlr_drm_renderer *renderer, int fd) {
|
||||
@ -285,14 +287,15 @@ static void wlr_drm_output_make_current(struct wlr_output_state *output) {
|
||||
}
|
||||
|
||||
static void wlr_drm_output_swap_buffers(struct wlr_output_state *output) {
|
||||
struct wlr_backend_state *drm = wl_container_of(output->renderer, drm, renderer);
|
||||
struct wlr_drm_backend *backend =
|
||||
wl_container_of(output->renderer, backend, renderer);
|
||||
struct wlr_drm_renderer *renderer = output->renderer;
|
||||
struct wlr_drm_crtc *crtc = output->crtc;
|
||||
struct wlr_drm_plane *plane = crtc->primary;
|
||||
|
||||
wlr_drm_plane_swap_buffers(renderer, plane);
|
||||
|
||||
drm->iface->crtc_pageflip(drm, output, crtc, get_fb_for_bo(plane->back), NULL);
|
||||
backend->iface->crtc_pageflip(backend, output, crtc, get_fb_for_bo(plane->back), NULL);
|
||||
output->pageflip_pending = true;
|
||||
}
|
||||
|
||||
@ -301,7 +304,8 @@ void wlr_drm_output_start_renderer(struct wlr_output_state *output) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct wlr_backend_state *drm = wl_container_of(output->renderer, drm, renderer);
|
||||
struct wlr_drm_backend *backend =
|
||||
wl_container_of(output->renderer, backend, renderer);
|
||||
struct wlr_drm_renderer *renderer = output->renderer;
|
||||
struct wlr_drm_crtc *crtc = output->crtc;
|
||||
struct wlr_drm_plane *plane = crtc->primary;
|
||||
@ -319,83 +323,86 @@ void wlr_drm_output_start_renderer(struct wlr_output_state *output) {
|
||||
}
|
||||
|
||||
drmModeModeInfo *mode = &output->base->current_mode->state->mode;
|
||||
drm->iface->crtc_pageflip(drm, output, crtc, get_fb_for_bo(bo), mode);
|
||||
backend->iface->crtc_pageflip(backend, output, crtc, get_fb_for_bo(bo), mode);
|
||||
output->pageflip_pending = true;
|
||||
}
|
||||
|
||||
static void wlr_drm_output_enable(struct wlr_output_state *output, bool enable) {
|
||||
struct wlr_backend_state *drm =
|
||||
wl_container_of(output->renderer, drm, renderer);
|
||||
struct wlr_drm_backend *backend =
|
||||
wl_container_of(output->renderer, backend, renderer);
|
||||
if (output->state != WLR_DRM_OUTPUT_CONNECTED) {
|
||||
return;
|
||||
}
|
||||
|
||||
drm->iface->conn_enable(drm, output, enable);
|
||||
backend->iface->conn_enable(backend, output, enable);
|
||||
|
||||
if (enable) {
|
||||
wlr_drm_output_start_renderer(output);
|
||||
}
|
||||
}
|
||||
|
||||
static void realloc_planes(struct wlr_backend_state *drm, const uint32_t *crtc_in) {
|
||||
static void realloc_planes(struct wlr_drm_backend *backend, const uint32_t *crtc_in) {
|
||||
// overlay, primary, cursor
|
||||
for (int type = 0; type < 3; ++type) {
|
||||
if (drm->num_type_planes[type] == 0) {
|
||||
if (backend->num_type_planes[type] == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
uint32_t possible[drm->num_type_planes[type]];
|
||||
uint32_t crtc[drm->num_crtcs];
|
||||
uint32_t crtc_res[drm->num_crtcs];
|
||||
uint32_t possible[backend->num_type_planes[type]];
|
||||
uint32_t crtc[backend->num_crtcs];
|
||||
uint32_t crtc_res[backend->num_crtcs];
|
||||
|
||||
for (size_t i = 0; i < drm->num_type_planes[type]; ++i) {
|
||||
possible[i] = drm->type_planes[type][i].possible_crtcs;
|
||||
for (size_t i = 0; i < backend->num_type_planes[type]; ++i) {
|
||||
possible[i] = backend->type_planes[type][i].possible_crtcs;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < drm->num_crtcs; ++i) {
|
||||
for (size_t i = 0; i < backend->num_crtcs; ++i) {
|
||||
if (crtc_in[i] == UNMATCHED) {
|
||||
crtc[i] = SKIP;
|
||||
} else if (drm->crtcs[i].planes[type]) {
|
||||
crtc[i] = drm->crtcs[i].planes[type] - drm->type_planes[type];
|
||||
} else if (backend->crtcs[i].planes[type]) {
|
||||
crtc[i] = backend->crtcs[i].planes[type]
|
||||
- backend->type_planes[type];
|
||||
} else {
|
||||
crtc[i] = UNMATCHED;
|
||||
}
|
||||
}
|
||||
|
||||
match_obj(drm->num_type_planes[type], possible, drm->num_crtcs, crtc, crtc_res);
|
||||
match_obj(backend->num_type_planes[type], possible,
|
||||
backend->num_crtcs, crtc, crtc_res);
|
||||
|
||||
for (size_t i = 0; i < drm->num_crtcs; ++i) {
|
||||
for (size_t i = 0; i < backend->num_crtcs; ++i) {
|
||||
if (crtc_res[i] == UNMATCHED || crtc_res[i] == SKIP) {
|
||||
continue;
|
||||
}
|
||||
|
||||
struct wlr_drm_crtc *c = &drm->crtcs[i];
|
||||
struct wlr_drm_crtc *c = &backend->crtcs[i];
|
||||
struct wlr_drm_plane **old = &c->planes[type];
|
||||
struct wlr_drm_plane *new = &drm->type_planes[type][crtc_res[i]];
|
||||
struct wlr_drm_plane *new = &backend->type_planes[type][crtc_res[i]];
|
||||
|
||||
if (*old != new) {
|
||||
wlr_drm_plane_renderer_free(&drm->renderer, *old);
|
||||
wlr_drm_plane_renderer_free(&drm->renderer, new);
|
||||
wlr_drm_plane_renderer_free(&backend->renderer, *old);
|
||||
wlr_drm_plane_renderer_free(&backend->renderer, new);
|
||||
*old = new;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void realloc_crtcs(struct wlr_backend_state *drm, struct wlr_output_state *output) {
|
||||
uint32_t crtc[drm->num_crtcs];
|
||||
uint32_t crtc_res[drm->num_crtcs];
|
||||
uint32_t possible_crtc[drm->outputs->length];
|
||||
static void realloc_crtcs(struct wlr_drm_backend *backend,
|
||||
struct wlr_output_state *output) {
|
||||
uint32_t crtc[backend->num_crtcs];
|
||||
uint32_t crtc_res[backend->num_crtcs];
|
||||
uint32_t possible_crtc[backend->outputs->length];
|
||||
|
||||
for (size_t i = 0; i < drm->num_crtcs; ++i) {
|
||||
for (size_t i = 0; i < backend->num_crtcs; ++i) {
|
||||
crtc[i] = UNMATCHED;
|
||||
}
|
||||
|
||||
memset(possible_crtc, 0, sizeof(possible_crtc));
|
||||
|
||||
size_t index;
|
||||
for (size_t i = 0; i < drm->outputs->length; ++i) {
|
||||
struct wlr_output_state *o = drm->outputs->items[i];
|
||||
for (size_t i = 0; i < backend->outputs->length; ++i) {
|
||||
struct wlr_output_state *o = backend->outputs->items[i];
|
||||
if (o == output) {
|
||||
index = i;
|
||||
}
|
||||
@ -405,14 +412,15 @@ static void realloc_crtcs(struct wlr_backend_state *drm, struct wlr_output_state
|
||||
}
|
||||
|
||||
possible_crtc[i] = o->possible_crtc;
|
||||
crtc[o->crtc - drm->crtcs] = i;
|
||||
crtc[o->crtc - backend->crtcs] = i;
|
||||
}
|
||||
|
||||
possible_crtc[index] = output->possible_crtc;
|
||||
match_obj(drm->outputs->length, possible_crtc, drm->num_crtcs, crtc, crtc_res);
|
||||
match_obj(backend->outputs->length, possible_crtc,
|
||||
backend->num_crtcs, crtc, crtc_res);
|
||||
|
||||
bool matched = false;
|
||||
for (size_t i = 0; i < drm->num_crtcs; ++i) {
|
||||
for (size_t i = 0; i < backend->num_crtcs; ++i) {
|
||||
// We don't want any of the current monitors to be deactivated.
|
||||
if (crtc[i] != UNMATCHED && crtc_res[i] == UNMATCHED) {
|
||||
return;
|
||||
@ -427,28 +435,29 @@ static void realloc_crtcs(struct wlr_backend_state *drm, struct wlr_output_state
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < drm->num_crtcs; ++i) {
|
||||
for (size_t i = 0; i < backend->num_crtcs; ++i) {
|
||||
if (crtc_res[i] == UNMATCHED) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (crtc_res[i] != crtc[i]) {
|
||||
struct wlr_output_state *o = drm->outputs->items[crtc_res[i]];
|
||||
o->crtc = &drm->crtcs[i];
|
||||
struct wlr_output_state *o = backend->outputs->items[crtc_res[i]];
|
||||
o->crtc = &backend->crtcs[i];
|
||||
}
|
||||
}
|
||||
|
||||
realloc_planes(drm, crtc_res);
|
||||
realloc_planes(backend, crtc_res);
|
||||
}
|
||||
|
||||
static bool wlr_drm_output_set_mode(struct wlr_output_state *output,
|
||||
struct wlr_output_mode *mode) {
|
||||
struct wlr_backend_state *drm = wl_container_of(output->renderer, drm, renderer);
|
||||
struct wlr_drm_backend *backend
|
||||
= wl_container_of(output->renderer, backend, renderer);
|
||||
|
||||
wlr_log(L_INFO, "Modesetting '%s' with '%ux%u@%u mHz'", output->base->name,
|
||||
mode->width, mode->height, mode->refresh);
|
||||
|
||||
drmModeConnector *conn = drmModeGetConnector(drm->fd, output->connector);
|
||||
drmModeConnector *conn = drmModeGetConnector(backend->fd, output->connector);
|
||||
if (!conn) {
|
||||
wlr_log_errno(L_ERROR, "Failed to get DRM connector");
|
||||
goto error_output;
|
||||
@ -461,7 +470,7 @@ static bool wlr_drm_output_set_mode(struct wlr_output_state *output,
|
||||
|
||||
drmModeEncoder *enc = NULL;
|
||||
for (int i = 0; !enc && i < conn->count_encoders; ++i) {
|
||||
enc = drmModeGetEncoder(drm->fd, conn->encoders[i]);
|
||||
enc = drmModeGetEncoder(backend->fd, conn->encoders[i]);
|
||||
}
|
||||
|
||||
if (!enc) {
|
||||
@ -470,7 +479,7 @@ static bool wlr_drm_output_set_mode(struct wlr_output_state *output,
|
||||
}
|
||||
|
||||
output->possible_crtc = enc->possible_crtcs;
|
||||
realloc_crtcs(drm, output);
|
||||
realloc_crtcs(backend, output);
|
||||
|
||||
if (!output->crtc) {
|
||||
wlr_log(L_ERROR, "Unable to match %s with a CRTC", output->base->name);
|
||||
@ -479,10 +488,10 @@ static bool wlr_drm_output_set_mode(struct wlr_output_state *output,
|
||||
|
||||
struct wlr_drm_crtc *crtc = output->crtc;
|
||||
wlr_log(L_DEBUG, "%s: crtc=%ju ovr=%jd pri=%jd cur=%jd", output->base->name,
|
||||
crtc - drm->crtcs,
|
||||
crtc->overlay ? crtc->overlay - drm->overlay_planes : -1,
|
||||
crtc->primary ? crtc->primary - drm->primary_planes : -1,
|
||||
crtc->cursor ? crtc->cursor - drm->cursor_planes : -1);
|
||||
crtc - backend->crtcs,
|
||||
crtc->overlay ? crtc->overlay - backend->overlay_planes : -1,
|
||||
crtc->primary ? crtc->primary - backend->primary_planes : -1,
|
||||
crtc->cursor ? crtc->cursor - backend->cursor_planes : -1);
|
||||
|
||||
output->state = WLR_DRM_OUTPUT_CONNECTED;
|
||||
output->width = output->base->width = mode->width;
|
||||
@ -492,8 +501,8 @@ static bool wlr_drm_output_set_mode(struct wlr_output_state *output,
|
||||
|
||||
// Since realloc_crtcs can deallocate planes on OTHER outputs,
|
||||
// we actually need to reinitalise all of them
|
||||
for (size_t i = 0; i < drm->outputs->length; ++i) {
|
||||
struct wlr_output_state *output = drm->outputs->items[i];
|
||||
for (size_t i = 0; i < backend->outputs->length; ++i) {
|
||||
struct wlr_output_state *output = backend->outputs->items[i];
|
||||
struct wlr_output_mode *mode = output->base->current_mode;
|
||||
struct wlr_drm_crtc *crtc = output->crtc;
|
||||
|
||||
@ -501,7 +510,7 @@ static bool wlr_drm_output_set_mode(struct wlr_output_state *output,
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!wlr_drm_plane_renderer_init(&drm->renderer, crtc->primary,
|
||||
if (!wlr_drm_plane_renderer_init(&backend->renderer, crtc->primary,
|
||||
mode->width, mode->height, GBM_FORMAT_XRGB8888,
|
||||
GBM_BO_USE_SCANOUT)) {
|
||||
wlr_log(L_ERROR, "Failed to initalise renderer for plane");
|
||||
@ -531,13 +540,14 @@ static void wlr_drm_output_transform(struct wlr_output_state *output,
|
||||
|
||||
static bool wlr_drm_output_set_cursor(struct wlr_output_state *output,
|
||||
const uint8_t *buf, int32_t stride, uint32_t width, uint32_t height) {
|
||||
struct wlr_backend_state *drm = wl_container_of(output->renderer, drm, renderer);
|
||||
struct wlr_drm_backend *backend
|
||||
= wl_container_of(output->renderer, backend, renderer);
|
||||
struct wlr_drm_renderer *renderer = output->renderer;
|
||||
struct wlr_drm_crtc *crtc = output->crtc;
|
||||
struct wlr_drm_plane *plane = crtc->cursor;
|
||||
|
||||
if (!buf) {
|
||||
return drm->iface->crtc_set_cursor(drm, crtc, NULL);
|
||||
return backend->iface->crtc_set_cursor(backend, crtc, NULL);
|
||||
}
|
||||
|
||||
// We don't have a real cursor plane, so we make a fake one
|
||||
@ -553,9 +563,9 @@ static bool wlr_drm_output_set_cursor(struct wlr_output_state *output,
|
||||
if (!plane->gbm) {
|
||||
int ret;
|
||||
uint64_t w, h;
|
||||
ret = drmGetCap(drm->fd, DRM_CAP_CURSOR_WIDTH, &w);
|
||||
ret = drmGetCap(backend->fd, DRM_CAP_CURSOR_WIDTH, &w);
|
||||
w = ret ? 64 : w;
|
||||
ret = drmGetCap(drm->fd, DRM_CAP_CURSOR_HEIGHT, &h);
|
||||
ret = drmGetCap(backend->fd, DRM_CAP_CURSOR_HEIGHT, &h);
|
||||
h = ret ? 64 : h;
|
||||
|
||||
if (width > w || height > h) {
|
||||
@ -580,7 +590,7 @@ static bool wlr_drm_output_set_cursor(struct wlr_output_state *output,
|
||||
wlr_matrix_texture(plane->matrix, plane->width, plane->height,
|
||||
output->base->transform ^ WL_OUTPUT_TRANSFORM_FLIPPED_180);
|
||||
|
||||
plane->wlr_rend = wlr_gles2_renderer_init(drm->base);
|
||||
plane->wlr_rend = wlr_gles2_renderer_init(&backend->backend);
|
||||
if (!plane->wlr_rend) {
|
||||
return false;
|
||||
}
|
||||
@ -625,14 +635,14 @@ static bool wlr_drm_output_set_cursor(struct wlr_output_state *output,
|
||||
|
||||
gbm_bo_unmap(bo, bo_data);
|
||||
|
||||
return drm->iface->crtc_set_cursor(drm, crtc, bo);
|
||||
return backend->iface->crtc_set_cursor(backend, crtc, bo);
|
||||
}
|
||||
|
||||
static bool wlr_drm_output_move_cursor(struct wlr_output_state *output,
|
||||
int x, int y) {
|
||||
struct wlr_backend_state *drm =
|
||||
wl_container_of(output->renderer, drm, renderer);
|
||||
return drm->iface->crtc_move_cursor(drm, output->crtc, x, y);
|
||||
struct wlr_drm_backend *backend =
|
||||
wl_container_of(output->renderer, backend, renderer);
|
||||
return backend->iface->crtc_move_cursor(backend, output->crtc, x, y);
|
||||
}
|
||||
|
||||
static void wlr_drm_output_destroy(struct wlr_output_state *output) {
|
||||
@ -673,17 +683,17 @@ static const int32_t subpixel_map[] = {
|
||||
[DRM_MODE_SUBPIXEL_NONE] = WL_OUTPUT_SUBPIXEL_NONE,
|
||||
};
|
||||
|
||||
void wlr_drm_scan_connectors(struct wlr_backend_state *drm) {
|
||||
void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) {
|
||||
wlr_log(L_INFO, "Scanning DRM connectors");
|
||||
|
||||
drmModeRes *res = drmModeGetResources(drm->fd);
|
||||
drmModeRes *res = drmModeGetResources(backend->fd);
|
||||
if (!res) {
|
||||
wlr_log_errno(L_ERROR, "Failed to get DRM resources");
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < res->count_connectors; ++i) {
|
||||
drmModeConnector *conn = drmModeGetConnector(drm->fd,
|
||||
drmModeConnector *conn = drmModeGetConnector(backend->fd,
|
||||
res->connectors[i]);
|
||||
if (!conn) {
|
||||
wlr_log_errno(L_ERROR, "Failed to get DRM connector");
|
||||
@ -691,7 +701,7 @@ void wlr_drm_scan_connectors(struct wlr_backend_state *drm) {
|
||||
}
|
||||
|
||||
struct wlr_output_state *output;
|
||||
int index = list_seq_find(drm->outputs, find_id, &conn->connector_id);
|
||||
int index = list_seq_find(backend->outputs, find_id, &conn->connector_id);
|
||||
|
||||
if (index == -1) {
|
||||
output = calloc(1, sizeof(*output));
|
||||
@ -709,13 +719,14 @@ void wlr_drm_scan_connectors(struct wlr_backend_state *drm) {
|
||||
continue;
|
||||
}
|
||||
|
||||
output->renderer = &drm->renderer;
|
||||
output->renderer = &backend->renderer;
|
||||
output->state = WLR_DRM_OUTPUT_DISCONNECTED;
|
||||
output->connector = conn->connector_id;
|
||||
|
||||
drmModeEncoder *curr_enc = drmModeGetEncoder(drm->fd, conn->encoder_id);
|
||||
drmModeEncoder *curr_enc = drmModeGetEncoder(backend->fd,
|
||||
conn->encoder_id);
|
||||
if (curr_enc) {
|
||||
output->old_crtc = drmModeGetCrtc(drm->fd, curr_enc->crtc_id);
|
||||
output->old_crtc = drmModeGetCrtc(backend->fd, curr_enc->crtc_id);
|
||||
drmModeFreeEncoder(curr_enc);
|
||||
}
|
||||
|
||||
@ -726,19 +737,20 @@ void wlr_drm_scan_connectors(struct wlr_backend_state *drm) {
|
||||
conn_get_name(conn->connector_type),
|
||||
conn->connector_type_id);
|
||||
|
||||
wlr_drm_get_connector_props(drm->fd, output->connector, &output->props);
|
||||
wlr_drm_get_connector_props(backend->fd,
|
||||
output->connector, &output->props);
|
||||
|
||||
size_t edid_len = 0;
|
||||
uint8_t *edid = wlr_drm_get_prop_blob(drm->fd, output->connector,
|
||||
output->props.edid, &edid_len);
|
||||
uint8_t *edid = wlr_drm_get_prop_blob(backend->fd,
|
||||
output->connector, output->props.edid, &edid_len);
|
||||
parse_edid(output->base, edid_len, edid);
|
||||
free(edid);
|
||||
|
||||
wlr_output_create_global(output->base, drm->display);
|
||||
list_add(drm->outputs, output);
|
||||
wlr_output_create_global(output->base, backend->display);
|
||||
list_add(backend->outputs, output);
|
||||
wlr_log(L_INFO, "Found display '%s'", output->base->name);
|
||||
} else {
|
||||
output = drm->outputs->items[index];
|
||||
output = backend->outputs->items[index];
|
||||
}
|
||||
|
||||
if (output->state == WLR_DRM_OUTPUT_DISCONNECTED &&
|
||||
@ -766,7 +778,7 @@ void wlr_drm_scan_connectors(struct wlr_backend_state *drm) {
|
||||
|
||||
output->state = WLR_DRM_OUTPUT_NEEDS_MODESET;
|
||||
wlr_log(L_INFO, "Sending modesetting signal for '%s'", output->base->name);
|
||||
wl_signal_emit(&drm->base->events.output_add, output->base);
|
||||
wl_signal_emit(&backend->backend.events.output_add, output->base);
|
||||
} else if (output->state == WLR_DRM_OUTPUT_CONNECTED &&
|
||||
conn->connection != DRM_MODE_CONNECTED) {
|
||||
|
||||
@ -783,8 +795,8 @@ void wlr_drm_scan_connectors(struct wlr_backend_state *drm) {
|
||||
static void page_flip_handler(int fd, unsigned seq,
|
||||
unsigned tv_sec, unsigned tv_usec, void *user) {
|
||||
struct wlr_output_state *output = user;
|
||||
struct wlr_backend_state *drm =
|
||||
wl_container_of(output->renderer, drm, renderer);
|
||||
struct wlr_drm_backend *backend =
|
||||
wl_container_of(output->renderer, backend, renderer);
|
||||
|
||||
output->pageflip_pending = false;
|
||||
if (output->state != WLR_DRM_OUTPUT_CONNECTED) {
|
||||
@ -797,7 +809,7 @@ static void page_flip_handler(int fd, unsigned seq,
|
||||
plane->front = NULL;
|
||||
}
|
||||
|
||||
if (drm->session->active) {
|
||||
if (backend->session->active) {
|
||||
wl_signal_emit(&output->base->events.frame, output->base);
|
||||
}
|
||||
}
|
||||
@ -834,7 +846,8 @@ void wlr_drm_output_cleanup(struct wlr_output_state *output, bool restore) {
|
||||
}
|
||||
|
||||
struct wlr_drm_renderer *renderer = output->renderer;
|
||||
struct wlr_backend_state *drm = wl_container_of(renderer, drm, renderer);
|
||||
struct wlr_drm_backend *backend =
|
||||
wl_container_of(renderer, backend, renderer);
|
||||
|
||||
switch (output->state) {
|
||||
case WLR_DRM_OUTPUT_CONNECTED:
|
||||
@ -861,8 +874,9 @@ void wlr_drm_output_cleanup(struct wlr_output_state *output, bool restore) {
|
||||
if (restore) {
|
||||
restore_output(output, renderer->fd);
|
||||
}
|
||||
wlr_log(L_INFO, "Emmiting destruction signal for '%s'", output->base->name);
|
||||
wl_signal_emit(&drm->base->events.output_remove, output->base);
|
||||
wlr_log(L_INFO, "Emmiting destruction signal for '%s'",
|
||||
output->base->name);
|
||||
wl_signal_emit(&backend->backend.events.output_remove, output->base);
|
||||
break;
|
||||
case WLR_DRM_OUTPUT_DISCONNECTED:
|
||||
break;
|
||||
|
@ -4,12 +4,12 @@ backend_files = files(
|
||||
'session/direct-ipc.c',
|
||||
'session/direct.c',
|
||||
'session/session.c',
|
||||
#'drm/backend.c',
|
||||
#'drm/drm.c',
|
||||
#'drm/drm-atomic.c',
|
||||
#'drm/drm-legacy.c',
|
||||
#'drm/drm-properties.c',
|
||||
#'drm/drm-util.c',
|
||||
'drm/backend.c',
|
||||
'drm/drm.c',
|
||||
'drm/drm-atomic.c',
|
||||
'drm/drm-legacy.c',
|
||||
'drm/drm-properties.c',
|
||||
'drm/drm-util.c',
|
||||
'libinput/backend.c',
|
||||
'libinput/events.c',
|
||||
'libinput/keyboard.c',
|
||||
|
@ -81,7 +81,7 @@ void wlr_drm_renderer_free(struct wlr_drm_renderer *renderer);
|
||||
|
||||
struct wlr_drm_interface;
|
||||
|
||||
struct wlr_drm_backend_state {
|
||||
struct wlr_drm_backend {
|
||||
struct wlr_backend backend;
|
||||
|
||||
const struct wlr_drm_interface *iface;
|
||||
@ -160,25 +160,26 @@ struct wlr_output_state {
|
||||
// Used to provide atomic or legacy DRM functions
|
||||
struct wlr_drm_interface {
|
||||
// Enable or disable DPMS for output
|
||||
void (*conn_enable)(struct wlr_backend_state *drm, struct wlr_output_state *output,
|
||||
bool enable);
|
||||
void (*conn_enable)(struct wlr_drm_backend *backend,
|
||||
struct wlr_output_state *output, bool enable);
|
||||
// Pageflip on crtc. If mode is non-NULL perform a full modeset using it.
|
||||
bool (*crtc_pageflip)(struct wlr_backend_state *drm, struct wlr_output_state *output,
|
||||
struct wlr_drm_crtc *crtc, uint32_t fb_id, drmModeModeInfo *mode);
|
||||
bool (*crtc_pageflip)(struct wlr_drm_backend *backend,
|
||||
struct wlr_output_state *output, struct wlr_drm_crtc *crtc,
|
||||
uint32_t fb_id, drmModeModeInfo *mode);
|
||||
// Enable the cursor buffer on crtc. Set bo to NULL to disable
|
||||
bool (*crtc_set_cursor)(struct wlr_backend_state *drm, struct wlr_drm_crtc *crtc,
|
||||
struct gbm_bo *bo);
|
||||
bool (*crtc_set_cursor)(struct wlr_drm_backend *backend,
|
||||
struct wlr_drm_crtc *crtc, struct gbm_bo *bo);
|
||||
// Move the cursor on crtc
|
||||
bool (*crtc_move_cursor)(struct wlr_backend_state *drm, struct wlr_drm_crtc *crtc,
|
||||
int x, int y);
|
||||
bool (*crtc_move_cursor)(struct wlr_drm_backend *backend,
|
||||
struct wlr_drm_crtc *crtc, int x, int y);
|
||||
};
|
||||
|
||||
bool wlr_drm_check_features(struct wlr_backend_state *drm);
|
||||
bool wlr_drm_resources_init(struct wlr_backend_state *drm);
|
||||
void wlr_drm_resources_free(struct wlr_backend_state *drm);
|
||||
bool wlr_drm_check_features(struct wlr_drm_backend *drm);
|
||||
bool wlr_drm_resources_init(struct wlr_drm_backend *drm);
|
||||
void wlr_drm_resources_free(struct wlr_drm_backend *drm);
|
||||
void wlr_drm_output_cleanup(struct wlr_output_state *output, bool restore);
|
||||
|
||||
void wlr_drm_scan_connectors(struct wlr_backend_state *state);
|
||||
void wlr_drm_scan_connectors(struct wlr_drm_backend *state);
|
||||
int wlr_drm_event(int fd, uint32_t mask, void *data);
|
||||
|
||||
void wlr_drm_output_start_renderer(struct wlr_output_state *output);
|
||||
|
Loading…
Reference in New Issue
Block a user