Refactor wlr_backend_state out of DRM backend

This commit is contained in:
Drew DeVault 2017-08-12 19:52:22 -04:00
parent c95a108d2f
commit 234b2104e4
6 changed files with 242 additions and 227 deletions

View File

@ -16,32 +16,34 @@
#include "backend/udev.h" #include "backend/udev.h"
#include "backend/drm.h" #include "backend/drm.h"
static bool wlr_drm_backend_init(struct wlr_backend_state *drm) { static bool wlr_drm_backend_init(struct wlr_backend *_backend) {
wlr_drm_scan_connectors(drm); struct wlr_drm_backend *backend = (struct wlr_drm_backend *)_backend;
wlr_drm_scan_connectors(backend);
return true; return true;
} }
static void wlr_drm_backend_destroy(struct wlr_backend_state *drm) { static void wlr_drm_backend_destroy(struct wlr_backend *_backend) {
if (!drm) { if (!_backend) {
return; return;
} }
struct wlr_drm_backend *backend = (struct wlr_drm_backend *)_backend;
for (size_t i = 0; drm->outputs && i < drm->outputs->length; ++i) { for (size_t i = 0; backend->outputs && i < backend->outputs->length; ++i) {
struct wlr_output_state *output = drm->outputs->items[i]; struct wlr_output_state *output = backend->outputs->items[i];
wlr_output_destroy(output->base); wlr_output_destroy(output->base);
} }
wlr_udev_signal_remove(drm->udev, &drm->drm_invalidated); wlr_udev_signal_remove(backend->udev, &backend->drm_invalidated);
wlr_drm_renderer_free(&drm->renderer); wlr_drm_renderer_free(&backend->renderer);
wlr_drm_resources_free(drm); wlr_drm_resources_free(backend);
wlr_session_close_file(drm->session, drm->fd); wlr_session_close_file(backend->session, backend->fd);
wl_event_source_remove(drm->drm_event); wl_event_source_remove(backend->drm_event);
list_free(drm->outputs); list_free(backend->outputs);
free(drm); free(backend);
} }
static struct wlr_egl *wlr_drm_backend_get_egl(struct wlr_backend_state *drm) { static struct wlr_egl *wlr_drm_backend_get_egl(struct wlr_backend *_backend) {
return &drm->renderer.egl; struct wlr_drm_backend *backend = (struct wlr_drm_backend *)_backend;
return &backend->renderer.egl;
} }
static struct wlr_backend_impl backend_impl = { 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) { 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; struct wlr_session *session = data;
if (session->active) { if (session->active) {
wlr_log(L_INFO, "DRM fd resumed"); wlr_log(L_INFO, "DRM fd resumed");
for (size_t i = 0; i < drm->outputs->length; ++i) { for (size_t i = 0; i < backend->outputs->length; ++i) {
struct wlr_output_state *output = drm->outputs->items[i]; struct wlr_output_state *output = backend->outputs->items[i];
wlr_drm_output_start_renderer(output); wlr_drm_output_start_renderer(output);
if (!output->crtc) { 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; 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); plane ? plane->cursor_bo : NULL);
} }
} else { } 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) { 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; struct wlr_udev *udev = data;
(void)udev; (void)udev;
char *name = drmGetDeviceNameFromFd2(drm->fd); char *name = drmGetDeviceNameFromFd2(backend->fd);
wlr_log(L_DEBUG, "%s invalidated", name); wlr_log(L_DEBUG, "%s invalidated", name);
free(name); free(name);
wlr_drm_scan_connectors(drm); wlr_drm_scan_connectors(backend);
} }
struct wlr_backend *wlr_drm_backend_create(struct wl_display *display, 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); free(name);
drmFreeVersion(version); drmFreeVersion(version);
struct wlr_backend_state *drm = calloc(1, sizeof(*drm)); struct wlr_drm_backend *backend = calloc(1, sizeof(struct wlr_drm_backend));
if (!drm) {
wlr_log_errno(L_ERROR, "Allocation failed");
return NULL;
}
struct wlr_backend *backend = wlr_backend_create(&backend_impl, drm);
if (!backend) { if (!backend) {
wlr_log_errno(L_ERROR, "Allocation failed"); wlr_log_errno(L_ERROR, "Allocation failed");
return NULL; return NULL;
} }
wlr_backend_create(&backend->backend, &backend_impl);
drm->base = backend; backend->session = session;
drm->session = session; backend->udev = udev;
drm->udev = udev; backend->outputs = list_create();
drm->outputs = list_create(); if (!backend->outputs) {
if (!drm->outputs) {
wlr_log(L_ERROR, "Failed to allocate list"); wlr_log(L_ERROR, "Failed to allocate list");
goto error_backend; goto error_backend;
} }
drm->fd = gpu_fd; backend->fd = gpu_fd;
struct stat st; struct stat st;
if (fstat(drm->fd, &st) < 0) { if (fstat(backend->fd, &st) < 0) {
wlr_log_errno(L_ERROR, "Stat failed"); wlr_log_errno(L_ERROR, "Stat failed");
} }
drm->dev = st.st_rdev; backend->dev = st.st_rdev;
drm->drm_invalidated.notify = drm_invalidated; backend->drm_invalidated.notify = drm_invalidated;
wlr_udev_signal_add(udev, drm->dev, &drm->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); 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); 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"); wlr_log(L_ERROR, "Failed to create DRM event source");
goto error_fd; goto error_fd;
} }
drm->session_signal.notify = session_signal; backend->session_signal.notify = session_signal;
wl_signal_add(&session->session_signal, &drm->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; goto error_event;
} }
if (!wlr_drm_resources_init(drm)) { if (!wlr_drm_resources_init(backend)) {
goto error_event; 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"); wlr_log(L_ERROR, "Failed to initialize renderer");
goto error_event; 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()); wlr_log(L_INFO, "Failed to bind egl/wl display: %s", egl_error());
} }
return backend; return &backend->backend;
error_event: error_event:
wl_event_source_remove(drm->drm_event); wl_event_source_remove(backend->drm_event);
error_fd: error_fd:
wlr_session_close_file(drm->session, drm->fd); wlr_session_close_file(backend->session, backend->fd);
list_free(drm->outputs); list_free(backend->outputs);
error_backend: error_backend:
free(drm);
free(backend); free(backend);
return NULL; return NULL;
} }

