2017-05-01 05:49:18 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2017-05-02 01:00:25 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2017-05-01 05:49:18 +00:00
|
|
|
|
|
|
|
#include "backend/drm/backend.h"
|
|
|
|
#include "backend/drm/drm.h"
|
|
|
|
#include "backend/drm/event.h"
|
|
|
|
#include "backend/drm/session.h"
|
|
|
|
#include "backend/drm/udev.h"
|
2017-05-02 01:00:25 +00:00
|
|
|
#include "common/log.h"
|
2017-05-01 05:49:18 +00:00
|
|
|
|
|
|
|
struct wlr_drm_backend *wlr_drm_backend_init(void)
|
|
|
|
{
|
|
|
|
struct wlr_drm_backend *backend = calloc(1, sizeof *backend);
|
2017-05-02 01:00:25 +00:00
|
|
|
if (!backend) {
|
|
|
|
wlr_log(L_ERROR, "Allocation failed: %s", strerror(errno));
|
2017-05-01 05:49:18 +00:00
|
|
|
return NULL;
|
2017-05-02 01:00:25 +00:00
|
|
|
}
|
2017-05-01 05:49:18 +00:00
|
|
|
|
|
|
|
if (!wlr_session_start(&backend->session)) {
|
2017-05-02 01:00:25 +00:00
|
|
|
wlr_log(L_ERROR, "Failed to start session");
|
2017-05-01 05:49:18 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wlr_udev_init(&backend->udev)) {
|
2017-05-02 01:00:25 +00:00
|
|
|
wlr_log(L_ERROR, "Failed to start udev");
|
2017-05-01 05:49:18 +00:00
|
|
|
goto error_session;
|
|
|
|
}
|
|
|
|
|
|
|
|
backend->fd = wlr_udev_find_gpu(&backend->udev, &backend->session);
|
|
|
|
if (backend->fd == -1) {
|
2017-05-02 01:00:25 +00:00
|
|
|
wlr_log(L_ERROR, "Failed to open DRM device");
|
2017-05-01 05:49:18 +00:00
|
|
|
goto error_udev;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wlr_drm_renderer_init(&backend->renderer, backend, backend->fd)) {
|
2017-05-02 01:00:25 +00:00
|
|
|
wlr_log(L_ERROR, "Failed to initialize renderer");
|
2017-05-01 05:49:18 +00:00
|
|
|
goto error_fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
wlr_drm_scan_connectors(backend);
|
|
|
|
|
|
|
|
return backend;
|
|
|
|
|
|
|
|
error_fd:
|
|
|
|
wlr_session_release_device(&backend->session, backend->fd);
|
|
|
|
error_udev:
|
|
|
|
wlr_udev_free(&backend->udev);
|
|
|
|
error_session:
|
|
|
|
wlr_session_end(&backend->session);
|
|
|
|
error:
|
|
|
|
free(backend);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_drm_backend_free(struct wlr_drm_backend *backend)
|
|
|
|
{
|
|
|
|
if (!backend)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < backend->display_len; ++i) {
|
2017-05-02 01:00:25 +00:00
|
|
|
wlr_drm_display_free(&backend->displays[i], true);
|
2017-05-01 05:49:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wlr_drm_renderer_free(&backend->renderer);
|
|
|
|
wlr_udev_free(&backend->udev);
|
|
|
|
wlr_session_release_device(&backend->session, backend->fd);
|
|
|
|
wlr_session_end(&backend->session);
|
|
|
|
|
|
|
|
free(backend->events);
|
|
|
|
free(backend->displays);
|
|
|
|
free(backend);
|
|
|
|
}
|
|
|
|
|