aboutsummaryrefslogtreecommitdiff
path: root/backend/drm
diff options
context:
space:
mode:
authorScott Anderson <ascent12@hotmail.com>2017-05-03 17:49:03 +1200
committerScott Anderson <ascent12@hotmail.com>2017-05-03 17:49:03 +1200
commit18387468bb9936d0e311c4a46535cfa93df277dc (patch)
treea2a97bc72de5b5e6118a88c1712cc666173bf1f4 /backend/drm
parent15d247bf3455904bf2262d2bf5d27645c03c9399 (diff)
Renamed 'wlr_drm_display' to 'wlr_drm_output'
Diffstat (limited to 'backend/drm')
-rw-r--r--backend/drm/backend.c30
-rw-r--r--backend/drm/drm.c283
2 files changed, 155 insertions, 158 deletions
diff --git a/backend/drm/backend.c b/backend/drm/backend.c
index 9f9a02c7..03e34d97 100644
--- a/backend/drm/backend.c
+++ b/backend/drm/backend.c
@@ -23,8 +23,8 @@ struct wlr_drm_backend *wlr_drm_backend_init(struct wlr_session *session,
backend->session = session;
- backend->displays = list_create();
- if (!backend->displays) {
+ backend->outputs = list_create();
+ if (!backend->outputs) {
wlr_log(L_ERROR, "Failed to allocate list");
goto error_backend;
}
@@ -51,16 +51,16 @@ struct wlr_drm_backend *wlr_drm_backend_init(struct wlr_session *session,
goto error_fd;
}
- wl_signal_init(&backend->signals.display_add);
- wl_signal_init(&backend->signals.display_rem);
- wl_signal_init(&backend->signals.display_render);
+ wl_signal_init(&backend->signals.output_add);
+ wl_signal_init(&backend->signals.output_rem);
+ wl_signal_init(&backend->signals.output_render);
if (add)
- wl_signal_add(&backend->signals.display_add, add);
+ wl_signal_add(&backend->signals.output_add, add);
if (rem)
- wl_signal_add(&backend->signals.display_rem, rem);
+ wl_signal_add(&backend->signals.output_rem, rem);
if (render)
- wl_signal_add(&backend->signals.display_render, render);
+ wl_signal_add(&backend->signals.output_render, render);
wlr_drm_scan_connectors(backend);
@@ -73,17 +73,17 @@ error_udev:
error_loop:
wl_event_loop_destroy(backend->event_loop);
error_list:
- list_free(backend->displays);
+ list_free(backend->outputs);
error_backend:
free(backend);
return NULL;
}
-static void free_display(void *item)
+static void free_output(void *item)
{
- struct wlr_drm_display *disp = item;
- wlr_drm_display_free(disp, true);
- free(disp);
+ struct wlr_drm_output *out = item;
+ wlr_drm_output_free(out, true);
+ free(out);
}
void wlr_drm_backend_free(struct wlr_drm_backend *backend)
@@ -91,7 +91,7 @@ void wlr_drm_backend_free(struct wlr_drm_backend *backend)
if (!backend)
return;
- list_foreach(backend->displays, free_display);
+ list_foreach(backend->outputs, free_output);
wlr_drm_renderer_free(&backend->renderer);
wlr_udev_free(&backend->udev);
@@ -102,7 +102,7 @@ void wlr_drm_backend_free(struct wlr_drm_backend *backend)
wl_event_source_remove(backend->event_src.udev);
wl_event_loop_destroy(backend->event_loop);
- list_free(backend->displays);
+ list_free(backend->outputs);
free(backend);
}
diff --git a/backend/drm/drm.c b/backend/drm/drm.c
index 617dd74a..13971687 100644
--- a/backend/drm/drm.c
+++ b/backend/drm/drm.c
@@ -37,23 +37,19 @@ static const char *conn_name[] = {
[DRM_MODE_CONNECTOR_DSI] = "DSI",
};
-static void page_flip_handler(int fd,
- unsigned seq,
- unsigned tv_sec,
- unsigned tv_usec,
- void *user)
-{
- struct wlr_drm_display *disp = user;
- struct wlr_drm_backend *backend = disp->renderer->backend;
-
- disp->pageflip_pending = true;
- if (!disp->cleanup)
- wl_signal_emit(&backend->signals.display_render, disp);
-}
+static void page_flip_handler(int fd, unsigned seq, unsigned tv_sec, unsigned tv_usec,
+ void *user) {
+
+ struct wlr_drm_output *out = user;
+ struct wlr_drm_backend *backend = out->renderer->backend;
+ out->pageflip_pending = true;
+ if (!out->cleanup) {
+ wl_signal_emit(&backend->signals.output_render, out);
+ }
+}
-static int drm_event(int fd, uint32_t mask, void *data)
-{
+static int drm_event(int fd, uint32_t mask, void *data) {
drmEventContext event = {
.version = DRM_EVENT_CONTEXT_VERSION,
.page_flip_handler = page_flip_handler,
@@ -65,8 +61,8 @@ static int drm_event(int fd, uint32_t mask, void *data)
}
bool wlr_drm_renderer_init(struct wlr_drm_renderer *renderer,
- struct wlr_drm_backend *backend, int fd)
-{
+ struct wlr_drm_backend *backend, int fd) {
+
renderer->gbm = gbm_create_device(fd);
if (!renderer->gbm) {
wlr_log(L_ERROR, "Failed to create GBM device: %s", strerror(errno));
@@ -98,30 +94,29 @@ error_gbm:
return false;
}
-void wlr_drm_renderer_free(struct wlr_drm_renderer *renderer)
-{
- if (!renderer)
+void wlr_drm_renderer_free(struct wlr_drm_renderer *renderer) {
+ if (!renderer) {
return;
+ }
wlr_egl_free(&renderer->egl);
gbm_device_destroy(renderer->gbm);
}
-static int find_id(const void *item, const void *cmp_to)
-{
- const struct wlr_drm_display *disp = item;
+static int find_id(const void *item, const void *cmp_to) {
+ const struct wlr_drm_output *out = item;
const uint32_t *id = cmp_to;
- if (disp->connector < *id)
+ if (out->connector < *id) {
return -1;
- else if (disp->connector > *id)
+ } else if (out->connector > *id) {
return 1;
- else
+ } else {
return 0;
+ }
}
-void wlr_drm_scan_connectors(struct wlr_drm_backend *backend)
-{
+void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) {
drmModeRes *res = drmModeGetResources(backend->fd);
if (!res) {
wlr_log(L_ERROR, "Failed to get DRM resources");
@@ -137,42 +132,44 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend)
continue;
}
- struct wlr_drm_display *disp;
- int index = list_seq_find(backend->displays, find_id, &id);
+ struct wlr_drm_output *out;
+ int index = list_seq_find(backend->outputs, find_id, &id);
if (index == -1) {
- disp = calloc(1, sizeof *disp);
- if (!disp) {
+ out = calloc(1, sizeof *out);
+ if (!out) {
wlr_log(L_ERROR, "Allocation failed: %s", strerror(errno));
drmModeFreeConnector(conn);
continue;
}
- disp->renderer = &backend->renderer;
- disp->state = DRM_DISP_DISCONNECTED;
- disp->connector = res->connectors[i];
- snprintf(disp->name, sizeof disp->name, "%s-%"PRIu32,
+ out->renderer = &backend->renderer;
+ out->state = DRM_OUTPUT_DISCONNECTED;
+ out->connector = res->connectors[i];
+ snprintf(out->name, sizeof out->name, "%s-%"PRIu32,
conn_name[conn->connector_type],
conn->connector_type_id);
- list_add(backend->displays, disp);
- wlr_log(L_INFO, "Found display '%s'", disp->name);
+ list_add(backend->outputs, out);
+ wlr_log(L_INFO, "Found display '%s'", out->name);
} else {
- disp = backend->displays->items[index];
+ out = backend->outputs->items[index];
}
- if (disp->state == DRM_DISP_DISCONNECTED &&
- conn->connection == DRM_MODE_CONNECTED) {
- disp->state = DRM_DISP_NEEDS_MODESET;
- wlr_log(L_INFO, "Sending modesetting signal for '%s'", disp->name);
- wl_signal_emit(&backend->signals.display_add, disp);
-
- } else if (disp->state == DRM_DISP_CONNECTED &&
- conn->connection != DRM_MODE_CONNECTED) {
- disp->state = DRM_DISP_DISCONNECTED;
- wlr_drm_display_free(disp, false);
- wlr_log(L_INFO, "Sending destruction signal for '%s'", disp->name);
- wl_signal_emit(&backend->signals.display_rem, disp);
+ if (out->state == DRM_OUTPUT_DISCONNECTED &&
+ conn->connection == DRM_MODE_CONNECTED) {
+
+ out->state = DRM_OUTPUT_NEEDS_MODESET;
+ wlr_log(L_INFO, "Sending modesetting signal for '%s'", out->name);
+ wl_signal_emit(&backend->signals.output_add, out);
+
+ } else if (out->state == DRM_OUTPUT_CONNECTED &&
+ conn->connection != DRM_MODE_CONNECTED) {
+
+ out->state = DRM_OUTPUT_DISCONNECTED;
+ wlr_drm_output_free(out, false);
+ wlr_log(L_INFO, "Sending destruction signal for '%s'", out->name);
+ wl_signal_emit(&backend->signals.output_rem, out);
}
drmModeFreeConnector(conn);
@@ -181,22 +178,22 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend)
drmModeFreeResources(res);
}
-static void free_fb(struct gbm_bo *bo, void *data)
-{
+static void free_fb(struct gbm_bo *bo, void *data) {
uint32_t *id = data;
- if (id && *id)
+ if (id && *id) {
drmModeRmFB(gbm_bo_get_fd(bo), *id);
+ }
free(id);
}
-static uint32_t get_fb_for_bo(int fd, struct gbm_bo *bo)
-{
+static uint32_t get_fb_for_bo(int fd, struct gbm_bo *bo) {
uint32_t *id = gbm_bo_get_user_data(bo);
- if (id)
+ if (id) {
return *id;
+ }
id = calloc(1, sizeof *id);
if (!id) {
@@ -213,55 +210,52 @@ static uint32_t get_fb_for_bo(int fd, struct gbm_bo *bo)
}
static bool display_init_renderer(struct wlr_drm_renderer *renderer,
- struct wlr_drm_display *disp)
-{
- disp->renderer = renderer;
-
- disp->gbm = gbm_surface_create(renderer->gbm,
- disp->width, disp->height,
- GBM_FORMAT_XRGB8888,
- GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
- if (!disp->gbm) {
- wlr_log(L_ERROR, "Failed to create GBM surface for %s: %s", disp->name,
+ struct wlr_drm_output *out) {
+
+ out->renderer = renderer;
+
+ out->gbm = gbm_surface_create(renderer->gbm, out->width, out->height,
+ GBM_FORMAT_XRGB8888, GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
+ if (!out->gbm) {
+ wlr_log(L_ERROR, "Failed to create GBM surface for %s: %s", out->name,
strerror(errno));
return false;
}
- disp->egl = wlr_egl_create_surface(&renderer->egl, disp->gbm);
- if (disp->egl == EGL_NO_SURFACE) {
- wlr_log(L_ERROR, "Failed to create EGL surface for %s", disp->name);
+ out->egl = wlr_egl_create_surface(&renderer->egl, out->gbm);
+ if (out->egl == EGL_NO_SURFACE) {
+ wlr_log(L_ERROR, "Failed to create EGL surface for %s", out->name);
return false;
}
// Render black frame
- eglMakeCurrent(renderer->egl.display, disp->egl, disp->egl, renderer->egl.context);
+ eglMakeCurrent(renderer->egl.display, out->egl, out->egl, renderer->egl.context);
- glViewport(0, 0, disp->width, disp->height);
+ glViewport(0, 0, out->width, out->height);
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
- eglSwapBuffers(renderer->egl.display, disp->egl);
+ eglSwapBuffers(renderer->egl.display, out->egl);
- struct gbm_bo *bo = gbm_surface_lock_front_buffer(disp->gbm);
+ struct gbm_bo *bo = gbm_surface_lock_front_buffer(out->gbm);
uint32_t fb_id = get_fb_for_bo(renderer->fd, bo);
- drmModeSetCrtc(renderer->fd, disp->crtc, fb_id, 0, 0,
- &disp->connector, 1, disp->active_mode);
- drmModePageFlip(renderer->fd, disp->crtc, fb_id, DRM_MODE_PAGE_FLIP_EVENT, disp);
+ drmModeSetCrtc(renderer->fd, out->crtc, fb_id, 0, 0,
+ &out->connector, 1, out->active_mode);
+ drmModePageFlip(renderer->fd, out->crtc, fb_id, DRM_MODE_PAGE_FLIP_EVENT, out);
- gbm_surface_release_buffer(disp->gbm, bo);
+ gbm_surface_release_buffer(out->gbm, bo);
return true;
}
-static drmModeModeInfo *select_mode(size_t num_modes,
- drmModeModeInfo modes[static num_modes],
- drmModeCrtc *old_crtc,
- const char *str)
-{
- if (strcmp(str, "preferred") == 0)
+static drmModeModeInfo *select_mode(size_t num_modes, drmModeModeInfo modes[static num_modes],
+ drmModeCrtc *old_crtc, const char *str) {
+
+ if (strcmp(str, "preferred") == 0) {
return &modes[0];
+ }
if (strcmp(str, "current") == 0) {
if (!old_crtc) {
@@ -270,8 +264,9 @@ static drmModeModeInfo *select_mode(size_t num_modes,
}
for (size_t i = 0; i < num_modes; ++i) {
- if (memcmp(&modes[i], &old_crtc->mode, sizeof modes[0]) == 0)
+ if (memcmp(&modes[i], &old_crtc->mode, sizeof modes[0]) == 0) {
return &modes[i];
+ }
}
// We should never get here
@@ -289,55 +284,57 @@ static drmModeModeInfo *select_mode(size_t num_modes,
}
for (size_t i = 0; i < num_modes; ++i) {
- if (modes[i].hdisplay == width &&
- modes[i].vdisplay == height &&
- (!rate || modes[i].vrefresh == rate))
+ if (modes[i].hdisplay == width && modes[i].vdisplay == height &&
+ (!rate || modes[i].vrefresh == rate)) {
+
return &modes[i];
+ }
}
wlr_log(L_ERROR, "Unable to find mode %ux%u@%u", width, height, rate);
return NULL;
}
-bool wlr_drm_display_modeset(struct wlr_drm_display *disp, const char *str)
-{
- struct wlr_drm_backend *backend = disp->renderer->backend;
- wlr_log(L_INFO, "Modesetting %s with '%s'", disp->name, str);
+bool wlr_drm_output_modeset(struct wlr_drm_output *out, const char *str) {
+ struct wlr_drm_backend *backend = out->renderer->backend;
+ wlr_log(L_INFO, "Modesetting %s with '%s'", out->name, str);
- drmModeConnector *conn = drmModeGetConnector(backend->fd, disp->connector);
+ drmModeConnector *conn = drmModeGetConnector(backend->fd, out->connector);
if (!conn) {
wlr_log(L_ERROR, "Failed to get DRM connector");
goto error;
}
if (conn->connection != DRM_MODE_CONNECTED || conn->count_modes == 0) {
- wlr_log(L_ERROR, "%s is not connected", disp->name);
+ wlr_log(L_ERROR, "%s is not connected", out->name);
goto error;
}
- disp->num_modes = conn->count_modes;
- disp->modes = malloc(sizeof *disp->modes * disp->num_modes);
- if (!disp->modes) {
+ out->num_modes = conn->count_modes;
+ out->modes = malloc(sizeof *out->modes * out->num_modes);
+ if (!out->modes) {
wlr_log(L_ERROR, "Allocation failed: %s", strerror(errno));
goto error;
}
- memcpy(disp->modes, conn->modes, sizeof *disp->modes * disp->num_modes);
+ memcpy(out->modes, conn->modes, sizeof *out->modes * out->num_modes);
wlr_log(L_INFO, "Detected modes:");
- for (size_t i = 0; i < disp->num_modes; ++i)
+ for (size_t i = 0; i < out->num_modes; ++i) {
wlr_log(L_INFO, " %"PRIu16"@%"PRIu16"@%"PRIu32,
- disp->modes[i].hdisplay, disp->modes[i].vdisplay,
- disp->modes[i].vrefresh);
+ out->modes[i].hdisplay, out->modes[i].vdisplay,
+ out->modes[i].vrefresh);
+ }
drmModeEncoder *curr_enc = drmModeGetEncoder(backend->fd, conn->encoder_id);
if (curr_enc) {
- disp->old_crtc = drmModeGetCrtc(backend->fd, curr_enc->crtc_id);
+ out->old_crtc = drmModeGetCrtc(backend->fd, curr_enc->crtc_id);
free(curr_enc);
}
- disp->active_mode = select_mode(disp->num_modes, disp->modes, disp->old_crtc, str);
- if (!disp->active_mode) {
- wlr_log(L_ERROR, "Failed to configure %s", disp->name);
+ out->active_mode = select_mode(out->num_modes, out->modes,
+ out->old_crtc, str);
+ if (!out->active_mode) {
+ wlr_log(L_ERROR, "Failed to configure %s", out->name);
goto error;
}
@@ -354,12 +351,13 @@ bool wlr_drm_display_modeset(struct wlr_drm_display *disp, const char *str)
continue;
for (int j = 0; j < res->count_crtcs; ++j) {
- if ((enc->possible_crtcs & (1 << j)) == 0)
+ if ((enc->possible_crtcs & (1 << j)) == 0) {
continue;
+ }
if ((backend->taken_crtcs & (1 << j)) == 0) {
backend->taken_crtcs |= 1 << j;
- disp->crtc = res->crtcs[j];
+ out->crtc = res->crtcs[j];
success = true;
break;
@@ -372,55 +370,56 @@ bool wlr_drm_display_modeset(struct wlr_drm_display *disp, const char *str)
drmModeFreeResources(res);
if (!success) {
- wlr_log(L_ERROR, "Failed to find CRTC for %s", disp->name);
+ wlr_log(L_ERROR, "Failed to find CRTC for %s", out->name);
goto error;
}
- disp->state = DRM_DISP_CONNECTED;
+ out->state = DRM_OUTPUT_CONNECTED;
- disp->width = disp->active_mode->hdisplay;
- disp->height = disp->active_mode->vdisplay;
+ out->width = out->active_mode->hdisplay;
+ out->height = out->active_mode->vdisplay;
- if (!display_init_renderer(&backend->renderer, disp)) {
- wlr_log(L_ERROR, "Failed to initalise renderer for %s", disp->name);
+ if (!display_init_renderer(&backend->renderer, out)) {
+ wlr_log(L_ERROR, "Failed to initalise renderer for %s", out->name);
goto error;
}
drmModeFreeConnector(conn);
wlr_log(L_INFO, "Configuring %s with mode %"PRIu16"x%"PRIu16"@%"PRIu32"",
- disp->name, disp->active_mode->hdisplay, disp->active_mode->vdisplay,
- disp->active_mode->vrefresh);
+ out->name, out->active_mode->hdisplay, out->active_mode->vdisplay,
+ out->active_mode->vrefresh);
return true;
error:
- disp->state = DRM_DISP_DISCONNECTED;
+ out->state = DRM_OUTPUT_DISCONNECTED;
drmModeFreeConnector(conn);
- free(disp->modes);
+ free(out->modes);
- wl_signal_emit(&backend->signals.display_rem, disp);
+ wl_signal_emit(&backend->signals.output_rem, out);
return false;
}
-void wlr_drm_display_free(struct wlr_drm_display *disp, bool restore)
-{
- if (!disp || disp->state != DRM_DISP_CONNECTED)
+void wlr_drm_output_free(struct wlr_drm_output *out, bool restore) {
+ if (!out || out->state != DRM_OUTPUT_CONNECTED) {
return;
+ }
- struct wlr_drm_renderer *renderer = disp->renderer;
+ struct wlr_drm_renderer *renderer = out->renderer;
- eglDestroySurface(renderer->egl.display, disp->egl);
- gbm_surface_destroy(disp->gbm);
+ eglDestroySurface(renderer->egl.display, out->egl);
+ gbm_surface_destroy(out->gbm);
- free(disp->modes);
- disp->state = DRM_DISP_DISCONNECTED;
+ free(out->modes);
+ out->state = DRM_OUTPUT_DISCONNECTED;
- if (!restore)
+ if (!restore) {
return;
+ }
- drmModeCrtc *crtc = disp->old_crtc;
+ drmModeCrtc *crtc = out->old_crtc;
if (crtc) {
// Wait for exising page flips to finish
@@ -429,34 +428,32 @@ void wlr_drm_display_free(struct wlr_drm_display *disp, bool restore)
.page_flip_handler = page_flip_handler,
};
- disp->cleanup = true;
- while (disp->pageflip_pending)
+ out->cleanup = true;
+ while (out->pageflip_pending)
drmHandleEvent(renderer->fd, &event);
drmModeSetCrtc(renderer->fd, crtc->crtc_id, crtc->buffer_id,
- crtc->x, crtc->y, &disp->connector,
+ crtc->x, crtc->y, &out->connector,
1, &crtc->mode);
drmModeFreeCrtc(crtc);
}
}
-void wlr_drm_display_begin(struct wlr_drm_display *disp)
-{
- struct wlr_drm_renderer *renderer = disp->renderer;
- eglMakeCurrent(renderer->egl.display, disp->egl, disp->egl, renderer->egl.context);
+void wlr_drm_output_begin(struct wlr_drm_output *out) {
+ struct wlr_drm_renderer *renderer = out->renderer;
+ eglMakeCurrent(renderer->egl.display, out->egl, out->egl, renderer->egl.context);
}
-void wlr_drm_display_end(struct wlr_drm_display *disp)
-{
- struct wlr_drm_renderer *renderer = disp->renderer;
- eglSwapBuffers(renderer->egl.display, disp->egl);
+void wlr_drm_output_end(struct wlr_drm_output *out) {
+ struct wlr_drm_renderer *renderer = out->renderer;
+ eglSwapBuffers(renderer->egl.display, out->egl);
- struct gbm_bo *bo = gbm_surface_lock_front_buffer(disp->gbm);
+ struct gbm_bo *bo = gbm_surface_lock_front_buffer(out->gbm);
uint32_t fb_id = get_fb_for_bo(renderer->fd, bo);
- drmModePageFlip(renderer->fd, disp->crtc, fb_id, DRM_MODE_PAGE_FLIP_EVENT, disp);
+ drmModePageFlip(renderer->fd, out->crtc, fb_id, DRM_MODE_PAGE_FLIP_EVENT, out);
- gbm_surface_release_buffer(disp->gbm, bo);
+ gbm_surface_release_buffer(out->gbm, bo);
- disp->pageflip_pending = false;
+ out->pageflip_pending = false;
}