|
|
@ -4,6 +4,7 @@
|
|
|
|
#include <string.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
#include <xf86drm.h>
|
|
|
|
#include <xf86drm.h>
|
|
|
|
#include <xf86drmMode.h>
|
|
|
|
#include <xf86drmMode.h>
|
|
|
|
#include <drm_mode.h>
|
|
|
|
#include <drm_mode.h>
|
|
|
@ -31,7 +32,10 @@ bool wlr_drm_check_features(struct wlr_drm_backend *backend) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (drmSetClientCap(backend->fd, DRM_CLIENT_CAP_ATOMIC, 1)) {
|
|
|
|
if (getenv("WLR_DRM_NO_ATOMIC")) {
|
|
|
|
|
|
|
|
wlr_log(L_DEBUG, "WLR_DRM_NO_ATOMIC set, forcing legacy DRM interface");
|
|
|
|
|
|
|
|
backend->iface = &legacy_iface;
|
|
|
|
|
|
|
|
} else 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");
|
|
|
|
backend->iface = &legacy_iface;
|
|
|
|
backend->iface = &legacy_iface;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -297,8 +301,14 @@ static void wlr_drm_output_swap_buffers(struct wlr_output *_output) {
|
|
|
|
|
|
|
|
|
|
|
|
wlr_drm_plane_swap_buffers(renderer, plane);
|
|
|
|
wlr_drm_plane_swap_buffers(renderer, plane);
|
|
|
|
|
|
|
|
|
|
|
|
backend->iface->crtc_pageflip(backend, output, crtc, get_fb_for_bo(plane->back), NULL);
|
|
|
|
uint32_t fb_id = get_fb_for_bo(plane->back);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (backend->iface->crtc_pageflip(backend, output, crtc, fb_id, NULL)) {
|
|
|
|
output->pageflip_pending = true;
|
|
|
|
output->pageflip_pending = true;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
wl_event_source_timer_update(output->retry_pageflip,
|
|
|
|
|
|
|
|
1000.0f / output->output.current_mode->refresh);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void wlr_drm_output_set_gamma(struct wlr_output *_output,
|
|
|
|
static void wlr_drm_output_set_gamma(struct wlr_output *_output,
|
|
|
@ -344,8 +354,12 @@ void wlr_drm_output_start_renderer(struct wlr_drm_output *output) {
|
|
|
|
struct wlr_drm_output_mode *_mode =
|
|
|
|
struct wlr_drm_output_mode *_mode =
|
|
|
|
(struct wlr_drm_output_mode *)output->output.current_mode;
|
|
|
|
(struct wlr_drm_output_mode *)output->output.current_mode;
|
|
|
|
drmModeModeInfo *mode = &_mode->mode;
|
|
|
|
drmModeModeInfo *mode = &_mode->mode;
|
|
|
|
backend->iface->crtc_pageflip(backend, output, crtc, get_fb_for_bo(bo), mode);
|
|
|
|
if (backend->iface->crtc_pageflip(backend, output, crtc, get_fb_for_bo(bo), mode)) {
|
|
|
|
output->pageflip_pending = true;
|
|
|
|
output->pageflip_pending = true;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
wl_event_source_timer_update(output->retry_pageflip,
|
|
|
|
|
|
|
|
1000.0f / output->output.current_mode->refresh);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void wlr_drm_output_enable(struct wlr_output *_output, bool enable) {
|
|
|
|
static void wlr_drm_output_enable(struct wlr_output *_output, bool enable) {
|
|
|
@ -553,7 +567,7 @@ error_enc:
|
|
|
|
error_conn:
|
|
|
|
error_conn:
|
|
|
|
drmModeFreeConnector(conn);
|
|
|
|
drmModeFreeConnector(conn);
|
|
|
|
error_output:
|
|
|
|
error_output:
|
|
|
|
wlr_drm_output_cleanup(output, false);
|
|
|
|
wlr_drm_output_cleanup(output);
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -700,7 +714,8 @@ static bool wlr_drm_output_move_cursor(struct wlr_output *_output,
|
|
|
|
|
|
|
|
|
|
|
|
static void wlr_drm_output_destroy(struct wlr_output *_output) {
|
|
|
|
static void wlr_drm_output_destroy(struct wlr_output *_output) {
|
|
|
|
struct wlr_drm_output *output = (struct wlr_drm_output *)_output;
|
|
|
|
struct wlr_drm_output *output = (struct wlr_drm_output *)_output;
|
|
|
|
wlr_drm_output_cleanup(output, true);
|
|
|
|
wlr_drm_output_cleanup(output);
|
|
|
|
|
|
|
|
wl_event_source_remove(output->retry_pageflip);
|
|
|
|
free(output);
|
|
|
|
free(output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -717,6 +732,13 @@ static struct wlr_output_impl output_impl = {
|
|
|
|
.get_gamma_size = wlr_drm_output_get_gamma_size,
|
|
|
|
.get_gamma_size = wlr_drm_output_get_gamma_size,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int retry_pageflip(void *data) {
|
|
|
|
|
|
|
|
struct wlr_drm_output *output = data;
|
|
|
|
|
|
|
|
wlr_log(L_INFO, "%s: Retrying pageflip", output->output.name);
|
|
|
|
|
|
|
|
wlr_drm_output_start_renderer(output);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int find_id(const void *item, const void *cmp_to) {
|
|
|
|
static int find_id(const void *item, const void *cmp_to) {
|
|
|
|
const struct wlr_drm_output *output = item;
|
|
|
|
const struct wlr_drm_output *output = item;
|
|
|
|
const uint32_t *id = cmp_to;
|
|
|
|
const uint32_t *id = cmp_to;
|
|
|
@ -748,6 +770,11 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
size_t seen_len = backend->outputs->length;
|
|
|
|
|
|
|
|
// +1 so it can never be 0
|
|
|
|
|
|
|
|
bool seen[seen_len + 1];
|
|
|
|
|
|
|
|
memset(seen, 0, sizeof(seen));
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < res->count_connectors; ++i) {
|
|
|
|
for (int i = 0; i < res->count_connectors; ++i) {
|
|
|
|
drmModeConnector *conn = drmModeGetConnector(backend->fd,
|
|
|
|
drmModeConnector *conn = drmModeGetConnector(backend->fd,
|
|
|
|
res->connectors[i]);
|
|
|
|
res->connectors[i]);
|
|
|
@ -768,6 +795,11 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
wlr_output_init(&output->output, &output_impl);
|
|
|
|
wlr_output_init(&output->output, &output_impl);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct wl_event_loop *ev = wl_display_get_event_loop(backend->display);
|
|
|
|
|
|
|
|
output->retry_pageflip = wl_event_loop_add_timer(ev, retry_pageflip,
|
|
|
|
|
|
|
|
output);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
output->renderer = &backend->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;
|
|
|
@ -798,6 +830,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) {
|
|
|
|
if (list_add(backend->outputs, output) == -1) {
|
|
|
|
if (list_add(backend->outputs, output) == -1) {
|
|
|
|
wlr_log_errno(L_ERROR, "Allocation failed");
|
|
|
|
wlr_log_errno(L_ERROR, "Allocation failed");
|
|
|
|
drmModeFreeConnector(conn);
|
|
|
|
drmModeFreeConnector(conn);
|
|
|
|
|
|
|
|
wl_event_source_remove(output->retry_pageflip);
|
|
|
|
free(output);
|
|
|
|
free(output);
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -805,6 +838,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) {
|
|
|
|
wlr_log(L_INFO, "Found display '%s'", output->output.name);
|
|
|
|
wlr_log(L_INFO, "Found display '%s'", output->output.name);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
output = backend->outputs->items[index];
|
|
|
|
output = backend->outputs->items[index];
|
|
|
|
|
|
|
|
seen[index] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (output->state == WLR_DRM_OUTPUT_DISCONNECTED &&
|
|
|
|
if (output->state == WLR_DRM_OUTPUT_DISCONNECTED &&
|
|
|
@ -843,13 +877,30 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) {
|
|
|
|
conn->connection != DRM_MODE_CONNECTED) {
|
|
|
|
conn->connection != DRM_MODE_CONNECTED) {
|
|
|
|
|
|
|
|
|
|
|
|
wlr_log(L_INFO, "'%s' disconnected", output->output.name);
|
|
|
|
wlr_log(L_INFO, "'%s' disconnected", output->output.name);
|
|
|
|
wlr_drm_output_cleanup(output, false);
|
|
|
|
wlr_drm_output_cleanup(output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
drmModeFreeConnector(conn);
|
|
|
|
drmModeFreeConnector(conn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
drmModeFreeResources(res);
|
|
|
|
drmModeFreeResources(res);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = seen_len; i-- > 0;) {
|
|
|
|
|
|
|
|
if (seen[i]) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_drm_output *output = backend->outputs->items[i];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wlr_log(L_INFO, "'%s' disappeared", output->output.name);
|
|
|
|
|
|
|
|
wlr_drm_output_cleanup(output);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
drmModeFreeCrtc(output->old_crtc);
|
|
|
|
|
|
|
|
wl_event_source_remove(output->retry_pageflip);
|
|
|
|
|
|
|
|
free(output);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
list_del(backend->outputs, i);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void page_flip_handler(int fd, unsigned seq,
|
|
|
|
static void page_flip_handler(int fd, unsigned seq,
|
|
|
@ -884,23 +935,46 @@ int wlr_drm_event(int fd, uint32_t mask, void *data) {
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void restore_output(struct wlr_drm_output *output, int fd) {
|
|
|
|
void wlr_drm_restore_outputs(struct wlr_drm_backend *drm) {
|
|
|
|
// Wait for any pending pageflips to finish
|
|
|
|
uint64_t to_close = (1 << drm->outputs->length) - 1;
|
|
|
|
while (output->pageflip_pending) {
|
|
|
|
|
|
|
|
wlr_drm_event(fd, 0, NULL);
|
|
|
|
for (size_t i = 0; i < drm->outputs->length; ++i) {
|
|
|
|
|
|
|
|
struct wlr_drm_output *output = drm->outputs->items[i];
|
|
|
|
|
|
|
|
if (output->state == WLR_DRM_OUTPUT_CONNECTED) {
|
|
|
|
|
|
|
|
output->state = WLR_DRM_OUTPUT_CLEANUP;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
time_t timeout = time(NULL) + 5;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (to_close && time(NULL) < timeout) {
|
|
|
|
|
|
|
|
wlr_drm_event(drm->fd, 0, NULL);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < drm->outputs->length; ++i) {
|
|
|
|
|
|
|
|
struct wlr_drm_output *output = drm->outputs->items[i];
|
|
|
|
|
|
|
|
if (output->state != WLR_DRM_OUTPUT_CLEANUP || !output->pageflip_pending) {
|
|
|
|
|
|
|
|
to_close &= ~(1 << i);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (to_close) {
|
|
|
|
|
|
|
|
wlr_log(L_ERROR, "Timed out stopping output renderers");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < drm->outputs->length; ++i) {
|
|
|
|
|
|
|
|
struct wlr_drm_output *output = drm->outputs->items[i];
|
|
|
|
drmModeCrtc *crtc = output->old_crtc;
|
|
|
|
drmModeCrtc *crtc = output->old_crtc;
|
|
|
|
if (!crtc) {
|
|
|
|
if (!crtc) {
|
|
|
|
return;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
drmModeSetCrtc(fd, crtc->crtc_id, crtc->buffer_id, crtc->x, crtc->y,
|
|
|
|
drmModeSetCrtc(drm->fd, crtc->crtc_id, crtc->buffer_id, crtc->x, crtc->y,
|
|
|
|
&output->connector, 1, &crtc->mode);
|
|
|
|
&output->connector, 1, &crtc->mode);
|
|
|
|
drmModeFreeCrtc(crtc);
|
|
|
|
drmModeFreeCrtc(crtc);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void wlr_drm_output_cleanup(struct wlr_drm_output *output, bool restore) {
|
|
|
|
void wlr_drm_output_cleanup(struct wlr_drm_output *output) {
|
|
|
|
if (!output) {
|
|
|
|
if (!output) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -911,12 +985,7 @@ void wlr_drm_output_cleanup(struct wlr_drm_output *output, bool restore) {
|
|
|
|
|
|
|
|
|
|
|
|
switch (output->state) {
|
|
|
|
switch (output->state) {
|
|
|
|
case WLR_DRM_OUTPUT_CONNECTED:
|
|
|
|
case WLR_DRM_OUTPUT_CONNECTED:
|
|
|
|
output->state = WLR_DRM_OUTPUT_DISCONNECTED;
|
|
|
|
case WLR_DRM_OUTPUT_CLEANUP:;
|
|
|
|
if (restore) {
|
|
|
|
|
|
|
|
restore_output(output, renderer->fd);
|
|
|
|
|
|
|
|
restore = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_drm_crtc *crtc = output->crtc;
|
|
|
|
struct wlr_drm_crtc *crtc = output->crtc;
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
wlr_drm_plane_renderer_free(renderer, crtc->planes[i]);
|
|
|
|
wlr_drm_plane_renderer_free(renderer, crtc->planes[i]);
|
|
|
@ -930,10 +999,6 @@ void wlr_drm_output_cleanup(struct wlr_drm_output *output, bool restore) {
|
|
|
|
output->possible_crtc = 0;
|
|
|
|
output->possible_crtc = 0;
|
|
|
|
/* Fallthrough */
|
|
|
|
/* Fallthrough */
|
|
|
|
case WLR_DRM_OUTPUT_NEEDS_MODESET:
|
|
|
|
case WLR_DRM_OUTPUT_NEEDS_MODESET:
|
|
|
|
output->state = WLR_DRM_OUTPUT_DISCONNECTED;
|
|
|
|
|
|
|
|
if (restore) {
|
|
|
|
|
|
|
|
restore_output(output, renderer->fd);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
wlr_log(L_INFO, "Emmiting destruction signal for '%s'",
|
|
|
|
wlr_log(L_INFO, "Emmiting destruction signal for '%s'",
|
|
|
|
output->output.name);
|
|
|
|
output->output.name);
|
|
|
|
wl_signal_emit(&backend->backend.events.output_remove, &output->output);
|
|
|
|
wl_signal_emit(&backend->backend.events.output_remove, &output->output);
|
|
|
@ -941,4 +1006,6 @@ void wlr_drm_output_cleanup(struct wlr_drm_output *output, bool restore) {
|
|
|
|
case WLR_DRM_OUTPUT_DISCONNECTED:
|
|
|
|
case WLR_DRM_OUTPUT_DISCONNECTED:
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
output->state = WLR_DRM_OUTPUT_DISCONNECTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|