Fixed hotplugging + make EGL more chatty.

This commit is contained in:
Scott Anderson 2017-05-04 21:58:11 +12:00
parent 4285b0c218
commit 7e9feb70a0
4 changed files with 43 additions and 26 deletions

View file

@ -110,7 +110,7 @@ void wlr_drm_output_end(struct wlr_drm_output *out) {
gbm_surface_release_buffer(out->gbm, bo); gbm_surface_release_buffer(out->gbm, bo);
out->pageflip_pending = false; out->pageflip_pending = true;
} }
static bool display_init_renderer(struct wlr_drm_renderer *renderer, static bool display_init_renderer(struct wlr_drm_renderer *renderer,
@ -168,6 +168,8 @@ static int find_id(const void *item, const void *cmp_to) {
} }
void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) { void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) {
wlr_log(L_INFO, "Scanning DRM connectors");
drmModeRes *res = drmModeGetResources(backend->fd); drmModeRes *res = drmModeGetResources(backend->fd);
if (!res) { if (!res) {
wlr_log(L_ERROR, "Failed to get DRM resources"); wlr_log(L_ERROR, "Failed to get DRM resources");
@ -196,11 +198,17 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) {
out->renderer = &backend->renderer; out->renderer = &backend->renderer;
out->state = DRM_OUTPUT_DISCONNECTED; out->state = DRM_OUTPUT_DISCONNECTED;
out->connector = res->connectors[i]; out->connector = id;
snprintf(out->name, sizeof out->name, "%s-%"PRIu32, snprintf(out->name, sizeof out->name, "%s-%"PRIu32,
conn_name[conn->connector_type], conn_name[conn->connector_type],
conn->connector_type_id); conn->connector_type_id);
drmModeEncoder *curr_enc = drmModeGetEncoder(backend->fd, conn->encoder_id);
if (curr_enc) {
out->old_crtc = drmModeGetCrtc(backend->fd, curr_enc->crtc_id);
free(curr_enc);
}
list_add(backend->outputs, out); list_add(backend->outputs, out);
wlr_log(L_INFO, "Found display '%s'", out->name); wlr_log(L_INFO, "Found display '%s'", out->name);
} else { } else {
@ -241,9 +249,8 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) {
} else if (out->state == DRM_OUTPUT_CONNECTED && } else if (out->state == DRM_OUTPUT_CONNECTED &&
conn->connection != DRM_MODE_CONNECTED) { conn->connection != DRM_MODE_CONNECTED) {
wlr_log(L_INFO, "'%s' disconnected", out->name);
wlr_drm_output_cleanup(out, false); wlr_drm_output_cleanup(out, false);
wlr_log(L_INFO, "Sending destruction signal for '%s'", out->name);
wl_signal_emit(&backend->signals.output_rem, out);
} }
error: error:
drmModeFreeConnector(conn); drmModeFreeConnector(conn);
@ -279,12 +286,6 @@ bool wlr_drm_output_modeset(struct wlr_drm_output *out, struct wlr_drm_mode *mod
goto error; goto error;
} }
drmModeEncoder *curr_enc = drmModeGetEncoder(backend->fd, conn->encoder_id);
if (curr_enc) {
out->old_crtc = drmModeGetCrtc(backend->fd, curr_enc->crtc_id);
free(curr_enc);
}
drmModeRes *res = drmModeGetResources(backend->fd); drmModeRes *res = drmModeGetResources(backend->fd);
if (!res) { if (!res) {
wlr_log(L_ERROR, "Failed to get DRM resources"); wlr_log(L_ERROR, "Failed to get DRM resources");
@ -336,11 +337,8 @@ bool wlr_drm_output_modeset(struct wlr_drm_output *out, struct wlr_drm_mode *mod
return true; return true;
error: error:
out->state = DRM_OUTPUT_DISCONNECTED; wlr_drm_output_cleanup(out, false);
drmModeFreeConnector(conn); drmModeFreeConnector(conn);
free(out->modes);
wl_signal_emit(&backend->signals.output_rem, out);
return false; return false;
} }
@ -351,8 +349,8 @@ static void page_flip_handler(int fd, unsigned seq, unsigned tv_sec, unsigned tv
struct wlr_drm_output *out = user; struct wlr_drm_output *out = user;
struct wlr_drm_backend *backend = wl_container_of(out->renderer, backend, renderer); struct wlr_drm_backend *backend = wl_container_of(out->renderer, backend, renderer);
out->pageflip_pending = true; out->pageflip_pending = false;
if (!out->cleanup) { if (out->state == DRM_OUTPUT_CONNECTED) {
wl_signal_emit(&backend->signals.output_render, out); wl_signal_emit(&backend->signals.output_render, out);
} }
} }
@ -369,18 +367,16 @@ int wlr_drm_event(int fd, uint32_t mask, void *data) {
} }
static void restore_output(struct wlr_drm_output *out, int fd) { static void restore_output(struct wlr_drm_output *out, int fd) {
// Wait for any pending pageflips to finish
while (out->pageflip_pending) {
wlr_drm_event(fd, 0, NULL);
}
drmModeCrtc *crtc = out->old_crtc; drmModeCrtc *crtc = out->old_crtc;
if (!crtc) { if (!crtc) {
return; return;
} }
// Wait for exising page flips to finish
out->cleanup = true;
while (out->pageflip_pending) {
wlr_drm_event(fd, 0, NULL);
}
drmModeSetCrtc(fd, crtc->crtc_id, crtc->buffer_id, crtc->x, crtc->y, drmModeSetCrtc(fd, crtc->crtc_id, crtc->buffer_id, crtc->x, crtc->y,
&out->connector, 1, &crtc->mode); &out->connector, 1, &crtc->mode);
drmModeFreeCrtc(crtc); drmModeFreeCrtc(crtc);
@ -392,6 +388,7 @@ void wlr_drm_output_cleanup(struct wlr_drm_output *out, bool restore) {
} }
struct wlr_drm_renderer *renderer = out->renderer; struct wlr_drm_renderer *renderer = out->renderer;
struct wlr_drm_backend *backend = wl_container_of(renderer, backend, renderer);
switch (out->state) { switch (out->state) {
case DRM_OUTPUT_CONNECTED: case DRM_OUTPUT_CONNECTED:
@ -410,14 +407,21 @@ void wlr_drm_output_cleanup(struct wlr_drm_output *out, bool restore) {
out->width = 0; out->width = 0;
out->height = 0; out->height = 0;
out->state = DRM_OUTPUT_DISCONNECTED;
if (restore) { if (restore) {
restore_output(out, renderer->fd); restore_output(out, renderer->fd);
} }
out->state = DRM_MODE_DISCONNECTED; wlr_log(L_INFO, "Emmiting destruction signal for '%s'", out->name);
wl_signal_emit(&backend->signals.output_rem, out);
break; break;
case DRM_OUTPUT_DISCONNECTED: case DRM_OUTPUT_DISCONNECTED:
break; break;
} }
} }
const char *wlr_drm_output_get_name(struct wlr_drm_output *out) {
return out->name;
}

