From 95a553dc51029406f9b52227e88ebd9f67b203a5 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Mon, 1 May 2017 15:33:42 +1200 Subject: Moved headers to the correct place. --- backend/drm/drm.h | 54 -------------- backend/drm/event.h | 21 ------ backend/drm/main.c | 160 ------------------------------------------ backend/drm/otd.h | 44 ------------ backend/drm/session.h | 25 ------- backend/drm/udev.h | 9 --- include/backend/drm/drm.h | 54 ++++++++++++++ include/backend/drm/event.h | 21 ++++++ include/backend/drm/otd.h | 44 ++++++++++++ include/backend/drm/session.h | 25 +++++++ include/backend/drm/udev.h | 9 +++ 11 files changed, 153 insertions(+), 313 deletions(-) delete mode 100644 backend/drm/drm.h delete mode 100644 backend/drm/event.h delete mode 100644 backend/drm/main.c delete mode 100644 backend/drm/otd.h delete mode 100644 backend/drm/session.h delete mode 100644 backend/drm/udev.h create mode 100644 include/backend/drm/drm.h create mode 100644 include/backend/drm/event.h create mode 100644 include/backend/drm/otd.h create mode 100644 include/backend/drm/session.h create mode 100644 include/backend/drm/udev.h diff --git a/backend/drm/drm.h b/backend/drm/drm.h deleted file mode 100644 index 8744b440..00000000 --- a/backend/drm/drm.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef DRM_H -#define DRM_H - -#include -#include -#include -#include -#include - -enum otd_display_state { - OTD_DISP_INVALID, - OTD_DISP_DISCONNECTED, - OTD_DISP_NEEDS_MODESET, - OTD_DISP_CONNECTED, -}; - -struct otd_display { - struct otd *otd; - - enum otd_display_state state; - uint32_t connector; - char name[16]; - - size_t num_modes; - drmModeModeInfo *modes; - drmModeModeInfo *active_mode; - - uint32_t width; - uint32_t height; - - uint32_t crtc; - drmModeCrtc *old_crtc; - - struct gbm_surface *gbm; - EGLSurface *egl; - uint32_t fb_id; - - bool pageflip_pending; - bool cleanup; -}; - -bool init_renderer(struct otd *otd); -void destroy_renderer(struct otd *otd); - -void scan_connectors(struct otd *otd); -bool modeset_str(struct otd *otd, struct otd_display *disp, const char *str); -void destroy_display_renderer(struct otd *otd, struct otd_display *disp); - -void get_drm_event(struct otd *otd); - -void rendering_begin(struct otd_display *disp); -void rendering_end(struct otd_display *disp); - -#endif diff --git a/backend/drm/event.h b/backend/drm/event.h deleted file mode 100644 index fc4f6f9a..00000000 --- a/backend/drm/event.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef EVENT_H -#define EVENT_H - -#include - -enum otd_event_type { - OTD_EV_NONE, - OTD_EV_RENDER, - OTD_EV_DISPLAY_REM, - OTD_EV_DISPLAY_ADD, -}; - -struct otd_event { - enum otd_event_type type; - struct otd_display *display; -}; - -bool otd_get_event(struct otd *otd, struct otd_event *restrict ret); -bool event_add(struct otd *otd, struct otd_display *disp, enum otd_event_type type); - -#endif diff --git a/backend/drm/main.c b/backend/drm/main.c deleted file mode 100644 index aab11e19..00000000 --- a/backend/drm/main.c +++ /dev/null @@ -1,160 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "otd.h" -#include "drm.h" -#include "event.h" - -// I know this is pretty crappy, -// but it's just for the example's sake -struct { - char *name; - char *mode; -} displays[8]; -int num_displays = 0; - -noreturn void usage(const char *name, int ret) -{ - fprintf(stderr, "usage: %s [-o [-m ]]*\n" - "\n" - " -h \tDisplay this help text\n" - " -o \tWhich diplay to use. e.g. DVI-I-1.\n" - " -m \tWhich mode to use. It must come after an -o option.\n" - " \tMust be either 'preferred', 'current', widthxheight\n" - " \tor widthxheight@rate. Defaults to 'preferred'.\n" - "\n" - "example: %s -o DVI-I-1 -m 1920x1080@60 -o DP-1 -m 1920x1200\n", - name, name); - - exit(ret); -} - -void parse_args(int argc, char *argv[]) -{ - int c; - int i = -1; - - while ((c = getopt(argc, argv, "ho:m:")) != -1) { - switch (c) { - case 'h': - usage(argv[0], 0); - case 'o': - i = num_displays++; - - if (num_displays == 8) { - fprintf(stderr, "Too many displays\n"); - exit(1); - } - - displays[i].name = strdup(optarg); - break; - case 'm': - if (i == -1) { - fprintf(stderr, "A display is required first\n"); - exit(1); - } - - fprintf(stderr, "Assigned '%s' to '%s'\n", optarg, displays[i].name); - displays[i].mode = optarg; - i = -1; - break; - default: - usage(argv[0], 1); - } - } - - // Trailing args - if (optind != argc) { - usage(argv[0], 1); - } -} - -int main(int argc, char *argv[]) -{ - parse_args(argc, argv); - - struct otd *otd = otd_start(); - if (!otd) - return 1; - - float colour[3] = {1.0, 0.0, 0.0}; - int dec = 0; - - struct timespec start, now; - clock_gettime(CLOCK_MONOTONIC, &start); - struct timespec last = start; - - while (clock_gettime(CLOCK_MONOTONIC, &now) == 0 && - now.tv_sec < start.tv_sec + 10) { - - struct otd_event ev; - if (!otd_get_event(otd, &ev)) - continue; - - struct otd_display *disp = ev.display; - - switch (ev.type) { - case OTD_EV_RENDER: - rendering_begin(disp); - - // This is all just calculating the colours. - // It's not particularly important. - - long ms = (now.tv_sec - last.tv_sec) * 1000 + - (now.tv_nsec - last.tv_nsec) / 1000000; - - int inc = (dec + 1) % 3; - - colour[dec] -= ms / 2000.0f; - colour[inc] += ms / 2000.0f; - - if (colour[dec] < 0.0f) { - colour[dec] = 0.0f; - colour[inc] = 1.0f; - - dec = (dec + 1) % 3; - } - - last = now; - - glViewport(0, 0, disp->width, disp->height); - glClearColor(colour[0], colour[1], colour[2], 1.0f); - glClear(GL_COLOR_BUFFER_BIT); - - rendering_end(disp); - break; - case OTD_EV_DISPLAY_REM: - printf("%s removed\n", disp->name); - break; - case OTD_EV_DISPLAY_ADD: - printf("%s added\n", disp->name); - - const char *mode = NULL; - for (int i = 0; i < num_displays; ++i) { - if (strcmp(disp->name, displays[i].name) == 0) { - mode = displays[i].mode; - } - } - if (!mode) - mode = "preferred"; - - if (!modeset_str(otd, ev.display, mode)) { - fprintf(stderr, "Modesetting %s failed\n", disp->name); - goto out; - } - break; - default: - break; - } - } - -out: - otd_finish(otd); -} diff --git a/backend/drm/otd.h b/backend/drm/otd.h deleted file mode 100644 index eef0e991..00000000 --- a/backend/drm/otd.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef LIBOTD_H -#define LIBOTD_H - -#include -#include -#include -#include -#include - -#include "session.h" - -struct otd { - int fd; - bool paused; - - // Priority Queue (Max-heap) - size_t event_cap; - size_t event_len; - struct otd_event *events; - - size_t display_len; - struct otd_display *displays; - - uint32_t taken_crtcs; - - struct gbm_device *gbm; - struct { - EGLDisplay disp; - EGLConfig conf; - EGLContext context; - } egl; - - struct otd_session session; - - struct udev *udev; - struct udev_monitor *mon; - int udev_fd; - char *drm_path; -}; - -struct otd *otd_start(void); -void otd_finish(struct otd *otd); - -#endif diff --git a/backend/drm/session.h b/backend/drm/session.h deleted file mode 100644 index c21900e9..00000000 --- a/backend/drm/session.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef SESSION_H -#define SESSION_H - -#include -#include - -struct otd_session { - char *id; - char *path; - char *seat; - - sd_bus *bus; -}; - -struct otd; -bool otd_new_session(struct otd *otd); -void otd_close_session(struct otd *otd); - -int take_device(struct otd *restrict otd, - const char *restrict path, - bool *restrict paused_out); - -void release_device(struct otd *otd, int fd); - -#endif diff --git a/backend/drm/udev.h b/backend/drm/udev.h deleted file mode 100644 index 9bd4c0d0..00000000 --- a/backend/drm/udev.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef UDEV_H -#define UDEV_H - -bool otd_udev_start(struct otd *otd); -void otd_udev_finish(struct otd *otd); -void otd_udev_find_gpu(struct otd *otd); -void otd_udev_event(struct otd *otd); - -#endif diff --git a/include/backend/drm/drm.h b/include/backend/drm/drm.h new file mode 100644 index 00000000..8744b440 --- /dev/null +++ b/include/backend/drm/drm.h @@ -0,0 +1,54 @@ +#ifndef DRM_H +#define DRM_H + +#include +#include +#include +#include +#include + +enum otd_display_state { + OTD_DISP_INVALID, + OTD_DISP_DISCONNECTED, + OTD_DISP_NEEDS_MODESET, + OTD_DISP_CONNECTED, +}; + +struct otd_display { + struct otd *otd; + + enum otd_display_state state; + uint32_t connector; + char name[16]; + + size_t num_modes; + drmModeModeInfo *modes; + drmModeModeInfo *active_mode; + + uint32_t width; + uint32_t height; + + uint32_t crtc; + drmModeCrtc *old_crtc; + + struct gbm_surface *gbm; + EGLSurface *egl; + uint32_t fb_id; + + bool pageflip_pending; + bool cleanup; +}; + +bool init_renderer(struct otd *otd); +void destroy_renderer(struct otd *otd); + +void scan_connectors(struct otd *otd); +bool modeset_str(struct otd *otd, struct otd_display *disp, const char *str); +void destroy_display_renderer(struct otd *otd, struct otd_display *disp); + +void get_drm_event(struct otd *otd); + +void rendering_begin(struct otd_display *disp); +void rendering_end(struct otd_display *disp); + +#endif diff --git a/include/backend/drm/event.h b/include/backend/drm/event.h new file mode 100644 index 00000000..fc4f6f9a --- /dev/null +++ b/include/backend/drm/event.h @@ -0,0 +1,21 @@ +#ifndef EVENT_H +#define EVENT_H + +#include + +enum otd_event_type { + OTD_EV_NONE, + OTD_EV_RENDER, + OTD_EV_DISPLAY_REM, + OTD_EV_DISPLAY_ADD, +}; + +struct otd_event { + enum otd_event_type type; + struct otd_display *display; +}; + +bool otd_get_event(struct otd *otd, struct otd_event *restrict ret); +bool event_add(struct otd *otd, struct otd_display *disp, enum otd_event_type type); + +#endif diff --git a/include/backend/drm/otd.h b/include/backend/drm/otd.h new file mode 100644 index 00000000..eef0e991 --- /dev/null +++ b/include/backend/drm/otd.h @@ -0,0 +1,44 @@ +#ifndef LIBOTD_H +#define LIBOTD_H + +#include +#include +#include +#include +#include + +#include "session.h" + +struct otd { + int fd; + bool paused; + + // Priority Queue (Max-heap) + size_t event_cap; + size_t event_len; + struct otd_event *events; + + size_t display_len; + struct otd_display *displays; + + uint32_t taken_crtcs; + + struct gbm_device *gbm; + struct { + EGLDisplay disp; + EGLConfig conf; + EGLContext context; + } egl; + + struct otd_session session; + + struct udev *udev; + struct udev_monitor *mon; + int udev_fd; + char *drm_path; +}; + +struct otd *otd_start(void); +void otd_finish(struct otd *otd); + +#endif diff --git a/include/backend/drm/session.h b/include/backend/drm/session.h new file mode 100644 index 00000000..c21900e9 --- /dev/null +++ b/include/backend/drm/session.h @@ -0,0 +1,25 @@ +#ifndef SESSION_H +#define SESSION_H + +#include +#include + +struct otd_session { + char *id; + char *path; + char *seat; + + sd_bus *bus; +}; + +struct otd; +bool otd_new_session(struct otd *otd); +void otd_close_session(struct otd *otd); + +int take_device(struct otd *restrict otd, + const char *restrict path, + bool *restrict paused_out); + +void release_device(struct otd *otd, int fd); + +#endif diff --git a/include/backend/drm/udev.h b/include/backend/drm/udev.h new file mode 100644 index 00000000..9bd4c0d0 --- /dev/null +++ b/include/backend/drm/udev.h @@ -0,0 +1,9 @@ +#ifndef UDEV_H +#define UDEV_H + +bool otd_udev_start(struct otd *otd); +void otd_udev_finish(struct otd *otd); +void otd_udev_find_gpu(struct otd *otd); +void otd_udev_event(struct otd *otd); + +#endif -- cgit v1.2.3