Replace list_t with wl_list in wlr_drm_backend

Signed-off-by: Heghedus Razvan <heghedus.razvan@gmail.com>
master
Heghedus Razvan 7 years ago
parent bde25fe020
commit c03e774636

@ -29,8 +29,8 @@ static void wlr_drm_backend_destroy(struct wlr_backend *backend) {
wlr_drm_restore_outputs(drm); wlr_drm_restore_outputs(drm);
for (size_t i = 0; drm->outputs && i < drm->outputs->length; ++i) { struct wlr_drm_connector *conn;
struct wlr_drm_connector *conn = drm->outputs->items[i]; wl_list_for_each(conn, &drm->outputs, link) {
wlr_output_destroy(&conn->output); wlr_output_destroy(&conn->output);
} }
@ -38,7 +38,6 @@ static void wlr_drm_backend_destroy(struct wlr_backend *backend) {
wlr_drm_renderer_finish(&drm->renderer); wlr_drm_renderer_finish(&drm->renderer);
wlr_session_close_file(drm->session, drm->fd); wlr_session_close_file(drm->session, drm->fd);
wl_event_source_remove(drm->drm_event); wl_event_source_remove(drm->drm_event);
list_free(drm->outputs);
free(drm); free(drm);
} }
@ -64,8 +63,8 @@ static void session_signal(struct wl_listener *listener, void *data) {
if (session->active) { if (session->active) {
wlr_log(L_INFO, "DRM fd resumed"); wlr_log(L_INFO, "DRM fd resumed");
for (size_t i = 0; i < drm->outputs->length; ++i) { struct wlr_drm_connector *conn;
struct wlr_drm_connector *conn = drm->outputs->items[i]; wl_list_for_each(conn, &drm->outputs, link){
wlr_drm_connector_start_renderer(conn); wlr_drm_connector_start_renderer(conn);
if (!conn->crtc) { if (!conn->crtc) {
@ -110,11 +109,7 @@ struct wlr_backend *wlr_drm_backend_create(struct wl_display *display,
wlr_backend_init(&drm->backend, &backend_impl); wlr_backend_init(&drm->backend, &backend_impl);
drm->session = session; drm->session = session;
drm->outputs = list_create(); wl_list_init(&drm->outputs);
if (!drm->outputs) {
wlr_log(L_ERROR, "Failed to allocate list");
goto error_backend;
}
drm->fd = gpu_fd; drm->fd = gpu_fd;
drm->parent = (struct wlr_drm_backend *)parent; drm->parent = (struct wlr_drm_backend *)parent;
@ -158,7 +153,6 @@ error_event:
wl_event_source_remove(drm->drm_event); wl_event_source_remove(drm->drm_event);
error_fd: error_fd:
wlr_session_close_file(drm->session, drm->fd); wlr_session_close_file(drm->session, drm->fd);
list_free(drm->outputs);
error_backend: error_backend:
free(drm); free(drm);
return NULL; return NULL;

@ -313,7 +313,7 @@ static void realloc_planes(struct wlr_drm_backend *drm, const uint32_t *crtc_in)
static void realloc_crtcs(struct wlr_drm_backend *drm, struct wlr_drm_connector *conn) { static void realloc_crtcs(struct wlr_drm_backend *drm, struct wlr_drm_connector *conn) {
uint32_t crtc[drm->num_crtcs]; uint32_t crtc[drm->num_crtcs];
uint32_t crtc_res[drm->num_crtcs]; uint32_t crtc_res[drm->num_crtcs];
uint32_t possible_crtc[drm->outputs->length]; uint32_t possible_crtc[wl_list_length(&drm->outputs)];
for (size_t i = 0; i < drm->num_crtcs; ++i) { for (size_t i = 0; i < drm->num_crtcs; ++i) {
crtc[i] = UNMATCHED; crtc[i] = UNMATCHED;
@ -321,9 +321,9 @@ static void realloc_crtcs(struct wlr_drm_backend *drm, struct wlr_drm_connector
memset(possible_crtc, 0, sizeof(possible_crtc)); memset(possible_crtc, 0, sizeof(possible_crtc));
ssize_t index = -1; ssize_t index = -1, i = 0;
for (size_t i = 0; i < drm->outputs->length; ++i) { struct wlr_drm_connector *c;
struct wlr_drm_connector *c = drm->outputs->items[i]; wl_list_for_each(c, &drm->outputs, link) {
if (c == conn) { if (c == conn) {
index = i; index = i;
} }
@ -334,11 +334,12 @@ static void realloc_crtcs(struct wlr_drm_backend *drm, struct wlr_drm_connector
possible_crtc[i] = c->possible_crtc; possible_crtc[i] = c->possible_crtc;
crtc[c->crtc - drm->crtcs] = i; crtc[c->crtc - drm->crtcs] = i;
i++;
} }
assert(index != -1); assert(index != -1);
possible_crtc[index] = conn->possible_crtc; possible_crtc[index] = conn->possible_crtc;
match_obj(drm->outputs->length, possible_crtc, drm->num_crtcs, match_obj(wl_list_length(&drm->outputs), possible_crtc, drm->num_crtcs,
crtc, crtc_res); crtc, crtc_res);
bool matched = false; bool matched = false;
@ -363,7 +364,14 @@ static void realloc_crtcs(struct wlr_drm_backend *drm, struct wlr_drm_connector
} }
if (crtc_res[i] != crtc[i]) { if (crtc_res[i] != crtc[i]) {
struct wlr_drm_connector *c = drm->outputs->items[crtc_res[i]]; struct wlr_drm_connector *c;
size_t pos = 0;
wl_list_for_each(c, &drm->outputs, link) {
if (pos == crtc_res[i]) {
break;
}
pos++;
}
c->crtc = &drm->crtcs[i]; c->crtc = &drm->crtcs[i];
} }
} }
@ -438,8 +446,7 @@ static bool wlr_drm_connector_set_mode(struct wlr_output *output,
// Since realloc_crtcs can deallocate planes on OTHER outputs, // Since realloc_crtcs can deallocate planes on OTHER outputs,
// we actually need to reinitalise all of them // we actually need to reinitalise all of them
for (size_t i = 0; i < drm->outputs->length; ++i) { wl_list_for_each(conn, &drm->outputs, link) {
struct wlr_drm_connector *conn = drm->outputs->items[i];
struct wlr_output_mode *mode = conn->output.current_mode; struct wlr_output_mode *mode = conn->output.current_mode;
struct wlr_drm_crtc *crtc = conn->crtc; struct wlr_drm_crtc *crtc = conn->crtc;
@ -667,13 +674,6 @@ static int retry_pageflip(void *data) {
return 0; return 0;
} }
static int find_id(const void *item, const void *cmp_to) {
const struct wlr_drm_connector *conn = item;
const uint32_t *id = cmp_to;
return (int)conn->id - (int)*id;
}
static const int32_t subpixel_map[] = { static const int32_t subpixel_map[] = {
[DRM_MODE_SUBPIXEL_UNKNOWN] = WL_OUTPUT_SUBPIXEL_UNKNOWN, [DRM_MODE_SUBPIXEL_UNKNOWN] = WL_OUTPUT_SUBPIXEL_UNKNOWN,
[DRM_MODE_SUBPIXEL_HORIZONTAL_RGB] = WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB, [DRM_MODE_SUBPIXEL_HORIZONTAL_RGB] = WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB,
@ -692,7 +692,7 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) {
return; return;
} }
size_t seen_len = drm->outputs->length; size_t seen_len = wl_list_length(&drm->outputs);
// +1 so it can never be 0 // +1 so it can never be 0
bool seen[seen_len + 1]; bool seen[seen_len + 1];
memset(seen, 0, sizeof(seen)); memset(seen, 0, sizeof(seen));
@ -704,11 +704,16 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) {
wlr_log_errno(L_ERROR, "Failed to get DRM connector"); wlr_log_errno(L_ERROR, "Failed to get DRM connector");
continue; continue;
} }
int index = 0;
struct wlr_drm_connector *wlr_conn; struct wlr_drm_connector *c, *wlr_conn = NULL;
int index = list_seq_find(drm->outputs, find_id, &drm_conn->connector_id); wl_list_for_each(c, &drm->outputs, link) {
index++;
if (index == -1) { if (c->id == drm_conn->connector_id) {
wlr_conn = c;
break;
}
}
if (!wlr_conn) {
wlr_conn = calloc(1, sizeof(*wlr_conn)); wlr_conn = calloc(1, sizeof(*wlr_conn));
if (!wlr_conn) { if (!wlr_conn) {
wlr_log_errno(L_ERROR, "Allocation failed"); wlr_log_errno(L_ERROR, "Allocation failed");
@ -749,17 +754,10 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) {
parse_edid(&wlr_conn->output, edid_len, edid); parse_edid(&wlr_conn->output, edid_len, edid);
free(edid); free(edid);
if (list_add(drm->outputs, wlr_conn) == -1) { wl_list_insert(&drm->outputs, &wlr_conn->link);
wlr_log_errno(L_ERROR, "Allocation failed");
drmModeFreeConnector(drm_conn);
wl_event_source_remove(wlr_conn->retry_pageflip);
free(wlr_conn);
continue;
}
wlr_output_create_global(&wlr_conn->output, drm->display); wlr_output_create_global(&wlr_conn->output, drm->display);
wlr_log(L_INFO, "Found display '%s'", wlr_conn->output.name); wlr_log(L_INFO, "Found display '%s'", wlr_conn->output.name);
} else { } else {
wlr_conn = drm->outputs->items[index];
seen[index] = true; seen[index] = true;
} }
@ -807,12 +805,14 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) {
drmModeFreeResources(res); drmModeFreeResources(res);
for (size_t i = seen_len; i-- > 0;) { struct wlr_drm_connector *conn, *tmp_conn;
if (seen[i]) { size_t index = seen_len - 1;
wl_list_for_each_safe(conn, tmp_conn, &drm->outputs, link) {
if (seen[index]) {
index--;
continue; continue;
} }
index--;
struct wlr_drm_connector *conn = drm->outputs->items[i];
wlr_log(L_INFO, "'%s' disappeared", conn->output.name); wlr_log(L_INFO, "'%s' disappeared", conn->output.name);
wlr_drm_connector_cleanup(conn); wlr_drm_connector_cleanup(conn);
@ -820,8 +820,6 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) {
drmModeFreeCrtc(conn->old_crtc); drmModeFreeCrtc(conn->old_crtc);
wl_event_source_remove(conn->retry_pageflip); wl_event_source_remove(conn->retry_pageflip);
free(conn); free(conn);
list_del(drm->outputs, i);
} }
} }
@ -856,10 +854,10 @@ int wlr_drm_event(int fd, uint32_t mask, void *data) {
} }
void wlr_drm_restore_outputs(struct wlr_drm_backend *drm) { void wlr_drm_restore_outputs(struct wlr_drm_backend *drm) {
uint64_t to_close = (1 << drm->outputs->length) - 1; uint64_t to_close = (1 << wl_list_length(&drm->outputs)) - 1;
for (size_t i = 0; i < drm->outputs->length; ++i) { struct wlr_drm_connector *conn;
struct wlr_drm_connector *conn = drm->outputs->items[i]; wl_list_for_each(conn, &drm->outputs, link) {
if (conn->state == WLR_DRM_CONN_CONNECTED) { if (conn->state == WLR_DRM_CONN_CONNECTED) {
conn->state = WLR_DRM_CONN_CLEANUP; conn->state = WLR_DRM_CONN_CLEANUP;
} }
@ -869,11 +867,13 @@ void wlr_drm_restore_outputs(struct wlr_drm_backend *drm) {
while (to_close && time(NULL) < timeout) { while (to_close && time(NULL) < timeout) {
wlr_drm_event(drm->fd, 0, NULL); wlr_drm_event(drm->fd, 0, NULL);
for (size_t i = 0; i < drm->outputs->length; ++i) { size_t i = 0;
struct wlr_drm_connector *conn = drm->outputs->items[i]; struct wlr_drm_connector *conn;
wl_list_for_each(conn, &drm->outputs, link) {
if (conn->state != WLR_DRM_CONN_CLEANUP || !conn->pageflip_pending) { if (conn->state != WLR_DRM_CONN_CLEANUP || !conn->pageflip_pending) {
to_close &= ~(1 << i); to_close &= ~(1 << i);
} }
i++;
} }
} }
@ -881,8 +881,7 @@ void wlr_drm_restore_outputs(struct wlr_drm_backend *drm) {
wlr_log(L_ERROR, "Timed out stopping output renderers"); wlr_log(L_ERROR, "Timed out stopping output renderers");
} }
for (size_t i = 0; i < drm->outputs->length; ++i) { wl_list_for_each(conn, &drm->outputs, link) {
struct wlr_drm_connector *conn = drm->outputs->items[i];
drmModeCrtc *crtc = conn->old_crtc; drmModeCrtc *crtc = conn->old_crtc;
if (!crtc) { if (!crtc) {
continue; continue;

@ -8,12 +8,12 @@
#include <xf86drmMode.h> #include <xf86drmMode.h>
#include <EGL/egl.h> #include <EGL/egl.h>
#include <gbm.h> #include <gbm.h>
#include <wayland-util.h>
#include <wlr/backend/session.h> #include <wlr/backend/session.h>
#include <wlr/backend/drm.h> #include <wlr/backend/drm.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include <wlr/egl.h> #include <wlr/egl.h>
#include <wlr/util/list.h>
#include "iface.h" #include "iface.h"
#include "properties.h" #include "properties.h"
@ -93,7 +93,7 @@ struct wlr_drm_backend {
struct wl_listener session_signal; struct wl_listener session_signal;
struct wl_listener drm_invalidated; struct wl_listener drm_invalidated;
list_t *outputs; struct wl_list outputs;
struct wlr_drm_renderer renderer; struct wlr_drm_renderer renderer;
struct wlr_session *session; struct wlr_session *session;
@ -130,6 +130,7 @@ struct wlr_drm_connector {
bool pageflip_pending; bool pageflip_pending;
struct wl_event_source *retry_pageflip; struct wl_event_source *retry_pageflip;
struct wl_list link;
}; };
bool wlr_drm_check_features(struct wlr_drm_backend *drm); bool wlr_drm_check_features(struct wlr_drm_backend *drm);

Loading…
Cancel
Save