Working commit

This commit is contained in:
Scott Anderson 2017-05-14 01:12:47 +12:00
parent c88f252580
commit 058b8bdf27
10 changed files with 133 additions and 13 deletions

View file

@ -37,6 +37,29 @@ static struct wlr_backend_impl backend_impl = {
.destroy = wlr_drm_backend_destroy
};
static void device_paused(struct wl_listener *listener, void *data) {
struct wlr_backend_state *backend = wl_container_of(listener, backend, device_paused);
// TODO: Actually pause the renderer or something.
// We currently just expect it to fail its next pageflip.
(void)backend;
}
static void device_resumed(struct wl_listener *listener, void *data) {
struct wlr_backend_state *drm = wl_container_of(listener, drm, device_paused);
int *new_fd = data;
close(drm->fd);
drm->fd = *new_fd;
drm->renderer.fd = *new_fd;
for (size_t i = 0; i < drm->outputs->length; ++i) {
struct wlr_output_state *output = drm->outputs->items[i];
wlr_drm_output_draw_blank(output);
}
}
struct wlr_backend *wlr_drm_backend_create(struct wl_display *display,
struct wlr_session *session) {
struct wlr_backend_state *state = calloc(1, sizeof(struct wlr_backend_state));
@ -79,6 +102,15 @@ struct wlr_backend *wlr_drm_backend_create(struct wl_display *display,
goto error_fd;
}
wl_list_init(&state->device_paused.link);
wl_list_init(&state->device_paused.link);
state->device_paused.notify = device_paused;
state->device_resumed.notify = device_resumed;
wl_signal_add(&session->device_paused, &state->device_paused);
wl_signal_add(&session->device_resumed, &state->device_resumed);
// TODO: what is the difference between the per-output renderer and this
// one?
if (!wlr_drm_renderer_init(&state->renderer, state->fd)) {

View file

@ -474,3 +474,31 @@ void wlr_drm_output_dpms(int fd, struct wlr_output_state *output, bool screen_on
DRM_MODE_DPMS_STANDBY);
}
}
void wlr_drm_output_draw_blank(struct wlr_output_state *output) {
if (output->state != DRM_OUTPUT_CONNECTED) {
return;
}
struct wlr_drm_renderer *renderer = output->renderer;
eglMakeCurrent(renderer->egl.display, output->egl, output->egl, renderer->egl.context);
glViewport(0, 0, output->width, output->height);
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
eglSwapBuffers(renderer->egl.display, output->egl);
struct gbm_bo *bo = gbm_surface_lock_front_buffer(output->gbm);
uint32_t fb_id = get_fb_for_bo(renderer->fd, bo);
drmModeSetCrtc(renderer->fd, output->crtc, fb_id, 0, 0,
&output->connector, 1, &output->wlr_output->current_mode->state->mode);
drmModePageFlip(renderer->fd, output->crtc, fb_id,
DRM_MODE_PAGE_FLIP_EVENT, output);
gbm_surface_release_buffer(output->gbm, bo);
wlr_log(L_INFO, "Drew blank frame");
}

View file

