From f193623ca11c245e9209a8df40115dbe420bbc22 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Mon, 2 Oct 2017 21:44:33 +1300 Subject: Change iface prefix to suffix --- backend/drm/atomic.c | 189 +++++++++++++++++++++++++++++++++++++++++++++ backend/drm/drm.c | 6 +- backend/drm/iface_atomic.c | 189 --------------------------------------------- backend/drm/iface_legacy.c | 66 ---------------- backend/drm/legacy.c | 66 ++++++++++++++++ 5 files changed, 258 insertions(+), 258 deletions(-) create mode 100644 backend/drm/atomic.c delete mode 100644 backend/drm/iface_atomic.c delete mode 100644 backend/drm/iface_legacy.c create mode 100644 backend/drm/legacy.c (limited to 'backend/drm') diff --git a/backend/drm/atomic.c b/backend/drm/atomic.c new file mode 100644 index 00000000..e7374a00 --- /dev/null +++ b/backend/drm/atomic.c @@ -0,0 +1,189 @@ +#include +#include +#include +#include +#include "backend/drm/drm.h" +#include "backend/drm/iface.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_drm_connector *conn, uint32_t flag, bool modeset) { + if (atom->failed) { + return false; + } + + uint32_t flags = DRM_MODE_PAGE_FLIP_EVENT | flag; + + int ret = drmModeAtomicCommit(drm_fd, atom->req, flags, conn); + if (ret) { + wlr_log_errno(L_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)) { + wlr_log_errno(L_ERROR, "%s: Atomic commit failed (%s)", + conn->output.name, modeset ? "modeset" : "pageflip"); + } + } + + 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->surf.width << 16); + atomic_add(atom, id, props->src_h, plane->surf.height << 16); + atomic_add(atom, id, props->crtc_w, plane->surf.width); + atomic_add(atom, id, props->crtc_h, plane->surf.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_drm_backend *drm, + struct wlr_drm_connector *conn, + 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, conn->id, conn->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, conn, + mode ? DRM_MODE_ATOMIC_ALLOW_MODESET : DRM_MODE_ATOMIC_NONBLOCK, + mode); +} + +static void atomic_conn_enable(struct wlr_drm_backend *drm, + struct wlr_drm_connector *conn, bool enable) { + struct wlr_drm_crtc *crtc = conn->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_drm_backend *drm, + struct wlr_drm_crtc *crtc, struct gbm_bo *bo); + +static bool atomic_crtc_set_cursor(struct wlr_drm_backend *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_drm_backend *drm, + struct wlr_drm_crtc *crtc, int x, int y); + +static bool atomic_crtc_move_cursor(struct wlr_drm_backend *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, +}; diff --git a/backend/drm/drm.c b/backend/drm/drm.c index ccdc92d9..1a5fea9f 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -32,13 +32,13 @@ bool wlr_drm_check_features(struct wlr_drm_backend *drm) { if (getenv("WLR_DRM_NO_ATOMIC")) { wlr_log(L_DEBUG, "WLR_DRM_NO_ATOMIC set, forcing legacy DRM interface"); - drm->iface = &iface_legacy; + drm->iface = &legacy_iface; } else if (drmSetClientCap(drm->fd, DRM_CLIENT_CAP_ATOMIC, 1)) { wlr_log(L_DEBUG, "Atomic modesetting unsupported, using legacy DRM interface"); - drm->iface = &iface_legacy; + drm->iface = &legacy_iface; } else { wlr_log(L_DEBUG, "Using atomic DRM interface"); - drm->iface = &iface_atomic; + drm->iface = &atomic_iface; } return true; diff --git a/backend/drm/iface_atomic.c b/backend/drm/iface_atomic.c deleted file mode 100644 index 1aef05d1..00000000 --- a/backend/drm/iface_atomic.c +++ /dev/null @@ -1,189 +0,0 @@ -#include -#include -#include -#include -#include "backend/drm/drm.h" -#include "backend/drm/iface.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_drm_connector *conn, uint32_t flag, bool modeset) { - if (atom->failed) { - return false; - } - - uint32_t flags = DRM_MODE_PAGE_FLIP_EVENT | flag; - - int ret = drmModeAtomicCommit(drm_fd, atom->req, flags, conn); - if (ret) { - wlr_log_errno(L_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)) { - wlr_log_errno(L_ERROR, "%s: Atomic commit failed (%s)", - conn->output.name, modeset ? "modeset" : "pageflip"); - } - } - - 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->surf.width << 16); - atomic_add(atom, id, props->src_h, plane->surf.height << 16); - atomic_add(atom, id, props->crtc_w, plane->surf.width); - atomic_add(atom, id, props->crtc_h, plane->surf.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_drm_backend *drm, - struct wlr_drm_connector *conn, - 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, conn->id, conn->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, conn, - mode ? DRM_MODE_ATOMIC_ALLOW_MODESET : DRM_MODE_ATOMIC_NONBLOCK, - mode); -} - -static void atomic_conn_enable(struct wlr_drm_backend *drm, - struct wlr_drm_connector *conn, bool enable) { - struct wlr_drm_crtc *crtc = conn->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_drm_backend *drm, - struct wlr_drm_crtc *crtc, struct gbm_bo *bo); - -static bool atomic_crtc_set_cursor(struct wlr_drm_backend *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_drm_backend *drm, - struct wlr_drm_crtc *crtc, int x, int y); - -static bool atomic_crtc_move_cursor(struct wlr_drm_backend *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 iface_atomic = { - .conn_enable = atomic_conn_enable, - .crtc_pageflip = atomic_crtc_pageflip, - .crtc_set_cursor = atomic_crtc_set_cursor, - .crtc_move_cursor = atomic_crtc_move_cursor, -}; diff --git a/backend/drm/iface_legacy.c b/backend/drm/iface_legacy.c deleted file mode 100644 index cf73bb87..00000000 --- a/backend/drm/iface_legacy.c +++ /dev/null @@ -1,66 +0,0 @@ -#include -#include -#include -#include -#include "backend/drm/drm.h" -#include "backend/drm/iface.h" -#include "backend/drm/util.h" - -static bool legacy_crtc_pageflip(struct wlr_drm_backend *drm, - struct wlr_drm_connector *conn, struct wlr_drm_crtc *crtc, - uint32_t fb_id, drmModeModeInfo *mode) { - if (mode) { - if (drmModeSetCrtc(drm->fd, crtc->id, fb_id, 0, 0, - &conn->id, 1, mode)) { - wlr_log_errno(L_ERROR, "%s: Failed to set CRTC", conn->output.name); - return false; - } - } - - if (drmModePageFlip(drm->fd, crtc->id, fb_id, DRM_MODE_PAGE_FLIP_EVENT, conn)) { - wlr_log_errno(L_ERROR, "%s: Failed to page flip", conn->output.name); - return false; - } - - return true; -} - -static void legacy_conn_enable(struct wlr_drm_backend *drm, - struct wlr_drm_connector *conn, bool enable) { - drmModeConnectorSetProperty(drm->fd, conn->id, conn->props.dpms, - enable ? DRM_MODE_DPMS_ON : DRM_MODE_DPMS_OFF); -} - -bool legacy_crtc_set_cursor(struct wlr_drm_backend *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->surf.width, plane->surf.height)) { - wlr_log_errno(L_ERROR, "Failed to set hardware cursor"); - return false; - } - - return true; -} - -bool legacy_crtc_move_cursor(struct wlr_drm_backend *drm, - struct wlr_drm_crtc *crtc, int x, int y) { - return !drmModeMoveCursor(drm->fd, crtc->id, x, y); -} - -const struct wlr_drm_interface iface_legacy = { - .conn_enable = legacy_conn_enable, - .crtc_pageflip = legacy_crtc_pageflip, - .crtc_set_cursor = legacy_crtc_set_cursor, - .crtc_move_cursor = legacy_crtc_move_cursor, -}; diff --git a/backend/drm/legacy.c b/backend/drm/legacy.c new file mode 100644 index 00000000..d75eb2cb --- /dev/null +++ b/backend/drm/legacy.c @@ -0,0 +1,66 @@ +#include +#include +#include +#include +#include "backend/drm/drm.h" +#include "backend/drm/iface.h" +#include "backend/drm/util.h" + +static bool legacy_crtc_pageflip(struct wlr_drm_backend *drm, + struct wlr_drm_connector *conn, struct wlr_drm_crtc *crtc, + uint32_t fb_id, drmModeModeInfo *mode) { + if (mode) { + if (drmModeSetCrtc(drm->fd, crtc->id, fb_id, 0, 0, + &conn->id, 1, mode)) { + wlr_log_errno(L_ERROR, "%s: Failed to set CRTC", conn->output.name); + return false; + } + } + + if (drmModePageFlip(drm->fd, crtc->id, fb_id, DRM_MODE_PAGE_FLIP_EVENT, conn)) { + wlr_log_errno(L_ERROR, "%s: Failed to page flip", conn->output.name); + return false; + } + + return true; +} + +static void legacy_conn_enable(struct wlr_drm_backend *drm, + struct wlr_drm_connector *conn, bool enable) { + drmModeConnectorSetProperty(drm->fd, conn->id, conn->props.dpms, + enable ? DRM_MODE_DPMS_ON : DRM_MODE_DPMS_OFF); +} + +bool legacy_crtc_set_cursor(struct wlr_drm_backend *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->surf.width, plane->surf.height)) { + wlr_log_errno(L_ERROR, "Failed to set hardware cursor"); + return false; + } + + return true; +} + +bool legacy_crtc_move_cursor(struct wlr_drm_backend *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, +}; -- cgit v1.2.3