mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2024-11-25 00:22:25 +00:00
Removed old session code from DRM backend.
This commit is contained in:
parent
762ac7f4c0
commit
81998fdc98
@ -11,7 +11,6 @@ add_library(wlr-backend
|
||||
wayland/wl_output.c
|
||||
drm/backend.c
|
||||
drm/drm.c
|
||||
drm/session.c
|
||||
drm/udev.c
|
||||
)
|
||||
|
||||
|
@ -4,17 +4,16 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <wlr/session.h>
|
||||
#include <wlr/common/list.h>
|
||||
|
||||
#include "backend/drm/backend.h"
|
||||
#include "backend/drm/drm.h"
|
||||
#include "backend/drm/session.h"
|
||||
#include "backend/drm/udev.h"
|
||||
#include "common/log.h"
|
||||
|
||||
struct wlr_drm_backend *wlr_drm_backend_init(struct wl_listener *add,
|
||||
struct wl_listener *rem,
|
||||
struct wl_listener *render)
|
||||
struct wlr_drm_backend *wlr_drm_backend_init(struct wlr_session *session,
|
||||
struct wl_listener *add, struct wl_listener *rem, struct wl_listener *render)
|
||||
{
|
||||
struct wlr_drm_backend *backend = calloc(1, sizeof *backend);
|
||||
if (!backend) {
|
||||
@ -22,6 +21,8 @@ struct wlr_drm_backend *wlr_drm_backend_init(struct wl_listener *add,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
backend->session = session;
|
||||
|
||||
backend->displays = list_create();
|
||||
if (!backend->displays) {
|
||||
wlr_log(L_ERROR, "Failed to allocate list");
|
||||
@ -34,17 +35,12 @@ struct wlr_drm_backend *wlr_drm_backend_init(struct wl_listener *add,
|
||||
goto error_list;
|
||||
}
|
||||
|
||||
if (!wlr_session_start(&backend->session)) {
|
||||
wlr_log(L_ERROR, "Failed to start session");
|
||||
if (!wlr_udev_init(backend)) {
|
||||
wlr_log(L_ERROR, "Failed to start udev");
|
||||
goto error_loop;
|
||||
}
|
||||
|
||||
if (!wlr_udev_init(backend)) {
|
||||
wlr_log(L_ERROR, "Failed to start udev");
|
||||
goto error_session;
|
||||
}
|
||||
|
||||
backend->fd = wlr_udev_find_gpu(&backend->udev, &backend->session);
|
||||
backend->fd = wlr_udev_find_gpu(&backend->udev, backend->session);
|
||||
if (backend->fd == -1) {
|
||||
wlr_log(L_ERROR, "Failed to open DRM device");
|
||||
goto error_udev;
|
||||
@ -71,11 +67,9 @@ struct wlr_drm_backend *wlr_drm_backend_init(struct wl_listener *add,
|
||||
return backend;
|
||||
|
||||
error_fd:
|
||||
wlr_session_release_device(&backend->session, backend->fd);
|
||||
wlr_session_close_file(backend->session, backend->fd);
|
||||
error_udev:
|
||||
wlr_udev_free(&backend->udev);
|
||||
error_session:
|
||||
wlr_session_end(&backend->session);
|
||||
error_loop:
|
||||
wl_event_loop_destroy(backend->event_loop);
|
||||
error_list:
|
||||
@ -101,8 +95,8 @@ void wlr_drm_backend_free(struct wlr_drm_backend *backend)
|
||||
|
||||
wlr_drm_renderer_free(&backend->renderer);
|
||||
wlr_udev_free(&backend->udev);
|
||||
wlr_session_release_device(&backend->session, backend->fd);
|
||||
wlr_session_end(&backend->session);
|
||||
wlr_session_close_file(backend->session, backend->fd);
|
||||
wlr_session_finish(backend->session);
|
||||
|
||||
wl_event_source_remove(backend->event_src.drm);
|
||||
wl_event_source_remove(backend->event_src.udev);
|
||||
|
@ -1,219 +0,0 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <systemd/sd-bus.h>
|
||||
#include <systemd/sd-login.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/sysmacros.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "backend/drm/backend.h"
|
||||
#include "backend/drm/session.h"
|
||||
#include "common/log.h"
|
||||
|
||||
int wlr_session_take_device(struct wlr_session *restrict session,
|
||||
const char *restrict path,
|
||||
bool *restrict paused_out)
|
||||
{
|
||||
int ret;
|
||||
int fd = -1;
|
||||
sd_bus_message *msg = NULL;
|
||||
sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||
|
||||
struct stat st;
|
||||
if (stat(path, &st) < 0) {
|
||||
wlr_log(L_ERROR, "Failed to stat '%s'", path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = sd_bus_call_method(session->bus,
|
||||
"org.freedesktop.login1",
|
||||
session->path,
|
||||
"org.freedesktop.login1.Session",
|
||||
"TakeDevice",
|
||||
&error, &msg,
|
||||
"uu", major(st.st_rdev), minor(st.st_rdev));
|
||||
if (ret < 0) {
|
||||
wlr_log(L_ERROR, "Failed to take device '%s': %s", path, error.message);
|
||||
goto error;
|
||||
}
|
||||
|
||||
int paused = 0;
|
||||
ret = sd_bus_message_read(msg, "hb", &fd, &paused);
|
||||
if (ret < 0) {
|
||||
wlr_log(L_ERROR, "Failed to parse DBus response for '%s': %s",
|
||||
path, 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 '%s': %s",
|
||||
path, strerror(errno));
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (paused_out)
|
||||
*paused_out = paused;
|
||||
|
||||
error:
|
||||
sd_bus_error_free(&error);
|
||||
sd_bus_message_unref(msg);
|
||||
return fd;
|
||||
}
|
||||
|
||||
void wlr_session_release_device(struct wlr_session *session, int fd)
|
||||
{
|
||||
int ret;
|
||||
sd_bus_message *msg = NULL;
|
||||
sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||
|
||||
struct stat st;
|
||||
if (fstat(fd, &st) < 0) {
|
||||
wlr_log(L_ERROR, "Failed to stat device '%d'", fd);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = sd_bus_call_method(session->bus,
|
||||
"org.freedesktop.login1",
|
||||
session->path,
|
||||
"org.freedesktop.login1.Session",
|
||||
"ReleaseDevice",
|
||||
&error, &msg,
|
||||
"uu", major(st.st_rdev), minor(st.st_rdev));
|
||||
if (ret < 0)
|
||||
wlr_log(L_ERROR, "Failed to release device '%d'", fd);
|
||||
|
||||
sd_bus_error_free(&error);
|
||||
sd_bus_message_unref(msg);
|
||||
}
|
||||
|
||||
static bool session_activate(struct wlr_session *session)
|
||||
{
|
||||
int ret;
|
||||
sd_bus_message *msg = NULL;
|
||||
sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||
|
||||
ret = sd_bus_call_method(session->bus,
|
||||
"org.freedesktop.login1",
|
||||
session->path,
|
||||
"org.freedesktop.login1.Session",
|
||||
"Activate",
|
||||
&error, &msg,
|
||||
"");
|
||||
if (ret < 0)
|
||||
wlr_log(L_ERROR, "Failed to activate session");
|
||||
|
||||
sd_bus_error_free(&error);
|
||||
sd_bus_message_unref(msg);
|
||||
return ret >= 0;
|
||||
}
|
||||
|
||||
static bool take_control(struct wlr_session *session)
|
||||
{
|
||||
int ret;
|
||||
sd_bus_message *msg = NULL;
|
||||
sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||
|
||||
ret = sd_bus_call_method(session->bus,
|
||||
"org.freedesktop.login1",
|
||||
session->path,
|
||||
"org.freedesktop.login1.Session",
|
||||
"TakeControl",
|
||||
&error, &msg,
|
||||
"b", false);
|
||||
if (ret < 0)
|
||||
wlr_log(L_ERROR, "Failed to take control of session");
|
||||
|
||||
sd_bus_error_free(&error);
|
||||
sd_bus_message_unref(msg);
|
||||
return ret >= 0;
|
||||
}
|
||||
|
||||
static void release_control(struct wlr_session *session)
|
||||
{
|
||||
int ret;
|
||||
sd_bus_message *msg = NULL;
|
||||
sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||
|
||||
ret = sd_bus_call_method(session->bus,
|
||||
"org.freedesktop.login1",
|
||||
session->path,
|
||||
"org.freedesktop.login1.Session",
|
||||
"ReleaseControl",
|
||||
&error, &msg,
|
||||
"");
|
||||
if (ret < 0)
|
||||
wlr_log(L_ERROR, "Failed to release control of session");
|
||||
|
||||
sd_bus_error_free(&error);
|
||||
sd_bus_message_unref(msg);
|
||||
}
|
||||
|
||||
void wlr_session_end(struct wlr_session *session)
|
||||
{
|
||||
release_control(session);
|
||||
|
||||
sd_bus_unref(session->bus);
|
||||
free(session->id);
|
||||
free(session->path);
|
||||
free(session->seat);
|
||||
}
|
||||
|
||||
bool wlr_session_start(struct wlr_session *session)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = sd_pid_get_session(getpid(), &session->id);
|
||||
if (ret < 0) {
|
||||
wlr_log(L_ERROR, "Failed to get session id: %s", strerror(-ret));
|
||||
goto error;
|
||||
}
|
||||
|
||||
ret = sd_session_get_seat(session->id, &session->seat);
|
||||
if (ret < 0) {
|
||||
wlr_log(L_ERROR, "Failed to get seat id: %s", strerror(-ret));
|
||||
goto error;
|
||||
}
|
||||
|
||||
// This could be done using asprintf, but I don't want to define _GNU_SOURCE
|
||||
|
||||
const char *fmt = "/org/freedesktop/login1/session/%s";
|
||||
int len = snprintf(NULL, 0, fmt, session->id);
|
||||
|
||||
session->path = malloc(len + 1);
|
||||
if (!session->path)
|
||||
goto error;
|
||||
|
||||
sprintf(session->path, fmt, session->id);
|
||||
|
||||
ret = sd_bus_default_system(&session->bus);
|
||||
if (ret < 0) {
|
||||
wlr_log(L_ERROR, "Failed to open DBus connection: %s", strerror(-ret));
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!session_activate(session))
|
||||
goto error_bus;
|
||||
|
||||
if (!take_control(session))
|
||||
goto error_bus;
|
||||
|
||||
return true;
|
||||
|
||||
error_bus:
|
||||
sd_bus_unref(session->bus);
|
||||
|
||||
error:
|
||||
free(session->path);
|
||||
free(session->id);
|
||||
free(session->seat);
|
||||
return false;
|
||||
}
|
@ -9,9 +9,10 @@
|
||||
#include <xf86drmMode.h>
|
||||
#include <wayland-server.h>
|
||||
|
||||
#include <wlr/session.h>
|
||||
|
||||
#include "backend/drm/backend.h"
|
||||
#include "backend/drm/udev.h"
|
||||
#include "backend/drm/session.h"
|
||||
#include "backend/drm/drm.h"
|
||||
#include "common/log.h"
|
||||
|
||||
@ -26,7 +27,7 @@ static bool device_is_kms(struct wlr_udev *udev,
|
||||
if (!path)
|
||||
return false;
|
||||
|
||||
fd = wlr_session_take_device(session, path, NULL);
|
||||
fd = wlr_session_open_file(session, path);
|
||||
if (fd < 0)
|
||||
return false;
|
||||
|
||||
@ -39,7 +40,7 @@ static bool device_is_kms(struct wlr_udev *udev,
|
||||
goto out_res;
|
||||
|
||||
if (*fd_out >= 0) {
|
||||
wlr_session_release_device(session, *fd_out);
|
||||
wlr_session_close_file(session, *fd_out);
|
||||
free(udev->drm_path);
|
||||
}
|
||||
|
||||
@ -52,7 +53,7 @@ static bool device_is_kms(struct wlr_udev *udev,
|
||||
out_res:
|
||||
drmModeFreeResources(res);
|
||||
out_fd:
|
||||
wlr_session_release_device(session, fd);
|
||||
wlr_session_close_file(session, fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -79,6 +80,7 @@ int wlr_udev_find_gpu(struct wlr_udev *udev, struct wlr_session *session)
|
||||
if (!dev)
|
||||
continue;
|
||||
|
||||
/*
|
||||
const char *seat = udev_device_get_property_value(dev, "ID_SEAT");
|
||||
if (!seat)
|
||||
seat = "seat0";
|
||||
@ -86,6 +88,7 @@ int wlr_udev_find_gpu(struct wlr_udev *udev, struct wlr_session *session)
|
||||
udev_device_unref(dev);
|
||||
continue;
|
||||
}
|
||||
*/
|
||||
|
||||
struct udev_device *pci =
|
||||
udev_device_get_parent_with_subsystem_devtype(dev, "pci", NULL);
|
||||
|
@ -12,4 +12,5 @@ add_executable(example-drm
|
||||
|
||||
target_link_libraries(example-drm
|
||||
wlr-backend
|
||||
wlr-session
|
||||
)
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <GLES3/gl3.h>
|
||||
|
||||
#include <wlr/backend/drm.h>
|
||||
#include <wlr/session.h>
|
||||
|
||||
struct state {
|
||||
float color[3];
|
||||
@ -92,7 +93,13 @@ int main()
|
||||
wl_list_init(&state.render.link);
|
||||
clock_gettime(CLOCK_MONOTONIC, &state.last_frame);
|
||||
|
||||
struct wlr_drm_backend *wlr = wlr_drm_backend_init(&state.add, &state.rem, &state.render);
|
||||
struct wlr_session *session = wlr_session_start();
|
||||
if (!session) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct wlr_drm_backend *wlr = wlr_drm_backend_init(session,
|
||||
&state.add, &state.rem, &state.render);
|
||||
|
||||
bool done = false;
|
||||
struct wl_event_loop *event_loop = wlr_drm_backend_get_event_loop(wlr);
|
||||
|
@ -8,10 +8,10 @@
|
||||
#include <libudev.h>
|
||||
#include <wayland-server.h>
|
||||
|
||||
#include <wlr/session.h>
|
||||
#include <wlr/common/list.h>
|
||||
#include <wlr/backend/drm.h>
|
||||
|
||||
#include "session.h"
|
||||
#include "udev.h"
|
||||
#include "event.h"
|
||||
#include "drm.h"
|
||||
@ -38,13 +38,12 @@ struct wlr_drm_backend {
|
||||
uint32_t taken_crtcs;
|
||||
|
||||
struct wlr_drm_renderer renderer;
|
||||
struct wlr_session session;
|
||||
struct wlr_session *session;
|
||||
struct wlr_udev udev;
|
||||
};
|
||||
|
||||
struct wlr_drm_backend *wlr_drm_backend_init(struct wl_listener *add,
|
||||
struct wl_listener *rem,
|
||||
struct wl_listener *render);
|
||||
struct wlr_drm_backend *wlr_drm_backend_init(struct wlr_session *session,
|
||||
struct wl_listener *add, struct wl_listener *rem, struct wl_listener *render);
|
||||
void wlr_drm_backend_free(struct wlr_drm_backend *backend);
|
||||
|
||||
#endif
|
||||
|
@ -1,24 +0,0 @@
|
||||
#ifndef SESSION_H
|
||||
#define SESSION_H
|
||||
|
||||
#include <systemd/sd-bus.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
struct wlr_session {
|
||||
sd_bus *bus;
|
||||
|
||||
char *id;
|
||||
char *path;
|
||||
char *seat;
|
||||
};
|
||||
|
||||
bool wlr_session_start(struct wlr_session *session);
|
||||
void wlr_session_end(struct wlr_session *session);
|
||||
|
||||
int wlr_session_take_device(struct wlr_session *restrict session,
|
||||
const char *restrict path,
|
||||
bool *restrict paused_out);
|
||||
|
||||
void wlr_session_release_device(struct wlr_session *session, int fd);
|
||||
|
||||
#endif
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include <libudev.h>
|
||||
|
||||
#include "backend/drm/session.h"
|
||||
#include <wlr/session.h>
|
||||
|
||||
struct wlr_udev {
|
||||
struct udev *udev;
|
||||
|
@ -2,13 +2,13 @@
|
||||
#define WLR_BACKEND_DRM_H
|
||||
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/session.h>
|
||||
|
||||
struct wlr_drm_backend;
|
||||
struct wlr_drm_display;
|
||||
|
||||
struct wlr_drm_backend *wlr_drm_backend_init(struct wl_listener *add,
|
||||
struct wl_listener *rem,
|
||||
struct wl_listener *render);
|
||||
struct wlr_drm_backend *wlr_drm_backend_init(struct wlr_session *session,
|
||||
struct wl_listener *add, struct wl_listener *rem, struct wl_listener *render);
|
||||
void wlr_drm_backend_free(struct wlr_drm_backend *backend);
|
||||
|
||||
struct wl_event_loop *wlr_drm_backend_get_event_loop(struct wlr_drm_backend *backend);
|
||||
|
@ -200,6 +200,9 @@ static struct wlr_session *logind_session_start(void) {
|
||||
if (!take_control(session))
|
||||
goto error_bus;
|
||||
|
||||
wl_log(L_INFO, "Successfully loaded logind session");
|
||||
|
||||
session->base.iface = session_logind_iface;
|
||||
return &session->base;
|
||||
|
||||
error_bus:
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include <stddef.h>
|
||||
|
||||
#include <wlr/session.h>
|
||||
#include <stdarg.h>
|
||||
#include "common/log.h"
|
||||
#include "session/interface.h"
|
||||
|
||||
static const struct session_interface *ifaces[] = {
|
||||
@ -20,6 +22,7 @@ struct wlr_session *wlr_session_start(void) {
|
||||
}
|
||||
}
|
||||
|
||||
wlr_log(L_ERROR, "Failed to load session backend");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user