@ -129,7 +129,7 @@ int main() {
struct wl_event_source *timer_vt = wl_event_loop_add_timer(event_loop,
timer_change_vt, session);
wl_event_source_timer_update(timer, 30000);
wl_event_source_timer_update(timer, 15000);
wl_event_source_timer_update(timer_vt, 5000);
while (!done) {

View file

@ -23,6 +23,9 @@ struct wlr_backend_state {
struct wlr_backend *backend;
struct wl_event_source *drm_event;
struct wl_listener device_paused;
struct wl_listener device_resumed;
uint32_t taken_crtcs;
list_t *outputs;

View file

@ -60,4 +60,6 @@ void wlr_drm_output_dpms(int fd, struct wlr_output_state *output, bool screen_on
void wlr_drm_scan_connectors(struct wlr_backend_state *state);
int wlr_drm_event(int fd, uint32_t mask, void *data);
void wlr_drm_output_draw_blank(struct wlr_output_state *output);
#endif

View file

@ -1,7 +1,7 @@
#ifndef WLR_SESSION_INTERFACE_H
#define WLR_SESSION_INTERFACE_H
struct wlr_session;
#include <wlr/session.h>
struct session_interface {
struct wlr_session *(*start)(struct wl_display *disp);
@ -12,10 +12,6 @@ struct session_interface {
bool (*change_vt)(struct wlr_session *session, int vt);
};
struct wlr_session {
struct session_interface iface;
};
extern const struct session_interface session_logind_iface;
extern const struct session_interface session_direct_iface;

View file

@ -3,7 +3,14 @@
#include <wayland-server.h>
struct wlr_session;
struct session_interface;
struct wlr_session {
const struct session_interface *iface;
struct wl_signal device_paused;
struct wl_signal device_resumed;
};
struct wlr_session *wlr_session_start(struct wl_display *disp);
void wlr_session_finish(struct wlr_session *session);

View file

@ -44,7 +44,9 @@ static struct wlr_session *direct_session_start(struct wl_display *disp) {
wlr_log(L_INFO, "Successfully loaded direct session");
session->base.iface = session_direct_iface;
session->base.iface = &session_direct_iface;
wl_signal_init(&session->base.device_paused);
wl_signal_init(&session->base.device_resumed);
return &session->base;
}

View file

@ -187,11 +187,59 @@ static int session_removed(sd_bus_message *msg, void *userdata, sd_bus_error *re
static int pause_device(sd_bus_message *msg, void *userdata, sd_bus_error *ret_error) {
wlr_log(L_INFO, "PauseDevice signal received");
struct logind_session *session = userdata;
int ret;
uint32_t major, minor;
ret = sd_bus_message_read(msg, "uu", &major, &minor);
if (ret < 0) {
wlr_log(L_ERROR, "Failed to parse D-Bus response for PauseDevice: %s",
strerror(-ret));
goto error;
}
dev_t dev = makedev(major, minor);
wl_signal_emit(&session->base.device_paused, &dev);
ret = sd_bus_call_method(session->bus, "org.freedesktop.login1",
session->path, "org.freedesktop.login1.Session", "PauseDeviceComplete",
ret_error, &msg, "uu", major, minor);
if (ret < 0) {
wlr_log(L_ERROR, "Failed to send PauseDeviceComplete signal");
}
error:
return 0;
}
static int resume_device(sd_bus_message *msg, void *userdata, sd_bus_error *ret_error) {
wlr_log(L_INFO, "ResumeDevice signal received");
struct logind_session *session = userdata;
int ret;
int fd;
uint32_t major, minor;
ret = sd_bus_message_read(msg, "uuh", &major, &minor, &fd);
if (ret < 0) {
wlr_log(L_ERROR, "Failed to parse D-Bus response for ResumeDevice: %s",
strerror(-ret));
goto error;
}
// The original fd seem to be closed when the message is freed
// so we just clone it.
fd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
if (fd == -1) {
wlr_log(L_ERROR, "Failed to clone file descriptor for ResumeDevice: %s",
strerror(errno));
goto error;
}
// TODO: Use major/minor to make sure the right devices are getting signals
wl_signal_emit(&session->base.device_resumed, &fd);
error:
return 0;
}
@ -289,7 +337,9 @@ static struct wlr_session *logind_session_start(struct wl_display *disp) {
wlr_log(L_INFO, "Successfully loaded logind session");
session->base.iface = session_logind_iface;
session->base.iface = &session_logind_iface;
wl_signal_init(&session->base.device_paused);
wl_signal_init(&session->base.device_resumed);
return &session->base;
error_bus:

View file

@ -28,19 +28,19 @@ struct wlr_session *wlr_session_start(struct wl_display *disp) {
}
void wlr_session_finish(struct wlr_session *session) {
session->iface.finish(session);
session->iface->finish(session);
};
int wlr_session_open_file(struct wlr_session *restrict session,
const char *restrict path) {
return session->iface.open(session, path);
return session->iface->open(session, path);
}
void wlr_session_close_file(struct wlr_session *session, int fd) {
session->iface.close(session, fd);
session->iface->close(session, fd);
}
bool wlr_session_change_vt(struct wlr_session *session, int vt) {
return session->iface.change_vt(session, vt);
return session->iface->change_vt(session, vt);
}