View file

@ -1,5 +1,6 @@
#include <EGL/egl.h> #include <EGL/egl.h>
#include <EGL/eglext.h> #include <EGL/eglext.h>
#include <GLES3/gl3.h>
#include <gbm.h> // GBM_FORMAT_XRGB8888 #include <gbm.h> // GBM_FORMAT_XRGB8888
#include "backend/egl.h" #include "backend/egl.h"
@ -120,7 +121,8 @@ bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, void *display) {
goto error; goto error;
} }
if (eglInitialize(egl->display, NULL, NULL) == EGL_FALSE) { EGLint major, minor;
if (eglInitialize(egl->display, &major, &minor) == EGL_FALSE) {
wlr_log(L_ERROR, "Failed to initialize EGL: %s", egl_error()); wlr_log(L_ERROR, "Failed to initialize EGL: %s", egl_error());
goto error; goto error;
} }
@ -140,6 +142,13 @@ bool wlr_egl_init(struct wlr_egl *egl, EGLenum platform, void *display) {
goto error; goto error;
} }
eglMakeCurrent(egl->display, EGL_NO_SURFACE, EGL_NO_SURFACE, egl->context);
wlr_log(L_INFO, "Using EGL %d.%d", (int)major, (int)minor);
wlr_log(L_INFO, "Supported EGL extensions: %s", eglQueryString(egl->display,
EGL_EXTENSIONS));
wlr_log(L_INFO, "Using %s", glGetString(GL_VERSION));
wlr_log(L_INFO, "Supported OpenGL ES extensions: %s", glGetString(GL_EXTENSIONS));
return true; return true;
error: error:

View file

@ -22,6 +22,7 @@ struct state {
void output_add(struct wl_listener *listener, void *data) void output_add(struct wl_listener *listener, void *data)
{ {
struct wlr_drm_output *out = data; struct wlr_drm_output *out = data;
fprintf(stderr, "Output '%s' added\n", wlr_drm_output_get_name(out));
size_t num_modes; size_t num_modes;
struct wlr_drm_mode *modes = wlr_drm_output_get_modes(out, &num_modes); struct wlr_drm_mode *modes = wlr_drm_output_get_modes(out, &num_modes);
@ -31,7 +32,8 @@ void output_add(struct wl_listener *listener, void *data)
void output_rem(struct wl_listener *listener, void *data) void output_rem(struct wl_listener *listener, void *data)
{ {
fprintf(stderr, "Output removed\n"); struct wlr_drm_output *out = data;
fprintf(stderr, "Output '%s' removed\n", wlr_drm_output_get_name(out));
} }
void output_render(struct wl_listener *listener, void *data) void output_render(struct wl_listener *listener, void *data)

View file

@ -20,6 +20,8 @@ struct wlr_drm_backend *wlr_drm_backend_init(struct wl_display *display,
struct wl_listener *render); struct wl_listener *render);
void wlr_drm_backend_free(struct wlr_drm_backend *backend); void wlr_drm_backend_free(struct wlr_drm_backend *backend);
const char *wlr_drm_output_get_name(struct wlr_drm_output *out);
struct wlr_drm_mode *wlr_drm_output_get_modes(struct wlr_drm_output *out, size_t *count); struct wlr_drm_mode *wlr_drm_output_get_modes(struct wlr_drm_output *out, size_t *count);
bool wlr_drm_output_modeset(struct wlr_drm_output *out, struct wlr_drm_mode *mode); bool wlr_drm_output_modeset(struct wlr_drm_output *out, struct wlr_drm_mode *mode);