View File

@ -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, static bool atomic_crtc_pageflip(struct wlr_drm_backend *backend,
struct wlr_drm_crtc *crtc, uint32_t fb_id, drmModeModeInfo *mode) { struct wlr_output_state *output,
struct wlr_drm_crtc *crtc,
uint32_t fb_id, drmModeModeInfo *mode) {
if (mode) { if (mode) {
if (crtc->mode_id) { 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"); wlr_log_errno(L_ERROR, "Unable to create property blob");
return false; 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.mode_id, crtc->mode_id);
atomic_add(&atom, crtc->id, crtc->props.active, 1); atomic_add(&atom, crtc->id, crtc->props.active, 1);
set_plane_props(&atom, crtc->primary, crtc->id, fb_id, true); 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, static void atomic_conn_enable(struct wlr_drm_backend *backend,
bool enable) { struct wlr_output_state *output, bool enable) {
struct wlr_drm_crtc *crtc = output->crtc; struct wlr_drm_crtc *crtc = output->crtc;
struct atomic atom; struct atomic atom;
atomic_begin(crtc, &atom); atomic_begin(crtc, &atom);
atomic_add(&atom, crtc->id, crtc->props.active, enable); 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, bool legacy_crtc_set_cursor(struct wlr_drm_backend *backend,
struct gbm_bo *bo); 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, static bool atomic_crtc_set_cursor(struct wlr_drm_backend *backend,
struct gbm_bo *bo) { struct wlr_drm_crtc *crtc, struct gbm_bo *bo) {
if (!crtc || !crtc->cursor) { if (!crtc || !crtc->cursor) {
return true; 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; struct wlr_drm_plane *plane = crtc->cursor;
// We can't use atomic operations on fake planes // We can't use atomic operations on fake planes
if (plane->id == 0) { if (plane->id == 0) {
return legacy_crtc_set_cursor(drm, crtc, bo); return legacy_crtc_set_cursor(backend, crtc, bo);
} }
struct atomic atom; 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); 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, bool legacy_crtc_move_cursor(struct wlr_drm_backend *backend,
int x, int y); 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, static bool atomic_crtc_move_cursor(struct wlr_drm_backend *backend,
int x, int y) { struct wlr_drm_crtc *crtc, int x, int y) {
struct wlr_drm_plane *plane = crtc->cursor; struct wlr_drm_plane *plane = crtc->cursor;
// We can't use atomic operations on fake planes // We can't use atomic operations on fake planes
if (plane->id == 0) { 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; 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_begin(crtc, &atom);
atomic_add(&atom, plane->id, plane->props.crtc_x, x); atomic_add(&atom, plane->id, plane->props.crtc_x, x);
atomic_add(&atom, plane->id, plane->props.crtc_y, y); 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 = { const struct wlr_drm_interface atomic_iface = {

View File

@ -5,38 +5,39 @@
#include "backend/drm.h" #include "backend/drm.h"
#include "backend/drm-util.h" #include "backend/drm-util.h"
static bool legacy_crtc_pageflip(struct wlr_backend_state *drm, struct wlr_output_state *output, static bool legacy_crtc_pageflip(struct wlr_drm_backend *backend,
struct wlr_drm_crtc *crtc, uint32_t fb_id, drmModeModeInfo *mode) { struct wlr_output_state *output, struct wlr_drm_crtc *crtc,
uint32_t fb_id, drmModeModeInfo *mode) {
if (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); &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; return true;
} }
static void legacy_conn_enable(struct wlr_backend_state *drm, struct wlr_output_state *output, static void legacy_conn_enable(struct wlr_drm_backend *backend,
bool enable) { struct wlr_output_state *output, bool enable) {
drmModeConnectorSetProperty(drm->fd, output->connector, output->props.dpms, drmModeConnectorSetProperty(backend->fd, output->connector, output->props.dpms,
enable ? DRM_MODE_DPMS_ON : DRM_MODE_DPMS_OFF); enable ? DRM_MODE_DPMS_ON : DRM_MODE_DPMS_OFF);
} }
bool legacy_crtc_set_cursor(struct wlr_backend_state *drm, struct wlr_drm_crtc *crtc, bool legacy_crtc_set_cursor(struct wlr_drm_backend *backend,
struct gbm_bo *bo) { struct wlr_drm_crtc *crtc, struct gbm_bo *bo) {
if (!crtc || !crtc->cursor) { if (!crtc || !crtc->cursor) {
return true; return true;
} }
if (!bo) { if (!bo) {
drmModeSetCursor(drm->fd, crtc->id, 0, 0, 0); drmModeSetCursor(backend->fd, crtc->id, 0, 0, 0);
return true; return true;
} }
struct wlr_drm_plane *plane = crtc->cursor; 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)) { plane->width, plane->height)) {
wlr_log_errno(L_ERROR, "Failed to set hardware cursor"); wlr_log_errno(L_ERROR, "Failed to set hardware cursor");
return false; return false;
@ -45,9 +46,9 @@ bool legacy_crtc_set_cursor(struct wlr_backend_state *drm, struct wlr_drm_crtc *
return true; return true;
} }
bool legacy_crtc_move_cursor(struct wlr_backend_state *drm, struct wlr_drm_crtc *crtc, bool legacy_crtc_move_cursor(struct wlr_drm_backend *backend,
int x, int y) { struct wlr_drm_crtc *crtc, int x, int y) {
return !drmModeMoveCursor(drm->fd, crtc->id, x, y); return !drmModeMoveCursor(backend->fd, crtc->id, x, y);
} }
const struct wlr_drm_interface legacy_iface = { const struct wlr_drm_interface legacy_iface = {

View File

@ -22,21 +22,21 @@
#include "backend/drm.h" #include "backend/drm.h"
#include "backend/drm-util.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 legacy_iface;
extern const struct wlr_drm_interface atomic_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"); wlr_log(L_ERROR, "DRM universal planes unsupported");
return false; 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"); wlr_log(L_DEBUG, "Atomic modesetting unsupported, using legacy DRM interface");
drm->iface = &legacy_iface; backend->iface = &legacy_iface;
} else { } else {
wlr_log(L_DEBUG, "Using atomic DRM interface"); wlr_log(L_DEBUG, "Using atomic DRM interface");
drm->iface = &atomic_iface; backend->iface = &atomic_iface;
} }
return true; return true;
@ -49,8 +49,8 @@ static int cmp_plane(const void *arg1, const void *arg2) {
return (int)a->type - (int)b->type; return (int)a->type - (int)b->type;
} }
static bool init_planes(struct wlr_backend_state *drm) { static bool init_planes(struct wlr_drm_backend *backend) {
drmModePlaneRes *plane_res = drmModeGetPlaneResources(drm->fd); drmModePlaneRes *plane_res = drmModeGetPlaneResources(backend->fd);
if (!plane_res) { if (!plane_res) {
wlr_log_errno(L_ERROR, "Failed to get DRM plane resources"); wlr_log_errno(L_ERROR, "Failed to get DRM plane resources");
return false; return false;
@ -63,17 +63,17 @@ static bool init_planes(struct wlr_backend_state *drm) {
return true; return true;
} }
drm->num_planes = plane_res->count_planes; backend->num_planes = plane_res->count_planes;
drm->planes = calloc(drm->num_planes, sizeof(*drm->planes)); backend->planes = calloc(backend->num_planes, sizeof(*backend->planes));
if (!drm->planes) { if (!backend->planes) {
wlr_log_errno(L_ERROR, "Allocation failed"); wlr_log_errno(L_ERROR, "Allocation failed");
goto error_res; goto error_res;
} }
for (size_t i = 0; i < drm->num_planes; ++i) { for (size_t i = 0; i < backend->num_planes; ++i) {
struct wlr_drm_plane *p = &drm->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) { if (!plane) {
wlr_log_errno(L_ERROR, "Failed to get DRM plane"); wlr_log_errno(L_ERROR, "Failed to get DRM plane");
goto error_planes; goto error_planes;
@ -83,39 +83,44 @@ static bool init_planes(struct wlr_backend_state *drm) {
p->possible_crtcs = plane->possible_crtcs; p->possible_crtcs = plane->possible_crtcs;
uint64_t type; uint64_t type;
if (!wlr_drm_get_plane_props(drm->fd, p->id, &p->props) || if (!wlr_drm_get_plane_props(backend->fd, p->id, &p->props) ||
!wlr_drm_get_prop(drm->fd, p->id, p->props.type, &type)) { !wlr_drm_get_prop(backend->fd, p->id, p->props.type, &type)) {
drmModeFreePlane(plane); drmModeFreePlane(plane);
goto error_planes; goto error_planes;
} }
p->type = type; p->type = type;
drm->num_type_planes[type]++; backend->num_type_planes[type]++;
drmModeFreePlane(plane); drmModeFreePlane(plane);
} }
wlr_log(L_INFO, "(%zu overlay, %zu primary, %zu cursor)", 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; backend->overlay_planes = backend->planes;
drm->primary_planes = drm->overlay_planes + drm->num_overlay_planes; backend->primary_planes = backend->overlay_planes
drm->cursor_planes = drm->primary_planes + drm->num_primary_planes; + backend->num_overlay_planes;
backend->cursor_planes = backend->primary_planes
+ backend->num_primary_planes;
drmModeFreePlaneResources(plane_res); drmModeFreePlaneResources(plane_res);
return true; return true;
error_planes: error_planes:
free(drm->planes); free(backend->planes);
error_res: error_res:
drmModeFreePlaneResources(plane_res); drmModeFreePlaneResources(plane_res);
return false; return false;
} }
bool wlr_drm_resources_init(struct wlr_backend_state *drm) { bool wlr_drm_resources_init(struct wlr_drm_backend *backend) {
drmModeRes *res = drmModeGetResources(drm->fd); drmModeRes *res = drmModeGetResources(backend->fd);
if (!res) { if (!res) {
wlr_log_errno(L_ERROR, "Failed to get DRM resources"); wlr_log_errno(L_ERROR, "Failed to get DRM resources");
return false; 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); wlr_log(L_INFO, "Found %d DRM CRTCs", res->count_crtcs);
drm->num_crtcs = res->count_crtcs; backend->num_crtcs = res->count_crtcs;
drm->crtcs = calloc(drm->num_crtcs, sizeof(drm->crtcs[0])); backend->crtcs = calloc(backend->num_crtcs, sizeof(backend->crtcs[0]));
if (!drm->crtcs) { if (!backend->crtcs) {
wlr_log_errno(L_ERROR, "Allocation failed"); wlr_log_errno(L_ERROR, "Allocation failed");
goto error_res; goto error_res;
} }
for (size_t i = 0; i < drm->num_crtcs; ++i) { for (size_t i = 0; i < backend->num_crtcs; ++i) {
struct wlr_drm_crtc *crtc = &drm->crtcs[i]; struct wlr_drm_crtc *crtc = &backend->crtcs[i];
crtc->id = res->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; goto error_crtcs;
} }
@ -145,28 +150,25 @@ bool wlr_drm_resources_init(struct wlr_backend_state *drm) {
return true; return true;
error_crtcs: error_crtcs:
free(drm->crtcs); free(backend->crtcs);
error_res: error_res:
drmModeFreeResources(res); drmModeFreeResources(res);
return false; return false;
} }
void wlr_drm_resources_free(struct wlr_backend_state *drm) { void wlr_drm_resources_free(struct wlr_drm_backend *backend) {
if (!drm) { if (!backend) {
return; return;
} }
for (size_t i = 0; i < backend->num_crtcs; ++i) {
for (size_t i = 0; i < drm->num_crtcs; ++i) { struct wlr_drm_crtc *crtc = &backend->crtcs[i];
struct wlr_drm_crtc *crtc = &drm->crtcs[i];
drmModeAtomicFree(crtc->atomic); drmModeAtomicFree(crtc->atomic);
if (crtc->mode_id) { if (crtc->mode_id) {
drmModeDestroyPropertyBlob(drm->fd, crtc->mode_id); drmModeDestroyPropertyBlob(backend->fd, crtc->mode_id);
} }
} }
free(backend->crtcs);
free(drm->crtcs); free(backend->planes);
free(drm->planes);
} }
bool wlr_drm_renderer_init(struct wlr_drm_renderer *renderer, int fd) { 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) { 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_renderer *renderer = output->renderer;
struct wlr_drm_crtc *crtc = output->crtc; struct wlr_drm_crtc *crtc = output->crtc;
struct wlr_drm_plane *plane = crtc->primary; struct wlr_drm_plane *plane = crtc->primary;
wlr_drm_plane_swap_buffers(renderer, plane); 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; output->pageflip_pending = true;
} }
@ -301,7 +304,8 @@ void wlr_drm_output_start_renderer(struct wlr_output_state *output) {
return; 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_renderer *renderer = output->renderer;
struct wlr_drm_crtc *crtc = output->crtc; struct wlr_drm_crtc *crtc = output->crtc;
struct wlr_drm_plane *plane = crtc->primary; 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; 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; output->pageflip_pending = true;
} }
static void wlr_drm_output_enable(struct wlr_output_state *output, bool enable) { static void wlr_drm_output_enable(struct wlr_output_state *output, bool enable) {
struct wlr_backend_state *drm = struct wlr_drm_backend *backend =
wl_container_of(output->renderer, drm, renderer); wl_container_of(output->renderer, backend, renderer);
if (output->state != WLR_DRM_OUTPUT_CONNECTED) { if (output->state != WLR_DRM_OUTPUT_CONNECTED) {
return; return;
} }
drm->iface->conn_enable(drm, output, enable); backend->iface->conn_enable(backend, output, enable);
if (enable) { if (enable) {
wlr_drm_output_start_renderer(output); 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 // overlay, primary, cursor
for (int type = 0; type < 3; ++type) { for (int type = 0; type < 3; ++type) {
if (drm->num_type_planes[type] == 0) { if (backend->num_type_planes[type] == 0) {
continue; continue;
} }
uint32_t possible[drm->num_type_planes[type]]; uint32_t possible[backend->num_type_planes[type]];
uint32_t crtc[drm->num_crtcs]; uint32_t crtc[backend->num_crtcs];
uint32_t crtc_res[drm->num_crtcs]; uint32_t crtc_res[backend->num_crtcs];
for (size_t i = 0; i < drm->num_type_planes[type]; ++i) { for (size_t i = 0; i < backend->num_type_planes[type]; ++i) {
possible[i] = drm->type_planes[type][i].possible_crtcs; 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) { if (crtc_in[i] == UNMATCHED) {
crtc[i] = SKIP; crtc[i] = SKIP;
} else if (drm->crtcs[i].planes[type]) { } else if (backend->crtcs[i].planes[type]) {
crtc[i] = drm->crtcs[i].planes[type] - drm->type_planes[type]; crtc[i] = backend->crtcs[i].planes[type]
- backend->type_planes[type];
} else { } else {
crtc[i] = UNMATCHED; 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) { if (crtc_res[i] == UNMATCHED || crtc_res[i] == SKIP) {
continue; 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 **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) { if (*old != new) {
wlr_drm_plane_renderer_free(&drm->renderer, *old); wlr_drm_plane_renderer_free(&backend->renderer, *old);
wlr_drm_plane_renderer_free(&drm->renderer, new); wlr_drm_plane_renderer_free(&backend->renderer, new);
*old = new; *old = new;
} }
} }
} }
} }
static void realloc_crtcs(struct wlr_backend_state *drm, struct wlr_output_state *output) { static void realloc_crtcs(struct wlr_drm_backend *backend,
uint32_t crtc[drm->num_crtcs]; struct wlr_output_state *output) {
uint32_t crtc_res[drm->num_crtcs]; uint32_t crtc[backend->num_crtcs];
uint32_t possible_crtc[drm->outputs->length]; 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; crtc[i] = UNMATCHED;
} }
memset(possible_crtc, 0, sizeof(possible_crtc)); memset(possible_crtc, 0, sizeof(possible_crtc));
size_t index; size_t index;
for (size_t i = 0; i < drm->outputs->length; ++i) { for (size_t i = 0; i < backend->outputs->length; ++i) {
struct wlr_output_state *o = drm->outputs->items[i]; struct wlr_output_state *o = backend->outputs->items[i];
if (o == output) { if (o == output) {
index = i; 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; possible_crtc[i] = o->possible_crtc;
crtc[o->crtc - drm->crtcs] = i; crtc[o->crtc - backend->crtcs] = i;
} }
possible_crtc[index] = output->possible_crtc; 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; 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. // We don't want any of the current monitors to be deactivated.
if (crtc[i] != UNMATCHED && crtc_res[i] == UNMATCHED) { if (crtc[i] != UNMATCHED && crtc_res[i] == UNMATCHED) {
return; return;
@ -427,28 +435,29 @@ static void realloc_crtcs(struct wlr_backend_state *drm, struct wlr_output_state
return; 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) { if (crtc_res[i] == UNMATCHED) {
continue; continue;
} }
if (crtc_res[i] != crtc[i]) { if (crtc_res[i] != crtc[i]) {
struct wlr_output_state *o = drm->outputs->items[crtc_res[i]]; struct wlr_output_state *o = backend->outputs->items[crtc_res[i]];
o->crtc = &drm->crtcs[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, static bool wlr_drm_output_set_mode(struct wlr_output_state *output,
struct wlr_output_mode *mode) { 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, wlr_log(L_INFO, "Modesetting '%s' with '%ux%u@%u mHz'", output->base->name,
mode->width, mode->height, mode->refresh); mode->width, mode->height, mode->refresh);
drmModeConnector *conn = drmModeGetConnector(drm->fd, output->connector); drmModeConnector *conn = drmModeGetConnector(backend->fd, output->connector);
if (!conn) { if (!conn) {
wlr_log_errno(L_ERROR, "Failed to get DRM connector"); wlr_log_errno(L_ERROR, "Failed to get DRM connector");
goto error_output; goto error_output;
@ -461,7 +470,7 @@ static bool wlr_drm_output_set_mode(struct wlr_output_state *output,
drmModeEncoder *enc = NULL; drmModeEncoder *enc = NULL;
for (int i = 0; !enc && i < conn->count_encoders; ++i) { 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) { if (!enc) {
@ -470,7 +479,7 @@ static bool wlr_drm_output_set_mode(struct wlr_output_state *output,
} }
output->possible_crtc = enc->possible_crtcs; output->possible_crtc = enc->possible_crtcs;
realloc_crtcs(drm, output); realloc_crtcs(backend, output);
if (!output->crtc) { if (!output->crtc) {
wlr_log(L_ERROR, "Unable to match %s with a CRTC", output->base->name); 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; struct wlr_drm_crtc *crtc = output->crtc;
wlr_log(L_DEBUG, "%s: crtc=%ju ovr=%jd pri=%jd cur=%jd", output->base->name, wlr_log(L_DEBUG, "%s: crtc=%ju ovr=%jd pri=%jd cur=%jd", output->base->name,
crtc - drm->crtcs, crtc - backend->crtcs,
crtc->overlay ? crtc->overlay - drm->overlay_planes : -1, crtc->overlay ? crtc->overlay - backend->overlay_planes : -1,
crtc->primary ? crtc->primary - drm->primary_planes : -1, crtc->primary ? crtc->primary - backend->primary_planes : -1,
crtc->cursor ? crtc->cursor - drm->cursor_planes : -1); crtc->cursor ? crtc->cursor - backend->cursor_planes : -1);
output->state = WLR_DRM_OUTPUT_CONNECTED; output->state = WLR_DRM_OUTPUT_CONNECTED;
output->width = output->base->width = mode->width; 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, // Since realloc_crtcs can deallocate planes on OTHER outputs,
// we actually need to reinitalise all of them // we actually need to reinitalise all of them
for (size_t i = 0; i < drm->outputs->length; ++i) { for (size_t i = 0; i < backend->outputs->length; ++i) {
struct wlr_output_state *output = drm->outputs->items[i]; struct wlr_output_state *output = backend->outputs->items[i];
struct wlr_output_mode *mode = output->base->current_mode; struct wlr_output_mode *mode = output->base->current_mode;
struct wlr_drm_crtc *crtc = output->crtc; struct wlr_drm_crtc *crtc = output->crtc;
@ -501,7 +510,7 @@ static bool wlr_drm_output_set_mode(struct wlr_output_state *output,
continue; 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, mode->width, mode->height, GBM_FORMAT_XRGB8888,
GBM_BO_USE_SCANOUT)) { GBM_BO_USE_SCANOUT)) {
wlr_log(L_ERROR, "Failed to initalise renderer for plane"); 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, 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) { 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_renderer *renderer = output->renderer;
struct wlr_drm_crtc *crtc = output->crtc; struct wlr_drm_crtc *crtc = output->crtc;
struct wlr_drm_plane *plane = crtc->cursor; struct wlr_drm_plane *plane = crtc->cursor;
if (!buf) { 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 // 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) { if (!plane->gbm) {
int ret; int ret;
uint64_t w, h; 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; 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; h = ret ? 64 : h;
if (width > w || height > 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, wlr_matrix_texture(plane->matrix, plane->width, plane->height,
output->base->transform ^ WL_OUTPUT_TRANSFORM_FLIPPED_180); 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) { if (!plane->wlr_rend) {
return false; return false;
} }
@ -625,14 +635,14 @@ static bool wlr_drm_output_set_cursor(struct wlr_output_state *output,
gbm_bo_unmap(bo, bo_data); 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, static bool wlr_drm_output_move_cursor(struct wlr_output_state *output,
int x, int y) { int x, int y) {
struct wlr_backend_state *drm = struct wlr_drm_backend *backend =
wl_container_of(output->renderer, drm, renderer); wl_container_of(output->renderer, backend, renderer);
return drm->iface->crtc_move_cursor(drm, output->crtc, x, y); return backend->iface->crtc_move_cursor(backend, output->crtc, x, y);
} }
static void wlr_drm_output_destroy(struct wlr_output_state *output) { 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, [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"); wlr_log(L_INFO, "Scanning DRM connectors");
drmModeRes *res = drmModeGetResources(drm->fd); drmModeRes *res = drmModeGetResources(backend->fd);
if (!res) { if (!res) {
wlr_log_errno(L_ERROR, "Failed to get DRM resources"); wlr_log_errno(L_ERROR, "Failed to get DRM resources");
return; return;
} }
for (int i = 0; i < res->count_connectors; ++i) { for (int i = 0; i < res->count_connectors; ++i) {
drmModeConnector *conn = drmModeGetConnector(drm->fd, drmModeConnector *conn = drmModeGetConnector(backend->fd,
res->connectors[i]); res->connectors[i]);
if (!conn) { if (!conn) {
wlr_log_errno(L_ERROR, "Failed to get DRM connector"); 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; 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) { if (index == -1) {
output = calloc(1, sizeof(*output)); output = calloc(1, sizeof(*output));
@ -709,13 +719,14 @@ void wlr_drm_scan_connectors(struct wlr_backend_state *drm) {
continue; continue;
} }
output->renderer = &drm->renderer; output->renderer = &backend->renderer;
output->state = WLR_DRM_OUTPUT_DISCONNECTED; output->state = WLR_DRM_OUTPUT_DISCONNECTED;
output->connector = conn->connector_id; 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) { 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); drmModeFreeEncoder(curr_enc);
} }
@ -726,19 +737,20 @@ void wlr_drm_scan_connectors(struct wlr_backend_state *drm) {
conn_get_name(conn->connector_type), conn_get_name(conn->connector_type),
conn->connector_type_id); 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; size_t edid_len = 0;
uint8_t *edid = wlr_drm_get_prop_blob(drm->fd, output->connector, uint8_t *edid = wlr_drm_get_prop_blob(backend->fd,
output->props.edid, &edid_len); output->connector, output->props.edid, &edid_len);
parse_edid(output->base, edid_len, edid); parse_edid(output->base, edid_len, edid);
free(edid); free(edid);
wlr_output_create_global(output->base, drm->display); wlr_output_create_global(output->base, backend->display);
list_add(drm->outputs, output); list_add(backend->outputs, output);
wlr_log(L_INFO, "Found display '%s'", output->base->name); wlr_log(L_INFO, "Found display '%s'", output->base->name);
} else { } else {
output = drm->outputs->items[index]; output = backend->outputs->items[index];
} }
if (output->state == WLR_DRM_OUTPUT_DISCONNECTED && 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; output->state = WLR_DRM_OUTPUT_NEEDS_MODESET;
wlr_log(L_INFO, "Sending modesetting signal for '%s'", output->base->name); 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 && } else if (output->state == WLR_DRM_OUTPUT_CONNECTED &&
conn->connection != DRM_MODE_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, static void page_flip_handler(int fd, unsigned seq,
unsigned tv_sec, unsigned tv_usec, void *user) { unsigned tv_sec, unsigned tv_usec, void *user) {
struct wlr_output_state *output = user; struct wlr_output_state *output = user;
struct wlr_backend_state *drm = struct wlr_drm_backend *backend =
wl_container_of(output->renderer, drm, renderer); wl_container_of(output->renderer, backend, renderer);
output->pageflip_pending = false; output->pageflip_pending = false;
if (output->state != WLR_DRM_OUTPUT_CONNECTED) { if (output->state != WLR_DRM_OUTPUT_CONNECTED) {
@ -797,7 +809,7 @@ static void page_flip_handler(int fd, unsigned seq,
plane->front = NULL; plane->front = NULL;
} }
if (drm->session->active) { if (backend->session->active) {
wl_signal_emit(&output->base->events.frame, output->base); 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_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) { switch (output->state) {
case WLR_DRM_OUTPUT_CONNECTED: case WLR_DRM_OUTPUT_CONNECTED:
@ -861,8 +874,9 @@ void wlr_drm_output_cleanup(struct wlr_output_state *output, bool restore) {
if (restore) { if (restore) {
restore_output(output, renderer->fd); restore_output(output, renderer->fd);
} }
wlr_log(L_INFO, "Emmiting destruction signal for '%s'", output->base->name); wlr_log(L_INFO, "Emmiting destruction signal for '%s'",
wl_signal_emit(&drm->base->events.output_remove, output->base); output->base->name);
wl_signal_emit(&backend->backend.events.output_remove, output->base);
break; break;
case WLR_DRM_OUTPUT_DISCONNECTED: case WLR_DRM_OUTPUT_DISCONNECTED:
break; break;

View File

@ -4,12 +4,12 @@ backend_files = files(
'session/direct-ipc.c', 'session/direct-ipc.c',
'session/direct.c', 'session/direct.c',
'session/session.c', 'session/session.c',
#'drm/backend.c', 'drm/backend.c',
#'drm/drm.c', 'drm/drm.c',
#'drm/drm-atomic.c', 'drm/drm-atomic.c',
#'drm/drm-legacy.c', 'drm/drm-legacy.c',
#'drm/drm-properties.c', 'drm/drm-properties.c',
#'drm/drm-util.c', 'drm/drm-util.c',
'libinput/backend.c', 'libinput/backend.c',
'libinput/events.c', 'libinput/events.c',
'libinput/keyboard.c', 'libinput/keyboard.c',

View File

@ -81,7 +81,7 @@ void wlr_drm_renderer_free(struct wlr_drm_renderer *renderer);
struct wlr_drm_interface; struct wlr_drm_interface;
struct wlr_drm_backend_state { struct wlr_drm_backend {
struct wlr_backend backend; struct wlr_backend backend;
const struct wlr_drm_interface *iface; const struct wlr_drm_interface *iface;
@ -160,25 +160,26 @@ struct wlr_output_state {
// Used to provide atomic or legacy DRM functions // Used to provide atomic or legacy DRM functions
struct wlr_drm_interface { struct wlr_drm_interface {
// Enable or disable DPMS for output // Enable or disable DPMS for output
void (*conn_enable)(struct wlr_backend_state *drm, struct wlr_output_state *output, void (*conn_enable)(struct wlr_drm_backend *backend,
bool enable); struct wlr_output_state *output, bool enable);
// Pageflip on crtc. If mode is non-NULL perform a full modeset using it. // 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, bool (*crtc_pageflip)(struct wlr_drm_backend *backend,
struct wlr_drm_crtc *crtc, uint32_t fb_id, drmModeModeInfo *mode); 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 // 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, bool (*crtc_set_cursor)(struct wlr_drm_backend *backend,
struct gbm_bo *bo); struct wlr_drm_crtc *crtc, struct gbm_bo *bo);
// Move the cursor on crtc // Move the cursor on crtc
bool (*crtc_move_cursor)(struct wlr_backend_state *drm, struct wlr_drm_crtc *crtc, bool (*crtc_move_cursor)(struct wlr_drm_backend *backend,
int x, int y); struct wlr_drm_crtc *crtc, int x, int y);
}; };
bool wlr_drm_check_features(struct wlr_backend_state *drm); bool wlr_drm_check_features(struct wlr_drm_backend *drm);
bool wlr_drm_resources_init(struct wlr_backend_state *drm); bool wlr_drm_resources_init(struct wlr_drm_backend *drm);
void wlr_drm_resources_free(struct wlr_backend_state *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_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); int wlr_drm_event(int fd, uint32_t mask, void *data);
void wlr_drm_output_start_renderer(struct wlr_output_state *output); void wlr_drm_output_start_renderer(struct wlr_output_state *output);