2017-08-09 08:43:01 +00:00
|
|
|
#include <gbm.h>
|
|
|
|
#include <xf86drm.h>
|
|
|
|
#include <xf86drmMode.h>
|
|
|
|
#include <wlr/util/log.h>
|
2017-09-30 06:03:34 +00:00
|
|
|
#include "backend/drm/drm.h"
|
2017-09-30 06:11:41 +00:00
|
|
|
#include "backend/drm/iface.h"
|
2017-09-30 06:03:34 +00:00
|
|
|
#include "backend/drm/util.h"
|
2017-08-09 08:43:01 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-08-13 14:51:50 +00:00
|
|
|
static bool atomic_commit(int drm_fd, struct atomic *atom,
|
2017-09-30 10:31:08 +00:00
|
|
|
struct wlr_drm_connector *conn, uint32_t flag, bool modeset) {
|
2017-08-09 08:43:01 +00:00
|
|
|
if (atom->failed) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-09 12:13:39 +00:00
|
|
|
uint32_t flags = DRM_MODE_PAGE_FLIP_EVENT | flag;
|
2017-08-09 08:43:01 +00:00
|
|
|
|
2017-09-30 10:31:08 +00:00
|
|
|
int ret = drmModeAtomicCommit(drm_fd, atom->req, flags, conn);
|
2017-08-09 08:43:01 +00:00
|
|
|
if (ret) {
|
2017-09-23 01:38:43 +00:00
|
|
|
wlr_log_errno(L_ERROR, "%s: Atomic commit failed (%s)",
|
2017-09-30 10:31:08 +00:00
|
|
|
conn->output.name, modeset ? "modeset" : "pageflip");
|
2017-09-09 11:06:44 +00:00
|
|
|
|
|
|
|
// Try to commit without new changes
|
|
|
|
drmModeAtomicSetCursor(atom->req, atom->cursor);
|
2017-09-30 10:31:08 +00:00
|
|
|
if (drmModeAtomicCommit(drm_fd, atom->req, flags, conn)) {
|
2017-09-23 01:38:43 +00:00
|
|
|
wlr_log_errno(L_ERROR, "%s: Atomic commit failed (%s)",
|
2017-09-30 10:31:08 +00:00
|
|
|
conn->output.name, modeset ? "modeset" : "pageflip");
|
2017-09-09 11:06:44 +00:00
|
|
|
}
|
2017-08-09 08:43:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2017-09-30 07:52:58 +00:00
|
|
|
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);
|
2017-08-09 08:43:01 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-30 09:22:26 +00:00
|
|
|
static bool atomic_crtc_pageflip(struct wlr_drm_backend *drm,
|
2017-09-30 10:31:08 +00:00
|
|
|
struct wlr_drm_connector *conn,
|
2017-08-12 23:52:22 +00:00
|
|
|
struct wlr_drm_crtc *crtc,
|
|
|
|
uint32_t fb_id, drmModeModeInfo *mode) {
|
2017-08-09 08:43:01 +00:00
|
|
|
if (mode) {
|
|
|
|
if (crtc->mode_id) {
|
2017-09-30 09:22:26 +00:00
|
|
|
drmModeDestroyPropertyBlob(drm->fd, crtc->mode_id);
|
2017-08-09 08:43:01 +00:00
|
|
|
}
|
|
|
|
|
2017-09-30 09:22:26 +00:00
|
|
|
if (drmModeCreatePropertyBlob(drm->fd, mode, sizeof(*mode), &crtc->mode_id)) {
|
2017-08-09 08:43:01 +00:00
|
|
|
wlr_log_errno(L_ERROR, "Unable to create property blob");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct atomic atom;
|
|
|
|
|
|
|
|
atomic_begin(crtc, &atom);
|
2017-09-30 10:31:08 +00:00
|
|
|
atomic_add(&atom, conn->id, conn->props.crtc_id, crtc->id);
|
2017-08-09 08:43:01 +00:00
|
|
|
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);
|
2017-09-30 10:31:08 +00:00
|
|
|
return atomic_commit(drm->fd, &atom, conn,
|
2017-09-23 01:38:43 +00:00
|
|
|
mode ? DRM_MODE_ATOMIC_ALLOW_MODESET : DRM_MODE_ATOMIC_NONBLOCK,
|
|
|
|
mode);
|
2017-08-09 08:43:01 +00:00
|
|
|
}
|
|
|
|
|
2017-09-30 09:22:26 +00:00
|
|
|
static void atomic_conn_enable(struct wlr_drm_backend *drm,
|
2017-09-30 10:31:08 +00:00
|
|
|
struct wlr_drm_connector *conn, bool enable) {
|
|
|
|
struct wlr_drm_crtc *crtc = conn->crtc;
|
2017-08-09 08:43:01 +00:00
|
|
|
struct atomic atom;
|
|
|
|
|
|
|
|
atomic_begin(crtc, &atom);
|
|
|
|
atomic_add(&atom, crtc->id, crtc->props.active, enable);
|
2017-09-30 09:22:26 +00:00
|
|
|
atomic_end(drm->fd, &atom);
|
2017-08-09 08:43:01 +00:00
|
|
|
}
|
|
|
|
|
2017-09-30 09:22:26 +00:00
|
|
|
bool legacy_crtc_set_cursor(struct wlr_drm_backend *drm,
|
2017-08-12 23:52:22 +00:00
|
|
|
struct wlr_drm_crtc *crtc, struct gbm_bo *bo);
|
2017-08-09 08:43:01 +00:00
|
|
|
|
2017-09-30 09:22:26 +00:00
|
|
|
static bool atomic_crtc_set_cursor(struct wlr_drm_backend *drm,
|
2017-08-12 23:52:22 +00:00
|
|
|
struct wlr_drm_crtc *crtc, struct gbm_bo *bo) {
|
2017-08-09 08:43:01 +00:00
|
|
|
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) {
|
2017-09-30 09:22:26 +00:00
|
|
|
return legacy_crtc_set_cursor(drm, crtc, bo);
|
2017-08-09 08:43:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-09-30 09:22:26 +00:00
|
|
|
return atomic_end(drm->fd, &atom);
|
2017-08-09 08:43:01 +00:00
|
|
|
}
|
|
|
|
|
2017-09-30 09:22:26 +00:00
|
|
|
bool legacy_crtc_move_cursor(struct wlr_drm_backend *drm,
|
2017-08-12 23:52:22 +00:00
|
|
|
struct wlr_drm_crtc *crtc, int x, int y);
|
2017-08-09 08:43:01 +00:00
|
|
|
|
2017-09-30 09:22:26 +00:00
|
|
|
static bool atomic_crtc_move_cursor(struct wlr_drm_backend *drm,
|
2017-08-12 23:52:22 +00:00
|
|
|
struct wlr_drm_crtc *crtc, int x, int y) {
|
Don't crash if crtc->cursor is NULL
Same as what atomic_crtc_set_cursor does
Core was generated by `_build/rootston/rootston'.
Program terminated with signal SIGSEGV, Segmentation fault.
0 0xb6f28a1c in atomic_crtc_move_cursor (drm=0x1ebc8e8, crtc=0x1ead498, x=0, y=0) at ../backend/drm/atomic.c:170
170 if (!crtc || !crtc->cursor) {
(gdb) bt
0 0xb6f28a1c in atomic_crtc_move_cursor (drm=0x1ebc8e8, crtc=0x1ead498, x=0, y=0) at ../backend/drm/atomic.c:170
1 0xb6f2a856 in wlr_drm_connector_move_cursor (output=0x2242b28, x=0, y=0) at ../backend/drm/drm.c:634
2 0xb6f3cea0 in wlr_output_cursor_set_image (cursor=0x21a0338, pixels=0x22e1290 "", stride=24, width=24, height=24, hotspot_x=4, hotspot_y=4) at ../types/wlr_output.c:516
3 0xb6f39da2 in wlr_cursor_set_image (cur=0x22cfc90, pixels=0x22e1290 "", stride=24, width=24, height=24, hotspot_x=4, hotspot_y=4, scale=1) at ../types/wlr_cursor.c:310
4 0xb6f44d2a in wlr_xcursor_manager_set_cursor_image (manager=0x22cfd10, name=0x434420 "left_ptr", cursor=0x22cfc90) at ../types/wlr_xcursor_manager.c:80
5 0x00431c0a in roots_seat_configure_xcursor (seat=0x22cef08) at ../rootston/seat.c:515
6 0x0043137c in roots_seat_init_cursor (seat=0x22cef08) at ../rootston/seat.c:210
7 0x004315ec in roots_seat_create (input=0x218d220, name=0x434594 "seat0") at ../rootston/seat.c:289
8 0x0042ecba in input_get_seat (input=0x218d220, name=0x434594 "seat0") at ../rootston/input.c:39
9 0x0042ed04 in input_add_notify (listener=0x218d228, data=0x218d3b0) at ../rootston/input.c:54
10 0xb6f2f2e6 in wl_signal_emit (signal=0x1ea548c, data=0x218d3b0) at /usr/include/wayland-server-core.h:387
11 0xb6f2f572 in input_add_reemit (listener=0x1ea9990, data=0x218d3b0) at ../backend/multi/backend.c:101
12 0xb6f2db7e in wl_signal_emit (signal=0x1ea992c, data=0x218d3b0) at /usr/include/wayland-server-core.h:387
13 0xb6f2ddaa in handle_device_added (backend=0x1ea9920, libinput_dev=0x2292598) at ../backend/libinput/events.c:87
14 0xb6f2e164 in wlr_libinput_event (backend=0x1ea9920, event=0x2292b78) at ../backend/libinput/events.c:198
15 0xb6f2d678 in wlr_libinput_readable (fd=23, mask=1, _backend=0x1ea9920) at ../backend/libinput/backend.c:28
16 0xb6f2d7c0 in wlr_libinput_backend_start (_backend=0x1ea9920) at ../backend/libinput/backend.c:74
17 0xb6f27170 in wlr_backend_start (backend=0x1ea9920) at ../backend/backend.c:30
18 0xb6f2f320 in multi_backend_start (wlr_backend=0x1ea5480) at ../backend/multi/backend.c:22
19 0xb6f27170 in wlr_backend_start (backend=0x1ea5480) at ../backend/backend.c:30
20 0x0042fbc6 in main (argc=1, argv=0xbe89dd04) at ../rootston/main.c:60
2018-01-15 12:21:22 +00:00
|
|
|
if (!crtc || !crtc->cursor) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-09 08:43:01 +00:00
|
|
|
struct wlr_drm_plane *plane = crtc->cursor;
|
|
|
|
// We can't use atomic operations on fake planes
|
|
|
|
if (plane->id == 0) {
|
2017-09-30 09:22:26 +00:00
|
|
|
return legacy_crtc_move_cursor(drm, crtc, x, y);
|
2017-08-09 08:43:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2017-09-30 09:22:26 +00:00
|
|
|
return atomic_end(drm->fd, &atom);
|
2017-08-09 08:43:01 +00:00
|
|
|
}
|
|
|
|
|
2017-10-02 08:44:33 +00:00
|
|
|
const struct wlr_drm_interface atomic_iface = {
|
2017-08-09 08:43:01 +00:00
|
|
|
.conn_enable = atomic_conn_enable,
|
|
|
|
.crtc_pageflip = atomic_crtc_pageflip,
|
|
|
|
.crtc_set_cursor = atomic_crtc_set_cursor,
|
|
|
|
.crtc_move_cursor = atomic_crtc_move_cursor,
|
|
|
|
};
|