backend: drm: switch to pageflip_handler_2

atomic and legacy now both pass the backend as the user data for the
pageflip event. We than retrieve the correct connector by matching on
the crtc_id passed to the page_flip_handler2.

Wlroots also requires the DRM_CRTC_IN_VBLANK_EVENT capability now.

Fixes #1297
This commit is contained in:
Rouven Czerwinski 2019-06-26 17:14:31 +02:00 committed by Scott Anderson
parent 0b1f9439ba
commit d10072e76c
3 changed files with 27 additions and 9 deletions

View File

@ -45,18 +45,20 @@ static bool atomic_end(int drm_fd, struct atomic *atom) {
static bool atomic_commit(int drm_fd, struct atomic *atom,
struct wlr_drm_connector *conn, uint32_t flags, bool modeset) {
struct wlr_drm_backend *drm =
get_drm_backend_from_backend(conn->output.backend);
if (atom->failed) {
return false;
}
int ret = drmModeAtomicCommit(drm_fd, atom->req, flags, conn);
int ret = drmModeAtomicCommit(drm_fd, atom->req, flags, drm);
if (ret) {
wlr_log_errno(WLR_ERROR, "%s: Atomic commit failed (%s)",
conn->output.name, modeset ? "modeset" : "pageflip");
// Try to commit without new changes
drmModeAtomicSetCursor(atom->req, atom->cursor);
if (drmModeAtomicCommit(drm_fd, atom->req, flags, conn)) {
if (drmModeAtomicCommit(drm_fd, atom->req, flags, drm)) {
wlr_log_errno(WLR_ERROR,
"%s: Atomic commit without new changes failed (%s)",
conn->output.name, modeset ? "modeset" : "pageflip");

View File

@ -50,6 +50,11 @@ bool check_drm_features(struct wlr_drm_backend *drm) {
return false;
}
if (drmGetCap(drm->fd, DRM_CAP_CRTC_IN_VBLANK_EVENT, &cap) || !cap) {
wlr_log(WLR_ERROR, "DRM_CRTC_IN_VBLANK_EVENT unsupported");
return false;
}
const char *no_atomic = getenv("WLR_DRM_NO_ATOMIC");
if (no_atomic && strcmp(no_atomic, "1") == 0) {
wlr_log(WLR_DEBUG,
@ -1359,10 +1364,21 @@ static int mhz_to_nsec(int mhz) {
}
static void page_flip_handler(int fd, unsigned seq,
unsigned tv_sec, unsigned tv_usec, void *data) {
struct wlr_drm_connector *conn = data;
struct wlr_drm_backend *drm =
get_drm_backend_from_backend(conn->output.backend);
unsigned tv_sec, unsigned tv_usec, unsigned crtc_id, void *data) {
struct wlr_drm_backend *drm = data;
struct wlr_drm_connector *conn = NULL;
struct wlr_drm_connector *search;
wl_list_for_each(search, &drm->outputs, link) {
if (search->crtc && search->crtc->id == crtc_id) {
conn = search;
}
}
if (!conn) {
wlr_log(WLR_ERROR, "No connector for crtc_id %u", crtc_id);
return;
}
conn->pageflip_pending = false;
@ -1411,8 +1427,8 @@ static void page_flip_handler(int fd, unsigned seq,
int handle_drm_event(int fd, uint32_t mask, void *data) {
drmEventContext event = {
.version = 2,
.page_flip_handler = page_flip_handler,
.version = 3,
.page_flip_handler2 = page_flip_handler,
};
drmHandleEvent(fd, &event);

View File

@ -17,7 +17,7 @@ static bool legacy_crtc_pageflip(struct wlr_drm_backend *drm,
}
}
if (drmModePageFlip(drm->fd, crtc->id, fb_id, DRM_MODE_PAGE_FLIP_EVENT, conn)) {
if (drmModePageFlip(drm->fd, crtc->id, fb_id, DRM_MODE_PAGE_FLIP_EVENT, drm)) {
wlr_log_errno(WLR_ERROR, "%s: Failed to page flip", conn->output.name);
return false;
}