Atomic modesetting

This commit is contained in:
Scott Anderson 2017-08-09 20:43:01 +12:00 committed by Drew DeVault
parent 913829e381
commit af67966d92
11 changed files with 350 additions and 72 deletions

View file

@ -53,7 +53,11 @@ static void session_signal(struct wl_listener *listener, void *data) {
for (size_t i = 0; i < drm->outputs->length; ++i) { for (size_t i = 0; i < drm->outputs->length; ++i) {
struct wlr_output_state *output = drm->outputs->items[i]; struct wlr_output_state *output = drm->outputs->items[i];
wlr_drm_output_start_renderer(output); wlr_drm_output_start_renderer(output);
wlr_drm_crtc_set_cursor(drm, output->crtc);
struct wlr_drm_plane *plane = output->crtc->cursor;
drm->iface->crtc_set_cursor(drm, output->crtc,
plane ? plane->cursor_bo : NULL);
} }
} else { } else {
wlr_log(L_INFO, "DRM fd paused"); wlr_log(L_INFO, "DRM fd paused");

176
backend/drm/drm-atomic.c Normal file
View file

@ -0,0 +1,176 @@
#include <gbm.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
#include <wlr/util/log.h>
#include "backend/drm.h"
#include "backend/drm-util.h"
struct atomic {
drmModeAtomicReq *req;
int cursor;
bool failed;
};
static void atomic_begin(struct wlr_drm_crtc *crtc, struct atomic *atom) {
if (!crtc->atomic) {
crtc->atomic = drmModeAtomicAlloc();
if (!crtc->atomic) {
wlr_log_errno(L_ERROR, "Allocation failed");
atom->failed = true;
return;
}
}
atom->req = crtc->atomic;
atom->cursor = drmModeAtomicGetCursor(atom->req);
atom->failed = false;
}
static bool atomic_end(int drm_fd, struct atomic *atom) {
if (atom->failed) {
return false;
}
uint32_t flags = DRM_MODE_ATOMIC_TEST_ONLY | DRM_MODE_ATOMIC_NONBLOCK;
if (drmModeAtomicCommit(drm_fd, atom->req, flags, NULL)) {
wlr_log_errno(L_ERROR, "Atomic test failed");
drmModeAtomicSetCursor(atom->req, atom->cursor);
return false;
}
return true;
}
static bool atomic_commit(int drm_fd, struct atomic *atom, struct wlr_output_state *output,
uint32_t flag) {
if (atom->failed) {
return false;
}
uint32_t flags = DRM_MODE_PAGE_FLIP_EVENT | DRM_MODE_ATOMIC_NONBLOCK | flag;
int ret = drmModeAtomicCommit(drm_fd, atom->req, flags, output);
if (ret) {
wlr_log_errno(L_ERROR, "Atomic commit failed");
}
drmModeAtomicSetCursor(atom->req, 0);
return !ret;
}
static inline void atomic_add(struct atomic *atom, uint32_t id, uint32_t prop, uint64_t val) {
if (!atom->failed && drmModeAtomicAddProperty(atom->req, id, prop, val) < 0) {
wlr_log_errno(L_ERROR, "Failed to add atomic DRM property");
atom->failed = true;
}
}
static void set_plane_props(struct atomic *atom, struct wlr_drm_plane *plane,
uint32_t crtc_id, uint32_t fb_id, bool set_crtc_xy) {
uint32_t id = plane->id;
const union wlr_drm_plane_props *props = &plane->props;
// The src_* properties are in 16.16 fixed point
atomic_add(atom, id, props->src_x, 0);
atomic_add(atom, id, props->src_y, 0);
atomic_add(atom, id, props->src_w, plane->width << 16);
atomic_add(atom, id, props->src_h, plane->height << 16);
atomic_add(atom, id, props->crtc_w, plane->width);
atomic_add(atom, id, props->crtc_h, plane->height);
atomic_add(atom, id, props->fb_id, fb_id);
atomic_add(atom, id, props->crtc_id, crtc_id);
if (set_crtc_xy) {
atomic_add(atom, id, props->crtc_x, 0);
atomic_add(atom, id, props->crtc_y, 0);
}
}
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) {
if (mode) {
if (crtc->mode_id) {
drmModeDestroyPropertyBlob(drm->fd, crtc->mode_id);
}
if (drmModeCreatePropertyBlob(drm->fd, mode, sizeof(*mode), &crtc->mode_id)) {
wlr_log_errno(L_ERROR, "Unable to create property blob");
return false;
}
}
struct atomic atom;
atomic_begin(crtc, &atom);
atomic_add(&atom, output->connector, output->props.crtc_id, crtc->id);
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);
}
static void atomic_conn_enable(struct wlr_backend_state *drm, 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);
}
bool legacy_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_backend_state *drm, struct wlr_drm_crtc *crtc,
struct gbm_bo *bo) {
if (!crtc || !crtc->cursor) {
return true;
}
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);
}
struct atomic atom;
atomic_begin(crtc, &atom);
if (bo) {
set_plane_props(&atom, plane, crtc->id, get_fb_for_bo(bo), false);
} else {
atomic_add(&atom, plane->id, plane->props.fb_id, 0);
atomic_add(&atom, plane->id, plane->props.crtc_id, 0);
}
return atomic_end(drm->fd, &atom);
}
bool legacy_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_backend_state *drm, 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);
}
struct atomic atom;
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);
}
const struct wlr_drm_interface atomic_iface = {
.conn_enable = atomic_conn_enable,
.crtc_pageflip = atomic_crtc_pageflip,
.crtc_set_cursor = atomic_crtc_set_cursor,
.crtc_move_cursor = atomic_crtc_move_cursor,
};

