2019-08-21 22:07:37 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2019-10-07 08:47:53 +02:00
|
|
|
#include "log.h"
|
2019-08-21 22:07:37 +02:00
|
|
|
#include "private.h"
|
|
|
|
|
2019-09-12 10:39:06 +02:00
|
|
|
struct liftoff_display *liftoff_display_create(int drm_fd)
|
2019-08-21 22:07:37 +02:00
|
|
|
{
|
2019-09-12 10:39:06 +02:00
|
|
|
struct liftoff_display *display;
|
2019-09-08 16:41:25 +02:00
|
|
|
drmModeRes *drm_res;
|
2019-08-21 22:07:37 +02:00
|
|
|
drmModePlaneRes *drm_plane_res;
|
|
|
|
uint32_t i;
|
|
|
|
|
|
|
|
display = calloc(1, sizeof(*display));
|
|
|
|
if (display == NULL) {
|
2019-10-19 12:35:14 +02:00
|
|
|
liftoff_log_errno(LIFTOFF_ERROR, "calloc");
|
2019-08-21 22:07:37 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2019-09-12 19:15:50 +02:00
|
|
|
|
|
|
|
liftoff_list_init(&display->planes);
|
|
|
|
liftoff_list_init(&display->outputs);
|
|
|
|
|
2019-08-21 22:07:37 +02:00
|
|
|
display->drm_fd = dup(drm_fd);
|
|
|
|
if (display->drm_fd < 0) {
|
2019-10-19 12:35:14 +02:00
|
|
|
liftoff_log_errno(LIFTOFF_ERROR, "dup");
|
2019-09-12 10:39:06 +02:00
|
|
|
liftoff_display_destroy(display);
|
2019-08-21 22:07:37 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-09-08 16:41:25 +02:00
|
|
|
drm_res = drmModeGetResources(drm_fd);
|
|
|
|
if (drm_res == NULL) {
|
2019-10-19 12:35:14 +02:00
|
|
|
liftoff_log_errno(LIFTOFF_ERROR, "drmModeGetResources");
|
2019-09-12 10:39:06 +02:00
|
|
|
liftoff_display_destroy(display);
|
2019-09-08 16:41:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
display->crtcs = malloc(drm_res->count_crtcs * sizeof(uint32_t));
|
|
|
|
if (display->crtcs == NULL) {
|
2019-10-19 12:35:14 +02:00
|
|
|
liftoff_log_errno(LIFTOFF_ERROR, "malloc");
|
2019-09-08 16:41:25 +02:00
|
|
|
drmModeFreeResources(drm_res);
|
2019-09-12 10:39:06 +02:00
|
|
|
liftoff_display_destroy(display);
|
2019-09-08 16:41:25 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
display->crtcs_len = drm_res->count_crtcs;
|
|
|
|
memcpy(display->crtcs, drm_res->crtcs,
|
|
|
|
drm_res->count_crtcs * sizeof(uint32_t));
|
|
|
|
|
|
|
|
drmModeFreeResources(drm_res);
|
|
|
|
|
2019-08-21 22:07:37 +02:00
|
|
|
/* TODO: allow users to choose which layers to hand over */
|
|
|
|
drm_plane_res = drmModeGetPlaneResources(drm_fd);
|
|
|
|
if (drm_plane_res == NULL) {
|
2019-10-19 12:35:14 +02:00
|
|
|
liftoff_log_errno(LIFTOFF_ERROR, "drmModeGetPlaneResources");
|
2019-09-12 10:39:06 +02:00
|
|
|
liftoff_display_destroy(display);
|
2019-08-21 22:07:37 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < drm_plane_res->count_planes; i++) {
|
2019-09-08 14:26:50 +02:00
|
|
|
if (plane_create(display, drm_plane_res->planes[i]) == NULL) {
|
2019-09-12 10:39:06 +02:00
|
|
|
liftoff_display_destroy(display);
|
2019-08-21 22:07:37 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
drmModeFreePlaneResources(drm_plane_res);
|
|
|
|
|
|
|
|
return display;
|
|
|
|
}
|
|
|
|
|
2019-09-12 10:39:06 +02:00
|
|
|
void liftoff_display_destroy(struct liftoff_display *display)
|
2019-08-21 22:07:37 +02:00
|
|
|
{
|
2019-09-12 10:39:06 +02:00
|
|
|
struct liftoff_plane *plane, *tmp;
|
2019-08-21 22:07:37 +02:00
|
|
|
|
|
|
|
close(display->drm_fd);
|
2019-09-12 10:39:06 +02:00
|
|
|
liftoff_list_for_each_safe(plane, tmp, &display->planes, link) {
|
2019-09-08 14:26:50 +02:00
|
|
|
plane_destroy(plane);
|
2019-08-21 22:07:37 +02:00
|
|
|
}
|
2019-09-08 16:41:25 +02:00
|
|
|
free(display->crtcs);
|
2019-08-21 22:07:37 +02:00
|
|
|
free(display);
|
|
|
|
}
|