|
|
@ -37,29 +37,6 @@ static const char *conn_name[] = {
|
|
|
|
[DRM_MODE_CONNECTOR_DSI] = "DSI",
|
|
|
|
[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_output *out = user;
|
|
|
|
|
|
|
|
struct wlr_drm_backend *backend = wl_container_of(out->renderer, backend, renderer);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
out->pageflip_pending = true;
|
|
|
|
|
|
|
|
if (!out->cleanup) {
|
|
|
|
|
|
|
|
wl_signal_emit(&backend->signals.output_render, out);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int wlr_drm_event(int fd, uint32_t mask, void *data) {
|
|
|
|
|
|
|
|
drmEventContext event = {
|
|
|
|
|
|
|
|
.version = DRM_EVENT_CONTEXT_VERSION,
|
|
|
|
|
|
|
|
.page_flip_handler = page_flip_handler,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
drmHandleEvent(fd, &event);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool wlr_drm_renderer_init(struct wlr_drm_renderer *renderer, int fd) {
|
|
|
|
bool wlr_drm_renderer_init(struct wlr_drm_renderer *renderer, int fd) {
|
|
|
|
|
|
|
|
|
|
|
|
renderer->gbm = gbm_create_device(fd);
|
|
|
|
renderer->gbm = gbm_create_device(fd);
|
|
|
@ -86,81 +63,6 @@ void wlr_drm_renderer_free(struct wlr_drm_renderer *renderer) {
|
|
|
|
gbm_device_destroy(renderer->gbm);
|
|
|
|
gbm_device_destroy(renderer->gbm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 (out->connector < *id) {
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
} else if (out->connector > *id) {
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < res->count_connectors; ++i) {
|
|
|
|
|
|
|
|
uint32_t id = res->connectors[i];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
drmModeConnector *conn = drmModeGetConnector(backend->fd, id);
|
|
|
|
|
|
|
|
if (!conn) {
|
|
|
|
|
|
|
|
wlr_log(L_ERROR, "Failed to get DRM connector");
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_drm_output *out;
|
|
|
|
|
|
|
|
int index = list_seq_find(backend->outputs, find_id, &id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (index == -1) {
|
|
|
|
|
|
|
|
out = calloc(1, sizeof *out);
|
|
|
|
|
|
|
|
if (!out) {
|
|
|
|
|
|
|
|
wlr_log(L_ERROR, "Allocation failed: %s", strerror(errno));
|
|
|
|
|
|
|
|
drmModeFreeConnector(conn);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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->outputs, out);
|
|
|
|
|
|
|
|
wlr_log(L_INFO, "Found display '%s'", out->name);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
out = backend->outputs->items[index];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
uint32_t *id = data;
|
|
|
|
|
|
|
|
|
|
|
@ -192,6 +94,25 @@ static uint32_t get_fb_for_bo(int fd, struct gbm_bo *bo) {
|
|
|
|
return *id;
|
|
|
|
return *id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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_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(out->gbm);
|
|
|
|
|
|
|
|
uint32_t fb_id = get_fb_for_bo(renderer->fd, bo);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
drmModePageFlip(renderer->fd, out->crtc, fb_id, DRM_MODE_PAGE_FLIP_EVENT, out);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gbm_surface_release_buffer(out->gbm, bo);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
out->pageflip_pending = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool display_init_renderer(struct wlr_drm_renderer *renderer,
|
|
|
|
static bool display_init_renderer(struct wlr_drm_renderer *renderer,
|
|
|
|
struct wlr_drm_output *out) {
|
|
|
|
struct wlr_drm_output *out) {
|
|
|
|
|
|
|
|
|
|
|
@ -225,7 +146,7 @@ static bool display_init_renderer(struct wlr_drm_renderer *renderer,
|
|
|
|
uint32_t fb_id = get_fb_for_bo(renderer->fd, bo);
|
|
|
|
uint32_t fb_id = get_fb_for_bo(renderer->fd, bo);
|
|
|
|
|
|
|
|
|
|
|
|
drmModeSetCrtc(renderer->fd, out->crtc, fb_id, 0, 0,
|
|
|
|
drmModeSetCrtc(renderer->fd, out->crtc, fb_id, 0, 0,
|
|
|
|
&out->connector, 1, out->active_mode);
|
|
|
|
&out->connector, 1, &out->active_mode->mode);
|
|
|
|
drmModePageFlip(renderer->fd, out->crtc, fb_id, DRM_MODE_PAGE_FLIP_EVENT, out);
|
|
|
|
drmModePageFlip(renderer->fd, out->crtc, fb_id, DRM_MODE_PAGE_FLIP_EVENT, out);
|
|
|
|
|
|
|
|
|
|
|
|
gbm_surface_release_buffer(out->gbm, bo);
|
|
|
|
gbm_surface_release_buffer(out->gbm, bo);
|
|
|
@ -233,54 +154,119 @@ static bool display_init_renderer(struct wlr_drm_renderer *renderer,
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static drmModeModeInfo *select_mode(size_t num_modes, drmModeModeInfo modes[static num_modes],
|
|
|
|
static int find_id(const void *item, const void *cmp_to) {
|
|
|
|
drmModeCrtc *old_crtc, const char *str) {
|
|
|
|
const struct wlr_drm_output *out = item;
|
|
|
|
|
|
|
|
const uint32_t *id = cmp_to;
|
|
|
|
|
|
|
|
|
|
|
|
if (strcmp(str, "preferred") == 0) {
|
|
|
|
if (out->connector < *id) {
|
|
|
|
return &modes[0];
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
} else if (out->connector > *id) {
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (strcmp(str, "current") == 0) {
|
|
|
|
void wlr_drm_scan_connectors(struct wlr_drm_backend *backend) {
|
|
|
|
if (!old_crtc) {
|
|
|
|
drmModeRes *res = drmModeGetResources(backend->fd);
|
|
|
|
wlr_log(L_ERROR, "Display does not have currently configured mode");
|
|
|
|
if (!res) {
|
|
|
|
return NULL;
|
|
|
|
wlr_log(L_ERROR, "Failed to get DRM resources");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < num_modes; ++i) {
|
|
|
|
for (int i = 0; i < res->count_connectors; ++i) {
|
|
|
|
if (memcmp(&modes[i], &old_crtc->mode, sizeof modes[0]) == 0) {
|
|
|
|
uint32_t id = res->connectors[i];
|
|
|
|
return &modes[i];
|
|
|
|
|
|
|
|
|
|
|
|
drmModeConnector *conn = drmModeGetConnector(backend->fd, id);
|
|
|
|
|
|
|
|
if (!conn) {
|
|
|
|
|
|
|
|
wlr_log(L_ERROR, "Failed to get DRM connector");
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_drm_output *out;
|
|
|
|
|
|
|
|
int index = list_seq_find(backend->outputs, find_id, &id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (index == -1) {
|
|
|
|
|
|
|
|
out = calloc(1, sizeof *out);
|
|
|
|
|
|
|
|
if (!out) {
|
|
|
|
|
|
|
|
wlr_log(L_ERROR, "Allocation failed: %s", strerror(errno));
|
|
|
|
|
|
|
|
drmModeFreeConnector(conn);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// We should never get here
|
|
|
|
out->renderer = &backend->renderer;
|
|
|
|
assert(0);
|
|
|
|
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->outputs, out);
|
|
|
|
|
|
|
|
wlr_log(L_INFO, "Found display '%s'", out->name);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
out = backend->outputs->items[index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unsigned width = 0;
|
|
|
|
if (out->state == DRM_OUTPUT_DISCONNECTED &&
|
|
|
|
unsigned height = 0;
|
|
|
|
conn->connection == DRM_MODE_CONNECTED) {
|
|
|
|
unsigned rate = 0;
|
|
|
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((ret = sscanf(str, "%ux%u@%u", &width, &height, &rate)) != 2 && ret != 3) {
|
|
|
|
wlr_log(L_INFO, "'%s' connected", out->name);
|
|
|
|
wlr_log(L_ERROR, "Invalid modesetting string '%s'", str);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
out->modes = malloc(sizeof(*out->modes) * conn->count_modes);
|
|
|
|
|
|
|
|
if (!out->modes) {
|
|
|
|
|
|
|
|
wlr_log(L_ERROR, "Allocation failed: %s", strerror(errno));
|
|
|
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wlr_log(L_INFO, "Detected modes:");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
out->num_modes = conn->count_modes;
|
|
|
|
|
|
|
|
for (int i = 0; i < conn->count_modes; ++i) {
|
|
|
|
|
|
|
|
drmModeModeInfo *mode = &conn->modes[i];
|
|
|
|
|
|
|
|
out->modes[i].width = mode->hdisplay;
|
|
|
|
|
|
|
|
out->modes[i].height = mode->vdisplay;
|
|
|
|
|
|
|
|
// TODO: Calculate more accurate refresh rate
|
|
|
|
|
|
|
|
out->modes[i].rate = mode->vrefresh;
|
|
|
|
|
|
|
|
out->modes[i].mode = *mode;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wlr_log(L_INFO, " %"PRIu16"@%"PRIu16"@%"PRIu32,
|
|
|
|
|
|
|
|
mode->hdisplay, mode->vdisplay,
|
|
|
|
|
|
|
|
mode->vrefresh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < num_modes; ++i) {
|
|
|
|
out->state = DRM_OUTPUT_NEEDS_MODESET;
|
|
|
|
if (modes[i].hdisplay == width && modes[i].vdisplay == height &&
|
|
|
|
wlr_log(L_INFO, "Sending modesetting signal for '%s'", out->name);
|
|
|
|
(!rate || modes[i].vrefresh == rate)) {
|
|
|
|
wl_signal_emit(&backend->signals.output_add, out);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (out->state == DRM_OUTPUT_CONNECTED &&
|
|
|
|
|
|
|
|
conn->connection != DRM_MODE_CONNECTED) {
|
|
|
|
|
|
|
|
|
|
|
|
return &modes[i];
|
|
|
|
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:
|
|
|
|
|
|
|
|
drmModeFreeConnector(conn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
drmModeFreeResources(res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wlr_log(L_ERROR, "Unable to find mode %ux%u@%u", width, height, rate);
|
|
|
|
struct wlr_drm_mode *wlr_drm_output_get_modes(struct wlr_drm_output *out, size_t *count) {
|
|
|
|
|
|
|
|
if (out->state == DRM_OUTPUT_DISCONNECTED) {
|
|
|
|
|
|
|
|
*count = 0;
|
|
|
|
return NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool wlr_drm_output_modeset(struct wlr_drm_output *out, const char *str) {
|
|
|
|
*count = out->num_modes;
|
|
|
|
|
|
|
|
return out->modes;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool wlr_drm_output_modeset(struct wlr_drm_output *out, struct wlr_drm_mode *mode) {
|
|
|
|
struct wlr_drm_backend *backend = wl_container_of(out->renderer, backend, renderer);
|
|
|
|
struct wlr_drm_backend *backend = wl_container_of(out->renderer, backend, renderer);
|
|
|
|
wlr_log(L_INFO, "Modesetting %s with '%s'", out->name, str);
|
|
|
|
|
|
|
|
|
|
|
|
wlr_log(L_INFO, "Modesetting '%s' with '%ux%u@%u'", out->name, mode->width,
|
|
|
|
|
|
|
|
mode->height, mode->rate);
|
|
|
|
|
|
|
|
|
|
|
|
drmModeConnector *conn = drmModeGetConnector(backend->fd, out->connector);
|
|
|
|
drmModeConnector *conn = drmModeGetConnector(backend->fd, out->connector);
|
|
|
|
if (!conn) {
|
|
|
|
if (!conn) {
|
|
|
@ -293,34 +279,12 @@ bool wlr_drm_output_modeset(struct wlr_drm_output *out, const char *str) {
|
|
|
|
goto error;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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(out->modes, conn->modes, sizeof *out->modes * out->num_modes);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wlr_log(L_INFO, "Detected modes:");
|
|
|
|
|
|
|
|
for (size_t i = 0; i < out->num_modes; ++i) {
|
|
|
|
|
|
|
|
wlr_log(L_INFO, " %"PRIu16"@%"PRIu16"@%"PRIu32,
|
|
|
|
|
|
|
|
out->modes[i].hdisplay, out->modes[i].vdisplay,
|
|
|
|
|
|
|
|
out->modes[i].vrefresh);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
drmModeEncoder *curr_enc = drmModeGetEncoder(backend->fd, conn->encoder_id);
|
|
|
|
drmModeEncoder *curr_enc = drmModeGetEncoder(backend->fd, conn->encoder_id);
|
|
|
|
if (curr_enc) {
|
|
|
|
if (curr_enc) {
|
|
|
|
out->old_crtc = drmModeGetCrtc(backend->fd, curr_enc->crtc_id);
|
|
|
|
out->old_crtc = drmModeGetCrtc(backend->fd, curr_enc->crtc_id);
|
|
|
|
free(curr_enc);
|
|
|
|
free(curr_enc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
@ -358,9 +322,9 @@ bool wlr_drm_output_modeset(struct wlr_drm_output *out, const char *str) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
out->state = DRM_OUTPUT_CONNECTED;
|
|
|
|
out->state = DRM_OUTPUT_CONNECTED;
|
|
|
|
|
|
|
|
out->active_mode = mode;
|
|
|
|
out->width = out->active_mode->hdisplay;
|
|
|
|
out->width = mode->width;
|
|
|
|
out->height = out->active_mode->vdisplay;
|
|
|
|
out->height = mode->height;
|
|
|
|
|
|
|
|
|
|
|
|
if (!display_init_renderer(&backend->renderer, out)) {
|
|
|
|
if (!display_init_renderer(&backend->renderer, out)) {
|
|
|
|
wlr_log(L_ERROR, "Failed to initalise renderer for %s", out->name);
|
|
|
|
wlr_log(L_ERROR, "Failed to initalise renderer for %s", out->name);
|
|
|
@ -369,10 +333,6 @@ bool wlr_drm_output_modeset(struct wlr_drm_output *out, const char *str) {
|
|
|
|
|
|
|
|
|
|
|
|
drmModeFreeConnector(conn);
|
|
|
|
drmModeFreeConnector(conn);
|
|
|
|
|
|
|
|
|
|
|
|
wlr_log(L_INFO, "Configuring %s with mode %"PRIu16"x%"PRIu16"@%"PRIu32"",
|
|
|
|
|
|
|
|
out->name, out->active_mode->hdisplay, out->active_mode->vdisplay,
|
|
|
|
|
|
|
|
out->active_mode->vrefresh);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
error:
|
|
|
@ -385,58 +345,79 @@ error:
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void wlr_drm_output_free(struct wlr_drm_output *out, bool restore) {
|
|
|
|
static void page_flip_handler(int fd, unsigned seq, unsigned tv_sec, unsigned tv_usec,
|
|
|
|
if (!out || out->state != DRM_OUTPUT_CONNECTED) {
|
|
|
|
void *user) {
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_drm_output *out = user;
|
|
|
|
|
|
|
|
struct wlr_drm_backend *backend = wl_container_of(out->renderer, backend, renderer);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
out->pageflip_pending = true;
|
|
|
|
|
|
|
|
if (!out->cleanup) {
|
|
|
|
|
|
|
|
wl_signal_emit(&backend->signals.output_render, out);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_drm_renderer *renderer = out->renderer;
|
|
|
|
int wlr_drm_event(int fd, uint32_t mask, void *data) {
|
|
|
|
|
|
|
|
drmEventContext event = {
|
|
|
|
|
|
|
|
.version = DRM_EVENT_CONTEXT_VERSION,
|
|
|
|
|
|
|
|
.page_flip_handler = page_flip_handler,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
eglDestroySurface(renderer->egl.display, out->egl);
|
|
|
|
drmHandleEvent(fd, &event);
|
|
|
|
gbm_surface_destroy(out->gbm);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
free(out->modes);
|
|
|
|
return 1;
|
|
|
|
out->state = DRM_OUTPUT_DISCONNECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!restore) {
|
|
|
|
static void restore_output(struct wlr_drm_output *out, int fd) {
|
|
|
|
|
|
|
|
drmModeCrtc *crtc = out->old_crtc;
|
|
|
|
|
|
|
|
if (!crtc) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
drmModeCrtc *crtc = out->old_crtc;
|
|
|
|
|
|
|
|
if (crtc) {
|
|
|
|
|
|
|
|
// Wait for exising page flips to finish
|
|
|
|
// Wait for exising page flips to finish
|
|
|
|
|
|
|
|
|
|
|
|
drmEventContext event = {
|
|
|
|
|
|
|
|
.version = DRM_EVENT_CONTEXT_VERSION,
|
|
|
|
|
|
|
|
.page_flip_handler = page_flip_handler,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
out->cleanup = true;
|
|
|
|
out->cleanup = true;
|
|
|
|
while (out->pageflip_pending)
|
|
|
|
while (out->pageflip_pending) {
|
|
|
|
drmHandleEvent(renderer->fd, &event);
|
|
|
|
wlr_drm_event(fd, 0, NULL);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
drmModeSetCrtc(renderer->fd, crtc->crtc_id, crtc->buffer_id,
|
|
|
|
drmModeSetCrtc(fd, crtc->crtc_id, crtc->buffer_id, crtc->x, crtc->y,
|
|
|
|
crtc->x, crtc->y, &out->connector,
|
|
|
|
&out->connector, 1, &crtc->mode);
|
|
|
|
1, &crtc->mode);
|
|
|
|
|
|
|
|
drmModeFreeCrtc(crtc);
|
|
|
|
drmModeFreeCrtc(crtc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void wlr_drm_output_begin(struct wlr_drm_output *out) {
|
|
|
|
void wlr_drm_output_cleanup(struct wlr_drm_output *out, bool restore) {
|
|
|
|
struct wlr_drm_renderer *renderer = out->renderer;
|
|
|
|
if (!out) {
|
|
|
|
eglMakeCurrent(renderer->egl.display, out->egl, out->egl, renderer->egl.context);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void wlr_drm_output_end(struct wlr_drm_output *out) {
|
|
|
|
|
|
|
|
struct wlr_drm_renderer *renderer = out->renderer;
|
|
|
|
struct wlr_drm_renderer *renderer = out->renderer;
|
|
|
|
eglSwapBuffers(renderer->egl.display, out->egl);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct gbm_bo *bo = gbm_surface_lock_front_buffer(out->gbm);
|
|
|
|
switch (out->state) {
|
|
|
|
uint32_t fb_id = get_fb_for_bo(renderer->fd, bo);
|
|
|
|
case DRM_OUTPUT_CONNECTED:
|
|
|
|
|
|
|
|
eglDestroySurface(renderer->egl.display, out->egl);
|
|
|
|
|
|
|
|
gbm_surface_destroy(out->gbm);
|
|
|
|
|
|
|
|
|
|
|
|
drmModePageFlip(renderer->fd, out->crtc, fb_id, DRM_MODE_PAGE_FLIP_EVENT, out);
|
|
|
|
out->egl = EGL_NO_SURFACE;
|
|
|
|
|
|
|
|
out->gbm = NULL;
|
|
|
|
|
|
|
|
/* Fallthrough */
|
|
|
|
|
|
|
|
|
|
|
|
gbm_surface_release_buffer(out->gbm, bo);
|
|
|
|
case DRM_OUTPUT_NEEDS_MODESET:
|
|
|
|
|
|
|
|
free(out->modes);
|
|
|
|
|
|
|
|
out->num_modes = 0;
|
|
|
|
|
|
|
|
out->modes = NULL;
|
|
|
|
|
|
|
|
out->active_mode = NULL;
|
|
|
|
|
|
|
|
out->width = 0;
|
|
|
|
|
|
|
|
out->height = 0;
|
|
|
|
|
|
|
|
|
|
|
|
out->pageflip_pending = false;
|
|
|
|
if (restore) {
|
|
|
|
|
|
|
|
restore_output(out, renderer->fd);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
out->state = DRM_MODE_DISCONNECTED;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case DRM_OUTPUT_DISCONNECTED:
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|