58
backend/drm/drm-legacy.c Normal file
View file

@ -0,0 +1,58 @@
#include <gbm.h>
#include <xf86drm.h>
#include <xf86drmMode.h>
#include <wlr/util/log.h>
#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) {
if (mode) {
drmModeSetCrtc(drm->fd, crtc->id, fb_id, 0, 0,
&output->connector, 1, mode);
}
drmModePageFlip(drm->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,
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) {
if (!crtc || !crtc->cursor) {
return true;
}
if (!bo) {
drmModeSetCursor(drm->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,
plane->width, plane->height)) {
wlr_log_errno(L_ERROR, "Failed to set hardware cursor");
return false;
}
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);
}
const struct wlr_drm_interface legacy_iface = {
.conn_enable = legacy_conn_enable,
.crtc_pageflip = legacy_crtc_pageflip,
.crtc_set_cursor = legacy_crtc_set_cursor,
.crtc_move_cursor = legacy_crtc_move_cursor,
};

View file

@ -27,6 +27,8 @@ static const struct prop_info connector_info[] = {
static const struct prop_info crtc_info[] = { static const struct prop_info crtc_info[] = {
#define INDEX(name) (offsetof(union wlr_drm_crtc_props, name) / sizeof(uint32_t)) #define INDEX(name) (offsetof(union wlr_drm_crtc_props, name) / sizeof(uint32_t))
{ "ACTIVE", INDEX(active) },
{ "MODE_ID", INDEX(mode_id) },
{ "rotation", INDEX(rotation) }, { "rotation", INDEX(rotation) },
{ "scaling mode", INDEX(scaling_mode) }, { "scaling mode", INDEX(scaling_mode) },
#undef INDEX #undef INDEX

View file

@ -2,7 +2,9 @@
#include <string.h> #include <string.h>
#include <drm.h> #include <drm.h>
#include <drm_mode.h> #include <drm_mode.h>
#include <gbm.h>
#include "backend/drm-util.h" #include "backend/drm-util.h"
#include <wlr/util/log.h>
int32_t calculate_refresh_rate(drmModeModeInfo *mode) { int32_t calculate_refresh_rate(drmModeModeInfo *mode) {
int32_t refresh = (mode->clock * 1000000LL / mode->htotal + int32_t refresh = (mode->clock * 1000000LL / mode->htotal +
@ -133,6 +135,40 @@ const char *conn_get_name(uint32_t type_id) {
} }
} }
static void free_fb(struct gbm_bo *bo, void *data) {
uint32_t id = (uintptr_t)data;
if (id) {
struct gbm_device *gbm = gbm_bo_get_device(bo);
drmModeRmFB(gbm_device_get_fd(gbm), id);
}
}
uint32_t get_fb_for_bo(struct gbm_bo *bo) {
uint32_t id = (uintptr_t)gbm_bo_get_user_data(bo);
if (id) {
return id;
}
struct gbm_device *gbm = gbm_bo_get_device(bo);
int fd = gbm_device_get_fd(gbm);
uint32_t width = gbm_bo_get_width(bo);
uint32_t height = gbm_bo_get_height(bo);
uint32_t handles[4] = {gbm_bo_get_handle(bo).u32};
uint32_t pitches[4] = {gbm_bo_get_stride(bo)};
uint32_t offsets[4] = {gbm_bo_get_offset(bo, 0)};
uint32_t format = gbm_bo_get_format(bo);
if (drmModeAddFB2(fd, width, height, format, handles, pitches, offsets, &id, 0)) {
wlr_log_errno(L_ERROR, "Unable to add DRM framebuffer");
}
gbm_bo_set_user_data(bo, (void *)(uintptr_t)id, free_fb);
return id;
}
static inline bool is_taken(size_t n, const uint32_t arr[static n], uint32_t key) { static inline bool is_taken(size_t n, const uint32_t arr[static n], uint32_t key) {
for (size_t i = 0; i < n; ++i) { for (size_t i = 0; i < n; ++i) {
if (arr[i] == key) { if (arr[i] == key) {

View file

@ -23,28 +23,33 @@
#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_backend_state *drm) {
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(drm->fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1)) {
wlr_log(L_INFO, "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(drm->fd, DRM_CLIENT_CAP_ATOMIC, 1)) {
wlr_log(L_INFO, "Atomic modesetting unsupported"); wlr_log(L_DEBUG, "Atomic modesetting unsupported, using legacy DRM interface");
drm->iface = &legacy_iface;
} else {
wlr_log(L_DEBUG, "Using atomic DRM interface");
drm->iface = &atomic_iface;
} }
return true; return true;
} }
static int cmp_plane(const void *arg1, const void *arg2) static int cmp_plane(const void *arg1, const void *arg2) {
{
const struct wlr_drm_plane *a = arg1; const struct wlr_drm_plane *a = arg1;
const struct wlr_drm_plane *b = arg2; const struct wlr_drm_plane *b = 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_backend_state *drm) {
{
drmModePlaneRes *plane_res = drmModeGetPlaneResources(drm->fd); drmModePlaneRes *plane_res = drmModeGetPlaneResources(drm->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");
@ -150,6 +155,15 @@ void wlr_drm_resources_free(struct wlr_backend_state *drm) {
return; return;
} }
for (size_t i = 0; i < drm->num_crtcs; ++i) {
struct wlr_drm_crtc *crtc = &drm->crtcs[i];
drmModeAtomicFree(crtc->atomic);
if (crtc->mode_id) {
drmModeDestroyPropertyBlob(drm->fd, crtc->mode_id);
}
}
free(drm->crtcs); free(drm->crtcs);
free(drm->planes); free(drm->planes);
} }
@ -180,7 +194,7 @@ void wlr_drm_renderer_free(struct wlr_drm_renderer *renderer) {
} }
static bool wlr_drm_plane_renderer_init(struct wlr_drm_renderer *renderer, static bool wlr_drm_plane_renderer_init(struct wlr_drm_renderer *renderer,
struct wlr_drm_plane *plane, uint32_t width, uint32_t height, uint32_t flags) { struct wlr_drm_plane *plane, uint32_t width, uint32_t height, uint32_t format, uint32_t flags) {
if (plane->width == width && plane->height == height) { if (plane->width == width && plane->height == height) {
return true; return true;
} }
@ -189,7 +203,7 @@ static bool wlr_drm_plane_renderer_init(struct wlr_drm_renderer *renderer,
plane->height = height; plane->height = height;
plane->gbm = gbm_surface_create(renderer->gbm, width, height, plane->gbm = gbm_surface_create(renderer->gbm, width, height,
GBM_FORMAT_ARGB8888, GBM_BO_USE_RENDERING | flags); format, GBM_BO_USE_RENDERING | flags);
if (!plane->gbm) { if (!plane->gbm) {
wlr_log_errno(L_ERROR, "Failed to create GBM surface for plane"); wlr_log_errno(L_ERROR, "Failed to create GBM surface for plane");
return false; return false;
@ -210,6 +224,8 @@ static void wlr_drm_plane_renderer_free(struct wlr_drm_renderer *renderer,
return; return;
} }
eglMakeCurrent(renderer->egl.display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
if (plane->front) { if (plane->front) {
gbm_surface_release_buffer(plane->gbm, plane->front); gbm_surface_release_buffer(plane->gbm, plane->front);
} }
@ -245,30 +261,6 @@ static void wlr_drm_plane_renderer_free(struct wlr_drm_renderer *renderer,
plane->cursor_bo = NULL; plane->cursor_bo = NULL;
} }
static void free_fb(struct gbm_bo *bo, void *data) {
uint32_t id = (uintptr_t)data;
if (id) {
struct gbm_device *gbm = gbm_bo_get_device(bo);
drmModeRmFB(gbm_device_get_fd(gbm), id);
}
}
static uint32_t get_fb_for_bo(struct gbm_bo *bo) {
uint32_t id = (uintptr_t)gbm_bo_get_user_data(bo);
if (id) {
return id;
}
struct gbm_device *gbm = gbm_bo_get_device(bo);
drmModeAddFB(gbm_device_get_fd(gbm), gbm_bo_get_width(bo), gbm_bo_get_height(bo),
24, 32, gbm_bo_get_stride(bo), gbm_bo_get_handle(bo).u32, &id);
gbm_bo_set_user_data(bo, (void *)(uintptr_t)id, free_fb);
return id;
}
static void wlr_drm_plane_make_current(struct wlr_drm_renderer *renderer, static void wlr_drm_plane_make_current(struct wlr_drm_renderer *renderer,
struct wlr_drm_plane *plane) { struct wlr_drm_plane *plane) {
eglMakeCurrent(renderer->egl.display, plane->egl, plane->egl, eglMakeCurrent(renderer->egl.display, plane->egl, plane->egl,
@ -292,14 +284,14 @@ 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_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);
uint32_t fb_id = get_fb_for_bo(plane->back);
drmModePageFlip(renderer->fd, crtc->id, fb_id, DRM_MODE_PAGE_FLIP_EVENT, output); drm->iface->crtc_pageflip(drm, output, crtc, get_fb_for_bo(plane->back), NULL);
output->pageflip_pending = true; output->pageflip_pending = true;
} }
@ -308,8 +300,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_renderer *renderer = output->renderer; struct wlr_drm_renderer *renderer = output->renderer;
struct wlr_output_mode *mode = output->base->current_mode;
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;
@ -325,28 +317,22 @@ void wlr_drm_output_start_renderer(struct wlr_output_state *output) {
bo = plane->back; bo = plane->back;
} }
uint32_t fb_id = get_fb_for_bo(bo); drmModeModeInfo *mode = &output->base->current_mode->state->mode;
drmModeSetCrtc(renderer->fd, crtc->id, fb_id, 0, 0, drm->iface->crtc_pageflip(drm, output, crtc, get_fb_for_bo(bo), mode);
&output->connector, 1, &mode->state->mode);
drmModePageFlip(renderer->fd, crtc->id, fb_id, DRM_MODE_PAGE_FLIP_EVENT, output);
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 *state = struct wlr_backend_state *drm =
wl_container_of(output->renderer, state, renderer); wl_container_of(output->renderer, drm, renderer);
if (output->state != WLR_DRM_OUTPUT_CONNECTED) { if (output->state != WLR_DRM_OUTPUT_CONNECTED) {
return; return;
} }
if (enable) { drm->iface->conn_enable(drm, output, enable);
drmModeConnectorSetProperty(state->fd, output->connector, output->props.dpms,
DRM_MODE_DPMS_ON);
if (enable) {
wlr_drm_output_start_renderer(output); wlr_drm_output_start_renderer(output);
} else {
drmModeConnectorSetProperty(state->fd, output->connector, output->props.dpms,
DRM_MODE_DPMS_OFF);
} }
} }
@ -515,7 +501,8 @@ static bool wlr_drm_output_set_mode(struct wlr_output_state *output,
} }
if (!wlr_drm_plane_renderer_init(&drm->renderer, crtc->primary, if (!wlr_drm_plane_renderer_init(&drm->renderer, crtc->primary,
mode->width, mode->height, GBM_BO_USE_SCANOUT)) { mode->width, mode->height, GBM_FORMAT_XRGB8888,
GBM_BO_USE_SCANOUT)) {
wlr_log(L_ERROR, "Failed to initalise renderer for plane"); wlr_log(L_ERROR, "Failed to initalise renderer for plane");
goto error_enc; goto error_enc;
} }
@ -541,22 +528,6 @@ static void wlr_drm_output_transform(struct wlr_output_state *output,
output->base->transform = transform; output->base->transform = transform;
} }
bool wlr_drm_crtc_set_cursor(struct wlr_backend_state *drm, struct wlr_drm_crtc *crtc) {
if (!crtc || !crtc->cursor || !crtc->cursor->gbm) {
return true;
}
struct wlr_drm_plane *plane = crtc->cursor;
uint32_t bo_handle = gbm_bo_get_handle(plane->cursor_bo).u32;
if (drmModeSetCursor(drm->fd, crtc->id, bo_handle, plane->width, plane->height)) {
wlr_log_errno(L_ERROR, "Failed to set hardware cursor");
return false;
}
return true;
}
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_backend_state *drm = wl_container_of(output->renderer, drm, renderer);
@ -565,10 +536,10 @@ static bool wlr_drm_output_set_cursor(struct wlr_output_state *output,
struct wlr_drm_plane *plane = crtc->cursor; struct wlr_drm_plane *plane = crtc->cursor;
if (!buf) { if (!buf) {
drmModeSetCursor(drm->fd, crtc->id, 0, 0, 0); return drm->iface->crtc_set_cursor(drm, crtc, NULL);
return true;
} }
// We don't have a real cursor plane, so we make a fake one
if (!plane) { if (!plane) {
plane = calloc(1, sizeof(*plane)); plane = calloc(1, sizeof(*plane));
if (!plane) { if (!plane) {
@ -591,7 +562,7 @@ static bool wlr_drm_output_set_cursor(struct wlr_output_state *output,
return false; return false;
} }
if (!wlr_drm_plane_renderer_init(renderer, plane, w, h, 0)) { if (!wlr_drm_plane_renderer_init(renderer, plane, w, h, GBM_FORMAT_ARGB8888, 0)) {
wlr_log(L_ERROR, "Cannot allocate cursor resources"); wlr_log(L_ERROR, "Cannot allocate cursor resources");
return false; return false;
} }
@ -653,14 +624,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 wlr_drm_crtc_set_cursor(drm, crtc); return drm->iface->crtc_set_cursor(drm, 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_backend_state *drm =
wl_container_of(output->renderer, drm, renderer); wl_container_of(output->renderer, drm, renderer);
return !drmModeMoveCursor(drm->fd, output->crtc->id, x, y); return drm->iface->crtc_move_cursor(drm, 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) {

View file

@ -162,6 +162,7 @@ error:
} }
void wlr_egl_free(struct wlr_egl *egl) { void wlr_egl_free(struct wlr_egl *egl) {
eglMakeCurrent(egl->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglDestroyContext(egl->display, egl->context); eglDestroyContext(egl->display, egl->context);
eglTerminate(egl->display); eglTerminate(egl->display);
eglReleaseThread(); eglReleaseThread();

View file

@ -7,6 +7,8 @@ wlr_files += files(
'session/session.c', 'session/session.c',
'drm/backend.c', 'drm/backend.c',
'drm/drm.c', 'drm/drm.c',
'drm/drm-atomic.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',

View file

@ -27,8 +27,13 @@ union wlr_drm_crtc_props {
// Neither of these are guranteed to exist // Neither of these are guranteed to exist
uint32_t rotation; uint32_t rotation;
uint32_t scaling_mode; uint32_t scaling_mode;
// atomic-modesetting only
uint32_t active;
uint32_t mode_id;
}; };
uint32_t props[2]; uint32_t props[4];
}; };
union wlr_drm_plane_props { union wlr_drm_plane_props {

View file

@ -12,6 +12,8 @@ int32_t calculate_refresh_rate(drmModeModeInfo *mode);
void parse_edid(struct wlr_output *restrict output, size_t len, const uint8_t *data); void parse_edid(struct wlr_output *restrict output, size_t len, const uint8_t *data);
// Returns the string representation of a DRM output type // Returns the string representation of a DRM output type
const char *conn_get_name(uint32_t type_id); const char *conn_get_name(uint32_t type_id);
// Returns the DRM framebuffer id for a gbm_bo
uint32_t get_fb_for_bo(struct gbm_bo *bo);
// Part of match_obj // Part of match_obj
enum { enum {

View file

@ -43,6 +43,9 @@ struct wlr_drm_plane {
struct wlr_drm_crtc { struct wlr_drm_crtc {
uint32_t id; uint32_t id;
uint32_t mode_id; // atomic modesetting only
drmModeAtomicReq *atomic;
union { union {
struct { struct {
struct wlr_drm_plane *overlay; struct wlr_drm_plane *overlay;
@ -76,8 +79,11 @@ struct wlr_drm_renderer {
bool wlr_drm_renderer_init(struct wlr_drm_renderer *renderer, int fd); bool wlr_drm_renderer_init(struct wlr_drm_renderer *renderer, int fd);
void wlr_drm_renderer_free(struct wlr_drm_renderer *renderer); void wlr_drm_renderer_free(struct wlr_drm_renderer *renderer);
struct wlr_drm_interface;
struct wlr_backend_state { struct wlr_backend_state {
struct wlr_backend *base; struct wlr_backend *base;
const struct wlr_drm_interface *iface;
int fd; int fd;
dev_t dev; dev_t dev;
@ -150,6 +156,22 @@ struct wlr_output_state {
bool pageflip_pending; bool pageflip_pending;
}; };
// 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);
// 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);
// 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);
// Move the cursor on crtc
bool (*crtc_move_cursor)(struct wlr_backend_state *drm, 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_backend_state *drm);
bool wlr_drm_resources_init(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); void wlr_drm_resources_free(struct wlr_backend_state *drm);
@ -159,6 +181,5 @@ void wlr_drm_scan_connectors(struct wlr_backend_state *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);
bool wlr_drm_crtc_set_cursor(struct wlr_backend_state *drm, struct wlr_drm_crtc *crtc);
#endif #endif